/****** Object:  StoredProcedure [dbo].[spFinPrestamo]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spFinPrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spFinPrestamo]
GO
/****** Object:  StoredProcedure [dbo].[spFinCuposSML]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spFinCuposSML]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spFinCuposSML]
GO
/****** Object:  StoredProcedure [dbo].[spFinCuotas]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spFinCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spFinCuotas]
GO
/****** Object:  StoredProcedure [dbo].[spFinCliente]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spFinCliente]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spFinCliente]
GO
/****** Object:  StoredProcedure [dbo].[spConsultaDatosEventoDian]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spConsultaDatosEventoDian]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spConsultaDatosEventoDian]
GO
/****** Object:  StoredProcedure [dbo].[spClieSalarios]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spClieSalarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spClieSalarios]
GO
/****** Object:  StoredProcedure [dbo].[spClientes]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spClientes]
GO
/****** Object:  StoredProcedure [dbo].[spArticulos]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfUpdateKmVehs]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfUpdateKmVehs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfUpdateKmVehs]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeUpdateItemTrn_TraEspPrograma]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeUpdateItemTrn_TraEspPrograma]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeUpdateItemTrn_TraEspPrograma]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_VencimientosDoc]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_VencimientosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_VencimientosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_VenceAbonos]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_VenceAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_VenceAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspReservasRelDet]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspReservasRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspReservasRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspReservasRel]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspReservasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspReservasRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspReservasFmt]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspReservasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspReservasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspProgramaPers]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspProgramaPers]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspProgramaPers]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPgrRelDet]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspPgrRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPgrRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPgrRel]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspPgrRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPgrRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPgrFmt]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspPgrFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPgrFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPedidoRelDet]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspPedidoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPedidoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPedidoRel]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspPedidoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPedidoRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPedidoFmt]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspPedidoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPedidoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOtroSiRel]    Script Date: 10/12/2025 8:10:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOtroSiRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOtroSiRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOtroSiFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOtroSiFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOtroSiFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOrdPagoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOrdPagoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOrdPagoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOrdenPagoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOrdenPagoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOrdenPagoLta]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOPagoRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOPagoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOPagoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDetRen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOPagoNetoDetRen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDetRen]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspOPagoNetoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspNovResFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspNovResFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspNovResFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspListaPasaResFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspListaPasaResFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspListaPasaResFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspListaPasaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspListaPasaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspListaPasaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspLiquidaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaOtrFmtCauDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspLiquidaOtrFmtCauDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaOtrFmtCauDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspLiquidaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaEgrFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspLiquidaEgrFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaEgrFac]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaDedFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspLiquidaDedFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaDedFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspGenRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspGenRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspGenRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspGenRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspGenRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspGenRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFuecRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFuecRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFuecFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecCond]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFuecCond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecCond]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFacturasRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFacturasRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFacturasRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFacturasRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFacturasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFacturasRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFacturaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspFacturaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFacturaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevOdpRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevOdpRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevOdpRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevOdpFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevOdpFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevOdpFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevLiquidaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevLiquidaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevLiquidaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevLiqRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevLiqRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevLiqRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevLiq]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevGenRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevGenRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevGenRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevFacturasRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevFacturasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevFacturasRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevFacFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevFacFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevFacFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevCumFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevCumFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevCumFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevCauRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevCauRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevCauRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevAntRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspDevAntRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevAntRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCumplidosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspCumplidosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCumplidosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCuenta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspCuenta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCuenta]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspContratoRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspContratoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspContratoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspContratoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspContratoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspContratoRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspContratoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspContratoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspContratoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspComFacturaNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspComFacturaNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspComFacturaNit]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCausacionLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspCausacionLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCausacionLiq]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCauRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspCauRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCauRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCauRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspCauRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCauRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspAnticiposRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspAnticiposRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspAnticiposRel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspAntAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTrn_TraEspAntAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTrn_TraEspAntAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTm_TraEspTempDetCons]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTm_TraEspTempDetCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTm_TraEspTempDetCons]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLis_VehiculosPza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLis_VehiculosPza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLis_VehiculosPza]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLis_NovPgr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLis_NovPgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLis_NovPgr]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLis_DirTe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeLis_DirTe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeLis_DirTe]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehPropietarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsVehPropietarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsVehPropietarios]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehPolizas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsVehPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsVehPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehiculos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehConductores]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsVehConductores]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsVehConductores]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVeh_Contrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsVeh_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsVeh_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsUpdateEstadoItem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsUpdateEstadoItem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsUpdateEstadoItem]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehTraspasos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_VehTraspasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_VehTraspasos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehNumOrden]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_VehNumOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_VehNumOrden]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehLecturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_VehLecturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_VehLecturas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehConductor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_VehConductor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_VehConductor]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspSedes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspSedes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspSedes]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspReservas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspReservas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspReservas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPrograma]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspPrograma]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPrograma]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPicoPlaca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspPicoPlaca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPicoPlaca]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspPedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPedido]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPasajeros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspPasajeros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPasajeros]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspOtroSi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspOtroSi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspOtroSi]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspOrdenPagoGIE]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspOrdenPagoGIE]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspOrdenPagoGIE]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspOrdenPago]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspOrdenPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspOrdenPago]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspFuec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspFuec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspFuec]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevOdpGIE]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspDevOdpGIE]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevOdpGIE]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevOdp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspDevOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevOdp]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspDevLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevLiq]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevCum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspDevCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevCum]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevCau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspDevCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevCau]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspDevAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevAnt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspCumplido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspCumplido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspCumplido]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspContratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspContratos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspCausacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspAnticipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_TraEspAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_TraEspAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_FcSemanas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_FcSemanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_FcSemanas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_Facturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_Facturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_Facturas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_Factcon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_Factcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_Factcon]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_DevFcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_DevFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_DevFcr]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_DevFco]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_DevFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_DevFco]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_Aprobacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTrn_Aprobacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTrn_Aprobacion]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraFijos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspPolizas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraEspPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraEspPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspObjContratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraEspObjContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraEspObjContratos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspHorario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraEspHorario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraEspHorario]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspGruposCol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraEspGruposCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraEspGruposCol]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspColegios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraEspColegios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraEspColegios]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraConcCausac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTraConcCausac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTraConcCausac]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposVehFactor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposVehFactor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposVehFactor]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposVeh]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposPpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposPpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposPpt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposOperac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposOperac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposOperac]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposNovPgr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposNovPgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposNovPgr]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposNivs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposNivs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposNivs]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposMot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposMot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposMot]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposMod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposMod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposMod]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposLub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposLub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposLub]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposLla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposLla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposLla]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposFuel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposFuel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposFuel]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposDocumentos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposDocumentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposDocumentos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposCon]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposComFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposComFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposComFmt]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposCol]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCatLic]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposCatLic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposCatLic]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCalendarPgr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposCalendarPgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposCalendarPgr]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposAdm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTiposAdm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTiposAdm]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercPropietario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercPropietario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercPropietario]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTerceros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTerceros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTerceros]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercDocumentos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercDocumentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercDocumentos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndtores]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercCndtores]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercCndtores]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndTarjetas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercCndTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercCndTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndReferencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercCndReferencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercCndReferencias]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercCndDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercCndDoc]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndContrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercCndContrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercCndContrato]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndCapac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercCndCapac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercCndCapac]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercAccionistas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTercAccionistas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTercAccionistas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTarifasEsp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTarifasEsp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTarifasEsp]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTablaPor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsTablaPor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsTablaPor]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Security]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_Security]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_Security]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Report]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_Report]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_Report]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Modulos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_Modulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_Modulos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_GruposUsu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_GruposUsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_GruposUsu]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_FmtDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_FmtDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_FmtDoc]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Estaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_Estaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_Estaciones]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Cnxextna]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_Cnxextna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_Cnxextna]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Autoriza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsSys_Autoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsSys_Autoriza]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsRutas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsRutas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsPreFacturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsPreFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsPreFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsOtroSiFromCOE]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsOtroSiFromCOE]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsOtroSiFromCOE]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvTrn_Facturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMsvTrn_Facturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMsvTrn_Facturas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvTrn_DevFcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMsvTrn_DevFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMsvTrn_DevFcr]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvPrograma]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMsvPrograma]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMsvPrograma]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvOrdenPago]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMsvOrdenPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMsvOrdenPago]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvLiquidacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMsvLiquidacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMsvLiquidacion]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvFuec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMsvFuec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMsvFuec]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMarcasLin]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMarcasLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMarcasLin]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMarcas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsMarcas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsMarcas]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLogTraEspSys]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsLogTraEspSys]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsLogTraEspSys]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLogTraEspPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsLogTraEspPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsLogTraEspPro]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLogTraEspInOut]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsLogTraEspInOut]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsLogTraEspInOut]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLocalidades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsLocalidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsLocalidades]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsListaPasaResProceso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsListaPasaResProceso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsListaPasaResProceso]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsListaPasaRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsListaPasaRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsListaPasaRes]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsListaPasajeros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsListaPasajeros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsListaPasajeros]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsGruposRot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsGruposRot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsGruposRot]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsGruposPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsGruposPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsGruposPro]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsGruposCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsGruposCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsGruposCli]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsExpLicencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsExpLicencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsExpLicencias]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEstadoVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsEstadoVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsEstadoVeh]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEstadoTer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsEstadoTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsEstadoTer]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEstadoDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsEstadoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsEstadoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEdsServicio]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsEdsServicio]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsEdsServicio]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsDocConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsDocConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsDocConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsDepartamentos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsDepartamentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsDepartamentos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsConceptosFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsConceptosFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsConceptosFijos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsConceptosDiv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsConceptosDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsConceptosDiv]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCompanias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsCompanias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsCompanias]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClasePol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsClasePol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsClasePol]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseDocCond]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsClaseDocCond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsClaseDocCond]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseDiv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsClaseDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsClaseDiv]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseCta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsClaseCta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsClaseCta]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseCapac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsClaseCapac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsClaseCapac]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCentrosServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsCentrosServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsCentrosServ]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCargos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsCargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsCargos]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCalndario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsCalndario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsCalndario]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsadm_Usuarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsadm_Usuarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsadm_Usuarios]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsadm_Registro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsadm_Registro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsadm_Registro]
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsadm_Opciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfSeInsadm_Opciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfSeInsadm_Opciones]
GO
/****** Object:  StoredProcedure [dbo].[paWcfGetCTraFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paWcfGetCTraFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paWcfGetCTraFijos]
GO
/****** Object:  StoredProcedure [dbo].[paUpZonas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpZonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpZonas]
GO
/****** Object:  StoredProcedure [dbo].[paUpVencimientosCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVencimientosCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVencimientosCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpVencimientosApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVencimientosApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVencimientosApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpVencimientosAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVencimientosAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVencimientosAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehRemolqTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehRemolqTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehRemolqTra]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehRemolqKmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehRemolqKmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehRemolqKmt]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehRemolq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehRemolq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehRemolq]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehPolizas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehPartes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehPartes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehPartes]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehLecturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehLecturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehLecturas]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosUbi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosUbi]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosTra]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosSCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosSCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosSCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosRetB]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosRetB]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosRetB]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosMuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosMuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosMuc]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosKmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosKmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosKmt]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosEcon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosEcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosEcon]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCup]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosCup]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosCup]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosCen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosCen]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCdt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosCdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosCdt]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paUpVehClientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVehClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVehClientes]
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_Saldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVeh_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVeh_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_CuposSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVeh_CuposSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVeh_CuposSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_CuposAll]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVeh_CuposAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVeh_CuposAll]
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_Cupos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVeh_Cupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVeh_Cupos]
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_Contrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpVeh_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpVeh_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paUpValesFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpValesFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpValesFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpValesDfa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpValesDfa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpValesDfa]
GO
/****** Object:  StoredProcedure [dbo].[paUpValesDevItem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpValesDevItem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpValesDevItem]
GO
/****** Object:  StoredProcedure [dbo].[paUpValesDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpValesDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpValesDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpUsucaja]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUsucaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUsucaja]
GO
/****** Object:  StoredProcedure [dbo].[paUpUsuariosPwd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUsuariosPwd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUsuariosPwd]
GO
/****** Object:  StoredProcedure [dbo].[paUpUsuariosCnn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUsuariosCnn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUsuariosCnn]
GO
/****** Object:  StoredProcedure [dbo].[paUpUsuarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUsuarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUsuarios]
GO
/****** Object:  StoredProcedure [dbo].[paUpUOpciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpUndMed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUndMed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUndMed]
GO
/****** Object:  StoredProcedure [dbo].[paUpUm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpUm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpUm]
GO
/****** Object:  StoredProcedure [dbo].[paUpTurnos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTurnos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTurnos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTurn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraTurn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraTurn]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTrasladosAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraTrasladosAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraTrasladosAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTraslados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTalonarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraTalonarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraTalonarios]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraslados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraReportes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraReportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraReportes]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemMciasMuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraRemMciasMuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraRemMciasMuc]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemesaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraRemesaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraRemesaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemesa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraRemesa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraRemesa]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemAnexo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraRemAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraRemAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraReexpedidoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraReexpedidoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraReexpedidoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraReexpedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraReexpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraReexpedido]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPresAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraPresAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraPresAnt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPorteInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraPorteInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraPorteInt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedidoApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraPedidoApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraPedidoApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedidoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraPedidoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraPedidoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraPedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraPedido]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedAnexo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraPedAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraPedAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenServAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenServAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenServAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenPagoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenPagoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenPagoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenPago]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenPago]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenLiqAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenLiqAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenLiqAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenLiq]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenCumAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenCumAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenCumAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenCum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenCum]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenAntApp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenAntApp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenAntApp]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenAntAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenAntAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenAntAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraOrdenAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraOrdenAnt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraManifInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraManifInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraManifInt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraManifiestoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraManifiestoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraManifiestoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraManifiesto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraManifiesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraManifiesto]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiqViajesAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraLiqViajesAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraLiqViajesAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiqViajes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraLiqViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraLiqViajes]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiquidaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraLiquidaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraLiquidaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraInfViajes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraInfViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraInfViajes]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraGuias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraGuias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraGuias]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraFijos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevReex]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevReex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevReex]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevOdp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevOdp]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevLgo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevLgo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevLgo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevLeg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevLeg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevLeg]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevCos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevCos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevCos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevCau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevCau]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevAos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevAos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevAos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDevAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDevAnt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDespProgram]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDespProgram]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDespProgram]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDespachosAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDespachosAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDespachosAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDespachos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDecAduana]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraDecAduana]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraDecAduana]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCumRadica]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraCumRadica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraCumRadica]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCumplidoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraCumplidoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraCumplidoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCumplido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraCumplido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraCumplido]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraConcCausac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraConcCausac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraConcCausac]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCausacionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraCausacionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraCausacionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCausacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticiposApp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraAnticiposApp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraAnticiposApp]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticiposApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraAnticiposApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraAnticiposApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticiposAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraAnticiposAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraAnticiposAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTraAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTraAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_VentasCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_VentasCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_VentasCom]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_vce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_vce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_vce]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_SaldosMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_SaldosMov]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_SaldosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_SaldosCue]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosCos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_SaldosCos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_SaldosCos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_SaldosAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_SaldosAnt]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PreExtoCuo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_PreExtoCuo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_PreExtoCuo]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PlasueldosVac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_PlasueldosVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_PlasueldosVac]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PlasueldosObs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_PlasueldosObs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_PlasueldosObs]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PagosTap]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_PagosTap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_PagosTap]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PagosCam]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_PagosCam]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_PagosCam]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_NominaPar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_NominaPar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_NominaPar]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_Nomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovVentasDos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovVentasDos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovVentasDos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovTanquesSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovTanquesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovTanquesSan]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovTanquesFis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovTanquesFis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovTanquesFis]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovInventDos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovInventDos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovInventDos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueVehCcSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueVehCcSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueVehCcSub]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueVehCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueVehCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueVehCc]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueSan]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitVehCcSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitVehCcSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitVehCcSub]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitVehCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitVehCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitVehCc]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitCcSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitCcSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitCcSub]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitCc]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitAgeCcSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitAgeCcSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitAgeCcSub]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitAgeCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitAgeCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitAgeCc]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitAge]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNitAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNitAge]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueNit]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueCcSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueCcSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueCcSub]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovCueCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovCueCc]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovClientesSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_MovClientesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_MovClientesSan]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LiquidaPar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_LiquidaPar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_LiquidaPar]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LiquidaInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_LiquidaInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_LiquidaInt]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_Liquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_Liquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_Liquida]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LibOfSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_LibOfSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_LibOfSan]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LibOf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_LibOf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_LibOf]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_KdexExto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_KdexExto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_KdexExto]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_IntNomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_IntNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_IntNomina]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_ExtVehVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_ExtVehVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehVal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_ExtVehVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_ExtVehVal]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehProd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_ExtVehProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_ExtVehProd]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_ExtVehPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_ExtVehPro]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_ExtVehNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_ExtVehNit]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EstCueCteVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_EstCueCteVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_EstCueCteVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EstCueCtePro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_EstCueCtePro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_EstCueCtePro]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EstadoGypDos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_EstadoGypDos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_EstadoGypDos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EdsFormasTap]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_EdsFormasTap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_EdsFormasTap]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_CxCobrarAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_CxCobrarAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_CxCobrarAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_CargosAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_CargosAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_CargosAnt]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalGenUno]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_BalGenUno]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_BalGenUno]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalGenDos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_BalGenDos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_BalGenDos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalComSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_BalComSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_BalComSan]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalComparaTres]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_BalComparaTres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_BalComparaTres]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalComparaDos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_BalComparaDos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_BalComparaDos]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AuxInvSanKar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_AuxInvSanKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_AuxInvSanKar]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AuxInvSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_AuxInvSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_AuxInvSan]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AuxInvCpm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_AuxInvCpm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_AuxInvCpm]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AutTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_AutTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_AutTot]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AportesNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_AportesNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_AportesNov]
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AportesDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptm_AportesDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptm_AportesDet]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposZona]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposZona]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposZona]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposTerc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposTerc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposTerc]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposTasas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposTasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposTasas]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposSustento]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposSustento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposSustento]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposRespFis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposRespFis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposRespFis]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposProceso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposProceso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposProceso]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposPrend]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposPrend]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposPrend]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposPpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposPpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposPpt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposPcnto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposPcnto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposPcnto]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposOperarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposOperarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposOperarios]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposOperac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposOperac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposOperac]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposNov]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposNom]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNivs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposNivs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposNivs]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposNat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposNat]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMotdev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposMotdev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposMotdev]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposMot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposMot]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposMod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposMod]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMnjo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposMnjo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposMnjo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMcia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposMat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposMat]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposLub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposLub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposLub]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposLla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposLla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposLla]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposInm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposInm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposInm]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposFuel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposFuel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposFuel]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposFil]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposFil]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposFil]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposEsc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposEsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposEsc]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposEnt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDocCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposDocCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposDocCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDocConsNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposDocConsNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposDocConsNum]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDocCons]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposDocCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposDocCons]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCot]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposComRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposComRes]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComFmtPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposComFmtPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposComFmtPre]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposComFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposComFmt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComConsNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposComConsNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposComConsNum]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComCons]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposComCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposComCons]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposComAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposComAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCom]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCol]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCnd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCnd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCnd]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCarga]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCarga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCarga]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposCar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposCar]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposBloq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposBloq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposBloq]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposBan]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposAdm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTiposAdm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTiposAdm]
GO
/****** Object:  StoredProcedure [dbo].[paUpTFmtos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTFmtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTFmtos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTerminales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTerminales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTerminales]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercVendedor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercVendedor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercVendedor]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercProveeEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercProveeEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercProveeEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercProvee]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercProvee]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercPropietarioSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercPropietarioSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercPropietarioSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercPropietario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercPropietario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercPropietario]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosVen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercerosVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercerosVen]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosPrv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercerosPrv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercerosPrv]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercerosEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercerosEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercerosCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercerosCli]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosCdt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercerosCdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercerosCdt]
GO
/****** Object:  StoredProcedure [dbo].[paUpTerceros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTerceros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTerceros]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresTar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresTar]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresFtar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresFtar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresFtar]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresCont]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresCont]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresCont]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtoresCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtoresCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtores]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndtores]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndtores]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndTarjetas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndReferencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndReferencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndReferencias]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndContrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCndContrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCndContrato]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClieVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClieVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieSaldosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClieSaldosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClieSaldosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClieSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClieSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieRef]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClieRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClieRef]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCliePrestamo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCliePrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCliePrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCliePreRef]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCliePreRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCliePreRef]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteSdo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClienteSdo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClienteSdo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClienteEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClienteEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteCre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClienteCre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClienteCre]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClienteCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClienteCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCliente]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercCliente]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercCliente]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieLineas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClieLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClieLineas]
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieGarant]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTercClieGarant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTercClieGarant]
GO
/****** Object:  StoredProcedure [dbo].[paUpTaxTarifClie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTaxTarifClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTaxTarifClie]
GO
/****** Object:  StoredProcedure [dbo].[paUpTaxTarifas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTaxTarifas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTaxTarifas]
GO
/****** Object:  StoredProcedure [dbo].[paUpTaxRutas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTaxRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTaxRutas]
GO
/****** Object:  StoredProcedure [dbo].[paUpTasasIntmora]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTasasIntmora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTasasIntmora]
GO
/****** Object:  StoredProcedure [dbo].[paUpTasasInteres]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTasasInteres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTasasInteres]
GO
/****** Object:  StoredProcedure [dbo].[paUpTasasDTF]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTasasDTF]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTasasDTF]
GO
/****** Object:  StoredProcedure [dbo].[paUptasas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUptasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUptasas]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifBuses]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifasServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifasServ]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasPaq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifasPaq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifasPaq]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasMasivo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifasMasivo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifasMasivo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasFletes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifasFletes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifasFletes]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasFleMay]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifasFleMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifasFleMay]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasAportes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifasAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifasAportes]
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifAnticipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTarifAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTarifAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanquesSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanquesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanquesSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanques]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanques]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqSaldosKar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanqSaldosKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanqSaldosKar]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanqSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanqSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqDispensLec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanqDispensLec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanqDispensLec]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqDispens]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanqDispens]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanqDispens]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqAforoFrac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanqAforoFrac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanqAforoFrac]
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqAforo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTanqAforo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTanqAforo]
GO
/****** Object:  StoredProcedure [dbo].[paUpTalleres]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTalleres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTalleres]
GO
/****** Object:  StoredProcedure [dbo].[paUpTablapor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpTablapor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpTablapor]
GO
/****** Object:  StoredProcedure [dbo].[paUpSubzonas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSubzonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSubzonas]
GO
/****** Object:  StoredProcedure [dbo].[paUpSubgruposCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSubgruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSubgruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpSubGruposAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSubGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSubGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paUpSubGrupos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSubGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSubGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paUpSubCentros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSubCentros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSubCentros]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobTiposDecNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobTiposDecNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobTiposDecNum]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobTiposDec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobTiposDec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobTiposDec]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobretasasEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobretasasEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobretasasEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobretasasCie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobretasasCie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobretasasCie]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobretasas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobretasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobretasas]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobProductos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobProductos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobProductos]
GO
/****** Object:  StoredProcedure [dbo].[paUpSobEntidades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSobEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSobEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paUpSerialesUbi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSerialesUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSerialesUbi]
GO
/****** Object:  StoredProcedure [dbo].[paUpSerialesSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSerialesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSerialesSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpSerialesEtd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSerialesEtd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSerialesEtd]
GO
/****** Object:  StoredProcedure [dbo].[paUpSeriales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSeriales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSeriales]
GO
/****** Object:  StoredProcedure [dbo].[paUpSecurity]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSecurity]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSecurity]
GO
/****** Object:  StoredProcedure [dbo].[paUpSectoresEco]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSectoresEco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSectoresEco]
GO
/****** Object:  StoredProcedure [dbo].[paUpSAutoriza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paUpSalidasDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSalidasDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSalidasDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpSalidas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpSalidas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpSalidas]
GO
/****** Object:  StoredProcedure [dbo].[paUpRutasTramos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRutasTramos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRutasTramos]
GO
/****** Object:  StoredProcedure [dbo].[paUpRutasPlan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRutasPlan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRutasPlan]
GO
/****** Object:  StoredProcedure [dbo].[paUpRutas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRutas]
GO
/****** Object:  StoredProcedure [dbo].[paUpRoles]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRoles]
GO
/****** Object:  StoredProcedure [dbo].[paUpResiduosPeligrosos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpResiduosPeligrosos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpResiduosPeligrosos]
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicionSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRequisicionSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRequisicionSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicionApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRequisicionApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRequisicionApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRequisicionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRequisicionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRequisicion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRequisicion]
GO
/****** Object:  StoredProcedure [dbo].[paUpReportSubPmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpReportSubPmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpReportSubPmt]
GO
/****** Object:  StoredProcedure [dbo].[paUpReportSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpReportSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpReportSub]
GO
/****** Object:  StoredProcedure [dbo].[paUpReportFmto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpReportFmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpReportFmto]
GO
/****** Object:  StoredProcedure [dbo].[paUpReport]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpReport]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpReport]
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRemisionFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRemisionFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRemisionApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRemisionApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRemisionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRemisionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionAbr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRemisionAbr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRemisionAbr]
GO
/****** Object:  StoredProcedure [dbo].[paUpRemision]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRemision]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRemision]
GO
/****** Object:  StoredProcedure [dbo].[paUpRelaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRelaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRelaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpRegistroFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRegistroFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRegistroFec]
GO
/****** Object:  StoredProcedure [dbo].[paUpRegistro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRegistro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRegistro]
GO
/****** Object:  StoredProcedure [dbo].[paUpRegimenDian]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRegimenDian]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRegimenDian]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecTanqueosAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecTanqueosAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecTanqueosAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecibosDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecibosDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecibosDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecibos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecFactura]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecFactura]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecChequesAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecChequesAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecChequesAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecCheques]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecCheques]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesTabo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesTabo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesTabo]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesCeroVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesCeroVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesCeroVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAplVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesAplVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesAplVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAcp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesAcp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesAcp]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBusesAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBusesAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorOdb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecAfavorOdb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecAfavorOdb]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecAfavorCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecAfavorCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorApld]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecAfavorApld]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecAfavorApld]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecAfavorApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecAfavorApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRecAfavorAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRecAfavorAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpRangosPeso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRangosPeso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRangosPeso]
GO
/****** Object:  StoredProcedure [dbo].[paUpRadicaValesDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRadicaValesDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRadicaValesDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpRadicaVales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpRadicaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpRadicaVales]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntTarjetasAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntTarjetasAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntTarjetasAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntTarjetas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntProg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntProg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntProg]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntPremios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntPremios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntPremios]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntos]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntFormas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntFormas]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntBases]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuntBases]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuntBases]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuestos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuestos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuestos]
GO
/****** Object:  StoredProcedure [dbo].[paUpPucNiif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPucNiif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPucNiif]
GO
/****** Object:  StoredProcedure [dbo].[paUpPuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPuc]
GO
/****** Object:  StoredProcedure [dbo].[paUpProfesiones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProfesiones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProfesiones]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdTarf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdTarf]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldoUbcKar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdSaldoUbcKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdSaldoUbcKar]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldoUbc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdSaldoUbc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdSaldoUbc]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldosKar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdSaldosKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdSaldosKar]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdProvee]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdProvee]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdProcesos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdProcesos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdProcesos]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdPrecios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdPrecios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdPrecios]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdPrecCrudo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdPrecCrudo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdPrecCrudo]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdPrecCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdPrecCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdPrecCom]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdOrden]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdOrden]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdMciasSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdMciasSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdMciasRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdMciasRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasIva]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdMciasIva]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdMciasIva]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasIca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdMciasIca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdMciasIca]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdMciasEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdMciasEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMcias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdMcias]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdInsumos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdInsumos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdInsumos]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdImptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdImptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdImptos]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdImpFron]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdImpFron]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdImpFron]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdEntrega]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdEntrega]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdEntrega]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdCostos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdCostos]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdConsolida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdConsolida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdConsolida]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdCombo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdCombo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdCombo]
GO
/****** Object:  StoredProcedure [dbo].[paUpProdAditivos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpProdAditivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpProdAditivos]
GO
/****** Object:  StoredProcedure [dbo].[paUpPresupuesto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPresupuesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPresupuesto]
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamosCan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPrestamosCan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPrestamosCan]
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamosAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPrestamosAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPrestamosAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPrestamosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPrestamosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paUpPreCausacionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPreCausacionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPreCausacionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpPolizas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paUpPlazos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPlazos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPlazos]
GO
/****** Object:  StoredProcedure [dbo].[paUpPicoPlaca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPicoPlaca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPicoPlaca]
GO
/****** Object:  StoredProcedure [dbo].[paUpPermisosRoles]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPermisosRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPermisosRoles]
GO
/****** Object:  StoredProcedure [dbo].[paUpPermisos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPermisos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPermisos]
GO
/****** Object:  StoredProcedure [dbo].[paUpPeajesTarf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPeajesTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPeajesTarf]
GO
/****** Object:  StoredProcedure [dbo].[paUpPeajesClase]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPeajesClase]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPeajesClase]
GO
/****** Object:  StoredProcedure [dbo].[paUpPeajesCat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPeajesCat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPeajesCat]
GO
/****** Object:  StoredProcedure [dbo].[paUpPaises]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPaises]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPaises]
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPagosFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPagosFor]
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosEod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPagosEod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPagosEod]
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPagosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPagosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosCnEfe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPagosCnEfe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPagosCnEfe]
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosCnChe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPagosCnChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPagosCnChe]
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosACns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpPagosACns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpPagosACns]
GO
/****** Object:  StoredProcedure [dbo].[paUpOrgTransito]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOrgTransito]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOrgTransito]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoRem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoRem]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoDvs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoDvs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoDvs]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoBlo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoBlo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoBlo]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoAbf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedidoAbf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedidoAbf]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpedido]
GO
/****** Object:  StoredProcedure [dbo].[paUpOpciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilTraslado]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilNotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilNotas]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilMediciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilMediciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilMediciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilInventDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilInventDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilInventDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilInvent]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilInvent]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilGuia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilGuia]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilEntrada]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilEntrada]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilEntrada]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilDevCostos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilDevCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilDevCostos]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilDevCompra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilDevCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilDevCompra]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilDespClie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilDespClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilDespClie]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCostoVen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilCostoVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilCostoVen]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCostos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilCostos]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCompraDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilCompraDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilCompraDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCompra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilCompra]
GO
/****** Object:  StoredProcedure [dbo].[paUpOilAjustes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOilAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOilAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paUpOcupaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOcupaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOcupaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCompraApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCompraApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraApb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCompraApb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCompraApb]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCompraAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCompraAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraAbr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCompraAbr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCompraAbr]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCompra]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombGui]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCombGui]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCombGui]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCombFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCombFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCombApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCombApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCombAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCombAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombAbr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOCombAbr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOCombAbr]
GO
/****** Object:  StoredProcedure [dbo].[paUpOComb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpOComb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpOComb]
GO
/****** Object:  StoredProcedure [dbo].[paUpObjetosApp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpObjetosApp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpObjetosApp]
GO
/****** Object:  StoredProcedure [dbo].[paUpNovedadTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNovedadTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNovedadTra]
GO
/****** Object:  StoredProcedure [dbo].[paUpNovedadRep]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNovedadRep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNovedadRep]
GO
/****** Object:  StoredProcedure [dbo].[paUpNotasBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNotasBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNotasBuses]
GO
/****** Object:  StoredProcedure [dbo].[paUpNotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNotas]
GO
/****** Object:  StoredProcedure [dbo].[paUpNotaProdDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNotaProdDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNotaProdDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpNotaProd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNotaProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNotaProd]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomZonasConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomZonasConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomZonasConv]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVehiculos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVacDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomVacDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomVacDet]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVacAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomVacAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomVacAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomVac]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomTablaRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomTablaRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomTablaRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomSueldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomSueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomSueldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomRetAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomRetAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomRetAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomRangosFsu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomRangosFsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomRangosFsu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestTCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestTCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestTCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestTAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestTAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestTAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestCan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestCan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestCan]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestAbn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrestAbn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrestAbn]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrest]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrest]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrest]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrendas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomPrendas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomPrendas]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNovedadAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomNovedadAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomNovedadAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNovedad]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomNovedad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomNovedad]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNovConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomNovConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomNovConv]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomNov]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLogVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomLogVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomLogVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLiquidaPar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomLiquidaPar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomLiquidaPar]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLiquidaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomLiquidaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomLiquidaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paUpNominaCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNominaCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNominaCmp]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomina]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomGruposConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomGruposConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomGruposConv]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomFijos]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomEstadosConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomEstadosConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomEstadosConv]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomEscalafones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomEscalafones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomEscalafones]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomDotacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomDotacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomDotacion]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomDefault]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomDefault]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomDefault]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConvenciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomConvenciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomConvenciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConOpciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomConOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomConOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConCuentas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomConCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomConCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConcConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomConcConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomConcConv]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConAuto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomConAuto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomConAuto]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCertf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomCertf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomCertf]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCausalesRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomCausalesRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomCausalesRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCapacitaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomCapacitaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomCapacitaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCAdmonAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomCAdmonAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomCAdmonAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCAdmon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomCAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomCAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomBasesConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomBasesConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomBasesConv]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAutoliqAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAutoliqAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAutoliqAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAutoliq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAutoliq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAutoliq]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAstncia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAstncia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAstncia]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAportante]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAportante]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAportante]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAlqTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAlqTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAlqTot]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAlqNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAlqNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAlqNov]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAlqDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAlqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAlqDet]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAjustes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomActividades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomActividades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomActividades]
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNomAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNomAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifPoliticas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNiifPoliticas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNiifPoliticas]
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifDetallePla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNiifDetallePla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNiifDetallePla]
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifCompAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNiifCompAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNiifCompAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifComp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpNiifComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpNiifComp]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudServicios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudServicios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudServicios]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudSecciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudSecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudSecciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudOrdenServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudInventario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudInventario]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudEstados]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudContratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudContratos]
GO
/****** Object:  StoredProcedure [dbo].[paUpMudArticulos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMudArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMudArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoTiposOdt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoTiposOdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoTiposOdt]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoTipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoTipos]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoSistemas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoSistemas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoSistemas]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoOrdenDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoOrdenDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoOrdenDet]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoOrdenAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoOrdenAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoOrdenAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoOrden]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoOrden]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoInspecciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoInspecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoInspecciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoEstados]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoControles]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoControles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoControles]
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMttoConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMttoConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paUpmonedasTas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpmonedasTas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpmonedasTas]
GO
/****** Object:  StoredProcedure [dbo].[paUpmonedasLoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpmonedasLoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpmonedasLoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpmonedas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpmonedas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpmonedas]
GO
/****** Object:  StoredProcedure [dbo].[paUpModulos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpModulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpModulos]
GO
/****** Object:  StoredProcedure [dbo].[paUpMercancias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMercancias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMercancias]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposPoliza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayTiposPoliza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayTiposPoliza]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposBonif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayTiposBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayTiposBonif]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposBienes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayTiposBienes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayTiposBienes]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposAprob]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayTiposAprob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayTiposAprob]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayTipos]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayPspto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayPspto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayPspto]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayLiquidaCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayLiquidaCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayLiquidaCmp]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayLiquidaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayLiquidaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayLiquidaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayLiqTotalesNcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayLiqTotalesNcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayLiqTotalesNcr]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayItemsInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayItemsInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayItemsInv]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayInventario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayInventario]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayEstados]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContratosEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayContratosEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayContratosEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContratosApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayContratosApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayContratosApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayContratos]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayContDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayContDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayBonif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayBonif]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayBonCuentas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayBonCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayBonCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paUpMayAnotaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMayAnotaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMayAnotaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpMarcasLin]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMarcasLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMarcasLin]
GO
/****** Object:  StoredProcedure [dbo].[paUpMarcas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpMarcas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpMarcas]
GO
/****** Object:  StoredProcedure [dbo].[paUpLotesSdo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLotesSdo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLotesSdo]
GO
/****** Object:  StoredProcedure [dbo].[paUpLotesSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLotesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLotesSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpLotesCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLotesCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLotesCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpLotes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLotes]
GO
/****** Object:  StoredProcedure [dbo].[paUpLog_Periodos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLog_Periodos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLog_Periodos]
GO
/****** Object:  StoredProcedure [dbo].[paUpLog_Nomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLog_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLog_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paUpLocalidades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLocalidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLocalidades]
GO
/****** Object:  StoredProcedure [dbo].[paUpLineasCredCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLineasCredCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLineasCredCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpLineas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpLineas]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurTiposRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurTiposRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurTiposRec]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurTipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurTipos]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurRecOfrecmto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurRecOfrecmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurRecOfrecmto]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurReclamac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurReclamac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurReclamac]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurPreguntas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurPreguntas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurPreguntas]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestigaCpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurInvestigaCpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurInvestigaCpt]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestigaCie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurInvestigaCie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurInvestigaCie]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestigaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurInvestigaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurInvestigaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestiga]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurInvestiga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurInvestiga]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvesHis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurInvesHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurInvesHis]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurEstados]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurDocumtos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurDocumtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurDocumtos]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurClaseAcc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurClaseAcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurClaseAcc]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCausales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCausales]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosVal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCasosVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCasosVal]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosHis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCasosHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCasosHis]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosCpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCasosCpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCasosCpt]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosCie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCasosCie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCasosCie]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCasosAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCasosAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCasos]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCalifica]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurCalifica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurCalifica]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurAutoridades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurAutoridades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurAutoridades]
GO
/****** Object:  StoredProcedure [dbo].[paUpJurActas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJurActas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJurActas]
GO
/****** Object:  StoredProcedure [dbo].[paUpJornadas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpJornadas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpJornadas]
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisicoTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpInvFisicoTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpInvFisicoTot]
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisicoPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpInvFisicoPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpInvFisicoPro]
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisicoAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpInvFisicoAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpInvFisicoAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisico]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpInvFisico]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpInvFisico]
GO
/****** Object:  StoredProcedure [dbo].[paUpInvDetalleSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpInvDetalleSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpInvDetalleSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpInstalaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpInstalaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpInstalaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpGuiaFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGuiaFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGuiaFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpGuiaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGuiaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGuiaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpGuiaAbr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGuiaAbr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGuiaAbr]
GO
/****** Object:  StoredProcedure [dbo].[paUpGuia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGuia]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposUsu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposUsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposUsu]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposRot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposRot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposRot]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposPro]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposObj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposObj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposObj]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposMcia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposCli]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposAR]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposAR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposAR]
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paUpGrupos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatVinculaDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatVinculaDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatVinculaDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatVincula]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatVincula]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatVincula]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatTrasladosDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatTrasladosDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatTrasladosDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatTraslados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatRetirosDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatRetirosDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatRetirosDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatRetiros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatRetiros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatRetiros]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatProrrateosDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatProrrateosDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatProrrateosDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatProrrateos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatProrrateos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatProrrateos]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatLiquidaDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatLiquidaDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatLiquidaDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevVinc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevVinc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevVinc]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevTraslado]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevRetiros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevRetiros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevRetiros]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevProrr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevProrr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevProrr]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevAjustes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevAjuPror]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevAjuPror]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevAjuPror]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevAdicional]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatDevAdicional]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatDevAdicional]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustesProrDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatAjustesProrDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatAjustesProrDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustesPror]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatAjustesPror]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatAjustesPror]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustesDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatAjustesDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatAjustesDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAdicionalesDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatAdicionalesDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatAdicionalesDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAdicionales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpGatAdicionales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpGatAdicionales]
GO
/****** Object:  StoredProcedure [dbo].[paUpFuentesPago]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFuentesPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFuentesPago]
GO
/****** Object:  StoredProcedure [dbo].[paUpFormaspago]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFormaspago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFormaspago]
GO
/****** Object:  StoredProcedure [dbo].[paUpFormasCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFormasCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFormasCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpFondos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFondos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFondos]
GO
/****** Object:  StoredProcedure [dbo].[paUpFmtFactura]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFmtFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFmtFactura]
GO
/****** Object:  StoredProcedure [dbo].[paUpFmtDocPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFmtDocPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFmtDocPre]
GO
/****** Object:  StoredProcedure [dbo].[paUpFmtDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFmtDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFmtDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinRecibosDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinRecibosDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinRecibosDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinRecibos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestGarant]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestGarant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestGarant]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestamoTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestamoTot]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoPag]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestamoPag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestamoPag]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoMora]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestamoMora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestamoMora]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestamoDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestamoDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoAcum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestamoAcum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestamoAcum]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinPrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinPrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinNotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinNotas]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinFactintDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinFactintDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinFactintDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinFactint]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinFactint]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinFactint]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinDevRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinDevPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinDevPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinDevPre]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinDevFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinDevFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinDevFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCuotasCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinCuotasCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinCuotasCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCuotasApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinCuotasApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinCuotasApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCuotasAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinCuotasAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinCuotasAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinConvenios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinConvenios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinConvenios]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinConcFactura]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinConcFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinConcFactura]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinClieSaldosLin]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinClieSaldosLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinClieSaldosLin]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinClieSaldosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinClieSaldosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinClieSaldosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinClieSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinClieSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinClieSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCanAportes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinCanAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinCanAportes]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAportes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinAportes]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAlmacenes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinAlmacenes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinAlmacenes]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorOdb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinAfavorOdb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinAfavorOdb]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinAfavorDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinAfavorDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinAfavorApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinAfavorApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFinAfavorAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFinAfavorAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos_Veh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFijos_Veh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFijos_Veh]
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos_Cue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFijos_Cue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFijos_Cue]
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos_Cla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFijos_Cla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFijos_Cla]
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFijos]
GO
/****** Object:  StoredProcedure [dbo].[paUpFields]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFields]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFields]
GO
/****** Object:  StoredProcedure [dbo].[paUpFcSemanasAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFcSemanasAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFcSemanasAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpFcSemanas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFcSemanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFcSemanas]
GO
/****** Object:  StoredProcedure [dbo].[paUpFcNotasDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFcNotasDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFcNotasDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpFcNotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFcNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFcNotas]
GO
/****** Object:  StoredProcedure [dbo].[paUpFacturasDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFacturasDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFacturasDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpFacturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paUpFactconDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFactconDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFactconDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpFactcon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpFactcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpFactcon]
GO
/****** Object:  StoredProcedure [dbo].[paUpExpLicencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpExpLicencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpExpLicencias]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstratos]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoTer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoTer]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoSer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoSer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoSer]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoPro]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoOper]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoOper]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoOper]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoGuia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoGuia]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoCiv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstadoCiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstadoCiv]
GO
/****** Object:  StoredProcedure [dbo].[paUpEstaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEstaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEstaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntradasDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntradasDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntradasDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntradas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntradas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntradas]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntidades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntArticulosSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntArticulosSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosDvsp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntArticulosDvsp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntArticulosDvsp]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosDvs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntArticulosDvs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntArticulosDvs]
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosDve]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEntArticulosDve]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEntArticulosDve]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleadosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleadosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosRint]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleadosRint]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleadosRint]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleadosRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleadosRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosFul]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleadosFul]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleadosFul]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosFon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleadosFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleadosFon]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleadosCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleadosCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpleados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpleados]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpaques]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmpaques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmpaques]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_Parientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_Parientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_Parientes]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ExpLaboral]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ExpLaboral]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ExpLaboral]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_Estudios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_Estudios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_Estudios]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoTlq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ContratoTlq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ContratoTlq]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ContratoRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ContratoRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoIns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ContratoIns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ContratoIns]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ContratoCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ContratoCc]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoAum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ContratoAum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ContratoAum]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoAre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_ContratoAre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_ContratoAre]
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_Contrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEmp_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEmp_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paUpEgrFactura]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEgrFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEgrFactura]
GO
/****** Object:  StoredProcedure [dbo].[paUpEgrAnticipoCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEgrAnticipoCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEgrAnticipoCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpEgrAnticipoApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEgrAnticipoApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEgrAnticipoApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsUnion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsUnion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsUnion]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsServicio]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsServicio]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsServicio]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsRangosCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsRangosCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsRangosCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsRangos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsRangos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsRangos]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsFormasPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsFormasPla]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsFormasFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsFormasFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasDfa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsFormasDfa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsFormasDfa]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsFormasAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsFormasAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCortesDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsCortesDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsCortesDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCortes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsCortes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsCortes]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCalibraDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsCalibraDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsCalibraDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCalibra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpEdsCalibra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpEdsCalibra]
GO
/****** Object:  StoredProcedure [dbo].[paUpDocSoporte]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDocSoporte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDocSoporte]
GO
/****** Object:  StoredProcedure [dbo].[paUpDocSopDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDocSopDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDocSopDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpDocMemoImp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDocMemoImp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDocMemoImp]
GO
/****** Object:  StoredProcedure [dbo].[paUpDocMemo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDocMemo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDocMemo]
GO
/****** Object:  StoredProcedure [dbo].[paUpDisciplinarioAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDisciplinarioAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDisciplinarioAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpDisciplinario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDisciplinario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDisciplinario]
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDiferidosRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDiferidosRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosMej]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDiferidosMej]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDiferidosMej]
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosDis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDiferidosDis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDiferidosDis]
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDiferidosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDiferidosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDiferidos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDiferidos]
GO
/****** Object:  StoredProcedure [dbo].[paUpDiarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDiarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDiarios]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevVal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevVal]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevSal]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevRecBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevPrestamos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevPla]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevPas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevPas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevPas]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevNpr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevNpr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevNpr]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevFvc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevFvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevFvc]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevFcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevFcr]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevFco]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevFco]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevEnt]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevCns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevCns]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevCausacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paUpDevCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDevCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDevCaj]
GO
/****** Object:  StoredProcedure [dbo].[paUpDespachosRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDespachosRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDespachosRec]
GO
/****** Object:  StoredProcedure [dbo].[paUpDespachosAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDespachosAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDespachosAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpDespachos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paUpDesagregaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDesagregaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDesagregaciones]
GO
/****** Object:  StoredProcedure [dbo].[paUpDependencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDependencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDependencias]
GO
/****** Object:  StoredProcedure [dbo].[paUpDepartamentos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpDepartamentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpDepartamentos]
GO
/****** Object:  StoredProcedure [dbo].[paUpCtasCorrientesChe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCtasCorrientesChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCtasCorrientesChe]
GO
/****** Object:  StoredProcedure [dbo].[paUpCtasCorrientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCtasCorrientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCtasCorrientes]
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCotizacionFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCotizacionFac]
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionApr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCotizacionApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCotizacionApr]
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCotizacionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCotizacionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionAbr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCotizacionAbr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCotizacionAbr]
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCotizacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCotizacion]
GO
/****** Object:  StoredProcedure [dbo].[paUpCorrResiduos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCorrResiduos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCorrResiduos]
GO
/****** Object:  StoredProcedure [dbo].[paUpConsignaDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConsignaDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConsignaDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpConsigna]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConsigna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConsigna]
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosTrib]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConceptosTrib]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConceptosTrib]
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConceptosPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConceptosPre]
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConceptosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConceptosCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosAdmon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConceptosAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConceptosAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paUpConcDiversos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConcDiversos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConcDiversos]
GO
/****** Object:  StoredProcedure [dbo].[paUpConcDivCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpConcDivCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpConcDivCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpComprobantesAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComprobantesAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComprobantesAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpComprobantes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComprobantes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComprobantes]
GO
/****** Object:  StoredProcedure [dbo].[paUpCompGastos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCompGastos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCompGastos]
GO
/****** Object:  StoredProcedure [dbo].[paUpCompCajaDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCompCajaDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCompCajaDev]
GO
/****** Object:  StoredProcedure [dbo].[paUpCompCaja]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCompCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCompCaja]
GO
/****** Object:  StoredProcedure [dbo].[paUpCompaniasFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCompaniasFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCompaniasFec]
GO
/****** Object:  StoredProcedure [dbo].[paUpCompanias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCompanias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCompanias]
GO
/****** Object:  StoredProcedure [dbo].[paUpComFacturaCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComFacturaCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComFacturaCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpComFacturaApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComFacturaApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComFacturaApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpComFacturaAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComFacturaAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComFacturaAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpComFactura]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComFactura]
GO
/****** Object:  StoredProcedure [dbo].[paUpComDetallePla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComDetallePla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComDetallePla]
GO
/****** Object:  StoredProcedure [dbo].[paUpComDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpComDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpComDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paUpCnxextna]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCnxextna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCnxextna]
GO
/****** Object:  StoredProcedure [dbo].[paUpClieContado]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClieContado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClieContado]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseTar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseTar]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseSub]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseRie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseRie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseRie]
GO
/****** Object:  StoredProcedure [dbo].[paUpClasePol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClasePol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClasePol]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseFon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseFon]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseDocCond]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseDocCond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseDocCond]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseDiv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseDiv]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseCta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseCta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseCta]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseCapac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseCapac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseCapac]
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpClaseBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpClaseBan]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesOdb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesOdb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesOdb]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesNdb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesNdb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesNdb]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesEod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesEod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesEod]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesDDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesDDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesDDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesDap]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesDap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesDap]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesCns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesCns]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesAnuRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesAnuRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesAnuRec]
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesACns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpChequesACns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpChequesACns]
GO
/****** Object:  StoredProcedure [dbo].[paUpCheques]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCheques]
GO
/****** Object:  StoredProcedure [dbo].[paUpCentrosServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCentrosServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCentrosServ]
GO
/****** Object:  StoredProcedure [dbo].[paUpCentroCosto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCentroCosto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCentroCosto]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausaValesAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausaValesAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausaValesAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausaVales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausaVales]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceCero]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacVenceCero]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacVenceCero]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacVenceApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacVenceApl]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceAcp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacVenceAcp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacVenceAcp]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacVenceAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacVenceAbo]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVence]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacVence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacVence]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacionNoInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacionNoInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacionNoInt]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacionCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacionCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacionCmp]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paUpCargos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCargos]
GO
/****** Object:  StoredProcedure [dbo].[paUpCalndario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpCalndario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpCalndario]
GO
/****** Object:  StoredProcedure [dbo].[paUpBusClaseCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpBusClaseCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpBusClaseCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpBodUbic]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpBodUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpBodUbic]
GO
/****** Object:  StoredProcedure [dbo].[paUpBodegas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paUpBancos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpBancos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpBancos]
GO
/****** Object:  StoredProcedure [dbo].[paUpAutorizaDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAutorizaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAutorizaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paUpAutorizaAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAutorizaAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAutorizaAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpAutoriza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paUpAreas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAreas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAreas]
GO
/****** Object:  StoredProcedure [dbo].[paUpAprobacionAnu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAprobacionAnu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAprobacionAnu]
GO
/****** Object:  StoredProcedure [dbo].[paUpAprobacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAprobacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAprobacion]
GO
/****** Object:  StoredProcedure [dbo].[paUpAlmBodegas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAlmBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAlmBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paUpAjuInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAjuInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAjuInv]
GO
/****** Object:  StoredProcedure [dbo].[paUpAgenciasEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAgenciasEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAgenciasEst]
GO
/****** Object:  StoredProcedure [dbo].[paUpAgenciasCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAgenciasCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAgenciasCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpAgencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAgencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAgencias]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfTiposMovCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfTiposMovCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfTiposMovCon]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfTiposMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfTiposMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfTiposMov]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfTiposDif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfTiposDif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfTiposDif]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfMantnmto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfMantnmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfMantnmto]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfLineas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfLineas]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfGruposCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfGruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfGruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfGrupos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfEstados]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfDeprecia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfDeprecia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfDeprecia]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfClasesCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfClasesCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfClasesCue]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfCausales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfCausales]
GO
/****** Object:  StoredProcedure [dbo].[paUpAfAmortiza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAfAmortiza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAfAmortiza]
GO
/****** Object:  StoredProcedure [dbo].[paUpAduanas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAduanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAduanas]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuPropietarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuPropietarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuPropietarios]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuPrestamosSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuPrestamosSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuPrestamosSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuPrestamos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasVehtSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasVehtSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasVehtSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasVehSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasVehSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasVehSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasNitSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasNitSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasNitSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasCcSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasCcSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasCcSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasAuxSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasAuxSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasAuxSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasAgeSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuNiifCuentasAgeSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuNiifCuentasAgeSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInvUbicaSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuInvUbicaSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuInvUbicaSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInvTanquesSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuInvTanquesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuInvTanquesSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInvLotesSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuInvLotesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuInvLotesSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInventarioSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuInventarioSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuInventarioSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasVehtSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasVehtSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasVehtSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasVehSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasVehSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasVehSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasNitSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasNitSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasNitSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasCcSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasCcSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasCcSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasAuxSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasAuxSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasAuxSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasAgeSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuFisCuentasAgeSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuFisCuentasAgeSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasVehtSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasVehtSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasVehtSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasVehSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasVehSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasVehSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasVehSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasVehSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasVehSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasNitSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasNitSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasNitSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasNitSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasNitSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasNitSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasCcSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasCcSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasCcSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasCcSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasCcSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasCcSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAuxSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasAuxSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasAuxSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAuxSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasAuxSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasAuxSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAgeSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasAgeSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasAgeSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAgeSA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCuentasAgeSA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCuentasAgeSA]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuClientesSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuClientesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuClientesSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuClientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuClientes]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCajaSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCajaSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCajaSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCajaOtr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCajaOtr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCajaOtr]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCajaEgr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCajaEgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCajaEgr]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCaja]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuCaja]
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuAportesSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpAcuAportesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpAcuAportesSan]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivosRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivosRet]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosMej]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivosMej]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivosMej]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosDis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivosDis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivosDis]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_PartesMej]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivos_PartesMej]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivos_PartesMej]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_PartesDis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivos_PartesDis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivos_PartesDis]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_Partes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivos_Partes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivos_Partes]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_Anexo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivos_Anexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivos_Anexo]
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paUpActivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paUpActivos]
GO
/****** Object:  StoredProcedure [dbo].[paQryZonasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryZonasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryZonasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryZonas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryZonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryZonas]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosTnit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosTnit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosTnit]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosTdoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosTdoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosTdoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosMor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosMor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosMor]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosLca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosLca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosLca]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosDab]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosDab]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosDab]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosAut]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosAut]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosAut]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientosAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientosAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientos_Crd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientos_Crd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientos_Crd]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencimientos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencimientos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosTsaf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosTsaf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosTsaf]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosTnit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosTnit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosTnit]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosSaNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosSaNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosSaNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosSaf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosSaf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosSaf]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosLrc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosLrc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosLrc]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosDap]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosDap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosDap]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonosAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonosAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonos_Fac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonos_Fac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonos_Fac]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVencAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVencAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasosVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehTraspasosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehTraspasosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasosID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehTraspasosID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehTraspasosID]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehTraspasosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehTraspasosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehTraspasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehTraspasos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehRemPolizasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehRemPolizasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehRemPolizasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehRemolqLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehRemolqLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehRemolqLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehRemolq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehRemolq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehRemolq]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPropietariosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehPropietariosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehPropietariosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPolizasPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehPolizasPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehPolizasPla]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPolizasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehPolizasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehPolizasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPolizas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPartesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehPartesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehPartesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPartes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehPartes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehPartes]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehNumOrden]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehNumOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehNumOrden]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturasVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehLecturasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehLecturasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturasId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehLecturasId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehLecturasId]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehLecturasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehLecturasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehLecturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehLecturas]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosUbi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosUbi]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosSalPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosSalPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosSalPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosSalCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosSalCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosSalCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosPza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosPza]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPpt1]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosPpt1]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosPpt1]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosPpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosPpt]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosPos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosPos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosPol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosPol]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosNum]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosNom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosNom]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosMot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosMot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosMot]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosMayPol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosMayPol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosMayPol]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosMay]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosMay]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosFicha]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosFicha]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosFicha]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosCau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculosCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculosCau]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductorId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehConductorId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehConductorId]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductoresLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehConductoresLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehConductoresLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductorDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehConductorDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehConductorDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehConductor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehConductor]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientesNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehClientesNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehClientesNum]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientesNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehClientesNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehClientesNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehClientesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehClientesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVehClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVehClientes]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_SaldosSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_SaldosSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_SaldosSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_SaldosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_SaldosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_SaldosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_SaldosCla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_SaldosCla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_SaldosCla]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Saldos_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_Saldos_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_Saldos_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Saldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_CuposCte]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_CuposCte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_CuposCte]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Cupos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_Cupos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_Cupos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Cupos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_Cupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_Cupos]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Contrato_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_Contrato_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_Contrato_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Contrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVeh_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVeh_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paQryValesRutas_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryValesRutas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryValesRutas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryValesRutas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryValesRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryValesRutas]
GO
/****** Object:  StoredProcedure [dbo].[paQryValesRad]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryValesRad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryValesRad]
GO
/****** Object:  StoredProcedure [dbo].[paQryVales_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVales_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVales_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryVales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryVales]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsucajaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsucajaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsucajaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsucaja]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsucaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsucaja]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsuariosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsuariosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsuariosGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsuariosGru]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsuariosEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsuariosEst]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsuariosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsuariosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosCnn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsuariosCnn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsuariosCnn]
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUsuarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUsuarios]
GO
/****** Object:  StoredProcedure [dbo].[paQryUOpciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMedLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUndMedLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUndMedLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMedDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUndMedDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUndMedDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMedDse]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUndMedDse]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUndMedDse]
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUndMed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUndMed]
GO
/****** Object:  StoredProcedure [dbo].[paQryUmDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUmDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUmDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryUm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryUm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryUm]
GO
/****** Object:  StoredProcedure [dbo].[paQryTurnos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTurnos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTurnos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTurnLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTurnLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTurnLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTrasladosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTrasladosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTrasladosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTrasladosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTrasladosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTrasladosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTrasladosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTrasladosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTrasladosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTraslados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTalonariosRmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTalonariosRmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTalonariosRmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTalonariosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraTalonariosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraTalonariosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTrasladosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTrasladosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTrasladosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTrasladosOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTrasladosOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTrasladosOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQryTrasladosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTrasladosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTrasladosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraslados_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraslados_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraslados_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraslados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemMciasOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemMciasOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemMciasOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemMcias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemMcias]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaOdp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaOdp]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaMuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaMuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaMuc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaCnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesaCnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesaCnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemesa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemesa]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCntdorFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemCntdorFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemCntdorFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCntdor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemCntdor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemCntdor]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCancelaOst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemCancelaOst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemCancelaOst]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCancelaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemCancelaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemCancelaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemAnexo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraRemAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraRemAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraReexpedidoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraReexpedidoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraReexpedidoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraReexpedidoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraReexpedidoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraReexpedidoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraReexpedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraReexpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraReexpedido]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresItems]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPresItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPresItems]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresAntLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPresAntLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPresAntLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresAntFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPresAntFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPresAntFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPresAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPresAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteIntLtd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPorteIntLtd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPorteIntLtd]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteIntLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPorteIntLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPorteIntLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteIntGas_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPorteIntGas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPorteIntGas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteInt_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPorteInt_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPorteInt_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPorteInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPorteInt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedMciasDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedMciasDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedMciasDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedMcias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedMcias]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedidoRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedidoRem]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedidoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedidoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRelCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedidoRelCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedidoRelCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedidoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedidoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedidoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedidoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedidoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedidoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedido]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedAnexo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraPedAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraPedAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServOpe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServOpe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServOpe]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenPagoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenPagoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenPagoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenPagoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoNet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenPagoNet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenPagoNet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenPagoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenPagoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenPagoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenPagoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPago]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenPago]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenManif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenManif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenManif]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenLiqRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenLiqRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenLiqLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenLiqLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenLiqFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenLiqFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenLiqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenLiqDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenLiq]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCumRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenCumRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenCumRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCumLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenCumLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenCumLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCumFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenCumFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenCumFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenCum]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntTotCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAntTotCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAntTotCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAntRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAntRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAntLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAntLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAntFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAntFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAntAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAntAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAboFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraOrdenAboFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraOrdenAboFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifRem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifRem]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifPrecFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifPrecFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifPrecFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifModLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifModLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifModLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifIntLtd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifIntLtd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifIntLtd]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifIntLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifIntLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifIntLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifIntCon_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifIntCon_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifIntCon_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifInt_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifInt_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifInt_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifInt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoRen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoRen]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRelPrec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoRelPrec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoRelPrec]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoOpe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoOpe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoOpe]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiestoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiestoDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiesto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifiesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifiesto]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifAnexo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraManifAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraManifAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqViajesRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqViajesRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqViajesRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqViajesRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqViajesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqViajesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqViajesFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqViajesFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqViajes]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaRelo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquidaRelo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquidaRelo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquidaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquidaRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaOtrFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquidaOtrFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquidaOtrFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquidaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquidaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquidaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquidaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaDedFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquidaDedFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquidaDedFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqManifFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqManifFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqManifFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqDetalleFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraLiqDetalleFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraLiqDetalleFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraInfViajesFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraInfViajesFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraInfViajesFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraInfViajes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraInfViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraInfViajes]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuiasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraGuiasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraGuiasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuiasFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraGuiasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraGuiasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuiasFco]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraGuiasFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraGuiasFco]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraGuias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraGuias]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraFijosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraFijosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraFijosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraFijos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraFacRemesasItem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraFacRemesasItem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraFacRemesasItem]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReexLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevReexLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevReexLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReexFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevReexFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevReexFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReexDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevReexDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevReexDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReex]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevReex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevReex]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevOdpRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevOdpRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevOdpLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevOdpLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevOdpFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevOdpFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevOdpDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevOdpDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevOdp]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLiqRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLiqRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLiqLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLiqLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLiqFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLiqFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLiqDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLiqDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLiq]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLgoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLgoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLgoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLgoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLgoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLgoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLgoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLgoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLgo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLgo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLegRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLegRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLegRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLegRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLegLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLegLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLegFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLegFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLegDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLegDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLeg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevLeg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevLeg]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCumFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCumFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCumFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCum]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCosDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCauRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCauRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCauLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCauLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCauFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCauFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCauDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCauDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevCau]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAntRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAntRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAntLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAntLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAntFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAntFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAntDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAntDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDevAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDevAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachosLtap]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDespachosLtap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDespachosLtap]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDespachosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDespachosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDespachosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDespachosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduanaLtd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDecAduanaLtd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDecAduanaLtd]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduanaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDecAduanaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDecAduanaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduana_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDecAduana_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDecAduana_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduana]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraDecAduana]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraDecAduana]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumRadicaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumRadicaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumRadicaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumRadicaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumRadicaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumRadicaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumRadica]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumRadica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumRadica]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumplidoRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumplidoRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumplidoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumplidoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumplidoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumplidoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumplidoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumplidoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCumplido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCumplido]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConceptosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConceptosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosItem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConceptosItem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConceptosItem]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConceptosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConceptosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConceptosFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConceptosFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConcCausacDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConcCausacDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConcCausacDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConcCausac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraConcCausac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraConcCausac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacionRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCausacionRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCausacionRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacionLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCausacionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCausacionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacionFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCausacionFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCausacionFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposTotCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticiposTotCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticiposTotCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposRelAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticiposRelAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticiposRelAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticiposRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticiposRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticiposMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticiposMov]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticiposLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticiposLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticiposFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticiposFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAntAbonosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAntAbonosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAntAbonosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAntAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTraAntAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTraAntAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTpapers]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTpapers]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTpapers]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_VentasRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_VentasRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_VentasRes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_VentasDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_VentasDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_VentasDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_VentasCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_VentasCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_VentasCom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vence_Ed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_vence_Ed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_vence_Ed]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vence]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_vence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_vence]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vceLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_vceLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_vceLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_vce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_vce]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ValesCred]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ValesCred]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ValesCred]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraRemFactMvo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraRemFactMvo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraRemFactMvo]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraRemFactLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraRemFactLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraRemFactLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraRemFact]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraRemFact]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraRemFact]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraMovLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraMovLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraMovLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraMovAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraMovAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraMovAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetConcLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetConcLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetConcLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetConc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetConc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetConc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetalleTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetalleTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleRmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetalleRmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetalleRmt]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleOct]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetalleOct]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetalleOct]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleMuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetalleMuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetalleMuc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetalleLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetalleLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_TraDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_TraDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Tanqueos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Tanqueos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Tanqueos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerTotU]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_SerTotU]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_SerTotU]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_SerTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_SerTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_SerPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_SerPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_SerId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_SerId]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Ser]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Ser]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Ser]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SaldosTer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_SaldosTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_SaldosTer]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SaldosCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_SaldosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_SaldosCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Saldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ResMensualInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ResMensualInv]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualCueN]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ResMensualCueN]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ResMensualCueN]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ResMensualCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ResMensualCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ResMensualCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ResMensualCli]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalleTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ReqDetalleTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ReqDetalleTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalleItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ReqDetalleItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ReqDetalleItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalleDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ReqDetalleDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ReqDetalleDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ReqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ReqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaRec]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaGru]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaGap]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaGap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaGap]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaCr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaCr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplicaCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplicaCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplica]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_RecAplica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_RecAplica]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreMovi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreMovi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreMovi]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreIntMoraLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreIntMoraLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreIntMoraLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreExtoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreExtoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreExtoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreCuotasSim]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreCuotasSim]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreCuotasSim]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreCuotasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreCuotasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreCuotasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreCartera]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreCartera]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreCartera]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PreAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PreAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PlasueldosKey]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PlasueldosKey]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PlasueldosKey]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Plasueldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Plasueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Plasueldos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosTEfe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosTEfe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosTEfe]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosFor]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosChe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_PagosChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_PagosChe]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Pagos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Pagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Pagos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_OccCompExi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_OccCompExi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_OccCompExi]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_OccComp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_OccComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_OccComp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NomResCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NomResCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NomResCon]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NomRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NomRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NomRes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaVint]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaVint]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaVint]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaVac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaVac]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaTPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaTPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaTPen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaTCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaTCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaTCon]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaSBas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaSBas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaSBas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaRet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaPre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaNov]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaLpre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaLpre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaLpre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaLInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaLInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaLInt]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaId]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaGCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaGCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaGCon]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaEitm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaEitm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaEitm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaEdv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaEdv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaEdv]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDsl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaDsl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaDsl]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDsa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaDsa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaDsa]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaDia]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCpre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaCpre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaCpre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaCon]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaCip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaCip]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaCau]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaBas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NominaBas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NominaBas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Nomina_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Nomina_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Nomina_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Nomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NomHoras]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NomHoras]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NomHoras]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifMov]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifLibOfi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifLibOfi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifLibOfi]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifLibDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifLibDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifLibDia]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifGyp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifGyp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifGyp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifGen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifGen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifGen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifComIB]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifComIB]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifComIB]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_NiifCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_NiifCom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovVentasAes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovVentasAes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovVentasAes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovVentas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovVentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovVentas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovTanquesRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovTanquesRes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovTanquesPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovTanquesPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesFis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovTanquesFis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovTanquesFis]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovTanquesDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovTanquesDia]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovInvent]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovInvent]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCueGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovCueGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovCueGru]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCueDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovCueDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovCueDia]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCueCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovCueCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovCueCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovClientesCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovClientesCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovClientesCli]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovClientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_MovClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_MovClientes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotTotU]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LotTotU]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LotTotU]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LotTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LotTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Lotr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Lotr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Lotr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LotLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LotLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotIng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LotIng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LotIng]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LotID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LotID]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LotGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LotGru]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Lot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Lot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Lot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ListaPrec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ListaPrec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ListaPrec]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaPre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaPar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaPar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaPar]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaLpre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaLpre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaLpre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaId]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaDed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaDed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaDed]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LiquidaCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LiquidaCon]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Liquida_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Liquida_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Liquida_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Liquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Liquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Liquida]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LibOfSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LibOfSan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfGcue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LibOfGcue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LibOfGcue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LibOfDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LibOfDia]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfcue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LibOfcue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LibOfcue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_LibOf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_LibOf]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexVcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexVcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexVcr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTVcc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTVcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTVcc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTUbi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTUbi]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTTan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTTan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTpro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTpro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTpro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotSob]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotSob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotSob]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotSal]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPun]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotPun]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotPun]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPlaV]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotPlaV]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotPlaV]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPlaC]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotPlaC]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotPlaC]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotPla]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTotFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTotFac]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTBod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTBod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTBod]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTBas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTBas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTBas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTar]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTanq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTanq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTanq]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTAju]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexTAju]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexTAju]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSubOpe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexSubOpe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexSubOpe]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSubc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexSubc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexSubc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexSub]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexSer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexSer]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexSal]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSai]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexSai]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexSai]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPrv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPrv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPrv]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPnp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPnp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPnp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPla]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPed]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPdc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPdc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPdc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexPas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexPas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexParc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexParc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexParc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexOdc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexOdc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexOdc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexOcc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexOcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexOcc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexNum]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNtsal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexNtsal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexNtsal]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNts]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexNts]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexNts]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNpr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexNpr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexNpr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexMng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexMng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexMng]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexLot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexLot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexLot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexItn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexItn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexItn]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexIns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexIns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexIns]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexIen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexIen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexIen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexID]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGui]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexGui]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexGui]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGtan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexGtan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexGtan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGpro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexGpro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexGpro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGord]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexGord]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexGord]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGBod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexGBod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexGBod]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexFcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexFcr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexFco]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexFco]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDvs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDvs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDvs]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDvf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDvf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDvf]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDve]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDve]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDve]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDfo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDfo]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDetC]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDetC]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDetC]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDcom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexDcom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexDcom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexCom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexCc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexBga]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexBga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexBga]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexAju]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KdexAju]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KdexAju]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Kdex]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Kdex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Kdex]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KarUbiTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KarUbiTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KarUbiSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KarUbiSal]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KarUbiPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KarUbiPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KarUbiID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KarUbiID]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_KarUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_KarUbi]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntNominaVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_IntNominaVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_IntNominaVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntNomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_IntNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_IntNomina]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntAhorroVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_IntAhorroVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_IntAhorroVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntAhorroLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_IntAhorroLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_IntAhorroLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntAhorro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_IntAhorro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_IntAhorro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Ingresos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Ingresos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Ingresos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_InfDiarioFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_InfDiarioFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_InfDiarioFor]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_InfDiarioDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_InfDiarioDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_InfDiarioDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_GypVentas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_GypVentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_GypVentas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItemsTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ForItemsTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ForItemsTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItemsItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ForItemsItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ForItemsItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItemsDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ForItemsDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ForItemsDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItems]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ForItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ForItems]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_FactNetoDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_FactNetoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_FactNetoDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_FactNeto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_FactNeto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_FactNeto]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVehVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ExtVehVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ExtVehVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVehSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ExtVehSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ExtVehSan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVehCr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ExtVehCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ExtVehCr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ExtVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ExtVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVrecEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EVrecEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EVrecEst]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVrec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EVrec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EVrec]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVcauVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EVcauVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EVcauVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVcau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EVcau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EVcau]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCteVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstCueCteVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstCueCteVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCtePro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstCueCtePro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstCueCtePro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCte_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstCueCte_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstCueCte_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCte]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstCueCte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstCueCte]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstClientesMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstClientesMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstClientesMov]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstClientes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstClientes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypTer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstadoGypTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstadoGypTer]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypTC]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstadoGypTC]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstadoGypTC]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypGcue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstadoGypGcue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstadoGypGcue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstadoGypCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstadoGypCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGyp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EstadoGyp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EstadoGyp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasTip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasTip]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasRan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasRan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasRan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasFma]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasFma]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasFma]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasFac]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasEfe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasEfe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasEfe]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasDsc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasDsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasDsc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasCre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasCre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCpla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasCpla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasCpla]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasChe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormasChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormasChe]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_EdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_EdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Dotacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Dotacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Dotacion]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DifIngresoDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DifIngresoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DifIngresoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DifIngreso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DifIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DifIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Diario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Diario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Diario]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueVce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DetCueVce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DetCueVce]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DetCueTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DetCueTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DetCueItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DetCueItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DetCueFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DetCueFac]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DetCueDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DetCueDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_DetCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_DetCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxpAplicaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxpAplicaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxpAplicaID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxpAplicaID]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaG]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxpAplicaG]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxpAplicaG]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxpAplicaFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxpAplicaFac]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplica]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxpAplica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxpAplica]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxPagarTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxPagarTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxPagarNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxPagarNit]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxPagarID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxPagarID]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpagarGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxpagarGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxpagarGru]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxPagarDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxPagarDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxPagar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxPagar]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxCobrarTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxCobrarTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxCobrarTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxCobrarId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxCobrarId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxCobrarId]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxCobrar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxCobrar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxCobrar]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonosTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonosTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosTip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonosTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonosTip]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonosItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonosItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosG]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonosG]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonosG]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CxcAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CxcAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CuotasCr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CuotasCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CuotasCr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cuotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Cuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Cuotas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Contratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Contratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Contratos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompVen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompVen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompVce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompVce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompVce]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompID]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompID]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompFac]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompDsc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompDsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompDsc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CompCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CompCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Compau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Compau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Compau]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Comp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Comp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Comp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComisionesDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ComisionesDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ComisionesDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Comisiones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Comisiones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Comisiones]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ComboTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ComboTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ComboPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ComboPla]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboLin]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ComboLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ComboLin]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ComboItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ComboItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Combo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Combo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Combo]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_cheqTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_cheqTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqNum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_cheqNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_cheqNum]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_cheqItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_cheqItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_cheqDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_cheqDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_cheq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_cheq]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ccCupones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_ccCupones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_ccCupones]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cartera]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Cartera]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Cartera]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CargosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CargosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosVce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CargosVce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CargosVce]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CargosPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CargosPre]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CargosGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CargosGru]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosCmpp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CargosCmpp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CargosCmpp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CargosCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CargosCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cargos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Cargos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Cargos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cargos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Cargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Cargos]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CajaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CajaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CajaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CajaFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CajaFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CajaFor]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CajaDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_CajaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_CajaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalPsptoCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalPsptoCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalPsptoCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalPspto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalPspto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalPspto]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalGenGcue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalGenGcue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalGenGcue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalGenCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalGenCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalGenCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalGen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalGen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalGen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComSan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComSan]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComparaTer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComparaTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComparaTer]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComparaGCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComparaGCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComparaGCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComparaCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComparaCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComparaCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalCompara]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalCompara]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalCompara]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComNiif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComNiif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComNiif]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComBases]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComBases]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComBases]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComAux]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalComAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalComAux]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalCom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalAcumGCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalAcumGCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalAcumGCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalAcum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_BalAcum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_BalAcum]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvVen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AuxInvVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AuxInvVen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvUbic]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AuxInvUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AuxInvUbic]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AuxInvPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AuxInvPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvCpm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AuxInvCpm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AuxInvCpm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AuxInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AuxInv]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotPag]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AutTotPag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AutTotPag]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AutTotItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AutTotItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotFon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AutTotFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AutTotFon]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AutTotDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AutTotDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AutTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AutTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesTSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesTSal]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTrie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesTrie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesTrie]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTpen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesTpen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesTpen]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesTot]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesTCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesTCom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesItm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesDsn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesDsn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesDsn]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesCom]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesCed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesCed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesCed]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesAtz]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesAtz]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesAtz]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesAfi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesAfi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesAfi]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesAdm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AportesAdm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AportesAdm]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Aportes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_Aportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_Aportes]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfTrasladoDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfTrasladoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfTrasladoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfTrasladoDif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfTrasladoDif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfTrasladoDif]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfTraslado]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfRetiroDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfRetiroDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfRetiroDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfRetiroDif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfRetiroDif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfRetiroDif]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfRetiro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfIngresoDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfIngresoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfIngresoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfIngreso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfDepPartesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfDepPartesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfDepPartesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfDepLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfDepLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfDepLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfDep]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfDep]
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfAmtLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytm_AfAmtLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytm_AfAmtLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposZona]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposZona]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposZona]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposVehDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposVehDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposVehDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposTerc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposTerc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposTerc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposTasas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposTasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposTasas]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposSustentoDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposSustentoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposSustentoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposSustento]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposSustento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposSustento]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposRespFis]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposRespFis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposRespFis]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposProceso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposProceso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposProceso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposPrend]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposPrend]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposPrend]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposPpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposPpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposPpt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposPcnto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposPcnto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposPcnto]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposOperarios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposOperarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposOperarios]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposOperac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposOperac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposOperac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNovTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposNovTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposNovTra]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposNom]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNivs]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposNivs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposNivs]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposNat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposNat]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMotdevDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMotdevDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMotdevDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMotdev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMotdev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMotdev]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMot]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMod]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMnjo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMnjo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMnjo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMcia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposMat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposMat]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposLub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposLub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposLub]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposLla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposLla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposLla]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposInm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposInm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposInm]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposFuel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposFuel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposFuel]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposFil]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposFil]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposFil]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposEsc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposEsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposEsc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocPag]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocPag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocPag]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocKar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocKar]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocInv]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocFor]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCueDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocCueDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocCueDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocConsLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocConsLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocConsLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCons]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocCons]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocAut]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocAut]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocAut]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDocAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDocAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCotDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCotDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCotDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCot]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComNiif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComNiif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComNiif]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComFmtDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComFmtDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComFmtDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComDsa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComDsa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComDsa]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComConsLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComConsLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComConsLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComCons]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComCons]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComAgencLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComAgencLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComAgencLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposComAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposComAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCom]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCol]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCnd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCnd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCnd]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCarga]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCarga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCarga]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposCar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposCar]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposBloq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposBloq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposBloq]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposBan]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposAdm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTiposAdm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTiposAdm]
GO
/****** Object:  StoredProcedure [dbo].[paQryTFmtosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTFmtosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTFmtosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTFmtos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTFmtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTFmtos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTerminales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTerminales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTerminales]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercVendedorReg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercVendedorReg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercVendedorReg]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercVendedorLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercVendedorLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercVendedorLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercVendedor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercVendedor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercVendedor]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercSedesDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercSedesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercSedesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercProveeLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercProveeLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercProveeLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercProvee]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercProvee]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietarioReg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercPropietarioReg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercPropietarioReg]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietarioLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercPropietarioLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercPropietarioLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietario_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercPropietario_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercPropietario_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercPropietario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercPropietario]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosUbi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosUbi]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosReg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosReg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosReg]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosDsoT]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosDsoT]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosDsoT]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosCta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosCta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosCta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosCod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosCod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosCod]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosBus]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercerosBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercerosBus]
GO
/****** Object:  StoredProcedure [dbo].[paQryTerceros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTerceros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTerceros]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndtoresLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndtoresLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndtoresLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndtoresLic]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndtoresLic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndtoresLic]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndtores]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndtores]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndtores]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndTarjetasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndTarjetasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndTarjetasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndTarjetasItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndTarjetasItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndTarjetasItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndTarjetas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndReferenciasVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndReferenciasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndReferenciasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndReferencias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndReferencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndReferencias]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndDocLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndDocLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndDocLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndContrato_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndContrato_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndContrato_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndContrato]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndContrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndContrato]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndCapacLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCndCapacLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCndCapacLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieVehPla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieVehPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieVehPla]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieVehLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieVehLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieVehLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieSaldosSum]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieSaldosSum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieSaldosSum]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieSaldos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieSaldos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieSaldos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRefLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieRefLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieRefLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRefItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieRefItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieRefItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRef_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieRef_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieRef_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRef]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieRef]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCliePrestamoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCliePrestamoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCliePrestamoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCliePrestamo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCliePrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCliePrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClienteLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClienteLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClienteLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCliente]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercCliente]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercCliente]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieLineasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieLineasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieLineasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieLineas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieLineas]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieGarantLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieGarantLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieGarantLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieGarant]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieGarant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieGarant]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieCuposLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieCuposLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieCuposLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieCia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTercClieCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTercClieCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxTarifClie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTaxTarifClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTaxTarifClie]
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxTarifas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTaxTarifas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTaxTarifas]
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxRutasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTaxRutasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTaxRutasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxRutas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTaxRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTaxRutas]
GO
/****** Object:  StoredProcedure [dbo].[paQrytasasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytasasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytasasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTasasIntmoraDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTasasIntmoraDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTasasIntmoraDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTasasInteresDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTasasInteresDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTasasInteresDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTasasInteres]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTasasInteres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTasasInteres]
GO
/****** Object:  StoredProcedure [dbo].[paQrytasasDiv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytasasDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytasasDiv]
GO
/****** Object:  StoredProcedure [dbo].[paQrytasas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrytasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrytasas]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifBuses]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasServLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasServLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasServLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasServ]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasPaqLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasPaqLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasPaqLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasMasivoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasMasivoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasMasivoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFletesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasFletesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasFletesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFletes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasFletes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasFletes]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFleMayLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasFleMayLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasFleMayLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFleMay]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifasFleMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifasFleMay]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifAnticiposLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifAnticiposLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifAnticiposLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifAnticipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTarifAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTarifAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanquesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanquesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanquesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanquesDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanquesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanquesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanques]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanques]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldosTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqSaldosTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqSaldosTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldosTan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqSaldosTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqSaldosTan]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldosSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqSaldosSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqSaldosSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqSaldos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqSaldos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqDispensPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqDispensPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensMan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqDispensMan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqDispensMan]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqDispensLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqDispensLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqDispensDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqDispensDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispens]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqDispens]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqDispens]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqAforoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqAforoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoLms]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqAforoLms]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqAforoLms]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoLmi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqAforoLmi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqAforoLmi]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoFracLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqAforoFracLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqAforoFracLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoFrac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqAforoFrac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqAforoFrac]
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTanqAforo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTanqAforo]
GO
/****** Object:  StoredProcedure [dbo].[paQryTalleresLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTalleresLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTalleresLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTalleres]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTalleres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTalleres]
GO
/****** Object:  StoredProcedure [dbo].[paQryTallasMovPed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTallasMovPed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTallasMovPed]
GO
/****** Object:  StoredProcedure [dbo].[paQryTallasMovDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTallasMovDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTallasMovDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryTallajesMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTallajesMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTallajesMov]
GO
/****** Object:  StoredProcedure [dbo].[paQryTallajesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTallajesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTallajesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporTar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTablaporTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTablaporTar]
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTablaporLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTablaporLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTablaporDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTablaporDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporCiu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTablaporCiu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTablaporCiu]
GO
/****** Object:  StoredProcedure [dbo].[paQryTablapor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryTablapor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryTablapor]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubzonasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubzonasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubzonasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubzonasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubzonasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubzonasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubzonas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubzonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubzonas]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposTas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGruposTas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGruposTas]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGruposLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGruposLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposLin]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGruposLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGruposLin]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGruposDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGruposDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubgruposCuePuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubgruposCuePuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubgruposCuePuc]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubgruposCueLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubgruposCueLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubgruposCueLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubgruposCue]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubgruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubgruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposAgencLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGruposAgencLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGruposAgencLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposAgenc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGrupos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubCentrosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubCentrosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubCentrosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubCentrosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubCentrosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubCentrosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrySubCentros]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySubCentros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySubCentros]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDecLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobTiposDecLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobTiposDecLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDecGas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobTiposDecGas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobTiposDecGas]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDecDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobTiposDecDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobTiposDecDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobTiposDec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobTiposDec]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasMes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasasMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasasMes]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasasEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasasEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasEgr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasasEgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasasEgr]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasasDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasasDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasas_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasas_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasas_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasas_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobretasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobretasas]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobProductosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobProductosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductosId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobProductosId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobProductosId]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductosExi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobProductosExi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobProductosExi]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobProductos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobProductos]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobGasOxigenLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobGasOxigenLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobGasOxigenLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidadesMun]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobEntidadesMun]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobEntidadesMun]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidadesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobEntidadesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobEntidadesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidadesDep]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobEntidadesDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobEntidadesDep]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paQrySobDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySobDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySobDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMovRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMovRel]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMovPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMovPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMovLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMovLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMovDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMovDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovDel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMovDel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMovDel]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMov_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMov_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMov_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerMov]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerialesPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerialesPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerialesPro]
GO
/****** Object:  StoredProcedure [dbo].[paQrySerialesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySerialesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySerialesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySeriales_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySeriales_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySeriales_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrySeriales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySeriales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySeriales]
GO
/****** Object:  StoredProcedure [dbo].[paQrySecurity]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySecurity]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySecurity]
GO
/****** Object:  StoredProcedure [dbo].[paQrySectoresEcoDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySectoresEcoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySectoresEcoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrySectoresEco]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySectoresEco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySectoresEco]
GO
/****** Object:  StoredProcedure [dbo].[paQrySAutorizaDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySAutorizaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySAutorizaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrySAutoriza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasReq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasReq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasReq]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasRel]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasNetDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasNetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasNetDet]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasNet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasNet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasNet]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasAdi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidasAdi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidasAdi]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidas_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySalidas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySalidas]
GO
/****** Object:  StoredProcedure [dbo].[paQrySaiArticulos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrySaiArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrySaiArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasTramosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasTramosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasTramosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasTramos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasTramos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasTramos]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasTra]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasPlanLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasPlanLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasPlanLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasPlanItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasPlanItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasPlanItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasPlan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasPlan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasPlan]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasCiu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasCiu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasCiu]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasBus]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutasBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutasBus]
GO
/****** Object:  StoredProcedure [dbo].[paQryRutas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRutas]
GO
/****** Object:  StoredProcedure [dbo].[paQryRoles]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRoles]
GO
/****** Object:  StoredProcedure [dbo].[paQryResiduosPeligrososLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryResiduosPeligrososLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryResiduosPeligrososLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryResiduosPeligrosos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryResiduosPeligrosos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryResiduosPeligrosos]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionMtto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionMtto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionMtto]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionLtm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionLtm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionLtm]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicionDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicionDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicion_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRequisicion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRequisicion]
GO
/****** Object:  StoredProcedure [dbo].[paQryReqDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportSubPmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportSubPmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportSubPmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportSubLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportSubLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportSubLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportGru]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportFmtoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportFmtoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportFmtoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportFmto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportFmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportFmto]
GO
/****** Object:  StoredProcedure [dbo].[paQryReportDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReportDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReportDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryReport]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryReport]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryReport]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemisionRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemisionRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionPed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemisionPed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemisionPed]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemisionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemisionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionFact]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemisionFact]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemisionFact]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemisionFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemisionFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemisionDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemisionDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemision_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemision_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemision_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRemision]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRemision]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRemision]
GO
/****** Object:  StoredProcedure [dbo].[paQryRelacionesFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRelacionesFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRelacionesFor]
GO
/****** Object:  StoredProcedure [dbo].[paQryRelacionesEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRelacionesEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRelacionesEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryRelaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRelaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRelaciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryRegistro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRegistro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRegistro]
GO
/****** Object:  StoredProcedure [dbo].[paQryRegimenDian]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRegimenDian]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRegimenDian]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecTanqueos_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecTanqueos_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecTanqueos_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecTanqueos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecTanqueos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecTanqueos]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecibosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecibosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecibosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecibosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecibosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecibosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecibosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecibosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecibos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecibos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaTpa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaTpa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaTpa]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaRec]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaDocA]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaDocA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaDocA]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaCla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaCla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaCla]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaApl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFacturaApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFacturaApl]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura_Cra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFactura_Cra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFactura_Cra]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFactura_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFactura_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura_Ant]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFactura_Ant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFactura_Ant]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecFactura]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecChequesRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecChequesRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecChequesPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecChequesPre]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecChequesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecChequesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesBus]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecChequesBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecChequesBus]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecCheques_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecCheques_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecCheques_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecCheques]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecCheques]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesVFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesVFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesVFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesVc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesVc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesVc]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesUlt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesUlt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesUlt]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesNMes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesNMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesNMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesNetIca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesNetIca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesNetIca]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesLiq]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesIca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesIca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesIca]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesAntVce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesAntVce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesAntVce]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesAnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBusesAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBusesAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBuses_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBuses_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses_Crl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBuses_Crl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBuses_Crl]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBuses_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBuses_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecAfavorTNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecAfavorTNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecAfavorTNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecAfavorSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecAfavorSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecAfavorSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryRecAfavor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRecAfavor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRecAfavor]
GO
/****** Object:  StoredProcedure [dbo].[paQryRangosPeso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRangosPeso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRangosPeso]
GO
/****** Object:  StoredProcedure [dbo].[paQryRadicaValesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRadicaValesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRadicaValesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryRadicaVales_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRadicaVales_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRadicaVales_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryRadicaVales]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryRadicaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryRadicaVales]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetasNit]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntTarjetasNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntTarjetasNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntTarjetasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntTarjetasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetasCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntTarjetasCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntTarjetasCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProgLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntProgLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntProgLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProgItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntProgItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntProgItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProgFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntProgFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntProgFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProg_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntProg_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntProg_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntProg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntProg]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntPremiosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntPremiosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntPremiosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntPremiosItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntPremiosItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntPremiosItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntPremios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntPremios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntPremios]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntosPrg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntosPrg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntosPrg]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntos]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntFormasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntFormasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntFormasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntFormas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntFormas]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntBasesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntBasesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntBasesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntBasesDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntBasesDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntBasesDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntBases]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuntBases]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuntBases]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestosTag]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuestosTag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuestosTag]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuestosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuestosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuestosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuestosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuestos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuestos]
GO
/****** Object:  StoredProcedure [dbo].[paQryPucSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPucSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPucSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryPucNiifAju]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPucNiifAju]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPucNiifAju]
GO
/****** Object:  StoredProcedure [dbo].[paQryPucNiif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPucNiif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPucNiif]
GO
/****** Object:  StoredProcedure [dbo].[paQryPucLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPucLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPucLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPucAju]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPucAju]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPucAju]
GO
/****** Object:  StoredProcedure [dbo].[paQryPuc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPuc]
GO
/****** Object:  StoredProcedure [dbo].[paQryProfesiones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProfesiones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProfesiones]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarfLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdTarfLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdTarfLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarfItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdTarfItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdTarfItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarfFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdTarfFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdTarfFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdTarf]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldoUbcTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldoUbcTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldoUbcTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldoUbc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldoUbc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldoUbc]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldosTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldosTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosP]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldosP]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldosP]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldosInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldosInv]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProveeLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdProveeLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdProveeLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProvee_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdProvee_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdProvee_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProvee]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdProvee]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProcesosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdProcesosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdProcesosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPreciosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPreciosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPreciosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPreciosCia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPreciosCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPreciosCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecios_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPrecios_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPrecios_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPrecios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPrecios]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecCrudoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPrecCrudoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPrecCrudoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecComLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPrecComLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPrecComLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPrecCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPrecCom]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPedidoInsuFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdPedidoInsuFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdPedidoInsuFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenTallasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrdenTallasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrdenTallasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenTallasFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrdenTallasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrdenTallasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenSalFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrdenSalFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrdenSalFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenLtp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrdenLtp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrdenLtp]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrdenLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrdenLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenEntFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrdenEntFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrdenEntFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrden_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrden_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrden_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrden]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdOrden]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasVal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasVal]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasShr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasShr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasShr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasRef]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasRef]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasPre]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasLpre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasLpre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasLpre]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasLkar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasLkar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasLkar]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasDes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasDes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasDes]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasCol]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasCol]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasCod]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasCod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasCod]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasCat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMciasCat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMciasCat]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMcias_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMcias_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMcias_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMcias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdMcias]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdInsumosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdInsumosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdInsumosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosUlt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImptosUlt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImptosUlt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImptosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImptosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImptosItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImptosItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImptosFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImptosFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImptos]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImpFronUlt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImpFronUlt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImpFronUlt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImpFronLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImpFronLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImpFronLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImpFron]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdImpFron]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdImpFron]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaTallasFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntregaTallasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntregaTallasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntregaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntregaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaInsuFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntregaInsuFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntregaInsuFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaDtlFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntregaDtlFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntregaDtlFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaDev_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntregaDev_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntregaDev_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntrega_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntrega_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntrega_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntrega]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdEntrega]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdEntrega]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCostosCia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdCostosCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdCostosCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCostos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdCostos]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsTallasFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsTallasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsTallasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsProcFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsProcFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsProcFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsPedFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsPedFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsPedFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsolida_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsolida_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsolida_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsolida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsolida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsolida]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsInsuLpt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsInsuLpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsInsuLpt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsInsuFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdConsInsuFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdConsInsuFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdComboPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdComboPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdComboLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdComboLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdComboItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdComboItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdComboFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdComboFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCombo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdCombo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdCombo]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCodigos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdCodigos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdCodigos]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdAditivosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdAditivosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdAditivosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryProdAditivos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryProdAditivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryProdAditivos]
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuestoPer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPresupuestoPer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPresupuestoPer]
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuestoMes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPresupuestoMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPresupuestoMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuesto_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPresupuesto_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPresupuesto_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuesto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPresupuesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPresupuesto]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamosTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamosTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamosPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamosPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosDft]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamosDft]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamosDft]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosCau]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamosCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamosCau]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamos_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamos_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamos_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCuotasTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCuotasTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCuotasTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCuotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionVct]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacionVct]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacionVct]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionVce]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacionVce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacionVce]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionCuo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacionCuo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacionCuo]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionAcp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacionAcp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacionAcp]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacion_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacion_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacion_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacion_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPreCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPreCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryPos40_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPos40_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPos40_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPolizasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPolizasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPolizasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPolizas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paQryPlazosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPlazosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPlazosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryPlazos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPlazos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPlazos]
GO
/****** Object:  StoredProcedure [dbo].[paQryPlantillasConcLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPlantillasConcLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPlantillasConcLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPicoPlaca]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPicoPlaca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPicoPlaca]
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisosRoles_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPermisosRoles_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPermisosRoles_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisosRoles]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPermisosRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPermisosRoles]
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPermisosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPermisosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPermisos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPermisos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPermisos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPermisos]
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesTarfLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPeajesTarfLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPeajesTarfLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesTarf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPeajesTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPeajesTarf]
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesClase]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPeajesClase]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPeajesClase]
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesCatDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPeajesCatDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPeajesCatDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesCat]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPeajesCat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPeajesCat]
GO
/****** Object:  StoredProcedure [dbo].[paQryPaisesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPaisesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPaisesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPaisesIso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPaisesIso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPaisesIso]
GO
/****** Object:  StoredProcedure [dbo].[paQryPaises]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPaises]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPaises]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosFor]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosFor]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosFdvc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosFdvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosFdvc]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosDsd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosDsd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosDsd]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosCns]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosCns]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosChe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosChe]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagosAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagosAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_LtaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagos_LtaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagos_LtaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_Lta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagos_Lta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagos_Lta]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_Bus]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagos_Bus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagos_Bus]
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryPagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryPagos]
GO
/****** Object:  StoredProcedure [dbo].[paQryOrgTransitoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOrgTransitoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOrgTransitoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryOrgTransito]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOrgTransito]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOrgTransito]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRmsn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoRmsn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoRmsn]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRms]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoRms]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoRms]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRem]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoRem]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoOpp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoOpp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoOpp]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoOcc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoOcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoOcc]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoDetFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoDetFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoDetFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoAct]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedidoAct]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedidoAct]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedido_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedido_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedido_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedido]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpedido]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpcionesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpcionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpcionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryOpciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilTrasladoRubrosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilTrasladoRubrosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilTrasladoRubrosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilTrasladoFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilTrasladoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilTrasladoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilTraslado]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilNotasFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilNotasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilNotasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilNotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilNotas]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilMedicionesFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilMedicionesFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilMedicionesFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilMediciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilMediciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilMediciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInventFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilInventFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilInventFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInventDevFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilInventDevFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilInventDevFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInventDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilInventDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilInventDev]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInvent]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilInvent]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilGuiaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilGuiaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilGuiaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilGuia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilGuia]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilFacturasLtd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilFacturasLtd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilFacturasLtd]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilEntradaFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilEntradaFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilEntradaFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilEntrada]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilEntrada]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilEntrada]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevFcrLtd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDevFcrLtd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDevFcrLtd]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCostosFmv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDevCostosFmv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDevCostosFmv]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCostosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDevCostosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDevCostosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCostos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDevCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDevCostos]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCompraFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDevCompraFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDevCompraFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCompra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDevCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDevCompra]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDespClieFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDespClieFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDespClieFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDespClie]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilDespClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilDespClie]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostoVenFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCostoVenFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCostoVenFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostoVen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCostoVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCostoVen]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostosFmv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCostosFmv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCostosFmv]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostosFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCostosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCostosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCostos]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCompraFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCompraFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCompraFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCompraDespFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCompraDespFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCompraDespFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCompra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilCompra]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilAjustesFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilAjustesFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilAjustesFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOilAjustes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOilAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOilAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paQryOcupaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOcupaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOcupaciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompraRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompraRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompraPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompraPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompraLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompraLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompraEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompraEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompraDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompraDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompra_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompra_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompra_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCompra]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombGuia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombGuia]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombGui]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombGui]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombGui]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombFact]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombFact]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombFact]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOCombDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOCombDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryOComb_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOComb_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOComb_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryOComb]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryOComb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryOComb]
GO
/****** Object:  StoredProcedure [dbo].[paQryObjetosAppSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryObjetosAppSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryObjetosAppSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryObjetosAppLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryObjetosAppLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryObjetosAppLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryObjetosApp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryObjetosApp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryObjetosApp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNovedadTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNovedadTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNovedadTra]
GO
/****** Object:  StoredProcedure [dbo].[paQryNovedadRep]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNovedadRep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNovedadRep]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasTotCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasTotCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasTotCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasDocumentoSOP40_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasDocumentoSOP40_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasDocumentoSOP40_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesVFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesVFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesVFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesVc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesVc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesVc]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesTotCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesTotCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesTotCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesNMes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesNMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesNMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesDb_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesDb_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesDb_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesCR_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesCR_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesCR_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesCaj]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBusesCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBusesCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBuses_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBuses_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBuses_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBuses]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasBuses]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotasAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotasAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotas_DocElectronicos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotas_DocElectronicos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotas_DocElectronicos]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotas_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotas]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProdRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotaProdRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotaProdRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProdOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotaProdOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotaProdOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProdLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotaProdLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotaProdLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProd_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotaProd_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotaProd_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNotaProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNotaProd]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomZonasConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomZonasConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomZonasConv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVehiculos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacNom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacNom]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacIng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacIng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacIng]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDetRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacDetRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacDetRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDetCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacDetCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacDetCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDet_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacDet_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacDet_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVacBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVacBan]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVac_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVac_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVac_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVac_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVac_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVac_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomVac]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomTablaRetItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomTablaRetItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomTablaRetItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomTablaRetInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomTablaRetInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomTablaRetInv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomTablaRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomTablaRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomTablaRet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomSueldosId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomSueldosId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomSueldosId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomSueldos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomSueldos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomSueldos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomSueldos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomSueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomSueldos]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetIng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetIng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetIng]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetDetLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetDetLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetDetLiq]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetBan]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetAct]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRetAct]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRetAct]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRet_Crr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRet_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRet_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRet_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRet_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRet_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRangosFsuLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRangosFsuLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRangosFsuLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRangosFsuId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRangosFsuId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRangosFsuId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRangosFsu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomRangosFsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomRangosFsu]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProvAjuLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomProvAjuLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomProvAjuLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProvAjuFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomProvAjuFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomProvAjuFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProrrogasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomProrrogasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomProrrogasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProrrogasId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomProrrogasId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomProrrogasId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProrrogas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomProrrogas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomProrrogas]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrmSaludLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrmSaludLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrmSaludLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestSdo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestSdo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestSdo]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrestAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrestAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrest_Cra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrest_Cra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrest_Cra]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrest]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrest]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrest]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrendas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomPrendas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomPrendas]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovEstLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovEstLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovEstLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovEst_Cp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovEst_Cp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovEst_Cp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadTra]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadTra]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadLic]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadLic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadLic]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadApo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedadApo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedadApo]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedad]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovedad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovedad]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovConvLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovConvLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovConvLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovConv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNovCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNovCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNov_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNov_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNov_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLogVehId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLogVehId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLogVehId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLogVehDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLogVehDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLogVehDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLogVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLogVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLogVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaUcp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaUcp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaUcp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaTip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaPtot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaPtot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaPtot]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaPar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaPar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaPar]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaIng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaIng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaIng]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaCmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaCes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaCes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaCes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquidaBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquidaBan]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquida_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquida_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquida_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDetTnm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiqDetTnm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiqDetTnm]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDetTEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiqDetTEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiqDetTEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDetEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiqDetEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiqDetEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDet_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiqDet_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiqDet_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomLiqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomLiqDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaVehc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaVehc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaVehc]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaVeha]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaVeha]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaVeha]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaTEmp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaTEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaTEmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaRtot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaRtot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaRtot]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaRst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaRst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaRst]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaPag]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaPag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaPag]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaInt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaInt]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaIng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaIng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaIng]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaGcon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaGcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaGcon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaElectronicaAjuste]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaElectronicaAjuste]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaElectronicaAjuste]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaElectronica]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaElectronica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaElectronica]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaDia]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaCip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaCip]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCed]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaCed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaCed]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaCa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaCa]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBanNv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaBanNv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaBanNv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBanlv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaBanlv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaBanlv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBanl]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaBanl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaBanl]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaBan]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaAux]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaAux]
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaApo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNominaApo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNominaApo]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomina_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomina_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomina_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomina_Cpn]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomina_Cpn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomina_Cpn]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomina]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomGruposConvLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomGruposConvLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomGruposConvLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomGruposConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomGruposConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomGruposConv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomFijosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomFijosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomFijosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomFijos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomFijos]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomEstadosConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomEstadosConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomEstadosConv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomEscalafonesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomEscalafonesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomEscalafonesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomEscalafones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomEscalafones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomEscalafones]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDotacionLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDotacionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDotacionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDotacion_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDotacion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDotacion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDotacion]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDotacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDotacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDiarioLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDiarioLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDiarioLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleTar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleTar]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleRtot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleRtot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleRtot]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleResN]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleResN]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleResN]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleRes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleRcon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleRcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleRcon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetallePmd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetallePmd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetallePmd]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetallePer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetallePer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetallePer]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleHex]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleHex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleHex]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleDsp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleDsp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleDsp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleDia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleDia]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleBas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleBas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleBas]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleAux]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleAux]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleAcu]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalleAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalleAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalle]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDefault]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomDefault]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomDefault]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConvZonasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConvZonasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConvZonasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConvencionesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConvencionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConvencionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConvenciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConvenciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConvenciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConOpcionesId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConOpcionesId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConOpcionesId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConOpciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConCuentasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConCuentasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConCuentasId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConCuentasId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasFon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConCuentasFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConCuentasFon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasCls]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConCuentasCls]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConCuentasCls]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasCla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConCuentasCla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConCuentasCla]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosTar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptosTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptosTar]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptosPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptosPre]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptosLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptosLiq]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosDsc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptosDsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptosDsc]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConcConvLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConcConvLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConcConvLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConcConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConcConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConcConv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConcCondLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConcCondLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConcCondLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAutoPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConAutoPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConAutoPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAutoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConAutoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConAutoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAutoId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConAutoId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConAutoId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAuto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomConAuto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomConAuto]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCertfMes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCertfMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCertfMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCertfLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCertfLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCertfLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCertf]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCertf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCertf]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCausalesRet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCausalesRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCausalesRet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCapacitacionesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCapacitacionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCapacitacionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmonId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCAdmonId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCAdmonId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmonCla]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCAdmonCla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCAdmonCla]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmon_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCAdmon_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCAdmon_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomCAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomCAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomBasesConv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomBasesConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomBasesConv]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliqPer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAutoliqPer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAutoliqPer]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliqDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAutoliqDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAutoliqDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliq_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAutoliq_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAutoliq_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAutoliq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAutoliq]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstnciaTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAstnciaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAstnciaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstnciaTip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAstnciaTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAstnciaTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstnciaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAstnciaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAstnciaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstncia]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAstncia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAstncia]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAportanteReg]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAportanteReg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAportanteReg]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAportante]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAportante]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAportante]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqTot_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAlqTot_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAlqTot_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAlqTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAlqTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqNov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAlqNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAlqNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAlqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAlqDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAjustesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAjustesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAjustesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAjustes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomActividadesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomActividadesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomActividadesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomActividades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomActividades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomActividades]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAbonosPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAbonosPre]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosPer]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAbonosPer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAbonosPer]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosLiq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAbonosLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAbonosLiq]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAbonosId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAbonosId]
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNomAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNomAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifRevelacLtc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifRevelacLtc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifRevelacLtc]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifRevelacLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifRevelacLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifRevelacLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifPoliticasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifPoliticasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifPoliticasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifDetalleLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifDetalleLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifDetalleLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifCompLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifCompLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifCompLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifComp_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifComp_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifComp_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifComp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNiifComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNiifComp]
GO
/****** Object:  StoredProcedure [dbo].[paQryNERecordLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryNERecordLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryNERecordLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudServiciosDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudServiciosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudServiciosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudServicios]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudServicios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudServicios]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudSecciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudSecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudSecciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenVehRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenVehRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenVehRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenVeh_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenVeh_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenVeh_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServVeh]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenServVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenServVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServReq]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenServReq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenServReq]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenServRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenServRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenServLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenServLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServ_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenServ_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenServ_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServ]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenOperRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenOperRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenOperRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenOper_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenOper_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenOper_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenNovRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenNovRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenNovRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenConcLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudOrdenConcLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudOrdenConcLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventarioOsm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudInventarioOsm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudInventarioOsm]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventarioLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudInventarioLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudInventarioLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventario_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudInventario_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudInventario_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudInventario]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudEstados]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContratosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContratosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContratosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContratosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContratos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContratos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContratos]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContNovRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContNovRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContNovRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContNov_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContNov_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContNov_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContFactRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudContFactRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudContFactRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudArticulosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudArticulosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudArticulosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMudArticulos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMudArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMudArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoTiposOdt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoTiposOdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoTiposOdt]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoTipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoTipos]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoSistemas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoSistemas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoSistemas]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenReqFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrdenReqFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrdenReqFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenRelDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrdenRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrdenRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrdenRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrdenRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrdenLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrdenLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrdenFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrdenFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrdenDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrdenDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrden]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoOrden]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoInspeccionesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoInspeccionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoInspeccionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoInspecciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoInspecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoInspecciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoEstados]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoDiagnFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoDiagnFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoDiagnFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoControlesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoControlesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoControlesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoControles]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoControles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoControles]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoConceptosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoConceptosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoConceptosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoConceptos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMttoConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMttoConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrymonedasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrymonedasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedasLoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrymonedasLoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrymonedasLoc]
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrymonedasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrymonedasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQrymonedas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQrymonedas]
GO
/****** Object:  StoredProcedure [dbo].[paQryModulosId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryModulosId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryModulosId]
GO
/****** Object:  StoredProcedure [dbo].[paQryModulos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryModulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryModulos]
GO
/****** Object:  StoredProcedure [dbo].[paQryMercanciasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMercanciasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMercanciasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMercancias]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMercancias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMercancias]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposPoliza]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayTiposPoliza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayTiposPoliza]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposBonif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayTiposBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayTiposBonif]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposBienes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayTiposBienes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayTiposBienes]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposAprob]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayTiposAprob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayTiposAprob]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayTipos]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPsptoLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayPsptoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayPsptoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPsptoItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayPsptoItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayPsptoItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPsptoCant]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayPsptoCant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayPsptoCant]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPspto]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayPspto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayPspto]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiquidaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiquidaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiquidaId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiquidaId]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaFec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiquidaFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiquidaFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaEst]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiquidaEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiquidaEst]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquida]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqTotalesTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqTotalesTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesNot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqTotalesNot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqTotalesNot]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqTotalesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqTotalesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesLog]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqTotalesLog]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqTotalesLog]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesAbp]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqTotalesAbp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqTotalesAbp]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesAbo]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqTotalesAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqTotalesAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqDetalleLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayLiqDetalleLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayLiqDetalleLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayItemsInvLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayItemsInvLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayItemsInvLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayItemsInvGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayItemsInvGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayItemsInvGru]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayItemsInv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayItemsInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayItemsInv]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventarioTot]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayInventarioTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayInventarioTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventarioLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayInventarioLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayInventarioLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventarioItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayInventarioItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayInventarioItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventario]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayInventario]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayEstados]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayEstados]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosRel]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratosRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratosRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosId]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratosId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratosId]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosCli]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratosCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratosCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosAct]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratosAct]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratosAct]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratos_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContratos]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocPen]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContDocPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContDocPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContDocLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContDocLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContDocItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContDocItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocDep]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContDocDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContDocDep]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayContDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayContDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonifSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonifSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonifLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonifLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonifItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonifItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifDet]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonifDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonifDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifCant]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonifCant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonifCant]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonif]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonif]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonCuentasTip]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonCuentasTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonCuentasTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonCuentasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonCuentasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonCuentasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonCuentas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayBonCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayBonCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAnotacionesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayAnotacionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayAnotacionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAnotacionesItm]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayAnotacionesItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayAnotacionesItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAnotaciones]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayAnotaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayAnotaciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAgenciasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMayAgenciasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMayAgenciasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMarcasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMarcasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLinLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMarcasLinLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMarcasLinLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLinDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMarcasLinDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMarcasLinDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLin]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMarcasLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMarcasLin]
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryMarcas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryMarcas]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMovLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotMovLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotMovLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMovGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotMovGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotMovGru]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMov_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotMov_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotMov_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMov]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotMov]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotesSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotesSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotesPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotesPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotesPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotes_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotes_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotes_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryLotes]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLotes]
GO
/****** Object:  StoredProcedure [dbo].[paQryLog_PeriodosLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLog_PeriodosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLog_PeriodosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLog_Periodos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLog_Periodos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLog_Periodos]
GO
/****** Object:  StoredProcedure [dbo].[paQryLog_Nomina]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLog_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLog_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesPais]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLocalidadesPais]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLocalidadesPais]
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesNom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLocalidadesNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLocalidadesNom]
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLocalidadesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLocalidadesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLocalidadesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLocalidadesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesDep]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLocalidadesDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLocalidadesDep]
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidades]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLocalidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLocalidades]
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLineasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLineasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasDso]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLineasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLineasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasCredLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLineasCredLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLineasCredLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasCredCueLta]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLineasCredCueLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLineasCredCueLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryLineas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryLineas]
GO
/****** Object:  StoredProcedure [dbo].[paQryKarUbicGru]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKarUbicGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKarUbicGru]
GO
/****** Object:  StoredProcedure [dbo].[paQryKarUbic]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKarUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKarUbic]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexTdoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexTdoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexTdoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexTan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexTan]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSubOpe]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexSubOpe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexSubOpe]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSubc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexSubc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexSubc]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSub]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSobtasa]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexSobtasa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexSobtasa]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSob]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexSob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexSob]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexReqSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexReqSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexReqSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexProCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexProCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexProCc]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPro]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPre]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPre]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPedSal]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPedSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPedSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPedOcc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPedOcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPedOcc]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPedFac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPedFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPedFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPbas]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPbas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPbas]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPar]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexPar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexPar]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexOrd]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexOdcEnt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexOdcEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexOdcEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexOdcCom]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexOdcCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexOdcCom]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexMovTan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexMovTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexMovTan]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexMovinv]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexMovinv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexMovinv]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexMng]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexMng]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexMng]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexGTan]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexGTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexGTan]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexDoc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexCc]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexCc]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBond]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexBond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexBond]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBon]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexBon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexBon]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBIvac]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexBIvac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexBIvac]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBIva]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexBIva]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexBIva]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBFcr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexBFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexBFcr]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBDev]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexBDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexBDev]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexAdi]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardexAdi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardexAdi]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardex_Cr]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardex_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardex_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryKardex]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryKardex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryKardex]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurTiposRec]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurTiposRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurTiposRec]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurTipos]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurTipos]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurReclamacFmt]    Script Date: 10/12/2025 8:10:22 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurReclamacFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurReclamacFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurReclamac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurReclamac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurReclamac]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurPreguntasDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurPreguntasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurPreguntasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurPreguntas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurPreguntas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurPreguntas]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestigaRad]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestigaRad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestigaRad]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestigaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestigaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestigaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_CrrH]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestiga_CrrH]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestiga_CrrH]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestiga_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestiga_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_Crh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestiga_Crh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestiga_Crh]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestiga_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestiga_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvestiga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvestiga]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvesHisItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvesHisItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvesHisItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvesHisDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvesHisDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvesHisDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvesHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurInvesHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurInvesHis]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurEstados]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurDocumtos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurDocumtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurDocumtos]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurClaseAcc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurClaseAcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurClaseAcc]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCausalesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCausalesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCausalesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCausalesDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCausalesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCausalesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCausales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCausales]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosRad]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosRad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosRad]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosQtnLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosQtnLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosQtnLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosPen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosHisLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosHisLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosHisLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosHisItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosHisItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosHisItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasosHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasosHis]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_CrrH]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasos_CrrH]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasos_CrrH]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasos_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasos_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_Crh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasos_Crh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasos_Crh]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCasos]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCalificaDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCalificaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCalificaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCalifica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurCalifica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurCalifica]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurAutoridades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurAutoridades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurAutoridades]
GO
/****** Object:  StoredProcedure [dbo].[paQryJurActas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJurActas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJurActas]
GO
/****** Object:  StoredProcedure [dbo].[paQryJornadas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryJornadas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryJornadas]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoTan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisicoTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisicoTan]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisicoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisicoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoPen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisicoPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisicoPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisicoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisicoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoDia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisicoDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisicoDia]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisico_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisico_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisico_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisico]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvFisico]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvFisico]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleTco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleTco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleTco]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleTan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleTan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleTan]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleSobTq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleSobTq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleSobTq]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleSob]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleSob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleSob]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetallePro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetallePro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetallePro]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleFalTq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleFalTq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleFalTq]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleFal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleFal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleFal]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleExp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleExp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleExp]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleExi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleExi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleExi]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleEtq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleEtq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleEtq]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalleDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalleDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInvDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInvDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQryInstalacionesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInstalacionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInstalacionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryInstalaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryInstalaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryInstalaciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaRelDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaPed]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaPed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaPed]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaFact]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaFact]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaFact]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuiaDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuiaDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuia_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuia_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuia_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGuia]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposUsuDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposUsuDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposUsuDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposUsu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposUsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposUsu]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposRot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposRot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposRot]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposObj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposObj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposObj]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposLin]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposCliLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposCliLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposCliLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposCli]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposAR]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposAR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposAR]
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paQryGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatVincula]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatVincula]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatVincula]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatRetiros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatRetiros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatRetiros]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatProrrateos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatProrrateos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatProrrateos]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevVinc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevVinc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevVinc]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevRetiros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevRetiros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevRetiros]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevProrr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevProrr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevProrr]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevAjuPror]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevAjuPror]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevAjuPror]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevAdicional]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatDevAdicional]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatDevAdicional]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatAportes]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAjustesPror]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatAjustesPror]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatAjustesPror]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAdicionales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryGatAdicionales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryGatAdicionales]
GO
/****** Object:  StoredProcedure [dbo].[paQryFuentesPago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFuentesPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFuentesPago]
GO
/****** Object:  StoredProcedure [dbo].[paQryFormaspagoID]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFormaspagoID]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFormaspagoID]
GO
/****** Object:  StoredProcedure [dbo].[paQryFormaspagoChe]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFormaspagoChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFormaspagoChe]
GO
/****** Object:  StoredProcedure [dbo].[paQryFormaspago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFormaspago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFormaspago]
GO
/****** Object:  StoredProcedure [dbo].[paQryFormasCueLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFormasCueLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFormasCueLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFormasCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFormasCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFormasCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosPen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFondosPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFondosPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFondosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFondosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFondosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFondosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosCla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFondosCla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFondosCla]
GO
/****** Object:  StoredProcedure [dbo].[paQryFondos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFondos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFondos]
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtFacturaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFmtFacturaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFmtFacturaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFmtFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFmtFactura]
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtDocDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFmtDocDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFmtDocDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtDocDft]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFmtDocDft]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFmtDocDft]
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFmtDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFmtDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinRecibosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinRecibosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinRecibosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinRecibosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinRecibosDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinRecibosDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinRecibosCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinRecibosCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestResEgr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestResEgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestResEgr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestGarantLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestGarantLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestGarantLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestGarant]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestGarant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestGarant]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoExto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoExto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoExto]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoDsb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoDsb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoDsb]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoAcum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamoAcum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamoAcum]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPagosFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinPagosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinPagosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinNotasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinNotasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotasFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinNotasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinNotasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotasCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinNotasCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinNotasCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinNotas]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFacturasInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFacturasInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFacturasInt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFacturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactSeguroFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFactSeguroFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFactSeguroFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactintLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFactintLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFactintLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactintFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFactintFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFactintFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactintCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFactintCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFactintCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactint]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinFactint]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinFactint]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevRecLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevRecLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevRecFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevRecFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevRecDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevRecDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevRecCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevRecCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevPreLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevPreLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevPreFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevPreFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevPreDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevPreDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevPreCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevPreCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevPre]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevFacLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevFacLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevFacFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevFacFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevFacDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevFacDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevFacCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevFacCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinDevFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinDevFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasRmc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasRmc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasRmc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasRac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasRac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasRac]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasInt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasExto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasExto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasExto]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasAbo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotasAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotasAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinConveniosFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinConveniosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinConveniosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinConvenios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinConvenios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinConvenios]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinConcFacturaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinConcFacturaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinConcFacturaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinClieSaldosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinClieSaldosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinClieSaldosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCiAportesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCiAportesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCiAportesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCausacionFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCausacionFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCausacionFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCauMoraFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCauMoraFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCauMoraFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCanAportesFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCanAportesFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCanAportesFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCanAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinCanAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinCanAportes]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAportesFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAportesFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAportesFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAportes]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAlmacenes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAlmacenes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAlmacenes]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAfavor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAfavor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAfavor]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAbonosRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAbonosRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosRca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAbonosRca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAbonosRca]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAbonosFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAbonosFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosExto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFinAbonosExto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFinAbonosExto]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_VehLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_VehLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_VehLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_VehDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_VehDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_VehDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Veh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_Veh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_Veh]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_CueDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_CueDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_CueDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Cue_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_Cue_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_Cue_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Cue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_Cue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_Cue]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_ClaTar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_ClaTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_ClaTar]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_ClaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_ClaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_ClaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_ClaDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_ClaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_ClaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Cla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos_Cla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos_Cla]
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFijos]
GO
/****** Object:  StoredProcedure [dbo].[paQryFieldsLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFieldsLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFieldsLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFields]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFields]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFields]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcSemanasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcSemanasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcSemanasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcSemanas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcSemanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcSemanas]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcNotasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcNotasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcNotasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcNotasFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcNotasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcNotasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcNotas]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcCausacionFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcCausacionFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcCausacionFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFcCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFcCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFcCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryFaeFmtos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFaeFmtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFaeFmtos]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactVales]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasRem]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRelTraDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasRelTraDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasRelTraDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRelTra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasRelTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasRelTra]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasPed]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasPed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasPed]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOdr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasOdr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasOdr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOdp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasOdp]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOdc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasOdc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasOdc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOcc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasOcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasOcc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasNetDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasNetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasNetDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasNet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasNet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasNet]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasIca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasIca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasIca]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasGui]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasGui]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasGui]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasFmtc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasFmtc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasFmtc]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasFmtb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasFmtb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasFmtb]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasCot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasCot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasCot]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturasCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturasCom]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturas40_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturas40_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturas40_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturas_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactconRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactconRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconNetDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactconNetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactconNetDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconNet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactconNet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactconNet]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactconLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactconLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactcon_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactcon_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactcon_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactcon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryFactcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryFactcon]
GO
/****** Object:  StoredProcedure [dbo].[paQryExpLicenciasDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryExpLicenciasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryExpLicenciasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryExpLicencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryExpLicencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryExpLicencias]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstratos]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoTer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoTer]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoSer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoSer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoSer]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoOper]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoOper]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoOper]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoGuia]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoDocDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoDocDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoDocDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoCiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstadoCiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstadoCiv]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstacionesDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstacionesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstacionesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEstaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEstaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEstaciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasOdc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasOdc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasOdc]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasNFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasNFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasNFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasNetDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasNetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasNetDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasNet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasNet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasNet]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasIns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasIns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasIns]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasEqv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradasEqv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradasEqv]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradas_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntradas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntradas]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paQryEntArticulosPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEntArticulosPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEntArticulosPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosVac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosVac]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosSue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosSue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosSue]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosReg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosReg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosReg]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosLab]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosLab]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosLab]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosFam]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosFam]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosFam]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosCon]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosCod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosCod]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosCnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosCnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosCna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosCna]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosBus]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleadosBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleadosBus]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpleados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpleados]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpaques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmpaques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmpaques]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ParientesDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ParientesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ParientesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_Parientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_Parientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_Parientes]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ExpLaboralDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ExpLaboralDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ExpLaboralDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ExpLaboral]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ExpLaboral]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ExpLaboral]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_EstudiosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_EstudiosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_EstudiosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_Estudios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_Estudios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_Estudios]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoVce]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoVce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoVce]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoNom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoNom]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoLab]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoLab]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoLab]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoId]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoId]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoEca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoEca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoEca]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoAct]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_ContratoAct]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_ContratoAct]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_Contrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_CentrosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEmp_CentrosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEmp_CentrosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaTnit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFacturaTnit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFacturaTnit]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFacturaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFacturaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFacturaDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFacturaDev]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaDap]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFacturaDap]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFacturaDap]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaApl]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFacturaApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFacturaApl]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaAbo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFacturaAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFacturaAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFactura_Fac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFactura_Fac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFactura_Fac]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFactura_Crc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFactura_Crc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFactura_Crc]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrFactura]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrAnticipoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrAnticipoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrAnticipoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrAnticipoApl]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEgrAnticipoApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEgrAnticipoApl]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsUnion_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsUnion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsUnion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsUnion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsUnion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsUnion]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsServicio]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsServicio]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsServicio]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosTip]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsRangosTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsRangosTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosSer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsRangosSer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsRangosSer]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsRangosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsRangosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosId]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsRangosId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsRangosId]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosFor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsRangosFor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsRangosFor]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsRangos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsRangos]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasVC]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasVC]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasVC]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasTotCaj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasTotCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasTotCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasRelDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasRelDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasRelDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasRan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasRan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasRan]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasPla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasPla]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasLtp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasLtp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasLtp]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasCos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormasCos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormasCos]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormas_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsForItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsForItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsForItems]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesUlt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortesUlt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortesUlt]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortesRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortesRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesNetDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortesNetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortesNetDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesNet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortesNet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortesNet]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesCor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortesCor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortesCor]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortes_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortes_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortes_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCortes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCortes]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCalibraLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCalibraLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCalibraLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCalibra_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCalibra_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCalibra_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCalibra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryEdsCalibra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryEdsCalibra]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocumentoSOP40_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocumentoSOP40_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocumentoSOP40_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSoporteRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocSoporteRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocSoporteRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSoporteFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocSoporteFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocSoporteFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSoporte]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocSoporte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocSoporte]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSopDevLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocSopDevLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocSopDevLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSopDevFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocSopDevFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocSopDevFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSopDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocSopDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocSopDev]
GO
/****** Object:  StoredProcedure [dbo].[paQryDocMemo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDocMemo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDocMemo]
GO
/****** Object:  StoredProcedure [dbo].[paQryDisciplinarioLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDisciplinarioLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDisciplinarioLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDisciplinarioFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDisciplinarioFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDisciplinarioFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDisciplinario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDisciplinario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDisciplinario]
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDiferidosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDiferidosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidosHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDiferidosHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDiferidosHis]
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidosAmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDiferidosAmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDiferidosAmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDiferidos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDiferidos]
GO
/****** Object:  StoredProcedure [dbo].[paQryDiarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDiarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDiarios]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevValLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevValLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevValLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevValDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevValDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevValDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevVal_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevVal_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevVal_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevVal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevVal]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSalRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevSalRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevSalRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSalLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevSalLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevSalLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSalDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevSalDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevSalDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSal_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevSal_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevSal_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesVFec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBusesVFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBusesVFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesNMes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBusesNMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBusesNMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBusesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBusesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesAntc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBusesAntc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBusesAntc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBusesAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBusesAnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBuses_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBuses_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBuses_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBuses_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBuses_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBuses_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecAcu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRecAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRecAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRec_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRec_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRec_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPrestamosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPrestamosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamos_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPrestamos_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPrestamos_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamos_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPrestamos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPrestamos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPlaRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPlaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPlaRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPlaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPlaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPlaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPlaDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPlaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPlaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPla_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPla_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPla_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPla]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPasDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPasDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPasDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPas_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevPas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevPas]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNprRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevNprRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevNprRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNprLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevNprLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevNprLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNprDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevNprDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevNprDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNpr_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevNpr_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevNpr_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNpr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevNpr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevNpr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcVFec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFvcVFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFvcVFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcNMes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFvcNMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFvcNMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFvcLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFvcLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFvcDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFvcDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvc_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFvc_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFvc_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFvc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrRelTraDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrRelTraDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrRelTraDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrRelTra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrRelTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrRelTra]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrFmtb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrFmtb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrFmtb]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrFmt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrAcu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcrAcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcrAcu]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcr40]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcr40]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcr40]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcr_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcr_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcr_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcoRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcoRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcoRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcoDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFcoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFcoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFco_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFco_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFco_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevFco]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEntRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevEntRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevEntRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEntLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevEntLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevEntLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEntDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevEntDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevEntDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryDeveloper]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDeveloper]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDeveloper]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCnsRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCnsRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCnsRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCnsLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCnsLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCnsLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCnsDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCnsDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCnsDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCns_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCns_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCns_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCns]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionVFec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacionVFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacionVFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionVc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacionVc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacionVc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionNMes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacionNMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacionNMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacion_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacion_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacion_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacion_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCajRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCajRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCajLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCajLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCajDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCajDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajBusPag]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCajBusPag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCajBusPag]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajBus]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCajBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCajBus]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCaj_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCaj_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCaj_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCaj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDevCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDevCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryDetCuentasRci]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDetCuentasRci]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDetCuentasRci]
GO
/****** Object:  StoredProcedure [dbo].[paQryDetCuentas_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDetCuentas_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDetCuentas_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDetCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDetCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDetCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosPen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachosPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachosPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosFre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachosFre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachosFre]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosAbi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachosAbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachosAbi]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachos_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachos_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachos_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachos_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paQryDesagregacionesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDesagregacionesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDesagregacionesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDesagregaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDesagregaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDesagregaciones]
GO
/****** Object:  StoredProcedure [dbo].[paQryDependenciasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDependenciasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDependenciasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryDependencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDependencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDependencias]
GO
/****** Object:  StoredProcedure [dbo].[paQryDepartamentos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryDepartamentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryDepartamentos]
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesPuc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCtasCorrientesPuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCtasCorrientesPuc]
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesNum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCtasCorrientesNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCtasCorrientesNum]
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCtasCorrientesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCtasCorrientesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCtasCorrientesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCtasCorrientesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesDsa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCtasCorrientesDsa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCtasCorrientesDsa]
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCtasCorrientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCtasCorrientes]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacionRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacionRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionFact]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacionFact]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacionFact]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacionFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacionFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacionDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacionDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacion_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCotizacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCotizacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryCorrResiduos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCorrResiduos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCorrResiduos]
GO
/****** Object:  StoredProcedure [dbo].[paQryConsignaRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConsignaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConsignaRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryConsignaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConsignaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConsignaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConsigna_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConsigna_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConsigna_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryConsigna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConsigna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConsigna]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosTribLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosTribLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosTribLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosTribDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosTribDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosTribDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosTrib]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosTrib]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosTrib]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosCueLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosCueLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosCueLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosAdmonLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosAdmonLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosAdmonLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosAdmon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptosAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptosAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosOsm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversosOsm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversosOsm]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversosNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversosNov]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosGas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversosGas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversosGas]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversosFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversosFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDiversos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDiversos]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDivCueLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDivCueLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDivCueLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDivCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryConcDivCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryConcDivCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesTotCaj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesTotCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesTotCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesNom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesNom]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesEgr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesEgr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesEgr]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesEgo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesEgo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesEgo]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesChx]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesChx]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesChx]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesChe]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesChe]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesCaj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantesCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantesCaj]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantes_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantes_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantes_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComprobantes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComprobantes]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompGastosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompGastosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompGastosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompGastos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompGastos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompGastos]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCajaRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCajaRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCajaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCajaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCajaDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCajaDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaBusPag]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCajaBusPag]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCajaBusPag]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaBusDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCajaBusDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCajaBusDet]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaBus]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCajaBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCajaBus]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCaja_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCaja_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCaja_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompCaja]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompaniasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompaniasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompaniasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompaniasDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompaniasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompaniasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompanias_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompanias_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompanias_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCompanias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCompanias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCompanias]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaTnit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaTnit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaTnit]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaRef]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaRef]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaGnit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaGnit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaGnit]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDve]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaDve]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaDve]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDab]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaDab]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaDab]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaCmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaCmp]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaAbo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFacturaAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFacturaAbo]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFactura_Ent]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFactura_Ent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFactura_Ent]
GO
/****** Object:  StoredProcedure [dbo].[paQryComFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComFactura]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleVis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleVis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleVis]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleVen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleVen]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleRetTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleRetTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleRetTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleRet]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleNitSub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleNitSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleNitSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleNitCc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleNitCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleNitCc]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleMud]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleMud]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleMud]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleDmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleDmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleDmto]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleDia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleDia]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleCueTip]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleCueTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleCueTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleCueNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleCueNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleCueNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleChe]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleChe]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleChe]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleAge]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalleAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalleAge]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalle_Crd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalle_Crd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalle_Crd]
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryComDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryComDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextnaTip]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCnxextnaTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCnxextnaTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextnaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCnxextnaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCnxextnaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextnaItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCnxextnaItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCnxextnaItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCnxextna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCnxextna]
GO
/****** Object:  StoredProcedure [dbo].[paQryClieContadoTel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClieContadoTel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClieContadoTel]
GO
/****** Object:  StoredProcedure [dbo].[paQryClieContadoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClieContadoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClieContadoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryClieContado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClieContado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClieContado]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseTarImp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseTarImp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseTarImp]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseTar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseTar]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseSub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseSub]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseRieDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseRieDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseRieDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseRie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseRie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseRie]
GO
/****** Object:  StoredProcedure [dbo].[paQryClasePol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClasePol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClasePol]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseFon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseFon]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseDocCond]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseDocCond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseDocCond]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseDivDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseDivDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseDivDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseDiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseDiv]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseCta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseCta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseCta]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseCapac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseCapac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseCapac]
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseBan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryClaseBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryClaseBan]
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryChequesRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryChequesRec]
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesPos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryChequesPos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryChequesPos]
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesPen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryChequesPen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryChequesPen]
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryChequesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryChequesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryChequesDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryChequesDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesCns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryChequesCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryChequesCns]
GO
/****** Object:  StoredProcedure [dbo].[paQryCheques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCheques]
GO
/****** Object:  StoredProcedure [dbo].[paQryCentrosServLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCentrosServLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCentrosServLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCentrosServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCentrosServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCentrosServ]
GO
/****** Object:  StoredProcedure [dbo].[paQryCentroCostoDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCentroCostoDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCentroCostoDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryCentroCostoCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCentroCostoCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCentroCostoCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryCentroCosto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCentroCosto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCentroCosto]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausaValesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausaValesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausaValesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausaVales_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausaVales_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausaVales_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausaVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausaVales]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceVp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceVp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceVp]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceVFec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceVFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceVFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceTpa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceTpa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceTpa]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceNMes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceNMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceNMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceMor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceMor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceMor]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceLca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceLca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceLca]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceExt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceExt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceExt]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceEvo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceEvo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceEvo]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceCli]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceApl]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceApl]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceApl]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceAbb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVenceAbb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVenceAbb]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVence_Cra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVence_Cra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVence_Cra]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVence_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVence_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVence_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVence]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacVence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacVence]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionOtr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionOtr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionOtr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionInt]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFijTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionFijTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionFijTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFij]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionFij]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionFij]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFfa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionFfa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionFfa]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionFec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionFec]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionFac]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionDia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionDia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionDia]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionD_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionD_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionD_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionCie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacionCie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacionCie]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacion_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacion_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacion_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacion_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryCargos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCargos]
GO
/****** Object:  StoredProcedure [dbo].[paQryCalndarioMes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCalndarioMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCalndarioMes]
GO
/****** Object:  StoredProcedure [dbo].[paQryCalndario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryCalndario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryCalndario]
GO
/****** Object:  StoredProcedure [dbo].[paQryBusClaseCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBusClaseCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBusClaseCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbicLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodUbicLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodUbicLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbicDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodUbicDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodUbicDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbicCan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodUbicCan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodUbicCan]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbic]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodUbic]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodegasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodegasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodegasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodegasDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodegasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodegasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryBodegas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paQryBancosEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBancosEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBancosEnt]
GO
/****** Object:  StoredProcedure [dbo].[paQryBancosDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBancosDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBancosDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryBancos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryBancos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryBancos]
GO
/****** Object:  StoredProcedure [dbo].[paQryAutorizaNum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAutorizaNum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAutorizaNum]
GO
/****** Object:  StoredProcedure [dbo].[paQryAutorizaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAutorizaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAutorizaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAutorizaDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAutorizaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAutorizaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paQryAutoriza_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAutoriza_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAutoriza_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAutoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paQryAreasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAreasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAreasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAreas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAreas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAreas]
GO
/****** Object:  StoredProcedure [dbo].[paQryAprobacionLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAprobacionLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAprobacionLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAprobacion_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAprobacion_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAprobacion_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAprobacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAprobacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAprobacion]
GO
/****** Object:  StoredProcedure [dbo].[paQryAlmBodegas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAlmBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAlmBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInvRel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAjuInvRel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAjuInvRel]
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInvOrd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAjuInvOrd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAjuInvOrd]
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInvLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAjuInvLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAjuInvLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInv_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAjuInv_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAjuInv_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAjuInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAjuInv]
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAgenciasLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAgenciasLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasId]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAgenciasId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAgenciasId]
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasCod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAgenciasCod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAgenciasCod]
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasCli]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAgenciasCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAgenciasCli]
GO
/****** Object:  StoredProcedure [dbo].[paQryAgencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAgencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAgencias]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfTiposMovDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfTiposMovDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfTiposMovDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfTiposMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfTiposMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfTiposMov]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfTiposDif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfTiposDif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfTiposDif]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPignoraLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfPignoraLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfPignoraLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPignoraCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfPignoraCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfPignoraCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPignora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfPignora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfPignora]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPartesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfPartesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfPartesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovValorizaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovValorizaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovValorizaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovValorizaCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovValorizaCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovValorizaCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovValoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovValoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovValoriza]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovTrasladoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovTrasladoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovTrasladoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovTrasladoCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovTrasladoCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovTrasladoCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovRetiroLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovRetiroLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovRetiroLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovRetiroCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovRetiroCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovRetiroCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovIngresoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovIngresoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovIngresoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovIngresoCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovIngresoCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovIngresoCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovimiento]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMovimiento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMovimiento]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMantnmtoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMantnmtoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMantnmtoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMantnmtoCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMantnmtoCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMantnmtoCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMantnmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfMantnmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfMantnmto]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfLineasDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfLineasDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfLineasDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfLineas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfLineas]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfGruposLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfGruposLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfGruposLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfGruposLin]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposDso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfGruposDso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfGruposDso]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposCueLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfGruposCueLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfGruposCueLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfGruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfGruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfEstados]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifValorizaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifValorizaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifValorizaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifValorizaCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifValorizaCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifValorizaCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifValoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifValoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifValoriza]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifTrasladoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifTrasladoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifTrasladoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifTrasladoCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifTrasladoCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifTrasladoCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifRetiroLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifRetiroLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifRetiroLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifRetiroCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifRetiroCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifRetiroCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifMovi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifMovi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifMovi]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifIngresoLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifIngresoLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifIngresoLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifIngresoCr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDifIngresoCr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDifIngresoCr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDepreciaRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDepreciaRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDepreciaRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDepreciaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDepreciaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDepreciaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDeprecia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfDeprecia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfDeprecia]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfClasesCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfClasesCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfClasesCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfCausales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfCausales]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfAmortizaRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfAmortizaRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfAmortizaRes]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfAmortizaLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfAmortizaLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfAmortizaLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryAfAmortiza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAfAmortiza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAfAmortiza]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPropietariosVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPropietariosVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosSalPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPropietariosSalPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPropietariosSalPro]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosSalCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPropietariosSalCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPropietariosSalCue]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPropietariosSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPropietariosSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosCla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPropietariosCla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPropietariosCla]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPropietarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPropietarios]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuNiifCuentasMayCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuNiifCuentasMayCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuNiifCuentasMayCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuNiifCuentasMay]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuNiifCuentasMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuNiifCuentasMay]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvUbicaSan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvUbicaSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvUbicaSan]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvUbica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvUbica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvUbica]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanquesSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvTanquesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvTanquesSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanquesGru]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvTanquesGru]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvTanquesGru]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanques_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvTanques_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvTanques_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvTanques]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvLotesSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvLotesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvLotesSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvLotes_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvLotes_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvLotes_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvLotes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInvLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInvLotes]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventarioSanp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInventarioSanp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInventarioSanp]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventarioSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInventarioSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInventarioSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventarioAju]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInventarioAju]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInventarioAju]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventario_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInventario_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInventario_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuInventario]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuFisCuentasMayCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuFisCuentasMayCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuFisCuentasMayCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuFisCuentasMay]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuFisCuentasMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuFisCuentasMay]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasVehSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasVehSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasVehSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasNitSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasNitSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasNitSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasNit]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasMayCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasMayCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasMayCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasMay]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasMay]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasGP]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasGP]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasGP]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCcSalcs]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasCcSalcs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasCcSalcs]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCcSalc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasCcSalc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasCcSalc]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCcSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasCcSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasCcSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasCc]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasBG]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasBG]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasBG]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAuxItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasAuxItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasAuxItm]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAgeSalTip]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasAgeSalTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasAgeSalTip]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAgeSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasAgeSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasAgeSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAge]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentasAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentasAge]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientesSan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuClientesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuClientesSan]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientesSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuClientesSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuClientesSal]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientesCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuClientesCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuClientesCia]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuClientes]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCajaTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCajaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCajaTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCajaBusesTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCajaBusesTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCajaBusesTot]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCajaBusesSan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCajaBusesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCajaBusesSan]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCaja_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCaja_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCaja_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryAcuCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryAcuCaja]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosMar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivosMar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivosMar]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivosLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivosLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivosHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivosHis]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosDep]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivosDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivosDep]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosBar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivosBar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivosBar]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_PartesLta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivos_PartesLta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivos_PartesLta]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_Partes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivos_Partes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivos_Partes]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_Cr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivos_Cr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivos_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_Anexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivos_Anexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivos_Anexo]
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paQryActivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paQryActivos]
GO
/****** Object:  StoredProcedure [dbo].[paListTercAccionistas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paListTercAccionistas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paListTercAccionistas]
GO
/****** Object:  StoredProcedure [dbo].[paInsZonas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsZonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsZonas]
GO
/****** Object:  StoredProcedure [dbo].[paInsVencimientos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVencimientos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVencimientos]
GO
/****** Object:  StoredProcedure [dbo].[paInsVencAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVencAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVencAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehTraspasos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehTraspasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehTraspasos]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehRemolq_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehRemolq_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehRemolq_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehRemolq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehRemolq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehRemolq]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehPolizas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehPartes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehPartes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehPartes]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehLecturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehLecturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehLecturas]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehiculos_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehiculos_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehiculos_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehiculos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehConductor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehConductor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehConductor]
GO
/****** Object:  StoredProcedure [dbo].[paInsVehClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVehClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVehClientes]
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_SaldosUni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVeh_SaldosUni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVeh_SaldosUni]
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_Saldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVeh_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVeh_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_CuposUni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVeh_CuposUni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVeh_CuposUni]
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_Cupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVeh_Cupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVeh_Cupos]
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_Contrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVeh_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVeh_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paInsValesRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsValesRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsValesRutas]
GO
/****** Object:  StoredProcedure [dbo].[paInsVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsVales]
GO
/****** Object:  StoredProcedure [dbo].[paInsUsucaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsUsucaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsUsucaja]
GO
/****** Object:  StoredProcedure [dbo].[paInsUsuarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsUsuarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsUsuarios]
GO
/****** Object:  StoredProcedure [dbo].[paInsUOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsUOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsUOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsUndMed]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsUndMed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsUndMed]
GO
/****** Object:  StoredProcedure [dbo].[paInsUm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsUm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsUm]
GO
/****** Object:  StoredProcedure [dbo].[paInsTurnos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTurnos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTurnos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraTurn]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraTurn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraTurn]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraTalonarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraTalonarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraTalonarios]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraReportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraReportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraReportes]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraRemMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraRemMcias]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemesa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraRemesa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraRemesa]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemCntdor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraRemCntdor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraRemCntdor]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraRemAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraRemAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraReexpedidoRem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraReexpedidoRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraReexpedidoRem]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraReexpedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraReexpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraReexpedido]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPresItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPresItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPresItems]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPresAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPresAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPresAnt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPorteIntMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPorteIntMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPorteIntMcia]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPorteInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPorteInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPorteInt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPedMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPedMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPedMcias]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPedido]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPedAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraPedAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraPedAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenRemesas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenRemesas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenPago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenPago]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenManif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenManif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenManif]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenLiq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenLiq]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenCum]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenAnt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenAbo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraOrdenAbo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraOrdenAbo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifRem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraManifRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraManifRem]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifMod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraManifMod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraManifMod]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifIntMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraManifIntMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraManifIntMcia]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraManifInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraManifInt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifiesto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraManifiesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraManifiesto]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraManifAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraManifAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiqViajes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraLiqViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraLiqViajes]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiquidaDed]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraLiquidaDed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraLiquidaDed]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraLiqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraLiqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraInfViajes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraInfViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraInfViajes]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraGuias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraGuias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraGuias]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraGuiaMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraGuiaMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraGuiaMcia]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraFijos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraFacRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraFacRemesas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraFacRemesas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevReex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevReex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevReex]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevOdp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevOdp]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevLiq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevLiq]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevLgo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevLgo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevLgo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevLeg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevLeg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevLeg]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevCum]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevCos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevCos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevCos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevCau]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevAos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevAos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevAos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDevAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDevAnt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDespProgram]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDespProgram]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDespProgram]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDespachos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDecMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDecMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDecMcia]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDecAduana]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraDecAduana]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraDecAduana]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCumRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraCumRemesas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraCumRemesas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCumRadica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraCumRadica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraCumRadica]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCumplido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraCumplido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraCumplido]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraConcCausac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraConcCausac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraConcCausac]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCauDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraCauDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraCauDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraAnticipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTraAntAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTraAntAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTraAntAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_VentasRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_VentasRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_VentasRes]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_VentasDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_VentasDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_VentasDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_VentasCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_VentasCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_VentasCom]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ventas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Ventas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Ventas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Pre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_vence_Pre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_vence_Pre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Not]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_vence_Not]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_vence_Not]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Fvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_vence_Fvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_vence_Fvc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Adm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_vence_Adm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_vence_Adm]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_vence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_vence]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vce]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_vce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_vce]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ValesCred_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ValesCred_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ValesCred_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ValesCred_Dev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ValesCred_Dev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ValesCred_Dev]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ValesCred]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ValesCred]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ValesCred]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemFact_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraRemFact_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraRemFact_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemFact]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraRemFact]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraRemFact]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum_Trr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraRemCum_Trr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraRemCum_Trr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraRemCum_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraRemCum_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum_Muc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraRemCum_Muc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraRemCum_Muc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraRemCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraRemCum]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraOstSel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraOstSel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraOstSel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraOstCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraOstCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraOstCum]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraOst]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraOst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraOst]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaOdp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraMovLiquidaOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraMovLiquidaOdp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaDop]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraMovLiquidaDop]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraMovLiquidaDop]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaDcc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraMovLiquidaDcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraMovLiquidaDcc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraMovLiquidaCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraMovLiquidaCau]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraMovLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraMovLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraLiqCausac_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraLiqCausac_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraLiqCausac_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraLiqCausac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraLiqCausac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraLiqCausac]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetConc_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetConc_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Leg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetConc_Leg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetConc_Leg]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Dlg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetConc_Dlg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetConc_Dlg]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Dev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetConc_Dev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetConc_Dev]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetConc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetConc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Rem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Rem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Rem]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Odp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Odp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Odp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Ocv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Ocv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Ocv]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Muc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Muc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Muc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Gtc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Gtc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Gtc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Crr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle_Crr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle_Crr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraConc_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraConc_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraConc_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraConc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraConc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraConc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraCentrega]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraCentrega]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraCentrega]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraAnt_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraAnt_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraAnt_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraAnt_Aos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraAnt_Aos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraAnt_Aos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_TraAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_TraAnt]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Tanqueos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Tanqueos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Tanqueos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Sobtasas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Sobtasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Sobtasas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ser_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Ser_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Ser_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ser_Dvn]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Ser_Dvn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Ser_Dvn]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ser]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Ser]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Ser]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Semanas_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Semanas_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Semanas_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Semanas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Semanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Semanas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Saldos_Kar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Saldos_Kar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Saldos_Kar]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Saldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ReqDetalle_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ReqDetalle_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ReqDetalle_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ReqDetalle_Mtto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ReqDetalle_Mtto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ReqDetalle_Mtto]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ReqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ReqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ReqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_RecAplica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_RecAplica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_RecAplica]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreVenceAmza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreVenceAmza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreVenceAmza]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreVence]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreVence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreVence]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PresPagos_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PresPagos_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PresPagos_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Rec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Rec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Rec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Pre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Pre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Pre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Odb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Odb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Odb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Ndb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Ndb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Ndb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Fac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Fac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Fac]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Dfa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Dfa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Dfa]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Apo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Apo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Apo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Abo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi_Abo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi_Abo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMovi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMovi]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreMora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreMora]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreIntMora_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreIntMora_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreIntMora_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreIntMora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreIntMora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreIntMora]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreFactura_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreFactura_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreFactura_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreFactura]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoRec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoRca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoRca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoRca]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPtmo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoPtmo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoPtmo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPri]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoPri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoPri]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoPre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoPra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoPra]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoOdb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoOdb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoOdb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoOda]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoOda]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoOda]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoNdb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoNdb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoNdb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoNcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoNcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoNcr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoNca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoNca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoNca]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoFif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoFif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoFif]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDpr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoDpr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoDpr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDpa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoDpa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoDpa]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDfi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoDfi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoDfi]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDfa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoDfa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoDfa]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoCuo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoCuo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoCuo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoApr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoApr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoApr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoApf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExtoApf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExtoApf]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreExto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreExto]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCuotas_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCuotas_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCuotas_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCuotas_Aza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCuotas_Aza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCuotas_Aza]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCompra_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCompra_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCompra_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Saf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCartera_Saf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCartera_Saf]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Pre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCartera_Pre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCartera_Pre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Ndb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCartera_Ndb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCartera_Ndb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Fac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCartera_Fac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCartera_Fac]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Apo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCartera_Apo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCartera_Apo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreCartera]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreCartera]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreAbonos_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreAbonos_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreAbonos_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_PreAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_PreAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Plasueldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Plasueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Plasueldos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Pagos_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Pagos_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Pagos_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Pagos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Pagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Pagos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_OccComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_OccComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_OccComp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NomRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NomRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NomRes]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina_Vac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Nomina_Vac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Nomina_Vac]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Nomina_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Nomina_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina_Liq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Nomina_Liq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Nomina_Liq]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NomHoras]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NomHoras]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NomHoras]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NivCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NivCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NivCue]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifMov_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifMov_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifMov_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifMov_Acc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifMov_Acc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifMov_Acc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifMov]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifLib]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifLib]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifLib]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifGyp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifGyp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifGyp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifGen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifGen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifGen]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_NiifCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_NiifCom]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MttoDetalle_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MttoDetalle_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MttoDetalle_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MttoDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MttoDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MttoDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovVentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovVentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovVentas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovTanques]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovInvent]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovInvent]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovCue_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovCue_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovCue_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovCue_Acc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovCue_Acc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovCue_Acc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovCue]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Rec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes_Rec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes_Rec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Odb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes_Odb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes_Odb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Ndb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes_Ndb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes_Ndb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Ncr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes_Ncr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes_Ncr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Fcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes_Fcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes_Fcr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Dfc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes_Dfc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes_Dfc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_MovClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_MovClientes]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Lot_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Lot_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Lot_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Lot_DVN]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Lot_DVN]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Lot_DVN]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Lot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Lot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Lot]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ListaPrec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ListaPrec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ListaPrec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Liquida_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Liquida_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Liquida_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Liquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Liquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Liquida]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_LibOf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_LibOf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_LibOf]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_SelDve]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex_SelDve]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex_SelDve]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_SelDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex_SelDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex_SelDev]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_Ord]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex_Ord]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex_Ord]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_NtsDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex_NtsDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex_NtsDev]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_Nts]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex_Nts]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex_Nts]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Kdex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Kdex]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_KarUbi_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_KarUbi_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_KarUbi_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_KarUbi_Dvn]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_KarUbi_Dvn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_KarUbi_Dvn]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_KarUbi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_KarUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_KarUbi]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_IntNomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_IntNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_IntNomina]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_IntAhorro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_IntAhorro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_IntAhorro]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ingresos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Ingresos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Ingresos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioPla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioPla]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioPas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioPas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioPas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioFcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioFcr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioFco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioFco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDvp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioDvp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioDvp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDnp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioDnp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioDnp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDfo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioDfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioDfo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDfc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_InfDiarioDfc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_InfDiarioDfc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ForItems_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ForItems_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ForItems_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ForItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ForItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ForItems]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_FactNeto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_FactNeto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_FactNeto]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ExtVehRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ExtVehRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ExtVehRec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ExtVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ExtVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ExtVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVrecOTR]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVrecOTR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVrecOTR]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVrecODB]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVrecODB]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVrecODB]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVrecCAR]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVrecCAR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVrecCAR]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVEstTip]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVEstTip]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVEstTip]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauNcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVcauNcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVcauNcr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauDvo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVcauDvo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVcauDvo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauDFV]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVcauDFV]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVcauDFV]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauCte]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVcauCte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVcauCte]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EVcau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EVcau]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Vce]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Vce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Vce]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Rec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Rec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Rec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Pre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Pre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Pre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Odb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Odb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Odb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Ndb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Ndb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Ndb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Ncr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Ncr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Ncr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Fvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Fvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Fvc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Dvo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Dvo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Dvo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Dfv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Dfv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Dfv]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Cc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte_Cc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte_Cc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstCueCte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstCueCte]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstClientes]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstadoGyp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EstadoGyp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EstadoGyp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EdsFormas_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EdsFormas_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas_Fac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EdsFormas_Fac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EdsFormas_Fac]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas_Cre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EdsFormas_Cre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EdsFormas_Cre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_EdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_EdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DifIngreso_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_DifIngreso_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_DifIngreso_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DifIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_DifIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_DifIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_SalDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_SalDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_SalDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Sal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Sal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Sal]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_RmtD]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_RmtD]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_RmtD]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rmt]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_RecDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_RecDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_RecDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc2Det]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rc2Det]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rc2Det]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc2]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rc2]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rc2]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc1Det]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rc1Det]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rc1Det]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc1]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Rc1]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Rc1]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_PlaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_PlaDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_PlaDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Pla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Pla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Pla]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_PdtD]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_PdtD]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_PdtD]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Pdt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Pdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Pdt]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_PasDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_PasDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_PasDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Pas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Pas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Pas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Ost]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Ost]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Ost]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Opt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Opt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Opt]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Odt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Odt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Odt]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Odp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Odp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Odp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_OdbDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_OdbDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_OdbDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Odb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Odb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Odb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od2Det]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Od2Det]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Od2Det]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od2]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Od2]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Od2]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od1Det]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Od1Det]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Od1Det]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od1]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Od1]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Od1]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_NotPre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_NotPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_NotPre]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_NotBus]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_NotBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_NotBus]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Not]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Not]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Not]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_MucD]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_MucD]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_MucD]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Muc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Muc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Muc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Lga]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Lga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Lga]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_FcrT]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_FcrT]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_FcrT]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_FcrDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_FcrDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_FcrDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Fcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Fcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Fcr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_FcoDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_FcoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_FcoDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Fco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Fco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Fco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_EntDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_EntDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_EntDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Ent]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Ent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Ent]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Egr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Egr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Egr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DvsDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DvsDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DvsDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dvs]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dvs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dvs]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DvpDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DvpDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DvpDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dvp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dvp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dvp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DveDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DveDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DveDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dve]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dve]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dve]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dvc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dva]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dva]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dva]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Drc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Drc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Drc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dop]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dop]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dop]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DnpDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DnpDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DnpDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dnp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dnp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dnp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dls]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dls]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dls]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dlg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dlg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dlg]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DfoDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DfoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DfoDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dfo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dfo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DfcT]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DfcT]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DfcT]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DfcDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_DfcDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_DfcDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dfc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dfc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dfc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dcu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dcu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dcu]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dao]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Dao]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Dao]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Cum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Cum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Cum]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Cos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Cos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Cos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Cns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Cns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Cns]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Che]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Che]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Che]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Aos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Aos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Aos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Ant]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Diario_Ant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Diario_Ant]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DetCue_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_DetCue_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_DetCue_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DetCue_Pto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_DetCue_Pto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_DetCue_Pto]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DetCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_DetCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_DetCue]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxpAplica_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxpAplica_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxpAplica_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxpAplica_Doc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxpAplica_Doc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxpAplica_Doc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxpAplica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxpAplica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxpAplica]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxPagar_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxPagar_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxPagar_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxPagar_Doc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxPagar_Doc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxPagar_Doc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxPagar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxPagar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxPagar]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxCobrar_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxCobrar_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxCobrar_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxCobrar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxCobrar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxCobrar]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxcAbonos_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxcAbonos_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxcAbonos_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxcAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CxcAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CxcAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Cuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Cuotas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Contratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Contratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Contratos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CompauAbr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CompauAbr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CompauAbr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Compau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Compau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Compau]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comp_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comp_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp_Niif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comp_Niif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comp_Niif]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp_Caj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comp_Caj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comp_Caj]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Rec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Rec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Rec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_PlaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_PlaDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_PlaDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Pla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Pla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Pla]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Odb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Odb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Odb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Ndb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Ndb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Ndb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Ncr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Ncr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Ncr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_FcrDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_FcrDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_FcrDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Fcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Fcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Fcr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_FcoDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_FcoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_FcoDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Fco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Fco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Fco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_DvpDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_DvpDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_DvpDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Dvp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Dvp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Dvp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_DfoDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_DfoDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_DfoDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Dfo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Dfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Dfo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_DfcDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_DfcDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_DfcDet]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Dfc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Comisiones_Dfc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Comisiones_Dfc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Combo_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Combo_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Combo_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Combo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Combo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Combo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_cheq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_cheq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_cheq]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ccCupones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_ccCupones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_ccCupones]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cartera_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Cartera_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Cartera_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cartera_Saf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Cartera_Saf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Cartera_Saf]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cartera]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Cartera]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Cartera]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cargos_Vce]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Cargos_Vce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Cargos_Vce]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cargos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Cargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Cargos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CajaTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_CajaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_CajaTot]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Rmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Rmt]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Rec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Rec]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Rco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Rco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rc2]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Rc2]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Rc2]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rc1]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Rc1]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Rc1]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Pla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Pla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Pla]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Pas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Pas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Pas]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Odb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Odb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Odb]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Od2]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Od2]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Od2]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Od1]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Od1]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Od1]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_NotBus]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_NotBus]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_NotBus]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Not]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Not]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Not]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Fco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Fco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Fco]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Egr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Egr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Egr]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dvp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Dvp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Dvp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Dvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Dvc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dva]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Dva]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Dva]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Drc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Drc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Drc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dnp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Dnp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Dnp]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dfo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Dfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Dfo]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dao]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Dao]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Dao]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Cns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Cns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Cns]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Aos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Aos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Aos]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Ant]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Caja_Ant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Caja_Ant]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalGen_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalGen_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalGen_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalGen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalGen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalGen]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCompara]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalCompara]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalCompara]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCom_SelAcc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalCom_SelAcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalCom_SelAcc]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCom_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalCom_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalCom_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalCom]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalAcum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_BalAcum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_BalAcum]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInvSan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInvSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInvSan]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenTanqCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelVenTanqCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelVenTanqCia]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenTanq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelVenTanq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelVenTanq]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelVenCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelVenCia]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenBodCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelVenBodCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelVenBodCia]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenBod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelVenBod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelVenBod]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelVen]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelTanq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelTanq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelTanq]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelInsBod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelInsBod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelInsBod]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelIns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelIns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelIns]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelBod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_SelBod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_SelBod]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AuxInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AuxInv]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AutTot_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AutTot_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AutTot_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AutTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AutTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AutTot]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Aportes_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Aportes_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Aportes_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Aportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_Aportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_Aportes]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfTraslado_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfTraslado_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfTraslado_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfTraslado_Dif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfTraslado_Dif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfTraslado_Dif]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfRetiro_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfRetiro_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfRetiro_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfRetiro_Dif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfRetiro_Dif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfRetiro_Dif]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfRetiro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfIngreso_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfIngreso_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfIngreso_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDepPartesSel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfDepPartesSel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfDepPartesSel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDepPartes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfDepPartes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfDepPartes]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDep_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfDep_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfDep_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDep]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfDep]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfAmt_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfAmt_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfAmt_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfAmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstm_AfAmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstm_AfAmt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposZona]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposZona]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposZona]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposTerc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposTerc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposTerc]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposTasas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposTasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposTasas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposSustento]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposSustento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposSustento]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposRespFis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposRespFis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposRespFis]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposProceso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposProceso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposProceso]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposPrend]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposPrend]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposPrend]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposPpt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposPpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposPpt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposPcnto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposPcnto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposPcnto]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposOperarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposOperarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposOperarios]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposOperac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposOperac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposOperac]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposNov]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposNom]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNivs]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposNivs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposNivs]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNat]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposNat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposNat]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMotdev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposMotdev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposMotdev]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposMot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposMot]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposMod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposMod]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMnjo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposMnjo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposMnjo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMat]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposMat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposMat]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposLub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposLub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposLub]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposLla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposLla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposLla]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposInm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposInm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposInm]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposFuel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposFuel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposFuel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposFil]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposFil]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposFil]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposEsc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposEsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposEsc]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposEnt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposDocCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposDocCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposDocCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposDocCons]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposDocCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposDocCons]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCot]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCon]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposComRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposComRes]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposComFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposComFmt]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComCons]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposComCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposComCons]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposComAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposComAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCom]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCol]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCnd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCnd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCnd]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCarga]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCarga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCarga]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposCar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposCar]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposBloq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposBloq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposBloq]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposBan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposBan]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposAdm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTiposAdm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTiposAdm]
GO
/****** Object:  StoredProcedure [dbo].[paInsTFmtos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTFmtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTFmtos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTerminales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTerminales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTerminales]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercVendedor_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercVendedor_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercVendedor_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercVendedor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercVendedor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercVendedor]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercSedes_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercSedes_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercSedes_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercSedes_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercSedes_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercSedes_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercProvee_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercProvee_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercProvee_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercProvee]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercProvee]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercPropietario_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercPropietario_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercPropietario_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercPropietario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercPropietario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercPropietario]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercOperarios_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercOperarios_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercOperarios_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTerceros_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTerceros_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTerceros_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTerceros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTerceros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTerceros]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndtores_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCndtores_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCndtores_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndtores]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCndtores]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCndtores]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndTarjetas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCndTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCndTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndReferencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCndReferencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCndReferencias]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndContrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCndContrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCndContrato]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieSaldos_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieSaldos_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieSaldos_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieRef]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieRef]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliePrestamo_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCliePrestamo_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCliePrestamo_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliePrestamo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCliePrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCliePrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliePreRef]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCliePreRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCliePreRef]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliente_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCliente_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCliente_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliente]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercCliente]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercCliente]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieLineas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieLineas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieGarant]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieGarant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieGarant]
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTercClieCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTercClieCia]
GO
/****** Object:  StoredProcedure [dbo].[paInsTaxTarifClie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTaxTarifClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTaxTarifClie]
GO
/****** Object:  StoredProcedure [dbo].[paInsTaxTarifas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTaxTarifas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTaxTarifas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTaxRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTaxRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTaxRutas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTasasIntmora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTasasIntmora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTasasIntmora]
GO
/****** Object:  StoredProcedure [dbo].[paInsTasasInteres]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTasasInteres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTasasInteres]
GO
/****** Object:  StoredProcedure [dbo].[paInsTasasDTF]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTasasDTF]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTasasDTF]
GO
/****** Object:  StoredProcedure [dbo].[paInstasas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInstasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInstasas]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifBuses]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifasServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifasServ]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasPaq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifasPaq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifasPaq]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasMasivo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifasMasivo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifasMasivo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasFletes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifasFletes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifasFletes]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasFleMay]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifasFleMay]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifasFleMay]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifasAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifasAportes]
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifAnticipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTarifAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTarifAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTanques]
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTanqSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTanqSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqDispens]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTanqDispens]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTanqDispens]
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqAforoFrac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTanqAforoFrac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTanqAforoFrac]
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqAforo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTanqAforo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTanqAforo]
GO
/****** Object:  StoredProcedure [dbo].[paInsTalleres]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTalleres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTalleres]
GO
/****** Object:  StoredProcedure [dbo].[paInsTablapor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsTablapor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsTablapor]
GO
/****** Object:  StoredProcedure [dbo].[paInsSubzonas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSubzonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSubzonas]
GO
/****** Object:  StoredProcedure [dbo].[paInsSubgruposCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSubgruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSubgruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsSubGruposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSubGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSubGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paInsSubGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSubGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSubGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paInsSubCentros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSubCentros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSubCentros]
GO
/****** Object:  StoredProcedure [dbo].[paInsSobTiposDec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSobTiposDec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSobTiposDec]
GO
/****** Object:  StoredProcedure [dbo].[paInsSobretasas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSobretasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSobretasas]
GO
/****** Object:  StoredProcedure [dbo].[paInsSobProductos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSobProductos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSobProductos]
GO
/****** Object:  StoredProcedure [dbo].[paInsSobEntidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSobEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSobEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paInsSobDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSobDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSobDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsSerMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSerMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSerMov]
GO
/****** Object:  StoredProcedure [dbo].[paInsSeriales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSeriales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSeriales]
GO
/****** Object:  StoredProcedure [dbo].[paInsSecurity]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSecurity]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSecurity]
GO
/****** Object:  StoredProcedure [dbo].[paInsSectoresEco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSectoresEco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSectoresEco]
GO
/****** Object:  StoredProcedure [dbo].[paInsSAutoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paInsSalidas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSalidas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSalidas]
GO
/****** Object:  StoredProcedure [dbo].[paInsSaiArticulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsSaiArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsSaiArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paInsRutasTramos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRutasTramos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRutasTramos]
GO
/****** Object:  StoredProcedure [dbo].[paInsRutasPlan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRutasPlan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRutasPlan]
GO
/****** Object:  StoredProcedure [dbo].[paInsRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRutas]
GO
/****** Object:  StoredProcedure [dbo].[paInsRoles]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRoles]
GO
/****** Object:  StoredProcedure [dbo].[paInsResiduosPeligrosos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsResiduosPeligrosos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsResiduosPeligrosos]
GO
/****** Object:  StoredProcedure [dbo].[paInsRequisicion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRequisicion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRequisicion]
GO
/****** Object:  StoredProcedure [dbo].[paInsReqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsReqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsReqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsReportSubPmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsReportSubPmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsReportSubPmt]
GO
/****** Object:  StoredProcedure [dbo].[paInsReportSub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsReportSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsReportSub]
GO
/****** Object:  StoredProcedure [dbo].[paInsReportFmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsReportFmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsReportFmto]
GO
/****** Object:  StoredProcedure [dbo].[paInsReport]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsReport]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsReport]
GO
/****** Object:  StoredProcedure [dbo].[paInsRemision]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRemision]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRemision]
GO
/****** Object:  StoredProcedure [dbo].[paInsRelaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRelaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRelaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsRegistro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRegistro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRegistro]
GO
/****** Object:  StoredProcedure [dbo].[paInsRegimenDian]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRegimenDian]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRegimenDian]
GO
/****** Object:  StoredProcedure [dbo].[paInsRecTanqueos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRecTanqueos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRecTanqueos]
GO
/****** Object:  StoredProcedure [dbo].[paInsRecibos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paInsRecFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRecFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRecFactura]
GO
/****** Object:  StoredProcedure [dbo].[paInsRecCheques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRecCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRecCheques]
GO
/****** Object:  StoredProcedure [dbo].[paInsRecBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paInsRecAfavor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRecAfavor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRecAfavor]
GO
/****** Object:  StoredProcedure [dbo].[paInsRangosPeso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRangosPeso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRangosPeso]
GO
/****** Object:  StoredProcedure [dbo].[paInsRadicaVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsRadicaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsRadicaVales]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntTarjetas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuntTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuntTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntProg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuntProg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuntProg]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntPremios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuntPremios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuntPremios]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuntos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuntos]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuntFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuntFormas]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntBases]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuntBases]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuntBases]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuestos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuestos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuestos]
GO
/****** Object:  StoredProcedure [dbo].[paInsPucNiif_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPucNiif_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPucNiif_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsPucNiif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPucNiif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPucNiif]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuc_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuc_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuc_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsPuc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPuc]
GO
/****** Object:  StoredProcedure [dbo].[paInsProfesiones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProfesiones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProfesiones]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdTarf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdTarf]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdSaldoUbc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdSaldoUbc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdSaldoUbc]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdProvee]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdProvee]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdProcesos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdProcesos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdProcesos]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdPrecios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdPrecios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdPrecios]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdPrecCrudo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdPrecCrudo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdPrecCrudo]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdPrecCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdPrecCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdPrecCom]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdOrden]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdOrden]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdMcias_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdMcias_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdMcias_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdMcias]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdInsumos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdInsumos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdInsumos]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdImptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdImptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdImptos]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdImpFron]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdImpFron]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdImpFron]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdEntrega]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdEntrega]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdEntrega]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdCostos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdCostos]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdConsolida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdConsolida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdConsolida]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdCombo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdCombo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdCombo]
GO
/****** Object:  StoredProcedure [dbo].[paInsProdAditivos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsProdAditivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsProdAditivos]
GO
/****** Object:  StoredProcedure [dbo].[paInsPresupuesto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPresupuesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPresupuesto]
GO
/****** Object:  StoredProcedure [dbo].[paInsPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paInsPresDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPresDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPresDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsPreCuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPreCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPreCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paInsPreCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPreCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPreCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsPolizas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paInsPlazos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPlazos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPlazos]
GO
/****** Object:  StoredProcedure [dbo].[paInsPicoPlaca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPicoPlaca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPicoPlaca]
GO
/****** Object:  StoredProcedure [dbo].[paInsPermisosRoles]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPermisosRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPermisosRoles]
GO
/****** Object:  StoredProcedure [dbo].[paInsPermisos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPermisos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPermisos]
GO
/****** Object:  StoredProcedure [dbo].[paInsPeajesTarf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPeajesTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPeajesTarf]
GO
/****** Object:  StoredProcedure [dbo].[paInsPeajesClase]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPeajesClase]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPeajesClase]
GO
/****** Object:  StoredProcedure [dbo].[paInsPeajesCat]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPeajesCat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPeajesCat]
GO
/****** Object:  StoredProcedure [dbo].[paInsPaises]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPaises]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPaises]
GO
/****** Object:  StoredProcedure [dbo].[paInsPagos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsPagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsPagos]
GO
/****** Object:  StoredProcedure [dbo].[paInsOrgTransito]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOrgTransito]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOrgTransito]
GO
/****** Object:  StoredProcedure [dbo].[paInsOpedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOpedido]
GO
/****** Object:  StoredProcedure [dbo].[paInsOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilTrasladoProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilTrasladoProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilTrasladoProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilNotas]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilMedicionesTq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilMedicionesTq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilMedicionesTq]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilMediciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilMediciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilMediciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilInventDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilInventDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilInventDev]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilInvent]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilInvent]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilGuia]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilFacturaProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilFacturaProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilFacturaProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilEntradaProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilEntradaProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilEntradaProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilEntrada]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilEntrada]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilEntrada]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDevFacProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilDevFacProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilDevFacProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDevCostos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilDevCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilDevCostos]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDevCompra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilDevCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilDevCompra]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDespClieProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilDespClieProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilDespClieProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDespClie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilDespClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilDespClie]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCostoVenProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilCostoVenProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilCostoVenProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCostoVen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilCostoVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilCostoVen]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCostos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilCostos]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCompraDesp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilCompraDesp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilCompraDesp]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCompra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilCompra]
GO
/****** Object:  StoredProcedure [dbo].[paInsOilAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOilAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOilAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paInsOcupaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOcupaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOcupaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsOCompra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOCompra]
GO
/****** Object:  StoredProcedure [dbo].[paInsOComb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsOComb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsOComb]
GO
/****** Object:  StoredProcedure [dbo].[paInsObjetosApp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsObjetosApp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsObjetosApp]
GO
/****** Object:  StoredProcedure [dbo].[paInsNovedadTra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNovedadTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNovedadTra]
GO
/****** Object:  StoredProcedure [dbo].[paInsNovedadRep]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNovedadRep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNovedadRep]
GO
/****** Object:  StoredProcedure [dbo].[paInsNotasBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNotasBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNotasBuses]
GO
/****** Object:  StoredProcedure [dbo].[paInsNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNotas]
GO
/****** Object:  StoredProcedure [dbo].[paInsNotaProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNotaProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNotaProd]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomZonasConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomZonasConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomZonasConv]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVehiculos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVacDet_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomVacDet_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomVacDet_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVacDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomVacDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomVacDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVac_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomVac_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomVac_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomVac]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomTablaRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomTablaRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomTablaRet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomSueldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomSueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomSueldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRetDet_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomRetDet_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomRetDet_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRetDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomRetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomRetDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRet_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomRet_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomRet_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomRet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRangosFsu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomRangosFsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomRangosFsu]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomProrrogas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomProrrogas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomProrrogas]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomPrest]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomPrest]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomPrest]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomPrendas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomPrendas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomPrendas]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNovedad]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomNovedad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomNovedad]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNovConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomNovConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomNovConv]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNovConc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomNovConc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomNovConc]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomNov]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomLogVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomLogVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomLogVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomLiqDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomLiqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomLiqDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomina_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomina_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomina_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomina]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomGruposConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomGruposConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomGruposConv]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomFijos]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomEstadosConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomEstadosConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomEstadosConv]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomEscalafones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomEscalafones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomEscalafones]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDotacionDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomDotacionDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomDotacionDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDotacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomDotacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomDotacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDetalle_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomDetalle_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomDetalle_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDefault]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomDefault]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomDefault]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConvenciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomConvenciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomConvenciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomConOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomConOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomConCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomConCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConcConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomConcConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomConcConv]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConAuto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomConAuto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomConAuto]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCertf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomCertf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomCertf]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCausalesRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomCausalesRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomCausalesRet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCapacitaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomCapacitaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomCapacitaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCAdmon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomCAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomCAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomBasesConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomBasesConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomBasesConv]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAutoliq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAutoliq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAutoliq]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAstncia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAstncia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAstncia]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAportante]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAportante]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAportante]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAlqTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAlqTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAlqTot]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAlqNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAlqNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAlqNov]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAlqDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAlqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAlqDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAjustesDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAjustesDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAjustesDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomActividades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomActividades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomActividades]
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNomAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNomAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInsNiifPoliticas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNiifPoliticas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNiifPoliticas]
GO
/****** Object:  StoredProcedure [dbo].[paInsNiifDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNiifDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNiifDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsNiifComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNiifComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNiifComp]
GO
/****** Object:  StoredProcedure [dbo].[paInsNERecordDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNERecordDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNERecordDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsNERecord]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsNERecord]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsNERecord]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudServicios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudServicios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudServicios]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudSecciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudSecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudSecciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudOrdenVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudOrdenVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudOrdenVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudOrdenServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudOrdenConc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudOrdenConc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudOrdenConc]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudInventario]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudEstados]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudContratos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudContNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudContNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudContNov]
GO
/****** Object:  StoredProcedure [dbo].[paInsMudArticulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMudArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMudArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoTrabajos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoTrabajos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoTrabajos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoTiposOdt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoTiposOdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoTiposOdt]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoTipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoTipos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoSistemas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoSistemas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoSistemas]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoOrdenReq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoOrdenReq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoOrdenReq]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoOrdenDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoOrdenDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoOrdenDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoOrden]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoOrden]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoInspecciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoInspecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoInspecciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoEstados]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoControles]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoControles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoControles]
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMttoConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMttoConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paInsmonedas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsmonedas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsmonedas]
GO
/****** Object:  StoredProcedure [dbo].[paInsModulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsModulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsModulos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMercancias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMercancias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMercancias]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposPoliza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayTiposPoliza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayTiposPoliza]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposBonif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayTiposBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayTiposBonif]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposBienes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayTiposBienes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayTiposBienes]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposAprob]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayTiposAprob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayTiposAprob]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayTipos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayPspto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayPspto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayPspto]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayLiqTotales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayLiqTotales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayLiqTotales]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayLiqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayLiqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayLiqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayItemsInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayItemsInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayItemsInv]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayInvmov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayInvmov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayInvmov]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayInventario]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayEstados]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayContratos]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayContDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayContDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayContDoc]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayCesion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayCesion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayCesion]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayBonif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayBonif]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayBonCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayBonCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayBonCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paInsMayAnotaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMayAnotaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMayAnotaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsMarcasLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMarcasLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMarcasLin]
GO
/****** Object:  StoredProcedure [dbo].[paInsMarcas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsMarcas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsMarcas]
GO
/****** Object:  StoredProcedure [dbo].[paInsLotMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLotMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLotMov]
GO
/****** Object:  StoredProcedure [dbo].[paInsLotes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLotes]
GO
/****** Object:  StoredProcedure [dbo].[paInsLog_Periodos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLog_Periodos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLog_Periodos]
GO
/****** Object:  StoredProcedure [dbo].[paInsLog_Nomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLog_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLog_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paInsLocalidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLocalidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLocalidades]
GO
/****** Object:  StoredProcedure [dbo].[paInsLineasCredCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLineasCredCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLineasCredCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsLineas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsLineas]
GO
/****** Object:  StoredProcedure [dbo].[paInsKarUbic]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsKarUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsKarUbic]
GO
/****** Object:  StoredProcedure [dbo].[paInsKardex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsKardex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsKardex]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurTiposRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurTiposRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurTiposRec]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurTipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurTipos]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurRecOfrecmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurRecOfrecmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurRecOfrecmto]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurReclamac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurReclamac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurReclamac]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurPreguntas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurPreguntas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurPreguntas]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurInvestiga]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurInvestiga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurInvestiga]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurInvesHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurInvesHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurInvesHis]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurEstados]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurDocumtos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurDocumtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurDocumtos]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurClaseAcc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurClaseAcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurClaseAcc]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCausales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurCausales]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCasosQtn]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurCasosQtn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurCasosQtn]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCasosHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurCasosHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurCasosHis]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCasos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurCasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurCasos]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCalifica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurCalifica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurCalifica]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurAutoridades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurAutoridades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurAutoridades]
GO
/****** Object:  StoredProcedure [dbo].[paInsJurActas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJurActas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJurActas]
GO
/****** Object:  StoredProcedure [dbo].[paInsJornadas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsJornadas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsJornadas]
GO
/****** Object:  StoredProcedure [dbo].[paInsInvFisico]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsInvFisico]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsInvFisico]
GO
/****** Object:  StoredProcedure [dbo].[paInsInvDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsInvDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsInvDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsInstalaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsInstalaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsInstalaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGuia]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposUsu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposUsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposUsu]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposRot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposRot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposRot]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposPro]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposObj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposObj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposObj]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposCli]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposCli]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposAR]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposAR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposAR]
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paInsGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatVincula]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatVincula]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatVincula]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatRetiros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatRetiros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatRetiros]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatProrratVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatProrratVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatProrratVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatProrrateos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatProrrateos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatProrrateos]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatIngresos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatIngresos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatIngresos]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevVinc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevVinc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevVinc]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevRetiros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevRetiros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevRetiros]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevProrr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevProrr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevProrr]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevAjuPror]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevAjuPror]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevAjuPror]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevAdicional]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatDevAdicional]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatDevAdicional]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAvaluos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatAvaluos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatAvaluos]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatAportes]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAjustesPror]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatAjustesPror]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatAjustesPror]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAdicionales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsGatAdicionales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsGatAdicionales]
GO
/****** Object:  StoredProcedure [dbo].[paInsFuentesPago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFuentesPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFuentesPago]
GO
/****** Object:  StoredProcedure [dbo].[paInsFormaspago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFormaspago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFormaspago]
GO
/****** Object:  StoredProcedure [dbo].[paInsFormasCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFormasCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFormasCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsFondos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFondos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFondos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFmtFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFmtFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFmtFactura]
GO
/****** Object:  StoredProcedure [dbo].[paInsFmtDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFmtDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFmtDoc]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinRecibos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinPrestGarant]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinPrestGarant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinPrestGarant]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinPrestamo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinPrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinPrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinPagos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinPagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinPagos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinNotas]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinFacturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinFactint]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinFactint]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinFactint]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinFactDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinFactDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinFactDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinDevRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinDevPre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinDevPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinDevPre]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinDevFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinDevFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinDevFac]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinConvenios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinConvenios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinConvenios]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinConcFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinConcFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinConcFactura]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldosLin_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinClieSaldosLin_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinClieSaldosLin_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldosLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinClieSaldosLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinClieSaldosLin]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldos_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinClieSaldos_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinClieSaldos_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinClieSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinClieSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCauMora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinCauMora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinCauMora]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCanAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinCanAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinCanAportes]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinAportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinAportes]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAmtza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinAmtza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinAmtza]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAlmacenes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinAlmacenes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinAlmacenes]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAfavor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinAfavor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinAfavor]
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFinAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFinAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos_Veh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFijos_Veh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFijos_Veh]
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos_Cue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFijos_Cue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFijos_Cue]
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos_Cla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFijos_Cla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFijos_Cla]
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFijos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFields]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFields]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFields]
GO
/****** Object:  StoredProcedure [dbo].[paInsFcSemanas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFcSemanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFcSemanas]
GO
/****** Object:  StoredProcedure [dbo].[paInsFcNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFcNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFcNotas]
GO
/****** Object:  StoredProcedure [dbo].[paInsFcCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFcCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFcCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsFcAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFcAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFcAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInsFactVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFactVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFactVales]
GO
/****** Object:  StoredProcedure [dbo].[paInsFacturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paInsFactcon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsFactcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsFactcon]
GO
/****** Object:  StoredProcedure [dbo].[paInsExpLicencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsExpLicencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsExpLicencias]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstratos]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoTer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoTer]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoSer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoSer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoSer]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoPro]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoOper]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoOper]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoOper]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoGuia]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoCiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstadoCiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstadoCiv]
GO
/****** Object:  StoredProcedure [dbo].[paInsEstaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEstaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEstaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsEntradas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEntradas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEntradas]
GO
/****** Object:  StoredProcedure [dbo].[paInsEntidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paInsEntArticulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEntArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEntArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmpleados_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmpleados_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmpleados_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmpleados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmpleados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmpleados]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmpaques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmpaques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmpaques]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_Parientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmp_Parientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmp_Parientes]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_ExpLaboral]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmp_ExpLaboral]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmp_ExpLaboral]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_Estudios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmp_Estudios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmp_Estudios]
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_Contrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEmp_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEmp_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrFactura_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEgrFactura_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEgrFactura_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEgrFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEgrFactura]
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrAnticipo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEgrAnticipo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEgrAnticipo]
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrAntAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEgrAntAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEgrAntAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsUnion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsUnion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsUnion]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsServicio]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsServicio]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsServicio]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsRangos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsRangos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsRangos]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsForItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsForItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsForItems]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsCortes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsCortes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsCortes]
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsCalibra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsEdsCalibra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsEdsCalibra]
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSoporteDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDocSoporteDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDocSoporteDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSoporte]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDocSoporte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDocSoporte]
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSopDevDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDocSopDevDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDocSopDevDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSopDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDocSopDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDocSopDev]
GO
/****** Object:  StoredProcedure [dbo].[paInsDocMemo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDocMemo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDocMemo]
GO
/****** Object:  StoredProcedure [dbo].[paInsDisciplinario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDisciplinario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDisciplinario]
GO
/****** Object:  StoredProcedure [dbo].[paInsDiferidos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDiferidos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDiferidos]
GO
/****** Object:  StoredProcedure [dbo].[paInsDiarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDiarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDiarios]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevVal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevVal]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevSal]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevRecBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevPla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevPla]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevPas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevPas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevPas]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevNpr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevNpr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevNpr]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevFvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevFvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevFvc]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevFcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevFcr]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevFco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevFco]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevEnt]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevCns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevCns]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsDevCaj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDevCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDevCaj]
GO
/****** Object:  StoredProcedure [dbo].[paInsDetCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDetCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDetCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paInsDespachos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paInsDesagregaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDesagregaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDesagregaciones]
GO
/****** Object:  StoredProcedure [dbo].[paInsDependencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDependencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDependencias]
GO
/****** Object:  StoredProcedure [dbo].[paInsDepartamentos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsDepartamentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsDepartamentos]
GO
/****** Object:  StoredProcedure [dbo].[paInsCtasCorrientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCtasCorrientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCtasCorrientes]
GO
/****** Object:  StoredProcedure [dbo].[paInsCotizacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCotizacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCotizacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsCorrResiduos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCorrResiduos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCorrResiduos]
GO
/****** Object:  StoredProcedure [dbo].[paInsConsigna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConsigna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConsigna]
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptosTrib]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConceptosTrib]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConceptosTrib]
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptosCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConceptosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConceptosCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptosAdmon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConceptosAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConceptosAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paInsConcDiversos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConcDiversos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConcDiversos]
GO
/****** Object:  StoredProcedure [dbo].[paInsConcDivCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsConcDivCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsConcDivCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsComprobantes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsComprobantes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsComprobantes]
GO
/****** Object:  StoredProcedure [dbo].[paInsCompGastos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCompGastos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCompGastos]
GO
/****** Object:  StoredProcedure [dbo].[paInsCompCajaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCompCajaDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCompCajaDet]
GO
/****** Object:  StoredProcedure [dbo].[paInsCompCaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCompCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCompCaja]
GO
/****** Object:  StoredProcedure [dbo].[paInsCompanias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCompanias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCompanias]
GO
/****** Object:  StoredProcedure [dbo].[paInsComFactura_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsComFactura_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsComFactura_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsComFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsComFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsComFactura]
GO
/****** Object:  StoredProcedure [dbo].[paInsComDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsComDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsComDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsCnxextna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCnxextna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCnxextna]
GO
/****** Object:  StoredProcedure [dbo].[paInsClieContado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClieContado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClieContado]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseTar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseTar]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseSub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseSub]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseRie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseRie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseRie]
GO
/****** Object:  StoredProcedure [dbo].[paInsClasePol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClasePol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClasePol]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseFon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseFon]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseDocCond]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseDocCond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseDocCond]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseDiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseDiv]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseCta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseCta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseCta]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseCapac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseCapac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseCapac]
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseBan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsClaseBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsClaseBan]
GO
/****** Object:  StoredProcedure [dbo].[paInsCheques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCheques]
GO
/****** Object:  StoredProcedure [dbo].[paInsCentrosServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCentrosServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCentrosServ]
GO
/****** Object:  StoredProcedure [dbo].[paInsCentroCosto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCentroCosto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCentroCosto]
GO
/****** Object:  StoredProcedure [dbo].[paInsCausaVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCausaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCausaVales]
GO
/****** Object:  StoredProcedure [dbo].[paInsCausacVence]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCausacVence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCausacVence]
GO
/****** Object:  StoredProcedure [dbo].[paInsCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsCargos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCargos]
GO
/****** Object:  StoredProcedure [dbo].[paInsCalndario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsCalndario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsCalndario]
GO
/****** Object:  StoredProcedure [dbo].[paInsBusClaseCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsBusClaseCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsBusClaseCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsBodUbic]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsBodUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsBodUbic]
GO
/****** Object:  StoredProcedure [dbo].[paInsBodegas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paInsBancos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsBancos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsBancos]
GO
/****** Object:  StoredProcedure [dbo].[paInsAutoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paInsAreas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAreas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAreas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAprobacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAprobacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAprobacion]
GO
/****** Object:  StoredProcedure [dbo].[paInsAlmBodegas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAlmBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAlmBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAjuInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAjuInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAjuInv]
GO
/****** Object:  StoredProcedure [dbo].[paInsAgencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAgencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAgencias]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfTiposMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfTiposMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfTiposMov]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfTiposDif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfTiposDif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfTiposDif]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfPignora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfPignora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfPignora]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfPartes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfPartes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfPartes]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovValoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfMovValoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfMovValoriza]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfMovTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfMovTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovRetiro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfMovRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfMovRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfMovIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfMovIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovimiento]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfMovimiento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfMovimiento]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMantnmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfMantnmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfMantnmto]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfLineas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfLineas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfGruposCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfGruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfGruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfEstados]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifValoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDifValoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDifValoriza]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDifTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDifTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifRetiro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDifRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDifRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifMovi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDifMovi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDifMovi]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDifIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDifIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDeprecia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDeprecia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDeprecia]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDeprecCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfDeprecCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfDeprecCom]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfClasesCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfClasesCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfClasesCue]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfCausales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfCausales]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfAmtDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfAmtDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfAmtDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfAmtComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfAmtComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfAmtComp]
GO
/****** Object:  StoredProcedure [dbo].[paInsAfAmortiza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAfAmortiza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAfAmortiza]
GO
/****** Object:  StoredProcedure [dbo].[paInsAduanas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAduanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAduanas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPropietariosUni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPropietariosUni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPropietariosUni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPropietarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPropietarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPropietarios]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamosLinCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPrestamosLinCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPrestamosLinCau]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamosLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPrestamosLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPrestamosLin]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamosCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPrestamosCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPrestamosCau]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamos_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPrestamos_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPrestamos_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuOrdenesUni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuOrdenesUni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuOrdenesUni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuOrdenes_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuOrdenes_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuOrdenes_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuOrdenes_Nit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuOrdenes_Nit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuOrdenes_Nit]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeht_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasVeht_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasVeht_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasVeh_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_Unc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasVeh_Unc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_Unc]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasVeh_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasVeh_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasNit_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasNit_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_Unf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasNit_Unf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasNit_Unf]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasNit_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasNit_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasNit_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasNit_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasNit]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasCc_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasCc_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasCc_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasCc_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasCc_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasCc_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasCc]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAux_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAux_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAux_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAux]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAux]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Veh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAge_Veh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Veh]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAge_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Unf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAge_Unf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Unf]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAge_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAge_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAge_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentasAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentasAge]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentas_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentas_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentas_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentas_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentas_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentas_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuNiifCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuNiifCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvUbicaKar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInvUbicaKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInvUbicaKar]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvUbica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInvUbica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInvUbica]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvTanquesKar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInvTanquesKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInvTanquesKar]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInvTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInvTanques]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvLotesKar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInvLotesKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInvLotesKar]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvLotes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInvLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInvLotes]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInventarioKar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInventarioKar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInventarioKar]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuInventario]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeht_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasVeht_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasVeht_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasVeh_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasVeh_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_Unc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasVeh_Unc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasVeh_Unc]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasVeh_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasVeh_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasVeh_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasVeh_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasNit_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasNit_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_Unf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasNit_Unf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasNit_Unf]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasNit_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasNit_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasNit_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasNit_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasNit]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasCc_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasCc_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasCc_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasCc_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasCc_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasCc_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasCc]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAux_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAux_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAux_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAux]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAux]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Veh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAge_Veh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAge_Veh]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAge_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAge_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Unf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAge_Unf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAge_Unf]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAge_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAge_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAge_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAge_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentasAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentasAge]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentas_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentas_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentas_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentas_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentas_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentas_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuFisCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuFisCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeht_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeht_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeht_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeht_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeht_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeht_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeh_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeh_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeh_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeh_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeh_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeh_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_Pla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeh_Pla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeh_Pla]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasNit_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasNit_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_Unf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasNit_Unf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasNit_Unf]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasNit_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasNit_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasNit_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasNit_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasNit]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasCc_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasCc_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasCc_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasCc_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasCc_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasCc_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasCc]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAux_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAux_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAux_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAux_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAux_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAux_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAux]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAux]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAge_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAge_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Unf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAge_Unf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAge_Unf]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAge_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAge_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAge_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAge_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Pla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAge_Pla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAge_Pla]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentasAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentasAge]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentas_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentas_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas_Sel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentas_Sel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentas_Sel]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas_San]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentas_San]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentas_San]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuClientesFcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuClientesFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuClientesFcr]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuClientes_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuClientes_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuClientes_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuClientes]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCajaFco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCajaFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCajaFco]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCajaBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCajaBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCajaBuses]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuCaja]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuAportesSan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuAportesSan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuAportesSan]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuAnticipos_Uni]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuAnticipos_Uni]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuAnticipos_Uni]
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuAnticipos_Nit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsAcuAnticipos_Nit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsAcuAnticipos_Nit]
GO
/****** Object:  StoredProcedure [dbo].[paInsActivos_Partes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsActivos_Partes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsActivos_Partes]
GO
/****** Object:  StoredProcedure [dbo].[paInsActivos_Anexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsActivos_Anexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsActivos_Anexo]
GO
/****** Object:  StoredProcedure [dbo].[paInsActivos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paInsActivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paInsActivos]
GO
/****** Object:  StoredProcedure [dbo].[paDelZonas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelZonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelZonas]
GO
/****** Object:  StoredProcedure [dbo].[paDelVencimientos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVencimientos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVencimientos]
GO
/****** Object:  StoredProcedure [dbo].[paDelVencAbonosSaf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVencAbonosSaf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVencAbonosSaf]
GO
/****** Object:  StoredProcedure [dbo].[paDelVencAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVencAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVencAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehTraspasos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehTraspasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehTraspasos]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehRemolq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehRemolq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehRemolq]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehPolizas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehPartes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehPartes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehPartes]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehLecturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehLecturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehLecturas]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehiculos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehConductor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehConductor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehConductor]
GO
/****** Object:  StoredProcedure [dbo].[paDelVehClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVehClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVehClientes]
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_SaldosAll]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVeh_SaldosAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVeh_SaldosAll]
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_Saldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVeh_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVeh_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_Cupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVeh_Cupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVeh_Cupos]
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_Contrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVeh_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVeh_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paDelValesRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelValesRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelValesRutas]
GO
/****** Object:  StoredProcedure [dbo].[paDelVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelVales]
GO
/****** Object:  StoredProcedure [dbo].[paDelUsucaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelUsucaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelUsucaja]
GO
/****** Object:  StoredProcedure [dbo].[paDelUsuarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelUsuarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelUsuarios]
GO
/****** Object:  StoredProcedure [dbo].[paDelUOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelUOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelUOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelUndMed]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelUndMed]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelUndMed]
GO
/****** Object:  StoredProcedure [dbo].[paDelUm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelUm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelUm]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraslados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraslados]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraRemMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraRemMcias]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemesa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraRemesa]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraRemesa]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemCntdor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraRemCntdor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraRemCntdor]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraRemAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraRemAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraReexpedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraReexpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraReexpedido]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPresItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraPresItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraPresItems]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPresAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraPresAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraPresAnt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPorteInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraPorteInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraPorteInt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPedMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraPedMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraPedMcias]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraPedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraPedido]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPedAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraPedAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraPedAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenRemesas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenRemesas]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenPago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenPago]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenManif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenManif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenManif]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenLiq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenLiq]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenCum]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraOrdenAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraOrdenAnt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifRem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraManifRem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraManifRem]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifInt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraManifInt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraManifInt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifiesto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraManifiesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraManifiesto]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraManifAnexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraManifAnexo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraLiqViajes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraLiqViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraLiqViajes]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraInfViajes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraInfViajes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraInfViajes]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraGuias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraGuias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraGuias]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraFijos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraFacRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraFacRemesas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraFacRemesas]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevReex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevReex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevReex]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevOdp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevOdp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevOdp]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevLiq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevLiq]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevLgo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevLgo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevLgo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevLeg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevLeg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevLeg]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevCum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevCum]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevCos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevCos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevCos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevCau]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevAos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevAos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevAos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDevAnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDevAnt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDespProgram]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDespProgram]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDespProgram]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDespachos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDecAduana]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraDecAduana]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraDecAduana]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCumRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraCumRemesas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraCumRemesas]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCumRadica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraCumRadica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraCumRadica]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCumplido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraCumplido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraCumplido]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraConcCausac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraConcCausac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraConcCausac]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCauDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraCauDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraCauDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraAnticipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTraAntAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTraAntAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTraAntAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Ventas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Ventas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Ventas]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_vce]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_vce]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_vce]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ValesCred]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_ValesCred]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_ValesCred]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_TraDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_TraDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_TraDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Ser]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Ser]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Ser]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Saldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Saldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Saldos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ReqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_ReqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_ReqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_RecAplica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_RecAplica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_RecAplica]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Plasueldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Plasueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Plasueldos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Pagos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Pagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Pagos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_OccComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_OccComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_OccComp]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NomRes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_NomRes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_NomRes]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NominaNom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_NominaNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_NominaNom]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NominaCon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_NominaCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_NominaCon]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NominaApo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_NominaApo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_NominaApo]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Nomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NomHoras]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_NomHoras]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_NomHoras]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovVentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_MovVentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_MovVentas]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_MovTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_MovTanques]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovInvent]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_MovInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_MovInvent]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_MovCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_MovCue]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_MovClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_MovClientes]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_LotEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_LotEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_LotEnt]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Lot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Lot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Lot]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ListaPrec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_ListaPrec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_ListaPrec]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Liquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Liquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Liquida]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_LibOf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_LibOf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_LibOf]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KdexNts]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_KdexNts]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_KdexNts]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KdexCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_KdexCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_KdexCom]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Kdex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Kdex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Kdex]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KarUbiNts]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_KarUbiNts]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_KarUbiNts]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KarUbi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_KarUbi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_KarUbi]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Ingresos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Ingresos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Ingresos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_InfDiario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_InfDiario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_InfDiario]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ForItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_ForItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_ForItems]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_EstClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_EstClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_EstClientes]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_EstadoGyp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_EstadoGyp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_EstadoGyp]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_EdsFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_EdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_EdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_DifIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_DifIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_DifIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Diario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Diario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Diario]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_DetCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_DetCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_DetCue]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxpAplica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_CxpAplica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_CxpAplica]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxPagar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_CxPagar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_CxPagar]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxCobrar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_CxCobrar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_CxCobrar]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxcAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_CxcAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_CxcAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Cuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Cuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Cuotas]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Contratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Contratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Contratos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Compau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Compau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Compau]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Comp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Comp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Comp]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Comisiones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Comisiones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Comisiones]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ComboLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_ComboLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_ComboLin]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Combo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Combo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Combo]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_cheq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_cheq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_cheq]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Cargos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Cargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Cargos]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CajaTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_CajaTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_CajaTot]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Caja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Caja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Caja]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalGen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_BalGen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_BalGen]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalCompara]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_BalCompara]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_BalCompara]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_BalCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_BalCom]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalAcum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_BalAcum]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_BalAcum]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AuxInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AuxInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AuxInv]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AutTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AutTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AutTot]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Aportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_Aportes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_Aportes]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AfTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AfTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfRetiro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AfRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AfRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AfIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AfIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfDep]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AfDep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AfDep]
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfAmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltm_AfAmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltm_AfAmt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposZona]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposZona]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposZona]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposVeh]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposTerc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposTerc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposTerc]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposSustento]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposSustento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposSustento]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposRespFis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposRespFis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposRespFis]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposProceso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposProceso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposProceso]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposPrend]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposPrend]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposPrend]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposPpt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposPpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposPpt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposPcnto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposPcnto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposPcnto]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposOperarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposOperarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposOperarios]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposOperac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposOperac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposOperac]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposNov]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposNom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposNom]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNivs]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposNivs]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposNivs]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNat]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposNat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposNat]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMotdev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposMotdev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposMotdev]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposMot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposMot]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposMod]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposMod]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMnjo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposMnjo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposMnjo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMat]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposMat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposMat]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposLub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposLub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposLub]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposLla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposLla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposLla]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposInm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposInm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposInm]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposFuel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposFuel]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposFuel]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposFil]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposFil]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposFil]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposEsc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposEsc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposEsc]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposEnt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposDocCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposDocCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposDocCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposDocCons]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposDocCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposDocCons]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCot]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCon]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposComFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposComFmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposComFmt]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposComCons]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposComCons]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposComCons]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposComAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposComAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposComAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCom]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCom]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCom]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCol]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCnd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCnd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCnd]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCarga]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCarga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCarga]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposCar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposCar]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposBloq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposBloq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposBloq]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposBan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposBan]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposAdm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTiposAdm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTiposAdm]
GO
/****** Object:  StoredProcedure [dbo].[paDelTFmtos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTFmtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTFmtos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTerminales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTerminales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTerminales]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercVendedor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercVendedor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercVendedor]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercProvee]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercProvee]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercPropietario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercPropietario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercPropietario]
GO
/****** Object:  StoredProcedure [dbo].[paDelTerceros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTerceros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTerceros]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndtores]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercCndtores]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercCndtores]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndTarjetas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercCndTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercCndTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndReferencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercCndReferencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercCndReferencias]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndContrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercCndContrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercCndContrato]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercClieVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercClieVeh]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercClieSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercClieSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieRef]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercClieRef]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercClieRef]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCliePrestamo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercCliePrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercCliePrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCliente]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercCliente]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercCliente]
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTercClieCia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTercClieCia]
GO
/****** Object:  StoredProcedure [dbo].[paDelTaxTarifClie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTaxTarifClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTaxTarifClie]
GO
/****** Object:  StoredProcedure [dbo].[paDelTaxTarifas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTaxTarifas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTaxTarifas]
GO
/****** Object:  StoredProcedure [dbo].[paDelTaxRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTaxRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTaxRutas]
GO
/****** Object:  StoredProcedure [dbo].[paDeltasas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeltasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeltasas]
GO
/****** Object:  StoredProcedure [dbo].[paDelTarifBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTarifBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTarifBuses]
GO
/****** Object:  StoredProcedure [dbo].[paDelTarifasFletes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTarifasFletes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTarifasFletes]
GO
/****** Object:  StoredProcedure [dbo].[paDelTarifAnticipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTarifAnticipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTarifAnticipos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTanques]
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTanqSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTanqSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqDispens]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTanqDispens]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTanqDispens]
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqAforoFrac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTanqAforoFrac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTanqAforoFrac]
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqAforo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTanqAforo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTanqAforo]
GO
/****** Object:  StoredProcedure [dbo].[paDelTalleres]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTalleres]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTalleres]
GO
/****** Object:  StoredProcedure [dbo].[paDelTablapor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelTablapor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelTablapor]
GO
/****** Object:  StoredProcedure [dbo].[paDelSubzonas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSubzonas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSubzonas]
GO
/****** Object:  StoredProcedure [dbo].[paDelSubgruposCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSubgruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSubgruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelSubGruposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSubGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSubGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paDelSubGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSubGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSubGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paDelSubCentros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSubCentros]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSubCentros]
GO
/****** Object:  StoredProcedure [dbo].[paDelSobTiposDec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSobTiposDec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSobTiposDec]
GO
/****** Object:  StoredProcedure [dbo].[paDelSobretasas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSobretasas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSobretasas]
GO
/****** Object:  StoredProcedure [dbo].[paDelSobProductos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSobProductos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSobProductos]
GO
/****** Object:  StoredProcedure [dbo].[paDelSobEntidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSobEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSobEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paDelSobDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSobDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSobDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelSerMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSerMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSerMov]
GO
/****** Object:  StoredProcedure [dbo].[paDelSeriales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSeriales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSeriales]
GO
/****** Object:  StoredProcedure [dbo].[paDelSecurity]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSecurity]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSecurity]
GO
/****** Object:  StoredProcedure [dbo].[paDelSectoresEco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSectoresEco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSectoresEco]
GO
/****** Object:  StoredProcedure [dbo].[paDelSAutoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paDelSalidas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSalidas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSalidas]
GO
/****** Object:  StoredProcedure [dbo].[paDelSaiArticulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelSaiArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelSaiArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paDelRutasTramos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRutasTramos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRutasTramos]
GO
/****** Object:  StoredProcedure [dbo].[paDelRutasPlan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRutasPlan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRutasPlan]
GO
/****** Object:  StoredProcedure [dbo].[paDelRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRutas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRutas]
GO
/****** Object:  StoredProcedure [dbo].[paDelRoles]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRoles]
GO
/****** Object:  StoredProcedure [dbo].[paDelRequisicionOdt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRequisicionOdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRequisicionOdt]
GO
/****** Object:  StoredProcedure [dbo].[paDelRequisicion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRequisicion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRequisicion]
GO
/****** Object:  StoredProcedure [dbo].[paDelReqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelReqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelReqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelReportSubPmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelReportSubPmt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelReportSubPmt]
GO
/****** Object:  StoredProcedure [dbo].[paDelReportSub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelReportSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelReportSub]
GO
/****** Object:  StoredProcedure [dbo].[paDelReportFmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelReportFmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelReportFmto]
GO
/****** Object:  StoredProcedure [dbo].[paDelReport]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelReport]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelReport]
GO
/****** Object:  StoredProcedure [dbo].[paDelRemision]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRemision]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRemision]
GO
/****** Object:  StoredProcedure [dbo].[paDelRelaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRelaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRelaciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelRegistro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRegistro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRegistro]
GO
/****** Object:  StoredProcedure [dbo].[paDelRegimenDian]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRegimenDian]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRegimenDian]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecTanqueos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecTanqueos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecTanqueos]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecibos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFacturaVc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecFacturaVc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecFacturaVc]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFactura_Doc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecFactura_Doc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecFactura_Doc]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFactura_Ant]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecFactura_Ant]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecFactura_Ant]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecFactura]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecCheques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecCheques]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paDelRecAfavor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRecAfavor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRecAfavor]
GO
/****** Object:  StoredProcedure [dbo].[paDelRangosPeso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRangosPeso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRangosPeso]
GO
/****** Object:  StoredProcedure [dbo].[paDelRadicaVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelRadicaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelRadicaVales]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntTarjetas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntTarjetas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntTarjetas]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntProg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntProg]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntProg]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntPremiosItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntPremiosItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntPremiosItm]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntPremios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntPremios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntPremios]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntos]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntFormasItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntFormasItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntFormasItm]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntFormas]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntBasesItm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntBasesItm]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntBasesItm]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntBases]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuntBases]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuntBases]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuestos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuestos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuestos]
GO
/****** Object:  StoredProcedure [dbo].[paDelPuc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPuc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPuc]
GO
/****** Object:  StoredProcedure [dbo].[paDelProfesiones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProfesiones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProfesiones]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdTarf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdTarf]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdSaldoUbc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdSaldoUbc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdSaldoUbc]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdSaldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdSaldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdSaldos]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdProvee]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdProvee]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdProvee]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdPrecios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdPrecios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdPrecios]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdOrden]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdOrden]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdMcias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdMcias]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdImptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdImptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdImptos]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdImpFron]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdImpFron]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdImpFron]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdEntrega]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdEntrega]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdEntrega]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdCostos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdCostos]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdConsolida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdConsolida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdConsolida]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdCombo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdCombo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdCombo]
GO
/****** Object:  StoredProcedure [dbo].[paDelProdAditivos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelProdAditivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelProdAditivos]
GO
/****** Object:  StoredProcedure [dbo].[paDelPresupuesto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPresupuesto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPresupuesto]
GO
/****** Object:  StoredProcedure [dbo].[paDelPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paDelPresDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPresDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPresDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelPreCuotasCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPreCuotasCau]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPreCuotasCau]
GO
/****** Object:  StoredProcedure [dbo].[paDelPreCuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPreCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPreCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paDelPolizas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPolizas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPolizas]
GO
/****** Object:  StoredProcedure [dbo].[paDelPlazos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPlazos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPlazos]
GO
/****** Object:  StoredProcedure [dbo].[paDelPicoPlaca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPicoPlaca]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPicoPlaca]
GO
/****** Object:  StoredProcedure [dbo].[paDelPermisosRoles]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPermisosRoles]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPermisosRoles]
GO
/****** Object:  StoredProcedure [dbo].[paDelPermisos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPermisos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPermisos]
GO
/****** Object:  StoredProcedure [dbo].[paDelPeajesTarf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPeajesTarf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPeajesTarf]
GO
/****** Object:  StoredProcedure [dbo].[paDelPeajesClase]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPeajesClase]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPeajesClase]
GO
/****** Object:  StoredProcedure [dbo].[paDelPeajesCat]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPeajesCat]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPeajesCat]
GO
/****** Object:  StoredProcedure [dbo].[paDelPaises]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPaises]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPaises]
GO
/****** Object:  StoredProcedure [dbo].[paDelPagos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelPagos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelPagos]
GO
/****** Object:  StoredProcedure [dbo].[paDelOpedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOpedido]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOpedido]
GO
/****** Object:  StoredProcedure [dbo].[paDelOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilMediciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilMediciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilMediciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilInvent]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilInvent]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilInvent]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilGuia]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilEntrada]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilEntrada]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilEntrada]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilDevCompra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilDevCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilDevCompra]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilDespClie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilDespClie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilDespClie]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilCostoVen]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilCostoVen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilCostoVen]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilCostos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilCostos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilCostos]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilCompra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilCompra]
GO
/****** Object:  StoredProcedure [dbo].[paDelOilAjustes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOilAjustes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOilAjustes]
GO
/****** Object:  StoredProcedure [dbo].[paDelOcupaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOcupaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOcupaciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelOCompra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOCompra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOCompra]
GO
/****** Object:  StoredProcedure [dbo].[paDelOComb]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelOComb]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelOComb]
GO
/****** Object:  StoredProcedure [dbo].[paDelObjetosApp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelObjetosApp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelObjetosApp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNovedadTra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNovedadTra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNovedadTra]
GO
/****** Object:  StoredProcedure [dbo].[paDelNovedadRep]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNovedadRep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNovedadRep]
GO
/****** Object:  StoredProcedure [dbo].[paDelNotasBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNotasBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNotasBuses]
GO
/****** Object:  StoredProcedure [dbo].[paDelNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNotas]
GO
/****** Object:  StoredProcedure [dbo].[paDelNotaProd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNotaProd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNotaProd]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomZonasConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomZonasConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomZonasConv]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVehiculos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomVehiculos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomVehiculos]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVacEmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomVacEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomVacEmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVacDetEmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomVacDetEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomVacDetEmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVacDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomVacDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomVacDet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomVac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomVac]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomTablaRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomTablaRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomTablaRet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomSueldos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomSueldos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomSueldos]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRetEmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomRetEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomRetEmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRetDetEmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomRetDetEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomRetDetEmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRetDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomRetDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomRetDet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomRet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRangosFsu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomRangosFsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomRangosFsu]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomProrrogas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomProrrogas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomProrrogas]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomPrest]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomPrest]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomPrest]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomPrendas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomPrendas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomPrendas]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNovedad]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomNovedad]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomNovedad]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNovConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomNovConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomNovConv]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNovCar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomNovCar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomNovCar]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomNov]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomLogVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomLogVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomLogVeh]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomLiqDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomLiqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomLiqDet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNominaPer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNominaPer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNominaPer]
GO
/****** Object:  StoredProcedure [dbo].[paDelNominaEmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNominaEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNominaEmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomina]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomGruposConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomGruposConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomGruposConv]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomFijos]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomEstadosConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomEstadosConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomEstadosConv]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomEscalafones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomEscalafones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomEscalafones]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDetallePer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomDetallePer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomDetallePer]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDetalleEmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomDetalleEmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomDetalleEmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDefault]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomDefault]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomDefault]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConvenciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomConvenciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomConvenciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomConOpciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomConOpciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomConCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomConCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConcConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomConcConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomConcConv]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConAuto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomConAuto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomConAuto]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomCertf]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomCertf]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomCertf]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomCausalesRet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomCausalesRet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomCausalesRet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomCAdmon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomCAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomCAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomBasesConv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomBasesConv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomBasesConv]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAutoliq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAutoliq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAutoliq]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAstncia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAstncia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAstncia]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAportante]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAportante]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAportante]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAlqTot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAlqTot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAlqTot]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAlqNov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAlqNov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAlqNov]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAlqDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAlqDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAlqDet]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAbonosPer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAbonosPer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAbonosPer]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAbonosLiq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAbonosLiq]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAbonosLiq]
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNomAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNomAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paDelNiifComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelNiifComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelNiifComp]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudServicios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudServicios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudServicios]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudSecciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudSecciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudSecciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudOrdenServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudOrdenServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudOrdenServ]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudInventario]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudEstados]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudContratos]
GO
/****** Object:  StoredProcedure [dbo].[paDelMudArticulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMudArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMudArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoTiposOdt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMttoTiposOdt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMttoTiposOdt]
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoTipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMttoTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMttoTipos]
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoSistemas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMttoSistemas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMttoSistemas]
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoOrden]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMttoOrden]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMttoOrden]
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMttoEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMttoEstados]
GO
/****** Object:  StoredProcedure [dbo].[paDelmonedas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelmonedas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelmonedas]
GO
/****** Object:  StoredProcedure [dbo].[paDelModulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelModulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelModulos]
GO
/****** Object:  StoredProcedure [dbo].[paDelMercancias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMercancias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMercancias]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposPoliza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayTiposPoliza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayTiposPoliza]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayTiposDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayTiposDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposBonif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayTiposBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayTiposBonif]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposBienes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayTiposBienes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayTiposBienes]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposAprob]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayTiposAprob]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayTiposAprob]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayTipos]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayPspto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayPspto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayPspto]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayLiquida]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayLiquida]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayLiqTotales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayLiqTotales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayLiqTotales]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayLiqDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayLiqDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayLiqDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayItemsInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayItemsInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayItemsInv]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayInvmov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayInvmov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayInvmov]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayInventario]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayEstados]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayContratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayContratos]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayContDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayContDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayContDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayBonif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayBonif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayBonif]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayBonCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayBonCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayBonCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paDelMayAnotaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMayAnotaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMayAnotaciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelMarcasLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMarcasLin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMarcasLin]
GO
/****** Object:  StoredProcedure [dbo].[paDelMarcas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelMarcas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelMarcas]
GO
/****** Object:  StoredProcedure [dbo].[paDelLotMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelLotMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelLotMov]
GO
/****** Object:  StoredProcedure [dbo].[paDelLotes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelLotes]
GO
/****** Object:  StoredProcedure [dbo].[paDelLog_Periodos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelLog_Periodos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelLog_Periodos]
GO
/****** Object:  StoredProcedure [dbo].[paDelLog_Nomina]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelLog_Nomina]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelLog_Nomina]
GO
/****** Object:  StoredProcedure [dbo].[paDelLocalidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelLocalidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelLocalidades]
GO
/****** Object:  StoredProcedure [dbo].[paDelLineas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelLineas]
GO
/****** Object:  StoredProcedure [dbo].[paDelKarUbic]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelKarUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelKarUbic]
GO
/****** Object:  StoredProcedure [dbo].[paDelKardex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelKardex]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelKardex]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurTiposRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurTiposRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurTiposRec]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurTipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurTipos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurTipos]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurRecOfrecmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurRecOfrecmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurRecOfrecmto]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurReclamac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurReclamac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurReclamac]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurPreguntas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurPreguntas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurPreguntas]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurInvestiga]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurInvestiga]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurInvestiga]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurInvesHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurInvesHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurInvesHis]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurEstados]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurDocumtos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurDocumtos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurDocumtos]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurClaseAcc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurClaseAcc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurClaseAcc]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCausales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurCausales]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCasosQtn]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurCasosQtn]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurCasosQtn]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCasosHis]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurCasosHis]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurCasosHis]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCasos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurCasos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurCasos]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCalifica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurCalifica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurCalifica]
GO
/****** Object:  StoredProcedure [dbo].[paDelJurAutoridades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJurAutoridades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJurAutoridades]
GO
/****** Object:  StoredProcedure [dbo].[paDelJornadas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelJornadas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelJornadas]
GO
/****** Object:  StoredProcedure [dbo].[paDelInvFisico]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelInvFisico]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelInvFisico]
GO
/****** Object:  StoredProcedure [dbo].[paDelInvDetalleEst]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelInvDetalleEst]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelInvDetalleEst]
GO
/****** Object:  StoredProcedure [dbo].[paDelInvDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelInvDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelInvDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelInstalaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelInstalaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelInstalaciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGuia]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposUsu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposUsu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposUsu]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposRot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposRot]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposRot]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposPro]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposObj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposObj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposObj]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposMcia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposMcia]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposCli]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposCli]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposCli]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposAR]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposAR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposAR]
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposAgenc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGruposAgenc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGruposAgenc]
GO
/****** Object:  StoredProcedure [dbo].[paDelGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paDelFuentesPago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFuentesPago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFuentesPago]
GO
/****** Object:  StoredProcedure [dbo].[paDelFormaspago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFormaspago]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFormaspago]
GO
/****** Object:  StoredProcedure [dbo].[paDelFormasCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFormasCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFormasCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelFondos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFondos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFondos]
GO
/****** Object:  StoredProcedure [dbo].[paDelFmtFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFmtFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFmtFactura]
GO
/****** Object:  StoredProcedure [dbo].[paDelFmtDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFmtDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFmtDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinRecibos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinRecibos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinRecibos]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinPrestamo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinPrestamo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinPrestamo]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinNotas]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinFactint]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinFactint]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinFactint]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinDevRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinDevPre]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinDevPre]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinDevPre]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinDevFac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinDevFac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinDevFac]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinCuotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinCuotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinCuotas]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinAlmacenes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinAlmacenes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinAlmacenes]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinAfavor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinAfavor]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinAfavor]
GO
/****** Object:  StoredProcedure [dbo].[paDelFinAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFinAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFinAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos_Veh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFijos_Veh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFijos_Veh]
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos_Cue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFijos_Cue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFijos_Cue]
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos_Cla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFijos_Cla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFijos_Cla]
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFijos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFijos]
GO
/****** Object:  StoredProcedure [dbo].[paDelFields]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFields]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFields]
GO
/****** Object:  StoredProcedure [dbo].[paDelFcSemanas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFcSemanas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFcSemanas]
GO
/****** Object:  StoredProcedure [dbo].[paDelFcNotas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFcNotas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFcNotas]
GO
/****** Object:  StoredProcedure [dbo].[paDelFcCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFcCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFcCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paDelFactVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFactVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFactVales]
GO
/****** Object:  StoredProcedure [dbo].[paDelFacturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFacturas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFacturas]
GO
/****** Object:  StoredProcedure [dbo].[paDelFactcon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelFactcon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelFactcon]
GO
/****** Object:  StoredProcedure [dbo].[paDelExpLicencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelExpLicencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelExpLicencias]
GO
/****** Object:  StoredProcedure [dbo].[paDeleteTercAccionistas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDeleteTercAccionistas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDeleteTercAccionistas]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstratos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstratos]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoVeh]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoTer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoTer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoTer]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoSer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoSer]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoSer]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoPro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoPro]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoOper]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoOper]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoOper]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoGuia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoGuia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoGuia]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoCiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstadoCiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstadoCiv]
GO
/****** Object:  StoredProcedure [dbo].[paDelEstaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEstaciones]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEstaciones]
GO
/****** Object:  StoredProcedure [dbo].[paDelEntradas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEntradas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEntradas]
GO
/****** Object:  StoredProcedure [dbo].[paDelEntidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEntidades]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEntidades]
GO
/****** Object:  StoredProcedure [dbo].[paDelEntArticulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEntArticulos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEntArticulos]
GO
/****** Object:  StoredProcedure [dbo].[paDelEmpleados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEmpleados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEmpleados]
GO
/****** Object:  StoredProcedure [dbo].[paDelEmpaques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEmpaques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEmpaques]
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_Parientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEmp_Parientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEmp_Parientes]
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_ExpLaboral]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEmp_ExpLaboral]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEmp_ExpLaboral]
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_Estudios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEmp_Estudios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEmp_Estudios]
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_Contrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEmp_Contrato]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEmp_Contrato]
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrFacturaDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEgrFacturaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEgrFacturaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEgrFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEgrFactura]
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrAnticipo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEgrAnticipo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEgrAnticipo]
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrAntAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEgrAntAbonos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEgrAntAbonos]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsUnion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsUnion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsUnion]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsServicio]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsServicio]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsServicio]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsRangos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsRangos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsRangos]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsFormasPla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsFormasPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsFormasPla]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsFormas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsFormas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsFormas]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsForItems]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsForItems]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsForItems]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsCortes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsCortes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsCortes]
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsCalibra]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelEdsCalibra]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelEdsCalibra]
GO
/****** Object:  StoredProcedure [dbo].[paDelDocSoporte]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDocSoporte]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDocSoporte]
GO
/****** Object:  StoredProcedure [dbo].[paDelDocSopDev]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDocSopDev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDocSopDev]
GO
/****** Object:  StoredProcedure [dbo].[paDelDocMemo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDocMemo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDocMemo]
GO
/****** Object:  StoredProcedure [dbo].[paDelDisciplinario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDisciplinario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDisciplinario]
GO
/****** Object:  StoredProcedure [dbo].[paDelDiferidos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDiferidos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDiferidos]
GO
/****** Object:  StoredProcedure [dbo].[paDelDiarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDiarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDiarios]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevVal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevVal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevVal]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevSal]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevSal]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevSal]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevRecBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevRecBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevRecBuses]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevRec]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevPla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevPla]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevPla]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevPas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevPas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevPas]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevNpr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevNpr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevNpr]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevFvc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevFvc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevFvc]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevFcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevFcr]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevFcr]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevFco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevFco]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevFco]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevEnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevEnt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevEnt]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevCns]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevCns]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevCns]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paDelDevCaj]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDevCaj]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDevCaj]
GO
/****** Object:  StoredProcedure [dbo].[paDelDetCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDetCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDetCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paDelDespachos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDespachos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDespachos]
GO
/****** Object:  StoredProcedure [dbo].[paDelDependencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDependencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDependencias]
GO
/****** Object:  StoredProcedure [dbo].[paDelDepartamentos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelDepartamentos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelDepartamentos]
GO
/****** Object:  StoredProcedure [dbo].[paDelCtasCorrientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCtasCorrientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCtasCorrientes]
GO
/****** Object:  StoredProcedure [dbo].[paDelCotizacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCotizacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCotizacion]
GO
/****** Object:  StoredProcedure [dbo].[paDelConsigna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConsigna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConsigna]
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptosTrib]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConceptosTrib]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConceptosTrib]
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptosCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConceptosCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConceptosCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptosAdmon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConceptosAdmon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConceptosAdmon]
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConceptos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConceptos]
GO
/****** Object:  StoredProcedure [dbo].[paDelConcDiversos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConcDiversos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConcDiversos]
GO
/****** Object:  StoredProcedure [dbo].[paDelConcDivCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelConcDivCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelConcDivCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelComprobantes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelComprobantes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelComprobantes]
GO
/****** Object:  StoredProcedure [dbo].[paDelCompCajaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCompCajaDet]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCompCajaDet]
GO
/****** Object:  StoredProcedure [dbo].[paDelCompCaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCompCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCompCaja]
GO
/****** Object:  StoredProcedure [dbo].[paDelCompanias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCompanias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCompanias]
GO
/****** Object:  StoredProcedure [dbo].[paDelComFacturaDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelComFacturaDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelComFacturaDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelComFacturaCmp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelComFacturaCmp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelComFacturaCmp]
GO
/****** Object:  StoredProcedure [dbo].[paDelComFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelComFactura]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelComFactura]
GO
/****** Object:  StoredProcedure [dbo].[paDelComDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelComDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelComDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelCnxextna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCnxextna]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCnxextna]
GO
/****** Object:  StoredProcedure [dbo].[paDelClieContado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClieContado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClieContado]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseTar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseTar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseTar]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseSub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseSub]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseSub]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseRie]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseRie]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseRie]
GO
/****** Object:  StoredProcedure [dbo].[paDelClasePol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClasePol]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClasePol]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseFon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseFon]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseFon]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseDocCond]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseDocCond]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseDocCond]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseDiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseDiv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseDiv]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseCta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseCta]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseCta]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseCapac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseCapac]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseCapac]
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseBan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelClaseBan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelClaseBan]
GO
/****** Object:  StoredProcedure [dbo].[paDelChequesRec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelChequesRec]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelChequesRec]
GO
/****** Object:  StoredProcedure [dbo].[paDelChequesDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelChequesDoc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelChequesDoc]
GO
/****** Object:  StoredProcedure [dbo].[paDelCheques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCheques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCheques]
GO
/****** Object:  StoredProcedure [dbo].[paDelCentrosServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCentrosServ]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCentrosServ]
GO
/****** Object:  StoredProcedure [dbo].[paDelCentroCosto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCentroCosto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCentroCosto]
GO
/****** Object:  StoredProcedure [dbo].[paDelCausaVales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCausaVales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCausaVales]
GO
/****** Object:  StoredProcedure [dbo].[paDelCausacVenceItem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCausacVenceItem]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCausacVenceItem]
GO
/****** Object:  StoredProcedure [dbo].[paDelCausacVence]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCausacVence]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCausacVence]
GO
/****** Object:  StoredProcedure [dbo].[paDelCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCausacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCausacion]
GO
/****** Object:  StoredProcedure [dbo].[paDelCargos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCargos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCargos]
GO
/****** Object:  StoredProcedure [dbo].[paDelCalndarioMes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCalndarioMes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCalndarioMes]
GO
/****** Object:  StoredProcedure [dbo].[paDelCalndario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelCalndario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelCalndario]
GO
/****** Object:  StoredProcedure [dbo].[paDelBusClaseCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelBusClaseCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelBusClaseCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelBodUbic]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelBodUbic]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelBodUbic]
GO
/****** Object:  StoredProcedure [dbo].[paDelBodegas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paDelBancos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelBancos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelBancos]
GO
/****** Object:  StoredProcedure [dbo].[paDelAutoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAutoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAutoriza]
GO
/****** Object:  StoredProcedure [dbo].[paDelAreas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAreas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAreas]
GO
/****** Object:  StoredProcedure [dbo].[paDelAprobacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAprobacion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAprobacion]
GO
/****** Object:  StoredProcedure [dbo].[paDelAlmBodegas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAlmBodegas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAlmBodegas]
GO
/****** Object:  StoredProcedure [dbo].[paDelAjuInv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAjuInv]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAjuInv]
GO
/****** Object:  StoredProcedure [dbo].[paDelAgencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAgencias]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAgencias]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfTiposMov]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfTiposMov]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfTiposMov]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfTiposDif]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfTiposDif]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfTiposDif]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfPignora]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfPignora]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfPignora]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovValoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfMovValoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfMovValoriza]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovRetiro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfMovRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfMovRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfMovIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfMovIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovimiento]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfMovimiento]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfMovimiento]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMantnmto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfMantnmto]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfMantnmto]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfLineas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfLineas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfLineas]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfGruposCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfGruposCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfGruposCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfGrupos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfGrupos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfGrupos]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfEstados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfEstados]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfEstados]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifValoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDifValoriza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDifValoriza]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifTraslado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDifTraslado]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDifTraslado]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifRetiro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDifRetiro]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDifRetiro]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifMovi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDifMovi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDifMovi]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifIngreso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDifIngreso]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDifIngreso]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDeprecia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfDeprecia]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfDeprecia]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfClasesCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfClasesCue]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfClasesCue]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfCausales]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfCausales]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfCausales]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfAmtDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfAmtDetalle]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfAmtDetalle]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfAmtComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfAmtComp]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfAmtComp]
GO
/****** Object:  StoredProcedure [dbo].[paDelAfAmortiza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAfAmortiza]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAfAmortiza]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuPropietarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuPropietarios]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuPropietarios]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuPrestamos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuPrestamos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuPrestamos]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInvUbica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuInvUbica]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuInvUbica]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInvTanques]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuInvTanques]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuInvTanques]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInvLotes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuInvLotes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuInvLotes]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInventario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuInventario]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuInventario]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCuentasVeh]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCuentasVeh]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasNit]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCuentasNit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCuentasNit]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasCc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCuentasCc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCuentasCc]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasAux]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCuentasAux]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCuentasAux]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasAge]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCuentasAge]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCuentasAge]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCuentas]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCuentas]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuClientes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuClientes]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuClientes]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCajaBuses]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCajaBuses]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCajaBuses]
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCaja]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelAcuCaja]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelAcuCaja]
GO
/****** Object:  StoredProcedure [dbo].[paDelActivos_Anexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelActivos_Anexo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelActivos_Anexo]
GO
/****** Object:  StoredProcedure [dbo].[paDelActivos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[paDelActivos]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[paDelActivos]
GO
/****** Object:  StoredProcedure [dbo].[Pa_Query]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pa_Query]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Pa_Query]
GO
/****** Object:  StoredProcedure [dbo].[Pa_InsertSelect]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pa_InsertSelect]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Pa_InsertSelect]
GO
/****** Object:  StoredProcedure [dbo].[Pa_Eliminar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pa_Eliminar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Pa_Eliminar]
GO
/****** Object:  StoredProcedure [dbo].[Pa_Agregar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pa_Agregar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Pa_Agregar]
GO
/****** Object:  StoredProcedure [dbo].[Pa_Actualizar]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pa_Actualizar]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Pa_Actualizar]
GO
/****** Object:  UserDefinedTableType [dbo].[wcfTempCausasionCuenta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'wcfTempCausasionCuenta' AND ss.name = N'dbo')
DROP TYPE [dbo].[wcfTempCausasionCuenta]
GO
/****** Object:  UserDefinedTableType [dbo].[wcfItm_TraEsDetConc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'wcfItm_TraEsDetConc' AND ss.name = N'dbo')
DROP TYPE [dbo].[wcfItm_TraEsDetConc]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehPropietarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeVehPropietarios' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeVehPropietarios]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehPolizas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeVehPolizas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeVehPolizas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehiculos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeVehiculos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeVehiculos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehConductores]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeVehConductores' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeVehConductores]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeVehAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeVehAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVeh_Contrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeVeh_Contrato' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeVeh_Contrato]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeUpdateKmVehs]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeUpdateKmVehs' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeUpdateKmVehs]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Vencimientos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Vencimientos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Vencimientos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VencAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_VencAbonos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_VencAbonos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehTraspasos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_VehTraspasos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_VehTraspasos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehNumOrden]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_VehNumOrden' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_VehNumOrden]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehLecturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_VehLecturas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_VehLecturas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehConductor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_VehConductor' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_VehConductor]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraTurn]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraTurn' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraTurn]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraTraslados]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraTraslados' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraTraslados]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraTrasladoRem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraTrasladoRem' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraTrasladoRem]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraReportes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraReportes' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraReportes]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraRemMcias' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraRemMcias]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemesa]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraRemesa' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraRemesa]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemCntdor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraRemCntdor' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraRemCntdor]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraRemAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraRemAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraPedMcias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraPedMcias' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraPedMcias]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraPedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraPedido' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraPedido]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraPedAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraPedAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraPedAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenServ' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenServ]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenOper]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenOper' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenOper]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenDet' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenDet]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenCumDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenCumDet' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenCumDet]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenCum' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenCum]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenAnt' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenAnt]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenAbo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraOrdenAbo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraOrdenAbo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraManifRem]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraManifRem' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraManifRem]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraManifiesto]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraManifiesto' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraManifiesto]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraManifAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraManifAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraManifAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraInfViajesOrd]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraInfViajesOrd' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraInfViajesOrd]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraInfViajes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraInfViajes' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraInfViajes]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspSedes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspSedes' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspSedes]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspReservaVehLista]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspReservaVehLista' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspReservaVehLista]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspReservas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspReservas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspReservas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspResDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspResDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspResDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspResAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspResAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspResAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspProgramaPers]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspProgramaPers' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspProgramaPers]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspProgramaDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspProgramaDet' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspProgramaDet]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPrograma]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspPrograma' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspPrograma]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPicoPlaca]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspPicoPlaca' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspPicoPlaca]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPedido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspPedido' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspPedido]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPedDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspPedDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspPedDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPedAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspPedAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspPedAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPasajeros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspPasajeros' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspPasajeros]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOtroSiContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspOtroSiContratos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspOtroSiContratos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOtroSi]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspOtroSi' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspOtroSi]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOrdenReservas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspOrdenReservas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspOrdenReservas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOrdenProg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspOrdenProg' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspOrdenProg]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOrdenPago]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspOrdenPago' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspOrdenPago]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspListaPasajeros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspListaPasajeros' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspListaPasajeros]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquidaOtr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspLiquidaOtr' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspLiquidaOtr]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquidaOdp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspLiquidaOdp' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspLiquidaOdp]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquidaDed]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspLiquidaDed' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspLiquidaDed]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquida]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspLiquida' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspLiquida]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuecDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspFuecDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspFuecDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuecCndtores]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspFuecCndtores' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspFuecCndtores]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuecAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspFuecAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspFuecAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuec]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspFuec' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspFuec]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFacResVehiculos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspFacResVehiculos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspFacResVehiculos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFacReservas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspFacReservas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspFacReservas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevOdp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspDevOdp' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspDevOdp]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevLiq]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspDevLiq' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspDevLiq]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspDevCum' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspDevCum]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevCau]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspDevCau' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspDevCau]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspDevAnt' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspDevAnt]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumReservas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspCumReservas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspCumReservas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumplidoProg]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspCumplidoProg' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspCumplidoProg]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumplido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspCumplido' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspCumplido]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumFacturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspCumFacturas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspCumFacturas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoVehLista]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspContratoVehLista' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspContratoVehLista]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspContratos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspContratos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoDet]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspContratoDet' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspContratoDet]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoAnexo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspContratoAnexo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspContratoAnexo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoAdendos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspContratoAdendos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspContratoAdendos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspConceptos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspConceptos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCausacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspCausacion' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspCausacion]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCauDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspCauDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspCauDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspAuxFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspAuxFactura' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspAuxFactura]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspAnticipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspAnticipos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspAnticipos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspAntAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraEspAntAbonos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraEspAntAbonos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevCum]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraDevCum' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraDevCum]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevCos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraDevCos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraDevCos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevAos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraDevAos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraDevAos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevAnt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraDevAnt' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraDevAnt]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDespProgram]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraDespProgram' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraDespProgram]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDespachos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraDespachos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraDespachos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraCumRemesas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraCumRemesas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumRadica]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraCumRadica' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraCumRadica]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumRadDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraCumRadDoc' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraCumRadDoc]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumplido]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraCumplido' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraCumplido]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraConceptos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraConceptos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraAnticipos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraAnticipos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraAnticipos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraAntAbonos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_TraAntAbonos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_TraAntAbonos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_RecAfavor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_RecAfavor' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_RecAfavor]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Pagos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Pagos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Pagos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_NiifDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_NiifDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_NiifDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_NiifCompFMsv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_NiifCompFMsv' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_NiifCompFMsv]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_NiifComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_NiifComp' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_NiifComp]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Kardex]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Kardex' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Kardex]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_FcSemanas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_FcSemanas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_FcSemanas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Facturas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Facturas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Facturas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Factcon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Factcon' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Factcon]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_EgrFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_EgrFactura' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_EgrFactura]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DocMemo]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_DocMemo' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_DocMemo]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DevFcr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_DevFcr' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_DevFcr]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DevFco]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_DevFco' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_DevFco]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DetCuentas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_DetCuentas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_DetCuentas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Comprobantes]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Comprobantes' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Comprobantes]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_ComFactura]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_ComFactura' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_ComFactura]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_ComDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_ComDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_ComDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Autoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Autoriza' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Autoriza]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Aprobacion]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTrn_Aprobacion' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTrn_Aprobacion]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraFijos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraFijos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspPolizas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraEspPolizas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraEspPolizas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspPolDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraEspPolDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraEspPolDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspObjContratos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraEspObjContratos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraEspObjContratos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspHorario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraEspHorario' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraEspHorario]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspGruposCol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraEspGruposCol' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraEspGruposCol]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspColegios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraEspColegios' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraEspColegios]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraConcCausac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTraConcCausac' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTraConcCausac]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposVehFactor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposVehFactor' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposVehFactor]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposVeh' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposVeh]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposPpt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposPpt' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposPpt]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposOperac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposOperac' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposOperac]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposNovPgr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposNovPgr' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposNovPgr]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposNivs]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposNivs' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposNivs]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposMot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposMot' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposMot]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposMod]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposMod' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposMod]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposLub]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposLub' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposLub]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposLla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposLla' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposLla]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposFuel]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposFuel' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposFuel]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposDocCons]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposDocCons' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposDocCons]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCon]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposCon' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposCon]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposComFmt]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposComFmt' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposComFmt]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposCol' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposCol]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCatLic]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposCatLic' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposCatLic]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCalendarPgr]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposCalendarPgr' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposCalendarPgr]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposAdm]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTiposAdm' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTiposAdm]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercPropietario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercPropietario' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercPropietario]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTerceros]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTerceros' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTerceros]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercDocumentos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercDocumentos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercDocumentos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndtores]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercCndtores' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercCndtores]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndTarjetas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercCndTarjetas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercCndTarjetas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndReferencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercCndReferencias' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercCndReferencias]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercCndDoc' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercCndDoc]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndContrato]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercCndContrato' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercCndContrato]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndCapac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercCndCapac' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercCndCapac]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercAccionistas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTercAccionistas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTercAccionistas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTarifasEsp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTarifasEsp' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTarifasEsp]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTablaPor]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeTablaPor' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeTablaPor]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_TiposDocCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_TiposDocCue' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_TiposDocCue]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_TiposDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_TiposDoc' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_TiposDoc]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Security]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_Security' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_Security]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Report]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_Report' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_Report]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Modulos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_Modulos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_Modulos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_GruposUsu]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_GruposUsu' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_GruposUsu]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_FmtDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_FmtDoc' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_FmtDoc]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Estaciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_Estaciones' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_Estaciones]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Cnxextna]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_Cnxextna' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_Cnxextna]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Autoriza]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeSys_Autoriza' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeSys_Autoriza]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasTramos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeRutasTramos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeRutasTramos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasRecorridos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeRutasRecorridos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeRutasRecorridos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasPlan]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeRutasPlan' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeRutasPlan]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasCliente]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeRutasCliente' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeRutasCliente]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeRutas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeRutas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRuta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeRuta' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeRuta]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeNiifDetalle]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeNiifDetalle' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeNiifDetalle]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeNiifComp]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeNiifComp' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeNiifComp]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeMcia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeMcia' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeMcia]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeMarcasLin]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeMarcasLin' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeMarcasLin]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeMarcas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeMarcas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeMarcas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraTarifas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLogTraTarifas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLogTraTarifas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspTarifas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLogTraEspTarifas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLogTraEspTarifas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspSys]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLogTraEspSys' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLogTraEspSys]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLogTraEspPro' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLogTraEspPro]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspInOut]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLogTraEspInOut' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLogTraEspInOut]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogSys]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLogSys' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLogSys]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLocalidades]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeLocalidades' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeLocalidades]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeListaPasaResProceso]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeListaPasaResProceso' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeListaPasaResProceso]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeGruposRot]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeGruposRot' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeGruposRot]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeGruposPro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeGruposPro' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeGruposPro]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeGruposCli]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeGruposCli' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeGruposCli]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos_Veh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeFijos_Veh' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeFijos_Veh]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos_Cue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeFijos_Cue' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeFijos_Cue]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos_Cla]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeFijos_Cla' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeFijos_Cla]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeFijos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeFijos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeExpLicencias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeExpLicencias' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeExpLicencias]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEstadoVeh]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeEstadoVeh' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeEstadoVeh]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEstadoTer]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeEstadoTer' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeEstadoTer]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEstadoDoc]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeEstadoDoc' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeEstadoDoc]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEdsServicio]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeEdsServicio' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeEdsServicio]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeDepartamentos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeDepartamentos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeDepartamentos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCumRemesas]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeCumRemesas' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeCumRemesas]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConceptosCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeConceptosCue' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeConceptosCue]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConceptosCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeConceptosCia' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeConceptosCia]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConceptos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeConceptos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeConceptos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConcDiversos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeConcDiversos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeConcDiversos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConcDivCue]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeConcDivCue' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeConcDivCue]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConcDivCia]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeConcDivCia' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeConcDivCia]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCompanias]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeCompanias' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeCompanias]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClieContado]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeClieContado' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeClieContado]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClasePol]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeClasePol' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeClasePol]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseDocCond]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeClaseDocCond' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeClaseDocCond]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseDiv]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeClaseDiv' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeClaseDiv]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseCta]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeClaseCta' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeClaseCta]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseCapac]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeClaseCapac' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeClaseCapac]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCentrosServ]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeCentrosServ' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeCentrosServ]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCargos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeCargos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeCargos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCalndario]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeCalndario' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeCalndario]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Usuarios]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeadm_Usuarios' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeadm_Usuarios]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_UOpciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeadm_UOpciones' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeadm_UOpciones]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Registro]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeadm_Registro' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeadm_Registro]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_PermisosRoles]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeadm_PermisosRoles' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeadm_PermisosRoles]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Permisos]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeadm_Permisos' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeadm_Permisos]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Opciones]    Script Date: 10/12/2025 8:10:23 ******/
IF  EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'dataTypeadm_Opciones' AND ss.name = N'dbo')
DROP TYPE [dbo].[dataTypeadm_Opciones]
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Opciones]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeadm_Opciones] AS TABLE(
	[IdOpc] [varchar](3) NULL,
	[Opcion] [varchar](100) NULL,
	[TipoDato] [varchar](15) NULL,
	[Valor] [varchar](100) NULL,
	[NivUp] [int] NULL,
	[nModulo] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Permisos]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeadm_Permisos] AS TABLE(
	[IdUsuario] [varchar](11) NULL,
	[IdObj] [varchar](10) NULL,
	[Consecutivo] [int] NULL,
	[PerAdd] [bit] NULL,
	[PerUpdate] [bit] NULL,
	[PerDelete] [bit] NULL,
	[PerAnular] [bit] NULL,
	[PerRead] [bit] NULL,
	[PerRename] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_PermisosRoles]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeadm_PermisosRoles] AS TABLE(
	[IdUsuario] [varchar](11) NULL,
	[IdObj] [varchar](10) NULL,
	[IdRole] [varchar](3) NULL,
	[Asignado] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Registro]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeadm_Registro] AS TABLE(
	[IdCia] [char](2) NULL,
	[TipoId] [char](1) NULL,
	[IdEmpresa] [varchar](16) NULL,
	[NitEmpresa] [varchar](16) NULL,
	[DvNit] [char](1) NULL,
	[RazonSocial] [varchar](250) NULL,
	[NitRepLegal] [varchar](16) NULL,
	[RepLegal] [varchar](150) NULL,
	[Descripcion] [varchar](250) NULL,
	[Direccion] [varchar](250) NULL,
	[Telefono] [varchar](20) NULL,
	[Fax] [varchar](20) NULL,
	[IdLocal] [varchar](8) NULL,
	[IdPais] [varchar](8) NULL,
	[e_mail] [varchar](100) NULL,
	[ArchivoLogo] [varchar](30) NULL,
	[NumeroSerial] [varchar](80) NULL,
	[Regimen] [varchar](50) NULL,
	[TipoPersna] [char](1) NULL,
	[Licencia] [varchar](20) NULL,
	[VigenciaLic] [smalldatetime] NULL,
	[Personeria] [varchar](40) NULL,
	[CIIUDane] [varchar](8) NULL,
	[Leyenda] [varchar](250) NULL,
	[FechaRegistro] [smalldatetime] NULL,
	[FechaVence] [smalldatetime] NULL,
	[CurrtyDate] [smalldatetime] NULL,
	[CurDate1] [smalldatetime] NULL,
	[FechaPrest] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_UOpciones]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeadm_UOpciones] AS TABLE(
	[IdUsuario] [varchar](11) NULL,
	[NomOpcion] [varchar](20) NULL,
	[Valor] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeadm_Usuarios]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeadm_Usuarios] AS TABLE(
	[IdUsuario] [varchar](11) NULL,
	[Usuario] [varchar](50) NULL,
	[PwdLog] [varchar](30) NULL,
	[IdGrupo] [int] NULL,
	[IdEstacion] [char](2) NULL,
	[IdCargo] [varchar](4) NULL,
	[Conectado] [bit] NULL,
	[FechaAcc] [smalldatetime] NULL,
	[FechaClave] [smalldatetime] NULL,
	[Caducidad] [int] NULL,
	[LoginSQL] [varchar](20) NULL,
	[PwdSQL] [varchar](20) NULL,
	[ModoSQL] [varchar](3) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCalndario]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeCalndario] AS TABLE(
	[FechaDia] [smalldatetime] NULL,
	[TipoFtvo] [varchar](3) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCargos]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeCargos] AS TABLE(
	[IdCargo] [varchar](4) NOT NULL,
	[Cargo] [varchar](50) NULL,
	[Funciones] [varchar](3000) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCentrosServ]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeCentrosServ] AS TABLE(
	[IdCenSer] [varchar](4) NULL,
	[CentroServ] [varchar](50) NULL,
	[DirCentro] [varchar](100) NULL,
	[IdLocal] [varchar](8) NULL,
	[Telefonos] [varchar](30) NULL,
	[TipoCentro] [varchar](10) NULL,
	[NitResp] [varchar](16) NULL,
	[Respnsable] [varchar](150) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseCapac]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeClaseCapac] AS TABLE(
	[IdClase] [varchar](4) NULL,
	[NomClase] [varchar](150) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseCta]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeClaseCta] AS TABLE(
	[IdClase] [varchar](4) NULL,
	[ClaseCuenta] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseDiv]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeClaseDiv] AS TABLE(
	[IdClase] [varchar](4) NULL,
	[NomClase] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClaseDocCond]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeClaseDocCond] AS TABLE(
	[IdDoc] [varchar](4) NULL,
	[Documento] [varchar](150) NULL,
	[Vigencia] [bit] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClasePol]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeClasePol] AS TABLE(
	[IdClase] [varchar](4) NULL,
	[ClasePoliza] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeClieContado]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeClieContado] AS TABLE(
	[IdCliente] [varchar](16) NOT NULL,
	[Nombre] [varchar](150) NOT NULL,
	[TipoId] [char](1) NOT NULL,
	[Dv] [char](1) NULL,
	[Direccion] [varchar](150) NULL,
	[IdLocal] [varchar](8) NOT NULL,
	[Telefono] [varchar](20) NOT NULL,
	[email] [varchar](100) NULL,
	[Excento] [bit] NOT NULL,
	[PosIniNom] [int] NOT NULL,
	[Inactivo] [bit] NOT NULL,
	[FechaAdd] [smalldatetime] NOT NULL,
	[FechaUpdate] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCompanias]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeCompanias] AS TABLE(
	[IdCia] [char](2) NULL,
	[Compania] [varchar](50) NULL,
	[DirInterface] [varchar](255) NULL,
	[FechaActual] [smalldatetime] NULL,
	[PeriodoActual] [smalldatetime] NULL,
	[IdCCosto] [varchar](16) NULL,
	[IdSubCos] [varchar](16) NULL,
	[IdTercero] [varchar](16) NULL,
	[CodSucsal] [varchar](10) NULL,
	[DireccSuc] [varchar](250) NULL,
	[TelefSuc] [varchar](20) NULL,
	[FaxSuc] [varchar](20) NULL,
	[IdLocal] [varchar](8) NULL,
	[TipoEDS] [varchar](10) NULL,
	[CodPlanta] [varchar](20) NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[Inactivo] [bit] NULL,
	[CodBodega] [varchar](4) NULL,
	[FecModPrest] [smalldatetime] NULL,
	[AutoIca] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConcDivCia]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeConcDivCia] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[IdCia] [char](2) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConcDivCue]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeConcDivCue] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[IdClase] [varchar](4) NULL,
	[IdCuenta] [varchar](16) NULL,
	[CdCueDev] [varchar](16) NULL,
	[TipoMov] [char](1) NULL,
	[TipoTerc] [char](1) NULL,
	[FecAdd] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConcDiversos]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeConcDiversos] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[Concepto] [varchar](250) NULL,
	[Grupo] [varchar](20) NULL,
	[EsServicio] [bit] NULL,
	[DeManfsto] [bit] NULL,
	[CdIva] [varchar](4) NULL,
	[CdRet] [varchar](4) NULL,
	[CdIca] [varchar](4) NULL,
	[CdAutoret] [varchar](4) NULL,
	[IdCueDeb] [varchar](16) NULL,
	[IdCueCre] [varchar](16) NULL,
	[Inactivo] [bit] NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[OrdenServ] [int] NULL,
	[NovedadNom] [bit] NULL,
	[CdConcDeveng] [varchar](4) NULL,
	[CdConcDed] [varchar](4) NULL,
	[RubroConc] [varchar](50) NULL,
	[MudReajuste] [varchar](50) NULL,
	[CodFEDian] [varchar](20) NULL,
	[TipoConcGat] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConceptos]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeConceptos] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[Concepto] [varchar](100) NULL,
	[IdDoc] [varchar](3) NULL,
	[IdCom] [varchar](3) NULL,
	[Vcmto] [bit] NULL,
	[Imptos] [bit] NULL,
	[Retfte] [bit] NULL,
	[RetIca] [bit] NULL,
	[Observacion] [varchar](150) NULL,
	[Pdterminado] [int] NULL,
	[TrfaSanc] [decimal](14, 4) NULL,
	[RndTotal] [int] NULL,
	[DcmtoEquiv] [bit] NULL,
	[Inactivo] [bit] NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[TipoContab] [varchar](10) NULL,
	[CdComNiif] [varchar](3) NULL,
	[CdComFiscal] [varchar](3) NULL,
	[CodCiaTdo] [char](2) NULL,
	[TipoConRev] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConceptosCia]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeConceptosCia] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[IdCia] [char](2) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeConceptosCue]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeConceptosCue] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[IdClase] [int] NULL,
	[Descripcion] [varchar](50) NULL,
	[IdCuenta] [varchar](16) NULL,
	[TipoMov] [char](1) NULL,
	[DetalleMov] [varchar](150) NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[TipoTerc] [char](1) NULL,
	[FecAdd] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeCumRemesas]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeCumRemesas] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('CUM'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[TipRem] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('01'),
	[ItemRem] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeDepartamentos]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeDepartamentos] AS TABLE(
	[IdDep] [varchar](8) NULL,
	[Departamento] [varchar](50) NULL,
	[Codigo] [varchar](4) NULL,
	[IdPais] [varchar](8) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEdsServicio]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeEdsServicio] AS TABLE(
	[IdEstacion] [varchar](4) NULL,
	[EstServicio] [varchar](50) NULL,
	[Direccion] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEstadoDoc]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeEstadoDoc] AS TABLE(
	[IdEstado] [varchar](4) NULL,
	[Estado] [varchar](50) NULL,
	[NColor] [int] NULL,
	[CodDcmto] [varchar](3) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEstadoTer]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeEstadoTer] AS TABLE(
	[IdEstado] [varchar](4) NULL,
	[Estado] [varchar](50) NULL,
	[NColor] [int] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeEstadoVeh]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeEstadoVeh] AS TABLE(
	[IdEstado] [varchar](4) NULL,
	[Estado] [varchar](50) NULL,
	[NColor] [int] NULL,
	[OutDemand] [bit] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeExpLicencias]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeExpLicencias] AS TABLE(
	[IdLugar] [varchar](8) NULL,
	[LugarLic] [varchar](50) NULL,
	[CodDpto] [varchar](8) NULL,
	[Dpto] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos]    Script Date: 10/12/2025 8:10:23 ******/
CREATE TYPE [dbo].[dataTypeFijos] AS TABLE(
	[IdCargo] [varchar](4) NULL,
	[Concepto] [varchar](100) NULL,
	[Obligatorio] [bit] NULL DEFAULT ((0)),
	[TipoAplica] [varchar](10) NULL,
	[DiasSemana] [varchar](20) NULL,
	[DiasMes] [varchar](100) NULL,
	[ValorMensual] [money] NULL DEFAULT ((0)),
	[ValorDiario] [money] NULL,
	[IdCuentaDeb] [varchar](16) NULL,
	[IdCuentaCre] [varchar](16) NULL,
	[IdCueDebVp] [varchar](16) NULL,
	[IdCueCreVp] [varchar](16) NULL,
	[NCuotas] [int] NULL DEFAULT ((0)),
	[DiasVcmto] [varchar](50) NULL,
	[OrdenAbono] [int] NULL DEFAULT ((0)),
	[TipoDcto] [char](1) NULL,
	[DctoPpago] [decimal](14, 4) NULL,
	[VrCargoAdic] [money] NULL DEFAULT ((0)),
	[FecLimiteIni] [smalldatetime] NULL,
	[FecLimiteFin] [smalldatetime] NULL,
	[Inactivo] [bit] NULL DEFAULT ((0)),
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos_Cla]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeFijos_Cla] AS TABLE(
	[IdCargo] [varchar](4) NULL,
	[IdClase] [varchar](4) NULL,
	[ValorMensual] [money] NULL,
	[ValorDiario] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos_Cue]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeFijos_Cue] AS TABLE(
	[IdCargo] [varchar](4) NULL,
	[IdAdmon] [varchar](4) NULL,
	[IdCuentaDeb] [varchar](16) NULL,
	[IdCuentaCre] [varchar](16) NULL,
	[IdCueDebVp] [varchar](16) NULL,
	[IdCueCreVp] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeFijos_Veh]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeFijos_Veh] AS TABLE(
	[IdCargo] [varchar](4) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[ValorMensual] [money] NULL,
	[ValorDiario] [money] NULL,
	[Excluir] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeGruposCli]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeGruposCli] AS TABLE(
	[IdGrupo] [varchar](4) NULL,
	[GrupoClie] [varchar](50) NULL,
	[ModApp] [varchar](10) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeGruposPro]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeGruposPro] AS TABLE(
	[IdGrupo] [varchar](4) NULL,
	[GrupoProp] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeGruposRot]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeGruposRot] AS TABLE(
	[IdGrupo] [varchar](4) NULL,
	[GrupoRot] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeListaPasaResProceso]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeListaPasaResProceso] AS TABLE(
	[IdLista] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[ItemRes] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[Fecha] [datetime] NULL,
	[IdUsuario] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLocalidades]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLocalidades] AS TABLE(
	[IdLocal] [varchar](8) NULL,
	[Localidad] [varchar](50) NULL,
	[IdDep] [varchar](8) NULL,
	[TipLocal] [varchar](20) NULL,
	[Dist_Kmt] [decimal](10, 4) NULL,
	[Time_hh] [varchar](8) NULL,
	[DistSede] [decimal](10, 4) NULL,
	[TimeSede] [varchar](8) NULL,
	[CelRow] [decimal](14, 4) NULL,
	[CelCol] [decimal](14, 4) NULL,
	[CodAlias] [varchar](10) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogSys]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLogSys] AS TABLE(
	[IdLog] [int] NOT NULL DEFAULT ((0)),
	[TipDoc] [varchar](3) NOT NULL,
	[Documento] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[Nombre] [varchar](50) NOT NULL,
	[Observacion] [varchar](250) NOT NULL,
	[IdTercero] [varchar](16) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[EsCom] [bit] NOT NULL DEFAULT ((0)),
	[Eliminado] [bit] NOT NULL DEFAULT ((0)),
	[Modificado] [bit] NOT NULL DEFAULT ((0)),
	[nModulo] [varchar](20) NOT NULL,
	[Dsname] [varchar](20) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspInOut]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLogTraEspInOut] AS TABLE(
	[IdLog] [int] NULL,
	[IdCia] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[Fecha] [smalldatetime] NULL,
	[HoraEntrada] [smalldatetime] NULL,
	[HoraSalida] [smalldatetime] NULL,
	[Finalizo] [bit] NULL,
	[Nombre] [varchar](50) NULL,
	[Dsname] [varchar](20) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspPro]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLogTraEspPro] AS TABLE(
	[IdLog] [int] NULL,
	[IdPro] [varchar](20) NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[Nombre] [varchar](50) NULL,
	[NomTabla] [varchar](20) NULL,
	[Observacion] [varchar](250) NULL,
	[nModulo] [varchar](20) NULL,
	[Dsname] [varchar](20) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspSys]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLogTraEspSys] AS TABLE(
	[IdLog] [int] NULL,
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[Nombre] [varchar](50) NULL,
	[Observacion] [varchar](250) NULL,
	[IdTercero] [varchar](16) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[EsCom] [bit] NULL DEFAULT ((0)),
	[Eliminado] [bit] NULL,
	[Modificado] [bit] NULL,
	[nModulo] [varchar](20) NULL,
	[Dsname] [varchar](20) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraEspTarifas]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLogTraEspTarifas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Numero] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[CdCarga] [varchar](16) NULL,
	[DescripCarga] [varchar](250) NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[PesoNeto] [decimal](14, 4) NULL,
	[TarifClie] [money] NULL,
	[TarifPago] [money] NULL,
	[VrTotal] [money] NULL,
	[IdUsuario] [varchar](11) NULL,
	[Nombre] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeLogTraTarifas]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeLogTraTarifas] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL,
	[Numero] [int] NOT NULL,
	[IdCia] [char](2) NOT NULL,
	[Item] [int] NOT NULL,
	[Fecha] [smalldatetime] NOT NULL,
	[IdMercancia] [varchar](16) NOT NULL,
	[DescripMcias] [varchar](250) NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL,
	[PesoNeto] [decimal](14, 4) NOT NULL,
	[Volumen] [decimal](14, 4) NOT NULL,
	[Cases] [int] NOT NULL,
	[Cajas] [int] NOT NULL,
	[Palets] [int] NOT NULL,
	[TarifClie] [money] NOT NULL,
	[TarifPago] [money] NOT NULL,
	[TarifTabla] [money] NOT NULL,
	[VrDeclarado] [money] NOT NULL,
	[VrSeguro] [money] NOT NULL,
	[TarifSeguro] [decimal](14, 4) NOT NULL,
	[UndTarifa] [varchar](10) NOT NULL,
	[TipoTarifa] [varchar](10) NOT NULL,
	[UndTarPago] [varchar](10) NOT NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[Nombre] [varchar](50) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeMarcas]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeMarcas] AS TABLE(
	[IdMarca] [varchar](4) NULL,
	[Marca] [varchar](50) NULL,
	[TipoMarca] [varchar](20) NULL,
	[CodigoMT] [varchar](10) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeMarcasLin]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeMarcasLin] AS TABLE(
	[IdLinea] [varchar](10) NULL,
	[LineaVeh] [varchar](50) NULL,
	[IdMarca] [varchar](4) NULL,
	[CodMT] [varchar](10) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeMcia]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeMcia] AS TABLE(
	[Item] [int] NOT NULL,
	[NitRemite] [varchar](16) NOT NULL,
	[Remitente] [varchar](250) NOT NULL,
	[DirOrigen] [varchar](250) NOT NULL,
	[NitDestntario] [varchar](16) NOT NULL,
	[Destinatario] [varchar](250) NOT NULL,
	[DirDestino] [varchar](250) NOT NULL,
	[SedeRem] [varchar](10) NOT NULL,
	[SedeDest] [varchar](10) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeNiifComp]    Script Date: 10/12/2025 8:10:24 ******/
CREATE TYPE [dbo].[dataTypeNiifComp] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NULL,
	[TipComCont] [varchar](3) NOT NULL,
	[ComprobanteCont] [int] NOT NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[TipoNiif] [varchar](10) NOT NULL DEFAULT ('NIIF'),
	[CtbTipo] [varchar](3) NULL,
	[CtbNumero] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeNiifDetalle]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeNiifDetalle] AS TABLE(
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NULL,
	[IdCuenta] [varchar](16) NULL,
	[Detalle] [varchar](250) NULL,
	[VrDebito] [money] NULL,
	[VrCredito] [money] NULL,
	[IdTercero] [varchar](16) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdCCosto] [varchar](16) NULL,
	[IdSubCos] [varchar](16) NULL,
	[VrBase] [money] NULL DEFAULT ((0)),
	[TarifaBase] [decimal](14, 4) NULL,
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NULL,
	[CodConce] [varchar](4) NULL,
	[NitDoc] [varchar](16) NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCiaFac] [char](2) NULL,
	[ItemFac] [int] NULL DEFAULT ((0)),
	[FecVence] [smalldatetime] NULL,
	[CodCta] [varchar](4) NULL,
	[NumCheque] [varchar](20) NULL,
	[Integrado] [bit] NULL,
	[TipoAplica] [char](1) NULL,
	[Consolida] [bit] NULL,
	[CodCargo] [varchar](4) NULL,
	[NitOtros] [varchar](16) NULL,
	[CodSubgpo] [varchar](8) NULL,
	[CiuOrigen] [varchar](8) NULL,
	[CodAgncia] [varchar](16) NULL,
	[VehPropio] [int] NULL,
	[Referncia] [varchar](50) NULL,
	[TipDocRef] [varchar](3) NULL,
	[DocRef] [int] NULL DEFAULT ((0)),
	[IdCiaRef] [char](2) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[CdConcTrib] [varchar](4) NULL,
	[CdTarifTrib] [varchar](4) NULL,
	[NumEstablec] [varchar](20) NULL,
	[PtoEmision] [varchar](20) NULL,
	[Num_Autoriza] [varchar](50) NULL,
	[FechAutoriza] [smalldatetime] NULL,
	[CodCuentaCG] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRuta]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeRuta] AS TABLE(
	[CdRutaTarif] [varchar](4) NOT NULL,
	[IdLocOrigen] [varchar](8) NOT NULL,
	[IdLocDestino] [varchar](8) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutas]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeRutas] AS TABLE(
	[IdRuta] [varchar](20) NULL,
	[Ruta] [varchar](100) NULL,
	[IdLocOri] [varchar](8) NULL,
	[IdLocDes] [varchar](8) NULL,
	[EsLocal] [bit] NULL,
	[Distkmt] [decimal](14, 4) NULL,
	[TmHoras] [varchar](8) NULL,
	[CodigoMt] [varchar](5) NULL,
	[FleteTon] [money] NULL,
	[Inactivo] [bit] NULL,
	[CdCiaTurno] [char](2) NULL,
	[PuntosRut] [decimal](14, 4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasCliente]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeRutasCliente] AS TABLE(
	[IdRuta] [varchar](4) NULL,
	[IdCliente] [varchar](16) NULL,
	[Ruta] [varchar](100) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasPlan]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeRutasPlan] AS TABLE(
	[IdRuta] [varchar](4) NULL,
	[IdPunto] [int] NULL,
	[Descripcion] [varchar](100) NULL,
	[Distancia] [decimal](14, 4) NULL,
	[Tiempo] [varchar](8) NULL,
	[ClasePto] [varchar](10) NULL,
	[CdPto] [varchar](4) NULL,
	[IdLocal] [varchar](8) NULL,
	[PosLat] [decimal](14, 4) NULL,
	[PosLon] [decimal](14, 4) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasRecorridos]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeRutasRecorridos] AS TABLE(
	[IdRuta] [varchar](4) NULL,
	[NumTramo] [int] NULL DEFAULT ((0)),
	[IdLocal] [varchar](8) NULL,
	[Detalle] [varchar](1000) NULL,
	[kmstramo] [decimal](14, 4) NULL DEFAULT ((0)),
	[kmstotal] [decimal](14, 4) NULL DEFAULT ((0)),
	[Alterno] [bit] NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeRutasTramos]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeRutasTramos] AS TABLE(
	[IdRuta] [varchar](4) NULL,
	[NumTramo] [int] NULL,
	[IdLocal] [varchar](8) NULL,
	[kmstramo] [decimal](14, 4) NULL,
	[kmstotal] [decimal](14, 4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Autoriza]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_Autoriza] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[ConceptoAut] [varchar](150) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Cnxextna]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_Cnxextna] AS TABLE(
	[IdReg] [int] NULL,
	[CnxTipo] [varchar](10) NULL,
	[CnxEngine] [varchar](10) NULL,
	[CnxDso] [varchar](250) NULL,
	[CnxDbname] [varchar](50) NULL,
	[CnxAutentic] [varchar](3) NULL,
	[CnxUid] [varchar](50) NULL,
	[CnxPwd] [varchar](50) NULL,
	[CnxOwner] [varchar](20) NULL,
	[CnxPpties] [varchar](250) NULL,
	[CnxObserv] [varchar](250) NULL,
	[CnxDriver] [varchar](100) NULL,
	[CnxPort] [varchar](30) NULL,
	[CnxTerminal] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Estaciones]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_Estaciones] AS TABLE(
	[IdEstacion] [char](2) NOT NULL,
	[Estacion] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_FmtDoc]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_FmtDoc] AS TABLE(
	[IdDoc] [varchar](3) NULL,
	[IdForma] [char](2) NULL,
	[Descripcion] [varchar](100) NULL,
	[Formato] [varchar](20) NULL,
	[Predtmnado] [bit] NULL,
	[TipoPapel] [int] NULL,
	[Orientacion] [int] NULL,
	[VistaPrevia] [bit] NULL,
	[VerSetup] [bit] NULL,
	[NumCopias] [int] NULL,
	[sp_Nombre] [varchar](50) NULL,
	[Ind_Location] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_GruposUsu]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_GruposUsu] AS TABLE(
	[IdGrupo] [int] NOT NULL DEFAULT ((0)),
	[Grupo] [varchar](50) NULL,
	[Descripcion] [varchar](100) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Modulos]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_Modulos] AS TABLE(
	[IdMod] [varchar](3) NULL,
	[Consecutivo] [int] NULL,
	[Descripcion] [varchar](50) NULL,
	[Valor] [bit] NULL,
	[nModulo] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Report]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_Report] AS TABLE(
	[TipoRep] [varchar](3) NULL,
	[IdRep] [char](2) NULL,
	[Descripcion] [varchar](100) NULL,
	[Formato] [varchar](20) NULL,
	[TipoPapel] [int] NULL,
	[Orientacion] [int] NULL,
	[VistaPrevia] [bit] NULL,
	[VerSetup] [bit] NULL,
	[NumCopias] [int] NULL,
	[sp_Nombre] [varchar](50) NULL,
	[Ind_Location] [varchar](50) NULL,
	[NomRep] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_Security]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_Security] AS TABLE(
	[IdLla] [int] NULL DEFAULT ((0)),
	[Descripcion] [varchar](50) NULL,
	[Pwd] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_TiposDoc]    Script Date: 10/12/2025 8:10:25 ******/
CREATE TYPE [dbo].[dataTypeSys_TiposDoc] AS TABLE(
	[IdDoc] [varchar](3) NULL,
	[TipoDoc] [varchar](50) NULL,
	[ConsUnico] [bit] NULL DEFAULT ((0)),
	[Leyenda] [varchar](250) NULL,
	[Inactivo] [bit] NULL DEFAULT ((0)),
	[IntegraCias] [bit] NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeSys_TiposDocCue]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeSys_TiposDocCue] AS TABLE(
	[IdDoc] [varchar](3) NULL,
	[IdClase] [int] NULL DEFAULT ((0)),
	[ClaseCuenta] [varchar](50) NULL,
	[TipoMov] [char](1) NULL DEFAULT ('N')
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTablaPor]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTablaPor] AS TABLE(
	[IdTarifa] [varchar](4) NULL,
	[Descripcion] [varchar](50) NULL,
	[IdClase] [varchar](4) NULL,
	[Tarifa] [decimal](16, 6) NULL,
	[Simbolo] [char](1) NULL,
	[CdLocdad] [varchar](8) NULL,
	[Minimo] [money] NULL,
	[Maximo] [money] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTarifasEsp]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTarifasEsp] AS TABLE(
	[Numero] [int] NULL,
	[CdRuta] [varchar](4) NULL,
	[IdOrigen] [varchar](8) NULL,
	[IdDestino] [varchar](8) NULL,
	[TipoTarifa] [varchar](10) NULL,
	[CdTipoVeh] [varchar](4) NULL,
	[TipAfilVeh] [varchar](10) NULL,
	[Kilometros] [decimal](16, 4) NULL,
	[TarifClie] [money] NULL,
	[TarifPago] [money] NULL,
	[IdMneda] [varchar](5) NULL,
	[Inactivo] [bit] NULL DEFAULT ((0)),
	[FechaCrea] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[VrDia] [money] NULL,
	[Horas] [int] NULL,
	[Nit] [varchar](16) NULL,
	[VrMonitor] [decimal](18, 0) NULL,
	[TarifaXRuta] [bit] NULL DEFAULT ((1))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercAccionistas]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercAccionistas] AS TABLE(
	[IdTercero] [varchar](16) NULL,
	[NitAccionista] [varchar](16) NULL,
	[NomAccionista] [varchar](150) NULL,
	[Participacion] [decimal](14, 4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndCapac]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercCndCapac] AS TABLE(
	[IdConductor] [varchar](16) NULL,
	[Item] [int] NULL,
	[IdClase] [varchar](4) NULL,
	[Fecha] [smalldatetime] NULL,
	[FecVence] [smalldatetime] NULL,
	[Habilitado] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndContrato]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercCndContrato] AS TABLE(
	[NumContrato] [int] NULL,
	[IdConductor] [varchar](16) NULL,
	[IdTipCon] [varchar](4) NULL,
	[IdModd] [varchar](4) NULL,
	[FecIngreso] [smalldatetime] NULL,
	[FecRetiro] [smalldatetime] NULL,
	[FecVigencia] [smalldatetime] NULL,
	[Observaciones] [varchar](250) NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndDoc]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercCndDoc] AS TABLE(
	[IdConductor] [varchar](16) NULL,
	[Item] [int] NULL,
	[IdDoc] [varchar](4) NULL,
	[Fecha] [smalldatetime] NULL,
	[FecVence] [smalldatetime] NULL,
	[Radicado] [bit] NULL,
	[Descripcion] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndReferencias]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercCndReferencias] AS TABLE(
	[IdConductor] [varchar](16) NULL,
	[Item] [int] NULL,
	[TipoRef] [varchar](10) NULL,
	[EmpresaRef] [varchar](150) NULL,
	[NitRef] [varchar](16) NULL,
	[DireccionRef] [varchar](150) NULL,
	[TelefonoRef] [varchar](30) NULL,
	[ContactoRef] [varchar](150) NULL,
	[EmailRef] [varchar](100) NULL,
	[CargoRef] [varchar](50) NULL,
	[CuentaBanco] [varchar](30) NULL,
	[FechaInicial] [smalldatetime] NULL,
	[FechaFinal] [smalldatetime] NULL,
	[Verificado] [varchar](150) NULL,
	[ObservRef] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndTarjetas]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercCndTarjetas] AS TABLE(
	[IdConductor] [varchar](16) NULL,
	[Item] [int] NULL,
	[NumeroTarj] [varchar](30) NULL,
	[Secuencia] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[FecVence] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercCndtores]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercCndtores] AS TABLE(
	[IdConductor] [varchar](16) NULL,
	[IdGrupo] [varchar](4) NULL,
	[IdModd] [varchar](4) NULL,
	[TipoSangre] [char](2) NULL,
	[FactorRh] [char](1) NULL,
	[FecNacmto] [smalldatetime] NULL,
	[LugarNacmto] [varchar](30) NULL,
	[Sexo] [char](1) NULL,
	[IdEstCivil] [varchar](4) NULL,
	[NHijos] [int] NULL,
	[LibMilitar] [varchar](25) NULL,
	[ClaseLib] [int] NULL,
	[FechaLib] [smalldatetime] NULL,
	[DistMil] [varchar](10) NULL,
	[CertJudicial] [varchar](25) NULL,
	[FecJudicial] [smalldatetime] NULL,
	[VigJudicial] [smalldatetime] NULL,
	[Pasporte] [varchar](25) NULL,
	[VigPaspte] [smalldatetime] NULL,
	[Licencia] [varchar](25) NULL,
	[IdLugar] [varchar](8) NULL,
	[CatLicencia] [int] NULL,
	[FecLicencia] [smalldatetime] NULL,
	[VigLicencia] [smalldatetime] NULL,
	[IdClase] [varchar](4) NULL,
	[NumCuenta] [varchar](30) NULL,
	[IdBanco] [varchar](4) NULL,
	[CdLocCue] [varchar](8) NULL,
	[CdFonPen] [varchar](8) NULL,
	[CdFonEps] [varchar](8) NULL,
	[CdFonArp] [varchar](8) NULL,
	[pVehiculo] [varchar](10) NULL,
	[PathFoto] [varchar](30) NULL,
	[PathFirma] [varchar](30) NULL,
	[PathLic] [varchar](30) NULL,
	[Cmntarios] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[Inactivo] [bit] NULL,
	[NumTarjeta] [varchar](30) NULL,
	[EdicTarjeta] [int] NULL,
	[FecTarjeta] [smalldatetime] NULL,
	[VigTarjeta] [smalldatetime] NULL,
	[PasSeguridad] [varchar](30) NULL,
	[FecPasSeg] [smalldatetime] NULL,
	[VigPasSeg] [smalldatetime] NULL,
	[NitEmpTrans] [varchar](16) NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[Num_Contrato] [int] NULL,
	[Contrato_Activo] [bit] NULL,
	[CdTipCon] [varchar](4) NULL,
	[Fec_Ingreso] [smalldatetime] NULL,
	[Fec_Retiro] [smalldatetime] NULL,
	[Fec_Vigencia] [smalldatetime] NULL,
	[Fec_IngresoAnt] [smalldatetime] NULL,
	[Fec_UltimoAcc] [smalldatetime] NULL,
	[PasadoJudicial] [varchar](250) NULL,
	[Restriccion] [varchar](50) NULL,
	[FecPagoPen] [smalldatetime] NULL,
	[FecPagoEps] [smalldatetime] NULL,
	[FecPagoArp] [smalldatetime] NULL,
	[CdTipoOper] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercDocumentos]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTercDocumentos] AS TABLE(
	[IdTercero] [varchar](16) NULL,
	[Documento] [varchar](500) NULL,
	[CodDoc] [varchar](4) NULL,
	[Item] [int] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTerceros]    Script Date: 10/12/2025 8:10:26 ******/
CREATE TYPE [dbo].[dataTypeTerceros] AS TABLE(
	[IdTercero] [varchar](16) NULL,
	[RazonSocial] [varchar](250) NULL,
	[Codigo] [varchar](16) NULL,
	[TipoId] [char](1) NULL,
	[Dv] [char](1) NULL,
	[NomCial] [varchar](250) NULL,
	[SiglaRaz] [varchar](50) NULL,
	[Direccion] [varchar](250) NULL,
	[IdLocal] [varchar](8) NULL,
	[Telefono] [varchar](20) NULL,
	[Fax] [varchar](20) NULL,
	[TelMovil] [varchar](20) NULL,
	[SitioWeb] [varchar](100) NULL,
	[e_mail] [varchar](100) NULL,
	[EsCliente] [bit] NULL,
	[EsVendedor] [bit] NULL,
	[EsConductor] [bit] NULL,
	[EsPropietario] [bit] NULL,
	[EsProveedor] [bit] NULL,
	[EsEmpleado] [bit] NULL,
	[EsOperario] [bit] NULL,
	[EsAccnista] [bit] NULL,
	[EsCiaAseg] [bit] NULL,
	[EsCliePres] [bit] NULL,
	[IdSector] [varchar](8) NULL,
	[IdProf] [varchar](4) NULL,
	[IdRegimen] [varchar](4) NULL,
	[TipEnte] [char](1) NULL,
	[IdLugarCed] [varchar](8) NULL,
	[FecExpCed] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IniStgNom] [int] NULL,
	[IdEstado] [varchar](4) NULL,
	[Inactivo] [bit] NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[ImgFoto] [varchar](30) NULL,
	[ImgFirma] [varchar](30) NULL,
	[ImagenDoc1] [varchar](50) NULL,
	[ImagenDoc2] [varchar](50) NULL,
	[ImagenDoc3] [varchar](50) NULL,
	[FechaNac] [smalldatetime] NULL,
	[IdEstOper] [varchar](4) NULL,
	[IdLocUbic] [varchar](8) NULL,
	[DescUbicac] [varchar](150) NULL,
	[CdGrupoTerc] [varchar](4) NULL,
	[RegimenFE] [bit] NULL,
	[PN_RUT] [bit] NULL DEFAULT ((0)),
	[RecPublicos] [bit] NULL DEFAULT ((0)),
	[CargoPublico] [varchar](50) NULL,
	[FecInicioCP] [smalldatetime] NULL,
	[FecFinalCp] [smalldatetime] NULL,
	[PersonaPub] [bit] NULL DEFAULT ((0)),
	[CargoPersPub] [varchar](50) NULL,
	[FecInicioPP] [smalldatetime] NULL,
	[FecFinalPP] [smalldatetime] NULL,
	[VrIngresos] [money] NULL DEFAULT ((0)),
	[VrOtroIng] [money] NULL DEFAULT ((0)),
	[VrGastos] [money] NULL DEFAULT ((0)),
	[VrActivos] [money] NULL DEFAULT ((0)),
	[VrPasivos] [money] NULL DEFAULT ((0)),
	[VrPatrimonio] [money] NULL DEFAULT ((0)),
	[ConcOtrosIng] [varchar](250) NULL,
	[OperActVirtual] [bit] NULL DEFAULT ((0)),
	[TipoOperVirtual] [varchar](150) NULL,
	[LavadoActivos] [bit] NULL DEFAULT ((0)),
	[RL_Nombre] [varchar](150) NULL,
	[RL_Identificacion] [varchar](16) NULL,
	[RL_Direccion] [varchar](250) NULL,
	[RL_CodCiudad] [varchar](8) NULL,
	[RL_Telefono] [varchar](20) NULL,
	[RL_Email] [varchar](150) NULL,
	[Asociado] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTercPropietario]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTercPropietario] AS TABLE(
	[IdPropietario] [varchar](16) NULL,
	[IdGrupo] [varchar](4) NULL,
	[CupoCredito] [money] NULL,
	[SaldoActual] [money] NULL,
	[Avala] [bit] NULL,
	[IdAdmon] [varchar](4) NULL,
	[IdTipCon] [varchar](4) NULL,
	[ContratoActivo] [bit] NULL,
	[FecIngreso] [smalldatetime] NULL,
	[FecRetiro] [smalldatetime] NULL,
	[FecVigencia] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposAdm]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposAdm] AS TABLE(
	[IdAdmon] [varchar](4) NULL,
	[TipoAdmon] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCalendarPgr]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposCalendarPgr] AS TABLE(
	[Codigo] [varchar](3) NULL,
	[Dias] [varchar](100) NULL,
	[Inactivo] [bit] NULL,
	[IncFestivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCatLic]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposCatLic] AS TABLE(
	[IdCateg] [int] NULL DEFAULT ((0)),
	[CategMT] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCol]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposCol] AS TABLE(
	[IdColor] [varchar](4) NULL,
	[NomColor] [varchar](50) NULL,
	[NColor] [int] NULL,
	[Inactivo] [bit] NULL,
	[CodigoMT] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposComFmt]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposComFmt] AS TABLE(
	[IdCom] [varchar](3) NULL,
	[IdForma] [char](2) NULL,
	[Descripcion] [varchar](100) NULL,
	[Formato] [varchar](20) NULL,
	[Predtmnado] [bit] NULL,
	[TipoPapel] [int] NULL,
	[Orientacion] [int] NULL,
	[VistaPrevia] [bit] NULL,
	[VerSetup] [bit] NULL,
	[NumCopias] [int] NULL,
	[sp_Nombre] [varchar](50) NULL,
	[Ind_Location] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposCon]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposCon] AS TABLE(
	[IdTipCon] [varchar](4) NULL,
	[TipoContrato] [varchar](100) NULL,
	[Duracion] [int] NULL,
	[Inactivo] [bit] NULL,
	[VincLabUgpp] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposDocCons]    Script Date: 10/12/2025 8:10:27 ******/
CREATE TYPE [dbo].[dataTypeTiposDocCons] AS TABLE(
	[IdDoc] [varchar](3) NULL,
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[LDesde] [int] NULL DEFAULT ((0)),
	[LHasta] [int] NULL DEFAULT ((0)),
	[Resolucion] [varchar](30) NULL,
	[RangoNum] [varchar](50) NULL,
	[FechaRes] [smalldatetime] NULL,
	[Prefijo] [varchar](5) NULL,
	[Numero] [int] NULL DEFAULT ((0)),
	[NumManual] [bit] NULL DEFAULT ((0)),
	[IntLotes] [bit] NULL DEFAULT ((0)),
	[ConfigFecha] [varchar](10) NULL,
	[Formato] [varchar](20) NULL,
	[TipoPapel] [int] NULL DEFAULT ((1)),
	[Orientacion] [int] NULL DEFAULT ((1)),
	[VistaPrevia] [bit] NULL DEFAULT ((0)),
	[VerSetup] [bit] NULL DEFAULT ((0)),
	[NumCopias] [int] NULL DEFAULT ((1)),
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[FechaVigRes] [smalldatetime] NULL,
	[ClaveTecDian] [varchar](250) NULL,
	[CodResol] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposFuel]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposFuel] AS TABLE(
	[IdCom] [varchar](4) NULL,
	[TipoComb] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposLla]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposLla] AS TABLE(
	[IdTlla] [varchar](4) NULL,
	[TipoLlanta] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposLub]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposLub] AS TABLE(
	[IdLub] [varchar](4) NULL,
	[TipoLub] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposMod]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposMod] AS TABLE(
	[IdModd] [varchar](4) NULL,
	[Modalidad] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposMot]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposMot] AS TABLE(
	[IdTipoMot] [varchar](4) NULL,
	[TipoMotor] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposNivs]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposNivs] AS TABLE(
	[IdNiv] [varchar](4) NULL,
	[NivelServicio] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposNovPgr]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposNovPgr] AS TABLE(
	[IdNovedad] [varchar](4) NULL,
	[Novedad] [varchar](50) NULL,
	[Tipo] [varchar](20) NULL,
	[IdEstado] [varchar](4) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposOperac]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposOperac] AS TABLE(
	[IdTipoOper] [varchar](4) NULL,
	[TipoOperacion] [varchar](50) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposPpt]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposPpt] AS TABLE(
	[IdPpd] [varchar](4) NULL,
	[TipoProp] [varchar](50) NULL,
	[VehPropio] [bit] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposVeh]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposVeh] AS TABLE(
	[IdTipoVeh] [varchar](4) NULL,
	[TipoVehiculo] [varchar](50) NULL,
	[Configuracion] [varchar](6) NULL,
	[Ejes] [int] NULL,
	[Llantas] [int] NULL,
	[CapacPeso] [decimal](14, 4) NULL,
	[UndCapac] [varchar](10) NULL,
	[CapacVol] [decimal](14, 4) NULL,
	[UndCapVol] [varchar](10) NULL,
	[CubAlto] [decimal](14, 4) NULL,
	[CubLargo] [decimal](14, 4) NULL,
	[CubAncho] [decimal](14, 4) NULL,
	[PesoBruto] [decimal](14, 4) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTiposVehFactor]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTiposVehFactor] AS TABLE(
	[IdTipoVeh] [varchar](4) NULL,
	[nSemana] [int] NULL,
	[TarifaFc] [decimal](14, 4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraConcCausac]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraConcCausac] AS TABLE(
	[IdConcepto] [varchar](4) NULL,
	[Concepto] [varchar](250) NULL,
	[IdCuenta] [varchar](16) NULL,
	[TipoConc] [varchar](10) NULL DEFAULT ('CTACOBRAR'),
	[Inactivo] [bit] NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspColegios]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraEspColegios] AS TABLE(
	[IdColegio] [varchar](4) NULL,
	[NomColegio] [varchar](500) NULL,
	[IdGrupo] [varchar](4) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspGruposCol]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraEspGruposCol] AS TABLE(
	[IdGrupo] [varchar](4) NULL,
	[Grupo] [varchar](250) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspHorario]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraEspHorario] AS TABLE(
	[IdHorario] [varchar](3) NULL,
	[Item] [int] NULL,
	[Inicio] [varchar](5) NULL,
	[Final] [varchar](5) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspObjContratos]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraEspObjContratos] AS TABLE(
	[IdObj] [varchar](4) NULL,
	[Objeto] [varchar](500) NULL,
	[Predtminado] [bit] NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspPolDetalle]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraEspPolDetalle] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('CPL'),
	[NumDoc] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL,
	[IdVehiculo] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraEspPolizas]    Script Date: 10/12/2025 8:10:28 ******/
CREATE TYPE [dbo].[dataTypeTraEspPolizas] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('CPL'),
	[NumDoc] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NULL,
	[FechaExp] [smalldatetime] NULL,
	[FechaVence] [smalldatetime] NULL,
	[TipoPol] [varchar](3) NULL,
	[IdProv] [varchar](16) NULL,
	[NumPoliza] [varchar](16) NULL DEFAULT ('0'),
	[VrPoliza] [money] NULL DEFAULT ((0)),
	[VrCobro] [money] NULL DEFAULT ((0)),
	[IdTipoVeh] [varchar](4) NULL,
	[TipoAfil] [varchar](10) NULL,
	[Todos] [bit] NULL DEFAULT ((0)),
	[OnlyActivos] [bit] NULL DEFAULT ((0)),
	[IdVehiculo] [varchar](10) NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipCom] [varchar](3) NOT NULL DEFAULT ('0'),
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL DEFAULT ('00'),
	[NCuotasOtros] [int] NOT NULL DEFAULT ((0)),
	[NCuotasSocios] [int] NOT NULL DEFAULT ((0)),
	[IdMneda] [varchar](5) NULL DEFAULT ('COP'),
	[OrigenAdd] [varchar](10) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[Inactivo] [bit] NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTraFijos]    Script Date: 10/12/2025 8:10:29 ******/
CREATE TYPE [dbo].[dataTypeTraFijos] AS TABLE(
	[Numero] [int] NULL DEFAULT ((0)),
	[IdConcepto] [varchar](4) NULL,
	[DescConc] [varchar](250) NULL,
	[TipoConc] [varchar](10) NULL,
	[Tarifa] [decimal](14, 4) NULL DEFAULT ((0)),
	[TipoTarif] [char](1) NULL DEFAULT ('%'),
	[TipoAfilVeh] [varchar](10) NULL DEFAULT ('0'),
	[CdTipoVeh] [varchar](4) NULL DEFAULT ('0'),
	[TipoTerc] [char](1) NULL DEFAULT ('N'),
	[Anulado] [bit] NULL DEFAULT ((0)),
	[CdCiuOrigen] [varchar](8) NULL,
	[CdCiuDestino] [varchar](8) NULL,
	[pVehiculo] [varchar](10) NULL,
	[CedConductor] [varchar](16) NULL,
	[CdRuta] [varchar](4) NULL,
	[TipoVigencia] [char](1) NULL,
	[FechaInicial] [smalldatetime] NULL,
	[FechaFinal] [smalldatetime] NULL,
	[NitCliente] [varchar](16) NULL,
	[CdMercancia] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Aprobacion]    Script Date: 10/12/2025 8:10:30 ******/
CREATE TYPE [dbo].[dataTypeTrn_Aprobacion] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Aprobacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[TipoPed] [varchar](3) NULL,
	[Pedido] [int] NULL,
	[IdCiaPed] [char](2) NULL,
	[FecPedido] [smalldatetime] NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[VrCupoCred] [money] NULL,
	[VrSaldoAct] [money] NULL,
	[ChequesDev] [bit] NULL,
	[ClienteMora] [bit] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[Tabla] [varchar](250) NULL,
	[ColTabla] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Autoriza]    Script Date: 10/12/2025 8:10:30 ******/
CREATE TYPE [dbo].[dataTypeTrn_Autoriza] AS TABLE(
	[TipAut] [varchar](3) NULL,
	[Autoriza] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[NumAutoriza] [int] NULL,
	[IdUsuarioAut] [varchar](11) NULL,
	[IdEstacion] [char](2) NULL,
	[NitTercero] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[TipoDoc] [varchar](3) NULL,
	[Documento] [int] NULL,
	[IdCiaDoc] [char](2) NULL,
	[FechaDoc] [smalldatetime] NULL,
	[DocRef] [int] NULL DEFAULT ((0)),
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[VrAprobado] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_ComDetalle]    Script Date: 10/12/2025 8:10:30 ******/
CREATE TYPE [dbo].[dataTypeTrn_ComDetalle] AS TABLE(
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NOT NULL,
	[IdCuenta] [varchar](16) NOT NULL,
	[Detalle] [varchar](250) NOT NULL,
	[VrDebito] [money] NOT NULL DEFAULT ((0)),
	[VrCredito] [money] NOT NULL DEFAULT ((0)),
	[IdTercero] [varchar](16) NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL DEFAULT ('0'),
	[IdCCosto] [varchar](16) NOT NULL,
	[IdSubCos] [varchar](16) NOT NULL,
	[VrBase] [money] NOT NULL DEFAULT ((0)),
	[TarifaBase] [decimal](10, 4) NOT NULL DEFAULT ((0)),
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NULL DEFAULT ('01'),
	[CodConce] [varchar](4) NULL,
	[NitDoc] [varchar](16) NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCiaFac] [char](2) NULL DEFAULT ('01'),
	[ItemFac] [int] NOT NULL DEFAULT ((0)),
	[FecVence] [smalldatetime] NOT NULL,
	[CodCta] [varchar](4) NULL,
	[NumCheque] [varchar](20) NULL,
	[Integrado] [bit] NOT NULL DEFAULT ((0)),
	[TipoAplica] [char](1) NOT NULL DEFAULT ('N'),
	[Consolida] [bit] NOT NULL DEFAULT ((0)),
	[CodCargo] [varchar](4) NULL,
	[NitOtros] [varchar](16) NULL,
	[CodSubgpo] [varchar](8) NULL,
	[CiuOrigen] [varchar](8) NULL,
	[CodAgncia] [varchar](16) NOT NULL DEFAULT ('0'),
	[VehPropio] [int] NOT NULL DEFAULT ((0)),
	[Referncia] [varchar](50) NULL,
	[TipDocRef] [varchar](3) NULL,
	[DocRef] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRef] [char](2) NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[CdConcTrib] [varchar](4) NULL,
	[CdTarifTrib] [varchar](4) NULL,
	[NumEstablec] [varchar](20) NULL,
	[PtoEmision] [varchar](20) NULL,
	[Num_Autoriza] [varchar](50) NULL,
	[FechAutoriza] [smalldatetime] NULL,
	[CdCuentaNiif] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_ComFactura]    Script Date: 10/12/2025 8:10:31 ******/
CREATE TYPE [dbo].[dataTypeTrn_ComFactura] AS TABLE(
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL DEFAULT ((1)),
	[IdProveedor] [varchar](16) NULL,
	[IdCuenta] [varchar](16) NULL,
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NULL DEFAULT ('01'),
	[FecEmision] [smalldatetime] NULL,
	[FecVence] [smalldatetime] NULL,
	[VrFactura] [money] NULL DEFAULT ((0)),
	[VrAbonado] [money] NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL DEFAULT ((0)),
	[ItemCom] [int] NULL DEFAULT ((0)),
	[Referencia] [varchar](50) NULL,
	[Detalle] [varchar](100) NULL,
	[pVehiculo] [varchar](10) NULL,
	[VehPropio] [bit] NULL DEFAULT ((0)),
	[TipRef] [varchar](3) NULL,
	[DocRef] [int] NULL DEFAULT ((0)),
	[IdCiaRef] [char](2) NULL,
	[EstadoApr] [int] NULL DEFAULT ((0)),
	[MontoAprob] [money] NOT NULL DEFAULT ((0)),
	[FecProgPago] [smalldatetime] NULL,
	[ObservAprob] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Comprobantes]    Script Date: 10/12/2025 8:10:32 ******/
CREATE TYPE [dbo].[dataTypeTrn_Comprobantes] AS TABLE(
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdTercero] [varchar](16) NOT NULL,
	[VrTotal] [money] NOT NULL DEFAULT ((0)),
	[IdCta] [varchar](4) NOT NULL,
	[EnEfectivo] [bit] NOT NULL DEFAULT ((0)),
	[NumCheque] [varchar](20) NULL,
	[FecCheque] [smalldatetime] NULL,
	[TipDoc] [varchar](3) NOT NULL,
	[Documento] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NOT NULL,
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[NumDev] [int] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[TipEgr] [varchar](3) NULL,
	[NEgreso] [int] NOT NULL DEFAULT ((0)),
	[pVehiculo] [varchar](10) NULL,
	[VehPropio] [int] NOT NULL DEFAULT ((0)),
	[CedCondtor] [varchar](16) NULL,
	[CodConce] [varchar](4) NULL,
	[Beneficiario] [varchar](150) NULL,
	[VrDivisa1] [money] NOT NULL DEFAULT ((0)),
	[VrDivisa2] [money] NOT NULL DEFAULT ((0)),
	[VrDivisa3] [money] NOT NULL DEFAULT ((0)),
	[PermEditar] [bit] NOT NULL DEFAULT ((0)),
	[Integrado] [bit] NOT NULL DEFAULT ((0)),
	[EsEgreso] [bit] NOT NULL DEFAULT ((0)),
	[Anticipo] [bit] NOT NULL DEFAULT ((0)),
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[Propddes] [varchar](50) NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[CdSustento] [varchar](4) NULL,
	[Tipo_Pago] [varchar](10) NULL,
	[Establec] [varchar](20) NULL,
	[PEmision] [varchar](20) NULL,
	[Autorizac] [varchar](50) NULL,
	[FechaAut] [smalldatetime] NULL,
	[NiifTipo] [varchar](3) NULL,
	[NiifNumero] [int] NOT NULL DEFAULT ((0)),
	[FisTipo] [varchar](3) NULL,
	[FisNumero] [int] NOT NULL DEFAULT ((0)),
	[DocSoporte] [int] NOT NULL DEFAULT ((0)),
	[CodRes] [varchar](4) NULL,
	[DescServicio] [varchar](500) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DetCuentas]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_DetCuentas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL,
	[IdCia] [char](2) NULL,
	[Concepto] [varchar](10) NULL,
	[Item] [int] NULL,
	[IdCuenta] [varchar](16) NULL,
	[Valor] [money] NULL,
	[Detalle] [varchar](150) NULL,
	[IdTercero] [varchar](16) NULL,
	[CodAgncia] [varchar](16) NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[VrBase] [money] NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCiaFac] [char](2) NULL,
	[ItemFac] [int] NULL,
	[FecVence] [smalldatetime] NULL,
	[Cheque] [varchar](20) NULL,
	[CiuOrigen] [varchar](8) NULL,
	[Referencia] [varchar](50) NULL,
	[VrTarifa] [decimal](14, 4) NULL,
	[TipoTarif] [char](1) NULL,
	[CodConc] [varchar](4) NULL,
	[CodTarif] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DevFco]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_DevFco] AS TABLE(
	[TipDev] [varchar](3) NULL,
	[Devolucion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipDoc] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaDoc] [char](2) NULL,
	[FecDoc] [smalldatetime] NULL,
	[nClieCon] [varchar](16) NULL,
	[VrSubTotal] [money] NULL,
	[VrDescuento] [money] NULL,
	[VrImpuesto] [money] NULL,
	[VrRetencion] [money] NULL,
	[VrReteICA] [money] NULL,
	[VrReteIVA] [money] NULL,
	[VrFletes] [money] NULL,
	[VrCargos] [money] NULL,
	[VrOtrDcto] [money] NULL,
	[VrCostos] [money] NULL,
	[VrNeto] [money] NULL,
	[VrEfectivo] [money] NULL,
	[VrPagosOtr] [money] NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[CantPuntos] [decimal](14, 4) NULL,
	[BaseImp] [money] NULL,
	[BaseRet] [money] NULL,
	[IdCajero] [varchar](11) NULL,
	[IdVend] [varchar](16) NULL,
	[TarifaCom] [decimal](14, 4) NULL,
	[CodTarCom] [varchar](4) NULL,
	[NitCliente] [varchar](16) NULL,
	[CdAgencia] [varchar](16) NULL,
	[IdCCosto] [varchar](16) NULL,
	[IdSubCos] [varchar](16) NULL,
	[IdLocal] [varchar](8) NULL,
	[EnEfectivo] [bit] NULL,
	[Pedido] [int] NULL,
	[IdCiaPed] [char](2) NULL,
	[Remision] [int] NULL,
	[IdCiaRem] [char](2) NULL,
	[FecPedido] [smalldatetime] NULL,
	[Modalidad] [varchar](10) NULL,
	[ModdDev] [varchar](10) NULL,
	[NumAutoriza] [int] NULL,
	[PlacaVehic] [varchar](10) NULL,
	[KmtVehic] [int] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[VrImpCons] [money] NULL,
	[VrReteCREE] [money] NULL,
	[TarifaRtc] [decimal](14, 4) NULL,
	[CodTarRtc] [varchar](4) NULL,
	[BaseIvaObsq] [money] NULL,
	[VrIvaObsequio] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DevFcr]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_DevFcr] AS TABLE(
	[TipDev] [varchar](3) NOT NULL,
	[Devolucion] [int] NOT NULL,
	[IdCia] [char](2) NOT NULL,
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipDoc] [varchar](3) NOT NULL,
	[Factura] [int] NOT NULL,
	[IdCiaDoc] [char](2) NOT NULL,
	[FecDoc] [smalldatetime] NOT NULL,
	[IdCliente] [varchar](16) NOT NULL,
	[IdAgencia] [varchar](16) NOT NULL,
	[VrSubTotal] [money] NOT NULL,
	[VrDescuento] [money] NOT NULL,
	[VrImpuesto] [money] NOT NULL,
	[VrRetencion] [money] NOT NULL,
	[VrReteICA] [money] NOT NULL,
	[VrReteIVA] [money] NOT NULL,
	[VrFletes] [money] NOT NULL,
	[VrOtros] [money] NOT NULL,
	[VrCargos] [money] NOT NULL,
	[VrOtrDcto] [money] NOT NULL,
	[VrCostos] [money] NOT NULL,
	[VrSobretasa] [money] NOT NULL,
	[VrImpGlobal] [money] NOT NULL,
	[VrFaltantes] [money] NOT NULL,
	[VrAnticipos] [money] NOT NULL,
	[VrNeto] [money] NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL,
	[CantPuntos] [decimal](14, 4) NOT NULL,
	[BaseImp] [money] NOT NULL,
	[BaseRet] [money] NOT NULL,
	[IdCCosto] [varchar](16) NOT NULL,
	[IdSubCos] [varchar](16) NOT NULL,
	[IdVend] [varchar](16) NOT NULL,
	[TarifaCom] [decimal](14, 4) NOT NULL,
	[CodTarCom] [varchar](4) NULL,
	[IdLocEnv] [varchar](8) NOT NULL,
	[Pedido] [int] NOT NULL,
	[IdCiaPed] [char](2) NOT NULL,
	[Remision] [int] NOT NULL,
	[IdCiaRem] [char](2) NOT NULL,
	[Cotizacion] [int] NOT NULL,
	[IdCiaCot] [char](2) NOT NULL,
	[FecPedido] [smalldatetime] NULL,
	[Modalidad] [varchar](10) NOT NULL,
	[ModdDev] [varchar](10) NOT NULL,
	[PlacaVehic] [varchar](10) NULL,
	[KmtVehic] [int] NOT NULL,
	[ZonaFrontera] [int] NOT NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL,
	[IdCiaCom] [char](2) NOT NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[VrImpCons] [money] NOT NULL,
	[VrReteCREE] [money] NOT NULL,
	[TarifaRtc] [decimal](14, 4) NOT NULL,
	[CodTarRtc] [varchar](4) NULL,
	[BaseIvaObsq] [money] NOT NULL,
	[VrIvaObsequio] [money] NOT NULL,
	[VrImpCarbono] [money] NOT NULL,
	[DevMasivo] [int] NOT NULL,
	[NumRecibo] [int] NOT NULL,
	[CdCiaRec] [char](2) NULL,
	[CdMotDev] [varchar](4) NULL,
	[BaseIvaIgp] [money] NOT NULL,
	[VrIvaIngProd] [money] NOT NULL,
	[TarifaArf] [decimal](14, 4) NOT NULL,
	[VrAutRetFte] [money] NOT NULL,
	[TarifaAri] [decimal](14, 4) NOT NULL,
	[VrAutRetIca] [money] NOT NULL,
	[VrImpuBA] [money] NOT NULL,
	[VrImpuCUP] [money] NOT NULL,
	[ImpAviTab] [money] NULL,
	[TarifaAvta] [decimal](14, 4) NULL,
	[VrBomberil] [money] NULL,
	[TarifaBom] [decimal](14, 4) NULL,
	[VrAutRetIat] [money] NULL,
	[VrAutRetBom] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_DocMemo]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_DocMemo] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL,
	[IdCia] [char](2) NULL,
	[Comentarios] [varchar](6500) NULL,
	[Nota1] [varchar](500) NULL,
	[Nota2] [varchar](500) NULL,
	[Nota3] [varchar](500) NULL,
	[CantImp] [int] NULL,
	[ArchivoImg] [varchar](150) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_EgrFactura]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_EgrFactura] AS TABLE(
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCiaFac] [char](2) NULL,
	[ItemFac] [int] NULL,
	[IdProveedor] [varchar](16) NULL,
	[IdCuenta] [varchar](16) NULL,
	[VrAbono] [money] NULL,
	[EsEgreso] [bit] NULL,
	[ItemCom] [int] NULL,
	[pVehiculo] [varchar](10) NULL,
	[VehPropio] [bit] NULL,
	[TipDev] [varchar](3) NULL,
	[NumDev] [int] NULL,
	[DetAbono] [varchar](100) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Factcon]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_Factcon] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[nClieCon] [varchar](16) NULL,
	[VrSubTotal] [money] NULL,
	[VrDescuento] [money] NULL,
	[VrImpuesto] [money] NULL,
	[VrRetencion] [money] NULL,
	[VrReteICA] [money] NULL,
	[VrReteIVA] [money] NULL,
	[VrFletes] [money] NULL,
	[VrCargos] [money] NULL,
	[VrOtrDcto] [money] NULL,
	[VrCostos] [money] NULL,
	[VrNeto] [money] NULL,
	[VrEfectivo] [money] NULL,
	[VrPagosOtr] [money] NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[CantPuntos] [decimal](14, 4) NULL,
	[PuntosAcum] [decimal](14, 4) NULL,
	[BaseImp] [money] NULL,
	[BaseRet] [money] NULL,
	[BaseIca] [money] NULL,
	[BaseRiv] [money] NULL,
	[TarifaIva] [decimal](14, 4) NULL,
	[TarifaRet] [decimal](14, 4) NULL,
	[TarifaIca] [decimal](14, 4) NULL,
	[TarifaRiv] [decimal](14, 4) NULL,
	[CodTarIva] [varchar](4) NULL,
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[CodTarRiv] [varchar](4) NULL,
	[IdCajero] [varchar](11) NULL,
	[IdVend] [varchar](16) NULL,
	[TarifaCom] [decimal](14, 4) NULL,
	[CodTarCom] [varchar](4) NULL,
	[NitCliente] [varchar](16) NULL,
	[CdAgencia] [varchar](16) NULL,
	[IdCCosto] [varchar](16) NULL,
	[IdSubCos] [varchar](16) NULL,
	[IdLocal] [varchar](8) NULL,
	[EnEfectivo] [bit] NULL,
	[CdForma] [varchar](4) NULL,
	[NumForma] [varchar](20) NULL,
	[DetallePago] [varchar](250) NULL,
	[Referncia1] [varchar](50) NULL,
	[Referncia2] [varchar](50) NULL,
	[CdBanco] [varchar](4) NULL,
	[TipPed] [varchar](3) NULL,
	[Pedido] [int] NULL,
	[IdCiaPed] [char](2) NULL,
	[TipRem] [varchar](3) NULL,
	[Remision] [int] NULL,
	[IdCiaRem] [char](2) NULL,
	[FecPedido] [smalldatetime] NULL,
	[Modalidad] [varchar](10) NULL,
	[PlacaVehic] [varchar](10) NULL,
	[KmtVehic] [int] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Anulado] [bit] NULL,
	[NumDev] [int] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[VrImpCons] [money] NULL,
	[VrReteCREE] [money] NULL,
	[TarifaRtc] [decimal](14, 4) NULL,
	[CodTarRtc] [varchar](4) NULL,
	[BaseIvaObsq] [money] NULL,
	[VrIvaObsequio] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Facturas]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_Facturas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL,
	[FechaVence] [smalldatetime] NULL,
	[VrSubTotal] [money] NULL,
	[VrDescuento] [money] NULL,
	[VrImpuesto] [money] NULL,
	[VrRetencion] [money] NULL,
	[VrReteICA] [money] NULL,
	[VrReteIVA] [money] NULL,
	[VrFletes] [money] NULL,
	[VrOtros] [money] NULL,
	[VrCargos] [money] NULL,
	[VrOtrDcto] [money] NULL,
	[VrCostos] [money] NULL,
	[VrSobretasa] [money] NULL,
	[VrImpGlobal] [money] NULL,
	[VrFaltantes] [money] NULL,
	[VrAnticipos] [money] NULL,
	[VrNeto] [money] NULL,
	[VrAplicado] [money] NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[CantPuntos] [decimal](14, 4) NULL,
	[PuntosAcum] [decimal](14, 4) NULL,
	[BaseImp] [money] NULL,
	[BaseRet] [money] NULL,
	[BaseIca] [money] NULL,
	[BaseRiv] [money] NULL,
	[TarifaIva] [decimal](14, 4) NULL,
	[TarifaRet] [decimal](14, 4) NULL,
	[TarifaIca] [decimal](14, 4) NULL,
	[TarifaRiv] [decimal](14, 4) NULL,
	[CodTarIva] [varchar](4) NULL,
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[CodTarRiv] [varchar](4) NULL,
	[IdCCosto] [varchar](16) NULL,
	[IdSubCos] [varchar](16) NULL,
	[IdVend] [varchar](16) NULL,
	[TarifaCom] [decimal](14, 4) NULL,
	[CodTarCom] [varchar](4) NULL,
	[DirEnvio] [varchar](250) NULL,
	[IdLocEnv] [varchar](8) NULL,
	[DiasEntraga] [int] NULL,
	[NitContac] [varchar](16) NULL,
	[NomContac] [varchar](150) NULL,
	[TelContac] [varchar](20) NULL,
	[emlContac] [varchar](100) NULL,
	[CargoContac] [varchar](50) NULL,
	[IdForma] [varchar](4) NULL,
	[DetallePago] [varchar](100) NULL,
	[MulPlazos] [bit] NULL,
	[IdPlazo] [varchar](4) NULL,
	[CdMney] [varchar](5) NULL,
	[NitEmpTrans] [varchar](16) NULL,
	[EmpTrans] [varchar](150) NULL,
	[pVehiculo] [varchar](10) NULL,
	[CdConductor] [varchar](16) NULL,
	[CdRuta] [varchar](4) NULL,
	[TipPed] [varchar](3) NULL,
	[Pedido] [int] NULL,
	[IdCiaPed] [char](2) NULL,
	[TipRem] [varchar](3) NULL,
	[Remision] [int] NULL,
	[IdCiaRem] [char](2) NULL,
	[TipCot] [varchar](3) NULL,
	[Cotizacion] [int] NULL,
	[IdCiaCot] [char](2) NULL,
	[FecPedido] [smalldatetime] NULL,
	[AutzaMora] [int] NULL,
	[AutzaCupo] [int] NULL,
	[Modalidad] [varchar](10) NULL,
	[KmtVehic] [int] NULL,
	[ZonaFrontera] [int] NULL,
	[PesoTotal] [decimal](14, 4) NULL,
	[UnidTotal] [decimal](14, 4) NULL,
	[VolTotal] [decimal](14, 4) NULL,
	[CantFalt] [decimal](14, 4) NULL,
	[VrCostoRem] [money] NULL,
	[VrCostoAfi] [money] NULL,
	[CodAutoRet] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Anulado] [bit] NULL,
	[NumDev] [int] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[VrImpCons] [money] NULL,
	[VrReteCREE] [money] NULL,
	[TarifaRtc] [decimal](14, 4) NULL,
	[CodTarRtc] [varchar](4) NULL,
	[Parqueadero] [bit] NULL,
	[FecCuotaParq] [smalldatetime] NULL,
	[BaseIvaObsq] [money] NULL,
	[VrIvaObsequio] [money] NULL,
	[VrImpCarbono] [money] NULL,
	[TipoFE] [varchar](3) NULL,
	[FechaFE] [smalldatetime] NULL,
	[BaseIvaIgp] [money] NULL,
	[VrIvaIngProd] [money] NULL,
	[CodTarArf] [varchar](4) NULL,
	[TarifaArf] [decimal](14, 4) NOT NULL,
	[VrAutRetFte] [money] NOT NULL,
	[CodTarAri] [varchar](4) NULL,
	[TarifaAri] [decimal](14, 4) NOT NULL,
	[VrAutRetIca] [money] NOT NULL,
	[CodigoPreFact] [varchar](3) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_FcSemanas]    Script Date: 10/12/2025 8:10:33 ******/
CREATE TYPE [dbo].[dataTypeTrn_FcSemanas] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[nSemana] [int] NULL DEFAULT ((0)),
	[NumCargue] [int] NULL DEFAULT ((0)),
	[CiaCargue] [char](2) NULL DEFAULT ('01'),
	[TipoSem] [int] NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NULL,
	[FecVence] [smalldatetime] NULL,
	[VrCargo] [money] NULL DEFAULT ((0)),
	[VrOtros] [money] NULL DEFAULT ((0)),
	[VrPagado] [money] NULL DEFAULT ((0)),
	[TipRec] [varchar](3) NULL,
	[Recibo] [int] NULL DEFAULT ((0)),
	[IdCiaRec] [char](2) NULL DEFAULT ('00'),
	[FechaPago] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[FecSemIni] [smalldatetime] NULL,
	[FecSemFin] [smalldatetime] NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Kardex]    Script Date: 10/12/2025 8:10:34 ******/
CREATE TYPE [dbo].[dataTypeTrn_Kardex] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL,
	[Documento] [int] NOT NULL,
	[IdCia] [char](2) NOT NULL,
	[Item] [int] NOT NULL,
	[Fecha] [smalldatetime] NOT NULL,
	[IdProducto] [varchar](16) NOT NULL,
	[IdBodega] [varchar](4) NOT NULL,
	[CdTanque] [varchar](4) NULL,
	[Entradas] [decimal](14, 4) NOT NULL,
	[Salidas] [decimal](14, 4) NOT NULL,
	[IdUnd] [varchar](4) NOT NULL,
	[VrUnitario] [money] NOT NULL,
	[VrPrecio] [money] NOT NULL,
	[VrCostProm] [money] NOT NULL,
	[TarifaIva] [decimal](14, 4) NOT NULL,
	[VrIvaEnt] [money] NOT NULL,
	[VrIvaSal] [money] NOT NULL,
	[TarifaDct] [decimal](14, 4) NOT NULL,
	[VrDctoEnt] [money] NOT NULL,
	[VrDctoSal] [money] NOT NULL,
	[VrCostoEnt] [money] NOT NULL,
	[VrCostoSal] [money] NOT NULL,
	[TarifaRet] [decimal](14, 4) NOT NULL,
	[VrReteEnt] [money] NOT NULL,
	[VrReteSal] [money] NOT NULL,
	[TarifaIca] [decimal](14, 4) NOT NULL,
	[VrIcaEnt] [money] NOT NULL,
	[VrIcaSal] [money] NOT NULL,
	[VrBruto] [money] NOT NULL,
	[CdUbic] [varchar](10) NULL,
	[NumLote] [varchar](30) NULL,
	[FechLote] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[IdTercero] [varchar](16) NOT NULL,
	[CdAgencia] [varchar](16) NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[CdLocal] [varchar](8) NOT NULL,
	[CdSzona] [varchar](4) NULL,
	[pVehiculo] [varchar](10) NULL,
	[IdVend] [varchar](16) NOT NULL,
	[Comision] [decimal](14, 4) NOT NULL,
	[CdOperario] [varchar](16) NULL,
	[ComisnOper] [decimal](14, 4) NOT NULL,
	[Referencia] [varchar](50) NULL,
	[Descripcion] [varchar](250) NULL,
	[Comptmntos] [varchar](50) NULL,
	[CdProdEquiv] [varchar](16) NULL,
	[TipOrd] [varchar](3) NOT NULL,
	[NumOrden] [int] NOT NULL,
	[IdCiaOrd] [char](2) NOT NULL,
	[Cotizacion] [int] NOT NULL,
	[IdCiaCot] [char](2) NOT NULL,
	[Remision] [int] NOT NULL,
	[IdCiaRem] [char](2) NOT NULL,
	[Factura] [varchar](15) NULL,
	[TipDocDev] [varchar](3) NOT NULL,
	[NumDocDev] [int] NOT NULL,
	[CdMngra] [varchar](10) NULL,
	[NumInicial] [decimal](14, 4) NOT NULL,
	[NumFinal] [decimal](14, 4) NOT NULL,
	[Sobretasa] [decimal](14, 4) NOT NULL,
	[TasaNac] [decimal](14, 4) NOT NULL,
	[TasaDep] [decimal](14, 4) NOT NULL,
	[TasaMun] [decimal](14, 4) NOT NULL,
	[Soldicom] [decimal](14, 4) NOT NULL,
	[ImpGlobal] [decimal](14, 4) NOT NULL,
	[OtroImpto] [decimal](14, 4) NOT NULL,
	[Unidades] [decimal](14, 4) NOT NULL,
	[ItemCombo] [int] NOT NULL,
	[Servcios] [bit] NOT NULL,
	[NoVentas] [int] NOT NULL,
	[EsCombo] [bit] NOT NULL,
	[EsProdBase] [int] NOT NULL,
	[CodTarDct] [varchar](4) NULL,
	[CodTarIva] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[CodTarRet] [varchar](4) NULL,
	[CodTarCom] [varchar](4) NULL,
	[CodTarCmc] [varchar](4) NULL,
	[ListaPrec] [char](1) NOT NULL,
	[VrBase] [money] NOT NULL,
	[CdMoneda] [varchar](5) NOT NULL,
	[VrTasaCamb] [money] NOT NULL,
	[VrDivisa1] [money] NOT NULL,
	[VrDivisa2] [money] NOT NULL,
	[VrDivisa3] [money] NOT NULL,
	[Referencia2] [varchar](50) NULL,
	[FecOrden] [smalldatetime] NULL,
	[galsbruto] [decimal](14, 4) NULL,
	[galsneto] [decimal](14, 4) NULL,
	[Temperatura] [decimal](14, 4) NULL,
	[UmTemp] [varchar](3) NULL,
	[Densidad] [decimal](14, 4) NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[Rec_Costo] [decimal](14, 4) NOT NULL,
	[MgenCont] [decimal](14, 4) NOT NULL,
	[VrImvCosto] [decimal](16, 4) NOT NULL,
	[TarifaIco] [decimal](14, 4) NOT NULL,
	[VrImpCon] [decimal](16, 4) NOT NULL,
	[CantObseq] [decimal](14, 4) NOT NULL,
	[VrIvaObseq] [money] NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_NiifComp]    Script Date: 10/12/2025 8:10:34 ******/
CREATE TYPE [dbo].[dataTypeTrn_NiifComp] AS TABLE(
	[TipComCont] [varchar](3) NOT NULL,
	[ComprobanteCont] [int] NOT NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[TipoNiif] [varchar](10) NOT NULL DEFAULT ('NIIF'),
	[CtbTipo] [varchar](3) NULL,
	[CtbNumero] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_NiifCompFMsv]    Script Date: 10/12/2025 8:10:34 ******/
CREATE TYPE [dbo].[dataTypeTrn_NiifCompFMsv] AS TABLE(
	[TipComCont] [varchar](3) NOT NULL,
	[ComprobanteCont] [int] NOT NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[TipoNiif] [varchar](10) NOT NULL DEFAULT ('NIIF'),
	[CtbTipo] [varchar](3) NULL,
	[CtbNumero] [int] NOT NULL DEFAULT ((0)),
	[Documento] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_NiifDetalle]    Script Date: 10/12/2025 8:10:34 ******/
CREATE TYPE [dbo].[dataTypeTrn_NiifDetalle] AS TABLE(
	[TipComCont] [varchar](3) NOT NULL,
	[ComprobanteCont] [int] NOT NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[IdCuenta] [varchar](16) NOT NULL,
	[Detalle] [varchar](250) NOT NULL,
	[VrDebito] [money] NOT NULL DEFAULT ((0)),
	[VrCredito] [money] NOT NULL DEFAULT ((0)),
	[IdTercero] [varchar](16) NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL DEFAULT ('0'),
	[IdCCosto] [varchar](16) NOT NULL,
	[IdSubCos] [varchar](16) NOT NULL,
	[Referncia] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Pagos]    Script Date: 10/12/2025 8:10:35 ******/
CREATE TYPE [dbo].[dataTypeTrn_Pagos] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL,
	[Documento] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NOT NULL,
	[IdForma] [varchar](4) NOT NULL DEFAULT ('EFE'),
	[Detalle] [varchar](150) NOT NULL,
	[VrPagado] [money] NOT NULL DEFAULT ((0)),
	[VrCambio] [money] NOT NULL DEFAULT ((0)),
	[EsCaja] [bit] NOT NULL DEFAULT ((1)),
	[IdBanco] [varchar](4) NOT NULL,
	[NitCliente] [varchar](16) NOT NULL DEFAULT ('0'),
	[CdAgencia] [varchar](16) NOT NULL DEFAULT ('0'),
	[NumForma] [varchar](20) NULL,
	[FecForma] [smalldatetime] NULL,
	[CtaForma] [varchar](30) NULL,
	[Beneficiario] [varchar](150) NULL,
	[Referncia1] [varchar](50) NULL,
	[Referncia2] [varchar](50) NULL,
	[CdLocal] [varchar](8) NOT NULL DEFAULT ('0'),
	[NumAutoriza] [varchar](30) NULL,
	[VrDenom] [money] NOT NULL DEFAULT ((0)),
	[Cantidad] [int] NOT NULL DEFAULT ((0)),
	[TipDenom] [char](1) NOT NULL DEFAULT ('B'),
	[TipRef] [varchar](3) NOT NULL DEFAULT ('0'),
	[DocRef] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRef] [char](2) NOT NULL DEFAULT ('00'),
	[ItemDoc] [int] NOT NULL DEFAULT ((0)),
	[CdCta] [varchar](4) NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[CdProducto] [varchar](16) NULL,
	[FE_Ticket] [bit] NOT NULL DEFAULT ((0)),
	[Cant_Gals] [decimal](14, 4) NULL,
	[PrecioBase] [money] NOT NULL DEFAULT ((0)),
	[PrecioUnit] [money] NOT NULL DEFAULT ((0)),
	[ConsCP] [bit] NOT NULL DEFAULT ((0)),
	[CodCueCons] [varchar](16) NULL,
	[PrecioPub] [money] NOT NULL DEFAULT ((0)),
	[RefVehiculo] [varchar](10) NULL,
	[RefNumVeh] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_RecAfavor]    Script Date: 10/12/2025 8:10:36 ******/
CREATE TYPE [dbo].[dataTypeTrn_RecAfavor] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Recibo] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[VrAFavor] [money] NULL,
	[VrOtrosDb] [money] NULL,
	[VrAbono] [money] NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL,
	[IdVend] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraAntAbonos]    Script Date: 10/12/2025 8:10:36 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraAntAbonos] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('ODP'),
	[Documento] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NOT NULL,
	[TipAnt] [varchar](3) NOT NULL DEFAULT ('ANT'),
	[Anticipo] [int] NOT NULL DEFAULT ((0)),
	[IdCiaAnt] [char](2) NOT NULL,
	[VrAbono] [money] NOT NULL DEFAULT ((0)),
	[TipoAplica] [varchar](10) NOT NULL DEFAULT ('OPAGO'),
	[Detalle] [varchar](100) NULL,
	[CdCuentaAnt] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraAnticipos]    Script Date: 10/12/2025 8:10:37 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraAnticipos] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('ANT'),
	[Anticipo] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipMuc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCiaMuc] [char](2) NOT NULL DEFAULT ('01'),
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdPoseedor] [varchar](16) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[VrAnticipo] [money] NOT NULL DEFAULT ((0)),
	[VrAbonado] [money] NOT NULL DEFAULT ((0)),
	[Modalidad] [varchar](10) NOT NULL DEFAULT ('EGRESO'),
	[TipoPago] [varchar](10) NOT NULL DEFAULT ('EFECTIVO'),
	[NumCheque] [varchar](20) NULL,
	[FecCheque] [smalldatetime] NULL,
	[IdCta] [varchar](4) NOT NULL DEFAULT ('0'),
	[IdCuenta] [varchar](16) NOT NULL,
	[Beneficiario] [varchar](150) NULL,
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[FechaVence] [smalldatetime] NULL,
	[NumPresAnt] [int] NOT NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NOT NULL DEFAULT ('0'),
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL DEFAULT ('00'),
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[NumDev] [int] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[CedBenef] [varchar](16) NULL,
	[PreAnticipo] [int] NOT NULL DEFAULT ((0)),
	[NumCargue] [int] NOT NULL DEFAULT ((0)),
	[CiaCargue] [char](2) NULL DEFAULT ('00')
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraConceptos]    Script Date: 10/12/2025 8:10:39 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraConceptos] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL,
	[Documento] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[Descripcion] [varchar](250) NOT NULL,
	[Tarifa] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[TipoConc] [varchar](10) NOT NULL DEFAULT ('DEDUCCION'),
	[RubroConcep] [varchar](20) NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[VrUnitario] [money] NOT NULL DEFAULT ((0)),
	[TarifIva] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[IdConcepto] [varchar](4) NOT NULL,
	[CdCuenta] [varchar](16) NOT NULL DEFAULT ('0'),
	[NitTercero] [varchar](16) NULL DEFAULT ('0'),
	[CdTipoEsc] [varchar](4) NULL,
	[FechaNov] [smalldatetime] NULL,
	[VrBase] [money] NOT NULL DEFAULT ((0)),
	[TipoTarif] [char](1) NOT NULL DEFAULT ('$'),
	[RefConc] [varchar](50) NULL,
	[Fijos] [bit] NOT NULL DEFAULT ((0)),
	[IncBaseRet] [int] NOT NULL DEFAULT ((0)),
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[Est_Factura] [int] NOT NULL,
	[Est_Liquida] [int] NOT NULL,
	[TipFact] [varchar](3) NULL,
	[NumFactura] [int] NOT NULL,
	[CiaFact] [char](2) NULL,
	[VrTotalFact] [money] NOT NULL,
	[TipLiq] [varchar](3) NULL,
	[NumLiquida] [int] NOT NULL,
	[CiaLiq] [char](2) NULL,
	[VrTotalLiq] [money] NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumplido]    Script Date: 10/12/2025 8:10:39 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraCumplido] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('CUM'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[TipMuc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCiaMuc] [char](2) NOT NULL DEFAULT ('01'),
	[IdVehiculo] [varchar](10) NOT NULL,
	[Modalidad] [varchar](10) NOT NULL DEFAULT ('TOTAL'),
	[DiasPlazo] [int] NOT NULL DEFAULT ((0)),
	[FecPago] [smalldatetime] NOT NULL,
	[TipoMargen] [varchar](10) NOT NULL DEFAULT ('UNIDAD'),
	[MargenFalt] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndCalcFalt] [varchar](10) NULL DEFAULT ('PESO'),
	[TarifFaltPago] [money] NOT NULL DEFAULT ((0)),
	[TarifFaltCobro] [money] NOT NULL DEFAULT ((0)),
	[NRadicaDoc] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRadic] [char](2) NULL,
	[CdCiaOfic] [char](2) NULL,
	[FecRadic] [smalldatetime] NULL,
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](1000) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[CdRuta] [varchar](4) NULL,
	[CdOrigen] [varchar](8) NULL,
	[CdDestino] [varchar](8) NULL,
	[TipoComp] [varchar](3) NULL,
	[NumComp] [int] NOT NULL DEFAULT ((0)),
	[CodConcepto] [varchar](4) NULL,
	[TipoCumpMT] [varchar](3) NULL,
	[MotivoSusp] [varchar](3) NULL,
	[ConsecSusp] [varchar](3) NULL,
	[VrAdicCargue] [decimal](16, 4) NOT NULL DEFAULT ((0)),
	[VrAdicDescargue] [decimal](16, 4) NOT NULL DEFAULT ((0)),
	[VrAdicFlete] [decimal](16, 4) NOT NULL DEFAULT ((0)),
	[MotivoVrAdic] [varchar](3) NULL,
	[VrDctoFlete] [decimal](16, 4) NOT NULL DEFAULT ((0)),
	[MotivoVrDcto] [varchar](3) NULL,
	[VrAdicAnticipo] [decimal](16, 4) NOT NULL DEFAULT ((0)),
	[FecEntregaDoc] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumRadDoc]    Script Date: 10/12/2025 8:10:41 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraCumRadDoc] AS TABLE(
	[NumRadica] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NOT NULL,
	[NitCliente] [varchar](16) NOT NULL,
	[ItemDoc] [int] NOT NULL DEFAULT ((0)),
	[Descripcion] [varchar](250) NULL,
	[Radicado] [bit] NOT NULL DEFAULT ((0)),
	[Referencia] [varchar](50) NULL,
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumRadica]    Script Date: 10/12/2025 8:10:41 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraCumRadica] AS TABLE(
	[NumRadica] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[TipMuc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCiaMuc] [char](2) NOT NULL DEFAULT ('01'),
	[CdCiaRad] [char](2) NOT NULL DEFAULT ('01'),
	[DocAnexos] [varchar](1000) NULL,
	[CantDoc] [int] NOT NULL DEFAULT ((0)),
	[FormaEnvio] [varchar](50) NULL,
	[NomRadica] [varchar](150) NULL,
	[CedRadica] [varchar](16) NULL,
	[Funcionario] [varchar](150) NULL,
	[Observacion] [varchar](2000) NULL,
	[NumeroCum] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCum] [char](2) NOT NULL DEFAULT ('00'),
	[FechaCum] [smalldatetime] NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraCumRemesas]    Script Date: 10/12/2025 8:10:42 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraCumRemesas] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('CUM'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[TipRem] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('01'),
	[ItemRem] [int] NOT NULL DEFAULT ((0)),
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoNeto] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndMed] [varchar](10) NOT NULL,
	[Volumen] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndVol] [varchar](10) NOT NULL,
	[Cases] [int] NOT NULL DEFAULT ((0)),
	[Cajas] [int] NOT NULL DEFAULT ((0)),
	[Palets] [int] NOT NULL DEFAULT ((0)),
	[TarifClie] [money] NOT NULL DEFAULT ((0)),
	[TarifPago] [money] NOT NULL DEFAULT ((0)),
	[UndTarifClie] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[UndTarifPago] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[CantCargue] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoCargue] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[VolCargue] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[CasesCargue] [int] NOT NULL DEFAULT ((0)),
	[CajasCargue] [int] NOT NULL DEFAULT ((0)),
	[PaletsCargue] [int] NOT NULL DEFAULT ((0)),
	[EstadoCump] [int] NOT NULL DEFAULT ((1)),
	[Remision] [decimal](18, 2) NOT NULL DEFAULT ((0)),
	[DocCliente] [varchar](30) NULL,
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[Detalle] [varchar](250) NULL,
	[TarifFlete] [money] NOT NULL DEFAULT ((0)),
	[TipoCumRemesa] [varchar](3) NULL,
	[MotivoSuspRem] [varchar](3) NULL,
	[HoraLlegaCargue] [smalldatetime] NULL,
	[HoraEntraCargue] [smalldatetime] NULL,
	[HoraSaleCargue] [smalldatetime] NULL,
	[HoraLlegaDescargue] [smalldatetime] NULL,
	[HoraEntraDescargue] [smalldatetime] NULL,
	[HoraSaleDescargue] [smalldatetime] NULL,
	[CodCCosto] [varchar](16) NULL,
	[CodSubCos] [varchar](16) NULL,
	[NitClieRem] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDespachos]    Script Date: 10/12/2025 8:10:44 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraDespachos] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[FecCargue] [smalldatetime] NOT NULL,
	[FecDespacho] [smalldatetime] NOT NULL,
	[IdOrigen] [varchar](8) NOT NULL,
	[IdDestino] [varchar](8) NOT NULL,
	[IdRuta] [varchar](4) NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[IdPoseedor] [varchar](16) NOT NULL,
	[NitRemite] [varchar](16) NOT NULL,
	[Remitente] [varchar](250) NOT NULL,
	[NitDestntario] [varchar](16) NOT NULL,
	[Destinatario] [varchar](250) NOT NULL DEFAULT ('varios'),
	[DescMcia] [varchar](150) NULL,
	[PesoTotal] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCiaOrd] [char](2) NOT NULL DEFAULT ('00'),
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('00'),
	[Estado] [int] NOT NULL DEFAULT ((0)),
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDespProgram]    Script Date: 10/12/2025 8:10:45 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraDespProgram] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[CdRuta] [varchar](4) NOT NULL,
	[IdPunto] [int] NOT NULL DEFAULT ((0)),
	[HoraProg] [smalldatetime] NOT NULL,
	[TipoProg] [int] NOT NULL DEFAULT ((0)),
	[IdUsuario] [varchar](11) NOT NULL,
	[FechaCrea] [smalldatetime] NOT NULL,
	[ObservProg] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevAnt]    Script Date: 10/12/2025 8:10:45 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraDevAnt] AS TABLE(
	[TipDev] [varchar](3) NOT NULL DEFAULT ('DVA'),
	[Devolucion] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('ANT'),
	[Anticipo] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NOT NULL DEFAULT ('01'),
	[FecDoc] [smalldatetime] NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdPoseedor] [varchar](16) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[VrDevolucion] [money] NOT NULL DEFAULT ((0)),
	[CdCta] [varchar](4) NOT NULL DEFAULT ('0'),
	[CdCuenta] [varchar](16) NOT NULL,
	[ModdDev] [varchar](10) NOT NULL DEFAULT ('TOTAL'),
	[OrigenAdd] [varchar](10) NOT NULL,
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevAos]    Script Date: 10/12/2025 8:10:46 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraDevAos] AS TABLE(
	[TipDev] [varchar](3) NOT NULL,
	[Devolucion] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipDoc] [varchar](3) NOT NULL,
	[Anticipo] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NOT NULL DEFAULT ('01'),
	[FecDoc] [smalldatetime] NOT NULL,
	[VrDevolucion] [money] NOT NULL DEFAULT ((0)),
	[CdCta] [varchar](4) NOT NULL DEFAULT ('0'),
	[CdCuenta] [varchar](16) NOT NULL,
	[ModdDev] [varchar](10) NOT NULL DEFAULT ('TOTAL'),
	[OrigenAdd] [varchar](10) NOT NULL,
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevCos]    Script Date: 10/12/2025 8:10:47 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraDevCos] AS TABLE(
	[TipDev] [varchar](3) NOT NULL,
	[Devolucion] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipDoc] [varchar](3) NOT NULL,
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NOT NULL DEFAULT ('01'),
	[FecDoc] [smalldatetime] NOT NULL,
	[ModdDev] [varchar](10) NOT NULL DEFAULT ('TOTAL'),
	[OrigenAdd] [varchar](10) NOT NULL,
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL,
	[Observacion] [varchar](250) NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraDevCum]    Script Date: 10/12/2025 8:10:47 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraDevCum] AS TABLE(
	[TipDev] [varchar](3) NOT NULL DEFAULT ('DCU'),
	[Devolucion] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('CUM'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NOT NULL DEFAULT ('01'),
	[FecDoc] [smalldatetime] NOT NULL,
	[ModdDev] [varchar](10) NOT NULL DEFAULT ('TOTAL'),
	[OrigenAdd] [varchar](10) NOT NULL,
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL,
	[Observacion] [varchar](250) NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspAntAbonos]    Script Date: 10/12/2025 8:10:48 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspAntAbonos] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NULL,
	[TipAnt] [varchar](3) NULL DEFAULT ('ANE'),
	[Anticipo] [int] NULL DEFAULT ((0)),
	[IdCiaAnt] [char](2) NULL,
	[VrAbono] [money] NULL DEFAULT ((0)),
	[TipoAplica] [varchar](10) NULL,
	[Detalle] [varchar](100) NULL,
	[CdCuentaAnt] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspAnticipos]    Script Date: 10/12/2025 8:10:48 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspAnticipos] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('ANE'),
	[Anticipo] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipRes] [varchar](3) NULL DEFAULT ('RES'),
	[Reserva] [int] NULL DEFAULT ((0)),
	[IdCiaRes] [char](2) NULL DEFAULT ('01'),
	[ItemRes] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[VrAnticipo] [money] NULL DEFAULT ((0)),
	[VrAbonado] [money] NULL DEFAULT ((0)),
	[Modalidad] [varchar](10) NULL DEFAULT ('EGRESO'),
	[TipoPago] [varchar](10) NULL DEFAULT ('EFECTIVO'),
	[NumCheque] [varchar](20) NULL,
	[FecCheque] [smalldatetime] NULL,
	[IdCta] [varchar](4) NULL DEFAULT ('0'),
	[IdCuenta] [varchar](16) NULL,
	[Beneficiario] [varchar](150) NULL,
	[CedBenef] [varchar](16) NULL,
	[Cantidad] [decimal](14, 4) NULL DEFAULT ((0)),
	[FechaVence] [smalldatetime] NULL,
	[NumPresAnt] [int] NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NULL DEFAULT ('0'),
	[Comprobante] [int] NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NULL DEFAULT ('00'),
	[Anulado] [bit] NULL DEFAULT ((0)),
	[NumDev] [int] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL,
	[PreAnticipo] [int] NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspAuxFactura]    Script Date: 10/12/2025 8:10:50 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspAuxFactura] AS TABLE(
	[TipFac] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaFac] [char](2) NULL,
	[Resolucion] [varchar](30) NULL,
	[Rango] [varchar](50) NULL,
	[FechaResl] [smalldatetime] NULL,
	[Prefijo] [varchar](5) NULL,
	[TipDocPf] [varchar](3) NULL,
	[PreFactura] [int] NULL,
	[IdCiaPf] [char](2) NULL,
	[CodigoPreFact] [varchar](3) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCauDetalle]    Script Date: 10/12/2025 8:10:50 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspCauDetalle] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Causacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[IdConcepto] [varchar](4) NULL,
	[Descripcion] [varchar](250) NULL,
	[TipoConc] [varchar](10) NULL,
	[VrDebito] [money] NULL,
	[VrCredito] [money] NULL,
	[CdCuenta] [varchar](16) NULL,
	[NitTercero] [varchar](16) NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NULL,
	[VrBase] [money] NULL,
	[TarifBase] [decimal](14, 4) NULL,
	[Referencia] [varchar](50) NULL,
	[TipDocRef] [varchar](3) NULL,
	[DocRef] [int] NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCiaFac] [char](2) NULL,
	[ItemFac] [int] NULL,
	[FecVence] [smalldatetime] NULL,
	[EstadoReg] [int] NULL,
	[TipoLiq] [varchar](3) NULL,
	[NumLiquida] [int] NULL,
	[CiaLiquida] [char](2) NULL,
	[VrAbonado] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCausacion]    Script Date: 10/12/2025 8:10:50 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspCausacion] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Causacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[IdProv] [varchar](16) NULL,
	[Factura] [varchar](20) NULL,
	[VrTotal] [money] NULL,
	[VrOtros] [money] NULL,
	[VrNeto] [money] NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Anulado] [bit] NULL,
	[NumDev] [int] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspConceptos]    Script Date: 10/12/2025 8:10:50 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspConceptos] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL DEFAULT ((0)),
	[Descripcion] [varchar](250) NULL,
	[Tarifa] [decimal](14, 4) NULL DEFAULT ((0)),
	[TipoConc] [varchar](10) NULL DEFAULT ('DEDUCCION'),
	[RubroConcep] [varchar](20) NULL,
	[Cantidad] [decimal](14, 4) NULL DEFAULT ((0)),
	[VrUnitario] [money] NULL DEFAULT ((0)),
	[TarifIva] [decimal](14, 4) NULL DEFAULT ((0)),
	[IdConcepto] [varchar](4) NULL,
	[CdCuenta] [varchar](16) NULL DEFAULT ('0'),
	[NitTercero] [varchar](16) NULL DEFAULT ('0'),
	[CdTipoEsc] [varchar](4) NULL,
	[FechaNov] [smalldatetime] NULL,
	[VrBase] [money] NULL DEFAULT ((0)),
	[TipoTarif] [char](1) NULL DEFAULT ('$'),
	[RefConc] [varchar](50) NULL,
	[Fijos] [bit] NULL DEFAULT ((0)),
	[IncBaseRet] [int] NULL DEFAULT ((0)),
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[Cliente] [bit] NULL,
	[Conductor] [bit] NULL,
	[Vehiculo] [bit] NULL,
	[ItemDoc] [int] NULL DEFAULT ((0)),
	[IdVehiculo] [varchar](10) NULL DEFAULT ('0')
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoAdendos]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspContratoAdendos] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Adendo] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[TipCont] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[IdCiaCont] [char](2) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoAnexo]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspContratoAnexo] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Contrato] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[TipContrato] [varchar](150) NULL,
	[IdContrato] [varchar](20) NULL,
	[IdObjCOE] [varchar](4) NULL,
	[ObjContrato] [varchar](1000) NULL,
	[NomCliente] [varchar](250) NULL,
	[TelCliente] [varchar](100) NULL,
	[emlCliente] [varchar](150) NULL,
	[DireccionCli] [varchar](250) NULL,
	[Observacion] [varchar](100) NULL,
	[NombArchivo] [varchar](100) NULL,
	[DescripCarga] [varchar](250) NULL,
	[Clausulas] [varchar](2500) NULL,
	[Responsable] [varchar](16) NULL,
	[NombreResp] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoDet]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspContratoDet] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[IdHorario] [varchar](3) NULL,
	[TipPed] [varchar](3) NULL,
	[Pedido] [int] NULL DEFAULT ((0)),
	[CiaPed] [char](2) NULL DEFAULT ('01'),
	[ItemPed] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[NumRes] [int] NULL DEFAULT ((0)),
	[IdCiaRes] [char](2) NULL DEFAULT ('00'),
	[ItemRes] [int] NULL DEFAULT ((0)),
	[IdVehiculo] [varchar](10) NULL,
	[CdTipVeh] [varchar](4) NULL,
	[NumPasajeros] [int] NULL,
	[PesoNeto] [decimal](12, 4) NULL,
	[VrUnitario] [money] NULL,
	[VrPago] [money] NULL,
	[IdRuta] [varchar](4) NULL,
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[EsRutaCliente] [bit] NULL,
	[CdCiuOrigen] [varchar](8) NULL,
	[DirOrigen] [varchar](max) NULL,
	[FecOrigen] [datetime] NULL,
	[CdCiuDestino] [varchar](8) NULL,
	[DirDestino] [varchar](max) NULL,
	[FecDestino] [datetime] NULL,
	[DiasDisp] [int] NULL DEFAULT ((0)),
	[VrDia] [money] NULL DEFAULT ((0)),
	[Parada] [varchar](10) NULL,
	[CdTipRuta] [varchar](15) NULL,
	[CdTipServicio] [varchar](20) NULL,
	[CantVeh] [int] NULL,
	[Retorno] [bit] NULL,
	[VrMonitor] [decimal](14, 4) NULL,
	[CantMonitor] [int] NULL,
	[VrMaxRec] [decimal](14, 4) NULL,
	[NumDias] [int] NULL,
	[TipoTarifa] [varchar](10) NULL,
	[IdColegio] [varchar](4) NULL,
	[Codigo] [varchar](3) NULL,
	[Itinerario] [varchar](1000) NULL,
	[VLargo] [bit] NULL,
	[IdOtroSi] [int] NULL,
	[ItemAnuladoOS] [bit] NULL,
	[EsItemPME] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratos]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspContratos] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[FechaInicio] [smalldatetime] NULL,
	[FechaFin] [smalldatetime] NULL,
	[IdCliente] [varchar](16) NULL,
	[IdVend] [varchar](16) NULL,
	[IdTarifCom] [varchar](4) NULL,
	[IdForma] [varchar](4) NULL,
	[Plazos] [bit] NULL,
	[TipoPago] [varchar](10) NULL,
	[Modalidad] [varchar](10) NULL,
	[TipoLiquid] [varchar](8) NULL,
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[VrPresupuesto] [money] NULL,
	[VrSaldoPresup] [money] NULL,
	[VrCobro] [money] NULL,
	[VrCargos] [money] NULL,
	[VrRetencion] [money] NULL,
	[VrReteIca] [money] NULL,
	[VrDctos] [money] NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[Peso] [decimal](14, 4) NULL,
	[NumAprob] [int] NULL,
	[IdCiaApr] [char](2) NULL,
	[FecAprob] [smalldatetime] NULL,
	[TipOdp] [varchar](3) NULL,
	[NumOdp] [int] NULL,
	[IdCiaOdp] [char](2) NULL,
	[FechaOdp] [smalldatetime] NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaFac] [char](2) NULL,
	[FechaFac] [smalldatetime] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[EsLicitacion] [bit] NULL,
	[Anulado] [bit] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](1000) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[CdCarga] [varchar](15) NULL,
	[IdAgencia] [varchar](16) NULL,
	[IdMneda] [varchar](5) NULL,
	[VrIva] [money] NULL,
	[CantPasajeros] [decimal](14, 4) NULL,
	[CdDescuento] [varchar](4) NULL,
	[UnionTemporal] [varchar](250) NULL,
	[IdGrupo] [varchar](4) NULL,
	[IdRutaG] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspContratoVehLista]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspContratoVehLista] AS TABLE(
	[IdLista] [int] NULL,
	[TipDoc] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[Fecha] [datetime] NULL,
	[IdEstado] [varchar](4) NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumFacturas]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspCumFacturas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Cumplido] [int] NULL,
	[IdCia] [char](2) NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaFac] [char](2) NULL,
	[IdCliente] [varchar](16) NULL,
	[VrIngreso] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumplido]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspCumplido] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Cumplido] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaFac] [char](2) NULL,
	[IdClieFac] [varchar](16) NULL,
	[CdRuta] [varchar](4) NULL,
	[CdOrigen] [varchar](8) NULL,
	[CdDestino] [varchar](8) NULL,
	[Anulado] [bit] NULL,
	[NumDev] [int] NULL,
	[FecDev] [smalldatetime] NULL,
	[TipoComp] [varchar](3) NULL,
	[NumComp] [int] NULL,
	[CodConcepto] [varchar](4) NULL,
	[Observacion] [varchar](1000) NULL,
	[IdEstado] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[ObservAnulado] [varchar](250) NULL,
	[CdCenCosto] [varchar](16) NULL,
	[CdSubCenCos] [varchar](16) NULL,
	[VrPago] [money] NULL,
	[VrCobro] [money] NULL,
	[VrAfiliados] [money] NULL,
	[VrPropios] [money] NULL,
	[VrTotalServ] [money] NULL,
	[VrTotalPagos] [money] NULL,
	[CodTarRtc] [varchar](4) NULL,
	[BaseRet] [money] NULL,
	[VrReteCree] [money] NULL,
	[VrNeto] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumplidoProg]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspCumplidoProg] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Cumplido] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[TipPgr] [varchar](3) NULL,
	[Programa] [int] NULL,
	[IdCiaPgr] [char](2) NULL,
	[ItemPgr] [int] NULL,
	[VrRecorrido] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspCumReservas]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspCumReservas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Cumplido] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[EstadoItemRes] [varchar](20) NULL,
	[VrRecorridos] [money] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[TipoAfil] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevAnt]    Script Date: 10/12/2025 8:10:51 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspDevAnt] AS TABLE(
	[TipDev] [varchar](3) NULL DEFAULT ('DAE'),
	[Devolucion] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipDoc] [varchar](3) NULL DEFAULT ('ANE'),
	[Anticipo] [int] NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NULL DEFAULT ('01'),
	[FecDoc] [smalldatetime] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[VrDevolucion] [money] NULL DEFAULT ((0)),
	[CdCta] [varchar](4) NULL DEFAULT ('0'),
	[CdCuenta] [varchar](16) NULL,
	[ModdDev] [varchar](10) NULL DEFAULT ('TOTAL'),
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevCau]    Script Date: 10/12/2025 8:10:52 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspDevCau] AS TABLE(
	[TipDev] [varchar](3) NULL,
	[Devolucion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipDoc] [varchar](3) NULL,
	[Causacion] [int] NULL,
	[IdCiaDoc] [char](2) NULL,
	[FecDoc] [smalldatetime] NULL,
	[IdProv] [varchar](16) NULL,
	[Factura] [varchar](20) NULL,
	[VrTotal] [money] NULL,
	[VrOtros] [money] NULL,
	[VrNeto] [money] NULL,
	[ModdDev] [varchar](10) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevCum]    Script Date: 10/12/2025 8:10:52 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspDevCum] AS TABLE(
	[TipDev] [varchar](3) NULL,
	[Devolucion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipDoc] [varchar](3) NULL,
	[Cumplido] [int] NULL,
	[IdCiaDoc] [char](2) NULL,
	[FecDoc] [smalldatetime] NULL,
	[ModdDev] [varchar](10) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Observacion] [varchar](250) NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevLiq]    Script Date: 10/12/2025 8:10:52 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspDevLiq] AS TABLE(
	[TipDev] [varchar](3) NULL,
	[Devolucion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipDoc] [varchar](3) NULL,
	[Liquidacion] [int] NULL,
	[IdCiaDoc] [char](2) NULL,
	[FecDoc] [smalldatetime] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[VrTotal] [money] NULL,
	[ModdDev] [varchar](10) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspDevOdp]    Script Date: 10/12/2025 8:10:52 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspDevOdp] AS TABLE(
	[TipDev] [varchar](3) NOT NULL,
	[Devolucion] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[TipDoc] [varchar](3) NOT NULL,
	[OrdPago] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDoc] [char](2) NOT NULL DEFAULT ('01'),
	[FecDoc] [smalldatetime] NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdPoseedor] [varchar](16) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[CxPagar] [bit] NOT NULL DEFAULT ((0)),
	[ModdDev] [varchar](10) NOT NULL DEFAULT ('TOTAL'),
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFacReservas]    Script Date: 10/12/2025 8:10:53 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspFacReservas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipoReg] [int] NULL,
	[FechaFact] [smalldatetime] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[FecReserva] [smalldatetime] NULL,
	[Descripcion] [varchar](250) NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[VrServicio] [money] NULL,
	[VrUnitario] [money] NULL,
	[VrCosto] [money] NULL,
	[TarifaIva] [decimal](14, 4) NULL,
	[VrImpuesto] [money] NULL,
	[TarifaDct] [decimal](14, 4) NULL,
	[VrDescuento] [money] NULL,
	[DocCliente] [varchar](30) NULL,
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[CdConcepto] [varchar](4) NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[NitTercero] [varchar](16) NULL,
	[CdAgencia] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NULL,
	[IdOrigen] [varchar](8) NULL,
	[IdDestino] [varchar](8) NULL,
	[Anulado] [int] NULL,
	[TipDocRef] [varchar](3) NULL,
	[NumDocRef] [int] NULL,
	[IdCiaRef] [char](2) NULL,
	[FecDocRef] [smalldatetime] NULL,
	[CodTarDct] [varchar](4) NULL,
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[TarifaRet] [decimal](14, 4) NULL,
	[VrRetencion] [money] NULL,
	[TarifaIca] [decimal](14, 4) NULL,
	[VrReteIca] [money] NULL,
	[EstadoItem] [varchar](20) NULL,
	[CodTarAvTa] [varchar](4) NULL,
	[TarifaAvTa] [decimal](14, 4) NULL DEFAULT ((0.0000)),
	[VrAvTa] [money] NULL DEFAULT ((0.00)),
	[CodTarBom] [varchar](4) NULL,
	[TarifaBom] [decimal](14, 4) NULL DEFAULT ((0.0000)),
	[VrBom] [money] NULL DEFAULT ((0.00))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFacResVehiculos]    Script Date: 10/12/2025 8:10:53 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspFacResVehiculos] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[TipoAfil] [varchar](10) NULL,
	[VrRecorrido] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuec]    Script Date: 10/12/2025 8:10:53 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspFuec] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('FUE'),
	[Fuec] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Numero] [varchar](21) NULL,
	[Fecha] [datetime] NULL,
	[FechaInicio] [smalldatetime] NULL,
	[FechaFin] [smalldatetime] NULL,
	[CdCarga] [varchar](15) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdConductor] [varchar](16) NULL,
	[IdConductor2] [varchar](16) NULL,
	[IdConductor3] [varchar](16) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdRuta] [varchar](4) NULL,
	[CdTipRuta] [varchar](15) NULL,
	[IdOrigen] [varchar](8) NULL,
	[IdDestino] [varchar](8) NULL,
	[Modalidad] [varchar](10) NULL,
	[CantPasajeros] [decimal](14, 4) NULL DEFAULT ((0)),
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[VrPresupuesto] [money] NULL DEFAULT ((0)),
	[VrCobro] [money] NULL DEFAULT ((0)),
	[VrPagos] [money] NULL DEFAULT ((0)),
	[VrCargos] [money] NULL DEFAULT ((0)),
	[VrDctos] [money] NULL DEFAULT ((0)),
	[VrIva] [money] NULL DEFAULT ((0)),
	[VrRetencion] [money] NULL DEFAULT ((0)),
	[VrReteIca] [money] NULL DEFAULT ((0)),
	[Cantidad] [decimal](14, 4) NULL DEFAULT ((0)),
	[Peso] [decimal](14, 4) NULL DEFAULT ((0)),
	[TipDocPgr] [varchar](3) NULL DEFAULT ('0'),
	[NumPgr] [int] NULL DEFAULT ((0)),
	[IdCiaPgr] [char](2) NULL DEFAULT ('00'),
	[ItemPgr] [int] NULL DEFAULT ((0)),
	[TipDocCnt] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[CiaCnt] [char](2) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL,
	[Consecutivo] [int] NULL,
	[Itinerario] [varchar](1000) NULL,
	[FuecParcial] [bit] NULL DEFAULT ((0)),
	[ComenParcial] [varchar](500) NULL,
	[Qr] [varchar](max) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuecAnexo]    Script Date: 10/12/2025 8:10:54 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspFuecAnexo] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('FUE'),
	[Fuec] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[TipContrato] [varchar](150) NULL,
	[IdContrato] [varchar](20) NULL,
	[ObjContrato] [varchar](1000) NULL,
	[DescripCarga] [varchar](250) NULL,
	[Observacion] [varchar](1000) NULL,
	[RespViaje] [varchar](300) NULL,
	[VehConvenio] [bit] NULL DEFAULT ((0)),
	[EmpresaVehCon] [varchar](16) NULL DEFAULT ('0')
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuecCndtores]    Script Date: 10/12/2025 8:10:55 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspFuecCndtores] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('FUE'),
	[Fuec] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('02'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[IdConductor] [varchar](16) NOT NULL DEFAULT ('0')
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspFuecDetalle]    Script Date: 10/12/2025 8:10:55 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspFuecDetalle] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('FUE'),
	[Fuec] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL DEFAULT ((0)),
	[IdCiaRes] [char](2) NULL DEFAULT ('00'),
	[ItemRes] [int] NULL DEFAULT ((0)),
	[NumPasajeros] [int] NULL,
	[PesoNeto] [decimal](12, 4) NULL,
	[VrCobro] [money] NULL DEFAULT ((0)),
	[VrPagos] [money] NULL DEFAULT ((0)),
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[CdTipServicio] [varchar](20) NULL,
	[EsRutaCliente] [bit] NULL,
	[Kilometros] [decimal](14, 4) NULL,
	[DirOrigen] [varchar](max) NULL,
	[FecOrigen] [datetime] NULL,
	[DirDestino] [varchar](max) NULL,
	[FecDestino] [datetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquida]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspLiquida] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Liquidacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[VrTotal] [money] NULL,
	[CxPagar] [bit] NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Anulado] [bit] NULL,
	[NumDev] [int] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[FecIniCau] [smalldatetime] NULL,
	[FecFinCau] [smalldatetime] NULL,
	[FecIniOdp] [smalldatetime] NULL,
	[FecFinOdp] [smalldatetime] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[ModLiquida] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquidaDed]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspLiquidaDed] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Liquidacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipCau] [varchar](3) NULL,
	[Causacion] [int] NULL,
	[IdCiaCau] [char](2) NULL,
	[ItemCau] [int] NULL,
	[FechaCau] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[Descripcion] [varchar](250) NULL,
	[VrAbono] [money] NULL,
	[NitPoseedor] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[EsVence] [bit] NULL,
	[TipOdp] [varchar](3) NULL,
	[OrdenPago] [int] NULL,
	[IdCiaOdp] [char](2) NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[VrSaldoOrden] [money] NULL,
	[CdCuenta] [varchar](16) NULL,
	[CdCuePagar] [varchar](16) NULL,
	[NumFactura] [varchar](20) NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[TipoFac] [varchar](3) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquidaOdp]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspLiquidaOdp] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Liquidacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipOdp] [varchar](3) NULL,
	[OrdPago] [int] NULL,
	[IdCiaOdp] [char](2) NULL,
	[VrAbonado] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspLiquidaOtr]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspLiquidaOtr] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Liquidacion] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipCau] [varchar](3) NULL,
	[Causacion] [int] NULL,
	[IdCiaCau] [char](2) NULL,
	[ItemCau] [int] NULL,
	[Factura] [varchar](15) NULL,
	[ItemFac] [int] NULL,
	[IdProveedor] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[VrAbono] [money] NULL,
	[TipFac] [varchar](3) NULL,
	[VrFactura] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspListaPasajeros]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspListaPasajeros] AS TABLE(
	[IdLista] [int] NULL,
	[Documento] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOrdenPago]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspOrdenPago] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[OrdPago] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[IdConcepto] [varchar](4) NULL,
	[Cantidad] [int] NULL,
	[Modalidad] [varchar](10) NULL,
	[LiqReservas] [bit] NULL,
	[CxPagar] [bit] NULL,
	[MulPlazos] [bit] NULL,
	[IdPlazo] [varchar](4) NULL,
	[FechaVence] [smalldatetime] NULL,
	[TipCom] [varchar](3) NULL,
	[Comprobante] [int] NULL,
	[IdCiaCom] [char](2) NULL,
	[Anulado] [bit] NULL,
	[NumDev] [int] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOrdenProg]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspOrdenProg] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[OrdPago] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[TipPgr] [varchar](3) NULL,
	[Programa] [int] NOT NULL,
	[IdCiaPgr] [char](2) NULL,
	[ItemPgr] [int] NULL,
	[VrRecorrido] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOrdenReservas]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspOrdenReservas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[OrdPago] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[TipRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdConductor] [varchar](16) NULL,
	[IdPropietario] [varchar](16) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[VrServicio] [money] NULL,
	[VrDescuento] [money] NULL,
	[VrRetencion] [money] NULL,
	[VrReteIca] [money] NULL,
	[VrReteCREE] [money] NULL,
	[VrAnticipos] [money] NULL,
	[VrOtrosDctos] [money] NULL,
	[VrImpuestos] [money] NULL,
	[VrOtrosPagos] [money] NULL,
	[VrNeto] [money] NULL,
	[BaseRet] [money] NULL,
	[BaseIca] [money] NULL,
	[BaseCree] [money] NULL,
	[TarifaRet] [decimal](14, 4) NULL,
	[TarifaIca] [decimal](14, 4) NULL,
	[TarifaRtc] [decimal](14, 4) NULL,
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[CodTarRtc] [varchar](4) NULL,
	[TipEgr] [varchar](3) NULL,
	[Egreso] [int] NULL,
	[IdCiaEgr] [char](2) NULL,
	[FechaEgr] [smalldatetime] NULL,
	[NumCheque] [varchar](20) NULL,
	[Referencia] [varchar](50) NULL,
	[VrConcPagos] [money] NULL,
	[VrConcDctos] [money] NULL,
	[VrConcFondo] [money] NULL,
	[VrConcSeguro] [money] NULL,
	[VrConcAporte] [money] NULL,
	[VrConcImpuesto] [money] NULL,
	[VrRecCaja] [money] NULL,
	[CdForma] [varchar](4) NULL,
	[CdCenCosto] [varchar](16) NULL,
	[CdSubCenCos] [varchar](16) NULL,
	[VrSeguros] [money] NOT NULL DEFAULT ((0)),
	[VrFondos] [money] NOT NULL DEFAULT ((0)),
	[VrAportes] [money] NOT NULL DEFAULT ((0)),
	[EdoLiqCausac] [int] NOT NULL DEFAULT ((0)),
	[EstadoItem] [varchar](20) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOtroSi]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspOtroSi] AS TABLE(
	[IdOtroSi] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[Adicion] [bit] NULL,
	[CFecha] [bit] NULL,
	[Items] [bit] NULL,
	[Aplicado] [bit] NULL,
	[TimeSys] [smalldatetime] NULL,
	[Observacion] [varchar](500) NULL,
	[IdUsuario] [varchar](11) NULL,
	[Anulado] [bit] NULL,
	[FecDev] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspOtroSiContratos]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspOtroSiContratos] AS TABLE(
	[IdOtroSi] [int] NULL,
	[TipDocCnt] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[IdCiaCnt] [char](2) NULL,
	[FechaFinAnt] [smalldatetime] NULL,
	[FechaFinNew] [smalldatetime] NULL,
	[VrPpto] [money] NULL,
	[VrSaldoPpo] [money] NULL,
	[VrAdicionPpto] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPasajeros]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspPasajeros] AS TABLE(
	[TipId] [varchar](2) NOT NULL,
	[Documento] [varchar](16) NOT NULL,
	[Apellidos] [varchar](250) NULL,
	[Nombres] [varchar](250) NULL,
	[Cargo] [varchar](250) NULL,
	[EsMonitor] [bit] NULL,
	[Telefono] [varchar](20) NULL,
	[Observacion] [varchar](250) NULL,
	[EsEstudiante] [bit] NULL,
	[IdResponsable] [varchar](16) NULL,
	[Porcentaje] [decimal](14, 4) NULL,
	[VrPago] [decimal](14, 4) NULL,
	[IdColegio] [varchar](4) NULL,
	[CdEstudiante] [varchar](16) NULL,
	[Jornada] [varchar](250) NULL,
	[Sede] [varchar](4) NULL,
	[Inactivo] [bit] NULL,
	[FechaNac] [smalldatetime] NULL,
	[IncluirPeriodo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPedAnexo]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspPedAnexo] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Pedido] [int] NULL,
	[IdCia] [char](2) NULL,
	[NomCliente] [varchar](150) NULL,
	[DirCliente] [varchar](250) NULL,
	[NomContacto] [varchar](150) NULL,
	[TelContacto] [varchar](30) NULL,
	[emlContacto] [varchar](100) NULL,
	[emlCliente] [varchar](100) NULL,
	[DescripCarga] [varchar](250) NULL,
	[Clausulas] [varchar](2500) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPedDetalle]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspPedDetalle] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Pedido] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[CdTipVeh] [varchar](4) NULL,
	[NumPasajeros] [int] NULL,
	[Parada] [varchar](10) NULL,
	[PesoNeto] [decimal](12, 4) NULL,
	[VrUnitario] [money] NULL,
	[IdRuta] [varchar](4) NULL,
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[EsRutaCliente] [bit] NULL,
	[CdCiuOrigen] [varchar](8) NULL,
	[DirOrigen] [varchar](max) NULL,
	[FecOrigen] [datetime] NULL,
	[CdCiuDestino] [varchar](8) NULL,
	[DirDestino] [varchar](max) NULL,
	[FecDestino] [datetime] NULL,
	[CdTipRuta] [varchar](15) NULL,
	[CdTipServicio] [varchar](20) NULL,
	[DiasDisp] [int] NULL,
	[VrDia] [money] NULL,
	[TipCtn] [varchar](3) NULL,
	[NumCnt] [int] NULL,
	[IdCiaCnt] [char](2) NULL,
	[ItemCnt] [int] NULL,
	[CantVeh] [int] NULL,
	[Retorno] [bit] NULL,
	[VrMonitor] [decimal](14, 4) NULL,
	[CantMonitor] [int] NULL,
	[TipoTarifa] [varchar](10) NULL,
	[Dias] [int] NULL,
	[Itinerario] [varchar](1000) NULL,
	[VLargo] [bit] NULL,
	[ItemPpalRet] [int] NULL,
	[CiaPpalRet] [char](2) NULL,
	[VrPago] [money] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPedido]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspPedido] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Pedido] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [smalldatetime] NULL,
	[FechaVence] [smalldatetime] NULL,
	[FecInicio] [smalldatetime] NULL,
	[FecFinal] [smalldatetime] NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL,
	[IdVend] [varchar](16) NULL,
	[IdTarifCom] [varchar](4) NULL,
	[TipoContrato] [varchar](10) NULL,
	[TipoPago] [varchar](10) NULL,
	[Modalidad] [varchar](10) NULL,
	[Vigencia] [varchar](10) NULL,
	[VrCobro] [money] NULL,
	[VrPagos] [money] NULL,
	[VrCargos] [money] NULL,
	[VrDctos] [money] NULL,
	[VrIva] [money] NULL,
	[CdDescuento] [varchar](4) NULL,
	[Presupuesto] [money] NULL,
	[CantPasajeros] [decimal](14, 4) NULL,
	[Cantidad] [decimal](14, 4) NULL,
	[Peso] [decimal](14, 4) NULL,
	[IdMneda] [varchar](5) NULL,
	[NumAprob] [int] NULL,
	[IdCiaApr] [char](2) NULL,
	[FecAprob] [smalldatetime] NULL,
	[EsLicitacion] [bit] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL,
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](1000) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL,
	[CdCarga] [varchar](15) NULL,
	[VrEditado] [money] NULL,
	[CantDias] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPicoPlaca]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspPicoPlaca] AS TABLE(
	[IdLocal] [varchar](8) NULL,
	[Fecha] [datetime] NULL,
	[UltimoDig] [varchar](50) NULL,
	[Observacion] [varchar](250) NULL,
	[ClaseMat] [varchar](250) NULL,
	[IdTipoVeh] [varchar](250) NULL,
	[Horas] [varchar](250) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspPrograma]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspPrograma] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Programa] [int] NULL,
	[IdCia] [char](2) NULL,
	[Fecha] [datetime] NULL,
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL,
	[FecDev] [smalldatetime] NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspProgramaDet]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspProgramaDet] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Programa] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[FechaInicio] [datetime] NULL,
	[FechaFin] [datetime] NULL,
	[TipDocRes] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCiaRes] [char](2) NULL,
	[ItemRes] [int] NULL,
	[IdOrigen] [varchar](8) NULL,
	[IdDestino] [varchar](8) NULL,
	[IdVehiculo] [varchar](10) NULL,
	[CdTipVeh] [varchar](4) NULL,
	[IdConductor] [varchar](16) NULL,
	[NumPasajeros] [int] NULL,
	[TipDocFuec] [varchar](3) NULL,
	[NumFuec] [int] NULL,
	[IdCiaFuec] [char](2) NULL,
	[TipDocOdp] [varchar](3) NULL,
	[NumOdp] [int] NULL,
	[IdCiaOdp] [char](2) NULL,
	[FechaOdp] [smalldatetime] NULL,
	[IdNovedad] [varchar](4) NULL,
	[Novedad] [varchar](250) NULL,
	[Cumplido] [bit] NULL,
	[FecIniCump] [datetime] NULL,
	[FecFinCump] [datetime] NULL,
	[VrCobro] [money] NULL,
	[VrPagos] [money] NULL,
	[DiasDisp] [int] NULL,
	[Parada] [varchar](10) NULL,
	[CdTipServicio] [varchar](20) NULL,
	[DirOrigen] [varchar](max) NULL,
	[DirDestino] [varchar](max) NULL,
	[IdRuta] [varchar](4) NULL,
	[CdTipRuta] [varchar](15) NULL,
	[PesoNeto] [decimal](12, 4) NULL,
	[EstadoItem] [bit] NULL,
	[VrMonitor] [decimal](14, 4) NULL,
	[CantMonitor] [int] NULL,
	[VrRecorrido] [decimal](14, 4) NULL,
	[Observacion] [varchar](max) NULL,
	[VLargo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspProgramaPers]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspProgramaPers] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Programa] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[Nit] [varchar](16) NULL,
	[IdNovedad] [varchar](4) NULL,
	[Novedad] [varchar](250) NULL,
	[Cumplido] [bit] NULL,
	[IdRuta] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspResAnexo]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspResAnexo] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCia] [char](2) NULL,
	[NomCliente] [varchar](250) NULL,
	[TelCliente] [varchar](100) NULL,
	[emlCliente] [varchar](150) NULL,
	[DireccionCli] [varchar](100) NULL,
	[Observacion] [varchar](1000) NULL,
	[NombArchivo] [varchar](100) NULL,
	[DescripCarga] [varchar](250) NULL,
	[Clausulas] [varchar](2500) NULL,
	[Responsable] [varchar](100) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspResDetalle]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspResDetalle] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Reserva] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[ItemCnt] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[CdTipVeh] [varchar](4) NULL,
	[IdConductor] [varchar](16) NULL,
	[IdRuta] [varchar](4) NULL,
	[CdTipRuta] [varchar](15) NULL,
	[NumPasajeros] [int] NULL,
	[PesoNeto] [decimal](12, 4) NULL,
	[VrCobro] [money] NULL,
	[VrPagos] [money] NULL,
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[EsRutaCliente] [bit] NULL,
	[CdCiuOrigen] [varchar](8) NULL,
	[DirOrigen] [varchar](max) NULL,
	[FecOrigen] [datetime] NULL,
	[CdCiuDestino] [varchar](8) NULL,
	[DirDestino] [varchar](max) NULL,
	[FecDestino] [datetime] NULL,
	[DiasDisp] [int] NULL,
	[VrDia] [money] NULL,
	[Parada] [varchar](10) NULL,
	[CdTipServicio] [varchar](20) NULL,
	[EstadoItem] [varchar](20) NULL,
	[VrMonitor] [decimal](14, 4) NULL,
	[CantMonitor] [int] NULL,
	[VrRecorrido] [decimal](14, 4) NULL,
	[NumDias] [int] NULL,
	[TipoTarifa] [varchar](10) NULL,
	[IdColegio] [varchar](4) NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaFac] [char](2) NULL,
	[FechaFac] [smalldatetime] NULL,
	[TipCum] [varchar](3) NULL,
	[Cumplido] [int] NULL,
	[IdCiaCum] [char](2) NULL,
	[FechaCum] [smalldatetime] NULL,
	[Codigo] [varchar](3) NULL,
	[Itinerario] [varchar](1000) NULL,
	[VLargo] [bit] NULL,
	[IdOtroSi] [int] NULL,
	[EsItemPME] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspReservas]    Script Date: 10/12/2025 8:10:56 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspReservas] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('RES'),
	[Reserva] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [datetime] NULL,
	[FechaInicio] [datetime] NULL,
	[FechaFin] [datetime] NULL,
	[TipDocCnt] [varchar](3) NULL,
	[Contrato] [int] NULL,
	[IdCiaCnt] [char](2) NULL,
	[EstadoRes] [varchar](20) NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL DEFAULT ('0'),
	[IdMneda] [varchar](5) NULL DEFAULT ('COP'),
	[CdCarga] [varchar](15) NULL,
	[Modalidad] [varchar](10) NULL,
	[TipoLiquid] [varchar](8) NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [int] NULL DEFAULT ((0)),
	[IdCiaFac] [char](2) NULL DEFAULT ('00'),
	[FechaFac] [smalldatetime] NULL,
	[TipFuec] [varchar](3) NULL,
	[NumFuec] [int] NULL DEFAULT ((0)),
	[IdCiaFuec] [char](2) NULL DEFAULT ('00'),
	[VrCobro] [money] NULL DEFAULT ((0)),
	[VrPagos] [money] NULL DEFAULT ((0)),
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL,
	[IdGrupo] [varchar](4) NULL,
	[IdRutaG] [varchar](4) NULL,
	[NoRequiereGIE] [bit] NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspReservaVehLista]    Script Date: 10/12/2025 8:10:57 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspReservaVehLista] AS TABLE(
	[IdLista] [int] NOT NULL,
	[TipDoc] [varchar](3) NOT NULL,
	[Reserva] [int] NOT NULL,
	[IdCia] [char](2) NOT NULL,
	[Item] [int] NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[Fecha] [datetime] NOT NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[IdListaCOE] [int] NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraEspSedes]    Script Date: 10/12/2025 8:10:57 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraEspSedes] AS TABLE(
	[IdColegio] [varchar](4) NULL,
	[IdSede] [varchar](4) NULL,
	[NomSede] [varchar](250) NULL,
	[Inactivo] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraInfViajes]    Script Date: 10/12/2025 8:10:57 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraInfViajes] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('OCV'),
	[NumViaje] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[IdOrigen] [varchar](8) NOT NULL,
	[IdDestino] [varchar](8) NOT NULL,
	[IdRuta] [varchar](4) NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdPoseedor] [varchar](16) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[nRemolque] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NOT NULL DEFAULT ('TERCEROS'),
	[VrFletes] [money] NOT NULL DEFAULT ((0)),
	[PesoTotal] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[NumManif] [int] NOT NULL DEFAULT ((0)),
	[IdCiaManif] [char](2) NOT NULL DEFAULT ('00'),
	[NumMintrans] [decimal](14, 2) NOT NULL DEFAULT ((0)),
	[MvoAnulacion] [varchar](5) NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraInfViajesOrd]    Script Date: 10/12/2025 8:10:58 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraInfViajesOrd] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('OCV'),
	[NumViaje] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[TipOrden] [varchar](3) NOT NULL DEFAULT ('OCT'),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCiaOrd] [char](2) NOT NULL DEFAULT ('01'),
	[ItemOrd] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraManifAnexo]    Script Date: 10/12/2025 8:10:58 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraManifAnexo] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[kmsTotal] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[VrFleteTon] [money] NOT NULL DEFAULT ((0)),
	[TipoRuta] [varchar](10) NULL DEFAULT ('URBANO'),
	[CdLocTrao] [varchar](8) NULL,
	[CdLocTrad] [varchar](8) NULL,
	[KmsTraOri] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[KmsTraDes] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[IdMneda] [varchar](5) NOT NULL DEFAULT ('COP'),
	[VrTasa] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[NomRemite] [varchar](150) NULL,
	[NomDestino] [varchar](150) NULL,
	[LugarFletes] [varchar](100) NULL,
	[NumAnticipo] [int] NOT NULL DEFAULT ((0)),
	[NumCheque] [varchar](20) NULL,
	[TipoMintrans] [varchar](10) NULL DEFAULT ('GENERAL'),
	[MucMintrans] [int] NOT NULL DEFAULT ((0)),
	[ContIntegral] [int] NOT NULL DEFAULT ((0)),
	[VolumenCarga] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[NumPoliza] [varchar](30) NULL,
	[CdBodDtno] [varchar](4) NULL,
	[TipoTrslado] [int] NULL DEFAULT ((0)),
	[MvoAnulacion] [varchar](5) NULL,
	[MvoSuspension] [varchar](5) NULL,
	[WsSeguro] [bit] NULL DEFAULT ((0)),
	[NumRadSeguro] [decimal](18, 2) NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraManifiesto]    Script Date: 10/12/2025 8:10:59 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraManifiesto] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[FecDespacho] [smalldatetime] NOT NULL,
	[FecEntrega] [smalldatetime] NULL,
	[IdOrigen] [varchar](8) NOT NULL,
	[IdDestino] [varchar](8) NOT NULL,
	[IdRuta] [varchar](4) NOT NULL,
	[IdRutaFle] [varchar](4) NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[nRemolque] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NOT NULL DEFAULT ('TERCEROS'),
	[IdPropietario] [varchar](16) NOT NULL,
	[IdPoseedor] [varchar](16) NOT NULL,
	[VrFletes] [money] NOT NULL DEFAULT ((0)),
	[VrRetencion] [money] NOT NULL DEFAULT ((0)),
	[VrReteIca] [money] NOT NULL DEFAULT ((0)),
	[VrDescuento] [money] NOT NULL DEFAULT ((0)),
	[VrAnticipo] [money] NOT NULL DEFAULT ((0)),
	[VrAntAdic] [money] NOT NULL DEFAULT ((0)),
	[VrNeto] [money] NOT NULL DEFAULT ((0)),
	[VrPagos] [money] NOT NULL DEFAULT ((0)),
	[VrCargos] [money] NOT NULL DEFAULT ((0)),
	[VrDctos] [money] NOT NULL DEFAULT ((0)),
	[TarifaFlete] [money] NOT NULL DEFAULT ((0)),
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoTotal] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[BaseRet] [money] NOT NULL DEFAULT ((0)),
	[TarifaRet] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[TarifaIca] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[CodTarRet] [varchar](4) NULL,
	[CodTarIca] [varchar](4) NULL,
	[IdLocFletes] [varchar](8) NOT NULL,
	[FechaPago] [smalldatetime] NULL,
	[PagoCargue] [varchar](50) NOT NULL,
	[PagoDescargue] [varchar](50) NOT NULL,
	[NumMintrans] [decimal](14, 2) NOT NULL DEFAULT ((0)),
	[EdoMintrans] [varchar](5) NULL,
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('00'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCump] [char](2) NOT NULL DEFAULT ('00'),
	[FechaCump] [smalldatetime] NULL,
	[EstCumplido] [int] NOT NULL DEFAULT ((0)),
	[TipOdp] [varchar](3) NOT NULL DEFAULT ('0'),
	[OrdPago] [int] NOT NULL DEFAULT ((0)),
	[IdCiaOdp] [char](2) NOT NULL DEFAULT ('00'),
	[FechaOdp] [smalldatetime] NULL,
	[EstOrden] [int] NOT NULL DEFAULT ((0)),
	[OrigenAdd] [varchar](10) NOT NULL,
	[TipCom] [varchar](3) NOT NULL DEFAULT ('0'),
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL DEFAULT ('00'),
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[VrFleteNeto] [money] NOT NULL DEFAULT ((0)),
	[TipInfVia] [varchar](3) NULL,
	[NumViaje] [int] NOT NULL DEFAULT ((0)),
	[CiaInfViaje] [char](2) NULL,
	[CdCatPeaje] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraManifRem]    Script Date: 10/12/2025 8:11:02 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraManifRem] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[TipRem] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('01'),
	[ItemRem] [int] NOT NULL DEFAULT ((0)),
	[TarifTabla] [money] NOT NULL DEFAULT ((0)),
	[TarifPago] [money] NOT NULL DEFAULT ((0)),
	[RemMintrans] [decimal](14, 2) NOT NULL DEFAULT ((0)),
	[EdoRemMin] [varchar](5) NULL,
	[CodBodDtno] [varchar](4) NULL,
	[TipTraslado] [int] NULL DEFAULT ((0)),
	[HorasCargue] [decimal](14, 4) NULL DEFAULT ((0)),
	[HorasDesc] [decimal](14, 4) NULL DEFAULT ((0)),
	[FecInicioCargue] [smalldatetime] NULL,
	[FecFinCargue] [smalldatetime] NULL,
	[FecIniciodesc] [smalldatetime] NULL,
	[FecFindesc] [smalldatetime] NULL,
	[TiempoCargue] [decimal](14, 4) NULL DEFAULT ((0)),
	[TiempoDesc] [decimal](14, 4) NULL DEFAULT ((0)),
	[FecLlegCargue] [smalldatetime] NULL,
	[FecSalidaCargue] [smalldatetime] NULL,
	[FecLlegdesc] [smalldatetime] NULL,
	[FecSalidadesc] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenAbo]    Script Date: 10/12/2025 8:11:03 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenAbo] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Documento] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NULL,
	[TipAnt] [varchar](3) NULL DEFAULT ('AOS'),
	[Anticipo] [int] NULL DEFAULT ((0)),
	[IdCiaAnt] [char](2) NULL,
	[VrAbono] [money] NULL DEFAULT ((0)),
	[TipoAplica] [varchar](10) NULL DEFAULT ('OPAGO'),
	[Observacion] [varchar](250) NULL,
	[CodCuenta] [varchar](16) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenAnt]    Script Date: 10/12/2025 8:11:03 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenAnt] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('AOS'),
	[Anticipo] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipOds] [varchar](3) NULL DEFAULT ('OSA'),
	[NumOrden] [int] NULL DEFAULT ((0)),
	[IdCiaOds] [char](2) NULL DEFAULT ('01'),
	[VrAnticipo] [money] NULL DEFAULT ((0)),
	[VrAbonado] [money] NULL DEFAULT ((0)),
	[TipoPago] [varchar](10) NOT NULL DEFAULT ('EFECTIVO'),
	[NumCheque] [varchar](20) NULL,
	[FecCheque] [smalldatetime] NULL,
	[IdCta] [varchar](4) NULL DEFAULT ('0'),
	[IdCuenta] [varchar](16) NULL,
	[Beneficiario] [varchar](150) NULL,
	[CedBenef] [varchar](16) NULL,
	[FechaVence] [smalldatetime] NULL,
	[TipCom] [varchar](3) NULL DEFAULT ('0'),
	[Comprobante] [int] NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NULL DEFAULT ('00'),
	[Anulado] [bit] NULL DEFAULT ((0)),
	[NumDev] [int] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenCum]    Script Date: 10/12/2025 8:11:05 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenCum] AS TABLE(
	[TipDoc] [varchar](3) NULL DEFAULT ('COS'),
	[Cumplido] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NULL,
	[TipOds] [varchar](3) NULL,
	[NumOrden] [int] NULL DEFAULT ((0)),
	[IdCiaOds] [char](2) NULL DEFAULT ('01'),
	[TipoAfiVehic] [varchar](10) NULL DEFAULT ('TERCEROS'),
	[FecDespacho] [smalldatetime] NULL,
	[FecRecibo] [smalldatetime] NULL,
	[FecIngCertif] [smalldatetime] NULL,
	[FecCertificado] [smalldatetime] NULL,
	[DescServicio] [varchar](100) NULL,
	[Cantidad] [decimal](14, 4) NULL DEFAULT ((0)),
	[VrTotal] [money] NULL DEFAULT ((0)),
	[VrCosto] [money] NULL DEFAULT ((0)),
	[RemCliente] [varchar](30) NULL,
	[Funcionario] [varchar](150) NULL,
	[TipCom] [varchar](3) NULL DEFAULT ('0'),
	[Comprobante] [int] NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NULL DEFAULT ('00'),
	[Anulado] [bit] NULL DEFAULT ((0)),
	[NumDev] [int] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](1000) NULL,
	[IdEstado] [varchar](4) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL,
	[CdTarIva] [varchar](4) NULL,
	[CdTarRiv] [varchar](4) NULL,
	[CdTarRet] [varchar](4) NULL,
	[CdTarIca] [varchar](4) NULL,
	[CdTarRtc] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenCumDet]    Script Date: 10/12/2025 8:11:05 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenCumDet] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('COS'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[IdMercancia] [varchar](16) NOT NULL,
	[Descripcion] [varchar](250) NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndMed] [varchar](10) NOT NULL,
	[VrUnitario] [money] NOT NULL DEFAULT ((0)),
	[TarifaPago] [money] NOT NULL DEFAULT ((0)),
	[DocCliente] [varchar](30) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenDet]    Script Date: 10/12/2025 8:11:06 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenDet] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('OST'),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[IdMercancia] [varchar](16) NOT NULL,
	[Descripcion] [varchar](250) NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndMed] [varchar](10) NOT NULL,
	[VrUnitario] [money] NOT NULL DEFAULT ((0)),
	[TarifaPago] [money] NOT NULL DEFAULT ((0)),
	[CantCump] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[TarifaCump] [money] NOT NULL DEFAULT ((0)),
	[PagoCump] [money] NOT NULL DEFAULT ((0)),
	[DocCliente] [varchar](30) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenOper]    Script Date: 10/12/2025 8:11:07 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenOper] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[NumOrden] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Item] [int] NULL DEFAULT ((0)),
	[IdOperario] [varchar](16) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraOrdenServ]    Script Date: 10/12/2025 8:11:07 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraOrdenServ] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[NumOrden] [int] NULL DEFAULT ((0)),
	[IdCia] [char](2) NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NULL,
	[FecDespacho] [smalldatetime] NULL,
	[FecRecibo] [smalldatetime] NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL DEFAULT ('0'),
	[IdVehiculo] [varchar](10) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[nRemolque] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NOT NULL DEFAULT ('TERCEROS'),
	[Modalidad] [varchar](10) NULL,
	[VrTotal] [money] NULL DEFAULT ((0)),
	[VrCosto] [money] NULL DEFAULT ((0)),
	[Cantidad] [decimal](14, 4) NULL DEFAULT ((0)),
	[VrAnticipo] [money] NULL DEFAULT ((0)),
	[IdDestino] [varchar](8) NULL,
	[TipoOrden] [varchar](10) NULL,
	[IdEstacion] [varchar](4) NULL,
	[NomEstacion] [varchar](50) NULL,
	[TipoResiduo] [varchar](100) NULL,
	[RemCliente] [varchar](30) NULL,
	[NomRecibido] [varchar](150) NULL,
	[FecIngCertif] [smalldatetime] NULL,
	[FecCertificado] [smalldatetime] NULL,
	[NumRemesa] [int] NULL DEFAULT ((0)),
	[CdCiaRem] [char](2) NULL DEFAULT ('00'),
	[EstCumplido] [int] NULL DEFAULT ((0)),
	[EstFactura] [int] NULL DEFAULT ((0)),
	[TipFact] [varchar](3) NULL,
	[NumFactura] [int] NULL DEFAULT ((0)),
	[CdCiaFact] [char](2) NULL,
	[kmtInicial] [int] NULL DEFAULT ((0)),
	[kmtFinal] [int] NULL DEFAULT ((0)),
	[EstOrden] [int] NULL DEFAULT ((0)),
	[TipLiq] [varchar](3) NULL,
	[NumLiquida] [int] NULL DEFAULT ((0)),
	[CdCiaLiq] [char](2) NULL,
	[OrigenAdd] [varchar](10) NULL,
	[Anulado] [bit] NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](1000) NULL,
	[IdEstado] [varchar](4) NULL,
	[TimeSys] [smalldatetime] NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NULL,
	[NumAprob] [int] NULL DEFAULT ((0)),
	[IdCiaApr] [char](2) NULL DEFAULT ('00'),
	[FecAprob] [smalldatetime] NULL,
	[UsuAprob] [varchar](11) NULL,
	[ObservAprob] [varchar](250) NULL,
	[CdRuta] [varchar](4) NULL,
	[IdOrigen] [varchar](8) NULL,
	[Cantkms] [int] NULL DEFAULT ((0)),
	[NumCump] [int] NULL DEFAULT ((0)),
	[CdCiaCum] [char](2) NULL,
	[CdTarIva] [varchar](4) NULL,
	[CdTarRiv] [varchar](4) NULL,
	[CdTarRet] [varchar](4) NULL,
	[CdTarIca] [varchar](4) NULL,
	[CdTarRtc] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraPedAnexo]    Script Date: 10/12/2025 8:11:08 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraPedAnexo] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('PDT'),
	[Pedido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[NomCliente] [varchar](150) NULL,
	[NomRemite] [varchar](150) NULL,
	[NomDestino] [varchar](150) NULL,
	[LugarCargue] [varchar](150) NULL,
	[LugarDescargue] [varchar](150) NULL,
	[NomContacto] [varchar](150) NULL,
	[TelContacto] [varchar](30) NULL,
	[emlContacto] [varchar](100) NULL,
	[ContacDestino] [varchar](150) NULL,
	[TelContacDest] [varchar](30) NULL,
	[emlContacDest] [varchar](100) NULL,
	[PolizaEsp] [bit] NOT NULL DEFAULT ((0)),
	[NumPolizaEsp] [varchar](50) NULL,
	[NitCiaPoliza] [varchar](16) NULL,
	[NomCiaPoliza] [varchar](150) NULL,
	[FecVencePol] [smalldatetime] NULL,
	[VrLimiteDesp] [money] NOT NULL DEFAULT ((0)),
	[Seguros] [varchar](10) NOT NULL DEFAULT ('EMPRESA'),
	[Cargue] [varchar](20) NOT NULL DEFAULT ('CLIENTE'),
	[Descargue] [varchar](20) NOT NULL DEFAULT ('CLIENTE'),
	[CdTipoEsc] [varchar](4) NULL DEFAULT ('0'),
	[NitSIA] [varchar](16) NULL,
	[NombreSIA] [varchar](150) NULL,
	[ContactoSIA] [varchar](150) NULL,
	[TelContacSIA] [varchar](30) NULL,
	[TipoRuta] [varchar](10) NOT NULL DEFAULT ('NACIONAL'),
	[TipoTrans] [varchar](10) NOT NULL DEFAULT ('GENERAL'),
	[Embarque] [varchar](10) NOT NULL DEFAULT ('SUELTA'),
	[CdTipCarga] [varchar](4) NULL,
	[DevContenedor] [bit] NOT NULL DEFAULT ((0)),
	[IdLocCont] [varchar](8) NULL,
	[PatioCont] [varchar](50) NULL,
	[CdTipoVeh] [varchar](4) NOT NULL DEFAULT ('0'),
	[MargenFalt] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[TipoMargen] [varchar](10) NOT NULL DEFAULT ('UNIDAD'),
	[UndCalcFalt] [varchar](10) NULL DEFAULT ('PESO'),
	[TarifFaltPago] [money] NOT NULL DEFAULT ((0)),
	[TarifFaltCobro] [money] NOT NULL DEFAULT ((0)),
	[EmbAdicional] [varchar](150) NULL,
	[CdRutaTarif] [varchar](4) NULL,
	[TipoServicio] [varchar](10) NULL,
	[CodTipoOper] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraPedido]    Script Date: 10/12/2025 8:11:10 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraPedido] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('PDT'),
	[Pedido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[FechaVence] [smalldatetime] NOT NULL,
	[FecDespacho] [smalldatetime] NOT NULL,
	[FecEntrega] [smalldatetime] NULL,
	[IdCliente] [varchar](16) NOT NULL,
	[IdAgencia] [varchar](16) NOT NULL DEFAULT ('0'),
	[IdClieFact] [varchar](16) NOT NULL,
	[IdRemitente] [varchar](16) NOT NULL,
	[IdDestinatario] [varchar](16) NOT NULL,
	[IdLocOrigen] [varchar](8) NOT NULL,
	[IdLocDestino] [varchar](8) NOT NULL,
	[IdVend] [varchar](16) NOT NULL,
	[IdTarifCom] [varchar](4) NOT NULL DEFAULT ('0'),
	[Modalidad] [varchar](10) NOT NULL,
	[Vigencia] [varchar](10) NOT NULL DEFAULT ('NORMAL'),
	[TipoTarifa] [varchar](10) NOT NULL DEFAULT ('PEDIDO'),
	[VrCobro] [money] NOT NULL DEFAULT ((0)),
	[VrPagos] [money] NOT NULL DEFAULT ((0)),
	[VrFletes] [money] NOT NULL DEFAULT ((0)),
	[VrCargue] [money] NOT NULL DEFAULT ((0)),
	[VrDesCargue] [money] NOT NULL DEFAULT ((0)),
	[VrEscolta] [money] NOT NULL DEFAULT ((0)),
	[VrDevContdor] [money] NOT NULL DEFAULT ((0)),
	[VrTraUrbano] [money] NOT NULL DEFAULT ((0)),
	[VrEmbalajes] [money] NOT NULL DEFAULT ((0)),
	[VrCargos] [money] NOT NULL DEFAULT ((0)),
	[VrDctos] [money] NOT NULL DEFAULT ((0)),
	[VrDeclarado] [money] NOT NULL DEFAULT ((0)),
	[VrSeguro] [money] NOT NULL DEFAULT ((0)),
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[CantDesp] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[IdMneda] [varchar](5) NOT NULL DEFAULT ('COP'),
	[VrTasa] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[Cotizacion] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCot] [char](2) NOT NULL DEFAULT ('00'),
	[NumAprob] [int] NOT NULL DEFAULT ((0)),
	[IdCiaApr] [char](2) NOT NULL DEFAULT ('01'),
	[FecAprob] [smalldatetime] NULL,
	[TipOdc] [varchar](3) NOT NULL DEFAULT ('OCT'),
	[OCargue] [int] NOT NULL DEFAULT ((0)),
	[IdCiaOdc] [char](2) NOT NULL DEFAULT ('01'),
	[FechaOdc] [smalldatetime] NULL,
	[TipRem] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('01'),
	[FechaRem] [smalldatetime] NULL,
	[TipFac] [varchar](3) NOT NULL DEFAULT ('FCR'),
	[Factura] [int] NOT NULL DEFAULT ((0)),
	[IdCiaFac] [char](2) NOT NULL DEFAULT ('00'),
	[FechaFac] [smalldatetime] NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraPedMcias]    Script Date: 10/12/2025 8:11:12 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraPedMcias] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('PDT'),
	[Pedido] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[IdMercancia] [varchar](16) NOT NULL,
	[DescripMcias] [varchar](250) NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoNeto] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndMed] [varchar](10) NOT NULL,
	[dmsAlto] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[dmsAncho] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[dmsLargo] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[Volumen] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndVol] [varchar](10) NOT NULL,
	[IdUnd] [varchar](4) NOT NULL,
	[IdEmp] [varchar](4) NOT NULL DEFAULT ('0'),
	[IdNat] [varchar](4) NOT NULL,
	[IdMnjo] [varchar](4) NOT NULL,
	[IdTmcia] [varchar](4) NOT NULL,
	[CdRango] [varchar](4) NULL,
	[Cases] [int] NOT NULL DEFAULT ((0)),
	[Cajas] [int] NOT NULL DEFAULT ((0)),
	[Palets] [int] NOT NULL DEFAULT ((0)),
	[NitRemite] [varchar](16) NOT NULL,
	[Remitente] [varchar](250) NOT NULL,
	[DirOrigen] [varchar](250) NOT NULL,
	[IdOrigen] [varchar](8) NOT NULL,
	[NitDestntario] [varchar](16) NOT NULL,
	[Destinatario] [varchar](250) NOT NULL DEFAULT ('varios'),
	[DirDestino] [varchar](250) NOT NULL,
	[IdDestino] [varchar](8) NOT NULL,
	[TarifClie] [money] NOT NULL DEFAULT ((0)),
	[TarifPago] [money] NOT NULL DEFAULT ((0)),
	[TarifTabla] [money] NOT NULL DEFAULT ((0)),
	[VrDeclarado] [money] NOT NULL DEFAULT ((0)),
	[VrSeguro] [money] NOT NULL DEFAULT ((0)),
	[TarifSeguro] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Contenedor1] [varchar](50) NULL,
	[Contenedor2] [varchar](50) NULL,
	[UndTarifa] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[UndTarifPago] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[DocCliente] [varchar](30) NULL,
	[Referencia3] [varchar](50) NULL,
	[CdTipoVehic] [varchar](4) NULL,
	[Tipo_Servicio] [varchar](10) NULL,
	[SedeRem] [varchar](10) NULL,
	[SedeDest] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemAnexo]    Script Date: 10/12/2025 8:11:14 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraRemAnexo] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[IdVend] [varchar](16) NOT NULL,
	[IdTarifCom] [varchar](4) NOT NULL DEFAULT ('0'),
	[NomCliente] [varchar](150) NULL,
	[NomRemite] [varchar](150) NULL,
	[NomDestino] [varchar](150) NULL,
	[LugarCargue] [varchar](150) NULL,
	[LugarDescargue] [varchar](150) NULL,
	[NomContacto] [varchar](150) NULL,
	[TelContacto] [varchar](30) NULL,
	[emlContacto] [varchar](100) NULL,
	[ContacDestino] [varchar](150) NULL,
	[TelContacDest] [varchar](30) NULL,
	[emlContacDest] [varchar](100) NULL,
	[TomadorPoliza] [char](1) NOT NULL DEFAULT ('N'),
	[PolizaSeguro] [varchar](50) NULL,
	[NitCiaPoliza] [varchar](16) NULL,
	[NomCiaPoliza] [varchar](150) NULL,
	[FecVencePol] [smalldatetime] NULL,
	[ManifMintrans] [decimal](14, 2) NOT NULL DEFAULT ((0)),
	[RemMintrans] [decimal](14, 2) NOT NULL DEFAULT ((0)),
	[TipSal] [varchar](3) NULL,
	[NumSalida] [int] NOT NULL DEFAULT ((0)),
	[IdCiaSal] [char](2) NULL DEFAULT ('00'),
	[NumInvent] [int] NOT NULL DEFAULT ((0)),
	[IdCiaInv] [char](2) NULL DEFAULT ('00'),
	[TipoRuta] [varchar](10) NOT NULL DEFAULT ('URBANO'),
	[TipoMintrans] [varchar](10) NULL DEFAULT ('GENERAL'),
	[NitEmpTransp] [varchar](16) NULL,
	[NumFactEmp] [varchar](20) NULL,
	[MvoAnulacion] [varchar](3) NULL,
	[PactoCargue] [bit] NOT NULL DEFAULT ((0)),
	[HorasPactoCargue] [int] NOT NULL DEFAULT ((0)),
	[MinPactoCargue] [int] NOT NULL DEFAULT ((0)),
	[HoraCitaCargue] [smalldatetime] NULL,
	[HoraLlegaCargue] [smalldatetime] NULL,
	[HoraEntraCargue] [smalldatetime] NULL,
	[HoraSaleCargue] [smalldatetime] NULL,
	[PactoDescargue] [bit] NOT NULL DEFAULT ((0)),
	[HorasPactoDescargue] [int] NOT NULL DEFAULT ((0)),
	[MinPactoDescargue] [int] NOT NULL DEFAULT ((0)),
	[HoraCitaDescargue] [smalldatetime] NULL,
	[HoraLlegaDescargue] [smalldatetime] NULL,
	[HoraEntraDescargue] [smalldatetime] NULL,
	[HoraSaleDescargue] [smalldatetime] NULL,
	[TipoDevRemesa] [varchar](3) NULL,
	[CodCiuTransb] [varchar](8) NULL,
	[MvoTransbordo] [varchar](3) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemCntdor]    Script Date: 10/12/2025 8:11:15 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraRemCntdor] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[NumOrden] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[IdTipoCon] [varchar](4) NULL,
	[NumContdor] [varchar](50) NULL,
	[PesoNeto] [decimal](14, 4) NULL,
	[IdTipoPre] [varchar](4) NULL,
	[NumPrecinto] [varchar](30) NULL,
	[ColorPrecinto] [varchar](20) NULL,
	[Sellos] [varchar](150) NULL,
	[Peligroso] [bit] NULL,
	[Perecedero] [bit] NULL,
	[Toxico] [bit] NULL,
	[Inflamable] [bit] NULL,
	[Difmanejo] [bit] NULL,
	[Fragil] [bit] NULL,
	[DevCont] [bit] NULL,
	[CdLocCont] [varchar](8) NULL,
	[PatioCont] [varchar](50) NULL,
	[Observacion] [varchar](150) NULL,
	[NumSalidaSello] [int] NULL,
	[CdCiaSalSello] [char](2) NULL,
	[ItemSalSello] [int] NULL,
	[CdProdSalida] [varchar](16) NULL,
	[NumSerialSello] [varchar](30) NULL,
	[NumComodato] [varchar](50) NULL,
	[FecVenceCom] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemesa]    Script Date: 10/12/2025 8:11:15 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraRemesa] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[FecDespacho] [smalldatetime] NOT NULL,
	[FecEntrega] [smalldatetime] NULL,
	[HoraLlegada] [smalldatetime] NULL,
	[IdCliente] [varchar](16) NOT NULL,
	[IdAgencia] [varchar](16) NOT NULL DEFAULT ('0'),
	[IdClieFact] [varchar](16) NOT NULL,
	[IdRemitente] [varchar](16) NOT NULL,
	[IdDestinatario] [varchar](16) NOT NULL,
	[IdLocOrigen] [varchar](8) NOT NULL,
	[IdLocDestino] [varchar](8) NOT NULL,
	[IdLocFletes] [varchar](8) NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[nRemolque] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NOT NULL DEFAULT ('TERCEROS'),
	[Modalidad] [varchar](10) NOT NULL,
	[TipoTarifa] [varchar](10) NOT NULL DEFAULT ('TABLA'),
	[VrCobro] [money] NOT NULL DEFAULT ((0)),
	[VrPagos] [money] NOT NULL DEFAULT ((0)),
	[VrFletes] [money] NOT NULL DEFAULT ((0)),
	[VrCargue] [money] NOT NULL DEFAULT ((0)),
	[VrDesCargue] [money] NOT NULL DEFAULT ((0)),
	[VrEscolta] [money] NOT NULL DEFAULT ((0)),
	[VrDevContdor] [money] NOT NULL DEFAULT ((0)),
	[VrTraUrbano] [money] NOT NULL DEFAULT ((0)),
	[VrEmbalajes] [money] NOT NULL DEFAULT ((0)),
	[VrCargos] [money] NOT NULL DEFAULT ((0)),
	[VrDctos] [money] NOT NULL DEFAULT ((0)),
	[VrDeclarado] [money] NOT NULL DEFAULT ((0)),
	[VrSeguro] [money] NOT NULL DEFAULT ((0)),
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoTotal] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[Items] [int] NOT NULL DEFAULT ((0)),
	[IdMneda] [varchar](5) NOT NULL DEFAULT ('COP'),
	[VrTasa] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[NumPedido] [int] NOT NULL DEFAULT ((0)),
	[IdCiaPed] [char](2) NOT NULL DEFAULT ('01'),
	[FechaPed] [smalldatetime] NULL,
	[TipDcm] [varchar](3) NOT NULL DEFAULT ('0'),
	[NumDocmto] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDcm] [char](2) NOT NULL DEFAULT ('01'),
	[FechaDcm] [smalldatetime] NULL,
	[NumManif] [int] NOT NULL DEFAULT ((0)),
	[IdCiaManif] [char](2) NOT NULL DEFAULT ('00'),
	[EstCumplido] [int] NOT NULL DEFAULT ((0)),
	[EstFactura] [int] NOT NULL DEFAULT ((0)),
	[CdConcepto] [varchar](4) NOT NULL DEFAULT ('0'),
	[CdRutaTarif] [varchar](4) NULL,
	[SerieGuia] [char](2) NOT NULL DEFAULT ('00'),
	[NumGuia] [int] NOT NULL DEFAULT ((0)),
	[CdForma] [varchar](4) NULL,
	[NumCausac] [int] NOT NULL DEFAULT ((0)),
	[CdCiaCausac] [char](2) NULL,
	[EdoCausac] [int] NOT NULL DEFAULT ((0)),
	[TipCom] [varchar](3) NOT NULL,
	[Comprobante] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCom] [char](2) NOT NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[Anulado] [bit] NOT NULL DEFAULT ((0)),
	[FecDev] [smalldatetime] NULL,
	[Observacion] [varchar](250) NULL,
	[IdEstado] [varchar](4) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL,
	[CdBodega] [varchar](4) NULL,
	[VigenciaOdc] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraRemMcias]    Script Date: 10/12/2025 8:11:18 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraRemMcias] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[IdMercancia] [varchar](16) NOT NULL,
	[DescripMcias] [varchar](250) NOT NULL,
	[Cantidad] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoNeto] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndMed] [varchar](10) NOT NULL,
	[dmsAlto] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[dmsAncho] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[dmsLargo] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[Volumen] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndVol] [varchar](10) NOT NULL,
	[IdUnd] [varchar](4) NOT NULL,
	[IdEmp] [varchar](4) NOT NULL,
	[IdNat] [varchar](4) NOT NULL,
	[IdTmcia] [varchar](4) NOT NULL,
	[IdMnjo] [varchar](4) NOT NULL,
	[CdRango] [varchar](4) NULL,
	[Cases] [int] NOT NULL DEFAULT ((0)),
	[Cajas] [int] NOT NULL DEFAULT ((0)),
	[Palets] [int] NOT NULL DEFAULT ((0)),
	[NitRemite] [varchar](16) NOT NULL,
	[Remitente] [varchar](250) NOT NULL,
	[DirOrigen] [varchar](250) NOT NULL,
	[IdOrigen] [varchar](8) NOT NULL,
	[NitDestntario] [varchar](16) NOT NULL,
	[Destinatario] [varchar](250) NOT NULL DEFAULT ('varios'),
	[DirDestino] [varchar](250) NOT NULL,
	[IdDestino] [varchar](8) NOT NULL,
	[TarifClie] [money] NOT NULL DEFAULT ((0)),
	[TarifPago] [money] NOT NULL DEFAULT ((0)),
	[TarifTabla] [money] NOT NULL DEFAULT ((0)),
	[VrDeclarado] [money] NOT NULL DEFAULT ((0)),
	[VrSeguro] [money] NOT NULL DEFAULT ((0)),
	[TarifSeguro] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[UndTarifa] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[UndTarifPago] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[Remision] [decimal](18, 2) NOT NULL DEFAULT ((0)),
	[DocCliente] [varchar](30) NOT NULL DEFAULT ('0'),
	[Referencia1] [varchar](50) NULL,
	[Referencia2] [varchar](50) NULL,
	[Referencia3] [varchar](50) NULL,
	[Contenedor1] [varchar](50) NULL,
	[Contenedor2] [varchar](50) NULL,
	[CdAgencia] [varchar](16) NOT NULL DEFAULT ('0'),
	[Cumplido] [int] NOT NULL DEFAULT ((0)),
	[IdCiaCump] [char](2) NOT NULL DEFAULT ('01'),
	[FechaCump] [smalldatetime] NULL,
	[DetalleCump] [varchar](250) NULL,
	[CantidadCump] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[PesoCump] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[VolCump] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[CasesCump] [int] NOT NULL DEFAULT ((0)),
	[CajasCump] [int] NOT NULL DEFAULT ((0)),
	[PaletsCump] [int] NOT NULL DEFAULT ((0)),
	[TarifCump] [money] NOT NULL DEFAULT ((0)),
	[PagoCump] [money] NOT NULL DEFAULT ((0)),
	[UndTarCump] [varchar](10) NOT NULL DEFAULT ('PESO'),
	[UndTarPagoCump] [varchar](10) NULL DEFAULT ('PESO'),
	[TipFac] [varchar](3) NOT NULL DEFAULT ('FCR'),
	[Factura] [int] NOT NULL DEFAULT ((0)),
	[IdCiaFac] [char](2) NOT NULL DEFAULT ('00'),
	[FechaFac] [smalldatetime] NULL,
	[TarifClieFac] [money] NOT NULL DEFAULT ((0)),
	[TipOdp] [varchar](3) NOT NULL DEFAULT ('0'),
	[NumeroOdp] [int] NOT NULL DEFAULT ((0)),
	[IdCiaOdp] [char](2) NOT NULL DEFAULT ('00'),
	[TarifOdp] [money] NOT NULL DEFAULT ((0)),
	[PesoCont] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[SedeRem] [varchar](10) NULL,
	[SedeDest] [varchar](10) NULL,
	[TipDocInv] [varchar](3) NULL,
	[NumDocInv] [int] NOT NULL DEFAULT ((0)),
	[IdCiaDocInv] [char](2) NULL DEFAULT ('00'),
	[ItemDocInv] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraReportes]    Script Date: 10/12/2025 8:11:21 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraReportes] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('MUC'),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[CdRuta] [varchar](4) NOT NULL,
	[IdPunto] [int] NOT NULL DEFAULT ((0)),
	[FecReporte] [smalldatetime] NOT NULL,
	[TipoRep] [varchar](10) NOT NULL,
	[EstadoRep] [int] NOT NULL DEFAULT ((0)),
	[IdUsuario] [varchar](11) NOT NULL,
	[FechaCrea] [smalldatetime] NOT NULL,
	[CdNovedad] [varchar](4) NULL,
	[ObservRep] [varchar](250) NULL,
	[TipoPunto] [varchar](10) NULL,
	[CdPuesto] [varchar](4) NULL,
	[NomConductor] [varchar](150) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraTrasladoRem]    Script Date: 10/12/2025 8:11:22 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraTrasladoRem] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('TRR'),
	[Traslado] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Item] [int] NOT NULL DEFAULT ((0)),
	[TipRem] [varchar](3) NOT NULL DEFAULT ('RMT'),
	[Remesa] [int] NOT NULL DEFAULT ((0)),
	[IdCiaRem] [char](2) NOT NULL DEFAULT ('01'),
	[ItemRem] [int] NOT NULL DEFAULT ((0)),
	[CdBodega] [varchar](4) NOT NULL,
	[EdoRecibido] [int] NOT NULL DEFAULT ((0)),
	[Comentarios] [varchar](250) NULL,
	[CdNovedad] [varchar](4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraTraslados]    Script Date: 10/12/2025 8:11:22 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraTraslados] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL DEFAULT ('TRR'),
	[Traslado] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('01'),
	[Fecha] [smalldatetime] NOT NULL,
	[FecDespacho] [smalldatetime] NOT NULL,
	[TipoTraslado] [int] NOT NULL DEFAULT ((0)),
	[IdBodega] [varchar](4) NOT NULL,
	[IdBodDtno] [varchar](4) NOT NULL,
	[IdVehiculo] [varchar](10) NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[Cantidad] [int] NOT NULL DEFAULT ((0)),
	[PesoTotal] [decimal](14, 4) NOT NULL DEFAULT ((0)),
	[Manifiesto] [int] NOT NULL DEFAULT ((0)),
	[CdCiaMuc] [char](2) NULL,
	[EstadoRec] [int] NOT NULL DEFAULT ((0)),
	[FechaRec] [smalldatetime] NULL,
	[CedRecibido] [varchar](16) NULL,
	[NomRecibido] [varchar](150) NULL,
	[Observacion] [varchar](1000) NULL,
	[OrigenAdd] [varchar](10) NOT NULL,
	[TimeSys] [smalldatetime] NOT NULL,
	[IdCiaCrea] [char](2) NOT NULL DEFAULT ('01'),
	[IdUsuario] [varchar](11) NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_TraTurn]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_TraTurn] AS TABLE(
	[Numero] [int] NOT NULL DEFAULT ((0)),
	[IdCia] [char](2) NOT NULL DEFAULT ('00'),
	[IdVehiculo] [varchar](10) NOT NULL,
	[IndTurno] [int] NOT NULL DEFAULT ((0)),
	[Fecha] [smalldatetime] NOT NULL,
	[IdConductor] [varchar](16) NOT NULL,
	[nRemolque] [varchar](10) NULL,
	[Estado] [int] NOT NULL DEFAULT ((0)),
	[TipOrd] [varchar](3) NULL DEFAULT ('0'),
	[NumOrden] [int] NOT NULL DEFAULT ((0)),
	[IdCiaOrd] [char](2) NULL,
	[FecOrden] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NOT NULL,
	[FechaCrea] [smalldatetime] NULL,
	[NitCliente] [varchar](16) NULL,
	[SedeClie] [varchar](10) NULL,
	[Autorizac] [int] NOT NULL DEFAULT ((0))
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehConductor]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_VehConductor] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[Numero] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[IdPropietario] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[IdCondNuevo] [varchar](16) NULL,
	[Observacion] [varchar](150) NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehLecturas]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_VehLecturas] AS TABLE(
	[TipDoc] [varchar](3) NULL,
	[Numero] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[TipoUnidad] [varchar](3) NULL,
	[pVehiculo] [varchar](10) NULL,
	[KmsAnterior] [int] NULL,
	[KmsActual] [int] NULL,
	[Kms2Anterior] [int] NULL,
	[Kms2Actual] [int] NULL,
	[TipoLectura] [varchar](10) NULL,
	[Observacion] [varchar](250) NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehNumOrden]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_VehNumOrden] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[Numero] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[NumOrden] [varchar](10) NULL,
	[NuevoNum] [varchar](10) NULL,
	[Observacion] [varchar](250) NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VehTraspasos]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_VehTraspasos] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[Numero] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[IdPpd] [varchar](4) NULL,
	[IdPropietario] [varchar](16) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdPropNuevo] [varchar](16) NULL,
	[IdPoseeNuevo] [varchar](16) NULL,
	[IdNewPpd] [varchar](4) NULL,
	[IdGrupo] [varchar](4) NULL,
	[VrComercial] [money] NULL,
	[VrCupo] [money] NULL,
	[VrAsegurado] [money] NULL,
	[Observacion] [varchar](150) NULL,
	[TipoAfil] [varchar](10) NULL,
	[TipoAfilNew] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_VencAbonos]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_VencAbonos] AS TABLE(
	[TipRec] [varchar](3) NULL,
	[Recibo] [int] NULL,
	[IdCia] [char](2) NULL,
	[Item] [int] NULL,
	[Fecha] [smalldatetime] NULL,
	[TipDoc] [varchar](3) NULL,
	[Factura] [int] NULL,
	[IdCiaFac] [char](2) NULL,
	[ItemFac] [int] NULL,
	[VrAbono] [money] NULL,
	[VrDescto] [money] NULL,
	[VrBaseCms] [money] NULL,
	[IdCliente] [varchar](16) NULL,
	[IdAgencia] [varchar](16) NULL,
	[IdVend] [varchar](16) NULL,
	[Comision] [decimal](14, 4) NULL,
	[Detalle] [varchar](150) NULL,
	[FecPago] [smalldatetime] NULL,
	[TipoAplica] [varchar](10) NULL,
	[TimeSys] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeTrn_Vencimientos]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeTrn_Vencimientos] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL,
	[Factura] [int] NOT NULL,
	[IdCia] [char](2) NOT NULL,
	[Item] [int] NOT NULL,
	[Fecha] [smalldatetime] NOT NULL,
	[FechaVence] [smalldatetime] NOT NULL,
	[VrFactura] [money] NOT NULL,
	[VrAbonado] [money] NOT NULL,
	[IdCliente] [varchar](16) NOT NULL,
	[IdAgencia] [varchar](16) NOT NULL,
	[IdVend] [varchar](16) NOT NULL,
	[Comision] [decimal](14, 4) NOT NULL,
	[TarifDcto] [decimal](14, 4) NOT NULL,
	[TipoDcto] [char](1) NOT NULL,
	[TipoBase] [varchar](10) NOT NULL,
	[FecLmtDcto] [smalldatetime] NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[Referencia] [varchar](50) NULL,
	[Detalle] [varchar](150) NULL,
	[TipRef] [varchar](3) NOT NULL,
	[DocRef] [int] NOT NULL,
	[IdCiaRef] [char](2) NOT NULL,
	[FecUltPago] [smalldatetime] NULL,
	[NumNota] [int] NOT NULL,
	[IdCiaNot] [char](2) NOT NULL,
	[TarifInt] [decimal](14, 4) NOT NULL,
	[FecLiqMora] [smalldatetime] NULL,
	[FecPlazoCal] [smalldatetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeUpdateKmVehs]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeUpdateKmVehs] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[KmActual] [int] NULL,
	[FechaUpdate] [datetime] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVeh_Contrato]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeVeh_Contrato] AS TABLE(
	[NumContrato] [int] NULL,
	[IdVehiculo] [varchar](10) NULL,
	[IdAdmon] [varchar](4) NULL,
	[IdTipCon] [varchar](4) NULL,
	[FecIngreso] [smalldatetime] NULL,
	[FecRetiro] [smalldatetime] NULL,
	[FecVigencia] [smalldatetime] NULL,
	[Observaciones] [varchar](250) NULL,
	[NumPagare] [varchar](20) NULL,
	[ArchPagare] [varchar](50) NULL,
	[FecUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehAnexo]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeVehAnexo] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[PolizaRCE] [varchar](30) NULL,
	[FecEmisionRCE] [smalldatetime] NULL,
	[FecVigenciaRCE] [smalldatetime] NULL,
	[appPyP] [bit] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehConductores]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeVehConductores] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[Item] [int] NULL,
	[CedConductor] [varchar](16) NULL,
	[TipoCond] [varchar](10) NULL,
	[FechaIng] [smalldatetime] NULL,
	[EstadoCond] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehiculos]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeVehiculos] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[NumVeh] [varchar](10) NULL,
	[ClaseVeh] [varchar](10) NULL,
	[IdTipoVeh] [varchar](4) NULL,
	[IdMarca] [varchar](4) NULL,
	[IdLinea] [varchar](10) NULL,
	[IdColor] [varchar](4) NULL,
	[IdTipoMot] [varchar](4) NULL,
	[IdCrceria] [varchar](4) NULL,
	[Modelo] [varchar](4) NULL,
	[FecRep] [smalldatetime] NULL,
	[Config] [varchar](5) NULL,
	[VehArtic] [bit] NULL,
	[NumLlan] [int] NULL,
	[NumLlans] [int] NULL,
	[IdCat] [varchar](4) NULL,
	[CdCatv] [varchar](4) NULL,
	[ClaseMat] [varchar](10) NULL,
	[Cilind] [decimal](14, 4) NULL,
	[CapTanq] [decimal](14, 4) NULL,
	[IdCom] [varchar](4) NULL,
	[IdLub] [varchar](4) NULL,
	[IdTlla] [varchar](4) NULL,
	[IdMarlla] [varchar](4) NULL,
	[PesoVacio] [decimal](14, 4) NULL,
	[PesoMax] [decimal](14, 4) NULL,
	[NumMotor] [varchar](30) NULL,
	[SerieChasis] [varchar](30) NULL,
	[NumSerie] [varchar](30) NULL,
	[CdRemque] [varchar](10) NULL,
	[Longitud] [decimal](14, 4) NULL,
	[CarrAlto] [decimal](14, 4) NULL,
	[CarrAncho] [decimal](14, 4) NULL,
	[CarrLargo] [decimal](14, 4) NULL,
	[CarrCapac] [decimal](14, 4) NULL,
	[UndCapc] [varchar](10) NULL,
	[Comptmtos] [int] NULL,
	[CapComp] [varchar](50) NULL,
	[PasjerosPie] [int] NULL,
	[PasjerosSen] [int] NULL,
	[NitEmpresa] [varchar](16) NULL,
	[IdPropietario] [varchar](16) NULL,
	[IdPoseedor] [varchar](16) NULL,
	[IdConductor] [varchar](16) NULL,
	[IdPpd] [varchar](4) NULL,
	[TipoAfil] [varchar](10) NULL,
	[Adquisc] [varchar](10) NULL,
	[NitProv] [varchar](16) NULL,
	[FecCompra] [smalldatetime] NULL,
	[VrComcial] [money] NULL,
	[VrAseg] [money] NULL,
	[VrAvaludo] [money] NULL,
	[VidaUtil] [int] NULL,
	[FecSalida] [smalldatetime] NULL,
	[NContrato] [int] NULL,
	[IdAdmon] [varchar](4) NULL,
	[IdNiv] [varchar](4) NULL,
	[IdGrupo] [varchar](4) NULL,
	[CdGrupR] [varchar](4) NULL,
	[CdTarifa] [varchar](4) NULL,
	[FecIngreso] [smalldatetime] NULL,
	[FecVigencia] [smalldatetime] NULL,
	[FecRetiro] [smalldatetime] NULL,
	[NumSoat] [varchar](30) NULL,
	[FecSoat] [smalldatetime] NULL,
	[VigSoat] [smalldatetime] NULL,
	[NitEmpSoat] [varchar](16) NULL,
	[TarjProp] [varchar](30) NULL,
	[FecTProp] [smalldatetime] NULL,
	[VigTProp] [smalldatetime] NULL,
	[CdLugTp] [varchar](8) NULL,
	[Ulttramite] [varchar](150) NULL,
	[RespCivil] [varchar](30) NULL,
	[FecRCivil] [smalldatetime] NULL,
	[VigRCivil] [smalldatetime] NULL,
	[RegNalCarga] [varchar](30) NULL,
	[FecRegNal] [smalldatetime] NULL,
	[VigRegNal] [smalldatetime] NULL,
	[RevTecMec] [varchar](30) NULL,
	[FecTecMec] [smalldatetime] NULL,
	[VigTecMec] [smalldatetime] NULL,
	[CertGases] [varchar](30) NULL,
	[FecCertGas] [smalldatetime] NULL,
	[VigCertGas] [smalldatetime] NULL,
	[TarjOper] [varchar](30) NULL,
	[FecTarjOper] [smalldatetime] NULL,
	[VigTarjOper] [smalldatetime] NULL,
	[KmInicial] [int] NULL,
	[KmActual] [int] NULL,
	[Km2Actual] [int] NULL,
	[Regtradora] [bit] NULL,
	[CentInicial] [int] NULL,
	[CentFinal] [int] NULL,
	[VrLmtCred] [money] NULL,
	[VrSaldoAct] [money] NULL,
	[Descripcion] [varchar](100) NULL,
	[Observacion] [varchar](250) NULL,
	[CdCenSer] [varchar](4) NULL,
	[CdLocal] [varchar](8) NULL,
	[Ubicacion] [varchar](100) NULL,
	[PathFoto] [varchar](30) NULL,
	[FecPriServ] [smalldatetime] NULL,
	[FecUltServ] [smalldatetime] NULL,
	[FecUltAcc] [smalldatetime] NULL,
	[TieneAcc] [bit] NULL,
	[FecPagImp] [smalldatetime] NULL,
	[IdEstado] [varchar](4) NULL,
	[Inactivo] [bit] NULL,
	[FechaAdd] [smalldatetime] NULL,
	[FechaUpdate] [smalldatetime] NULL,
	[IdUsuario] [varchar](11) NULL,
	[ValorCupo] [money] NULL,
	[ObligaTProd] [bit] NULL,
	[GarantiaAcc] [bit] NULL,
	[DocCompleta] [bit] NULL,
	[CertMovilizacion] [varchar](20) NULL,
	[FecCertMovil] [smalldatetime] NULL,
	[VigCertMovil] [smalldatetime] NULL,
	[CdRutaHab] [varchar](4) NULL,
	[DeclaracImp] [varchar](50) NULL,
	[TipoIngreso] [varchar](4) NULL,
	[IdOrgTra] [varchar](8) NULL,
	[GPSoperador] [varchar](250) NULL,
	[GPSUsuario] [varchar](50) NULL,
	[GPSClave] [varchar](50) NULL,
	[CantFiltros] [decimal](14, 4) NULL,
	[GPSIdOper] [varchar](16) NULL,
	[LiqFletePropio] [bit] NULL,
	[EdoVincula] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehPolizas]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeVehPolizas] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[IdClase] [varchar](4) NULL,
	[Numero] [varchar](30) NULL,
	[FecEmision] [smalldatetime] NULL,
	[FecVigencia] [smalldatetime] NULL,
	[NitCompania] [varchar](16) NULL,
	[Valor] [money] NULL,
	[Comntarios] [varchar](100) NULL,
	[DiasAviso] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dataTypeVehPropietarios]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[dataTypeVehPropietarios] AS TABLE(
	[IdVehiculo] [varchar](10) NULL,
	[Item] [int] NULL,
	[NitPropietario] [varchar](16) NULL,
	[PorcPartic] [decimal](14, 4) NULL,
	[FechaIng] [smalldatetime] NULL,
	[EstadoProp] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[wcfItm_TraEsDetConc]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[wcfItm_TraEsDetConc] AS TABLE(
	[TipDoc] [varchar](50) NULL,
	[Causacion] [varchar](50) NULL,
	[IdCia] [varchar](50) NULL,
	[Item] [varchar](50) NULL,
	[IdConcepto] [varchar](50) NULL,
	[Descripcion] [varchar](255) NULL,
	[TipoConc] [varchar](50) NULL,
	[VrDebito] [varchar](50) NULL,
	[VrCredito] [varchar](50) NULL,
	[CdCuenta] [varchar](50) NULL,
	[NitTercero] [varchar](50) NULL,
	[RazonSocial] [varchar](255) NULL,
	[CdCCosto] [varchar](50) NULL,
	[CCosto] [varchar](255) NULL,
	[CdSubCos] [varchar](50) NULL,
	[SubCosto] [varchar](255) NULL,
	[pVehiculo] [varchar](50) NULL,
	[NumVeh] [varchar](50) NULL,
	[ClaseMat] [varchar](50) NULL,
	[TipoAfiVehic] [varchar](50) NULL,
	[VrBase] [varchar](50) NULL,
	[TarifBase] [varchar](50) NULL,
	[Referencia] [varchar](50) NULL,
	[TipDocRef] [varchar](50) NULL,
	[DocRef] [varchar](50) NULL,
	[TipFac] [varchar](50) NULL,
	[Factura] [varchar](50) NULL,
	[IdCiaFac] [varchar](50) NULL,
	[ItemFac] [varchar](50) NULL,
	[FecVence] [datetime] NULL,
	[EstadoReg] [varchar](50) NULL,
	[TipoLiq] [varchar](50) NULL,
	[NumLiquida] [varchar](50) NULL,
	[CiaLiquida] [varchar](50) NULL,
	[VrAbonado] [varchar](50) NULL,
	[TmNumero] [varchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[wcfTempCausasionCuenta]    Script Date: 10/12/2025 8:11:23 ******/
CREATE TYPE [dbo].[wcfTempCausasionCuenta] AS TABLE(
	[TipDoc] [varchar](3) NOT NULL,
	[Causacion] [int] NOT NULL,
	[IdCia] [char](2) NOT NULL,
	[Item] [int] NOT NULL,
	[IdConcepto] [varchar](4) NOT NULL,
	[Descripcion] [varchar](250) NOT NULL,
	[TipoConc] [varchar](10) NOT NULL,
	[VrDebito] [money] NOT NULL,
	[VrCredito] [money] NOT NULL,
	[CdCuenta] [varchar](16) NOT NULL,
	[NitTercero] [varchar](16) NOT NULL,
	[CdCCosto] [varchar](16) NULL,
	[CdSubCos] [varchar](16) NULL,
	[pVehiculo] [varchar](10) NULL,
	[TipoAfiVehic] [varchar](10) NOT NULL,
	[VrBase] [money] NOT NULL,
	[TarifBase] [decimal](14, 4) NOT NULL,
	[Referencia] [varchar](50) NULL,
	[TipDocRef] [varchar](3) NULL,
	[DocRef] [int] NOT NULL,
	[TipFac] [varchar](3) NULL,
	[Factura] [varchar](15) NULL,
	[IdCiaFac] [char](2) NULL,
	[ItemFac] [int] NOT NULL,
	[FecVence] [smalldatetime] NOT NULL,
	[EstadoReg] [int] NOT NULL,
	[TipoLiq] [varchar](3) NULL,
	[NumLiquida] [int] NOT NULL,
	[CiaLiquida] [char](2) NULL,
	[VrAbonado] [money] NOT NULL
)
GO
/****** Object:  StoredProcedure [dbo].[Pa_Actualizar]    Script Date: 10/12/2025 8:11:23 ******/
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
/****** Object:  StoredProcedure [dbo].[Pa_Agregar]    Script Date: 10/12/2025 8:11:23 ******/
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
/****** Object:  StoredProcedure [dbo].[Pa_Eliminar]    Script Date: 10/12/2025 8:11:23 ******/
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
/****** Object:  StoredProcedure [dbo].[Pa_InsertSelect]    Script Date: 10/12/2025 8:11:23 ******/
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
/****** Object:  StoredProcedure [dbo].[Pa_Query]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS ON
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
/****** Object:  StoredProcedure [dbo].[paDelActivos]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelActivos] @pmIdActivo VARCHAR(30)
 AS 
 BEGIN
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnActivos'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM Activos_Anexo  WHERE IdActivo=@pmIdActivo
  DELETE FROM Activos  WHERE IdActivo=@pmIdActivo
 COMMIT TRANSACTION  @TrnNombre
END
GO
/****** Object:  StoredProcedure [dbo].[paDelActivos_Anexo]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelActivos_Anexo] @pmIdActivo VARCHAR(30)
 AS 
 DELETE FROM Activos_Anexo  WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCaja]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAcuCaja] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 DELETE FROM AcuCaja
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCajaBuses]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuCajaBuses] @pmFecha SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmIdCia CHAR(2)
AS
 DELETE FROM  AcuCajaBuses WHERE Fecha=@pmFecha
 AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuClientes]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuClientes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16)
 AS 
 DELETE FROM AcuClientes
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentas]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuCuentas] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM AcuCuentas
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasAge]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAcuCuentasAge] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM AcuCuentasAge
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasAux]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuCuentasAux] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 DELETE FROM AcuCuentasAux
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasCc]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAcuCuentasCc] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM AcuCuentasCc
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasNit]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAcuCuentasNit] @pmnAnno INT,@pmnMes INT
,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM AcuCuentasNit
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuCuentasVeh]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAcuCuentasVeh] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM AcuCuentasVeh
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInventario]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuInventario] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)
 AS 
 DELETE FROM AcuInventario
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInvLotes]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuInvLotes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)
 AS 
 DELETE FROM AcuInvLotes
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInvTanques]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuInvTanques] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)
 AS 
 DELETE FROM AcuInvTanques
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuInvUbica]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuInvUbica] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)
 AS 
 DELETE FROM AcuInvUbica
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuPrestamos]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAcuPrestamos] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM AcuPrestamos
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAcuPropietarios]    Script Date: 10/12/2025 8:11:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paDelAcuPropietarios]  @pmnMes INT, @pmnAnno INT,@pmIdCia CHAR(2)=Null
AS
 DELETE FROM  AcuPropietarios 
 WHERE  nMes=@pmnMes AND nAnno=@pmnAnno AND  IdCia LIKE ISNULL(@pmIdCia, '%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAfAmortiza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfAmortiza] @pmNumero INT
 AS 
 DELETE FROM Trn_AfAmortiza
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelAfAmtComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfAmtComp] @pmNumero INT
 AS 
 DELETE FROM Trn_AfAmtComp
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelAfAmtDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfAmtDetalle] @pmNumero INT,@pmIdDiferido VARCHAR(30)
 AS 
 DELETE FROM Trn_AfAmtDetalle
 WHERE Numero=@pmNumero AND IdDiferido LIKE ISNULL(@pmIdDiferido,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAfCausales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfCausales] @pmIdCausal VARCHAR(4)
 AS 
 DELETE FROM AfCausales
 WHERE IdCausal=@pmIdCausal
GO
/****** Object:  StoredProcedure [dbo].[paDelAfClasesCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfClasesCue] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM AfClasesCue
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDeprecia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfDeprecia] @pmNumero INT
 AS 
 DELETE FROM Trn_AfDeprecia
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfDetalle] @pmNumero INT,@pmIdActivo VARCHAR(30)
 AS 
 DELETE FROM Trn_AfDetalle
 WHERE Numero=@pmNumero AND IdActivo LIKE ISNULL(@pmIdActivo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfDifIngreso] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfDifIngreso
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifMovi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfDifMovi] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfDifMovi
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifRetiro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfDifRetiro] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfDifRetiro
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfDifTraslado] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfDifTraslado
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfDifValoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfDifValoriza] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfDifValoriza
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfEstados] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM AfEstados
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelAfGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfGrupos] @pmIdGrupo VARCHAR(4)
 AS 
 BEGIN
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnAfGrupos'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM AfGruposCue  WHERE IdGrupo=@pmIdGrupo
  DELETE FROM AfGrupos  WHERE IdGrupo=@pmIdGrupo
 COMMIT TRANSACTION  @TrnNombre
END
GO
/****** Object:  StoredProcedure [dbo].[paDelAfGruposCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfGruposCue] @pmIdGrupo VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 DELETE FROM AfGruposCue
 WHERE IdGrupo=@pmIdGrupo AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelAfLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfLineas] @pmIdLinea VARCHAR(4)
 AS 
 DELETE FROM AfLineas
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMantnmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfMantnmto] @pmNumero INT
 AS 
 DELETE FROM Trn_AfMantnmto
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovimiento]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfMovimiento] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfMovimiento
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfMovIngreso] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfMovIngreso
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovRetiro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfMovRetiro] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfMovRetiro
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfMovValoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfMovValoriza] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AfMovValoriza
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAfPignora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfPignora] @pmNumero INT
 AS 
 DELETE FROM Trn_AfPignora
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelAfTiposDif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAfTiposDif] @pmIdTipDif VARCHAR(4)
 AS 
 DELETE FROM AfTiposDif
 WHERE IdTipDif=@pmIdTipDif
GO
/****** Object:  StoredProcedure [dbo].[paDelAfTiposMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAfTiposMov] @pmIdMov VARCHAR(4)
 AS 
 DELETE FROM AfTiposMov
 WHERE IdMov=@pmIdMov
GO
/****** Object:  StoredProcedure [dbo].[paDelAgencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAgencias] @pmIdAgencia VARCHAR(16)
 AS 
 DELETE FROM Agencias
 WHERE IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paDelAjuInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAjuInv] @pmTipDoc VARCHAR(3),@pmAjuste INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_AjuInv
 WHERE TipDoc=@pmTipDoc AND Ajuste=@pmAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAlmBodegas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAlmBodegas] @pmIdBodega VARCHAR(4)
 AS 
 DELETE FROM AlmBodegas
 WHERE IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paDelAprobacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAprobacion] @pmTipDoc VARCHAR(3),@pmAprobacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Aprobacion
 WHERE TipDoc=@pmTipDoc AND Aprobacion=@pmAprobacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelAreas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelAreas] @pmIdArea VARCHAR(4)
 AS 
 DELETE FROM Areas
 WHERE IdArea=@pmIdArea
GO
/****** Object:  StoredProcedure [dbo].[paDelAutoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelAutoriza] @pmTipAut VARCHAR(3),@pmAutoriza INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Autoriza
 WHERE TipAut=@pmTipAut AND Autoriza=@pmAutoriza AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelBancos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelBancos] @pmIdBanco VARCHAR(4)
 AS 
 DELETE FROM Bancos
 WHERE IdBanco=@pmIdBanco
GO
/****** Object:  StoredProcedure [dbo].[paDelBodegas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelBodegas] @pmIdBodega VARCHAR(4)
 AS 
 DELETE FROM Bodegas
 WHERE IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paDelBodUbic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelBodUbic] @pmIdUbic VARCHAR(10)
 AS 
 DELETE FROM BodUbic
 WHERE IdUbic=@pmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paDelBusClaseCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelBusClaseCue] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM BusClaseCue
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelCalndario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCalndario] @pmFechaDia SMALLDATETIME
 AS 
 DELETE FROM Calndario
 WHERE FechaDia=@pmFechaDia
GO
/****** Object:  StoredProcedure [dbo].[paDelCalndarioMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCalndarioMes] @pmMes INT,@pmAnno INT
 AS 
 DELETE FROM Calndario
 WHERE Month(FechaDia)=@pmMes AND Year(FechaDia)=@pmAnno
GO
/****** Object:  StoredProcedure [dbo].[paDelCargos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCargos] @pmIdCargo VARCHAR(4)
 AS 
 DELETE FROM Cargos
 WHERE IdCargo=@pmIdCargo
GO
/****** Object:  StoredProcedure [dbo].[paDelCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCausacion] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Causacion
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelCausacVence]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCausacVence] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2) 
 AS 
 DELETE FROM Trn_CausacVence
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelCausacVenceItem]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCausacVenceItem] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2) 
,@pmItem INT
 AS 
 DELETE FROM Trn_CausacVence
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paDelCausaVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCausaVales] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_CausaVales
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelCentroCosto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCentroCosto] @pmIdCCosto VARCHAR(16)
 AS 
 DELETE FROM CentroCosto
 WHERE IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paDelCentrosServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCentrosServ] @pmIdCenSer VARCHAR(4)
 AS 
 DELETE FROM CentrosServ
 WHERE IdCenSer=@pmIdCenSer
GO
/****** Object:  StoredProcedure [dbo].[paDelCheques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCheques] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Cheques
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelChequesDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelChequesDoc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
 AS 
 DELETE FROM Trn_Cheques
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc 
 AND  IdCia=@pmIdCiaDoc AND Recibo<=0
GO
/****** Object:  StoredProcedure [dbo].[paDelChequesRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelChequesRec] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Cheques
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseBan] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseBan
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseCapac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseCapac] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseCapac WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseCta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelClaseCta] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseCta
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseDiv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelClaseDiv] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseDiv
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseDocCond]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseDocCond] @pmIdDoc VARCHAR(4)
 AS 
 DELETE FROM ClaseDocCond
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseFon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelClaseFon] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseFon
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClasePol]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelClasePol] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClasePol
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseRie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseRie] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseRie
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseSub] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseSub
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClaseTar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClaseTar] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ClaseTar
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelClieContado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelClieContado] @pmIdCliente VARCHAR(16)
 AS 
 DELETE FROM ClieContado
 WHERE IdCliente=@pmIdCliente
GO
/****** Object:  StoredProcedure [dbo].[paDelCnxextna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCnxextna] @pmIdReg INT
 AS 
 DELETE FROM Sys_Cnxextna
 WHERE IdReg=@pmIdReg
GO
/****** Object:  StoredProcedure [dbo].[paDelComDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelComDetalle] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT=Null
 AS 
 DELETE FROM Trn_ComDetalle
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelComFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelComFactura] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmIdProveedor VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia 
 AND IdProveedor=@pmIdProveedor   AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelComFacturaCmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelComFacturaCmp] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItemCom INT=Null
AS
 DELETE FROM  Trn_ComFactura  
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia 
 AND (ItemCom>=ISNULL(@pmItemCom,0)  AND ItemCom<=ISNULL(@pmItemCom,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelComFacturaDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelComFacturaDoc] @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFactura VARCHAR(15)
 AS 
 DELETE FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND  Factura LIKE ISNULL(@pmFactura,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelCompanias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelCompanias] @pmIdCia CHAR(2)
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnCompanias'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM CompListas WHERE IdCia=@pmIdCia 
  DELETE FROM Companias WHERE IdCia=@pmIdCia
  COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelCompCaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCompCaja] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_CompCaja
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelCompCajaDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCompCajaDet] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_CompCajaDet
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelComprobantes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelComprobantes] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Comprobantes
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelConcDivCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelConcDivCue] @pmIdConcepto VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 DELETE FROM ConcDivCue
 WHERE IdConcepto=@pmIdConcepto AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelConcDiversos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelConcDiversos] @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM ConcDiversos
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelConceptos] @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM Conceptos
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptosAdmon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelConceptosAdmon] @pmIdConcepto VARCHAR(4),@pmIdAdmon VARCHAR(4),@pmIdClase INT
 AS 
 DELETE FROM ConceptosAdmon
 WHERE IdConcepto=@pmIdConcepto AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptosCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelConceptosCue] @pmIdConcepto VARCHAR(4),@pmIdClase INT
 AS 
 DELETE FROM ConceptosCue
 WHERE IdConcepto=@pmIdConcepto
 AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelConceptosTrib]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelConceptosTrib] @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM ConceptosTrib WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paDelConsigna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelConsigna] @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Consigna
 WHERE TipDoc=@pmTipDoc AND Consignacion=@pmConsignacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelCotizacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCotizacion] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Cotizacion
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelCtasCorrientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelCtasCorrientes] @pmIdCta VARCHAR(4)
 AS 
 DELETE FROM CtasCorrientes
 WHERE IdCta=@pmIdCta
GO
/****** Object:  StoredProcedure [dbo].[paDelDepartamentos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDepartamentos] @pmIdDep VARCHAR(8)
 AS 
 DELETE FROM Departamentos
 WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paDelDependencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDependencias] @pmIdDep VARCHAR(4)
 AS 
 DELETE FROM Dependencias
 WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paDelDespachos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDespachos] @pmTipDoc VARCHAR(3),@pmCartulina INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Despachos
 WHERE TipDoc=@pmTipDoc AND Cartulina=@pmCartulina AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDetCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDetCuentas] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmConcepto VARCHAR(10),@pmItem INT
 AS 
 DELETE FROM Trn_DetCuentas
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND Concepto LIKE ISNULL(@pmConcepto,'%')
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelDevCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevCaj] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevCaj
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevCausacion]  @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)

AS
 DELETE FROM  Trn_DevCausacion 
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevCns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevCns] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevCns
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevEnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevEnt
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevFco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevFco] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevFco
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevFcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevFcr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevFcr
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevFvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevFvc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevFvc
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevNpr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevNpr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevNpr
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevPas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevPas] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevPas
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevPla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevPla] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevPla
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevPrestamos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevPrestamos
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevRec
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevRecBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevRecBuses] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
AS
 DELETE FROM  Trn_DevRecBuses  WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevSal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevSal
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDevVal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDevVal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DevVal
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDiarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDiarios] @pmIdDiario VARCHAR(4)
 AS 
 DELETE FROM Diarios
 WHERE IdDiario=@pmIdDiario
GO
/****** Object:  StoredProcedure [dbo].[paDelDiferidos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelDiferidos] @pmIdDiferido VARCHAR(30)
 AS 
 DELETE FROM Diferidos
 WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paDelDisciplinario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDisciplinario] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Disciplinario
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDocMemo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDocMemo] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DocMemo
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDocSopDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDocSopDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DocSopDev
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelDocSoporte]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelDocSoporte] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_DocSoporte
 WHERE TipDoc=@pmTipDoc AND NumDoc=@pmNumDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsCalibra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEdsCalibra] @pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EdsCalibra
 WHERE TipDoc=@pmTipDoc AND nNota=@pmnNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsCortes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEdsCortes] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EdsCortes
 WHERE TipDoc=@pmTipDoc AND Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsForItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEdsForItems] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT
 AS 
 DELETE FROM Trn_EdsForItems
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEdsFormas] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT
 AS 
 DELETE FROM Trn_EdsFormas
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsFormasPla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEdsFormasPla] @pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EdsFormas
 WHERE Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsRangos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEdsRangos] @pmTipoRango VARCHAR(3),@pmIdRango INT
 AS 
 DELETE FROM Trn_EdsRangos
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsServicio]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEdsServicio] @pmIdEstacion VARCHAR(4)
 AS 
 DELETE FROM EdsServicio
 WHERE IdEstacion=@pmIdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paDelEdsUnion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEdsUnion] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EdsUnion WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrAntAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEgrAntAbonos] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EgrAntAbonos WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrAnticipo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEgrAnticipo] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EgrAnticipo WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEgrFactura] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT=Null
 AS 
 DELETE FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelEgrFacturaDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEgrFacturaDoc] @pmTipDev VARCHAR(3),@pmNumDev INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EgrFactura
 WHERE TipCom=@pmTipDev AND Comprobante=@pmNumDev AND IdCia=@pmIdCia
 AND TipDev=@pmTipDev AND NumDev=@pmNumDev AND EsEgreso=0
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_Contrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEmp_Contrato] @pmNContrato INT
 AS 
 DELETE FROM Emp_Contrato
 WHERE NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_Estudios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEmp_Estudios] @pmIdEmpleado VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Emp_Estudios
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_ExpLaboral]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEmp_ExpLaboral] @pmIdEmpleado VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Emp_ExpLaboral
 WHERE IdEmpleado=@pmIdEmpleado
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelEmp_Parientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEmp_Parientes] @pmIdEmpleado VARCHAR(16),@pmItem INT=Null
 AS 
 DELETE FROM Emp_Parientes
 WHERE IdEmpleado=@pmIdEmpleado   AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelEmpaques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEmpaques] @pmIdEmp VARCHAR(4)
 AS 
 DELETE FROM Empaques
 WHERE IdEmp=@pmIdEmp
GO
/****** Object:  StoredProcedure [dbo].[paDelEmpleados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEmpleados] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelEntArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEntArticulos] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_EntArticulos
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEntidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEntidades] @pmIdTabla VARCHAR(20)
 AS 
 DELETE FROM Sys_Entidades
 WHERE IdTabla=@pmIdTabla
GO
/****** Object:  StoredProcedure [dbo].[paDelEntradas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Entradas
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelEstaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEstaciones] @pmIdEstacion CHAR(2)
 AS 
 DELETE FROM Sys_Estaciones
 WHERE IdEstacion=@pmIdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoCiv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEstadoCiv] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoCiv
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEstadoDoc] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoDoc
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEstadoGuia] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoGuia WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoOper]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEstadoOper] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoOper WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEstadoPro] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoPro
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoSer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelEstadoSer] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoSer
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoTer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEstadoTer] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoTer
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstadoVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEstadoVeh] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM EstadoVeh
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelEstratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelEstratos] @pmIdEstrato VARCHAR(4)
 AS 
 DELETE FROM Estratos
 WHERE IdEstrato=@pmIdEstrato
GO
/****** Object:  StoredProcedure [dbo].[paDeleteTercAccionistas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--ELIMINAR
CREATE PROCEDURE [dbo].[paDeleteTercAccionistas]
	@TercAccionistas dbo.dataTypeTercAccionistas READONLY
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @FilasAfectadas INT = 0;

	DELETE T FROM TercAccionistas AS T
	INNER JOIN @TercAccionistas AS D 
			ON D.IdTercero = T.IdTercero
			AND D.NitAccionista = T.NitAccionista
	SET @FilasAfectadas = @@ROWCOUNT 
	IF(@FilasAfectadas = 0)
		BEGIN
			SELECT 'Registro no eliminado' AS Mensaje 
		END
	ELSE
		BEGIN
			SELECT '1' AS Mensaje
		END

END
GO
/****** Object:  StoredProcedure [dbo].[paDelExpLicencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelExpLicencias] @pmIdLugar VARCHAR(8)
 AS 
 DELETE FROM ExpLicencias
 WHERE IdLugar=@pmIdLugar
GO
/****** Object:  StoredProcedure [dbo].[paDelFactcon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFactcon] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Factcon
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFacturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFacturas] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Facturas
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFactVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFactVales] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FactVales
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFcCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFcCausacion] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FcCausacion
 WHERE TipDoc=@pmTipDoc AND NumDoc=@pmNumDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFcNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFcNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FcNotas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFcSemanas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFcSemanas] @pmIdVehiculo VARCHAR(10),@pmnSemana INT
 AS 
 DELETE FROM Trn_FcSemanas
 WHERE IdVehiculo=@pmIdVehiculo AND nSemana=@pmnSemana
GO
/****** Object:  StoredProcedure [dbo].[paDelFields]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFields] @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20)=Null
 AS 
 DELETE FROM Sys_Fields
 WHERE IdEntidad=@pmIdEntidad AND IdCampo LIKE ISNULL(@pmIdCampo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFijos] @pmIdCargo VARCHAR(4)
AS
 DELETE FROM  Fijos  WHERE IdCargo=@pmIdCargo
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos_Cla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFijos_Cla] @pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4)
AS
 DELETE FROM  Fijos_Cla   WHERE IdCargo=@pmIdCargo AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos_Cue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paDelFijos_Cue]  @pmIdCargo VARCHAR(4), @pmIdAdmon VARCHAR(4)
AS
  DELETE FROM  Fijos_Cue
 WHERE   IdCargo=@pmIdCargo AND  IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelFijos_Veh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFijos_Veh] @pmIdCargo VARCHAR(4),@pmIdVehiculo VARCHAR(10)
AS
  DELETE FROM  Fijos_Veh  WHERE IdCargo=@pmIdCargo AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelFinAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFinAbonos] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinAfavor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinAfavor] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinAfavor
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinAlmacenes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinAlmacenes] @pmIdAlmacen VARCHAR(4)
 AS 
 DELETE FROM FinAlmacenes
 WHERE IdAlmacen=@pmIdAlmacen
GO
/****** Object:  StoredProcedure [dbo].[paDelFinCuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinCuotas] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinCuotas
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinDevFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinDevFac] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinDevFac
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinDevPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinDevPre] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinDevPre
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinDevRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinDevRec
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinFactint]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinFactint] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinFactint
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinNotas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinPrestamo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinPrestamo] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinPrestamo
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFinRecibos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFinRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_FinRecibos
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelFmtDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFmtDoc] @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2)
 AS 
 DELETE FROM Sys_FmtDoc
 WHERE IdDoc=@pmIdDoc AND IdForma LIKE ISNULL(@pmIdForma,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelFmtFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFmtFactura] @pmnFormato VARCHAR(10)
 AS 
 DELETE FROM Sys_FmtFactura
 WHERE nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paDelFondos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFondos] @pmIdFondo VARCHAR(8)
 AS 
 DELETE FROM Fondos
 WHERE IdFondo=@pmIdFondo
GO
/****** Object:  StoredProcedure [dbo].[paDelFormasCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFormasCue] @pmIdForma VARCHAR(4),@pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM FormasCue
 WHERE IdForma=@pmIdForma AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelFormaspago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFormaspago] @pmIdForma VARCHAR(4)
 AS 
 DELETE FROM Formaspago
 WHERE IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paDelFuentesPago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelFuentesPago] @pmIdFuente VARCHAR(4)
 AS 
 DELETE FROM FuentesPago
 WHERE IdFuente=@pmIdFuente
GO
/****** Object:  StoredProcedure [dbo].[paDelGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelGrupos] @pmIdGrupo VARCHAR(8)
 AS 
 DELETE FROM Grupos
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelGruposAgenc] @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM GruposAgenc
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposAR]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelGruposAR] @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM GruposAR
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposCli]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelGruposCli] @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM GruposCli
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelGruposMcia] @pmIdGrupo VARCHAR(10)
 AS 
 DELETE FROM GruposMcia
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposObj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelGruposObj] @pmIdGrupo VARCHAR(6)
 AS 
 DELETE FROM Sys_GruposObj
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelGruposPro] @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM GruposPro
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposRot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelGruposRot] @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM GruposRot
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGruposUsu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelGruposUsu] @pmIdGrupo INT
 AS 
 DELETE FROM Sys_GruposUsu
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelGuia] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Guia
 WHERE TipDoc=@pmTipDoc AND Guia=@pmGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelInstalaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelInstalaciones] @pmIdInstala VARCHAR(4)
 AS 
 DELETE FROM Instalaciones
 WHERE IdInstala=@pmIdInstala
GO
/****** Object:  StoredProcedure [dbo].[paDelInvDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelInvDetalle] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelInvDetalleEst]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelInvDetalleEst] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdEstacion CHAR(2)
 AS 
 DELETE FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND IdEstacion=@pmIdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paDelInvFisico]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelInvFisico] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_InvFisico
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelJornadas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelJornadas] @pmIdJornada VARCHAR(4)
 AS 
 DELETE FROM Jornadas
 WHERE IdJornada=@pmIdJornada
GO
/****** Object:  StoredProcedure [dbo].[paDelJurAutoridades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurAutoridades] @pmIdAutoridad VARCHAR(4)
 AS 
 DELETE FROM JurAutoridades
 WHERE IdAutoridad=@pmIdAutoridad
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCalifica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurCalifica] @pmIdCalifica VARCHAR(4)
 AS 
 DELETE FROM JurCalifica
 WHERE IdCalifica=@pmIdCalifica
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCasos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurCasos] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_JurCasos
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCasosHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelJurCasosHis]  @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2), @pmActualizaID INT=Null
AS
 DELETE FROM  Trn_JurCasosHis
 WHERE  TipDoc=@pmTipDoc AND  CasoID=@pmCasoID AND  IdCia=@pmIdCia 
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCasosQtn]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelJurCasosQtn] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2), @pmItem INT=Null
AS
 DELETE FROM  Trn_JurCasosQtn
 WHERE  TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND  IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelJurCausales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurCausales] @pmIdCausal VARCHAR(4)
 AS 
 DELETE FROM JurCausales
 WHERE IdCausal=@pmIdCausal
GO
/****** Object:  StoredProcedure [dbo].[paDelJurClaseAcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurClaseAcc] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM JurClaseAcc
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelJurDocumtos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurDocumtos] @pmIdDoc VARCHAR(4)
 AS 
 DELETE FROM JurDocumtos
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paDelJurEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurEstados] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM JurEstados
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelJurInvesHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelJurInvesHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT
 AS 
 DELETE FROM Trn_JurInvesHis
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia 
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelJurInvestiga]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurInvestiga] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_JurInvestiga
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelJurPreguntas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurPreguntas] @pmIdPregunta VARCHAR(4)
 AS 
 DELETE FROM JurPreguntas
 WHERE IdPregunta=@pmIdPregunta
GO
/****** Object:  StoredProcedure [dbo].[paDelJurReclamac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurReclamac] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_JurReclamac
 WHERE TipDoc=@pmTipDoc AND Reclamac=@pmReclamac AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelJurRecOfrecmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelJurRecOfrecmto] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_JurRecOfrecmto
 WHERE TipDoc=@pmTipDoc AND Reclamac=@pmReclamac AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelJurTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurTipos] @pmIdTipoPro VARCHAR(4)
 AS 
 DELETE FROM JurTipos
 WHERE IdTipoPro=@pmIdTipoPro
GO
/****** Object:  StoredProcedure [dbo].[paDelJurTiposRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelJurTiposRec] @pmIdTipoRec VARCHAR(4)
 AS 
 DELETE FROM JurTiposRec
 WHERE IdTipoRec=@pmIdTipoRec
GO
/****** Object:  StoredProcedure [dbo].[paDelKardex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelKardex] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelKarUbic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelKarUbic] @pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_KarUbic
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelLineas] @pmIdLinea VARCHAR(8)
 AS 
 DELETE FROM Lineas
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paDelLocalidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelLocalidades] @pmIdLocal VARCHAR(8)
 AS 
 DELETE FROM Localidades
 WHERE IdLocal=@pmIdLocal
GO
/****** Object:  StoredProcedure [dbo].[paDelLog_Nomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelLog_Nomina] @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8)
 AS 
 DELETE FROM Log_Nomina
 WHERE IdNom LIKE ISNULL(@pmIdNom,'%') AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelLog_Periodos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelLog_Periodos] @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Log_Periodos
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelLotes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelLotes] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
,@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10)
 AS 
 DELETE FROM Trn_Lotes
 WHERE NumLote=@pmNumLote AND IdProducto=@pmIdProducto AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%') AND IdUbic LIKE ISNULL(@pmIdUbic,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelLotMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelLotMov] @pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_LotMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelMarcas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMarcas] @pmIdMarca VARCHAR(4)
 AS 
 DELETE FROM Marcas
 WHERE IdMarca=@pmIdMarca
GO
/****** Object:  StoredProcedure [dbo].[paDelMarcasLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMarcasLin] @pmIdLinea VARCHAR(10)
 AS 
 DELETE FROM MarcasLin
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paDelMayAnotaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayAnotaciones] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_MayAnotaciones
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelMayBonCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayBonCuentas] @pmIdBonif VARCHAR(4),@pmTipoCue INT,@pmCdTipo VARCHAR(4)
 AS 
 DELETE FROM MayBonCuentas
 WHERE IdBonif=@pmIdBonif AND TipoCue=@pmTipoCue AND CdTipo LIKE ISNULL(@pmCdTipo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelMayBonif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayBonif] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_MayBonif
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelMayContDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayContDoc] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_MayContDoc
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelMayContratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayContratos] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MayContratos
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMayEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayEstados] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM MayEstados
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelMayInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayInventario] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_MayInventario
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelMayInvmov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayInvmov] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS
 DELETE FROM Trn_MayInvmov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMayItemsInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayItemsInv] @pmIdArticulo VARCHAR(16)
 AS 
 DELETE FROM MayItemsInv
 WHERE IdArticulo=@pmIdArticulo
GO
/****** Object:  StoredProcedure [dbo].[paDelMayLiqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayLiqDetalle] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MayLiqDetalle
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMayLiqTotales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayLiqTotales] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MayLiqTotales
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMayLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayLiquida] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MayLiquida
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMayPspto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayPspto] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_MayPspto
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayTipos] @pmIdTipo VARCHAR(4)
 AS 
 DELETE FROM MayTipos
 WHERE IdTipo=@pmIdTipo
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposAprob]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayTiposAprob] @pmIdAprob VARCHAR(4)
 AS 
 DELETE FROM MayTiposAprob
 WHERE IdAprob=@pmIdAprob
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposBienes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayTiposBienes] @pmIdTipBien VARCHAR(4)
 AS 
 DELETE FROM MayTiposBienes
 WHERE IdTipBien=@pmIdTipBien
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposBonif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayTiposBonif] @pmIdBonif VARCHAR(4)
 AS 
 DELETE FROM MayTiposBonif
 WHERE IdBonif=@pmIdBonif
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelMayTiposDoc] @pmIdDoc VARCHAR(4)
 AS 
 DELETE FROM MayTiposDoc
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paDelMayTiposPoliza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMayTiposPoliza] @pmIdTipoPol VARCHAR(4)
 AS 
 DELETE FROM MayTiposPoliza
 WHERE IdTipoPol=@pmIdTipoPol
GO
/****** Object:  StoredProcedure [dbo].[paDelMercancias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMercancias] @pmIdMercancia VARCHAR(16)
 AS 
 DELETE FROM Mercancias
 WHERE IdMercancia=@pmIdMercancia
GO
/****** Object:  StoredProcedure [dbo].[paDelModulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelModulos] @pmIdMod VARCHAR(3)
 AS 
 DELETE FROM Sys_Modulos
 WHERE IdMod LIKE ISNULL(@pmIdMod,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelmonedas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelmonedas] @pmIdMneda VARCHAR(5)
 AS 
 DELETE FROM adm_monedas
 WHERE IdMneda=@pmIdMneda
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMttoEstados] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM MttoEstados WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoOrden]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMttoOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MttoOrden WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoSistemas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMttoSistemas] @pmIdSistema VARCHAR(4)
 AS 
 DELETE FROM MttoSistemas WHERE IdSistema=@pmIdSistema
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMttoTipos] @pmIdMtto VARCHAR(4)
 AS 
 DELETE FROM MttoTipos WHERE IdMtto=@pmIdMtto
GO
/****** Object:  StoredProcedure [dbo].[paDelMttoTiposOdt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMttoTiposOdt] @pmIdTipoOdt VARCHAR(4)
 AS 
 DELETE FROM MttoTiposOdt WHERE IdTipoOdt=@pmIdTipoOdt
GO
/****** Object:  StoredProcedure [dbo].[paDelMudArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudArticulos] @pmIdArticulo VARCHAR(16)
 AS 
 DELETE FROM MudArticulos
 WHERE IdArticulo=@pmIdArticulo
GO
/****** Object:  StoredProcedure [dbo].[paDelMudContratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudContratos] @pmTipDoc VARCHAR(3),@pmNumContrato INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MudContratos
 WHERE TipDoc=@pmTipDoc AND NumContrato=@pmNumContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMudEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudEstados] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM MudEstados
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelMudInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudInventario] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MudInventario
 WHERE TipDoc=@pmTipDoc AND NumInvent=@pmNumInvent AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMudOrdenServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_MudOrdenServ
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelMudSecciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudSecciones] @pmIdSeccion VARCHAR(4)
 AS 
 DELETE FROM MudSecciones
 WHERE IdSeccion=@pmIdSeccion
GO
/****** Object:  StoredProcedure [dbo].[paDelMudServicios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelMudServicios] @pmIdTipoServ VARCHAR(4)
 AS 
 DELETE FROM MudServicios
 WHERE IdTipoServ=@pmIdTipoServ
GO
/****** Object:  StoredProcedure [dbo].[paDelNiifComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNiifComp] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_NiifComp
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAbonos] @pmNPrestamo INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAbonosLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAbonosLiq] @pmDscto VARCHAR(3),@pmNLiquida INT,@pmIdEmpleado VARCHAR(16)=Null
AS 
 DELETE FROM  Trn_NomAbonos
 WHERE Dscto=@pmDscto AND NLiquida=@pmNLiquida AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAbonosPer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomAbonosPer] @pmIdPeriodo VARCHAR(8),@pmDscto VARCHAR(3),@pmIdEmpleado VARCHAR(16)=Null
AS 
 DELETE FROM  Trn_NomAbonos
 WHERE IdPeriodo=@pmIdPeriodo AND Dscto LIKE ISNULL(@pmDscto,'%')  
 AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAlqDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAlqDet] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 DELETE FROM Trn_NomAlqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAlqNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAlqNov] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 DELETE FROM Trn_NomAlqNov
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAlqTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAlqTot] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 DELETE FROM Trn_NomAlqTot
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAportante]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAportante] @pmIdAportnte VARCHAR(16)
 AS 
 DELETE FROM NomAportante
 WHERE IdAportnte=@pmIdAportnte
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAstncia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAstncia] @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME
 AS 
 DELETE FROM Trn_NomAstncia
 WHERE IdEmpleado=@pmIdEmpleado AND FechaDia=ISNULL(@pmFechaDia,FechaDia)
GO
/****** Object:  StoredProcedure [dbo].[paDelNomAutoliq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomAutoliq] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20)=Null
 AS 
 DELETE FROM Trn_NomAutoliq
 WHERE TipoLiq=@pmTipoLiq AND Numero LIKE ISNULL(@pmNumero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomBasesConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomBasesConv] @pmIdBase VARCHAR(4)
 AS 
 DELETE FROM NomBasesConv
 WHERE IdBase=@pmIdBase
GO
/****** Object:  StoredProcedure [dbo].[paDelNomCAdmon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomCAdmon] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelNomCausalesRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomCausalesRet] @pmIdCausa VARCHAR(4)
 AS 
 DELETE FROM NomCausalesRet
 WHERE IdCausa=@pmIdCausa
GO
/****** Object:  StoredProcedure [dbo].[paDelNomCertf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomCertf] @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20)
 AS 
 DELETE FROM Trn_NomCertf
 WHERE IdEmpleado=@pmIdEmpleado AND NumCertf LIKE ISNULL(@pmNumCertf,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConAuto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomConAuto] @pmIdReg INT
 AS 
 DELETE FROM Trn_NomConAuto
 WHERE IdReg=@pmIdReg
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConcConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomConcConv] @pmId INT
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnNomConcConv'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM Trn_NomConcCond WHERE IdConc=@pmId
  DELETE FROM Trn_NomConcConv WHERE [Id]=@pmId
  COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomConceptos] @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM NomConceptos
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomConCuentas] @pmIdConcepto VARCHAR(4),@pmItem INT
 AS 
 DELETE FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomConOpciones] @pmIdConcepto VARCHAR(4),@pmIdOpc INT
 AS 
 DELETE FROM NomConOpciones
 WHERE IdConcepto=@pmIdConcepto 
  AND (IdOpc>=ISNULL(@pmIdOpc,0)  AND IdOpc<=ISNULL(@pmIdOpc,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomConvenciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomConvenciones] @pmId INT
 AS 
 DELETE FROM NomConvenciones WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDefault]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomDefault] @pmnAnno INT,@pmIdOpc VARCHAR(3)
 AS 
 DELETE FROM NomDefault
 WHERE nAnno=@pmnAnno AND IdOpc LIKE ISNULL(@pmIdOpc,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomDetalle] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmItem INT
 AS 
 DELETE FROM Trn_NomDetalle
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDetalleEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomDetalleEmp] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomDetalle 
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelNomDetallePer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomDetallePer] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null,@pmEsRetiro BIT=Null
 AS 
 DELETE Trn_NomDetalle 
 FROM Trn_NomDetalle AS D INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdPeriodo=@pmIdPeriodo AND EsRetiro=@pmEsRetiro
 AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomEscalafones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomEscalafones] @pmIdEscfon VARCHAR(4)
 AS 
 DELETE FROM NomEscalafones WHERE IdEscfon=@pmIdEscfon
GO
/****** Object:  StoredProcedure [dbo].[paDelNomEstadosConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomEstadosConv] @pmIdEstado VARCHAR(4)
 AS 
 DELETE FROM NomEstadosConv WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paDelNomFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomFijos] @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT
 AS 
 DELETE FROM Trn_NomFijos
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomGruposConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomGruposConv] @pmIdGrupo VARCHAR(4)
 AS 
 DELETE FROM NomGruposConv WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelNomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomina] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)
 AS 
 DELETE FROM Trn_Nomina
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro like ISNULL(@pmKeyRegistro,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNominaEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNominaEmp] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelNominaPer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNominaPer] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmEsRetiro BIT
 AS 
 DELETE FROM Trn_Nomina
 WHERE IdPeriodo=@pmIdPeriodo AND EsRetiro=@pmEsRetiro AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomLiqDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomLiqDet] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomLiquida] @pmTipoLiq VARCHAR(3),@pmNumero INT
 AS 
 DELETE FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelNomLogVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomLogVeh] @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 DELETE FROM Trn_NomLogVeh
 WHERE IdEmpleado=@pmIdEmpleado AND NumReg=@pmNumReg
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomNov] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNovCar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomNovCar] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 DELETE FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND OrigCargue='AUTO'
 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado ,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNovConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomNovConv] @pmId BIGINT
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnNomNovConv'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM Trn_NomNovConc WHERE IdNovedad=@pmId
  DELETE FROM Trn_NomNovEst WHERE IdNovedad=@pmId
  DELETE FROM Trn_NomNovConv WHERE [Id]=@pmId
  COMMIT TRANSACTION @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelNomNovedad]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomNovedad] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomPrendas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomPrendas] @pmIdPrend VARCHAR(4)
 AS 
 DELETE FROM NomPrendas WHERE IdPrend=@pmIdPrend
GO
/****** Object:  StoredProcedure [dbo].[paDelNomPrest]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomPrest] @pmNPrestamo INT
 AS 
 DELETE FROM Trn_NomPrest
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paDelNomProrrogas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomProrrogas] @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 DELETE FROM Trn_NomProrrogas
 WHERE IdEmpleado=@pmIdEmpleado
 AND (NumReg>=ISNULL(@pmNumReg,0)  AND NumReg<=ISNULL(@pmNumReg,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRangosFsu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomRangosFsu] @pmIdRango INT
 AS 
 DELETE FROM NomRangosFsu
 WHERE IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomRet] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomRetDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRetDetEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomRetDetEmp] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelNomRetEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomRetEmp] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelNomSueldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomSueldos] @pmNumero INT,@pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomSueldos
 WHERE Numero=@pmNumero AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelNomTablaRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomTablaRet] @pmnAnno INT,@pmnIntrvalo INT
 AS 
 DELETE FROM NomTablaRet
 WHERE nAnno=@pmnAnno 
 AND (nIntrvalo>=ISNULL(@pmnIntrvalo,0)  AND nIntrvalo<=ISNULL(@pmnIntrvalo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomVac] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 DELETE FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVacDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomVacDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM Trn_NomVacDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVacDetEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomVacDetEmp] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomVacDet
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVacEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNomVacEmp] @pmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paDelNomVehiculos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomVehiculos] @pmIdVehiculo VARCHAR(10)
 AS 
 DELETE FROM NomVehiculos
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paDelNomZonasConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNomZonasConv] @pmIdZona VARCHAR(4)
 AS 
 DELETE FROM NomZonasConv
 WHERE IdZona=@pmIdZona
GO
/****** Object:  StoredProcedure [dbo].[paDelNotaProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNotaProd] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_NotaProd
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Notas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelNotasBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelNotasBuses] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_NotasBuses
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelNovedadRep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNovedadRep] @pmIdNov VARCHAR(4)
 AS 
 DELETE FROM NovedadRep
 WHERE IdNov=@pmIdNov
GO
/****** Object:  StoredProcedure [dbo].[paDelNovedadTra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelNovedadTra] @pmIdNovedad VARCHAR(4)
 AS 
 DELETE FROM NovedadTra
 WHERE IdNovedad=@pmIdNovedad
GO
/****** Object:  StoredProcedure [dbo].[paDelObjetosApp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelObjetosApp] @pmIdObj VARCHAR(10)
 AS 
 DELETE FROM Sys_ObjetosApp
 WHERE IdObj=@pmIdObj
GO
/****** Object:  StoredProcedure [dbo].[paDelOComb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOComb] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OComb
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelOCompra] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OCompra
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOcupaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOcupaciones] @pmIdOcupac VARCHAR(4)
 AS 
 DELETE FROM Ocupaciones WHERE IdOcupac=@pmIdOcupac
GO
/****** Object:  StoredProcedure [dbo].[paDelOilAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilAjustes] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilAjustes
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilCompra] @pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilCompra
 WHERE TipDoc=@pmTipDoc AND NumCompra=@pmNumCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilCostos] @pmTipProc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilCostos
 WHERE TipProc=@pmTipProc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilCostoVen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilCostoVen] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilCostoVen WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilDespClie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilDespClie] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilDespClie
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilDevCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilDevCompra] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilDevCompra
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilEntrada]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilEntrada
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilGuia WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilInvent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilInvent] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilInvent
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilMediciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilMediciones] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilMediciones
 WHERE TipDoc=@pmTipDoc AND NumInvent=@pmNumInvent AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOilTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelOilTraslado] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_OilTraslado
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelOpciones] @pmIdOpc VARCHAR(3)
 AS 
 DELETE FROM adm_Opciones
 WHERE IdOpc LIKE ISNULL(@pmIdOpc,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelOpedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelOpedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Opedido
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelPagos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPagos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Pagos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelPaises]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPaises] @pmIdPais VARCHAR(8)
 AS 
 DELETE FROM adm_Paises
 WHERE IdPais=@pmIdPais
GO
/****** Object:  StoredProcedure [dbo].[paDelPeajesCat]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPeajesCat] @pmIdCat VARCHAR(4)
 AS 
 DELETE FROM PeajesCat
 WHERE IdCat=@pmIdCat
GO
/****** Object:  StoredProcedure [dbo].[paDelPeajesClase]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPeajesClase] @pmIdClase VARCHAR(4)
 AS 
 DELETE FROM PeajesClase
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelPeajesTarf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPeajesTarf] @pmIdCat VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 DELETE FROM PeajesTarf
 WHERE IdCat=@pmIdCat AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelPermisos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPermisos] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null
 AS 
 DELETE FROM adm_Permisos
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelPermisosRoles]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPermisosRoles] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null,@pmIdRole VARCHAR(3)=Null
 AS 
 DELETE FROM adm_PermisosRoles
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%')  AND IdRole LIKE ISNULL(@pmIdRole,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelPicoPlaca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelPicoPlaca] @pmFecha SMALLDATETIME
 AS 
 DELETE FROM PicoPlaca
 WHERE Fecha=@pmFecha
GO
/****** Object:  StoredProcedure [dbo].[paDelPlazos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelPlazos] @pmIdPlazo VARCHAR(4)
 AS 
 DELETE FROM Plazos
 WHERE IdPlazo=@pmIdPlazo
GO
/****** Object:  StoredProcedure [dbo].[paDelPolizas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPolizas] @pmNumPoliza VARCHAR(30)
 AS 
 DELETE FROM Polizas
 WHERE NumPoliza=@pmNumPoliza
GO
/****** Object:  StoredProcedure [dbo].[paDelPreCuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelPreCuotas] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmNumCuota INT
 AS 
 DELETE FROM Trn_PreCuotas
 WHERE TipDoc=@pmTipDoc AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia 
AND (NumCuota>=ISNULL(@pmNumCuota,0)  AND NumCuota<=ISNULL(@pmNumCuota,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelPreCuotasCau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paDelPreCuotasCau] @pmCausacionID INT
 AS
 DELETE FROM  Trn_PreCuotas 
 WHERE CausacionID=@pmCausacionID
GO
/****** Object:  StoredProcedure [dbo].[paDelPresDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPresDetalle] @pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_PresDetalle
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPrestamos] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Prestamos
 WHERE TipDoc=@pmTipDoc AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelPresupuesto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelPresupuesto] @pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Presupuesto
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelProdAditivos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdAditivos] @pmIdProducto VARCHAR(16),@pmIdAditivo VARCHAR(16)
 AS 
 DELETE FROM ProdAditivos
 WHERE IdProducto=@pmIdProducto AND IdAditivo LIKE ISNULL(@pmIdAditivo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelProdCombo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdCombo] @pmIdProducto VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM ProdCombo
 WHERE IdProducto=@pmIdProducto
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelProdConsolida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdConsolida] @pmTipDoc VARCHAR(3),@pmNumCons INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_ProdConsolida
 WHERE TipDoc=@pmTipDoc AND NumCons=@pmNumCons AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelProdCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdCostos] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 DELETE FROM ProdCostos
 WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelProdEntrega]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdEntrega] @pmTipDoc VARCHAR(3),@pmNumEntrega INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_ProdEntrega WHERE TipDoc=@pmTipDoc AND NumEntrega=@pmNumEntrega AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelProdImpFron]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdImpFron] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT
 AS 
 DELETE FROM ProdImpFron
 WHERE IdProducto=@pmIdProducto AND IdClase LIKE ISNULL(@pmIdClase,'%')
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelProdImptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdImptos] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT
 AS 
 DELETE FROM ProdImptos
 WHERE IdProducto=@pmIdProducto AND IdClase LIKE ISNULL(@pmIdClase,'%')
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelProdMcias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdMcias] @pmIdProducto VARCHAR(16)
 AS 
 DELETE FROM ProdMcias
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paDelProdOrden]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_ProdOrden
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelProdPrecios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdPrecios] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 DELETE FROM ProdPrecios
 WHERE IdProducto=@pmIdProducto AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelProdProvee]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdProvee] @pmIdProducto VARCHAR(16),@pmIdProv VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 DELETE FROM ProdProvee
 WHERE IdProducto=@pmIdProducto AND IdProv LIKE ISNULL(@pmIdProv,'%') 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelProdSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelProdSaldos] @pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 DELETE FROM ProdSaldos
 WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelProdSaldoUbc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdSaldoUbc] @pmIdProducto VARCHAR(16),@pmIdUbic VARCHAR(10),@pmIdCia CHAR(2)
 AS 
 DELETE FROM ProdSaldoUbc
 WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdUbic LIKE ISNULL(@pmIdUbic,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelProdTarf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProdTarf] @pmTipo VARCHAR(3),@pmNumero INT
 AS 
 DELETE FROM Trn_ProdTarf
 WHERE Tipo=@pmTipo 
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelProfesiones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelProfesiones] @pmIdProf VARCHAR(4)
 AS 
 DELETE FROM Profesiones
 WHERE IdProf=@pmIdProf
GO
/****** Object:  StoredProcedure [dbo].[paDelPuc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuc] @pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM Puc
 WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paDelPuestos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuestos] @pmIdPto VARCHAR(4)
 AS 
 DELETE FROM Puestos
 WHERE IdPto=@pmIdPto
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntBases]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntBases] @pmIdProgrma INT
 AS 
 DELETE FROM PuntBases
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntBasesItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntBasesItm] @pmIdProgrma INT,@pmCdSubgrupo VARCHAR(8),@pmCdProducto VARCHAR(16)
 AS 
 DELETE FROM PuntBases
 WHERE IdProgrma=@pmIdProgrma AND CdSubgrupo LIKE ISNULL(@pmCdSubgrupo,'%')
 AND CdProducto LIKE ISNULL(@pmCdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntFormas] @pmIdProgrma INT
 AS 
 DELETE FROM PuntFormas
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntFormasItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntFormasItm] @pmIdProgrma INT,@pmIdForma VARCHAR(4)
 AS 
 DELETE FROM PuntFormas
 WHERE IdProgrma=@pmIdProgrma AND IdForma LIKE ISNULL(@pmIdForma,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Puntos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntPremios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntPremios] @pmIdProgrma INT
 AS 
 DELETE FROM PuntPremios
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntPremiosItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntPremiosItm] @pmIdProgrma INT,@pmItem INT
 AS 
 DELETE FROM PuntPremios
 WHERE IdProgrma=@pmIdProgrma
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntProg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntProg] @pmIdProgrma INT
 AS 
 DELETE FROM PuntProg
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paDelPuntTarjetas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelPuntTarjetas] @pmNumTarjeta VARCHAR(20)
 AS 
 DELETE FROM PuntTarjetas
 WHERE NumTarjeta=@pmNumTarjeta
GO
/****** Object:  StoredProcedure [dbo].[paDelRadicaVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRadicaVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_RadicaVales
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRangosPeso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelRangosPeso] @pmIdRango VARCHAR(4)
 AS 
 DELETE FROM RangosPeso
 WHERE IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paDelRecAfavor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelRecAfavor] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_RecAfavor
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRecBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRecBuses] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_RecBuses
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRecCheques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelRecCheques] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_RecCheques
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelRecFactura] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_RecFactura
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFactura_Ant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRecFactura_Ant]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
,@pmItemDoc INT=Null,@pmAplAntcpo BIT=Null
AS
 DELETE FROM Trn_RecFactura  WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND  IdCiaDoc=@pmIdCiaDoc
 AND (ItemDoc>=ISNULL(@pmItemDoc,0)  AND ItemDoc<=ISNULL(@pmItemDoc,2147483647))
 AND (AplAntcpo=ISNULL(@pmAplAntcpo,0) or AplAntcpo=ISNULL(@pmAplAntcpo,1))
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFactura_Doc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRecFactura_Doc]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmAplAntcpo BIT=Null
AS
 IF @pmAplAntcpo  IS NULL
  DELETE FROM Trn_RecFactura  WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND  IdCiaDoc=@pmIdCiaDoc
 ELSE
  DELETE FROM Trn_RecFactura  WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND  IdCiaDoc=@pmIdCiaDoc
   AND AplAntcpo=@pmAplAntcpo
GO
/****** Object:  StoredProcedure [dbo].[paDelRecFacturaVc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRecFacturaVc]  @pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 DELETE FROM Trn_RecFactura
  WHERE  TipRec IN ('OD1','OTR')
 AND  IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelRecibos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Recibos
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRecTanqueos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelRecTanqueos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_RecTanqueos
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRegimenDian]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRegimenDian] @pmIdRegimen VARCHAR(4)
 AS 
 DELETE FROM RegimenDian
 WHERE IdRegimen=@pmIdRegimen
GO
/****** Object:  StoredProcedure [dbo].[paDelRegistro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRegistro] @pmIdCia CHAR(2)
 AS 
 DELETE FROM adm_Registro
 WHERE IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRelaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRelaciones] @pmIdTabla VARCHAR(20),@pmTablaForanea VARCHAR(20)=Null,@pmCampoForaneo VARCHAR(20)=Null
 AS 
 DELETE FROM Sys_Relaciones
 WHERE IdTabla=@pmIdTabla AND TablaForanea LIKE ISNULL(@pmTablaForanea,'%')
  AND CampoForaneo LIKE ISNULL(@pmCampoForaneo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelRemision]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRemision] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Remision
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelReport]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelReport] @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2)=Null
 AS 
 DELETE FROM Sys_Report
 WHERE TipoRep=@pmTipoRep AND IdRep LIKE ISNULL(@pmIdRep,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelReportFmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelReportFmto] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
 AS 
 DELETE FROM Sys_ReportFmto
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato
GO
/****** Object:  StoredProcedure [dbo].[paDelReportSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelReportSub] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20),@pmNombreSub VARCHAR(20)=Null
 AS 
 DELETE FROM Sys_ReportSub
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato AND NombreSub LIKE ISNULL(@pmNombreSub,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelReportSubPmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelReportSubPmt] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmNombreSub VARCHAR(20),@pmIndParam INT
 AS 
 DELETE FROM Sys_ReportSubPmt
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato
  AND NombreSub LIKE ISNULL(@pmNombreSub,'%')
  AND (IndParam>=ISNULL(@pmIndParam,0)  AND IndParam<=ISNULL(@pmIndParam,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelReqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelReqDetalle] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_ReqDetalle
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRequisicion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRequisicion] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Requisicion
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelRequisicionOdt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRequisicionOdt] @pmTipOdt VARCHAR(3),@pmNumOrden INT,@pmIdCiaOdt CHAR(2)
 AS 
 IF EXISTS (SELECT * FROM Trn_MttoOrdenReq WHERE TipOdt=@pmTipOdt AND NumOrden=@pmNumOrden AND IdCiaOdt=@pmIdCiaOdt)
  BEGIN 
   DECLARE @TrnNombre VARCHAR(30)
   SET @TrnNombre = 'Trn_MttoOrdenReq'
   BEGIN TRANSACTION @TrnNombre
   DELETE FROM Trn_ReqDetalle FROM Trn_ReqDetalle INNER JOIN Trn_MttoOrdenReq ON Trn_ReqDetalle.TipDoc=Trn_MttoOrdenReq.TipReq
   AND Trn_ReqDetalle.Requisicion=Trn_MttoOrdenReq.Requisicion AND Trn_ReqDetalle.IdCia=Trn_MttoOrdenReq.IdCia
   WHERE Trn_MttoOrdenReq.TipOdt=@pmTipOdt AND Trn_MttoOrdenReq.NumOrden=@pmNumOrden AND Trn_MttoOrdenReq.IdCiaOdt=@pmIdCiaOdt
   DELETE FROM Trn_Requisicion FROM Trn_Requisicion INNER JOIN Trn_MttoOrdenReq ON Trn_Requisicion.TipDoc=Trn_MttoOrdenReq.TipReq
   AND Trn_Requisicion.Requisicion=Trn_MttoOrdenReq.Requisicion AND Trn_Requisicion.IdCia=Trn_MttoOrdenReq.IdCia
   WHERE Trn_MttoOrdenReq.TipOdt=@pmTipOdt AND Trn_MttoOrdenReq.NumOrden=@pmNumOrden AND Trn_MttoOrdenReq.IdCiaOdt=@pmIdCiaOdt
   COMMIT TRANSACTION  @TrnNombre
  END
GO
/****** Object:  StoredProcedure [dbo].[paDelRoles]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRoles] @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3)=Null
 AS 
 DELETE FROM Sys_Roles
 WHERE IdObj=@pmIdObj AND IdRole LIKE ISNULL(@pmIdRole,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelRutas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRutas] @pmIdRuta VARCHAR(4)
 AS 
 DELETE FROM Rutas
 WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paDelRutasPlan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelRutasPlan] @pmIdRuta VARCHAR(4),@pmIdPunto INT
 AS 
 DELETE FROM RutasPlan
 WHERE IdRuta=@pmIdRuta
 AND (IdPunto>=ISNULL(@pmIdPunto,0)  AND IdPunto<=ISNULL(@pmIdPunto,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelRutasTramos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelRutasTramos] @pmIdRuta VARCHAR(4),@pmNumTramo INT
 AS 
 DELETE FROM RutasTramos
 WHERE IdRuta=@pmIdRuta 
  AND (NumTramo>=ISNULL(@pmNumTramo,0)  AND NumTramo<=ISNULL(@pmNumTramo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelSaiArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSaiArticulos] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_SaiArticulos
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelSalidas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSalidas] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Salidas
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelSAutoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSAutoriza] @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM Sys_Autoriza
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paDelSectoresEco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSectoresEco] @pmIdSector VARCHAR(8)
 AS 
 DELETE FROM SectoresEco
 WHERE IdSector=@pmIdSector
GO
/****** Object:  StoredProcedure [dbo].[paDelSecurity]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSecurity] @pmIdLla INT
 AS 
 DELETE FROM Sys_Security
 WHERE IdLla=@pmIdLla
GO
/****** Object:  StoredProcedure [dbo].[paDelSeriales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSeriales] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Seriales
 WHERE IdProducto=@pmIdProducto AND  IdCia=@pmIdCia AND NumSerial LIKE ISNULL(@pmNumSerial,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelSerMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSerMov] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 DELETE FROM Trn_SerMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelSobDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSobDetalle] @pmIdDec VARCHAR(4),@pmNumDeclara INT
 AS 
 DELETE FROM Trn_SobDetalle
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paDelSobEntidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSobEntidades] @pmIdEnterr VARCHAR(8)
 AS 
 DELETE FROM SobEntidades
 WHERE IdEnterr=@pmIdEnterr
GO
/****** Object:  StoredProcedure [dbo].[paDelSobProductos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSobProductos] @pmIdClase INT
 AS 
 DELETE FROM SobProductos
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paDelSobretasas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSobretasas] @pmIdDec VARCHAR(4),@pmNumDeclara INT
 AS 
 DELETE FROM Trn_Sobretasas
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paDelSobTiposDec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSobTiposDec] @pmIdDec VARCHAR(4)
 AS 
 DELETE FROM SobTiposDec
 WHERE IdDec=@pmIdDec
GO
/****** Object:  StoredProcedure [dbo].[paDelSubCentros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSubCentros] @pmIdSubCos VARCHAR(16)
 AS 
 DELETE FROM SubCentros
 WHERE IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paDelSubGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSubGrupos] @pmIdSubgrupo VARCHAR(8)
 AS 
 DELETE FROM SubGrupos
 WHERE IdSubgrupo=@pmIdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paDelSubGruposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelSubGruposAgenc] @pmIdSubAgenc VARCHAR(4)
 AS 
 DELETE FROM SubGruposAgenc
 WHERE IdSubAgenc=@pmIdSubAgenc
GO
/****** Object:  StoredProcedure [dbo].[paDelSubgruposCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSubgruposCue] @pmIdSubgrupo VARCHAR(8),@pmIdClase VARCHAR(4)
 AS 
 DELETE FROM SubgruposCue
 WHERE IdSubgrupo=@pmIdSubgrupo AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelSubzonas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelSubzonas] @pmIdSzona VARCHAR(4)
 AS 
 DELETE FROM Subzonas
 WHERE IdSzona=@pmIdSzona
GO
/****** Object:  StoredProcedure [dbo].[paDelTablapor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTablapor] @pmIdTarifa VARCHAR(4)
 AS 
 DELETE FROM Tablapor
 WHERE IdTarifa=@pmIdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paDelTalleres]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTalleres] @pmIdTaller VARCHAR(4)
 AS 
 DELETE FROM Talleres WHERE IdTaller=@pmIdTaller
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqAforo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTanqAforo] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4)
 AS 
 DELETE FROM TanqAforo
 WHERE IdTanque=@pmIdTanque 
 AND (UndAforo>=ISNULL(@pmUndAforo,0)  AND UndAforo<=ISNULL(@pmUndAforo,9999999999))
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqAforoFrac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTanqAforoFrac] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4)
 AS 
 DELETE FROM TanqAforoFrac
 WHERE IdTanque=@pmIdTanque 
 AND (UndAforo>=ISNULL(@pmUndAforo,0)  AND UndAforo<=ISNULL(@pmUndAforo,9999999999))
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqDispens]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTanqDispens] @pmIdMngra VARCHAR(10)
 AS 
 DELETE FROM TanqDispens
 WHERE IdMngra=@pmIdMngra
GO
/****** Object:  StoredProcedure [dbo].[paDelTanqSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTanqSaldos] @pmIdTanque VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 DELETE FROM TanqSaldos
 WHERE IdTanque LIKE ISNULL(@pmIdTanque,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTanques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTanques] @pmIdTanque VARCHAR(4)
 AS 
 DELETE FROM Tanques
 WHERE IdTanque=@pmIdTanque
GO
/****** Object:  StoredProcedure [dbo].[paDelTarifAnticipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTarifAnticipos] @pmNumero INT
 AS 
 DELETE FROM TarifAnticipos
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelTarifasFletes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTarifasFletes]  @pmNumero INT
 AS 
 DELETE FROM TarifasFletes  WHERE  Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelTarifBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTarifBuses] @pmIdTarifa VARCHAR(4)
 AS 
 DELETE FROM TarifBuses
 WHERE IdTarifa=@pmIdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paDeltasas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltasas] @pmIdMneda VARCHAR(5),@pmIdMnedaD VARCHAR(5),@pmFecha SMALLDATETIME
 AS 
 DELETE FROM Trn_tasas
 WHERE Fecha=@pmFecha AND IdMnedaD=@pmIdMnedaD AND IdMneda LIKE ISNULL(@pmIdMneda,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTaxRutas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTaxRutas] @pmIdRuta VARCHAR(4)
 AS 
 DELETE FROM TaxRutas  WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paDelTaxTarifas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTaxTarifas] @pmTipoTarif VARCHAR(10),@pmItem INT
 AS 
 DELETE FROM TaxTarifas
 WHERE TipoTarif=@pmTipoTarif AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paDelTaxTarifClie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTaxTarifClie] @pmTipoTarif VARCHAR(10),@pmItem INT
 AS 
 DELETE FROM TaxTarifClie
 WHERE TipoTarif=@pmTipoTarif 
 AND Item BETWEEN ISNULL(@pmItem,0) AND ISNULL(@pmItem,2147483647)
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercClieCia] @pmIdClie VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 DELETE FROM TercClieCia
 WHERE IdClie=@pmIdClie AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCliente]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTercCliente] @pmIdClie VARCHAR(16)
 AS 
 DELETE FROM TercCliente
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCliePrestamo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercCliePrestamo] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16)
 AS 
 DELETE FROM TercCliePrestamo
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieRef]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTercClieRef] @pmIdClie VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM TercClieRef
 WHERE IdClie=@pmIdClie
AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercClieSaldos] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16)
 AS 
 DELETE FROM TercClieSaldos
 WHERE IdClie LIKE ISNULL(@pmIdClie,'%') AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTercClieVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTercClieVeh] @pmIdClie VARCHAR(16),@pmpVehiculo VARCHAR(10)
 AS 
 DELETE FROM TercClieVeh
 WHERE IdClie=@pmIdClie AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndContrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercCndContrato] @pmNumContrato INT
 AS 
 DELETE FROM TercCndContrato
 WHERE NumContrato=@pmNumContrato
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndReferencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercCndReferencias] @pmIdConductor VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM TercCndReferencias
 WHERE IdConductor=@pmIdConductor  
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndTarjetas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercCndTarjetas] @pmIdConductor VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM TercCndTarjetas
 WHERE IdConductor=@pmIdConductor 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelTercCndtores]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercCndtores] @pmIdConductor VARCHAR(16)
 AS 
 DELETE FROM TercCndtores
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paDelTerceros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTerceros] @pmIdTercero VARCHAR(16)
 AS 
 DELETE FROM Terceros
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paDelTercPropietario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTercPropietario] @pmIdPropietario VARCHAR(16)
 AS 
 DELETE FROM TercPropietario
 WHERE IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paDelTercProvee]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTercProvee] @pmIdProv VARCHAR(16)
 AS 
 DELETE FROM TercProvee
 WHERE IdProv=@pmIdProv
GO
/****** Object:  StoredProcedure [dbo].[paDelTercVendedor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTercVendedor] @pmIdVend VARCHAR(16)
 AS 
 DELETE FROM TercVendedor
 WHERE IdVend=@pmIdVend
GO
/****** Object:  StoredProcedure [dbo].[paDelTerminales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTerminales] @pmIdTerminal VARCHAR(4)
 AS 
 DELETE FROM Terminales
 WHERE IdTerminal=@pmIdTerminal
GO
/****** Object:  StoredProcedure [dbo].[paDelTFmtos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTFmtos] @pmnFormato VARCHAR(10)
 AS 
 DELETE FROM Sys_TFmtos
 WHERE nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposAdm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposAdm] @pmIdAdmon VARCHAR(4)
 AS 
 DELETE FROM TiposAdm
 WHERE IdAdmon=@pmIdAdmon
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposAgenc] @pmIdTipAgenc VARCHAR(4)
 AS 
 DELETE FROM TiposAgenc
 WHERE IdTipAgenc=@pmIdTipAgenc
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposBan] @pmIdBandera VARCHAR(4)
 AS 
 DELETE FROM TiposBan
 WHERE IdBandera=@pmIdBandera
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposBloq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposBloq] @pmIdTipBloq VARCHAR(4)
 AS 
 DELETE FROM TiposBloq
 WHERE IdTipBloq=@pmIdTipBloq
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposCar] @pmIdCrceria VARCHAR(4)
 AS 
 DELETE FROM TiposCar
 WHERE IdCrceria=@pmIdCrceria
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCarga]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposCarga] @pmIdTipCarga VARCHAR(4)
 AS 
 DELETE FROM TiposCarga
 WHERE IdTipCarga=@pmIdTipCarga
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCnd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposCnd] @pmIdTipoCon VARCHAR(4)
 AS 
 DELETE FROM TiposCnd
 WHERE IdTipoCon=@pmIdTipoCon
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCol]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposCol] @pmIdColor VARCHAR(4)
 AS 
 DELETE FROM TiposCol
 WHERE IdColor=@pmIdColor
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposCom] @pmIdCom VARCHAR(3)
 AS 
 DELETE FROM TiposCom
 WHERE IdCom=@pmIdCom
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposComAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposComAgenc] @pmIdSubAgenc VARCHAR(4)
 AS 
 DELETE FROM TiposComAgenc
 WHERE IdSubAgenc=@pmIdSubAgenc
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposComCons]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposComCons] @pmIdCom VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 DELETE FROM TiposComCons
 WHERE IdCom=@pmIdCom AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposComFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposComFmt] @pmIdCom VARCHAR(3),@pmIdForma CHAR(2)
 AS 
 DELETE FROM TiposComFmt WHERE IdCom=@pmIdCom AND IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposCon] @pmIdTipCon VARCHAR(4)
 AS 
 DELETE FROM TiposCon
 WHERE IdTipCon=@pmIdTipCon
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposCot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposCot] @pmIdCot VARCHAR(4)
 AS 
 DELETE FROM TiposCot
 WHERE IdCot=@pmIdCot
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposDoc] @pmIdDoc VARCHAR(3)
 AS 
 DELETE FROM Sys_TiposDoc
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposDocCons]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposDocCons] @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 DELETE FROM TiposDocCons
 WHERE IdDoc=@pmIdDoc AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposDocCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposDocCue] @pmIdDoc VARCHAR(3),@pmIdClase INT
 AS 
 DELETE FROM Sys_TiposDocCue
 WHERE IdDoc=@pmIdDoc  AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposEnt] @pmIdEnt VARCHAR(4)
 AS 
 DELETE FROM TiposEnt WHERE IdEnt=@pmIdEnt
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposEsc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposEsc] @pmIdTipoEsc VARCHAR(4)
 AS 
 DELETE FROM TiposEsc
 WHERE IdTipoEsc=@pmIdTipoEsc
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposFil]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposFil] @pmIdFiltro VARCHAR(4)
 AS 
 DELETE FROM TiposFil
 WHERE IdFiltro=@pmIdFiltro
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposFuel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposFuel] @pmIdCom VARCHAR(4)
 AS 
 DELETE FROM TiposFuel
 WHERE IdCom=@pmIdCom
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposInm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposInm] @pmIdTipoInm VARCHAR(4)
 AS 
 DELETE FROM TiposInm
 WHERE IdTipoInm=@pmIdTipoInm
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposLla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposLla] @pmIdTlla VARCHAR(4)
 AS 
 DELETE FROM TiposLla
 WHERE IdTlla=@pmIdTlla
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposLub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposLub] @pmIdLub VARCHAR(4)
 AS 
 DELETE FROM TiposLub
 WHERE IdLub=@pmIdLub
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMat]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposMat] @pmIdMat VARCHAR(4)
 AS 
 DELETE FROM TiposMat
 WHERE IdMat=@pmIdMat
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposMcia] @pmIdTmcia VARCHAR(4)
 AS 
 DELETE FROM TiposMcia
 WHERE IdTmcia=@pmIdTmcia
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMnjo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposMnjo] @pmIdMnjo VARCHAR(4)
 AS 
 DELETE FROM TiposMnjo
 WHERE IdMnjo=@pmIdMnjo
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposMod] @pmIdModd VARCHAR(4)
 AS 
 DELETE FROM TiposMod
 WHERE IdModd=@pmIdModd
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposMot] @pmIdTipoMot VARCHAR(4)
 AS 
 DELETE FROM TiposMot
 WHERE IdTipoMot=@pmIdTipoMot
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposMotdev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposMotdev] @pmIdMotDev VARCHAR(4)
 AS 
 DELETE FROM TiposMotdev WHERE IdMotDev=@pmIdMotDev
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNat]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposNat] @pmIdNat VARCHAR(4)
 AS 
 DELETE FROM TiposNat
 WHERE IdNat=@pmIdNat
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNivs]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposNivs] @pmIdNiv VARCHAR(4)
 AS 
 DELETE FROM TiposNivs
 WHERE IdNiv=@pmIdNiv
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposNom] @pmIdNom VARCHAR(4)
 AS 
 DELETE FROM TiposNom
 WHERE IdNom=@pmIdNom
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposNov] @pmIdNov VARCHAR(4)
 AS 
 DELETE FROM TiposNov
 WHERE IdNov=@pmIdNov
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposOperac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposOperac] @pmIdTipoOper VARCHAR(4)
 AS 
 DELETE FROM TiposOperac WHERE IdTipoOper=@pmIdTipoOper
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposOperarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposOperarios] @pmIdOper VARCHAR(4)
 AS 
 DELETE FROM TiposOperarios WHERE IdOper=@pmIdOper
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposPcnto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposPcnto] @pmIdTipoPre VARCHAR(4)
 AS 
 DELETE FROM TiposPcnto
 WHERE IdTipoPre=@pmIdTipoPre
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposPpt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposPpt] @pmIdPpd VARCHAR(4)
 AS 
 DELETE FROM TiposPpt
 WHERE IdPpd=@pmIdPpd
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposPrend]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposPrend] @pmIdPrend VARCHAR(4)
 AS 
 DELETE FROM TiposPrend
 WHERE IdPrend=@pmIdPrend
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposProceso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposProceso] @pmIdTipProc VARCHAR(4)
 AS 
 DELETE FROM TiposProceso WHERE IdTipProc=@pmIdTipProc
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposRespFis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposRespFis] @pmIdResFis VARCHAR(10)
 AS 
 DELETE FROM TiposRespFis WHERE IdResFis=@pmIdResFis
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposSustento]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposSustento] @pmIdSustento VARCHAR(4)
 AS 
 DELETE FROM TiposSustento WHERE IdSustento=@pmIdSustento
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposTerc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposTerc] @pmIdTipoTerc VARCHAR(4)
 AS 
 DELETE FROM TiposTerc
 WHERE IdTipoTerc=@pmIdTipoTerc
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposVeh] @pmIdTipoVeh VARCHAR(4)
 AS 
 DELETE FROM TiposVeh
 WHERE IdTipoVeh=@pmIdTipoVeh
GO
/****** Object:  StoredProcedure [dbo].[paDelTiposZona]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTiposZona] @pmIdTipZona VARCHAR(4)
 AS 
 DELETE FROM TiposZona
 WHERE IdTipZona=@pmIdTipZona
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfAmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AfAmt] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_AfAmt
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfDep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AfDep] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_AfDep
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AfIngreso] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_AfIngreso
 WHERE tmNumero=@pmtmNumero  
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfRetiro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AfRetiro] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_AfRetiro
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AfTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AfTraslado] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_AfTraslado
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Aportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_Aportes] @pmtmEst  VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
,@pmtmItem INT=Null
 AS 
 DELETE FROM tm_Aportes
 WHERE tmEst=@pmtmEst AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AutTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AutTot] @pmtmEst VARCHAR(5),@pmtmItem INT=Null
 AS 
 DELETE FROM tm_AutTot
 WHERE tmEst=@pmtmEst 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_AuxInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_AuxInv] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_AuxInv
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalAcum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_BalAcum] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_BalAcum  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_BalCom] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_BalCom
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalCompara]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_BalCompara] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_BalCompara
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_BalGen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_BalGen] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_BalGen
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Caja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Caja] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Caja
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CajaTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_CajaTot] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_CajaTot
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Cargos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_Cargos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Cargos
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_cheq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_cheq] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_cheq
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Combo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Combo] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Combo
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ComboLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_ComboLin] @pmtmNumero VARCHAR(5),@pmtmLinea INT
 AS 
 DELETE FROM tm_Combo
 WHERE tmNumero=@pmtmNumero AND tmLinea=@pmtmLinea
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Comisiones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Comisiones] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Comisiones  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Comp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Comp] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Compau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Compau] @pmtmNumero VARCHAR(5),@pmtmTipCom VARCHAR(3)
,@pmtmComprobante INT,@pmtmIdCia CHAR(2)
 AS 
 DELETE FROM tm_Compau
 WHERE tmNumero=@pmtmNumero AND tmTipCom LIKE ISNULL(@pmtmTipCom,'%') AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
AND (tmComprobante>=ISNULL(@pmtmComprobante,0)  AND tmComprobante<=ISNULL(@pmtmComprobante,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Contratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Contratos] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Contratos WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Cuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_Cuotas] @pmtmEst CHAR(2),@pmtmPrestamoID INT=Null,@pmtmIdCia CHAR(2)=Null,@pmtmNumCuota INT=Null
AS
 DELETE FROM  tm_Cuotas  
 WHERE tmEst=@pmtmEst
 AND (tmPrestamoID>=ISNULL(@pmtmPrestamoID,0)  AND tmPrestamoID<=ISNULL(@pmtmPrestamoID,2147483647))
 AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 AND (tmNumCuota>=ISNULL(@pmtmNumCuota,0)  AND tmNumCuota<=ISNULL(@pmtmNumCuota,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxcAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_CxcAbonos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxCobrar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_CxCobrar] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_CxCobrar
 WHERE tmNumero=@pmtmNumero 
AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxPagar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_CxPagar] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_CxPagar
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_CxpAplica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_CxpAplica] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_CxpAplica
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_DetCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_DetCue] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmConcepto VARCHAR(10)=Null
 AS 
 DELETE FROM tm_DetCue
 WHERE tmNumero=@pmtmNumero AND tmConcepto LIKE ISNULL(@pmtmConcepto,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Diario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Diario] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Diario
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_DifIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_DifIngreso] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_DifIngreso
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_EdsFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_EdsFormas] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_EstadoGyp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_EstadoGyp] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_EstadoGyp
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_EstClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_EstClientes] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_EstClientes WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ForItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_ForItems] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_ForItems
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_InfDiario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_InfDiario] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_InfDiario
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Ingresos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Ingresos] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Ingresos  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KarUbi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_KarUbi] @pmtmNumero VARCHAR(5),@pmtmItem INT
,@pmtmLinea INT=Null,@pmtmIdProducto VARCHAR(16)=Null
 AS 
 DELETE FROM tm_KarUbi
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647)) 
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KarUbiNts]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_KarUbiNts] @pmtmNumero VARCHAR(5),@pmtmLinea INT=Null
,@pmtmIdProducto VARCHAR(16)=Null
 AS 
 DELETE FROM tm_KarUbi
 WHERE tmNumero=@pmtmNumero AND tmEntradas>0 AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Kdex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Kdex] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KdexCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_KdexCom] @pmtmNumero VARCHAR(5),@pmtmItemCbo INT
 AS 
 DELETE FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmEsProdBase<>0   
 AND (tmItemCbo>=ISNULL(@pmtmItemCbo,0)  AND tmItemCbo<=ISNULL(@pmtmItemCbo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_KdexNts]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_KdexNts] @pmtmNumero VARCHAR(5),@pmtmItemCbo INT
 AS 
 DELETE FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmEntradas>0
 AND (tmItemCbo>=ISNULL(@pmtmItemCbo,0)  AND tmItemCbo<=ISNULL(@pmtmItemCbo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_LibOf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_LibOf] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_LibOf
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Liquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Liquida] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ListaPrec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_ListaPrec] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_ListaPrec
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Lot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Lot] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16)=Null
,@pmtmLinea INT=Null
 AS 
 DELETE FROM tm_Lot
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_LotEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_LotEnt] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)
 AS 
 DELETE FROM tm_Lot
 WHERE tmNumero=@pmtmNumero AND tmEntradas>0 
AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_MovClientes] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_MovClientes
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_MovCue] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_MovCue  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovInvent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_MovInvent] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_MovInvent
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovTanques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_MovTanques] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_MovTanques
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_MovVentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_MovVentas] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_MovVentas  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NomHoras]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_NomHoras]
 AS 
 DELETE FROM tm_NomHoras
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Nomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_Nomina] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NominaApo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_NominaApo] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq IN ('APORTE','PROVISION')
 AND tmItem>=1000  AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NominaCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_NominaCon] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4),@pmtmClaseLiq VARCHAR(10)=Null
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdConcepto=@pmtmIdConcepto
 AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%') AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NominaNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_NominaNom] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmNContto INT
 AS 
 DELETE FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq<>'NOVEDAD'
 AND  tmIdEmpleado=@pmtmIdEmpleado  AND tmNContto=@pmtmNContto
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_NomRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_NomRes] @pmtmNumero VARCHAR(5)
 AS 
 DELETE FROM tm_NomRes
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_OccComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_OccComp] @pmtmTipDoc VARCHAR(3),@pmtmOCargue INT,@pmtmIdCia CHAR(2)
 AS 
 DELETE FROM tm_OccComp
 WHERE tmTipDoc=@pmtmTipDoc AND tmOCargue=@pmtmOCargue AND tmIdCia=@pmtmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Pagos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Pagos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Plasueldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Plasueldos] @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30)
 AS 
 DELETE FROM tm_Plasueldos
 WHERE tmIdPeriodo LIKE ISNULL(@pmtmIdPeriodo,'%')
 AND tmKeyRegistro LIKE ISNULL(@pmtmKeyRegistro,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_RecAplica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_RecAplica] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_RecAplica
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ReqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_ReqDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_ReqDetalle
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Saldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Saldos] @pmtmEst CHAR(2)
 AS 
 DELETE FROM tm_Saldos  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Ser]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_Ser] @pmtmNumero VARCHAR(5),@pmtmItem INT
,@pmtmIdProducto VARCHAR(16)=Null,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 DELETE FROM tm_Ser
 WHERE tmNumero=@pmtmNumero   AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_TraDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_TraDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_TraDetalle
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_ValesCred]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_ValesCred] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 DELETE FROM tm_ValesCred
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_vce]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDeltm_vce]
 AS 
 DELETE FROM tm_vce
GO
/****** Object:  StoredProcedure [dbo].[paDeltm_Ventas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltm_Ventas] @pmtmEst CHAR(2)
 AS
 DELETE FROM tm_VentasRes  WHERE tmEst=@pmtmEst
 DELETE FROM tm_VentasDet  WHERE tmEst=@pmtmEst
 DELETE FROM tm_VentasCom  WHERE tmEst=@pmtmEst
 DELETE FROM tm_Ventas  WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paDelTraAntAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraAntAbonos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraAntAbonos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraAnticipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraAnticipos] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraAnticipos
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCauDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraCauDetalle] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraCauDetalle
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraCausacion] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraCausacion
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraConcCausac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraConcCausac] @pmIdConcepto VARCHAR(4)
 AS 
 DELETE FROM TraConcCausac
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paDelTraConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraConceptos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraConceptos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCumplido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraCumplido] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraCumplido
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCumRadica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraCumRadica] @pmNumRadica INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraCumRadica
 WHERE NumRadica=@pmNumRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraCumRemesas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraCumRemesas] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2) 
 AS 
 DELETE FROM Trn_TraCumRemesas
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDecAduana]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDecAduana] @pmTipDoc VARCHAR(3),@pmNumDeclara INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDecAduana
 WHERE TipDoc=@pmTipDoc AND NumDeclara=@pmNumDeclara AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDespachos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDespachos] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDespachos
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDespProgram]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDespProgram] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDespProgram
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevAnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevAnt
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevAos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevAos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevAos
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevCau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevCau] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevCau
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevCos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevCos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevCos WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevCum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevCum] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevCum
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevLeg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevLeg] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevLeg
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevLgo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevLgo] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevLgo WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevLiq] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevLiq
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevOdp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevOdp] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevOdp
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraDevReex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraDevReex] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraDevReex
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraFacRemesas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraFacRemesas] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraFacRemesas
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraFijos] @pmNumero INT
 AS 
 DELETE FROM TraFijos  WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paDelTraGuias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraGuias] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraGuias
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraInfViajes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraInfViajes] @pmTipDoc VARCHAR(3),@pmNumViaje INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraInfViajes
 WHERE TipDoc=@pmTipDoc AND NumViaje=@pmNumViaje AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraLiquida] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraLiquida
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraLiqViajes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraLiqViajes
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifAnexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraManifAnexo] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraManifAnexo
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifiesto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraManifiesto] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnManifiesto'
   BEGIN TRANSACTION @TrnNombre
   DELETE FROM  Trn_TraManifAnexo  WHERE  TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia 
   DELETE FROM Trn_TraManifiesto  WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia 
  COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraManifInt] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraManifInt
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraManifRem]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraManifRem] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraManifRem
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenAnt] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenAnt
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenCum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenCum] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenCum
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenLiq] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenLiq WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenManif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenManif] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenManif
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenPago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenPago] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenPago
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenRemesas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenRemesas] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenRemesas
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraOrdenServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraOrdenServ
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPedAnexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraPedAnexo] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
  DELETE FROM Trn_TraPedAnexo WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraPedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnPedido'
   BEGIN TRANSACTION @TrnNombre
   DELETE FROM Trn_TraPedAnexo WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
   DELETE FROM Trn_TraPedido WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
  COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPedMcias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraPedMcias] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraPedMcias
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPorteInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraPorteInt
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPresAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraPresAnt] @pmNumPsto INT
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnPresAnt'
  BEGIN TRANSACTION @TrnNombre
   DELETE FROM Trn_TraPresItems  WHERE NumPsto=@pmNumPsto    
   DELETE FROM Trn_TraPresAnt  WHERE NumPsto=@pmNumPsto
  COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelTraPresItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraPresItems] @pmNumPsto INT,@pmItem INT
 AS 
 DELETE FROM Trn_TraPresItems
 WHERE NumPsto=@pmNumPsto 
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelTraReexpedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraReexpedido] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraReexpedido
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemAnexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraRemAnexo] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraRemAnexo
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemCntdor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraRemCntdor] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraRemCntdor
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemesa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraRemesa] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'TrnRemesa'
   BEGIN TRANSACTION @TrnNombre
   DELETE FROM Trn_TraRemAnexo  WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
   DELETE FROM Trn_TraRemesa  WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
  COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paDelTraRemMcias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraRemMcias] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraRemMcias
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraslados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Traslados
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelTraTraslados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelTraTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_TraTraslados
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelUm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelUm] @pmUndMed VARCHAR(10)
 AS 
 DELETE FROM Sys_Um
 WHERE UndMed=@pmUndMed
GO
/****** Object:  StoredProcedure [dbo].[paDelUndMed]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelUndMed] @pmIdUnd VARCHAR(4)
 AS 
 DELETE FROM UndMed
 WHERE IdUnd=@pmIdUnd
GO
/****** Object:  StoredProcedure [dbo].[paDelUOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelUOpciones] @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20)=Null
 AS 
 DELETE FROM adm_UOpciones
 WHERE IdUsuario=@pmIdUsuario AND NomOpcion LIKE ISNULL(@pmNomOpcion,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelUsuarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelUsuarios] @pmIdUsuario VARCHAR(11)
AS
BEGIN
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnUsuarios'
  BEGIN TRANSACTION @TrnNombre
  DELETE FROM adm_PermisosRoles WHERE IdUsuario=@pmIdUsuario
  DELETE FROM adm_Permisos WHERE IdUsuario=@pmIdUsuario 
  DELETE FROM  adm_UOpciones  WHERE  IdUsuario=@pmIdUsuario
  DELETE FROM adm_Usuarios WHERE IdUsuario=@pmIdUsuario
 COMMIT TRANSACTION  @TrnNombre
END
GO
/****** Object:  StoredProcedure [dbo].[paDelUsucaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelUsucaja] @pmIdUsuario VARCHAR(11),@pmnFormato VARCHAR(10)
 AS 
 DELETE FROM adm_Usucaja
 WHERE IdUsuario=@pmIdUsuario AND nFormato LIKE ISNULL(@pmnFormato,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Vales
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelValesRutas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelValesRutas] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_ValesRutas
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_Contrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVeh_Contrato] @pmNumContrato INT
 AS 
 DELETE FROM Veh_Contrato
 WHERE NumContrato=@pmNumContrato
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_Cupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVeh_Cupos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4)
 AS 
 DELETE FROM Veh_Cupos
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase like ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_Saldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVeh_Saldos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 DELETE FROM Veh_Saldos
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase LIKE ISNULL(@pmIdClase,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paDelVeh_SaldosAll]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVeh_SaldosAll] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
 IF @pmIdVehiculo IS NULL
  DELETE Veh_Saldos
  FROM Vehiculos AS V INNER JOIN Veh_Saldos  AS S  ON V.IdVehiculo=S.IdVehiculo
  WHERE  IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 ELSE
  DELETE FROM Veh_Saldos  WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paDelVehClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVehClientes] @pmIdVehiculo VARCHAR(10)
 AS 
 DELETE FROM VehClientes
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paDelVehConductor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVehConductor] @pmIdVehiculo VARCHAR(10),@pmNumero INT
 AS 
 DELETE FROM Trn_VehConductor
 WHERE IdVehiculo=@pmIdVehiculo 
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelVehiculos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVehiculos] @pmIdVehiculo VARCHAR(10)
 AS 
 DELETE FROM Vehiculos
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paDelVehLecturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVehLecturas] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_VehLecturas  WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelVehPartes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVehPartes] @pmIdVehiculo VARCHAR(10),@pmNumParte VARCHAR(20)
 AS 
 DELETE FROM VehPartes WHERE IdVehiculo=@pmIdVehiculo AND NumParte=@pmNumParte
GO
/****** Object:  StoredProcedure [dbo].[paDelVehPolizas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVehPolizas] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4)
 AS 
 DELETE FROM VehPolizas
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelVehRemolq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVehRemolq] @pmIdRemque VARCHAR(10)
 AS 
 DELETE FROM VehRemolq
 WHERE IdRemque=@pmIdRemque
GO
/****** Object:  StoredProcedure [dbo].[paDelVehTraspasos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVehTraspasos] @pmIdVehiculo VARCHAR(10),@pmNumero INT
 AS 
 DELETE FROM Trn_VehTraspasos
 WHERE IdVehiculo=@pmIdVehiculo 
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paDelVencAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVencAbonos] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelVencAbonosSaf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelVencAbonosSaf]  @pmTipDoc VARCHAR(3),@pmFactura INT
,@pmIdCiaFac CHAR(2),@pmTipoAplica VARCHAR(10)=Null
 AS 
 DELETE FROM Trn_VencAbonos
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND  IdCiaFac=@pmIdCiaFac
 AND TipoAplica LIKE ISNULL(@pmTipoAplica,'%')
GO
/****** Object:  StoredProcedure [dbo].[paDelVencimientos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelVencimientos] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 DELETE FROM Trn_Vencimientos
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paDelZonas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelZonas] @pmIdZona VARCHAR(4)
 AS 
 DELETE FROM Zonas
 WHERE IdZona=@pmIdZona
GO
/****** Object:  StoredProcedure [dbo].[paInsActivos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsActivos] @pmIdActivo VARCHAR(30),@pmNomActivo VARCHAR(250),@pmNumSerie VARCHAR(30),@pmCodInvent VARCHAR(16),@pmCodBarras VARCHAR(20),@pmIdGrupo VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdInstala VARCHAR(4),@pmIdDep VARCHAR(4),@pmIdRespons VARCHAR(16),@pmIdCia CHAR(2),@pmIdProv VARCHAR(16),@pmFecCompra SMALLDATETIME
,@pmFecActivacion SMALLDATETIME,@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmVrCompra MONEY,@pmVrComercial MONEY,@pmVrBaseDep MONEY,@pmVrMejoras MONEY,@pmVrDisminucion MONEY,@pmVidaUtil INT,@pmFecFinDep DATETIME,@pmMetodoDep VARCHAR(10),@pmAjustable BIT,@pmContable BIT,@pmCueEnGrupo BIT,@pmVrAjuInfAcum MONEY
,@pmVrDepAcuHis MONEY,@pmVrDepAcuAju MONEY,@pmVrAjuInfDep MONEY,@pmNumMesesDep INT,@pmFecUltDep SMALLDATETIME,@pmMarca VARCHAR(30),@pmModelo VARCHAR(10),@pmNumPlaca VARCHAR(20),@pmNumDoc VARCHAR(20),@pmReferencia VARCHAR(50),@pmIdEstado VARCHAR(4),@pmFecRetiro SMALLDATETIME,@pmIdCausal VARCHAR(4),@pmVrVenta MONEY,@pmTipoContable VARCHAR(10),@pmVrSalvamento MONEY,@pmDepPartes BIT
,@pmUndsProd INT,@pmTipComp VARCHAR(3),@pmNumComp INT,@pmCdCiaComp CHAR(2),@pmVUExtend INT,@pmFecCreacion SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Activos (IdActivo,NomActivo,NumSerie,CodInvent,CodBarras,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdCia,IdProv,FecCompra,FecActivacion,NumOrden,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep,VrMejoras,VrDisminucion,VidaUtil,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep,FecUltDep,Marca
,Modelo,NumPlaca,NumDoc,Referencia,IdEstado,FecRetiro,IdCausal,VrVenta,FecCreacion,IdUsuario,TipoContable,VrSalvamento,DepPartes,UndsProd,TipComp,NumComp,CdCiaComp,VUExtend)
 VALUES (@pmIdActivo,@pmNomActivo,@pmNumSerie,@pmCodInvent,@pmCodBarras,@pmIdGrupo,@pmIdCCosto,@pmIdSubCos,@pmIdInstala,@pmIdDep,@pmIdRespons,@pmIdCia,@pmIdProv,@pmFecCompra,@pmFecActivacion,@pmNumOrden,@pmIdCiaOrden,@pmNumEntrada,@pmIdCiaEnt,@pmVrCompra,@pmVrComercial,@pmVrBaseDep,@pmVrMejoras,@pmVrDisminucion,@pmVidaUtil,@pmFecFinDep,@pmMetodoDep,@pmAjustable,@pmContable,@pmCueEnGrupo,@pmVrAjuInfAcum,@pmVrDepAcuHis
,@pmVrDepAcuAju,@pmVrAjuInfDep,@pmNumMesesDep,@pmFecUltDep,@pmMarca,@pmModelo,@pmNumPlaca,@pmNumDoc,@pmReferencia,@pmIdEstado,@pmFecRetiro,@pmIdCausal,@pmVrVenta,@pmFecCreacion,@pmIdUsuario,@pmTipoContable,@pmVrSalvamento,@pmDepPartes,@pmUndsProd,@pmTipComp,@pmNumComp,@pmCdCiaComp,@pmVUExtend)
GO
/****** Object:  StoredProcedure [dbo].[paInsActivos_Anexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsActivos_Anexo] @pmIdActivo VARCHAR(30),@pmIdCuenta VARCHAR(16),@pmIdCueDep VARCHAR(16),@pmIdCueGasto VARCHAR(16),@pmIdCueAjuste VARCHAR(16),@pmIdCueCorr VARCHAR(16),@pmIdCueAjuDep VARCHAR(16),@pmIdCueCorrAD VARCHAR(16),@pmNumPoliza VARCHAR(30),@pmNitCiaAseg VARCHAR(16),@pmFecPoliza SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmVrAsegurado MONEY,@pmVrCuotaMes MONEY,@pmVendPoliza VARCHAR(150),@pmTeleVend VARCHAR(30),@pmDiasGarantia INT,@pmComentGarantia VARCHAR(250),@pmPignorado BIT
,@pmFecIniPignor SMALLDATETIME,@pmFecFinPignor SMALLDATETIME,@pmGarantPignor VARCHAR(150),@pmMantenimiento BIT,@pmNumContrato VARCHAR(20),@pmFecIniCont SMALLDATETIME,@pmFecFinCont SMALLDATETIME,@pmPeriodicidad INT,@pmFecUltMnmto SMALLDATETIME,@pmNitEmpMnmto VARCHAR(16),@pmComentMnmto VARCHAR(250),@pmDesUbicacion VARCHAR(100),@pmComentarios VARCHAR(250),@pmComentRetiro VARCHAR(250),@pmDatosTecnicos VARCHAR(4000),@pmCodNiifAct VARCHAR(16),@pmCodNiifDep VARCHAR(16),@pmCodNiifGasto VARCHAR(16)
 AS 
 INSERT INTO Activos_Anexo (IdActivo,IdCuenta,IdCueDep,IdCueGasto,IdCueAjuste,IdCueCorr,IdCueAjuDep,IdCueCorrAD,NumPoliza,NitCiaAseg,FecPoliza,FecVigencia,VrAsegurado,VrCuotaMes,VendPoliza,TeleVend,DiasGarantia,ComentGarantia,Pignorado,FecIniPignor,FecFinPignor,GarantPignor,Mantenimiento,NumContrato,FecIniCont,FecFinCont,Periodicidad,FecUltMnmto,NitEmpMnmto,ComentMnmto,DesUbicacion,Comentarios,ComentRetiro,DatosTecnicos,CodNiifAct,CodNiifDep,CodNiifGasto)
 VALUES (@pmIdActivo,@pmIdCuenta,@pmIdCueDep,@pmIdCueGasto,@pmIdCueAjuste,@pmIdCueCorr,@pmIdCueAjuDep,@pmIdCueCorrAD,@pmNumPoliza,@pmNitCiaAseg,@pmFecPoliza,@pmFecVigencia,@pmVrAsegurado,@pmVrCuotaMes,@pmVendPoliza,@pmTeleVend,@pmDiasGarantia,@pmComentGarantia,@pmPignorado,@pmFecIniPignor,@pmFecFinPignor,@pmGarantPignor,@pmMantenimiento,@pmNumContrato,@pmFecIniCont,@pmFecFinCont,@pmPeriodicidad,@pmFecUltMnmto,@pmNitEmpMnmto,@pmComentMnmto,@pmDesUbicacion
,@pmComentarios,@pmComentRetiro,@pmDatosTecnicos,@pmCodNiifAct,@pmCodNiifDep,@pmCodNiifGasto)
GO
/****** Object:  StoredProcedure [dbo].[paInsActivos_Partes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsActivos_Partes] @pmIdActivo VARCHAR(30),@pmItem INT,@pmDescParte VARCHAR(250),@pmNumParte VARCHAR(30),@pmFecIniDep SMALLDATETIME,@pmMetDeprec VARCHAR(10),@pmVidaUtil INT,@pmUndsProd INT,@pmVrCompra MONEY,@pmVrBaseDep MONEY,@pmVrSalvamento MONEY
,@pmVrDepAcum MONEY,@pmVrDepAcumHis MONEY,@pmNitProv VARCHAR(16),@pmIdEstado VARCHAR(4),@pmFecCreacion SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmCueEnAfijo BIT,@pmIdCuenta VARCHAR(16),@pmIdCueDep VARCHAR(16),@pmIdCueGasto VARCHAR(16),@pmCodNiifAct VARCHAR(16),@pmCodNiifDep VARCHAR(16),@pmCodNiifGasto VARCHAR(16)
,@pmVrMejoras MONEY,@pmVrDisminuc MONEY,@pmVrAjuAcum MONEY,@pmVrAjuDepAcum MONEY,@pmFec_Retiro SMALLDATETIME
 AS 
 INSERT INTO Activos_Partes (IdActivo,Item,DescParte,NumParte,FecIniDep,MetDeprec,VidaUtil,UndsProd,VrCompra,VrBaseDep,VrMejoras,VrDisminuc,VrSalvamento,VrDepAcum,VrDepAcumHis,VrAjuAcum,VrAjuDepAcum,NitProv,IdEstado,FecCreacion,IdUsuario,CueEnAfijo,IdCuenta,IdCueDep,IdCueGasto,CodNiifAct,CodNiifDep,CodNiifGasto,Fec_Retiro)
 VALUES (@pmIdActivo,@pmItem,@pmDescParte,@pmNumParte,@pmFecIniDep,@pmMetDeprec,@pmVidaUtil,@pmUndsProd,@pmVrCompra,@pmVrBaseDep,@pmVrMejoras,@pmVrDisminuc,@pmVrSalvamento,@pmVrDepAcum,@pmVrDepAcumHis,@pmVrAjuAcum,@pmVrAjuDepAcum,@pmNitProv,@pmIdEstado,@pmFecCreacion,@pmIdUsuario,@pmCueEnAfijo,@pmIdCuenta,@pmIdCueDep,@pmIdCueGasto,@pmCodNiifAct,@pmCodNiifDep,@pmCodNiifGasto,@pmFec_Retiro)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuAnticipos_Nit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuAnticipos_Nit] @pmIdPoseedor VARCHAR(16),@pmIdPoseedorDos VARCHAR(16),@pmNewIdPoseedor VARCHAR(16)
 AS 
 IF EXISTS (SELECT * FROM AcuAnticipos WHERE IdPoseedor=@pmIdPoseedor OR IdPoseedor=@pmIdPoseedorDos)
  INSERT INTO AcuAnticipos (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo,SaldoAnt,VrAnticipos,VrPagos)
  SELECT nAnno,nMes,IdCia,@pmNewIdPoseedor,IdVehiculo,SUM(SaldoAnt),SUM(VrAnticipos),SUM(VrPagos)
  FROM AcuAnticipos WHERE IdPoseedor=@pmIdPoseedor OR IdPoseedor=@pmIdPoseedorDos
  GROUP BY nAnno,nMes,IdCia,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuAnticipos_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuAnticipos_Uni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuAnticipos WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
  INSERT INTO AcuAnticipos (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo,SaldoAnt,VrAnticipos,VrPagos)
  SELECT nAnno,nMes,IdCia,IdPoseedor,@pmNewVehiculo,SUM(SaldoAnt),SUM(VrAnticipos),SUM(VrPagos)
  FROM AcuAnticipos WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
  GROUP BY nAnno,nMes,IdCia,IdPoseedor
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuAportesSan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuAportesSan] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT,@pmIdCia CHAR(2)=Null,@pmIdAsociado VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 INSERT INTO AcuAportes (nAnno,nMes,IdCia,IdAsociado,UndVehiculo,IdVehiculo,Concepto,SaldoAnt,VrAporte,VrDeduccion)
 SELECT @pmnAnno,@pmnMes,A.IdCia,A.IdAsociado,A.UndVehiculo,A.IdVehiculo,A.Concepto,A.SaldoAnt+A.VrAporte-A.VrDeduccion,0,0
 FROM AcuAportes AS A WHERE A.nAnno=@pmAnnoAnt AND A.nMes=@pmMesAnt
 AND NOT EXISTS (SELECT * FROM AcuAportes AS AP WHERE AP.nAnno=@pmnAnno AND AP.nMes=@pmnMes  
 AND AP.IdCia=A.IdCia AND AP.IdAsociado=A.IdAsociado AND AP.UndVehiculo=A.UndVehiculo AND AP.IdVehiculo=A.IdVehiculo AND AP.Concepto=A.Concepto)
 AND (@pmIdCia IS NULL OR A.IdCia=@pmIdCia) AND (@pmIdAsociado IS NULL OR A.IdAsociado=@pmIdAsociado) AND (@pmIdVehiculo IS NULL OR A.IdVehiculo=@pmIdVehiculo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCaja] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11),@pmSaldoAnt MONEY
,@pmFacturas MONEY,@pmDevFacturas MONEY,@pmPlanillas MONEY,@pmDevPlanillas MONEY,@pmRecibos MONEY,@pmDevRecibos MONEY
,@pmIngCaja MONEY,@pmDevIngCaja MONEY,@pmEgrCaja MONEY,@pmDevEgrCaja MONEY,@pmConsignac MONEY,@pmDevConsig MONEY
,@pmNotasCalibra MONEY,@pmDevCalibra MONEY,@pmOtrosIng MONEY,@pmOtrosEgr MONEY
 AS 
 INSERT INTO AcuCaja (FechaDia,NumCorte,IdCia,IdUsuario,SaldoAnt,Facturas,DevFacturas,Planillas,DevPlanillas,Recibos,DevRecibos,IngCaja,DevIngCaja
,EgrCaja,DevEgrCaja,Consignac,DevConsig,NotasCalibra,DevCalibra,OtrosIng,OtrosEgr)
 VALUES (@pmFechaDia,@pmNumCorte,@pmIdCia,@pmIdUsuario,@pmSaldoAnt,@pmFacturas,@pmDevFacturas,@pmPlanillas
,@pmDevPlanillas,@pmRecibos,@pmDevRecibos,@pmIngCaja,@pmDevIngCaja,@pmEgrCaja,@pmDevEgrCaja,@pmConsignac,@pmDevConsig,@pmNotasCalibra,@pmDevCalibra,@pmOtrosIng,@pmOtrosEgr)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCajaBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuCajaBuses] @pmIdUsuario VARCHAR(11),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmSaldoAnterior MONEY
, @pmTotalDebitos MONEY, @pmTotalCreditos MONEY, @pmNuevoSaldo  MONEY

AS
  INSERT INTO  AcuCajaBuses  (IdUsuario, IdCia, Fecha, SaldoAnterior, TotalDebitos, TotalCreditos, NuevoSaldo )
  VALUES (@pmIdUsuario,@pmIdCia,@pmFecha,@pmSaldoAnterior, @pmTotalDebitos, @pmTotalCreditos, @pmNuevoSaldo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCajaFco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCajaFco] @pmFechaDia SMALLDATETIME,@pmNumCorte INT
,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO AcuCaja (FechaDia,NumCorte,IdCia,IdUsuario,Facturas)
 SELECT Fecha,@pmNumCorte,IdCia,IdUsuario,SUM(VrPagado-VrCambio)
 FROM Trn_Pagos
 WHERE TipDoc IN ('FCO','FO1','FO2','FO3','FO4','FO5')  AND Fecha=@pmFechaDia AND EsCaja<>0 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 GROUP BY Fecha,IdCia,IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuClientes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmSaldoAnt MONEY,@pmFacturas MONEY,@pmDevFacturas MONEY,@pmRecibos MONEY,@pmDevRecibos MONEY,@pmNotasDeb MONEY,@pmNotasCre MONEY
 AS 
 INSERT INTO AcuClientes (nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Facturas,DevFacturas,Recibos,DevRecibos,NotasDeb,NotasCre)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCliente,@pmIdAgencia,@pmSaldoAnt,@pmFacturas,@pmDevFacturas,@pmRecibos,@pmDevRecibos,@pmNotasDeb,@pmNotasCre)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuClientes_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuClientes_Uni] @pmIdCliente VARCHAR(16),@pmIdClienteDos VARCHAR(16),@pmNewCliente VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCliente FROM AcuClientes WHERE IdCliente=@pmIdCliente OR IdCliente=@pmIdClienteDos)
  INSERT INTO AcuClientes (nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Facturas,DevFacturas,Recibos,DevRecibos,NotasDeb,NotasCre)
  SELECT  nAnno,nMes,IdCia,@pmNewCliente,IdAgencia,SUM(SaldoAnt),SUM(Facturas),SUM(DevFacturas),SUM(Recibos),SUM(DevRecibos),SUM(NotasDeb),SUM(NotasCre)
  FROM AcuClientes WHERE IdCliente=@pmIdCliente OR IdCliente=@pmIdClienteDos
  GROUP BY nAnno,nMes,IdCia,IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuClientesFcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuClientesFcr] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 INSERT INTO AcuClientes (nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Facturas,DevFacturas,Recibos,DevRecibos,NotasDeb,NotasCre)
 SELECT YEAR(Fecha),MONTH(Fecha),IdCia,IdCliente,IdAgencia,0,SUM(VrFactura),0,0,0,0,0
 FROM Trn_Vencimientos
 WHERE TipDoc<>'NDB'  AND YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY YEAR(Fecha),MONTH(Fecha),IdCia,IdCliente,IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentas] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentas_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuCuentas AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuCuentas AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentas_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(Fecha),@pmnMes,IdCia,D.IdCuenta,0,SUM(VrDebito),SUM(VrCredito)
 FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento=1
 AND (@pmIdCia IS NULL OR IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR D.IdCuenta=@pmIdCuenta) 
 GROUP BY  YEAR(Fecha),IdCia,D.IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentas_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentas_Uni] @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuCuentas WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuCuentas
  WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAge] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdTercero,@pmCodAgncia,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Pla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAge_Pla]  @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuCuentasAge WHERE (CodAgncia=@pmIdVehiculo OR CodAgncia=@pmIdVehiculoDos) AND TipoAcum='NV')
  INSERT INTO AcuCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,@pmNewVehiculo,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuCuentasAge WHERE (CodAgncia=@pmIdVehiculo OR CodAgncia=@pmIdVehiculoDos) AND TipoAcum='NV'
 GROUP BY nAnno,nMes,IdCia,IdCuenta,IdTercero,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAge_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.CodAgncia,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuCuentasAge AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuCuentasAge AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.CodAgncia=S.CodAgncia)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAge_Sel]  @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 --nit-veh
  INSERT INTO AcuCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(Fecha),@pmnMes,IdCia,D.IdCuenta,IdTercero,IdVehiculo,'NV',0,SUM(VrDebito),SUM(VrCredito)
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND Tercero<>0 AND Vehiculo<>0
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(Fecha),IdCia,D.IdCuenta,IdTercero,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Unf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAge_Unf]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuCuentasAge WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdTercero,CodAgncia,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuCuentasAge WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
 GROUP BY  nAnno,nMes,IdCia,IdTercero,CodAgncia,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAge_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAge_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdTercero FROM AcuCuentasAge WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO AcuCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewTercero,CodAgncia,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuCuentasAge WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
 GROUP BY nAnno,nMes,IdCia,IdCuenta,CodAgncia,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAux]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAux] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmnReg INT,@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmSubAuxiliar VARCHAR(16),@pmTipoAcum VARCHAR(4),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY,@pmTipoAfiVehic INT
 AS 
 INSERT INTO AcuCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmnReg,@pmIdCuenta,@pmIdTercero,@pmCodAgncia,@pmIdCCosto,@pmIdSubCos
,@pmSubAuxiliar,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos,@pmTipoAfiVehic)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAux_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAux_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(4),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
 SELECT @pmnAnno,@pmnMes,S.IdCia,0,S.IdCuenta,S.IdTercero,S.CodAgncia,S.IdCCosto,S.IdSubCos,S.SubAuxiliar,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0,S.TipoAfiVehic
 FROM AcuCuentasAux AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuCuentasAux AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta
 AND AC.IdTercero=S.IdTercero AND AC.CodAgncia=S.CodAgncia AND AC.IdCCosto=S.IdCCosto AND AC.IdSubCos=S.IdSubCos
 AND AC.SubAuxiliar=S.SubAuxiliar AND AC.TipoAcum=S.TipoAcum AND AC.TipoAfiVehic=S.TipoAfiVehic)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasAux_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasAux_Uni]  @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuCuentasAux WHERE (SubAuxiliar=@pmIdVehiculo OR SubAuxiliar=@pmIdVehiculoDos) AND TipoAcum LIKE '%V%')
  INSERT INTO AcuCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
  SELECT nAnno,nMes,IdCia,MAX(nReg),IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,@pmNewVehiculo,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos),TipoAfiVehic
  FROM AcuCuentasAux WHERE (SubAuxiliar=@pmIdVehiculo OR SubAuxiliar=@pmIdVehiculoDos) AND TipoAcum LIKE '%V%'
  GROUP BY nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,TipoAcum,TipoAfiVehic
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasCc] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdCCosto,@pmIdSubCos
,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasCc_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdCCosto,S.IdSubCos,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuCuentasCc AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuCuentasCc AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdCCosto=S.IdCCosto AND AC.IdSubCos=S.IdSubCos)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasCc_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'AcuCuentasCc'
  BEGIN TRANSACTION @TrnNombre
  INSERT INTO AcuCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(Fecha),@pmnMes,IdCia,D.IdCuenta,IdCCosto,'-1','CC',0,SUM(VrDebito),SUM(VrCredito)
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND CentroCosto<>0 
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(Fecha),IdCia,D.IdCuenta,IdCCosto
 --centro de costo-subcentro
  INSERT INTO AcuCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(Fecha),@pmnMes,IdCia,D.IdCuenta,IdCCosto,IdSubCos,'CS',0,SUM(VrDebito),SUM(VrCredito)
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND CentroCosto<>0 AND SubCentro<>0
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(Fecha),IdCia,D.IdCuenta,IdCCosto,IdSubCos
 COMMIT TRANSACTION  @TrnNombre
END
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasCc_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasCc_Uni]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuCuentasCc WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdCCosto,IdSubCos,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuCuentasCc WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia,IdCCosto,IdSubCos,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasNit] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdTercero,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasNit_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuCuentasNit AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuCuentasNit AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasNit_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(Fecha),@pmnMes,IdCia,D.IdCuenta,IdTercero,0,SUM(VrDebito),SUM(VrCredito)
 FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND Tercero<>0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(Fecha),IdCia,D.IdCuenta,IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_Unf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasNit_Unf]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuCuentasNit WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdTercero,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuCuentasNit WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia,IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasNit_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasNit_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdTercero FROM AcuCuentasNit WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO AcuCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewTercero,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuCuentasNit WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
  GROUP BY nAnno,nMes,IdCia,IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeh] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdVehiculo,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_Pla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeh_Pla] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuCuentasVeh WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
   INSERT INTO AcuCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
   SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewVehiculo,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
   FROM AcuCuentasVeh WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
   GROUP BY nAnno,nMes,IdCia,IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeh_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdVehiculo,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuCuentasVeh AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuCuentasVeh AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdVehiculo=S.IdVehiculo)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeh_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(Fecha),@pmnMes,IdCia,D.IdCuenta,IdVehiculo,0,SUM(VrDebito),SUM(VrCredito)
 FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND Vehiculo<>0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(Fecha),IdCia,D.IdCuenta,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeh_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeh_Uni]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuCuentasVeh WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
   INSERT INTO AcuCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
   SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdVehiculo,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
   FROM AcuCuentasVeh WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
   GROUP BY nAnno,nMes,IdCia,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeht_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeht_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuCuentasVeht (nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.IdVehiculo,S.TipoAfiVehic,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuCuentasVeht AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuCuentasVeht AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.IdVehiculo=S.IdVehiculo AND AC.TipoAfiVehic=S.TipoAfiVehic)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuCuentasVeht_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuCuentasVeht_Uni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuCuentasVeht WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
  INSERT INTO AcuCuentasVeht (nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,@pmNewVehiculo,TipoAfiVehic,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuCuentasVeht WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
  GROUP BY nAnno,nMes,IdCia,IdCuenta,IdTercero,TipoAfiVehic,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentas] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuFisCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentas_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuFisCuentas AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuFisCuentas AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentas_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuFisCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,0,SUM(D.VrDebito),SUM(D.VrCredito)
 FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
 INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='FISCAL' AND P.Movimiento<>0
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentas_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentas_Uni] @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuFisCuentas WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuFisCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuFisCuentas
  WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAge] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuFisCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdTercero,@pmCodAgncia,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAge_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.CodAgncia,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuFisCuentasAge AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuFisCuentasAge AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.CodAgncia=S.CodAgncia)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAge_Sel]  @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 --nit-veh
  INSERT INTO AcuFisCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdTercero,D.IdVehiculo,'NV',0,SUM(D.VrDebito),SUM(D.VrCredito)
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='FISCAL' AND P.Movimiento=1 AND P.Tercero=1 AND P.Vehiculo=1
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdTercero,D.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Unf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAge_Unf]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuFisCuentasAge WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuFisCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdTercero,CodAgncia,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuFisCuentasAge WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
 GROUP BY nAnno,nMes,IdCia,IdTercero,CodAgncia,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAge_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdTercero FROM AcuFisCuentasAge WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO AcuFisCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewTercero,CodAgncia,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuFisCuentasAge WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
 GROUP BY nAnno,nMes,IdCia,IdCuenta,CodAgncia,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAge_Veh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAge_Veh]  @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuFisCuentasAge WHERE (CodAgncia=@pmIdVehiculo OR CodAgncia=@pmIdVehiculoDos) AND TipoAcum='NV')
  INSERT INTO AcuFisCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,@pmNewVehiculo,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuFisCuentasAge WHERE (CodAgncia=@pmIdVehiculo OR CodAgncia=@pmIdVehiculoDos) AND TipoAcum='NV'
  GROUP BY nAnno,nMes,IdCia,IdCuenta,IdTercero,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAux]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAux] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmnReg INT,@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmSubAuxiliar VARCHAR(16),@pmTipoAcum VARCHAR(4),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY,@pmTipoAfiVehic INT
 AS 
 INSERT INTO AcuFisCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmnReg,@pmIdCuenta,@pmIdTercero,@pmCodAgncia,@pmIdCCosto,@pmIdSubCos
,@pmSubAuxiliar,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos,@pmTipoAfiVehic)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasAux_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasAux_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(4),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
 SELECT @pmnAnno,@pmnMes,S.IdCia,0,S.IdCuenta,S.IdTercero,S.CodAgncia,S.IdCCosto,S.IdSubCos,S.SubAuxiliar,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0,S.TipoAfiVehic
 FROM AcuFisCuentasAux AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuFisCuentasAux AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes 
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.CodAgncia=S.CodAgncia AND AC.IdCCosto=S.IdCCosto AND AC.IdSubCos=S.IdSubCos
 AND AC.SubAuxiliar=S.SubAuxiliar AND AC.TipoAcum=S.TipoAcum AND AC.TipoAfiVehic=S.TipoAfiVehic)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasCc] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuFisCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdCCosto,@pmIdSubCos
,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasCc_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdCCosto,S.IdSubCos,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuFisCuentasCc AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuFisCuentasCc AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdCCosto=S.IdCCosto AND AC.IdSubCos=S.IdSubCos)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasCc_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'AcuFisCuentasCc'
  BEGIN TRANSACTION @TrnNombre
  INSERT INTO AcuFisCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdCCosto,'-1','CC',0,SUM(D.VrDebito),SUM(D.VrCredito)
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='FISCAL' AND P.Movimiento=1 AND P.CentroCosto=1
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdCCosto
 --centro de costo-subcentro
  INSERT INTO AcuFisCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdCCosto,D.IdSubCos,'CS',0,SUM(D.VrDebito),SUM(D.VrCredito)
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='FISCAL' AND P.Movimiento=1 AND CentroCosto=1 AND SubCentro=1
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdCCosto,D.IdSubCos
 COMMIT TRANSACTION  @TrnNombre
END
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasCc_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasCc_Uni]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuFisCuentasCc WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuFisCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdCCosto,IdSubCos,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuFisCuentasCc WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia,IdCCosto,IdSubCos,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasNit] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuFisCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdTercero,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasNit_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuFisCuentasNit AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuFisCuentasNit AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasNit_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuFisCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdTercero,0,SUM(D.VrDebito),SUM(D.VrCredito)
 FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
 INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='FISCAL' AND P.Movimiento=1 AND P.Tercero=1
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_Unf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasNit_Unf]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuFisCuentasNit WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuFisCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdTercero,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuFisCuentasNit WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia,IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasNit_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasNit_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdTercero FROM AcuFisCuentasNit WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO AcuFisCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewTercero,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuFisCuentasNit WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
  GROUP BY nAnno,nMes,IdCia,IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasVeh] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuFisCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdVehiculo,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasVeh_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdVehiculo,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuFisCuentasVeh AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuFisCuentasVeh AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdVehiculo=S.IdVehiculo)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasVeh_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuFisCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdVehiculo,0,SUM(D.VrDebito),SUM(D.VrCredito)
 FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='FISCAL' AND P.Movimiento=1 AND P.Vehiculo=1
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_Unc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasVeh_Unc]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuFisCuentasVeh WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
   INSERT INTO AcuFisCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
   SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdVehiculo,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
   FROM AcuFisCuentasVeh WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
   GROUP BY nAnno,nMes,IdCia,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeh_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasVeh_Uni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuFisCuentasVeh WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
   INSERT INTO AcuFisCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
   SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewVehiculo,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
   FROM AcuFisCuentasVeh WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
   GROUP BY nAnno,nMes,IdCia,IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuFisCuentasVeht_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuFisCuentasVeht_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuFisCuentasVeht (nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.IdVehiculo,S.TipoAfiVehic,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuFisCuentasVeht AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuFisCuentasVeht AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.IdVehiculo=S.IdVehiculo AND AC.TipoAfiVehic=S.TipoAfiVehic)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInventario] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmSaldoAnt DECIMAL(14,4),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4)
,@pmCostoAnt MONEY,@pmCostoEnt MONEY,@pmCostoSal MONEY
 AS 
 INSERT INTO AcuInventario (nAnno,nMes,IdCia,IdProducto,IdBodega,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdProducto,@pmIdBodega,@pmSaldoAnt,@pmEntradas,@pmSalidas
,@pmCostoAnt,@pmCostoEnt,@pmCostoSal)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInventarioKar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInventarioKar] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 INSERT INTO AcuInventario (nAnno,nMes,IdCia,IdProducto,IdBodega,Entradas,Salidas,CostoEnt,CostoSal,SaldoAnt,CostoAnt)
 SELECT @pmnAnno,@pmnMes,IdCia,K.IdProducto,K.IdBodega,SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal),0,0
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE  YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes AND TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')
 AND TipoRef<>'SERVICIO' AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY IdCia,K.IdProducto,K.IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvLotes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInvLotes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4)
,@pmNumLote VARCHAR(30),@pmSaldoAnt DECIMAL(14,4),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4),@pmCostoAnt MONEY,@pmCostoEnt MONEY,@pmCostoSal MONEY
 AS 
 INSERT INTO AcuInvLotes (nAnno,nMes,IdCia,IdProducto,IdBodega,NumLote,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdProducto,@pmIdBodega,@pmNumLote,@pmSaldoAnt,@pmEntradas,@pmSalidas,@pmCostoAnt,@pmCostoEnt,@pmCostoSal)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvLotesKar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInvLotesKar] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 INSERT INTO AcuInvLotes (nAnno,nMes,IdCia,IdProducto,IdBodega,NumLote,Entradas,Salidas,CostoEnt,CostoSal,SaldoAnt,CostoAnt)
 SELECT @pmnAnno,@pmnMes,IdCia,L.IdProducto,L.IdBodega,NumLote,SUM(Entradas),SUM(Salidas),0,0,0,0
 FROM Trn_LotMov AS L INNER JOIN ProdMcias AS P ON L.IdProducto=P.IdProducto
 WHERE  YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes AND TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')
 AND TipoRef<>'SERVICIO' AND Lotes=1  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND L.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY IdCia,L.IdProducto,L.IdBodega,NumLote
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvTanques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInvTanques] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16),@pmIdTanque VARCHAR(4)
,@pmSaldoAnt DECIMAL(14,4),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4),@pmCostoAnt MONEY,@pmCostoEnt MONEY,@pmCostoSal MONEY
 AS 
 INSERT INTO AcuInvTanques (nAnno,nMes,IdCia,IdProducto,IdTanque,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdProducto,@pmIdTanque,@pmSaldoAnt,@pmEntradas,@pmSalidas,@pmCostoAnt,@pmCostoEnt,@pmCostoSal)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvTanquesKar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInvTanquesKar] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 INSERT INTO AcuInvTanques (nAnno,nMes,IdCia,IdProducto,IdTanque,Entradas,Salidas,CostoEnt,CostoSal,SaldoAnt,CostoAnt)
 SELECT @pmnAnno,@pmnMes,IdCia,K.IdProducto,CASE WHEN CdTanque IS NULL THEN '0' WHEN LEN(CdTanque)<1 THEN '0' ELSE CdTanque END
,SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal),0,0
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE  YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes AND TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')
 AND TipoRef<>'SERVICIO' AND Tanques=1 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY IdCia,K.IdProducto,CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvUbica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInvUbica] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdUbic VARCHAR(10),@pmSaldoAnt DECIMAL(14,4),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4)
,@pmCostoAnt MONEY,@pmCostoEnt MONEY,@pmCostoSal MONEY
 AS 
 INSERT INTO AcuInvUbica (nAnno,nMes,IdCia,IdProducto,IdUbic,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdProducto,@pmIdUbic,@pmSaldoAnt,@pmEntradas,@pmSalidas
,@pmCostoAnt,@pmCostoEnt,@pmCostoSal)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuInvUbicaKar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuInvUbicaKar] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 INSERT INTO AcuInvUbica (nAnno,nMes,IdCia,IdProducto,IdUbic,Entradas,Salidas,CostoEnt,CostoSal,SaldoAnt,CostoAnt)
 SELECT @pmnAnno,@pmnMes,IdCia,U.IdProducto,U.IdUbic,SUM(Entradas),SUM(Salidas),0,0,0,0
 FROM  Trn_KarUbic AS U INNER JOIN ProdMcias AS P ON U.IdProducto=P.IdProducto
 WHERE  YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes AND TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')
 AND TipoRef<>'SERVICIO' AND Tanques=0 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND U.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY IdCia,U.IdProducto,U.IdUbic
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentas] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuNiifCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentas_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuNiifCuentas AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentas AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentas_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuNiifCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,0,SUM(D.VrDebito),SUM(D.VrCredito)
 FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
 INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='NIIF' AND P.Movimiento<>0
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentas_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentas_Uni] @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuNiifCuentas WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuNiifCuentas (nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuNiifCuentas
  WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAge] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuNiifCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdTercero,@pmCodAgncia,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAge_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.CodAgncia,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuNiifCuentasAge AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentasAge AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.CodAgncia=S.CodAgncia)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Sel]  @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 --nit-veh
  INSERT INTO AcuNiifCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdTercero,D.IdVehiculo,'NV',0,SUM(D.VrDebito),SUM(D.VrCredito)
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='NIIF' AND P.Movimiento=1 AND P.Tercero=1 AND P.Vehiculo=1
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdTercero,D.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Unf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Unf]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuNiifCuentasAge WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuNiifCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdTercero,CodAgncia,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuNiifCuentasAge WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
 GROUP BY nAnno,nMes,IdCia,IdTercero,CodAgncia,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdTercero FROM AcuNiifCuentasAge WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO AcuNiifCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewTercero,CodAgncia,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuNiifCuentasAge WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
 GROUP BY nAnno,nMes,IdCia,IdCuenta,CodAgncia,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAge_Veh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAge_Veh]  @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuNiifCuentasAge WHERE (CodAgncia=@pmIdVehiculo OR CodAgncia=@pmIdVehiculoDos) AND TipoAcum='NV')
  INSERT INTO AcuNiifCuentasAge (nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,@pmNewVehiculo,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuNiifCuentasAge WHERE (CodAgncia=@pmIdVehiculo OR CodAgncia=@pmIdVehiculoDos) AND TipoAcum='NV'
  GROUP BY nAnno,nMes,IdCia,IdCuenta,IdTercero,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAux]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAux] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmnReg INT,@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmSubAuxiliar VARCHAR(16),@pmTipoAcum VARCHAR(4),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY,@pmTipoAfiVehic INT
 AS 
 INSERT INTO AcuNiifCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmnReg,@pmIdCuenta,@pmIdTercero,@pmCodAgncia,@pmIdCCosto,@pmIdSubCos
,@pmSubAuxiliar,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos,@pmTipoAfiVehic)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasAux_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasAux_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(4),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentasAux (nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos,TipoAfiVehic)
 SELECT @pmnAnno,@pmnMes,S.IdCia,0,S.IdCuenta,S.IdTercero,S.CodAgncia,S.IdCCosto,S.IdSubCos,S.SubAuxiliar,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0,S.TipoAfiVehic
 FROM AcuNiifCuentasAux AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentasAux AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes 
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.CodAgncia=S.CodAgncia AND AC.IdCCosto=S.IdCCosto AND AC.IdSubCos=S.IdSubCos
 AND AC.SubAuxiliar=S.SubAuxiliar AND AC.TipoAcum=S.TipoAcum AND AC.TipoAfiVehic=S.TipoAfiVehic)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasCc] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuNiifCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdCCosto,@pmIdSubCos
,@pmTipoAcum,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasCc_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdCCosto,S.IdSubCos,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuNiifCuentasCc AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentasCc AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdCCosto=S.IdCCosto AND AC.IdSubCos=S.IdSubCos)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasCc_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SET @TrnNombre = 'AcuNiifCuentasCc'
  BEGIN TRANSACTION @TrnNombre
  INSERT INTO AcuNiifCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdCCosto,'-1','CC',0,SUM(D.VrDebito),SUM(D.VrCredito)
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='NIIF' AND P.Movimiento=1 AND P.CentroCosto=1
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdCCosto
 --centro de costo-subcentro
  INSERT INTO AcuNiifCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdCCosto,D.IdSubCos,'CS',0,SUM(D.VrDebito),SUM(D.VrCredito)
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='NIIF' AND P.Movimiento=1 AND CentroCosto=1 AND SubCentro=1
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdCCosto,D.IdSubCos
 COMMIT TRANSACTION  @TrnNombre
END
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasCc_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasCc_Uni]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuNiifCuentasCc WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuNiifCuentasCc (nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdCCosto,IdSubCos,TipoAcum,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuNiifCuentasCc WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia,IdCCosto,IdSubCos,TipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasNit] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuNiifCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdTercero,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasNit_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuNiifCuentasNit AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentasNit AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasNit_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuNiifCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdTercero,0,SUM(D.VrDebito),SUM(D.VrCredito)
 FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
 INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='NIIF' AND P.Movimiento=1 AND P.Tercero=1
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_Unf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasNit_Unf]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuNiifCuentasNit WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
  INSERT INTO AcuNiifCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdTercero,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuNiifCuentasNit WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
  GROUP BY nAnno,nMes,IdCia,IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasNit_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasNit_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdTercero FROM AcuNiifCuentasNit WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO AcuNiifCuentasNit (nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos)
  SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewTercero,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  FROM AcuNiifCuentasNit WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
  GROUP BY nAnno,nMes,IdCia,IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasVeh] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY
 AS 
 INSERT INTO AcuNiifCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCuenta,@pmIdVehiculo,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdVehiculo,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuNiifCuentasVeh AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt 
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentasVeh AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes  
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdVehiculo=S.IdVehiculo)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_Sel] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
 INSERT INTO AcuNiifCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT YEAR(D.Fecha),@pmnMes,D.IdCia,D.IdCuenta,D.IdVehiculo,0,SUM(D.VrDebito),SUM(D.VrCredito)
 FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif='NIIF' AND P.Movimiento=1 AND P.Vehiculo=1
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
 GROUP BY  YEAR(D.Fecha),D.IdCia,D.IdCuenta,D.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_Unc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_Unc]  @pmIdCuenta VARCHAR(16),@pmIdCuentaDos VARCHAR(16),@pmNewCuenta VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCuenta FROM AcuNiifCuentasVeh WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos)
   INSERT INTO AcuNiifCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
   SELECT nAnno,nMes,IdCia,@pmNewCuenta,IdVehiculo,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
   FROM AcuNiifCuentasVeh WHERE IdCuenta=@pmIdCuenta OR IdCuenta=@pmIdCuentaDos
   GROUP BY nAnno,nMes,IdCia,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeh_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasVeh_Uni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuNiifCuentasVeh WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
   INSERT INTO AcuNiifCuentasVeh (nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos)
   SELECT nAnno,nMes,IdCia,IdCuenta,@pmNewVehiculo,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
   FROM AcuNiifCuentasVeh WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
   GROUP BY nAnno,nMes,IdCia,IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuNiifCuentasVeht_San]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuNiifCuentasVeht_San] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 INSERT INTO AcuNiifCuentasVeht (nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT @pmnAnno,@pmnMes,S.IdCia,S.IdCuenta,S.IdTercero,S.IdVehiculo,S.TipoAfiVehic,S.TipoAcum,S.SaldoAnterior+S.TotalDebitos-S.TotalCreditos,0,0
 FROM AcuNiifCuentasVeht AS S WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND S.TipoAcum=@pmTipoAcum
 AND NOT EXISTS (SELECT * FROM AcuNiifCuentasVeht AS AC WHERE AC.nAnno=@pmnAnno AND AC.nMes=@pmnMes AND AC.TipoAcum=@pmTipoAcum
 AND AC.IdCia=S.IdCia AND AC.IdCuenta=S.IdCuenta AND AC.IdTercero=S.IdTercero AND AC.IdVehiculo=S.IdVehiculo AND AC.TipoAfiVehic=S.TipoAfiVehic)
 AND (@pmIdCia IS NULL OR S.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR S.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuOrdenes_Nit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuOrdenes_Nit] @pmIdPoseedor VARCHAR(16),@pmIdPoseedorDos VARCHAR(16),@pmNewIdPoseedor VARCHAR(16)
 AS 
 IF EXISTS (SELECT * FROM AcuOrdenes WHERE IdPoseedor=@pmIdPoseedor OR IdPoseedor=@pmIdPoseedorDos)
  INSERT INTO AcuOrdenes (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo,SaldoAnt,VrIngresos,VrCausac)
  SELECT nAnno,nMes,IdCia,@pmNewIdPoseedor,IdVehiculo,SUM(SaldoAnt),SUM(VrIngresos),SUM(VrCausac)
  FROM AcuOrdenes WHERE IdPoseedor=@pmIdPoseedor OR IdPoseedor=@pmIdPoseedorDos
  GROUP BY nAnno,nMes,IdCia,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuOrdenes_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuOrdenes_Uni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 IF EXISTS (SELECT * FROM AcuOrdenes WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
  INSERT INTO AcuOrdenes (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo,SaldoAnt,VrIngresos,VrCausac)
  SELECT nAnno,nMes,IdCia,IdPoseedor,@pmNewVehiculo,SUM(SaldoAnt),SUM(VrIngresos),SUM(VrCausac)
  FROM AcuOrdenes WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
  GROUP BY nAnno,nMes,IdCia,IdPoseedor
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuOrdenesUni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInsAcuOrdenesUni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
AS
IF EXISTS (SELECT * FROM AcuOrdenes WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
 INSERT INTO AcuOrdenes (nAnno,nMes,IdCia,IdPoseedor,IdVehiculo,SaldoAnt,VrIngresos,VrCausac)
 SELECT nAnno,nMes,IdCia,IdPoseedor,@pmNewVehiculo,SUM(SaldoAnt),SUM(VrIngresos),SUM(VrCausac)
 FROM AcuOrdenes WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
 GROUP BY nAnno,nMes,IdCia,IdPoseedor
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuPrestamos] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmSaldoAnt MONEY
,@pmPrestamos MONEY,@pmDevPrestamos MONEY,@pmRecibos MONEY,@pmDevRecibos MONEY,@pmNotasDeb MONEY,@pmNotasCre MONEY
,@pmFacturas MONEY,@pmDevFacturas MONEY
 AS 
 INSERT INTO AcuPrestamos (nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Prestamos,DevPrestamos,Recibos,DevRecibos,NotasDeb,NotasCre,Facturas,DevFacturas)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCliente,@pmIdAgencia,@pmSaldoAnt,@pmPrestamos,@pmDevPrestamos,@pmRecibos,@pmDevRecibos,@pmNotasDeb,@pmNotasCre,@pmFacturas,@pmDevFacturas)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamos_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAcuPrestamos_Uni] @pmIdCliente VARCHAR(16),@pmIdClienteDos VARCHAR(16),@pmNewCliente VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdCliente FROM AcuPrestamos WHERE IdCliente=@pmIdCliente OR IdCliente=@pmIdClienteDos)
  INSERT INTO AcuPrestamos (nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Prestamos,DevPrestamos,Recibos,DevRecibos,NotasDeb,NotasCre,Facturas,DevFacturas)
 SELECT nAnno,nMes,IdCia,@pmNewCliente,IdAgencia,SUM(SaldoAnt),SUM(Prestamos),SUM(DevPrestamos),SUM(Recibos),SUM(DevRecibos),SUM(NotasDeb)
,SUM(NotasCre),SUM(Facturas),SUM(DevFacturas)
 FROM AcuPrestamos WHERE IdCliente=@pmIdCliente OR IdCliente=@pmIdClienteDos
  GROUP BY  nAnno,nMes,IdCia,IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamosCau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuPrestamosCau]  @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 INSERT INTO AcuPrestamos (nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Prestamos,DevPrestamos,Recibos,DevRecibos,NotasDeb,NotasCre,Facturas,DevFacturas)
 SELECT YEAR(CASE WHEN C.TipDoc='PR1' AND C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END)
,MONTH(CASE WHEN C.TipDoc='PR1' AND C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END)
,C.IdCia,C.IdCliente,C.IdAgencia,0,SUM(CASE C.TipDoc WHEN 'PR1' THEN C.VrTotal ELSE 0 END),0,0,0
 ,SUM(CASE C.TipDoc WHEN 'ND2' THEN C.VrTotal ELSE 0 END),0,SUM(CASE C.TipDoc WHEN 'FIF' THEN C.VrTotal ELSE 0 END),0
 FROM Trn_FinCuotas AS C LEFT JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc  AND C.IdPrestamo=P.IdPrestamo AND C.IdCia=P.IdCia
 WHERE C.TipDoc IN ('PR1','ND2','FIF')  AND YEAR(CASE WHEN C.TipDoc='PR1' AND C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END)=@pmnAnno
 AND MONTH(CASE WHEN C.TipDoc='PR1' AND C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END)=@pmnMes 
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY YEAR(CASE WHEN C.TipDoc='PR1' AND C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END)
 ,MONTH(CASE WHEN C.TipDoc='PR1' AND C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END)
 ,C.IdCia,C.IdCliente,C.IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamosLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuPrestamosLin] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4),@pmConcepto VARCHAR(10),@pmSaldoAnt MONEY,@pmTotalCargos MONEY,@pmTotalAbonos MONEY
,@pmPrestamos MONEY,@pmDevPrestamos MONEY,@pmRecibos MONEY,@pmDevRecibos MONEY,@pmNotasDeb MONEY,@pmNotasCre MONEY,@pmFacturas MONEY
,@pmDevFacturas MONEY,@pmOtrosAbonos MONEY,@pmDevAportes MONEY,@pmSaAportes MONEY
 AS 
 INSERT INTO AcuPrestamosLin (nAnno,nMes,IdCia,IdCliente,IdAgencia,IdLinea,Concepto,SaldoAnt,TotalCargos,TotalAbonos
,Prestamos,DevPrestamos,Recibos,DevRecibos,NotasDeb,NotasCre,Facturas,DevFacturas,OtrosAbonos,DevAportes,SaAportes)
 VALUES (@pmnAnno,@pmnMes,@pmIdCia,@pmIdCliente,@pmIdAgencia,@pmIdLinea,@pmConcepto,@pmSaldoAnt,@pmTotalCargos,@pmTotalAbonos
,@pmPrestamos,@pmDevPrestamos,@pmRecibos,@pmDevRecibos,@pmNotasDeb,@pmNotasCre,@pmFacturas,@pmDevFacturas,@pmOtrosAbonos,@pmDevAportes,@pmSaAportes)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPrestamosLinCau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAcuPrestamosLinCau] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
AS 
INSERT INTO AcuPrestamosLin (nAnno,nMes,IdCia,IdCliente,IdAgencia,IdLinea,Concepto,SaldoAnt,TotalCargos,TotalAbonos
,Prestamos,DevPrestamos,Recibos,DevRecibos,NotasDeb,NotasCre,Facturas,DevFacturas,OtrosAbonos,DevAportes,SaAportes)
SELECT YEAR(Fecha),MONTH(Fecha),IdCia,IdCliente,IdAgencia,ISNULL(CodLinCred,'0001'),Concepto,0,SUM(VrTotal),0
,SUM(CASE WHEN TipDoc IN ('PR1','CVN','APO') THEN VrTotal ELSE 0 END),0,0,0
,SUM(CASE WHEN TipDoc='ND2' THEN VrTotal ELSE 0 END),0
,SUM(CASE WHEN TipDoc='FIF' THEN VrTotal ELSE 0 END),0,0,0,0
FROM Trn_FinCuotas
WHERE (TipDoc IN ('ND2','FIF','CVN','APO') OR (TipDoc='PR1' AND Concepto<>'CAPITAL'))
AND YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes 
AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
GROUP BY YEAR(Fecha),MONTH(Fecha),IdCia,IdCliente,IdAgencia,CodLinCred,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPropietarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInsAcuPropietarios] @pmIdReg INT,@pmIdPropietario VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4), @pmIdCia CHAR(2)
,@pmnMes INT, @pmnAnno INT,@pmSaldoAnterior MONEY, @pmTotalDebitos MONEY, @pmTotalCreditos MONEY
AS
 INSERT INTO AcuPropietarios (nAnno,IdReg,nMes,IdPropietario,IdVehiculo,IdClase,IdCia,SaldoAnterior,TotalDebitos,TotalCreditos)
 VALUES (@pmnAnno,@pmIdReg,@pmnMes,@pmIdPropietario,@pmIdVehiculo,@pmIdClase,@pmIdCia,@pmSaldoAnterior
,@pmTotalDebitos,@pmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInsAcuPropietariosUni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInsAcuPropietariosUni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
AS
IF EXISTS (SELECT * FROM AcuPropietarios WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
 INSERT INTO AcuPropietarios (nAnno,IdReg,nMes,IdPropietario,IdVehiculo,IdClase,IdCia,SaldoAnterior,TotalDebitos,TotalCreditos)
 SELECT nAnno,MAX(IdReg),nMes,IdPropietario,@pmNewVehiculo,IdClase,IdCia,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
 FROM AcuPropietarios WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
 GROUP BY nAnno,nMes,IdPropietario,IdClase,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsAduanas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAduanas] @pmIdAduana VARCHAR(4),@pmNomAduana VARCHAR(150),@pmIdPais VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO Aduanas (IdAduana,NomAduana,IdPais,Inactivo)
 VALUES (@pmIdAduana,@pmNomAduana,@pmIdPais,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfAmortiza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfAmortiza] @pmNumero INT,@pmFecha SMALLDATETIME,@pmEstado INT
,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCia CHAR(2)
 AS 
 INSERT INTO Trn_AfAmortiza (Numero,Fecha,Estado,IdUsuario,FechaCrea,IdCia)
 VALUES (@pmNumero,@pmFecha,@pmEstado,@pmIdUsuario,@pmFechaCrea,@pmIdCia)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfAmtComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfAmtComp] @pmNumero INT,@pmIdCia CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmTipoCompNiif VARCHAR(3),@pmNumCompNiif INT,@pmTipoCompFis VARCHAR(3),@pmNumCompFis INT
 AS 
 INSERT INTO Trn_AfAmtComp (Numero,IdCia,TipCom,Comprobante,TipoCompNiif,NumCompNiif,TipoCompFis,NumCompFis)
 VALUES (@pmNumero,@pmIdCia,@pmTipCom,@pmComprobante,@pmTipoCompNiif,@pmNumCompNiif,@pmTipoCompFis,@pmNumCompFis)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfAmtDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfAmtDetalle] @pmNumero INT,@pmItem INT,@pmIdDiferido VARCHAR(30),@pmValorTotal MONEY,@pmVrAdiciones MONEY
,@pmVrDisminucion MONEY,@pmVrAcuAjustes MONEY,@pmVrAmortizaHis MONEY,@pmVrAmortizaMes MONEY,@pmVrAjustesInf MONEY
,@pmVrAjustesAmtza MONEY,@pmVrAmtzaHisAcum MONEY,@pmVrAmortizaAcum MONEY,@pmVrAjuAmtzaAcum MONEY,@pmVrCorrMonAcum MONEY
,@pmVrBaseCorrMon MONEY,@pmVrCorrMonDif MONEY,@pmTarifaAju DECIMAL(14,4),@pmIdCia CHAR(2),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16)
,@pmCdDep VARCHAR(4),@pmNitRespons VARCHAR(16),@pmFecInicioAmtza SMALLDATETIME,@pmNPeriodos INT
,@pmCuotaGal DECIMAL(14,4),@pmVentaGal DECIMAL(14,4),@pmVrInversion MONEY,@pmCdGrupoDif VARCHAR(4),@pmCantCuotasIni INT
 AS 
 INSERT INTO Trn_AfAmtDetalle (Numero,Item,IdDiferido,ValorTotal,VrAdiciones,VrDisminucion,VrAcuAjustes,VrAmortizaHis,VrAmortizaMes,VrAjustesInf,VrAjustesAmtza
,VrAmtzaHisAcum,VrAmortizaAcum,VrAjuAmtzaAcum,VrCorrMonAcum,VrBaseCorrMon,VrCorrMonDif,TarifaAju,IdCia,CdCCosto,CdSubCos,CdDep,NitRespons,FecInicioAmtza,NPeriodos,CuotaGal,VentaGal,VrInversion,CdGrupoDif,CantCuotasIni)
 VALUES (@pmNumero,@pmItem,@pmIdDiferido,@pmValorTotal,@pmVrAdiciones,@pmVrDisminucion,@pmVrAcuAjustes,@pmVrAmortizaHis,@pmVrAmortizaMes
,@pmVrAjustesInf,@pmVrAjustesAmtza,@pmVrAmtzaHisAcum,@pmVrAmortizaAcum,@pmVrAjuAmtzaAcum,@pmVrCorrMonAcum,@pmVrBaseCorrMon,@pmVrCorrMonDif,@pmTarifaAju
,@pmIdCia,@pmCdCCosto,@pmCdSubCos,@pmCdDep,@pmNitRespons,@pmFecInicioAmtza,@pmNPeriodos,@pmCuotaGal,@pmVentaGal,@pmVrInversion,@pmCdGrupoDif,@pmCantCuotasIni)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfCausales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfCausales] @pmIdCausal VARCHAR(4),@pmCausal VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO AfCausales (IdCausal,Causal,Inactivo)
 VALUES (@pmIdCausal,@pmCausal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfClasesCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfClasesCue] @pmIdClase VARCHAR(4),@pmClaseCue VARCHAR(50),@pmConcepto VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO AfClasesCue (IdClase,ClaseCue,Concepto,Inactivo)
 VALUES (@pmIdClase,@pmClaseCue,@pmConcepto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDeprecCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfDeprecCom] @pmNumero INT,@pmIdCia CHAR(2),@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmTipComAju VARCHAR(3),@pmCompAjustes INT
,@pmTipoCompNiif VARCHAR(3),@pmNumCompNiif INT,@pmTipoCompFis VARCHAR(3),@pmNumCompFis INT
 AS 
 INSERT INTO Trn_AfDeprecCom (Numero,IdCia,TipCom,Comprobante,TipComAju,CompAjustes,TipoCompNiif,NumCompNiif,TipoCompFis,NumCompFis)
 VALUES (@pmNumero,@pmIdCia,@pmTipCom,@pmComprobante,@pmTipComAju,@pmCompAjustes,@pmTipoCompNiif,@pmNumCompNiif,@pmTipoCompFis,@pmNumCompFis)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDeprecia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfDeprecia] @pmNumero INT,@pmFecha SMALLDATETIME
,@pmEstado INT,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCia CHAR(2)
 AS 
 INSERT INTO Trn_AfDeprecia (Numero,Fecha,Estado,IdUsuario,FechaCrea,IdCia)
 VALUES (@pmNumero,@pmFecha,@pmEstado,@pmIdUsuario,@pmFechaCrea,@pmIdCia)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfDetalle] @pmNumero INT,@pmItem INT,@pmIdActivo VARCHAR(30),@pmVrCostoIni MONEY,@pmVrMejoras MONEY,@pmVrDisminucion MONEY,@pmVrAcuAjustes MONEY,@pmVrDepreciaHis MONEY,@pmVrDepreciaMes MONEY
,@pmVrAjustesInf MONEY,@pmVrAjustesDep MONEY,@pmVrDepreciaAcum MONEY,@pmVrAjuDepAcum MONEY,@pmTarifaAju DECIMAL(14,4),@pmIdCia CHAR(2),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmCdInstala VARCHAR(4)
,@pmCdDep VARCHAR(4),@pmNitRespons VARCHAR(16),@pmFecIniDep SMALLDATETIME,@pmMesesVida INT,@pmMetodoDeprec VARCHAR(10),@pmCdGrupoAct VARCHAR(4),@pmVrSalvamnto MONEY,@pmUnidades INT,@pmCantidad INT,@pmDep_Partes BIT,@pmCantMeses INT
 AS 
 INSERT INTO Trn_AfDetalle (Numero,Item,IdActivo,VrCostoIni,VrMejoras,VrDisminucion,VrAcuAjustes,VrDepreciaHis,VrDepreciaMes,VrAjustesInf,VrAjustesDep,VrDepreciaAcum,VrAjuDepAcum,TarifaAju,IdCia,CdCCosto,CdSubCos,CdInstala,CdDep,NitRespons
,FecIniDep,MesesVida,MetodoDeprec,CdGrupoAct,VrSalvamnto,Unidades,Cantidad,Dep_Partes,CantMeses)
 VALUES (@pmNumero,@pmItem,@pmIdActivo,@pmVrCostoIni,@pmVrMejoras,@pmVrDisminucion,@pmVrAcuAjustes,@pmVrDepreciaHis,@pmVrDepreciaMes,@pmVrAjustesInf,@pmVrAjustesDep,@pmVrDepreciaAcum,@pmVrAjuDepAcum
,@pmTarifaAju,@pmIdCia,@pmCdCCosto,@pmCdSubCos,@pmCdInstala,@pmCdDep,@pmNitRespons,@pmFecIniDep,@pmMesesVida,@pmMetodoDeprec,@pmCdGrupoAct,@pmVrSalvamnto,@pmUnidades,@pmCantidad,@pmDep_Partes,@pmCantMeses)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfDifIngreso] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdDiferido VARCHAR(30)
,@pmFecActivacion SMALLDATETIME,@pmNumPeriodos INT,@pmVrBase MONEY,@pmVrMejoras MONEY,@pmVrDisminucion MONEY
,@pmVrAjuInfAcum MONEY,@pmVrAmortizaHis MONEY,@pmVrAmortizaAju MONEY,@pmVrAjuInfAmtza MONEY,@pmNumMesesAmtza INT
,@pmVrCorrMonDif MONEY,@pmNumMesesCorr INT,@pmFecUltAmtza SMALLDATETIME,@pmConcepto VARCHAR(150)
 AS 
 INSERT INTO Trn_AfDifIngreso (IdMov,Numero,IdCia,Item,IdDiferido,FecActivacion,NumPeriodos,VrBase,VrMejoras,VrDisminucion
,VrAjuInfAcum,VrAmortizaHis,VrAmortizaAju,VrAjuInfAmtza,NumMesesAmtza,VrCorrMonDif,NumMesesCorr,FecUltAmtza,Concepto)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdDiferido,@pmFecActivacion,@pmNumPeriodos,@pmVrBase
,@pmVrMejoras,@pmVrDisminucion,@pmVrAjuInfAcum,@pmVrAmortizaHis,@pmVrAmortizaAju,@pmVrAjuInfAmtza,@pmNumMesesAmtza
,@pmVrCorrMonDif,@pmNumMesesCorr,@pmFecUltAmtza,@pmConcepto)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifMovi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfDifMovi] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME
,@pmAnulado BIT,@pmObservacion VARCHAR(250),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmFecCreacion SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_AfDifMovi (IdMov,Numero,IdCia,Fecha,Anulado,Observacion,TipCom,Comprobante,IdCiaCom,FecCreacion,IdUsuario)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmFecha,@pmAnulado,@pmObservacion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmFecCreacion,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifRetiro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfDifRetiro] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdDiferido VARCHAR(30),@pmIdCausal VARCHAR(4)
,@pmVrCostoIni MONEY,@pmVrAdiciones MONEY,@pmVrDisminucion MONEY,@pmVrAcuAjustes MONEY,@pmVrAmortizaAcum MONEY,@pmVrAjuAmtzaAcum MONEY
,@pmFechaRet SMALLDATETIME,@pmConcepto VARCHAR(250)
 AS 
 INSERT INTO Trn_AfDifRetiro (IdMov,Numero,IdCia,Item,IdDiferido,IdCausal,VrCostoIni,VrAdiciones,VrDisminucion,VrAcuAjustes,VrAmortizaAcum,VrAjuAmtzaAcum,FechaRet,Concepto)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdDiferido,@pmIdCausal,@pmVrCostoIni,@pmVrAdiciones,@pmVrDisminucion,@pmVrAcuAjustes,@pmVrAmortizaAcum,@pmVrAjuAmtzaAcum,@pmFechaRet,@pmConcepto)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfDifTraslado] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdDiferido VARCHAR(30),@pmIdGrupo VARCHAR(4),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmIdDep VARCHAR(4),@pmIdRespons VARCHAR(16),@pmUbicacion VARCHAR(150),@pmCdCiaDest CHAR(2),@pmCdGrupoDest VARCHAR(4),@pmCdCCostoDest VARCHAR(16)
,@pmCdSubCosDest VARCHAR(16),@pmCdDepDest VARCHAR(4),@pmCdResponsDest VARCHAR(16),@pmUbicacionDest VARCHAR(150),@pmConcepto VARCHAR(150)
 AS 
 INSERT INTO Trn_AfDifTraslado (IdMov,Numero,IdCia,Item,IdDiferido,IdGrupo,IdCCosto,IdSubCos,IdDep,IdRespons,Ubicacion,CdCiaDest,CdGrupoDest,CdCCostoDest,CdSubCosDest,CdDepDest,CdResponsDest,UbicacionDest,Concepto)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdDiferido,@pmIdGrupo,@pmIdCCosto,@pmIdSubCos,@pmIdDep,@pmIdRespons,@pmUbicacion,@pmCdCiaDest,@pmCdGrupoDest,@pmCdCCostoDest
,@pmCdSubCosDest,@pmCdDepDest,@pmCdResponsDest,@pmUbicacionDest,@pmConcepto)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfDifValoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfDifValoriza] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT
,@pmIdDiferido VARCHAR(30),@pmConcepto VARCHAR(250),@pmValor MONEY,@pmNitProvee VARCHAR(16)
 AS 
 INSERT INTO Trn_AfDifValoriza (IdMov,Numero,IdCia,Item,IdDiferido,Concepto,Valor,NitProvee)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdDiferido,@pmConcepto,@pmValor,@pmNitProvee)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO AfEstados (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfGrupos] @pmIdGrupo VARCHAR(4),@pmGrupo VARCHAR(50),@pmIdLinea VARCHAR(4),@pmVidaUtil INT,@pmInactivo BIT
 AS 
 INSERT INTO AfGrupos (IdGrupo,Grupo,IdLinea,VidaUtil,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupo,@pmIdLinea,@pmVidaUtil,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfGruposCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfGruposCue] @pmIdGrupo VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCuenta VARCHAR(16)
 AS 
 INSERT INTO AfGruposCue (IdGrupo,IdClase,IdCuenta)
 VALUES (@pmIdGrupo,@pmIdClase,@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfLineas] @pmIdLinea VARCHAR(4),@pmLinea VARCHAR(50),@pmVidaUtil INT,@pmTarfDep DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO AfLineas (IdLinea,Linea,VidaUtil,TarfDep,Inactivo)
 VALUES (@pmIdLinea,@pmLinea,@pmVidaUtil,@pmTarfDep,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMantnmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfMantnmto] @pmIdCia CHAR(2),@pmIdActivo VARCHAR(30),@pmFecha SMALLDATETIME,@pmNumContrato VARCHAR(20)
,@pmNitEmpresa VARCHAR(16),@pmNomEmpresa VARCHAR(150),@pmFinContrato BIT,@pmIdUsuario VARCHAR(11),@pmDiagnostico VARCHAR(2000),@pmComentarios VARCHAR(4000)
,@pmIdMtto VARCHAR(4),@pmVrMantnmto MONEY 
 AS 
 INSERT INTO Trn_AfMantnmto (IdCia,IdActivo,Fecha,NumContrato,NitEmpresa,NomEmpresa,FinContrato,IdUsuario,Diagnostico,Comentarios,IdMtto,VrMantnmto)
 VALUES (@pmIdCia,@pmIdActivo,@pmFecha,@pmNumContrato,@pmNitEmpresa,@pmNomEmpresa,@pmFinContrato,@pmIdUsuario,@pmDiagnostico,@pmComentarios,@pmIdMtto,@pmVrMantnmto)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovimiento]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfMovimiento] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmDocumento VARCHAR(20)
,@pmAnulado BIT,@pmObservacion VARCHAR(250),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmTipoCompNiif VARCHAR(3),@pmNumCompNiif INT
,@pmTipoCompFis VARCHAR(3),@pmNumCompFis INT,@pmFecCreacion SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_AfMovimiento (IdMov,Numero,IdCia,Fecha,Documento,Anulado,Observacion,TipCom,Comprobante,IdCiaCom,FecCreacion,IdUsuario,TipoCompNiif,NumCompNiif,TipoCompFis,NumCompFis)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmFecha,@pmDocumento,@pmAnulado,@pmObservacion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmFecCreacion,@pmIdUsuario,@pmTipoCompNiif,@pmNumCompNiif,@pmTipoCompFis,@pmNumCompFis)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfMovIngreso] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdActivo VARCHAR(30)
,@pmFecActivacion SMALLDATETIME,@pmVrMejoras MONEY,@pmVrDisminucion MONEY,@pmVrAjuInfAcum MONEY,@pmVrDepAcuHis MONEY
,@pmVrDepAcuAju MONEY,@pmVrAjuInfDep MONEY,@pmNumMesesDep INT,@pmFecUltDep SMALLDATETIME,@pmConcepto VARCHAR(150),@pmNumParte INT,@pmCantidad INT
 AS 
 INSERT INTO Trn_AfMovIngreso (IdMov,Numero,IdCia,Item,IdActivo,FecActivacion,VrMejoras,VrDisminucion,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep,FecUltDep,Concepto,NumParte,Cantidad)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdActivo,@pmFecActivacion,@pmVrMejoras,@pmVrDisminucion,@pmVrAjuInfAcum,@pmVrDepAcuHis,@pmVrDepAcuAju
,@pmVrAjuInfDep,@pmNumMesesDep,@pmFecUltDep,@pmConcepto,@pmNumParte,@pmCantidad)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovRetiro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfMovRetiro] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdActivo VARCHAR(30),@pmIdCausal VARCHAR(4)
,@pmNitTercero VARCHAR(16),@pmNomTercero VARCHAR(150),@pmVrCostoIni MONEY,@pmVrMejoras MONEY,@pmVrDisminucion MONEY,@pmVrAcuAjustes MONEY
,@pmVrDepAcum MONEY,@pmVrAjuDepAcum MONEY,@pmVrIngreso MONEY,@pmFechaRet SMALLDATETIME,@pmIdCueDeb VARCHAR(16),@pmIdCueIng VARCHAR(16),@pmConcepto VARCHAR(250),@pmNumParte INT
 AS 
 INSERT INTO Trn_AfMovRetiro (IdMov,Numero,IdCia,Item,IdActivo,IdCausal,NitTercero,NomTercero,VrCostoIni,VrMejoras,VrDisminucion,VrAcuAjustes,VrDepAcum,VrAjuDepAcum,VrIngreso,FechaRet,IdCueDeb,IdCueIng,Concepto,NumParte)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdActivo,@pmIdCausal,@pmNitTercero,@pmNomTercero,@pmVrCostoIni,@pmVrMejoras,@pmVrDisminucion,@pmVrAcuAjustes
,@pmVrDepAcum,@pmVrAjuDepAcum,@pmVrIngreso,@pmFechaRet,@pmIdCueDeb,@pmIdCueIng,@pmConcepto,@pmNumParte)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfMovTraslado] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdActivo VARCHAR(30),@pmIdGrupo VARCHAR(4)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdInstala VARCHAR(4),@pmIdDep VARCHAR(4),@pmIdRespons VARCHAR(16),@pmCdCiaDest CHAR(2)
,@pmCdGrupoDest VARCHAR(4),@pmCdCCostoDest VARCHAR(16),@pmCdSubCosDest VARCHAR(16),@pmCdInstalaDest VARCHAR(4),@pmCdDepDest VARCHAR(4)
,@pmCdResponsDest VARCHAR(16),@pmConcepto VARCHAR(150),@pmUbicacion VARCHAR(100),@pmUbicacionDest VARCHAR(100)
 AS 
 INSERT INTO Trn_AfMovTraslado (IdMov,Numero,IdCia,Item,IdActivo,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,CdCiaDest,CdGrupoDest,CdCCostoDest
,CdSubCosDest,CdInstalaDest,CdDepDest,CdResponsDest,Concepto,Ubicacion,UbicacionDest)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdActivo,@pmIdGrupo,@pmIdCCosto,@pmIdSubCos,@pmIdInstala,@pmIdDep,@pmIdRespons,@pmCdCiaDest
,@pmCdGrupoDest,@pmCdCCostoDest,@pmCdSubCosDest,@pmCdInstalaDest,@pmCdDepDest,@pmCdResponsDest,@pmConcepto,@pmUbicacion,@pmUbicacionDest)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfMovValoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfMovValoriza] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmIdActivo VARCHAR(30),@pmConcepto VARCHAR(250),@pmValor MONEY
,@pmNitProvee VARCHAR(16),@pmFecAdquis SMALLDATETIME,@pmNumDocmto VARCHAR(20),@pmDescripParte VARCHAR(150),@pmNum_Parte INT
 AS 
 INSERT INTO Trn_AfMovValoriza (IdMov,Numero,IdCia,Item,IdActivo,Concepto,Valor,NitProvee,FecAdquis,NumDocmto,DescripParte,Num_Parte)
 VALUES (@pmIdMov,@pmNumero,@pmIdCia,@pmItem,@pmIdActivo,@pmConcepto,@pmValor,@pmNitProvee,@pmFecAdquis,@pmNumDocmto,@pmDescripParte,@pmNum_Parte)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfPartes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfPartes] @pmNumero INT,@pmItem INT,@pmIdActivo VARCHAR(30),@pmIdParte INT,@pmVrBaseDep MONEY,@pmVrCostoIni MONEY,@pmVrMejoras MONEY,@pmVrDisminuc MONEY,@pmVrAcumAju MONEY,@pmVrDepAcum MONEY,@pmVrDeprecia MONEY
,@pmVrDepHis MONEY,@pmVrAjusteInf MONEY,@pmVrAjuDeprec MONEY,@pmVrAcumAjuDep MONEY,@pmVrSalvamnto MONEY,@pmUnidades INT,@pmCantidad INT,@pmFecIniDep SMALLDATETIME,@pmVida_Util INT,@pmMetDeprec VARCHAR(10),@pmCantCuoIni INT
 AS 
 INSERT INTO Trn_AfPartes (Numero,Item,IdActivo,IdParte,VrBaseDep,VrCostoIni,VrMejoras,VrDisminuc,VrAcumAju,VrDepAcum,VrDeprecia,VrDepHis,VrAjusteInf,VrAjuDeprec,VrAcumAjuDep,VrSalvamnto,Unidades,Cantidad,FecIniDep,Vida_Util,MetDeprec,CantCuoIni)
 VALUES (@pmNumero,@pmItem,@pmIdActivo,@pmIdParte,@pmVrBaseDep,@pmVrCostoIni,@pmVrMejoras,@pmVrDisminuc,@pmVrAcumAju,@pmVrDepAcum,@pmVrDeprecia,@pmVrDepHis,@pmVrAjusteInf,@pmVrAjuDeprec,@pmVrAcumAjuDep,@pmVrSalvamnto,@pmUnidades
,@pmCantidad,@pmFecIniDep,@pmVida_Util,@pmMetDeprec,@pmCantCuoIni)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfPignora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfPignora] @pmIdActivo VARCHAR(30),@pmFecha SMALLDATETIME,@pmTipoAccion VARCHAR(10),@pmNomTercero VARCHAR(150)
,@pmComentarios VARCHAR(150),@pmGarantia VARCHAR(150),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_AfPignora (IdActivo,Fecha,TipoAccion,NomTercero,Comentarios,Garantia,IdUsuario)
 VALUES (@pmIdActivo,@pmFecha,@pmTipoAccion,@pmNomTercero,@pmComentarios,@pmGarantia,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfTiposDif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAfTiposDif] @pmIdTipDif VARCHAR(4),@pmTipoDiferido VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO AfTiposDif (IdTipDif,TipoDiferido,Inactivo)
 VALUES (@pmIdTipDif,@pmTipoDiferido,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAfTiposMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAfTiposMov] @pmIdMov VARCHAR(4),@pmTipoMov VARCHAR(50),@pmConsecutivo INT,@pmInactivo BIT
 AS 
 INSERT INTO AfTiposMov (IdMov,TipoMov,Consecutivo,Inactivo)
 VALUES (@pmIdMov,@pmTipoMov,@pmConsecutivo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAgencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAgencias] @pmIdAgencia VARCHAR(16),@pmCodAgencia VARCHAR(16),@pmIdClie VARCHAR(16),@pmAgencia VARCHAR(150),@pmDirAgncia VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelAgncia VARCHAR(20),@pmFaxAgncia VARCHAR(20),@pmNitCont VARCHAR(16)
,@pmNomCont VARCHAR(150),@pmemlCont VARCHAR(100),@pmCargoCont VARCHAR(50),@pmIdSzona VARCHAR(4),@pmIdPlazo VARCHAR(4),@pmCdPlazoComb VARCHAR(4),@pmIdForma VARCHAR(4),@pmCdBandera VARCHAR(4),@pmIdVend VARCHAR(16),@pmCdCms VARCHAR(4),@pmCdDct VARCHAR(4),@pmIntMora DECIMAL(14,4)
,@pmDiasGracia INT,@pmFactFletes BIT,@pmFactSold BIT,@pmVrCupoCre MONEY,@pmVrSaldoAct MONEY,@pmFecUpCupo SMALLDATETIME,@pmNContrato INT,@pmCiaCont CHAR(2),@pmFecIngreso SMALLDATETIME,@pmReferencia VARCHAR(50),@pmComentarios VARCHAR(250),@pmCupoGalones DECIMAL(14,4)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTipoZona VARCHAR(10),@pmCodSicom VARCHAR(20),@pmCdTipAgenc VARCHAR(4),@pmCdSubAgenc VARCHAR(4),@pmCdGrupAgenc VARCHAR(4), @pmCdSubGrupAgenc VARCHAR(4), @pmCdFntePago VARCHAR(4), @pmPlazoSobtasa VARCHAR(20)
,@pmDocFinanc VARCHAR(3), @pmVolContMes DECIMAL(14,4), @pmVolContTotal DECIMAL(14,4), @pmVolViabMes DECIMAL(14,4),@pmVolViabTotal DECIMAL(14,4), @pmFecPriVenta SMALLDATETIME, @pmInvCtbObra MONEY, @pmInvCtbCapital MONEY, @pmInvCtbEfectivo MONEY, @pmInvCtbImagen MONEY, @pmInvCtbMntmto MONEY
,@pmFecDesemb SMALLDATETIME, @pmInvContObra MONEY, @pmInvContCapital MONEY, @pmInvContEfectivo MONEY, @pmInvContImagen MONEY, @pmCrtlAprovInv INT, @pmCrtlAprovImg INT,@pmFecVigCond SMALLDATETIME,@pmTasaIntArranq DECIMAL(14,4),@pmAgencOperando BIT
,@pmTipoFactFletes INT,@pmCdCCBonif VARCHAR(16),@pmCdSubCCBonif VARCHAR(16),@pmCodRuta VARCHAR(4),@pmCodDiaEnt VARCHAR(4),@pmCdGruClie VARCHAR(4),@pmCupoElectcom DECIMAL(14,4),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Agencias (IdAgencia,CodAgencia,IdClie,Agencia,DirAgncia,IdLocal,TelAgncia,FaxAgncia,NitCont,NomCont,emlCont,CargoCont,IdSzona,IdPlazo,CdPlazoComb,IdForma,CdBandera,IdVend,CdCms,CdDct,IntMora,DiasGracia,FactFletes,FactSold,VrCupoCre,VrSaldoAct,FecUpCupo,NContrato,CiaCont,CodSicom,FecIngreso,Referencia,Comentarios
,CupoGalones,TipoZona,IdEstado,Inactivo,FechaAdd,IdUsuario,CdTipAgenc, CdSubAgenc, CdGrupAgenc, CdSubGrupAgenc, CdFntePago, PlazoSobtasa, DocFinanc, VolContMes, VolContTotal, VolViabMes,VolViabTotal, FecPriVenta, InvCtbObra, InvCtbCapital, InvCtbEfectivo, InvCtbImagen, InvCtbMntmto, FecDesemb, InvContObra, InvContCapital
,InvContEfectivo, InvContImagen, CrtlAprovInv, CrtlAprovImg,FecVigCond,TasaIntArranq,AgencOperando,TipoFactFletes,CdCCBonif,CdSubCCBonif,CodRuta,CodDiaEnt,CdGruClie,CupoElectcom)
 VALUES (@pmIdAgencia,@pmCodAgencia,@pmIdClie,@pmAgencia,@pmDirAgncia,@pmIdLocal,@pmTelAgncia,@pmFaxAgncia,@pmNitCont,@pmNomCont,@pmemlCont,@pmCargoCont,@pmIdSzona,@pmIdPlazo,@pmCdPlazoComb,@pmIdForma,@pmCdBandera,@pmIdVend
,@pmCdCms,@pmCdDct,@pmIntMora,@pmDiasGracia,@pmFactFletes,@pmFactSold,@pmVrCupoCre,@pmVrSaldoAct,@pmFecUpCupo,@pmNContrato,@pmCiaCont,@pmCodSicom,@pmFecIngreso,@pmReferencia,@pmComentarios,@pmCupoGalones,@pmTipoZona,@pmIdEstado,@pmInactivo,@pmFechaAdd,@pmIdUsuario
,@pmCdTipAgenc, @pmCdSubAgenc,@pmCdGrupAgenc,@pmCdSubGrupAgenc,@pmCdFntePago,@pmPlazoSobtasa,@pmDocFinanc,@pmVolContMes,@pmVolContTotal,@pmVolViabMes,@pmVolViabTotal,@pmFecPriVenta
,@pmInvCtbObra, @pmInvCtbCapital,@pmInvCtbEfectivo,@pmInvCtbImagen,@pmInvCtbMntmto,@pmFecDesemb,@pmInvContObra,@pmInvContCapital,@pmInvContEfectivo,@pmInvContImagen,@pmCrtlAprovInv,@pmCrtlAprovImg,@pmFecVigCond,@pmTasaIntArranq,@pmAgencOperando,@pmTipoFactFletes,@pmCdCCBonif,@pmCdSubCCBonif,@pmCodRuta,@pmCodDiaEnt,@pmCdGruClie,@pmCupoElectcom)
GO
/****** Object:  StoredProcedure [dbo].[paInsAjuInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAjuInv] @pmTipDoc VARCHAR(3),@pmAjuste INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16)
,@pmVrSubTotal MONEY,@pmCantidad DECIMAL(14,4),@pmBaseAjuInf MONEY,@pmTarifPaag DECIMAL(14,4),@pmNumDcmto INT,@pmNumOrden INT,@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_AjuInv (TipDoc,Ajuste,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,Cantidad,BaseAjuInf,TarifPaag,NumDcmto,NumOrden,IdCCosto,IdSubCos,Modalidad,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmAjuste,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdTercero,@pmVrSubTotal,@pmCantidad,@pmBaseAjuInf,@pmTarifPaag,@pmNumDcmto,@pmNumOrden
,@pmIdCCosto,@pmIdSubCos,@pmModalidad,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsAlmBodegas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAlmBodegas] @pmIdBodega VARCHAR(4),@pmBodega VARCHAR(100),@pmDireccion VARCHAR(100),@pmTelBodega VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO AlmBodegas (IdBodega,Bodega,Direccion,TelBodega,Inactivo)
 VALUES (@pmIdBodega,@pmBodega,@pmDireccion,@pmTelBodega,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAprobacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsAprobacion] @pmTipDoc VARCHAR(3),@pmAprobacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipoPed VARCHAR(3)
,@pmPedido INT,@pmIdCiaPed CHAR(2),@pmFecPedido SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmpVehiculo VARCHAR(10)
,@pmVrCupoCred MONEY,@pmVrSaldoAct MONEY,@pmChequesDev BIT,@pmClienteMora BIT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Aprobacion (TipDoc,Aprobacion,IdCia,Fecha,TipoPed,Pedido,IdCiaPed,FecPedido,IdCliente,IdAgencia,pVehiculo,VrCupoCred,VrSaldoAct,ChequesDev,ClienteMora
,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmAprobacion,@pmIdCia,@pmFecha,@pmTipoPed,@pmPedido,@pmIdCiaPed,@pmFecPedido,@pmIdCliente,@pmIdAgencia,@pmpVehiculo
,@pmVrCupoCred,@pmVrSaldoAct,@pmChequesDev,@pmClienteMora,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsAreas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAreas] @pmIdArea VARCHAR(4),@pmArea VARCHAR(50),@pmJefeArea VARCHAR(50)
,@pmIdCCosto VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO Areas (IdArea,Area,JefeArea,IdCCosto,Inactivo)
 VALUES (@pmIdArea,@pmArea,@pmJefeArea,@pmIdCCosto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsAutoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsAutoriza] @pmTipAut VARCHAR(3),@pmAutoriza INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNumAutoriza INT,@pmIdUsuarioAut VARCHAR(11)
,@pmIdEstacion CHAR(2),@pmNitTercero VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmTipoDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFechaDoc SMALLDATETIME,@pmDocRef INT
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrAprobado MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Autoriza (TipAut,Autoriza,IdCia,Fecha,IdConcepto,NumAutoriza,IdUsuarioAut,IdEstacion,NitTercero,pVehiculo,TipoDoc,Documento,IdCiaDoc,FechaDoc,DocRef,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrAprobado)
 VALUES (@pmTipAut,@pmAutoriza,@pmIdCia,@pmFecha,@pmIdConcepto,@pmNumAutoriza,@pmIdUsuarioAut,@pmIdEstacion,@pmNitTercero,@pmpVehiculo,@pmTipoDoc,@pmDocumento,@pmIdCiaDoc,@pmFechaDoc,@pmDocRef,@pmOrigenAdd
,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrAprobado)
GO
/****** Object:  StoredProcedure [dbo].[paInsBancos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsBancos] @pmIdBanco VARCHAR(4),@pmBanco VARCHAR(50),@pmIdClase VARCHAR(4),@pmCodEntidad VARCHAR(20)
,@pmDireccion VARCHAR(50),@pmContacto VARCHAR(50),@pmComision DECIMAL(10,4),@pmInactivo BIT
 AS 
 INSERT INTO Bancos (IdBanco,Banco,IdClase,CodEntidad,Direccion,Contacto,Comision,Inactivo)
 VALUES (@pmIdBanco,@pmBanco,@pmIdClase,@pmCodEntidad,@pmDireccion,@pmContacto,@pmComision,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsBodegas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsBodegas] @pmIdBodega VARCHAR(4),@pmBodega VARCHAR(50),@pmDescrip VARCHAR(100)
,@pmLtaPre CHAR(1),@pmTipoInv VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Bodegas (IdBodega,Bodega,Descrip,LtaPre,TipoInv,Inactivo)
 VALUES (@pmIdBodega,@pmBodega,@pmDescrip,@pmLtaPre,@pmTipoInv,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsBodUbic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsBodUbic] @pmIdUbic VARCHAR(10),@pmUbicacion VARCHAR(50),@pmIdBodega VARCHAR(4),@pmPasillo VARCHAR(10),@pmNivel VARCHAR(10),@pmProfdad VARCHAR(10)
,@pmDimAltura DECIMAL(14,4),@pmDimAnch DECIMAL(14,4),@pmDimLong DECIMAL(14,4),@pmCapcVolm DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmCapcPeso DECIMAL(14,4),@pmUndPes VARCHAR(10)
,@pmCdTmcia VARCHAR(4),@pmCdMnjo VARCHAR(4),@pmNotas VARCHAR(250),@pmInactivo BIT
 AS 
 INSERT INTO BodUbic (IdUbic,Ubicacion,IdBodega,Pasillo,Nivel,Profdad,DimAltura,DimAnch,DimLong,CapcVolm,UndCapc,CapcPeso,UndPes,CdTmcia,CdMnjo,Notas,Inactivo)
 VALUES (@pmIdUbic,@pmUbicacion,@pmIdBodega,@pmPasillo,@pmNivel,@pmProfdad,@pmDimAltura,@pmDimAnch,@pmDimLong,@pmCapcVolm,@pmUndCapc,@pmCapcPeso
,@pmUndPes,@pmCdTmcia,@pmCdMnjo,@pmNotas,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsBusClaseCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsBusClaseCue] @pmIdClase VARCHAR(4),@pmClaseCuenta VARCHAR(50),@pmPrioridad INT,@pmInactivo BIT
 AS 
 INSERT INTO BusClaseCue (IdClase,ClaseCuenta,Prioridad,Inactivo)
 VALUES (@pmIdClase,@pmClaseCuenta,@pmPrioridad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsCalndario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsCalndario] @pmFechaDia SMALLDATETIME,@pmTipoFtvo VARCHAR(3)
 AS 
 INSERT INTO Calndario (FechaDia,TipoFtvo)
 VALUES (@pmFechaDia,@pmTipoFtvo)
GO
/****** Object:  StoredProcedure [dbo].[paInsCargos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCargos] @pmIdCargo VARCHAR(4),@pmCargo VARCHAR(50),@pmFunciones VARCHAR(3000),@pmInactivo BIT
 AS 
 INSERT INTO Cargos (IdCargo,Cargo,Funciones,Inactivo)
 VALUES (@pmIdCargo,@pmCargo,@pmFunciones,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCausacion] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmFactura VARCHAR(15),@pmIdProveedor VARCHAR(16),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmReferencia VARCHAR(20),@pmModalidad VARCHAR(10),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY
,@pmValorDcto MONEY,@pmValorIva MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorFletes MONEY,@pmValorNeto MONEY,@pmValorCCobrar MONEY,@pmBaseIva MONEY,@pmBaseRet MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmIdTarIva VARCHAR(4),@pmIdTarRet VARCHAR(4),@pmIdTarIca VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4)
,@pmCxPagar BIT,@pmCxcVarios BIT,@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCierreCte BIT,@pmIndFactura INT,@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Causacion (TipDoc,Documento,IdCia,Fecha,IdConcepto,Factura,IdProveedor,FecFactura,FecVence,Referencia,Modalidad,IdVehiculo,IdPropietario,IdConductor,VehPropio,ValorTotal,ValorDcto,ValorIva,ValorReteFte,ValorReteIva,ValorReteIca,ValorOtros,ValorFletes,ValorNeto,ValorCCobrar,BaseIva,BaseRet,TarifaIva,TarifaRet,TarifaIca,IdTarIva,IdTarRet,IdTarIca,MulPlazos,IdPlazo,CxPagar,CxcVarios,TipEgr,Egreso,IdCiaEgr,Anulado,NumDev,FecDev,TipCom,Comprobante,IdCiaCom
,Observacion,IdEstado,CierreCte,TimeSys,IdCiaCrea,IdUsuario,IndFactura)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmFecha,@pmIdConcepto,@pmFactura,@pmIdProveedor,@pmFecFactura,@pmFecVence,@pmReferencia,@pmModalidad,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmVehPropio,@pmValorTotal,@pmValorDcto,@pmValorIva,@pmValorReteFte,@pmValorReteIva,@pmValorReteIca,@pmValorOtros,@pmValorFletes,@pmValorNeto,@pmValorCCobrar,@pmBaseIva,@pmBaseRet,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmIdTarIva,@pmIdTarRet,@pmIdTarIca,@pmMulPlazos
,@pmIdPlazo,@pmCxPagar,@pmCxcVarios,@pmTipEgr,@pmEgreso,@pmIdCiaEgr,@pmAnulado,@pmNumDev,@pmFecDev,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmCierreCte,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmIndFactura)
GO
/****** Object:  StoredProcedure [dbo].[paInsCausacVence]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCausacVence] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecEmision SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmValorFactura MONEY,@pmValorAbono MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmVehPropio BIT,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4)
,@pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdConcepto VARCHAR(4),@pmFecUltPago SMALLDATETIME,@pmNotaInt INT,@pmFecUltLiquida SMALLDATETIME,@pmFactura VARCHAR(15),@pmReferencia VARCHAR(20),@pmDetalle VARCHAR(100),@pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCiaRec CHAR(2),@pmValorAtcpo MONEY,@pmIdCuenta VARCHAR(16),@pmCombCant DECIMAL(14,4),@pmCombValor MONEY
,@pmBaseImpu MONEY,@pmTarifa_Iva DECIMAL(14,4),@pmVrIva MONEY,@pmTarifa_Ret DECIMAL(14,4),@pmVrRetFte MONEY,@pmTarifa_Ica DECIMAL(14,4),@pmVrRetIca MONEY,@pmCodTarifIva VARCHAR(4),@pmCodTarifRet VARCHAR(4),@pmCodTarifIca VARCHAR(4),@pmTipDocFac VARCHAR(3),@pmNumDocFac INT,@pmCdCiaFac CHAR(2)
 AS 
 INSERT INTO Trn_CausacVence (TipDoc,Documento,IdCia,Item,FecEmision,FecVence,ValorFactura,ValorAbono,IdCliente,IdAgencia,IdVehiculo,VehPropio,IdVendedor,Comision,IdCargo,IdClase,IdConcepto,FecUltPago,NotaInt,FecUltLiquida,Factura,Referencia,Detalle,TipRec,Recibo,IdCiaRec,ValorAtcpo,IdCuenta,CombCant,CombValor
,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca,CodTarifIva,CodTarifRet,CodTarifIca,TipDocFac,NumDocFac,CdCiaFac)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecEmision,@pmFecVence,@pmValorFactura,@pmValorAbono,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmVehPropio,@pmIdVendedor,@pmComision,@pmIdCargo,@pmIdClase,@pmIdConcepto,@pmFecUltPago,@pmNotaInt,@pmFecUltLiquida,@pmFactura,@pmReferencia,@pmDetalle,@pmTipRec
,@pmRecibo,@pmIdCiaRec,@pmValorAtcpo,@pmIdCuenta,@pmCombCant,@pmCombValor,@pmBaseImpu,@pmTarifa_Iva,@pmVrIva,@pmTarifa_Ret,@pmVrRetFte,@pmTarifa_Ica,@pmVrRetIca,@pmCodTarifIva,@pmCodTarifRet,@pmCodTarifIca,@pmTipDocFac,@pmNumDocFac,@pmCdCiaFac)
GO
/****** Object:  StoredProcedure [dbo].[paInsCausaVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCausaVales] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY
,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmIdVend VARCHAR(16)
,@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_CausaVales (TipDoc,Documento,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,TarifaIva,TarifaRet,TarifaIca,CodTarIva,CodTarRet,CodTarIca,IdVend,TarifaCom,CodTarCom,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado
,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFechaVence,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCargos,@pmVrOtrDcto,@pmVrCostos,@pmVrNeto,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca
,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCodTarArf,@pmTarifaArf,@pmVrAutRetFte,@pmCodTarAri,@pmTarifaAri,@pmVrAutRetIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsCentroCosto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsCentroCosto] @pmIdCCosto VARCHAR(16),@pmCCosto VARCHAR(100),@pmCodCias VARCHAR(500),@pmFechaAdd SMALLDATETIME
,@pmInactivo BIT
 AS 
 INSERT INTO CentroCosto (IdCCosto,CCosto,FechaAdd,Inactivo,CodCias)
 VALUES (@pmIdCCosto,@pmCCosto,@pmFechaAdd,@pmInactivo,@pmCodCias)
GO
/****** Object:  StoredProcedure [dbo].[paInsCentrosServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsCentrosServ] @pmIdCenSer VARCHAR(4),@pmCentroServ VARCHAR(50),@pmDirCentro VARCHAR(100)
,@pmIdLocal VARCHAR(8),@pmTelefonos VARCHAR(30),@pmTipoCentro VARCHAR(10),@pmNitResp VARCHAR(16)
,@pmRespnsable VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO CentrosServ (IdCenSer,CentroServ,DirCentro,IdLocal,Telefonos,TipoCentro,NitResp,Respnsable,Inactivo)
 VALUES (@pmIdCenSer,@pmCentroServ,@pmDirCentro,@pmIdLocal,@pmTelefonos,@pmTipoCentro,@pmNitResp,@pmRespnsable,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsCheques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCheques] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmVrForma MONEY,@pmCtaForma VARCHAR(30),@pmBeneficiario VARCHAR(150),@pmReferncia1 VARCHAR(50)
,@pmReferncia2 VARCHAR(50),@pmDetalle VARCHAR(150),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmCdVend VARCHAR(16),@pmIdLocal VARCHAR(8),@pmTipRec VARCHAR(3),@pmRecibo INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmTipCon VARCHAR(3),@pmNumConsig INT,@pmIdCiaCon CHAR(2),@pmFecConsig SMALLDATETIME,@pmCdCta VARCHAR(4),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Cheques (TipForma,Numero,IdBanco,IdCia,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle,NitCliente,CdAgencia,CdVend,IdLocal,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,Anulado,FecDev,IdEstado,IdCiaCrea,IdUsuario)
 VALUES (@pmTipForma,@pmNumero,@pmIdBanco,@pmIdCia,@pmFecha,@pmFecPago,@pmVrForma,@pmCtaForma,@pmBeneficiario,@pmReferncia1,@pmReferncia2,@pmDetalle,@pmNitCliente,@pmCdAgencia,@pmCdVend,@pmIdLocal,@pmTipRec,@pmRecibo,@pmTipDoc,@pmDocumento,@pmIdCiaDoc
,@pmFecDoc,@pmTipCon,@pmNumConsig,@pmIdCiaCon,@pmFecConsig,@pmCdCta,@pmAnulado,@pmFecDev,@pmIdEstado,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseBan] @pmIdClase VARCHAR(4),@pmClaseBanco VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseBan (IdClase,ClaseBanco,Inactivo)
 VALUES (@pmIdClase,@pmClaseBanco,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseCapac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseCapac] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO ClaseCapac (IdClase,NomClase,Inactivo)
 VALUES (@pmIdClase,@pmNomClase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseCta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseCta] @pmIdClase VARCHAR(4),@pmClaseCuenta VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseCta (IdClase,ClaseCuenta,Inactivo)
 VALUES (@pmIdClase,@pmClaseCuenta,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseDiv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsClaseDiv] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseDiv (IdClase,NomClase,Inactivo)
 VALUES (@pmIdClase,@pmNomClase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseDocCond]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseDocCond] @pmIdDoc VARCHAR(4),@pmDocumento VARCHAR(150),@pmVigencia BIT,@pmInactivo BIT
 AS 
 INSERT INTO ClaseDocCond (IdDoc,Documento,Vigencia,Inactivo)
 VALUES (@pmIdDoc,@pmDocumento,@pmVigencia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseFon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsClaseFon] @pmIdClase VARCHAR(4),@pmClaseFondo VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseFon (IdClase,ClaseFondo,Inactivo)
 VALUES (@pmIdClase,@pmClaseFondo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClasePol]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsClasePol] @pmIdClase VARCHAR(4),@pmClasePoliza VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClasePol (IdClase,ClasePoliza,Inactivo)
 VALUES (@pmIdClase,@pmClasePoliza,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseRie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseRie] @pmIdClase VARCHAR(4),@pmClaseRiesgo VARCHAR(50),@pmTarifa DECIMAL(10,4),@pmInactivo BIT
,@pmCodClase VARCHAR(4)
 AS 
 INSERT INTO ClaseRie (IdClase,ClaseRiesgo,Tarifa,Inactivo,CodClase)
 VALUES (@pmIdClase,@pmClaseRiesgo,@pmTarifa,@pmInactivo,@pmCodClase)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseSub] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseSub (IdClase,NomClase,Inactivo)
 VALUES (@pmIdClase,@pmNomClase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClaseTar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClaseTar] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ClaseTar (IdClase,NomClase,Inactivo)
 VALUES (@pmIdClase,@pmNomClase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsClieContado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsClieContado] @pmIdCliente VARCHAR(16),@pmNombre VARCHAR(150),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmDireccion VARCHAR(150)
,@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmemail VARCHAR(100),@pmExcento BIT,@pmPosIniNom INT,@pmInactivo BIT,@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO ClieContado (IdCliente,Nombre,TipoId,Dv,Direccion,IdLocal,Telefono,email,Excento,PosIniNom,Inactivo,FechaAdd)
 VALUES (@pmIdCliente,@pmNombre,@pmTipoId,@pmDv,@pmDireccion,@pmIdLocal,@pmTelefono,@pmemail,@pmExcento,@pmPosIniNom,@pmInactivo,@pmFechaAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsCnxextna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCnxextna] @pmIdReg INT,@pmCnxEngine VARCHAR(10),@pmCnxDso VARCHAR(250),@pmCnxDbname VARCHAR(50),@pmCnxAutentic VARCHAR(3)
,@pmCnxUid VARCHAR(50),@pmCnxPwd VARCHAR(50),@pmCnxOwner VARCHAR(20),@pmCnxObserv VARCHAR(250),@pmCnxTipo VARCHAR(10),@pmCnxPpties VARCHAR(250)
,@pmCnxDriver VARCHAR(100),@pmCnxPort VARCHAR(30),@pmCnxTerminal VARCHAR(4)
 AS 
 INSERT INTO Sys_Cnxextna (IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxPpties,CnxObserv,CnxDriver,CnxPort,CnxTerminal)
 VALUES (@pmIdReg,@pmCnxTipo,@pmCnxEngine,@pmCnxDso,@pmCnxDbname,@pmCnxAutentic,@pmCnxUid,@pmCnxPwd,@pmCnxOwner,@pmCnxPpties,@pmCnxObserv,@pmCnxDriver,@pmCnxPort,@pmCnxTerminal)
GO
/****** Object:  StoredProcedure [dbo].[paInsComDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsComDetalle] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmVehPropio INT,@pmVrBase MONEY,@pmTarifaBase DECIMAL(10,4),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4),@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmReferncia VARCHAR(50)
,@pmNitDoc VARCHAR(16),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11),@pmCdConcTrib VARCHAR(4),@pmCdTarifTrib VARCHAR(4),@pmNumEstablec VARCHAR(20),@pmPtoEmision VARCHAR(20),@pmNum_Autoriza VARCHAR(50),@pmFechAutoriza SMALLDATETIME,@pmCdCuentaNiif VARCHAR(16)
 AS 
 INSERT INTO Trn_ComDetalle (TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,IdSubCos,CodAgncia,Referncia,NitDoc
,TipDocRef,DocRef,IdCiaRef,TimeSys,IdCiaCrea,IdUsuario,CdConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza,CdCuentaNiif)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmIdCuenta,@pmDetalle,@pmVrDebito,@pmVrCredito,@pmIdTercero,@pmIdVehiculo,@pmIdCCosto,@pmVehPropio,@pmVrBase,@pmTarifaBase,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmCodConce,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmCodCta,@pmNumCheque,@pmIntegrado,@pmTipoAplica,@pmConsolida,@pmCodCargo
,@pmNitOtros,@pmCodSubgpo,@pmCiuOrigen,@pmIdSubCos,@pmCodAgncia,@pmReferncia,@pmNitDoc,@pmTipDocRef,@pmDocRef,@pmIdCiaRef,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCdConcTrib,@pmCdTarifTrib,@pmNumEstablec,@pmPtoEmision,@pmNum_Autoriza,@pmFechAutoriza,@pmCdCuentaNiif)
GO
/****** Object:  StoredProcedure [dbo].[paInsComFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsComFactura] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmItem INT,@pmIdProveedor VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecEmision SMALLDATETIME
,@pmFecVence SMALLDATETIME,@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmItemCom INT,@pmReferencia VARCHAR(50),@pmDetalle VARCHAR(100),@pmpVehiculo VARCHAR(10),@pmVehPropio BIT
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmEstadoApr INT,@pmMontoAprob MONEY,@pmFecProgPago SMALLDATETIME,@pmObservAprob VARCHAR(250)
 AS 
 INSERT INTO Trn_ComFactura (TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob,FecProgPago,ObservAprob)
 VALUES (@pmTipFac,@pmFactura,@pmIdCia,@pmItem,@pmIdProveedor,@pmIdCuenta,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmFecEmision,@pmFecVence,@pmVrFactura,@pmVrAbonado,@pmTipCom,@pmComprobante,@pmItemCom
,@pmReferencia,@pmDetalle,@pmpVehiculo,@pmVehPropio,@pmTipRef,@pmDocRef,@pmIdCiaRef,@pmEstadoApr,@pmMontoAprob,@pmFecProgPago,@pmObservAprob)
GO
/****** Object:  StoredProcedure [dbo].[paInsComFactura_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsComFactura_Uni] @pmIdProveedor VARCHAR(16),@pmNewProveedor VARCHAR(16)
 AS 
 INSERT INTO Trn_ComFactura (TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob,FecProgPago,ObservAprob)
 SELECT TipFac,Factura,IdCia,Item,@pmNewProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob,FecProgPago,ObservAprob
 FROM Trn_ComFactura WHERE IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paInsCompanias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCompanias] @pmIdCia CHAR(2),@pmCompania VARCHAR(50),@pmDirInterface VARCHAR(255),@pmFechaActual SMALLDATETIME
,@pmPeriodoActual SMALLDATETIME,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdTercero VARCHAR(16)
,@pmCodSucsal VARCHAR(10),@pmDireccSuc VARCHAR(250),@pmTelefSuc VARCHAR(20),@pmFaxSuc VARCHAR(20),@pmIdLocal VARCHAR(8),@pmTipoEDS VARCHAR(10)
,@pmCodPlanta VARCHAR(20),@pmCodBodega VARCHAR(4),@pmFecModPrest SMALLDATETIME,@pmAutoIca BIT,@pmFechaAdd SMALLDATETIME,@pmInactivo BIT
 AS 
 INSERT INTO Companias (IdCia,Compania,DirInterface,FechaActual,PeriodoActual,IdCCosto,IdSubCos,IdTercero
,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,TipoEDS,CodPlanta,FechaAdd,Inactivo,CodBodega,FecModPrest,AutoIca)
 VALUES (@pmIdCia,@pmCompania,@pmDirInterface,@pmFechaActual,@pmPeriodoActual,@pmIdCCosto,@pmIdSubCos,@pmIdTercero
,@pmCodSucsal,@pmDireccSuc,@pmTelefSuc,@pmFaxSuc,@pmIdLocal,@pmTipoEDS,@pmCodPlanta,@pmFechaAdd,@pmInactivo,@pmCodBodega,@pmFecModPrest,@pmAutoIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsCompCaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCompCaja] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTotal MONEY
,@pmVrTotDebito MONEY,@pmVrTotCredito MONEY,@pmEnEfectivo BIT,@pmCdCta VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdCajero VARCHAR(11),@pmNumForma VARCHAR(20),@pmCdBanco VARCHAR(4),@pmReferencia VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
,@pmNumVehiculo VARCHAR(10),@pmFacCalidad INT,@pmSemInicial INT,@pmSemFinal INT
 AS 
 INSERT INTO Trn_CompCaja (TipDoc,Recibo,IdCia,Fecha,IdConcepto,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,CdCta,IdTercero,CdAgencia,IdCCosto,IdSubCos,IdCajero,NumForma,CdBanco,Referencia
,NumVehiculo,FacCalidad,SemInicial,SemFinal,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmIdConcepto,@pmVrEfectivo,@pmVrOtros,@pmVrTotal,@pmVrTotDebito,@pmVrTotCredito,@pmEnEfectivo,@pmCdCta,@pmIdTercero,@pmCdAgencia,@pmIdCCosto
,@pmIdSubCos,@pmIdCajero,@pmNumForma,@pmCdBanco,@pmReferencia,@pmNumVehiculo,@pmFacCalidad,@pmSemInicial,@pmSemFinal,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsCompCajaDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsCompCajaDet] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250)
,@pmVrDebito MONEY,@pmVrCredito MONEY,@pmNitTercero VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmVrBase MONEY
,@pmTarifaBase DECIMAL(14,4),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME
,@pmCodCta VARCHAR(4),@pmNumCheque VARCHAR(20),@pmTipoAplica CHAR(1),@pmNitOtros VARCHAR(16),@pmCodAgencia VARCHAR(16),@pmReferncia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
,@pmDocSop BIT,@pmTipSop VARCHAR(3),@pmNumSoporte INT,@pmIdCiaSop CHAR(2),@pmTipoImp VARCHAR(4),@pmCodTarImp VARCHAR(4),@pmItemBase INT,@pmConcAsociado INT
 AS 
 INSERT INTO Trn_CompCajaDet (TipDoc,Recibo,IdCia,Item,IdConcepto,IdCuenta,Detalle,VrDebito,VrCredito,NitTercero,pVehiculo,CdCCosto,CdSubCos,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence
,CodCta,NumCheque,TipoAplica,NitOtros,CodAgencia,Referncia,TipDocRef,DocRef,IdCiaRef,DocSop,TipSop,NumSoporte,IdCiaSop,TipoImp,CodTarImp,ItemBase,ConcAsociado)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmItem,@pmIdConcepto,@pmIdCuenta,@pmDetalle,@pmVrDebito,@pmVrCredito,@pmNitTercero,@pmpVehiculo,@pmCdCCosto,@pmCdSubCos,@pmVrBase
,@pmTarifaBase,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmCodCta,@pmNumCheque,@pmTipoAplica,@pmNitOtros,@pmCodAgencia,@pmReferncia,@pmTipDocRef,@pmDocRef,@pmIdCiaRef
,@pmDocSop,@pmTipSop,@pmNumSoporte,@pmIdCiaSop,@pmTipoImp,@pmCodTarImp,@pmItemBase,@pmConcAsociado)
GO
/****** Object:  StoredProcedure [dbo].[paInsCompGastos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCompGastos] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdPlantilla VARCHAR(4),@pmIdTercero VARCHAR(16),@pmTipFact VARCHAR(3)
,@pmFactura VARCHAR(15),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrTotal MONEY,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_CompGastos (TipCom,Comprobante,IdCia,Fecha,IdPlantilla,IdTercero,TipFact,Factura,FecFactura,FecVence,VrTotal,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmFecha,@pmIdPlantilla,@pmIdTercero,@pmTipFact,@pmFactura,@pmFecFactura,@pmFecVence,@pmVrTotal,@pmAnulado,@pmFecDev,@pmObservacion
,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsComprobantes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsComprobantes] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrTotal MONEY,@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmTipEgr VARCHAR(3),@pmNEgreso INT,@pmpVehiculo VARCHAR(10),@pmVehPropio INT,@pmCedCondtor VARCHAR(16),@pmCodConce VARCHAR(4),@pmBeneficiario VARCHAR(150),@pmVrDivisa1 MONEY,@pmVrDivisa2 MONEY,@pmVrDivisa3 MONEY, @pmPermEditar BIT,@pmIntegrado BIT,@pmEsEgreso BIT,@pmAnticipo BIT,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmCdSustento VARCHAR(4),@pmTipo_Pago VARCHAR(10),@pmEstablec VARCHAR(20),@pmPEmision VARCHAR(20),@pmAutorizac VARCHAR(50),@pmFechaAut SMALLDATETIME,@pmNiifTipo VARCHAR(3),@pmNiifNumero INT,@pmFisTipo VARCHAR(3),@pmFisNumero INT,@pmDocSoporte INT,@pmCodRes VARCHAR(4),@pmDescServicio VARCHAR(500)
,@pmPropddes VARCHAR(50),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Comprobantes (TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,PermEditar,Integrado,EsEgreso,Anticipo,VrDivisa1,VrDivisa2,VrDivisa3,Observacion,IdEstado,Propddes
,TimeSys,IdCiaCrea,IdUsuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,NiifTipo,NiifNumero,FisTipo,FisNumero,DocSoporte,CodRes,DescServicio)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmFecha,@pmIdTercero,@pmVrTotal,@pmIdCta,@pmEnEfectivo,@pmNumCheque,@pmFecCheque,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmAnulado,@pmNumDev,@pmFecDev,@pmTipEgr,@pmNEgreso,@pmpVehiculo,@pmVehPropio,@pmCedCondtor,@pmCodConce,@pmBeneficiario,@pmPermEditar,@pmIntegrado,@pmEsEgreso
,@pmAnticipo,@pmVrDivisa1,@pmVrDivisa2,@pmVrDivisa3,@pmObservacion,@pmIdEstado,@pmPropddes,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCdSustento,@pmTipo_Pago,@pmEstablec,@pmPEmision,@pmAutorizac,@pmFechaAut,@pmNiifTipo,@pmNiifNumero,@pmFisTipo,@pmFisNumero,@pmDocSoporte,@pmCodRes,@pmDescServicio)
GO
/****** Object:  StoredProcedure [dbo].[paInsConcDivCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsConcDivCue] @pmIdConcepto VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmCdCueDev VARCHAR(16)
,@pmTipoMov CHAR(1),@pmTipoTerc CHAR(1),@pmFecAdd SMALLDATETIME
 AS 
 INSERT INTO ConcDivCue (IdConcepto,IdClase,IdCuenta,CdCueDev,TipoMov,TipoTerc,FecAdd)
 VALUES (@pmIdConcepto,@pmIdClase,@pmIdCuenta,@pmCdCueDev,@pmTipoMov,@pmTipoTerc,@pmFecAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsConcDiversos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConcDiversos] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmGrupo VARCHAR(20),@pmEsServicio BIT,@pmDeManfsto BIT,@pmCdIva VARCHAR(4)
,@pmCdRet VARCHAR(4),@pmCdIca VARCHAR(4),@pmIdCueDeb VARCHAR(16),@pmIdCueCre VARCHAR(16),@pmInactivo BIT
,@pmCdAutoret VARCHAR(4),@pmOrdenServ INT,@pmNovedadNom BIT,@pmCdConcDeveng VARCHAR(4),@pmCdConcDed VARCHAR(4),@pmRubroConc VARCHAR(50),@pmMudReajuste BIT,@pmCodFEDian VARCHAR(20),@pmTipoConcGat INT
,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO ConcDiversos (IdConcepto,Concepto,Grupo,EsServicio,DeManfsto,CdIva,CdRet,CdIca,CdAutoret,IdCueDeb,IdCueCre,Inactivo,FechaAdd,IdUsuario,OrdenServ,NovedadNom,CdConcDeveng,CdConcDed,RubroConc,MudReajuste,CodFEDian,TipoConcGat)
 VALUES (@pmIdConcepto,@pmConcepto,@pmGrupo,@pmEsServicio,@pmDeManfsto,@pmCdIva,@pmCdRet,@pmCdIca,@pmCdAutoret,@pmIdCueDeb,@pmIdCueCre,@pmInactivo,@pmFechaAdd
,@pmIdUsuario,@pmOrdenServ,@pmNovedadNom,@pmCdConcDeveng,@pmCdConcDed,@pmRubroConc,@pmMudReajuste,@pmCodFEDian,@pmTipoConcGat)
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConceptos] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(100),@pmIdDoc VARCHAR(3),@pmIdCom VARCHAR(3),@pmVcmto BIT,@pmImptos BIT
,@pmRetfte BIT,@pmRetIca BIT,@pmObservacion VARCHAR(150),@pmPdterminado INT,@pmTrfaSanc DECIMAL(14,4),@pmRndTotal INT,@pmDcmtoEquiv BIT
,@pmInactivo BIT,@pmTipoContab VARCHAR(10),@pmCdComNiif VARCHAR(3),@pmCdComFiscal VARCHAR(3),@pmCodCiaTdo CHAR(2),@pmTipoConRev INT
,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Conceptos (IdConcepto,Concepto,IdDoc,IdCom,Vcmto,Imptos,Retfte,RetIca,Observacion,Pdterminado,TrfaSanc,RndTotal,DcmtoEquiv
,Inactivo,FechaAdd,IdUsuario,TipoContab,CdComNiif,CdComFiscal,CodCiaTdo,TipoConRev)
 VALUES (@pmIdConcepto,@pmConcepto,@pmIdDoc,@pmIdCom,@pmVcmto,@pmImptos,@pmRetfte,@pmRetIca,@pmObservacion,@pmPdterminado,@pmTrfaSanc
,@pmRndTotal,@pmDcmtoEquiv,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmTipoContab,@pmCdComNiif,@pmCdComFiscal,@pmCodCiaTdo,@pmTipoConRev)
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptosAdmon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConceptosAdmon] @pmIdConcepto VARCHAR(4),@pmIdAdmon VARCHAR(4),@pmIdClase INT
,@pmIdCuenta VARCHAR(16),@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO ConceptosAdmon (IdConcepto,IdAdmon,IdClase,IdCuenta,FechaAdd)
 VALUES (@pmIdConcepto,@pmIdAdmon,@pmIdClase,@pmIdCuenta,@pmFechaAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptosCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConceptosCue] @pmIdConcepto VARCHAR(4),@pmIdClase INT,@pmDescripcion VARCHAR(50),@pmIdCuenta VARCHAR(16),@pmTipoMov CHAR(1)
,@pmDetalleMov VARCHAR(150),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipoTerc CHAR(1),@pmFecAdd SMALLDATETIME
 AS 
 INSERT INTO ConceptosCue (IdConcepto,IdClase,Descripcion,IdCuenta,TipoMov,DetalleMov,CdCCosto,CdSubCos,TipoTerc,FecAdd)
 VALUES (@pmIdConcepto,@pmIdClase,@pmDescripcion,@pmIdCuenta,@pmTipoMov,@pmDetalleMov,@pmCdCCosto,@pmCdSubCos,@pmTipoTerc,@pmFecAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsConceptosTrib]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConceptosTrib] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmCodigoConc VARCHAR(10)
,@pmIdClase VARCHAR(4),@pmCdTarifa VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO ConceptosTrib (IdConcepto,Concepto,CodigoConc,IdClase,CdTarifa,Inactivo)
 VALUES (@pmIdConcepto,@pmConcepto,@pmCodigoConc,@pmIdClase,@pmCdTarifa,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsConsigna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConsigna] @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTotal MONEY,@pmEnEfectivo BIT,@pmIdCta VARCHAR(4)
,@pmIdCuenta VARCHAR(16),@pmIdCliente VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmNitDeptante VARCHAR(16),@pmDepositante VARCHAR(150),@pmTelDeptante VARCHAR(20),@pmReferencia VARCHAR(50)
,@pmReferncia2 VARCHAR(50),@pmNumConsigna VARCHAR(20),@pmRangosDoc VARCHAR(100),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecConsig SMALLDATETIME,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Consigna (TipDoc,Consignacion,IdCia,Fecha,IdConcepto,VrEfectivo,VrOtros,VrTotal,EnEfectivo,IdCta,IdCuenta,IdCliente,IdCCosto,IdSubCos,IdCajero,NitDeptante,Depositante,TelDeptante,Referencia,Referncia2,NumConsigna,RangosDoc,FecConsig,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmConsignacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmVrEfectivo,@pmVrOtros,@pmVrTotal,@pmEnEfectivo,@pmIdCta,@pmIdCuenta,@pmIdCliente,@pmIdCCosto,@pmIdSubCos,@pmIdCajero,@pmNitDeptante,@pmDepositante
,@pmTelDeptante,@pmReferencia,@pmReferncia2,@pmNumConsigna,@pmRangosDoc,@pmFecConsig,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsCorrResiduos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCorrResiduos] @pmIdCorr VARCHAR(8),@pmGrupoRP VARCHAR(4),@pmCodigoCR VARCHAR(10),@pmCorrResiduo VARCHAR(500),@pmInactivo BIT
 AS 
 INSERT INTO CorrResiduos (IdCorr,GrupoRP,CodigoCR,CorrResiduo,Inactivo)
 VALUES (@pmIdCorr,@pmGrupoRP,@pmCodigoCR,@pmCorrResiduo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsCotizacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCotizacion] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY
,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmDirContacto VARCHAR(250),@pmIdLocal VARCHAR(8),@pmDiasVigencia INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150)
,@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargoContac VARCHAR(50),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(250),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmModalidad VARCHAR(10),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4),@pmNumPedido INT,@pmCdCiaPed CHAR(2),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Cotizacion (TipDoc,Cotizacion,IdCia,Fecha,FechaVence,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,IdVend,TarifaCom,CodTarCom,DirContacto,IdLocal,DiasVigencia,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney
,TipFac,Factura,IdCiaFac,FechaFact,Modalidad,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,NumAprob,FecAprob,CdUsuAprob,NumPedido,CdCiaPed,VrImpuBA,VrImpuCUP,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmCotizacion,@pmIdCia,@pmFecha,@pmFechaVence,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrFletes,@pmVrOtros,@pmVrOtrDcto,@pmVrNeto,@pmCantidad,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmDirContacto,@pmIdLocal,@pmDiasVigencia,@pmNitContac
,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargoContac,@pmIdForma,@pmDetallePago,@pmMulPlazos,@pmIdPlazo,@pmCdMney,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFact,@pmModalidad,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmNumAprob,@pmFecAprob,@pmCdUsuAprob,@pmNumPedido,@pmCdCiaPed,@pmVrImpuBA,@pmVrImpuCUP,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsCtasCorrientes]    Script Date: 10/12/2025 8:11:24 ******/
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
/****** Object:  StoredProcedure [dbo].[paInsDepartamentos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDepartamentos] @pmIdDep VARCHAR(8),@pmDepartamento VARCHAR(50)
,@pmCodigo VARCHAR(4), @pmIdPais VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO Departamentos (IdDep,Departamento,Codigo,IdPais,Inactivo)
 VALUES (@pmIdDep,@pmDepartamento,@pmCodigo,@pmIdPais,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsDependencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDependencias] @pmIdDep VARCHAR(4),@pmDependencia VARCHAR(50),@pmJefeDep VARCHAR(50),@pmIdArea VARCHAR(4)
,@pmTipRiesgo DECIMAL(10,4),@pmIdSubCos VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO Dependencias (IdDep,Dependencia,JefeDep,IdArea,IdSubCos,TipRiesgo,Inactivo)
 VALUES (@pmIdDep,@pmDependencia,@pmJefeDep,@pmIdArea,@pmIdSubCos,@pmTipRiesgo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsDesagregaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDesagregaciones] @pmIdDrp VARCHAR(8),@pmCodigoDR VARCHAR(10),@pmDesagregacion VARCHAR(500),@pmCodigoCR VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO Desagregaciones (IdDrp,CodigoDR,Desagregacion,CodigoCR,Inactivo)
 VALUES (@pmIdDrp,@pmCodigoDR,@pmDesagregacion,@pmCodigoCR,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsDespachos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDespachos] @pmTipDoc VARCHAR(3),@pmCartulina INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdRuta VARCHAR(4),@pmNumOrden INT,@pmFechaRec SMALLDATETIME,@pmIdVehiculo VARCHAR(10)
,@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmIdConductor1 VARCHAR(16),@pmIdRelevador VARCHAR(16),@pmVehPropio BIT,@pmCentInicial INT,@pmCentFinal INT,@pmNPasajeros INT,@pmRecorridos INT,@pmValorProducido MONEY
,@pmValorGastos MONEY,@pmValorAhorro MONEY,@pmValorOtros MONEY,@pmValorVales MONEY,@pmValorAbono MONEY,@pmValorPasaje MONEY,@pmTipoAdmon VARCHAR(10),@pmIdTipRec VARCHAR(3),@pmReciboCaja INT,@pmIdCiaRec CHAR(2)
,@pmNumAutoriza VARCHAR(30),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Despachos (TipDoc,Cartulina,IdCia,Fecha,IdRuta,NumOrden,FechaRec,IdVehiculo,IdPropietario,IdConductor,IdConductor1,IdRelevador,VehPropio,CentInicial,CentFinal,NPasajeros,Recorridos,ValorProducido,ValorGastos,ValorAhorro,ValorOtros
,ValorVales,ValorAbono,ValorPasaje,TipoAdmon,IdTipRec,ReciboCaja,IdCiaRec,NumAutoriza,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmCartulina,@pmIdCia,@pmFecha,@pmIdRuta,@pmNumOrden,@pmFechaRec,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmIdConductor1,@pmIdRelevador,@pmVehPropio,@pmCentInicial,@pmCentFinal
,@pmNPasajeros,@pmRecorridos,@pmValorProducido,@pmValorGastos,@pmValorAhorro,@pmValorOtros,@pmValorVales,@pmValorAbono,@pmValorPasaje,@pmTipoAdmon,@pmIdTipRec,@pmReciboCaja,@pmIdCiaRec,@pmNumAutoriza,@pmAnulado,@pmNumDev
,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDetCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDetCuentas] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmConcepto VARCHAR(10),@pmItem INT
,@pmIdCuenta VARCHAR(16),@pmValor MONEY,@pmDetalle VARCHAR(150),@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16),@pmCdCCosto VARCHAR(16)
,@pmCdSubCos VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmVrBase MONEY,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT
,@pmFecVence SMALLDATETIME,@pmCheque VARCHAR(20),@pmCiuOrigen VARCHAR(8),@pmReferencia VARCHAR(50),@pmVrTarifa DECIMAL(14,4)
,@pmTipoTarif CHAR(1),@pmCodConc VARCHAR(4),@pmCodTarif VARCHAR(4)
 AS 
 INSERT INTO Trn_DetCuentas (TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,VrBase,TipFac,Factura,IdCiaFac
,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmConcepto,@pmItem,@pmIdCuenta,@pmValor,@pmDetalle,@pmIdTercero,@pmCodAgncia,@pmCdCCosto,@pmCdSubCos
,@pmpVehiculo,@pmVrBase,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmCheque,@pmCiuOrigen,@pmReferencia,@pmVrTarifa,@pmTipoTarif,@pmCodConc,@pmCodTarif)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevCaj] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrEfectivo MONEY
,@pmVrOtros MONEY,@pmVrTotal MONEY,@pmVrTotDebito MONEY,@pmVrTotCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmEnEfectivo BIT,@pmCdCta VARCHAR(4)
,@pmNumForma VARCHAR(20),@pmCdBanco VARCHAR(4),@pmReferencia VARCHAR(50),@pmNumAutoriza INT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11),@pmNumVehiculo VARCHAR(10)
 AS 
 INSERT INTO Trn_DevCaj (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,IdTercero,IdAgencia,IdCCosto,IdSubCos,IdCajero,EnEfectivo,CdCta,NumForma,CdBanco,Referencia,NumAutoriza
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,NumVehiculo)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmRecibo,@pmIdCiaDoc,@pmFecDoc,@pmVrEfectivo,@pmVrOtros,@pmVrTotal,@pmVrTotDebito,@pmVrTotCredito,@pmIdTercero,@pmIdAgencia,@pmIdCCosto,@pmIdSubCos
,@pmIdCajero,@pmEnEfectivo,@pmCdCta,@pmNumForma,@pmCdBanco,@pmReferencia,@pmNumAutoriza,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumVehiculo)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDevCausacion] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
,@pmFecDoc SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorIva MONEY,@pmValorReteFte MONEY
,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorFletes MONEY,@pmValorNeto MONEY,@pmValorCxc MONEY,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmFactura VARCHAR(15),@pmIdProveedor VARCHAR(16)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevCausacion (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Documento,IdCiaDoc,FecDoc,IdVehiculo,IdConductor,IdPropietario,VehPropio,ValorTotal,ValorDcto,ValorIva,ValorReteFte,ValorReteIva,ValorReteIca,ValorOtros,ValorFletes,ValorNeto
,ValorCxc,IdPlazo,CxPagar,Factura,IdProveedor,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmFecDoc,@pmIdVehiculo,@pmIdConductor,@pmIdPropietario,@pmVehPropio,@pmValorTotal,@pmValorDcto,@pmValorIva,@pmValorReteFte
,@pmValorReteIva,@pmValorReteIca,@pmValorOtros,@pmValorFletes,@pmValorNeto,@pmValorCxc,@pmIdPlazo,@pmCxPagar,@pmFactura,@pmIdProveedor,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevCns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDevCns] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrEfectivo MONEY
,@pmVrOtros MONEY,@pmVrTotal MONEY,@pmEnEfectivo BIT,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmIdCliente VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmReferencia VARCHAR(50),@pmReferncia2 VARCHAR(50)
,@pmNumConsigna VARCHAR(20),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevCns (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Consignacion,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,EnEfectivo,IdCta,IdCuenta,IdCliente,IdCCosto,IdSubCos,IdCajero,Referencia,Referncia2,NumConsigna,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmConsignacion,@pmIdCiaDoc,@pmFecDoc,@pmVrEfectivo,@pmVrOtros,@pmVrTotal,@pmEnEfectivo,@pmIdCta,@pmIdCuenta,@pmIdCliente,@pmIdCCosto,@pmIdSubCos,@pmIdCajero,@pmReferencia,@pmReferncia2
,@pmNumConsigna,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevEnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProv VARCHAR(16)
,@pmFactura VARCHAR(15),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrCargos MONEY
,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmNitFletes VARCHAR(16),@pmCxPagar BIT,@pmDocEquiv VARCHAR(3),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmModalidad VARCHAR(10)
,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrRetFlete MONEY,@pmVrIcaFlete MONEY,@pmFletesCosto BIT,@pmVrIvaMvc MONEY
,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmVrImpuCons MONEY,@pmVrSobtasaCons MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4)
,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevEnt (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Entrada,IdCiaDoc,FecDoc,IdProv,Factura,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,FletesCosto,CxPagar,DocEquiv
,BaseImp,BaseRet,CdCCosto,CdSubCos,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,VrImpuCons,VrSobtasaCons,BaseIvaIgp,VrIvaIngProd,ImpAviTab,TarifaAvta,VrImpuBA,VrImpuCUP)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmEntrada,@pmIdCiaDoc,@pmFecDoc,@pmIdProv,@pmFactura,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrOtros
,@pmVrSobretasa,@pmVrImpGlobal,@pmVrCargos,@pmVrOtrDcto,@pmVrNeto,@pmCantidad,@pmNitFletes,@pmVrRetFlete,@pmVrIcaFlete,@pmFletesCosto,@pmCxPagar,@pmDocEquiv,@pmBaseImp,@pmBaseRet,@pmCdCCosto,@pmCdSubCos,@pmModalidad,@pmModdDev,@pmOrigenAdd
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrIvaMvc,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmVrBomberil,@pmTarifaBom,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmVrImpCarbono,@pmVrImpuCons,@pmVrSobtasaCons,@pmBaseIvaIgp,@pmVrIvaIngProd,@pmImpAviTab,@pmTarifaAvta,@pmVrImpuBA,@pmVrImpuCUP)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevFco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevFco] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmnClieCon VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4)
,@pmCantPuntos DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmPedido INT,@pmIdCiaPed CHAR(2),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFecPedido SMALLDATETIME,@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmNumAutoriza INT,@pmPlacaVehic VARCHAR(10),@pmKmtVehic INT,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmCdMotDev VARCHAR(4)
,@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevFco (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,BaseImp,BaseRet,IdCajero,IdVend,TarifaCom
,CodTarCom,NitCliente,CdAgencia,IdCCosto,IdSubCos,IdLocal,EnEfectivo,Pedido,IdCiaPed,Remision,IdCiaRem,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,NumAutoriza,TimeSys,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq
,VrIvaObsequio,CdMotDev,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP,ImpAviTab,TarifaAvta,VrBomberil,TarifaBom,VrAutRetIat,VrAutRetBom)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmFactura,@pmIdCiaDoc,@pmFecDoc,@pmnClieCon,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrCargos,@pmVrOtrDcto,@pmVrCostos
,@pmVrNeto,@pmVrEfectivo,@pmVrPagosOtr,@pmCantidad,@pmCantPuntos,@pmBaseImp,@pmBaseRet,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmNitCliente,@pmCdAgencia,@pmIdCCosto,@pmIdSubCos,@pmIdLocal,@pmEnEfectivo,@pmPedido,@pmIdCiaPed,@pmRemision
,@pmIdCiaRem,@pmFecPedido,@pmModalidad,@pmModdDev,@pmPlacaVehic,@pmKmtVehic,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmNumAutoriza,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrImpCons,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmCdMotDev
,@pmTarifaArf,@pmVrAutRetFte,@pmTarifaAri,@pmVrAutRetIca,@pmVrImpuBA,@pmVrImpuCUP,@pmImpAviTab,@pmTarifaAvta,@pmVrBomberil,@pmTarifaBom,@pmVrAutRetIat,@pmVrAutRetBom)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevFcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevFcr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY
,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrFaltantes MONEY,@pmVrAnticipos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmCantPuntos DECIMAL(14,4),@pmBaseImp MONEY
,@pmBaseRet MONEY,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdLocEnv VARCHAR(8),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmFecPedido SMALLDATETIME,@pmModalidad VARCHAR(10)
,@pmPlacaVehic VARCHAR(10),@pmKmtVehic INT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY
,@pmDevMasivo INT,@pmNumRecibo INT,@pmCdCiaRec CHAR(2),@pmCdMotDev VARCHAR(4),@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevFcr (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,IdLocEnv
,Pedido,IdCiaPed,Remision,IdCiaRem,Cotizacion,IdCiaCot,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,ZonaFrontera,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,DevMasivo,NumRecibo,CdCiaRec,CdMotDev,BaseIvaIgp,VrIvaIngProd,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca
,VrImpuBA,VrImpuCUP,ImpAviTab,TarifaAvta,VrBomberil,TarifaBom,VrAutRetIat,VrAutRetBom)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmFactura,@pmIdCiaDoc,@pmFecDoc,@pmIdCliente,@pmIdAgencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrOtros,@pmVrCargos,@pmVrOtrDcto,@pmVrCostos,@pmVrSobretasa,@pmVrImpGlobal,@pmVrFaltantes
,@pmVrAnticipos,@pmVrNeto,@pmCantidad,@pmCantPuntos,@pmBaseImp,@pmBaseRet,@pmIdCCosto,@pmIdSubCos,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmIdLocEnv,@pmPedido,@pmIdCiaPed,@pmRemision,@pmIdCiaRem,@pmCotizacion,@pmIdCiaCot,@pmFecPedido,@pmModalidad,@pmModdDev,@pmPlacaVehic,@pmKmtVehic,@pmZonaFrontera,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrImpCons,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmVrImpCarbono,@pmDevMasivo,@pmNumRecibo,@pmCdCiaRec,@pmCdMotDev,@pmBaseIvaIgp,@pmVrIvaIngProd,@pmTarifaArf,@pmVrAutRetFte,@pmTarifaAri,@pmVrAutRetIca,@pmVrImpuBA,@pmVrImpuCUP,@pmImpAviTab,@pmTarifaAvta,@pmVrBomberil,@pmTarifaBom,@pmVrAutRetIat,@pmVrAutRetBom)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevFvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevFvc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4)
,@pmCodTarCom VARCHAR(4),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevFvc (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,IdVend,TarifaCom,CodTarCom,ModdDev,TipCom,Comprobante,IdCiaCom,Observacion
,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmFactura,@pmIdCiaDoc,@pmFecDoc,@pmIdCliente,@pmIdAgencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCargos,@pmVrOtrDcto,@pmVrCostos,@pmVrNeto,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmIdVend
,@pmTarifaCom,@pmCodTarCom,@pmModdDev,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTarifaArf,@pmVrAutRetFte,@pmTarifaAri,@pmVrAutRetIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevNpr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDevNpr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumNota INT
,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY,@pmVrCostos MONEY,@pmCantEnt DECIMAL(14,4),@pmCantSal DECIMAL(14,4),@pmNumOrden INT
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevNpr (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumNota,IdCiaDoc,FecDoc,IdTercero,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden,IdCCosto,IdSubCos,Modalidad,ModdDev,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumNota,@pmIdCiaDoc,@pmFecDoc,@pmIdTercero,@pmVrSubTotal,@pmVrCostos,@pmCantEnt,@pmCantSal
,@pmNumOrden,@pmIdCCosto,@pmIdSubCos,@pmModalidad,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevPas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevPas] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmNitTercero VARCHAR(16),@pmCdJornada VARCHAR(4)
,@pmVrSubTotal MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmModdDev VARCHAR(10),@pmNumAutoriza INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevPas (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,nNota,IdCiaDoc,FecDoc,NitTercero,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto,Cantidad,IdCajero,IdVend,TarifaCom,CodTarCom,IdCCosto,IdSubCos,Referencia,ModdDev,NumAutoriza,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmnNota,@pmIdCiaDoc,@pmFecDoc,@pmNitTercero,@pmCdJornada,@pmVrSubTotal,@pmVrSobretasa,@pmVrImpGlobal,@pmVrOtros,@pmVrCostos,@pmVrNeto,@pmCantidad,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom
,@pmIdCCosto,@pmIdSubCos,@pmReferencia,@pmModdDev,@pmNumAutoriza,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevPla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDevPla] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3)
,@pmPlanilla INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmNitTercero VARCHAR(16),@pmIdJornada VARCHAR(4),@pmVrSubTotal MONEY,@pmVrSobretasa MONEY
,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrSobrantes MONEY,@pmVrFaltantes MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY
,@pmVrCreditos MONEY,@pmVrGastComb MONEY,@pmVrGastOtros MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4),@pmVrConTotal MONEY,@pmVrConImp MONEY,@pmVrConDcto MONEY,@pmVrConCos MONEY
,@pmConCant DECIMAL(14,4),@pmVrCreTotal MONEY,@pmVrCreImp MONEY,@pmVrCreDcto MONEY,@pmVrCreCos MONEY,@pmCreCant DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16)
,@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitRef VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50)
,@pmModalidad VARCHAR(10),@pmFecCorte SMALLDATETIME,@pmNumCorte INT,@pmModdDev VARCHAR(10),@pmNumAutoriza INT,@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevPla (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Planilla,IdCiaDoc,FecDoc,NitTercero,IdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb
,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,IdVend,TarifaCom,CodTarCom,NitRef,IdCCosto,IdSubCos,Referencia,Modalidad,FecCorte,NumCorte,ModdDev
,NumAutoriza,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmPlanilla,@pmIdCiaDoc,@pmFecDoc,@pmNitTercero,@pmIdJornada,@pmVrSubTotal,@pmVrSobretasa,@pmVrImpGlobal,@pmVrOtros,@pmVrSobrantes
,@pmVrFaltantes,@pmVrCostos,@pmVrNeto,@pmVrEfectivo,@pmVrCreditos,@pmVrGastComb,@pmVrGastOtros,@pmVrPagosOtr,@pmCantidad,@pmVrConTotal,@pmVrConImp,@pmVrConDcto,@pmVrConCos,@pmConCant,@pmVrCreTotal
,@pmVrCreImp,@pmVrCreDcto,@pmVrCreCos,@pmCreCant,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmNitRef,@pmIdCCosto,@pmIdSubCos,@pmReferencia,@pmModalidad,@pmFecCorte,@pmNumCorte,@pmModdDev
,@pmNumAutoriza,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevPrestamos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmPrestamo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmFechaPrest SMALLDATETIME
,@pmTipoPlazo VARCHAR(10),@pmNumCuotas INT,@pmTipoCuota VARCHAR(10),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY,@pmTasaInteres DECIMAL(14,4),@pmCxPagar BIT,@pmFactura VARCHAR(20)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevPrestamos (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Prestamo,IdCiaDoc,FecDoc,FechaPrest,TipoPlazo,NumCuotas,TipoCuota,IdVehiculo,IdPropietario,IdConductor,VehPropio,ValorTotal,TasaInteres,CxPagar,Factura,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmPrestamo,@pmIdCiaDoc,@pmFecDoc,@pmFechaPrest,@pmTipoPlazo,@pmNumCuotas,@pmTipoCuota,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmVehPropio,@pmValorTotal,@pmTasaInteres,@pmCxPagar
,@pmFactura,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrRetencion MONEY
,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrAhorro MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmVrEfectivo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4)
,@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmNumAutoriza INT,@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevRec (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,IdAgencia,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,IdCCosto,IdSubCos,IdCajero,IdVend,TarifaCom,CodTarCom,IdLocal,EnEfectivo,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,NumAutoriza,Modalidad,ModdDev
,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmRecibo,@pmIdCiaDoc,@pmFecDoc,@pmFecPago,@pmIdCliente,@pmIdAgencia,@pmVrRecibido,@pmVrSubTotal,@pmVrDescuento,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrOtros,@pmVrOtrDcto,@pmVrAhorro,@pmVrPagosMas,@pmVrNeto,@pmVrAplicado,@pmVrAnticipo,@pmVrEfectivo,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmIdCCosto,@pmIdSubCos
,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmIdLocal,@pmEnEfectivo,@pmReferencia,@pmpVehiculo,@pmCdConductor,@pmTipDcm,@pmDocumento,@pmIdCiaDcm,@pmNumAutoriza,@pmModalidad,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmVrBomberil,@pmTarifaBom,@pmCodTarifBom,@pmImpAviTab,@pmTarifaAvta,@pmCodTarifAvta)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevRecBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDevRecBuses] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmModalidad VARCHAR(10),@pmValorRecibido MONEY,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorOtrosDct MONEY
,@pmValorPagMas MONEY,@pmValorAhorro MONEY,@pmValorOConce MONEY,@pmValorNeto MONEY,@pmValorAplicado MONEY,@pmValorAnticipo MONEY,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmIdTarCom VARCHAR(4),@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20)
,@pmIdBanco VARCHAR(4),@pmEsParcial BIT,@pmIdClase VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevRecBuses (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,IdCliente,IdAgencia,IdVehiculo,IdConductor,VehPropio,Modalidad,ValorRecibido,ValorTotal,ValorDcto,ValorReteFte,ValorReteIva,ValorReteIca,ValorOtros,ValorOtrosDct,ValorPagMas,ValorAhorro,ValorOConce,ValorNeto,ValorAplicado,ValorAnticipo,IdVendedor,Comision,IdTarCom,IdCta,EnEfectivo
,NumCheque,IdBanco,EsParcial,IdClase,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmRecibo,@pmIdCiaDoc,@pmFecDoc,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmIdConductor,@pmVehPropio,@pmModalidad,@pmValorRecibido,@pmValorTotal,@pmValorDcto,@pmValorReteFte,@pmValorReteIva,@pmValorReteIca,@pmValorOtros,@pmValorOtrosDct
,@pmValorPagMas,@pmValorAhorro,@pmValorOConce,@pmValorNeto,@pmValorAplicado,@pmValorAnticipo,@pmIdVendedor,@pmComision,@pmIdTarCom,@pmIdCta,@pmEnEfectivo,@pmNumCheque,@pmIdBanco,@pmEsParcial,@pmIdClase,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevSal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmSalida INT
,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4)
,@pmBaseImp MONEY,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmpVehiculo VARCHAR(10)
,@pmNContrato INT,@pmIdCiaCont CHAR(2),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmModRequis VARCHAR(10)
,@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevSal (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Salida,IdCiaDoc,FecDoc,IdTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,IdCCosto,IdSubCos,TipOrd,NumOrden
,IdCiaOrd,pVehiculo,Modalidad,NContrato,IdCiaCont,NitCliente,CdAgencia,ModRequis,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrImpuBA,VrImpuCUP)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmSalida,@pmIdCiaDoc,@pmFecDoc,@pmIdTercero,@pmVrSubTotal,@pmVrImpuesto,@pmVrCostos,@pmVrNeto
,@pmCantidad,@pmBaseImp,@pmIdCCosto,@pmIdSubCos,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmpVehiculo,@pmModalidad,@pmNContrato,@pmIdCiaCont,@pmNitCliente,@pmCdAgencia,@pmModRequis,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrImpuBA,@pmVrImpuCUP)
GO
/****** Object:  StoredProcedure [dbo].[paInsDevVal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDevVal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmIdTercero VARCHAR(16),@pmTotalPagos MONEY,@pmTotalCobros MONEY,@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmVrDescuento MONEY,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DevVal (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,nRadica,IdCiaDoc,FecDoc,IdTercero,TotalPagos,TotalCobros,Referencia,CxPagar,VrDescuento,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmnRadica,@pmIdCiaDoc,@pmFecDoc,@pmIdTercero,@pmTotalPagos,@pmTotalCobros,@pmReferencia,@pmCxPagar,@pmVrDescuento,@pmModdDev,@pmOrigenAdd
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDiarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsDiarios] @pmIdDiario VARCHAR(4),@pmDiario VARCHAR(50),@pmCodTransac VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Diarios (IdDiario,Diario,Inactivo,CodTransac)
 VALUES (@pmIdDiario,@pmDiario,@pmInactivo,@pmCodTransac)
GO
/****** Object:  StoredProcedure [dbo].[paInsDiferidos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDiferidos] @pmIdDiferido VARCHAR(30),@pmNomDiferido VARCHAR(250),@pmIdTipDif VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdDep VARCHAR(4)
,@pmIdRespons VARCHAR(16),@pmIdCia CHAR(2),@pmFecInicio SMALLDATETIME,@pmValorTotal MONEY,@pmVrAdiciones MONEY,@pmVrDisminucion MONEY,@pmNumPeriodos INT,@pmFecFinAmtza DATETIME
,@pmAjustable BIT,@pmContable BIT,@pmVrAjuInfAcum MONEY,@pmVrAmtzaAcuHis MONEY,@pmVrAmtzaAcum MONEY,@pmVrAjuInfAmtza MONEY,@pmCuotasAmtza INT,@pmVrCorrMonDifAcu MONEY
,@pmCorrMonDiferida MONEY,@pmNumMesesDif INT,@pmFecUltAmtza SMALLDATETIME,@pmCueEnGrupo BIT,@pmIdCuenta VARCHAR(16),@pmIdCueAmortiza VARCHAR(16),@pmIdCueAjuDif VARCHAR(16),@pmIdCueCorrDif VARCHAR(16)
,@pmIdCueAjuAmtza VARCHAR(16),@pmIdCueCorrAA VARCHAR(16),@pmNumDoc VARCHAR(20),@pmReferencia VARCHAR(50),@pmDesUbicacion VARCHAR(150),@pmIdEstado VARCHAR(4),@pmFecRetiro SMALLDATETIME
,@pmIdCausal VARCHAR(4),@pmComentRetiro VARCHAR(250),@pmComentarios VARCHAR(250),@pmTipoAmtza CHAR(1),@pmNitCliente VARCHAR(16),@pmAgenCliente VARCHAR(16),@pmCantGalones DECIMAL (14,4),@pmIdProv VARCHAR(16)
,@pmNumPlaca  VARCHAR(20),@pmCodInstala VARCHAR(4),@pmTipoInvers VARCHAR(10),@pmTipoContable VARCHAR(10),@pmCodNiifDif VARCHAR(16),@pmCodNiifAmtza VARCHAR(16)
,@pmTipComp VARCHAR(3),@pmNumComp INT,@pmCdCiaComp CHAR(2),@pmFecCreacion SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Diferidos (IdDiferido,NomDiferido,IdTipDif,IdGrupo,IdCCosto,IdSubCos,IdDep,IdRespons,IdCia,FecInicio,ValorTotal,VrAdiciones,VrDisminucion,NumPeriodos,FecFinAmtza,Ajustable,Contable,VrAjuInfAcum,VrAmtzaAcuHis,VrAmtzaAcum
,VrAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif,FecUltAmtza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,DesUbicacion,IdEstado,FecRetiro,IdCausal
,ComentRetiro,Comentarios,FecCreacion,IdUsuario,TipoAmtza,NitCliente,AgenCliente,CantGalones,IdProv,NumPlaca,CodInstala,TipoInvers,TipoContable,CodNiifDif,CodNiifAmtza,TipComp,NumComp,CdCiaComp)
 VALUES (@pmIdDiferido,@pmNomDiferido,@pmIdTipDif,@pmIdGrupo,@pmIdCCosto,@pmIdSubCos,@pmIdDep,@pmIdRespons,@pmIdCia,@pmFecInicio,@pmValorTotal,@pmVrAdiciones,@pmVrDisminucion,@pmNumPeriodos
,@pmFecFinAmtza,@pmAjustable,@pmContable,@pmVrAjuInfAcum,@pmVrAmtzaAcuHis,@pmVrAmtzaAcum,@pmVrAjuInfAmtza,@pmCuotasAmtza,@pmVrCorrMonDifAcu,@pmCorrMonDiferida,@pmNumMesesDif
,@pmFecUltAmtza,@pmCueEnGrupo,@pmIdCuenta,@pmIdCueAmortiza,@pmIdCueAjuDif,@pmIdCueCorrDif,@pmIdCueAjuAmtza,@pmIdCueCorrAA,@pmNumDoc,@pmReferencia,@pmDesUbicacion,@pmIdEstado,@pmFecRetiro,@pmIdCausal
,@pmComentRetiro,@pmComentarios,@pmFecCreacion,@pmIdUsuario,@pmTipoAmtza,@pmNitCliente,@pmAgenCliente,@pmCantGalones,@pmIdProv,@pmNumPlaca,@pmCodInstala,@pmTipoInvers,@pmTipoContable,@pmCodNiifDif,@pmCodNiifAmtza,@pmTipComp,@pmNumComp,@pmCdCiaComp)
GO
/****** Object:  StoredProcedure [dbo].[paInsDisciplinario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDisciplinario]  @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecSuceso SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmIdRuta VARCHAR(4),@pmLugar VARCHAR(150),@pmNomReporta VARCHAR(150)
,@pmCedReporta VARCHAR(16),@pmVehiculoRep VARCHAR(10),@pmRepCond BIT,@pmCoordinador VARCHAR(150),@pmDespachador VARCHAR(150),@pmCitaDescargos BIT,@pmFecCita SMALLDATETIME,@pmMemoCita VARCHAR(50),@pmImputacion VARCHAR(2500),@pmDescargos VARCHAR(3000),@pmFecDesc SMALLDATETIME,@pmRecibeDesc VARCHAR(150)
,@pmTipoSancion VARCHAR(10),@pmDescSancion VARCHAR(1000),@pmFecSancion SMALLDATETIME,@pmCantSancion DECIMAL(14,4),@pmCodInfracc INT,@pmReferencia VARCHAR(50),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmTipoInf VARCHAR(10)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Disciplinario (TipDoc,Numero,IdCia,Fecha,FecSuceso,IdVehiculo,IdPropietario,IdConductor,IdRuta,TipoInf,Lugar,NomReporta,CedReporta,VehiculoRep,RepCond,Coordinador,Despachador,CitaDescargos,FecCita,MemoCita,Imputacion,Descargos,FecDesc,RecibeDesc,TipoSancion,DescSancion,FecSancion,CantSancion,CodInfracc,Referencia,Observacion,Anulado,NumDev,FecDev,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumero,@pmIdCia,@pmFecha,@pmFecSuceso,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmIdRuta,@pmTipoInf,@pmLugar,@pmNomReporta,@pmCedReporta,@pmVehiculoRep,@pmRepCond,@pmCoordinador,@pmDespachador,@pmCitaDescargos,@pmFecCita,@pmMemoCita,@pmImputacion,@pmDescargos,@pmFecDesc,@pmRecibeDesc,@pmTipoSancion
,@pmDescSancion,@pmFecSancion,@pmCantSancion,@pmCodInfracc,@pmReferencia,@pmObservacion,@pmAnulado,@pmNumDev,@pmFecDev,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsDocMemo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDocMemo] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmComentarios VARCHAR(6500)
,@pmNota1 VARCHAR(500),@pmNota2 VARCHAR(500),@pmNota3 VARCHAR(500),@pmCantImp INT,@pmArchivoImg VARCHAR(150)
 AS 
 INSERT INTO Trn_DocMemo (TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmComentarios,@pmNota1,@pmNota2,@pmNota3,@pmCantImp,@pmArchivoImg)
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSopDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDocSopDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmBomberil DECIMAL(16,6),@pmImpAviTab DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmValorTotal DECIMAL(16,6)
,@pmBaseRet DECIMAL(16,6),@pmBaseBom DECIMAL(16,6),@pmCodRes VARCHAR(4),@pmDescServicio VARCHAR(500),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmNitCueProv VARCHAR(16),@pmCodCueProv VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmVrOtrosImpu DECIMAL(16,6),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DocSopDev (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumDoc,IdCiaDoc,FecDoc,IdTercero,SubTotal,Descuento,Retencion,ReteIca,Bomberil,ImpAviTab,OtrosCargos,OtrosDctos,ValorTotal,BaseRet,BaseBom,CodRes,DescServicio,CdCCosto,CdSubCos,TipDocRef,NumDocRef,IdCiaRef,NitCueProv,CodCueProv,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,VrOtrosImpu)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumDoc,@pmIdCiaDoc,@pmFecDoc,@pmIdTercero,@pmSubTotal,@pmDescuento,@pmRetencion,@pmReteIca,@pmBomberil,@pmImpAviTab,@pmOtrosCargos,@pmOtrosDctos,@pmValorTotal,@pmBaseRet,@pmBaseBom,@pmCodRes,@pmDescServicio,@pmCdCCosto,@pmCdSubCos,@pmTipDocRef,@pmNumDocRef,@pmIdCiaRef,@pmNitCueProv,@pmCodCueProv,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrOtrosImpu)
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSopDevDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDocSopDevDet] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(1000),@pmCantidad DECIMAL(16,6),@pmVrUnitario DECIMAL(16,6),@pmValorOper DECIMAL(16,6),@pmVrDcto DECIMAL(16,6),@pmVrRetencion DECIMAL(16,6),@pmVrRetIca DECIMAL(16,6),@pmVrBomberil DECIMAL(16,6),@pmVrAviTab DECIMAL(16,6),@pmTarifaDct DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaBom DECIMAL(14,4),@pmTarifaAvta DECIMAL(14,4),@pmCodTarDct VARCHAR(4)
,@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarifBom VARCHAR(4),@pmCodTarifAvta VARCHAR(4),@pmItemCom INT,@pmCdCuenta VARCHAR(16),@pmCdCueCre VARCHAR(16),@pmCodCC VARCHAR(16),@pmCodSubCc VARCHAR(16),@pmPlacaVeh VARCHAR(10),@pmVeh_Propio INT,@pmNitCliente VARCHAR(16),@pmCodAgencia VARCHAR(16),@pmDetalle VARCHAR(500),@pmNitTercero VARCHAR(16)
 AS 
 INSERT INTO Trn_DocSopDevDet (TipDev,Devolucion,IdCia,Item,IdProducto,Descripcion,Cantidad,VrUnitario,ValorOper,VrDcto,VrRetencion,VrRetIca,VrBomberil,VrAviTab,TarifaDct,TarifaRet,TarifaIca,TarifaBom,TarifaAvta,CodTarDct,CodTarRet,CodTarIca,CodTarifBom,CodTarifAvta,ItemCom,CdCuenta,CdCueCre,CodCC,CodSubCc,PlacaVeh,Veh_Propio,NitCliente,CodAgencia,Detalle,NitTercero)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmItem,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmVrUnitario,@pmValorOper,@pmVrDcto,@pmVrRetencion,@pmVrRetIca,@pmVrBomberil,@pmVrAviTab,@pmTarifaDct,@pmTarifaRet,@pmTarifaIca,@pmTarifaBom,@pmTarifaAvta,@pmCodTarDct,@pmCodTarRet,@pmCodTarIca,@pmCodTarifBom,@pmCodTarifAvta,@pmItemCom,@pmCdCuenta,@pmCdCueCre,@pmCodCC,@pmCodSubCc,@pmPlacaVeh,@pmVeh_Propio,@pmNitCliente,@pmCodAgencia,@pmDetalle,@pmNitTercero)
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSoporte]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDocSoporte] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmIdAdquiriente VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmIdMedPago VARCHAR(4),@pmMetPago INT,@pmModalidad VARCHAR(20),@pmNumFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmBomberil DECIMAL(16,6),@pmImpAviTab DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmValorTotal DECIMAL(16,6)
,@pmBaseRet DECIMAL(16,6),@pmBaseBom DECIMAL(16,6),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaBom DECIMAL(14,4),@pmTarifaAvta DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarifBom VARCHAR(4),@pmCodTarifAvta VARCHAR(4),@pmDescServicio VARCHAR(500),@pmCodRes VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmAnulado BIT,@pmTipDocDev VARCHAR(3),@pmNumDev INT,@pmCdCiaDev CHAR(2),@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(500),@pmIdEstado VARCHAR(4),@pmCodCueProv VARCHAR(16),@pmNitCueProv VARCHAR(16),@pmVrOtrosImpu DECIMAL(16,6),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_DocSoporte (TipDoc,NumDoc,IdCia,Fecha,IdTercero,IdAdquiriente,IdConcepto,IdMedPago,MetPago,Modalidad,NumFactura,FechaFac,FechaVence,SubTotal,Descuento,Retencion,ReteIca,Bomberil,ImpAviTab,OtrosCargos,OtrosDctos,ValorTotal,BaseRet,BaseBom,TarifaRet,TarifaIca,TarifaBom,TarifaAvta,CodTarRet,CodTarIca,CodTarifBom,CodTarifAvta,DescServicio,CodRes,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,TipDocRef,NumDocRef,IdCiaRef,Anulado,TipDocDev,NumDev,CdCiaDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,CodCueProv,NitCueProv,VrOtrosImpu)
 VALUES (@pmTipDoc,@pmNumDoc,@pmIdCia,@pmFecha,@pmIdTercero,@pmIdAdquiriente,@pmIdConcepto,@pmIdMedPago,@pmMetPago,@pmModalidad,@pmNumFactura,@pmFechaFac,@pmFechaVence,@pmSubTotal,@pmDescuento,@pmRetencion,@pmReteIca,@pmBomberil,@pmImpAviTab,@pmOtrosCargos,@pmOtrosDctos,@pmValorTotal,@pmBaseRet,@pmBaseBom,@pmTarifaRet,@pmTarifaIca,@pmTarifaBom,@pmTarifaAvta,@pmCodTarRet,@pmCodTarIca,@pmCodTarifBom,@pmCodTarifAvta,@pmDescServicio,@pmCodRes,@pmCdCCosto,@pmCdSubCos,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmTipDocRef,@pmNumDocRef,@pmIdCiaRef,@pmAnulado,@pmTipDocDev,@pmNumDev,@pmCdCiaDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCodCueProv,@pmNitCueProv,@pmVrOtrosImpu)
GO
/****** Object:  StoredProcedure [dbo].[paInsDocSoporteDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsDocSoporteDet] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(1000),@pmCantidad DECIMAL(16,6),@pmVrUnitario DECIMAL(16,6),@pmValorOper DECIMAL(16,6),@pmVrDcto DECIMAL(16,6),@pmVrRetencion DECIMAL(16,6),@pmVrRetIca DECIMAL(16,6)
,@pmVrBomberil DECIMAL(16,6),@pmVrAviTab DECIMAL(16,6),@pmTarifaDct DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaBom DECIMAL(14,4),@pmTarifaAvta DECIMAL(14,4),@pmCodTarDct VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarifBom VARCHAR(4),@pmCodTarifAvta VARCHAR(4),@pmItemCom INT
,@pmCdCuenta VARCHAR(16),@pmCdCueCre VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmDetalle VARCHAR(500),@pmNitTercero VARCHAR(16),@pmCodCC VARCHAR(16),@pmCodSubCc VARCHAR(16),@pmPlacaVeh VARCHAR(10),@pmVeh_Propio INT,@pmNitCliente VARCHAR(16),@pmCodAgencia VARCHAR(16)
 AS 
 INSERT INTO Trn_DocSoporteDet (TipDoc,NumDoc,IdCia,Item,IdProducto,Descripcion,Cantidad,VrUnitario,ValorOper,VrDcto,VrRetencion,VrRetIca,VrBomberil,VrAviTab,TarifaDct,TarifaRet,TarifaIca,TarifaBom,TarifaAvta,CodTarDct,CodTarRet,CodTarIca,CodTarifBom,CodTarifAvta,ItemCom,CdCuenta,CdCueCre,TipCom,Comprobante,IdCiaCom,Detalle,NitTercero,CodCC,CodSubCc,PlacaVeh,Veh_Propio,NitCliente,CodAgencia)
 VALUES (@pmTipDoc,@pmNumDoc,@pmIdCia,@pmItem,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmVrUnitario,@pmValorOper,@pmVrDcto,@pmVrRetencion,@pmVrRetIca,@pmVrBomberil,@pmVrAviTab,@pmTarifaDct,@pmTarifaRet,@pmTarifaIca,@pmTarifaBom,@pmTarifaAvta,@pmCodTarDct,@pmCodTarRet,@pmCodTarIca,@pmCodTarifBom,@pmCodTarifAvta,@pmItemCom,@pmCdCuenta,@pmCdCueCre,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmDetalle
,@pmNitTercero,@pmCodCC,@pmCodSubCc,@pmPlacaVeh,@pmVeh_Propio,@pmNitCliente,@pmCodAgencia)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsCalibra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEdsCalibra] @pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNitTercero VARCHAR(16),@pmCdJornada VARCHAR(4),@pmVrSubTotal MONEY
,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_EdsCalibra (TipDoc,nNota,IdCia,Fecha,IdConcepto,NitTercero,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto,Cantidad,IdCajero,IdVend,TarifaCom,CodTarCom,IdCCosto,IdSubCos
,Referencia,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmnNota,@pmIdCia,@pmFecha,@pmIdConcepto,@pmNitTercero,@pmCdJornada,@pmVrSubTotal,@pmVrSobretasa,@pmVrImpGlobal,@pmVrOtros,@pmVrCostos,@pmVrNeto,@pmCantidad
,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmIdCCosto,@pmIdSubCos,@pmReferencia,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsCortes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEdsCortes] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNitTercero VARCHAR(16),@pmIdJornada VARCHAR(4),@pmVrSubTotal MONEY,@pmVrSobretasa MONEY
,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrSobrantes MONEY,@pmVrFaltantes MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrCreditos MONEY,@pmVrGastComb MONEY,@pmVrGastOtros MONEY,@pmVrPagosOtr MONEY
,@pmCantidad DECIMAL(14,4),@pmVrConTotal MONEY,@pmVrConImp MONEY,@pmVrConDcto MONEY,@pmVrConCos MONEY,@pmConCant DECIMAL(14,4),@pmVrCreTotal MONEY,@pmVrCreImp MONEY,@pmVrCreDcto MONEY,@pmVrCreCos MONEY,@pmCreCant DECIMAL(14,4)
,@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitRef VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmModalidad VARCHAR(10),@pmFecCorte SMALLDATETIME
,@pmNumCorte INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoInt VARCHAR(10),@pmVrDctoClie MONEY,@pmNumTurno INT,@pmVrExcedClie MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_EdsCortes (TipDoc,Planilla,IdCia,Fecha,IdConcepto,NitTercero,IdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos
,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,IdVend,TarifaCom,CodTarCom,NitRef,IdCCosto,IdSubCos,Referencia,Modalidad,FecCorte,NumCorte,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,TipoInt,VrDctoClie,NumTurno,VrExcedClie)
 VALUES (@pmTipDoc,@pmPlanilla,@pmIdCia,@pmFecha,@pmIdConcepto,@pmNitTercero,@pmIdJornada,@pmVrSubTotal,@pmVrSobretasa,@pmVrImpGlobal,@pmVrOtros,@pmVrSobrantes,@pmVrFaltantes,@pmVrCostos,@pmVrNeto,@pmVrEfectivo,@pmVrCreditos,@pmVrGastComb
,@pmVrGastOtros,@pmVrPagosOtr,@pmCantidad,@pmVrConTotal,@pmVrConImp,@pmVrConDcto,@pmVrConCos,@pmConCant,@pmVrCreTotal,@pmVrCreImp,@pmVrCreDcto,@pmVrCreCos,@pmCreCant,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmNitRef,@pmIdCCosto,@pmIdSubCos
,@pmReferencia,@pmModalidad,@pmFecCorte,@pmNumCorte,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoInt,@pmVrDctoClie,@pmNumTurno,@pmVrExcedClie)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsForItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEdsForItems] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT,@pmItem INT,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCantidad DECIMAL(14,4)
,@pmVrPrecio MONEY,@pmTarifaIva DECIMAL(14,4),@pmVrIva MONEY,@pmTarifaDct DECIMAL(14,4),@pmVrDcto MONEY,@pmServicios BIT,@pmDescripcion VARCHAR(150),@pmListaPrec CHAR(1),@pmCantDev DECIMAL(14,4),@pmCantFact DECIMAL(14,4)
,@pmCdOperario VARCHAR(16),@pmComision DECIMAL(14,4),@pmCodTarBa VARCHAR(4),@pmTarifaIba DECIMAL(16,6),@pmVrImpuBa MONEY,@pmCodTarCup VARCHAR(4),@pmTarifaCup DECIMAL(16,6),@pmVrImpuCup MONEY
 AS 
 INSERT INTO Trn_EdsForItems (TipoRango,IdRango,NumSerie,NumForma,Item,IdProducto,IdBodega,Cantidad,VrPrecio,TarifaIva,VrIva,TarifaDct,VrDcto,Servicios,Descripcion,ListaPrec,CantDev,CantFact,CdOperario,Comision,CodTarBa,TarifaIba,VrImpuBa,CodTarCup,TarifaCup,VrImpuCup)
 VALUES (@pmTipoRango,@pmIdRango,@pmNumSerie,@pmNumForma,@pmItem,@pmIdProducto,@pmIdBodega,@pmCantidad,@pmVrPrecio,@pmTarifaIva,@pmVrIva,@pmTarifaDct,@pmVrDcto,@pmServicios,@pmDescripcion,@pmListaPrec,@pmCantDev,@pmCantFact,@pmCdOperario,@pmComision
,@pmCodTarBa,@pmTarifaIba,@pmVrImpuBa,@pmCodTarCup,@pmTarifaCup,@pmVrImpuCup)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEdsFormas] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT,@pmPlanilla INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME
,@pmVrTotal MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmnVehiculo VARCHAR(10),@pmIdCajero VARCHAR(11)
,@pmIdVend VARCHAR(16),@pmCdProducto VARCHAR(16),@pmCantidad DECIMAL(14,4),@pmIdForma VARCHAR(4),@pmItem INT,@pmReferencia VARCHAR(50),@pmCantPuntos DECIMAL(14,4)
,@pmObservacion VARCHAR(150),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmFechaDcm SMALLDATETIME,@pmAgencDcm VARCHAR(16),@pmAnulado BIT
,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmVrPrecio MONEY,@pmNumRef2 VARCHAR(50),@pmVrBase MONEY,@pmVrPrecioEsp MONEY
 AS 
 INSERT INTO Trn_EdsFormas (TipoRango,IdRango,NumSerie,NumForma,Planilla,IdCia,Fecha,VrTotal,IdCliente,IdAgencia,IdCuenta,pVehiculo,nVehiculo,IdCajero,IdVend,CdProducto,Cantidad
,IdForma,Item,Referencia,CantPuntos,Observacion,TipDcm,Documento,IdCiaDcm,FechaDcm,AgencDcm,Anulado,NumDev,FecDev,CdCCosto,CdSubCos,VrPrecio,NumRef2,VrBase,VrPrecioEsp)
 VALUES (@pmTipoRango,@pmIdRango,@pmNumSerie,@pmNumForma,@pmPlanilla,@pmIdCia,@pmFecha,@pmVrTotal,@pmIdCliente,@pmIdAgencia,@pmIdCuenta,@pmpVehiculo
,@pmnVehiculo,@pmIdCajero,@pmIdVend,@pmCdProducto,@pmCantidad,@pmIdForma,@pmItem,@pmReferencia,@pmCantPuntos,@pmObservacion
,@pmTipDcm,@pmDocumento,@pmIdCiaDcm,@pmFechaDcm,@pmAgencDcm,@pmAnulado,@pmNumDev,@pmFecDev,@pmCdCCosto,@pmCdSubCos,@pmVrPrecio,@pmNumRef2,@pmVrBase,@pmVrPrecioEsp)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsRangos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEdsRangos] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmIdForma VARCHAR(4),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmnVehiculo VARCHAR(10),@pmIdCuenta VARCHAR(16),@pmNumSerie VARCHAR(5),@pmNumInicial INT,@pmNumFinal INT,@pmNumTarjeta VARCHAR(30)
,@pmVrCupo MONEY,@pmVrConsumos MONEY,@pmTipoConsumo INT,@pmReqPlaca BIT,@pmReqProd BIT,@pmReqGalones BIT,@pmVldAgencia BIT,@pmVldPlaca VARCHAR(10),@pmModalidad VARCHAR(10)
,@pmAnulado BIT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmNumAuto BIT,@pmNumActual INT,@pmCod_CCosto VARCHAR(16),@pmCod_SubCosto VARCHAR(16),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_EdsRangos (TipoRango,IdRango,IdForma,Fecha,FecVence,IdCliente,IdAgencia,pVehiculo,nVehiculo,IdCuenta,NumSerie,NumInicial,NumFinal,NumTarjeta,VrCupo,VrConsumos,TipoConsumo,ReqPlaca
,ReqProd,ReqGalones,VldAgencia,VldPlaca,Modalidad,Anulado,Observacion,IdEstado,NumAuto,NumActual,TimeSys,IdCiaCrea,IdUsuario,Cod_CCosto,Cod_SubCosto)
 VALUES (@pmTipoRango,@pmIdRango,@pmIdForma,@pmFecha,@pmFecVence,@pmIdCliente,@pmIdAgencia,@pmpVehiculo,@pmnVehiculo,@pmIdCuenta,@pmNumSerie,@pmNumInicial,@pmNumFinal,@pmNumTarjeta
,@pmVrCupo,@pmVrConsumos,@pmTipoConsumo,@pmReqPlaca,@pmReqProd,@pmReqGalones,@pmVldAgencia,@pmVldPlaca,@pmModalidad,@pmAnulado,@pmObservacion,@pmIdEstado,@pmNumAuto,@pmNumActual,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCod_CCosto,@pmCod_SubCosto)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsServicio]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEdsServicio] @pmIdEstacion VARCHAR(4),@pmEstServicio VARCHAR(50),@pmDireccion VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO EdsServicio (IdEstacion,EstServicio,Direccion,Inactivo)
 VALUES (@pmIdEstacion,@pmEstServicio,@pmDireccion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEdsUnion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEdsUnion] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmCdTanque VARCHAR(4),@pmCapacidad DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmNivAgua DECIMAL(14,4)
,@pmTipoTrasl VARCHAR(3),@pmNumTraslado INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_EdsUnion (TipDoc,NumNota,IdCia,Fecha,CdTanque,Capacidad,Cantidad,NivAgua,TipoTrasl,NumTraslado,OrigenAdd,Anulado,FecDev,Observacion,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmCdTanque,@pmCapacidad,@pmCantidad,@pmNivAgua,@pmTipoTrasl,@pmNumTraslado,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrAntAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEgrAntAbonos] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipCan VARCHAR(3),@pmnAnticipo INT,@pmIdCiaAnt CHAR(2)
,@pmItemAnt INT,@pmVrAbonado MONEY,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16),@pmFecFactura SMALLDATETIME,@pmItemCom INT
 AS 
 INSERT INTO Trn_EgrAntAbonos (TipCom,Comprobante,IdCia,Item,TipCan,nAnticipo,IdCiaAnt,ItemAnt,VrAbonado,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,FecFactura,ItemCom)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmTipCan,@pmnAnticipo,@pmIdCiaAnt,@pmItemAnt,@pmVrAbonado,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmIdProveedor,@pmFecFactura,@pmItemCom)
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrAnticipo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEgrAnticipo] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT
,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmIdTercero VARCHAR(16),@pmVrAnticipo MONEY,@pmVrAplicado MONEY
 AS 
 INSERT INTO Trn_EgrAnticipo (TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,IdTercero,VrAnticipo,VrAplicado)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmIdCuenta,@pmIdTercero,@pmVrAnticipo,@pmVrAplicado)
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEgrFactura] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16)
,@pmIdCuenta VARCHAR(16),@pmVrAbono MONEY,@pmEsEgreso BIT,@pmItemCom INT,@pmpVehiculo VARCHAR(10),@pmVehPropio BIT,@pmTipDev VARCHAR(3),@pmNumDev INT,@pmDetAbono VARCHAR(100)
 AS 
 INSERT INTO Trn_EgrFactura (TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmIdProveedor,@pmIdCuenta,@pmVrAbono
,@pmEsEgreso,@pmItemCom,@pmpVehiculo,@pmVehPropio,@pmTipDev,@pmNumDev,@pmDetAbono)
GO
/****** Object:  StoredProcedure [dbo].[paInsEgrFactura_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEgrFactura_Uni]  @pmIdProveedor VARCHAR(16),@pmNewProveedor VARCHAR(16)
 AS 
 INSERT INTO Trn_EgrFactura (TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono)
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,@pmNewProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura WHERE IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_Contrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEmp_Contrato] @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmIndefinido BIT,@pmIdCargo VARCHAR(4),@pmIdJornada VARCHAR(4)
,@pmIdDep VARCHAR(4),@pmIdArea VARCHAR(4),@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCia CHAR(2),@pmIdNom VARCHAR(4),@pmTipoLiquida CHAR(1),@pmModPromdio CHAR(1),@pmVrSalario MONEY,@pmVrAuxTrans MONEY,@pmSalMinimo BIT,@pmSalIntegral BIT
,@pmFPnomina VARCHAR(10),@pmModoRet INT,@pmFecAfiSeg SMALLDATETIME,@pmATFinMes BIT,@pmSegFinMes BIT,@pmDenyPEN BIT,@pmDenyEPS BIT,@pmDenyARP BIT,@pmDenyCaj BIT,@pmDenyCes BIT,@pmDenyPri BIT,@pmDenyVac BIT,@pmDenyHex BIT,@pmBasePrest CHAR(2)
,@pmBaseSeg CHAR(2),@pmDchDotacion BIT,@pmDchCafeteria BIT,@pmReclmto VARCHAR(50),@pmNotas VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmIdClase VARCHAR(4),@pmTipoTrabj INT,@pmIdCot VARCHAR(4),@pmVrUpc MONEY,@pmIdGrupo VARCHAR(4)
,@pmDenyDcto BIT,@pmSubTipoCot VARCHAR(3),@pmDsoSabado BIT,@pmFspFinmes BIT,@pmFecFinPrueba SMALLDATETIME,@pmTipoPrendDot VARCHAR(10),@pmTipoMedSent VARCHAR(4),@pmBenefPacto VARCHAR(100),@pmTipoTraspaso INT,@pmFechaTraspaso SMALLDATETIME,@pmContratoRef INT,@pmIdMedPago VARCHAR(4),@pmIdActEco VARCHAR(10)
,@pmIdConvCT INT,@pmCodGrupoCT VARCHAR(4),@pmCodBaseCT VARCHAR(4),@pmCodEscfon VARCHAR(4),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Emp_Contrato (NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,IdCargo,IdJornada,IdDep,IdArea,IdInstala,IdCCosto,IdCia,IdNom,TipoLiquida,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS
,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,IdEstado,Inactivo,IdSubCos,IdClase,TipoTrabj,FecAdd,IdUsuario,IdCot,VrUpc,IdGrupo,DenyDcto,SubTipoCot,DsoSabado,FspFinmes,FecFinPrueba,TipoPrendDot,TipoMedSent,BenefPacto,TipoTraspaso,FechaTraspaso,ContratoRef,IdMedPago,IdActEco,IdConvCT,CodGrupoCT,CodBaseCT,CodEscfon)
 VALUES (@pmNContrato,@pmIdEmpleado,@pmIdTipCon,@pmFecIngreso,@pmFecVigencia,@pmFecRetiro,@pmIndefinido,@pmIdCargo,@pmIdJornada,@pmIdDep,@pmIdArea,@pmIdInstala,@pmIdCCosto,@pmIdCia,@pmIdNom,@pmTipoLiquida,@pmModPromdio,@pmVrSalario,@pmVrAuxTrans,@pmSalMinimo
,@pmSalIntegral,@pmFPnomina,@pmModoRet,@pmFecAfiSeg,@pmATFinMes,@pmSegFinMes,@pmDenyPEN,@pmDenyEPS,@pmDenyARP,@pmDenyCaj,@pmDenyCes,@pmDenyPri,@pmDenyVac,@pmDenyHex,@pmBasePrest,@pmBaseSeg,@pmDchDotacion,@pmDchCafeteria,@pmReclmto,@pmNotas
,@pmIdEstado,@pmInactivo,@pmIdSubCos,@pmIdClase,@pmTipoTrabj,@pmFecAdd,@pmIdUsuario,@pmIdCot,@pmVrUpc,@pmIdGrupo,@pmDenyDcto,@pmSubTipoCot,@pmDsoSabado,@pmFspFinmes,@pmFecFinPrueba,@pmTipoPrendDot,@pmTipoMedSent,@pmBenefPacto,@pmTipoTraspaso,@pmFechaTraspaso,@pmContratoRef,@pmIdMedPago,@pmIdActEco,@pmIdConvCT,@pmCodGrupoCT,@pmCodBaseCT,@pmCodEscfon)
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_Estudios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEmp_Estudios] @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEstblecmto VARCHAR(50)
,@pmTitulo VARCHAR(50),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdClase VARCHAR(4),@pmHabilitado BIT
 AS 
 INSERT INTO Emp_Estudios (IdEmpleado,Item,Estblecmto,Titulo,Fecha,FecVence,IdClase,Habilitado)
 VALUES (@pmIdEmpleado,@pmItem,@pmEstblecmto,@pmTitulo,@pmFecha,@pmFecVence,@pmIdClase,@pmHabilitado)
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_ExpLaboral]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEmp_ExpLaboral] @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEmpresa VARCHAR(50),@pmCargo VARCHAR(20)
,@pmFecInicio SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmDirEmpresa VARCHAR(100),@pmTelEmpresa VARCHAR(20)
 AS 
 INSERT INTO Emp_ExpLaboral (IdEmpleado,Item,Empresa,Cargo,FecInicio,FecRetiro,DirEmpresa,TelEmpresa)
 VALUES (@pmIdEmpleado,@pmItem,@pmEmpresa,@pmCargo,@pmFecInicio,@pmFecRetiro,@pmDirEmpresa,@pmTelEmpresa)
GO
/****** Object:  StoredProcedure [dbo].[paInsEmp_Parientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEmp_Parientes] @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmParntsco VARCHAR(10),@pmNombre VARCHAR(50)
,@pmFecNacmto SMALLDATETIME,@pmUltGrado VARCHAR(20),@pmDirccion VARCHAR(100),@pmTelefno VARCHAR(20),@pmTipoRef VARCHAR(10),@pmNitRef VARCHAR(16)
,@pmEmailRef VARCHAR(100),@pmCargoRef VARCHAR(50)
 AS 
 INSERT INTO Emp_Parientes (IdEmpleado,Item,Parntsco,Nombre,FecNacmto,UltGrado,Dirccion,Telefno,TipoRef,NitRef,EmailRef,CargoRef)
 VALUES (@pmIdEmpleado,@pmItem,@pmParntsco,@pmNombre,@pmFecNacmto,@pmUltGrado,@pmDirccion,@pmTelefno,@pmTipoRef,@pmNitRef,@pmEmailRef,@pmCargoRef)
GO
/****** Object:  StoredProcedure [dbo].[paInsEmpaques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEmpaques] @pmIdEmp VARCHAR(4),@pmEmpaque VARCHAR(50)
,@pmCodMintra VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Empaques (IdEmp,Empaque,CodMintra,Inactivo)
 VALUES (@pmIdEmp,@pmEmpaque,@pmCodMintra,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEmpleados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEmpleados] @pmIdEmpleado VARCHAR(16),@pmApellidos VARCHAR(80),@pmNombres VARCHAR(70),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmIdLugarCed VARCHAR(8),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmTelMovil VARCHAR(20),@pme_mail VARCHAR(100),@pmVvdaPropia BIT, @pmFecNacmto SMALLDATETIME,@pmLugarNacmto VARCHAR(30)
,@pmTipoSangre CHAR(2),@pmFactorRh CHAR(1),@pmSexo CHAR(1),@pmIdEstCivil VARCHAR(4),@pmNHijos INT,@pmLibMilitar VARCHAR(25),@pmClaseLib INT,@pmFechaLib SMALLDATETIME,@pmDistMil VARCHAR(10),@pmCertJudicial VARCHAR(25),@pmFecJudicial SMALLDATETIME,@pmVigJudicial SMALLDATETIME,@pmPasporte VARCHAR(25),@pmVigPaspte SMALLDATETIME,@pmLicencia VARCHAR(25),@pmIdLugar VARCHAR(8)
,@pmCatLicencia INT,@pmFecLicencia SMALLDATETIME,@pmVigLicencia SMALLDATETIME,@pmIdProf VARCHAR(4),@pmTallaCam VARCHAR(5),@pmTallaPan VARCHAR(5),@pmTallaZap VARCHAR(5),@pmUsaGafas BIT,@pmConyugue VARCHAR(50),@pmConyFecNac SMALLDATETIME,@pmConyTrabaja BIT,@pmConyEmpresa VARCHAR(50),@pmConyCargo VARCHAR(20),@pmConyFing SMALLDATETIME,@pmConyTel VARCHAR(20),@pmIdFonPen VARCHAR(8)
,@pmIdFonEps VARCHAR(8),@pmIdFonArp VARCHAR(8),@pmIdFonCes VARCHAR(8),@pmIdCajaCom VARCHAR(8),@pmCdFonAvp VARCHAR(8),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(25),@pmIdBanco VARCHAR(4),@pmNContrato INT,@pmFecVincula SMALLDATETIME,@pmFecUltAum SMALLDATETIME,@pmFecUltCes SMALLDATETIME,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME,@pmFecUltDot SMALLDATETIME
,@pmFecUltExm SMALLDATETIME,@pmFecUltCap SMALLDATETIME,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME,@pmFecRetAnt SMALLDATETIME,@pmFotoEmp VARCHAR(30),@pmFotoLic VARCHAR(30),@pmFotoFirma VARCHAR(30),@pmEsCondtor BIT,@pmpVehiculo VARCHAR(10),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCdLocCue VARCHAR(8),@pmFecUltParc SMALLDATETIME,@pmDecRenta INT,@pmNivelEduc VARCHAR(4),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Empleados (IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen
,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,IdClase,NumCuenta,IdBanco,NContrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FecUltParc,FotoEmp,FotoLic,FotoFirma,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,Observacion,CdFonAvp,IdEstado,Inactivo,CdLocCue,FechaAdd,IdUsuario,DecRenta,NivelEduc)
 VALUES (@pmIdEmpleado,@pmApellidos,@pmNombres,@pmCodigo,@pmTipoId,@pmDv,@pmIdLugarCed,@pmDireccion,@pmIdLocal,@pmTelefono,@pmTelMovil,@pme_mail,@pmVvdaPropia,@pmFecNacmto,@pmLugarNacmto,@pmTipoSangre,@pmFactorRh,@pmSexo,@pmIdEstCivil,@pmNHijos,@pmLibMilitar,@pmClaseLib,@pmFechaLib,@pmDistMil,@pmCertJudicial,@pmFecJudicial,@pmVigJudicial,@pmPasporte,@pmVigPaspte,@pmLicencia,@pmIdLugar,@pmCatLicencia,@pmFecLicencia,@pmVigLicencia
,@pmIdProf,@pmTallaCam,@pmTallaPan,@pmTallaZap,@pmUsaGafas,@pmConyugue,@pmConyFecNac,@pmConyTrabaja,@pmConyEmpresa,@pmConyCargo,@pmConyFing,@pmConyTel,@pmIdFonPen,@pmIdFonEps,@pmIdFonArp,@pmIdFonCes,@pmIdCajaCom,@pmIdClase,@pmNumCuenta,@pmIdBanco,@pmNContrato,@pmFecVincula,@pmFecUltAum,@pmFecUltCes,@pmFecUltPri,@pmFecUltVac,@pmFecUltIng,@pmFecUltRet,@pmFecUltDot,@pmFecUltExm,@pmFecUltCap,@pmFecUltParc,@pmFotoEmp,@pmFotoLic
,@pmFotoFirma,@pmNCAnterior,@pmFecIngAnt,@pmFecRetAnt,@pmEsCondtor,@pmpVehiculo,@pmObservacion,@pmCdFonAvp,@pmIdEstado,@pmInactivo,@pmCdLocCue,@pmFechaAdd,@pmIdUsuario,@pmDecRenta,@pmNivelEduc)
GO
/****** Object:  StoredProcedure [dbo].[paInsEmpleados_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEmpleados_Sel] @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16),@pmNewCodigo VARCHAR(16)
,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Empleados (IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen
,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,IdClase,NumCuenta,IdBanco,NContrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FotoEmp,FotoLic,FotoFirma,NCAnterior,FecIngAnt,FecRetAnt,FecUltParc,EsCondtor,pVehiculo,Observacion,IdEstado,CdFonAvp,Inactivo,CdLocCue,FechaAdd,IdUsuario,DecRenta,NivelEduc)
 SELECT  @pmNewCedula,Apellidos,Nombres,@pmNewCodigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen
,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,IdClase,NumCuenta,IdBanco,NContrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FotoEmp,FotoLic,FotoFirma,NCAnterior,FecIngAnt,FecRetAnt,FecUltParc,EsCondtor,pVehiculo,Observacion,IdEstado,CdFonAvp,Inactivo,CdLocCue,@pmFechaAdd,@pmIdUsuario,DecRenta,NivelEduc
 FROM  Empleados WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsEntArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEntArticulos] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmEntradas DECIMAL(14,4)
,@pmSalidas DECIMAL(14,4),@pmVrUnitario MONEY,@pmTarifaIva DECIMAL(14,4),@pmVrIva MONEY,@pmTarifaDct DECIMAL(14,4),@pmVrDcto MONEY,@pmTipOrd VARCHAR(3)
,@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2)
 AS 
 INSERT INTO Trn_EntArticulos (TipDoc,Entrada,IdCia,Item,IdProducto,IdBodega,Entradas,Salidas,VrUnitario,TarifaIva,VrIva,TarifaDct,VrDcto,TipOrd,NumOrden,IdCiaOrd,TipSal,NumSalida,IdCiaSal)
 VALUES (@pmTipDoc,@pmEntrada,@pmIdCia,@pmItem,@pmIdProducto,@pmIdBodega,@pmEntradas,@pmSalidas,@pmVrUnitario,@pmTarifaIva,@pmVrIva,@pmTarifaDct
,@pmVrDcto,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmTipSal,@pmNumSalida,@pmIdCiaSal)
GO
/****** Object:  StoredProcedure [dbo].[paInsEntidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEntidades] @pmIdTabla VARCHAR(20),@pmNivelRel INT,@pmCamposPK VARCHAR(50),@pmFngKey BIT
,@pmSp_Qry VARCHAR(30),@pmSp_Qpmt VARCHAR(50),@pmSp_Ins VARCHAR(30),@pmSp_Upd VARCHAR(30),@pmSp_Del VARCHAR(30)
 AS 
 INSERT INTO Sys_Entidades (IdTabla,NivelRel,CamposPK,FngKey,Sp_Qry,Sp_Qpmt,Sp_Ins,Sp_Upd,Sp_Del)
 VALUES (@pmIdTabla,@pmNivelRel,@pmCamposPK,@pmFngKey,@pmSp_Qry,@pmSp_Qpmt,@pmSp_Ins,@pmSp_Upd,@pmSp_Del)
GO
/****** Object:  StoredProcedure [dbo].[paInsEntradas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmNitFletes VARCHAR(16),@pmTipOdc VARCHAR(3)
,@pmOCompra INT,@pmIdCiaOdc CHAR(2),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmDocEquiv VARCHAR(3),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4)
,@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT
,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrRetFlete MONEY,@pmVrIcaFlete MONEY,@pmCodTarRetFle VARCHAR(4),@pmCodTarIcaFle VARCHAR(4),@pmFletesCosto BIT,@pmVrIvaMvc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmCodTarifBom VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4)
,@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmTipoSA VARCHAR(3),@pmNumSalAlm INT,@pmCdCiaSA CHAR(2),@pmVrImpuCons MONEY,@pmVrSobtasaCons MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmTipSop VARCHAR(3),@pmNumDocSop INT,@pmCdCiaSop CHAR(2),@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Entradas (TipDoc,Entrada,IdCia,Fecha,IdConcepto,IdProv,Factura,FechaFac,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,IdPlazo,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva
,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CdCCosto,CdSubCos,TipEgr,Egreso,IdCiaEgr,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,TipoSA,NumSalAlm,CdCiaSA,VrImpuCons,VrSobtasaCons,BaseIvaIgp,VrIvaIngProd,TipSop,NumDocSop,CdCiaSop,ImpAviTab,TarifaAvta,CodTarifAvta,VrImpuBA,VrImpuCUP)
 VALUES (@pmTipDoc,@pmEntrada,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdProv,@pmFactura,@pmFechaFac,@pmFechaVence,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrOtros,@pmVrSobretasa,@pmVrImpGlobal,@pmVrCargos,@pmVrOtrDcto,@pmVrNeto,@pmCantidad,@pmNitFletes
, @pmVrRetFlete,@pmVrIcaFlete,@pmCodTarRetFle,@pmCodTarIcaFle,@pmFletesCosto,@pmTipOdc,@pmOCompra,@pmIdCiaOdc,@pmMulPlazos,@pmIdPlazo,@pmCxPagar,@pmDocEquiv,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmCdCCosto,@pmCdSubCos,@pmTipEgr,@pmEgreso,@pmIdCiaEgr,@pmModalidad,@pmOrigenAdd
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrIvaMvc,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmCodTarifBom,@pmVrBomberil,@pmTarifaBom,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmVrImpCarbono,@pmTipoSA,@pmNumSalAlm,@pmCdCiaSA,@pmVrImpuCons,@pmVrSobtasaCons,@pmBaseIvaIgp,@pmVrIvaIngProd,@pmTipSop,@pmNumDocSop,@pmCdCiaSop,@pmImpAviTab,@pmTarifaAvta,@pmCodTarifAvta,@pmVrImpuBA,@pmVrImpuCUP)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEstaciones] @pmIdEstacion CHAR(2),@pmEstacion VARCHAR(50)
 AS 
 INSERT INTO Sys_Estaciones (IdEstacion,Estacion)
 VALUES (@pmIdEstacion,@pmEstacion)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoCiv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEstadoCiv] @pmIdEstado VARCHAR(4),@pmEstCivil VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO EstadoCiv (IdEstado,EstCivil,Inactivo)
 VALUES (@pmIdEstado,@pmEstCivil,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEstadoDoc] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT
,@pmCodDcmto VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO EstadoDoc (IdEstado,Estado,NColor,CodDcmto,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmCodDcmto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEstadoGuia] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoGuia (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoOper]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEstadoOper] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoOper (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEstadoPro] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoPro (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoSer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsEstadoSer] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoSer (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoTer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEstadoTer] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoTer (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstadoVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEstadoVeh] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmOutDemand BIT,@pmInactivo BIT
 AS 
 INSERT INTO EstadoVeh (IdEstado,Estado,NColor,OutDemand,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmOutDemand,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsEstratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsEstratos] @pmIdEstrato VARCHAR(4),@pmEstrato VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO Estratos (IdEstrato,Estrato,Inactivo)
 VALUES (@pmIdEstrato,@pmEstrato,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsExpLicencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsExpLicencias] @pmIdLugar VARCHAR(8),@pmLugarLic VARCHAR(50),@pmCodDpto VARCHAR(8)
,@pmDpto VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO ExpLicencias (IdLugar,LugarLic,CodDpto,Dpto,Inactivo)
 VALUES (@pmIdLugar,@pmLugarLic,@pmCodDpto,@pmDpto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsFactcon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFactcon] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmnClieCon VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrCargos MONEY
,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4),@pmCantPuntos DECIMAL(14,4),@pmPuntosAcum DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4)
,@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmCdForma VARCHAR(4),@pmNumForma VARCHAR(20),@pmDetallePago VARCHAR(250),@pmReferncia1 VARCHAR(50),@pmReferncia2 VARCHAR(50),@pmCdBanco VARCHAR(4),@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFecPedido SMALLDATETIME
,@pmModalidad VARCHAR(10),@pmPlacaVehic VARCHAR(10),@pmKmtVehic INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4)
,@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmTipoFE VARCHAR(3),@pmFechaFE SMALLDATETIME,@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Factcon (TipDoc,Factura,IdCia,Fecha,IdConcepto,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCajero,IdVend,TarifaCom
,CodTarCom,NitCliente,CdAgencia,IdCCosto,IdSubCos,IdLocal,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido,Modalidad,PlacaVehic,KmtVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
,TipoFE,FechaFE,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP,ImpAviTab,TarifaAvta,CodTarifAvta,VrBomberil,TarifaBom,CodTarifBom,VrAutRetIat,VrAutRetBom)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmFecha,@pmIdConcepto,@pmnClieCon,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrCargos,@pmVrOtrDcto,@pmVrCostos,@pmVrNeto,@pmVrEfectivo,@pmVrPagosOtr,@pmCantidad,@pmCantPuntos,@pmPuntosAcum,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv
,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmNitCliente,@pmCdAgencia,@pmIdCCosto,@pmIdSubCos,@pmIdLocal,@pmEnEfectivo,@pmCdForma,@pmNumForma,@pmDetallePago,@pmReferncia1,@pmReferncia2,@pmCdBanco,@pmTipPed,@pmPedido,@pmIdCiaPed
,@pmTipRem,@pmRemision,@pmIdCiaRem,@pmFecPedido,@pmModalidad,@pmPlacaVehic,@pmKmtVehic,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrImpCons,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmTipoFE,@pmFechaFE
,@pmCodTarArf,@pmTarifaArf,@pmVrAutRetFte,@pmCodTarAri,@pmTarifaAri,@pmVrAutRetIca,@pmVrImpuBA,@pmVrImpuCUP,@pmImpAviTab,@pmTarifaAvta,@pmCodTarifAvta,@pmVrBomberil,@pmTarifaBom,@pmCodTarifBom,@pmVrAutRetIat,@pmVrAutRetBom)
GO
/****** Object:  StoredProcedure [dbo].[paInsFacturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFacturas] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrFaltantes MONEY,@pmVrAnticipos MONEY
,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmCantidad DECIMAL(14,4),@pmCantPuntos DECIMAL(14,4),@pmPuntosAcum DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4)
,@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(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),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5)
,@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmCdRuta VARCHAR(4),@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmTipCot VARCHAR(3)
,@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmFecPedido SMALLDATETIME,@pmAutzaMora INT,@pmAutzaCupo INT,@pmModalidad VARCHAR(10),@pmKmtVehic INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmZonaFrontera INT,@pmPesoTotal DECIMAL(14,4),@pmUnidTotal DECIMAL(14,4),@pmVolTotal DECIMAL(14,4),@pmCantFalt DECIMAL(14,4),@pmVrCostoRem MONEY,@pmVrCostoAfi MONEY,@pmCodAutoRet VARCHAR(4),@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmParqueadero BIT,@pmFecCuotaParq SMALLDATETIME
,@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmTipoFE VARCHAR(3),@pmFechaFE SMALLDATETIME,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmTipoOperTra VARCHAR(10),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Facturas (TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem
,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,ZonaFrontera,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,CodAutoRet,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,TipoFE,FechaFE,BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP,ImpAviTab,TarifaAvta,CodTarifAvta,VrBomberil,TarifaBom,CodTarifBom,VrAutRetIat,VrAutRetBom,TipoOperTra)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFechaVence,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrFletes,@pmVrOtros,@pmVrCargos,@pmVrOtrDcto,@pmVrCostos,@pmVrSobretasa,@pmVrImpGlobal,@pmVrFaltantes,@pmVrAnticipos,@pmVrNeto,@pmVrAplicado,@pmCantidad,@pmCantPuntos,@pmPuntosAcum,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmIdCCosto,@pmIdSubCos,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmDirEnvio
,@pmIdLocEnv,@pmDiasEntraga,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargoContac,@pmIdForma,@pmDetallePago,@pmMulPlazos,@pmIdPlazo,@pmCdMney,@pmNitEmpTrans,@pmEmpTrans,@pmpVehiculo,@pmCdConductor,@pmCdRuta,@pmTipPed,@pmPedido,@pmIdCiaPed,@pmTipRem,@pmRemision,@pmIdCiaRem,@pmTipCot,@pmCotizacion,@pmIdCiaCot,@pmFecPedido,@pmAutzaMora,@pmAutzaCupo,@pmModalidad,@pmKmtVehic,@pmZonaFrontera,@pmPesoTotal,@pmUnidTotal,@pmVolTotal,@pmCantFalt,@pmVrCostoRem,@pmVrCostoAfi,@pmCodAutoRet,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrImpCons,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc
,@pmParqueadero,@pmFecCuotaParq,@pmBaseIvaObsq,@pmVrIvaObsequio,@pmVrImpCarbono,@pmTipoFE,@pmFechaFE,@pmBaseIvaIgp,@pmVrIvaIngProd,@pmCodTarArf,@pmTarifaArf,@pmVrAutRetFte,@pmCodTarAri,@pmTarifaAri,@pmVrAutRetIca,@pmVrImpuBA,@pmVrImpuCUP,@pmImpAviTab,@pmTarifaAvta,@pmCodTarifAvta,@pmVrBomberil,@pmTarifaBom,@pmCodTarifBom,@pmVrAutRetIat,@pmVrAutRetBom,@pmTipoOperTra)
GO
/****** Object:  StoredProcedure [dbo].[paInsFactVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFactVales] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT
,@pmTipRad VARCHAR(3),@pmnRadica INT,@pmIdCiaRad CHAR(2),@pmItemRad INT
 AS 
 INSERT INTO Trn_FactVales (TipDoc,Factura,IdCia,Item,TipRad,nRadica,IdCiaRad,ItemRad)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmItem,@pmTipRad,@pmnRadica,@pmIdCiaRad,@pmItemRad)
GO
/****** Object:  StoredProcedure [dbo].[paInsFcAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFcAbonos] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME
,@pmIdVehiculo VARCHAR(10),@pmnSemana INT,@pmVrAbono MONEY,@pmDescripcion VARCHAR(150)
 AS 
 INSERT INTO Trn_FcAbonos (TipRec,Recibo,IdCia,Item,Fecha,IdVehiculo,nSemana,VrAbono,Descripcion)
 VALUES (@pmTipRec,@pmRecibo,@pmIdCia,@pmItem,@pmFecha,@pmIdVehiculo,@pmnSemana,@pmVrAbono,@pmDescripcion)
GO
/****** Object:  StoredProcedure [dbo].[paInsFcCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFcCausacion] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecCausac SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmVrNeto MONEY,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FcCausacion (TipDoc,NumDoc,IdCia,Fecha,FecCausac,IdConcepto,VrNeto,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumDoc,@pmIdCia,@pmFecha,@pmFecCausac,@pmIdConcepto,@pmVrNeto,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado
,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFcNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFcNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT
,@pmVrNota MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmTipRec VARCHAR(3),@pmReciboFc INT,@pmIdCiaRec CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FcNotas (TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdVehiculo,IdPropietario,IdConductor,VehPropio,VrNota,VrNeto,VrAplicado,CdCCosto,CdSubCos,Referencia,TipRec,ReciboFc,IdCiaRec,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmVehPropio,@pmVrNota,@pmVrNeto,@pmVrAplicado,@pmCdCCosto,@pmCdSubCos,@pmReferencia,@pmTipRec,@pmReciboFc,@pmIdCiaRec
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFcSemanas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFcSemanas] @pmIdVehiculo VARCHAR(10),@pmnSemana INT,@pmNumCargue INT,@pmCiaCargue CHAR(2),@pmTipoSem INT,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrCargo MONEY
,@pmVrOtros MONEY,@pmVrPagado MONEY,@pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCiaRec CHAR(2),@pmFechaPago SMALLDATETIME,@pmObservacion VARCHAR(250)
, @pmFecSemIni SMALLDATETIME, @pmFecSemFin SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FcSemanas (IdVehiculo,nSemana,NumCargue,CiaCargue,TipoSem,Fecha,FecVence,VrCargo,VrOtros,VrPagado,TipRec,Recibo,IdCiaRec,FechaPago,Observacion,FecSemIni,FecSemFin,TimeSys,IdUsuario)
 VALUES (@pmIdVehiculo,@pmnSemana,@pmNumCargue,@pmCiaCargue,@pmTipoSem,@pmFecha,@pmFecVence,@pmVrCargo,@pmVrOtros,@pmVrPagado,@pmTipRec,@pmRecibo,@pmIdCiaRec,@pmFechaPago
,@pmObservacion,@pmFecSemIni,@pmFecSemFin,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFields]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFields] @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20),@pmDescripcion VARCHAR(50),@pmTipoDato VARCHAR(15),@pmLongMax INT,@pmRequerido BIT,@pmPmryKey BIT
,@pmFmtValue VARCHAR(20),@pmDftValue VARCHAR(20),@pmAliasFld VARCHAR(20),@pmAliasQry2 VARCHAR(20),@pmIndField INT,@pmTipoEntidad VARCHAR(5),@pmLstTipo VARCHAR(5),@pmLstClnaValor VARCHAR(20)
,@pmLstClnaLista VARCHAR(50),@pmLstQuery VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO Sys_Fields (IdEntidad,IdCampo,Descripcion,TipoDato,LongMax,Requerido,PmryKey,FmtValue,DftValue,AliasFld,AliasQry2,IndField,TipoEntidad,LstTipo,LstClnaValor,LstClnaLista,LstQuery,Inactivo)
 VALUES (@pmIdEntidad,@pmIdCampo,@pmDescripcion,@pmTipoDato,@pmLongMax,@pmRequerido,@pmPmryKey,@pmFmtValue,@pmDftValue,@pmAliasFld,@pmAliasQry2,@pmIndField,@pmTipoEntidad
,@pmLstTipo,@pmLstClnaValor,@pmLstClnaLista,@pmLstQuery,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFijos] @pmIdCargo VARCHAR(4),@pmConcepto VARCHAR(100), @pmObligatorio BIT, @pmTipoAplica VARCHAR(10),  @pmDiasSemana VARCHAR(20), @pmDiasMes VARCHAR(100)
, @pmValorMensual MONEY, @pmValorDiario MONEY, @pmIdCuentaDeb VARCHAR(16), @pmIdCuentaCre VARCHAR(16), @pmIdCueDebVp VARCHAR(16), @pmIdCueCreVp VARCHAR(16),@pmInactivo BIT
,@pmNCuotas INT,@pmDiasVcmto VARCHAR(50),@pmOrdenAbono INT,@pmTipoDcto CHAR(1),@pmDctoPpago DECIMAL(14,4),@pmVrCargoAdic MONEY,@pmFecLimiteIni SMALLDATETIME,@pmFecLimiteFin SMALLDATETIME
,@pmCdTarifaIva VARCHAR(4),@pmCdTarifaRet VARCHAR(4),@pmCdCuentaIva VARCHAR(16),@pmCdCuentaRet VARCHAR(16),@pmCdCuentaIca VARCHAR(16),@pmCodFEDian VARCHAR(20),@pmIvaIncluido BIT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
AS
INSERT INTO Fijos (IdCargo,Concepto,Obligatorio,TipoAplica,DiasSemana,DiasMes,ValorMensual,ValorDiario,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,NCuotas,DiasVcmto,OrdenAbono,TipoDcto,DctoPpago
,VrCargoAdic,FecLimiteIni,FecLimiteFin,Inactivo,FechaAdd,IdUsuario,CdTarifaIva,CdTarifaRet,CdCuentaIva,CdCuentaRet,CdCuentaIca,CodFEDian,IvaIncluido)
 VALUES (@pmIdCargo,@pmConcepto, @pmObligatorio, @pmTipoAplica, @pmDiasSemana, @pmDiasMes
, @pmValorMensual, @pmValorDiario, @pmIdCuentaDeb, @pmIdCuentaCre, @pmIdCueDebVp, @pmIdCueCreVp
,@pmNCuotas,@pmDiasVcmto,@pmOrdenAbono,@pmTipoDcto,@pmDctoPpago,@pmVrCargoAdic,@pmFecLimiteIni,@pmFecLimiteFin,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmCdTarifaIva,@pmCdTarifaRet,@pmCdCuentaIva,@pmCdCuentaRet,@pmCdCuentaIca,@pmCodFEDian,@pmIvaIncluido)
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos_Cla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFijos_Cla] @pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4),@pmValorMensual MONEY,@pmValorDiario MONEY
AS
 INSERT INTO  Fijos_Cla  (IdCargo,IdClase,ValorMensual,ValorDiario )
 VALUES (@pmIdCargo,@pmIdClase,@pmValorMensual,@pmValorDiario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos_Cue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInsFijos_Cue] @pmIdCargo VARCHAR(4), @pmIdAdmon VARCHAR(4),@pmIdCuentaDeb VARCHAR(16), @pmIdCuentaCre VARCHAR(16)
, @pmIdCueDebVp VARCHAR(16),@pmIdCueCreVp VARCHAR(16),@pmIdCuentaIva VARCHAR(16),@pmIdCuentaRet VARCHAR(16),@pmIdCuentaIca VARCHAR(16)
AS
 INSERT INTO Fijos_Cue (IdCargo,IdAdmon,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,IdCuentaIva,IdCuentaRet,IdCuentaIca)
 VALUES (@pmIdCargo,@pmIdAdmon,@pmIdCuentaDeb,@pmIdCuentaCre,@pmIdCueDebVp,@pmIdCueCreVp,@pmIdCuentaIva,@pmIdCuentaRet,@pmIdCuentaIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsFijos_Veh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFijos_Veh] @pmIdCargo VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmValorMensual MONEY,@pmValorDiario MONEY,@pmExcluir BIT
AS
 INSERT INTO Fijos_Veh (IdCargo,IdVehiculo,ValorMensual, ValorDiario,  Excluir)
 VALUES (@pmIdCargo,@pmIdVehiculo,@pmValorMensual, @pmValorDiario,  @pmExcluir)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFinAbonos] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCiaPre CHAR(2)
,@pmItemPre INT,@pmTotalAbono MONEY,@pmVrBaseCms MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16)
,@pmComision DECIMAL(14,4),@pmCantGal DECIMAL(14,4),@pmDetalle VARCHAR(150),@pmTipoAplica INT,@pmFecPago SMALLDATETIME,@pmTimeSys SMALLDATETIME
 AS 
 INSERT INTO Trn_FinAbonos (TipRec,Recibo,IdCia,Item,Fecha,TipDoc,IdPrestamo,IdCiaPre,ItemPre,TotalAbono,VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,CantGal,Detalle,TipoAplica,FecPago,TimeSys)
 VALUES (@pmTipRec,@pmRecibo,@pmIdCia,@pmItem,@pmFecha,@pmTipDoc,@pmIdPrestamo,@pmIdCiaPre,@pmItemPre,@pmTotalAbono,@pmVrBaseCms,@pmIdCliente,@pmIdAgencia
,@pmIdVend,@pmComision,@pmCantGal,@pmDetalle,@pmTipoAplica,@pmFecPago,@pmTimeSys)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAfavor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFinAfavor] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmVrAFavor MONEY
,@pmVrOtrosDb MONEY,@pmVrAbono MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmCodLinCred VARCHAR(4),@pmConcepto VARCHAR(10)
 AS 
 INSERT INTO Trn_FinAfavor (TipDoc,Recibo,IdCia,Fecha,VrAFavor,VrOtrosDb,VrAbono,IdCliente,IdAgencia,IdVend,CodLinCred,Concepto)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmVrAFavor,@pmVrOtrosDb,@pmVrAbono,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmCodLinCred,@pmConcepto)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAlmacenes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinAlmacenes] @pmIdAlmacen VARCHAR(4),@pmAlmacen VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO FinAlmacenes (IdAlmacen,Almacen,Inactivo)
 VALUES (@pmIdAlmacen,@pmAlmacen,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAmtza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinAmtza] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecCausac SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmNumDias INT,@pmVrCuota MONEY,@pmVrCapital MONEY
,@pmVrInteres MONEY,@pmVrSaldo MONEY,@pmTasaEfeMes DECIMAL(16,8),@pmTasaEfeDia DECIMAL(16,8),@pmCausacion INT,@pmCdCiaCausac CHAR(2),@pmVrCuoCausac MONEY,@pmVrIntCausac MONEY,@pmVrSaldoCausac MONEY,@pmVrSeguroCuo MONEY
,@pmVrCustodia MONEY,@pmVrProrroga MONEY,@pmTasaCustodia DECIMAL(16,8),@pmFecInicioPM SMALLDATETIME,@pmFecFinalPM SMALLDATETIME,@pmDiasInteresPM INT,@pmVrInteresPM MONEY
 AS 
 INSERT INTO Trn_FinAmtza (TipDoc,IdPrestamo,IdCia,Item,FecCausac,FecVence,NumDias,VrCuota,VrCapital,VrInteres,VrSaldo,TasaEfeMes,TasaEfeDia,Causacion,CdCiaCausac,VrCuoCausac,VrIntCausac,VrSaldoCausac,VrSeguroCuo,VrCustodia,VrProrroga,TasaCustodia
,FecInicioPM,FecFinalPM,DiasInteresPM,VrInteresPM)
 VALUES (@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItem,@pmFecCausac,@pmFecVence,@pmNumDias,@pmVrCuota,@pmVrCapital,@pmVrInteres,@pmVrSaldo,@pmTasaEfeMes,@pmTasaEfeDia,@pmCausacion
,@pmCdCiaCausac,@pmVrCuoCausac,@pmVrIntCausac,@pmVrSaldoCausac,@pmVrSeguroCuo,@pmVrCustodia,@pmVrProrroga,@pmTasaCustodia,@pmFecInicioPM,@pmFecFinalPM,@pmDiasInteresPM,@pmVrInteresPM)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinAportes] @pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecLiquida SMALLDATETIME,@pmCodCia CHAR(2),@pmCodGrupo VARCHAR(4),@pmCodTipoTerc VARCHAR(4),@pmValorTotal MONEY,@pmBaseApo MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinAportes (TipLiq,NumLiquida,IdCia,Fecha,FecLiquida,CodCia,CodGrupo,CodTipoTerc,ValorTotal,BaseApo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,Anulado,NumDev,FecDev,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipLiq,@pmNumLiquida,@pmIdCia,@pmFecha,@pmFecLiquida,@pmCodCia,@pmCodGrupo,@pmCodTipoTerc,@pmValorTotal,@pmBaseApo,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmAnulado,@pmNumDev,@pmFecDev,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCanAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinCanAportes] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmValorTotal MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(2000),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinCanAportes (TipDoc,NumNota,IdCia,Fecha,IdCliente,IdAgencia,ValorTotal,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,FecDev,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmIdCliente,@pmIdAgencia,@pmValorTotal,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmFecDev,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCauMora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinCauMora] @pmTipoProc VARCHAR(3),@pmNumProc INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCiaPre CHAR(2),@pmItemPre INT,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmFecVence SMALLDATETIME,@pmVrTotal MONEY,@pmVrAbonado MONEY,@pmFecUltLiq SMALLDATETIME,@pmFecIniLiq SMALLDATETIME,@pmFecFinLiq SMALLDATETIME
,@pmDiasLiquida INT,@pmDiasGracia INT,@pmBaseLiquida MONEY,@pmTasaEA DECIMAL(16,8),@pmTasaEM DECIMAL(16,8),@pmTasaDia DECIMAL(16,8),@pmVrLiquida MONEY,@pmTarifaIva DECIMAL(14,4),@pmVrIvaInt MONEY,@pmNumNotaDb INT,@pmNumComp INT
,@pmCdLinCred VARCHAR(4),@pmNCuotaLiq INT,@pmTarifaRet DECIMAL(14,4),@pmVrRetFte MONEY
 AS 
 INSERT INTO Trn_FinCauMora (TipoProc,NumProc,IdCia,Item,TipDoc,IdPrestamo,IdCiaPre,ItemPre,IdCliente,IdAgencia,IdVend,FecVence,VrTotal,VrAbonado,FecUltLiq,FecIniLiq,FecFinLiq,DiasLiquida,DiasGracia,BaseLiquida
,TasaEA,TasaEM,TasaDia,VrLiquida,TarifaIva,VrIvaInt,NumNotaDb,NumComp,CdLinCred,NCuotaLiq,TarifaRet,VrRetFte)
 VALUES (@pmTipoProc,@pmNumProc,@pmIdCia,@pmItem,@pmTipDoc,@pmIdPrestamo,@pmIdCiaPre,@pmItemPre,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmFecVence,@pmVrTotal,@pmVrAbonado,@pmFecUltLiq,@pmFecIniLiq,@pmFecFinLiq
,@pmDiasLiquida,@pmDiasGracia,@pmBaseLiquida,@pmTasaEA,@pmTasaEM,@pmTasaDia,@pmVrLiquida,@pmTarifaIva,@pmVrIvaInt,@pmNumNotaDb,@pmNumComp,@pmCdLinCred,@pmNCuotaLiq,@pmTarifaRet,@pmVrRetFte)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinCausacion] @pmTipoProc VARCHAR(3),@pmNumProc INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTotalCapital MONEY
,@pmTotalInteres MONEY,@pmTotalIntMora MONEY,@pmTipoCred VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmAnulado BIT,@pmObservacion VARCHAR(250)
,@pmEdoCausac INT,@pmTotalOtros MONEY,@pmTipoLiquida VARCHAR(10),@pmTotalCustodia MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinCausacion (TipoProc,NumProc,IdCia,Fecha,TotalCapital,TotalInteres,TotalIntMora,TotalOtros,TipoLiquida,TipoCred,TipCom,Comprobante,Anulado,Observacion,EdoCausac,TimeSys,IdUsuario,TotalCustodia)
 VALUES (@pmTipoProc,@pmNumProc,@pmIdCia,@pmFecha,@pmTotalCapital,@pmTotalInteres,@pmTotalIntMora,@pmTotalOtros,@pmTipoLiquida,@pmTipoCred,@pmTipCom,@pmComprobante,@pmAnulado
,@pmObservacion,@pmEdoCausac,@pmTimeSys,@pmIdUsuario,@pmTotalCustodia)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinClieSaldos] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 INSERT INTO FinClieSaldos (IdClie,CdAgencia,IdCia,VrSaldo)
 VALUES (@pmIdClie,@pmCdAgencia,@pmIdCia,@pmVrSaldo)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldos_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFinClieSaldos_Uni] @pmIdClie VARCHAR(16),@pmIdClieDos VARCHAR(16),@pmNewClie VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdClie FROM FinClieSaldos WHERE IdClie=@pmIdClie OR IdClie=@pmIdClieDos)
  INSERT INTO FinClieSaldos (IdClie,CdAgencia,IdCia,VrSaldo)
  SELECT @pmNewClie,CdAgencia,IdCia,SUM(VrSaldo)
  FROM FinClieSaldos  
  WHERE  IdClie=@pmIdClie OR IdClie=@pmIdClieDos
  GROUP BY CdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldosLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinClieSaldosLin] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4)
,@pmIdCia CHAR(2),@pmVrSaldoCap MONEY,@pmVrSaldoInt MONEY,@pmVrSaldoOtro MONEY
 AS 
 INSERT INTO FinClieSaldosLin (IdClie,CdAgencia,IdLinea,IdCia,VrSaldoCap,VrSaldoInt,VrSaldoOtro)
 VALUES (@pmIdClie,@pmCdAgencia,@pmIdLinea,@pmIdCia,@pmVrSaldoCap,@pmVrSaldoInt,@pmVrSaldoOtro)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinClieSaldosLin_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFinClieSaldosLin_Uni] @pmIdClie VARCHAR(16),@pmIdClieDos VARCHAR(16),@pmNewClie VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdClie FROM FinClieSaldosLin WHERE IdClie=@pmIdClie OR IdClie=@pmIdClieDos)
  INSERT INTO FinClieSaldosLin (IdClie,CdAgencia,IdLinea,IdCia,VrSaldoCap,VrSaldoInt,VrSaldoOtro)
  SELECT @pmNewClie,CdAgencia,IdLinea,IdCia,SUM(VrSaldoCap),SUM(VrSaldoInt),SUM(VrSaldoOtro)
  FROM FinClieSaldosLin 
  WHERE  IdClie=@pmIdClie OR IdClie=@pmIdClieDos
  GROUP BY CdAgencia,IdLinea,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsFinConcFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinConcFactura] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmTipoConc VARCHAR(10),@pmGravado BIT,@pmCodTarIva VARCHAR(4)
,@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmCdCueIva VARCHAR(16),@pmCdCueRet VARCHAR(16),@pmCdCueIca VARCHAR(16),@pmInactivo BIT,@pmCodFEDian VARCHAR(20)
,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO FinConcFactura (IdConcepto,Concepto,TipoConc,Gravado,CodTarIva,CodTarRet,CodTarIca,IdCuenta,CdCueIva,CdCueRet,CdCueIca,Inactivo,CodFEDian,FechaAdd,IdUsuario)
 VALUES (@pmIdConcepto,@pmConcepto,@pmTipoConc,@pmGravado,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmIdCuenta
,@pmCdCueIva,@pmCdCueRet,@pmCdCueIca,@pmInactivo,@pmCodFEDian,@pmFechaAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinConvenios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinConvenios] @pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmValorTotal MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(2000),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinConvenios (TipLiq,NumLiquida,IdCia,Fecha,IdConcepto,IdProveedor,NumFactura,FecFactura,FecVence,ValorTotal,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,NumDev,FecDev,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipLiq,@pmNumLiquida,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdProveedor,@pmNumFactura,@pmFecFactura,@pmFecVence,@pmValorTotal,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmNumDev,@pmFecDev,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinCuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinCuotas] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmNumCuota INT,@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrTotal MONEY,@pmVrAbonado MONEY
,@pmTipoTasa VARCHAR(10),@pmDTF_EA DECIMAL(16,8),@pmTasaNom DECIMAL(16,8),@pmSpread_TA DECIMAL(16,8),@pmTasaEfe DECIMAL(16,8),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmTipoCuota INT
,@pmNumCausacion INT,@pmIdCiaCau CHAR(2),@pmDetalle VARCHAR(250),@pmFecUltPago SMALLDATETIME,@pmConcepto VARCHAR(10),@pmFecLiqMora SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmCodLinCred VARCHAR(4)
,@pmNumFactura VARCHAR(20),@pmVrInteresFact MONEY,@pmDiasLiquida INT,@pmFecUltCausac SMALLDATETIME,@pmVrAcumCapital MONEY,@pmConvenio INT,@pmNitConvenio VARCHAR(16),@pmNumPreMora INT
,@pmTipoCausac VARCHAR(3),@pmFacturaInt INT,@pmTipFacInt VARCHAR(3),@pmNumFacInt INT,@pmCdCiaFacInt CHAR(2),@pmFechaFacInt SMALLDATETIME,@pmTarifIvaInt DECIMAL(14,4),@pmVrIvaInt MONEY,@pmTarifRetInt DECIMAL(14,4),@pmVrRetInt MONEY

 AS 
 INSERT INTO Trn_FinCuotas (TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,IdCliente,IdAgencia,Concepto,TipoCuota,TipoCausac,NumCausacion,IdCiaCau,Detalle,FecUltPago,FecLiqMora
,FechaCrea,CodLinCred,NumFactura,VrInteresFact,DiasLiquida,FecUltCausac,VrAcumCapital,Convenio,NitConvenio,NumPreMora,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt,TarifIvaInt,VrIvaInt,TarifRetInt,VrRetInt)
 VALUES (@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItem,@pmNumCuota,@pmFecha,@pmFechaVence,@pmVrTotal,@pmVrAbonado,@pmTipoTasa,@pmDTF_EA,@pmTasaNom,@pmSpread_TA,@pmTasaEfe,@pmIdCliente
,@pmIdAgencia,@pmConcepto,@pmTipoCuota,@pmTipoCausac,@pmNumCausacion,@pmIdCiaCau,@pmDetalle,@pmFecUltPago,@pmFecLiqMora,@pmFechaCrea,@pmCodLinCred,@pmNumFactura,@pmVrInteresFact,@pmDiasLiquida,@pmFecUltCausac,@pmVrAcumCapital,@pmConvenio,@pmNitConvenio,@pmNumPreMora
,@pmFacturaInt,@pmTipFacInt,@pmNumFacInt,@pmCdCiaFacInt,@pmFechaFacInt,@pmTarifIvaInt,@pmVrIvaInt,@pmTarifRetInt,@pmVrRetInt)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinDevFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinDevFac] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmIdVend VARCHAR(16),@pmIdLocal VARCHAR(8),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinDevFac (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,IdVend,IdLocal,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion
,IdEstado,TimeSys,IdCiaCrea,IdUsuario,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmFactura,@pmIdCiaDoc,@pmFecDoc,@pmIdCliente,@pmIdAgencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCargos,@pmVrOtrDcto,@pmVrNeto,@pmIdVend,@pmIdLocal
,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTarifaArf,@pmVrAutRetFte,@pmTarifaAri,@pmVrAutRetIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinDevPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinDevPre] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmVrPrestamo MONEY,@pmIdVend VARCHAR(16),@pmCxPagar BIT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinDevPre (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,IdPrestamo,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrPrestamo,IdVend,CxPagar,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmIdPrestamo,@pmIdCiaDoc,@pmFecDoc,@pmIdCliente,@pmIdAgencia,@pmVrPrestamo,@pmIdVend,@pmCxPagar,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante
,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinDevRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrRetencion MONEY
,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmVrEfectivo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmEnEfectivo BIT,@pmReferencia VARCHAR(50),@pmNumAutoriza INT
,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinDevRec (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,IdAgencia,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,IdVend,TarifaCom,CodTarCom,EnEfectivo,Referencia,NumAutoriza,ModdDev,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmRecibo,@pmIdCiaDoc,@pmFecDoc,@pmFecPago,@pmIdCliente,@pmIdAgencia,@pmVrRecibido,@pmVrSubTotal,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrOtros,@pmVrOtrDcto,@pmVrPagosMas,@pmVrNeto,@pmVrAplicado,@pmVrAnticipo,@pmVrEfectivo,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmIdVend,@pmTarifaCom
,@pmCodTarCom,@pmEnEfectivo,@pmReferencia,@pmNumAutoriza,@pmModdDev,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinFactDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinFactDet] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmTipoReg VARCHAR(10),@pmCantidad DECIMAL(14,4)
,@pmVrUnitario MONEY,@pmVrTotal MONEY,@pmTarifIva DECIMAL(14,4),@pmVrIva MONEY,@pmTarifRet DECIMAL(14,4),@pmVrRetfte MONEY,@pmTarifIca DECIMAL(14,4),@pmVrRetica MONEY,@pmnPrestamo INT,@pmCdCiaPrest CHAR(2)
,@pmFecIniLiq SMALLDATETIME,@pmFecFinLiq SMALLDATETIME,@pmCantDias INT,@pmCdTarifIva VARCHAR(4),@pmCdTarifRet VARCHAR(4),@pmCdTarifIca VARCHAR(4),@pmTarifDcto DECIMAL(14,4),@pmVrDcto MONEY,@pmCdTarifDct VARCHAR(4)
 AS 
 INSERT INTO Trn_FinFactDet (TipDoc,Factura,IdCia,Item,IdConcepto,Concepto,TipoReg,Cantidad,VrUnitario,VrTotal,TarifIva,VrIva,TarifRet,VrRetfte,TarifIca,VrRetica,TarifDcto,VrDcto,nPrestamo,CdCiaPrest,FecIniLiq,FecFinLiq,CantDias,CdTarifIva,CdTarifRet,CdTarifIca,CdTarifDct)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmItem,@pmIdConcepto,@pmConcepto,@pmTipoReg,@pmCantidad,@pmVrUnitario,@pmVrTotal,@pmTarifIva,@pmVrIva,@pmTarifRet,@pmVrRetfte,@pmTarifIca,@pmVrRetica,@pmTarifDcto,@pmVrDcto,@pmnPrestamo
,@pmCdCiaPrest,@pmFecIniLiq,@pmFecFinLiq,@pmCantDias,@pmCdTarifIva,@pmCdTarifRet,@pmCdTarifIca,@pmCdTarifDct)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinFactint]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinFactint] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY
,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4)
,@pmIdLocal VARCHAR(8),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoFactInt VARCHAR(10),@pmCodTarRtc VARCHAR(4),@pmTarifaRtc DECIMAL(14,4),@pmTipoFE VARCHAR(3),@pmFechaFE SMALLDATETIME
,@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinFactint (TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,IdLocal,MulPlazos,IdPlazo,TipoFactInt
,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,CodTarRtc,TarifaRtc,TipoFE,FechaFE,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFechaVence,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCargos,@pmVrOtrDcto,@pmVrNeto,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmIdCCosto,@pmIdSubCos
,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmIdLocal,@pmMulPlazos,@pmIdPlazo,@pmTipoFactInt,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCodTarRtc,@pmTarifaRtc,@pmTipoFE,@pmFechaFE,@pmCodTarArf,@pmTarifaArf,@pmVrAutRetFte,@pmCodTarAri,@pmTarifaAri,@pmVrAutRetIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinFacturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinFacturas] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmNumFactura VARCHAR(20),@pmFecha SMALLDATETIME
,@pmFechaVence SMALLDATETIME,@pmVrFactura MONEY,@pmVrInteres MONEY,@pmDiasLiq DECIMAL(14,4),@pmTasaEfeMes DECIMAL(16,8),@pmTasaEfeDia DECIMAL(16,8),@pmFechaPago SMALLDATETIME,@pmItemPago INT
,@pmFacturado BIT,@pmTipFac VARCHAR(3),@pmFacturaInt INT,@pmFecFactura SMALLDATETIME,@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
,@pmVrAbono MONEY,@pmCdCiaFac CHAR(2),@pmFechaLiq SMALLDATETIME,@pmDiasPlazo INT
 AS 
 INSERT INTO Trn_FinFacturas (TipDoc,IdPrestamo,IdCia,Item,NumFactura,Fecha,FechaVence,VrFactura,VrInteres,DiasLiq,TasaEfeMes,TasaEfeDia,FechaPago,ItemPago,FechaLiq,FecInicio,FecFinal,VrAbono,Facturado,TipFac,FacturaInt,CdCiaFac,FecFactura,DiasPlazo)
 VALUES (@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItem,@pmNumFactura,@pmFecha,@pmFechaVence,@pmVrFactura,@pmVrInteres,@pmDiasLiq
,@pmTasaEfeMes,@pmTasaEfeDia,@pmFechaPago,@pmItemPago,@pmFechaLiq,@pmFecInicio,@pmFecFinal,@pmVrAbono,@pmFacturado,@pmTipFac,@pmFacturaInt,@pmCdCiaFac,@pmFecFactura,@pmDiasPlazo)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrSancion MONEY,@pmVrOtros MONEY,@pmVrNeto MONEY
,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16)
,@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmFecDcm SMALLDATETIME,@pmCdForma VARCHAR(4),@pmNumCheque VARCHAR(20),@pmCdBanco VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmModalidad VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinNotas (TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrSancion,VrOtros,VrNeto,VrAplicado,VrAnticipo,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,FecDcm,CdForma,NumCheque,CdBanco
,MulPlazos,IdPlazo,Modalidad,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFechaVence,@pmVrSubTotal,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrSancion,@pmVrOtros,@pmVrNeto,@pmVrAplicado,@pmVrAnticipo,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv
,@pmIdCCosto,@pmIdSubCos,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmReferencia,@pmpVehiculo,@pmCdConductor,@pmTipDcm,@pmDocumento,@pmIdCiaDcm,@pmFecDcm,@pmCdForma,@pmNumCheque,@pmCdBanco,@pmMulPlazos,@pmIdPlazo,@pmModalidad,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinPagos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinPagos] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmNumero VARCHAR(20),@pmFecha SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmVrCuota MONEY
,@pmEdoForma INT,@pmCdBanco VARCHAR(4),@pmCtaCheque VARCHAR(30),@pmDetalle VARCHAR(150),@pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCiaRec CHAR(2),@pmVrLiqMora MONEY,@pmFecLiqMora SMALLDATETIME
,@pmVrRecCaja MONEY,@pmTarifSeguro DECIMAL(14,4),@pmTotalSeguro DECIMAL(14,4)
 AS 
 INSERT INTO Trn_FinPagos (TipDoc,IdPrestamo,IdCia,Item,Numero,Fecha,FecPago,VrCuota,EdoForma,CdBanco,CtaCheque,Detalle,TipRec,Recibo,IdCiaRec,VrLiqMora,FecLiqMora,VrRecCaja,TarifSeguro,TotalSeguro)
 VALUES (@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItem,@pmNumero,@pmFecha,@pmFecPago,@pmVrCuota,@pmEdoForma,@pmCdBanco,@pmCtaCheque
,@pmDetalle,@pmTipRec,@pmRecibo,@pmIdCiaRec,@pmVrLiqMora,@pmFecLiqMora,@pmVrRecCaja,@pmTarifSeguro,@pmTotalSeguro)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinPrestamo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinPrestamo] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecPrestamo SMALLDATETIME,@pmFecCorte SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrPrestamo MONEY,@pmIdTasa VARCHAR(4),@pmNPlazos INT,@pmCausacion VARCHAR(10),@pmIdMora VARCHAR(4),@pmNContrato INT,@pmCdCiaCon CHAR(2)
,@pmNActaJunta INT,@pmNumCredito VARCHAR(20),@pmIdVend VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipoGarantia VARCHAR(10),@pmVrGarantia MONEY,@pmDescGarantia VARCHAR(250),@pmCxPagar BIT,@pmNumCuotaIni INT,@pmAcumCapital MONEY,@pmAcumIntereses MONEY,@pmAcumIntMora MONEY,@pmAcumCuotas INT,@pmPagosCapital MONEY,@pmPagosIntereses MONEY,@pmPagosIntMora MONEY,@pmCuotasPagadas INT
,@pmCuotasMora INT,@pmTipoAprob VARCHAR(20),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmDiaCausac INT,@pmDiaCausac2 INT,@pmDiasVence VARCHAR(50),@pmIdLinea VARCHAR(4),@pmTipoPlazo CHAR(1),@pmTipoCausac INT,@pmCdTasa2 VARCHAR(4),@pmVrSeguro MONEY
,@pmVrIntereses MONEY,@pmVrNeto MONEY,@pmVrCuota MONEY,@pmTipoCredito VARCHAR(10),@pmCalcIntMora BIT,@pmNitEmpConv VARCHAR(16),@pmCuotasConv INT,@pmRefinanciado INT,@pmNumPrestRef INT,@pmCiaPrestRef CHAR(2),@pmVrRefinanc MONEY,@pmDescRefinanc  VARCHAR(150),@pmCdAlmacen VARCHAR(4),@pmCauAnticipado BIT,@pmCdCtaPago VARCHAR(4)
,@pmVrInteresPM MONEY,@pmCantDiasPM INT,@pmNumNotaIni INT,@pmNumNotaFin INT,@pmFechaFinPM SMALLDATETIME,@pmIndDebAuto INT,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinPrestamo (TipDoc,IdPrestamo,IdCia,Fecha,FecPrestamo,FecCorte,DiaCausac,DiaCausac2,DiasVence,IdConcepto,IdCliente,IdAgencia,VrPrestamo,IdLinea,IdTasa,NPlazos,TipoPlazo,Causacion,IdMora,NContrato,CdCiaCon,NActaJunta,NumCredito,IdVend,pVehiculo,CdConductor,TipoGarantia,VrGarantia,DescGarantia,CxPagar,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora
,TipoAprob,TipoCausac,CdTasa2,VrSeguro,VrIntereses,VrNeto,VrCuota,TipoCredito,CalcIntMora,NitEmpConv,CuotasConv,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CdAlmacen,CauAnticipado,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,CdCtaPago,VrInteresPM,CantDiasPM,NumNotaIni,NumNotaFin,FechaFinPM,IndDebAuto)
 VALUES (@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmFecha,@pmFecPrestamo,@pmFecCorte,@pmDiaCausac,@pmDiaCausac2,@pmDiasVence,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmVrPrestamo,@pmIdLinea,@pmIdTasa,@pmNPlazos,@pmTipoPlazo,@pmCausacion,@pmIdMora,@pmNContrato,@pmCdCiaCon,@pmNActaJunta,@pmNumCredito,@pmIdVend,@pmpVehiculo,@pmCdConductor,@pmTipoGarantia,@pmVrGarantia,@pmDescGarantia
,@pmCxPagar,@pmNumCuotaIni,@pmAcumCapital,@pmAcumIntereses,@pmAcumIntMora,@pmAcumCuotas,@pmPagosCapital,@pmPagosIntereses,@pmPagosIntMora,@pmCuotasPagadas,@pmCuotasMora,@pmTipoAprob,@pmTipoCausac
,@pmCdTasa2,@pmVrSeguro,@pmVrIntereses,@pmVrNeto,@pmVrCuota,@pmTipoCredito,@pmCalcIntMora,@pmNitEmpConv,@pmCuotasConv,@pmRefinanciado,@pmNumPrestRef,@pmCiaPrestRef,@pmVrRefinanc,@pmDescRefinanc,@pmCdAlmacen,@pmCauAnticipado,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCdCtaPago,@pmVrInteresPM,@pmCantDiasPM,@pmNumNotaIni,@pmNumNotaFin,@pmFechaFinPM,@pmIndDebAuto)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinPrestGarant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinPrestGarant] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoGarant VARCHAR(20),@pmDescGarant VARCHAR(250),@pmCdInmueble VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmVrGarantia MONEY,@pmVrAvaluo MONEY,@pmPesoBruto DECIMAL(16,6),@pmPesoNeto DECIMAL(16,6),@pmPropietario VARCHAR(250),@pmDirInmueble VARCHAR(250),@pmCdCiudad VARCHAR(8),@pmMatricula VARCHAR(50),@pmEscritura VARCHAR(50),@pmNumNotaria VARCHAR(20),@pmMarcaVeh VARCHAR(20),@pmModelo VARCHAR(4)
,@pmCdBanco VARCHAR(4),@pmFecCheque SMALLDATETIME,@pmNumCheque VARCHAR(20),@pmOtroTipoVehic VARCHAR(50),@pmOtroInmueble VARCHAR(50),@pmCedFmnte1 VARCHAR(16),@pmNomFmnte1 VARCHAR(150),@pmCedFmnte2 VARCHAR(16),@pmNomFmnte2 VARCHAR(150),@pmCedFmnte3 VARCHAR(16),@pmNomFmnte3 VARCHAR(150),@pmCedFmnte4 VARCHAR(16),@pmNomFmnte4 VARCHAR(150),@pmCedFmnte5 VARCHAR(16),@pmNomFmnte5 VARCHAR(150),@pmCedFmnte6 VARCHAR(16),@pmNomFmnte6 VARCHAR(150),@pmArchivoImg VARCHAR(500),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinPrestGarant (TipDoc,IdPrestamo,IdCia,Item,TipoGarant,DescGarant,CdInmueble,CdTipoVeh,VrGarantia,VrAvaluo,PesoBruto,PesoNeto,IdUsuario,Propietario,DirInmueble,CdCiudad,Matricula,Escritura,NumNotaria,MarcaVeh,Modelo,CdBanco,FecCheque,NumCheque,OtroTipoVehic,OtroInmueble,CedFmnte1,NomFmnte1,CedFmnte2,NomFmnte2,CedFmnte3,NomFmnte3,CedFmnte4,NomFmnte4,CedFmnte5,NomFmnte5,CedFmnte6,NomFmnte6,ArchivoImg)
 VALUES (@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItem,@pmTipoGarant,@pmDescGarant,@pmCdInmueble,@pmCdTipoVeh,@pmVrGarantia,@pmVrAvaluo,@pmPesoBruto,@pmPesoNeto,@pmIdUsuario,@pmPropietario,@pmDirInmueble,@pmCdCiudad,@pmMatricula,@pmEscritura,@pmNumNotaria,@pmMarcaVeh,@pmModelo,@pmCdBanco,@pmFecCheque,@pmNumCheque,@pmOtroTipoVehic,@pmOtroInmueble,@pmCedFmnte1,@pmNomFmnte1,@pmCedFmnte2,@pmNomFmnte2,@pmCedFmnte3
,@pmNomFmnte3,@pmCedFmnte4,@pmNomFmnte4,@pmCedFmnte5,@pmNomFmnte5,@pmCedFmnte6,@pmNomFmnte6,@pmArchivoImg)
GO
/****** Object:  StoredProcedure [dbo].[paInsFinRecibos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFinRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFecPago SMALLDATETIME,@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY
,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrEfectivo MONEY,@pmVrAnticipo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4)
,@pmCodTarCom VARCHAR(4),@pmEnEfectivo BIT,@pmCdForma VARCHAR(4),@pmNumForma VARCHAR(20),@pmDetallePago VARCHAR(250),@pmCdBanco VARCHAR(4),@pmCdCta VARCHAR(4),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipoCredito VARCHAR(10),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2)
,@pmVrAboCapital MONEY,@pmLiqAboCapital INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrAboOtros MONEY,@pmVrPagoCuotas MONEY,@pmVrPagoAportes MONEY,@pmVrPagoConvenio MONEY,@pmVrAboCuotas MONEY,@pmVrAboAportes MONEY,@pmVrAboConvenio MONEY,@pmVrAntPrestamo MONEY,@pmVrAntAportes MONEY,@pmVrAntConvenio MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_FinRecibos (TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrEfectivo,VrAnticipo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,IdVend,TarifaCom,CodTarCom,EnEfectivo,CdForma,NumForma,DetallePago,CdBanco,CdCta,Referencia,pVehiculo,CdConductor
,TipoCredito,TipDcm,Documento,IdCiaDcm,VrAboCapital,LiqAboCapital,VrAboOtros,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,VrPagoCuotas,VrPagoAportes,VrPagoConvenio,VrAboCuotas,VrAboAportes,VrAboConvenio,VrAntPrestamo,VrAntAportes,VrAntConvenio)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFecPago,@pmVrRecibido,@pmVrSubTotal,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrOtros,@pmVrOtrDcto,@pmVrPagosMas,@pmVrNeto,@pmVrAplicado,@pmVrEfectivo,@pmVrAnticipo,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarRet,@pmCodTarIca
,@pmCodTarRiv,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmEnEfectivo,@pmCdForma,@pmNumForma,@pmDetallePago,@pmCdBanco,@pmCdCta,@pmReferencia,@pmpVehiculo,@pmCdConductor,@pmTipoCredito,@pmTipDcm,@pmDocumento,@pmIdCiaDcm,@pmVrAboCapital,@pmLiqAboCapital,@pmVrAboOtros,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario
,@pmVrPagoCuotas,@pmVrPagoAportes,@pmVrPagoConvenio,@pmVrAboCuotas,@pmVrAboAportes,@pmVrAboConvenio,@pmVrAntPrestamo,@pmVrAntAportes,@pmVrAntConvenio)
GO
/****** Object:  StoredProcedure [dbo].[paInsFmtDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFmtDoc] @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmPredtmnado BIT,@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT
,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 INSERT INTO Sys_FmtDoc (IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location)
 VALUES (@pmIdDoc,@pmIdForma,@pmDescripcion,@pmFormato,@pmPredtmnado,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmsp_Nombre,@pmInd_Location)
GO
/****** Object:  StoredProcedure [dbo].[paInsFmtFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFmtFactura] @pmnFormato VARCHAR(10),@pmIdDoc VARCHAR(3),@pmCdForma CHAR(2)
 AS 
 INSERT INTO Sys_FmtFactura (nFormato,IdDoc,CdForma)
 VALUES (@pmnFormato,@pmIdDoc,@pmCdForma)
GO
/****** Object:  StoredProcedure [dbo].[paInsFondos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFondos] @pmIdFondo VARCHAR(8),@pmFondo VARCHAR(100),@pmIdClase VARCHAR(4)
,@pmIdTercero VARCHAR(16),@pmCodigoEps VARCHAR(10),@pmCodigoPen VARCHAR(10),@pmCodigoArp VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Fondos (IdFondo,Fondo,IdClase,IdTercero,CodigoEps,CodigoPen,CodigoArp,Inactivo)
 VALUES (@pmIdFondo,@pmFondo,@pmIdClase,@pmIdTercero,@pmCodigoEps,@pmCodigoPen,@pmCodigoArp,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsFormasCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFormasCue] @pmIdForma VARCHAR(4),@pmIdConcepto VARCHAR(4)
,@pmIdCuenta VARCHAR(16),@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO FormasCue (IdForma,IdConcepto,IdCuenta,FechaAdd)
 VALUES (@pmIdForma,@pmIdConcepto,@pmIdCuenta,@pmFechaAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsFormaspago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFormaspago] @pmIdForma VARCHAR(4),@pmFormaPago VARCHAR(50),@pmConsecutivo INT,@pmCuadreCaja BIT,@pmRefDcmto BIT
,@pmRefNit BIT,@pmRefBco BIT,@pmRefFech BIT,@pmRefAtza BIT,@pmRefOtro BIT,@pmVldRangos BIT,@pmVleConsumo BIT
,@pmCodIntegrity VARCHAR(20),@pmCodValera VARCHAR(10),@pmCodIntCom VARCHAR(20),@pmRefProducto BIT,@pmFactTicket BIT,@pmCdMedPago VARCHAR(4),@pmValCtaPago BIT,@pmInactivo BIT
 AS 
 INSERT INTO Formaspago (IdForma,FormaPago,Consecutivo,CuadreCaja,RefDcmto,RefNit,RefBco,RefFech,RefAtza,RefOtro,VldRangos,VleConsumo,CodIntegrity,CodValera,Inactivo,CodIntCom,RefProducto,FactTicket,CdMedPago,ValCtaPago)
 VALUES (@pmIdForma,@pmFormaPago,@pmConsecutivo,@pmCuadreCaja,@pmRefDcmto,@pmRefNit,@pmRefBco,@pmRefFech,@pmRefAtza
,@pmRefOtro,@pmVldRangos,@pmVleConsumo,@pmCodIntegrity,@pmCodValera,@pmInactivo,@pmCodIntCom,@pmRefProducto,@pmFactTicket,@pmCdMedPago,@pmValCtaPago)
GO
/****** Object:  StoredProcedure [dbo].[paInsFuentesPago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFuentesPago] @pmIdFuente VARCHAR(4),@pmFuentePago VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO FuentesPago (IdFuente,FuentePago,Inactivo)
 VALUES (@pmIdFuente,@pmFuentePago,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAdicionales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatAdicionales] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrAporte MONEY,@pmVrSaldo MONEY,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatAdicionales (TipDoc,NumRegistro,IdCia,Fecha,IdConcepto,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrAporte,VrSaldo,VrAvaluo,TipoBaseLiq,TipoAfiVeh,Referencia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumRegistro,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrAporte,@pmVrSaldo,@pmVrAvaluo,@pmTipoBaseLiq,@pmTipoAfiVeh,@pmReferencia,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatAjustes] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmVrAjustes MONEY,@pmReferencia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmCiaDocRef CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
,@pmTipCau VARCHAR(3),@pmCausacion INT,@pmIdCiaCau CHAR(2),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatAjustes (TipDoc,NumAjuste,IdCia,Fecha,FechaVence,IdConcepto,Modalidad,VrAjustes,Referencia,TipDocRef,NumDocRef,CiaDocRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,TipCau,Causacion,IdCiaCau,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumAjuste,@pmIdCia,@pmFecha,@pmFechaVence,@pmIdConcepto,@pmModalidad,@pmVrAjustes,@pmReferencia,@pmTipDocRef,@pmNumDocRef,@pmCiaDocRef,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmTipCau,@pmCausacion,@pmIdCiaCau,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAjustesPror]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatAjustesPror] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmTipPror VARCHAR(3),@pmNumProceso INT,@pmIdCiaPror CHAR(2),@pmVrAjustes MONEY,@pmReferencia VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatAjustesPror (TipDoc,NumAjuste,IdCia,Fecha,IdConcepto,Modalidad,TipPror,NumProceso,IdCiaPror,VrAjustes,Referencia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumAjuste,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmTipPror,@pmNumProceso,@pmIdCiaPror,@pmVrAjustes,@pmReferencia,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatAportes] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecEmision SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVahiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmConcepto VARCHAR(20),@pmImporte MONEY,@pmVrAvaluo MONEY,@pmVrComercial MONEY,@pmVrAsegurado MONEY,@pmTipoBaseLiq CHAR(1),@pmCantidad DECIMAL(14,4)
,@pmDescripcion VARCHAR(500),@pmReferencia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmTipoAfiVeh VARCHAR(10),@pmFecLiqApo SMALLDATETIME,@pmTarifaApo DECIMAL(14,4),@pmCodTarifApo VARCHAR(4),@pmCantDiasAnt DECIMAL(14,4),@pmVrDiasAnt MONEY,@pmVrDevolucion MONEY,@pmFechaCrea SMALLDATETIME
 AS 
 INSERT INTO Trn_GatAportes (TipDoc,NumRegistro,IdCia,Item,FecEmision,FecVence,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,Concepto,Importe,VrAvaluo,VrComercial,VrAsegurado,TipoBaseLiq,Cantidad,TarifaApo,CodTarifApo,CantDiasAnt,VrDiasAnt,VrDevolucion,Descripcion,Referencia,TipDocRef,NumDocRef,TipCom,Comprobante,TipoAfiVeh,FecLiqApo,FechaCrea)
 VALUES (@pmTipDoc,@pmNumRegistro,@pmIdCia,@pmItem,@pmFecEmision,@pmFecVence,@pmIdAsociado,@pmUndVahiculo,@pmIdVehiculo,@pmnRemolque,@pmConcepto,@pmImporte,@pmVrAvaluo,@pmVrComercial,@pmVrAsegurado,@pmTipoBaseLiq,@pmCantidad,@pmTarifaApo,@pmCodTarifApo,@pmCantDiasAnt,@pmVrDiasAnt,@pmVrDevolucion,@pmDescripcion,@pmReferencia,@pmTipDocRef,@pmNumDocRef,@pmTipCom,@pmComprobante,@pmTipoAfiVeh,@pmFecLiqApo,@pmFechaCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatAvaluos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatAvaluos] @pmIdCia CHAR(2),@pmFechaAvaluo SMALLDATETIME,@pmId_Vehiculo VARCHAR(10),@pmUndVehiculo CHAR(1),@pmIdAsociado VARCHAR(16),@pmVrAvaluoAnt MONEY,@pmVrAvaluo MONEY,@pmPorcAvaluo DECIMAL(14,4),@pmNumProceso INT,@pmObservacion VARCHAR(500)
,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME
 AS 
 INSERT INTO Trn_GatAvaluos (IdCia,FechaAvaluo,Id_Vehiculo,UndVehiculo,IdAsociado,VrAvaluoAnt,VrAvaluo,PorcAvaluo,NumProceso,Observacion,IdUsuario,FechaCrea)
 VALUES (@pmIdCia,@pmFechaAvaluo,@pmId_Vehiculo,@pmUndVehiculo,@pmIdAsociado,@pmVrAvaluoAnt,@pmVrAvaluo,@pmPorcAvaluo,@pmNumProceso,@pmObservacion,@pmIdUsuario,@pmFechaCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevAdicional]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevAdicional] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrDevolucion MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevAdicional (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumRegistro,IdCiaDoc,FecDoc,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumRegistro,@pmIdCiaDoc,@pmFecDoc,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrDevolucion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevAjuPror]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevAjuPror] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(20),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevAjuPror (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumAjuste,IdCiaDoc,FecDoc,Modalidad,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumAjuste,@pmIdCiaDoc,@pmFecDoc,@pmModalidad,@pmVrDevolucion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevAjustes] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(20),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevAjustes (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumAjuste,IdCiaDoc,FecDoc,Modalidad,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumAjuste,@pmIdCiaDoc,@pmFecDoc,@pmModalidad,@pmVrDevolucion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevLiquida] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumLiquida INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(20),@pmVrDevolucion MONEY,@pmVrBaseLiq MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevLiquida (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumLiquida,IdCiaDoc,FecDoc,Modalidad,VrDevolucion,VrBaseLiq,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumLiquida,@pmIdCiaDoc,@pmFecDoc,@pmModalidad,@pmVrDevolucion,@pmVrBaseLiq,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevProrr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevProrr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(10),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10)
,@pmnRemolque VARCHAR(10),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevProrr (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumProceso,IdCiaDoc,FecDoc,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumProceso,@pmIdCiaDoc,@pmFecDoc,@pmModalidad,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrDevolucion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevRetiros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevRetiros] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumRetiro INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmTipoRetiro VARCHAR(10),@pmModalidad VARCHAR(10),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrDevolucion MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevRetiros (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumRetiro,IdCiaDoc,FecDoc,TipoRetiro,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumRetiro,@pmIdCiaDoc,@pmFecDoc,@pmTipoRetiro,@pmModalidad,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrDevolucion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevTraslado] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmTipDoc VARCHAR(3),@pmNumTraslado INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10)
,@pmIdAsociadoDtn VARCHAR(16),@pmUndVehicDtn CHAR(1),@pmIdVehiculoDtn VARCHAR(10),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevTraslado (TipDev,Devolucion,IdCia,Fecha,IdConcepto,Modalidad,TipDoc,NumTraslado,IdCiaDoc,FecDoc,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,IdAsociadoDtn,UndVehicDtn,IdVehiculoDtn,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmTipDoc,@pmNumTraslado,@pmIdCiaDoc,@pmFecDoc,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmIdAsociadoDtn,@pmUndVehicDtn,@pmIdVehiculoDtn,@pmVrDevolucion,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatDevVinc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatDevVinc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumDocVinc INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10)
,@pmnRemolque VARCHAR(10),@pmVrIngresos MONEY,@pmVrTraslados MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatDevVinc (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumDocVinc,IdCiaDoc,FecDoc,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrIngresos,VrTraslados,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumDocVinc,@pmIdCiaDoc,@pmFecDoc,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrIngresos,@pmVrTraslados,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatIngresos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatIngresos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmIdConcepto VARCHAR(4),@pmTipoConc VARCHAR(20),@pmDescripcion VARCHAR(500),@pmVrIngreso MONEY
,@pmVrDevolucion MONEY,@pmVrAbonos MONEY,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmCiaDocRef CHAR(2),@pmCodCuenta VARCHAR(16),@pmItemDet INT,@pmEstadoReg INT
 AS 
 INSERT INTO Trn_GatIngresos (TipDoc,Recibo,IdCia,Item,Fecha,IdAsociado,UndVehiculo,IdVehiculo,IdConcepto,TipoConc,Descripcion,VrIngreso,VrDevolucion,VrAbonos,TipDocRef,NumDocRef,CiaDocRef,CodCuenta,ItemDet,EstadoReg)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmItem,@pmFecha,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmIdConcepto,@pmTipoConc,@pmDescripcion,@pmVrIngreso,@pmVrDevolucion,@pmVrAbonos,@pmTipDocRef,@pmNumDocRef,@pmCiaDocRef,@pmCodCuenta,@pmItemDet,@pmEstadoReg)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatLiquida] @pmTipDoc VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaLiquida SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmPeriodos INT,@pmTarifaLiq DECIMAL(14,4),@pmVrAportes MONEY,@pmReferencia VARCHAR(50),@pmVrBaseLiq MONEY,@pmCdTarifLiq VARCHAR(4)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmTipCau VARCHAR(3),@pmCausacion INT,@pmIdCiaCau CHAR(2),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatLiquida (TipDoc,NumLiquida,IdCia,Fecha,FechaLiquida,FechaVence,IdConcepto,Modalidad,Periodos,TarifaLiq,VrAportes,Referencia,VrBaseLiq,CdTarifLiq,TipCau,Causacion,IdCiaCau,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumLiquida,@pmIdCia,@pmFecha,@pmFechaLiquida,@pmFechaVence,@pmIdConcepto,@pmModalidad,@pmPeriodos,@pmTarifaLiq,@pmVrAportes,@pmReferencia,@pmVrBaseLiq,@pmCdTarifLiq,@pmTipCau,@pmCausacion,@pmIdCiaCau,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatProrrateos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatProrrateos] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipDocActa VARCHAR(3),@pmNumDocActa INT,@pmIdCiaActa CHAR(2),@pmFecSuceso SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrAprobado MONEY,@pmVrAvaluo MONEY,@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatProrrateos (TipDoc,NumProceso,IdCia,Fecha,IdConcepto,Modalidad,TipDocActa,NumDocActa,IdCiaActa,FecSuceso,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrAprobado,VrAvaluo,TipoAfiVeh,Referencia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumProceso,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmTipDocActa,@pmNumDocActa,@pmIdCiaActa,@pmFecSuceso,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrAprobado,@pmVrAvaluo,@pmTipoAfiVeh,@pmReferencia,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatProrratVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatProrratVeh] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmTarifaLiq DECIMAL(16,6)
,@pmVrAportes MONEY,@pmImporte MONEY,@pmVrRetiros MONEY,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmCodTarifa VARCHAR(4),@pmObservacion VARCHAR(500),@pmFecLiquida SMALLDATETIME,@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmEdoVincula INT
 AS 
 INSERT INTO Trn_GatProrratVeh (TipDoc,NumProceso,IdCia,Item,IdAsociado,UndVehiculo,IdVehiculo,TarifaLiq,VrAportes,Importe,VrRetiros,VrAvaluo,TipoBaseLiq,CodTarifa,Observacion,FecLiquida,FecIngreso,FecRetiro,EdoVincula)
 VALUES (@pmTipDoc,@pmNumProceso,@pmIdCia,@pmItem,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmTarifaLiq,@pmVrAportes,@pmImporte,@pmVrRetiros,@pmVrAvaluo,@pmTipoBaseLiq,@pmCodTarifa,@pmObservacion,@pmFecLiquida,@pmFecIngreso,@pmFecRetiro,@pmEdoVincula)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatRetiros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatRetiros] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaRetiro SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipoRetiro VARCHAR(10),@pmModalidad VARCHAR(10),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrRetiro MONEY,@pmVrAportes MONEY,@pmVrVinculacion MONEY,@pmVrSaldoVinc MONEY,@pmVrGarantia MONEY,@pmVrSaldoApo MONEY,@pmVrTotalApo MONEY,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10)
,@pmReferencia VARCHAR(50),@pmFechaCorte SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatRetiros (TipDoc,NumRegistro,IdCia,Fecha,FechaRetiro,IdConcepto,TipoRetiro,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrRetiro,VrAportes,VrVinculacion,VrSaldoVinc,VrGarantia,VrSaldoApo,VrTotalApo,VrAvaluo,TipoBaseLiq,TipoAfiVeh,Referencia,FechaCorte,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumRegistro,@pmIdCia,@pmFecha,@pmFechaRetiro,@pmIdConcepto,@pmTipoRetiro,@pmModalidad,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmVrRetiro,@pmVrAportes,@pmVrVinculacion,@pmVrSaldoVinc,@pmVrGarantia,@pmVrSaldoApo,@pmVrTotalApo,@pmVrAvaluo,@pmTipoBaseLiq,@pmTipoAfiVeh,@pmReferencia,@pmFechaCorte,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatSaldos] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVahiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrAportes MONEY,@pmVrVinculacion MONEY,@pmVrAvaluo MONEY,@pmVrComercial MONEY,@pmVrAsegurado MONEY,@pmTipoBaseLiq CHAR(1)
,@pmCantidad DECIMAL(14,4),@pmFecVincAsoc SMALLDATETIME,@pmFecLiquidaApo SMALLDATETIME,@pmTipoAfiVeh VARCHAR(10),@pmAnulado BIT,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME
 AS 
 INSERT INTO Trn_GatSaldos (TipDoc,NumRegistro,IdCia,Fecha,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrAportes,VrVinculacion,VrAvaluo,VrComercial,VrAsegurado,TipoBaseLiq,Cantidad,FecVincAsoc,FecLiquidaApo,TipoAfiVeh,Anulado,Observacion,IdUsuario,FechaCrea)
 VALUES (@pmTipDoc,@pmNumRegistro,@pmIdCia,@pmFecha,@pmIdAsociado,@pmUndVahiculo,@pmIdVehiculo,@pmnRemolque,@pmVrAportes,@pmVrVinculacion,@pmVrAvaluo,@pmVrComercial,@pmVrAsegurado,@pmTipoBaseLiq,@pmCantidad,@pmFecVincAsoc,@pmFecLiquidaApo,@pmTipoAfiVeh,@pmAnulado,@pmObservacion,@pmIdUsuario,@pmFechaCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatTraslados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatTraslados] @pmTipDoc VARCHAR(3),@pmNumTraslado INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmIdAsociadoDtn VARCHAR(16),@pmUndVehicDtn CHAR(1),@pmIdVehiculoDtn VARCHAR(10),@pmVrTraslado MONEY,@pmVrAportes MONEY,@pmVrVinculacion MONEY,@pmVrSaldoVinc MONEY,@pmVrGarantia MONEY,@pmVrSaldoApo MONEY,@pmVrTotalApo MONEY
,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50),@pmFechaCorte SMALLDATETIME,@pmVrAbonos MONEY,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmCiaDocRef CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmTarifaGar DECIMAL(14,4),@pmUndTarifGar CHAR(1),@pmComentarioGar VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatTraslados (TipDoc,NumTraslado,IdCia,Fecha,IdConcepto,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,IdAsociadoDtn,UndVehicDtn,IdVehiculoDtn,VrTraslado,VrAportes,VrVinculacion,VrSaldoVinc,VrGarantia,VrSaldoApo,VrTotalApo,VrAvaluo,TipoBaseLiq,TipoAfiVeh,Referencia,FechaCorte,VrAbonos,TipDocRef,NumDocRef,CiaDocRef,TarifaGar,UndTarifGar,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,ComentarioGar,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumTraslado,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmIdAsociadoDtn,@pmUndVehicDtn,@pmIdVehiculoDtn,@pmVrTraslado,@pmVrAportes,@pmVrVinculacion,@pmVrSaldoVinc,@pmVrGarantia,@pmVrSaldoApo,@pmVrTotalApo,@pmVrAvaluo,@pmTipoBaseLiq,@pmTipoAfiVeh,@pmReferencia,@pmFechaCorte,@pmVrAbonos,@pmTipDocRef,@pmNumDocRef,@pmCiaDocRef,@pmTarifaGar,@pmUndTarifGar,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmComentarioGar,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGatVincula]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGatVincula] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaIngreso SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmTarifaVinc DECIMAL(14,4),@pmVrVinculacion MONEY,@pmVrIngresos MONEY,@pmVrTraslados MONEY,@pmVrAvaluo MONEY,@pmVrComercial MONEY,@pmVrAsegurado MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50),@pmCdTarifVinc VARCHAR(4)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmFecUltLiqApo SMALLDATETIME,@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_GatVincula (TipDoc,NumRegistro,IdCia,Fecha,FechaIngreso,IdConcepto,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,TarifaVinc,VrVinculacion,VrIngresos,VrTraslados,VrAvaluo,VrComercial,VrAsegurado,TipoBaseLiq,TipoAfiVeh,Referencia,CdTarifVinc,TipCom,Comprobante,IdCiaCom,FecUltLiqApo,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumRegistro,@pmIdCia,@pmFecha,@pmFechaIngreso,@pmIdConcepto,@pmIdAsociado,@pmUndVehiculo,@pmIdVehiculo,@pmnRemolque,@pmTarifaVinc,@pmVrVinculacion,@pmVrIngresos,@pmVrTraslados,@pmVrAvaluo,@pmVrComercial,@pmVrAsegurado,@pmTipoBaseLiq,@pmTipoAfiVeh,@pmReferencia,@pmCdTarifVinc,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmFecUltLiqApo,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGrupos] @pmIdGrupo VARCHAR(8),@pmGrupo VARCHAR(150)
,@pmIdLinea VARCHAR(8),@pmTipoInvent VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Grupos (IdGrupo,Grupo,IdLinea,TipoInvent,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupo,@pmIdLinea,@pmTipoInvent,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGruposAgenc] @pmIdGrupo VARCHAR(4),@pmGrupoAgenc VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO GruposAgenc (IdGrupo,GrupoAgenc,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupoAgenc,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposAR]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsGruposAR] @pmIdGrupo VARCHAR(4),@pmAltoRiesgo VARCHAR(50),@pmTarfaTrab DECIMAL(10,4),@pmTarfaEmp DECIMAL(10,4),@pmInactivo BIT
 AS 
 INSERT INTO GruposAR (IdGrupo,AltoRiesgo,TarfaTrab,TarfaEmp,Inactivo)
 VALUES (@pmIdGrupo,@pmAltoRiesgo,@pmTarfaTrab,@pmTarfaEmp,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposCli]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGruposCli] @pmIdGrupo VARCHAR(4),@pmGrupoClie VARCHAR(50),@pmModApp VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO GruposCli (IdGrupo,GrupoClie,ModApp,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupoClie,@pmModApp,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGruposMcia] @pmIdGrupo VARCHAR(10),@pmGrupoMcia VARCHAR(250),@pmInactivo BIT
 AS 
 INSERT INTO GruposMcia (IdGrupo,GrupoMcia,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupoMcia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposObj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGruposObj] @pmIdGrupo VARCHAR(6),@pmGrupoObjeto VARCHAR(50),@pmnModulo VARCHAR(10)
 AS 
 INSERT INTO Sys_GruposObj (IdGrupo,GrupoObjeto,nModulo)
 VALUES (@pmIdGrupo,@pmGrupoObjeto,@pmnModulo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsGruposPro] @pmIdGrupo VARCHAR(4),@pmGrupoProp VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO GruposPro (IdGrupo,GrupoProp,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupoProp,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposRot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsGruposRot] @pmIdGrupo VARCHAR(4),@pmGrupoRot VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO GruposRot (IdGrupo,GrupoRot,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupoRot,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsGruposUsu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsGruposUsu] @pmIdGrupo INT,@pmGrupo VARCHAR(50),@pmDescripcion VARCHAR(100)
 AS 
 INSERT INTO Sys_GruposUsu (IdGrupo,Grupo,Descripcion)
 VALUES (@pmIdGrupo,@pmGrupo,@pmDescripcion)
GO
/****** Object:  StoredProcedure [dbo].[paInsGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsGuia] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaDesp SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmCantidad DECIMAL(14,4),@pmDirEnvio VARCHAR(250),@pmIdLocal VARCHAR(8),@pmLugarEnv VARCHAR(50),@pmHorasVig DECIMAL(14,4),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16)
,@pmEmpTrans VARCHAR(150),@pmCdRuta VARCHAR(4),@pmCdCiuOrigen VARCHAR(8),@pmReferncia VARCHAR(50),@pmTipOcc VARCHAR(3),@pmOCargue INT,@pmIdCiaOcc CHAR(2),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT
,@pmTipoTemp VARCHAR(10),@pmTemperatura DECIMAL(14,4),@pmTipoOCargue INT,@pmRemolque VARCHAR(10),@pmNumVerifica INT,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Guia (TipDoc,Guia,IdCia,Fecha,FechaDesp,FechaVence,IdCliente,IdAgencia,Cantidad,DirEnvio,IdLocal,LugarEnv,HorasVig,IdVehiculo,IdConductor,NitEmpTrans,EmpTrans,CdRuta,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,Factura,IdCiaFac,FechaFact,OrigenAdd,ZonaFrontera,TipoTemp,Temperatura,Remolque,Anulado,FecDev
,Observacion,IdEstado,CdCiuOrigen,TimeSys,IdCiaCrea,IdUsuario,TipoOCargue,NumVerifica)
 VALUES (@pmTipDoc,@pmGuia,@pmIdCia,@pmFecha,@pmFechaDesp,@pmFechaVence,@pmIdCliente,@pmIdAgencia,@pmCantidad,@pmDirEnvio,@pmIdLocal,@pmLugarEnv,@pmHorasVig,@pmIdVehiculo,@pmIdConductor,@pmNitEmpTrans,@pmEmpTrans,@pmCdRuta,@pmReferncia,@pmTipOcc,@pmOCargue,@pmIdCiaOcc,@pmTipFac,@pmFactura,@pmIdCiaFac
,@pmFechaFact,@pmOrigenAdd,@pmZonaFrontera,@pmTipoTemp,@pmTemperatura,@pmRemolque,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmCdCiuOrigen,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoOCargue,@pmNumVerifica)
GO
/****** Object:  StoredProcedure [dbo].[paInsInstalaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsInstalaciones] @pmIdInstala VARCHAR(4),@pmInstlacion VARCHAR(50),@pmDirInstala VARCHAR(100)
,@pmCodCiu VARCHAR(8),@pmCodCia CHAR(2),@pmIdClase VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO Instalaciones (IdInstala,Instlacion,DirInstala,CodCia,CodCiu,IdClase,Inactivo)
 VALUES (@pmIdInstala,@pmInstlacion,@pmDirInstala,@pmCodCia,@pmCodCiu,@pmIdClase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsInvDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsInvDetalle] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCdUbic VARCHAR(10),@pmCdTanque VARCHAR(4)
,@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmCantExist DECIMAL(14,4),@pmDescripcion VARCHAR(250),@pmUnidades DECIMAL(14,4),@pmUndAforo DECIMAL(14,4),@pmUndAgua DECIMAL(14,4)
,@pmCantAgua DECIMAL(14,4),@pmNoConteo BIT,@pmIdUsuario VARCHAR(11),@pmIdEstacion CHAR(2),@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO Trn_InvDetalle (TipDoc,nInventario,IdCia,Item,IdProducto,IdBodega,CdUbic,CdTanque,Cantidad,VrUnitario,CantExist,Descripcion,Unidades,UndAforo,UndAgua,CantAgua,NoConteo,IdUsuario,IdEstacion,FechaAdd)
 VALUES (@pmTipDoc,@pmnInventario,@pmIdCia,@pmItem,@pmIdProducto,@pmIdBodega,@pmCdUbic,@pmCdTanque,@pmCantidad,@pmVrUnitario,@pmCantExist,@pmDescripcion,@pmUnidades,@pmUndAforo
,@pmUndAgua,@pmCantAgua,@pmNoConteo,@pmIdUsuario,@pmIdEstacion,@pmFechaAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsInvFisico]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsInvFisico] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmModalidad VARCHAR(10),@pmCdBodega VARCHAR(4),@pmCantFisico DECIMAL(14,4)
,@pmVrTotalFisico MONEY,@pmExistencias DECIMAL(14,4),@pmVrTotalCosto MONEY,@pmProcesado BIT,@pmFecProceso SMALLDATETIME,@pmNumAjuSob INT,@pmNumAjuFal INT
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFCodBodega VARCHAR(4),@pmFCodMarca VARCHAR(4),@pmFCodSubGrupo VARCHAR(8)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_InvFisico (TipDoc,nInventario,IdCia,Fecha,Modalidad,CdBodega,CantFisico,VrTotalFisico,Existencias,VrTotalCosto,OrigenAdd,Procesado,FecProceso,NumAjuSob,NumAjuFal,Anulado,FecDev,Observacion
,IdEstado,TimeSys,IdCiaCrea,IdUsuario,FCodBodega,FCodMarca,FCodSubGrupo)
 VALUES (@pmTipDoc,@pmnInventario,@pmIdCia,@pmFecha,@pmModalidad,@pmCdBodega,@pmCantFisico,@pmVrTotalFisico,@pmExistencias,@pmVrTotalCosto,@pmOrigenAdd,@pmProcesado,@pmFecProceso,@pmNumAjuSob
,@pmNumAjuFal,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmFCodBodega,@pmFCodMarca,@pmFCodSubGrupo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJornadas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsJornadas] @pmIdJornada VARCHAR(4),@pmJornada VARCHAR(50),@pmHorasDia INT
,@pmRangos VARCHAR(25),@pmTurnoRotativo BIT,@pmInactivo BIT
 AS 
 INSERT INTO Jornadas (IdJornada,Jornada,HorasDia,Rangos,Inactivo,TurnoRotativo)
 VALUES (@pmIdJornada,@pmJornada,@pmHorasDia,@pmRangos,@pmInactivo,@pmTurnoRotativo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurActas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurActas] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumActa VARCHAR(20),@pmFechaActa SMALLDATETIME,@pmModalidad VARCHAR(10),@pmValorTotal MONEY,@pmReferencia VARCHAR(50),@pmEstadoPror INT,@pmTipPror VARCHAR(3),@pmNumPror INT,@pmIdCiaPror CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmModuloCrea VARCHAR(10)
 AS 
 INSERT INTO Trn_JurActas (TipDoc,NumProceso,IdCia,Fecha,NumActa,FechaActa,Modalidad,ValorTotal,Referencia,EstadoPror,TipPror,NumPror,IdCiaPror,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea)
 VALUES (@pmTipDoc,@pmNumProceso,@pmIdCia,@pmFecha,@pmNumActa,@pmFechaActa,@pmModalidad,@pmValorTotal,@pmReferencia,@pmEstadoPror,@pmTipPror,@pmNumPror,@pmIdCiaPror,@pmAnulado,@pmNumDev,@pmFechaDev,@pmObservacion,@pmIdUsuario,@pmFechaCrea,@pmIdCiaCrea,@pmModuloCrea)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurAutoridades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurAutoridades] @pmIdAutoridad VARCHAR(4),@pmNomAutoridad VARCHAR(50),@pmDireccion VARCHAR(100),@pmInactivo BIT
 AS 
 INSERT INTO JurAutoridades (IdAutoridad,NomAutoridad,Direccion,Inactivo)
 VALUES (@pmIdAutoridad,@pmNomAutoridad,@pmDireccion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCalifica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurCalifica] @pmIdCalifica VARCHAR(4),@pmCalificaCaso VARCHAR(50),@pmIdClase VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO JurCalifica (IdCalifica,CalificaCaso,IdClase,Inactivo)
 VALUES (@pmIdCalifica,@pmCalificaCaso,@pmIdClase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCasos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurCasos] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmRadicacion VARCHAR(20),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmSinRecorrido BIT,@pmTipCar VARCHAR(3)
,@pmCartulina INT,@pmIdCiaCar CHAR(2),@pmFechaSuc SMALLDATETIME,@pmIdRuta VARCHAR(4),@pmIdAbogado VARCHAR(16),@pmIdAuxiliar VARCHAR(16),@pmIdAutoridad VARCHAR(4),@pmIdTipoPro VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCalifica VARCHAR(4),@pmLugarAcc VARCHAR(100)
,@pmCausaAcc VARCHAR(3300),@pmComentario VARCHAR(3300),@pmObservacion VARCHAR(250),@pmContraparte VARCHAR(100),@pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20),@pmValDanosCParte MONEY,@pmValDanosEmp MONEY,@pmValDeducible MONEY
,@pmEmpAsegdora VARCHAR(100),@pmAuxMutuo BIT,@pmArchivoCaso VARCHAR(100),@pmDocumntos VARCHAR(250),@pmCroquis VARCHAR(20),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmReclamaciones VARCHAR(1000)
,@pmCdCausal VARCHAR(4),@pmCedtraparte VARCHAR(16),@pmPolizaResCivil VARCHAR(30),@pmVigencResCivil SMALLDATETIME,@pmNitEmpAseg VARCHAR(16),@pmNombreAseg VARCHAR(150)
,@pmUndVehiculo CHAR(1),@pmNumRemolque VARCHAR(10),@pmTipActaJur VARCHAR(3),@pmNumActaJur INT,@pmCiaActaJur CHAR(2),@pmEstadoProc INT,@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_JurCasos (TipDoc,CasoID,IdCia,Fecha,Radicacion,IdVehiculo,IdPropietario,IdConductor,SinRecorrido,TipCar,Cartulina,IdCiaCar,FechaSuc,IdRuta,IdAbogado,IdAuxiliar,IdAutoridad,IdTipoPro,IdClase,IdCalifica,LugarAcc,CausaAcc,Comentario,Observacion,Contraparte,DirContraparte,TelContraparte
,ValDanosCParte,ValDanosEmp,ValDeducible,EmpAsegdora,AuxMutuo,ArchivoCaso,Documntos,Croquis,Anulado,FecDev,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Reclamaciones,CdCausal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,UndVehiculo,NumRemolque,TipActaJur,NumActaJur,CiaActaJur,EstadoProc)
 VALUES (@pmTipDoc,@pmCasoID,@pmIdCia,@pmFecha,@pmRadicacion,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmSinRecorrido,@pmTipCar,@pmCartulina,@pmIdCiaCar,@pmFechaSuc,@pmIdRuta,@pmIdAbogado,@pmIdAuxiliar,@pmIdAutoridad,@pmIdTipoPro,@pmIdClase,@pmIdCalifica
,@pmLugarAcc,@pmCausaAcc,@pmComentario,@pmObservacion,@pmContraparte,@pmDirContraparte,@pmTelContraparte,@pmValDanosCParte,@pmValDanosEmp,@pmValDeducible,@pmEmpAsegdora,@pmAuxMutuo,@pmArchivoCaso,@pmDocumntos,@pmCroquis,@pmAnulado,@pmFecDev,@pmIdEstado
,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmReclamaciones,@pmCdCausal,@pmCedtraparte,@pmPolizaResCivil,@pmVigencResCivil,@pmNitEmpAseg,@pmNombreAseg,@pmUndVehiculo,@pmNumRemolque,@pmTipActaJur,@pmNumActaJur,@pmCiaActaJur,@pmEstadoProc)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCasosHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurCasosHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT,@pmFechaUp SMALLDATETIME,@pmHistorial VARCHAR(3500),@pmEstadoAct VARCHAR(3500)
,@pmCierreProc BIT,@pmArchivoProc VARCHAR(100),@pmNombreCparte VARCHAR(100),@pmDirCparte VARCHAR(100),@pmTelCparte VARCHAR(20),@pmDanosCParte MONEY,@pmDanosEmp MONEY
,@pmValorDeducible MONEY,@pmAseguradora VARCHAR(100),@pmAuxilioMutuo BIT,@pmIdEstado VARCHAR(4),@pmIdUsuario VARCHAR(11),@pmCedContparte VARCHAR(16)
 AS 
 INSERT INTO Trn_JurCasosHis (TipDoc,CasoID,IdCia,ActualizaID,FechaUp,Historial,EstadoAct,CierreProc,ArchivoProc,NombreCparte,DirCparte,TelCparte,DanosCParte,DanosEmp,ValorDeducible,Aseguradora,AuxilioMutuo,IdEstado,IdUsuario,CedContparte)
 VALUES (@pmTipDoc,@pmCasoID,@pmIdCia,@pmActualizaID,@pmFechaUp,@pmHistorial,@pmEstadoAct,@pmCierreProc,@pmArchivoProc,@pmNombreCparte,@pmDirCparte,@pmTelCparte,@pmDanosCParte,@pmDanosEmp
,@pmValorDeducible,@pmAseguradora,@pmAuxilioMutuo,@pmIdEstado,@pmIdUsuario,@pmCedContparte)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCasosQtn]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsJurCasosQtn] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdPregunta VARCHAR(4),@pmDescripcion VARCHAR(250)
 AS 
 INSERT INTO Trn_JurCasosQtn (TipDoc,CasoID,IdCia,Item,IdPregunta,Descripcion)
 VALUES (@pmTipDoc,@pmCasoID,@pmIdCia,@pmItem,@pmIdPregunta,@pmDescripcion)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurCausales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurCausales] @pmIdCausal VARCHAR(4),@pmCausal VARCHAR(50),@pmIdTipoPro VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO JurCausales (IdCausal,Causal,IdTipoPro,Inactivo)
 VALUES (@pmIdCausal,@pmCausal,@pmIdTipoPro,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurClaseAcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurClaseAcc] @pmIdClase VARCHAR(4),@pmClaseAccdte VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO JurClaseAcc (IdClase,ClaseAccdte,Inactivo)
 VALUES (@pmIdClase,@pmClaseAccdte,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurDocumtos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurDocumtos] @pmIdDoc VARCHAR(4),@pmDocumnto VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO JurDocumtos (IdDoc,Documnto,Inactivo)
 VALUES (@pmIdDoc,@pmDocumnto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmInactivo BIT,@pmNColor INT
 AS 
 INSERT INTO JurEstados (IdEstado,Estado,Inactivo,NColor)
 VALUES (@pmIdEstado,@pmEstado,@pmInactivo,@pmNColor)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurInvesHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurInvesHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT,@pmFechaUp SMALLDATETIME,@pmHistorial VARCHAR(3000),@pmEstadoAct VARCHAR(3000),@pmPruebas VARCHAR(1200)
,@pmDocumntos VARCHAR(250),@pmCierreProc BIT,@pmArchivoProc VARCHAR(100),@pmNombreCparte VARCHAR(100),@pmDirCparte VARCHAR(100),@pmTelCparte VARCHAR(20),@pmIdEstado VARCHAR(4),@pmCedContparte VARCHAR(16),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_JurInvesHis (TipDoc,CasoID,IdCia,ActualizaID,FechaUp,Historial,EstadoAct,Pruebas,Documntos,CierreProc,ArchivoProc,NombreCparte,DirCparte,TelCparte,IdEstado,IdUsuario,CedContparte)
 VALUES (@pmTipDoc,@pmCasoID,@pmIdCia,@pmActualizaID,@pmFechaUp,@pmHistorial,@pmEstadoAct,@pmPruebas,@pmDocumntos,@pmCierreProc,@pmArchivoProc,@pmNombreCparte,@pmDirCparte,@pmTelCparte,@pmIdEstado,@pmIdUsuario,@pmCedContparte)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurInvestiga]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurInvestiga] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmRadicacion VARCHAR(20),@pmIdAbogado VARCHAR(16),@pmIdAuxiliar VARCHAR(16),@pmIdAutoridad VARCHAR(4),@pmIdEmpresa VARCHAR(16)
,@pmObservacion VARCHAR(250),@pmContraparte VARCHAR(100),@pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20),@pmArchivoCaso VARCHAR(100),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmCedtraparte VARCHAR(16),@pmCdTipoPro VARCHAR(4)
,@pmCdCausal VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_JurInvestiga (TipDoc,CasoID,IdCia,Fecha,Radicacion,IdAbogado,IdAuxiliar,IdAutoridad,IdEmpresa,Observacion,Contraparte,DirContraparte,TelContraparte,ArchivoCaso,Anulado,FecDev,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Cedtraparte,CdTipoPro,CdCausal)
 VALUES (@pmTipDoc,@pmCasoID,@pmIdCia,@pmFecha,@pmRadicacion,@pmIdAbogado,@pmIdAuxiliar,@pmIdAutoridad,@pmIdEmpresa,@pmObservacion,@pmContraparte,@pmDirContraparte,@pmTelContraparte,@pmArchivoCaso,@pmAnulado,@pmFecDev
,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCedtraparte,@pmCdTipoPro,@pmCdCausal)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurPreguntas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurPreguntas] @pmIdPregunta VARCHAR(4),@pmPreguntaBas VARCHAR(250),@pmIdTipoPro VARCHAR(4),@pmTipoDato VARCHAR(15),@pmInactivo BIT
 AS 
 INSERT INTO JurPreguntas (IdPregunta,PreguntaBas,IdTipoPro,TipoDato,Inactivo)
 VALUES (@pmIdPregunta,@pmPreguntaBas,@pmIdTipoPro,@pmTipoDato,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurReclamac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurReclamac] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaRec SMALLDATETIME,@pmTipSin VARCHAR(3),@pmSiniestro INT,@pmIdCiaSin CHAR(2)
,@pmIdReclamnte VARCHAR(16),@pmIdTipoRec VARCHAR(4),@pmVrReclamac MONEY,@pmObservacion VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_JurReclamac (TipDoc,Reclamac,IdCia,Fecha,FechaRec,TipSin,Siniestro,IdCiaSin,IdReclamnte,IdTipoRec,VrReclamac,Observacion,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmReclamac,@pmIdCia,@pmFecha,@pmFechaRec,@pmTipSin,@pmSiniestro,@pmIdCiaSin,@pmIdReclamnte,@pmIdTipoRec,@pmVrReclamac,@pmObservacion,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurRecOfrecmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurRecOfrecmto] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2),@pmItem INT,@pmFechaOfrec SMALLDATETIME,@pmVrOfrecmto MONEY,@pmOfcAceptado INT,@pmFecAceptado SMALLDATETIME
,@pmOfcPagado INT,@pmNumSolGiro VARCHAR(30),@pmComentarios VARCHAR(1000),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_JurRecOfrecmto (TipDoc,Reclamac,IdCia,Item,FechaOfrec,VrOfrecmto,OfcAceptado,FecAceptado,OfcPagado,NumSolGiro,Comentarios,TimeSys,IdUsuario)
 VALUES (@pmTipDoc,@pmReclamac,@pmIdCia,@pmItem,@pmFechaOfrec,@pmVrOfrecmto,@pmOfcAceptado,@pmFecAceptado,@pmOfcPagado,@pmNumSolGiro,@pmComentarios,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurTipos] @pmIdTipoPro VARCHAR(4),@pmTipoProceso VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO JurTipos (IdTipoPro,TipoProceso,Inactivo)
 VALUES (@pmIdTipoPro,@pmTipoProceso,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsJurTiposRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsJurTiposRec] @pmIdTipoRec VARCHAR(4),@pmTipReclamante VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO JurTiposRec (IdTipoRec,TipReclamante,Inactivo)
 VALUES (@pmIdTipoRec,@pmTipReclamante,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsKardex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsKardex] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCdTanque VARCHAR(4),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4),@pmIdUnd VARCHAR(4),@pmVrUnitario MONEY,@pmVrPrecio MONEY,@pmVrCostProm MONEY,@pmTarifaIva DECIMAL(14,4),@pmVrIvaEnt MONEY,@pmVrIvaSal MONEY,@pmTarifaDct DECIMAL(14,4),@pmVrDctoEnt MONEY,@pmVrDctoSal MONEY,@pmVrCostoEnt MONEY
,@pmVrCostoSal MONEY,@pmTarifaRet DECIMAL(14,4),@pmVrReteEnt MONEY,@pmVrReteSal MONEY,@pmTarifaIca DECIMAL(14,4),@pmVrIcaEnt MONEY,@pmVrIcaSal MONEY,@pmVrBruto MONEY,@pmCdUbic VARCHAR(10),@pmNumLote VARCHAR(30),@pmFechLote SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmCdLocal VARCHAR(8),@pmCdSzona VARCHAR(4),@pmpVehiculo VARCHAR(10),@pmIdVend VARCHAR(16),@pmComision DECIMAL(14,4)
,@pmCdOperario VARCHAR(16),@pmComisnOper DECIMAL(14,4),@pmReferencia VARCHAR(50),@pmDescripcion VARCHAR(250),@pmComptmntos VARCHAR(50),@pmCdProdEquiv VARCHAR(16),@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFactura VARCHAR(15),@pmTipDocDev VARCHAR(3),@pmNumDocDev INT,@pmCdMngra VARCHAR(10),@pmNumInicial DECIMAL(14,4),@pmNumFinal DECIMAL(14,4),@pmSobretasa DECIMAL(14,4),@pmTasaNac DECIMAL(14,4),@pmTasaDep DECIMAL(14,4)
,@pmTasaMun DECIMAL(14,4),@pmSoldicom DECIMAL(14,4),@pmImpGlobal DECIMAL(14,4),@pmOtroImpto DECIMAL(14,4),@pmUnidades DECIMAL(14,4),@pmItemCombo INT,@pmServcios BIT,@pmNoVentas INT,@pmEsCombo BIT,@pmEsProdBase INT,@pmCodTarDct VARCHAR(4),@pmCodTarIva VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarCom VARCHAR(4),@pmCodTarCmc VARCHAR(4),@pmListaPrec CHAR(1),@pmVrBase MONEY,@pmCdMoneda VARCHAR(5),@pmVrTasaCamb MONEY,@pmVrDivisa1 MONEY,@pmVrDivisa2 MONEY
,@pmVrDivisa3 MONEY,@pmReferencia2 VARCHAR(50),@pmFecOrden SMALLDATETIME,@pmgalsbruto DECIMAL(14,4),@pmgalsneto DECIMAL(14,4), @pmTemperatura DECIMAL(14,4),@pmUmTemp VARCHAR(3),@pmDensidad DECIMAL(14,4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmRec_Costo DECIMAL(14,4),@pmMgenCont  DECIMAL(14,4),@pmVrImvCosto DECIMAL(16,4),@pmTarifaIco DECIMAL(14,4),@pmVrImpCon DECIMAL(16,4),@pmCantObseq DECIMAL(14,4),@pmVrIvaObseq MONEY,@pmBaseIvaCom DECIMAL(16,4),@pmImpCarbono DECIMAL(14,4),@pmIngBaseCom DECIMAL(16,4)
,@pmTarifaStc DECIMAL(14,4),@pmSobtasaCons DECIMAL(16,4),@pmCodTarIco VARCHAR(4),@pmBaseIvp MONEY,@pmTarifaIvp DECIMAL(14,4),@pmIvaIngProd MONEY,@pmTarifaIba DECIMAL(16,6),@pmVrImpuBa MONEY,@pmCodTarBa VARCHAR(4),@pmTarifaCup DECIMAL(16,6),@pmVrImpuCup MONEY,@pmCodTarCup VARCHAR(4),@pmTarifaIat DECIMAL(14,4),@pmVrAviTab MONEY,@pmCodTarIat VARCHAR(4),@pmTarifaBom DECIMAL(14,4),@pmVrSobBom MONEY,@pmCodTarBom VARCHAR(4)
 AS 
 INSERT INTO Trn_Kardex (TipDoc,Documento,IdCia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,CdMngra,NumInicial
,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo,MgenCont,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecha,@pmIdProducto,@pmIdBodega,@pmCdTanque,@pmEntradas,@pmSalidas,@pmIdUnd,@pmVrUnitario,@pmVrPrecio,@pmVrCostProm,@pmTarifaIva,@pmVrIvaEnt,@pmVrIvaSal,@pmTarifaDct,@pmVrDctoEnt,@pmVrDctoSal,@pmVrCostoEnt,@pmVrCostoSal,@pmTarifaRet,@pmVrReteEnt,@pmVrReteSal,@pmTarifaIca,@pmVrIcaEnt,@pmVrIcaSal,@pmVrBruto,@pmCdUbic,@pmNumLote,@pmFechLote,@pmIdConcepto,@pmIdTercero,@pmCdAgencia,@pmCdCCosto,@pmCdSubCos,@pmCdLocal,@pmCdSzona,@pmpVehiculo,@pmIdVend
,@pmComision,@pmCdOperario,@pmComisnOper,@pmReferencia,@pmDescripcion,@pmComptmntos,@pmCdProdEquiv,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmCotizacion,@pmIdCiaCot,@pmRemision,@pmIdCiaRem,@pmFactura,@pmTipDocDev,@pmNumDocDev,@pmCdMngra,@pmNumInicial,@pmNumFinal,@pmSobretasa,@pmTasaNac,@pmTasaDep,@pmTasaMun,@pmSoldicom,@pmImpGlobal,@pmOtroImpto,@pmUnidades,@pmItemCombo,@pmServcios,@pmNoVentas,@pmEsCombo,@pmEsProdBase,@pmCodTarDct,@pmCodTarIva,@pmCodTarIca,@pmCodTarRet,@pmCodTarCom,@pmCodTarCmc
,@pmListaPrec,@pmVrBase,@pmCdMoneda,@pmVrTasaCamb,@pmVrDivisa1,@pmVrDivisa2,@pmVrDivisa3,@pmReferencia2,@pmFecOrden,@pmgalsbruto,@pmgalsneto,@pmTemperatura,@pmUmTemp,@pmDensidad,@pmTimeSys,@pmIdUsuario,@pmRec_Costo,@pmMgenCont,@pmVrImvCosto,@pmTarifaIco,@pmVrImpCon,@pmCantObseq,@pmVrIvaObseq,@pmBaseIvaCom,@pmImpCarbono,@pmIngBaseCom,@pmTarifaStc,@pmSobtasaCons,@pmCodTarIco,@pmBaseIvp,@pmTarifaIvp,@pmIvaIngProd,@pmTarifaIba,@pmVrImpuBa,@pmCodTarBa,@pmTarifaCup,@pmVrImpuCup,@pmCodTarCup,@pmTarifaIat,@pmVrAviTab,@pmCodTarIat,@pmTarifaBom,@pmVrSobBom,@pmCodTarBom)
GO
/****** Object:  StoredProcedure [dbo].[paInsKarUbic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsKarUbic] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4),@pmFecha SMALLDATETIME,@pmLinea INT
 AS 
 INSERT INTO Trn_KarUbic (TipDoc,Documento,IdCia,Item,IdProducto,IdBodega,IdUbic,Entradas,Salidas,Fecha,Linea)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmIdProducto,@pmIdBodega,@pmIdUbic,@pmEntradas,@pmSalidas,@pmFecha,@pmLinea)
GO
/****** Object:  StoredProcedure [dbo].[paInsLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLineas] @pmIdLinea VARCHAR(8),@pmLinea VARCHAR(150)
,@pmTipoInvent VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Lineas (IdLinea,Linea,TipoInvent,Inactivo)
 VALUES (@pmIdLinea,@pmLinea,@pmTipoInvent,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsLineasCredCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLineasCredCue] @pmIdLinea VARCHAR(4),@pmIdTipoTerc VARCHAR(4),@pmConcepto VARCHAR(10),@pmIdCuentaDb VARCHAR(16),@pmIdCuentaCr VARCHAR(16)
 AS 
 INSERT INTO LineasCredCue (IdLinea,IdTipoTerc,Concepto,IdCuentaDb,IdCuentaCr)
 VALUES (@pmIdLinea,@pmIdTipoTerc,@pmConcepto,@pmIdCuentaDb,@pmIdCuentaCr)
GO
/****** Object:  StoredProcedure [dbo].[paInsLocalidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLocalidades] @pmIdLocal VARCHAR(8),@pmLocalidad VARCHAR(50),@pmIdDep VARCHAR(8),@pmTipLocal VARCHAR(20),@pmDist_Kmt DECIMAL(10,4)
,@pmTime_hh VARCHAR(8),@pmCelRow DECIMAL(14,4),@pmCelCol DECIMAL(14,4),@pmInactivo BIT,@pmDistSede DECIMAL(10,4),@pmTimeSede VARCHAR(8),@pmCodAlias VARCHAR(10)
 AS 
 INSERT INTO Localidades (IdLocal,Localidad,IdDep,TipLocal,Dist_Kmt,Time_hh,CelRow,CelCol,DistSede,TimeSede,CodAlias,Inactivo)
 VALUES (@pmIdLocal,@pmLocalidad,@pmIdDep,@pmTipLocal,@pmDist_Kmt,@pmTime_hh,@pmCelRow,@pmCelCol,@pmDistSede,@pmTimeSede,@pmCodAlias,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsLog_Nomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLog_Nomina] @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmCerrado BIT
,@pmIntCtaCte BIT,@pmLogCtaCte VARCHAR(100)
 AS 
 INSERT INTO Log_Nomina (IdNom,IdPeriodo,Cerrado,IntCtaCte,LogCtaCte)
 VALUES (@pmIdNom,@pmIdPeriodo,@pmCerrado,@pmIntCtaCte,@pmLogCtaCte)
GO
/****** Object:  StoredProcedure [dbo].[paInsLog_Periodos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsLog_Periodos] @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO Log_Periodos (Anno,IdCia,Ene,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic,CierreAnno)
 VALUES (@pmAnno,@pmIdCia,0,0,0,0,0,0,0,0,0,0,0,0,0)
GO
/****** Object:  StoredProcedure [dbo].[paInsLotes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsLotes] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10)
,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmSaldoActual DECIMAL(14,4),@pmNitProv VARCHAR(16),@pmTipDoc VARCHAR(3),@pmEntrada INT,@pmTimeSys SMALLDATETIME
 AS 
 INSERT INTO Trn_Lotes (NumLote,IdProducto,IdCia,IdBodega,IdUbic,Fecha,FecVence,SaldoActual,NitProv,TipDoc,Entrada,TimeSys)
 VALUES (@pmNumLote,@pmIdProducto,@pmIdCia,@pmIdBodega,@pmIdUbic,@pmFecha,@pmFecVence,@pmSaldoActual,@pmNitProv,@pmTipDoc,@pmEntrada,@pmTimeSys)
GO
/****** Object:  StoredProcedure [dbo].[paInsLotMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLotMov] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmCdUbic VARCHAR(10),@pmEntradas DECIMAL(14,4),@pmSalidas DECIMAL(14,4),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmLinea INT
 AS 
 INSERT INTO Trn_LotMov (TipDoc,Documento,IdCia,Item,NumLote,IdProducto,IdBodega,CdUbic,Entradas,Salidas,Fecha,FecVence,Linea)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmNumLote,@pmIdProducto,@pmIdBodega,@pmCdUbic,@pmEntradas,@pmSalidas,@pmFecha,@pmFecVence,@pmLinea)
GO
/****** Object:  StoredProcedure [dbo].[paInsMarcas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMarcas] @pmIdMarca VARCHAR(4),@pmMarca VARCHAR(50),@pmTipoMarca VARCHAR(20)
,@pmCodigoMT VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Marcas (IdMarca,Marca,TipoMarca,CodigoMT,Inactivo)
 VALUES (@pmIdMarca,@pmMarca,@pmTipoMarca,@pmCodigoMT,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMarcasLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMarcasLin] @pmIdLinea VARCHAR(10),@pmLineaVeh VARCHAR(50),@pmIdMarca VARCHAR(4),@pmCodMT VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO MarcasLin (IdLinea,LineaVeh,IdMarca,CodMT,Inactivo)
 VALUES (@pmIdLinea,@pmLineaVeh,@pmIdMarca,@pmCodMT,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayAnotaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayAnotaciones] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME
,@pmDetalle VARCHAR(5000),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MayAnotaciones (NContrato,IdCia,Item,Fecha,Detalle,IdUsuario)
 VALUES (@pmNContrato,@pmIdCia,@pmItem,@pmFecha,@pmDetalle,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayBonCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayBonCuentas] @pmIdBonif VARCHAR(4),@pmTipoCue INT
,@pmCdTipo VARCHAR(4),@pmIdCuenta VARCHAR(16)
 AS 
 INSERT INTO MayBonCuentas (IdBonif,TipoCue,CdTipo,IdCuenta)
 VALUES (@pmIdBonif,@pmTipoCue,@pmCdTipo,@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayBonif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayBonif] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoProd VARCHAR(20),@pmVrInicial DECIMAL(14,4),@pmVrFinal DECIMAL(14,4)
,@pmUnidad VARCHAR(10),@pmTarifa DECIMAL(14,4),@pmTipoTarifa CHAR(1),@pmPeriodo VARCHAR(10),@pmCdProducto VARCHAR(16),@pmCdSubgrupo VARCHAR(8)
,@pmTipoMargen CHAR(1),@pmIntvExcluido BIT,@pmIntvGlobal BIT,@pmIvaIncluido BIT
 AS 
 INSERT INTO Trn_MayBonif (NContrato,IdCia,Item,TipoProd,VrInicial,VrFinal,Unidad,Tarifa,TipoTarifa,Periodo,CdProducto,CdSubgrupo,TipoMargen,IntvExcluido,IntvGlobal,IvaIncluido)
 VALUES (@pmNContrato,@pmIdCia,@pmItem,@pmTipoProd,@pmVrInicial,@pmVrFinal,@pmUnidad,@pmTarifa,@pmTipoTarifa,@pmPeriodo,@pmCdProducto,@pmCdSubgrupo,@pmTipoMargen,@pmIntvExcluido,@pmIntvGlobal,@pmIvaIncluido)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayCesion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayCesion] @pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdNueClie VARCHAR(16),@pmIdNueAgenc VARCHAR(16)
,@pmFecInicio SMALLDATETIME,@pmClaseCont VARCHAR(10),@pmCdTipoCont VARCHAR(4),@pmCuotaBase DECIMAL(14,4),@pmCuotaMin DECIMAL(14,4),@pmAcumGals DECIMAL(14,4),@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MayCesion (Numero,Fecha,NContrato,IdCia,IdCliente,IdAgencia,IdNueClie,IdNueAgenc,FecInicio,ClaseCont,CdTipoCont,CuotaBase,CuotaMin,AcumGals,Observacion,TimeSys,IdUsuario)
 VALUES (@pmNumero,@pmFecha,@pmNContrato,@pmIdCia,@pmIdCliente,@pmIdAgencia,@pmIdNueClie,@pmIdNueAgenc,@pmFecInicio,@pmClaseCont,@pmCdTipoCont,@pmCuotaBase,@pmCuotaMin,@pmAcumGals,@pmObservacion,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayContDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayContDoc] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdDoc VARCHAR(4),@pmFechaRad SMALLDATETIME
,@pmDependencia VARCHAR(50),@pmEstado VARCHAR(10),@pmFechaAprob SMALLDATETIME,@pmComentarios VARCHAR(250),@pmCdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MayContDoc (NContrato,IdCia,Item,IdDoc,FechaRad,Dependencia,Estado,FechaAprob,Comentarios,CdUsuario)
 VALUES (@pmNContrato,@pmIdCia,@pmItem,@pmIdDoc,@pmFechaRad,@pmDependencia,@pmEstado,@pmFechaAprob,@pmComentarios,@pmCdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayContratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayContratos] @pmNContrato INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdTipo VARCHAR(4),@pmIdBonif VARCHAR(4),@pmConvBonif BIT,@pmCuotaFija BIT
,@pmCondPago BIT,@pmDiasGracia INT,@pmModPlazo VARCHAR(10),@pmPlazo INT,@pmFechaVence SMALLDATETIME,@pmModRecursos VARCHAR(150),@pmVrInversion MONEY,@pmVrInventario MONEY,@pmVrCuota MONEY,@pmModCuota VARCHAR(10)
,@pmIdBandera VARCHAR(4),@pmAprobJunta INT,@pmFechaAprob SMALLDATETIME,@pmObservAprob VARCHAR(250),@pmObservacion VARCHAR(250),@pmIdVend VARCHAR(16),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
,@pmFechaInicio SMALLDATETIME,@pmCuotaMin DECIMAL(14,4),@pmTipoAprob VARCHAR(10),@pmNumInterno VARCHAR(20),@pmInvCombus DECIMAL(14,4),@pmCuotaBase DECIMAL(14,4),@pmFechaFirma SMALLDATETIME,@pmCdAprobNeg VARCHAR(4),@pmArchivoAprob VARCHAR(50)
,@pmClaseContrato VARCHAR(10),@pmDescTipoCont VARCHAR(250),@pmGarantHipoteca BIT,@pmGarantPrenda BIT,@pmGarantPoliza BIT,@pmGarantBanco BIT,@pmGarantPagare BIT,@pmGarantOtro BIT,@pmCdTipoBien VARCHAR(4),@pmVrAvaludo MONEY,@pmNroEscritura VARCHAR(50)
,@pmCdTipoPoliza VARCHAR(4),@pmDescPoliza VARCHAR(150),@pmVigencPoliza INT,@pmFecVencPoliza SMALLDATETIME,@pmValorPoliza MONEY,@pmEdoGarantias INT,@pmDescGarantOtro VARCHAR(250),@pmInverContab INT,@pmInverContrac INT,@pmVolContMes DECIMAL(14,4)
,@pmVolContTotal DECIMAL(14,4),@pmVolViabMes DECIMAL(14,4),@pmVolViabTotal DECIMAL(14,4),@pmInvCtbObra MONEY,@pmInvCtbCapital MONEY,@pmInvCtbEfectivo MONEY,@pmInvCtbImagen MONEY,@pmInvCtbMntmto MONEY,@pmFecDesemb SMALLDATETIME,@pmInvContObra MONEY
,@pmInvContCapital MONEY,@pmInvContEfectivo MONEY,@pmInvContImagen MONEY,@pmCrtlAprovInv INT,@pmCrtlAprovImg INT,@pmCdTipoBloq VARCHAR(4),@pmEdoDocmtos INT,@pmDescEdoDoc VARCHAR(250),@pmRentabInicial DECIMAL(14,4),@pmGraciaBonif INT
,@pmActFechaIni INT,@pmCdZonaCont VARCHAR(4),@pmContVigente BIT,@pmVolContrac INT,@pmDescHipotec VARCHAR(250),@pmVrAvaComerc MONEY,@pmFecRegEscritura SMALLDATETIME,@pmNotariaEsc VARCHAR(50),@pmCdTipPrenda VARCHAR(4),@pmVrAvaPrenda MONEY
,@pmPolizaPrenda VARCHAR(30),@pmFecVigPrenda SMALLDATETIME,@pmVrAsegPrenda MONEY,@pmContOperando BIT
 AS 
 INSERT INTO Trn_MayContratos (NContrato,IdCia,Fecha,IdCliente,IdAgencia,IdTipo,IdBonif,ConvBonif,CuotaFija,CondPago,DiasGracia,ModPlazo,Plazo,FechaVence,ModRecursos,VrInversion,VrInventario,VrCuota,ModCuota,IdBandera,AprobJunta,FechaAprob
,ObservAprob,Observacion,IdVend,IdEstado,TimeSys,IdCiaCrea,IdUsuario,FechaInicio,CuotaMin,TipoAprob,NumInterno,InvCombus,CuotaBase
,FechaFirma,CdAprobNeg,ArchivoAprob,ClaseContrato,DescTipoCont,GarantHipoteca,GarantPrenda,GarantPoliza,GarantBanco,GarantPagare,GarantOtro,CdTipoBien,VrAvaludo,NroEscritura,CdTipoPoliza,DescPoliza,VigencPoliza,FecVencPoliza,ValorPoliza,EdoGarantias,DescGarantOtro,InverContab,InverContrac
,VolContMes,VolContTotal,VolViabMes,VolViabTotal,InvCtbObra,InvCtbCapital,InvCtbEfectivo,InvCtbImagen,InvCtbMntmto,FecDesemb,InvContObra,InvContCapital,InvContEfectivo,InvContImagen,CrtlAprovInv,CrtlAprovImg,CdTipoBloq,EdoDocmtos,DescEdoDoc,RentabInicial,GraciaBonif
,ActFechaIni,CdZonaCont,ContVigente,VolContrac,DescHipotec,VrAvaComerc,FecRegEscritura,NotariaEsc,CdTipPrenda,VrAvaPrenda,PolizaPrenda,FecVigPrenda,VrAsegPrenda,ContOperando)
 VALUES (@pmNContrato,@pmIdCia,@pmFecha,@pmIdCliente,@pmIdAgencia,@pmIdTipo,@pmIdBonif,@pmConvBonif,@pmCuotaFija,@pmCondPago,@pmDiasGracia,@pmModPlazo,@pmPlazo,@pmFechaVence,@pmModRecursos,@pmVrInversion
,@pmVrInventario,@pmVrCuota,@pmModCuota,@pmIdBandera,@pmAprobJunta,@pmFechaAprob,@pmObservAprob,@pmObservacion,@pmIdVend,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmFechaInicio,@pmCuotaMin,@pmTipoAprob,@pmNumInterno,@pmInvCombus,@pmCuotaBase
,@pmFechaFirma,@pmCdAprobNeg,@pmArchivoAprob,@pmClaseContrato,@pmDescTipoCont,@pmGarantHipoteca,@pmGarantPrenda,@pmGarantPoliza,@pmGarantBanco,@pmGarantPagare,@pmGarantOtro,@pmCdTipoBien,@pmVrAvaludo,@pmNroEscritura,@pmCdTipoPoliza,@pmDescPoliza,@pmVigencPoliza,@pmFecVencPoliza,@pmValorPoliza
,@pmEdoGarantias,@pmDescGarantOtro,@pmInverContab,@pmInverContrac,@pmVolContMes,@pmVolContTotal,@pmVolViabMes,@pmVolViabTotal,@pmInvCtbObra,@pmInvCtbCapital,@pmInvCtbEfectivo,@pmInvCtbImagen,@pmInvCtbMntmto,@pmFecDesemb,@pmInvContObra,@pmInvContCapital,@pmInvContEfectivo,@pmInvContImagen
,@pmCrtlAprovInv,@pmCrtlAprovImg,@pmCdTipoBloq,@pmEdoDocmtos,@pmDescEdoDoc,@pmRentabInicial,@pmGraciaBonif,@pmActFechaIni,@pmCdZonaCont,@pmContVigente,@pmVolContrac,@pmDescHipotec,@pmVrAvaComerc,@pmFecRegEscritura,@pmNotariaEsc,@pmCdTipPrenda,@pmVrAvaPrenda,@pmPolizaPrenda,@pmFecVigPrenda,@pmVrAsegPrenda,@pmContOperando)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50)
,@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO MayEstados (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayInventario] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdArticulo VARCHAR(16),@pmDetalle VARCHAR(150)
,@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrTotal MONEY,@pmTipoArticulo VARCHAR(10),@pmReferencia VARCHAR(50)
,@pmIdTipo VARCHAR(4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCantEntrega DECIMAL(14,4)
,@pmFecEntrega SMALLDATETIME,@pmEstado VARCHAR(10),@pmCdProd VARCHAR(16),@pmNumReq INT,@pmIdCiaReq CHAR(2),@pmCantReq DECIMAL(14,4)
,@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmCantOrden DECIMAL(14,4)
 AS 
 INSERT INTO Trn_MayInventario (NContrato,IdCia,Item,IdArticulo,Detalle,Cantidad,VrUnitario,VrTotal,TipoArticulo,Referencia,IdTipo,TipDoc,Documento,IdCiaDoc
,CantEntrega,FecEntrega,Estado,CdProd,NumReq,IdCiaReq,CantReq,NumOrden,IdCiaOrd,CantOrden)
 VALUES (@pmNContrato,@pmIdCia,@pmItem,@pmIdArticulo,@pmDetalle,@pmCantidad,@pmVrUnitario,@pmVrTotal,@pmTipoArticulo,@pmReferencia
,@pmIdTipo,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmCantEntrega,@pmFecEntrega,@pmEstado
,@pmCdProd,@pmNumReq,@pmIdCiaReq,@pmCantReq,@pmNumOrden,@pmIdCiaOrd,@pmCantOrden)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayInvmov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayInvmov] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFechaDoc SMALLDATETIME,@pmIdArticulo VARCHAR(16)
,@pmCantidad DECIMAL(14,4),@pmNContrato INT,@pmIdCiaCon CHAR(2),@pmItemArt INT
 AS 
 INSERT INTO Trn_MayInvmov (TipDoc,Documento,IdCia,Item,FechaDoc,IdArticulo,Cantidad,NContrato,IdCiaCon,ItemArt)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFechaDoc,@pmIdArticulo,@pmCantidad,@pmNContrato,@pmIdCiaCon,@pmItemArt)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayItemsInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayItemsInv] @pmIdArticulo VARCHAR(16),@pmDescrpcion VARCHAR(150),@pmUndMed VARCHAR(10)
,@pmGrupoArt VARCHAR(50),@pmCdProducto VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO MayItemsInv (IdArticulo,Descrpcion,UndMed,GrupoArt,CdProducto,Inactivo)
 VALUES (@pmIdArticulo,@pmDescrpcion,@pmUndMed,@pmGrupoArt,@pmCdProducto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayLiqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayLiqDetalle] @pmNLiquida INT,@pmIdCia CHAR(2),@pmNContrato INT,@pmIdCiaCon CHAR(2)
,@pmItem INT,@pmIdSubgrupo VARCHAR(8),@pmCombustible BIT,@pmUnidades DECIMAL(14,4),@pmUnidDev DECIMAL(14,4)
,@pmValorTotal MONEY,@pmValorDev MONEY,@pmIntervalo VARCHAR(50),@pmMargen DECIMAL(14,4)
,@pmTarifa DECIMAL(14,4),@pmTipoTarifa CHAR(1),@pmVrLiquida MONEY,@pmLogDetalle VARCHAR(250),@pmSubsidio  DECIMAL(14,4)
,@pmVenGalones DECIMAL(14,4),@pmVenTotal MONEY,@pmCantExcluido DECIMAL(14,4),@pmMgnNeto DECIMAL(14,4),@pmTipoMargen CHAR(1)
,@pmPorcIvaCom DECIMAL(14,4),@pmVrIvaCom DECIMAL(16,4),@pmIvaIncBonif BIT,@pmCdAgenc VARCHAR(16),@pmVrBaseIva DECIMAL(16,4),@pmVrLiquidaNeto MONEY
 AS 
 INSERT INTO Trn_MayLiqDetalle (NLiquida,IdCia,NContrato,IdCiaCon,Item,IdSubgrupo,Combustible,Unidades,UnidDev,ValorTotal
,ValorDev,Intervalo,Margen,Tarifa,TipoTarifa,VrLiquida,LogDetalle,Subsidio,VenGalones,VenTotal,CantExcluido,MgnNeto,TipoMargen
,PorcIvaCom,VrIvaCom,IvaIncBonif,CdAgenc,VrBaseIva,VrLiquidaNeto)
 VALUES (@pmNLiquida,@pmIdCia,@pmNContrato,@pmIdCiaCon,@pmItem,@pmIdSubgrupo,@pmCombustible,@pmUnidades
,@pmUnidDev,@pmValorTotal,@pmValorDev,@pmIntervalo,@pmMargen,@pmTarifa,@pmTipoTarifa,@pmVrLiquida
,@pmLogDetalle,@pmSubsidio,@pmVenGalones,@pmVenTotal,@pmCantExcluido,@pmMgnNeto,@pmTipoMargen,@pmPorcIvaCom,@pmVrIvaCom,@pmIvaIncBonif,@pmCdAgenc,@pmVrBaseIva,@pmVrLiquidaNeto)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayLiqTotales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayLiqTotales] @pmNLiquida INT,@pmIdCia CHAR(2),@pmItem INT,@pmNContrato INT,@pmIdCiaCon CHAR(2)
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmUnidades DECIMAL(14,4),@pmVrBonif MONEY,@pmVrAbono MONEY
,@pmVrCuotaFija MONEY,@pmDiasGracia INT,@pmTipoNcr VARCHAR(3),@pmNotaCred INT,@pmIdCiaNot CHAR(2),@pmLogLiquida VARCHAR(250)
,@pmVrIvaBonif DECIMAL(16,4),@pmBaseIvaBonif DECIMAL(16,4),@pmVrBonifNeto MONEY
 AS 
 INSERT INTO Trn_MayLiqTotales (NLiquida,IdCia,Item,NContrato,IdCiaCon,IdCliente,IdAgencia,Unidades,VrBonif,VrAbono
,VrCuotaFija,DiasGracia,TipoNcr,NotaCred,IdCiaNot,LogLiquida,VrIvaBonif,BaseIvaBonif,VrBonifNeto)
 VALUES (@pmNLiquida,@pmIdCia,@pmItem,@pmNContrato,@pmIdCiaCon,@pmIdCliente,@pmIdAgencia,@pmUnidades
,@pmVrBonif,@pmVrAbono,@pmVrCuotaFija,@pmDiasGracia,@pmTipoNcr,@pmNotaCred,@pmIdCiaNot,@pmLogLiquida,@pmVrIvaBonif,@pmBaseIvaBonif,@pmVrBonifNeto)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayLiquida] @pmNLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmEstado INT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MayLiquida (NLiquida,IdCia,Fecha,Observacion,Estado,FecDev,TipCom,Comprobante,IdCiaCom,TimeSys,IdUsuario)
 VALUES (@pmNLiquida,@pmIdCia,@pmFecha,@pmObservacion,@pmEstado,@pmFecDev,@pmTipCom,@pmComprobante
,@pmIdCiaCom,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayPspto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayPspto] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoProd VARCHAR(20),@pmCantidad DECIMAL(14,4),@pmUnidad VARCHAR(10)
,@pmCantMes DECIMAL(14,4),@pmCdProducto VARCHAR(16),@pmCdSubgrupo VARCHAR(8)
 AS 
 INSERT INTO Trn_MayPspto (NContrato,IdCia,Item,TipoProd,Cantidad,Unidad,CantMes,CdProducto,CdSubgrupo)
 VALUES (@pmNContrato,@pmIdCia,@pmItem,@pmTipoProd,@pmCantidad,@pmUnidad,@pmCantMes,@pmCdProducto,@pmCdSubgrupo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayTipos] @pmIdTipo VARCHAR(4),@pmTipContrato VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MayTipos (IdTipo,TipContrato,Inactivo)
 VALUES (@pmIdTipo,@pmTipContrato,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposAprob]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayTiposAprob] @pmIdAprob VARCHAR(4),@pmTipoAprob VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MayTiposAprob (IdAprob,TipoAprob,Inactivo)
 VALUES (@pmIdAprob,@pmTipoAprob,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposBienes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayTiposBienes] @pmIdTipBien VARCHAR(4),@pmTipoBien VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MayTiposBienes (IdTipBien,TipoBien,Inactivo)
 VALUES (@pmIdTipBien,@pmTipoBien,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposBonif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayTiposBonif] @pmIdBonif VARCHAR(4),@pmTipoBonif VARCHAR(50)
,@pmAboCartera BIT,@pmAboPstmo BIT,@pmInactivo BIT
 AS 
 INSERT INTO MayTiposBonif (IdBonif,TipoBonif,AboCartera,AboPstmo,Inactivo)
 VALUES (@pmIdBonif,@pmTipoBonif,@pmAboCartera,@pmAboPstmo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsMayTiposDoc] @pmIdDoc VARCHAR(4),@pmNombreDoc VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO MayTiposDoc (IdDoc,NombreDoc,Inactivo)
 VALUES (@pmIdDoc,@pmNombreDoc,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMayTiposPoliza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMayTiposPoliza] @pmIdTipoPol VARCHAR(4),@pmTipoPoliza VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MayTiposPoliza (IdTipoPol,TipoPoliza,Inactivo)
 VALUES (@pmIdTipoPol,@pmTipoPoliza,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMercancias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMercancias] @pmIdMercancia VARCHAR(16),@pmDescripMcia VARCHAR(250),@pmCodigoMcia VARCHAR(16),@pmIdGrupo VARCHAR(10),@pmUndMed VARCHAR(10)
,@pmIdUnd VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmEstadoMcia VARCHAR(20),@pmContenedor BIT
,@pmIdProducto VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmUmCapac VARCHAR(10),@pmCodigoUN VARCHAR(30),@pmUM_Prod VARCHAR(10),@pmCodArancel VARCHAR(5),@pmCodSubpartida VARCHAR(5),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Mercancias (IdMercancia,DescripMcia,CodigoMcia,IdGrupo,UndMed,IdUnd,IdEmp,IdNat,IdMnjo,IdTmcia,EstadoMcia,Contenedor,IdProducto,UmCapac,IdEstado,Inactivo,FechaAdd,IdUsuario,CodigoUN,UM_Prod,CodArancel,CodSubpartida)
 VALUES (@pmIdMercancia,@pmDescripMcia,@pmCodigoMcia,@pmIdGrupo,@pmUndMed,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmIdMnjo,@pmIdTmcia,@pmEstadoMcia,@pmContenedor,@pmIdProducto
,@pmUmCapac,@pmIdEstado,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmCodigoUN,@pmUM_Prod,@pmCodArancel,@pmCodSubpartida)
GO
/****** Object:  StoredProcedure [dbo].[paInsModulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsModulos] @pmIdMod VARCHAR(3),@pmConsecutivo INT,@pmDescripcion VARCHAR(50)
,@pmValor BIT,@pmnModulo VARCHAR(10)
 AS 
 INSERT INTO Sys_Modulos (IdMod,Consecutivo,Descripcion,Valor,nModulo)
 VALUES (@pmIdMod,@pmConsecutivo,@pmDescripcion,@pmValor,@pmnModulo)
GO
/****** Object:  StoredProcedure [dbo].[paInsmonedas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsmonedas] @pmIdMneda VARCHAR(5),@pmMneda VARCHAR(50),@pmSimbolo VARCHAR(10),@pmMneLocal BIT
,@pmVrCambio DECIMAL(12,6),@pmInactivo BIT
 AS 
 INSERT INTO adm_monedas (IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo)
 VALUES (@pmIdMneda,@pmMneda,@pmSimbolo,@pmMneLocal,@pmVrCambio,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoConceptos] @pmIdConc VARCHAR(4),@pmConcepto VARCHAR(150),@pmIdSistema VARCHAR(4),@pmIdMtto VARCHAR(4),@pmTipoControl INT
,@pmIntervalo_km INT,@pmIntervalo_dias INT,@pmReq_Parte BIT,@pmInactivo BIT,@pmCodigoMO VARCHAR(16),@pmIntervalo_Horas INT
,@pmCantHoras DECIMAL(14,2),@pmTarifaCosto DECIMAL(16,4),@pmTarifaClie DECIMAL(16,4),@pmIntvAlarma VARCHAR(50),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO MttoConceptos (IdConc,Concepto,IdSistema,IdMtto,TipoControl,Intervalo_km,Intervalo_dias,Intervalo_Horas,Req_Parte,CodigoMO,CantHoras,TarifaCosto,Inactivo,FechaCrea,IdUsuario,TarifaClie,IntvAlarma)
 VALUES (@pmIdConc,@pmConcepto,@pmIdSistema,@pmIdMtto,@pmTipoControl,@pmIntervalo_km,@pmIntervalo_dias,@pmIntervalo_Horas,@pmReq_Parte,@pmCodigoMO,@pmCantHoras,@pmTarifaCosto,@pmInactivo,@pmFechaCrea,@pmIdUsuario,@pmTarifaClie,@pmIntvAlarma)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoControles]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoControles] @pmTipoUnidad CHAR(1),@pmNumUnidad VARCHAR(10),@pmIdConc VARCHAR(4),@pmTipoControl INT,@pmIntervalo_km INT,@pmIntervalo_dias INT,@pmIntervalo_Horas INT,@pmkmUltMtto INT,@pmkmUltMttoRuta INT
,@pmkmUltMttoSat INT,@pmFecUltMtto SMALLDATETIME,@pmComentarios VARCHAR(1000),@pmInactivo BIT,@pmHsUltMtto INT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO MttoControles (TipoUnidad,NumUnidad,IdConc,TipoControl,Intervalo_km,Intervalo_dias,Intervalo_Horas,kmUltMtto,kmUltMttoRuta,kmUltMttoSat,FecUltMtto,HsUltMtto,Comentarios,Inactivo,FechaCrea,IdUsuario)
 VALUES (@pmTipoUnidad,@pmNumUnidad,@pmIdConc,@pmTipoControl,@pmIntervalo_km,@pmIntervalo_dias,@pmIntervalo_Horas,@pmkmUltMtto,@pmkmUltMttoRuta,@pmkmUltMttoSat,@pmFecUltMtto,@pmHsUltMtto,@pmComentarios,@pmInactivo,@pmFechaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO MttoEstados (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoInspecciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoInspecciones] @pmIdInspec VARCHAR(4),@pmInspeccion VARCHAR(150),@pmIdSistema VARCHAR(4),@pmIdMtto VARCHAR(4)
,@pmTipoDato INT,@pmUndMed VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MttoInspecciones (IdInspec,Inspeccion,IdSistema,IdMtto,TipoDato,UndMed,Inactivo)
 VALUES (@pmIdInspec,@pmInspeccion,@pmIdSistema,@pmIdMtto,@pmTipoDato,@pmUndMed,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoOrden]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaOrden SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdTipoOdt VARCHAR(4),@pmIdCenSer VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmIdOperario VARCHAR(16),@pmIdSupervisor VARCHAR(16),@pmModalidad VARCHAR(10),@pmkmVehiculo INT,@pmkmRemolque INT,@pmVrServicios MONEY,@pmVrRepuestos MONEY,@pmVrManoObra MONEY,@pmVrOtros MONEY,@pmFechaCierre SMALLDATETIME
,@pmNitCenSer VARCHAR(16),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmCdEstadoVeh VARCHAR(4),@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmIdCiaFact CHAR(2),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MttoOrden (TipDoc,NumOrden,IdCia,Fecha,FechaOrden,FechaVence,IdTipoOdt,IdCenSer,IdVehiculo,nRemolque,IdConductor,IdOperario,IdSupervisor,Modalidad,kmVehiculo,kmRemolque,VrServicios,VrRepuestos,VrManoObra,VrOtros,FechaCierre,NitCenSer,CdEstadoVeh
,IdEstado,Anulado,NumDev,FecDev,Observacion,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,TipFact,NumFactura,IdCiaFact)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmFechaOrden,@pmFechaVence,@pmIdTipoOdt,@pmIdCenSer,@pmIdVehiculo,@pmnRemolque,@pmIdConductor,@pmIdOperario,@pmIdSupervisor,@pmModalidad,@pmkmVehiculo,@pmkmRemolque,@pmVrServicios,@pmVrRepuestos
,@pmVrManoObra,@pmVrOtros,@pmFechaCierre,@pmNitCenSer,@pmCdEstadoVeh,@pmIdEstado,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipFact,@pmNumFactura,@pmIdCiaFact)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoOrdenDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoOrdenDet] @pmTipOdt VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmFechaServ SMALLDATETIME,@pmIdConc VARCHAR(4),@pmDescripcion VARCHAR(1000),@pmCantidad DECIMAL(14,4)
,@pmVrUnitario DECIMAL(16,6),@pmUndMed VARCHAR(50),@pmCdMtto VARCHAR(4),@pmIdEstado VARCHAR(4),@pmIdOperario VARCHAR(16),@pmNumVehic VARCHAR(10),@pmNumParte VARCHAR(20)
,@pmReq_Rep BIT,@pmReq_MO BIT,@pmTipoServ VARCHAR(10),@pmCodCentro VARCHAR(4),@pmNitCenServ VARCHAR(16),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MttoOrdenDet (TipOdt,NumOrden,IdCia,Item,FechaServ,IdConc,Descripcion,Cantidad,VrUnitario,UndMed,CdMtto,IdEstado,IdOperario,NumVehic,NumParte,Req_Rep,Req_MO,FechaCrea,IdUsuario,TipoServ,CodCentro,NitCenServ)
 VALUES (@pmTipOdt,@pmNumOrden,@pmIdCia,@pmItem,@pmFechaServ,@pmIdConc,@pmDescripcion,@pmCantidad,@pmVrUnitario,@pmUndMed,@pmCdMtto,@pmIdEstado,@pmIdOperario,@pmNumVehic,@pmNumParte
,@pmReq_Rep,@pmReq_MO,@pmFechaCrea,@pmIdUsuario,@pmTipoServ,@pmCodCentro,@pmNitCenServ)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoOrdenReq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoOrdenReq] @pmTipReq VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoItem VARCHAR(10),@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmIdUnd VARCHAR(4),@pmVrUnitario DECIMAL(16,6),@pmCdBodega VARCHAR(4)
,@pmTipOdt VARCHAR(3),@pmNumOrden INT,@pmIdCiaOdt CHAR(2),@pmEstadoReq INT,@pmIdOperario VARCHAR(16),@pmCdCenServ VARCHAR(4),@pmNitTercero VARCHAR(16),@pmNumVehic VARCHAR(10),@pmNumParte VARCHAR(20),@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2),@pmCantSalida DECIMAL(14,4)
,@pmObservacion VARCHAR(1000),@pmCdConcServ VARCHAR(4),@pmVrPrecioUnd MONEY,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MttoOrdenReq (TipReq,Requisicion,IdCia,Item,TipoItem,IdProducto,Descripcion,Cantidad,IdUnd,VrUnitario,CdBodega,TipOdt,NumOrden,IdCiaOdt,EstadoReq,IdOperario,CdCenServ,NitTercero,NumVehic,NumParte,TipSal,NumSalida,IdCiaSal,CantSalida,Observacion,FechaCrea,IdUsuario,CdConcServ,VrPrecioUnd)
 VALUES (@pmTipReq,@pmRequisicion,@pmIdCia,@pmItem,@pmTipoItem,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmIdUnd,@pmVrUnitario,@pmCdBodega,@pmTipOdt,@pmNumOrden,@pmIdCiaOdt,@pmEstadoReq,@pmIdOperario,@pmCdCenServ,@pmNitTercero,@pmNumVehic,@pmNumParte,@pmTipSal,@pmNumSalida,@pmIdCiaSal,@pmCantSalida
,@pmObservacion,@pmFechaCrea,@pmIdUsuario,@pmCdConcServ,@pmVrPrecioUnd)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoSistemas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoSistemas] @pmIdSistema VARCHAR(4),@pmSistema VARCHAR(50),@pmSeccion CHAR(1),@pmInactivo BIT
 AS 
 INSERT INTO MttoSistemas (IdSistema,Sistema,Seccion,Inactivo)
 VALUES (@pmIdSistema,@pmSistema,@pmSeccion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoTipos] @pmIdMtto VARCHAR(4),@pmTipoMtto VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MttoTipos (IdMtto,TipoMtto,Inactivo)
 VALUES (@pmIdMtto,@pmTipoMtto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoTiposOdt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoTiposOdt] @pmIdTipoOdt VARCHAR(4),@pmTipoOrden VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO MttoTiposOdt (IdTipoOdt,TipoOrden,Inactivo)
 VALUES (@pmIdTipoOdt,@pmTipoOrden,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMttoTrabajos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMttoTrabajos] @pmFecha SMALLDATETIME,@pmIdConc VARCHAR(4),@pmTipoMtto INT,@pmTipoUnidad CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmTipDoc VARCHAR(3)
,@pmNumOrden INT,@pmIdCia CHAR(2),@pmNumParte VARCHAR(20),@pmCantHoras INT,@pmkmActual INT,@pmKmRuta INT,@pmkmOtro INT,@pmkmAntMtto INT,@pmKmAntMtto2 INT,@pmkmAntMtto3 INT,@pmFecAntMtto SMALLDATETIME
 AS 
 INSERT INTO Trn_MttoTrabajos (Fecha,IdConc,TipoMtto,TipoUnidad,IdVehiculo,nRemolque,TipDoc,NumOrden,IdCia,NumParte,CantHoras,kmActual,KmRuta,kmOtro,kmAntMtto,KmAntMtto2,kmAntMtto3,FecAntMtto)
 VALUES (@pmFecha,@pmIdConc,@pmTipoMtto,@pmTipoUnidad,@pmIdVehiculo,@pmnRemolque,@pmTipDoc,@pmNumOrden,@pmIdCia,@pmNumParte,@pmCantHoras,@pmkmActual,@pmKmRuta,@pmkmOtro,@pmkmAntMtto,@pmKmAntMtto2,@pmkmAntMtto3,@pmFecAntMtto)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudArticulos] @pmIdArticulo VARCHAR(16),@pmArticulo VARCHAR(250),@pmIdSeccion VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO MudArticulos (IdArticulo,Articulo,IdSeccion,Inactivo)
 VALUES (@pmIdArticulo,@pmArticulo,@pmIdSeccion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudContNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudContNov] @pmTipDoc VARCHAR(3),@pmNumContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipoNov VARCHAR(10),@pmDescripcion VARCHAR(500),@pmTarifaServ DECIMAL(16,4),@pmTipInv VARCHAR(3),@pmNumInvent INT,@pmCdCiaInv CHAR(2),@pmItemInv INT
,@pmCdArticulo VARCHAR(16),@pmCantidad DECIMAL(14,4),@pmCdEstado VARCHAR(4),@pmCdBodega VARCHAR(4),@pmCdBodDest VARCHAR(4),@pmNumDocRef VARCHAR(20),@pmIdUsuario VARCHAR(11),@pmNotas VARCHAR(2500)
 AS 
 INSERT INTO Trn_MudContNov (TipDoc,NumContrato,IdCia,Item,Fecha,TipoNov,Descripcion,TarifaServ,TipInv,NumInvent,CdCiaInv,ItemInv,CdArticulo,Cantidad,CdEstado,CdBodega,CdBodDest,NumDocRef,IdUsuario,Notas)
 VALUES (@pmTipDoc,@pmNumContrato,@pmIdCia,@pmItem,@pmFecha,@pmTipoNov,@pmDescripcion,@pmTarifaServ,@pmTipInv,@pmNumInvent,@pmCdCiaInv,@pmItemInv,@pmCdArticulo,@pmCantidad,@pmCdEstado,@pmCdBodega,@pmCdBodDest,@pmNumDocRef,@pmIdUsuario,@pmNotas)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudContratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudContratos] @pmTipDoc VARCHAR(3),@pmNumContrato INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCdBodega2 VARCHAR(4),@pmVrServicio MONEY,@pmVrImpuesto MONEY,@pmVrDeclarado MONEY
,@pmVrSeguro MONEY,@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmFechaRetiro SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(30),@pmemlContacto VARCHAR(150),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MudContratos (TipDoc,NumContrato,IdCia,Fecha,FechaInicio,FechaFinal,IdCliente,IdAgencia,IdBodega,CdBodega2,VrServicio,VrImpuesto,VrDeclarado,VrSeguro,TipOrden,NumOrden,IdCiaOrden,FechaRetiro,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,NomContacto,TelsContacto,emlContacto)
 VALUES (@pmTipDoc,@pmNumContrato,@pmIdCia,@pmFecha,@pmFechaInicio,@pmFechaFinal,@pmIdCliente,@pmIdAgencia,@pmIdBodega,@pmCdBodega2,@pmVrServicio,@pmVrImpuesto,@pmVrDeclarado,@pmVrSeguro,@pmTipOrden,@pmNumOrden,@pmIdCiaOrden,@pmFechaRetiro,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNomContacto,@pmTelsContacto,@pmemlContacto)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO MudEstados (IdEstado,Estado,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstado,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudInventario] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdTipoServ VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirCargue VARCHAR(500),@pmTipoInmRem VARCHAR(30),@pmPisoCargue VARCHAR(10),@pmTelsRemite VARCHAR(30),@pmCelRemite VARCHAR(30),@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDescargue VARCHAR(500)
,@pmTipoInmDest VARCHAR(30),@pmPisoDescargue VARCHAR(10),@pmTelsDest VARCHAR(30),@pmCelDest VARCHAR(30),@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdVend VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmNitEmpresa VARCHAR(16),@pmNomEmpresa VARCHAR(150),@pmCajasEmp INT,@pmCajasClie INT,@pmVrDeclarado MONEY,@pmVrServicio MONEY,@pmNumCotizac VARCHAR(20),@pmNumPlanilla VARCHAR(20),@pmNumActa VARCHAR(20)
,@pmTipOsm VARCHAR(3),@pmNumOrden INT,@pmIdCiaOsm CHAR(2),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmResponsable VARCHAR(150),@pmFormaPago VARCHAR(50),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmContactoDest VARCHAR(150),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MudInventario (TipDoc,NumInvent,IdCia,Fecha,FecDespacho,IdTipoServ,IdCliente,IdAgencia,IdRemitente,Remitente,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,IdDestinatario,Destinatario,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,IdOrigen,IdDestino,IdVend,pVehiculo,CdConductor,nRemolque,TipoAfiVehic,NitEmpresa,NomEmpresa,CajasEmp,CajasClie,VrDeclarado,VrServicio,NumCotizac,NumPlanilla,NumActa,TipOsm,NumOrden,IdCiaOsm,NomContacto,TelsContacto,emlContacto,Responsable
,FormaPago,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,ContactoDest)
 VALUES (@pmTipDoc,@pmNumInvent,@pmIdCia,@pmFecha,@pmFecDespacho,@pmIdTipoServ,@pmIdCliente,@pmIdAgencia,@pmIdRemitente,@pmRemitente,@pmDirCargue,@pmTipoInmRem,@pmPisoCargue,@pmTelsRemite,@pmCelRemite,@pmIdDestinatario,@pmDestinatario,@pmDirDescargue,@pmTipoInmDest,@pmPisoDescargue,@pmTelsDest,@pmCelDest,@pmIdOrigen,@pmIdDestino,@pmIdVend,@pmpVehiculo,@pmCdConductor,@pmnRemolque,@pmTipoAfiVehic,@pmNitEmpresa,@pmNomEmpresa,@pmCajasEmp,@pmCajasClie,@pmVrDeclarado,@pmVrServicio
,@pmNumCotizac,@pmNumPlanilla,@pmNumActa,@pmTipOsm,@pmNumOrden,@pmIdCiaOsm,@pmNomContacto,@pmTelsContacto,@pmemlContacto,@pmResponsable,@pmFormaPago,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmContactoDest)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudOrdenConc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudOrdenConc] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDescripcion VARCHAR(500),@pmValorTotal MONEY,@pmTarifaIva DECIMAL(14,4),@pmTipoConc VARCHAR(10),@pmTipoRubro VARCHAR(20)
,@pmTipoReg INT,@pmCdCuenta VARCHAR(16),@pmNitTercero VARCHAR(16),@pmReferencia VARCHAR(50),@pmNumDocRef VARCHAR(20),@pmCodTarIva VARCHAR(4),@pmIndFactItem INT,@pmNumDocFac VARCHAR(20),@pmTarifSeguro DECIMAL(14,4),@pmCodTarSeg VARCHAR(4),@pmPlacaVehic VARCHAR(10),@pmTarifaPago MONEY
,@pmFechaReg SMALLDATETIME,@pmCdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MudOrdenConc (TipDoc,NumOrden,IdCia,Item,IdConcepto,Descripcion,ValorTotal,TarifaIva,TipoConc,TipoRubro,TipoReg,CdCuenta,NitTercero,Referencia,NumDocRef,CodTarIva,IndFactItem,NumDocFac,TarifSeguro,CodTarSeg,PlacaVehic,TarifaPago,FechaReg,CdUsuario)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmItem,@pmIdConcepto,@pmDescripcion,@pmValorTotal,@pmTarifaIva,@pmTipoConc,@pmTipoRubro,@pmTipoReg,@pmCdCuenta,@pmNitTercero,@pmReferencia,@pmNumDocRef,@pmCodTarIva,@pmIndFactItem,@pmNumDocFac,@pmTarifSeguro,@pmCodTarSeg,@pmPlacaVehic,@pmTarifaPago,@pmFechaReg,@pmCdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudOrdenServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdTipoServ VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmDirCargue VARCHAR(500),@pmTipoInmRem VARCHAR(30),@pmPisoCargue VARCHAR(10),@pmTelsRemite VARCHAR(30),@pmCelRemite VARCHAR(30),@pmDirDescargue VARCHAR(500)
,@pmTipoInmDest VARCHAR(30),@pmPisoDescargue VARCHAR(10),@pmTelsDest VARCHAR(30),@pmCelDest VARCHAR(30),@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmVrServicio MONEY,@pmVrEmpaque MONEY,@pmVrBodega MONEY,@pmVrOtros MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrNeto MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmServicios VARCHAR(50),@pmFormaPago VARCHAR(50),@pmReferencia VARCHAR(50)
,@pmTipInv VARCHAR(3),@pmNumInvent INT,@pmIdCiaInv CHAR(2),@pmTipRem VARCHAR(3),@pmNumRemesa INT,@pmIdCiaRem CHAR(2),@pmEstFactura INT,@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmCdCiaFact CHAR(2),@pmTipCausac VARCHAR(3),@pmCausacion INT,@pmCdCiaCau CHAR(2),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmContactoDest VARCHAR(150),@pmemlContDest VARCHAR(100)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmEstCumplido INT,@pmFechaCump SMALLDATETIME,@pmTipoRuta VARCHAR(10),@pmVolumen VARCHAR(50),@pmEstadoBod INT,@pmCdBodega VARCHAR(4),@pmFechaIngBod SMALLDATETIME,@pmFechaRetBod SMALLDATETIME,@pmNitRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmNitDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150)
,@pmNumAutCupo INT,@pmNumAutMora INT,@pmReferencias VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_MudOrdenServ (TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdTipoServ,IdCliente,IdAgencia,IdVend,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,IdOrigen,IdDestino,VrServicio,VrEmpaque,VrBodega,VrOtros,VrDescuento,VrImpuesto,VrNeto,VrDeclarado,VrSeguro,Servicios,FormaPago,Referencia,TipInv,NumInvent,IdCiaInv
,TipRem,NumRemesa,IdCiaRem,EstFactura,TipFact,NumFactura,CdCiaFact,TipCausac,Causacion,CdCiaCau,NomContacto,TelsContacto,emlContacto,ContactoDest,emlContDest,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,EstCumplido,FechaCump,TipoRuta,Volumen,EstadoBod,CdBodega,FechaIngBod,FechaRetBod,NitRemitente,Remitente,NitDestinatario,Destinatario,NumAutCupo,NumAutMora,Referencias)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmFecDespacho,@pmIdTipoServ,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmDirCargue,@pmTipoInmRem,@pmPisoCargue,@pmTelsRemite,@pmCelRemite,@pmDirDescargue,@pmTipoInmDest,@pmPisoDescargue,@pmTelsDest,@pmCelDest,@pmIdOrigen,@pmIdDestino,@pmVrServicio,@pmVrEmpaque,@pmVrBodega,@pmVrOtros,@pmVrDescuento,@pmVrImpuesto,@pmVrNeto,@pmVrDeclarado,@pmVrSeguro
,@pmServicios,@pmFormaPago,@pmReferencia,@pmTipInv,@pmNumInvent,@pmIdCiaInv,@pmTipRem,@pmNumRemesa,@pmIdCiaRem,@pmEstFactura,@pmTipFact,@pmNumFactura,@pmCdCiaFact,@pmTipCausac,@pmCausacion,@pmCdCiaCau,@pmNomContacto,@pmTelsContacto,@pmemlContacto,@pmContactoDest,@pmemlContDest,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmEstCumplido,@pmFechaCump
,@pmTipoRuta,@pmVolumen,@pmEstadoBod,@pmCdBodega,@pmFechaIngBod,@pmFechaRetBod,@pmNitRemitente,@pmRemitente,@pmNitDestinatario,@pmDestinatario,@pmNumAutCupo,@pmNumAutMora,@pmReferencias)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudOrdenVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudOrdenVeh] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdVehiculo VARCHAR(10),@pmTipoAfiVehic VARCHAR(10)
,@pmNitEmpresa VARCHAR(16),@pmNomEmpresa VARCHAR(150),@pmnRemolque VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdCondAux VARCHAR(16)
,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmCdCiaRef CHAR(2),@pmCdTipoOper VARCHAR(4),@pmTipoIngreso VARCHAR(10),@pmTarifaIng DECIMAL(14,4),@pmVrIngreso MONEY
 AS 
 INSERT INTO Trn_MudOrdenVeh (TipDoc,NumOrden,IdCia,Item,IdVehiculo,TipoAfiVehic,NitEmpresa,NomEmpresa,nRemolque,IdConductor,IdCondAux,TipDocRef,NumDocRef,CdCiaRef,CdTipoOper,TipoIngreso,TarifaIng,VrIngreso)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmItem,@pmIdVehiculo,@pmTipoAfiVehic,@pmNitEmpresa,@pmNomEmpresa,@pmnRemolque,@pmIdConductor,@pmIdCondAux,@pmTipDocRef,@pmNumDocRef,@pmCdCiaRef,@pmCdTipoOper,@pmTipoIngreso,@pmTarifaIng,@pmVrIngreso)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudSecciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudSecciones] @pmIdSeccion VARCHAR(4),@pmSeccion VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO MudSecciones (IdSeccion,Seccion,Inactivo)
 VALUES (@pmIdSeccion,@pmSeccion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsMudServicios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsMudServicios] @pmIdTipoServ VARCHAR(4),@pmTipoServicio VARCHAR(150),@pmTransporte BIT,@pmBodega BIT,@pmEmpaque BIT,@pmPersonal BIT,@pmInactivo BIT
 AS 
 INSERT INTO MudServicios (IdTipoServ,TipoServicio,Transporte,Bodega,Empaque,Personal,Inactivo)
 VALUES (@pmIdTipoServ,@pmTipoServicio,@pmTransporte,@pmBodega,@pmEmpaque,@pmPersonal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNERecord]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNERecord] @pmTipoReg VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmIdRegNom VARCHAR(30),@pmNumLiquida INT,@pmNumSemLiq INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmCantNoRem DECIMAL(10,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmIdDep VARCHAR(4),@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrATransMes MONEY,@pmpVehiculo VARCHAR(10),@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME
,@pmDiasVac INT,@pmNPeriodos INT,@pmCantRem INT,@pmVrRemndo MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmEsRetiro BIT,@pmNLiqRet INT,@pmTipoLiq CHAR(1),@pmEsParcial BIT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmCdTipoCot VARCHAR(4),@pmSubTipo_Cot VARCHAR(3),@pmSal_Integral BIT,@pmTipoIdent CHAR(1),@pmNotasAportante VARCHAR(250),@pmCantModifica INT,@pmNE_Estado INT,@pmNE_Prefijo VARCHAR(20),@pmNE_Numero INT,@pmNE_FecEnvio SMALLDATETIME,@pmNE_CUNE VARCHAR(500),@pmNE_CntAju INT,@pmNE_Ajustes VARCHAR(500)
 AS 
 INSERT INTO Trn_NERecord (TipoReg,NumRegistro,IdCia,Fecha,IdPeriodo,IdEmpleado,NContrato,IdRegNom,NumLiquida,NumSemLiq,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,FecIniPmd,FecFinPmd,DiasVac,NPeriodos,CantRem,VrRemndo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,EsParcial,FechaCrea,IdUsuario,CdTipoCot,SubTipo_Cot,Sal_Integral,TipoIdent,NotasAportante,CantModifica,NE_Estado,NE_Prefijo,NE_Numero,NE_FecEnvio,NE_CUNE,NE_CntAju,NE_Ajustes)
 VALUES (@pmTipoReg,@pmNumRegistro,@pmIdCia,@pmFecha,@pmIdPeriodo,@pmIdEmpleado,@pmNContrato,@pmIdRegNom,@pmNumLiquida,@pmNumSemLiq,@pmFecInicial,@pmFecFinal,@pmCantidad,@pmCantNoRem,@pmVrDevengado,@pmVrDeducido,@pmIdDep,@pmIdInstala,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmVrSalario,@pmVrATransMes,@pmpVehiculo,@pmFecIniPmd,@pmFecFinPmd,@pmDiasVac,@pmNPeriodos,@pmCantRem,@pmVrRemndo,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmEsRetiro,@pmNLiqRet,@pmTipoLiq,@pmEsParcial,@pmFechaCrea,@pmIdUsuario,@pmCdTipoCot,@pmSubTipo_Cot,@pmSal_Integral,@pmTipoIdent,@pmNotasAportante,@pmCantModifica,@pmNE_Estado,@pmNE_Prefijo,@pmNE_Numero,@pmNE_FecEnvio,@pmNE_CUNE,@pmNE_CntAju,@pmNE_Ajustes)
GO
/****** Object:  StoredProcedure [dbo].[paInsNERecordDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNERecordDet] @pmTipoReg VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(250),@pmCantDevg DECIMAL(10,4),@pmCantDed DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrTotDevg MONEY,@pmVrTotDed MONEY,@pmUnidad VARCHAR(10),@pmClaseLiq VARCHAR(10),@pmVrOrigen MONEY
,@pmTarifa DECIMAL(10,4),@pmDiasCalc DECIMAL(10,4),@pmDiasNov DECIMAL(10,4),@pmCodFondo VARCHAR(8),@pmNPrestamo INT,@pmNCuota INT,@pmOrigCargue VARCHAR(10),@pmVrBaseLiq MONEY,@pmVrBasExceso MONEY,@pmNitTercero VARCHAR(16),@pmHoraInicial DATETIME,@pmHoraFinal DATETIME,@pmTipoIncLab VARCHAR(20)
 AS 
 INSERT INTO Trn_NERecordDet (TipoReg,NumRegistro,IdCia,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,NitTercero,HoraInicial,HoraFinal,TipoIncLab)
 VALUES (@pmTipoReg,@pmNumRegistro,@pmIdCia,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantDevg,@pmCantDed,@pmVrUnitario,@pmVrTotDevg,@pmVrTotDed,@pmUnidad,@pmClaseLiq,@pmVrOrigen,@pmTarifa,@pmDiasCalc,@pmDiasNov,@pmCodFondo,@pmNPrestamo,@pmNCuota,@pmOrigCargue,@pmVrBaseLiq,@pmVrBasExceso,@pmNitTercero,@pmHoraInicial,@pmHoraFinal,@pmTipoIncLab)
GO
/****** Object:  StoredProcedure [dbo].[paInsNiifComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNiifComp] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrTotal MONEY,@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmTipEgr VARCHAR(3),@pmNEgreso INT,@pmpVehiculo VARCHAR(10),@pmVehPropio INT,@pmCedCondtor VARCHAR(16),@pmCodConce VARCHAR(4),@pmBeneficiario VARCHAR(250),@pmVrDivisa1 DECIMAL(16,6),@pmVrDivisa2 DECIMAL(16,6),@pmVrDivisa3 DECIMAL(16,6)
,@pmPermEditar BIT,@pmIntegrado BIT,@pmEsEgreso BIT,@pmAnticipo BIT,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmTipoNiif VARCHAR(10),@pmCdSustento VARCHAR(4),@pmTipo_Pago VARCHAR(10),@pmEstablec VARCHAR(20),@pmPEmision VARCHAR(20),@pmAutorizac VARCHAR(50),@pmFechaAut SMALLDATETIME
,@pmCtbTipo VARCHAR(3),@pmCtbNumero INT,@pmFisTipo VARCHAR(3),@pmFisNumero INT,@pmPropddes VARCHAR(50),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NiifComp (TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso
,Anticipo,Observacion,IdEstado,Propddes,TimeSys,IdCiaCrea,IdUsuario,TipoNiif,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,CtbTipo,CtbNumero,FisTipo,FisNumero)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmFecha,@pmIdTercero,@pmVrTotal,@pmIdCta,@pmEnEfectivo,@pmNumCheque,@pmFecCheque,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmAnulado,@pmNumDev,@pmFecDev,@pmTipEgr,@pmNEgreso,@pmpVehiculo,@pmVehPropio,@pmCedCondtor,@pmCodConce,@pmBeneficiario
,@pmVrDivisa1,@pmVrDivisa2,@pmVrDivisa3,@pmPermEditar,@pmIntegrado,@pmEsEgreso,@pmAnticipo,@pmObservacion,@pmIdEstado,@pmPropddes,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoNiif,@pmCdSustento,@pmTipo_Pago,@pmEstablec,@pmPEmision,@pmAutorizac,@pmFechaAut,@pmCtbTipo,@pmCtbNumero,@pmFisTipo,@pmFisNumero)
GO
/****** Object:  StoredProcedure [dbo].[paInsNiifDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNiifDetalle] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmVrBase MONEY,@pmTarifaBase DECIMAL(14,4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmNitDoc VARCHAR(16)
,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4),@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmVehPropio INT,@pmReferncia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmTimeSys SMALLDATETIME
,@pmFecUpdate SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11),@pmCdConcTrib VARCHAR(4),@pmCdTarifTrib VARCHAR(4),@pmNumEstablec VARCHAR(20),@pmPtoEmision VARCHAR(20),@pmNum_Autoriza VARCHAR(50),@pmFechAutoriza SMALLDATETIME,@pmCodCuentaCG VARCHAR(16)
 AS 
 INSERT INTO Trn_NiifDetalle (TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza,CodCuentaCG)
 VALUES (@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmIdCuenta,@pmDetalle,@pmVrDebito,@pmVrCredito,@pmIdTercero,@pmIdVehiculo,@pmIdCCosto,@pmIdSubCos,@pmVrBase,@pmTarifaBase,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmCodConce,@pmNitDoc,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmCodCta,@pmNumCheque,@pmIntegrado,@pmTipoAplica,@pmConsolida,@pmCodCargo,@pmNitOtros,@pmCodSubgpo,@pmCiuOrigen,@pmCodAgncia,@pmVehPropio,@pmReferncia
,@pmTipDocRef,@pmDocRef,@pmIdCiaRef,@pmTimeSys,@pmFecUpdate,@pmIdCiaCrea,@pmIdUsuario,@pmCdConcTrib,@pmCdTarifTrib,@pmNumEstablec,@pmPtoEmision,@pmNum_Autoriza,@pmFechAutoriza,@pmCodCuentaCG)
GO
/****** Object:  StoredProcedure [dbo].[paInsNiifPoliticas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNiifPoliticas] @pmIdPolitica INT,@pmDescripcion VARCHAR(250),@pmClasePol VARCHAR(100),@pmObjetivo VARCHAR(1000),@pmAlcance VARCHAR(2500),@pmReconocimiento VARCHAR(2500),@pmMed_Inicial VARCHAR(2000)
,@pmMed_Final VARCHAR(2000),@pmPdoVigencia INT,@pmVigencia VARCHAR(250),@pmNotas VARCHAR(1000),@pmAnexo VARCHAR(150),@pmInactivo BIT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NiifPoliticas (IdPolitica,Descripcion,ClasePol,Objetivo,Alcance,Reconocimiento,Med_Inicial,Med_Final,PdoVigencia,Vigencia,Notas,Anexo,Inactivo,FechaCrea,IdUsuario)
 VALUES (@pmIdPolitica,@pmDescripcion,@pmClasePol,@pmObjetivo,@pmAlcance,@pmReconocimiento,@pmMed_Inicial,@pmMed_Final,@pmPdoVigencia,@pmVigencia,@pmNotas,@pmAnexo,@pmInactivo,@pmFechaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAbonos] @pmNPrestamo INT,@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmFechaAbo SMALLDATETIME
,@pmVrAbono MONEY,@pmnCuotas INT,@pmIdPeriodo VARCHAR(8),@pmDscto VARCHAR(3),@pmDetalle VARCHAR(50),@pmNLiquida INT
 AS 
 INSERT INTO Trn_NomAbonos (NPrestamo,Item,IdEmpleado,FechaAbo,VrAbono,nCuotas,IdPeriodo,Dscto,Detalle,NLiquida)
 VALUES (@pmNPrestamo,@pmItem,@pmIdEmpleado,@pmFechaAbo,@pmVrAbono,@pmnCuotas,@pmIdPeriodo,@pmDscto,@pmDetalle,@pmNLiquida)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomActividades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomActividades] @pmIdActEco VARCHAR(10),@pmIdSector VARCHAR(8),@pmCodAdicional VARCHAR(10),@pmDescActividad VARCHAR(1000),@pmInactivo BIT
 AS 
 INSERT INTO NomActividades (IdActEco,IdSector,CodAdicional,DescActividad,Inactivo)
 VALUES (@pmIdActEco,@pmIdSector,@pmCodAdicional,@pmDescActividad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAjustes] @pmTipNota VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmIdPeriodo VARCHAR(8),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdRegNom VARCHAR(30),@pmNumLiquida INT,@pmNumSemLiq INT,@pmIdNom VARCHAR(4),@pmTipoLiq CHAR(1),@pmObservacion VARCHAR(2000),@pmNA_Estado INT
,@pmNA_Prefijo VARCHAR(20),@pmNA_Numero INT,@pmNA_FecEnvio SMALLDATETIME,@pmNA_CUNE VARCHAR(500),@pmNE_Prefijo VARCHAR(20),@pmNE_Numero INT,@pmNE_CUNE VARCHAR(500),@pmNE_TipoAju INT,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomAjustes (TipNota,NumNota,IdCia,IdEmpleado,NContrato,IdPeriodo,FechaInicial,FechaFinal,IdRegNom,NumLiquida,NumSemLiq,IdNom,TipoLiq,Observacion,NA_Estado,NA_Prefijo,NA_Numero,NA_FecEnvio,NA_CUNE,NE_Prefijo,NE_Numero,NE_CUNE,FechaCrea,IdCiaCrea,IdUsuario,NE_TipoAju)
 VALUES (@pmTipNota,@pmNumNota,@pmIdCia,@pmIdEmpleado,@pmNContrato,@pmIdPeriodo,@pmFechaInicial,@pmFechaFinal,@pmIdRegNom,@pmNumLiquida,@pmNumSemLiq,@pmIdNom,@pmTipoLiq,@pmObservacion,@pmNA_Estado,@pmNA_Prefijo,@pmNA_Numero,@pmNA_FecEnvio,@pmNA_CUNE,@pmNE_Prefijo,@pmNE_Numero,@pmNE_CUNE,@pmFechaCrea,@pmIdCiaCrea,@pmIdUsuario,@pmNE_TipoAju)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAjustesDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAjustesDet] @pmTipNota VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(250),@pmCantDevg DECIMAL(14,4),@pmCantDed DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrTotDevg MONEY,@pmVrTotDed MONEY,@pmUnidad VARCHAR(10),@pmClaseLiq VARCHAR(10),@pmVrOrigen MONEY,@pmTarifa DECIMAL(14,4),@pmDiasCalc DECIMAL(14,4),@pmDiasNov DECIMAL(14,4)
,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCodFondo VARCHAR(8),@pmNPrestamo INT,@pmNCuota INT,@pmOrigCargue VARCHAR(10),@pmVrBaseLiq MONEY,@pmVrBasExceso MONEY,@pmNitTercero VARCHAR(16),@pmTipoIncLab VARCHAR(20)
 AS 
 INSERT INTO Trn_NomAjustesDet (TipNota,NumNota,IdCia,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen,Tarifa,DiasCalc,DiasNov,FecInicial,FecFinal,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,NitTercero,TipoIncLab)
 VALUES (@pmTipNota,@pmNumNota,@pmIdCia,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantDevg,@pmCantDed,@pmVrUnitario,@pmVrTotDevg,@pmVrTotDed,@pmUnidad,@pmClaseLiq,@pmVrOrigen,@pmTarifa,@pmDiasCalc,@pmDiasNov,@pmFecInicial,@pmFecFinal,@pmCodFondo,@pmNPrestamo,@pmNCuota,@pmOrigCargue,@pmVrBaseLiq,@pmVrBasExceso,@pmNitTercero,@pmTipoIncLab)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAlqDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAlqDet] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmApellido1 VARCHAR(50),@pmApellido2 VARCHAR(50),@pmNombre1 VARCHAR(50),@pmNombre2 VARCHAR(50),@pmIdFonPen VARCHAR(8),@pmIdFonSal VARCHAR(8),@pmIdFonRie VARCHAR(8),@pmIdCajCom VARCHAR(8),@pmSalBasico MONEY
,@pmVrIBCPen MONEY,@pmDiasPen DECIMAL(10,4),@pmTarifPen DECIMAL(10,4),@pmVrPension MONEY,@pmVrApoFsp MONEY,@pmVrApoFsu MONEY,@pmVrApoVolAfi MONEY,@pmVrApoVolApt MONEY,@pmVrNoReten MONEY,@pmVrIBCSal MONEY,@pmDiasSal DECIMAL(10,4),@pmTarifSal DECIMAL(10,4),@pmVrSalud MONEY,@pmVrUpc MONEY,@pmVrIncap MONEY,@pmVrLicencia MONEY,@pmNumAutInc VARCHAR(30)
,@pmNumAutLic VARCHAR(30),@pmVrIBCRie MONEY,@pmDiasRie DECIMAL(10,4),@pmTarifRie DECIMAL(10,4),@pmVrRiesgos MONEY,@pmVrIncIrp MONEY,@pmNumAutIrp VARCHAR(30),@pmIdInstala VARCHAR(4),@pmVrIBCRef MONEY,@pmVrIBCCajas MONEY,@pmDiasCom DECIMAL(10,4),@pmTarifCom DECIMAL(10,4),@pmVrCajas MONEY,@pmTarifSen DECIMAL(10,4),@pmVrSena MONEY,@pmTarifIcb DECIMAL(10,4),@pmVrICBF MONEY
,@pmTarifEsap DECIMAL(10,4),@pmVrESAP MONEY,@pmTarifEdu DECIMAL(10,4),@pmVrMinEdu MONEY,@pmTarifFsp DECIMAL(10,4),@pmTarifFsu DECIMAL(10,4),@pmCdFonAvp VARCHAR(8),@pmVrIBCparaf MONEY,@pmCantHoras INT,@pmTipoSalario VARCHAR(10),@pmIdActEco VARCHAR(10)
 AS 
 INSERT INTO Trn_NomAlqDet (TipoLiq,Numero,Item,IdEmpleado,NContrato,Apellido1,Apellido2,Nombre1,Nombre2,IdFonPen,IdFonSal,IdFonRie,IdCajCom,SalBasico,VrIBCPen,DiasPen,TarifPen,VrPension,VrApoFsp,VrApoFsu,VrApoVolAfi,VrApoVolApt,VrNoReten,VrIBCSal,DiasSal,TarifSal,VrSalud,VrUpc,VrIncap,VrLicencia,NumAutInc,NumAutLic,VrIBCRie,DiasRie,TarifRie,VrRiesgos,VrIncIrp,NumAutIrp,IdInstala,VrIBCRef,VrIBCCajas,DiasCom,TarifCom,VrCajas
,TarifSen,VrSena,TarifIcb,VrICBF,TarifEsap,VrESAP,TarifEdu,VrMinEdu,TarifFsp,TarifFsu,CdFonAvp,VrIBCparaf,CantHoras,TipoSalario,IdActEco)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmIdEmpleado,@pmNContrato,@pmApellido1,@pmApellido2,@pmNombre1,@pmNombre2,@pmIdFonPen,@pmIdFonSal,@pmIdFonRie,@pmIdCajCom,@pmSalBasico,@pmVrIBCPen,@pmDiasPen,@pmTarifPen,@pmVrPension,@pmVrApoFsp,@pmVrApoFsu,@pmVrApoVolAfi,@pmVrApoVolApt,@pmVrNoReten,@pmVrIBCSal,@pmDiasSal,@pmTarifSal,@pmVrSalud,@pmVrUpc,@pmVrIncap,@pmVrLicencia
,@pmNumAutInc,@pmNumAutLic,@pmVrIBCRie,@pmDiasRie,@pmTarifRie,@pmVrRiesgos,@pmVrIncIrp,@pmNumAutIrp,@pmIdInstala,@pmVrIBCRef,@pmVrIBCCajas,@pmDiasCom,@pmTarifCom,@pmVrCajas,@pmTarifSen,@pmVrSena,@pmTarifIcb,@pmVrICBF,@pmTarifEsap,@pmVrESAP,@pmTarifEdu,@pmVrMinEdu,@pmTarifFsp,@pmTarifFsu,@pmCdFonAvp,@pmVrIBCparaf,@pmCantHoras,@pmTipoSalario,@pmIdActEco)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAlqNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAlqNov] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNovIng INT,@pmNovRet INT,@pmNovTde INT,@pmNovTae INT,@pmNovTdp INT,@pmNovTap INT
,@pmNovVsp INT,@pmNovVte INT,@pmNovVst INT,@pmNovSln INT,@pmNovIge INT,@pmNovLma INT,@pmNovVac INT,@pmNovAvp INT,@pmNovVct INT,@pmNovIrp INT,@pmCodNewPen VARCHAR(8),@pmCodNewSal VARCHAR(8),@pmCodNewIns VARCHAR(4)
,@pmCodNewRie VARCHAR(4),@pmCodNewGru VARCHAR(4),@pmDiasNov INT,@pmDiasSan DECIMAL(14,4),@pmDiasDnrPen INT,@pmDiasDnrSal INT,@pmNovDsr INT,@pmFecNovIng SMALLDATETIME,@pmFecNovRet SMALLDATETIME,@pmFecNovVsp SMALLDATETIME
,@pmFecIniSln SMALLDATETIME,@pmFecFinSln SMALLDATETIME,@pmFecIniIge SMALLDATETIME,@pmFecFinIge SMALLDATETIME,@pmFecIniLma SMALLDATETIME,@pmFecFinLma SMALLDATETIME,@pmFecIniVac SMALLDATETIME,@pmFecFinVac SMALLDATETIME
,@pmFecIniVct SMALLDATETIME,@pmFecFinVct SMALLDATETIME,@pmFecIniIrl SMALLDATETIME,@pmFecFinIrl SMALLDATETIME
 AS 
 INSERT INTO Trn_NomAlqNov (TipoLiq,Numero,Item,IdEmpleado,NovIng,NovRet,NovTde,NovTae,NovTdp,NovTap,NovVsp,NovVte,NovVst,NovSln,NovIge,NovLma,NovVac,NovAvp,NovVct,NovIrp,CodNewPen,CodNewSal,CodNewIns,CodNewRie,CodNewGru,DiasNov,DiasSan,DiasDnrPen,DiasDnrSal
,NovDsr,FecNovIng,FecNovRet,FecNovVsp,FecIniSln,FecFinSln,FecIniIge,FecFinIge,FecIniLma,FecFinLma,FecIniVac,FecFinVac,FecIniVct,FecFinVct,FecIniIrl,FecFinIrl)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmIdEmpleado,@pmNovIng,@pmNovRet,@pmNovTde,@pmNovTae,@pmNovTdp,@pmNovTap,@pmNovVsp,@pmNovVte,@pmNovVst,@pmNovSln,@pmNovIge,@pmNovLma,@pmNovVac,@pmNovAvp,@pmNovVct
,@pmNovIrp,@pmCodNewPen,@pmCodNewSal,@pmCodNewIns,@pmCodNewRie,@pmCodNewGru,@pmDiasNov,@pmDiasSan,@pmDiasDnrPen,@pmDiasDnrSal,@pmNovDsr,@pmFecNovIng,@pmFecNovRet,@pmFecNovVsp,@pmFecIniSln,@pmFecFinSln,@pmFecIniIge,@pmFecFinIge,@pmFecIniLma,@pmFecFinLma
,@pmFecIniVac,@pmFecFinVac,@pmFecIniVct,@pmFecFinVct,@pmFecIniIrl,@pmFecFinIrl)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAlqTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAlqTot] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmTipAdm VARCHAR(3),@pmIdFondo VARCHAR(8),@pmCodTipoApo CHAR(2),@pmVrTotalCot MONEY,@pmVrTotalFsp MONEY,@pmVrTotalFsu MONEY
,@pmVrTotalAva MONEY,@pmVrTotalAve MONEY,@pmVrTotalUpc MONEY,@pmVrTotalLic MONEY,@pmVrTotalInc MONEY,@pmVrTotalOtr MONEY,@pmDiasMora INT,@pmTarifMora DECIMAL(10,4),@pmVrIntMora MONEY,@pmVrIMoraOtr MONEY,@pmVrTotalSAF MONEY
,@pmVrSAFUpc MONEY,@pmVrTotalPagar MONEY,@pmVrTotalFon MONEY,@pmTotalAfi INT,@pmNumAutLic VARCHAR(30),@pmNumAutInc VARCHAR(30),@pmNumPlaSAF VARCHAR(20),@pmTipoReg INT
 AS 
 INSERT INTO Trn_NomAlqTot (TipoLiq,Numero,Item,TipAdm,IdFondo,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF,TipoReg)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmTipAdm,@pmIdFondo,@pmCodTipoApo,@pmVrTotalCot,@pmVrTotalFsp,@pmVrTotalFsu,@pmVrTotalAva,@pmVrTotalAve,@pmVrTotalUpc,@pmVrTotalLic,@pmVrTotalInc,@pmVrTotalOtr,@pmDiasMora,@pmTarifMora,@pmVrIntMora,@pmVrIMoraOtr,@pmVrTotalSAF
,@pmVrSAFUpc,@pmVrTotalPagar,@pmVrTotalFon,@pmTotalAfi,@pmNumAutLic,@pmNumAutInc,@pmNumPlaSAF,@pmTipoReg)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAportante]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomAportante] @pmIdAportnte VARCHAR(16),@pmRazonSocial VARCHAR(200),@pmTipoId CHAR(1),@pmDvNit CHAR(1),@pmIdRepLegal VARCHAR(16),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pme_mail VARCHAR(100)
,@pmClaseApo CHAR(1),@pmTipoEco CHAR(1),@pmTipoPersna CHAR(1),@pmCIIUDane VARCHAR(8),@pmFecIniCndato SMALLDATETIME,@pmTipAccCndato INT,@pmFecFinCndato SMALLDATETIME,@pmCodOperInfo VARCHAR(10),@pmTipoApo CHAR(1),@pmFecMatMerc SMALLDATETIME
,@pmExonParaf INT,@pmExonCajas INT,@pmCondEspecial VARCHAR(250),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO NomAportante (IdAportnte,RazonSocial,TipoId,DvNit,IdRepLegal,Direccion,IdLocal,Telefono,Fax,e_mail,ClaseApo,TipoEco,TipoPersna,CIIUDane,FecIniCndato,TipAccCndato,FecFinCndato,CodOperInfo,TipoApo,FecAdd,IdUsuario,FecMatMerc,ExonParaf,ExonCajas,CondEspecial)
 VALUES (@pmIdAportnte,@pmRazonSocial,@pmTipoId,@pmDvNit,@pmIdRepLegal,@pmDireccion,@pmIdLocal,@pmTelefono,@pmFax,@pme_mail,@pmClaseApo,@pmTipoEco,@pmTipoPersna,@pmCIIUDane,@pmFecIniCndato,@pmTipAccCndato
,@pmFecFinCndato,@pmCodOperInfo,@pmTipoApo,@pmFecAdd,@pmIdUsuario,@pmFecMatMerc,@pmExonParaf,@pmExonCajas,@pmCondEspecial)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAstncia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomAstncia] @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME,@pmHHDiurno DECIMAL(10,4),@pmHHNocturno DECIMAL(10,4),@pmHEDiurno DECIMAL(10,4),@pmHENocturno DECIMAL(10,4),@pmTipoJrnada VARCHAR(10)
,@pmEsDmncal BIT,@pmHorario VARCHAR(30),@pmCodTurno VARCHAR(4),@pmHoras_Dia DECIMAL(10,4),@pmTimeSys SMALLDATETIME, @pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomAstncia (IdEmpleado,FechaDia,HHDiurno,HHNocturno,HEDiurno,HENocturno,TipoJrnada,EsDmncal,Horario,TimeSys,IdUsuario,CodTurno,Horas_Dia)
 VALUES (@pmIdEmpleado,@pmFechaDia,@pmHHDiurno,@pmHHNocturno,@pmHEDiurno,@pmHENocturno,@pmTipoJrnada,@pmEsDmncal,@pmHorario,@pmTimeSys,@pmIdUsuario,@pmCodTurno,@pmHoras_Dia)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomAutoliq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomAutoliq] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmFecha SMALLDATETIME,@pmPerAutoliq VARCHAR(6),@pmPerAutoSal VARCHAR(6),@pmFechaPago SMALLDATETIME,@pmIdAportnte VARCHAR(16),@pmPresentacion CHAR(1),@pmCodCia CHAR(2),@pmCodFondo VARCHAR(8),@pmCodArp VARCHAR(8),@pmCodOper VARCHAR(10),@pmEsCorr BIT,@pmPerCorr VARCHAR(6)
,@pmNumCorr VARCHAR(20),@pmTotalEmp INT,@pmVrNomina MONEY,@pmVrPension MONEY,@pmVrSalud MONEY,@pmVrRiesgos MONEY,@pmVrCajas MONEY,@pmVrSena MONEY,@pmVrIcbf MONEY,@pmVrEsap MONEY,@pmVrMinEduc MONEY,@pmTotalAfipen INT,@pmTotalAfiSal INT,@pmTotalAfiRie INT,@pmTotalAfiCaj INT,@pmTotalAfiSen INT,@pmTotalAfiIcb INT,@pmTotalAfiEsa INT,@pmTotalAfiEduc INT,@pmTotAdmPen INT
,@pmTotAdmSal INT,@pmTotAdmRie INT,@pmTotAdmCom INT,@pmObservacion VARCHAR(250),@pmLogAdmon VARCHAR(250),@pmRedoMiles BIT,@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmTipoPlanilla VARCHAR(3)
 AS 
 INSERT INTO Trn_NomAutoliq (TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,IdAportnte,Presentacion,CodCia,CodFondo,CodArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,VrPension,VrSalud,VrRiesgos,VrCajas,VrSena,VrIcbf,VrEsap,VrMinEduc,TotalAfipen,TotalAfiSal,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,Observacion,LogAdmon,RedoMiles,Anulado,IdEstado,TimeSys,IdUsuario,TipoPlanilla)
 VALUES (@pmTipoLiq,@pmNumero,@pmFecha,@pmPerAutoliq,@pmPerAutoSal,@pmFechaPago,@pmIdAportnte,@pmPresentacion,@pmCodCia,@pmCodFondo,@pmCodArp,@pmCodOper,@pmEsCorr,@pmPerCorr,@pmNumCorr,@pmTotalEmp,@pmVrNomina,@pmVrPension,@pmVrSalud,@pmVrRiesgos,@pmVrCajas,@pmVrSena,@pmVrIcbf,@pmVrEsap,@pmVrMinEduc,@pmTotalAfipen,@pmTotalAfiSal,@pmTotalAfiRie,@pmTotalAfiCaj,@pmTotalAfiSen,@pmTotalAfiIcb
,@pmTotalAfiEsa,@pmTotalAfiEduc,@pmTotAdmPen,@pmTotAdmSal,@pmTotAdmRie,@pmTotAdmCom,@pmObservacion,@pmLogAdmon,@pmRedoMiles,@pmAnulado,@pmIdEstado,@pmTimeSys,@pmIdUsuario,@pmTipoPlanilla)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomBasesConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomBasesConv] @pmIdBase VARCHAR(4),@pmNombreBase VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO NomBasesConv (IdBase,NombreBase,Inactivo)
 VALUES (@pmIdBase,@pmNombreBase,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCAdmon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomCAdmon] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmClaseAdmon VARCHAR(10)
,@pmFecIniNov SMALLDATETIME,@pmNNovedad INT,@pmIdFondo VARCHAR(8),@pmIdFonNew VARCHAR(8),@pmObservacion VARCHAR(100),@pmAnulado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomCAdmon (IdEmpleado,Numero,Fecha,NContrato,ClaseAdmon,FecIniNov,NNovedad,IdFondo,IdFonNew,Observacion,Anulado,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmClaseAdmon,@pmFecIniNov,@pmNNovedad,@pmIdFondo,@pmIdFonNew,@pmObservacion,@pmAnulado,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCapacitaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomCapacitaciones] @pmIdClase VARCHAR(4),@pmItem INT,@pmVigencia INT,@pmCdEmpleado VARCHAR(16),@pmCdProf VARCHAR(4)
,@pmCdCargo VARCHAR(4),@pmCdArea VARCHAR(4),@pmCdDep VARCHAR(4),@pmCumplimto VARCHAR(20),@pmInactivo BIT
 AS 
 INSERT INTO NomCapacitaciones (IdClase,Item,Vigencia,CdEmpleado,CdProf,CdCargo,CdArea,CdDep,Cumplimto,Inactivo)
 VALUES (@pmIdClase,@pmItem,@pmVigencia,@pmCdEmpleado,@pmCdProf,@pmCdCargo,@pmCdArea,@pmCdDep,@pmCumplimto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCausalesRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomCausalesRet] @pmIdCausa VARCHAR(4),@pmCausalRet VARCHAR(100),@pmIndmnizar BIT,@pmInactivo BIT
 AS 
 INSERT INTO NomCausalesRet (IdCausa,CausalRet,Indmnizar,Inactivo)
 VALUES (@pmIdCausa,@pmCausalRet,@pmIndmnizar,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomCertf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomCertf] @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20),@pmnAnno INT,@pmnMes INT,@pmVrCertf MONEY
,@pmObservacion VARCHAR(100),@pmClaseCert VARCHAR(10),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomCertf (IdEmpleado,NumCertf,nAnno,nMes,VrCertf,Observacion,FecAdd,IdUsuario,ClaseCert)
 VALUES (@pmIdEmpleado,@pmNumCertf,@pmnAnno,@pmnMes,@pmVrCertf,@pmObservacion,@pmFecAdd,@pmIdUsuario,@pmClaseCert)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConAuto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomConAuto] @pmIdReg INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmVrAplicar MONEY,@pmModalidad CHAR(1)
,@pmOrigenBase CHAR(2),@pmFrecAplica VARCHAR(10),@pmCedEmpleado VARCHAR(16),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodCcto VARCHAR(16)
,@pmCritSelect VARCHAR(4000),@pmFecFinal SMALLDATETIME,@pmExceptuar VARCHAR(8),@pmObservacion VARCHAR(50),@pmCodSubCos VARCHAR(16),@pmInactivo BIT
,@pmNumPerMes INT,@pmNitTercero VARCHAR(16),@pmAplicaPrima INT,@pmAplicaVac INT,@pmPdoAplicaEsp VARCHAR(8),@pmVrAplicaEsp MONEY,@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomConAuto (IdReg,IdConcepto,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,CodNom,CodDep,CodCcto,CritSelect,FecFinal,Exceptuar,Observacion,CodSubCos
,Inactivo,NumPerMes,FecAdd,IdUsuario,NitTercero,AplicaPrima,AplicaVac,PdoAplicaEsp,VrAplicaEsp)
 VALUES (@pmIdReg,@pmIdConcepto,@pmFecInicio,@pmVrAplicar,@pmModalidad,@pmOrigenBase,@pmFrecAplica,@pmCedEmpleado,@pmCodNom,@pmCodDep,@pmCodCcto,@pmCritSelect,@pmFecFinal,@pmExceptuar
,@pmObservacion,@pmCodSubCos,@pmInactivo,@pmNumPerMes,@pmFecAdd,@pmIdUsuario,@pmNitTercero,@pmAplicaPrima,@pmAplicaVac,@pmPdoAplicaEsp,@pmVrAplicaEsp)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConcConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomConcConv] @pmIdPeriodo INT,@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdConv INT,@pmIdGrupo VARCHAR(4),@pmCodEscfon VARCHAR(4),@pmCodZona VARCHAR(4),@pmTipoNom VARCHAR(10),@pmIdConcepto VARCHAR(4),@pmDescripcion VARCHAR(500),@pmUnidad VARCHAR(10),@pmImporte MONEY,@pmObservaciones VARCHAR(1000),@pmInactivo BIT,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME
 AS 
 INSERT INTO Trn_NomConcConv (IdPeriodo,FecInicio,FecFinal,IdConv,IdGrupo,CodEscfon,CodZona,TipoNom,IdConcepto,Descripcion,Unidad,Importe,Observaciones,IdUsuario,FechaCrea,Inactivo)
 VALUES (@pmIdPeriodo,@pmFecInicio,@pmFecFinal,@pmIdConv,@pmIdGrupo,@pmCodEscfon,@pmCodZona,@pmTipoNom,@pmIdConcepto,@pmDescripcion,@pmUnidad,@pmImporte,@pmObservaciones,@pmIdUsuario,@pmFechaCrea,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomConceptos] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(100),@pmClaseCon VARCHAR(10),@pmUnidad VARCHAR(10),@pmTarifa DECIMAL(10,4)
,@pmBaseTrfa CHAR(2),@pmPdtermnado BIT,@pmInactivo BIT,@pmTarifaEmp DECIMAL(14,4),@pmDiasEmp INT,@pmIdConcNE VARCHAR(50),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO NomConceptos (IdConcepto,Concepto,ClaseCon,Unidad,Tarifa,BaseTrfa,Pdtermnado,Inactivo,FechaAdd,IdUsuario,TarifaEmp,DiasEmp,IdConcNE)
 VALUES (@pmIdConcepto,@pmConcepto,@pmClaseCon,@pmUnidad,@pmTarifa,@pmBaseTrfa,@pmPdtermnado,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmTarifaEmp,@pmDiasEmp,@pmIdConcNE)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomConCuentas] @pmIdConcepto VARCHAR(4),@pmItem INT,@pmNClase INT,@pmIdCuenta VARCHAR(16)
,@pmTipoMov CHAR(1),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodFon VARCHAR(8),@pmNitTerc CHAR(1),@pmTipo_Nom VARCHAR(10)
 AS 
 INSERT INTO NomConCuentas (IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc,Tipo_Nom)
 VALUES (@pmIdConcepto,@pmItem,@pmNClase,@pmIdCuenta,@pmTipoMov,@pmCodNom,@pmCodDep,@pmCodFon,@pmNitTerc,@pmTipo_Nom)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomConOpciones] @pmIdConcepto VARCHAR(4),@pmIdOpc INT,@pmNomOpcion VARCHAR(50),@pmAsignado BIT
 AS 
 INSERT INTO NomConOpciones (IdConcepto,IdOpc,NomOpcion,Asignado)
 VALUES (@pmIdConcepto,@pmIdOpc,@pmNomOpcion,@pmAsignado)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomConvenciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomConvenciones] @pmFecha SMALLDATETIME,@pmProyecto VARCHAR(150),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdLocal VARCHAR(8),@pmNitTercero VARCHAR(16),@pmObservacion VARCHAR(500),@pmFecProrroga SMALLDATETIME
,@pmFechaCrea SMALLDATETIME,@pmInactivo BIT
 AS 
 INSERT INTO NomConvenciones (Fecha,Proyecto,FecInicio,FecFinal,IdLocal,NitTercero,Observacion,FechaCrea,Inactivo,FecProrroga)
 VALUES (@pmFecha,@pmProyecto,@pmFecInicio,@pmFecFinal,@pmIdLocal,@pmNitTercero,@pmObservacion,@pmFechaCrea,@pmInactivo,@pmFecProrroga)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDefault]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomDefault] @pmnAnno INT,@pmIdOpc VARCHAR(3),@pmDescripcion VARCHAR(100),@pmValor MONEY
 AS 
 INSERT INTO NomDefault (nAnno,IdOpc,Descripcion,Valor)
 VALUES (@pmnAnno,@pmIdOpc,@pmDescripcion,@pmValor)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomDetalle] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantDevg DECIMAL(10,4),@pmCantDed DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrTotDevg MONEY,@pmVrTotDed MONEY
,@pmUnidad VARCHAR(10),@pmClaseLiq VARCHAR(10),@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmDiasCalc DECIMAL(10,4),@pmDiasNov DECIMAL(10,4),@pmCodFondo VARCHAR(8),@pmNPrestamo INT,@pmNCuota INT,@pmOrigCargue VARCHAR(10),@pmVrBaseLiq MONEY,@pmVrBasExceso MONEY,@pmNitTercero VARCHAR(16)
,@pmHoraInicial DATETIME,@pmHoraFinal DATETIME,@pmTipoIncLab VARCHAR(20),@pmVrIngNoSal MONEY
 AS 
 INSERT INTO Trn_NomDetalle (IdPeriodo,KeyRegistro,IdEmpleado,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,NitTercero,HoraInicial,HoraFinal,TipoIncLab,VrIngNoSal)
 VALUES (@pmIdPeriodo,@pmKeyRegistro,@pmIdEmpleado,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantDevg,@pmCantDed,@pmVrUnitario,@pmVrTotDevg,@pmVrTotDed,@pmUnidad,@pmClaseLiq,@pmVrOrigen,@pmTarifa
,@pmDiasCalc,@pmDiasNov,@pmCodFondo,@pmNPrestamo,@pmNCuota,@pmOrigCargue,@pmVrBaseLiq,@pmVrBasExceso,@pmNitTercero,@pmHoraInicial,@pmHoraFinal,@pmTipoIncLab,@pmVrIngNoSal)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDetalle_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomDetalle_Sel] @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomDetalle (IdPeriodo,KeyRegistro,IdEmpleado,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen
,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,NitTercero,HoraInicial,HoraFinal,TipoIncLab,VrIngNoSal)
 SELECT D.IdPeriodo,@pmNewCedula +CAST(NContrato AS VARCHAR(10)) +CASE EsRetiro WHEN 1 THEN '_1' ELSE '_0'  END
,@pmNewCedula,Item,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen
,Tarifa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,NitTercero,HoraInicial,HoraFinal,TipoIncLab,VrIngNoSal
 FROM Trn_NomDetalle AS D INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDotacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomDotacion] @pmIdCia CHAR(2),@pmNumero INT,@pmFecha SMALLDATETIME,@pmTipoDotac VARCHAR(10),@pmTipoEntrega INT,@pmPlazoEntrega INT
,@pmFecVence SMALLDATETIME,@pmTipoReg INT,@pmAnulado BIT,@pmObservacion VARCHAR(1000),@pmCritFiltros VARCHAR(250),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomDotacion (IdCia,Numero,Fecha,TipoDotac,TipoEntrega,PlazoEntrega,FecVence,TipoReg,Anulado,FechaCrea,IdUsuario,Observacion,CritFiltros)
 VALUES (@pmIdCia,@pmNumero,@pmFecha,@pmTipoDotac,@pmTipoEntrega,@pmPlazoEntrega,@pmFecVence,@pmTipoReg,@pmAnulado,@pmFechaCrea,@pmIdUsuario,@pmObservacion,@pmCritFiltros)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomDotacionDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomDotacionDet] @pmIdCia CHAR(2),@pmNumero INT,@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmIdPrend VARCHAR(4)
,@pmDescripcion VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmUnidad VARCHAR(10),@pmVrUnitario MONEY
 AS 
 INSERT INTO Trn_NomDotacionDet (IdCia,Numero,Item,IdEmpleado,NContrato,IdPrend,Descripcion,Cantidad,Unidad,VrUnitario)
 VALUES (@pmIdCia,@pmNumero,@pmItem,@pmIdEmpleado,@pmNContrato,@pmIdPrend,@pmDescripcion,@pmCantidad,@pmUnidad,@pmVrUnitario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomEscalafones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomEscalafones] @pmIdEscfon VARCHAR(4),@pmEscalafon VARCHAR(150),@pmIdConv INT,@pmIdGrupo VARCHAR(4),@pmIdCargo VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO NomEscalafones (IdEscfon,Escalafon,IdConv,IdGrupo,IdCargo,Inactivo)
 VALUES (@pmIdEscfon,@pmEscalafon,@pmIdConv,@pmIdGrupo,@pmIdCargo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomEstadosConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomEstadosConv] @pmIdEstado VARCHAR(4),@pmEstadoConv VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 INSERT INTO NomEstadosConv (IdEstado,EstadoConv,NColor,Inactivo)
 VALUES (@pmIdEstado,@pmEstadoConv,@pmNColor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomFijos] @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT,@pmTarifa DECIMAL(10,4),@pmVrBase MONEY,@pmVrSalarios MONEY,@pmVrPrima MONEY,@pmVrVacacnes MONEY,@pmVrSIntExcto MONEY
,@pmVrOtrosIng MONEY,@pmVrIngresos MONEY,@pmVrPensiones MONEY,@pmVrDedcido MONEY,@pmVrExcento MONEY,@pmVrCertEdu MONEY,@pmVrCertVda MONEY,@pmVrCertAFC MONEY,@pmVrCertfcado MONEY,@pmPeriodos DECIMAL(10,4),@pmVrTotalBase MONEY
,@pmOrignPorc VARCHAR(10),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmVrSalud MONEY,@pmIngNoSalario MONEY,@pmPagosMedicPre MONEY,@pmAportesVolPen MONEY,@pmGastosRep MONEY,@pmIndemnizac MONEY
 AS 
 INSERT INTO Trn_NomFijos (IdEmpleado,nAnno,nMes,Tarifa,VrBase,VrSalarios,VrPrima,VrVacacnes,VrSIntExcto,VrOtrosIng,VrIngresos,VrPensiones,VrDedcido,VrExcento,VrCertEdu,VrCertVda,VrCertAFC,VrCertfcado,Periodos,VrTotalBase,OrignPorc,FecAdd,IdUsuario
,VrSalud,IngNoSalario,PagosMedicPre,AportesVolPen,GastosRep,Indemnizac)
 VALUES (@pmIdEmpleado,@pmnAnno,@pmnMes,@pmTarifa,@pmVrBase,@pmVrSalarios,@pmVrPrima,@pmVrVacacnes,@pmVrSIntExcto,@pmVrOtrosIng,@pmVrIngresos,@pmVrPensiones,@pmVrDedcido,@pmVrExcento,@pmVrCertEdu,@pmVrCertVda,@pmVrCertAFC
,@pmVrCertfcado,@pmPeriodos,@pmVrTotalBase,@pmOrignPorc,@pmFecAdd,@pmIdUsuario,@pmVrSalud,@pmIngNoSalario,@pmPagosMedicPre,@pmAportesVolPen,@pmGastosRep,@pmIndemnizac)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomGruposConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomGruposConv] @pmIdGrupo VARCHAR(4),@pmGrupoConv VARCHAR(150),@pmIdConv INT,@pmInactivo BIT
 AS 
 INSERT INTO NomGruposConv (IdGrupo,GrupoConv,IdConv,Inactivo)
 VALUES (@pmIdGrupo,@pmGrupoConv,@pmIdConv,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomina] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmNContrato INT,@pmIdDep VARCHAR(4)
,@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrATransMes MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmEsRetiro BIT,@pmNLiqRet INT
,@pmTipoLiq CHAR(1),@pmCantNoRem DECIMAL(10,4),@pmCdTipoCot VARCHAR(4),@pmSubTipo_Cot VARCHAR(3),@pmSal_Integral BIT,@pmTipoIdent CHAR(1),@pmNotasAportante VARCHAR(250),@pmCantModifica INT,@pmNE_Estado INT,@pmNE_Prefijo VARCHAR(20),@pmNE_Numero INT,@pmNE_FecEnvio DATETIME
,@pmNE_CUNE VARCHAR(500),@pmNE_ComAju BIT,@pmNE_CntAju INT,@pmNE_Ajustes VARCHAR(500),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmFecUpdate SMALLDATETIME
 AS 
 INSERT INTO Trn_Nomina (IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,Cantidad,VrDevengado,VrDeducido,NContrato,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,CantNoRem,TimeSys,FecUpdate,IdUsuario
,CdTipoCot,SubTipo_Cot,Sal_Integral,TipoIdent,NotasAportante,CantModifica,NE_Estado,NE_Prefijo,NE_Numero,NE_FecEnvio,NE_CUNE,NE_QR,NE_ComAju,NE_CntAju,NE_Ajustes)
 VALUES (@pmIdPeriodo,@pmKeyRegistro,@pmIdEmpleado,@pmFecInicial,@pmFecFinal,@pmCantidad,@pmVrDevengado,@pmVrDeducido,@pmNContrato,@pmIdDep,@pmIdInstala,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmVrSalario,@pmVrATransMes,@pmpVehiculo,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado
,@pmEsRetiro,@pmNLiqRet,@pmTipoLiq,@pmCantNoRem,@pmTimeSys,@pmFecUpdate,@pmIdUsuario,@pmCdTipoCot,@pmSubTipo_Cot,@pmSal_Integral,@pmTipoIdent,@pmNotasAportante,@pmCantModifica,@pmNE_Estado,@pmNE_Prefijo,@pmNE_Numero,@pmNE_FecEnvio,@pmNE_CUNE,Null,@pmNE_ComAju,@pmNE_CntAju,@pmNE_Ajustes)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomina_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomina_Sel]  @pmIdEmpleado  VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_Nomina (IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,Cantidad,VrDevengado,VrDeducido,NContrato,IdDep
,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,CantNoRem,TimeSys,IdUsuario
,CdTipoCot,SubTipo_Cot,Sal_Integral,TipoIdent,NotasAportante,CantModifica,NE_Estado,NE_Prefijo,NE_Numero,NE_FecEnvio,NE_CUNE,NE_QR,NE_ComAju,NE_CntAju,NE_Ajustes)
 SELECT  IdPeriodo,@pmNewCedula +CAST(NContrato AS VARCHAR(10)) +CASE EsRetiro WHEN 1 THEN '_1' ELSE '_0'  END,@pmNewCedula,FecInicial,FecFinal,Cantidad,VrDevengado
,VrDeducido,NContrato,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,CantNoRem
,TimeSys,IdUsuario,CdTipoCot,SubTipo_Cot,Sal_Integral,TipoIdent,NotasAportante,CantModifica,NE_Estado,NE_Prefijo,NE_Numero,NE_FecEnvio,NE_CUNE,NE_QR,NE_ComAju,NE_CntAju,NE_Ajustes
 FROM Trn_Nomina 
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsNomLiqDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomLiqDet] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmFecUltLiq SMALLDATETIME,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmVrBase MONEY,@pmCantidad INT
,@pmVrLiquida MONEY,@pmVrDeducido MONEY,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME,@pmDiasBase INT,@pmDiasNoRem INT,@pmTarifa DECIMAL(10,4),@pmNPrestamo INT,@pmNCuota INT,@pmLogPmdio VARCHAR(1500),@pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmpVehiculo VARCHAR(10),@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrParcial MONEY,@pmNitTercero VARCHAR(16)
 AS 
 INSERT INTO Trn_NomLiqDet (TipoLiq,Numero,Item,IdConcepto,Detalle,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,Tarifa,NPrestamo,NCuota,LogPmdio,IdEmpleado,NContrato,pVehiculo,IdDep,IdCCosto,IdSubCos,IdNom,VrSalario,VrParcial,NitTercero)
 VALUES (@pmTipoLiq,@pmNumero,@pmItem,@pmIdConcepto,@pmDetalle,@pmFecUltLiq,@pmFecInicial,@pmFecFinal,@pmVrBase,@pmCantidad,@pmVrLiquida,@pmVrDeducido,@pmFecIniPmd,@pmFecFinPmd,@pmDiasBase,@pmDiasNoRem,@pmTarifa,@pmNPrestamo,@pmNCuota,@pmLogPmdio
,@pmIdEmpleado,@pmNContrato,@pmpVehiculo,@pmIdDep,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmVrSalario,@pmVrParcial,@pmNitTercero)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomLiquida] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME,@pmSemstre INT,@pmVrTotal MONEY,@pmVrTotDed MONEY,@pmVrAplicado MONEY,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomLiquida (TipoLiq,Numero,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,TimeSys,IdUsuario)
 VALUES (@pmTipoLiq,@pmNumero,@pmFecha,@pmSemstre,@pmVrTotal,@pmVrTotDed,@pmVrAplicado,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmIdEstado,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomLogVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomLogVeh] @pmIdEmpleado VARCHAR(16),@pmNumReg INT,@pmFecha SMALLDATETIME,@pmpVehAnterior VARCHAR(10),@pmNitPropAnt VARCHAR(16)
,@pmpVehNew VARCHAR(10),@pmNitPropNew VARCHAR(16),@pmObservacion VARCHAR(100),@pmNitCondAnt VARCHAR(16),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomLogVeh (IdEmpleado,NumReg,Fecha,pVehAnterior,NitPropAnt,pVehNew,NitPropNew,Observacion,NitCondAnt,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumReg,@pmFecha,@pmpVehAnterior,@pmNitPropAnt,@pmpVehNew,@pmNitPropNew,@pmObservacion,@pmNitCondAnt,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomNov] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad DECIMAL(10,4),@pmVrUnitario MONEY
,@pmVrTotal MONEY,@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmOrigCargue VARCHAR(10),@pmNumDocRef VARCHAR(20),@pmNum_Contrato INT,@pmNit_Tercero VARCHAR(16),@pmHoraInicial DATETIME,@pmHoraFinal DATETIME,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomNov (IdPeriodo,IdEmpleado,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrTotal,VrOrigen,Tarifa,OrigCargue,TimeSys,IdUsuario,NumDocRef,Num_Contrato,Nit_Tercero,HoraInicial,HoraFinal)
 VALUES (@pmIdPeriodo,@pmIdEmpleado,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantidad,@pmVrUnitario,@pmVrTotal,@pmVrOrigen,@pmTarifa,@pmOrigCargue, @pmTimeSys,@pmIdUsuario,@pmNumDocRef,@pmNum_Contrato,@pmNit_Tercero,@pmHoraInicial,@pmHoraFinal)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNovConc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomNovConc] @pmIdNovedad BIGINT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDescripcion VARCHAR(500),@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrTotal MONEY,@pmVrBaseLiq MONEY,@pmTarifa DECIMAL(14,4),@pmUnidad VARCHAR(10),@pmClaseCon VARCHAR(10),@pmNitTercero VARCHAR(16),@pmReferencia VARCHAR(50),@pmHoraInicial DATETIME,@pmHoraFinal DATETIME
,@pmTipoReg INT,@pmNumRegVf INT,@pmCantDias INT,@pmCantNov INT
 AS 
 INSERT INTO Trn_NomNovConc (IdNovedad,Item,IdConcepto,Descripcion,Cantidad,VrUnitario,VrTotal,VrBaseLiq,Tarifa,Unidad,ClaseCon,NitTercero,Referencia,HoraInicial,HoraFinal,TipoReg,NumRegVf,CantDias,CantNov)
 VALUES (@pmIdNovedad,@pmItem,@pmIdConcepto,@pmDescripcion,@pmCantidad,@pmVrUnitario,@pmVrTotal,@pmVrBaseLiq,@pmTarifa,@pmUnidad,@pmClaseCon,@pmNitTercero,@pmReferencia,@pmHoraInicial,@pmHoraFinal,@pmTipoReg,@pmNumRegVf,@pmCantDias,@pmCantNov)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNovConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomNovConv] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdConv INT,@pmIdGrupo VARCHAR(4),@pmCodEscfon VARCHAR(4),@pmCodBase VARCHAR(4),@pmCodZona VARCHAR(4),@pmTipoNom VARCHAR(10),@pmCantidad DECIMAL(14,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmVrSalario MONEY,@pmOrigenReg INT,@pmAnulado BIT
,@pmVrAuxTransp MONEY,@pmVrSalBasDia MONEY,@pmVrAuxTraDia MONEY,@pmVrPriConDia MONEY,@pmIdNom VARCHAR(4),@pmNumRegLog INT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomNovConv (IdPeriodo,IdEmpleado,NContrato,FecInicial,FecFinal,IdConv,IdGrupo,CodEscfon,CodBase,CodZona,TipoNom,Cantidad,VrDevengado,VrDeducido,VrSalario,OrigenReg,Anulado,FechaCrea,IdUsuario,VrAuxTransp,VrSalBasDia,VrAuxTraDia,VrPriConDia,IdNom,NumRegLog)
 VALUES (@pmIdPeriodo,@pmIdEmpleado,@pmNContrato,@pmFecInicial,@pmFecFinal,@pmIdConv,@pmIdGrupo,@pmCodEscfon,@pmCodBase,@pmCodZona,@pmTipoNom,@pmCantidad,@pmVrDevengado,@pmVrDeducido,@pmVrSalario,@pmOrigenReg,@pmAnulado,@pmFechaCrea,@pmIdUsuario,@pmVrAuxTransp,@pmVrSalBasDia,@pmVrAuxTraDia,@pmVrPriConDia,@pmIdNom,@pmNumRegLog)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomNovedad]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomNovedad] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantDias INT,@pmDiaInicio INT
,@pmModalidad VARCHAR(10),@pmIdNov VARCHAR(4),@pmRemnrado BIT,@pmObservacion VARCHAR(250),@pmCodInstla VARCHAR(4),@pmInactivo BIT,@pmCodClsRie VARCHAR(4),@pmNumAutza VARCHAR(30),@pmCodNewFon VARCHAR(8)
,@pmCodOldFon VARCHAR(8),@pmVrCotVolAfi MONEY,@pmVrCotVolApo MONEY,@pmVrNoRetenido MONEY,@pmTipoIncap CHAR(1),@pmFechaDcto SMALLDATETIME,@pmVrDescuento MONEY
,@pmTipoBaseLiq VARCHAR(3),@pmIncAlargado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomNovedad (IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,Remnrado,Observacion,CodInstla,Inactivo,CodClsRie,NumAutza,CodOldFon,CodNewFon,VrCotVolAfi,VrCotVolApo
,VrNoRetenido,TipoIncap,FechaDcto,VrDescuento,TimeSys,IdUsuario,TipoBaseLiq,IncAlargado)
 VALUES (@pmIdEmpleado,@pmNumero,@pmIdConcepto,@pmFecInicio,@pmFecFinal,@pmCantDias,@pmDiaInicio,@pmModalidad,@pmIdNov,@pmRemnrado,@pmObservacion,@pmCodInstla,@pmInactivo,@pmCodClsRie,@pmNumAutza,@pmCodOldFon,@pmCodNewFon
 ,@pmVrCotVolAfi,@pmVrCotVolApo,@pmVrNoRetenido,@pmTipoIncap,@pmFechaDcto,@pmVrDescuento,@pmTimeSys,@pmIdUsuario,@pmTipoBaseLiq,@pmIncAlargado)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomPrendas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomPrendas] @pmIdPrend VARCHAR(4),@pmDescPrenda VARCHAR(100),@pmTipoPrenda VARCHAR(10),@pmVrCostoUnd MONEY,@pmInactivo BIT
 AS 
 INSERT INTO NomPrendas (IdPrend,DescPrenda,TipoPrenda,Inactivo,VrCostoUnd)
 VALUES (@pmIdPrend,@pmDescPrenda,@pmTipoPrenda,@pmInactivo,@pmVrCostoUnd)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomPrest]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomPrest] @pmNPrestamo INT,@pmFecha SMALLDATETIME,@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmVrPrestamo MONEY
,@pmNumCuotas INT,@pmVrCuota MONEY,@pmFecInicio SMALLDATETIME,@pmFrecDcto VARCHAR(10),@pmExceptuar VARCHAR(8),@pmTotPrestamo MONEY,@pmTotAbonado MONEY
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmCxpagar BIT
,@pmDsctNom INT,@pmDsctPri INT,@pmDsctVac INT,@pmDsctEspPer VARCHAR(8),@pmDsctEspVal MONEY,@pmVrTmAbono MONEY,@pmNumPerMes INT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomPrest (NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom
,Observacion,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal,VrTmAbono,TimeSys,IdUsuario,NumPerMes)
 VALUES (@pmNPrestamo,@pmFecha,@pmIdEmpleado,@pmIdConcepto,@pmVrPrestamo,@pmNumCuotas,@pmVrCuota,@pmFecInicio,@pmFrecDcto,@pmExceptuar,@pmTotPrestamo,@pmTotAbonado,@pmAnulado,@pmFecDev,@pmTipCom
,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmCxpagar,@pmDsctNom,@pmDsctPri,@pmDsctVac,@pmDsctEspPer,@pmDsctEspVal,@pmVrTmAbono,@pmTimeSys,@pmIdUsuario,@pmNumPerMes)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomProrrogas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomProrrogas] @pmIdEmpleado VARCHAR(16),@pmNumReg INT,@pmNContrato INT,@pmFecha SMALLDATETIME,@pmFecAnterior SMALLDATETIME,@pmIndefinido BIT,@pmCdTipCon VARCHAR(4)
,@pmCdCargo VARCHAR(4),@pmCdDep VARCHAR(4),@pmCdArea VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmIdCargo VARCHAR(4),@pmIdArea VARCHAR(4)
,@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmObservacion VARCHAR(150),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomProrrogas (IdEmpleado,NumReg,NContrato,Fecha,FecAnterior,Indefinido,CdTipCon,CdCargo,CdDep,CdArea,CdCCosto,CdSubCos,IdTipCon,IdCargo,IdArea,IdDep,IdCCosto,IdSubCos,Observacion,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumReg,@pmNContrato,@pmFecha,@pmFecAnterior,@pmIndefinido,@pmCdTipCon,@pmCdCargo,@pmCdDep,@pmCdArea,@pmCdCCosto,@pmCdSubCos,@pmIdTipCon,@pmIdCargo,@pmIdArea
,@pmIdDep,@pmIdCCosto,@pmIdSubCos,@pmObservacion,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRangosFsu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomRangosFsu] @pmIdRango INT,@pmVrInicial DECIMAL(12,2),@pmVrFinal DECIMAL(12,2),@pmTarifa DECIMAL(10,4)
 AS 
 INSERT INTO NomRangosFsu (IdRango,VrInicial,VrFinal,Tarifa)
 VALUES (@pmIdRango,@pmVrInicial,@pmVrFinal,@pmTarifa)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomRet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmIdCausa VARCHAR(4),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmDiasTrab INT
,@pmDiasNoRem INT,@pmVrTotDev MONEY,@pmVrTotDed MONEY,@pmVrTotCes MONEY,@pmVrTotPri MONEY,@pmVrTotVac MONEY,@pmVrTotInt MONEY,@pmVrTotInd MONEY,@pmVrNeto MONEY,@pmVrBaseCes MONEY,@pmVrBaseVac MONEY,@pmIdPeriodo VARCHAR(8)
,@pmKeyReg VARCHAR(30),@pmNPerVac INT,@pmVrSalario MONEY,@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmTipoLiq CHAR(1),@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmVrParCes MONEY,@pmVrParInt MONEY,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomRet (IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo
,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,VrParCes,VrParInt,TimeSys,IdUsuario)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmIdCausa,@pmFecInicial,@pmFecFinal,@pmDiasTrab,@pmDiasNoRem,@pmVrTotDev,@pmVrTotDed,@pmVrTotCes,@pmVrTotPri,@pmVrTotVac,@pmVrTotInt,@pmVrTotInd,@pmVrNeto,@pmVrBaseCes,@pmVrBaseVac,@pmIdPeriodo,@pmKeyReg
,@pmNPerVac,@pmVrSalario,@pmIdDep,@pmIdCCosto,@pmIdSubCos,@pmIdNom,@pmTipoLiq,@pmpVehiculo,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmAnulado,@pmIdEstado,@pmVrParCes,@pmVrParInt,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRet_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomRet_Sel] @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomRet (IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac
,VrTotInt,VrTotInd,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo
,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,VrParCes,VrParInt,TimeSys,IdUsuario)
 SELECT @pmNewCedula,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac
,VrTotInt,VrTotInd,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo
,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,VrParCes,VrParInt,TimeSys,IdUsuario
 FROM  Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomRetDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrDevngado MONEY,@pmVrDeducido MONEY,@pmTarifa DECIMAL(10,4),@pmVrBase MONEY,@pmDiasBase DECIMAL(10,4)
,@pmDiasNoRem DECIMAL(10,4),@pmFecUltLiq SMALLDATETIME,@pmFecDesde SMALLDATETIME,@pmFecHasta SMALLDATETIME,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME,@pmGrupoLiq VARCHAR(15),@pmNPrestamo INT,@pmNCuota INT,@pmLogPmdio VARCHAR(1500)
,@pmClaseLiq VARCHAR(10),@pmCodFondo VARCHAR(8),@pmVrBaseLiq MONEY
 AS 
 INSERT INTO Trn_NomRetDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq)
 VALUES (@pmIdEmpleado,@pmNumero,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantidad,@pmVrUnitario,@pmVrDevngado,@pmVrDeducido,@pmTarifa,@pmVrBase,@pmDiasBase,@pmDiasNoRem,@pmFecUltLiq,@pmFecDesde,@pmFecHasta,@pmFecIniPmd,@pmFecFinPmd,@pmGrupoLiq
,@pmNPrestamo,@pmNCuota,@pmLogPmdio,@pmClaseLiq,@pmCodFondo,@pmVrBaseLiq)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomRetDet_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomRetDet_Sel] @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomRetDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem
,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq)
 SELECT @pmNewCedula,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem
,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq
 FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsNomSueldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomSueldos] @pmNumero INT,@pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmNContrato INT,@pmVrSueAnterior MONEY,@pmVrSueNuevo MONEY,@pmVrAtAnterior MONEY,@pmVrAtNuevo MONEY
,@pmMetodoUp CHAR(1),@pmReemplzado BIT,@pmFecUltAumto SMALLDATETIME,@pmCritSelect VARCHAR(250),@pmObservacion VARCHAR(100),@pmTipoActualiza VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomSueldos (Numero,IdEmpleado,Fecha,NContrato,VrSueAnterior,VrSueNuevo,VrAtAnterior,VrAtNuevo,MetodoUp,Reemplzado,FecUltAumto,CritSelect,Observacion,TipoActualiza,TimeSys,IdUsuario)
 VALUES (@pmNumero,@pmIdEmpleado,@pmFecha,@pmNContrato,@pmVrSueAnterior,@pmVrSueNuevo,@pmVrAtAnterior,@pmVrAtNuevo,@pmMetodoUp,@pmReemplzado,@pmFecUltAumto
,@pmCritSelect,@pmObservacion,@pmTipoActualiza,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomTablaRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomTablaRet] @pmnAnno INT,@pmnIntrvalo INT,@pmVrInicial MONEY,@pmVrFinal MONEY,@pmTarifa DECIMAL(10,4),@pmVrRetncion MONEY
,@pmTarExcdnte DECIMAL(10,4),@pmVrBaseExc MONEY,@pmFechaAdd SMALLDATETIME, @pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO NomTablaRet (nAnno,nIntrvalo,VrInicial,VrFinal,Tarifa,VrRetncion,TarExcdnte,VrBaseExc,FechaAdd,IdUsuario)
 VALUES (@pmnAnno,@pmnIntrvalo,@pmVrInicial,@pmVrFinal,@pmTarifa,@pmVrRetncion,@pmTarExcdnte,@pmVrBaseExc,@pmFechaAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomVac] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrLiquida MONEY,@pmVrBase MONEY,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME
,@pmDiasBase INT,@pmDiasNoRem INT,@pmDiasVac INT,@pmNNovedad INT,@pmNPeriodos INT,@pmCantRem INT,@pmVrRemndo MONEY,@pmVrTotDed MONEY,@pmVrSalario MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmLogPmdio VARCHAR(1500)
,@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmDiasAjuste INT,@pmLiqParcial BIT,@pmDiasDom INT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NomVac (IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,VrSalario,pVehiculo,DiasAjuste,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario,LiqParcial,DiasDom)
 VALUES (@pmIdEmpleado,@pmNumero,@pmFecha,@pmNContrato,@pmFecInicial,@pmFecFinal,@pmCantidad,@pmVrLiquida,@pmVrBase,@pmFecIniPmd,@pmFecFinPmd,@pmDiasBase,@pmDiasNoRem,@pmDiasVac,@pmNNovedad,@pmNPeriodos,@pmCantRem,@pmVrRemndo,@pmVrTotDed,@pmVrSalario,@pmpVehiculo,@pmDiasAjuste
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmLogPmdio,@pmIdEstado,@pmAnulado,@pmTimeSys,@pmIdUsuario,@pmLiqParcial,@pmDiasDom)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVac_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomVac_Sel] @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomVac (IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase
,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,VrSalario,pVehiculo,DiasAjuste,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario)
 SELECT @pmNewCedula,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase
,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,VrSalario,pVehiculo,DiasAjuste,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,IdEstado,Anulado,TimeSys,IdUsuario
 FROM  Trn_NomVac WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVacDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomVacDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad INT,@pmVrDevgado MONEY,@pmVrDeducido MONEY
,@pmTarifa DECIMAL(10,4),@pmVrBaseLiq MONEY,@pmVrCertfcado MONEY,@pmVrPension MONEY,@pmNPrestamo INT,@pmNCuota INT,@pmIdPeriodo VARCHAR(8),@pmVrSalud MONEY,@pmCodFondo VARCHAR(8)
 AS 
 INSERT INTO Trn_NomVacDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud,CodFondo)
 VALUES (@pmIdEmpleado,@pmNumero,@pmItem,@pmIdConcepto,@pmDetalle,@pmCantidad,@pmVrDevgado,@pmVrDeducido,@pmTarifa,@pmVrBaseLiq,@pmVrCertfcado,@pmVrPension,@pmNPrestamo,@pmNCuota,@pmIdPeriodo,@pmVrSalud,@pmCodFondo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVacDet_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNomVacDet_Sel] @pmIdEmpleado VARCHAR(16),@pmNewCedula VARCHAR(16)
 AS 
 INSERT INTO Trn_NomVacDet (IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud,CodFondo)
 SELECT @pmNewCedula,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud,CodFondo
 FROM  Trn_NomVacDet 
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paInsNomVehiculos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomVehiculos] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmClaseVeh VARCHAR(50),@pmTipoAdmon VARCHAR(50)
,@pmGrupoProp VARCHAR(50),@pmVehPropio BIT,@pmCedCond VARCHAR(16),@pmConductor VARCHAR(50)
 AS 
 INSERT INTO NomVehiculos (IdVehiculo,NumVeh,ClaseVeh,TipoAdmon,GrupoProp,VehPropio,CedCond,Conductor)
 VALUES (@pmIdVehiculo,@pmNumVeh,@pmClaseVeh,@pmTipoAdmon,@pmGrupoProp,@pmVehPropio,@pmCedCond,@pmConductor)
GO
/****** Object:  StoredProcedure [dbo].[paInsNomZonasConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNomZonasConv] @pmIdZona VARCHAR(4),@pmZonaConv VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO NomZonasConv (IdZona,ZonaConv,Inactivo)
 VALUES (@pmIdZona,@pmZonaConv,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNotaProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNotaProd] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4)
,@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY,@pmVrCostos MONEY,@pmCantEnt DECIMAL(14,4),@pmCantSal DECIMAL(14,4),@pmNumOrden INT
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoProd INT
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NotaProd (TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden,IdCCosto,IdSubCos,Modalidad,TipoProd,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdTercero,@pmVrSubTotal,@pmVrCostos,@pmCantEnt,@pmCantSal,@pmNumOrden
,@pmIdCCosto,@pmIdSubCos,@pmModalidad,@pmTipoProd,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev
,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCosto MONEY,@pmVrSancion MONEY,@pmVrOtros MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmCantidad DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY
,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmCdCajero VARCHAR(11),@pmIdLocal VARCHAR(8),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT
,@pmIdCiaDcm CHAR(2),@pmFecDcm SMALLDATETIME,@pmCdProducto VARCHAR(16),@pmCdForma VARCHAR(4),@pmNumCheque VARCHAR(20),@pmCdBanco VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmPrestCaja BIT,@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmnRemesa INT,@pmCdCiaRem CHAR(2),@pmItemRem INT,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmIdConcFE INT,@pmTipoNotaFE INT
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Notas (TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCosto,VrSancion,VrOtros,VrNeto,VrAplicado,VrAnticipo,Cantidad,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,CdCajero,IdLocal,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,FecDcm,CdProducto,CdForma,NumCheque,CdBanco,MulPlazos,IdPlazo,PrestCaja
,Modalidad,nRemesa,CdCiaRem,ItemRem,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrReteCREE,TarifaRtc,CodTarRtc,IdConcFE,TipoNotaFE)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFechaVence,@pmVrSubTotal,@pmVrImpuesto,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrCosto,@pmVrSancion,@pmVrOtros,@pmVrNeto,@pmVrAplicado,@pmVrAnticipo,@pmCantidad,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmIdCCosto,@pmIdSubCos,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmCdCajero,@pmIdLocal,@pmReferencia,@pmpVehiculo
,@pmCdConductor,@pmTipDcm,@pmDocumento,@pmIdCiaDcm,@pmFecDcm,@pmCdProducto,@pmCdForma,@pmNumCheque,@pmCdBanco,@pmMulPlazos,@pmIdPlazo,@pmPrestCaja,@pmModalidad,@pmnRemesa,@pmCdCiaRem,@pmItemRem,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmIdConcFE,@pmTipoNotaFE)
GO
/****** Object:  StoredProcedure [dbo].[paInsNotasBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsNotasBuses] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY,@pmValorIva MONEY,@pmValorReteFte MONEY,@pmValorReteIca MONEY,@pmValorCosto MONEY,@pmValorSancion MONEY,@pmValorNeto MONEY,@pmValorAplicado MONEY
,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmIdTarCom VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmPrestCaja BIT,@pmIntMora BIT,@pmNumCheque VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdClase VARCHAR(4),@pmIdCargo VARCHAR(4),@pmReferencia VARCHAR(20),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmBaseIva MONEY,@pmBaseRet MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmIdTarIva VARCHAR(4)
,@pmIdTarRet VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmIdConcFE INT,@pmTipoNotaFE INT,@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_NotasBuses (TipDoc,NumNota,IdCia,Fecha,FecVence,IdConcepto,IdCliente,IdAgencia,IdVehiculo,IdConductor,VehPropio,ValorTotal,ValorIva,ValorReteFte,ValorReteIca,ValorCosto,ValorSancion,ValorNeto,ValorAplicado,IdVendedor,Comision,IdTarCom,MulPlazos,IdPlazo,PrestCaja,IntMora,NumCheque,IdBanco,IdCCosto,IdClase,IdCargo,Referencia,TipDcm,Documento,IdCiaDoc,BaseIva,BaseRet,TarifaIva,TarifaRet,IdTarIva,IdTarRet,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,IdConcFE,TipoNotaFE)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmFecVence,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmIdConductor,@pmVehPropio,@pmValorTotal,@pmValorIva,@pmValorReteFte,@pmValorReteIca,@pmValorCosto,@pmValorSancion,@pmValorNeto,@pmValorAplicado,@pmIdVendedor,@pmComision,@pmIdTarCom,@pmMulPlazos,@pmIdPlazo,@pmPrestCaja,@pmIntMora,@pmNumCheque,@pmIdBanco,@pmIdCCosto,@pmIdClase,@pmIdCargo,@pmReferencia,@pmTipDcm
,@pmDocumento,@pmIdCiaDoc,@pmBaseIva,@pmBaseRet,@pmTarifaIva,@pmTarifaRet,@pmIdTarIva,@pmIdTarRet,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmIdConcFE,@pmTipoNotaFE)
GO
/****** Object:  StoredProcedure [dbo].[paInsNovedadRep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNovedadRep] @pmIdNov VARCHAR(4),@pmNovedad VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO NovedadRep (IdNov,Novedad,Inactivo)
 VALUES (@pmIdNov,@pmNovedad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsNovedadTra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsNovedadTra] @pmIdNovedad VARCHAR(4),@pmNovedad VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO NovedadTra (IdNovedad,Novedad,Inactivo)
 VALUES (@pmIdNovedad,@pmNovedad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsObjetosApp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsObjetosApp] @pmIdObj VARCHAR(10),@pmIdGrupo VARCHAR(6),@pmSubModulo VARCHAR(3),@pmIndObj INT,@pmNombre VARCHAR(100),@pmFormulario VARCHAR(10)
,@pmPermisos VARCHAR(20),@pmNivelMinimo INT,@pmNomArchivo VARCHAR(30)
 AS 
 INSERT INTO Sys_ObjetosApp (IdObj,IdGrupo,SubModulo,IndObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo)
 VALUES (@pmIdObj,@pmIdGrupo,@pmSubModulo,@pmIndObj,@pmNombre,@pmFormulario,@pmPermisos,@pmNivelMinimo,@pmNomArchivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsOComb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOComb] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaDesp SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmDirEnvio VARCHAR(250)
,@pmIdLocal VARCHAR(8),@pmLugarEnv VARCHAR(50),@pmDiasEntraga INT,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmCdRuta VARCHAR(4),@pmReferncia VARCHAR(50),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(150)
,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmTipGui VARCHAR(3),@pmGuia INT,@pmIdCiaGui CHAR(2),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmAutzaMora INT,@pmAutzaCupo INT,@pmAprobacion INT,@pmFechaAprob SMALLDATETIME
,@pmDetalleAprob VARCHAR(250),@pmCdUsuAprob VARCHAR(11),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmIdTerminal VARCHAR(4),@pmTipoOrden INT,@pmRemolque VARCHAR(10),@pmVrImpCarbono MONEY,@pmVrIvaIngProd MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OComb (TipDoc,OCargue,IdCia,Fecha,FechaDesp,FechaVence,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrNeto,Cantidad,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocal,LugarEnv,DiasEntraga,IdVehiculo,IdConductor,NitEmpTrans,EmpTrans,CdRuta,Referncia
,IdForma,DetallePago,MulPlazos,IdPlazo,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,Factura,IdCiaFac,FechaFact,AutzaMora,AutzaCupo,Aprobacion,FechaAprob,DetalleAprob,CdUsuAprob,IdTerminal,OrigenAdd,ZonaFrontera,TipoOrden,Remolque,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrImpCarbono,VrIvaIngProd)
 VALUES (@pmTipDoc,@pmOCargue,@pmIdCia,@pmFecha,@pmFechaDesp,@pmFechaVence,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrFletes,@pmVrOtros,@pmVrCargos,@pmVrOtrDcto,@pmVrSobretasa,@pmVrImpGlobal,@pmVrNeto,@pmCantidad,@pmIdVend,@pmTarifaCom,@pmCodTarCom
,@pmDirEnvio,@pmIdLocal,@pmLugarEnv,@pmDiasEntraga,@pmIdVehiculo,@pmIdConductor,@pmNitEmpTrans,@pmEmpTrans,@pmCdRuta,@pmReferncia,@pmIdForma,@pmDetallePago,@pmMulPlazos,@pmIdPlazo,@pmTipPed,@pmPedido,@pmIdCiaPed,@pmTipGui,@pmGuia,@pmIdCiaGui,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFact,@pmAutzaMora,@pmAutzaCupo,@pmAprobacion
,@pmFechaAprob,@pmDetalleAprob,@pmCdUsuAprob,@pmIdTerminal,@pmOrigenAdd,@pmZonaFrontera,@pmTipoOrden,@pmRemolque,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrImpCarbono,@pmVrIvaIngProd)
GO
/****** Object:  StoredProcedure [dbo].[paInsOCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOCompra] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrSobtasa MONEY,@pmVrImpGlobal MONEY
,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdEmpresa VARCHAR(16),@pmDirEntrega VARCHAR(250),@pmIdLocEtga VARCHAR(8),@pmDiasEntraga INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(100),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4)
,@pmCdMney VARCHAR(5),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmLiqFletes BIT,@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipEnt VARCHAR(3),@pmEntrada INT,@pmIdCiaEnt CHAR(2),@pmNumAutoriza INT,@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME
,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4),@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmVrReteIVA MONEY,@pmCodTarRiv VARCHAR(4),@pmNivelAprob INT,@pmVrIvaMvc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmNumDocSop INT,@pmCdCiaSop CHAR(2)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OCompra (TipDoc,OCompra,IdCia,Fecha,FechaVence,IdConcepto,IdProv,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobtasa,VrImpGlobal,VrRetencion,VrReteICA,VrReteIVA,VrNeto,Cantidad,TarifaRet,TarifaIca,CodTarRet,CodTarIca,CodTarRiv,IdEmpresa,DirEntrega,IdLocEtga,DiasEntraga,NitContac,NomContac,TelContac,emlContac,IdCCosto,IdSubCos,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans
,LiqFletes,pVehiculo,CdConductor,TipEnt,Entrada,IdCiaEnt,NumAutoriza,Modalidad,Vigencia,OrigenAdd,Anulado,FecDev,Observacion,NumAprob,FecAprob,CdUsuAprob,NivelAprob,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,VrImpuBA,VrImpuCUP,NumDocSop,CdCiaSop)
 VALUES (@pmTipDoc,@pmOCompra,@pmIdCia,@pmFecha,@pmFechaVence,@pmIdConcepto,@pmIdProv,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrFletes,@pmVrOtros,@pmVrCargos,@pmVrOtrDcto,@pmVrSobtasa,@pmVrImpGlobal,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrNeto,@pmCantidad,@pmTarifaRet,@pmTarifaIca,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmIdEmpresa,@pmDirEntrega,@pmIdLocEtga,@pmDiasEntraga,@pmNitContac,@pmNomContac
,@pmTelContac,@pmemlContac,@pmIdCCosto,@pmIdSubCos,@pmIdForma,@pmDetallePago,@pmMulPlazos,@pmIdPlazo,@pmCdMney,@pmNitEmpTrans,@pmEmpTrans,@pmLiqFletes,@pmpVehiculo,@pmCdConductor,@pmTipEnt,@pmEntrada,@pmIdCiaEnt,@pmNumAutoriza,@pmModalidad,@pmVigencia,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmNumAprob,@pmFecAprob,@pmCdUsuAprob,@pmNivelAprob,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrIvaMvc,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmVrImpuBA,@pmVrImpuCUP,@pmNumDocSop,@pmCdCiaSop)
GO
/****** Object:  StoredProcedure [dbo].[paInsOcupaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOcupaciones] @pmIdOcupac VARCHAR(4),@pmOcupacion VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO Ocupaciones (IdOcupac,Ocupacion,Inactivo)
 VALUES (@pmIdOcupac,@pmOcupacion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilAjustes] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecProceso SMALLDATETIME,@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmTipoProceso VARCHAR(10),@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCantEntradas DECIMAL(16,6),@pmCantSalidas DECIMAL(16,6),@pmCostoEnt DECIMAL(16,6),@pmCostoSal DECIMAL(16,6),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilAjustes (TipDoc,NumProceso,IdCia,Fecha,FecProceso,TipOrden,NumOrden,IdCiaOrden,TipoProceso,IdConcepto,IdTercero,CantEntradas,CantSalidas,CostoEnt,CostoSal,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumProceso,@pmIdCia,@pmFecha,@pmFecProceso,@pmTipOrden,@pmNumOrden,@pmIdCiaOrden,@pmTipoProceso,@pmIdConcepto,@pmIdTercero,@pmCantEntradas,@pmCantSalidas,@pmCostoEnt,@pmCostoSal,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilCompra] @pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmImpuesto DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmReteIva DECIMAL(16,6),@pmIvaIngProd DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmFletes DECIMAL(16,6),@pmVrNeto DECIMAL(16,6),@pmCantidad DECIMAL(16,6),@pmBaseImp DECIMAL(16,6),@pmBaseRet DECIMAL(16,6),@pmBaseIvaIgp DECIMAL(16,6)
,@pmTarifaIva DECIMAL(16,6),@pmTarifaRet DECIMAL(16,6),@pmTarifaIca DECIMAL(16,6),@pmTarifaRiv DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmEstRegCosto INT,@pmNumRegCosto INT,@pmCiaRegCosto CHAR(2)
,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilCompra (TipDoc,NumCompra,IdCia,Fecha,IdConcepto,IdProveedor,NumFactura,FechaFac,FechaVence,MulPlazos,IdPlazo,CxPagar,SubTotal,Descuento,Impuesto,Retencion,ReteIca,ReteIva,IvaIngProd,OtrosCargos,OtrosDctos,Fletes,VrNeto,Cantidad,BaseImp,BaseRet,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CdCCosto,CdSubCos,Modalidad,FechaInicio,FechaFinal,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,NumDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario,EstRegCosto,NumRegCosto,CiaRegCosto)
 VALUES (@pmTipDoc,@pmNumCompra,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdProveedor,@pmNumFactura,@pmFechaFac,@pmFechaVence,@pmMulPlazos,@pmIdPlazo,@pmCxPagar,@pmSubTotal,@pmDescuento,@pmImpuesto,@pmRetencion,@pmReteIca,@pmReteIva,@pmIvaIngProd,@pmOtrosCargos,@pmOtrosDctos,@pmFletes,@pmVrNeto,@pmCantidad,@pmBaseImp,@pmBaseRet,@pmBaseIvaIgp,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmCdCCosto,@pmCdSubCos,@pmModalidad,@pmFechaInicio,@pmFechaFinal,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmNumDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario,@pmEstRegCosto,@pmNumRegCosto,@pmCiaRegCosto)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCompraDesp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilCompraDesp] @pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCia CHAR(2),@pmItem INT,@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmItemEnt INT,@pmIdProducto VARCHAR(16),@pmCantBruto DECIMAL(16,6),@pmCantNeto DECIMAL(16,6),@pmCantEntrada DECIMAL(16,6)
,@pmUndMed VARCHAR(10),@pmUMCargue VARCHAR(10),@pmVrUnitario DECIMAL(16,6),@pmNumTasas INT,@pmTasaBrent DECIMAL(16,6),@pmTasaWti DECIMAL(16,6),@pmTRMdolar DECIMAL(16,6),@pmPuntos DECIMAL(16,6),@pmPrecioUnd DECIMAL(16,6),@pmVrTotal DECIMAL(16,6),@pmCdMoneda VARCHAR(5),@pmUMprecio VARCHAR(10)
 AS 
 INSERT INTO Trn_OilCompraDesp (TipDoc,NumCompra,IdCia,Item,NumGuia,IdCiaGuia,TipEnt,NumEntrada,IdCiaEnt,ItemEnt,IdProducto,CantBruto,CantNeto,CantEntrada,UndMed,UMCargue,VrUnitario,NumTasas,TasaBrent,TasaWti,TRMdolar,Puntos,PrecioUnd,VrTotal,CdMoneda,UMprecio)
 VALUES (@pmTipDoc,@pmNumCompra,@pmIdCia,@pmItem,@pmNumGuia,@pmIdCiaGuia,@pmTipEnt,@pmNumEntrada,@pmIdCiaEnt,@pmItemEnt,@pmIdProducto,@pmCantBruto,@pmCantNeto,@pmCantEntrada,@pmUndMed,@pmUMCargue,@pmVrUnitario,@pmNumTasas,@pmTasaBrent,@pmTasaWti,@pmTRMdolar,@pmPuntos,@pmPrecioUnd,@pmVrTotal,@pmCdMoneda,@pmUMprecio)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilCostos] @pmTipProc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNitProveedor VARCHAR(16),@pmCodCiaFac CHAR(2),@pmCantidad DECIMAL(16,6),@pmSubTotal DECIMAL(20,6),@pmVrTransporte DECIMAL(20,6),@pmVrTraVacio DECIMAL(20,6),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilCostos (TipProc,NumProceso,IdCia,Fecha,FechaInicio,FechaFinal,IdConcepto,NitProveedor,CodCiaFac,Cantidad,SubTotal,VrTransporte,VrTraVacio,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,NumDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipProc,@pmNumProceso,@pmIdCia,@pmFecha,@pmFechaInicio,@pmFechaFinal,@pmIdConcepto,@pmNitProveedor,@pmCodCiaFac,@pmCantidad,@pmSubTotal,@pmVrTransporte,@pmVrTraVacio,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmNumDev,@pmObservacion,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCostoVen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilCostoVen] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(20,6),@pmCantDev DECIMAL(16,6),@pmVrDevFact DECIMAL(20,6),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilCostoVen (TipDoc,NumNota,IdCia,Fecha,FechaInicio,FechaFinal,IdConcepto,Cantidad,ValorTotal,CantDev,VrDevFact,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmFechaInicio,@pmFechaFinal,@pmIdConcepto,@pmCantidad,@pmValorTotal,@pmCantDev,@pmVrDevFact,@pmCdCCosto,@pmCdSubCos,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilCostoVenProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilCostoVenProd] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(500),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmVrUnitario DECIMAL(16,6),@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmIdCiaFact CHAR(2),@pmItemFact INT,@pmFechaFact SMALLDATETIME,@pmTipGuia VARCHAR(3),@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmFechaGuia SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipoProd VARCHAR(10)
 AS 
 INSERT INTO Trn_OilCostoVenProd (TipDoc,NumNota,IdCia,Item,IdProducto,Descripcion,Cantidad,UndMed,VrUnitario,TipFact,NumFactura,IdCiaFact,ItemFact,FechaFact,TipGuia,NumGuia,IdCiaGuia,FechaGuia,IdCliente,IdAgencia,IdVehiculo,CdCCosto,CdSubCos,TipoProd)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmItem,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmUndMed,@pmVrUnitario,@pmTipFact,@pmNumFactura,@pmIdCiaFact,@pmItemFact,@pmFechaFact,@pmTipGuia,@pmNumGuia,@pmIdCiaGuia,@pmFechaGuia,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmCdCCosto,@pmCdSubCos,@pmTipoProd)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDespClie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilDespClie] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecDescargue SMALLDATETIME,@pmHorasVig DECIMAL(14,4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmRemolque VARCHAR(10),@pmIdEstacion VARCHAR(4),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmLugarOrigen VARCHAR(150),@pmDirDestino VARCHAR(250),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmModalidad VARCHAR(10),@pmReferencia VARCHAR(50),@pmNumRemision VARCHAR(20),@pmDetSellos VARCHAR(500)
,@pmCodSicom VARCHAR(20),@pmZonaFrontera INT,@pmCantidad DECIMAL(16,6),@pmSubTotal DECIMAL(16,6),@pmVrIva DECIMAL(16,6),@pmVrTransporte DECIMAL(16,6),@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmEstFactura INT,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilDespClie (TipDoc,NumGuia,IdCia,Fecha,FecCargue,FecDespacho,FecDescargue,HorasVig,IdCliente,IdAgencia,IdVehiculo,IdConductor,NitEmpTrans,NomEmpTrans,Remolque,IdEstacion,IdLocOrigen,IdLocDestino,LugarOrigen,DirDestino,NomContacto,TelContacto,emlContacto,Modalidad,Referencia,NumRemision,DetSellos,CodSicom,ZonaFrontera,Cantidad,SubTotal,VrIva,VrTransporte,TipOrden,NumOrden,IdCiaOrden,EstFactura,TipFac,Factura,IdCiaFac,FechaFact,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumGuia,@pmIdCia,@pmFecha,@pmFecCargue,@pmFecDespacho,@pmFecDescargue,@pmHorasVig,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmIdConductor,@pmNitEmpTrans,@pmNomEmpTrans,@pmRemolque,@pmIdEstacion,@pmIdLocOrigen,@pmIdLocDestino,@pmLugarOrigen,@pmDirDestino,@pmNomContacto,@pmTelContacto,@pmemlContacto,@pmModalidad,@pmReferencia,@pmNumRemision,@pmDetSellos,@pmCodSicom,@pmZonaFrontera,@pmCantidad,@pmSubTotal,@pmVrIva,@pmVrTransporte,@pmTipOrden,@pmNumOrden,@pmIdCiaOrden,@pmEstFactura,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFact,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDespClieProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilDespClieProd] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTanque VARCHAR(4),@pmTipoProd VARCHAR(10),@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(1000),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmTempLab DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmAPI_Corregido DECIMAL(16,6)
,@pmDensidad DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmFactorTemp DECIMAL(16,6),@pmVrUnitario DECIMAL(16,6),@pmFleteUnd DECIMAL(16,6),@pmTarifaIva DECIMAL(16,6),@pmVrIva DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodSicomPro VARCHAR(20),@pmIndMezcla INT,@pmItemMezcla INT,@pmFactorMezcla DECIMAL(16,6),@pmCantBruto DECIMAL(16,6)
 AS 
 INSERT INTO Trn_OilDespClieProd (TipDoc,NumGuia,IdCia,Item,IdTanque,TipoProd,IdProducto,Descripcion,Cantidad,UndMed,Temperatura,TempLab,UnidTemp,ValorAPI,API_Corregido,Densidad,ValorVCW,FactorTemp,VrUnitario,FleteUnd,TarifaIva,VrIva,CodTarIva,CodSicomPro,IndMezcla,ItemMezcla,FactorMezcla,CantBruto)
 VALUES (@pmTipDoc,@pmNumGuia,@pmIdCia,@pmItem,@pmIdTanque,@pmTipoProd,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmUndMed,@pmTemperatura,@pmTempLab,@pmUnidTemp,@pmValorAPI,@pmAPI_Corregido,@pmDensidad,@pmValorVCW,@pmFactorTemp,@pmVrUnitario,@pmFleteUnd,@pmTarifaIva,@pmVrIva,@pmCodTarIva,@pmCodSicomPro,@pmIndMezcla,@pmItemMezcla,@pmFactorMezcla,@pmCantBruto)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDevCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilDevCompra] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmCxPagar BIT,@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmImpuesto DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmReteIva DECIMAL(16,6),@pmIvaIngProd DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmFletes DECIMAL(16,6),@pmVrNeto DECIMAL(16,6),@pmCantidad DECIMAL(16,6),@pmBaseImp DECIMAL(16,6),@pmBaseRet DECIMAL(16,6),@pmBaseIvaIgp DECIMAL(16,6)
,@pmTarifaIva DECIMAL(16,6),@pmTarifaRet DECIMAL(16,6),@pmTarifaIca DECIMAL(16,6),@pmTarifaRiv DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(2000),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilDevCompra (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumCompra,IdCiaDoc,FecDoc,IdProveedor,NumFactura,CxPagar,SubTotal,Descuento,Impuesto,Retencion,ReteIca,ReteIva,IvaIngProd,OtrosCargos,OtrosDctos,Fletes,VrNeto,Cantidad,BaseImp,BaseRet,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CdCCosto,CdSubCos,Modalidad,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumCompra,@pmIdCiaDoc,@pmFecDoc,@pmIdProveedor,@pmNumFactura,@pmCxPagar,@pmSubTotal,@pmDescuento,@pmImpuesto,@pmRetencion,@pmReteIca,@pmReteIva,@pmIvaIngProd,@pmOtrosCargos,@pmOtrosDctos,@pmFletes,@pmVrNeto,@pmCantidad,@pmBaseImp,@pmBaseRet,@pmBaseIvaIgp,@pmTarifaIva,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmCdCCosto,@pmCdSubCos,@pmModalidad,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDevCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilDevCostos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmCantidad DECIMAL(16,6),@pmSubTotal DECIMAL(20,6),@pmVrTransporte DECIMAL(20,6),@pmVrTraVacio DECIMAL(20,6),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(2000),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilDevCostos (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumProceso,IdCiaDoc,FecDoc,Cantidad,SubTotal,VrTransporte,VrTraVacio,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmNumProceso,@pmIdCiaDoc,@pmFecDoc,@pmCantidad,@pmSubTotal,@pmVrTransporte,@pmVrTraVacio,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilDevFacProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilDevFacProd] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(500),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmVrUnitario DECIMAL(16,6),@pmTarifaDct DECIMAL(16,6),@pmVrDcto DECIMAL(16,6),@pmTarifaIva DECIMAL(16,6),@pmVrIva DECIMAL(16,6),@pmTarifaRet DECIMAL(16,6),@pmVrRetFte DECIMAL(16,6),@pmTarifaIca DECIMAL(16,6),@pmVrRetIca DECIMAL(16,6)
,@pmFleteUnd DECIMAL(16,6),@pmCostoUnit DECIMAL(16,6),@pmItemDet INT,@pmTipoProd VARCHAR(10),@pmTipGuia VARCHAR(3),@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmCantGuia DECIMAL(16,6),@pmIndMezcla INT,@pmItemMezcla INT,@pmFactorMezcla DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodTarDct VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodSicomPro VARCHAR(20),@pmCodBodega VARCHAR(4),@pmItemGuia INT,@pmVrBaseRet DECIMAL(16,6)
 AS 
 INSERT INTO Trn_OilDevFacProd (TipDev,Devolucion,IdCia,Item,IdTanque,IdProducto,Descripcion,Cantidad,UndMed,VrUnitario,TarifaDct,VrDcto,TarifaIva,VrIva,TarifaRet,VrRetFte,TarifaIca,VrRetIca,FleteUnd,CostoUnit,ItemDet,TipoProd,TipGuia,NumGuia,IdCiaGuia,CantGuia,IndMezcla,ItemMezcla,FactorMezcla,CodTarIva,CodTarDct,CodTarRet,CodTarIca,CodSicomPro,CodBodega,ItemGuia,VrBaseRet)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmItem,@pmIdTanque,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmUndMed,@pmVrUnitario,@pmTarifaDct,@pmVrDcto,@pmTarifaIva,@pmVrIva,@pmTarifaRet,@pmVrRetFte,@pmTarifaIca,@pmVrRetIca,@pmFleteUnd,@pmCostoUnit,@pmItemDet,@pmTipoProd,@pmTipGuia,@pmNumGuia,@pmIdCiaGuia,@pmCantGuia,@pmIndMezcla,@pmItemMezcla,@pmFactorMezcla,@pmCodTarIva,@pmCodTarDct,@pmCodTarRet,@pmCodTarIca,@pmCodSicomPro,@pmCodBodega,@pmItemGuia,@pmVrBaseRet)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilEntrada]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmFecDespacho SMALLDATETIME,@pmFecDescargue SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmRemolque VARCHAR(10),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT,@pmTipFactCxp VARCHAR(3),@pmNumFactura INT,@pmIdCiaCxp CHAR(2),@pmEstContable INT,@pmCdConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmTipoAju VARCHAR(3),@pmNumAjuInv INT,@pmIdCiaAju CHAR(2),@pmCantAjuste DECIMAL(16,6),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilEntrada (TipEnt,NumEntrada,IdCia,Fecha,NumGuia,IdCiaGuia,FecDespacho,FecDescargue,IdProveedor,IdVehiculo,IdConductor,NitEmpTrans,NomEmpTrans,Remolque,ValorTotal,CtaPagar,TipFactCxp,NumFactura,IdCiaCxp,TipoAju,NumAjuInv,IdCiaAju,CantAjuste,EstContable,CdConcepto,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario,NumFactTra,CdCiaFtr)
 VALUES (@pmTipEnt,@pmNumEntrada,@pmIdCia,@pmFecha,@pmNumGuia,@pmIdCiaGuia,@pmFecDespacho,@pmFecDescargue,@pmIdProveedor,@pmIdVehiculo,@pmIdConductor,@pmNitEmpTrans,@pmNomEmpTrans,@pmRemolque,@pmValorTotal,@pmCtaPagar,@pmTipFactCxp,@pmNumFactura,@pmIdCiaCxp,@pmTipoAju,@pmNumAjuInv,@pmIdCiaAju,@pmCantAjuste,@pmEstContable,@pmCdConcepto,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario,@pmNumFactTra,@pmCdCiaFtr)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilEntradaProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilEntradaProd] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmAPI_Corregido DECIMAL(16,6),@pmDensidad DECIMAL(16,6),@pmCantCargue DECIMAL(16,6)
,@pmTempCargue DECIMAL(16,6),@pmAPI_Cargue DECIMAL(16,6),@pmVCW_Cargue DECIMAL(16,6),@pmPesoNeto DECIMAL(16,6),@pmVrUnitario DECIMAL(16,6),@pmUMCargue VARCHAR(10)
 AS 
 INSERT INTO Trn_OilEntradaProd (TipEnt,NumEntrada,IdCia,Item,IdTanque,IdProducto,Cantidad,UndMed,Temperatura,UnidTemp,ValorAPI,ValorVCW,API_Corregido,Densidad,CantCargue,TempCargue,API_Cargue,VCW_Cargue,PesoNeto,VrUnitario,UMCargue)
 VALUES (@pmTipEnt,@pmNumEntrada,@pmIdCia,@pmItem,@pmIdTanque,@pmIdProducto,@pmCantidad,@pmUndMed,@pmTemperatura,@pmUnidTemp,@pmValorAPI,@pmValorVCW,@pmAPI_Corregido,@pmDensidad,@pmCantCargue,@pmTempCargue,@pmAPI_Cargue,@pmVCW_Cargue,@pmPesoNeto,@pmVrUnitario,@pmUMCargue)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilFacturaProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilFacturaProd] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(500),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmVrUnitario DECIMAL(16,6),@pmTarifaDct DECIMAL(16,6),@pmVrDcto DECIMAL(16,6),@pmTarifaIva DECIMAL(16,6),@pmVrIva DECIMAL(16,6)
,@pmTarifaRet DECIMAL(16,6),@pmVrRetFte DECIMAL(16,6),@pmTarifaIca DECIMAL(16,6),@pmVrRetIca DECIMAL(16,6),@pmFleteUnd DECIMAL(16,6),@pmCostoUnit DECIMAL(16,6),@pmTemperatura DECIMAL(16,6),@pmTempLab DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmAPI_Corregido DECIMAL(16,6),@pmDensidad DECIMAL(16,6),@pmTipoProd VARCHAR(10)
,@pmTipGuia VARCHAR(3),@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmCantGuia DECIMAL(16,6),@pmIndMezcla INT,@pmItemMezcla INT,@pmFactorMezcla DECIMAL(16,6),@pmNumTasas INT,@pmTasaBrent DECIMAL(16,6),@pmTasaWti DECIMAL(16,6),@pmTRMdolar DECIMAL(16,6),@pmPuntos DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodTarDct VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCdMoneda VARCHAR(5),@pmCodSicomPro VARCHAR(20),@pmCodBodega VARCHAR(4)
,@pmItemGuia INT,@pmVrBaseRet DECIMAL(16,6)
 AS 
 INSERT INTO Trn_OilFacturaProd (TipDoc,Factura,IdCia,Item,IdTanque,IdProducto,Descripcion,Cantidad,UndMed,VrUnitario,TarifaDct,VrDcto,TarifaIva,VrIva,TarifaRet,VrRetFte,TarifaIca,VrRetIca,FleteUnd,CostoUnit,Temperatura,TempLab,UnidTemp,ValorAPI,API_Corregido,Densidad,TipoProd,TipGuia,NumGuia,IdCiaGuia,CantGuia,IndMezcla,ItemMezcla,FactorMezcla,NumTasas,TasaBrent,TasaWti,TRMdolar,Puntos,CodTarIva,CodTarDct,CodTarRet,CodTarIca,CdMoneda,CodSicomPro,CodBodega,ItemGuia,VrBaseRet)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmItem,@pmIdTanque,@pmIdProducto,@pmDescripcion,@pmCantidad,@pmUndMed,@pmVrUnitario,@pmTarifaDct,@pmVrDcto,@pmTarifaIva,@pmVrIva,@pmTarifaRet,@pmVrRetFte,@pmTarifaIca,@pmVrRetIca,@pmFleteUnd,@pmCostoUnit,@pmTemperatura,@pmTempLab,@pmUnidTemp,@pmValorAPI,@pmAPI_Corregido,@pmDensidad,@pmTipoProd,@pmTipGuia,@pmNumGuia,@pmIdCiaGuia,@pmCantGuia,@pmIndMezcla,@pmItemMezcla,@pmFactorMezcla
,@pmNumTasas,@pmTasaBrent,@pmTasaWti,@pmTRMdolar,@pmPuntos,@pmCodTarIva,@pmCodTarDct,@pmCodTarRet,@pmCodTarIca,@pmCdMoneda,@pmCodSicomPro,@pmCodBodega,@pmItemGuia,@pmVrBaseRet)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdEstacion VARCHAR(4),@pmIdProducto VARCHAR(16),@pmCantBruto DECIMAL(16,6),@pmCantNeto DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmCantDescargue DECIMAL(16,6),@pmAPIDescargue DECIMAL(16,6),@pmTempDescargue DECIMAL(16,6),@pmFecDescargue SMALLDATETIME
,@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmNumRemision VARCHAR(20),@pmRemolque VARCHAR(10),@pmTipoEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmNumFactCom INT,@pmCdCiaFco CHAR(2),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2)
,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilGuia (TipDoc,NumGuia,IdCia,Fecha,FecDespacho,IdProveedor,IdVehiculo,IdConductor,IdEstacion,IdProducto,CantBruto,CantNeto,UndMed,Temperatura,UnidTemp,ValorAPI,ValorVCW,CantDescargue,APIDescargue,TempDescargue,FecDescargue,NitEmpTrans,NomEmpTrans,NumRemision,Remolque,TipoEnt,NumEntrada,IdCiaEnt,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario,NumFactCom,CdCiaFco,NumFactTra,CdCiaFtr)
 VALUES (@pmTipDoc,@pmNumGuia,@pmIdCia,@pmFecha,@pmFecDespacho,@pmIdProveedor,@pmIdVehiculo,@pmIdConductor,@pmIdEstacion,@pmIdProducto,@pmCantBruto,@pmCantNeto,@pmUndMed,@pmTemperatura,@pmUnidTemp,@pmValorAPI,@pmValorVCW,@pmCantDescargue,@pmAPIDescargue,@pmTempDescargue,@pmFecDescargue,@pmNitEmpTrans,@pmNomEmpTrans,@pmNumRemision,@pmRemolque,@pmTipoEnt,@pmNumEntrada,@pmIdCiaEnt,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado
,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario,@pmNumFactCom,@pmCdCiaFco,@pmNumFactTra,@pmCdCiaFtr)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilInvent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilInvent] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT,@pmEstContable INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilInvent (TipEnt,NumEntrada,IdCia,Fecha,IdConcepto,Modalidad,IdProveedor,NumFactura,FechaFac,FechaVence,Cantidad,ValorTotal,CtaPagar,EstContable,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,NumDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipEnt,@pmNumEntrada,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmIdProveedor,@pmNumFactura,@pmFechaFac,@pmFechaVence,@pmCantidad,@pmValorTotal,@pmCtaPagar,@pmEstContable,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmNumDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilInventDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilInventDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(2000),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilInventDev (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipEnt,NumEntrada,IdCiaDoc,FecDoc,IdProveedor,Cantidad,ValorTotal,CtaPagar,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipEnt,@pmNumEntrada,@pmIdCiaDoc,@pmFecDoc,@pmIdProveedor,@pmCantidad,@pmValorTotal,@pmCtaPagar,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilMediciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilMediciones] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecProceso SMALLDATETIME,@pmIdTurno VARCHAR(4),@pmIdOperario VARCHAR(16),@pmNomOperario VARCHAR(150),@pmAjuInvSob INT,@pmAjuInvFal INT,@pmIdCiaAin CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipDocAju VARCHAR(3),@pmVolPT DECIMAL(16,6),@pmVolMP DECIMAL(16,6),@pmNumNota INT,@pmFecProcAnt SMALLDATETIME,@pmNumHoras DECIMAL(14,4),@pmNumSalida INT,@pmNumNcp INT,@pmIdCiaNcp CHAR(2)
,@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilMediciones (TipDoc,NumInvent,IdCia,Fecha,FecProceso,IdTurno,IdOperario,NomOperario,Modalidad,TipDocAju,AjuInvSob,AjuInvFal,IdCiaAin,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario,VolPT,VolMP,NumNota,FecProcAnt,NumHoras,NumSalida,NumNcp,IdCiaNcp)
 VALUES (@pmTipDoc,@pmNumInvent,@pmIdCia,@pmFecha,@pmFecProceso,@pmIdTurno,@pmIdOperario,@pmNomOperario,@pmModalidad,@pmTipDocAju,@pmAjuInvSob,@pmAjuInvFal,@pmIdCiaAin,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario,@pmVolPT,@pmVolMP,@pmNumNota,@pmFecProcAnt,@pmNumHoras,@pmNumSalida,@pmNumNcp,@pmIdCiaNcp)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilMedicionesTq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilMedicionesTq] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmNivelVol DECIMAL(16,6),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTipoMed INT,@pmAlturaTq DECIMAL(16,6)
,@pmUndAforoC DECIMAL(16,6),@pmUndAforoF DECIMAL(16,6),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmAPI_Corregido DECIMAL(16,6),@pmDensidad DECIMAL(16,6),@pmCantSaldo DECIMAL(16,6),@pmCantAjuste DECIMAL(16,6),@pmVrUnitario DECIMAL(16,6)
,@pmTempLab DECIMAL(16,6),@pmVolMedido DECIMAL(16,6),@pmVolNeto DECIMAL(16,6),@pmVol_Anterior DECIMAL(16,6),@pmCantEntradas DECIMAL(16,6),@pmCantSalidas DECIMAL(16,6)
,@pmTipoProd VARCHAR(10),@pmDescripcion VARCHAR(500)
 AS 
 INSERT INTO Trn_OilMedicionesTq (TipDoc,NumInvent,IdCia,Item,IdTanque,IdProducto,NivelVol,Cantidad,UndMed,TipoMed,AlturaTq,UndAforoC,UndAforoF,Temperatura,UnidTemp,ValorAPI,API_Corregido,Densidad,CantSaldo,CantAjuste,VrUnitario
,TempLab,VolMedido,VolNeto,Vol_Anterior,CantEntradas,CantSalidas,TipoProd,Descripcion)
 VALUES (@pmTipDoc,@pmNumInvent,@pmIdCia,@pmItem,@pmIdTanque,@pmIdProducto,@pmNivelVol,@pmCantidad,@pmUndMed,@pmTipoMed,@pmAlturaTq,@pmUndAforoC,@pmUndAforoF,@pmTemperatura,@pmUnidTemp,@pmValorAPI,@pmAPI_Corregido,@pmDensidad,@pmCantSaldo,@pmCantAjuste,@pmVrUnitario
,@pmTempLab,@pmVolMedido,@pmVolNeto,@pmVol_Anterior,@pmCantEntradas,@pmCantSalidas,@pmTipoProd,@pmDescripcion)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilNotas (TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdTercero,Cantidad,ValorTotal,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdTercero,@pmCantidad,@pmValorTotal,@pmCdCCosto,@pmCdSubCos,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilTraslado] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCantMP DECIMAL(16,6),@pmCantProducido DECIMAL(16,6),@pmCantConsumo DECIMAL(16,6),@pmCantCrudoCom DECIMAL(16,6),@pmTotal_MP DECIMAL(20,6),@pmVU_MP DECIMAL(20,6),@pmCantBrutoMP DECIMAL(16,6),@pmCantNetoMP DECIMAL(16,6),@pmCantFactMP DECIMAL(16,6),@pmTotal_TRA DECIMAL(20,6),@pmVU_TRA DECIMAL(20,6)
,@pmCantNetoTRA DECIMAL(16,6),@pmCantFactTRA DECIMAL(16,6),@pmTotal_TVacio DECIMAL(20,6),@pmVU_TVacio DECIMAL(20,6),@pmCantNetoTv DECIMAL(16,6),@pmCantFactTv DECIMAL(16,6),@pmTotal_Standby DECIMAL(20,6),@pmVU_Standby DECIMAL(20,6),@pmCant_Standby DECIMAL(16,6),@pmTotal_MOD DECIMAL(20,6),@pmTotal_CIF DECIMAL(20,6),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmOrigenAdd VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_OilTraslado (TipDoc,NumNota,IdCia,Fecha,FechaInicio,FechaFinal,IdConcepto,IdTercero,CantMP,CantProducido,CantConsumo,CantCrudoCom,Total_MP,VU_MP,CantBrutoMP,CantNetoMP,CantFactMP,Total_TRA,VU_TRA,CantNetoTRA,CantFactTRA,Total_TVacio,VU_TVacio,CantNetoTv,CantFactTv,Total_Standby,VU_Standby,Cant_Standby,Total_MOD,Total_CIF,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmFecha,@pmFechaInicio,@pmFechaFinal,@pmIdConcepto,@pmIdTercero,@pmCantMP,@pmCantProducido,@pmCantConsumo,@pmCantCrudoCom,@pmTotal_MP,@pmVU_MP,@pmCantBrutoMP,@pmCantNetoMP,@pmCantFactMP,@pmTotal_TRA,@pmVU_TRA,@pmCantNetoTRA,@pmCantFactTRA,@pmTotal_TVacio,@pmVU_TVacio,@pmCantNetoTv,@pmCantFactTv,@pmTotal_Standby,@pmVU_Standby,@pmCant_Standby,@pmTotal_MOD,@pmTotal_CIF,@pmCdCCosto,@pmCdSubCos,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmOrigenAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsOilTrasladoProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOilTrasladoProd] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(500),@pmTipoProd VARCHAR(10),@pmSaldoInicial DECIMAL(16,6),@pmSaldoFinal DECIMAL(16,6),@pmEntradas DECIMAL(16,6),@pmDespachos DECIMAL(16,6),@pmDespMezcla DECIMAL(16,6),@pmSalidas DECIMAL(16,6),@pmAjuSobrante DECIMAL(16,6),@pmAjuFaltante DECIMAL(16,6),@pmCantidad DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmPorcRend DECIMAL(16,6)
,@pmCostoAnt DECIMAL(20,6),@pmVrUnitario DECIMAL(20,6),@pmVrTotal DECIMAL(20,6),@pmSaldoMPAnt DECIMAL(16,6),@pmCantProdAnt DECIMAL(16,6),@pmCostoMPAnt DECIMAL(20,6),@pmCostoMPMes DECIMAL(20,6),@pmCostoUndMP DECIMAL(20,6),@pmCostoUndTra DECIMAL(20,6),@pmCostoTotalTra DECIMAL(20,6),@pmCostoTotalSB DECIMAL(20,6),@pmCostoUndVco DECIMAL(20,6),@pmCostoTotalVco DECIMAL(20,6),@pmCostoTotalMod DECIMAL(20,6),@pmCostoTotalCif DECIMAL(20,6),@pmCodMezcla VARCHAR(16),@pmCdoSubMezcla VARCHAR(8)
,@pmProducido DECIMAL(16,6),@pmCantVehTnsto DECIMAL(16,6),@pmCantBrutoDesp DECIMAL(16,6),@pmCantNetoDesp DECIMAL(16,6),@pmCantTraDesp DECIMAL(16,6)
 AS 
 INSERT INTO Trn_OilTrasladoProd (TipDoc,NumNota,IdCia,Item,IdProducto,Descripcion,TipoProd,SaldoInicial,SaldoFinal,Entradas,Despachos,DespMezcla,Salidas,AjuSobrante,AjuFaltante,Cantidad,UndMed,PorcRend,CostoAnt,VrUnitario,VrTotal,SaldoMPAnt,CantProdAnt,CostoMPAnt,CostoMPMes,CostoUndMP,CostoUndTra,CostoTotalTra,CostoTotalSB,CostoUndVco,CostoTotalVco,CostoTotalMod,CostoTotalCif,CodMezcla,CdoSubMezcla,Producido,CantVehTnsto,CantBrutoDesp,CantNetoDesp,CantTraDesp)
 VALUES (@pmTipDoc,@pmNumNota,@pmIdCia,@pmItem,@pmIdProducto,@pmDescripcion,@pmTipoProd,@pmSaldoInicial,@pmSaldoFinal,@pmEntradas,@pmDespachos,@pmDespMezcla,@pmSalidas,@pmAjuSobrante,@pmAjuFaltante,@pmCantidad,@pmUndMed,@pmPorcRend,@pmCostoAnt,@pmVrUnitario,@pmVrTotal,@pmSaldoMPAnt,@pmCantProdAnt,@pmCostoMPAnt,@pmCostoMPMes,@pmCostoUndMP,@pmCostoUndTra,@pmCostoTotalTra,@pmCostoTotalSB,@pmCostoUndVco,@pmCostoTotalVco,@pmCostoTotalMod
,@pmCostoTotalCif,@pmCodMezcla,@pmCdoSubMezcla,@pmProducido,@pmCantVehTnsto,@pmCantBrutoDesp,@pmCantNetoDesp,@pmCantTraDesp)
GO
/****** Object:  StoredProcedure [dbo].[paInsOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsOpciones] @pmIdOpc VARCHAR(3),@pmOpcion VARCHAR(100),@pmTipoDato VARCHAR(15)
,@pmValor VARCHAR(100),@pmNivUp INT,@pmnModulo VARCHAR(10)
 AS 
 INSERT INTO adm_Opciones (IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo)
 VALUES (@pmIdOpc,@pmOpcion,@pmTipoDato,@pmValor,@pmNivUp,@pmnModulo)
GO
/****** Object:  StoredProcedure [dbo].[paInsOpedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOpedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdClieFact VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY
,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmDirEnvio VARCHAR(250),@pmIdLocEnv VARCHAR(8),@pmLugarEnvio VARCHAR(50)
,@pmDiasEntraga INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargoContac VARCHAR(50),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(100),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150)
,@pmAsignarVeh BIT,@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmCdRuta VARCHAR(4),@pmListaPrec CHAR(1),@pmRefPedido VARCHAR(50),@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmNumAutoriza INT,@pmNumAutCupo INT,@pmNumAutCheq INT,@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME
,@pmDetalleAprob VARCHAR(250),@pmCdUsuAprob VARCHAR(11),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFechaRem SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmTipoTrans INT,@pmTipoOrden VARCHAR(3),@pmTipoModifica VARCHAR(10),@pmNumCotizac INT,@pmCdCiaCotizac CHAR(2),@pmNumAutSicom VARCHAR(50),@pmVrImpCarbono MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Opedido (TipDoc,Pedido,IdCia,Fecha,FechaVence,IdConcepto,IdCliente,IdAgencia,IdClieFact,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrNeto,Cantidad,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,LugarEnvio,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago
,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,AsignarVeh,pVehiculo,CdConductor,CdRuta,ListaPrec,RefPedido,Modalidad,Vigencia,NumAutoriza,NumAutCupo,NumAutCheq,NumAprob,IdCiaApr,FecAprob,DetalleAprob,CdUsuAprob,TipFac,Factura,IdCiaFac,FechaFact,TipRem,Remision,IdCiaRem,FechaRem,NumCotizac,CdCiaCotizac,OrigenAdd,ZonaFrontera,TipoTrans,TipoOrden,TipoModifica,Anulado,FecDev,Observacion,IdEstado
,TimeSys,IdCiaCrea,IdUsuario,NumAutSicom,VrImpCarbono,BaseIvaIgp,VrIvaIngProd,VrImpuBA,VrImpuCUP)
 VALUES (@pmTipDoc,@pmPedido,@pmIdCia,@pmFecha,@pmFechaVence,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmIdClieFact,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrFletes,@pmVrOtros,@pmVrCargos,@pmVrOtrDcto,@pmVrSobretasa,@pmVrImpGlobal,@pmVrNeto,@pmCantidad,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmDirEnvio,@pmIdLocEnv
,@pmLugarEnvio,@pmDiasEntraga,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargoContac,@pmIdForma,@pmDetallePago,@pmMulPlazos,@pmIdPlazo,@pmCdMney,@pmNitEmpTrans,@pmEmpTrans,@pmAsignarVeh,@pmpVehiculo,@pmCdConductor,@pmCdRuta,@pmListaPrec,@pmRefPedido,@pmModalidad,@pmVigencia,@pmNumAutoriza,@pmNumAutCupo
,@pmNumAutCheq,@pmNumAprob,@pmIdCiaApr,@pmFecAprob,@pmDetalleAprob,@pmCdUsuAprob,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFact,@pmTipRem,@pmRemision,@pmIdCiaRem,@pmFechaRem,@pmNumCotizac,@pmCdCiaCotizac,@pmOrigenAdd,@pmZonaFrontera,@pmTipoTrans,@pmTipoOrden,@pmTipoModifica,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumAutSicom,@pmVrImpCarbono,@pmBaseIvaIgp,@pmVrIvaIngProd,@pmVrImpuBA,@pmVrImpuCUP)
GO
/****** Object:  StoredProcedure [dbo].[paInsOrgTransito]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsOrgTransito] @pmIdOrgTra VARCHAR(8),@pmNomOrgTrans VARCHAR(250),@pmIdLocal VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO OrgTransito (IdOrgTra,NomOrgTrans,IdLocal,Inactivo)
 VALUES (@pmIdOrgTra,@pmNomOrgTrans,@pmIdLocal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsPagos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPagos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdForma VARCHAR(4),@pmDetalle VARCHAR(150),@pmVrPagado MONEY,@pmVrCambio MONEY
,@pmEsCaja BIT,@pmIdBanco VARCHAR(4),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmNumForma VARCHAR(20),@pmFecForma SMALLDATETIME,@pmCtaForma VARCHAR(30),@pmBeneficiario VARCHAR(150),@pmReferncia1 VARCHAR(50)
,@pmReferncia2 VARCHAR(50),@pmCdLocal VARCHAR(8),@pmNumAutoriza VARCHAR(30),@pmVrDenom MONEY,@pmCantidad INT,@pmTipDenom CHAR(1),@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmItemDoc INT
,@pmCdCta VARCHAR(4),@pmCdProducto VARCHAR(16),@pmFE_Ticket BIT,@pmCant_Gals DECIMAL(14,4),@pmPrecioBase MONEY,@pmPrecioUnit MONEY,@pmConsCP BIT,@pmCodCueCons VARCHAR(16)
,@pmPrecioPub MONEY,@pmRefVehiculo VARCHAR(10),@pmRefNumVeh VARCHAR(10),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Pagos (TipDoc,Documento,IdCia,Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta,IdUsuario
,CdProducto,FE_Ticket,Cant_Gals,PrecioBase,PrecioUnit,ConsCP,CodCueCons,PrecioPub,RefVehiculo,RefNumVeh)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecha,@pmIdForma,@pmDetalle,@pmVrPagado,@pmVrCambio,@pmEsCaja,@pmIdBanco,@pmNitCliente,@pmCdAgencia,@pmNumForma,@pmFecForma,@pmCtaForma,@pmBeneficiario,@pmReferncia1,@pmReferncia2
,@pmCdLocal,@pmNumAutoriza,@pmVrDenom,@pmCantidad,@pmTipDenom,@pmTipRef,@pmDocRef,@pmIdCiaRef,@pmItemDoc,@pmCdCta,@pmIdUsuario,@pmCdProducto,@pmFE_Ticket,@pmCant_Gals,@pmPrecioBase,@pmPrecioUnit,@pmConsCP,@pmCodCueCons,@pmPrecioPub,@pmRefVehiculo,@pmRefNumVeh)
GO
/****** Object:  StoredProcedure [dbo].[paInsPaises]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPaises] @pmIdPais VARCHAR(8),@pmCodISO VARCHAR(3),@pmNombrePais VARCHAR(50),@pmIdMneda VARCHAR(5)
 AS 
 INSERT INTO adm_Paises (IdPais,CodISO,NombrePais,IdMneda)
 VALUES (@pmIdPais,@pmCodISO,@pmNombrePais,@pmIdMneda)
GO
/****** Object:  StoredProcedure [dbo].[paInsPeajesCat]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPeajesCat] @pmIdCat VARCHAR(4),@pmCatpeaje VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO PeajesCat (IdCat,Catpeaje,Inactivo)
 VALUES (@pmIdCat,@pmCatpeaje,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsPeajesClase]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPeajesClase] @pmIdClase VARCHAR(4),@pmClasePeaje VARCHAR(50),@pmNitConsec VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO PeajesClase (IdClase,ClasePeaje,NitConsec,Inactivo)
 VALUES (@pmIdClase,@pmClasePeaje,@pmNitConsec,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsPeajesTarf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPeajesTarf] @pmIdCat VARCHAR(4),@pmIdClase VARCHAR(4),@pmVrTarifa MONEY
 AS 
 INSERT INTO PeajesTarf (IdCat,IdClase,VrTarifa)
 VALUES (@pmIdCat,@pmIdClase,@pmVrTarifa)
GO
/****** Object:  StoredProcedure [dbo].[paInsPermisos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPermisos] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmConsecutivo INT,@pmPerAdd BIT,@pmPerUpdate BIT
,@pmPerDelete BIT,@pmPerAnular BIT,@pmPerRead BIT,@pmPerRename BIT
 AS 
 INSERT INTO adm_Permisos (IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename)
 VALUES (@pmIdUsuario,@pmIdObj,@pmConsecutivo,@pmPerAdd,@pmPerUpdate,@pmPerDelete,@pmPerAnular,@pmPerRead,@pmPerRename)
GO
/****** Object:  StoredProcedure [dbo].[paInsPermisosRoles]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPermisosRoles] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmAsignado BIT
 AS 
 INSERT INTO adm_PermisosRoles (IdUsuario,IdObj,IdRole,Asignado)
 VALUES (@pmIdUsuario,@pmIdObj,@pmIdRole,@pmAsignado)
GO
/****** Object:  StoredProcedure [dbo].[paInsPicoPlaca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPicoPlaca] @pmFecha SMALLDATETIME,@pmUltimoDig VARCHAR(50)
 AS 
 INSERT INTO PicoPlaca (Fecha,UltimoDig)
 VALUES (@pmFecha,@pmUltimoDig)
GO
/****** Object:  StoredProcedure [dbo].[paInsPlazos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPlazos] @pmIdPlazo VARCHAR(4),@pmPlazo VARCHAR(50),@pmNVmto INT
,@pmDiasPago VARCHAR(50),@pmCdDctoPp VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO Plazos (IdPlazo,Plazo,NVmto,DiasPago,Inactivo,CdDctoPp)
 VALUES (@pmIdPlazo,@pmPlazo,@pmNVmto,@pmDiasPago,@pmInactivo,@pmCdDctoPp)
GO
/****** Object:  StoredProcedure [dbo].[paInsPolizas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPolizas] @pmNumPoliza VARCHAR(30),@pmFecha SMALLDATETIME,@pmVigencia SMALLDATETIME,@pmNitCompania VARCHAR(16),@pmCompania VARCHAR(150)
,@pmNitTomador VARCHAR(16),@pmTomador VARCHAR(150),@pmNitAseg VARCHAR(16),@pmAsegurado VARCHAR(150),@pmNitBenef VARCHAR(16),@pmBeneficiario VARCHAR(150)
,@pmInactivo BIT,@pmDescFirma VARCHAR(2000),@pmCodEmpresa VARCHAR(20),@pmTipo_Poliza VARCHAR(20),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Polizas (NumPoliza,Fecha,Vigencia,NitCompania,Compania,NitTomador,Tomador,NitAseg,Asegurado,NitBenef,Beneficiario,DescFirma,Inactivo,FechaAdd,IdUsuario,CodEmpresa,Tipo_Poliza)
 VALUES (@pmNumPoliza,@pmFecha,@pmVigencia,@pmNitCompania,@pmCompania,@pmNitTomador,@pmTomador,@pmNitAseg,@pmAsegurado
,@pmNitBenef,@pmBeneficiario,@pmDescFirma,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmCodEmpresa,@pmTipo_Poliza)
GO
/****** Object:  StoredProcedure [dbo].[paInsPreCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPreCausacion] @pmCausacionID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmModalidad VARCHAR(10),@pmTotalCapital MONEY,@pmTotalInteres MONEY,@pmTotalCuota MONEY,@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmTipDoc VARCHAR(3),@pmPrestamoID INT
,@pmIdCiaDoc CHAR(2),@pmNumCuota INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_PreCausacion (CausacionID,IdCia,Fecha,Modalidad,TotalCapital,TotalInteres,TotalCuota,IdVehiculo,IdPropietario,TipDoc,PrestamoID,IdCiaDoc,NumCuota,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,TimeSys,IdUsuario)
 VALUES (@pmCausacionID,@pmIdCia,@pmFecha,@pmModalidad,@pmTotalCapital,@pmTotalInteres,@pmTotalCuota,@pmIdVehiculo,@pmIdPropietario,@pmTipDoc,@pmPrestamoID,@pmIdCiaDoc,@pmNumCuota,@pmAnulado,@pmFecDev,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsPreCuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPreCuotas] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmNumCuota INT,@pmFecCausa SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmValorCapital MONEY,@pmValorInteres MONEY,@pmValorCuota MONEY,@pmCausacionID INT,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_PreCuotas (TipDoc,PrestamoID,IdCia,NumCuota,FecCausa,FecVence,ValorCapital,ValorInteres,ValorCuota,CausacionID,IdUsuario)
 VALUES (@pmTipDoc,@pmPrestamoID,@pmIdCia,@pmNumCuota,@pmFecCausa,@pmFecVence,@pmValorCapital,@pmValorInteres,@pmValorCuota,@pmCausacionID,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsPresDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPresDetalle] @pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdCuenta VARCHAR(16),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmVrPresupuesto MONEY,@pmSaldoAnterior MONEY,@pmTotalDebitos MONEY,@pmTotalCreditos MONEY,@pmTipoNiif VARCHAR(10)
,@pmCodCueNiif VARCHAR(16),@pmVrPrespNiif MONEY,@pmSAnteriorNiif MONEY,@pmDebitosNiif MONEY,@pmCreditosNiif MONEY,@pmCdUsuario VARCHAR(11),@pmFecUpdate SMALLDATETIME
 AS 
 INSERT INTO Trn_PresDetalle (Numero,IdCia,Item,IdCuenta,IdCCosto,IdSubCos,VrPresupuesto,SaldoAnterior,TotalDebitos,TotalCreditos,TipoNiif,CodCueNiif,VrPrespNiif,SAnteriorNiif,DebitosNiif,CreditosNiif,CdUsuario,FecUpdate)
 VALUES (@pmNumero,@pmIdCia,@pmItem,@pmIdCuenta,@pmIdCCosto,@pmIdSubCos,@pmVrPresupuesto,@pmSaldoAnterior,@pmTotalDebitos,@pmTotalCreditos,@pmTipoNiif,@pmCodCueNiif,@pmVrPrespNiif,@pmSAnteriorNiif,@pmDebitosNiif,@pmCreditosNiif,@pmCdUsuario,@pmFecUpdate)
GO
/****** Object:  StoredProcedure [dbo].[paInsPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPrestamos] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecPrestamo SMALLDATETIME,@pmFecInicio SMALLDATETIME,@pmTipoPlazo VARCHAR(10),@pmNumCuotas INT
,@pmDiasCausa VARCHAR(5),@pmDiasVence VARCHAR(5),@pmTipoCuota VARCHAR(10),@pmValorPrestamo MONEY,@pmTasaInteres DECIMAL(14,4),@pmTotalCausado MONEY,@pmTotalInteres MONEY,@pmUltimaCuota INT,@pmCancelado BIT,@pmIdConcepto VARCHAR(4)
,@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmCxPagar BIT,@pmReferencia VARCHAR(20),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME, @pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Prestamos (TipDoc,PrestamoID,IdCia,Fecha,FecPrestamo,FecInicio,TipoPlazo,NumCuotas,DiasCausa,DiasVence,TipoCuota,ValorPrestamo,TasaInteres,TotalCausado,TotalInteres,UltimaCuota,Cancelado,IdConcepto,IdVehiculo,IdPropietario,IdConductor
,VehPropio,CxPagar,Referencia,Anulado,NumDev,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmPrestamoID,@pmIdCia,@pmFecha,@pmFecPrestamo,@pmFecInicio,@pmTipoPlazo,@pmNumCuotas,@pmDiasCausa,@pmDiasVence,@pmTipoCuota,@pmValorPrestamo,@pmTasaInteres,@pmTotalCausado,@pmTotalInteres
,@pmUltimaCuota,@pmCancelado,@pmIdConcepto,@pmIdVehiculo,@pmIdPropietario,@pmIdConductor,@pmVehPropio,@pmCxPagar,@pmReferencia,@pmAnulado,@pmNumDev,@pmFecDev,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsPresupuesto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPresupuesto] @pmNumero INT,@pmIdCia CHAR(2),@pmnAnno INT,@pmnMes INT
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoPsto INT, @pmDetCentros BIT
,@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Presupuesto (Numero,IdCia,nAnno,nMes,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,TipoPsto,DetCentros)
 VALUES (@pmNumero,@pmIdCia,@pmnAnno,@pmnMes,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoPsto, @pmDetCentros)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdAditivos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsProdAditivos] @pmIdProducto VARCHAR(16),@pmIdAditivo VARCHAR(16),@pmCant DECIMAL(14,4),@pmUnidad VARCHAR(10)
,@pmCdBodega VARCHAR(4),@pmCdTanq VARCHAR(4)
 AS 
 INSERT INTO ProdAditivos (IdProducto,IdAditivo,Cant,Unidad,CdBodega,CdTanq)
 VALUES (@pmIdProducto,@pmIdAditivo,@pmCant,@pmUnidad,@pmCdBodega,@pmCdTanq)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdCombo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdCombo] @pmIdProducto VARCHAR(16),@pmItem INT,@pmIdProdBas VARCHAR(16),@pmCant DECIMAL(14,4)
,@pmCdBodega VARCHAR(4),@pmCdTanq VARCHAR(4),@pmFacMezcla VARCHAR(10),@pmExentoSob BIT
 AS 
 INSERT INTO ProdCombo (IdProducto,Item,IdProdBas,Cant,CdBodega,CdTanq,FacMezcla,ExentoSob)
 VALUES (@pmIdProducto,@pmItem,@pmIdProdBas,@pmCant,@pmCdBodega,@pmCdTanq,@pmFacMezcla,@pmExentoSob)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdConsolida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdConsolida] @pmTipDoc VARCHAR(3),@pmNumCons INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdBodega VARCHAR(4),@pmCdBodDest VARCHAR(4),@pmIdBodIns VARCHAR(4),@pmCdBodInsDest VARCHAR(4),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmCritPedidos VARCHAR(500),@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_ProdConsolida (TipDoc,NumCons,IdCia,Fecha,IdBodega,CdBodDest,IdBodIns,CdBodInsDest,OrigenAdd,Anulado,FecDev,CritPedidos,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumCons,@pmIdCia,@pmFecha,@pmIdBodega,@pmCdBodDest,@pmIdBodIns,@pmCdBodInsDest,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmCritPedidos,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdCostos] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmCostoAnt MONEY
,@pmCostoUlt MONEY,@pmCostoPmd MONEY,@pmFecUltPmd SMALLDATETIME
 AS 
 INSERT INTO ProdCostos (IdProducto,IdCia,CostoAnt,CostoUlt,CostoPmd,FecUltPmd)
 VALUES (@pmIdProducto,@pmIdCia,@pmCostoAnt,@pmCostoUlt,@pmCostoPmd,@pmFecUltPmd)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdEntrega]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdEntrega] @pmTipDoc VARCHAR(3),@pmNumEntrega INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmFecEntrega SMALLDATETIME,@pmCostoTotal MONEY,@pmDescuento MONEY,@pmCantTotal DECIMAL(14,4),@pmTipoEntrega VARCHAR(10),@pmNitTercero VARCHAR(16)
,@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmEdoOrden INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmCodConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmNumDev INT,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_ProdEntrega (TipDoc,NumEntrega,IdCia,Fecha,TipOrden,NumOrden,IdCiaOrden,FecEntrega,CostoTotal,Descuento,CantTotal,TipoEntrega,NitTercero,NomContacto,TelContacto,EdoOrden,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,CodConcepto,TipCom,Comprobante,IdCiaCom,NumDev)
 VALUES (@pmTipDoc,@pmNumEntrega,@pmIdCia,@pmFecha,@pmTipOrden,@pmNumOrden,@pmIdCiaOrden,@pmFecEntrega,@pmCostoTotal,@pmDescuento,@pmCantTotal,@pmTipoEntrega,@pmNitTercero,@pmNomContacto,@pmTelContacto,@pmEdoOrden,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCodConcepto,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmNumDev)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdImpFron]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdImpFron] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT,@pmIdLocal VARCHAR(8),@pmTarifa DECIMAL(14,4),@pmSimbTfa CHAR(1),@pmCdTarifa VARCHAR(4)
,@pmRngFecha BIT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmLtaPre CHAR(1),@pmInactivo BIT,@pmFecUpdate SMALLDATETIME,@pmTarifZfe DECIMAL(14,4),@pmCdDpto VARCHAR(8)
 AS 
 INSERT INTO ProdImpFron (IdProducto,IdClase,Item,IdLocal,CdDpto,Tarifa,SimbTfa,CdTarifa,TarifZfe,RngFecha,FecInicial,FecFinal,LtaPre,Inactivo,FecUpdate)
 VALUES (@pmIdProducto,@pmIdClase,@pmItem,@pmIdLocal,@pmCdDpto,@pmTarifa,@pmSimbTfa,@pmCdTarifa,@pmTarifZfe,@pmRngFecha,@pmFecInicial
,@pmFecFinal,@pmLtaPre,@pmInactivo,@pmFecUpdate)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdImptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdImptos] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT,@pmTarifa DECIMAL(14,4),@pmSimbTfa CHAR(1),@pmCdTarifa VARCHAR(4)
,@pmRngFecha BIT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmLtaPre CHAR(1),@pmInactivo BIT,@pmFecUpdate SMALLDATETIME,@pmTarifZfe DECIMAL(14,4)
 AS 
 INSERT INTO ProdImptos (IdProducto,IdClase,Item,Tarifa,SimbTfa,CdTarifa,TarifZfe,RngFecha,FecInicial,FecFinal,LtaPre,Inactivo,FecUpdate)
 VALUES (@pmIdProducto,@pmIdClase,@pmItem,@pmTarifa,@pmSimbTfa,@pmCdTarifa,@pmTarifZfe,@pmRngFecha,@pmFecInicial,@pmFecFinal,@pmLtaPre,@pmInactivo,@pmFecUpdate)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdInsumos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdInsumos] @pmIdProducto VARCHAR(16),@pmItem INT,@pmIdInsumo VARCHAR(16),@pmIdTipProc VARCHAR(4),@pmCantidad DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO ProdInsumos (IdProducto,Item,IdInsumo,IdTipProc,Cantidad,Inactivo)
 VALUES (@pmIdProducto,@pmItem,@pmIdInsumo,@pmIdTipProc,@pmCantidad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdMcias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdMcias] @pmIdProducto VARCHAR(16),@pmDescripProd VARCHAR(150),@pmDescripAbrv VARCHAR(50),@pmCodBarras VARCHAR(20),@pmReferencia VARCHAR(20),@pmTipoRef VARCHAR(10),@pmIdSubgrupo VARCHAR(8),@pmIdMarca VARCHAR(4),@pmColor VARCHAR(30),@pmTamano VARCHAR(30),@pmMedAlto DECIMAL(14,4)
,@pmMedAncho DECIMAL(14,4),@pmMedLargo DECIMAL(14,4),@pmMedVolm DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmIdUnd VARCHAR(4),@pmIdUndP VARCHAR(4),@pmCdUndS VARCHAR(4),@pmCdUndE VARCHAR(4),@pmCdUndEb VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmIdBodega VARCHAR(4)
,@pmIdUbic VARCHAR(10),@pmDesUbic VARCHAR(50),@pmIdProv VARCHAR(16),@pmGarProv INT,@pmGarClie INT,@pmCdDctCom VARCHAR(4),@pmVrCostAnt MONEY,@pmVrCosto MONEY,@pmVrCostPmd MONEY,@pmIdTarIva VARCHAR(4),@pmIvaInc VARCHAR(10),@pmLtPreDef CHAR(1),@pmPrecio1 MONEY,@pmPrecio2 MONEY,@pmPrecio3 MONEY,@pmPrecio4 MONEY
,@pmPrecio5 MONEY,@pmCdMon1 VARCHAR(5),@pmCdMon2 VARCHAR(5),@pmCdMon3 VARCHAR(5),@pmCdMon4 VARCHAR(5),@pmCdMon5 VARCHAR(5),@pmBaseMgn VARCHAR(10),@pmCdMgn1 VARCHAR(4),@pmCdMgn2 VARCHAR(4),@pmCdMgn3 VARCHAR(4),@pmCdMgn4 VARCHAR(4),@pmCdMgn5 VARCHAR(4),@pmCdDct1 VARCHAR(4),@pmCdDct2 VARCHAR(4)
,@pmCdDct3 VARCHAR(4),@pmCdDct4 VARCHAR(4),@pmCdDct5 VARCHAR(4),@pmCdTarIca VARCHAR(4),@pmCdTarRet VARCHAR(4),@pmExtciaMin DECIMAL(14,4),@pmExtciaMax DECIMAL(14,4),@pmExtciaAct DECIMAL(14,4),@pmFactor1 DECIMAL(14,4),@pmFactor2 DECIMAL(14,4),@pmFactor3 DECIMAL(14,4),@pmFactor4 DECIMAL(14,4),@pmFactor5 DECIMAL(14,4),@pmSeriales BIT
,@pmLotes BIT,@pmCombo BIT,@pmNoAjustes BIT,@pmTanques BIT,@pmValesComb BIT,@pmFecUltcom SMALLDATETIME,@pmFecUltVta SMALLDATETIME,@pmCodMcia VARCHAR(10),@pmDescripLong VARCHAR(250),@pmCmntarios VARCHAR(250),@pmPathFoto VARCHAR(30),@pmCantTpv DECIMAL(14,4),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTipoZonaFront VARCHAR(3),@pmExcluidoImp BIT
,@pmElectrocomb BIT,@pmIvaDetCombo BIT,@pmLtaBaseIva INT,@pmCodFEDian VARCHAR(20),@pmTallaje BIT,@pmTipoProdCo VARCHAR(10),@pmTipoIBAICU INT,@pmProcedencia INT,@pmCantAzucar DECIMAL(16,6),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO ProdMcias (IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,IdSubgrupo,IdMarca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,UndMed,IdUnd,IdUndP,CdUndS,CdUndE,CdUndEb,IdEmp,IdNat,IdMnjo,IdTmcia,IdBodega,IdUbic,DesUbic,IdProv,GarProv,GarClie,CdDctCom,VrCostAnt,VrCosto,VrCostPmd,IdTarIva,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,CdTarIca,CdTarRet,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,FecUltcom,FecUltVta,CodMcia,DescripLong,Cmntarios,PathFoto,CantTpv,IdEstado,Inactivo,FechaAdd,IdUsuario,TipoZonaFront,ExcluidoImp,Electrocomb,IvaDetCombo,LtaBaseIva,CodFEDian,Tallaje,TipoProdCo,TipoIBAICU,Procedencia,CantAzucar)
 VALUES (@pmIdProducto,@pmDescripProd,@pmDescripAbrv,@pmCodBarras,@pmReferencia,@pmTipoRef,@pmIdSubgrupo,@pmIdMarca,@pmColor,@pmTamano,@pmMedAlto,@pmMedAncho,@pmMedLargo,@pmMedVolm,@pmUndMed,@pmIdUnd,@pmIdUndP,@pmCdUndS,@pmCdUndE,@pmCdUndEb,@pmIdEmp,@pmIdNat,@pmIdMnjo,@pmIdTmcia,@pmIdBodega,@pmIdUbic,@pmDesUbic
,@pmIdProv,@pmGarProv,@pmGarClie,@pmCdDctCom,@pmVrCostAnt,@pmVrCosto,@pmVrCostPmd,@pmIdTarIva,@pmIvaInc,@pmLtPreDef,@pmPrecio1,@pmPrecio2,@pmPrecio3,@pmPrecio4,@pmPrecio5,@pmCdMon1,@pmCdMon2,@pmCdMon3,@pmCdMon4,@pmCdMon5,@pmBaseMgn,@pmCdMgn1,@pmCdMgn2,@pmCdMgn3,@pmCdMgn4,@pmCdMgn5,@pmCdDct1,@pmCdDct2,@pmCdDct3
,@pmCdDct4,@pmCdDct5,@pmCdTarIca,@pmCdTarRet,@pmExtciaMin,@pmExtciaMax,@pmExtciaAct,@pmFactor1,@pmFactor2,@pmFactor3,@pmFactor4,@pmFactor5,@pmSeriales,@pmLotes,@pmCombo,@pmNoAjustes,@pmTanques,@pmValesComb,@pmFecUltcom,@pmFecUltVta,@pmCodMcia,@pmDescripLong,@pmCmntarios,@pmPathFoto,@pmCantTpv,@pmIdEstado,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmTipoZonaFront,@pmExcluidoImp,@pmElectrocomb,@pmIvaDetCombo,@pmLtaBaseIva,@pmCodFEDian,@pmTallaje
,@pmTipoProdCo,@pmTipoIBAICU,@pmProcedencia,@pmCantAzucar)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdMcias_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsProdMcias_Sel] @pmIdProducto VARCHAR(16),@pmNewProducto VARCHAR(16)
 AS 
 INSERT INTO ProdMcias (IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,IdSubgrupo,IdMarca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,UndMed,IdUnd,IdUndP,CdUndS,CdUndE,CdUndEb,IdEmp,IdNat,IdMnjo,IdTmcia,IdBodega,IdUbic,DesUbic,IdProv,GarProv,GarClie,CdDctCom,VrCostAnt,VrCosto,VrCostPmd,IdTarIva,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,CdTarIca,CdTarRet,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,FecUltcom,FecUltVta,CodMcia,DescripLong,Cmntarios,PathFoto,CantTpv,IdEstado,Inactivo,FechaAdd,IdUsuario,TipoZonaFront,ExcluidoImp,Electrocomb,CodFEDian,Tallaje,TipoProdCo,TipoIBAICU,Procedencia,CantAzucar)
 SELECT @pmNewProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,IdSubgrupo,IdMarca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,UndMed,IdUnd,IdUndP,CdUndS,CdUndE,CdUndEb,IdEmp,IdNat,IdMnjo,IdTmcia,IdBodega,IdUbic,DesUbic,IdProv,GarProv,GarClie,CdDctCom,VrCostAnt,VrCosto,VrCostPmd,IdTarIva,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,CdTarIca,CdTarRet,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,FecUltcom,FecUltVta,CodMcia,DescripLong,Cmntarios,PathFoto,CantTpv,IdEstado,Inactivo,FechaAdd,IdUsuario,TipoZonaFront,ExcluidoImp,Electrocomb,CodFEDian,Tallaje,TipoProdCo,TipoIBAICU,Procedencia,CantAzucar
 FROM  ProdMcias WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paInsProdOrden]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipCons VARCHAR(3),@pmNumCons INT,@pmIdCiaCons CHAR(2),@pmModalidad VARCHAR(10),@pmIdTipProc VARCHAR(4),@pmIdTaller VARCHAR(4),@pmCostoTotal MONEY,@pmConPago BIT,@pmEdoOrden INT
,@pmFecEntrega SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmNitTercero VARCHAR(16),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmProcFinal BIT,@pmNum_Entrega INT,@pmCdCiaEnt CHAR(2)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_ProdOrden (TipDoc,NumOrden,IdCia,Fecha,TipCons,NumCons,IdCiaCons,Modalidad,IdTipProc,IdTaller,CostoTotal,ConPago,EdoOrden,FecEntrega,NitTercero,NomContacto,TelContacto,ProcFinal,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,Num_Entrega,CdCiaEnt)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmTipCons,@pmNumCons,@pmIdCiaCons,@pmModalidad,@pmIdTipProc,@pmIdTaller,@pmCostoTotal,@pmConPago,@pmEdoOrden,@pmFecEntrega,@pmNitTercero,@pmNomContacto,@pmTelContacto,@pmProcFinal,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNum_Entrega,@pmCdCiaEnt)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdPrecCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdPrecCom] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmNumero INT,@pmTipoTarif VARCHAR(3),@pmnMes INT,@pmnAnno INT
,@pmTarifa DECIMAL(14,4),@pmNitProv VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO ProdPrecCom (IdProducto,IdCia,Numero,TipoTarif,nMes,nAnno,Tarifa,NitProv,Inactivo)
 VALUES (@pmIdProducto,@pmIdCia,@pmNumero,@pmTipoTarif,@pmnMes,@pmnAnno,@pmTarifa,@pmNitProv,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdPrecCrudo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdPrecCrudo] @pmTipoTarif VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16),@pmIdTercero VARCHAR(16),@pmDuracion VARCHAR(10),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmTarifa DECIMAL(16,6)
,@pmIdMoneda VARCHAR(5),@pmUndMed VARCHAR(10),@pmCodCiudad VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO ProdPrecCrudo (TipoTarif,Numero,IdCia,IdProducto,IdTercero,Duracion,FecInicio,FecFinal,Tarifa,IdMoneda,UndMed,Inactivo,CodCiudad)
 VALUES (@pmTipoTarif,@pmNumero,@pmIdCia,@pmIdProducto,@pmIdTercero,@pmDuracion,@pmFecInicio,@pmFecFinal,@pmTarifa,@pmIdMoneda,@pmUndMed,@pmInactivo,@pmCodCiudad)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdPrecios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdPrecios] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmVrPrecio1 MONEY,@pmVrPrecio2 MONEY,@pmVrPrecio3 MONEY,@pmVrPrecio4 MONEY
,@pmVrPrecio5 MONEY,@pmIvaInc VARCHAR(10),@pmCdTarIva VARCHAR(4),@pmCdMoney1 VARCHAR(5),@pmCdMoney2 VARCHAR(5),@pmCdMoney3 VARCHAR(5)
,@pmCdMoney4 VARCHAR(5),@pmCdMoney5 VARCHAR(5),@pmCdMargen1 VARCHAR(4),@pmCdMargen2 VARCHAR(4),@pmCdMargen3 VARCHAR(4),@pmCdMargen4 VARCHAR(4)
,@pmCdMargen5 VARCHAR(4),@pmBaseMargen VARCHAR(10),@pmCdDcto1 VARCHAR(4),@pmCdDcto2 VARCHAR(4),@pmCdDcto3 VARCHAR(4),@pmCdDcto4 VARCHAR(4),@pmCdDcto5 VARCHAR(4)
,@pmIdUnd VARCHAR(4),@pmIdBodega VARCHAR(4)
 AS 
 INSERT INTO ProdPrecios (IdProducto,IdCia,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,IvaInc,CdTarIva,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5
,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5,IdUnd,IdBodega)
 VALUES (@pmIdProducto,@pmIdCia,@pmVrPrecio1,@pmVrPrecio2,@pmVrPrecio3,@pmVrPrecio4,@pmVrPrecio5,@pmIvaInc,@pmCdTarIva,@pmCdMoney1,@pmCdMoney2,@pmCdMoney3,@pmCdMoney4,@pmCdMoney5
,@pmCdMargen1,@pmCdMargen2,@pmCdMargen3,@pmCdMargen4,@pmCdMargen5,@pmBaseMargen,@pmCdDcto1,@pmCdDcto2,@pmCdDcto3,@pmCdDcto4,@pmCdDcto5,@pmIdUnd,@pmIdBodega)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdProcesos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdProcesos] @pmIdProducto VARCHAR(16),@pmItem INT,@pmIdTipProc VARCHAR(4),@pmCostoEst MONEY,@pmUltCosto MONEY,@pmProcFinal BIT
,@pmCostoMP BIT,@pmCDI_Adic BIT,@pmCodTarifCDI VARCHAR(4)
 AS 
 INSERT INTO ProdProcesos (IdProducto,Item,IdTipProc,CostoEst,UltCosto,ProcFinal,CostoMP,CDI_Adic,CodTarifCDI)
 VALUES (@pmIdProducto,@pmItem,@pmIdTipProc,@pmCostoEst,@pmUltCosto,@pmProcFinal,@pmCostoMP,@pmCDI_Adic,@pmCodTarifCDI)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdProvee]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsProdProvee] @pmIdProducto VARCHAR(16),@pmIdProv VARCHAR(16),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmDiasGar INT,@pmCdDct VARCHAR(4)
,@pmVrCostCom MONEY,@pmVrCostPmd MONEY,@pmRefProv VARCHAR(20),@pmDcmento INT
 AS 
 INSERT INTO ProdProvee (IdProducto,IdProv,IdCia,Fecha,DiasGar,CdDct,VrCostCom,VrCostPmd,RefProv,Dcmento)
 VALUES (@pmIdProducto,@pmIdProv,@pmIdCia,@pmFecha,@pmDiasGar,@pmCdDct,@pmVrCostCom,@pmVrCostPmd,@pmRefProv,@pmDcmento)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdSaldos] @pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4)
,@pmIdCia CHAR(2),@pmSaldoActual DECIMAL(14,4)
 AS 
 INSERT INTO ProdSaldos (IdProducto,IdBodega,IdCia,SaldoActual)
 VALUES (@pmIdProducto,@pmIdBodega,@pmIdCia,@pmSaldoActual)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdSaldoUbc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsProdSaldoUbc] @pmIdProducto VARCHAR(16),@pmIdUbic VARCHAR(10),@pmIdCia CHAR(2),@pmSaldoActual DECIMAL(14,4)
 AS 
 INSERT INTO ProdSaldoUbc (IdProducto,IdUbic,IdCia,SaldoActual)
 VALUES (@pmIdProducto,@pmIdUbic,@pmIdCia,@pmSaldoActual)
GO
/****** Object:  StoredProcedure [dbo].[paInsProdTarf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsProdTarf] @pmTipo VARCHAR(3),@pmNumero INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCdCia CHAR(2),@pmCdLinea VARCHAR(8),@pmCdGrupo VARCHAR(8),@pmCdSubgrupo VARCHAR(8),@pmCdMarca VARCHAR(4),@pmCdProducto VARCHAR(16)
,@pmTarifa DECIMAL(14,4),@pmSimbTfa CHAR(1),@pmLtaPre CHAR(1),@pmCdTarifa VARCHAR(4),@pmCdClie VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmCdVend VARCHAR(16),@pmCdCiudad VARCHAR(8),@pmCdZona VARCHAR(4),@pmCdSzona VARCHAR(4),@pmCdGruCli VARCHAR(4),@pmOtrosCrit VARCHAR(250)
,@pmAnulado BIT,@pmCodBod VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_ProdTarf (Tipo,Numero,FecInicial,FecFinal,CdCia,CdLinea,CdGrupo,CdSubgrupo,CdMarca,CdProducto,Tarifa,SimbTfa,LtaPre,CdTarifa,CdClie,CdAgencia,CdVend,CdCiudad,CdZona,CdSzona,CdGruCli,OtrosCrit,Anulado,TimeSys,IdUsuario,CodBod)
 VALUES (@pmTipo,@pmNumero,@pmFecInicial,@pmFecFinal,@pmCdCia,@pmCdLinea,@pmCdGrupo,@pmCdSubgrupo,@pmCdMarca,@pmCdProducto,@pmTarifa,@pmSimbTfa,@pmLtaPre,@pmCdTarifa,@pmCdClie,@pmCdAgencia,@pmCdVend,@pmCdCiudad,@pmCdZona,@pmCdSzona,@pmCdGruCli,@pmOtrosCrit,@pmAnulado,@pmTimeSys,@pmIdUsuario,@pmCodBod)
GO
/****** Object:  StoredProcedure [dbo].[paInsProfesiones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsProfesiones] @pmIdProf VARCHAR(4),@pmProfesion VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO Profesiones (IdProf,Profesion,Inactivo)
 VALUES (@pmIdProf,@pmProfesion,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuc] @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(100),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT,@pmSubCentro BIT,@pmVehiculo BIT,@pmCentroCosto BIT,@pmVencimiento BIT
,@pmBaseGravable BIT,@pmPorcntaje DECIMAL(10,4),@pmNaturaleza CHAR(1),@pmAjustable BIT,@pmCuentaAjuDeb VARCHAR(16),@pmCuentaAjuCre VARCHAR(16),@pmCheques BIT,@pmReferncias BIT
,@pmAgencia BIT,@pmFmtDian INT,@pmConDian INT,@pmRenDec INT,@pmCdTipDoc VARCHAR(3),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmInactivo BIT,@pmAfijos INT
,@pmListarConc VARCHAR(4),@pmReqAutorizac BIT,@pmAntProveedor BIT,@pmIdCueNiif VARCHAR(16)
 AS 
 INSERT INTO Puc (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,SubCentro,Vehiculo,CentroCosto,Vencimiento,BaseGravable,Porcntaje,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referncias
,Agencia,FmtDian,ConDian,RenDec,CdTipDoc,FechaAdd,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor,IdCueNiif)
 VALUES (@pmIdCuenta,@pmNomCuenta,@pmMayor,@pmMovimiento,@pmTercero,@pmSubCentro,@pmVehiculo,@pmCentroCosto,@pmVencimiento,@pmBaseGravable,@pmPorcntaje,@pmNaturaleza,@pmAjustable,@pmCuentaAjuDeb,@pmCuentaAjuCre
,@pmCheques,@pmReferncias,@pmAgencia,@pmFmtDian,@pmConDian,@pmRenDec,@pmCdTipDoc,@pmFechaAdd,@pmIdUsuario,@pmInactivo,@pmAfijos,@pmListarConc,@pmReqAutorizac,@pmAntProveedor,@pmIdCueNiif)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuc_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuc_Sel] @pmIdCuenta VARCHAR(16),@pmNewCuenta VARCHAR(16)
AS 
 INSERT INTO Puc (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,SubCentro,Vehiculo,CentroCosto,Vencimiento,BaseGravable,Porcntaje,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referncias
,Agencia,FmtDian,ConDian,RenDec,CdTipDoc,FechaAdd,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor,IdCueNiif)
 SELECT @pmNewCuenta,NomCuenta,Mayor,Movimiento,Tercero,SubCentro,Vehiculo,CentroCosto,Vencimiento,BaseGravable,Porcntaje,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referncias
,Agencia,FmtDian,ConDian,RenDec,CdTipDoc,FechaAdd,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor,IdCueNiif
 FROM Puc WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsPucNiif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPucNiif] @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(250),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT,@pmVehiculo BIT,@pmAgencia BIT,@pmCentroCosto BIT,@pmSubCentro BIT,@pmVencimiento BIT,@pmBaseGravable BIT,@pmTarifaPred DECIMAL(14,4),@pmNaturaleza CHAR(1),@pmAjustable BIT
,@pmCuentaAjuDeb VARCHAR(16),@pmCuentaAjuCre VARCHAR(16),@pmCheques BIT,@pmReferencias BIT,@pmCdTipDoc VARCHAR(3),@pmInactivo BIT,@pmAfijos INT,@pmListarConc VARCHAR(4),@pmReqAutorizac BIT,@pmAntProveedor BIT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO PucNiif (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referencias,CdTipDoc,FechaCrea,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor)
 VALUES (@pmIdCuenta,@pmNomCuenta,@pmMayor,@pmMovimiento,@pmTercero,@pmVehiculo,@pmAgencia,@pmCentroCosto,@pmSubCentro,@pmVencimiento,@pmBaseGravable,@pmTarifaPred,@pmNaturaleza,@pmAjustable,@pmCuentaAjuDeb,@pmCuentaAjuCre,@pmCheques,@pmReferencias,@pmCdTipDoc,@pmFechaCrea,@pmIdUsuario,@pmInactivo,@pmAfijos,@pmListarConc,@pmReqAutorizac,@pmAntProveedor)
GO
/****** Object:  StoredProcedure [dbo].[paInsPucNiif_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPucNiif_Sel] @pmIdCuenta VARCHAR(16),@pmNewCuenta VARCHAR(16)
AS 
 INSERT INTO PucNiif (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre
,Cheques,Referencias,CdTipDoc,FechaCrea,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor)
SELECT @pmNewCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre
,Cheques,Referencias,CdTipDoc,FechaCrea,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor
FROM PucNiif WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInsPuestos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPuestos] @pmIdPto VARCHAR(4),@pmPtoControl VARCHAR(100),@pmTagPuesto VARCHAR(50),@pmIdLocal VARCHAR(8)
,@pmUbicacion VARCHAR(100),@pmContacto VARCHAR(150),@pmTelefono VARCHAR(20),@pmTelMovil VARCHAR(20),@pmReferencia VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO Puestos (IdPto,PtoControl,TagPuesto,IdLocal,Ubicacion,Contacto,Telefono,TelMovil,Referencia,Inactivo)
 VALUES (@pmIdPto,@pmPtoControl,@pmTagPuesto,@pmIdLocal,@pmUbicacion,@pmContacto,@pmTelefono,@pmTelMovil,@pmReferencia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntBases]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuntBases] @pmIdProgrma INT,@pmCdSubgrupo VARCHAR(8),@pmCdProducto VARCHAR(16)
,@pmPuntos DECIMAL(14,4),@pmMonto DECIMAL(14,4)
 AS 
 INSERT INTO PuntBases (IdProgrma,CdSubgrupo,CdProducto,Puntos,Monto)
 VALUES (@pmIdProgrma,@pmCdSubgrupo,@pmCdProducto,@pmPuntos,@pmMonto)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuntFormas] @pmIdProgrma INT,@pmIdForma VARCHAR(4),@pmPuntos DECIMAL(14,4)
 AS 
 INSERT INTO PuntFormas (IdProgrma,IdForma,Puntos)
 VALUES (@pmIdProgrma,@pmIdForma,@pmPuntos)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsPuntos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmVrBase MONEY,@pmPuntFactura DECIMAL(14,4),@pmPuntExtra DECIMAL(14,4),@pmPuntRedim DECIMAL(14,4)
,@pmIdProgrma INT,@pmNumTarjeta VARCHAR(20),@pmDetalles VARCHAR(50),@pmReferncia VARCHAR(50)
 AS 
 INSERT INTO Trn_Puntos (TipDoc,Documento,IdCia,Item,Fecha,IdCliente,IdAgencia,VrBase,PuntFactura,PuntExtra,PuntRedim,IdProgrma,NumTarjeta,Detalles,Referncia)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecha,@pmIdCliente,@pmIdAgencia,@pmVrBase,@pmPuntFactura,@pmPuntExtra,@pmPuntRedim
,@pmIdProgrma,@pmNumTarjeta,@pmDetalles,@pmReferncia)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntPremios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuntPremios] @pmIdProgrma INT,@pmItem INT,@pmDescripcion VARCHAR(100)
,@pmIdProducto VARCHAR(16),@pmPuntos DECIMAL(14,4),@pmVrBono MONEY
 AS 
 INSERT INTO PuntPremios (IdProgrma,Item,Descripcion,IdProducto,Puntos,VrBono)
 VALUES (@pmIdProgrma,@pmItem,@pmDescripcion,@pmIdProducto,@pmPuntos,@pmVrBono)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntProg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuntProg] @pmIdProgrma INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmMesesInact INT,@pmMesesVcmto INT
,@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO PuntProg (IdProgrma,FecInicial,FecFinal,MesesInact,MesesVcmto,Observacion,Anulado,TimeSys,IdUsuario)
 VALUES (@pmIdProgrma,@pmFecInicial,@pmFecFinal,@pmMesesInact,@pmMesesVcmto,@pmObservacion,@pmAnulado,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsPuntTarjetas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsPuntTarjetas] @pmNumTarjeta VARCHAR(20),@pmIdClie VARCHAR(16),@pmFecha SMALLDATETIME
,@pmTotalPuntos DECIMAL(14,4),@pmPuntRedim DECIMAL(14,4),@pmFecUltCompra SMALLDATETIME
,@pmInactivo BIT,@pmFechaUpdate SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO PuntTarjetas (NumTarjeta,IdClie,Fecha,TotalPuntos,PuntRedim,FecUltCompra,Inactivo,FechaUpdate,IdUsuario)
 VALUES (@pmNumTarjeta,@pmIdClie,@pmFecha,@pmTotalPuntos,@pmPuntRedim,@pmFecUltCompra,@pmInactivo,@pmFechaUpdate,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsRadicaVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRadicaVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16)
,@pmTotalPagos MONEY,@pmTotalCobros MONEY,@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmVrDescuento MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmOrigenAdd VARCHAR(10),@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_RadicaVales (TipDoc,nRadica,IdCia,Fecha,FechaVence,IdConcepto,IdTercero,TotalPagos,TotalCobros,Referencia,CxPagar,VrDescuento,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmnRadica,@pmIdCia,@pmFecha,@pmFechaVence,@pmIdConcepto,@pmIdTercero,@pmTotalPagos,@pmTotalCobros,@pmReferencia,@pmCxPagar,@pmVrDescuento,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsRangosPeso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRangosPeso] @pmIdRango VARCHAR(4),@pmDescripRango VARCHAR(50)
,@pmValorInicial DECIMAL(14,4),@pmValorFinal DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO RangosPeso (IdRango,DescripRango,ValorInicial,ValorFinal,Inactivo)
 VALUES (@pmIdRango,@pmDescripRango,@pmValorInicial,@pmValorFinal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsRecAfavor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRecAfavor] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmVrAFavor MONEY
,@pmVrAbono MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmVrOtrosDb MONEY
 AS 
 INSERT INTO Trn_RecAfavor (TipDoc,Recibo,IdCia,Fecha,VrAFavor,VrAbono,IdCliente,IdAgencia,IdVend,VrOtrosDb)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmVrAFavor,@pmVrAbono,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmVrOtrosDb)
GO
/****** Object:  StoredProcedure [dbo].[paInsRecBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRecBuses] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCar VARCHAR(3),@pmCartulina INT,@pmIdCiaCar CHAR(2),@pmIdVehiculo VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmCentInicial INT,@pmCentFinal INT,@pmNPasajeros INT,@pmRecorridos INT,@pmValorRecibido MONEY,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorOtrosDct MONEY
,@pmValorPagMas MONEY,@pmValorNeto MONEY,@pmValorAplicado MONEY,@pmValorAnticipo MONEY,@pmValorAbono MONEY,@pmTotalProducido MONEY,@pmTotalGastos MONEY,@pmTotalAhorro MONEY,@pmTotalOtros MONEY,@pmTotalVales MONEY,@pmTotalAbono MONEY,@pmValorPasaje MONEY,@pmIdVendedor VARCHAR(16)
,@pmComision DECIMAL(14,4),@pmIdTarCom VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmIdBanco VARCHAR(4),@pmReferencia VARCHAR(20),@pmBaseIva MONEY,@pmBaseRet MONEY,@pmBaseOtr MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4)
,@pmTarifaOtr DECIMAL(14,4),@pmIdTarIva VARCHAR(4),@pmIdTarRet VARCHAR(4),@pmIdTarOtr VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdRuta VARCHAR(4),@pmIdRelevador VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_RecBuses (TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,Modalidad,TipCar,Cartulina,IdCiaCar,IdVehiculo,IdConductor,VehPropio,CentInicial,CentFinal,NPasajeros,Recorridos,ValorRecibido,ValorTotal,ValorDcto,ValorReteFte,ValorReteIva,ValorReteIca,ValorOtros,ValorOtrosDct,ValorPagMas,ValorNeto,ValorAplicado,ValorAnticipo,ValorAbono
,TotalProducido,TotalGastos,TotalAhorro,TotalOtros,TotalVales,TotalAbono,ValorPasaje,IdVendedor,Comision,IdTarCom,IdCCosto,IdCta,EnEfectivo,NumCheque,IdBanco,Referencia,BaseIva,BaseRet,BaseOtr,TarifaIva,TarifaRet,TarifaOtr,IdTarIva,IdTarRet,IdTarOtr,IdClase,IdRuta,IdRelevador,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmModalidad,@pmTipCar,@pmCartulina,@pmIdCiaCar,@pmIdVehiculo,@pmIdConductor,@pmVehPropio,@pmCentInicial,@pmCentFinal,@pmNPasajeros,@pmRecorridos,@pmValorRecibido,@pmValorTotal,@pmValorDcto,@pmValorReteFte,@pmValorReteIva,@pmValorReteIca
,@pmValorOtros,@pmValorOtrosDct,@pmValorPagMas,@pmValorNeto,@pmValorAplicado,@pmValorAnticipo,@pmValorAbono,@pmTotalProducido,@pmTotalGastos,@pmTotalAhorro,@pmTotalOtros,@pmTotalVales,@pmTotalAbono,@pmValorPasaje,@pmIdVendedor,@pmComision,@pmIdTarCom,@pmIdCCosto,@pmIdCta,@pmEnEfectivo,@pmNumCheque,@pmIdBanco,@pmReferencia,@pmBaseIva
,@pmBaseRet,@pmBaseOtr,@pmTarifaIva,@pmTarifaRet,@pmTarifaOtr,@pmIdTarIva,@pmIdTarRet,@pmIdTarOtr,@pmIdClase,@pmIdRuta,@pmIdRelevador,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsRecCheques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRecCheques] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrTotal MONEY,@pmCantidad DECIMAL(14,4)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmPlacaVehic VARCHAR(10),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_RecCheques (TipDoc,Recibo,IdCia,Fecha,IdCliente,IdAgencia,VrTotal,Cantidad,PlacaVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmIdCliente,@pmIdAgencia,@pmVrTotal,@pmCantidad,@pmPlacaVehic,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev
,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsRecFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRecFactura] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmItemDoc INT,@pmFecha SMALLDATETIME,@pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4),@pmValorAbono MONEY,@pmDevolucion MONEY,@pmDescuento MONEY
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmVehPropio BIT,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmDetalle VARCHAR(100),@pmFecPago SMALLDATETIME,@pmAplAntcpo BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_RecFactura (TipRec,Recibo,IdCia,Item,TipDoc,Documento,IdCiaDoc,ItemDoc,Fecha,IdCargo,IdClase,ValorAbono,Devolucion,Descuento,IdCliente,IdAgencia,IdVehiculo,VehPropio,IdVendedor,Comision,Detalle,FecPago,AplAntcpo,TimeSys,IdUsuario)
 VALUES (@pmTipRec,@pmRecibo,@pmIdCia,@pmItem,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmItemDoc,@pmFecha,@pmIdCargo,@pmIdClase,@pmValorAbono,@pmDevolucion,@pmDescuento,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmVehPropio,@pmIdVendedor,@pmComision
,@pmDetalle,@pmFecPago,@pmAplAntcpo,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsRecibos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFecPago SMALLDATETIME,@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY
,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrAhorro MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmVrEfectivo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarRet VARCHAR(4)
,@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmCdForma VARCHAR(4),@pmNumForma VARCHAR(20),@pmDetallePago VARCHAR(250),@pmCdBanco VARCHAR(4),@pmCdCta VARCHAR(4)
,@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrDevFact MONEY,@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Recibos (TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdCajero,IdVend,TarifaCom,CodTarCom,IdLocal,EnEfectivo
,CdForma,NumForma,DetallePago,CdBanco,CdCta,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VrReteCREE,TarifaRtc,CodTarRtc,VrDevFact,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmFecPago,@pmVrRecibido,@pmVrSubTotal,@pmVrDescuento,@pmVrRetencion,@pmVrReteICA,@pmVrReteIVA,@pmVrOtros,@pmVrOtrDcto,@pmVrAhorro,@pmVrPagosMas,@pmVrNeto,@pmVrAplicado,@pmVrAnticipo,@pmVrEfectivo,@pmBaseRet,@pmBaseIca,@pmBaseRiv,@pmTarifaRet
,@pmTarifaIca,@pmTarifaRiv,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmIdCCosto,@pmIdSubCos,@pmIdCajero,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmIdLocal,@pmEnEfectivo,@pmCdForma,@pmNumForma,@pmDetallePago,@pmCdBanco,@pmCdCta,@pmReferencia,@pmpVehiculo,@pmCdConductor,@pmTipDcm,@pmDocumento,@pmIdCiaDcm
,@pmModalidad,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmVrDevFact,@pmVrBomberil,@pmTarifaBom,@pmCodTarifBom,@pmImpAviTab,@pmTarifaAvta,@pmCodTarifAvta)
GO
/****** Object:  StoredProcedure [dbo].[paInsRecTanqueos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRecTanqueos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmDocumento VARCHAR(10)
,@pmIdTipoCom VARCHAR(4),@pmCantidad DECIMAL(14,4),@pmValorUnitario MONEY,@pmIdEstacion VARCHAR(4)
 AS 
 INSERT INTO Trn_RecTanqueos (TipDoc,Recibo,IdCia,Item,Fecha,Documento,IdTipoCom,Cantidad,ValorUnitario,IdEstacion)
 VALUES (@pmTipDoc,@pmRecibo,@pmIdCia,@pmItem,@pmFecha,@pmDocumento,@pmIdTipoCom,@pmCantidad,@pmValorUnitario,@pmIdEstacion)
GO
/****** Object:  StoredProcedure [dbo].[paInsRegimenDian]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRegimenDian] @pmIdRegimen VARCHAR(4),@pmRegimen VARCHAR(50),@pmCodFiscal VARCHAR(20),@pmInactivo BIT
 AS 
 INSERT INTO RegimenDian (IdRegimen,Regimen,CodFiscal,Inactivo)
 VALUES (@pmIdRegimen,@pmRegimen,@pmCodFiscal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsRegistro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRegistro] @pmIdCia CHAR(2),@pmIdEmpresa VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmDvNit CHAR(1),@pmRazonSocial VARCHAR(250)
,@pmDescripcion VARCHAR(250),@pmDireccion VARCHAR(250),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmIdLocal VARCHAR(8),@pmIdPais VARCHAR(8)
,@pme_mail VARCHAR(100),@pmArchivoLogo VARCHAR(30),@pmNumeroSerial VARCHAR(80),@pmRegimen VARCHAR(50),@pmLicencia VARCHAR(20),@pmVigenciaLic SMALLDATETIME
,@pmPersoneria VARCHAR(40),@pmLeyenda VARCHAR(250),@pmFechaRegistro SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmCurrtyDate SMALLDATETIME
,@pmTipoId CHAR(1),@pmNitRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150),@pmTipoPersna CHAR(1),@pmCIIUDane VARCHAR(8),@pmCurDate1 SMALLDATETIME,@pmFechaPrest SMALLDATETIME
 AS 
 INSERT INTO adm_Registro (IdCia,IdEmpresa,NitEmpresa,DvNit,RazonSocial,Descripcion,Direccion,Telefono,Fax,IdLocal,IdPais,e_mail,ArchivoLogo,NumeroSerial,Regimen,Licencia,VigenciaLic
,Personeria,Leyenda,FechaRegistro,FechaVence,CurrtyDate,TipoId,NitRepLegal,RepLegal,TipoPersna,CIIUDane,CurDate1,FechaPrest)
 VALUES (@pmIdCia,@pmIdEmpresa,@pmNitEmpresa,@pmDvNit,@pmRazonSocial,@pmDescripcion,@pmDireccion,@pmTelefono,@pmFax,@pmIdLocal,@pmIdPais,@pme_mail,@pmArchivoLogo
,@pmNumeroSerial,@pmRegimen,@pmLicencia,@pmVigenciaLic,@pmPersoneria,@pmLeyenda,@pmFechaRegistro,@pmFechaVence,@pmCurrtyDate,@pmTipoId,@pmNitRepLegal,@pmRepLegal,@pmTipoPersna,@pmCIIUDane,@pmCurDate1,@pmFechaPrest)
GO
/****** Object:  StoredProcedure [dbo].[paInsRelaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRelaciones] @pmIdTabla VARCHAR(20),@pmTablaForanea VARCHAR(20),@pmCampoForaneo VARCHAR(20)
,@pmBasedeDatos VARCHAR(10),@pmNoValidar BIT
 AS 
 INSERT INTO Sys_Relaciones (IdTabla,TablaForanea,CampoForaneo,BasedeDatos,NoValidar)
 VALUES (@pmIdTabla,@pmTablaForanea,@pmCampoForaneo,@pmBasedeDatos,@pmNoValidar)
GO
/****** Object:  StoredProcedure [dbo].[paInsRemision]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRemision] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaDesp SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmUnidades DECIMAL(14,4),@pmIdVend VARCHAR(16)
,@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(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),@pmMulPlazos BIT, @pmIdPlazo VARCHAR(4), @pmCdRuta VARCHAR(4)
,@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmDetalleEnvio VARCHAR(250),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmTipPed VARCHAR(3)
,@pmPedido INT,@pmIdCiaPed CHAR(2),@pmFechaPed SMALLDATETIME,@pmNumAutoriza INT,@pmModalidad VARCHAR(10),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Remision (TipDoc,Remision,IdCia,Fecha,FechaDesp,FechaVence,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,Unidades,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac
,IdForma,DetallePago,MulPlazos, IdPlazo, CdRuta,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,DetalleEnvio,TipFac,Factura,IdCiaFac,FechaFact,TipPed,Pedido,IdCiaPed,FechaPed,NumAutoriza,Modalidad,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,NumAprob,FecAprob,CdUsuAprob,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmRemision,@pmIdCia,@pmFecha,@pmFechaDesp,@pmFechaVence,@pmIdConcepto,@pmIdCliente,@pmIdAgencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrFletes,@pmVrOtros,@pmVrOtrDcto,@pmVrNeto,@pmCantidad,@pmUnidades,@pmIdVend,@pmTarifaCom,@pmCodTarCom
,@pmDirEnvio,@pmIdLocEnv,@pmDiasEntraga,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargoContac,@pmIdForma,@pmDetallePago,@pmMulPlazos,@pmIdPlazo,@pmCdRuta,@pmNitEmpTrans,@pmEmpTrans,@pmpVehiculo,@pmCdConductor,@pmDetalleEnvio,@pmTipFac,@pmFactura,@pmIdCiaFac
,@pmFechaFact,@pmTipPed,@pmPedido,@pmIdCiaPed,@pmFechaPed,@pmNumAutoriza,@pmModalidad,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmNumAprob,@pmFecAprob,@pmCdUsuAprob,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsReport]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsReport] @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT
,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50),@pmNomRep VARCHAR(50)
 AS 
 INSERT INTO Sys_Report (TipoRep,IdRep,Descripcion,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location,NomRep)
 VALUES (@pmTipoRep,@pmIdRep,@pmDescripcion,@pmFormato,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmsp_Nombre,@pmInd_Location,@pmNomRep)
GO
/****** Object:  StoredProcedure [dbo].[paInsReportFmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsReportFmto] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmTipoOrigen VARCHAR(10),@pmCrVersion INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 INSERT INTO Sys_ReportFmto (TipoRep,Formato,TipoOrigen,CrVersion,sp_Nombre,Ind_Location)
 VALUES (@pmTipoRep,@pmFormato,@pmTipoOrigen,@pmCrVersion,@pmsp_Nombre,@pmInd_Location)
GO
/****** Object:  StoredProcedure [dbo].[paInsReportSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsReportSub] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmNombreSub VARCHAR(20),@pmTipoOrigen VARCHAR(10),@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 INSERT INTO Sys_ReportSub (TipoRep,Formato,NombreSub,TipoOrigen,sp_Nombre,Ind_Location)
 VALUES (@pmTipoRep,@pmFormato,@pmNombreSub,@pmTipoOrigen,@pmsp_Nombre,@pmInd_Location)
GO
/****** Object:  StoredProcedure [dbo].[paInsReportSubPmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsReportSubPmt] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmNombreSub VARCHAR(20),@pmIndParam INT,@pmNomParam VARCHAR(30),@pmTipoDato VARCHAR(15),@pmValorPred VARCHAR(100)
 AS 
 INSERT INTO Sys_ReportSubPmt (TipoRep,Formato,NombreSub,IndParam,NomParam,TipoDato,ValorPred)
 VALUES (@pmTipoRep,@pmFormato,@pmNombreSub,@pmIndParam,@pmNomParam,@pmTipoDato,@pmValorPred)
GO
/****** Object:  StoredProcedure [dbo].[paInsReqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsReqDetalle] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2),@pmItem INT,@pmCdProducto VARCHAR(16),@pmDescripcion VARCHAR(250),@pmIdSubgrupo VARCHAR(8)
,@pmCdBodega VARCHAR(4),@pmCantidad DECIMAL(14,4),@pmIdUnd VARCHAR(4),@pmVrUnitario MONEY,@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmTipSal VARCHAR(3),@pmNSalida INT,@pmIdCiaSal CHAR(2),@pmFechaSal SMALLDATETIME,@pmReferencia VARCHAR(250),@pmCantSalida DECIMAL(14,4),@pmCantDevSal DECIMAL(14,4)
,@pmCodCCtoDet VARCHAR(16),@pmCodSCtoDet VARCHAR(16),@pmPlacaVehDet VARCHAR(10),@pmCant_Orden DECIMAL(14,4)
AS 
 INSERT INTO Trn_ReqDetalle (TipDoc,Requisicion,IdCia,Item,CdProducto,Descripcion,IdSubgrupo,CdBodega,Cantidad,IdUnd,VrUnitario,TipOrd,NumOrden,IdCiaOrd,TipSal,NSalida,IdCiaSal,FechaSal
,Referencia,CantSalida,CantDevSal,CodCCtoDet,CodSCtoDet,PlacaVehDet,Cant_Orden)
 VALUES (@pmTipDoc,@pmRequisicion,@pmIdCia,@pmItem,@pmCdProducto,@pmDescripcion,@pmIdSubgrupo,@pmCdBodega,@pmCantidad,@pmIdUnd,@pmVrUnitario,@pmTipOrd
,@pmNumOrden,@pmIdCiaOrd,@pmTipSal,@pmNSalida,@pmIdCiaSal,@pmFechaSal,@pmReferencia,@pmCantSalida,@pmCantDevSal,@pmCodCCtoDet,@pmCodSCtoDet,@pmPlacaVehDet,@pmCant_Orden)
GO
/****** Object:  StoredProcedure [dbo].[paInsRequisicion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRequisicion] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdRespons VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdDep VARCHAR(4),@pmVrSubTotal MONEY,@pmCantidad DECIMAL(14,4)
,@pmNContrato INT,@pmIdCiaCont CHAR(2),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmModalidad VARCHAR(10),@pmDirEntrega VARCHAR(250),@pmIdLocEnt VARCHAR(8),@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2),@pmFechaSal SMALLDATETIME,@pmNumAprob INT,@pmFecAprob SMALLDATETIME
,@pmCdUsuAprob VARCHAR(11),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(50),@pmEmailContacto VARCHAR(100),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmNum_Vehic VARCHAR(10),@pmNum_Trailer VARCHAR(10),@pmTipoVigencia VARCHAR(10),@pmNivelAprob INT
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Requisicion (TipDoc,Requisicion,IdCia,Fecha,FechaVence,IdConcepto,IdRespons,IdCCosto,IdSubCos,IdDep,VrSubTotal,Cantidad,NContrato,IdCiaCont,NitCliente,CdAgencia,Modalidad,DirEntrega,IdLocEnt,TipSal,NumSalida,IdCiaSal,FechaSal,NumAprob,FecAprob,CdUsuAprob,NomContacto,TelsContacto,EmailContacto
,Num_Vehic,Num_Trailer,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,TipoVigencia,NivelAprob)
 VALUES (@pmTipDoc,@pmRequisicion,@pmIdCia,@pmFecha,@pmFechaVence,@pmIdConcepto,@pmIdRespons,@pmIdCCosto,@pmIdSubCos,@pmIdDep,@pmVrSubTotal,@pmCantidad,@pmNContrato,@pmIdCiaCont,@pmNitCliente,@pmCdAgencia,@pmModalidad,@pmDirEntrega,@pmIdLocEnt,@pmTipSal,@pmNumSalida,@pmIdCiaSal
,@pmFechaSal,@pmNumAprob,@pmFecAprob,@pmCdUsuAprob,@pmNomContacto,@pmTelsContacto,@pmEmailContacto,@pmNum_Vehic,@pmNum_Trailer,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoVigencia,@pmNivelAprob)
GO
/****** Object:  StoredProcedure [dbo].[paInsResiduosPeligrosos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsResiduosPeligrosos] @pmCodigoUN VARCHAR(30),@pmDesignacion VARCHAR(500),@pmClase VARCHAR(10),@pmPeligroSec VARCHAR(10),@pmGrupoEmb VARCHAR(20),@pmIdCoRes VARCHAR(8),@pmIdCRdes VARCHAR(8),@pmInactivo BIT
 AS 
 INSERT INTO ResiduosPeligrosos (CodigoUN,Designacion,Clase,PeligroSec,GrupoEmb,IdCoRes,IdCRdes,Inactivo)
 VALUES (@pmCodigoUN,@pmDesignacion,@pmClase,@pmPeligroSec,@pmGrupoEmb,@pmIdCoRes,@pmIdCRdes,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsRoles]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRoles] @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmFuncion VARCHAR(100)
 AS 
 INSERT INTO Sys_Roles (IdObj,IdRole,Funcion)
 VALUES (@pmIdObj,@pmIdRole,@pmFuncion)
GO
/****** Object:  StoredProcedure [dbo].[paInsRutas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRutas] @pmIdRuta VARCHAR(4),@pmRuta VARCHAR(100),@pmIdLocOri VARCHAR(8),@pmIdLocDes VARCHAR(8)
,@pmEsLocal BIT,@pmDistkmt DECIMAL(14,4),@pmTmHoras VARCHAR(8),@pmCodigoMt VARCHAR(5)
,@pmFleteTon MONEY,@pmCdCiaTurno CHAR(2),@pmPuntosRut DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO Rutas (IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,Inactivo,CdCiaTurno,PuntosRut)
 VALUES (@pmIdRuta,@pmRuta,@pmIdLocOri,@pmIdLocDes,@pmEsLocal,@pmDistkmt,@pmTmHoras,@pmCodigoMt,@pmFleteTon,@pmInactivo,@pmCdCiaTurno,@pmPuntosRut)
GO
/****** Object:  StoredProcedure [dbo].[paInsRutasPlan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsRutasPlan] @pmIdRuta VARCHAR(4),@pmIdPunto INT,@pmDescripcion VARCHAR(100),@pmDistancia DECIMAL(14,4)
,@pmTiempo VARCHAR(8),@pmClasePto VARCHAR(10),@pmCdPto VARCHAR(4),@pmIdLocal VARCHAR(8),@pmPosLat DECIMAL(14,4),@pmPosLon DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO RutasPlan (IdRuta,IdPunto,Descripcion,Distancia,Tiempo,ClasePto,CdPto,IdLocal,PosLat,PosLon,Inactivo)
 VALUES (@pmIdRuta,@pmIdPunto,@pmDescripcion,@pmDistancia,@pmTiempo,@pmClasePto,@pmCdPto,@pmIdLocal,@pmPosLat,@pmPosLon,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsRutasTramos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsRutasTramos] @pmIdRuta VARCHAR(4),@pmNumTramo INT,@pmIdLocal VARCHAR(8),@pmkmstramo DECIMAL(14,4),@pmkmstotal DECIMAL(14,4)
 AS 
 INSERT INTO RutasTramos (IdRuta,NumTramo,IdLocal,kmstramo,kmstotal)
 VALUES (@pmIdRuta,@pmNumTramo,@pmIdLocal,@pmkmstramo,@pmkmstotal)
GO
/****** Object:  StoredProcedure [dbo].[paInsSaiArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSaiArticulos] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipEnt VARCHAR(3)
,@pmEntrada INT,@pmIdCiaEnt CHAR(2),@pmItemEnt INT,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY
 AS 
 INSERT INTO Trn_SaiArticulos (TipDoc,Salida,IdCia,Item,TipEnt,Entrada,IdCiaEnt,ItemEnt,IdProducto,IdBodega,Cantidad,VrUnitario)
 VALUES (@pmTipDoc,@pmSalida,@pmIdCia,@pmItem,@pmTipEnt,@pmEntrada,@pmIdCiaEnt,@pmItemEnt,@pmIdProducto,@pmIdBodega,@pmCantidad,@pmVrUnitario)
GO
/****** Object:  StoredProcedure [dbo].[paInsSalidas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSalidas] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16)
,@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmBaseImp MONEY,@pmTarifaIva DECIMAL(14,4),@pmCodTarIva VARCHAR(4)
,@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmModalidad VARCHAR(10)
,@pmCdConductor VARCHAR(16),@pmCdDep VARCHAR(4),@pmNContrato INT,@pmIdCiaCont CHAR(2),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmModRequis VARCHAR(10)
,@pmDirEntrega VARCHAR(250),@pmIdLocEnt VARCHAR(8),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmGuiaComb INT,@pmCdCiaGuia CHAR(2),@pmNumDotac INT,@pmDiaVigDot INT,@pmFecVigDot SMALLDATETIME,@pmEdoDocEnt INT,@pmNumDocEnt INT,@pmCiaDocEnt CHAR(2)
,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Salidas (TipDoc,Salida,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,TarifaIva,CodTarIva,TipOrd,NumOrden,IdCiaOrd,IdCCosto,IdSubCos
,pVehiculo,CdConductor,CdDep,NContrato,IdCiaCont ,NitCliente,CdAgencia,ModRequis,DirEntrega,IdLocEnt,GuiaComb,CdCiaGuia
,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,NumDotac,DiaVigDot,FecVigDot,EdoDocEnt,NumDocEnt,CiaDocEnt,VrImpuBA,VrImpuCUP)
 VALUES (@pmTipDoc,@pmSalida,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdTercero,@pmVrSubTotal,@pmVrImpuesto,@pmVrCostos,@pmVrNeto,@pmCantidad,@pmBaseImp,@pmTarifaIva
,@pmCodTarIva,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmIdCCosto,@pmIdSubCos,@pmpVehiculo
,@pmCdConductor,@pmCdDep,@pmNContrato,@pmIdCiaCont,@pmNitCliente,@pmCdAgencia,@pmModRequis,@pmDirEntrega,@pmIdLocEnt,@pmGuiaComb,@pmCdCiaGuia
,@pmModalidad,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado
,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumDotac,@pmDiaVigDot,@pmFecVigDot,@pmEdoDocEnt,@pmNumDocEnt,@pmCiaDocEnt,@pmVrImpuBA,@pmVrImpuCUP)
GO
/****** Object:  StoredProcedure [dbo].[paInsSAutoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSAutoriza] @pmIdConcepto VARCHAR(4),@pmConceptoAut VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO Sys_Autoriza (IdConcepto,ConceptoAut,Inactivo)
 VALUES (@pmIdConcepto,@pmConceptoAut,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsSectoresEco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSectoresEco] @pmIdSector VARCHAR(8),@pmSectorEco VARCHAR(250),@pmCdTarifRtc VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO SectoresEco (IdSector,SectorEco,Inactivo,CdTarifRtc)
 VALUES (@pmIdSector,@pmSectorEco,@pmInactivo,@pmCdTarifRtc)
GO
/****** Object:  StoredProcedure [dbo].[paInsSecurity]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSecurity] @pmIdLla INT,@pmDescripcion VARCHAR(50),@pmPwd VARCHAR(10)
 AS 
 INSERT INTO Sys_Security (IdLla,Descripcion,Pwd)
 VALUES (@pmIdLla,@pmDescripcion,@pmPwd)
GO
/****** Object:  StoredProcedure [dbo].[paInsSeriales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsSeriales] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4),@pmCdUbic VARCHAR(10),@pmFecEntrada SMALLDATETIME
,@pmFecSalida SMALLDATETIME,@pmNitProv VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmObservacion VARCHAR(250),@pmReferncia1 VARCHAR(50),@pmReferncia2 VARCHAR(50)
,@pmFecRef1 SMALLDATETIME,@pmFecRef2 SMALLDATETIME,@pmUbicacion VARCHAR(50),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Seriales (IdProducto,NumSerial,IdCia,IdBodega,CdUbic,FecEntrada,FecSalida,NitProv,IdEstado,Inactivo,Observacion,Referncia1,Referncia2,FecRef1,FecRef2,Ubicacion,IdUsuario)
 VALUES (@pmIdProducto,@pmNumSerial,@pmIdCia,@pmIdBodega,@pmCdUbic,@pmFecEntrada,@pmFecSalida,@pmNitProv,@pmIdEstado,@pmInactivo,@pmObservacion,@pmReferncia1,@pmReferncia2
,@pmFecRef1,@pmFecRef2,@pmUbicacion,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsSerMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSerMov] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30)
,@pmIdBodega VARCHAR(4),@pmCdUbic VARCHAR(10),@pmLinea INT,@pmMovimiento VARCHAR(3),@pmFecha SMALLDATETIME,@pmObservacion VARCHAR(150),@pmReferencia VARCHAR(50)
 AS 
 INSERT INTO Trn_SerMov (TipDoc,Documento,IdCia,Item,IdProducto,NumSerial,IdBodega,CdUbic,Linea,Movimiento,Fecha,Observacion,Referencia)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmIdProducto,@pmNumSerial,@pmIdBodega,@pmCdUbic,@pmLinea,@pmMovimiento,@pmFecha,@pmObservacion,@pmReferencia)
GO
/****** Object:  StoredProcedure [dbo].[paInsSobDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSobDetalle] @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmItem INT,@pmConcepto VARCHAR(250)
,@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrBase MONEY,@pmTarifa DECIMAL(14,4),@pmVrLiquida MONEY
,@pmVrPrecio MONEY,@pmClaseProd VARCHAR(20),@pmTarifGalon DECIMAL(14,4),@pmPorcBase DECIMAL(14,4),@pmPorcAch DECIMAL(14,4) 
 AS 
 INSERT INTO Trn_SobDetalle (IdDec,NumDeclara,Item,Concepto,Cantidad,VrUnitario,VrBase,Tarifa,VrLiquida,VrPrecio,ClaseProd,TarifGalon,PorcBase,PorcAch)
 VALUES (@pmIdDec,@pmNumDeclara,@pmItem,@pmConcepto,@pmCantidad,@pmVrUnitario,@pmVrBase,@pmTarifa
,@pmVrLiquida,@pmVrPrecio,@pmClaseProd,@pmTarifGalon,@pmPorcBase,@pmPorcAch)
GO
/****** Object:  StoredProcedure [dbo].[paInsSobEntidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSobEntidades] @pmIdEnterr VARCHAR(8),@pmTipoEnterr VARCHAR(10),@pmNitEntidad VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1)
,@pmDirOficina VARCHAR(250),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmSitioWeb VARCHAR(100),@pme_mail VARCHAR(100)
,@pmCedRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150),@pmFormaPago VARCHAR(10),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30)
,@pmIdBanco VARCHAR(4),@pmCdLocCue VARCHAR(8),@pmCargoRep VARCHAR(50),@pmNomTitular VARCHAR(150),@pmNomEntidad VARCHAR(50),@pmInactivo BIT
,@pmCodCtaPag VARCHAR(4)
 AS 
 INSERT INTO SobEntidades (IdEnterr,TipoEnterr,NitEntidad,TipoId,Dv,DirOficina,Telefono,Fax,SitioWeb,e_mail,CedRepLegal,RepLegal,CargoRep,FormaPago,IdClase,NumCuenta,NomTitular,IdBanco,CdLocCue,NomEntidad,Inactivo,CodCtaPag)
 VALUES (@pmIdEnterr,@pmTipoEnterr,@pmNitEntidad,@pmTipoId,@pmDv,@pmDirOficina,@pmTelefono,@pmFax,@pmSitioWeb,@pme_mail,@pmCedRepLegal,@pmRepLegal,@pmCargoRep,@pmFormaPago
,@pmIdClase,@pmNumCuenta,@pmNomTitular,@pmIdBanco,@pmCdLocCue,@pmNomEntidad,@pmInactivo,@pmCodCtaPag)
GO
/****** Object:  StoredProcedure [dbo].[paInsSobProductos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsSobProductos] @pmIdClase INT,@pmIdProducto VARCHAR(16),@pmClaseProd VARCHAR(20)
 AS 
 INSERT INTO SobProductos (IdClase,IdProducto,ClaseProd)
 VALUES (@pmIdClase,@pmIdProducto,@pmClaseProd)
GO
/****** Object:  StoredProcedure [dbo].[paInsSobretasas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSobretasas] @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmFecha SMALLDATETIME,@pmnAnno INT,@pmnMes INT,@pmIdEnterr VARCHAR(8),@pmTipoEntidad VARCHAR(10),@pmVrSobretasa MONEY,@pmVrSanciones MONEY,@pmVrCompensa MONEY,@pmVrIntMora MONEY
,@pmVrTotalPagar MONEY,@pmVrFondoSubs MONEY,@pmVrRecaudoDep MONEY,@pmNitDeclara VARCHAR(16),@pmDvDeclara CHAR(1),@pmCedDeclara VARCHAR(16),@pmDeclarante VARCHAR(250),@pmDirEntidad VARCHAR(250),@pmEmailEnt VARCHAR(100),@pmNomRepres VARCHAR(150)
,@pmCargoRepres VARCHAR(50),@pmTipoFirma INT,@pmNitRevisor VARCHAR(16),@pmNomRevisor VARCHAR(150),@pmTpRevisor VARCHAR(20),@pmNumCheque VARCHAR(30),@pmCodBanco VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4)
,@pmCdLocCue VARCHAR(8),@pmTitularCuenta VARCHAR(150),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTransf MONEY,@pmVrPagado MONEY,@pmEstado INT,@pmAdhesivo VARCHAR(30),@pmFechaPago SMALLDATETIME,@pmEsCorr BIT,@pmNumCorr VARCHAR(30),@pmFecCorr SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmCodCta VARCHAR(4),@pmTipEgreso VARCHAR(3),@pmNumEgreso INT,@pmCiaEgreso CHAR(2)
 AS 
 INSERT INTO Trn_Sobretasas (IdDec,NumDeclara,Fecha,nAnno,nMes,IdEnterr,TipoEntidad,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrFondoSubs,VrRecaudoDep,NitDeclara,DvDeclara,CedDeclara,Declarante,DirEntidad,EmailEnt,NomRepres,CargoRepres,TipoFirma,NitRevisor
,NomRevisor,TpRevisor,NumCheque,CodBanco,IdClase,NumCuenta,IdBanco,CdLocCue,TitularCuenta,VrEfectivo,VrOtros,VrTransf,VrPagado,Estado,Adhesivo,FechaPago,EsCorr,NumCorr,FecCorr,Observacion,TimeSys,IdUsuario,CodCta,TipEgreso,NumEgreso,CiaEgreso)
 VALUES (@pmIdDec,@pmNumDeclara,@pmFecha,@pmnAnno,@pmnMes,@pmIdEnterr,@pmTipoEntidad,@pmVrSobretasa,@pmVrSanciones,@pmVrCompensa,@pmVrIntMora,@pmVrTotalPagar,@pmVrFondoSubs,@pmVrRecaudoDep,@pmNitDeclara,@pmDvDeclara,@pmCedDeclara,@pmDeclarante
,@pmDirEntidad,@pmEmailEnt,@pmNomRepres,@pmCargoRepres,@pmTipoFirma,@pmNitRevisor,@pmNomRevisor,@pmTpRevisor,@pmNumCheque,@pmCodBanco,@pmIdClase,@pmNumCuenta,@pmIdBanco,@pmCdLocCue,@pmTitularCuenta,@pmVrEfectivo,@pmVrOtros,@pmVrTransf,@pmVrPagado
,@pmEstado,@pmAdhesivo,@pmFechaPago,@pmEsCorr,@pmNumCorr,@pmFecCorr,@pmObservacion,@pmTimeSys,@pmIdUsuario,@pmCodCta,@pmTipEgreso,@pmNumEgreso,@pmCiaEgreso)
GO
/****** Object:  StoredProcedure [dbo].[paInsSobTiposDec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSobTiposDec] @pmIdDec VARCHAR(4),@pmDeclaracion VARCHAR(100),@pmTipoDec VARCHAR(20),@pmNitDec VARCHAR(16),@pmTipoIdDec CHAR(1)
,@pmNombreDec VARCHAR(250),@pmDvDec CHAR(1),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmCedRepLegal VARCHAR(16)
,@pmRepLegal VARCHAR(150),@pmTipoFirma INT,@pmNitRevisor VARCHAR(16),@pmNomRevisor VARCHAR(150),@pmTpRevisor VARCHAR(20),@pmTarifSubsidio DECIMAL(14,4),@pmConsecutivo INT
 AS 
 INSERT INTO SobTiposDec (IdDec,Declaracion,TipoDec,NitDec,TipoIdDec,NombreDec,DvDec,Direccion,IdLocal,Telefono,CedRepLegal,RepLegal,TipoFirma,NitRevisor,NomRevisor,TpRevisor,TarifSubsidio,Consecutivo)
 VALUES (@pmIdDec,@pmDeclaracion,@pmTipoDec,@pmNitDec,@pmTipoIdDec,@pmNombreDec,@pmDvDec,@pmDireccion,@pmIdLocal,@pmTelefono,@pmCedRepLegal,@pmRepLegal
,@pmTipoFirma,@pmNitRevisor,@pmNomRevisor,@pmTpRevisor,@pmTarifSubsidio,@pmConsecutivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsSubCentros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSubCentros] @pmIdSubCos VARCHAR(16),@pmSubCosto VARCHAR(100),@pmIdCCosto VARCHAR(16),@pmFecAdd SMALLDATETIME,@pmInactivo BIT
 AS 
 INSERT INTO SubCentros (IdSubCos,SubCosto,IdCCosto,FecAdd,Inactivo)
 VALUES (@pmIdSubCos,@pmSubCosto,@pmIdCCosto,@pmFecAdd,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsSubGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSubGrupos] @pmIdSubgrupo VARCHAR(8),@pmSubgrupo VARCHAR(150),@pmIdGrupo VARCHAR(8)
,@pmCdTarIva VARCHAR(4),@pmCdTarAut VARCHAR(4),@pmCdTarRet VARCHAR(4),@pmCdTarIca VARCHAR(4)
,@pmTipoInvent VARCHAR(10),@pmCdTarifImv VARCHAR(4),@pmCdTarifIco VARCHAR(4),@pmCdTarIvp VARCHAR(4),@pmCdTarifIcu VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO SubGrupos (IdSubgrupo,Subgrupo,IdGrupo,CdTarIva,CdTarAut,CdTarRet,CdTarIca,TipoInvent,Inactivo,CdTarifImv,CdTarifIco,CdTarIvp,CdTarifIcu)
 VALUES (@pmIdSubgrupo,@pmSubgrupo,@pmIdGrupo,@pmCdTarIva,@pmCdTarAut,@pmCdTarRet,@pmCdTarIca,@pmTipoInvent,@pmInactivo,@pmCdTarifImv,@pmCdTarifIco,@pmCdTarIvp,@pmCdTarifIcu)
GO
/****** Object:  StoredProcedure [dbo].[paInsSubGruposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsSubGruposAgenc] @pmIdSubAgenc VARCHAR(4),@pmSubGrupoAgenc VARCHAR(50),@pmIdGrupo VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO SubGruposAgenc (IdSubAgenc,SubGrupoAgenc,IdGrupo,Inactivo)
 VALUES (@pmIdSubAgenc,@pmSubGrupoAgenc,@pmIdGrupo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsSubgruposCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsSubgruposCue] @pmIdSubgrupo VARCHAR(8),@pmIdClase VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmCdCueDev VARCHAR(16)
,@pmCdCueCom VARCHAR(16),@pmCdCueCdv VARCHAR(16),@pmFecAdd SMALLDATETIME
 AS 
 INSERT INTO SubgruposCue (IdSubgrupo,IdClase,IdCuenta,CdCueDev,CdCueCom,CdCueCdv,FecAdd)
 VALUES (@pmIdSubgrupo,@pmIdClase,@pmIdCuenta,@pmCdCueDev,@pmCdCueCom,@pmCdCueCdv,@pmFecAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsSubzonas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsSubzonas] @pmIdSzona VARCHAR(4),@pmSubzona VARCHAR(50),@pmIdZona VARCHAR(4),@pmCdRuta VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO Subzonas (IdSzona,Subzona,IdZona,Inactivo,Cd_Rut)
 VALUES (@pmIdSzona,@pmSubzona,@pmIdZona,@pmInactivo,@pmCdRuta)
GO
/****** Object:  StoredProcedure [dbo].[paInsTablapor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTablapor] @pmIdTarifa VARCHAR(4),@pmDescripcion VARCHAR(50),@pmIdClase VARCHAR(4),@pmTarifa DECIMAL(16,6)
,@pmSimbolo CHAR(1),@pmCdLocdad VARCHAR(8),@pmMinimo MONEY,@pmMaximo MONEY,@pmInactivo BIT
 AS 
 INSERT INTO Tablapor (IdTarifa,Descripcion,IdClase,Tarifa,Simbolo,CdLocdad,Minimo,Maximo,Inactivo)
 VALUES (@pmIdTarifa,@pmDescripcion,@pmIdClase,@pmTarifa,@pmSimbolo,@pmCdLocdad,@pmMinimo,@pmMaximo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTalleres]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTalleres] @pmIdTaller VARCHAR(4),@pmNomTaller VARCHAR(100),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(30),@pmTelCelular VARCHAR(30),@pmNitTercero VARCHAR(16),@pmTipoTaller VARCHAR(20),@pmInactivo BIT
 AS 
 INSERT INTO Talleres (IdTaller,NomTaller,Direccion,IdLocal,Telefono,TelCelular,NitTercero,TipoTaller,Inactivo)
 VALUES (@pmIdTaller,@pmNomTaller,@pmDireccion,@pmIdLocal,@pmTelefono,@pmTelCelular,@pmNitTercero,@pmTipoTaller,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqAforo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTanqAforo] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4),@pmCantidad DECIMAL(14,4)
 AS 
 INSERT INTO TanqAforo (IdTanque,UndAforo,Cantidad)
 VALUES (@pmIdTanque,@pmUndAforo,@pmCantidad)
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqAforoFrac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTanqAforoFrac] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4),@pmFraccion DECIMAL(14,4),@pmMilimetros DECIMAL(14,4)
 AS 
 INSERT INTO TanqAforoFrac (IdTanque,UndAforo,Fraccion,Milimetros)
 VALUES (@pmIdTanque,@pmUndAforo,@pmFraccion,@pmMilimetros)
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqDispens]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTanqDispens] @pmIdMngra VARCHAR(10),@pmNumDisp VARCHAR(4),@pmNumPos VARCHAR(4),@pmNumMngra VARCHAR(4),@pmIdTanque VARCHAR(4),@pmDescripcion VARCHAR(50)
,@pmLecGalAnt DECIMAL(14,4),@pmLecGalUlt DECIMAL(14,4),@pmLecPesAnt MONEY,@pmLecPesUlt MONEY,@pmLtaPrec CHAR(1),@pmFechaAdd SMALLDATETIME,@pmInactivo BIT,@pmLecGalMax DECIMAL(14,4)
 AS 
 INSERT INTO TanqDispens (IdMngra,NumDisp,NumPos,NumMngra,IdTanque,Descripcion,LecGalAnt,LecGalUlt,LecPesAnt,LecPesUlt,LtaPrec,FechaAdd,Inactivo,LecGalMax)
 VALUES (@pmIdMngra,@pmNumDisp,@pmNumPos,@pmNumMngra,@pmIdTanque,@pmDescripcion,@pmLecGalAnt,@pmLecGalUlt,@pmLecPesAnt,@pmLecPesUlt,@pmLtaPrec,@pmFechaAdd,@pmInactivo,@pmLecGalMax)
GO
/****** Object:  StoredProcedure [dbo].[paInsTanqSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTanqSaldos] @pmIdTanque VARCHAR(4),@pmIdCia CHAR(2),@pmSaldoActual DECIMAL(14,4)
 AS 
 INSERT INTO TanqSaldos (IdTanque,IdCia,SaldoActual)
 VALUES (@pmIdTanque,@pmIdCia,@pmSaldoActual)
GO
/****** Object:  StoredProcedure [dbo].[paInsTanques]    Script Date: 10/12/2025 8:11:24 ******/
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
/****** Object:  StoredProcedure [dbo].[paInsTarifAnticipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifAnticipos] @pmNumero INT,@pmCuotaMax DECIMAL(14,4),@pmTipoCuota VARCHAR(10),@pmTipoAplica VARCHAR(10)
,@pmCdOrigen VARCHAR(8),@pmCdDestino VARCHAR(8),@pmNitCliente VARCHAR(16),@pmCdTipoVeh VARCHAR(4),@pmTipoAfilVeh VARCHAR(10)
,@pmInactivo BIT,@pmCdRuta VARCHAR(4),@pmNitPropietario VARCHAR(16),@pmTipo_Egreso VARCHAR(20),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11) 
 AS 
 INSERT INTO TarifAnticipos (Numero,CuotaMax,TipoCuota,TipoAplica,CdOrigen,CdDestino,CdRuta,NitCliente,CdTipoVeh,TipoAfilVeh,Inactivo,FechaCrea,IdUsuario,NitPropietario,Tipo_Egreso)
 VALUES (@pmNumero,@pmCuotaMax,@pmTipoCuota,@pmTipoAplica,@pmCdOrigen,@pmCdDestino,@pmCdRuta,@pmNitCliente,@pmCdTipoVeh,@pmTipoAfilVeh,@pmInactivo,@pmFechaCrea,@pmIdUsuario,@pmNitPropietario,@pmTipo_Egreso)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifasAportes] @pmFecha SMALLDATETIME,@pmIdTarifVinc VARCHAR(4),@pmIdTarifApo VARCHAR(4),@pmTarifTraslado DECIMAL(14,4),@pmUndTarifTdo VARCHAR(10),@pmBaseTarifVinc VARCHAR(10),@pmBaseLiqAportes VARCHAR(10),@pmFrecLiqAportes INT,@pmCodGrupo VARCHAR(4),@pmNitAsociado VARCHAR(16),@pmId_Vehiculo VARCHAR(10),@pmUndVehiculo CHAR(1),@pmTipoVigencia CHAR(1),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME
,@pmAnulado BIT,@pmObservacion VARCHAR(500),@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME
 AS 
 INSERT INTO TarifasAportes (Fecha,IdTarifVinc,IdTarifApo,TarifTraslado,UndTarifTdo,BaseTarifVinc,BaseLiqAportes,FrecLiqAportes,CodGrupo,NitAsociado,Id_Vehiculo,UndVehiculo,TipoVigencia,FechaInicial,FechaFinal,Anulado,IdUsuario,FechaCrea,FechaAct,Observacion)
 VALUES (@pmFecha,@pmIdTarifVinc,@pmIdTarifApo,@pmTarifTraslado,@pmUndTarifTdo,@pmBaseTarifVinc,@pmBaseLiqAportes,@pmFrecLiqAportes,@pmCodGrupo,@pmNitAsociado,@pmId_Vehiculo,@pmUndVehiculo,@pmTipoVigencia,@pmFechaInicial,@pmFechaFinal,@pmAnulado,@pmIdUsuario,@pmFechaCrea,Null,@pmObservacion)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasFleMay]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifasFleMay] @pmIdAgencia VARCHAR(16),@pmTipoTarifa VARCHAR(10),@pmNumero INT,@pmNitEmpresa VARCHAR(16)
,@pmCapacMin DECIMAL(14,4),@pmCapacMax DECIMAL(14,4),@pmVrTarifa DECIMAL(14,4),@pmTipoLiquida VARCHAR(10),@pmDescTipoVeh VARCHAR(50)
,@pmInactivo BIT,@pmTipoVehic INT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TarifasFleMay (IdAgencia,TipoTarifa,Numero,TipoVehic,NitEmpresa,CapacMin,CapacMax,VrTarifa,TipoLiquida,DescTipoVeh,Inactivo,FechaCrea,IdUsuario)
 VALUES (@pmIdAgencia,@pmTipoTarifa,@pmNumero,@pmTipoVehic,@pmNitEmpresa,@pmCapacMin,@pmCapacMax,@pmVrTarifa,@pmTipoLiquida,@pmDescTipoVeh,@pmInactivo,@pmFechaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasFletes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifasFletes] @pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmNumero INT,@pmTipoTarifa VARCHAR(10),@pmTarifClie MONEY,@pmTarifPago MONEY
,@pmTarifTabla MONEY,@pmIdMneda VARCHAR(5),@pmUndMed VARCHAR(10),@pmNitCliente VARCHAR(16),@pmCdNat VARCHAR(4),@pmCdTipoVeh VARCHAR(4)
,@pmCdRango VARCHAR(4),@pmUndTarifClie VARCHAR(10),@pmUndTarifPago VARCHAR(10),@pmInactivo BIT,@pmCdRuta VARCHAR(4),@pmCdMercancia VARCHAR(16)
,@pmTipoAfiVehic VARCHAR(10),@pmTarifAfiliado DECIMAL(16,6),@pmTarifTercero DECIMAL(16,6),@pmTarifPropio DECIMAL(16,6),@pmTipoOper VARCHAR(10)
,@pmCdGrupo VARCHAR(4),@pmMargenMin DECIMAL(14,4),@pmCdAgencia VARCHAR(16),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TarifasFletes (Numero,IdOrigen,IdDestino,CdRuta,TipoTarifa,TarifClie,TarifPago,TarifTabla,IdMneda,UndMed,NitCliente,CdNat,CdTipoVeh,CdRango
,UndTarifClie,UndTarifPago,TipoAfiVehic,TarifAfiliado,TarifTercero,TarifPropio,Inactivo,CdMercancia,FechaCrea,IdUsuario,TipoOper,CdGrupo,MargenMin,CdAgencia)
 VALUES (@pmNumero,@pmIdOrigen,@pmIdDestino,@pmCdRuta,@pmTipoTarifa,@pmTarifClie,@pmTarifPago,@pmTarifTabla,@pmIdMneda,@pmUndMed,@pmNitCliente
,@pmCdNat,@pmCdTipoVeh,@pmCdRango,@pmUndTarifClie,@pmUndTarifPago,@pmTipoAfiVehic,@pmTarifAfiliado,@pmTarifTercero,@pmTarifPropio,@pmInactivo,@pmCdMercancia,@pmFechaCrea,@pmIdUsuario,@pmTipoOper,@pmCdGrupo,@pmMargenMin,@pmCdAgencia)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasMasivo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifasMasivo] @pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdTipoVeh VARCHAR(4),@pmTarifaUnd DECIMAL(14,4),@pmVrFletes DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO TarifasMasivo (IdOrigen,IdDestino,IdTipoVeh,TarifaUnd,VrFletes,Inactivo)
 VALUES (@pmIdOrigen,@pmIdDestino,@pmIdTipoVeh,@pmTarifaUnd,@pmVrFletes,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasPaq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifasPaq] @pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmTarifaUnd DECIMAL(14,4),@pmTiempoEnt DECIMAL(14,4)
,@pmTarifaMin DECIMAL(14,4),@pmFormaPago VARCHAR(20),@pmInactivo BIT
 AS 
 INSERT INTO TarifasPaq (IdOrigen,IdDestino,TarifaUnd,TiempoEnt,TarifaMin,FormaPago,Inactivo)
 VALUES (@pmIdOrigen,@pmIdDestino,@pmTarifaUnd,@pmTiempoEnt,@pmTarifaMin,@pmFormaPago,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifasServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTarifasServ] @pmTipoServ INT,@pmIdCliente VARCHAR(16),@pmIdMercancia VARCHAR(16),@pmIdEstacion VARCHAR(4),@pmUndMed VARCHAR(10)
,@pmTipoAfiVehic VARCHAR(10),@pmCdTipoVeh VARCHAR(4),@pmTarifaClie DECIMAL(16,4),@pmTarifaPago DECIMAL(16,4),@pmInactivo BIT
,@pmMargenMin DECIMAL(14,4),@pmCdRuta VARCHAR(4),@pmCdCiuOrigen VARCHAR(8),@pmCdCiuDestino VARCHAR(8),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TarifasServ (TipoServ,IdCliente,IdMercancia,IdEstacion,UndMed,TipoAfiVehic,CdTipoVeh,TarifaClie,TarifaPago,Inactivo,FechaCrea,IdUsuario,MargenMin,CdRuta,CdCiuOrigen,CdCiuDestino)
 VALUES (@pmTipoServ,@pmIdCliente,@pmIdMercancia,@pmIdEstacion,@pmUndMed,@pmTipoAfiVehic,@pmCdTipoVeh,@pmTarifaClie,@pmTarifaPago,@pmInactivo,@pmFechaCrea,@pmIdUsuario,@pmMargenMin,@pmCdRuta,@pmCdCiuOrigen,@pmCdCiuDestino)
GO
/****** Object:  StoredProcedure [dbo].[paInsTarifBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTarifBuses] @pmIdTarifa VARCHAR(4),@pmDescripcion VARCHAR(20),@pmVrNormal MONEY,@pmVrFestivo MONEY,@pmInactivo BIT
 AS 
 INSERT INTO TarifBuses (IdTarifa,Descripcion,VrNormal,VrFestivo,Inactivo)
 VALUES (@pmIdTarifa,@pmDescripcion,@pmVrNormal,@pmVrFestivo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInstasas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstasas] @pmIdMneda VARCHAR(5),@pmIdMnedaD VARCHAR(5),@pmFecha SMALLDATETIME,@pmTasaDia DECIMAL(14,6)
 AS 
 INSERT INTO Trn_tasas (IdMneda,IdMnedaD,Fecha,TasaDia)
 VALUES (@pmIdMneda,@pmIdMnedaD,@pmFecha,@pmTasaDia)
GO
/****** Object:  StoredProcedure [dbo].[paInsTasasDTF]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTasasDTF] @pmnAnno INT,@pmnMes INT,@pmnSem INT,@pmDTF_EA DECIMAL(14,4),@pmTIBC_EA DECIMAL(14,4),@pmFactor_Mon DECIMAL(14,4)
 AS 
 INSERT INTO TasasDTF (nAnno,nMes,nSem,DTF_EA,TIBC_EA,Factor_Mon)
 VALUES (@pmnAnno,@pmnMes,@pmnSem,@pmDTF_EA,@pmTIBC_EA,@pmFactor_Mon)
GO
/****** Object:  StoredProcedure [dbo].[paInsTasasInteres]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTasasInteres] @pmIdTasa VARCHAR(4),@pmDescTasa VARCHAR(50),@pmTipoInteres VARCHAR(10),@pmTipoPeriodo VARCHAR(10),@pmCausaInteres INT,@pmTipoDTF VARCHAR(10)
,@pmDTF_EA DECIMAL(14,4),@pmSpread_TA DECIMAL(14,4),@pmTasaEfectiva DECIMAL(14,4),@pmOpcCompra DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO TasasInteres (IdTasa,DescTasa,TipoInteres,TipoPeriodo,CausaInteres,TipoDTF,DTF_EA,Spread_TA,TasaEfectiva,OpcCompra,Inactivo)
 VALUES (@pmIdTasa,@pmDescTasa,@pmTipoInteres,@pmTipoPeriodo,@pmCausaInteres,@pmTipoDTF,@pmDTF_EA,@pmSpread_TA,@pmTasaEfectiva,@pmOpcCompra,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTasasIntmora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTasasIntmora] @pmIdMora VARCHAR(4),@pmDescMora VARCHAR(50),@pmTipoInteres VARCHAR(10)
,@pmTasaEA DECIMAL(14,4),@pmTasaEM DECIMAL(14,4),@pmDiasGracia INT,@pmInactivo BIT
 AS 
 INSERT INTO TasasIntmora (IdMora,DescMora,TipoInteres,TasaEA,TasaEM,DiasGracia,Inactivo)
 VALUES (@pmIdMora,@pmDescMora,@pmTipoInteres,@pmTasaEA,@pmTasaEM,@pmDiasGracia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTaxRutas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTaxRutas] @pmIdRuta VARCHAR(4),@pmNomRuta VARCHAR(100),@pmTipoRuta VARCHAR(10)
,@pmTarifPago MONEY,@pmTarifCobro MONEY,@pmOrigen VARCHAR(30),@pmDestino VARCHAR(30),@pmCodRuta VARCHAR(20),@pmInactivo BIT
 AS 
 INSERT INTO TaxRutas (IdRuta,NomRuta,TipoRuta,TarifPago,TarifCobro,Origen,Destino,CodRuta,Inactivo)
 VALUES (@pmIdRuta,@pmNomRuta,@pmTipoRuta,@pmTarifPago,@pmTarifCobro,@pmOrigen,@pmDestino,@pmCodRuta,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTaxTarifas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTaxTarifas] @pmTipoTarif VARCHAR(10),@pmItem INT,@pmTipoHora INT,@pmNumInicial DECIMAL(14,4)
,@pmNumFinal DECIMAL(14,4),@pmTarifPago MONEY,@pmTarifCobro MONEY
 AS 
 INSERT INTO TaxTarifas (TipoTarif,Item,TipoHora,NumInicial,NumFinal,TarifPago,TarifCobro)
 VALUES (@pmTipoTarif,@pmItem,@pmTipoHora,@pmNumInicial,@pmNumFinal,@pmTarifPago,@pmTarifCobro)
GO
/****** Object:  StoredProcedure [dbo].[paInsTaxTarifClie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTaxTarifClie] @pmTipoTarif VARCHAR(10),@pmItem INT,@pmIdClie VARCHAR(16),@pmTipoHora INT,@pmIdRuta VARCHAR(4)
,@pmNumInicial DECIMAL(14,4),@pmNumFinal DECIMAL(14,4),@pmTarifPago MONEY,@pmTarifCobro MONEY
 AS 
 INSERT INTO TaxTarifClie (TipoTarif,Item,IdClie,TipoHora,IdRuta,NumInicial,NumFinal,TarifPago,TarifCobro)
 VALUES (@pmTipoTarif,@pmItem,@pmIdClie,@pmTipoHora,@pmIdRuta,@pmNumInicial,@pmNumFinal,@pmTarifPago,@pmTarifCobro)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercClieCia] @pmIdClie VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 INSERT INTO TercClieCia (IdClie,IdCia)
 VALUES (@pmIdClie,@pmIdCia)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieGarant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercClieGarant] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4),@pmItem INT,@pmTipoGarant VARCHAR(20),@pmCdInmueble VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmVrGarant MONEY,@pmVrAvaluo MONEY,@pmPropietario VARCHAR(250),@pmDirInmueble VARCHAR(250),@pmCdCiudad VARCHAR(8),@pmMatricula VARCHAR(50),@pmEscritura VARCHAR(50)
,@pmNumNotaria VARCHAR(20),@pmMarcaVeh VARCHAR(20),@pmModelo VARCHAR(4),@pmCdBanco VARCHAR(4),@pmFecCheque SMALLDATETIME,@pmNumCheque VARCHAR(20),@pmOtroTipoVehic VARCHAR(50),@pmOtroInmueble VARCHAR(50),@pmCedFmnte1 VARCHAR(16),@pmNomFmnte1 VARCHAR(150),@pmCedFmnte2 VARCHAR(16),@pmNomFmnte2 VARCHAR(150),@pmCedFmnte3 VARCHAR(16),@pmNomFmnte3 VARCHAR(150)
,@pmCedFmnte4 VARCHAR(16),@pmNomFmnte4 VARCHAR(150),@pmCedFmnte5 VARCHAR(16),@pmNomFmnte5 VARCHAR(150),@pmCedFmnte6 VARCHAR(16),@pmNomFmnte6 VARCHAR(150)
 AS 
 INSERT INTO TercClieGarant (IdClie,IdAgencia,IdLinea,Item,TipoGarant,CdInmueble,CdTipoVeh,VrGarant,VrAvaluo,Propietario,DirInmueble,CdCiudad,Matricula,Escritura,NumNotaria,MarcaVeh,Modelo,CdBanco,FecCheque,NumCheque,OtroTipoVehic,OtroInmueble,CedFmnte1,NomFmnte1,CedFmnte2,NomFmnte2,CedFmnte3,NomFmnte3,CedFmnte4,NomFmnte4,CedFmnte5,NomFmnte5,CedFmnte6,NomFmnte6)
 VALUES (@pmIdClie,@pmIdAgencia,@pmIdLinea,@pmItem,@pmTipoGarant,@pmCdInmueble,@pmCdTipoVeh,@pmVrGarant,@pmVrAvaluo,@pmPropietario,@pmDirInmueble,@pmCdCiudad,@pmMatricula,@pmEscritura,@pmNumNotaria,@pmMarcaVeh,@pmModelo,@pmCdBanco,@pmFecCheque,@pmNumCheque,@pmOtroTipoVehic,@pmOtroInmueble,@pmCedFmnte1,@pmNomFmnte1,@pmCedFmnte2,@pmNomFmnte2,@pmCedFmnte3
,@pmNomFmnte3,@pmCedFmnte4,@pmNomFmnte4,@pmCedFmnte5,@pmNomFmnte5,@pmCedFmnte6,@pmNomFmnte6)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercClieLineas] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4),@pmIdTasa VARCHAR(4),@pmnPlazo INT,@pmTipoPlazo CHAR(1),@pmCupoCredito MONEY,@pmSaldoCapital MONEY,@pmSaldoInteres MONEY,@pmMaxCupoSmlv DECIMAL(14,4),@pmTipoCausac VARCHAR(10),@pmDiasVence VARCHAR(20)
,@pmFecPreAprob SMALLDATETIME,@pmPlazoAprob INT,@pmEtdoAprob INT,@pmTipoAprob VARCHAR(20),@pmDescAprob VARCHAR(250),@pmGarantias BIT,@pmTipoGarantia VARCHAR(10),@pmDescGarantia VARCHAR(250),@pmVrGarantia MONEY,@pmReqCheques BIT,@pmFecActCupo SMALLDATETIME,@pmEstadoAct INT
,@pmLiqSeguro BIT,@pmCdTasaConv VARCHAR(4),@pmNitConvenio VARCHAR(16),@pmCuotasConv INT,@pmCdTarifSeguro VARCHAR(4),@pmTasaIntLinea BIT,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercClieLineas (IdClie,IdAgencia,IdLinea,IdTasa,nPlazo,TipoPlazo,CupoCredito,SaldoCapital,SaldoInteres,MaxCupoSmlv,TipoCausac,DiasVence,LiqSeguro,FecPreAprob,PlazoAprob,EtdoAprob,TipoAprob,DescAprob,Garantias,TipoGarantia,DescGarantia,VrGarantia,ReqCheques,FecActCupo,CdTasaConv,NitConvenio,CuotasConv,EstadoAct,FechaCrea,IdUsuario,CdTarifSeguro,TasaIntLinea)
 VALUES (@pmIdClie,@pmIdAgencia,@pmIdLinea,@pmIdTasa,@pmnPlazo,@pmTipoPlazo,@pmCupoCredito,@pmSaldoCapital,@pmSaldoInteres,@pmMaxCupoSmlv,@pmTipoCausac,@pmDiasVence,@pmLiqSeguro,@pmFecPreAprob,@pmPlazoAprob,@pmEtdoAprob,@pmTipoAprob,@pmDescAprob,@pmGarantias,@pmTipoGarantia,@pmDescGarantia,@pmVrGarantia
,@pmReqCheques,@pmFecActCupo,@pmCdTasaConv,@pmNitConvenio,@pmCuotasConv,@pmEstadoAct,@pmFechaCrea,@pmIdUsuario,@pmCdTarifSeguro,@pmTasaIntLinea)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliente]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliente] @pmIdClie VARCHAR(16),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50),@pmDirEnv VARCHAR(250)
,@pmIdLocEnv VARCHAR(8),@pmDiasEntga INT,@pmIdSzona VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4),@pmIdEstrato VARCHAR(4),@pmIdVend VARCHAR(16),@pmNitFact VARCHAR(16),@pmIdRuta VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30)
,@pmIdBanco VARCHAR(4),@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmCdRet VARCHAR(4),@pmCdRiv VARCHAR(4),@pmCdCms VARCHAR(4),@pmExcIva BIT,@pmTrfIntMora DECIMAL(14,4),@pmDiasGracia INT,@pmLiqFletes BIT,@pmFactSold BIT,@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT
,@pmIncIca BIT,@pmFactTipo INT,@pmVrCupo MONEY,@pmVrSaldo MONEY,@pmUidClie VARCHAR(16),@pmPwdClie VARCHAR(10),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmMatMerc VARCHAR(20),@pmFecMat SMALLDATETIME
,@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmCmntario1 VARCHAR(250),@pmCmntario2 VARCHAR(250),@pmPlazosImp VARCHAR(20),@pmCdBandera VARCHAR(4),@pmContrato BIT,@pmNContrato INT,@pmCiaContMay CHAR(2),@pmCmntario3 VARCHAR(250),@pmPrendGarant VARCHAR(150)
,@pmFecUpCupo SMALLDATETIME,@pmTipoCliente VARCHAR(10),@pmRestric_Cia BIT,@pmCupoGalones DECIMAL(14,4),@pmCdPlazoComb VARCHAR(4),@pmCodClieSicom VARCHAR(20),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFecPlazoDoc SMALLDATETIME,@pmEdoRadicaDoc INT,@pmCdTipBloq VARCHAR(4)
,@pmDescEdoDoc VARCHAR(250),@pmComIndustrial INT,@pmNumLista CHAR(1),@pmTermicas BIT,@pmCodRetCom VARCHAR(4),@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16),@pmCdDiaEnt VARCHAR(4),@pmAutoIca BIT,@pmExcImpBACU BIT,@pmTipoFMR INT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercCliente (IdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga,IdSzona,IdGrupo,IdPlazo,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret
,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie,CodClieSicom,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,PlazosImp,IdEstado,TipoCliente,Inactivo,CdBandera,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo,FechaAdd,IdUsuario
,CupoGalones,Restric_Cia,CdPlazoComb,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca,ExcImpBACU,TipoFMR)
 VALUES (@pmIdClie,@pmNitRepLeg,@pmNomRepLeg,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargContac,@pmDirEnv,@pmIdLocEnv,@pmDiasEntga,@pmIdSzona,@pmIdGrupo,@pmIdPlazo,@pmIdForma,@pmIdEstrato,@pmIdVend,@pmNitFact,@pmIdRuta,@pmIdClase,@pmNumCuenta
,@pmIdBanco,@pmCdMney,@pmCdDct,@pmCdRet,@pmCdRiv,@pmCdCms,@pmExcIva,@pmTrfIntMora,@pmDiasGracia,@pmLiqFletes,@pmFactSold,@pmAutoret,@pmIncRet,@pmIncRiv,@pmIncIca,@pmFactTipo,@pmVrCupo,@pmVrSaldo,@pmUidClie,@pmPwdClie,@pmCodClieSicom,@pmFecIngreso,@pmFecVigencia,@pmFecRetiro
,@pmMatMerc,@pmFecMat,@pmPathFoto,@pmPathFirma,@pmCmntario1,@pmCmntario2,@pmPlazosImp,@pmIdEstado,@pmTipoCliente,@pmInactivo,@pmCdBandera,@pmContrato,@pmNContrato,@pmCiaContMay,@pmCmntario3,@pmPrendGarant,@pmFecUpCupo,@pmFechaAdd,@pmIdUsuario,@pmCupoGalones,@pmRestric_Cia
,@pmCdPlazoComb,@pmFecPlazoDoc,@pmEdoRadicaDoc,@pmCdTipBloq,@pmDescEdoDoc,@pmComIndustrial,@pmNumLista,@pmTermicas,@pmCodRetCom,@pmCodCCosto,@pmCodSubCosto,@pmCdDiaEnt,@pmAutoIca,@pmExcImpBACU,@pmTipoFMR)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliente_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliente_Sel] @pmIdClie VARCHAR(16),@pmNewIdClie VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdClie FROM  TercCliente WHERE  IdClie=@pmIdClie)
  INSERT INTO TercCliente (IdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga,IdSzona,IdGrupo,IdPlazo,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret
 ,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie,CodClieSicom,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,PlazosImp,IdEstado,TipoCliente,Inactivo,CdBandera,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo,FechaAdd,IdUsuario
,CupoGalones,Restric_Cia,CdPlazoComb,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca,ExcImpBACU,TipoFMR)
  SELECT @pmNewIdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga,IdSzona,IdGrupo,IdPlazo,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret
 ,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie,CodClieSicom,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,PlazosImp,IdEstado,TipoCliente,Inactivo,CdBandera,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo,FechaAdd,IdUsuario,CupoGalones,Restric_Cia,CdPlazoComb
,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt,AutoIca,ExcImpBACU,TipoFMR
  FROM  TercCliente 
  WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliePreRef]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliePreRef] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmItem INT,@pmTipoRef VARCHAR(10)
,@pmReferencia VARCHAR(150),@pmNitRefncia VARCHAR(16),@pmDirRefncia VARCHAR(150),@pmTelRefncia VARCHAR(30)
,@pmemlRefncia VARCHAR(100),@pmCargRefncia VARCHAR(50),@pmNumCuenta VARCHAR(30),@pmObservcion VARCHAR(250)
,@pmParentesco VARCHAR(10),@pmFechaNac SMALLDATETIME,@pmEdad INT,@pmBenSolidario BIT
 AS 
 INSERT INTO TercCliePreRef (IdClie,IdAgencia,Item,TipoRef,Referencia,NitRefncia,DirRefncia,TelRefncia,emlRefncia,CargRefncia,NumCuenta,Observcion
,Parentesco,FechaNac,Edad,BenSolidario)
 VALUES (@pmIdClie,@pmIdAgencia,@pmItem,@pmTipoRef,@pmReferencia,@pmNitRefncia,@pmDirRefncia,@pmTelRefncia,@pmemlRefncia,@pmCargRefncia,@pmNumCuenta,@pmObservcion
,@pmParentesco,@pmFechaNac,@pmEdad,@pmBenSolidario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliePrestamo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliePrestamo] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100)
,@pmCargContac VARCHAR(50),@pmIdSzona VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdTipoTerc VARCHAR(4),@pmIdVend VARCHAR(16),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmEsExento BIT,@pmCalcIntMora BIT,@pmDiasGracia INT
,@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmVrSalBasico MONEY,@pmMaxDcto DECIMAL(14,4),@pmMatMerc VARCHAR(20),@pmFecMat SMALLDATETIME,@pmNomAgencia VARCHAR(150),@pmDirAgencia VARCHAR(250)
,@pmIdLocalAge VARCHAR(8),@pmComentarios VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTipoSalario CHAR(1),@pmNumTarj VARCHAR(30),@pmPwdTarj VARCHAR(30),@pmFecVenceTc SMALLDATETIME,@pmIncRetFte BIT,@pmFechaImp SMALLDATETIME,@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16)
,@pmFecNacmto SMALLDATETIME,@pmNacionalidad VARCHAR(50),@pmSexo CHAR(1),@pmCdEstCivil VARCHAR(4),@pmNumPerCargo INT,@pmNivelEduc VARCHAR(4),@pmTipoVivienda VARCHAR(10),@pmEstratoSocial INT,@pmIdOcupac VARCHAR(4),@pmVrPension MONEY,@pmVrOtrosDev MONEY
,@pmVrPasivo MONEY,@pmVrPatrimonio MONEY,@pmEmpresaLab VARCHAR(150),@pmFecIngLab SMALLDATETIME,@pmTelEmpresa VARCHAR(20),@pmDirEmpresa VARCHAR(250),@pmEmailEmpresa VARCHAR(100),@pmBaseAportes MONEY,@pmCdTarifApo VARCHAR(4),@pmVrAportes MONEY,@pmFecInicioApo SMALLDATETIME,@pmFecFinalApo SMALLDATETIME
,@pmDiaCausacApo VARCHAR(150),@pmFecRetiroApo SMALLDATETIME,@pmCausalRetiro VARCHAR(250),@pmSinDctoNom BIT,@pmSinLiqAporte BIT,@pmCabFamilia BIT,@pmDebitoAuto VARCHAR(20),@pmVrActivos MONEY,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercCliePrestamo (IdClie,IdAgencia,IdSzona,IdGrupo,IdTipoTerc,IdVend,IdClase,NumCuenta,IdBanco,NomAgencia,DirAgencia,IdLocalAge,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,EsExento,CalcIntMora,DiasGracia
,FecIngreso,FecVigencia,FecRetiro,VrSalBasico,MaxDcto,TipoSalario,MatMerc,FecMat,Comentarios,IdEstado,Inactivo,FechaCrea,IdUsuario,NumTarj,PwdTarj,FecVenceTc,IncRetFte,FechaImp,CodCCosto,CodSubCosto
,FecNacmto,Nacionalidad,Sexo,CdEstCivil,NumPerCargo,NivelEduc,TipoVivienda,EstratoSocial,IdOcupac,VrPension,VrOtrosDev,VrPasivo,VrPatrimonio,EmpresaLab,FecIngLab,TelEmpresa,DirEmpresa,EmailEmpresa,BaseAportes,CdTarifApo,VrAportes,FecInicioApo,FecFinalApo
,DiaCausacApo,FecRetiroApo,CausalRetiro,SinDctoNom,SinLiqAporte,CabFamilia,DebitoAuto,VrActivos)
 VALUES (@pmIdClie,@pmIdAgencia,@pmIdSzona,@pmIdGrupo,@pmIdTipoTerc,@pmIdVend,@pmIdClase,@pmNumCuenta,@pmIdBanco,@pmNomAgencia,@pmDirAgencia,@pmIdLocalAge,@pmNitRepLeg,@pmNomRepLeg,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargContac,@pmEsExento
,@pmCalcIntMora,@pmDiasGracia,@pmFecIngreso,@pmFecVigencia,@pmFecRetiro,@pmVrSalBasico,@pmMaxDcto,@pmTipoSalario,@pmMatMerc,@pmFecMat,@pmComentarios,@pmIdEstado,@pmInactivo,@pmFechaCrea,@pmIdUsuario,@pmNumTarj,@pmPwdTarj,@pmFecVenceTc,@pmIncRetFte,@pmFechaImp,@pmCodCCosto,@pmCodSubCosto
,@pmFecNacmto,@pmNacionalidad,@pmSexo,@pmCdEstCivil,@pmNumPerCargo,@pmNivelEduc,@pmTipoVivienda,@pmEstratoSocial,@pmIdOcupac,@pmVrPension,@pmVrOtrosDev,@pmVrPasivo,@pmVrPatrimonio,@pmEmpresaLab,@pmFecIngLab,@pmTelEmpresa,@pmDirEmpresa,@pmEmailEmpresa,@pmBaseAportes
,@pmCdTarifApo,@pmVrAportes,@pmFecInicioApo,@pmFecFinalApo,@pmDiaCausacApo,@pmFecRetiroApo,@pmCausalRetiro,@pmSinDctoNom,@pmSinLiqAporte,@pmCabFamilia,@pmDebitoAuto,@pmVrActivos)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCliePrestamo_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCliePrestamo_Sel] @pmIdClie VARCHAR(16),@pmNewIdClie VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdClie FROM  TercCliePrestamo WHERE  IdClie=@pmIdClie)
  INSERT INTO TercCliePrestamo (IdClie,IdAgencia,IdSzona,IdGrupo,IdTipoTerc,IdVend,IdClase,NumCuenta,IdBanco,NomAgencia,DirAgencia,IdLocalAge,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,EsExento,CalcIntMora,DiasGracia,FecIngreso,FecVigencia,FecRetiro,VrSalBasico
 ,MaxDcto,TipoSalario,MatMerc,FecMat,Comentarios,IdEstado,Inactivo,FechaCrea,IdUsuario,NumTarj,PwdTarj,FecVenceTc,IncRetFte,FechaImp,CodCCosto,CodSubCosto,FecNacmto,Nacionalidad,Sexo,CdEstCivil,NumPerCargo,NivelEduc,TipoVivienda,EstratoSocial,IdOcupac,VrPension,VrOtrosDev,VrPasivo,VrPatrimonio
,EmpresaLab,FecIngLab,TelEmpresa,DirEmpresa,EmailEmpresa,BaseAportes,CdTarifApo,VrAportes,FecInicioApo,FecFinalApo,DiaCausacApo,FecRetiroApo,CausalRetiro,SinDctoNom,SinLiqAporte,CabFamilia,DebitoAuto,VrActivos)
 SELECT @pmNewIdClie,IdAgencia,IdSzona,IdGrupo,IdTipoTerc,IdVend,IdClase,NumCuenta,IdBanco,NomAgencia,DirAgencia,IdLocalAge,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,EsExento,CalcIntMora,DiasGracia,FecIngreso,FecVigencia,FecRetiro,VrSalBasico
 ,MaxDcto,TipoSalario,MatMerc,FecMat,Comentarios,IdEstado,Inactivo,FechaCrea,IdUsuario,NumTarj,PwdTarj,FecVenceTc,IncRetFte,FechaImp,CodCCosto,CodSubCosto,FecNacmto,Nacionalidad,Sexo,CdEstCivil,NumPerCargo,NivelEduc,TipoVivienda,EstratoSocial,IdOcupac,VrPension,VrOtrosDev,VrPasivo,VrPatrimonio
,EmpresaLab,FecIngLab,TelEmpresa,DirEmpresa,EmailEmpresa,BaseAportes,CdTarifApo,VrAportes,FecInicioApo,FecFinalApo,DiaCausacApo,FecRetiroApo,CausalRetiro,SinDctoNom,SinLiqAporte,CabFamilia,DebitoAuto,VrActivos
 FROM TercCliePrestamo WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieRef]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercClieRef] @pmIdClie VARCHAR(16),@pmItem INT,@pmTipoRef VARCHAR(10),@pmReferencia VARCHAR(150)
,@pmNitRefncia VARCHAR(16),@pmDirRefncia VARCHAR(150),@pmTelRefncia VARCHAR(30),@pmemlRefncia VARCHAR(100)
,@pmCargRefncia VARCHAR(50),@pmNumCuenta VARCHAR(30),@pmObservcion VARCHAR(250)
 AS 
 INSERT INTO TercClieRef (IdClie,Item,TipoRef,Referencia,NitRefncia,DirRefncia,TelRefncia,emlRefncia,CargRefncia,NumCuenta,Observcion)
 VALUES (@pmIdClie,@pmItem,@pmTipoRef,@pmReferencia,@pmNitRefncia,@pmDirRefncia,@pmTelRefncia,@pmemlRefncia
,@pmCargRefncia,@pmNumCuenta,@pmObservcion)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercClieSaldos] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 INSERT INTO TercClieSaldos (IdClie,CdAgencia,IdCia,VrSaldo)
 VALUES (@pmIdClie,@pmCdAgencia,@pmIdCia,@pmVrSaldo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieSaldos_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercClieSaldos_Uni] @pmIdClie VARCHAR(16),@pmIdClieDos VARCHAR(16),@pmNewClie VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdClie FROM TercClieSaldos WHERE IdClie=@pmIdClie OR IdClie=@pmIdClieDos)
  INSERT INTO TercClieSaldos (IdClie,CdAgencia,IdCia,VrSaldo)
  SELECT @pmNewClie,CdAgencia,IdCia,SUM(VrSaldo)
  FROM TercClieSaldos
  WHERE  IdClie=@pmIdClie OR IdClie=@pmIdClieDos
  GROUP BY CdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsTercClieVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercClieVeh] @pmIdClie VARCHAR(16),@pmpVehiculo VARCHAR(10)
,@pmCdConductor VARCHAR(16),@pmNumVehiculo VARCHAR(10),@pmDescripcion VARCHAR(100)
 AS 
 INSERT INTO TercClieVeh (IdClie,pVehiculo,CdConductor,NumVehiculo,Descripcion)
 VALUES (@pmIdClie,@pmpVehiculo,@pmCdConductor,@pmNumVehiculo,@pmDescripcion)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndContrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCndContrato] @pmNumContrato INT,@pmIdConductor VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmIdModd VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmFecVigencia SMALLDATETIME
,@pmObservaciones VARCHAR(250),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercCndContrato (NumContrato,IdConductor,IdTipCon,IdModd,FecIngreso,FecRetiro,FecVigencia,Observaciones,IdUsuario)
 VALUES (@pmNumContrato,@pmIdConductor,@pmIdTipCon,@pmIdModd,@pmFecIngreso,@pmFecRetiro,@pmFecVigencia,@pmObservaciones,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndReferencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCndReferencias] @pmIdConductor VARCHAR(16),@pmItem INT,@pmTipoRef VARCHAR(10),@pmEmpresaRef VARCHAR(150),@pmNitRef VARCHAR(16),@pmDireccionRef VARCHAR(150)
,@pmTelefonoRef VARCHAR(30),@pmContactoRef VARCHAR(150),@pmEmailRef VARCHAR(100),@pmCargoRef VARCHAR(50),@pmCuentaBanco VARCHAR(30),@pmFechaInicial SMALLDATETIME
,@pmFechaFinal SMALLDATETIME,@pmVerificado VARCHAR(150),@pmObservRef VARCHAR(250)
 AS 
 INSERT INTO TercCndReferencias (IdConductor,Item,TipoRef,EmpresaRef,NitRef,DireccionRef,TelefonoRef,ContactoRef,EmailRef,CargoRef,CuentaBanco,FechaInicial,FechaFinal,Verificado,ObservRef)
 VALUES (@pmIdConductor,@pmItem,@pmTipoRef,@pmEmpresaRef,@pmNitRef,@pmDireccionRef,@pmTelefonoRef,@pmContactoRef,@pmEmailRef,@pmCargoRef,@pmCuentaBanco,@pmFechaInicial,@pmFechaFinal,@pmVerificado,@pmObservRef)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndTarjetas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCndTarjetas] @pmIdConductor VARCHAR(16),@pmItem INT,@pmNumeroTarj VARCHAR(30)
,@pmSecuencia INT,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME
 AS 
 INSERT INTO TercCndTarjetas (IdConductor,Item,NumeroTarj,Secuencia,Fecha,FecVence)
 VALUES (@pmIdConductor,@pmItem,@pmNumeroTarj,@pmSecuencia,@pmFecha,@pmFecVence)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndtores]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercCndtores] @pmIdConductor VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmIdModd VARCHAR(4),@pmTipoSangre CHAR(2),@pmFactorRh CHAR(1),@pmLibMilitar VARCHAR(25),@pmClaseLib INT,@pmFechaLib SMALLDATETIME,@pmDistMil VARCHAR(10)
,@pmCertJudicial VARCHAR(25),@pmFecJudicial SMALLDATETIME,@pmVigJudicial SMALLDATETIME,@pmLicencia VARCHAR(25),@pmIdLugar VARCHAR(8),@pmCatLicencia INT,@pmFecLicencia SMALLDATETIME,@pmVigLicencia SMALLDATETIME
,@pmFecNacmto SMALLDATETIME,@pmLugarNacmto VARCHAR(30),@pmSexo CHAR(1),@pmIdEstCivil VARCHAR(4),@pmNHijos INT,@pmPasporte VARCHAR(25),@pmVigPaspte SMALLDATETIME
,@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmCdLocCue VARCHAR(8),@pmCdFonPen VARCHAR(8),@pmCdFonEps VARCHAR(8),@pmCdFonArp VARCHAR(8),@pmpVehiculo VARCHAR(10),@pmPathFoto VARCHAR(30)
,@pmPathFirma VARCHAR(30),@pmPathLic VARCHAR(30),@pmCmntarios VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmNumTarjeta VARCHAR(30),@pmEdicTarjeta INT,@pmFecTarjeta SMALLDATETIME
,@pmVigTarjeta SMALLDATETIME,@pmPasSeguridad VARCHAR(30),@pmFecPasSeg SMALLDATETIME,@pmVigPasSeg SMALLDATETIME,@pmNitEmpTrans VARCHAR(16),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
,@pmNum_Contrato INT,@pmContrato_Activo BIT,@pmCdTipCon VARCHAR(4),@pmFec_Ingreso SMALLDATETIME,@pmFec_Retiro SMALLDATETIME,@pmFec_Vigencia SMALLDATETIME,@pmFec_IngresoAnt SMALLDATETIME,@pmFec_UltimoAcc SMALLDATETIME
,@pmPasadoJudicial VARCHAR(250),@pmRestriccion VARCHAR(50),@pmFecPagoPen SMALLDATETIME,@pmFecPagoEps SMALLDATETIME,@pmFecPagoArp SMALLDATETIME,@pmCdTipoOper VARCHAR(4)
 AS 
 INSERT INTO TercCndtores (IdConductor,IdGrupo,IdModd,TipoSangre,FactorRh,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdClase,NumCuenta,IdBanco,CdLocCue,CdFonPen,CdFonEps,CdFonArp,pVehiculo
,FecNacmto,LugarNacmto,Sexo,IdEstCivil,NHijos,Pasporte,VigPaspte,PathFoto,PathFirma,PathLic,Cmntarios,IdEstado,Inactivo,NumTarjeta,EdicTarjeta,FecTarjeta,VigTarjeta,PasSeguridad,FecPasSeg,VigPasSeg,NitEmpTrans,FechaAdd,IdUsuario,Num_Contrato,Contrato_Activo,CdTipCon,Fec_Ingreso
 ,Fec_Retiro,Fec_Vigencia,Fec_IngresoAnt,Fec_UltimoAcc,PasadoJudicial,Restriccion,FecPagoPen,FecPagoEps,FecPagoArp,CdTipoOper)
 VALUES (@pmIdConductor,@pmIdGrupo,@pmIdModd,@pmTipoSangre,@pmFactorRh,@pmLibMilitar,@pmClaseLib,@pmFechaLib,@pmDistMil,@pmCertJudicial,@pmFecJudicial,@pmVigJudicial,@pmLicencia,@pmIdLugar,@pmCatLicencia,@pmFecLicencia,@pmVigLicencia,@pmIdClase
,@pmNumCuenta,@pmIdBanco,@pmCdLocCue,@pmCdFonPen,@pmCdFonEps,@pmCdFonArp,@pmpVehiculo,@pmFecNacmto,@pmLugarNacmto,@pmSexo,@pmIdEstCivil,@pmNHijos,@pmPasporte,@pmVigPaspte,@pmPathFoto,@pmPathFirma,@pmPathLic,@pmCmntarios
,@pmIdEstado,@pmInactivo,@pmNumTarjeta,@pmEdicTarjeta,@pmFecTarjeta,@pmVigTarjeta,@pmPasSeguridad,@pmFecPasSeg,@pmVigPasSeg,@pmNitEmpTrans,@pmFechaAdd,@pmIdUsuario,@pmNum_Contrato,@pmContrato_Activo,@pmCdTipCon,@pmFec_Ingreso
 ,@pmFec_Retiro,@pmFec_Vigencia,@pmFec_IngresoAnt,@pmFec_UltimoAcc,@pmPasadoJudicial,@pmRestriccion,@pmFecPagoPen,@pmFecPagoEps,@pmFecPagoArp,@pmCdTipoOper)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercCndtores_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercCndtores_Sel] @pmIdConductor VARCHAR(16),@pmNewConductor VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdConductor FROM  TercCndtores WHERE IdConductor=@pmIdConductor)
  INSERT INTO TercCndtores (IdConductor,IdGrupo,IdModd,TipoSangre,FactorRh,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdClase,NumCuenta,IdBanco,CdLocCue,CdFonPen,CdFonEps,CdFonArp,pVehiculo
 ,FecNacmto,LugarNacmto,Sexo,IdEstCivil,NHijos,Pasporte,VigPaspte,PathFoto,PathFirma,PathLic,Cmntarios,IdEstado,Inactivo,NumTarjeta,EdicTarjeta,FecTarjeta,VigTarjeta,PasSeguridad,FecPasSeg,VigPasSeg,NitEmpTrans,FechaAdd,IdUsuario
,Num_Contrato,Contrato_Activo,CdTipCon,Fec_Ingreso,Fec_Retiro,Fec_Vigencia,Fec_IngresoAnt,Fec_UltimoAcc,PasadoJudicial,Restriccion,FecPagoPen,FecPagoEps,FecPagoArp,CdTipoOper)
  SELECT @pmNewConductor,IdGrupo,IdModd,TipoSangre,FactorRh,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdClase,NumCuenta,IdBanco,CdLocCue,CdFonPen,CdFonEps,CdFonArp,pVehiculo
 ,FecNacmto,LugarNacmto,Sexo,IdEstCivil,NHijos,Pasporte,VigPaspte,PathFoto,PathFirma,PathLic,Cmntarios,IdEstado,Inactivo,NumTarjeta,EdicTarjeta,FecTarjeta,VigTarjeta,PasSeguridad,FecPasSeg,VigPasSeg,NitEmpTrans,FechaAdd,IdUsuario
,Num_Contrato,Contrato_Activo,CdTipCon,Fec_Ingreso,Fec_Retiro,Fec_Vigencia,Fec_IngresoAnt,Fec_UltimoAcc,PasadoJudicial,Restriccion,FecPagoPen,FecPagoEps,FecPagoArp,CdTipoOper
  FROM TercCndtores 
  WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paInsTerceros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTerceros] @pmIdTercero VARCHAR(16),@pmRazonSocial VARCHAR(250),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8)
,@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmTelMovil VARCHAR(20),@pmSitioWeb VARCHAR(100),@pme_mail VARCHAR(100),@pmEsCliente BIT,@pmEsVendedor BIT,@pmEsConductor BIT
,@pmEsPropietario BIT,@pmEsProveedor BIT,@pmEsEmpleado BIT,@pmEsOperario BIT,@pmEsAccnista BIT,@pmEsCiaAseg BIT,@pmIdSector VARCHAR(8),@pmIdRegimen VARCHAR(4),@pmIdLugarCed VARCHAR(8),@pmObservacion VARCHAR(250)
,@pmIniStgNom INT,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmNomCial VARCHAR(250),@pmSiglaRaz VARCHAR(50),@pmIdProf VARCHAR(4),@pmTipEnte CHAR(1),@pmFecExpCed SMALLDATETIME,@pmEsCliePres BIT,@pmImgFoto VARCHAR(30),@pmImgFirma VARCHAR(30)
,@pmImagenDoc1 VARCHAR(50),@pmImagenDoc2 VARCHAR(50),@pmImagenDoc3 VARCHAR(50),@pmFechaNac SMALLDATETIME,@pmIdEstOper VARCHAR(4),@pmIdLocUbic VARCHAR(8),@pmDescUbicac VARCHAR(150),@pmCdGrupoTerc VARCHAR(4),@pmRegimenFE BIT,@pmPN_RUT BIT
,@pmRecPublicos BIT,@pmCargoPublico VARCHAR(50),@pmFecInicioCP SMALLDATETIME,@pmFecFinalCp SMALLDATETIME,@pmPersonaPub BIT,@pmCargoPersPub VARCHAR(50),@pmFecInicioPP SMALLDATETIME,@pmFecFinalPP SMALLDATETIME
,@pmVrIngresos MONEY,@pmVrOtroIng MONEY,@pmVrGastos MONEY,@pmVrActivos MONEY,@pmVrPasivos MONEY,@pmVrPatrimonio MONEY,@pmConcOtrosIng VARCHAR(250),@pmOperActVirtual BIT,@pmTipoOperVirtual VARCHAR(150),@pmLavadoActivos BIT
,@pmRL_Nombre VARCHAR(150),@pmRL_Identificacion VARCHAR(16),@pmRL_Direccion VARCHAR(250),@pmRL_CodCiudad VARCHAR(8),@pmRL_Telefono VARCHAR(20),@pmRL_Email VARCHAR(150),@pmAsociado BIT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Terceros (IdTercero,RazonSocial,Codigo,TipoId,Dv,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdRegimen
,IdLugarCed,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,IdUsuario,NomCial,SiglaRaz,IdProf,TipEnte,FecExpCed,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,CdGrupoTerc,RegimenFE,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos
,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado)
 VALUES (@pmIdTercero,@pmRazonSocial,@pmCodigo,@pmTipoId,@pmDv,@pmDireccion,@pmIdLocal,@pmTelefono,@pmFax,@pmTelMovil,@pmSitioWeb,@pme_mail,@pmEsCliente,@pmEsVendedor,@pmEsConductor,@pmEsPropietario,@pmEsProveedor
,@pmEsEmpleado,@pmEsOperario,@pmEsAccnista,@pmEsCiaAseg,@pmEsCliePres,@pmIdSector,@pmIdRegimen,@pmIdLugarCed,@pmObservacion,@pmIniStgNom,@pmIdEstado,@pmInactivo,@pmFechaAdd,@pmIdUsuario
,@pmNomCial,@pmSiglaRaz,@pmIdProf,@pmTipEnte,@pmFecExpCed,@pmImgFoto,@pmImgFirma,@pmImagenDoc1,@pmImagenDoc2,@pmImagenDoc3,@pmFechaNac,@pmIdEstOper,@pmIdLocUbic,@pmDescUbicac,@pmCdGrupoTerc,@pmRegimenFE,@pmPN_RUT
,@pmRecPublicos,@pmCargoPublico,@pmFecInicioCP,@pmFecFinalCp,@pmPersonaPub,@pmCargoPersPub,@pmFecInicioPP,@pmFecFinalPP,@pmVrIngresos,@pmVrOtroIng,@pmVrGastos,@pmVrActivos,@pmVrPasivos,@pmVrPatrimonio,@pmConcOtrosIng
,@pmOperActVirtual,@pmTipoOperVirtual,@pmLavadoActivos,@pmRL_Nombre,@pmRL_Identificacion,@pmRL_Direccion,@pmRL_CodCiudad,@pmRL_Telefono,@pmRL_Email,@pmAsociado)
GO
/****** Object:  StoredProcedure [dbo].[paInsTerceros_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTerceros_Sel] @pmIdTercero VARCHAR(16),@pmNewTercero VARCHAR(16),@pmNewCodigo VARCHAR(16)
 AS 
 INSERT INTO Terceros (IdTercero,RazonSocial,Codigo,TipoId,Dv,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdRegimen
,IdLugarCed,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,IdUsuario,NomCial,SiglaRaz,IdProf,TipEnte,FecExpCed,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,CdGrupoTerc,RegimenFE,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado)
 SELECT @pmNewTercero,RazonSocial,@pmNewCodigo,TipoId,Dv,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdRegimen
,IdLugarCed,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,IdUsuario,NomCial,SiglaRaz,IdProf,TipEnte,FecExpCed,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,CdGrupoTerc,RegimenFE,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado
 FROM  Terceros 
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsTercOperarios_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercOperarios_Sel] @pmIdOperario VARCHAR(16),@pmNewOperario VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdOperario FROM TercOperarios WHERE IdOperario=@pmIdOperario)
  INSERT INTO TercOperarios (IdOperario,IdTipoOper,TipoSalario,VrSalario)
  SELECT @pmNewOperario,IdTipoOper,TipoSalario,VrSalario
  FROM TercOperarios WHERE IdOperario=@pmIdOperario
GO
/****** Object:  StoredProcedure [dbo].[paInsTercPropietario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercPropietario] @pmIdPropietario VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmCupoCredito MONEY,@pmSaldoActual MONEY,@pmAvala BIT,@pmIdAdmon VARCHAR(4),@pmIdTipCon VARCHAR(4)
,@pmContratoActivo BIT,@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercPropietario (IdPropietario,IdGrupo,CupoCredito,SaldoActual,Avala,IdAdmon,IdTipCon,ContratoActivo,FecIngreso,FecRetiro,FecVigencia,Observacion,IdEstado,FechaAdd,IdUsuario)
 VALUES (@pmIdPropietario,@pmIdGrupo,@pmCupoCredito,@pmSaldoActual,@pmAvala,@pmIdAdmon,@pmIdTipCon,@pmContratoActivo,@pmFecIngreso,@pmFecRetiro,@pmFecVigencia,@pmObservacion,@pmIdEstado,@pmFechaAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercPropietario_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercPropietario_Sel] @pmIdPropietario VARCHAR(16),@pmNewPropietario VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdPropietario FROM  TercPropietario WHERE  IdPropietario=@pmIdPropietario)
  INSERT INTO TercPropietario (IdPropietario,IdGrupo,CupoCredito,SaldoActual,Avala,IdAdmon,IdTipCon,ContratoActivo,FecIngreso,FecRetiro,FecVigencia,Observacion,IdEstado,FechaAdd,IdUsuario)
  SELECT @pmNewPropietario,IdGrupo,CupoCredito,SaldoActual,Avala,IdAdmon,IdTipCon,ContratoActivo,FecIngreso,FecRetiro,FecVigencia,Observacion,IdEstado,FechaAdd,IdUsuario
  FROM TercPropietario WHERE  IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paInsTercProvee]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercProvee] @pmIdProv VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150)
,@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50),@pmDirOrdComp VARCHAR(250),@pmIdLocOrd VARCHAR(8),@pmDiasEntga INT,@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4)
,@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT,@pmIncIca BIT,@pmLiqFletes BIT,@pmCdRet VARCHAR(4)
,@pmCdRiv VARCHAR(4),@pmGartProd INT,@pmFecIngreso SMALLDATETIME,@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmCmntarios VARCHAR(250),@pmContrato BIT,@pmNContrato VARCHAR(20),@pmFecVigencia SMALLDATETIME
,@pmFecRetiro SMALLDATETIME,@pmObsFinanc VARCHAR(250),@pmObsJuridica VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCodRetCom VARCHAR(4),@pmCupoElectcom DECIMAL(14,4),@pmAutoIca BIT,@pmCodRetIca VARCHAR(4),@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercProvee (IdProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv
,GartProd,FecIngreso,PathFoto,PathFirma,Cmntarios,IdEstado,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Inactivo,FechaAdd,IdUsuario,CodRetCom,CupoElectcom,AutoIca,CodRetIca)
 VALUES (@pmIdProv,@pmIdGrupo,@pmNitRepLeg,@pmNomRepLeg,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargContac,@pmDirOrdComp,@pmIdLocOrd,@pmDiasEntga,@pmIdPlazo,@pmIdForma,@pmCdMney,@pmCdDct,@pmIdClase
,@pmNumCuenta,@pmIdBanco,@pmAutoret,@pmIncRet,@pmIncRiv,@pmIncIca,@pmLiqFletes,@pmCdRet,@pmCdRiv,@pmGartProd,@pmFecIngreso,@pmPathFoto,@pmPathFirma,@pmCmntarios,@pmIdEstado
,@pmContrato,@pmNContrato,@pmFecVigencia,@pmFecRetiro,@pmObsFinanc,@pmObsJuridica,@pmInactivo,@pmFechaAdd,@pmIdUsuario,@pmCodRetCom,@pmCupoElectcom,@pmAutoIca,@pmCodRetIca)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercProvee_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercProvee_Sel] @pmIdProv VARCHAR(16),@pmNewProv VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdProv FROM  TercProvee WHERE  IdProv=@pmIdProv)
 INSERT INTO TercProvee (IdProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv
,GartProd,FecIngreso,PathFoto,PathFirma,Cmntarios,IdEstado,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Inactivo,FechaAdd,IdUsuario,CodRetCom,CupoElectcom,AutoIca,CodRetIca)
 SELECT @pmNewProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv
,GartProd,FecIngreso,PathFoto,PathFirma,Cmntarios,IdEstado,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Inactivo,FechaAdd,IdUsuario,CodRetCom,CupoElectcom,AutoIca,CodRetIca
 FROM TercProvee WHERE  IdProv=@pmIdProv
GO
/****** Object:  StoredProcedure [dbo].[paInsTercSedes_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercSedes_Sel] @pmIdTercero VARCHAR(16),@pmNewTercero VARCHAR(16)
 AS 
 INSERT INTO TercSedes (IdTercero,IdSede,NomSede,Principal,IdLocSede)
 SELECT @pmNewTercero,IdSede,NomSede,Principal,IdLocSede
 FROM  TercSedes 
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paInsTercSedes_Uni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercSedes_Uni] @pmIdTercero VARCHAR(16),@pmIdTerceroDos VARCHAR(16),@pmNewTercero VARCHAR(16)
AS 
 BEGIN
 DELETE FROM TercSedes WHERE IdTercero=@pmIdTerceroDos 
 AND EXISTS ( SELECT * FROM TercSedes AS TS1 WHERE TS1.IdTercero=@pmIdTercero AND TS1.IdSede=TercSedes.IdSede)
 --unificar
 IF EXISTS (SELECT * FROM TercSedes WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos)
  INSERT INTO TercSedes (IdTercero,IdSede,NomSede,Principal,IdLocSede)
  SELECT @pmNewTercero,IdSede,NomSede,Principal,IdLocSede
  FROM  TercSedes 
  WHERE IdTercero=@pmIdTercero OR IdTercero=@pmIdTerceroDos
 END
GO
/****** Object:  StoredProcedure [dbo].[paInsTercVendedor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTercVendedor] @pmIdVend VARCHAR(16),@pmIdTarCms VARCHAR(4),@pmIdTarCm2 VARCHAR(4),@pmCdJorn VARCHAR(4),@pmIdSzona VARCHAR(4)
,@pmIdGrupo VARCHAR(4),@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmComntarios VARCHAR(250),@pmInactivo BIT,@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30)
,@pmIdBanco VARCHAR(4),@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO TercVendedor (IdVend,IdTarCms,IdTarCm2,CdJorn,IdSzona,IdGrupo,PathFoto,PathFirma,Comntarios,Inactivo,IdClase,NumCuenta,IdBanco,FecAdd,IdUsuario)
 VALUES (@pmIdVend,@pmIdTarCms,@pmIdTarCm2,@pmCdJorn,@pmIdSzona,@pmIdGrupo,@pmPathFoto,@pmPathFirma,@pmComntarios,@pmInactivo,@pmIdClase,@pmNumCuenta,@pmIdBanco,@pmFecAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTercVendedor_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTercVendedor_Sel] @pmIdVend VARCHAR(16),@pmNewVend VARCHAR(16)
 AS 
 IF EXISTS (SELECT IdVend FROM  TercVendedor WHERE  IdVend=@pmIdVend)
  INSERT INTO TercVendedor (IdVend,IdTarCms,IdTarCm2,CdJorn,IdSzona,IdGrupo,PathFoto,PathFirma,Comntarios,Inactivo,IdClase,NumCuenta,IdBanco,FecAdd,IdUsuario)
  SELECT @pmNewVend,IdTarCms,IdTarCm2,CdJorn,IdSzona,IdGrupo,PathFoto,PathFirma,Comntarios,Inactivo,IdClase,NumCuenta,IdBanco,FecAdd,IdUsuario
  FROM TercVendedor WHERE  IdVend=@pmIdVend
GO
/****** Object:  StoredProcedure [dbo].[paInsTerminales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTerminales] @pmIdTerminal VARCHAR(4),@pmTerminal VARCHAR(50),@pmIdCia CHAR(2),@pmInactivo BIT
 AS 
 INSERT INTO Terminales (IdTerminal,Terminal,IdCia,Inactivo)
 VALUES (@pmIdTerminal,@pmTerminal,@pmIdCia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTFmtos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTFmtos] @pmnFormato VARCHAR(10),@pmFmtoFactura VARCHAR(50),@pmTipFac VARCHAR(3)
 AS 
 INSERT INTO Sys_TFmtos (nFormato,FmtoFactura,TipFac)
 VALUES (@pmnFormato,@pmFmtoFactura,@pmTipFac)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposAdm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposAdm] @pmIdAdmon VARCHAR(4),@pmTipoAdmon VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposAdm (IdAdmon,TipoAdmon,Inactivo)
 VALUES (@pmIdAdmon,@pmTipoAdmon,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposAgenc] @pmIdTipAgenc VARCHAR(4),@pmTipoAgencia VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposAgenc (IdTipAgenc,TipoAgencia,Inactivo)
 VALUES (@pmIdTipAgenc,@pmTipoAgencia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposBan] @pmIdBandera VARCHAR(4),@pmTipoBandera VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposBan (IdBandera,TipoBandera,Inactivo)
 VALUES (@pmIdBandera,@pmTipoBandera,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposBloq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposBloq] @pmIdTipBloq VARCHAR(4),@pmTipoBloqueo VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposBloq (IdTipBloq,TipoBloqueo,Inactivo)
 VALUES (@pmIdTipBloq,@pmTipoBloqueo,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposCar] @pmIdCrceria VARCHAR(4),@pmTipoCar VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposCar (IdCrceria,TipoCar,Inactivo)
 VALUES (@pmIdCrceria,@pmTipoCar,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCarga]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposCarga] @pmIdTipCarga VARCHAR(4),@pmTipoCarga VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposCarga (IdTipCarga,TipoCarga,Inactivo)
 VALUES (@pmIdTipCarga,@pmTipoCarga,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCnd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposCnd] @pmIdTipoCon VARCHAR(4),@pmTipoContndor VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposCnd (IdTipoCon,TipoContndor,Inactivo)
 VALUES (@pmIdTipoCon,@pmTipoContndor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCol]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposCol] @pmIdColor VARCHAR(4),@pmNomColor VARCHAR(50),@pmNColor INT,@pmCodigoMT VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO TiposCol (IdColor,NomColor,NColor,CodigoMT,Inactivo)
 VALUES (@pmIdColor,@pmNomColor,@pmNColor,@pmCodigoMT,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposCom] @pmIdCom VARCHAR(3),@pmTipoCom VARCHAR(50),@pmIdDiario VARCHAR(4)
,@pmEsEgreso BIT,@pmConsUnico BIT,@pmInactivo BIT,@pmClaseNiif VARCHAR(10),@pmDoc_Soporte BIT,@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO TiposCom (IdCom,TipoCom,IdDiario,EsEgreso,ConsUnico,Inactivo,FechaAdd,ClaseNiif,Doc_Soporte)
 VALUES (@pmIdCom,@pmTipoCom,@pmIdDiario,@pmEsEgreso,@pmConsUnico,@pmInactivo,@pmFechaAdd,@pmClaseNiif,@pmDoc_Soporte)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposComAgenc] @pmIdSubAgenc VARCHAR(4),@pmSubTipoAgenc VARCHAR(50),@pmIdTipAgenc VARCHAR(4),@pmInactivo BIT
 AS 
 INSERT INTO TiposComAgenc (IdSubAgenc,SubTipoAgenc,IdTipAgenc,Inactivo)
 VALUES (@pmIdSubAgenc,@pmSubTipoAgenc,@pmIdTipAgenc,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComCons]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposComCons] @pmIdCom VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT
,@pmNumero INT,@pmNumManual BIT,@pmFormato VARCHAR(20),@pmConfigFecha VARCHAR(10),@pmTipoPapel INT
,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmCodResol VARCHAR(4),@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO TiposComCons (IdCom,IdCia,LDesde,LHasta,Numero,NumManual,Formato,ConfigFecha
,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,FechaAdd,CodResol)
 VALUES (@pmIdCom,@pmIdCia,@pmLDesde,@pmLHasta,@pmNumero,@pmNumManual,@pmFormato,@pmConfigFecha
,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmFechaAdd,@pmCodResol)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposComFmt] @pmIdCom VARCHAR(3),@pmIdForma CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmPredtmnado BIT
,@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 INSERT INTO TiposComFmt (IdCom,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location)
 VALUES (@pmIdCom,@pmIdForma,@pmDescripcion,@pmFormato,@pmPredtmnado,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmsp_Nombre,@pmInd_Location)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposComRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposComRes] @pmIdRes VARCHAR(4),@pmResolucion VARCHAR(50),@pmPrefijo VARCHAR(5),@pmNumInicial INT,@pmNumFinal INT,@pmFechaExpRes SMALLDATETIME,@pmFechaVigencia SMALLDATETIME,@pmEstablecimiento VARCHAR(100)
 AS 
 INSERT INTO TiposComRes (IdRes,Resolucion,Prefijo,NumInicial,NumFinal,FechaExpRes,FechaVigencia,Establecimiento)
 VALUES (@pmIdRes,@pmResolucion,@pmPrefijo,@pmNumInicial,@pmNumFinal,@pmFechaExpRes,@pmFechaVigencia,@pmEstablecimiento)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposCon] @pmIdTipCon VARCHAR(4),@pmTipoContrato VARCHAR(100)
,@pmDuracion INT,@pmVincLabUgpp VARCHAR(250),@pmCodDIAN VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO TiposCon (IdTipCon,TipoContrato,Duracion,Inactivo,VincLabUgpp,CodDIAN)
 VALUES (@pmIdTipCon,@pmTipoContrato,@pmDuracion,@pmInactivo,@pmVincLabUgpp,@pmCodDIAN)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposCot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposCot] @pmIdCot VARCHAR(4),@pmCotizante VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposCot (IdCot,Cotizante,Inactivo)
 VALUES (@pmIdCot,@pmCotizante,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposDoc] @pmIdDoc VARCHAR(3),@pmTipoDoc VARCHAR(50),@pmConsUnico BIT
,@pmLeyenda VARCHAR(250),@pmInactivo BIT,@pmIntegraCias BIT
 AS 
 INSERT INTO Sys_TiposDoc (IdDoc,TipoDoc,ConsUnico,Leyenda,Inactivo,IntegraCias)
 VALUES (@pmIdDoc,@pmTipoDoc,@pmConsUnico,@pmLeyenda,@pmInactivo,@pmIntegraCias)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposDocCons]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposDocCons] @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT,@pmResolucion VARCHAR(30)
,@pmRangoNum VARCHAR(50),@pmFechaRes SMALLDATETIME,@pmPrefijo VARCHAR(5),@pmNumero INT,@pmNumManual BIT,@pmIntLotes BIT
,@pmConfigFecha VARCHAR(10),@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT
,@pmNumCopias INT,@pmFechaVigRes SMALLDATETIME,@pmClaveTecDian VARCHAR(250),@pmCodResol VARCHAR(4),@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO TiposDocCons (IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero,NumManual,IntLotes,ConfigFecha
,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,FechaAdd,FechaVigRes,ClaveTecDian,CodResol)
 VALUES (@pmIdDoc,@pmIdCia,@pmLDesde,@pmLHasta,@pmResolucion,@pmRangoNum,@pmFechaRes,@pmPrefijo,@pmNumero
,@pmNumManual,@pmIntLotes,@pmConfigFecha,@pmFormato,@pmTipoPapel,@pmOrientacion,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmFechaAdd,@pmFechaVigRes,@pmClaveTecDian,@pmCodResol)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposDocCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposDocCue] @pmIdDoc VARCHAR(3),@pmIdClase INT
,@pmClaseCuenta VARCHAR(50),@pmTipoMov CHAR(1)
 AS 
 INSERT INTO Sys_TiposDocCue (IdDoc,IdClase,ClaseCuenta,TipoMov)
 VALUES (@pmIdDoc,@pmIdClase,@pmClaseCuenta,@pmTipoMov)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[paInsTiposEnt] @pmIdEnt VARCHAR(4),@pmDiaEntrega VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposEnt (IdEnt,DiaEntrega,Inactivo)
 VALUES (@pmIdEnt,@pmDiaEntrega,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposEsc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposEsc] @pmIdTipoEsc VARCHAR(4),@pmTipoEscolta VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposEsc (IdTipoEsc,TipoEscolta,Inactivo)
 VALUES (@pmIdTipoEsc,@pmTipoEscolta,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposFil]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposFil] @pmIdFiltro VARCHAR(4),@pmTipoFiltro VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposFil (IdFiltro,TipoFiltro,Inactivo)
 VALUES (@pmIdFiltro,@pmTipoFiltro,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposFuel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposFuel] @pmIdCom VARCHAR(4),@pmTipoComb VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposFuel (IdCom,TipoComb,Inactivo)
 VALUES (@pmIdCom,@pmTipoComb,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposInm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposInm] @pmIdTipoInm VARCHAR(4),@pmTipoInmueble VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposInm (IdTipoInm,TipoInmueble,Inactivo)
 VALUES (@pmIdTipoInm,@pmTipoInmueble,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposLla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposLla] @pmIdTlla VARCHAR(4),@pmTipoLlanta VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposLla (IdTlla,TipoLlanta,Inactivo)
 VALUES (@pmIdTlla,@pmTipoLlanta,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposLub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposLub] @pmIdLub VARCHAR(4),@pmTipoLub VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposLub (IdLub,TipoLub,Inactivo)
 VALUES (@pmIdLub,@pmTipoLub,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMat]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposMat] @pmIdMat VARCHAR(4),@pmMaterial VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposMat (IdMat,Material,Inactivo)
 VALUES (@pmIdMat,@pmMaterial,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposMcia] @pmIdTmcia VARCHAR(4),@pmTipoMcia VARCHAR(50),@pmCodPeligrosidad VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO TiposMcia (IdTmcia,TipoMcia,CodPeligrosidad,Inactivo)
 VALUES (@pmIdTmcia,@pmTipoMcia,@pmCodPeligrosidad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMnjo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposMnjo] @pmIdMnjo VARCHAR(4),@pmManejoMcia VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposMnjo (IdMnjo,ManejoMcia,Inactivo)
 VALUES (@pmIdMnjo,@pmManejoMcia,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposMod] @pmIdModd VARCHAR(4),@pmModalidad VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposMod (IdModd,Modalidad,Inactivo)
 VALUES (@pmIdModd,@pmModalidad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposMot] @pmIdTipoMot VARCHAR(4),@pmTipoMotor VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposMot (IdTipoMot,TipoMotor,Inactivo)
 VALUES (@pmIdTipoMot,@pmTipoMotor,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposMotdev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposMotdev] @pmIdMotDev VARCHAR(4),@pmMotivoDev VARCHAR(150)
,@pmTipoFact VARCHAR(3),@pmInactivo BIT,@pmEstadoPed BIT,@pmCodEstadoPed VARCHAR(4),@pmBodegaDev BIT,@pmCodBodegaDev VARCHAR(4),@pmCodCias VARCHAR(500)
 AS 
 INSERT INTO TiposMotdev (IdMotDev,MotivoDev,TipoFact,Inactivo,EstadoPed,CodEstadoPed,BodegaDev,CodBodegaDev,CodCias)
 VALUES (@pmIdMotDev,@pmMotivoDev,@pmTipoFact,@pmInactivo,@pmEstadoPed,@pmCodEstadoPed,@pmBodegaDev,@pmCodBodegaDev,@pmCodCias)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNat]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposNat] @pmIdNat VARCHAR(4),@pmNatlzaprod VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposNat (IdNat,Natlzaprod,Inactivo)
 VALUES (@pmIdNat,@pmNatlzaprod,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNivs]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposNivs] @pmIdNiv VARCHAR(4),@pmNivelServicio VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposNivs (IdNiv,NivelServicio,Inactivo)
 VALUES (@pmIdNiv,@pmNivelServicio,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposNom] @pmIdNom VARCHAR(4),@pmTipoNomina VARCHAR(50),@pmAsistencia BIT,@pmNoDevenga BIT
,@pmTipoLiquida CHAR(1),@pmFechaActual SMALLDATETIME,@pmInactivo BIT,@pmCdCiaInt CHAR(2),@pmLiqEspSalud BIT,@pmDctoSalud DECIMAL(14,4)
,@pmPagoSalud DECIMAL(14,4),@pmNomDiario BIT
 AS 
 INSERT INTO TiposNom (IdNom,TipoNomina,Asistencia,NoDevenga,TipoLiquida,FechaActual,Inactivo,CdCiaInt,LiqEspSalud,DctoSalud,PagoSalud,NomDiario)
 VALUES (@pmIdNom,@pmTipoNomina,@pmAsistencia,@pmNoDevenga,@pmTipoLiquida,@pmFechaActual,@pmInactivo,@pmCdCiaInt,@pmLiqEspSalud,@pmDctoSalud,@pmPagoSalud,@pmNomDiario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposNov] @pmIdNov VARCHAR(4),@pmNovedad VARCHAR(50),@pmAdmon VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO TiposNov (IdNov,Novedad,Admon,Inactivo)
 VALUES (@pmIdNov,@pmNovedad,@pmAdmon,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposOperac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposOperac] @pmIdTipoOper VARCHAR(4),@pmTipoOperacion VARCHAR(50),@pmInactivo BIT,@pmTipoIngreso VARCHAR(10),@pmTarifaIng DECIMAL(14,4)
 AS 
 INSERT INTO TiposOperac (IdTipoOper,TipoOperacion,Inactivo,TipoIngreso,TarifaIng)
 VALUES (@pmIdTipoOper,@pmTipoOperacion,@pmInactivo,@pmTipoIngreso,@pmTarifaIng)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposOperarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposOperarios] @pmIdOper VARCHAR(4),@pmTipoOperario VARCHAR(50),@pmTarifaCom DECIMAL(14,4)
,@pmGrupoOper VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO TiposOperarios (IdOper,TipoOperario,TarifaCom,Inactivo,GrupoOper)
 VALUES (@pmIdOper,@pmTipoOperario,@pmTarifaCom,@pmInactivo,@pmGrupoOper)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposPcnto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposPcnto] @pmIdTipoPre VARCHAR(4),@pmPrecinto VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposPcnto (IdTipoPre,Precinto,Inactivo)
 VALUES (@pmIdTipoPre,@pmPrecinto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposPpt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposPpt] @pmIdPpd VARCHAR(4),@pmTipoProp VARCHAR(50),@pmVehPropio BIT,@pmInactivo BIT
 AS 
 INSERT INTO TiposPpt (IdPpd,TipoProp,VehPropio,Inactivo)
 VALUES (@pmIdPpd,@pmTipoProp,@pmVehPropio,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposPrend]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposPrend] @pmIdPrend VARCHAR(4),@pmTipoPrenda VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposPrend (IdPrend,TipoPrenda,Inactivo)
 VALUES (@pmIdPrend,@pmTipoPrenda,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposProceso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposProceso] @pmIdTipProc VARCHAR(4),@pmTipoProceso VARCHAR(150),@pmDescripcion VARCHAR(1000),@pmIndOrden INT,@pmInactivo BIT
 AS 
 INSERT INTO TiposProceso (IdTipProc,TipoProceso,Descripcion,IndOrden,Inactivo)
 VALUES (@pmIdTipProc,@pmTipoProceso,@pmDescripcion,@pmIndOrden,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposRespFis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposRespFis] @pmIdResFis VARCHAR(10),@pmNomResFiscal VARCHAR(250),@pmInactivo BIT
 AS 
 INSERT INTO TiposRespFis (IdResFis,NomResFiscal,Inactivo)
 VALUES (@pmIdResFis,@pmNomResFiscal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposSustento]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposSustento] @pmIdSustento VARCHAR(4),@pmSustento VARCHAR(150),@pmInactivo BIT
 AS 
 INSERT INTO TiposSustento (IdSustento,Sustento,Inactivo)
 VALUES (@pmIdSustento,@pmSustento,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposTasas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposTasas] @pmIdTasa VARCHAR(4),@pmTipoTasa VARCHAR(50),@pmSimbolo VARCHAR(10),@pmUnidad VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposTasas (IdTasa,TipoTasa,Simbolo,Unidad,Inactivo)
 VALUES (@pmIdTasa,@pmTipoTasa,@pmSimbolo,@pmUnidad,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposTerc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposTerc] @pmIdTipoTerc VARCHAR(4),@pmTipoTercero VARCHAR(100),@pmInactivo BIT
 AS 
 INSERT INTO TiposTerc (IdTipoTerc,TipoTercero,Inactivo)
 VALUES (@pmIdTipoTerc,@pmTipoTercero,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposVeh] @pmIdTipoVeh VARCHAR(4),@pmTipoVehiculo VARCHAR(50)
,@pmConfiguracion VARCHAR(6),@pmEjes INT,@pmLlantas INT,@pmCapacPeso DECIMAL(14,4),@pmUndCapac VARCHAR(10)
,@pmCapacVol DECIMAL(14,4),@pmUndCapVol VARCHAR(10),@pmCubAlto DECIMAL(14,4),@pmCubLargo DECIMAL(14,4),@pmCubAncho DECIMAL(14,4)
,@pmPesoBruto DECIMAL(14,4),@pmInactivo BIT
 AS 
 INSERT INTO TiposVeh (IdTipoVeh,TipoVehiculo,Configuracion,Ejes,Llantas,CapacPeso,UndCapac,CapacVol,UndCapVol,CubAlto,CubLargo,CubAncho,PesoBruto,Inactivo)
 VALUES (@pmIdTipoVeh,@pmTipoVehiculo,@pmConfiguracion,@pmEjes,@pmLlantas,@pmCapacPeso,@pmUndCapac,@pmCapacVol,@pmUndCapVol,@pmCubAlto,@pmCubLargo,@pmCubAncho,@pmPesoBruto,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTiposZona]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTiposZona] @pmIdTipZona VARCHAR(4),@pmTipoZona VARCHAR(50),@pmInactivo BIT
 AS 
 INSERT INTO TiposZona (IdTipZona,TipoZona,Inactivo)
 VALUES (@pmIdTipZona,@pmTipoZona,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfAmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfAmt] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdDiferido VARCHAR(30),@pmtmCostoIni MONEY,@pmtmAdiciones MONEY,@pmtmDisminucion MONEY,@pmtmAcuAjustes MONEY,@pmtmAmortizaHis MONEY
,@pmtmAmortizaMes MONEY,@pmtmAjustesInf MONEY,@pmtmAjustesAmtza MONEY,@pmtmAmortizaAcum MONEY,@pmtmAjuAmtzaAcum MONEY,@pmtmCorrMonAcum MONEY,@pmtmBaseCorrMon MONEY,@pmtmCorrMonDif MONEY,@pmtmAmtzaHisAcum MONEY,@pmtmTarifa DECIMAL(14,4)
,@pmtmIdCia CHAR(2),@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmCdDep VARCHAR(4),@pmtmNitRespons VARCHAR(16),@pmtmNumPeriodos INT,@pmtmFechaIni SMALLDATETIME,@pmtmEstadoReg INT,@pmtmObservacion VARCHAR(150)
,@pmtmCuota DECIMAL(14,4),@pmtmGalones DECIMAL(14,4),@pmtmNitProvee VARCHAR(16),@pmtmInversion MONEY,@pmtmCdGrupo VARCHAR(4),@pmtmTipoContab VARCHAR(10)
 AS 
 INSERT INTO tm_AfAmt (tmNumero,tmItem,tmIdDiferido,tmCostoIni,tmAdiciones,tmDisminucion,tmAcuAjustes,tmAmortizaHis,tmAmortizaMes,tmAjustesInf,tmAjustesAmtza,tmAmortizaAcum,tmAjuAmtzaAcum,tmCorrMonAcum,tmBaseCorrMon,tmCorrMonDif
,tmAmtzaHisAcum,tmTarifa,tmIdCia,tmCdCCosto,tmCdSubCos,tmCdDep,tmNitRespons,tmNumPeriodos,tmFechaIni,tmEstadoReg,tmObservacion,tmCuota,tmGalones,tmNitProvee,tmInversion,tmCdGrupo,tmTipoContab)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdDiferido,@pmtmCostoIni,@pmtmAdiciones,@pmtmDisminucion,@pmtmAcuAjustes,@pmtmAmortizaHis,@pmtmAmortizaMes,@pmtmAjustesInf,@pmtmAjustesAmtza,@pmtmAmortizaAcum,@pmtmAjuAmtzaAcum
,@pmtmCorrMonAcum,@pmtmBaseCorrMon,@pmtmCorrMonDif,@pmtmAmtzaHisAcum,@pmtmTarifa,@pmtmIdCia,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmCdDep,@pmtmNitRespons,@pmtmNumPeriodos,@pmtmFechaIni,@pmtmEstadoReg,@pmtmObservacion,@pmtmCuota,@pmtmGalones,@pmtmNitProvee,@pmtmInversion,@pmtmCdGrupo,@pmtmTipoContab)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfAmt_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfAmt_Sel] @pmtmNumero VARCHAR(5),@pmNumero INT
 AS 
 INSERT INTO tm_AfAmt (tmNumero,tmItem,tmIdDiferido,tmCostoIni,tmAdiciones,tmDisminucion,tmAcuAjustes,tmAmortizaHis,tmAmortizaMes,tmAjustesInf,tmAjustesAmtza,tmAmortizaAcum
,tmAjuAmtzaAcum,tmCorrMonAcum,tmBaseCorrMon,tmCorrMonDif,tmAmtzaHisAcum,tmTarifa,tmIdCia,tmCdCCosto,tmCdSubCos,tmCdDep,tmNitRespons,tmNumPeriodos,tmFechaIni
,tmEstadoReg,tmObservacion,tmCuota,tmGalones,tmNitProvee,tmInversion,tmCdGrupo,tmTipoContab)
 SELECT @pmtmNumero,Item,DT.IdDiferido,DT.ValorTotal,DT.VrAdiciones,DT.VrDisminucion,VrAcuAjustes,VrAmortizaHis,VrAmortizaMes,VrAjustesInf,VrAjustesAmtza,VrAmortizaAcum,VrAjuAmtzaAcum
,VrCorrMonAcum,VrBaseCorrMon,VrCorrMonDif,VrAmtzaHisAcum,TarifaAju,DT.IdCia,CdCCosto,CdSubCos,CdDep,NitRespons,NPeriodos,FecInicioAmtza,1,'',CuotaGal,VentaGal,IdProv,VrInversion,CdGrupoDif,TipoContable
 FROM Trn_AfAmtDetalle AS DT INNER JOIN Diferidos AS D ON DT.IdDiferido=D.IdDiferido
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfDep] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdActivo VARCHAR(30),@pmtmCostoIni MONEY,@pmtmMejoras MONEY
,@pmtmDisminucion MONEY,@pmtmAcuAjustes MONEY,@pmtmDepreciaHis MONEY,@pmtmDepreciaMes MONEY,@pmtmAjustesInf MONEY,@pmtmAjustesDep MONEY
,@pmtmDepreciaAcum MONEY,@pmtmAjuDepAcum MONEY,@pmtmTarifa DECIMAL(14,4),@pmtmIdCia CHAR(2),@pmtmCdCCosto VARCHAR(16)
,@pmtmCdSubCos VARCHAR(16),@pmtmCdInstala VARCHAR(4),@pmtmCdDep VARCHAR(4),@pmtmNitRespons VARCHAR(16),@pmtmVidaUtil INT
,@pmtmMetodo VARCHAR(10),@pmtmFechaIni SMALLDATETIME,@pmtmEstadoReg INT,@pmtmObservacion VARCHAR(150),@pmtmCdGrupo VARCHAR(4)
,@pmtmSalvamento MONEY,@pmtmTipoContab VARCHAR(10),@pmtmPartes BIT,@pmtmUnidades INT,@pmtmCantidad INT
 AS 
 INSERT INTO tm_AfDep (tmNumero,tmItem,tmIdActivo,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepreciaHis,tmDepreciaMes,tmAjustesInf,tmAjustesDep,tmDepreciaAcum,tmAjuDepAcum,tmTarifa
,tmIdCia,tmCdCCosto,tmCdSubCos,tmCdInstala,tmCdDep,tmNitRespons,tmVidaUtil,tmMetodo,tmFechaIni,tmEstadoReg,tmObservacion,tmCdGrupo,tmSalvamento,tmTipoContab,tmPartes,tmUnidades,tmCantidad)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdActivo,@pmtmCostoIni,@pmtmMejoras,@pmtmDisminucion,@pmtmAcuAjustes,@pmtmDepreciaHis,@pmtmDepreciaMes,@pmtmAjustesInf,@pmtmAjustesDep
,@pmtmDepreciaAcum,@pmtmAjuDepAcum,@pmtmTarifa,@pmtmIdCia,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmCdInstala,@pmtmCdDep,@pmtmNitRespons,@pmtmVidaUtil,@pmtmMetodo,@pmtmFechaIni,@pmtmEstadoReg,@pmtmObservacion,@pmtmCdGrupo
,@pmtmSalvamento,@pmtmTipoContab,@pmtmPartes,@pmtmUnidades,@pmtmCantidad)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDep_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfDep_Sel] @pmtmNumero VARCHAR(5),@pmNumero INT
 AS 
 INSERT INTO tm_AfDep (tmNumero,tmItem,tmIdActivo,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepreciaHis,tmDepreciaMes,tmAjustesInf,tmAjustesDep,tmDepreciaAcum,tmAjuDepAcum,tmTarifa
,tmIdCia,tmCdCCosto,tmCdSubCos,tmCdInstala,tmCdDep,tmNitRespons,tmVidaUtil,tmMetodo,tmFechaIni,tmEstadoReg,tmObservacion,tmCdGrupo,tmSalvamento,tmTipoContab,tmPartes,tmUnidades,tmCantidad)
 SELECT @pmtmNumero,Item,IdActivo,VrCostoIni,VrMejoras,VrDisminucion,VrAcuAjustes,VrDepreciaHis,VrDepreciaMes,VrAjustesInf,VrAjustesDep,VrDepreciaAcum,VrAjuDepAcum,TarifaAju
,IdCia,CdCCosto,CdSubCos,CdInstala,CdDep,NitRespons,MesesVida,MetodoDeprec,FecIniDep,0,'',CdGrupoAct,VrSalvamnto,'0',Dep_Partes,Unidades,Cantidad
 FROM Trn_AfDetalle
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDepPartes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfDepPartes] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdActivo VARCHAR(30),@pmtmIdParte INT,@pmtmCostoIni MONEY,@pmtmMejoras MONEY,@pmtmDisminucion MONEY,@pmtmAcuAjustes MONEY,@pmtmDepreciaHis MONEY,@pmtmDepreciaMes MONEY
,@pmtmAjustesInf MONEY,@pmtmAjustesDep MONEY,@pmtmDepreciaAcum MONEY,@pmtmAjuDepAcum MONEY,@pmtmTarifa DECIMAL(14,4),@pmtmVidaUtil INT,@pmtmMetodo VARCHAR(10),@pmtmFechaIni SMALLDATETIME,@pmtmEstadoReg INT,@pmtmObservacion VARCHAR(150)
,@pmtmSalvamento MONEY,@pmtmUnidades INT,@pmtmCantidad INT
 AS 
 INSERT INTO tm_AfDepPartes (tmNumero,tmItem,tmIdActivo,tmIdParte,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepreciaHis,tmDepreciaMes,tmAjustesInf,tmAjustesDep,tmDepreciaAcum,tmAjuDepAcum,tmTarifa,tmVidaUtil,tmMetodo,tmFechaIni,tmEstadoReg,tmObservacion,tmSalvamento,tmUnidades,tmCantidad)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdActivo,@pmtmIdParte,@pmtmCostoIni,@pmtmMejoras,@pmtmDisminucion,@pmtmAcuAjustes,@pmtmDepreciaHis,@pmtmDepreciaMes,@pmtmAjustesInf,@pmtmAjustesDep,@pmtmDepreciaAcum,@pmtmAjuDepAcum,@pmtmTarifa,@pmtmVidaUtil
,@pmtmMetodo,@pmtmFechaIni,@pmtmEstadoReg,@pmtmObservacion,@pmtmSalvamento,@pmtmUnidades,@pmtmCantidad)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfDepPartesSel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfDepPartesSel] @pmtmNumero VARCHAR(5),@pmNumero INT
 AS 
 INSERT INTO tm_AfDepPartes (tmNumero,tmItem,tmIdActivo,tmIdParte,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepreciaHis,tmDepreciaMes,tmAjustesInf,tmAjustesDep,tmDepreciaAcum
,tmAjuDepAcum,tmTarifa,tmVidaUtil,tmMetodo,tmFechaIni,tmEstadoReg,tmObservacion,tmSalvamento,tmUnidades,tmCantidad)
SELECT @pmtmNumero,Item,IdActivo,IdParte,VrCostoIni,VrMejoras,VrDisminuc,VrAcumAju,VrDepHis,VrDeprecia,VrAjusteInf,VrAjuDeprec,VrDepAcum,VrAcumAjuDep
,0,Vida_Util,MetDeprec,FecIniDep,0,'',VrSalvamnto,Unidades,Cantidad
FROM Trn_AfPartes
WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfIngreso] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdActivo VARCHAR(30),@pmtmFecha SMALLDATETIME
,@pmtmVrMejoras MONEY,@pmtmVrDisminucion MONEY,@pmtmVrAjuInfAcum MONEY,@pmtmVrDepAcuHis MONEY,@pmtmVrDepAcuAju MONEY
,@pmtmVrAjuInfDep MONEY,@pmtmNumMeses INT,@pmtmVidaUtil INT,@pmtmBaseDep MONEY,@pmtmMetodo VARCHAR(10),@pmtmFecUltDep SMALLDATETIME,@pmtmConcepto VARCHAR(150)
,@pmtmUnidades INT,@pmtmSalvamento MONEY,@pmtmDepPartes BIT,@pmtmNumParte INT,@pmtmCantidad INT
 AS 
 INSERT INTO tm_AfIngreso (tmNumero,tmItem,tmIdActivo,tmFecha,tmVrMejoras,tmVrDisminucion,tmVrAjuInfAcum,tmVrDepAcuHis,tmVrDepAcuAju,tmVrAjuInfDep,tmNumMeses
,tmVidaUtil,tmBaseDep,tmMetodo,tmFecUltDep,tmConcepto,tmUnidades,tmSalvamento,tmDepPartes,tmNumParte,tmCantidad)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdActivo,@pmtmFecha,@pmtmVrMejoras,@pmtmVrDisminucion,@pmtmVrAjuInfAcum,@pmtmVrDepAcuHis,@pmtmVrDepAcuAju
,@pmtmVrAjuInfDep,@pmtmNumMeses,@pmtmVidaUtil,@pmtmBaseDep,@pmtmMetodo,@pmtmFecUltDep,@pmtmConcepto,@pmtmUnidades,@pmtmSalvamento,@pmtmDepPartes,@pmtmNumParte,@pmtmCantidad)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfIngreso_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_AfIngreso_Sel] @pmtmNumero VARCHAR(5),@pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 BEGIN
 INSERT INTO tm_AfIngreso (tmNumero,tmItem,tmIdActivo,tmFecha,tmVrMejoras,tmVrDisminucion,tmVrAjuInfAcum,tmVrDepAcuHis,tmVrDepAcuAju,tmVrAjuInfDep,tmNumMeses
,tmVidaUtil,tmBaseDep,tmMetodo,tmFecUltDep,tmConcepto,tmUnidades,tmSalvamento,tmDepPartes,tmNumParte,tmCantidad)
 SELECT  @pmtmNumero,Item,I.IdActivo,I.FecActivacion,I.VrMejoras,I.VrDisminucion,I.VrAjuInfAcum,I.VrDepAcuHis,I.VrDepAcuAju,I.VrAjuInfDep,I.NumMesesDep
,VidaUtil,VrBaseDep,MetodoDep,I.FecUltDep,Concepto,UndsProd,VrSalvamento,DepPartes,NumParte,Cantidad
 FROM Trn_AfMovIngreso AS I INNER JOIN Activos AS A ON I.IdActivo=A.IdActivo
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND I.IdCia=@pmIdCia AND A.DepPartes=0
--registros de partes
 INSERT INTO tm_AfIngreso (tmNumero,tmItem,tmIdActivo,tmFecha,tmVrMejoras,tmVrDisminucion,tmVrAjuInfAcum,tmVrDepAcuHis,tmVrDepAcuAju,tmVrAjuInfDep,tmNumMeses
,tmVidaUtil,tmBaseDep,tmMetodo,tmFecUltDep,tmConcepto,tmUnidades,tmSalvamento,tmDepPartes,tmNumParte,tmCantidad)
 SELECT  @pmtmNumero,I.Item,I.IdActivo,I.FecActivacion,I.VrMejoras,I.VrDisminucion,I.VrAjuInfAcum,I.VrDepAcuHis,I.VrDepAcuAju,I.VrAjuInfDep,I.NumMesesDep
,P.VidaUtil,P.VrBaseDep,P.MetDeprec,I.FecUltDep,Concepto,P.UndsProd,P.VrSalvamento,1,I.NumParte,I.Cantidad
 FROM Trn_AfMovIngreso AS I INNER JOIN Activos AS A ON I.IdActivo=A.IdActivo
 LEFT JOIN Activos_Partes AS P ON I.IdActivo=P.IdActivo AND I.NumParte=P.Item
 WHERE I.IdMov=@pmIdMov AND I.Numero=@pmNumero AND I.IdCia=@pmIdCia AND A.DepPartes=1
 END
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfRetiro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfRetiro] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdActivo VARCHAR(30),@pmtmIdCausal VARCHAR(4)
,@pmtmNitTercero VARCHAR(16),@pmtmNomTercero VARCHAR(150),@pmtmCostoIni MONEY,@pmtmMejoras MONEY,@pmtmDisminucion MONEY
,@pmtmAcuAjustes MONEY,@pmtmDepAcum MONEY,@pmtmAjuDepAcum MONEY,@pmtmVrIngreso MONEY,@pmtmFechaRet SMALLDATETIME
,@pmtmIdCueDeb VARCHAR(16),@pmtmIdCueIng VARCHAR(16),@pmtmConcepto VARCHAR(250),@pmtmIdCia CHAR(2)
,@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmNitRespons VARCHAR(16),@pmtmNumParte INT
 AS 
 INSERT INTO tm_AfRetiro (tmNumero,tmItem,tmIdActivo,tmIdCausal,tmNitTercero,tmNomTercero,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepAcum
,tmAjuDepAcum,tmVrIngreso,tmFechaRet,tmIdCueDeb,tmIdCueIng,tmConcepto,tmIdCia,tmCdCCosto,tmCdSubCos,tmNitRespons,tmNumParte)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdActivo,@pmtmIdCausal,@pmtmNitTercero,@pmtmNomTercero,@pmtmCostoIni,@pmtmMejoras
,@pmtmDisminucion,@pmtmAcuAjustes,@pmtmDepAcum,@pmtmAjuDepAcum,@pmtmVrIngreso,@pmtmFechaRet,@pmtmIdCueDeb,@pmtmIdCueIng
,@pmtmConcepto,@pmtmIdCia,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmNitRespons,@pmtmNumParte)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfRetiro_Dif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_AfRetiro_Dif] @pmtmNumero VARCHAR(5),@pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_AfRetiro (tmNumero,tmItem,tmIdActivo,tmIdCausal,tmNitTercero,tmNomTercero,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepAcum
,tmAjuDepAcum,tmVrIngreso,tmFechaRet,tmIdCueDeb,tmIdCueIng,tmConcepto,tmIdCia,tmCdCCosto,tmCdSubCos,tmNitRespons,tmNumParte)
 SELECT  @pmtmNumero,Item,R.IdDiferido,R.IdCausal,'0','',VrCostoIni,R.VrAdiciones,R.VrDisminucion,VrAcuAjustes,VrAmortizaAcum,VrAjuAmtzaAcum,0,FechaRet
,'','',Concepto,R.IdCia,IdCCosto,IdSubCos,IdRespons,0
 FROM Trn_AfDifRetiro AS R INNER JOIN Diferidos AS D ON R.IdDiferido=D.IdDiferido
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfRetiro_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfRetiro_Sel] @pmtmNumero VARCHAR(5),@pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_AfRetiro (tmNumero,tmItem,tmIdActivo,tmIdCausal,tmNitTercero,tmNomTercero,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepAcum
,tmAjuDepAcum,tmVrIngreso,tmFechaRet,tmIdCueDeb,tmIdCueIng,tmConcepto,tmIdCia,tmCdCCosto,tmCdSubCos,tmNitRespons,tmNumParte)
 SELECT  @pmtmNumero,Item,R.IdActivo,R.IdCausal,NitTercero,NomTercero,VrCostoIni,R.VrMejoras,R.VrDisminucion,VrAcuAjustes,VrDepAcum
,VrAjuDepAcum,VrIngreso,FechaRet,IdCueDeb,IdCueIng,Concepto,R.IdCia,IdCCosto,IdSubCos,IdRespons,NumParte
 FROM Trn_AfMovRetiro AS R INNER JOIN  Activos AS A ON R.IdActivo=A.IdActivo
 WHERE R.IdMov=@pmIdMov AND R.Numero=@pmNumero AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfTraslado] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdActivo VARCHAR(30),@pmtmIdCia CHAR(2),@pmtmIdGrupo VARCHAR(4)
,@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdInstala VARCHAR(4),@pmtmIdDep VARCHAR(4),@pmtmIdRespons VARCHAR(16)
,@pmtmCdCiaDest CHAR(2),@pmtmCdGrupoDest VARCHAR(4),@pmtmCdCCostoDest VARCHAR(16),@pmtmCdSubCosDest VARCHAR(16)
,@pmtmCdInstalaDest VARCHAR(4),@pmtmCdDepDest VARCHAR(4),@pmtmCdResponsDest VARCHAR(16),@pmtmConcepto VARCHAR(150)
,@pmtmUbicacion VARCHAR(100),@pmtmUbicacionDest VARCHAR(100)
 AS 
 INSERT INTO tm_AfTraslado (tmNumero,tmItem,tmIdActivo,tmIdCia,tmIdGrupo,tmIdCCosto,tmIdSubCos,tmIdInstala,tmIdDep,tmIdRespons,tmCdCiaDest
,tmCdGrupoDest,tmCdCCostoDest,tmCdSubCosDest,tmCdInstalaDest,tmCdDepDest,tmCdResponsDest,tmConcepto,tmUbicacion,tmUbicacionDest)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdActivo,@pmtmIdCia,@pmtmIdGrupo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdInstala,@pmtmIdDep
,@pmtmIdRespons,@pmtmCdCiaDest,@pmtmCdGrupoDest,@pmtmCdCCostoDest,@pmtmCdSubCosDest,@pmtmCdInstalaDest,@pmtmCdDepDest
,@pmtmCdResponsDest,@pmtmConcepto,@pmtmUbicacion,@pmtmUbicacionDest)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfTraslado_Dif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_AfTraslado_Dif] @pmtmNumero VARCHAR(5),@pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_AfTraslado (tmNumero,tmItem,tmIdActivo,tmIdCia,tmIdGrupo,tmIdCCosto,tmIdSubCos,tmIdInstala,tmIdDep,tmIdRespons,tmCdCiaDest
,tmCdGrupoDest,tmCdCCostoDest,tmCdSubCosDest,tmCdInstalaDest,tmCdDepDest,tmCdResponsDest,tmConcepto,tmUbicacion,tmUbicacionDest)
SELECT  @pmtmNumero,Item,IdDiferido,IdCia,IdGrupo,IdCCosto,IdSubCos,'0',IdDep,IdRespons,CdCiaDest
,CdGrupoDest,CdCCostoDest,CdSubCosDest,'0',CdDepDest,CdResponsDest,Concepto,Ubicacion,UbicacionDest
 FROM Trn_AfDifTraslado
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AfTraslado_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AfTraslado_Sel] @pmtmNumero VARCHAR(5),@pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_AfTraslado (tmNumero,tmItem,tmIdActivo,tmIdCia,tmIdGrupo,tmIdCCosto,tmIdSubCos,tmIdInstala,tmIdDep,tmIdRespons,tmCdCiaDest
,tmCdGrupoDest,tmCdCCostoDest,tmCdSubCosDest,tmCdInstalaDest,tmCdDepDest,tmCdResponsDest,tmConcepto,tmUbicacion,tmUbicacionDest)
SELECT  @pmtmNumero,Item,IdActivo,IdCia,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,CdCiaDest
,CdGrupoDest,CdCCostoDest,CdSubCosDest,CdInstalaDest,CdDepDest,CdResponsDest,Concepto,Ubicacion,UbicacionDest
 FROM Trn_AfMovTraslado
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Aportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Aportes] @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmApellido1 VARCHAR(50),@pmtmApellido2 VARCHAR(50),@pmtmNombre1 VARCHAR(50),@pmtmNombre2 VARCHAR(50),@pmtmNContto INT,@pmtmDiasPen DECIMAL(10,4),@pmtmDiasSal DECIMAL(10,4),@pmtmDiasRie DECIMAL(10,4),@pmtmDiasCom DECIMAL(10,4),@pmtmBasePen MONEY,@pmtmBaseSal MONEY,@pmtmBaseRie MONEY,@pmtmBaseCom MONEY,@pmtmBaseRef MONEY,@pmtmValorPen MONEY,@pmtmValorSal MONEY,@pmtmValorRie MONEY,@pmtmValorCom MONEY,@pmtmValorSena MONEY
,@pmtmValorIcbf MONEY,@pmtmValorFsp MONEY,@pmtmValorFsu MONEY,@pmtmValorESAP MONEY,@pmtmValorMin MONEY,@pmtmTarfaPen DECIMAL(10,4),@pmtmTarfaSal DECIMAL(10,4),@pmtmTarfaRie DECIMAL(10,4),@pmtmTarfaFsp DECIMAL(10,4),@pmtmTarfaFsu DECIMAL(10,4),@pmtmTarfaEsa DECIMAL(10,4),@pmtmTarfaMin DECIMAL(10,4),@pmtmTarfaCom DECIMAL(10,4),@pmtmTarfaIcb DECIMAL(10,4),@pmtmTarfaSen DECIMAL(10,4),@pmtmNovIng INT,@pmtmNovRet INT,@pmtmNovTda INT,@pmtmNovTaa INT,@pmtmNovTdp INT,@pmtmNovTap INT,@pmtmNovVsp INT,@pmtmNovVte INT,@pmtmNovVst INT,@pmtmNovSln INT,@pmtmNovIge INT,@pmtmNovLma INT,@pmtmNovVac INT
,@pmtmNovAvp INT,@pmtmNovIrp INT,@pmtmNovVct INT,@pmtmCodNewEps VARCHAR(8),@pmtmCodNewPen VARCHAR(8),@pmtmCodNewRie VARCHAR(8),@pmtmCodNewIns VARCHAR(4),@pmtmCodNewTar VARCHAR(4),@pmtmCodNewGru VARCHAR(4),@pmtmVrIncap MONEY,@pmtmVrLicencia MONEY,@pmtmVrVolAfi MONEY,@pmtmVrVolApo MONEY,@pmtmVrNoReten MONEY,@pmtmVrUpc MONEY,@pmtmVrIncIrp MONEY,@pmtmNAutLic VARCHAR(30),@pmtmNAutInc VARCHAR(30),@pmtmNAutIrp VARCHAR(30),@pmtmIdFonPen VARCHAR(8),@pmtmIdFonSal VARCHAR(8),@pmtmIdFonRie VARCHAR(8),@pmtmIdFonCaj VARCHAR(8),@pmtmIdInstala VARCHAR(4)
,@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVehiculo VARCHAR(10),@pmtmVrBasico MONEY,@pmtmDiasNov DECIMAL(10,4),@pmtmCdFonAvp VARCHAR(8),@pmtmDiasSan DECIMAL(14,4),@pmtmDiasDnrPen INT,@pmtmDiasDnrSal INT,@pmtmNovDsr INT,@pmtmFecNovIng SMALLDATETIME,@pmtmFecNovRet SMALLDATETIME,@pmtmFecNovVsp SMALLDATETIME,@pmtmFecIniSln SMALLDATETIME,@pmtmFecFinSln SMALLDATETIME
,@pmtmFecIniIge SMALLDATETIME,@pmtmFecFinIge SMALLDATETIME,@pmtmFecIniLma SMALLDATETIME,@pmtmFecFinLma SMALLDATETIME,@pmtmFecIniVac SMALLDATETIME,@pmtmFecFinVac SMALLDATETIME,@pmtmFecIniVct SMALLDATETIME,@pmtmFecFinVct SMALLDATETIME,@pmtmFecIniIrl SMALLDATETIME,@pmtmFecFinIrl SMALLDATETIME,@pmtmVrIBCparaf MONEY,@pmtmCantHoras INT,@pmtmTipSalario VARCHAR(10),@pmtmIdActEco VARCHAR(10)
 AS 
 INSERT INTO tm_Aportes (tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNContto,tmDiasPen,tmDiasSal,tmDiasRie,tmDiasCom,tmBasePen,tmBaseSal,tmBaseRie,tmBaseCom,tmBaseRef,tmValorPen,tmValorSal,tmValorRie,tmValorCom,tmValorSena,tmValorIcbf,tmValorFsp,tmValorFsu,tmTarfaPen,tmTarfaSal,tmTarfaRie,tmTarfaFsp,tmTarfaFsu,tmTarfaEsa,tmTarfaMin,tmTarfaCom,tmTarfaIcb,tmTarfaSen,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmCodNewEps,tmCodNewPen,tmCodNewRie,tmCodNewIns,tmCodNewTar,tmCodNewGru
,tmVrIncap,tmVrLicencia,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp,tmNAutLic,tmNAutInc,tmNAutIrp,tmIdFonPen,tmIdFonSal,tmIdFonRie,tmIdFonCaj,tmIdInstala,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVehiculo,tmVrBasico,tmDiasNov,tmValorESAP,tmValorMin,tmCdFonAvp,tmDiasSan,tmDiasDnrPen,tmDiasDnrSal,tmNovDsr,tmFecNovIng,tmFecNovRet,tmFecNovVsp,tmFecIniSln,tmFecFinSln,tmFecIniIge,tmFecFinIge,tmFecIniLma,tmFecFinLma,tmFecIniVac,tmFecFinVac,tmFecIniVct,tmFecFinVct,tmFecIniIrl,tmFecFinIrl,tmVrIBCparaf,tmCantHoras,tmTipSalario,tmIdActEco)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdEmpleado,@pmtmApellido1,@pmtmApellido2,@pmtmNombre1,@pmtmNombre2,@pmtmNContto,@pmtmDiasPen,@pmtmDiasSal,@pmtmDiasRie,@pmtmDiasCom,@pmtmBasePen,@pmtmBaseSal,@pmtmBaseRie,@pmtmBaseCom,@pmtmBaseRef,@pmtmValorPen,@pmtmValorSal,@pmtmValorRie,@pmtmValorCom,@pmtmValorSena,@pmtmValorIcbf,@pmtmValorFsp,@pmtmValorFsu,@pmtmTarfaPen,@pmtmTarfaSal,@pmtmTarfaRie,@pmtmTarfaFsp,@pmtmTarfaFsu,@pmtmTarfaEsa,@pmtmTarfaMin,@pmtmTarfaCom,@pmtmTarfaIcb,@pmtmTarfaSen,@pmtmNovIng,@pmtmNovRet,@pmtmNovTda,@pmtmNovTaa,@pmtmNovTdp,@pmtmNovTap
,@pmtmNovVsp,@pmtmNovVte,@pmtmNovVst,@pmtmNovSln,@pmtmNovIge,@pmtmNovLma,@pmtmNovVac,@pmtmNovAvp,@pmtmNovIrp,@pmtmNovVct,@pmtmCodNewEps,@pmtmCodNewPen,@pmtmCodNewRie,@pmtmCodNewIns,@pmtmCodNewTar,@pmtmCodNewGru,@pmtmVrIncap,@pmtmVrLicencia,@pmtmVrVolAfi,@pmtmVrVolApo,@pmtmVrNoReten,@pmtmVrUpc,@pmtmVrIncIrp,@pmtmNAutLic,@pmtmNAutInc,@pmtmNAutIrp,@pmtmIdFonPen,@pmtmIdFonSal,@pmtmIdFonRie,@pmtmIdFonCaj,@pmtmIdInstala,@pmtmIdDep,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmVehiculo,@pmtmVrBasico,@pmtmDiasNov,@pmtmValorESAP,@pmtmValorMin,@pmtmCdFonAvp,@pmtmDiasSan,@pmtmDiasDnrPen,@pmtmDiasDnrSal
,@pmtmNovDsr,@pmtmFecNovIng,@pmtmFecNovRet,@pmtmFecNovVsp,@pmtmFecIniSln,@pmtmFecFinSln,@pmtmFecIniIge,@pmtmFecFinIge,@pmtmFecIniLma,@pmtmFecFinLma,@pmtmFecIniVac,@pmtmFecFinVac,@pmtmFecIniVct,@pmtmFecFinVct,@pmtmFecIniIrl,@pmtmFecFinIrl,@pmtmVrIBCparaf,@pmtmCantHoras,@pmtmTipSalario,@pmtmIdActEco)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Aportes_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Aportes_Sel]  @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmtmEst VARCHAR(5)
 AS 
 INSERT INTO tm_Aportes (tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNContto,tmDiasPen,tmDiasSal,tmDiasRie,tmDiasCom,tmBasePen,tmBaseSal,tmBaseRie,tmBaseCom,tmBaseRef,tmValorPen,tmValorSal,tmValorRie,tmValorCom,tmValorSena,tmValorIcbf,tmValorFsp,tmValorFsu
,tmTarfaPen,tmTarfaSal,tmTarfaRie,tmTarfaFsp,tmTarfaFsu,tmTarfaEsa,tmTarfaMin,tmTarfaCom,tmTarfaIcb,tmTarfaSen,tmVrIncap,tmVrLicencia,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp,tmNAutLic,tmNAutInc,tmNAutIrp,tmIdFonPen,tmIdFonSal,tmIdFonRie,tmIdFonCaj,tmIdInstala,tmIdDep,tmIdCCosto
,tmIdSubCos,tmIdNom,tmVehiculo,tmVrBasico,tmValorESAP,tmValorMin,tmCdFonAvp,tmDiasSan,tmDiasDnrPen,tmDiasDnrSal,tmNovDsr,tmFecNovIng,tmFecNovRet,tmFecNovVsp,tmFecIniSln,tmFecFinSln,tmFecIniIge,tmFecFinIge,tmFecIniLma,tmFecFinLma,tmFecIniVac,tmFecFinVac,tmFecIniVct,tmFecFinVct,tmFecIniIrl,tmFecFinIrl,tmVrIBCparaf,tmCantHoras,tmTipSalario,tmIdActEco)
 SELECT @pmtmEst,Item,IdEmpleado,Apellido1,Apellido2,Nombre1,Nombre2,NContrato,DiasPen,DiasSal,DiasRie,DiasCom,VrIBCPen,VrIBCSal,VrIBCRie,VrIBCCajas,VrIBCRef,VrPension,VrSalud,VrRiesgos,VrCajas,VrSena,VrICBF,VrApoFsp,VrApoFsu,TarifPen,TarifSal,TarifRie,TarifFsp,TarifFsu,TarifEsap,TarifEdu
,TarifCom,TarifIcb,TarifSen,VrIncap,VrLicencia,VrApoVolAfi,VrApoVolApt,VrNoReten,VrUpc,VrIncIrp,NumAutLic,NumAutInc,NumAutIrp,IdFonPen,IdFonSal,IdFonRie,IdCajCom,IdInstala,'0','0','0','0','',SalBasico,VrESAP,VrMinEdu,CdFonAvp,0,0,0
,0,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,VrIBCparaf,CantHoras,TipoSalario,IdActEco
 FROM Trn_NomAlqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AutTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AutTot] @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmTipAdm VARCHAR(3),@pmtmIdFondo VARCHAR(8),@pmtmCodTipoApo CHAR(2),@pmtmTotalCot MONEY,@pmtmTotalFsp MONEY,@pmtmTotalFsu MONEY
,@pmtmTotalAva MONEY,@pmtmTotalAve MONEY,@pmtmTotalUpc MONEY,@pmtmTotalLic MONEY,@pmtmTotalInc MONEY,@pmtmTotalOtr MONEY,@pmtmDiasMora INT,@pmtmTarifMora DECIMAL(10,4),@pmtmIntMora MONEY,@pmtmIMoraOtr MONEY
,@pmtmTotalSAF MONEY,@pmtmSAFUpc MONEY,@pmtmTotalPagar MONEY,@pmtmTotalFon MONEY,@pmtmTotalAfi INT,@pmtmNumAutLic VARCHAR(30),@pmtmNumAutInc VARCHAR(30),@pmtmNumPlaSAF VARCHAR(20)
 AS 
 INSERT INTO tm_AutTot (tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar
,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF)
 VALUES (@pmtmEst,@pmtmItem,@pmtmTipAdm,@pmtmIdFondo,@pmtmCodTipoApo,@pmtmTotalCot,@pmtmTotalFsp,@pmtmTotalFsu,@pmtmTotalAva,@pmtmTotalAve,@pmtmTotalUpc,@pmtmTotalLic,@pmtmTotalInc,@pmtmTotalOtr,@pmtmDiasMora
,@pmtmTarifMora,@pmtmIntMora,@pmtmIMoraOtr,@pmtmTotalSAF,@pmtmSAFUpc,@pmtmTotalPagar,@pmtmTotalFon,@pmtmTotalAfi,@pmtmNumAutLic,@pmtmNumAutInc,@pmtmNumPlaSAF)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AutTot_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_AutTot_Sel] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmtmEst VARCHAR(5)
 AS 
 INSERT INTO tm_AutTot (tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar
,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF)
 SELECT @pmtmEst,Item,TipAdm,IdFondo,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar
,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF
 FROM Trn_NomAlqTot
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmIdCia CHAR(2),@pmtmNumLote VARCHAR(30),@pmtmSaldoAnt DECIMAL(14,4)
,@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmCostoAnt MONEY,@pmtmCostoEnt MONEY,@pmtmCostoSal MONEY,@pmtmCostoProm MONEY,@pmtmCdTanque VARCHAR(4),@pmtmVtaCant DECIMAL(14,4)
,@pmtmVtaCantDev DECIMAL(14,4),@pmtmVtaTotal MONEY,@pmtmVtaTotalDev MONEY,@pmtmVtaCosto MONEY,@pmtmVtaCostoDev MONEY,@pmtmVtaIva MONEY,@pmtmVtaIvaDev MONEY,@pmtmVtaDcto MONEY
,@pmtmVtaDctoDev MONEY,@pmtmVtaRet MONEY,@pmtmVtaRetDev MONEY,@pmtmVtaIca MONEY,@pmtmVtaIcaDev MONEY,@pmtmVtaTasa MONEY,@pmtmVtaTasaDev MONEY,@pmtmVtaGlobal MONEY
,@pmtmVtaGlobalDev MONEY,@pmtmVtaSol MONEY,@pmtmVtaSolDev MONEY,@pmtmProdCia BIT
,@pmtmUltCostoPre MONEY,@pmtmCostoAntPre MONEY,@pmtmBaseMargen VARCHAR(10),@pmtmTarifaIva DECIMAL(14,4)
,@pmtmPrecioBas1 MONEY,@pmtmPrecioBas2 MONEY,@pmtmPrecioBas3 MONEY,@pmtmPrecioBas4 MONEY,@pmtmPrecioBas5 MONEY
,@pmtmMargen1 DECIMAL(14,4),@pmtmMargen2 DECIMAL(14,4),@pmtmMargen3 DECIMAL(14,4),@pmtmMargen4 DECIMAL(14,4),@pmtmMargen5 DECIMAL(14,4)
,@pmtmDcto1 DECIMAL(14,4),@pmtmDcto2 DECIMAL(14,4),@pmtmDcto3 DECIMAL(14,4),@pmtmDcto4 DECIMAL(14,4),@pmtmDcto5 DECIMAL(14,4)
,@pmtmIncIva1 BIT,@pmtmIncIva2 BIT,@pmtmIncIva3 BIT,@pmtmIncIva4 BIT,@pmtmIncIva5 BIT
,@pmtmPrecioVta1 MONEY,@pmtmPrecioVta2 MONEY,@pmtmPrecioVta3 MONEY,@pmtmPrecioVta4 MONEY,@pmtmPrecioVta5 MONEY
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdBodega,tmIdCia,tmNumLote,tmSaldoAnt,tmEntradas,tmSalidas,tmCostoAnt,tmCostoEnt,tmCostoSal,tmCostoProm,tmCdTanque,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev
,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev,tmProdCia
,tmUltCostoPre,tmCostoAntPre,tmBaseMargen,tmTarifaIva,tmPrecioBas1,tmPrecioBas2,tmPrecioBas3,tmPrecioBas4,tmPrecioBas5,tmMargen1,tmMargen2,tmMargen3,tmMargen4,tmMargen5
,tmDcto1,tmDcto2,tmDcto3,tmDcto4,tmDcto5,tmIncIva1,tmIncIva2,tmIncIva3,tmIncIva4,tmIncIva5,tmPrecioVta1,tmPrecioVta2,tmPrecioVta3,tmPrecioVta4,tmPrecioVta5)
 VALUES (@pmtmEst,@pmtmIdProducto,@pmtmIdBodega,@pmtmIdCia,@pmtmNumLote,@pmtmSaldoAnt,@pmtmEntradas,@pmtmSalidas,@pmtmCostoAnt,@pmtmCostoEnt,@pmtmCostoSal,@pmtmCostoProm,@pmtmCdTanque
,@pmtmVtaCant,@pmtmVtaCantDev,@pmtmVtaTotal,@pmtmVtaTotalDev,@pmtmVtaCosto,@pmtmVtaCostoDev,@pmtmVtaIva,@pmtmVtaIvaDev,@pmtmVtaDcto,@pmtmVtaDctoDev,@pmtmVtaRet,@pmtmVtaRetDev
,@pmtmVtaIca,@pmtmVtaIcaDev,@pmtmVtaTasa,@pmtmVtaTasaDev,@pmtmVtaGlobal,@pmtmVtaGlobalDev,@pmtmVtaSol,@pmtmVtaSolDev,@pmtmProdCia
,@pmtmUltCostoPre,@pmtmCostoAntPre,@pmtmBaseMargen,@pmtmTarifaIva,@pmtmPrecioBas1,@pmtmPrecioBas2,@pmtmPrecioBas3,@pmtmPrecioBas4,@pmtmPrecioBas5,@pmtmMargen1,@pmtmMargen2,@pmtmMargen3,@pmtmMargen4,@pmtmMargen5
,@pmtmDcto1,@pmtmDcto2,@pmtmDcto3,@pmtmDcto4,@pmtmDcto5,@pmtmIncIva1,@pmtmIncIva2,@pmtmIncIva3,@pmtmIncIva4,@pmtmIncIva5,@pmtmPrecioVta1,@pmtmPrecioVta2,@pmtmPrecioVta3,@pmtmPrecioVta4,@pmtmPrecioVta5)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_Sel] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDetCia BIT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 IF @pmDetCia <>0
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,IdCia,'0','0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia
 ELSE
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,'00','0','0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelBod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelBod] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDetCia BIT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 IF @pmDetCia <>0
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,IdCia,K.IdBodega,'0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia,K.IdBodega
 ELSE
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,'00',K.IdBodega,'0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,K.IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelIns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelIns] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDetCia BIT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 IF @pmDetCia <>0
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,IdCia,'0','0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND TipoRef='INSUMO'
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia
 ELSE
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,'00','0','0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipoRef='INSUMO' 
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelInsBod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelInsBod] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDetCia BIT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 IF @pmDetCia <>0
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,IdCia,K.IdBodega,'0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND TipoRef='INSUMO'
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia,K.IdBodega
 ELSE
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,'00',K.IdBodega,'0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipoRef='INSUMO' 
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,K.IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelTanq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelTanq] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDetCia BIT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 IF @pmDetCia <>0
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,IdCia,CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS CdBodga,'0'
 ,CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS NumTanque
 ,SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND Tanques<>0 AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia,CdTanque
 ELSE
  INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal)
  SELECT @pmtmEst,K.IdProducto,'00',CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS CdBodga
  ,'0',CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS NumTanque
  ,SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND Tanques<>0 AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelVen] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal
 ,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev
 ,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev) 
 SELECT @pmtmEst,K.IdProducto,'00','0','0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
--variables de ventas
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Salidas ELSE 0 END ) AS VtaCant
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Entradas ELSE 0 END ) AS VtaCantDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrPrecio*(Salidas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrPrecio*(Entradas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrCostoSal ELSE 0 END ) AS VtaCosto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrCostoEnt ELSE 0 END ) AS VtaCostoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIvaSal ELSE 0 END ) AS VtaIva
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIvaEnt ELSE 0 END ) AS VtaIvaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrDctoSal ELSE 0 END ) AS VtaDcto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrDctoEnt ELSE 0 END ) AS VtaDctoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrReteSal ELSE 0 END ) AS VtaRet
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrReteEnt ELSE 0 END ) AS VtaRetDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIcaSal ELSE 0 END ) AS VtaIca
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIcaEnt ELSE 0 END ) AS VtaIcaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Sobretasa*Salidas ELSE 0 END ) AS VtaTasa
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Sobretasa*Entradas ELSE 0 END ) AS VtaTasaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN ImpGlobal*Salidas ELSE 0 END ) AS VtaGlobal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN ImpGlobal*Entradas ELSE 0 END ) AS VtaGlobalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Soldicom*Salidas ELSE 0 END ) AS VtaSol
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Soldicom*Entradas ELSE 0 END ) AS VtaSolDev
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenBod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelVenBod] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal
 ,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev
 ,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev) 
 SELECT @pmtmEst,K.IdProducto,'00',K.IdBodega,'0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
--variables de ventas
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Salidas ELSE 0 END ) AS VtaCant
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Entradas ELSE 0 END ) AS VtaCantDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrPrecio*(Salidas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrPrecio*(Entradas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrCostoSal ELSE 0 END ) AS VtaCosto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrCostoEnt ELSE 0 END ) AS VtaCostoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIvaSal ELSE 0 END ) AS VtaIva
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIvaEnt ELSE 0 END ) AS VtaIvaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrDctoSal ELSE 0 END ) AS VtaDcto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrDctoEnt ELSE 0 END ) AS VtaDctoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrReteSal ELSE 0 END ) AS VtaRet
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrReteEnt ELSE 0 END ) AS VtaRetDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIcaSal ELSE 0 END ) AS VtaIca
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIcaEnt ELSE 0 END ) AS VtaIcaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Sobretasa*Salidas ELSE 0 END ) AS VtaTasa
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Sobretasa*Entradas ELSE 0 END ) AS VtaTasaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN ImpGlobal*Salidas ELSE 0 END ) AS VtaGlobal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN ImpGlobal*Entradas ELSE 0 END ) AS VtaGlobalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Soldicom*Salidas ELSE 0 END ) AS VtaSol
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Soldicom*Entradas ELSE 0 END ) AS VtaSolDev
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,K.IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenBodCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelVenBodCia] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal
 ,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev
 ,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev) 
 SELECT @pmtmEst,K.IdProducto,IdCia,K.IdBodega,'0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
--variables de ventas
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Salidas ELSE 0 END ) AS VtaCant
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Entradas ELSE 0 END ) AS VtaCantDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrPrecio*(Salidas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrPrecio*(Entradas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrCostoSal ELSE 0 END ) AS VtaCosto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrCostoEnt ELSE 0 END ) AS VtaCostoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIvaSal ELSE 0 END ) AS VtaIva
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIvaEnt ELSE 0 END ) AS VtaIvaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrDctoSal ELSE 0 END ) AS VtaDcto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrDctoEnt ELSE 0 END ) AS VtaDctoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrReteSal ELSE 0 END ) AS VtaRet
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrReteEnt ELSE 0 END ) AS VtaRetDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIcaSal ELSE 0 END ) AS VtaIca
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIcaEnt ELSE 0 END ) AS VtaIcaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Sobretasa*Salidas ELSE 0 END ) AS VtaTasa
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Sobretasa*Entradas ELSE 0 END ) AS VtaTasaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN ImpGlobal*Salidas ELSE 0 END ) AS VtaGlobal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN ImpGlobal*Entradas ELSE 0 END ) AS VtaGlobalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Soldicom*Salidas ELSE 0 END ) AS VtaSol
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Soldicom*Entradas ELSE 0 END ) AS VtaSolDev
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia,K.IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelVenCia] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal
 ,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev
 ,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev) 
 SELECT @pmtmEst,K.IdProducto,IdCia,'0','0','0',SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
--variables de ventas
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Salidas ELSE 0 END ) AS VtaCant
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Entradas ELSE 0 END ) AS VtaCantDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrPrecio*(Salidas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrPrecio*(Entradas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrCostoSal ELSE 0 END ) AS VtaCosto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrCostoEnt ELSE 0 END ) AS VtaCostoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIvaSal ELSE 0 END ) AS VtaIva
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIvaEnt ELSE 0 END ) AS VtaIvaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrDctoSal ELSE 0 END ) AS VtaDcto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrDctoEnt ELSE 0 END ) AS VtaDctoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrReteSal ELSE 0 END ) AS VtaRet
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrReteEnt ELSE 0 END ) AS VtaRetDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIcaSal ELSE 0 END ) AS VtaIca
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIcaEnt ELSE 0 END ) AS VtaIcaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Sobretasa*Salidas ELSE 0 END ) AS VtaTasa
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Sobretasa*Entradas ELSE 0 END ) AS VtaTasaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN ImpGlobal*Salidas ELSE 0 END ) AS VtaGlobal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN ImpGlobal*Entradas ELSE 0 END ) AS VtaGlobalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Soldicom*Salidas ELSE 0 END ) AS VtaSol
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Soldicom*Entradas ELSE 0 END ) AS VtaSolDev
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenTanq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelVenTanq] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal
 ,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev
 ,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev) 
 SELECT @pmtmEst,K.IdProducto,'00',CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS CdBodga,'0'
,CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS NumTanque
,SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
--variables de ventas
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Salidas ELSE 0 END ) AS VtaCant
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Entradas ELSE 0 END ) AS VtaCantDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrPrecio*(Salidas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrPrecio*(Entradas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrCostoSal ELSE 0 END ) AS VtaCosto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrCostoEnt ELSE 0 END ) AS VtaCostoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIvaSal ELSE 0 END ) AS VtaIva
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIvaEnt ELSE 0 END ) AS VtaIvaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrDctoSal ELSE 0 END ) AS VtaDcto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrDctoEnt ELSE 0 END ) AS VtaDctoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrReteSal ELSE 0 END ) AS VtaRet
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrReteEnt ELSE 0 END ) AS VtaRetDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIcaSal ELSE 0 END ) AS VtaIca
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIcaEnt ELSE 0 END ) AS VtaIcaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Sobretasa*Salidas ELSE 0 END ) AS VtaTasa
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Sobretasa*Entradas ELSE 0 END ) AS VtaTasaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN ImpGlobal*Salidas ELSE 0 END ) AS VtaGlobal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN ImpGlobal*Entradas ELSE 0 END ) AS VtaGlobalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Soldicom*Salidas ELSE 0 END ) AS VtaSol
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Soldicom*Entradas ELSE 0 END ) AS VtaSolDev
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND Tanques<>0 AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInv_SelVenTanqCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInv_SelVenTanqCia] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdCia,tmIdBodega,tmNumLote,tmCdTanque,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal
 ,tmVtaCant,tmVtaCantDev,tmVtaTotal,tmVtaTotalDev,tmVtaCosto,tmVtaCostoDev,tmVtaIva,tmVtaIvaDev,tmVtaDcto,tmVtaDctoDev
 ,tmVtaRet,tmVtaRetDev,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev) 
 SELECT @pmtmEst,K.IdProducto,IdCia,CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS CdBodga
,'0',CASE CdTanque WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdTanque  END AS NumTanque
,SUM(Entradas),SUM(Salidas),SUM(VrCostoEnt),SUM(VrCostoSal)
--variables de ventas
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Salidas ELSE 0 END ) AS VtaCant
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Entradas ELSE 0 END ) AS VtaCantDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrPrecio*(Salidas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrPrecio*(Entradas-ISNULL(CantObseq,0)) ELSE 0 END ) AS VtaTotalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrCostoSal ELSE 0 END ) AS VtaCosto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrCostoEnt ELSE 0 END ) AS VtaCostoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIvaSal ELSE 0 END ) AS VtaIva
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIvaEnt ELSE 0 END ) AS VtaIvaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrDctoSal ELSE 0 END ) AS VtaDcto
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrDctoEnt ELSE 0 END ) AS VtaDctoDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrReteSal ELSE 0 END ) AS VtaRet
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrReteEnt ELSE 0 END ) AS VtaRetDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN VrIcaSal ELSE 0 END ) AS VtaIca
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN VrIcaEnt ELSE 0 END ) AS VtaIcaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Sobretasa*Salidas ELSE 0 END ) AS VtaTasa
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Sobretasa*Entradas ELSE 0 END ) AS VtaTasaDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN ImpGlobal*Salidas ELSE 0 END ) AS VtaGlobal
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN ImpGlobal*Entradas ELSE 0 END ) AS VtaGlobalDev
,SUM(CASE WHEN NoVentas IN (1,3,5) THEN Soldicom*Salidas ELSE 0 END ) AS VtaSol
,SUM(CASE WHEN NoVentas IN (2,4,6) THEN Soldicom*Entradas ELSE 0 END ) AS VtaSolDev
  FROM Trn_Kardex  AS K INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND TipoRef<>'INSUMO'  AND Tanques<>0 AND  TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY K.IdProducto,IdCia,CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paInstm_AuxInvSan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_AuxInvSan] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmIdCia CHAR(2),@pmtmNumLote VARCHAR(30),@pmtmSaldoAnt DECIMAL(14,4)
,@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmCostoAnt MONEY,@pmtmCostoEnt MONEY,@pmtmCostoSal MONEY,@pmtmCostoProm MONEY,@pmtmCdTanque VARCHAR(4)
 AS 
 INSERT INTO tm_AuxInv (tmEst,tmIdProducto,tmIdBodega,tmIdCia,tmNumLote,tmSaldoAnt,tmEntradas,tmSalidas,tmCostoAnt,tmCostoEnt,tmCostoSal,tmCostoProm,tmCdTanque)
 VALUES (@pmtmEst,@pmtmIdProducto,@pmtmIdBodega,@pmtmIdCia,@pmtmNumLote,@pmtmSaldoAnt,@pmtmEntradas,@pmtmSalidas,@pmtmCostoAnt,@pmtmCostoEnt,@pmtmCostoSal,@pmtmCostoProm,@pmtmCdTanque)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalAcum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_BalAcum] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT,@pmtmIdCia CHAR(2),@pmtmIdTercero VARCHAR(16)
,@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmCodAgncia VARCHAR(16),@pmtmTipo VARCHAR(4)
,@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY
 AS 
 INSERT INTO tm_BalAcum (tmEst,tmIdCuenta,tmItem,tmIdCia,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmItem,@pmtmIdCia,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmCodAgncia
,@pmtmTipo,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_BalCom] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT,@pmtmIdTercero VARCHAR(16)
,@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmCodAgncia VARCHAR(16)
,@pmtmTipo VARCHAR(4),@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY
,@pmtmVrPresupto MONEY,@pmtmVrCompras MONEY
 AS 
 INSERT INTO tm_BalCom (tmEst,tmIdCuenta,tmItem,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior
,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo,tmVrPresupto,tmVrCompras)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmItem,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmCodAgncia
,@pmtmTipo,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmNuevoSaldo,@pmtmVrPresupto,@pmtmVrCompras)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCom_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_BalCom_Sel] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCCosto VARCHAR(16)=Null
,@pmIdSubCos VARCHAR(16)=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null
AS
 IF @pmCueIni IS NULL --NO RANGOS
  INSERT INTO tm_BalCom (tmEst,tmIdCuenta,tmItem,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmNuevoSaldo,tmTotalDebitos,tmTotalCreditos)
  SELECT @pmtmEst,IdCuenta,0,'0','0','0','0','0','0',0,0,SUM(VrDebito),SUM(VrCredito)
  FROM   Trn_ComDetalle
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  GROUP BY  IdCuenta
 ELSE --RANGOS 
  INSERT INTO tm_BalCom (tmEst,tmIdCuenta,tmItem,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmNuevoSaldo,tmTotalDebitos,tmTotalCreditos)
  SELECT @pmtmEst,IdCuenta,0,'0','0','0','0','0','0',0,0,SUM(VrDebito),SUM(VrCredito)
  FROM   Trn_ComDetalle
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCuenta BETWEEN @pmCueIni AND @pmCueFin
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
 AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  GROUP BY  IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCom_SelAcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_BalCom_SelAcc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCCosto VARCHAR(16)=Null
,@pmIdSubCos VARCHAR(16)=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null
AS
--terceros Accionistas
 IF @pmCueIni IS NULL --NO RANGOS
  INSERT INTO tm_BalCom (tmEst,tmIdCuenta,tmItem,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmNuevoSaldo,tmTotalDebitos,tmTotalCreditos)
  SELECT @pmtmEst,IdCuenta,0,'0','0','0','0','0','0',0,0,SUM(VrDebito),SUM(VrCredito)
  FROM   Trn_ComDetalle AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (EsAccnista<>0 OR D.IdTercero='0') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  GROUP BY  IdCuenta
 ELSE --RANGOS 
  INSERT INTO tm_BalCom (tmEst,tmIdCuenta,tmItem,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmNuevoSaldo,tmTotalDebitos,tmTotalCreditos)
  SELECT @pmtmEst,IdCuenta,0,'0','0','0','0','0','0',0,0,SUM(VrDebito),SUM(VrCredito)
  FROM   Trn_ComDetalle AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (EsAccnista<>0 OR D.IdTercero='0') AND IdCuenta BETWEEN @pmCueIni AND @pmCueFin
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
 AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  GROUP BY  IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalCompara]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_BalCompara] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT,@pmtmIdCia CHAR(2),@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmCodAgncia VARCHAR(16)
,@pmtmTipo VARCHAR(4),@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY,@pmtmSalAnt3 MONEY,@pmtmDebitos3 MONEY
,@pmtmCreditos3 MONEY,@pmtmSaldo3 MONEY
 AS 
 INSERT INTO tm_BalCompara (tmEst,tmIdCuenta,tmItem,tmIdCia,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmSalAnt3,tmDebitos3,tmCreditos3,tmSaldo3)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmItem,@pmtmIdCia,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmCodAgncia,@pmtmTipo,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmNuevoSaldo,@pmtmSalAnt2,@pmtmDebitos2
,@pmtmCreditos2,@pmtmSaldo2,@pmtmSalAnt3,@pmtmDebitos3,@pmtmCreditos3,@pmtmSaldo3)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalGen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_BalGen] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2),@pmtmSaldoAnterior MONEY
,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY
,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY
 AS 
 INSERT INTO tm_BalGen (tmEst,tmIdCuenta,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmIdCia,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmNuevoSaldo,@pmtmSalAnt2
,@pmtmDebitos2,@pmtmCreditos2,@pmtmSaldo2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_BalGen_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_BalGen_Sel] @pmtmEst CHAR(2),@pmNiv INT,@pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT,@pmDetCia BIT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmCue8 VARCHAR(1)=Null,@pmCue9 VARCHAR(1)=Null
 AS 
 IF @pmDetCia <>0 --Detalle por compañias 
  INSERT INTO tm_BalGen (tmEst,tmIdCuenta,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
 ,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2)
  SELECT @pmtmEst,SUBSTRING(A.IdCuenta,1,@pmNiv),IdCia,SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  ,SUM(SaldoAnterior+TotalDebitos-TotalCreditos),0,0,0,0
 FROM  AcuCuentas AS A INNER JOIN  Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes BETWEEN @pmnMesIni AND @pmnMesFin
 AND Movimiento<>0 AND SUBSTRING(A.IdCuenta,1,1) IN ('1','2','3',@pmCue8,@pmCue9)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),IdCia
 ELSE
  INSERT INTO tm_BalGen (tmEst,tmIdCuenta,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
 ,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2)
  SELECT @pmtmEst,SUBSTRING(A.IdCuenta,1,@pmNiv),'00',SUM(SaldoAnterior),SUM(TotalDebitos),SUM(TotalCreditos)
  ,SUM(SaldoAnterior+TotalDebitos-TotalCreditos),0,0,0,0
 FROM  AcuCuentas AS A INNER JOIN  Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes BETWEEN @pmnMesIni AND @pmnMesFin
 AND Movimiento<>0 AND SUBSTRING(A.IdCuenta,1,1) IN ('1','2','3',@pmCue8,@pmCue9)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Ant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Ant] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,7,TipDoc,Anticipo,IdCia,Fecha,IdConcepto,IdPoseedor,'0',VrAnticipo,0,0,0,0,0,0,0,0,VrAnticipo AS ValNeto,CASE TipoPago WHEN 'EFECTIVO' THEN VrAnticipo ELSE 0 END
,0,0,0,0,0,0,0,CASE TipoPago WHEN 'EFECTIVO' THEN 1 ELSE 0 END,CASE TipoPago WHEN 'EFECTIVO' THEN 'EFE' ELSE 'CHE' END,NumCheque,IdBanco,SUBSTRING(Beneficiario,1,150),A.IdCta,FecCheque,IdConductor,0,'0',IdUsuario,'0','ANTICIPOS',''
,Modalidad,IdVehiculo,TipMuc,Manifiesto,IdCiaMuc,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_TraAnticipos AS A LEFT JOIN CtasCorrientes AS CT ON A.IdCta=CT.IdCta
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipoPago='EFECTIVO'
 AND A.IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Aos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Aos] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,7,A.TipDoc,A.Anticipo,A.IdCia,A.Fecha,A.IdConcepto,O.IdPoseedor,O.IdAgencia,A.VrAnticipo,0,0,0,0,0,0,0,0,A.VrAnticipo AS ValNeto,CASE A.TipoPago WHEN 'EFECTIVO' THEN A.VrAnticipo ELSE 0 END
,0,0,0,0,0,0,0,CASE A.TipoPago WHEN 'EFECTIVO' THEN 1 ELSE 0 END,CASE A.TipoPago WHEN 'EFECTIVO' THEN 'EFE' ELSE 'CHE' END,A.NumCheque,IdBanco,SUBSTRING(A.Beneficiario,1,150),A.IdCta,A.FecCheque,ISNULL(A.CedBenef,'0'),0,'0',A.IdUsuario,'0','ANTICIPOS',''
,'EGRESO',O.IdVehiculo,A.TipOds,A.NumOrden,A.IdCiaOds,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado,A.NumDev,A.FecDev,A.Observacion,A.TimeSys
 FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 LEFT JOIN CtasCorrientes AS CT ON A.IdCta=CT.IdCta
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipoPago='EFECTIVO'
 AND A.IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Cns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Cns] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,5,TipDoc,Consignacion,IdCia,Fecha,IdConcepto,IdCliente,'0',VrTotal,0,0,0,VrOtros,0,0,0,0,VrEfectivo AS ValNeto,VrEfectivo
,0,0,0,0,0,0,0,EnEfectivo,'EFE',NumConsigna,'0',Depositante,IdCta,Null,NitDeptante,0,'0',IdCajero,'0',Referencia,Referncia2
,'CONSIGNA','','',0,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Consigna
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dao]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Dao] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,7,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,O.IdPoseedor,O.IdAgencia,D.VrDevolucion,0,0,0,0,0,0,0,0,D.VrDevolucion AS ValNeto,CASE A.TipoPago WHEN 'EFECTIVO' THEN D.VrDevolucion ELSE 0 END
,0,0,0,0,0,0,0,CASE A.TipoPago WHEN 'EFECTIVO' THEN 1 ELSE 0 END,CASE A.TipoPago WHEN 'EFECTIVO' THEN 'EFE' ELSE 'CHE' END,A.NumCheque,IdBanco,SUBSTRING(A.Beneficiario,1,150),D.CdCta,A.FecCheque,ISNULL(A.CedBenef,'0'),0,'0',D.IdUsuario,'0','ANTICIPOS',''
,'EGRESO',O.IdVehiculo,A.TipOds,A.NumOrden,A.IdCiaOds,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Anticipo,D.FecDoc,D.Observacion,D.TimeSys
 FROM Trn_TraDevAos AS D INNER JOIN Trn_TraOrdenAnt AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 LEFT JOIN CtasCorrientes AS CT ON D.CdCta=CT.IdCta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipoPago='EFECTIVO'
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dfo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Dfo] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.NitCliente,D.CdAgencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto+D.VrImpCons,D.VrRetencion+D.VrReteICA+D.VrReteIVA,D.VrFletes,D.VrCargos,D.VrOtrDcto,0,0,D.VrNeto,D.VrEfectivo
,D.VrPagosOtr,0,0,0,D.Cantidad,D.CantPuntos,0,D.EnEfectivo,F.CdForma,F.NumForma,F.CdBanco,SUBSTRING(F.DetallePago,1,150),'0',D.FecPedido,D.IdVend,D.TarifaCom,D.nClieCon,D.IdCajero,D.IdLocal,Referncia1,Referncia2
,D.Modalidad,'','PED',D.Pedido,D.IdCiaPed,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Factura,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_DevFco AS D INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dnp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Dnp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,0,VrSobretasa,0,0,0,0,VrImpGlobal,VrOtros,VrNeto,VrNeto,0,0,0,0,Cantidad
,0,0,1,'EFE','','0','','0',Null,IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','NOTACALIB','','0',0,'00',TipCom,Comprobante,IdCiaCom,0,nNota,FecDoc,Observacion,TimeSys
 FROM Trn_DevPas
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Drc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Drc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,CASE TipDoc WHEN 'RCO' THEN 3 ELSE 4 END,TipDev,Devolucion,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrTotal,0,0,0,0,VrTotDebito,VrTotCredito,0,0,VrEfectivo AS ValNeto,VrEfectivo
,0,0,0,0,0,0,0,EnEfectivo,'EFE',NumForma,CdBanco,'',CdCta,Null,'0',0,'0',IdCajero,'0',Referencia,'','RECIBOS','','',0,'00',TipCom,Comprobante,IdCiaCom,0,Recibo,FecDoc,Observacion,TimeSys
 FROM Trn_DevCaj
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dva]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Dva] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,7,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdPoseedor,'0',VrDevolucion,0,0,0,0,0,0,0,0,VrDevolucion AS ValNeto,CASE A.TipoPago WHEN 'EFECTIVO' THEN VrDevolucion ELSE 0 END
,0,0,0,0,0,0,0,CASE A.TipoPago WHEN 'EFECTIVO' THEN 1 ELSE 0 END,CASE A.TipoPago WHEN 'EFECTIVO' THEN 'EFE' ELSE 'CHE' END,NumCheque,IdBanco,SUBSTRING(A.Beneficiario,1,150),D.CdCta,A.FecCheque,D.IdConductor,0,'0',D.IdUsuario,'0','ANTICIPOS',''
,A.Modalidad,D.IdVehiculo,A.TipMuc,A.Manifiesto,A.IdCiaMuc,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Anticipo,D.FecDoc,D.Observacion,D.TimeSys
 FROM Trn_TraDevAnt AS D INNER JOIN Trn_TraAnticipos AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 LEFT JOIN CtasCorrientes AS CT ON D.CdCta=CT.IdCta
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipoPago='EFECTIVO'
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Dvc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,5,TipDev,Devolucion,IdCia,Fecha,IdConcepto,IdCliente,'0',VrTotal,0,0,0,VrOtros,0,0,0,0,VrEfectivo AS ValNeto,VrEfectivo
,0,0,0,0,0,0,0,EnEfectivo,'EFE',NumConsigna,'0','',IdCta,Null,'0',0,'0',IdCajero,'0',Referencia,Referncia2
,ModdDev,'','',0,'00',TipCom,Comprobante,IdCiaCom,0,Consignacion,FecDoc,Observacion,TimeSys
 FROM Trn_DevCns
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Dvp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Dvp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,VrConDcto+VrCreDcto,VrSobretasa,0,VrCreTotal+VrConTotal+VrCreImp+VrConImp,VrSobrantes,VrFaltantes,VrImpGlobal,VrOtros,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,0,0,0,'EFE','','0','','0',FecCorte,IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'',Modalidad,'','COR',NumCorte,'00'
,TipCom,Comprobante,IdCiaCom,0,Planilla,FecDoc,Observacion,TimeSys
 FROM Trn_DevPla
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Egr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Egr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,6,TipCom,Comprobante,IdCia,Fecha,'0',IdTercero,'0',VrTotal,0,0,0,0,0,0,0,0,VrTotal AS ValNeto,CASE EnEfectivo WHEN 1 THEN VrTotal ELSE 0 END
,0,0,0,0,0,0,0,EnEfectivo,CASE EnEfectivo WHEN 1 THEN  'EFE' ELSE 'CHE' END,NumCheque,IdBanco,SUBSTRING(Beneficiario,1,150),C.IdCta,FecCheque,'0',0,'0',IdUsuario,'0','',''
,'EGRESO',pVehiculo,TipDoc,Documento,IdCiaDoc,CASE WHEN TipEgr IS NULL OR LEN(TipEgr)=0 THEN '0' ELSE TipEgr END ,NEgreso,'00',Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Comprobantes AS C LEFT JOIN CtasCorrientes AS CT ON C.IdCta=CT.IdCta
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsEgreso=1 AND Anticipo=0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Fco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Fco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,1,TipDoc,Factura,IdCia,Fecha,IdConcepto,NitCliente,CdAgencia,VrSubTotal,VrDescuento,VrImpuesto+VrImpCons,VrRetencion+VrReteICA+VrReteIVA,VrFletes,VrCargos,VrOtrDcto,0,0,VrNeto,VrEfectivo
,VrPagosOtr,0,0,0,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,SUBSTRING(DetallePago,1,150),'0',FecPedido,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referncia1,Referncia2
,Modalidad,'',TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Factcon
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Not]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Not] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,7,TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,0,VrImpuesto,VrRetencion+VrReteICA+VrReteIVA,VrSancion,0,0,0,0,VrOtros AS ValNeto,VrOtros
,0,0,0,0,Cantidad,0,0,1,CdForma,NumCheque,CdBanco,'','0',FecDcm,IdVend,TarifaCom,'0',CdCajero,IdLocal,Referencia,''
,Modalidad,pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,0,0,Null,Observacion,TimeSys
 FROM Trn_Notas
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND PrestCaja<>0 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND CdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_NotBus]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_NotBus] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,7,TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,ValorTotal,0,ValorIva,ValorReteFte+ValorReteIca,ValorSancion,0,0,0,0,ValorNeto ,ValorNeto
,0,0,0,0,0,0,0,1,'EFE',NumCheque,IdBanco,'','0',FecVence,IdVendedor,Comision,'0',IdUsuario,'0',Referencia,''
,'CAJA',IdVehiculo,TipDcm,Documento,IdCiaDoc,TipCom,Comprobante,IdCiaCom,0,0,Null,Observacion,TimeSys
 FROM Trn_NotasBuses
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND PrestCaja<>0 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Od1]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Od1] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,2,TipDev, Devolucion, D.IdCia, D.Fecha, D.IdConcepto,D.IdCliente, D.IdAgencia,D.ValorTotal, D.ValorDcto,D.ValorReteIva,D.ValorReteFte+D.ValorReteIca,D.ValorPagMas,D.ValorOtros,D.ValorOtrosDct,0,D.ValorAhorro,D.ValorNeto,0
,0,0,0,0,R.NPasajeros,0,0,D.EnEfectivo,'EFE',D.NumCheque,D.IdBanco,'',D.IdCta,D.FecDoc, D.IdVendedor, D.Comision,'0',D.IdUsuario,'0',R.Referencia,'',D.Modalidad,D.IdVehiculo,D.TipDoc, D.Recibo, D.IdCiaDoc,D.TipCom, D.Comprobante, D.IdCiaCom,0,0,Null, D.Observacion,D.TimeSys
 FROM Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Od2]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Od2] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,2,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,D.VrSubTotal,0,D.VrReteIVA,D.VrRetencion+D.VrReteICA,D.VrPagosMas,D.VrOtros,D.VrOtrDcto,0,0,D.VrNeto,D.VrEfectivo
,0,0,0,0,0,0,0,D.EnEfectivo,CdForma,NumForma,CdBanco,SUBSTRING(DetallePago,1,150),CdCta,D.FecPago,D.IdVend,D.TarifaCom,'0',D.IdUsuario,'0',D.Referencia,''
,'RC2',R.pVehiculo,R.TipDcm,R.Documento,R.IdCiaDcm,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Recibo,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_FinDevRec AS D INNER JOIN Trn_FinRecibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Odb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Odb] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,2,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,D.VrSubTotal,D.VrDescuento,D.VrReteIVA,D.VrRetencion+D.VrReteICA,D.VrPagosMas,D.VrOtros,D.VrOtrDcto,0,D.VrAhorro,D.VrNeto,D.VrEfectivo
,0,0,0,0,0,0,0,D.EnEfectivo,CdForma,NumForma,CdBanco,SUBSTRING(DetallePago,1,150),CdCta,D.FecPago,D.IdVend,D.TarifaCom,'0',D.IdCajero,D.IdLocal,D.Referencia,''
,D.Modalidad,D.pVehiculo,D.TipDcm,D.Documento,D.IdCiaDcm,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Recibo,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_DevRec AS D INNER JOIN Trn_Recibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Pas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Pas] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDoc,nNota,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,0,VrSobretasa,0,0,0,0,VrImpGlobal,VrOtros,VrNeto,VrNeto,0,0,0,0,Cantidad
,0,0,1,'EFE','','0','','0',Null,IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','NOTACALIB','','0',0,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCalibra
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Pla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Pla] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDoc,Planilla,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,VrConDcto+VrCreDcto,VrSobretasa,0,VrCreTotal+VrConTotal+VrCreImp+VrConImp,VrSobrantes,VrFaltantes,VrImpGlobal,VrOtros,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,0,0,0,'EFE','','0','','0',FecCorte,IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'',Modalidad,'','COR',NumCorte,'00'
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCortes
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rc1]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Rc1] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,2,TipDoc, Recibo, IdCia, Fecha,IdConcepto, IdCliente, IdAgencia,ValorTotal, ValorDcto,ValorReteIva, ValorReteFte+ValorReteIca,ValorPagMas,ValorOtros,ValorOtrosDct,0,TotalAhorro,ValorNeto,0
,0,0,0,0,NPasajeros,0,0,EnEfectivo,'EFE',NumCheque,IdBanco,'',IdCta,Null, IdVendedor, Comision, '0',IdUsuario,'0',Referencia,''
,Modalidad,IdVehiculo,TipCar, Cartulina, IdCiaCar,TipCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev, Observacion,TimeSys
FROM Trn_RecBuses
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rc2]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Rc2] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,2,TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,0,VrReteIVA,VrRetencion+VrReteICA,VrPagosMas,VrOtros,VrOtrDcto,0,0,VrNeto,VrEfectivo
,0,0,0,0,0,0,0,EnEfectivo,CdForma,NumForma,CdBanco,SUBSTRING(DetallePago,1,150),CdCta,FecPago,IdVend,TarifaCom,'0',IdUsuario,'0',Referencia,''
,'RC2',pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_FinRecibos
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Rco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,CASE TipDoc WHEN 'RCO' THEN 3 ELSE 4 END,TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdTercero,CdAgencia,VrTotal,0,0,0,0,VrTotDebito,VrTotCredito,0,0,VrEfectivo AS ValNeto,VrEfectivo
,0,0,0,0,0,0,0,EnEfectivo,'EFE',NumForma,CdBanco,'',CdCta,Null,'0',0,'0',IdCajero,'0',Referencia,'','RECIBOS','','',0,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_CompCaja
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Rec] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,2,TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrReteIVA,VrRetencion+VrReteICA,VrPagosMas,VrOtros,VrOtrDcto,0,VrAhorro,VrNeto,VrEfectivo
,0,0,0,0,0,0,0,EnEfectivo,CdForma,NumForma,CdBanco,SUBSTRING(DetallePago,1,150),CdCta,FecPago,IdVend,TarifaCom,'0',IdCajero,IdLocal,Referencia,''
,Modalidad,pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Recibos
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Caja_Rmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Caja_Rmt] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Caja (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo
,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros,Cantidad,CantPuntos,PuntosAcum,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,8,TipDoc,Documento,IdCia,Fecha,'0',NitCliente,CdAgencia,VrPagado,VrCambio,0,0,0,0,0,0,0,VrPagado AS ValNeto,CASE EsCaja WHEN 1 THEN VrPagado ELSE 0 END
,0,0,0,0,0,0,0,EsCaja,IdForma,NumForma,IdBanco,Beneficiario,CdCta,FecForma,'0',0,'0',IdUsuario,CdLocal,Referncia1,Referncia2
,'REMESAS',Referncia2,TipRef,DocRef,IdCiaRef,'0',0,'00',0,0,Null,Detalle,Fecha
 FROM Trn_Pagos
 WHERE TipDoc IN ('RMT','ODP','DOP') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CajaTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_CajaTot] @pmtmEst CHAR(2),@pmtmTipo INT,@pmtmItem INT
,@pmtmConcepto VARCHAR(150),@pmtmValorTotal MONEY,@pmtmValorOtros MONEY
 AS 
 INSERT INTO tm_CajaTot (tmEst,tmTipo,tmItem,tmConcepto,tmValorTotal,tmValorOtros)
 VALUES (@pmtmEst,@pmtmTipo,@pmtmItem,@pmtmConcepto,@pmtmValorTotal,@pmtmValorOtros)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cargos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Cargos] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdVehiculo VARCHAR(10),@pmtmVehPropio BIT,@pmtmIdConductor VARCHAR(16),@pmtmIdCliente VARCHAR(16),@pmtmIdCargo VARCHAR(4),@pmtmConcepto VARCHAR(100),@pmtmReferencia VARCHAR(20)
,@pmtmFactura VARCHAR(15),@pmtmValor MONEY,@pmtmDetalle VARCHAR(100),@pmtmFecVence SMALLDATETIME,@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCiaDoc CHAR(2),@pmtmConductor VARCHAR(100),@pmtmAbonado MONEY,@pmtmTipDocAnt VARCHAR(3)
,@pmtmDocAnticipo INT,@pmtmCiaDocAnt CHAR(2),@pmtmPrestamoID INT,@pmtmIdCiaPre CHAR(2),@pmtmNumCuota INT,@pmtmFecCausa SMALLDATETIME,@pmtmValorCapital MONEY,@pmtmValorInteres MONEY,@pmtmIdCuenta VARCHAR(16),@pmtmCombCant DECIMAL(14,4),@pmtmCombValor MONEY
,@pmtmBaseImpu MONEY,@pmtmTarifaIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifaRet DECIMAL(14,4),@pmtmVrRetFte MONEY,@pmtmTarifaIca DECIMAL(14,4),@pmtmVrRetIca MONEY,@pmtmCodTarifIva VARCHAR(4),@pmtmCodTarifRet VARCHAR(4),@pmtmCodTarifIca VARCHAR(4)
 AS 
 INSERT INTO tm_Cargos (tmNumero,tmItem,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdCliente,tmIdCargo,tmConcepto,tmReferencia,tmFactura,tmValor,tmDetalle,tmFecVence,tmTipDoc,tmDocumento,tmIdCiaDoc,tmConductor,tmAbonado,tmTipDocAnt,tmDocAnticipo,tmCiaDocAnt,tmPrestamoID,tmIdCiaPre,tmNumCuota
,tmFecCausa,tmValorCapital,tmValorInteres,tmIdCuenta,tmCombCant,tmCombValor,tmBaseImpu,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrRetIca,tmCodTarifIva,tmCodTarifRet,tmCodTarifIca)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdVehiculo,@pmtmVehPropio,@pmtmIdConductor,@pmtmIdCliente,@pmtmIdCargo,@pmtmConcepto,@pmtmReferencia,@pmtmFactura,@pmtmValor,@pmtmDetalle,@pmtmFecVence,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCiaDoc,@pmtmConductor,@pmtmAbonado
,@pmtmTipDocAnt,@pmtmDocAnticipo,@pmtmCiaDocAnt,@pmtmPrestamoID,@pmtmIdCiaPre,@pmtmNumCuota,@pmtmFecCausa,@pmtmValorCapital,@pmtmValorInteres,@pmtmIdCuenta,@pmtmCombCant,@pmtmCombValor,@pmtmBaseImpu,@pmtmTarifaIva,@pmtmVrIva,@pmtmTarifaRet,@pmtmVrRetFte,@pmtmTarifaIca,@pmtmVrRetIca
,@pmtmCodTarifIva,@pmtmCodTarifRet,@pmtmCodTarifIca)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cargos_Vce]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Cargos_Vce]  @pmTipDoc VARCHAR(3), @pmDocumento INT, @pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
AS 
 INSERT INTO tm_Cargos (tmNumero, tmItem, tmIdVehiculo, tmVehPropio, tmIdCliente, tmIdCargo, tmConcepto, tmReferencia, tmFactura, tmValor, tmDetalle,tmIdConductor,tmFecVence,tmTipDoc, tmDocumento 
, tmIdCiaDoc, tmConductor,tmAbonado,tmTipDocAnt , tmDocAnticipo, tmCiaDocAnt ,tmIdCuenta,tmCombCant,tmCombValor,tmBaseImpu,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrRetIca,tmCodTarifIva,tmCodTarifRet,tmCodTarifIca)
 SELECT @pmtmNumero,Item,IdVehiculo,VehPropio,IdCliente,F.IdCargo,Concepto,Referencia,Factura,ValorFactura,Detalle,IdVendedor,FecVence
 ,CASE WHEN (TipDoc='ADM' AND NumDocFac>0) THEN TipDocFac ELSE TipDoc END
 ,CASE WHEN (TipDoc='ADM' AND NumDocFac>0) THEN NumDocFac ELSE Documento END
 ,CASE WHEN (TipDoc='ADM' AND NumDocFac>0) THEN CdCiaFac ELSE IdCia END
,RazonSocial,ValorAtcpo,TipRec, Recibo, IdCiaRec,IdCuenta,CombCant,CombValor,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca,CodTarifIva,CodTarifRet,CodTarifIca
 FROM  Trn_CausacVence AS V INNER JOIN Terceros AS C ON V.IdVendedor=C.IdTercero
 INNER JOIN Fijos AS F ON V.IdCargo=F.IdCargo
 WHERE   TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cartera]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Cartera] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmVrSaldo MONEY
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmComision DECIMAL(14,4),@pmTarifDcto DECIMAL(14,4),@pmTipoDcto CHAR(1),@pmTipoBase VARCHAR(10),@pmFecLmtDcto SMALLDATETIME,@pmIdConcepto VARCHAR(4)
,@pmReferencia VARCHAR(50),@pmDetalle VARCHAR(150),@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmFecUltPago SMALLDATETIME,@pmNumNota INT,@pmIdCiaNot CHAR(2),@pmTarifInt DECIMAL(14,4),@pmFecLiqMora SMALLDATETIME
,@pmCtaForma VARCHAR(30),@pmBeneficiario VARCHAR(150),@pmRefCheque VARCHAR(50),@pmNumCheque VARCHAR(20),@pmCdBanco VARCHAR(4)
 AS 
 INSERT INTO tm_Cartera (tmEst,TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,VrSaldo,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot
,TarifInt,FecLiqMora,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 VALUES (@pmtmEst,@pmTipDoc,@pmFactura,@pmIdCia,@pmItem,@pmFecha,@pmFechaVence,@pmVrFactura,@pmVrAbonado,@pmVrSaldo,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmComision,@pmTarifDcto,@pmTipoDcto,@pmTipoBase,@pmFecLmtDcto
,@pmIdConcepto,@pmReferencia,@pmDetalle,@pmTipRef,@pmDocRef,@pmIdCiaRef,@pmFecUltPago,@pmNumNota,@pmIdCiaNot,@pmTarifInt,@pmFecLiqMora,@pmCtaForma,@pmBeneficiario,@pmRefCheque,@pmNumCheque,@pmCdBanco)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cartera_Saf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Cartera_Saf] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_Cartera (tmEst,TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,VrSaldo,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto
,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
SELECT @pmtmEst,'SAF',MAX(Recibo),IdCia,0,getdate(),getdate(),SUM(VrAFavor-VrOtrosDb),SUM(VrAbono),SUM((VrAFavor-VrOtrosDb)-VrAbono)
,IdCliente,IdAgencia,IdVend,0,0,'%','TOTAL',NULL,'0','SALDO A FAVOR','SALDO A FAVOR','0',0,'00',Null,0,'00',0,Null,'0','','','',''
 FROM Trn_RecAfavor
 WHERE  (VrAFavor-VrOtrosDb)>VrAbono AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 GROUP BY IdCia,IdCliente,IdAgencia,IdVend
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cartera_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Cartera_Sel] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 INSERT INTO tm_Cartera (tmEst,TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,VrSaldo,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto
,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
SELECT @pmtmEst,TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,VrFactura-VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto
,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,'0','','','',''
 FROM Trn_Vencimientos 
 WHERE  VrFactura>VrAbonado  AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ccCupones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_ccCupones] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmTipoReg INT,@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmItemDoc INT,@pmtmFecEmision SMALLDATETIME,@pmtmFecVence SMALLDATETIME,@pmtmValorFactura MONEY,@pmtmValorAbono MONEY
,@pmtmIdPropietario VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdConductor VARCHAR(16),@pmtmIdCargo VARCHAR(4),@pmtmIdClase VARCHAR(4),@pmtmFactura VARCHAR(15),@pmtmReferencia VARCHAR(50),@pmtmDetalle VARCHAR(100),@pmtmDescuento MONEY,@pmtmNCuota INT
 AS 
 INSERT INTO tm_ccCupones (tmEst,tmItem,tmTipoReg,tmTipDoc,tmDocumento,tmIdCia,tmItemDoc,tmFecEmision,tmFecVence,tmValorFactura,tmValorAbono,tmIdPropietario,tmIdVehiculo,tmIdConductor,tmIdCargo,tmIdClase,tmFactura,tmReferencia,tmDetalle,tmDescuento,tmNCuota)
 VALUES (@pmtmEst,@pmtmItem,@pmtmTipoReg,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCia,@pmtmItemDoc,@pmtmFecEmision,@pmtmFecVence,@pmtmValorFactura,@pmtmValorAbono,@pmtmIdPropietario,@pmtmIdVehiculo,@pmtmIdConductor,@pmtmIdCargo,@pmtmIdClase
,@pmtmFactura,@pmtmReferencia,@pmtmDetalle,@pmtmDescuento,@pmtmNCuota)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_cheq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_cheq] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipForma VARCHAR(3),@pmtmNumForma VARCHAR(20),@pmtmIdBanco VARCHAR(4),@pmtmFecha SMALLDATETIME,@pmtmFecPago SMALLDATETIME
,@pmtmVrForma MONEY,@pmtmCtaForma VARCHAR(30),@pmtmBeneficiario VARCHAR(150),@pmtmReferncia1 VARCHAR(50),@pmtmReferncia2 VARCHAR(50),@pmtmDetalle VARCHAR(150),@pmtmNitCliente VARCHAR(16),@pmtmCdAgencia VARCHAR(16)
,@pmtmCdVend VARCHAR(16),@pmtmIdLocal VARCHAR(8),@pmtmCdCta VARCHAR(4)
 AS 
 INSERT INTO tm_cheq (tmNumero,tmItem,tmTipForma,tmNumForma,tmIdBanco,tmFecha,tmFecPago,tmVrForma,tmCtaForma,tmBeneficiario,tmReferncia1,tmReferncia2,tmDetalle,tmNitCliente,tmCdAgencia,tmCdVend,tmIdLocal,tmCdCta)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipForma,@pmtmNumForma,@pmtmIdBanco,@pmtmFecha,@pmtmFecPago,@pmtmVrForma,@pmtmCtaForma,@pmtmBeneficiario,@pmtmReferncia1,@pmtmReferncia2,@pmtmDetalle
,@pmtmNitCliente,@pmtmCdAgencia,@pmtmCdVend,@pmtmIdLocal,@pmtmCdCta)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Combo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Combo] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdProdBase VARCHAR(16)
,@pmtmCantidad DECIMAL(14,4),@pmtmIdBodega VARCHAR(4),@pmtmCdTanque VARCHAR(4),@pmtmIdUnd VARCHAR(4),@pmtmFactor DECIMAL(14,4)
,@pmtmUndFac VARCHAR(10),@pmtmServcios BIT,@pmtmLinea INT,@pmtmVrUnitario MONEY
 AS 
 INSERT INTO tm_Combo (tmNumero,tmItem,tmIdProducto,tmIdProdBase,tmCantidad,tmIdBodega,tmCdTanque,tmIdUnd,tmFactor,tmUndFac,tmServcios,tmLinea,tmVrUnitario)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProducto,@pmtmIdProdBase,@pmtmCantidad,@pmtmIdBodega,@pmtmCdTanque,@pmtmIdUnd,@pmtmFactor
,@pmtmUndFac,@pmtmServcios,@pmtmLinea,@pmtmVrUnitario)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Combo_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Combo_Sel] @pmtmNumero VARCHAR(5), @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_Combo (tmNumero,tmItem,tmIdProducto,tmIdProdBase,tmCantidad,tmIdBodega,tmCdTanque,tmIdUnd,tmFactor,tmUndFac,tmServcios,tmLinea,tmVrUnitario)
 SELECT @pmtmNumero,Item,CdProdEquiv,IdProducto,Entradas+Salidas,IdBodega,CdTanque,IdUnd,Unidades,SUBSTRING(Referencia,1,10),Servcios,ItemCombo,VrUnitario
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND  IdCia=@pmIdCia AND EsProdBase=1
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Dfc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Dfc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,1,Fecha,FecDoc,IdVend,TarifaCom,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,IdConcepto,'0',Cantidad,'0',IdUsuario,'0',0,IdLocEnv,'0',Modalidad,TipDoc,Factura,IdCiaDoc,0,Observacion,'',ModdDev
 FROM Trn_DevFcr
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%') AND TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_DfcDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_DfcDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdLinea VARCHAR(8)=Null
,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,Item,D.Fecha,FecDoc,K.IdVend,Comision,IdCliente,IdAgencia,VrPrecio*Entradas,VrDctoEnt,VrIvaEnt,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,D.IdConcepto,K.IdProducto,Entradas,'0',D.IdUsuario,CdOperario,ComisnOper,CdLocal,CdSzona,Modalidad,D.TipDoc,D.Factura,IdCiaDoc,0,Observacion,Descripcion,K.Referencia
 FROM Trn_DevFcr AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND CdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND (Comision>ISNULL(@pmTarifaCom,-1) OR ComisnOper>ISNULL(@pmTarifaCom,-1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') 
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%') AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Dfo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Dfo] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,1,Fecha,FecDoc,IdVend,TarifaCom,NitCliente,CdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,IdConcepto,'0',Cantidad,nClieCon,IdCajero,'0',0,IdLocal,'0',Modalidad,TipDoc,Factura,IdCiaDoc,0,Observacion,'',ModdDev
 FROM Trn_DevFco
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND NitCliente LIKE ISNULL(@pmIdCliente,'%') AND CdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_DfoDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_DfoDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdLinea VARCHAR(8)=Null
,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,Item,D.Fecha,FecDoc,K.IdVend,Comision,NitCliente,D.CdAgencia,VrPrecio*Entradas,VrDctoEnt,VrIvaEnt,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,D.IdConcepto,K.IdProducto,Entradas,nClieCon,IdCajero,CdOperario,ComisnOper,CdLocal,CdSzona,Modalidad,D.TipDoc,D.Factura,IdCiaDoc,0,Observacion,Descripcion,K.Referencia
 FROM Trn_DevFco AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.NitCliente LIKE ISNULL(@pmIdCliente,'%') AND D.CdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND CdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND (Comision>ISNULL(@pmTarifaCom,-1) OR ComisnOper>ISNULL(@pmTarifaCom,-1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') 
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%') AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Dvp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Dvp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,1,Fecha,FecDoc,IdVend,TarifaCom,NitTercero,'0',VrSubTotal+VrConTotal+VrCreTotal,VrConDcto+VrCreDcto,VrConImp+VrCreImp,VrSobretasa+VrImpGlobal,VrOtros
,VrSobrantes,VrFaltantes,IdConcepto,'0',Cantidad+ConCant+CreCant,NitRef,IdCajero,'0',0,'0','0',Modalidad,TipDoc,Planilla,IdCiaDoc,0,Observacion,ModdDev,Referencia
 FROM Trn_DevPla
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND  TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_DvpDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_DvpDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmTarifaCom DECIMAL(14,4),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)

SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,Item,D.Fecha,FecDoc,K.IdVend,Comision,NitTercero,'0',VrPrecio*Entradas,VrDctoEnt,VrIvaEnt,VrSobretasa+VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes
,D.IdConcepto,K.IdProducto,Entradas,NitRef,IdCajero,CdOperario,ComisnOper,CdLocal,CdSzona,Modalidad,D.TipDoc,Planilla,IdCiaDoc,0,Observacion,Descripcion,K.Referencia
 FROM Trn_DevPla AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND CdLocal LIKE ISNULL(@pmIdLocEnv,'%') 
 AND (Comision>ISNULL(@pmTarifaCom,-1) OR ComisnOper>ISNULL(@pmTarifaCom,-1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') 
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%') AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Fco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Fco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDoc,Factura,IdCia,1,Fecha,Fecha AS FecVence,IdVend,TarifaCom,NitCliente,CdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,IdConcepto,'0',Cantidad,nClieCon,IdCajero,'0',0,IdLocal,'0',Modalidad,TipPed,Pedido,IdCiaPed,Anulado,Observacion,DetallePago,Referncia1
 FROM Trn_Factcon
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND NitCliente LIKE ISNULL(@pmIdCliente,'%') AND CdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_FcoDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_FcoDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdLinea VARCHAR(8)=Null
,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
 SELECT @pmtmEst,F.TipDoc,F.Factura,F.IdCia,Item,F.Fecha,K.Fecha,K.IdVend,Comision,NitCliente,F.CdAgencia,VrPrecio*Salidas,VrDctoSal,VrIvaSal,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,F.IdConcepto,K.IdProducto,Salidas,nClieCon,IdCajero,CdOperario,ComisnOper,CdLocal,CdSzona,Modalidad,TipPed,Pedido,IdCiaPed,Anulado,Observacion,Descripcion,K.Referencia
 FROM Trn_Factcon AS F INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  F.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND NitCliente LIKE ISNULL(@pmIdCliente,'%') AND F.CdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND CdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND (Comision>ISNULL(@pmTarifaCom,-1) OR ComisnOper>ISNULL(@pmTarifaCom,-1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') 
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%') AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Fcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Fcr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDoc,Factura,IdCia,1,Fecha,FechaVence,IdVend,TarifaCom,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,IdConcepto,'0',Cantidad,'0',IdUsuario,'0',0,IdLocEnv,'0',Modalidad,TipPed,Pedido,IdCiaPed,Anulado,Observacion,DetallePago,pVehiculo
 FROM Trn_Facturas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%') AND TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_FcrDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_FcrDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdLinea VARCHAR(8)=Null
,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,F.TipDoc,F.Factura,F.IdCia,Item,F.Fecha,FechaVence,K.IdVend,Comision,IdCliente,IdAgencia,VrPrecio*Salidas,VrDctoSal,VrIvaSal,VrRetencion+VrReteICA,VrFletes,VrCargos,VrOtrDcto
,F.IdConcepto,K.IdProducto,Salidas,'0',F.IdUsuario,CdOperario,ComisnOper,CdLocal,CdSzona,Modalidad,TipPed,Pedido,IdCiaPed,Anulado,Observacion,Descripcion,K.Referencia
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  F.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND F.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND CdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND (Comision>ISNULL(@pmTarifaCom,-1) OR ComisnOper>ISNULL(@pmTarifaCom,-1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') 
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%') AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Ncr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Ncr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,A.TipRec,A.Recibo,A.IdCia,Item,A.Fecha,A.FecPago,A.IdVend,Comision,A.IdCliente,A.IdAgencia,VrBaseCms,0,VrImpuesto,VrRetencion+VrReteICA,VrSancion,VrOtros,VrDescto
,IdConcepto,CdProducto,Cantidad,'0',CdCajero,'0',0,IdLocal,'0',Modalidad,A.TipDoc,Factura,IdCiaFac,0,Observacion,Detalle,Referencia
 FROM  Trn_VencAbonos AS A INNER JOIN Trn_Notas AS N ON A.TipRec=N.TipDoc AND A.Recibo=N.NumNota  AND  A.IdCia=N.IdCia
 WHERE TipRec='NCR'  AND  A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND A.IdVend LIKE ISNULL(@pmIdVend,'%') AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND A.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND A.Comision>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Ndb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Ndb] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDoc,NumNota,IdCia,1,Fecha,FechaVence,IdVend,TarifaCom,IdCliente,IdAgencia,VrSubTotal,0,VrImpuesto,VrRetencion+VrReteICA,VrSancion,VrOtros,0
,IdConcepto,CdProducto,Cantidad,'0',CdCajero,'0',0,IdLocal,'0',Modalidad,TipDcm,Documento,IdCiaDcm,0,Observacion,NumCheque,Referencia
 FROM  Trn_Notas 
 WHERE TipDoc='NDB'  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Odb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Odb] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,A.TipRec,A.Recibo,A.IdCia,Item,A.Fecha,A.FecPago,A.IdVend,Comision,A.IdCliente,A.IdAgencia,CASE WHEN VrBaseCms<0 THEN VrBaseCms*-1 ELSE VrBaseCms END,0,VrReteIVA,VrRetencion+VrReteICA,VrPagosMas,VrOtros,VrDescto
,IdConcepto,'0',0,'0',IdCajero,'0',0,IdLocal,'0',Modalidad,A.TipDoc,Factura,IdCiaFac,0,Observacion,Detalle,Referencia
 FROM  Trn_VencAbonos AS A INNER JOIN Trn_DevRec AS R ON A.TipRec=R.TipDev AND A.Recibo=R.Devolucion AND   A.IdCia=R.IdCia
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND A.IdVend LIKE ISNULL(@pmIdVend,'%') AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND A.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND A.Comision>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Pla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Pla] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipDoc,Planilla,IdCia,1,Fecha,FecCorte,IdVend,TarifaCom,NitTercero,'0',VrSubTotal+VrConTotal+VrCreTotal,VrConDcto+VrCreDcto,VrConImp+VrCreImp,VrSobretasa+VrImpGlobal,VrOtros
,VrSobrantes,VrFaltantes,IdConcepto,'0',Cantidad,NitRef,IdCajero,'0',0,'0','0',Modalidad,'COR',NumCorte,'00',Anulado,Observacion,'',Referencia
 FROM Trn_EdsCortes
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND  TarifaCom>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_PlaDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_PlaDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmTarifaCom DECIMAL(14,4),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
 SELECT @pmtmEst,C.TipDoc,Planilla,C.IdCia,Item,C.Fecha,FecCorte,K.IdVend,Comision,NitTercero,'0',VrPrecio*Salidas,VrDctoSal,VrIvaSal,VrSobretasa+VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes
,C.IdConcepto,K.IdProducto,Salidas,NitRef,IdCajero,CdOperario,ComisnOper,CdLocal,CdSzona,Modalidad,'COR',NumCorte,'00',Anulado,Observacion,Descripcion,K.Referencia
 FROM Trn_EdsCortes AS C INNER JOIN Trn_Kardex AS K ON C.TipDoc=K.TipDoc AND C.Planilla=K.Documento AND C.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND CdLocal LIKE ISNULL(@pmIdLocEnv,'%') 
 AND (Comision>ISNULL(@pmTarifaCom,-1) OR ComisnOper>ISNULL(@pmTarifaCom,-1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') 
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%') AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comisiones_Rec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comisiones_Rec] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmTarifaCom DECIMAL(14,4)
 AS 
 INSERT INTO tm_Comisiones (tmEst,TipDoc,Numero,IdCia,Item,Fecha,FecVence,IdVend,TarifaCom,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos
,IdConcepto,CdProducto,Cantidad,nClieCon,IdCajero,CdOperario,ComisnOper,IdLocal,CdSzona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,Observacion,Detalles,Referencia)
SELECT @pmtmEst,TipRec,A.Recibo,A.IdCia,Item,A.Fecha,A.FecPago,A.IdVend,Comision,A.IdCliente,A.IdAgencia
,CASE WHEN SUBSTRING(A.TipDoc,1,2)='FC' AND A.VrBaseCms>0 AND (A.VrAbono-A.VrBaseCms)>=0 THEN A.VrAbono ELSE A.VrBaseCms END
,CASE WHEN SUBSTRING(A.TipDoc,1,2)='FC' AND A.VrBaseCms>0 AND (A.VrAbono-A.VrBaseCms)>=0 THEN A.VrAbono-A.VrBaseCms ELSE 0 END
,VrReteIVA,VrRetencion+VrReteICA,VrPagosMas,VrOtros,VrDescto,IdConcepto,'0',0,'0',IdCajero,'0',0,IdLocal,'0',Modalidad,A.TipDoc,Factura,IdCiaFac,Anulado,Observacion,Detalle,Referencia
 FROM Trn_VencAbonos AS A INNER JOIN Trn_Recibos AS R ON A.TipRec=R.TipDoc AND A.Recibo=R.Recibo AND A.IdCia=R.IdCia
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND A.IdVend LIKE ISNULL(@pmIdVend,'%') AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND A.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdLocal LIKE ISNULL(@pmIdLocEnv,'%') AND A.Comision>ISNULL(@pmTarifaCom,-1)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Comp] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdCuenta VARCHAR(16),@pmtmDetalle VARCHAR(250),@pmtmVrDebito MONEY,@pmtmVrCredito MONEY,@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16)
,@pmtmVrBase MONEY,@pmtmTarifaBase DECIMAL(10,4),@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCiaDoc CHAR(2),@pmtmCodConce VARCHAR(4),@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15),@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmFecVence SMALLDATETIME,@pmtmCodCta VARCHAR(4)
,@pmtmNumCheque VARCHAR(20),@pmtmIntegrado BIT,@pmtmTipoAplica CHAR(1),@pmtmConsolida BIT,@pmtmCodCargo VARCHAR(4),@pmtmNitOtros VARCHAR(16),@pmtmCodSubgpo VARCHAR(8),@pmtmCiuOrigen VARCHAR(8),@pmtmCodAgncia VARCHAR(16),@pmtmVehPropio INT,@pmtmReferncia VARCHAR(50),@pmtmTipCom VARCHAR(3)
,@pmtmComprobante INT,@pmtmIdCia CHAR(2),@pmtmNombre VARCHAR(100),@pmtmCcosto VARCHAR(100),@pmtmSubcc VARCHAR(100),@pmtmTercero VARCHAR(150),@pmtmTipDocRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmNitDoc VARCHAR(16),@pmtmConcTrib VARCHAR(4),@pmtmTarifTrib VARCHAR(4)
,@pmtmEstablec VARCHAR(20),@pmtmPtoEmision VARCHAR(20),@pmtmAutoriza VARCHAR(50),@pmtmFechAut SMALLDATETIME,@pmtmCuentaNiif VARCHAR(16)
 AS 
 INSERT INTO tm_Comp (tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo
,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdCuenta,@pmtmDetalle,@pmtmVrDebito,@pmtmVrCredito,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmVrBase,@pmtmTarifaBase,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCiaDoc,@pmtmCodConce,@pmtmTipFac,@pmtmFactura,@pmtmIdCiaFac,@pmtmItemFac,@pmtmFecVence
,@pmtmCodCta,@pmtmNumCheque,@pmtmIntegrado,@pmtmTipoAplica,@pmtmConsolida,@pmtmCodCargo,@pmtmNitOtros,@pmtmCodSubgpo,@pmtmCiuOrigen,@pmtmCodAgncia,@pmtmVehPropio,@pmtmReferncia,@pmtmTipCom,@pmtmComprobante,@pmtmIdCia,@pmtmNombre,@pmtmCcosto,@pmtmSubcc,@pmtmTercero
,@pmtmTipDocRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmNitDoc,@pmtmConcTrib,@pmtmTarifTrib,@pmtmEstablec,@pmtmPtoEmision,@pmtmAutoriza,@pmtmFechAut,@pmtmCuentaNiif)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp_Caj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comp_Caj] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_Comp (tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodAgncia,tmVehPropio,tmReferncia,tmComprobante,tmNombre,tmCcosto,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif)
SELECT  @pmtmNumero,Item,D.IdCuenta,Detalle,VrDebito,VrCredito,NitTercero,pVehiculo,CdCCosto,CdSubCos,VrBase,TarifaBase,TipDoc,Recibo,IdCia,IdConcepto,TipFac,Factura,IdCiaFac
,CASE WHEN D.TipDoc='RCO' AND D.ConcAsociado>0 THEN D.ConcAsociado ELSE (CASE WHEN LEN(ISNULL(D.TipoImp,''))>0 AND ISNULL(D.TipoImp,'')<>'0' THEN D.ItemBase ELSE D.ItemFac END) END
,FecVence,CodCta,NumCheque,1,TipoAplica,ISNULL(D.DocSop,0),IdConcepto,NitOtros,CodAgencia,0,Referncia,0,SUBSTRING(NomCuenta,1,100),SUBSTRING(CCosto,1,100),SUBSTRING(RazonSocial,1,150),CASE WHEN ISNULL(D.DocSop,0)=1 THEN D.TipSop ELSE D.TipDocRef END
,CASE WHEN ISNULL(D.DocSop,0)=1 THEN D.NumSoporte ELSE D.DocRef END,CASE WHEN ISNULL(D.DocSop,0)=1 THEN D.IdCiaSop ELSE D.IdCiaRef END,D.TipoImp,D.CodTarImp,'','','',Null,P.IdCueNiif
 FROM Trn_CompCajaDet AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero
 LEFT JOIN CentroCosto AS O ON D.CdCCosto=O.IdCCosto
 WHERE D.TipDoc=@pmTipDoc AND D.Recibo=@pmRecibo AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp_Niif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comp_Niif] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Comp (tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce
,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo
,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif)
 SELECT @pmtmNumero,Item,D.IdCuenta,Detalle,VrDebito,VrCredito,D.IdTercero,IdVehiculo,D.IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia
,TipCom,Comprobante,IdCia,SUBSTRING(NomCuenta,1,100),SUBSTRING(CCosto,1,100),'',SUBSTRING(RazonSocial,1,150),TipDocRef,DocRef,IdCiaRef,NitDoc,CdConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza,D.IdCuenta
 FROM Trn_NiifDetalle AS D INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 LEFT JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Comp_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Comp_Sel] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Comp (tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce
,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo
,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif)
 SELECT @pmtmNumero,Item,D.IdCuenta,Detalle,VrDebito,VrCredito,D.IdTercero,IdVehiculo,D.IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia
,TipCom,Comprobante,IdCia,SUBSTRING(NomCuenta,1,100),SUBSTRING(CCosto,1,100),'',SUBSTRING(RazonSocial,1,150),TipDocRef,DocRef,IdCiaRef,NitDoc,CdConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza,CdCuentaNiif
 FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 LEFT JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Compau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Compau] @pmtmNumero VARCHAR(5),@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCia CHAR(2)
 AS 
 INSERT INTO tm_Compau (tmNumero,tmTipCom,tmComprobante,tmIdCia,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos
,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica
,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut)
 SELECT tmNumero,@pmtmTipCom,@pmtmComprobante,@pmtmIdCia,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos
,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica
,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CompauAbr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CompauAbr] @pmtmNumero VARCHAR(5),@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCia CHAR(2)
 AS 
 INSERT INTO  tm_Comp (tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos
,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica
,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
,tmTipCom,tmComprobante,tmIdCia,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif)
SELECT tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos
,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica
,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
,tmTipCom,tmComprobante,tmIdCia,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,''
FROM  tm_Compau 
WHERE  tmNumero=@pmtmNumero AND tmTipCom=@pmtmTipCom AND tmComprobante=@pmtmComprobante  AND tmIdCia=@pmtmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Contratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Contratos] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmContrato INT,@pmtmIdCia CHAR(2)
,@pmtmTipoProd VARCHAR(20),@pmtmCdProducto VARCHAR(16),@pmtmPeriodo VARCHAR(6),@pmtmPresptoMes DECIMAL(14,4),@pmtmPresptoAnno DECIMAL(14,4),@pmtmCantNeto DECIMAL(14,4),@pmtmValorNeto MONEY
 AS 
 INSERT INTO tm_Contratos (tmEst,tmItem,tmContrato,tmIdCia,tmTipoProd,tmCdProducto,tmPeriodo,tmPresptoMes,tmPresptoAnno,tmCantNeto,tmValorNeto)
 VALUES (@pmtmEst,@pmtmItem,@pmtmContrato,@pmtmIdCia,@pmtmTipoProd,@pmtmCdProducto,@pmtmPeriodo
,@pmtmPresptoMes,@pmtmPresptoAnno,@pmtmCantNeto,@pmtmValorNeto)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Cuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Cuotas] @pmtmEst CHAR(2),@pmtmPrestamoID INT,@pmtmIdCia CHAR(2),@pmtmNumCuota INT,@pmtmFecCausa SMALLDATETIME, @pmtmFecVence SMALLDATETIME, @pmtmValorCapital MONEY
, @pmtmValorInteres MONEY,@pmtmValorCuota MONEY,@pmtmSaldo MONEY, @pmtmValorCausado MONEY, @pmtmValorAbonado MONEY,@pmtmFecPago SMALLDATETIME, @pmtmTipRec VARCHAR(3), @pmtmRecibo INT, @pmtmIdCiaRec CHAR(2)
AS
 INSERT INTO tm_Cuotas (tmEst, tmPrestamoID, tmIdCia, tmNumCuota, tmFecCausa, tmFecVence, tmValorCapital, tmValorInteres,tmValorCuota, tmSaldo, tmValorCausado, tmValorAbonado,tmFecPago, tmTipRec, tmRecibo, tmIdCiaRec)
 VALUES ( @pmtmEst,@pmtmPrestamoID,@pmtmIdCia,@pmtmNumCuota,@pmtmFecCausa, @pmtmFecVence, @pmtmValorCapital, @pmtmValorInteres,@pmtmValorCuota,@pmtmSaldo, @pmtmValorCausado, @pmtmValorAbonado
,@pmtmFecPago, @pmtmTipRec, @pmtmRecibo, @pmtmIdCiaRec)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxcAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CxcAbonos] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipDoc VARCHAR(3),@pmtmFactura INT,@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmVrAbono MONEY,@pmtmVrDescto MONEY
,@pmtmVrBaseCms MONEY,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmComision DECIMAL(14,4),@pmtmDetalle VARCHAR(150),@pmtmTipoAplica VARCHAR(10)
,@pmtmCodTarDct VARCHAR(4),@pmtmCodTarCom VARCHAR(4),@pmtmTipRec VARCHAR(3),@pmtmRecibo INT,@pmtmCiaRec CHAR(2),@pmtmItemRec INT,@pmtmFecPago SMALLDATETIME
 AS 
 INSERT INTO tm_CxcAbonos (tmNumero,tmItem,tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmVrDescto,tmVrBaseCms,tmIdCliente,tmIdAgencia,tmIdVend,tmComision,tmDetalle,tmTipoAplica
,tmCodTarDct,tmCodTarCom,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipDoc,@pmtmFactura,@pmtmIdCiaFac,@pmtmItemFac,@pmtmVrAbono,@pmtmVrDescto,@pmtmVrBaseCms,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdVend,@pmtmComision
,@pmtmDetalle,@pmtmTipoAplica,@pmtmCodTarDct,@pmtmCodTarCom,@pmtmTipRec,@pmtmRecibo,@pmtmCiaRec,@pmtmItemRec,@pmtmFecPago)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxcAbonos_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CxcAbonos_Sel] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_CxcAbonos (tmNumero,tmItem,tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmVrDescto,tmVrBaseCms,tmIdCliente
,tmIdAgencia,tmIdVend,tmComision,tmDetalle,tmTipoAplica,tmCodTarDct,tmCodTarCom,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago)
 SELECT @pmtmNumero,Item,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,IdCliente,IdAgencia
,IdVend,Comision,Detalle,TipoAplica,'','',TipRec,Recibo,IdCia,Item AS ItemRec,FecPago
 FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxCobrar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CxCobrar] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmFecVence SMALLDATETIME,@pmtmVrFactura MONEY,@pmtmTarifDcto DECIMAL(14,4)
,@pmtmTipoDcto CHAR(1),@pmtmTipoBase VARCHAR(10),@pmtmFecLmtDcto SMALLDATETIME,@pmtmReferencia VARCHAR(50),@pmtmDetalle VARCHAR(150)
,@pmtmTipRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmTotAbono MONEY,@pmtmFecPlazo SMALLDATETIME
 AS 
 INSERT INTO tm_CxCobrar (tmNumero,tmItem,tmFecVence,tmVrFactura,tmTarifDcto,tmTipoDcto,tmTipoBase,tmFecLmtDcto,tmReferencia,tmDetalle,tmTipRef,tmDocRef,tmIdCiaRef,tmTotAbono,tmFecPlazo)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmFecVence,@pmtmVrFactura,@pmtmTarifDcto,@pmtmTipoDcto,@pmtmTipoBase,@pmtmFecLmtDcto,@pmtmReferencia
,@pmtmDetalle,@pmtmTipRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmTotAbono,@pmtmFecPlazo)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxCobrar_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CxCobrar_Sel] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_CxCobrar (tmNumero,tmItem,tmFecVence,tmVrFactura,tmTarifDcto,tmTipoDcto,tmTipoBase,tmFecLmtDcto,tmReferencia,tmDetalle,tmTipRef,tmDocRef,tmIdCiaRef,tmTotAbono,tmFecPlazo)
 SELECT @pmtmNumero,Item,FechaVence,VrFactura,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,0,FecPlazoCal
 FROM Trn_Vencimientos 
 WHERE TipDoc=@pmTipDoc  AND Factura=@pmFactura  AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxPagar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CxPagar] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProveedor VARCHAR(16),@pmtmFecVence SMALLDATETIME,@pmtmIdCuenta VARCHAR(16),@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT
,@pmtmIdCiaDoc CHAR(2),@pmtmVrFactura MONEY,@pmtmItemCom INT,@pmtmReferencia VARCHAR(50),@pmtmDetalle VARCHAR(100),@pmtmpVehiculo VARCHAR(10),@pmtmVehPropio BIT,@pmtmTipRef VARCHAR(3),@pmtmDocRef INT
,@pmtmIdCiaRef CHAR(2),@pmtmProveedor VARCHAR(250)
 AS 
 INSERT INTO tm_CxPagar (tmNumero,tmItem,tmIdProveedor,tmFecVence,tmIdCuenta,tmTipDoc,tmDocumento,tmIdCiaDoc,tmVrFactura,tmItemCom,tmReferencia,tmDetalle,tmpVehiculo,tmVehPropio,tmTipRef,tmDocRef,tmIdCiaRef,tmProveedor)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProveedor,@pmtmFecVence,@pmtmIdCuenta,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCiaDoc,@pmtmVrFactura,@pmtmItemCom,@pmtmReferencia,@pmtmDetalle,@pmtmpVehiculo
,@pmtmVehPropio,@pmtmTipRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmProveedor)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxPagar_Doc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_CxPagar_Doc]  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_CxPagar (tmNumero,tmItem,tmIdProveedor,tmFecVence,tmIdCuenta,tmTipDoc,tmDocumento,tmIdCiaDoc,tmVrFactura,tmItemCom,tmReferencia,tmDetalle
,tmpVehiculo,tmVehPropio,tmTipRef,tmDocRef,tmIdCiaRef,tmProveedor)
 SELECT @pmtmNumero,Item,IdProveedor,FecVence,IdCuenta,TipDoc,Documento,IdCiaDoc,VrFactura,ItemCom,Referencia,Detalle
,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,RazonSocial
 FROM Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND  IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND ItemCom<=0 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND Factura LIKE ISNULL(@pmFactura,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxPagar_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_CxPagar_Sel] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_CxPagar (tmNumero,tmItem,tmIdProveedor,tmFecVence,tmIdCuenta,tmTipDoc,tmDocumento,tmIdCiaDoc,tmVrFactura,tmItemCom,tmReferencia,tmDetalle
,tmpVehiculo,tmVehPropio,tmTipRef,tmDocRef,tmIdCiaRef,tmProveedor)
 SELECT @pmtmNumero,Item,IdProveedor,FecVence,IdCuenta,TipDoc,Documento,IdCiaDoc,VrFactura,ItemCom,Referencia,Detalle
,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,RazonSocial
 FROM Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero
 WHERE TipFac=@pmTipFac  AND Factura=@pmFactura  AND IdCia=@pmIdCia AND IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxpAplica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_CxpAplica] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProveedor VARCHAR(16),@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15)
,@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmVrAbono MONEY,@pmtmIdCuenta VARCHAR(16),@pmtmpVehiculo VARCHAR(10),@pmtmVehPropio BIT,@pmtmTipDev VARCHAR(3)
,@pmtmNumDev INT,@pmtmDetAbono VARCHAR(100),@pmtmProveedor VARCHAR(250)
 AS 
 INSERT INTO tm_CxpAplica (tmNumero,tmItem,tmIdProveedor,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmIdCuenta,tmpVehiculo,tmVehPropio,tmTipDev,tmNumDev,tmDetAbono,tmProveedor)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProveedor,@pmtmTipFac,@pmtmFactura,@pmtmIdCiaFac,@pmtmItemFac,@pmtmVrAbono,@pmtmIdCuenta,@pmtmpVehiculo,@pmtmVehPropio
,@pmtmTipDev,@pmtmNumDev,@pmtmDetAbono,@pmtmProveedor)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxpAplica_Doc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_CxpAplica_Doc] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmFactura VARCHAR(15)=Null,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_CxpAplica (tmNumero,tmItem,tmIdProveedor,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmIdCuenta,tmpVehiculo,tmVehPropio,tmTipDev,tmNumDev,tmDetAbono,tmProveedor)
 SELECT @pmtmNumero,Item,IdProveedor,TipFac,Factura,IdCiaFac,ItemFac,VrAbono,IdCuenta,pVehiculo,VehPropio,TipDev,NumDev,DetAbono,RazonSocial
 FROM Trn_EgrFactura AS E INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero
 WHERE  TipCom=@pmTipCom AND Comprobante=@pmComprobante  AND IdCia=@pmIdCia
 AND TipDev=@pmTipCom AND NumDev=@pmComprobante AND EsEgreso=0
 AND Factura LIKE ISNULL(@pmFactura,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_CxpAplica_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_CxpAplica_Sel] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_CxpAplica (tmNumero,tmItem,tmIdProveedor,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmIdCuenta,tmpVehiculo,tmVehPropio,tmTipDev,tmNumDev,tmDetAbono,tmProveedor)
 SELECT @pmtmNumero,Item,IdProveedor,TipFac,Factura,IdCiaFac,ItemFac,VrAbono,IdCuenta,pVehiculo,VehPropio,TipDev,NumDev,DetAbono,RazonSocial
 FROM Trn_EgrFactura AS E INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero
 WHERE  TipCom=@pmTipCom AND Comprobante=@pmComprobante  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DetCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_DetCue] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmConcepto VARCHAR(10),@pmtmIdCuenta VARCHAR(16),@pmtmValor MONEY,@pmtmDetalle VARCHAR(150),@pmtmIdTercero VARCHAR(16)
,@pmtmCodAgncia VARCHAR(16),@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmpVehiculo VARCHAR(10),@pmtmVrBase MONEY,@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15),@pmtmIdCiaFac CHAR(2)
,@pmtmItemFac INT,@pmtmFecVence SMALLDATETIME,@pmtmCheque VARCHAR(20),@pmtmCiuOrigen VARCHAR(8),@pmtmReferencia VARCHAR(50),@pmtmTarifa DECIMAL(14,4),@pmtmTipoTarif CHAR(1),@pmtmCodConc VARCHAR(4),@pmtmCodTarif VARCHAR(4)
 AS 
 INSERT INTO tm_DetCue (tmNumero,tmItem,tmConcepto,tmIdCuenta,tmValor,tmDetalle,tmIdTercero,tmCodAgncia,tmCdCCosto,tmCdSubCos,tmpVehiculo,tmVrBase,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCheque,tmCiuOrigen,tmReferencia,tmTarifa,tmTipoTarif,tmCodConc,tmCodTarif)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmConcepto,@pmtmIdCuenta,@pmtmValor,@pmtmDetalle,@pmtmIdTercero,@pmtmCodAgncia,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmpVehiculo,@pmtmVrBase,@pmtmTipFac,@pmtmFactura,@pmtmIdCiaFac
,@pmtmItemFac,@pmtmFecVence,@pmtmCheque,@pmtmCiuOrigen,@pmtmReferencia,@pmtmTarifa,@pmtmTipoTarif,@pmtmCodConc,@pmtmCodTarif)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DetCue_Pto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_DetCue_Pto] @pmtmNumero VARCHAR(5),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_DetCue (tmNumero,tmItem,tmConcepto,tmIdCuenta,tmValor,tmDetalle,tmIdTercero,tmCodAgncia,tmCdCCosto,tmCdSubCos
,tmpVehiculo,tmVrBase,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCheque,tmCiuOrigen,tmReferencia,tmTarifa,tmTipoTarif,tmCodConc,tmCodTarif)
 SELECT @pmtmNumero,Item,ISNULL(TipoNiif,'0'),IdCuenta,VrPresupuesto,'PRESUPUESTO','0','0',IdCCosto,IdSubCos
,'0',VrPrespNiif,'','','00',0,FecUpdate,ISNULL(CodCueNiif,''),'',CdUsuario,0,'$','',''
 FROM Trn_PresDetalle
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DetCue_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_DetCue_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmConcepto VARCHAR(10)
 AS 
 INSERT INTO  tm_DetCue (tmNumero,tmItem,tmConcepto,tmIdCuenta,tmValor,tmDetalle,tmIdTercero,tmCodAgncia,tmCdCCosto,tmCdSubCos
,tmpVehiculo,tmVrBase,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCheque,tmCiuOrigen,tmReferencia,tmTarifa,tmTipoTarif,tmCodConc,tmCodTarif)
 SELECT @pmtmNumero,Item,Concepto,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac
,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
 FROM Trn_DetCuentas
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND Concepto LIKE ISNULL(@pmConcepto,'%')
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Ant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Ant] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,A.TipDoc,A.Anticipo,A.IdCia,A.Fecha,A.IdConcepto,M.IdPropietario,'0',M.VrFletes,M.VrDescuento,0,0,0,0,0,M.VrAnticipo+M.VrAntAdic,0,A.VrDeduccion,0,0,0,A.VrAnticipo,0,A.VrAbonado,0,0
,M.Cantidad,'0',M.PesoTotal,CASE WHEN A.TipoPago='EFECTIVO' THEN 1 ELSE 0 END,SUBSTRING(A.TipoPago,1,3),A.NumCheque,'',A.TipoPago,A.IdCta,A.FecCheque,A.CedBenef,0,'0',A.IdUsuario,M.IdOrigen,M.nRemolque,M.TipoAfiVehic,A.Beneficiario,A.Modalidad,A.IdVehiculo
,A.TipMuc,A.Manifiesto,A.IdCiaMuc,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado,A.NumDev,A.FecDev,A.Observacion,A.TimeSys,0,M.IdRuta,M.IdOrigen,M.IdDestino,A.IdPoseedor,A.IdConductor,'','',A.NumCargue,A.CiaCargue
FROM Trn_TraAnticipos AS A INNER JOIN Trn_TraManifiesto AS M ON A.TipMuc=M.TipDoc AND A.Manifiesto=M.Manifiesto AND A.IdCiaMuc=M.IdCia
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (A.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Aos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Aos] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,A.TipDoc,A.Anticipo,A.IdCia,A.Fecha,A.IdConcepto,O.IdCliente,O.IdAgencia,O.VrCosto,0,0,0,0,0,0,O.VrAnticipo,0,0,0,0,0,A.VrAnticipo,0,A.VrAbonado,0,0
,0,'0',O.Cantidad,CASE WHEN A.TipoPago='EFECTIVO' THEN 1 ELSE 0 END,SUBSTRING(A.TipoPago,1,3),A.NumCheque,'',A.TipoPago,A.IdCta,A.FecCheque,A.CedBenef,0,'0',A.IdUsuario,O.IdOrigen,O.nRemolque,O.TipoAfiVehic,A.Beneficiario,A.TipoAncpo,O.IdVehiculo
,A.TipOds,A.NumOrden,A.IdCiaOds,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado,A.NumDev,A.FecDev,A.Observacion,A.TimeSys,0,O.CdRuta,O.IdOrigen,O.IdDestino,O.IdPoseedor,O.IdConductor,'','',O.NumRemesa,O.CdCiaRem
FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (A.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Che]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Che] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,R.TipDoc,R.Recibo,R.IdCia,R.Fecha,'0',IdCliente,IdAgencia,VrForma,0,0,0,0,0,0,0,0,0,0,0,0,VrForma AS ValCheque,0,VrForma AS ValorOtros,0,0,0,'0',0,0,TipForma,Numero,IdBanco
,Detalle,CASE CdCta WHEN Null THEN '0' WHEN '' THEN '0' ELSE CdCta END,FecPago,CdVend,0,'0',R.IdUsuario,IdLocal,Referncia1,Referncia2,Beneficiario,'CHEQUES','',C.TipDoc,Documento,IdCiaDoc,'0',0,'00',R.Anulado,NumDev,R.FecDev,Observacion,TimeSys
 FROM Trn_RecCheques AS R INNER JOIN Trn_Cheques AS C ON R.TipDoc=C.TipRec AND R.Recibo=C.Recibo AND R.IdCia=C.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Cns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Cns] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,C.TipDoc,C.Consignacion,C.IdCia,C.Fecha,IdConcepto,NitCliente,CdAgencia,VrPagado,VrCambio,0,0,0,0,0,0,0,0,0,0,0,VrPagado-VrCambio,CASE IdForma WHEN 'EFE' THEN VrPagado-VrCambio ELSE 0 END
,0,0,0,0,'0',0,EnEfectivo,IdForma,NumForma,IdBanco,Detalle,CASE CdCta WHEN NULL THEN '0' WHEN '' THEN '0' ELSE CdCta  END,FecForma,NitDeptante,0,'0',IdCajero,CdLocal,Referncia1,P.Referncia2,Beneficiario,'CONSIGNA','',TipRef,DocRef,IdCiaRef
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Consigna AS C INNER JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND C.Consignacion=P.Documento AND C.IdCia=P.IdCia
 WHERE  C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Cos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Cos] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,C.TipDoc,C.Cumplido,C.IdCia,C.Fecha,C.IdConcepto,O.IdCliente,O.IdAgencia,C.VrTotal,0,0,0,0,0,0,0,0,0,0,0,C.VrCosto,C.VrTotal
,0,0,0,0,0,'0',C.Cantidad,0,'',C.RemCliente,'',C.DescServicio,'',C.FecDespacho,O.IdConductor,0,'0',C.IdUsuario,O.IdOrigen,O.nRemolque,C.TipoAfiVehic,C.Funcionario,O.Modalidad,O.IdVehiculo
,C.TipOds,C.NumOrden,C.IdCiaOds,C.TipCom,C.Comprobante,C.IdCiaCom,C.Anulado,C.NumDev,C.FecDev,C.Observacion,C.TimeSys,0,O.CdRuta,O.IdOrigen,O.IdDestino,O.IdPoseedor,O.IdConductor,'','',O.NumRemesa,O.CdCiaRem 
FROM Trn_TraOrdenCum AS C INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden AND C.IdCiaOds=O.IdCia
WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (C.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (C.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Cum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Cum] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,C.TipDoc,C.Cumplido,C.IdCia,C.Fecha,ISNULL(C.CodConcepto,''),M.IdPropietario,'0',CR.TotalCobro,0,0,0,0,0,0,C.VrAdicFlete,C.VrAdicCargue,C.VrAdicDescargue,0,0,CR.TotalPagos,CR.TotalPagos,0,0,0,C.VrAdicAnticipo
,CR.Cantidad,'0',CR.PesoTotal,0,'','','','','',C.FecPago,'0',0,'0',C.IdUsuario,C.CdOrigen,M.nRemolque,M.TipoAfiVehic,'',C.Modalidad,C.IdVehiculo
,C.TipMuc,C.Manifiesto,C.IdCiaMuc,C.TipoComp,C.NumComp,C.IdCia,C.Anulado,0,C.FecDev,C.Observacion,C.TimeSys,0,C.CdRuta,C.CdOrigen,C.CdDestino,M.IdPoseedor,M.IdConductor,'','',M.Remesa,M.IdCiaRem
FROM Trn_TraCumplido AS C INNER JOIN Trn_TraManifiesto AS M ON C.TipMuc=M.TipDoc AND C.Manifiesto=M.Manifiesto AND C.IdCiaMuc=M.IdCia
LEFT JOIN (SELECT TipDoc,Cumplido,IdCia,SUM(Cantidad) AS Cantidad,SUM(PesoNeto) AS PesoTotal,SUM(PesoNeto*TarifClie) AS TotalCobro,SUM(PesoNeto*TarifPago) AS TotalPagos
FROM Trn_TraCumRemesas GROUP BY TipDoc,Cumplido,IdCia) AS CR ON C.TipDoc=CR.TipDoc AND C.Cumplido=CR.Cumplido AND C.IdCia=CR.IdCia
WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (C.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (C.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dao]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dao] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,O.IdCliente,O.IdAgencia,O.VrCosto,0,0,0,0,0,0,A.VrAnticipo,0,0,0,0,0,D.VrDevolucion,0,A.VrAbonado,0,0
,0,'0',O.Cantidad,CASE WHEN A.TipoPago='EFECTIVO' THEN 1 ELSE 0 END,SUBSTRING(A.TipoPago,1,3),A.NumCheque,'',A.TipoPago,D.CdCta,A.FecCheque,A.CedBenef,0,'0',D.IdUsuario,O.IdOrigen,O.nRemolque,O.TipoAfiVehic,A.Beneficiario,D.ModdDev,O.IdVehiculo
,A.TipOds,A.NumOrden,A.IdCiaOds,D.TipCom,D.Comprobante,D.IdCiaCom,1,0,D.Fecha,D.Observacion,D.TimeSys,0,O.CdRuta,O.IdOrigen,O.IdDestino,O.IdPoseedor,O.IdConductor,'','',D.Anticipo,D.IdCiaDoc
FROM Trn_TraDevAos AS D INNER JOIN Trn_TraOrdenAnt AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,O.IdCliente,O.IdAgencia,C.VrTotal,0,0,0,0,0,0,0,0,0,0,0,C.VrCosto,C.VrTotal
,0,0,0,0,0,'0',C.Cantidad,0,'',C.RemCliente,'',C.DescServicio,'',C.FecDespacho,O.IdConductor,0,'0',D.IdUsuario,O.IdOrigen,O.nRemolque,C.TipoAfiVehic,C.Funcionario,D.ModdDev,O.IdVehiculo
,C.TipOds,C.NumOrden,C.IdCiaOds,D.TipCom,D.Comprobante,D.IdCiaCom,1,0,D.Fecha,D.Observacion,D.TimeSys,0,O.CdRuta,O.IdOrigen,O.IdDestino,O.IdPoseedor,O.IdConductor,'','',D.Cumplido,D.IdCiaDoc 
FROM Trn_TraDevCos AS D INNER JOIN Trn_TraOrdenCum AS C ON D.TipDoc=C.TipDoc AND D.Cumplido=C.Cumplido AND D.IdCiaDoc=C.IdCia
INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden AND C.IdCiaOds=O.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dcu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dcu] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,ISNULL(D.IdConcepto,''),M.IdPropietario,'0',CR.TotalCobro,0,0,0,0,0,0,C.VrAdicFlete,C.VrAdicCargue,C.VrAdicDescargue,0,0,CR.TotalPagos,CR.TotalPagos,0,0,0,C.VrAdicAnticipo
,CR.Cantidad,'0',CR.PesoTotal,0,'','','','','',C.FecPago,'0',0,'0',C.IdUsuario,C.CdOrigen,M.nRemolque,M.TipoAfiVehic,'',D.ModdDev,C.IdVehiculo
,C.TipMuc,C.Manifiesto,C.IdCiaMuc,D.TipCom,D.Comprobante,D.IdCiaCom,1,0,D.Fecha,D.Observacion,D.TimeSys,0,C.CdRuta,C.CdOrigen,C.CdDestino,M.IdPoseedor,M.IdConductor,'','',D.Cumplido,D.IdCiaDoc
FROM Trn_TraDevCum AS D INNER JOIN Trn_TraCumplido AS C ON D.TipDoc=C.TipDoc AND D.Cumplido=C.Cumplido AND D.IdCiaDoc=C.IdCia
INNER JOIN Trn_TraManifiesto AS M ON C.TipMuc=M.TipDoc AND C.Manifiesto=M.Manifiesto AND C.IdCiaMuc=M.IdCia
LEFT JOIN (SELECT TipDoc,Cumplido,IdCia,SUM(Cantidad) AS Cantidad,SUM(PesoNeto) AS PesoTotal,SUM(PesoNeto*TarifClie) AS TotalCobro,SUM(PesoNeto*TarifPago) AS TotalPagos
FROM Trn_TraCumRemesas GROUP BY TipDoc,Cumplido,IdCia) AS CR ON D.TipDoc=CR.TipDoc AND D.Cumplido=CR.Cumplido AND D.IdCiaDoc=CR.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dfc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dfc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
 SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrSobretasa,D.VrRetencion,D.VrReteICA,D.VrReteIVA,D.VrFletes
,D.VrCargos,D.VrOtrDcto,D.VrImpGlobal,D.VrOtros,D.VrCostos,D.VrNeto,0,0,0,0,D.CantPuntos,'0',D.Cantidad,MulPlazos,IdForma,'','0'
,DetallePago,'0',F.FecPedido,D.IdVend,D.TarifaCom,'0',D.IdUsuario,D.IdLocEnv,ModdDev,'','',D.Modalidad,pVehiculo,D.TipDoc,D.Factura,D.IdCiaDoc,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,D.Fecha,D.Observacion,D.TimeSys,D.VrImpCons
,F.CdRuta,D.IdLocEnv,'','',F.CdConductor,'','',D.Pedido,D.IdCiaPed
 FROM Trn_DevFcr AS D INNER JOIN Trn_Facturas AS F ON D.TipDoc=F.TipDoc  AND D.Factura=F.Factura  AND D.IdCiaDoc=F.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR D.IdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DfcDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DfcDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpConsumo)
 SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,KarValor,KarDcto,KarIva,KarSobTasa,KarReteFte,KarIca,D.VrReteIVA,D.VrFletes
,D.VrCargos,D.VrOtrDcto,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarIva-KarDcto+KarImpGlobal+KarSobTasa+KarSoldicom,0,0,0,0,D.CantPuntos,IdProducto,KarCantidad,MulPlazos,IdForma,'','0'
,DetallePago,'0',F.FecPedido,D.IdVend,D.TarifaCom,'0',D.IdUsuario,D.IdLocEnv,ModdDev,'','',D.Modalidad,pVehiculo,TipPed,D.Pedido,D.IdCiaPed,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Factura,FecDoc,D.Observacion,D.TimeSys,ISNULL(KarImpCon,0)
 FROM Trn_DevFcr AS D INNER JOIN  Trn_Facturas AS F ON D.TipDoc=F.TipDoc  AND D.Factura=F.Factura  AND D.IdCiaDoc=F.IdCia
 INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Entradas) AS KarCantidad,SUM(VrPrecio*Entradas) AS KarValor
,SUM(VrIvaEnt) AS KarIva,SUM(VrDctoEnt) AS KarDcto,SUM(VrCostoEnt) AS KarCosto,SUM(VrIcaEnt) AS KarIca,SUM(VrReteEnt) AS KarReteFte
,SUM(Sobretasa*Entradas) AS KarSobTasa,SUM(Soldicom*Entradas) AS KarSoldicom,SUM(ImpGlobal*Entradas) AS KarImpGlobal,SUM(VrImpCon) AS KarImpCon
 FROM  Trn_Kardex  WHERE TipDoc IN ('DFC','DF1','DF2','DF3','DF4','DF5') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON D.TipDev=K.KarTipoDoc  AND D.Devolucion=K.KarNumDoc  AND D.IdCia=K.KarIdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DfcT]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DfcT] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,DV.TipDev,DV.Devolucion,DV.IdCia,DV.Fecha,DV.IdConcepto,DV.IdCliente,DV.IdAgencia,D.VrUnitario*D.Cantidad,D.VrDescuento,D.VrImpuesto,0,D.VrRetencion,D.VrReteIca,0,0
,0,D.VrFaltante,D.VrSeguroRem,D.VrAutRetIca,D.VrCosto*D.CantPago,(D.VrUnitario*D.Cantidad)-D.VrDescuento+D.VrImpuesto,0,0,0,0,D.Cantidad,D.CdMercancia,D.PesoNeto,0,F.IdForma,'','0'
,CASE WHEN LEN(D.Descripcion)>150 THEN SUBSTRING(D.Descripcion,1,150) ELSE D.Descripcion END ,'0',D.FecRemesa,DV.IdVend,DV.TarifaCom,'0',DV.IdUsuario,DV.IdLocEnv,D.Referencia1,D.Referencia2,'',DV.ModdDev
,D.pVehiculo,D.TipRem,D.Remesa,D.IdCiaRem,DV.TipCom,DV.Comprobante,DV.IdCiaCom,1,0,DV.Fecha,DV.Observacion,DV.TimeSys,DV.VrImpCons,F.CdRuta,D.IdOrigen,D.IdDestino,D.NitTercero,F.CdConductor,'','',DV.Factura,DV.IdCiaDoc
FROM Trn_DevFcr AS DV INNER JOIN Trn_TraFacRemesas AS D ON DV.TipDev=D.TipDoc AND DV.Devolucion=D.Factura AND DV.IdCia=D.IdCia
INNER JOIN Trn_Facturas AS F ON DV.TipDoc=F.TipDoc AND DV.Factura=F.Factura AND DV.IdCiaDoc=F.IdCia
WHERE DV.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (DV.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (DV.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dfo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dfo] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpConsumo)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.NitCliente,D.CdAgencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,0,D.VrRetencion,D.VrReteICA,D.VrReteIVA,D.VrFletes
,D.VrCargos,D.VrOtrDcto,0,0,D.VrCostos,D.VrNeto,D.VrEfectivo,D.VrPagosOtr,0,0,D.CantPuntos,'0',D.Cantidad,D.EnEfectivo,F.CdForma,F.NumForma,F.CdBanco
,SUBSTRING(F.DetallePago,1,150),'0',D.FecPedido,D.IdVend,D.TarifaCom,D.nClieCon,D.IdCajero,D.IdLocal,Referncia1,Referncia2,'',D.Modalidad,'','PED',D.Pedido,D.IdCiaPed,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Factura,FecDoc,D.Observacion,D.TimeSys,D.VrImpCons
 FROM Trn_DevFco AS D INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DfoDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DfoDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpConsumo)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.NitCliente,D.CdAgencia,KarValor,KarDcto,KarIva,0,KarReteFte,KarIca,D.VrReteIVA,D.VrFletes
,D.VrCargos,D.VrOtrDcto,0,0,KarCosto,D.VrNeto,D.VrEfectivo,D.VrPagosOtr,0,0,D.CantPuntos,IdProducto,KarCantidad,D.EnEfectivo,F.CdForma,F.NumForma,F.CdBanco
,SUBSTRING(F.DetallePago,1,150),'0',D.FecPedido,D.IdVend,D.TarifaCom,D.nClieCon,D.IdCajero,D.IdLocal,Referncia1,Referncia2,'',D.Modalidad,'','PED',D.Pedido,D.IdCiaPed,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Factura,FecDoc,D.Observacion,D.TimeSys,ISNULL(KarImpCon,0)
 FROM Trn_DevFco AS D INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Entradas) AS KarCantidad,SUM(VrPrecio*Entradas) AS KarValor
,SUM(VrIvaEnt) AS KarIva,SUM(VrDctoEnt) AS KarDcto,SUM(VrCostoEnt) AS KarCosto,SUM(VrIcaEnt) AS KarIca,SUM(VrReteEnt) AS KarReteFte,SUM(VrImpCon) AS KarImpCon
 FROM  Trn_Kardex  WHERE TipDoc IN ('DFO','DO1','DO2','DO3','DO4','DO5') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON D.TipDev=K.KarTipoDoc  AND D.Devolucion=K.KarNumDoc  AND D.IdCia=K.KarIdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dlg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dlg] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDev VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdPropietario,'0',D.VrGastos,0,0,0,0,0,0,0,D.VrOtrosCred,0,0,0,D.VrCombustible,D.VrAnticipos,0,0,D.VrDiferencia,0
,D.galsComb,'0',D.PesoTotal,L.LiqMixto,'','','',L.DescMcias,'',D.FecDoc,D.NitEmpresa,0,'0',D.IdUsuario,L.IdLocOrigen,L.Referencia,D.ModdDev,'',D.Modalidad,D.IdVehiculo
,D.TipMuc,D.Manifiesto,D.IdCiaMuc,D.TipCom,D.Comprobante,D.IdCiaCom,1,0,D.Fecha,D.Observacion,D.TimeSys,0,L.IdRuta,L.IdLocOrigen,L.IdLocDestino,D.IdPoseedor,D.IdConductor,'','',D.Liquidacion,D.IdCiaDoc
FROM Trn_TraDevLeg AS D INNER JOIN Trn_TraLiqViajes AS L ON D.TipDoc=L.TipDoc AND D.Liquidacion=L.Liquidacion AND D.IdCiaDoc=L.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
AND (D.TipDev=@pmTipDev OR @pmTipDev IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dls]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dls] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDev VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,O.IdCliente,O.IdAgencia,D.VrTotal,D.VrDescuento,D.VrIva,0,D.VrRetencion,D.VrReteIca,D.VrReteIva,D.VrOtros
,D.VrGastos,0,0,0,D.VrCosto,D.VrNeto,0,0,D.VrAnticipo,0,0,'0',D.Cantidad,D.CxPagar,'',L.NumCheque,'',O.TipoResiduo,'',L.FechaVence,L.IdConductor,0,'0',D.IdUsuario,O.IdOrigen,L.Referencia,L.TipoAfiVehic,O.NomRecibido,D.ModdDev,L.IdVehiculo
,L.TipOds,L.NumOrden,L.IdCiaOds,D.TipCom,D.Comprobante,D.IdCiaCom,1,0,D.Fecha,D.Observacion,D.TimeSys,D.VrReteCREE,O.CdRuta,O.IdOrigen,O.IdDestino,L.IdPoseedor,L.IdConductor,'','',D.Liquidacion,D.IdCiaDoc
FROM Trn_TraDevLgo AS D INNER JOIN Trn_TraOrdenLiq AS L ON D.TipDoc=L.TipDoc AND D.Liquidacion=L.Liquidacion AND D.IdCiaDoc=L.IdCia
INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.TipDev=@pmTipDev OR @pmTipDev IS NULL)
AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dnp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dnp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,0,0,VrSobretasa,0,0,0,0
,0,0,VrImpGlobal,VrOtros,VrCostos,VrNeto,VrNeto AS VrTotalEfe,0,0,0,0,'0',Cantidad,1,'EFE','','0'
,'','0',Null,IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','','NOTACALIB','','0',0,'00',TipCom,Comprobante,IdCiaCom,0,nNota,FecDoc,Observacion,TimeSys
 FROM Trn_DevPas
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DnpDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DnpDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',KarValor,KarDcto,KarIva,KarSobTasa,0,0,0,0
,0,0,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarSobTasa+KarIva+KarImpGlobal+KarSoldicom,0,0,0,0,0,IdProducto,KarCantidad,1,'EFE','','0'
,'','0',Null,IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','','NOTACALIB','','0',0,'00',TipCom,Comprobante,IdCiaCom,0,nNota,FecDoc,Observacion,TimeSys
 FROM Trn_DevPas  AS  D  INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Salidas) AS KarCantidad,SUM(VrPrecio*Salidas) AS KarValor
,SUM(VrIvaSal) AS KarIva,SUM(VrDctoSal) AS KarDcto,SUM(VrCostoSal) AS KarCosto,SUM(VrIcaSal) AS KarIca,SUM(VrReteSal) AS KarReteFte
,SUM(Sobretasa*Salidas) AS KarSobTasa,SUM(Soldicom*Salidas) AS KarSoldicom,SUM(ImpGlobal*Salidas) AS KarImpGlobal
 FROM  Trn_Kardex  WHERE TipDoc='DNP'  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON D.TipDev=K.KarTipoDoc  AND D.Devolucion=K.KarNumDoc  AND D.IdCia=K.KarIdCia
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dop]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dop] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,OM.IdPropietario,'0',OM.VrTotalFletes,OM.VrDescuento,OM.VrImpuestos,OM.VrEstampilla,OM.VrRetencion,OM.VrReteIca,0,OM.VrFondos
,OM.VrOtrosPagos,OM.VrOtrosDctos,OM.VrSeguros,OM.VrFaltantes,OM.VrTotalFletes-OM.VrDescuento,OM.VrNeto,0,0,OM.VrAnticipos,0,OM.Unidades,'',OM.PesoTotal,O.LiqRemesas,OM.CdForma,OM.NumCheque,''
,'','',O.FechaVence,'0',0,'0',D.IdUsuario,M.IdLocFletes,OM.Referencia,M.TipoAfiVehic,'',D.ModdDev,D.IdVehiculo,OM.TipMuc,OM.Manifiesto,OM.IdCiaMuc,D.TipCom,D.Comprobante,D.IdCiaCom,1,0,D.Fecha,D.Observacion,D.TimeSys
,OM.VrReteCREE,M.IdRuta,M.IdOrigen,M.IdDestino,D.IdPoseedor,D.IdConductor,'','',D.OrdPago,D.IdCiaDoc
FROM Trn_TraDevOdp AS D INNER JOIN Trn_TraOrdenPago AS O ON D.TipDoc=O.TipDoc AND D.OrdPago=O.OrdPago AND D.IdCiaDoc=O.IdCia
INNER JOIN Trn_TraOrdenManif AS OM ON D.TipDoc=OM.TipDoc AND D.OrdPago=OM.OrdPago AND D.IdCiaDoc=OM.IdCia
INNER JOIN Trn_TraManifiesto AS M ON OM.TipMuc=M.TipDoc AND OM.Manifiesto=M.Manifiesto AND OM.IdCiaMuc=M.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Drc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Drc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,C.IdCia,C.Fecha,IdConcepto,IdTercero,CdAgencia,VrPagado,VrCambio,0,0,0,0,0,VrTotal
,VrTotDebito,VrTotCredito,0,0,0,VrPagado-VrCambio,CASE IdForma WHEN 'EFE' THEN VrPagado-VrCambio ELSE 0 END,0,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,IdBanco
,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,NitCliente,0,'0',IdCajero,CdLocal,Referncia1,Referncia2,Beneficiario
,CASE C.TipDoc WHEN 'RCO' THEN 'RECIBOS' ELSE 'EGRCAJA' END,'',TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,0,Recibo,FecDoc,Observacion,TimeSys
 FROM Trn_DevCaj AS C INNER JOIN Trn_Pagos AS P ON C.TipDev=P.TipDoc AND C.Devolucion=P.Documento AND C.IdCia=P.IdCia
 WHERE  C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dva]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dva] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,D.Fecha,D.IdConcepto,M.IdPropietario,'0',M.VrFletes,M.VrDescuento,0,0,0,0,0,M.VrAnticipo+M.VrAntAdic,0,A.VrDeduccion,0,0,0,D.VrDevolucion,A.VrAnticipo,A.VrAbonado,0,0
,M.Cantidad,'0',M.PesoTotal,CASE WHEN A.TipoPago='EFECTIVO' THEN 1 ELSE 0 END,SUBSTRING(A.TipoPago,1,3),A.NumCheque,'',A.TipoPago,A.IdCta,A.FecCheque,A.CedBenef,0,'0',D.IdUsuario,M.IdOrigen,M.nRemolque,M.TipoAfiVehic,A.Beneficiario,D.ModdDev,D.IdVehiculo
,A.TipMuc,A.Manifiesto,A.IdCiaMuc,D.TipCom,D.Comprobante,D.IdCiaCom,1,D.Devolucion,D.Fecha,D.Observacion,D.TimeSys,0,M.IdRuta,M.IdOrigen,M.IdDestino,D.IdPoseedor,D.IdConductor,'','',D.Anticipo,D.IdCiaDoc
FROM Trn_TraDevAnt AS D INNER JOIN Trn_TraAnticipos AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
INNER JOIN Trn_TraManifiesto AS M ON A.TipMuc=M.TipDoc AND A.Manifiesto=M.Manifiesto AND A.IdCiaMuc=M.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (D.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dvc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,C.IdCia,C.Fecha,IdConcepto,NitCliente,CdAgencia,VrPagado,VrCambio,0,0,0,0,0,0,0,0,0,0,0,VrPagado-VrCambio,CASE IdForma WHEN 'EFE' THEN VrPagado-VrCambio ELSE 0 END
,0,0,0,0,'0',0,EnEfectivo,IdForma,NumForma,IdBanco,Detalle,CASE CdCta WHEN NULL THEN '0' WHEN '' THEN '0' ELSE CdCta  END,FecForma,'0',0,'0',IdCajero,CdLocal,Referncia1,P.Referncia2,Beneficiario,ModdDev,'',TipRef,DocRef,IdCiaRef
,TipCom,Comprobante,IdCiaCom,0,Consignacion,FecDoc,Observacion,TimeSys
 FROM Trn_DevCns AS C INNER JOIN Trn_Pagos AS P ON C.TipDev=P.TipDoc AND C.Devolucion=P.Documento AND C.IdCia=P.IdCia
 WHERE  C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dve]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dve] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdProv,'0',D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrSobretasa,D.VrRetencion,D.VrReteICA,D.VrReteIVA,D.VrFletes
,D.VrCargos,D.VrOtrDcto,D.VrImpGlobal,D.VrOtros,0,D.VrNeto,0,0,0,0,0,'0',D.Cantidad,D.CxPagar,'EFE',D.Factura,'0'
,ModdDev,'0',FechaFac,CASE D.NitFletes WHEN Null THEN '0' WHEN '' THEN '0' ELSE D.NitFletes END,0,'0',D.IdUsuario,'0',D.Factura AS FacReferencia,D.DocEquiv,'',D.Modalidad,'',TipOdc,OCompra,IdCiaOdc
,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Entrada,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_DevEnt AS D INNER JOIN  Trn_Entradas AS E ON D.TipDoc=E.TipDoc AND  D.Entrada=E.Entrada AND  D.IdCiaDoc=E.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DveDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DveDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdProv,'0',KarValor,KarDcto,KarIva,KarSobTasa,KarReteFte,KarIca,D.VrReteIVA,D.VrFletes
,D.VrCargos,D.VrOtrDcto,KarImpGlobal,KarSoldicom,KarCosto,KarValor-KarDcto+KarIva+KarSobTasa+KarImpGlobal+KarSoldicom,0,0,0,0,0,IdProducto,KarCantidad,D.CxPagar,'EFE',D.Factura,'0'
,ModdDev,'0',FechaFac,CASE D.NitFletes WHEN Null THEN '0' WHEN '' THEN '0' ELSE D.NitFletes END,0,'0',D.IdUsuario,'0',D.Factura AS FacReferencia,D.DocEquiv,'',D.Modalidad,'',TipOdc,OCompra,IdCiaOdc
,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Entrada,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_DevEnt AS D INNER JOIN  Trn_Entradas AS E ON D.TipDoc=E.TipDoc AND  D.Entrada=E.Entrada AND  D.IdCiaDoc=E.IdCia
 INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Salidas) AS KarCantidad,SUM(VrPrecio*Salidas) AS KarValor
,SUM(VrIvaSal) AS KarIva,SUM(VrDctoSal) AS KarDcto,SUM(VrCostoSal) AS KarCosto,SUM(VrIcaSal) AS KarIca,SUM(VrReteSal) AS KarReteFte
,SUM(Sobretasa*Salidas) AS KarSobTasa,SUM(Soldicom*Salidas) AS KarSoldicom,SUM(ImpGlobal*Salidas) AS KarImpGlobal
 FROM  Trn_Kardex  WHERE TipDoc IN ('DVE','DEI') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON D.TipDev=K.KarTipoDoc  AND D.Devolucion=K.KarNumDoc  AND D.IdCia=K.KarIdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dvp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dvp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal+VrCreTotal+VrConTotal,VrConDcto+VrCreDcto,VrCreImp+VrConImp,VrSobretasa,0,0,0,VrSubTotal AS TotalComb
,VrSobrantes,VrFaltantes,VrImpGlobal,VrOtros,VrCostos+VrConCos+VrCreCos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrGastComb+VrGastOtros,0,'0',Cantidad,0,'EFE','','0'
,'','0',FecCorte,IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'','',Modalidad,'','COR',NumCorte,'00',TipCom,Comprobante,IdCiaCom,0,Planilla,FecDoc,Observacion,TimeSys
 FROM Trn_DevPla
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DvpDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DvpDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',KarValor,KarDcto,KarIva,KarSobTasa,0,0,0,0
,VrSobrantes,VrFaltantes,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarIva+KarSobTasa+KarImpGlobal+KarSoldicom,VrEfectivo,VrPagosOtr,VrCreditos,VrGastComb+VrGastOtros,0,IdProducto,KarCantidad,0,'EFE','','0'
,'','0',FecCorte,IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'','',Modalidad,'','COR',NumCorte,'00',TipCom,Comprobante,IdCiaCom,0,Planilla,FecDoc,Observacion,TimeSys
 FROM Trn_DevPla  AS D  INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Entradas) AS KarCantidad,SUM(VrPrecio*Entradas) AS KarValor
,SUM(VrIvaEnt) AS KarIva,SUM(VrDctoEnt) AS KarDcto,SUM(VrCostoEnt) AS KarCosto,SUM(VrIcaEnt) AS KarIca,SUM(VrReteEnt) AS KarReteFte
,SUM(Sobretasa*Entradas) AS KarSobTasa,SUM(Soldicom*Entradas) AS KarSoldicom,SUM(ImpGlobal*Entradas) AS KarImpGlobal
 FROM  Trn_Kardex  WHERE TipDoc='DVP' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON D.TipDev=K.KarTipoDoc  AND D.Devolucion=K.KarNumDoc  AND D.IdCia=K.KarIdCia
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Dvs]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Dvs] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDev,Devolucion,IdCia,Fecha,IdConcepto,IdTercero,CdAgencia,VrSubTotal,0,VrImpuesto,0,0,0,0,0
,0,0,0,0,VrCostos,VrNeto,0,0,0,0,0,'0',Cantidad,0,'EFE','','0'
,'','0',Null,NitCliente,0,'0',IdUsuario,'0',ModRequis,ModdDev,'',Modalidad,pVehiculo,TipOrd,NumOrden,IdCiaOrd,TipCom,Comprobante,IdCiaCom,0,Salida,FecDoc,Observacion,TimeSys
 FROM Trn_DevSal
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_DvsDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_DvsDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDev,Devolucion,IdCia,Fecha,IdConcepto,IdTercero,CdAgencia,KarValor,KarDcto,KarIva,0,0,0,0,0
,0,0,0,0,KarCosto,KarValor+KarIva,0,0,0,0,0,IdProducto,KarCantidad,0,'EFE','','0'
,'','0',Null,NitCliente,0,'0',IdUsuario,'0',ModRequis,ModdDev,'',Modalidad,pVehiculo,TipOrd,NumOrden,IdCiaOrd,TipCom,Comprobante,IdCiaCom,0,Salida,FecDoc,Observacion,TimeSys
 FROM Trn_DevSal  AS D INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Entradas) AS KarCantidad,SUM(VrPrecio*Entradas) AS KarValor
,SUM(VrIvaEnt) AS KarIva,SUM(VrDctoEnt) AS KarDcto,SUM(VrCostoEnt) AS KarCosto
 FROM  Trn_Kardex  WHERE TipDoc IN ('DVS','DSI') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON D.TipDev=K.KarTipoDoc  AND D.Devolucion=K.KarNumDoc  AND D.IdCia=K.KarIdCia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Egr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Egr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
 AS 
INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipCom,Comprobante,IdCia,Fecha,'0',IdTercero,'0',VrTotal,0,0,0,0,0,0,0,0,0,0,0,0,VrTotal AS ValNeto,CASE EnEfectivo WHEN 1 THEN VrTotal ELSE 0 END
,0,0,0,0,'0',0,EnEfectivo,CASE EnEfectivo WHEN 1 THEN  'EFE' ELSE 'CHE' END,NumCheque,IdBanco
,'',C.IdCta,FecCheque,CASE CedCondtor WHEN NULL THEN '0' WHEN '' THEN '0' ELSE CedCondtor END,0,'0',IdUsuario,'0','','',Beneficiario,'EGRESO',pVehiculo,TipDoc,Documento,IdCiaDoc,CASE WHEN TipEgr IS NULL OR LEN(TipEgr)=0 THEN '0' ELSE TipEgr END
 ,NEgreso,'00',Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Comprobantes AS C LEFT JOIN CtasCorrientes AS CT ON C.IdCta=CT.IdCta
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsEgreso<>0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Ent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Ent] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDoc,Entrada,IdCia,Fecha,IdConcepto,IdProv,'0',VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,VrImpGlobal,VrOtros,0,VrNeto,0,0,0,0,0,'0',Cantidad,CxPagar,'EFE',Factura,'0'
,'','0',FechaFac,CASE NitFletes WHEN Null THEN '0' WHEN '' THEN '0' ELSE NitFletes END,0,'0',IdUsuario,'0',Factura AS FacReferencia,DocEquiv,'',Modalidad,'',TipOdc,OCompra,IdCiaOdc,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Entradas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_EntDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_EntDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDoc,Entrada,IdCia,Fecha,IdConcepto,IdProv,'0',KarValor,KarDcto,KarIva,KarSobTasa,KarReteFte,KarIca,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarIva-KarDcto,0,0,0,0,0,IdProducto,KarCantidad,CxPagar,'EFE',Factura,'0'
,'','0',FechaFac,CASE NitFletes WHEN Null THEN '0' WHEN '' THEN '0' ELSE NitFletes END,0,'0',IdUsuario,'0',Factura AS FacReferencia,DocEquiv,'',Modalidad,'',TipOdc,OCompra,IdCiaOdc,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Entradas AS E  INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Entradas) AS KarCantidad,SUM(VrUnitario*Entradas) AS KarValor
,SUM(VrIvaEnt) AS KarIva,SUM(VrDctoEnt) AS KarDcto,SUM(VrCostoEnt) AS KarCosto,SUM(VrIcaEnt) AS KarIca,SUM(VrReteEnt) AS KarReteFte
,SUM(Sobretasa*Entradas) AS KarSobTasa,SUM(Soldicom*Entradas) AS KarSoldicom,SUM(ImpGlobal*Entradas) AS KarImpGlobal
 FROM  Trn_Kardex  WHERE TipDoc IN ('ENT','COM') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON E.TipDoc=K.KarTipoDoc  AND E.Entrada=K.KarNumDoc  AND E.IdCia=K.KarIdCia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Fco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Fco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpConsumo)
 SELECT @pmtmEst,TipDoc,Factura,IdCia,Fecha,IdConcepto,NitCliente,CdAgencia,VrSubTotal,VrDescuento,VrImpuesto,0,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,0,0,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,0,0,CantPuntos,'0',Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,SUBSTRING(DetallePago,1,150),'0',FecPedido,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referncia1,Referncia2,'',Modalidad,'',TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCons
 FROM Trn_Factcon
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_FcoDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_FcoDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpConsumo)
 SELECT @pmtmEst,TipDoc,Factura,IdCia,Fecha,IdConcepto,NitCliente,CdAgencia,KarValor,KarDcto,KarIva,0,KarReteFte,KarIca,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,0,0,KarCosto,VrNeto,VrEfectivo,VrPagosOtr,0,0,CantPuntos,IdProducto,KarCantidad,EnEfectivo,CdForma,NumForma,CdBanco
,SUBSTRING(DetallePago,1,150),'0',FecPedido,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referncia1,Referncia2,'',Modalidad,'',TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,ISNULL(KarImpCon,0)
 FROM Trn_Factcon AS F INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Salidas) AS KarCantidad,SUM(VrPrecio*Salidas) AS KarValor
,SUM(VrIvaSal) AS KarIva,SUM(VrDctoSal) AS KarDcto,SUM(VrCostoSal) AS KarCosto,SUM(VrIcaSal) AS KarIca,SUM(VrReteSal) AS KarReteFte,SUM(VrImpCon) AS KarImpCon
 FROM  Trn_Kardex  WHERE TipDoc IN ('FCO','FO1','FO2','FO3','FO4','FO5') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON F.TipDoc=K.KarTipoDoc  AND F.Factura=K.KarNumDoc  AND F.IdCia=K.KarIdCia
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Fcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Fcr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
 SELECT @pmtmEst,TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,VrImpGlobal,VrOtros,VrCostos,VrNeto,0,0,0,0,CantPuntos,'0',Cantidad,MulPlazos,IdForma,'','0'
,DetallePago,'0',FecPedido,IdVend,TarifaCom,'0',IdUsuario,IdLocEnv,'','','',Modalidad,pVehiculo,TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCons
,CdRuta,IdLocEnv,'','',CdConductor,'','',Remision,IdCiaRem
 FROM Trn_Facturas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_FcrDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_FcrDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpConsumo)
 SELECT @pmtmEst,TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,KarValor,KarDcto,KarIva,KarSobTasa,KarReteFte,KarIca,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarIva-KarDcto+KarSobTasa+KarSoldicom+KarImpGlobal,0,0,0,0,CantPuntos,IdProducto,KarCantidad,MulPlazos,IdForma,'','0'
,DetallePago,'0',FecPedido,IdVend,TarifaCom,'0',IdUsuario,IdLocEnv,'','','',Modalidad,pVehiculo,TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,ISNULL(KarImpCon,0)
 FROM Trn_Facturas  AS F INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Salidas) AS KarCantidad,SUM(VrPrecio*Salidas) AS KarValor
,SUM(VrIvaSal) AS KarIva,SUM(VrDctoSal) AS KarDcto,SUM(VrCostoSal) AS KarCosto,SUM(VrIcaSal) AS KarIca,SUM(VrReteSal) AS KarReteFte
,SUM(Sobretasa*Salidas) AS KarSobTasa,SUM(Soldicom*Salidas) AS KarSoldicom,SUM(ImpGlobal*Salidas) AS KarImpGlobal,SUM(VrImpCon) AS KarImpCon
 FROM  Trn_Kardex  WHERE TipDoc IN ('FCR','FC1','FC2','FC3','FC4','FC5') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON F.TipDoc=K.KarTipoDoc  AND F.Factura=K.KarNumDoc  AND F.IdCia=K.KarIdCia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_FcrT]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_FcrT] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
 SELECT @pmtmEst,F.TipDoc,F.Factura,F.IdCia,F.Fecha,F.IdConcepto,F.IdCliente,F.IdAgencia,D.VrUnitario*D.Cantidad,D.VrDescuento,D.VrImpuesto,0,D.VrRetencion,D.VrReteIca,0,0
,0,D.VrFaltante,D.VrSeguroRem,D.VrAutRetIca,D.VrCosto*D.CantPago,(D.VrUnitario*D.Cantidad)-D.VrDescuento+D.VrImpuesto,0,0,0,0,D.Cantidad,D.CdMercancia,D.PesoNeto,0,F.IdForma,'','0'
,CASE WHEN LEN(D.Descripcion)>150 THEN SUBSTRING(D.Descripcion,1,150) ELSE D.Descripcion END ,'0',D.FecRemesa,F.IdVend,F.TarifaCom,'0',F.IdUsuario,F.IdLocEnv,D.Referencia1,D.Referencia2,'',F.Modalidad
,D.pVehiculo,D.TipRem,D.Remesa,D.IdCiaRem,F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado,F.NumDev,F.FecDev,F.Observacion,F.TimeSys,F.VrImpCons,F.CdRuta,D.IdOrigen,D.IdDestino,D.NitTercero,F.CdConductor,'','',F.Pedido,F.IdCiaPed
FROM Trn_Facturas AS F INNER JOIN Trn_TraFacRemesas AS D ON F.TipDoc=D.TipDoc AND F.Factura=D.Factura AND F.IdCia=D.IdCia
WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (F.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Lga]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Lga] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,L.TipDoc,L.Liquidacion,L.IdCia,L.Fecha,L.IdConcepto,L.IdPropietario,'0',L.VrGastos,0,0,0,0,0,0,0,L.VrOtrosCred,0,0,0,L.VrCombustible,L.VrAnticipos,0,0,L.VrDiferencia,0
,L.galsComb,'0',L.PesoTotal,L.LiqMixto,'','','',L.DescMcias,'',L.FechaMuc,L.NitEmpresa,0,'0',L.IdUsuario,L.IdLocOrigen,L.Referencia,L.Modalidad,'',L.Modalidad,L.IdVehiculo
,L.TipMuc,L.Manifiesto,L.IdCiaMuc,L.TipCom,L.Comprobante,L.IdCiaCom,L.Anulado,L.NumDev,L.FecDev,L.Observacion,L.TimeSys,0,L.IdRuta,L.IdLocOrigen,L.IdLocDestino,L.IdPoseedor,L.IdConductor,'','',L.NumDocRef,L.IdCiaRef
FROM Trn_TraLiqViajes AS L
WHERE L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (L.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (L.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
AND (L.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Muc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Muc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,M.TipDoc,M.Manifiesto,M.IdCia,M.Fecha,'0',M.IdPropietario,'0',M.VrFletes,M.VrDescuento,0,0,M.VrRetencion,M.VrReteIca,0,M.VrPagos,M.VrCargos,M.VrDctos,0,0,M.VrFletes,M.VrNeto,0,0,M.VrAnticipo,M.VrAntAdic
,M.Cantidad,'0',M.PesoTotal,0,'',MA.TipoRuta,'','','',M.FecDespacho,M.CdCondRelev,0,'0',M.IdUsuario,M.IdLocFletes,M.nRemolque,M.TipoAfiVehic,MA.NomRemite,MA.TipoMintrans,M.IdVehiculo
,'RMT',M.Remesa,M.IdCiaRem,M.TipCom,M.Comprobante,M.IdCiaCom,M.Anulado,0,M.FecDev,Substring (M.Observacion,1,250),M.TimeSys,0,M.IdRuta,M.IdOrigen,M.IdDestino,M.IdPoseedor,M.IdConductor,'','',M.Cumplido,M.IdCiaCump
FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND M.Manifiesto=MA.Manifiesto AND M.IdCia=MA.IdCia
WHERE M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (M.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (M.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_MucD]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_MucD] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,M.TipDoc,M.Manifiesto,M.IdCia,M.Fecha,R.CdConcepto,R.IdCliente,R.IdAgencia,D.PesoNeto*MR.TarifPago,0,0,0,0,0,0,D.PesoNeto*MR.TarifTabla,0,0,0,0,D.PesoNeto*MR.TarifPago,D.PesoNeto*MR.TarifPago,0,0,M.VrAnticipo,M.VrAntAdic
,D.Cantidad,D.IdMercancia,D.PesoNeto,0,'',MA.TipoRuta,'',CASE WHEN LEN(D.DescripMcias)>150 THEN SUBSTRING(D.DescripMcias,1,150) ELSE D.DescripMcias END,'',M.FecDespacho,M.CdCondRelev,0,'0',M.IdUsuario
,M.IdLocFletes,D.Referencia1,D.Referencia2,CASE WHEN LEN(D.Remitente)>150 THEN SUBSTRING(D.Remitente,1,150) ELSE D.Remitente END,MA.TipoMintrans,M.IdVehiculo,MR.TipRem,MR.Remesa,MR.IdCiaRem,M.TipCom,M.Comprobante,M.IdCiaCom
,M.Anulado,0,M.FecDev,SUBSTRING(M.Observacion,1,250),M.TimeSys,0,M.IdRuta,D.IdOrigen,D.IdDestino,M.IdPoseedor,M.IdConductor,D.NitRemite,D.NitDestntario,R.NumPedido,R.IdCiaPed
FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND M.Manifiesto=MA.Manifiesto AND M.IdCia=MA.IdCia
INNER JOIN Trn_TraManifRem AS MR ON M.TipDoc=MR.TipDoc AND M.Manifiesto=MR.Manifiesto AND M.IdCia=MR.IdCia
INNER JOIN Trn_TraRemMcias AS D ON MR.TipRem=D.TipDoc AND MR.Remesa=D.NumOrden AND MR.IdCiaRem=D.IdCia AND MR.ItemRem=D.Item
INNER JOIN Trn_TraRemesa AS R ON MR.TipRem=R.TipDoc AND MR.Remesa=R.NumOrden AND MR.IdCiaRem=R.IdCia
WHERE M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (M.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (M.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Not]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Not] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,0,VrImpuesto,0,VrRetencion,VrReteICA,VrReteIVA,VrSancion
,0,0,0,0,VrCosto,VrNeto,VrOtros AS VlrEfectivo,0,0,0,0,CdProducto,Cantidad,PrestCaja,CdForma,NumCheque,CdBanco
,'','0',FecDcm,IdVend,TarifaCom,'0',CdCajero,IdLocal,Referencia,'','',Modalidad,pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,0,0,Null,Observacion,TimeSys
 FROM Trn_Notas
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND CdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_NotBus]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_NotBus] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,ValorTotal,0,ValorIva,0,ValorReteFte,ValorReteIca,0,ValorSancion
,0,0,0,0,ValorCosto,ValorNeto,0,0,0,0,0,'0',0,PrestCaja,'0',NumCheque,IdBanco
,'','0',FecVence,IdVendedor,Comision,'0',IdUsuario,'0',Referencia,'','','BUSES',IdVehiculo,TipDcm,Documento,IdCiaDoc,TipCom,Comprobante,IdCiaCom,0,0,Null,Observacion,TimeSys
 FROM Trn_NotasBuses
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_NotPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_NotPre] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,0,VrImpuesto,0,VrRetencion,VrReteICA,VrReteIVA,VrSancion
,0,0,0,0,0,VrNeto,VrOtros AS VlrEfectivo,0,0,0,0,'0',0,0,CdForma,NumCheque,CdBanco
,'','0',FecDcm,IdVend,TarifaCom,'0',IdUsuario,'0',Referencia,'','',Modalidad,pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,0,0,Null,Observacion,TimeSys
 FROM Trn_FinNotas
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od1]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Od1] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,D.ValorTotal,D.ValorDcto,0,0,D.ValorReteFte,D.ValorReteIca,D.ValorReteIva,D.ValorPagMas
,D.ValorOtros,D.ValorOtrosDct,0,D.ValorAhorro,0,D.ValorNeto,CASE D.EnEfectivo WHEN 1 THEN D.ValorNeto ELSE 0 END,CASE D.EnEfectivo WHEN 0 THEN D.ValorNeto ELSE 0 END,0,0,0,'0',0,D.EnEfectivo,'EFE',D.NumCheque,D.IdBanco
,'',R.IdCta,Null,D.IdVendedor,D.Comision,'0',D.IdUsuario,'0',R.Referencia,'','',D.Modalidad,D.IdVehiculo,TipCar,Cartulina,IdCiaCar,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Recibo,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od1Det]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Od1Det] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,R.IdCia,R.Fecha,IdConcepto,IdCliente,IdAgencia,VrPagado,VrCambio,0,0,ValorReteFte,ValorReteIca,ValorReteIva,ValorPagMas
,ValorOtros,ValorOtrosDct,0,ValorAhorro,0,VrPagado-VrCambio,CASE IdForma WHEN 'EFE' THEN VrPagado-VrCambio ELSE 0 END, CASE IdForma WHEN 'EFE' THEN 0 ELSE  VrPagado-VrCambio END
,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,P.IdBanco,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,IdVendedor,Comision,'0',R.IdUsuario,CdLocal,Referncia1,Referncia2,Beneficiario
,Modalidad,IdVehiculo,R.TipDoc,Recibo,IdCiaDoc,TipCom,Comprobante,IdCiaCom,0,Recibo,FecDoc,Observacion,TimeSys
 FROM Trn_DevRecBuses AS R INNER JOIN Trn_Pagos AS P ON R.TipDev=P.TipDoc AND R.Devolucion=P.Documento AND R.IdCia=P.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od2]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Od2] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,D.VrSubTotal,0,0,0,D.VrRetencion,D.VrReteICA,D.VrReteIVA,D.VrPagosMas
,D.VrOtros,D.VrOtrDcto,0,0,0,D.VrNeto,D.VrEfectivo,0,0,0,0,'0',0,D.EnEfectivo,CdForma,NumForma,CdBanco
,SUBSTRING(DetallePago,1,150),CdCta,D.FecPago,D.IdVend,D.TarifaCom,'0',D.IdUsuario,'0',D.Referencia,'','','RC2',R.pVehiculo,R.TipDcm,R.Documento,R.IdCiaDcm,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Recibo,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_FinDevRec AS D INNER JOIN Trn_FinRecibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Od2Det]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Od2Det] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,R.IdCia,R.Fecha,IdConcepto,IdCliente,IdAgencia,VrPagado,VrCambio,0,0,VrRetencion,VrReteICA,VrReteIVA,VrPagosMas
,VrOtros,VrOtrDcto,0,0,0,VrPagado-VrCambio,VrEfectivo,0,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,IdBanco
,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,IdVend,TarifaCom,'0',R.IdUsuario,CdLocal,Referncia1,Referncia2,Beneficiario,'RC2','0',TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,0,Recibo,FecDoc,Observacion,TimeSys
 FROM Trn_FinDevRec AS R INNER JOIN Trn_Pagos AS P ON R.TipDev=P.TipDoc AND R.Devolucion=P.Documento AND R.IdCia=P.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Odb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Odb] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.IdCliente,D.IdAgencia,D.VrSubTotal,D.VrDescuento,0,0,D.VrRetencion,D.VrReteICA,D.VrReteIVA,D.VrPagosMas
,D.VrOtros,D.VrOtrDcto,0,D.VrAhorro,0,D.VrNeto,D.VrEfectivo,0,0,0,0,'0',0,D.EnEfectivo,CdForma,NumForma,CdBanco
,SUBSTRING(DetallePago,1,150),CdCta,D.FecPago,D.IdVend,D.TarifaCom,'0',D.IdCajero,D.IdLocal,D.Referencia,'','',D.Modalidad,D.pVehiculo,D.TipDcm,D.Documento,D.IdCiaDcm,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Recibo,FecDoc,D.Observacion,D.TimeSys
 FROM Trn_DevRec AS D INNER JOIN Trn_Recibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_OdbDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_OdbDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDev,Devolucion,R.IdCia,R.Fecha,IdConcepto,IdCliente,IdAgencia,VrPagado,VrCambio,0,0,VrRetencion,VrReteICA,VrReteIVA,VrPagosMas
,VrOtros,VrOtrDcto,0,VrAhorro,0,VrPagado-VrCambio,VrEfectivo,0,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,IdBanco
,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,IdVend,TarifaCom,'0',IdCajero,CdLocal,Referncia1,Referncia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,0,Recibo,FecDoc,Observacion,TimeSys
 FROM Trn_DevRec AS R INNER JOIN Trn_Pagos AS P ON R.TipDev=P.TipDoc AND R.Devolucion=P.Documento AND R.IdCia=P.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Odp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Odp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,O.TipDoc,O.OrdPago,O.IdCia,O.Fecha,O.IdConcepto,OM.IdPropietario,'0',OM.VrTotalFletes,OM.VrDescuento,OM.VrImpuestos,OM.VrEstampilla,OM.VrRetencion,OM.VrReteIca,0,OM.VrFondos
,OM.VrOtrosPagos,OM.VrOtrosDctos,OM.VrSeguros,OM.VrFaltantes,OM.VrTotalFletes-OM.VrDescuento,OM.VrNeto,0,0,OM.VrAnticipos,0,OM.Unidades,'',OM.PesoTotal,O.LiqRemesas,OM.CdForma,OM.NumCheque,''
,'','',O.FechaVence,'0',0,'0',O.IdUsuario,M.IdLocFletes,OM.Referencia,M.TipoAfiVehic,'',O.Modalidad,OM.IdVehiculo,OM.TipMuc,OM.Manifiesto,OM.IdCiaMuc,O.TipCom,O.Comprobante,O.IdCiaCom,O.Anulado,O.NumDev,O.FecDev,O.Observacion,O.TimeSys
,OM.VrReteCREE,M.IdRuta,M.IdOrigen,M.IdDestino,OM.IdPoseedor,OM.IdConductor,'','',OM.Egreso,OM.IdCiaEgr
FROM Trn_TraOrdenPago AS O INNER JOIN Trn_TraOrdenManif AS OM ON O.TipDoc=OM.TipDoc AND O.OrdPago=OM.OrdPago AND O.IdCia=OM.IdCia
INNER JOIN Trn_TraManifiesto AS M ON OM.TipMuc=M.TipDoc AND OM.Manifiesto=M.Manifiesto AND OM.IdCiaMuc=M.IdCia
WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (O.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Odt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Odt] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,O.TipDoc,O.NumOrden,O.IdCia,O.Fecha,O.TipDoc,O.IdConductor,'0',O.VrServicios,0,0,0,0,0,0,O.VrOtros,O.VrManoObra,0,0,0,O.VrRepuestos,O.VrServicios
,0,0,0,0,O.kmRemolque,'0',O.kmVehiculo,0,'',O.nRemolque,'',O.IdCenSer,'',O.FechaOrden,O.IdOperario,0,O.IdSupervisor,O.IdUsuario,'0',O.nRemolque,O.IdCenSer,'',O.Modalidad,O.IdVehiculo
,O.TipFact,O.NumFactura,O.IdCiaFact,'0',0,'00',O.Anulado,O.NumDev,O.FecDev,O.Observacion,O.TimeSys,0,'','','',O.IdConductor,O.IdConductor,'','',0,''
FROM Trn_MttoOrden AS O
WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (O.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Opt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Opt] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,L.TipDoc,L.Liquidacion,L.IdCia,L.Fecha,L.IdConcepto,O.IdCliente,O.IdAgencia,L.VrTotal,L.VrDescuento,L.VrIva,0,L.VrRetencion,L.VrReteIca,L.VrReteIva,L.VrOtros
,L.VrGastos,0,0,0,L.VrCosto,L.VrNeto,0,0,L.VrAnticipo,0,0,'0',L.Cantidad,L.CxPagar,'',L.NumCheque,'',O.TipoResiduo,'',L.FechaVence,L.IdConductor,0,'0',L.IdUsuario,O.IdOrigen,L.Referencia,L.TipoAfiVehic,O.NomRecibido,O.Modalidad,L.IdVehiculo
,L.TipOds,L.NumOrden,L.IdCiaOds,L.TipCom,L.Comprobante,L.IdCiaCom,L.Anulado,L.NumDev,L.FecDev,L.Observacion,L.TimeSys,L.VrReteCREE,O.CdRuta,O.IdOrigen,O.IdDestino,L.IdPoseedor,L.IdConductor,'','',L.Egreso,L.IdCiaEgr
FROM Trn_TraOrdenLiq AS L INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
WHERE L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (L.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
AND (L.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (L.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Ost]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Ost] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,O.TipDoc,O.NumOrden,O.IdCia,O.Fecha,O.TipDoc,O.IdCliente,O.IdAgencia,O.VrTotal,0,0,0,0,0,0,0,0,0,0,0,O.VrCosto,O.VrTotal
,0,0,0,0,0,'0',O.Cantidad,0,'',O.RemCliente,'',O.TipoResiduo,'',O.FecDespacho,O.IdConductor,0,'0',O.IdUsuario,O.IdOrigen,O.nRemolque,O.TipoAfiVehic,O.NomRecibido,O.Modalidad,O.IdVehiculo
,O.TipFact,O.NumFactura,O.CdCiaFact,'0',0,'00',O.Anulado,0,O.FecDev,O.Observacion,O.TimeSys,0,O.CdRuta,O.IdOrigen,O.IdDestino,O.IdPoseedor,O.IdConductor,'','',O.NumRemesa,O.CdCiaRem 
FROM Trn_TraOrdenServ AS O
WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (O.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (O.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Pas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Pas] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,nNota,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,0,0,VrSobretasa,0,0,0,0
,0,0,VrImpGlobal,VrOtros,VrCostos,VrNeto,VrNeto AS VrTotalEfe,0,0,0,0,'0',Cantidad,1,'EFE','','0'
,'','0',Null,IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','','NOTACALIB','','0',0,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCalibra
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_PasDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_PasDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,nNota,IdCia,Fecha,IdConcepto,NitTercero,'0',KarValor,KarDcto,KarIva,KarSobTasa,0,0,0,0
,0,0,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarIva+KarSobTasa+KarSoldicom+KarImpGlobal,0,0,0,0,0,IdProducto,KarCantidad,1,'EFE','','0'
,'','0',Null,IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','','NOTACALIB','','0',0,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCalibra AS N INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Entradas) AS KarCantidad,SUM(VrPrecio*Entradas) AS KarValor
,SUM(VrIvaEnt) AS KarIva,SUM(VrDctoEnt) AS KarDcto,SUM(VrCostoEnt) AS KarCosto,SUM(VrIcaEnt) AS KarIca,SUM(VrReteEnt) AS KarReteFte
,SUM(Sobretasa*Entradas) AS KarSobTasa,SUM(Soldicom*Entradas) AS KarSoldicom,SUM(ImpGlobal*Entradas) AS KarImpGlobal
 FROM  Trn_Kardex  WHERE TipDoc='PAS' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON N.TipDoc=K.KarTipoDoc  AND N.nNota=K.KarNumDoc  AND N.IdCia=K.KarIdCia
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Pdt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Pdt] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,P.TipDoc,P.Pedido,P.IdCia,P.Fecha,0,P.IdCliente,P.IdAgencia,P.VrCobro,0,0,0,0,0,0,P.VrSeguro,P.VrPagos,P.VrDctos,0,0,P.VrFletes,P.VrCobro
,0,0,P.VrDeclarado,0,P.CantDesp,'0',P.Cantidad,0,'',PA.TipoRuta,'',PA.EmbAdicional,'',P.FecDespacho,P.IdVend,0,'0',P.IdUsuario,P.IdLocOrigen,PA.TipoTrans,PA.CdTipoVeh,PA.NomCliente,PA.TipoServicio,''
,P.TipRem,P.Remesa,P.IdCiaRem,'0',0,'',P.Anulado,0,P.FecDev,P.Observacion,P.TimeSys,0,PA.CdRutaTarif,P.IdLocOrigen,P.IdLocDestino,'','',P.IdRemitente,P.IdDestinatario,P.Factura,P.IdCiaFac
FROM Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
WHERE P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (P.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
AND (P.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (P.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_PdtD]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_PdtD] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,P.TipDoc,P.Pedido,P.IdCia,P.Fecha,0,P.IdCliente,P.IdAgencia,D.TarifClie*D.PesoNeto,0,0,0,0,0,0,D.VrSeguro,0,0,0,0,D.TarifPago*D.PesoNeto,D.TarifClie*D.PesoNeto
,0,0,D.VrDeclarado,0,D.Cantidad,D.IdMercancia,D.PesoNeto,0,'',PA.TipoRuta,'',CASE WHEN LEN(D.DescripMcias)>150 THEN SUBSTRING(D.DescripMcias,1,150) ELSE D.DescripMcias END,'',P.FecDespacho,P.IdVend,0,'0',P.IdUsuario,D.IdOrigen
,D.Referencia1,D.Referencia2,CASE WHEN LEN(D.Remitente)>150 THEN SUBSTRING(D.Remitente,1,150) ELSE D.Remitente END,PA.TipoServicio,D.CdTipoVehic,P.TipRem,P.Remesa,P.IdCiaRem,'0',0,''
,P.Anulado,0,P.FecDev,P.Observacion,P.TimeSys,0,PA.CdRutaTarif,D.IdOrigen,D.IdDestino,'','',D.NitRemite,D.NitDestntario,P.Factura,P.IdCiaFac
FROM Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
INNER JOIN Trn_TraPedMcias AS D ON P.TipDoc=D.TipDoc AND P.Pedido=D.Pedido AND P.IdCia=D.IdCia
WHERE P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (P.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
AND (P.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (P.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Pla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Pla] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,Planilla,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal+VrCreTotal+VrConTotal,VrConDcto+VrCreDcto,VrCreImp+VrConImp,VrSobretasa,0,0,0,VrSubTotal AS VrCombustible
,VrSobrantes,VrFaltantes,VrImpGlobal,VrOtros,VrCostos+VrCreCos+VrConCos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrGastComb+VrGastOtros,0,'0',Cantidad,0,'EFE','','0'
,'','0',FecCorte,IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'','',Modalidad,'','COR',NumCorte,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCortes
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_PlaDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_PlaDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,Planilla,IdCia,Fecha,IdConcepto,NitTercero,'0',KarValor,KarDcto,KarIva,KarSobTasa,0,0,0,0
,VrSobrantes,VrFaltantes,KarImpGlobal,KarSoldicom,KarCosto,KarValor+KarIva+KarSobTasa+KarImpGlobal+KarSoldicom,VrEfectivo,VrPagosOtr,VrCreditos,VrGastComb+VrGastOtros,0,IdProducto,KarCantidad,0,'EFE','','0'
,'','0',FecCorte,IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'','',Modalidad,'','COR',NumCorte,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCortes  F INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Salidas) AS KarCantidad,SUM(VrPrecio*Salidas) AS KarValor
,SUM(VrIvaSal) AS KarIva,SUM(VrDctoSal) AS KarDcto,SUM(VrCostoSal) AS KarCosto,SUM(VrIcaSal) AS KarIca,SUM(VrReteSal) AS KarReteFte
,SUM(Sobretasa*Salidas) AS KarSobTasa,SUM(Soldicom*Salidas) AS KarSoldicom,SUM(ImpGlobal*Salidas) AS KarImpGlobal
 FROM  Trn_Kardex  WHERE TipDoc='PLA' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON F.TipDoc=K.KarTipoDoc  AND F.Planilla=K.KarNumDoc  AND F.IdCia=K.KarIdCia
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc1]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rc1] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc, Recibo, IdCia, Fecha, IdConcepto, IdCliente, IdAgencia,ValorTotal,ValorDcto,0,0,ValorReteFte,ValorReteIca,ValorReteIva,ValorPagMas,ValorOtros,ValorOtrosDct
,0,TotalAhorro,0,ValorNeto,CASE EnEfectivo WHEN 1 THEN ValorNeto ELSE 0 END,CASE EnEfectivo WHEN 0 THEN ValorNeto ELSE 0 END,0,0,0,'0',0,EnEfectivo,CASE EnEfectivo WHEN 1 THEN  'EFE' ELSE 'CHE' END
,NumCheque,IdBanco,'',IdCta,Null,IdVendedor,Comision,'0',IdUsuario,'0',Referencia,'','',Modalidad,IdVehiculo,TipCar, Cartulina, IdCiaCar,TipCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev,Observacion,TimeSys
 FROM Trn_RecBuses
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc1Det]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rc1Det] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,R.TipDoc,Recibo,R.IdCia,R.Fecha,IdConcepto,IdCliente,IdAgencia,VrPagado,VrCambio,0,0,ValorReteFte,ValorReteIca,ValorReteIva,ValorPagMas
,ValorOtros,ValorOtrosDct,0,TotalAhorro,0,VrPagado-VrCambio,CASE EnEfectivo WHEN 1 THEN VrPagado-VrCambio ELSE 0 END,CASE EnEfectivo WHEN 0 THEN VrPagado-VrCambio ELSE 0 END,0,0,0,'0',0,EnEfectivo
,IdForma,NumForma,P.IdBanco,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,IdVendedor,Comision,'0',R.IdUsuario,CdLocal,Referncia1,Referncia2,Beneficiario,Modalidad,IdVehiculo,TipCar,Cartulina,IdCiaCar
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_RecBuses AS R INNER JOIN Trn_Pagos AS P ON R.TipDoc=P.TipDoc AND R.Recibo=P.Documento AND R.IdCia=P.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc2]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rc2] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,0,0,0,VrRetencion,VrReteICA,VrReteIVA,VrPagosMas
,VrOtros,VrOtrDcto,0,0,0,VrNeto,VrEfectivo,0,0,0,0,'0',0,EnEfectivo,CdForma,NumForma,CdBanco
,SUBSTRING(DetallePago,1,150),CdCta,FecPago,IdVend,TarifaCom,'0',IdUsuario,'0',Referencia,'','','RC2',pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_FinRecibos
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rc2Det]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rc2Det] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,R.TipDoc,Recibo,R.IdCia,R.Fecha,IdConcepto,IdCliente,IdAgencia,VrPagado,VrCambio,0,0,VrRetencion,VrReteICA,VrReteIVA,VrPagosMas
,VrOtros,VrOtrDcto,0,0,0,VrPagado-VrCambio,VrEfectivo,0,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,IdBanco
,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,IdVend,TarifaCom,'0',R.IdUsuario,CdLocal,Referncia1,Referncia2,Beneficiario,'RC2',pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_FinRecibos AS R INNER JOIN Trn_Pagos AS P ON R.TipDoc=P.TipDoc AND R.Recibo=P.Documento AND R.IdCia=P.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,C.TipDoc,Recibo,C.IdCia,C.Fecha,IdConcepto,IdTercero,P.CdAgencia,VrPagado,VrCambio,0,0,0,0,0,VrTotal
,VrTotDebito,VrTotCredito,0,0,0,VrPagado-VrCambio,CASE IdForma WHEN 'EFE' THEN VrPagado-VrCambio ELSE 0 END,0,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,IdBanco
,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,NitCliente,0,'0',IdCajero,CdLocal,Referncia1,Referncia2,Beneficiario,CASE C.TipDoc WHEN 'RCO' THEN 'RECIBOS' ELSE 'EGRCAJA' END,'',TipRef,DocRef,IdCiaRef
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_CompCaja AS C INNER JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND C.Recibo=P.Documento AND C.IdCia=P.IdCia
 WHERE  C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rec] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,0,0,VrRetencion,VrReteICA,VrReteIVA,VrPagosMas
,VrOtros,VrOtrDcto,0,VrAhorro,0,VrNeto,VrEfectivo,0,0,0,0,'0',0,EnEfectivo,CdForma,NumForma,CdBanco
,SUBSTRING(DetallePago,1,150),CdCta,FecPago,IdVend,TarifaCom,'0',IdCajero,IdLocal,Referencia,'','',Modalidad,pVehiculo,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Recibos
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_RecDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_RecDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,R.TipDoc,Recibo,R.IdCia,R.Fecha,IdConcepto,IdCliente,IdAgencia,VrPagado,VrCambio,0,0,VrRetencion,VrReteICA,VrReteIVA,VrPagosMas
,VrOtros,VrOtrDcto,0,VrAhorro,0,VrPagado-VrCambio,VrEfectivo,0,0,0,0,'0',0,EnEfectivo,IdForma,P.NumForma,IdBanco
,Detalle,CASE P.CdCta WHEN NULL THEN '0'  WHEN '' THEN '0' ELSE P.CdCta END,FecForma,IdVend,TarifaCom,'0',IdCajero,CdLocal,Referncia1,Referncia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Recibos AS R INNER JOIN Trn_Pagos AS P ON R.TipDoc=P.TipDoc AND R.Recibo=P.Documento AND R.IdCia=P.IdCia
 WHERE  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Rmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Rmt] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,R.TipDoc,R.NumOrden,R.IdCia,R.Fecha,CdConcepto,R.IdCliente,R.IdAgencia,R.VrCobro,0,0,0,0,0,0,R.VrSeguro,R.VrPagos,R.VrDctos,0,0,R.VrFletes,R.VrCobro
,0,0,R.VrDeclarado,0,0,'0',R.PesoTotal,0,R.CdForma,RA.TipoRuta,'','','',R.FecDespacho,RA.IdVend,0,'0',R.IdUsuario,R.IdLocFletes,R.nRemolque,R.TipoAfiVehic,RA.NomCliente,R.Modalidad,R.IdVehiculo
,R.TipDcm,R.NumDocmto,R.IdCiaDcm,R.TipCom,R.Comprobante,R.IdCiaCom,R.Anulado,0,R.FecDev,R.Observacion,R.TimeSys,R.VrCargos,R.CdRutaTarif,R.IdLocOrigen,R.IdLocDestino,'0',R.IdConductor,R.IdRemitente,R.IdDestinatario,R.NumPedido,R.IdCiaPed
FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
WHERE R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (R.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
AND (R.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (R.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_RmtD]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_RmtD] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
,VrImpConsumo,IdRuta,IdLocOrigen,IdLocDestino,IdPoseedor,IdConductor,IdRemitente,IdDestinatario,NumPedido,IdCiaPed)
SELECT @pmtmEst,R.TipDoc,R.NumOrden,R.IdCia,R.Fecha,CdConcepto,R.IdCliente,R.IdAgencia,D.PesoNeto*D.TarifClie,0,0,0,0,0,0,D.VrSeguro,D.PesoNeto*D.TarifPago,0,0,0,D.PesoNeto*D.TarifTabla,D.PesoNeto*D.TarifClie
,0,0,D.VrDeclarado,0,D.Cantidad,D.IdMercancia,D.PesoNeto,0,R.CdForma,RA.TipoRuta,'',CASE WHEN LEN(D.DescripMcias)>150 THEN SUBSTRING(D.DescripMcias,1,150) ELSE D.DescripMcias END,'',R.FecDespacho,RA.IdVend,0,'0',R.IdUsuario
,R.IdLocFletes,D.Referencia1,D.Referencia2,CASE WHEN LEN(D.Remitente)>150 THEN SUBSTRING(D.Remitente,1,150) ELSE D.Remitente END,R.Modalidad,R.IdVehiculo,R.TipDcm,R.NumDocmto,R.IdCiaDcm,R.TipCom,R.Comprobante,R.IdCiaCom,R.Anulado
,0,R.FecDev,R.Observacion,R.TimeSys,R.VrCargos,R.CdRutaTarif,D.IdOrigen,D.IdDestino,'0',R.IdConductor,D.NitRemite,D.NitDestntario,R.NumPedido,R.IdCiaPed
FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
INNER JOIN Trn_TraRemMcias AS D ON R.TipDoc=D.TipDoc AND R.NumOrden=D.NumOrden AND R.IdCia=D.IdCia
WHERE R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (R.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL)
AND (R.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (R.IdUsuario=@pmIdUsuario OR @pmIdUsuario IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_Sal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_Sal] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDoc,Salida,IdCia,Fecha,IdConcepto,IdTercero,CdAgencia,VrSubTotal,0,VrImpuesto,0,0,0,0,0
,0,0,0,0,VrCostos,VrNeto,0,0,0,0,0,'0',Cantidad,0,'EFE','','0'
,SUBSTRING(DirEntrega,1,150),'0',Null,CdConductor,0,'0',IdUsuario,IdLocEnt,ModRequis,'','',Modalidad,pVehiculo,TipOrd,NumOrden,IdCiaOrd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Salidas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Diario_SalDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Diario_SalDet] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 INSERT INTO tm_Diario (tmEst,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros
,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,Cantidad,EnEfectivo,CdForma,NumForma,CdBanco
,DetallePagos,CdCta,FecCheque,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Beneficiario,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
 SELECT @pmtmEst,TipDoc,Salida,IdCia,Fecha,IdConcepto,IdTercero,CdAgencia,KarValor,KarDcto,KarIva,0,0,0,0,0
,0,0,0,0,KarCosto,KarValor+KarIva,0,0,0,0,0,IdProducto,KarCantidad,0,'EFE','','0'
,SUBSTRING(DirEntrega,1,150),'0',Null,CdConductor,0,'0',IdUsuario,IdLocEnt,ModRequis,'','',Modalidad,pVehiculo,TipOrd,NumOrden,IdCiaOrd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_Salidas  AS S INNER JOIN (SELECT TipDoc AS KarTipoDoc,Documento AS KarNumDoc,IdCia AS KarIdCia,IdProducto,SUM(Salidas) AS KarCantidad,SUM(VrPrecio*Salidas) AS KarValor
,SUM(VrIvaSal) AS KarIva,SUM(VrDctoSal) AS KarDcto,SUM(VrCostoSal) AS KarCosto
 FROM  Trn_Kardex  WHERE TipDoc IN ('SAL','SAI') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipDoc,Documento,IdCia,IdProducto) AS K ON S.TipDoc=K.KarTipoDoc  AND S.Salida=K.KarNumDoc  AND S.IdCia=K.KarIdCia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DifIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_DifIngreso] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdDiferido VARCHAR(30),@pmtmFecha SMALLDATETIME,@pmtmPeriodos INT,@pmtmVrBase MONEY
,@pmtmMejoras MONEY,@pmtmDisminucion MONEY,@pmtmAjustes MONEY,@pmtmAmortiza MONEY,@pmtmAmortizaAju MONEY,@pmtmAjuInfAmtza MONEY,@pmtmMesesAcum INT
,@pmtmCorrMonDif MONEY,@pmtmMesesCorr INT,@pmtmFecUltAmtza SMALLDATETIME,@pmtmConcepto VARCHAR(150)
 AS 
 INSERT INTO tm_DifIngreso (tmNumero,tmItem,tmIdDiferido,tmFecha,tmPeriodos,tmVrBase,tmMejoras,tmDisminucion,tmAjustes,tmAmortiza,tmAmortizaAju,tmAjuInfAmtza
,tmMesesAcum,tmCorrMonDif,tmMesesCorr,tmFecUltAmtza,tmConcepto)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdDiferido,@pmtmFecha,@pmtmPeriodos,@pmtmVrBase,@pmtmMejoras,@pmtmDisminucion,@pmtmAjustes
,@pmtmAmortiza,@pmtmAmortizaAju,@pmtmAjuInfAmtza,@pmtmMesesAcum,@pmtmCorrMonDif,@pmtmMesesCorr,@pmtmFecUltAmtza,@pmtmConcepto)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_DifIngreso_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_DifIngreso_Sel] @pmtmNumero VARCHAR(5),@pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_DifIngreso (tmNumero,tmItem,tmIdDiferido,tmFecha,tmPeriodos,tmVrBase,tmMejoras,tmDisminucion,tmAjustes,tmAmortiza,tmAmortizaAju,tmAjuInfAmtza
,tmMesesAcum,tmCorrMonDif,tmMesesCorr,tmFecUltAmtza,tmConcepto)
 SELECT  @pmtmNumero,Item,IdDiferido,FecActivacion,NumPeriodos,VrBase,VrMejoras,VrDisminucion,VrAjuInfAcum,VrAmortizaHis
,VrAmortizaAju,VrAjuInfAmtza,NumMesesAmtza,VrCorrMonDif,NumMesesCorr,FecUltAmtza,Concepto
 FROM Trn_AfDifIngreso
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EdsFormas] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmCredito BIT,@pmtmTipoRango VARCHAR(3),@pmtmIdRango INT,@pmtmIdForma VARCHAR(4)
,@pmtmObservacion VARCHAR(150),@pmtmEsCaja BIT,@pmtmIdBanco VARCHAR(4),@pmtmNForma VARCHAR(20),@pmtmFecForma SMALLDATETIME,@pmtmCtaForma VARCHAR(30)
,@pmtmBeneficiario VARCHAR(150),@pmtmNumSerie VARCHAR(5),@pmtmNumForma INT,@pmtmVrTotal MONEY,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16)
,@pmtmIdCuenta VARCHAR(16),@pmtmpVehiculo VARCHAR(10),@pmtmnVehiculo VARCHAR(10),@pmtmIdVend VARCHAR(16),@pmtmCdProducto VARCHAR(16)
,@pmtmCantidad DECIMAL(14,4),@pmtmReferencia VARCHAR(50),@pmtmReferncia2 VARCHAR(50),@pmtmCantPuntos DECIMAL(14,4),@pmtmCdLocal VARCHAR(8)
,@pmtmNumAutoriza VARCHAR(30),@pmtmVrDenom MONEY,@pmtmCantDenm INT,@pmtmTipDenom CHAR(1),@pmtmCdCta VARCHAR(4),@pmtmTipAplica VARCHAR(10),@pmtmIdUsuario VARCHAR(11)
,@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmVrPrecio MONEY,@pmtmVrBase MONEY,@pmtmVrPresp MONEY
 AS 
 INSERT INTO tm_EdsFormas (tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma
,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm
,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrBase,tmVrPresp)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmCredito,@pmtmTipoRango,@pmtmIdRango,@pmtmIdForma,@pmtmObservacion,@pmtmEsCaja,@pmtmIdBanco,@pmtmNForma,@pmtmFecForma,@pmtmCtaForma
,@pmtmBeneficiario,@pmtmNumSerie,@pmtmNumForma,@pmtmVrTotal,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdCuenta,@pmtmpVehiculo,@pmtmnVehiculo,@pmtmIdVend,@pmtmCdProducto
,@pmtmCantidad,@pmtmReferencia,@pmtmReferncia2,@pmtmCantPuntos,@pmtmCdLocal,@pmtmNumAutoriza,@pmtmVrDenom,@pmtmCantDenm,@pmtmTipDenom,@pmtmCdCta,@pmtmTipAplica,@pmtmIdUsuario,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmVrPrecio,@pmtmVrBase,@pmtmVrPresp)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas_Cre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EdsFormas_Cre]  @pmtmNumero VARCHAR(5),@pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_EdsFormas (tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma
,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm
,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrBase,tmVrPresp)
 SELECT @pmtmNumero,Item,1,TipoRango,IdRango,IdForma,Observacion,0,'0','0',Fecha,'0','',NumSerie,NumForma,VrTotal,IdCliente,IdAgencia,IdCuenta,pVehiculo,nVehiculo
,IdVend,ISNULL(CdProducto,'0'),Cantidad,Referencia,NumRef2,CantPuntos,'0','',0,0,'B','0','',IdCajero,CdCCosto,CdSubCos,VrPrecio,VrBase,VrPrecioEsp
 FROM Trn_EdsFormas
 WHERE Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas_Fac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EdsFormas_Fac] @pmtmNumero VARCHAR(5),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2)
AS 
 INSERT INTO tm_EdsFormas (tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma
,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm
,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrBase,tmVrPresp)
SELECT @pmtmNumero,ROW_NUMBER() OVER(ORDER BY Planilla),1,TipoRango,IdRango,IdForma,Observacion,0,'0','0',Fecha,'0','',NumSerie,NumForma,VrTotal,IdCliente,IdAgencia,IdCuenta,pVehiculo,nVehiculo
,IdVend,ISNULL(CdProducto,'0'),Cantidad,Referencia,NumRef2,CantPuntos,'0','',0,0,'B','0','',IdCajero,CdCCosto,CdSubCos,VrPrecio,VrBase,VrPrecioEsp
FROM Trn_EdsFormas
WHERE TipDcm=@pmTipDcm AND Documento=@pmDocumento AND IdCiaDcm=@pmIdCiaDcm
AND Planilla>0 AND IdCia<>'' AND IdCia<>'00'
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EdsFormas_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EdsFormas_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_EdsFormas (tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma
,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm
,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrBase,tmVrPresp)
 SELECT @pmtmNumero,Item,0,CASE WHEN FE_Ticket=1 THEN 'TKT' ELSE '0' END,0,IdForma,Detalle,EsCaja,IdBanco,NumForma,FecForma,CtaForma,Beneficiario,'0',0
,VrPagado,NitCliente,CdAgencia,'0',RefVehiculo,RefNumVeh,'0',ISNULL(CdProducto,'0'),Cant_Gals,Referncia1,Referncia2,0,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,CdCta,'',IdUsuario,'0','0',PrecioPub,PrecioBase,PrecioUnit
 FROM Trn_Pagos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstadoGyp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstadoGyp] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT,@pmtmIdCia CHAR(2),@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16)
,@pmtmCodAgncia VARCHAR(16),@pmtmTipo VARCHAR(4),@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY,@pmtmTipoAfi INT
 AS 
 INSERT INTO tm_EstadoGyp (tmEst,tmIdCuenta,tmItem,tmIdCia,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmTipoAfi)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmItem,@pmtmIdCia,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmCodAgncia,@pmtmTipo,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmNuevoSaldo
,@pmtmSalAnt2,@pmtmDebitos2,@pmtmCreditos2,@pmtmSaldo2,@pmtmTipoAfi)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstClientes] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdCia CHAR(2),@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmFecUltFcr SMALLDATETIME,@pmtmPPlazoFcr DECIMAL(14,4),@pmtmMayorFcr MONEY
,@pmtmMenorFcr MONEY,@pmtmFecUltFco SMALLDATETIME,@pmtmPPlazoFco DECIMAL(14,4),@pmtmMayorFco MONEY,@pmtmMenorFco MONEY,@pmtmVentaBruto MONEY,@pmtmVrDevolucion MONEY,@pmtmVrDescuentos MONEY,@pmtmCostoBruto MONEY
,@pmtmCostoDev MONEY,@pmtmVrIva MONEY,@pmtmFecUltPago SMALLDATETIME,@pmtmPromPago DECIMAL(14,4),@pmtmSaldoMora MONEY,@pmtmFecIniMora SMALLDATETIME,@pmtmDiasEnMora INT,@pmtmChequesDev INT,@pmtmSaldoActual MONEY
,@pmtmSaldoAnterior MONEY,@pmtmVrFacturas MONEY,@pmtmVrDevFacturas MONEY,@pmtmVrRecibos MONEY,@pmtmVrDevRecibos MONEY,@pmtmVrNotasDeb MONEY,@pmtmVrNotasCre MONEY,@pmtmVrCheques MONEY
 AS 
 INSERT INTO tm_EstClientes (tmEst,tmItem,tmIdCia,tmIdCliente,tmIdAgencia,tmFecUltFcr,tmPPlazoFcr,tmMayorFcr,tmMenorFcr,tmFecUltFco,tmPPlazoFco,tmMayorFco,tmMenorFco,tmVentaBruto,tmVrDevolucion,tmVrDescuentos,tmCostoBruto,tmCostoDev,tmVrIva
,tmFecUltPago,tmPromPago,tmSaldoMora,tmFecIniMora,tmDiasEnMora,tmChequesDev,tmSaldoActual,tmSaldoAnterior,tmVrFacturas,tmVrDevFacturas,tmVrRecibos,tmVrDevRecibos,tmVrNotasDeb,tmVrNotasCre,tmVrCheques)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdCia,@pmtmIdCliente,@pmtmIdAgencia,@pmtmFecUltFcr,@pmtmPPlazoFcr,@pmtmMayorFcr,@pmtmMenorFcr,@pmtmFecUltFco,@pmtmPPlazoFco,@pmtmMayorFco,@pmtmMenorFco,@pmtmVentaBruto,@pmtmVrDevolucion
,@pmtmVrDescuentos,@pmtmCostoBruto,@pmtmCostoDev,@pmtmVrIva,@pmtmFecUltPago,@pmtmPromPago,@pmtmSaldoMora,@pmtmFecIniMora,@pmtmDiasEnMora,@pmtmChequesDev,@pmtmSaldoActual,@pmtmSaldoAnterior,@pmtmVrFacturas
,@pmtmVrDevFacturas,@pmtmVrRecibos,@pmtmVrDevRecibos,@pmtmVrNotasDeb,@pmtmVrNotasCre,@pmtmVrCheques)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_EstCueCte] @pmtmEst CHAR(2), @pmtmTipDoc VARCHAR(3), @pmtmDocumento INT, @pmtmIdCia CHAR(2), @pmtmItem INT, @pmtmIndTip INT, @pmtmFecha SMALLDATETIME, @pmtmFecVence SMALLDATETIME, @pmtmValorDebito MONEY, @pmtmValorCredito MONEY, @pmtmValorAbono MONEY
, @pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16), @pmtmIdVehiculo VARCHAR(10), @pmtmVehPropio BIT, @pmtmIdVendedor VARCHAR(16), @pmtmComision DECIMAL(10,4), @pmtmIdCargo VARCHAR(4), @pmtmIdClase VARCHAR(4), @pmtmIdConcepto VARCHAR(4), @pmtmFecUltPago SMALLDATETIME, @pmtmFactura VARCHAR(15), @pmtmReferencia VARCHAR(50)
,@pmtmDetalle VARCHAR(250), @pmtmTipCar VARCHAR(3), @pmtmCartulina INT, @pmtmIdCiaCar CHAR(2), @pmtmModalidad VARCHAR(10), @pmtmCentInicial INT, @pmtmCentFinal INT, @pmtmNPasajeros INT, @pmtmRecorridos INT, @pmtmValorRecibido MONEY, @pmtmTotalGastos MONEY,@pmtmTotalVales MONEY
, @pmtmTotalAhorro MONEY, @pmtmTotalOtros MONEY, @pmtmTotalAbono MONEY, @pmtmNumCheque VARCHAR(20), @pmtmIdBanco VARCHAR(4), @pmtmAnulado BIT, @pmtmNumDev INT, @pmtmFecDev SMALLDATETIME, @pmtmIntMora BIT, @pmtmCxPagar BIT, @pmtmTipDcm VARCHAR(3), @pmtmDocDev INT, @pmtmIdCiaDcm CHAR(2)
, @pmtmFecDcm SMALLDATETIME, @pmtmIdEstado VARCHAR(4), @pmtmIdUsuario VARCHAR(11), @pmtmTimeSys SMALLDATETIME, @pmtmSaldoAnt MONEY, @pmtmSaldoAntCla MONEY, @pmtmSaldoAntCia MONEY, @pmtmSaldoAntDia MONEY,@pmtmNuevoSaldo MONEY,@pmtmSalAntPro MONEY,@pmtmSalAntProCla MONEY,@pmtmSalAntProCia MONEY
AS
 INSERT INTO tm_EstCueCte (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente, 
                     tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmFactura, tmReferencia, 
                    tmDetalle, tmTipCar, tmCartulina, tmIdCiaCar, tmModalidad, tmCentInicial, tmCentFinal, tmNPasajeros, tmRecorridos, tmValorRecibido, tmTotalGastos, 
                   tmTotalVales, tmTotalAhorro, tmTotalOtros, tmTotalAbono, tmNumCheque, tmIdBanco, tmAnulado, tmNumDev, tmFecDev, tmIntMora, tmCxPagar, 
                  tmTipDcm, tmDocDev, tmIdCiaDcm, tmFecDcm, tmIdEstado, tmIdUsuario, tmTimeSys, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo,tmSalAntPro,tmSalAntProCla,tmSalAntProCia)
 VALUES (@pmtmEst, @pmtmTipDoc, @pmtmDocumento, @pmtmIdCia, @pmtmItem, @pmtmIndTip, @pmtmFecha, @pmtmFecVence, @pmtmValorDebito, @pmtmValorCredito, @pmtmValorAbono
, @pmtmIdCliente,@pmtmIdAgencia, @pmtmIdVehiculo, @pmtmVehPropio, @pmtmIdVendedor, @pmtmComision, @pmtmIdCargo, @pmtmIdClase, @pmtmIdConcepto, @pmtmFecUltPago, @pmtmFactura, @pmtmReferencia
,@pmtmDetalle, @pmtmTipCar, @pmtmCartulina, @pmtmIdCiaCar, @pmtmModalidad, @pmtmCentInicial, @pmtmCentFinal, @pmtmNPasajeros, @pmtmRecorridos, @pmtmValorRecibido, @pmtmTotalGastos,@pmtmTotalVales
, @pmtmTotalAhorro, @pmtmTotalOtros, @pmtmTotalAbono, @pmtmNumCheque, @pmtmIdBanco, @pmtmAnulado, @pmtmNumDev, @pmtmFecDev, @pmtmIntMora, @pmtmCxPagar, @pmtmTipDcm, @pmtmDocDev, @pmtmIdCiaDcm
, @pmtmFecDcm, @pmtmIdEstado, @pmtmIdUsuario, @pmtmTimeSys, @pmtmSaldoAnt, @pmtmSaldoAntCla, @pmtmSaldoAntCia, @pmtmSaldoAntDia,@pmtmNuevoSaldo,@pmtmSalAntPro,@pmtmSalAntProCla,@pmtmSalAntProCia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Cc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Cc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
  INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
 ,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmFactura, tmReferencia,tmDetalle, tmCartulina
 ,tmIdUsuario,tmIdEstado,tmModalidad,tmCxPagar, tmTimeSys, tmAnulado, tmNumDev, tmFecDev,tmIdBanco, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,R.TipRec,R.Recibo,R.IdCia,R.Item+10000,@pmtmIndTip,R.Fecha,V.FecVence,0,R.ValorAbono,0,R.IdCliente
,R.IdAgencia,R.IdVehiculo,R.VehPropio,R.IdVendedor,R.Comision,R.IdCargo,R.IdClase,V.IdConcepto,FecPago,V.Factura,V.Referencia,R.Detalle,V.NotaInt
,R.IdUsuario,'0001','CCTE',0,R.TimeSys,0,0,Null,'0',0,0,0,0,0
 FROM Trn_RecFactura AS R INNER JOIN Trn_CausacVence AS V ON R.TipDoc =V.TipDoc  AND R.Documento=V.Documento  AND R.IdCiaDoc=V.IdCia AND R.ItemDoc=V.Item
 INNER JOIN Vehiculos AS VH ON R.IdVehiculo=VH.IdVehiculo 
 WHERE R.TipRec='OTR'  AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND R.IdCia like ISNULL(@pmIdCia,'%%')
 AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND VH.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Dfv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Dfv] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
AS
 INSERT INTO tm_EstCueCte (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
,tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdClase,tmIdCargo,tmIdBanco,tmIdAgencia,tmIdConcepto, tmDetalle, tmTipDcm, tmDocDev, tmIdCiaDcm, tmFecDcm, tmIdEstado
, tmIdUsuario, tmTimeSys, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,TipDev, Devolucion,D.IdCia,Item,@pmtmIndTip,Fecha,FecVence,0,ValorFactura,0,D.IdCliente,VC.IdVehiculo,VC.VehPropio,VC.IdVendedor,0,VC.IdClase,IdCargo,'0','0',VC.IdConcepto
,D.Observacion,D.TipDoc, D.Factura, IdCiaDoc, FecDoc,D.IdEstado,D.IdUsuario,TimeSys,0,0,0,0,0
 FROM    Trn_DevFvc AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Factura=VC.Documento AND D.IdCiaDoc=VC.IdCia
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo 
 WHERE  TipDev='DFV'  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND VC.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY  D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Dvo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Dvo] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null,@pmTipDev VARCHAR(3)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
AS
 INSERT INTO tm_EstCueCte (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
,tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdClase,tmIdCargo,tmIdBanco,tmIdAgencia,tmIdConcepto, tmDetalle, tmTipDcm, tmDocDev, tmIdCiaDcm, tmFecDcm, tmIdEstado
, tmIdUsuario, tmTimeSys, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,TipDev, Devolucion,D.IdCia,Item,@pmtmIndTip,Fecha,FecVence,0,ValorFactura,0,IdCliente,VC.IdVehiculo,VC.VehPropio,VC.IdVendedor,0,VC.IdClase,IdCargo,'0','0',VC.IdConcepto
,D.Observacion,D.TipDoc, D.Documento, IdCiaDoc, FecDoc,D.IdEstado,D.IdUsuario,TimeSys,0,0,0,0,0
 FROM    Trn_DevCausacion AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Documento=VC.Documento AND D.IdCiaDoc=VC.IdCia
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo 
 WHERE  TipDev IN ('DVO','DVA')  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.TipDoc LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND TipDev LIKE ISNULL(@pmTipDev,'%')
 ORDER BY  D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Fvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Fvc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
  INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
 ,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmFactura, tmReferencia,tmDetalle, tmCartulina
 ,tmIdUsuario,tmIdEstado,tmModalidad,tmCxPagar, tmTimeSys, tmAnulado, tmNumDev, tmFecDev,tmIdBanco, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia, Item,@pmtmIndTip,FecEmision, V.FecVence,ValorFactura,0,ValorAbono,V.IdCliente, V.IdAgencia, V.IdVehiculo,V.VehPropio, IdVendedor, Comision
 ,IdCargo, V.IdClase, V.IdConcepto,FecUltPago,V.Factura, V.Referencia,Detalle,NotaInt,C.IdUsuario,C.IdEstado,'FVC',0,TimeSys,Anulado,NumDev, FecDev,'0',0,0,0,0,0
 FROM  Trn_CausacVence AS V INNER JOIN Trn_CausaVales AS C ON V.TipDoc=C.TipDoc AND V.Documento=C.Documento AND V.IdCia=C.IdCia
 INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
 WHERE V.TipDoc='FVC'  AND FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND V.IdCia like ISNULL(@pmIdCia,'%%')
 AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND V.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') 
 ORDER BY V.TipDoc, V.IdCia,V.Documento
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Ncr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Ncr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
 INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto,   tmReferencia
,tmDetalle, tmModalidad,tmNumCheque, tmIdBanco, tmIntMora,  tmTipDcm, tmDocDev, tmIdCiaDcm,  tmIdEstado
, tmIdUsuario, tmTimeSys, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst, TipDoc, NumNota, IdCia,1,@pmtmIndTip, Fecha,FecVence,0,ValorNeto,ValorAplicado,IdCliente, IdAgencia, N.IdVehiculo, N.VehPropio,N.IdConductor,Comision
,IdCargo,N.IdClase,IdConcepto,Referencia,N.Observacion,'NC1',NumCheque, IdBanco,IntMora,TipDcm, Documento, IdCiaDoc,N.IdEstado,N.IdUsuario,TimeSys,0,0,0,0,0
 FROM  Trn_NotasBuses  AS N INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo 
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia like ISNULL(@pmIdCia,'%%')
 AND N.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND N.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY  IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Ndb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Ndb]  @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
 INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
 ,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmFactura, tmReferencia,tmDetalle, tmCartulina,tmNumCheque, tmIdBanco
 ,tmIntMora,tmIdUsuario,tmIdEstado,tmModalidad, tmTimeSys,tmTipDcm, tmDocDev, tmIdCiaDcm,tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia, Item,@pmtmIndTip,FecEmision, V.FecVence,ValorFactura,0,ValorAbono,V.IdCliente, V.IdAgencia, V.IdVehiculo,V.VehPropio, V.IdVendedor, V.Comision
 ,V.IdCargo, V.IdClase, V.IdConcepto,FecUltPago,V.Factura, V.Referencia,Detalle,NotaInt,NumCheque,IdBanco,IntMora,N.IdUsuario,N.IdEstado,N.TipDoc,TimeSys,TipDcm,N.Documento,IdCiaDoc,0,0,0,0,0
 FROM  Trn_CausacVence AS V INNER JOIN Trn_NotasBuses AS N ON V.TipDoc=N.TipDoc  AND V.Documento=N.NumNota AND V.IdCia=N.IdCia
 INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
 WHERE V.TipDoc=@pmTipDoc AND FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND V.IdCia like ISNULL(@pmIdCia,'%%')
 AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND V.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY V.TipDoc, V.IdCia,V.Documento
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Odb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Odb]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
 INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto,  tmReferencia
,tmDetalle, tmTipCar, tmCartulina, tmIdCiaCar, tmModalidad, tmCentInicial, tmCentFinal, tmNPasajeros, tmRecorridos, tmValorRecibido, tmTotalGastos,tmTotalVales, tmTotalAhorro
, tmTotalOtros, tmTotalAbono, tmNumCheque, tmIdBanco, tmCxPagar, tmTipDcm, tmDocDev, tmIdCiaDcm, tmFecDcm, tmIdEstado
, tmIdUsuario, tmTimeSys, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
SELECT @pmtmEst,TipDev, Devolucion, D.IdCia,1,@pmtmIndTip,D.Fecha,D.Fecha AS FecVce,D.ValorNeto,0, D.ValorAplicado,D.IdCliente, D.IdAgencia, D.IdVehiculo, D.VehPropio,D.IdConductor,D.Comision,'0',D.IdClase
,D.IdConcepto,Referencia,D.Observacion,TipCar, Cartulina, IdCiaCar,D.Modalidad,R.CentInicial,R.CentFinal, NPasajeros, Recorridos,D.ValorRecibido,TotalGastos,TotalVales,TotalAhorro
,TotalOtros,TotalAbono, D.NumCheque, D.IdBanco,D.EnEfectivo, D.TipDoc, D.Recibo, IdCiaDoc, FecDoc,R.IdEstado,R.IdUsuario,D.TimeSys,0,0,0,0,0
 FROM  Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses  AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY  D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Pre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Pre] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
 --estado cuenta -prestamos
  INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
 ,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmFactura, tmReferencia,tmDetalle, tmCartulina
 ,tmIdUsuario,tmIdEstado,tmModalidad,tmCxPagar, tmTimeSys, tmAnulado, tmNumDev, tmFecDev,tmIdBanco, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia, Item,@pmtmIndTip,FecEmision, V.FecVence,ValorFactura,0,ValorAbono,IdCliente, IdAgencia, V.IdVehiculo,V.VehPropio, IdVendedor, Comision
 ,IdCargo, V.IdClase, V.IdConcepto,FecUltPago,V.Factura, V.Referencia,Detalle,NotaInt,P.IdUsuario,P.IdEstado,TipoCuota,CxPagar,TimeSys,Anulado,NumDev, FecDev,'0',0,0,0,0,0
 FROM  Trn_CausacVence AS V INNER JOIN Trn_Prestamos AS P ON V.TipDoc=P.TipDoc AND V.Documento=P.PrestamoID AND V.IdCia=P.IdCia
 INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
 WHERE V.TipDoc='PRE'  AND FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND V.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 ORDER BY V.TipDoc, V.IdCia,V.Documento
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Rec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Rec]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
 INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
 ,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmReferencia
 ,tmDetalle, tmTipCar, tmCartulina, tmIdCiaCar, tmModalidad, tmCentInicial, tmCentFinal, tmNPasajeros, tmRecorridos, tmValorRecibido, tmTotalGastos,tmTotalVales, tmTotalAhorro
 , tmTotalOtros, tmTotalAbono, tmNumCheque, tmIdBanco, tmAnulado, tmNumDev, tmFecDev, tmCxPagar,tmIdEstado
 , tmIdUsuario, tmTimeSys, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,TipDoc, Recibo, IdCia, 1,@pmtmIndTip,Fecha,Fecha AS FecVce,0,ValorNeto,ValorAplicado,IdCliente, IdAgencia,R.IdVehiculo,R.VehPropio,R.IdConductor,Comision,'0'
,R.IdClase,IdConcepto,Referencia,R.Observacion,TipCar, Cartulina, IdCiaCar,Modalidad,R.CentInicial,R.CentFinal, NPasajeros, Recorridos,ValorRecibido,TotalGastos,TotalVales,TotalAhorro
,TotalOtros,TotalAbono, NumCheque, IdBanco, Anulado, NumDev, FecDev,EnEfectivo,R.IdEstado,R.IdUsuario,TimeSys,0,0,0,0,0
 FROM  Trn_RecBuses  AS R INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY  IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EstCueCte_Vce]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_EstCueCte_Vce] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmtmIndTip INT,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS
  INSERT INTO tm_EstCueCte  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmIndTip, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmValorAbono, tmIdCliente
 ,tmIdAgencia, tmIdVehiculo, tmVehPropio, tmIdVendedor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmFactura, tmReferencia,tmDetalle, tmCartulina
 ,tmIdUsuario,tmIdEstado,tmModalidad,tmCxPagar, tmTimeSys, tmAnulado, tmNumDev, tmFecDev,tmIdBanco, tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo)
 SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia, Item,@pmtmIndTip,FecEmision, V.FecVence,ValorFactura,0,ValorAbono,IdCliente, IdAgencia, V.IdVehiculo,V.VehPropio, IdVendedor, Comision
 ,IdCargo, V.IdClase, V.IdConcepto,FecUltPago,V.Factura, V.Referencia,Detalle,NotaInt,C.IdUsuario,C.IdEstado,Modalidad,CxPagar,TimeSys,Anulado,NumDev, FecDev,'0',0,0,0,0,0
 FROM  Trn_CausacVence AS V INNER JOIN Trn_Causacion AS C ON V.TipDoc=C.TipDoc AND V.Documento=C.Documento AND V.IdCia=C.IdCia
 INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
 WHERE V.TipDoc IN ('ADM','OTR')  AND FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND V.IdCia like ISNULL(@pmIdCia,'%%')
 AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 ORDER BY V.TipDoc, V.IdCia,V.Documento
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVcau] @pmtmEst CHAR(2),@pmtmTipo VARCHAR(3),@pmtmDocmnto INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmFecha SMALLDATETIME,@pmtmGrupo VARCHAR(3),@pmtmIdCargo VARCHAR(4),@pmtmIdConcepto VARCHAR(4),@pmtmValor MONEY,@pmtmValorDev MONEY,@pmtmVrGastos MONEY,@pmtmIdCliente VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmVehPropio BIT,@pmtmIdConductor VARCHAR(16)
,@pmtmModalidad VARCHAR(10),@pmtmValorTotal MONEY,@pmtmGalones DECIMAL(14,4),@pmtmVrComb MONEY,@pmtmDetalle VARCHAR(250),@pmtmNumCheque VARCHAR(20),@pmtmReferencia VARCHAR(50),@pmtmIdClase VARCHAR(4),@pmtmAnulado BIT,@pmtmNumDev INT,@pmtmFecDev SMALLDATETIME,@pmtmTipDcm VARCHAR(3),@pmtmDocDev INT,@pmtmIdCiaDcm CHAR(2),@pmtmFecDcm SMALLDATETIME,@pmtmIdEstado VARCHAR(4),@pmtmIdUsuario VARCHAR(11),@pmtmTimeSys SMALLDATETIME
 AS 
 INSERT INTO tm_EVcau (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmIdCargo,tmIdConcepto,tmValor,tmValorDev,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmModalidad,tmValorTotal,tmGalones,tmVrComb,tmDetalle,tmNumCheque,tmReferencia,tmIdClase,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmVrGastos,tmTimeSys)
 VALUES (@pmtmEst,@pmtmTipo,@pmtmDocmnto,@pmtmIdCia,@pmtmItem,@pmtmFecha,@pmtmGrupo,@pmtmIdCargo,@pmtmIdConcepto,@pmtmValor,@pmtmValorDev,@pmtmIdCliente,@pmtmIdVehiculo,@pmtmVehPropio,@pmtmIdConductor,@pmtmModalidad,@pmtmValorTotal,@pmtmGalones,@pmtmVrComb,@pmtmDetalle,@pmtmNumCheque,@pmtmReferencia,@pmtmIdClase,@pmtmAnulado,@pmtmNumDev,@pmtmFecDev
,@pmtmTipDcm,@pmtmDocDev,@pmtmIdCiaDcm,@pmtmFecDcm,@pmtmIdEstado,@pmtmIdUsuario,@pmtmVrGastos,@pmtmTimeSys)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauCte]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVcauCte] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS
--INSERTA CAUSACIONES CIERRE CTE
 INSERT INTO tm_EVcau (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmIdCargo,tmIdConcepto,tmValor,tmValorDev,tmVrGastos,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmModalidad,tmValorTotal,tmGalones,tmVrComb,tmDetalle,tmNumCheque,tmReferencia,tmIdClase,tmAnulado
,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,'DVO',Recibo,IdCia,Item+2000,Fecha,TipRec,IdCargo,'0',0,ValorAbono,(ValorAbono*-1),R.IdCliente,R.IdVehiculo,VehPropio,IdVendedor,'CCTE',ValorAbono,0,0,Detalle,'0','OTROS',IdClase,0
,0,Null,TipDoc,Documento,IdCiaDoc,Null,'0001',R.IdUsuario,R.TimeSys
 FROM  Trn_RecFactura  AS R  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo 
 WHERE  TipRec='OTR' AND  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauDFV]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVcauDFV] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS
 INSERT INTO tm_EVcau (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmIdCargo,tmIdConcepto,tmValor,tmValorDev,tmVrGastos,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmModalidad,tmValorTotal,tmGalones,tmVrComb,tmDetalle,tmNumCheque,tmReferencia,tmIdClase,tmAnulado
,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,TipDev, Devolucion, D.IdCia,Item+1000,Fecha,VC.TipDoc,IdCargo,D.IdConcepto,0,ValorFactura,(ValorFactura*-1),VC.IdCliente,VC.IdVehiculo,VC.VehPropio,VC.IdVendedor,D.TipDoc,VrSubTotal,0,0,D.Observacion,VC.Factura,VC.Referencia,VC.IdClase,0,0,Null,D.TipDoc,D.Factura,IdCiaDoc, FecDoc,D.IdEstado,D.IdUsuario,TimeSys
 FROM   Trn_DevFvc  AS D  INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Factura=VC.Documento AND D.IdCiaDoc=VC.IdCia
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo 
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia like ISNULL(@pmIdCia,'%%')
 AND VC.IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND VC.IdCliente like ISNULL(@pmIdCliente,'%')
 AND IdGrupo like ISNULL(@pmIdGrupo,'%') AND IdAdmon like ISNULL(@pmIdAdmon,'%') AND VC.IdClase like ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauDvo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVcauDvo] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS
--INSERTA DEV CAUSACIONES
 INSERT INTO tm_EVcau (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmIdCargo,tmIdConcepto,tmValor,tmValorDev,tmVrGastos,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmModalidad,tmValorTotal,tmGalones,tmVrComb,tmDetalle,tmNumCheque,tmReferencia,tmIdClase,tmAnulado
,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,TipDev, Devolucion, IdCia,1,Fecha,TipDev,'0',IdConcepto,0,ValorNeto,(ValorNeto*-1),D.IdPropietario,D.IdVehiculo,D.VehPropio,D.IdConductor,TipDoc,ValorTotal,0,0,D.Observacion,Factura,'',TipDoc,0,0,Null,TipDoc, Documento, IdCiaDoc, FecDoc,D.IdEstado,D.IdUsuario,TimeSys
 FROM   Trn_DevCausacion  AS D INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo 
 WHERE TipDev IN ('DVO','DVA') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia like ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND D.IdPropietario like ISNULL(@pmIdCliente,'%')
 AND IdGrupo like ISNULL(@pmIdGrupo,'%') AND IdAdmon like ISNULL(@pmIdAdmon,'%') AND TipDoc like ISNULL(@pmIdClase,'%')
 ORDER BY  IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVcauNcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVcauNcr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS
--INSERTA notas credito
 INSERT INTO tm_EVcau (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmIdCargo,tmIdConcepto,tmValor,tmValorDev,tmVrGastos,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmModalidad,tmValorTotal,tmGalones,tmVrComb,tmDetalle,tmNumCheque,tmReferencia,tmIdClase,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,TipDoc,NumNota, IdCia,1,Fecha,TipDoc,'0',IdConcepto,0,ValorNeto,0,IdCliente,N.IdVehiculo, N.VehPropio,N.IdConductor,'NC1',ValorTotal,0,0,N.Observacion,NumCheque,Referencia,N.IdClase,0,0,Null,TipDcm, Documento, IdCiaDoc,Null,N.IdEstado,N.IdUsuario,TimeSys
 FROM  Trn_NotasBuses  AS N INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo 
 WHERE TipDoc='NC1'  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND N.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND N.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY  IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVEstTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVEstTip] @pmtmEst CHAR(2)
AS 
 INSERT INTO tm_EVEst (tmEst,tmIdTipo,tmTotalProducido,tmMaxProducido,tmMinProducido,tmTotalRecrridos,tmTotalPasaj,tmTotalDias,tmTotalCausac,tmGalones,tmValorComb,tmCantVeh)
 SELECT  tmEst,CASE CdTarifa  WHEN NULL THEN '0' WHEN '' THEN '0' ELSE CdTarifa END
,SUM(tmTotalProducido),MAX(tmMaxProducido),MIN(tmMinProducido),SUM(tmTotalRecrridos),SUM(tmTotalPasaj),SUM(tmTotalDias),SUM(tmTotalCausac),SUM(tmGalones)
,SUM(tmValorComb),COUNT(tmIdVehiculo)
 FROM tm_ExtVeh AS EV INNER JOIN Vehiculos AS V ON EV.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst
 GROUP BY tmEst,CdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVrecCAR]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVrecCAR] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
--INSERTA RECIBOS DE CARTULINAS
 INSERT INTO tm_EVrec (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmValor,tmValorDev,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdConcepto,tmModalidad,tmTipCar,tmCartulina,tmIdCiaCar,tmFechaRec,tmCentInicial
,tmCentFinal,tmNPasajeros,tmRecorridos,tmValorTotal,tmValorOtros,tmTotalProducido,tmTotalGastos,tmTotalAhorro,tmTotalOtros,tmTotalVales,tmTotalAbono,tmValorPasaje,tmDetalle,tmNumCheque,tmReferencia,tmIdBanco,tmIdClase,tmIdRuta,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,R.TipDoc, Recibo, R.IdCia,1,R.Fecha,'RC1',ValorNeto,0,IdCliente,R.IdVehiculo,R.VehPropio,R.IdConductor,IdConcepto,Modalidad,TipCar, R.Cartulina, IdCiaCar,FechaRec,R.CentInicial,R.CentFinal, R.NPasajeros, R.Recorridos,ValorTotal,R.ValorOtros,TotalProducido,TotalGastos,TotalAhorro,TotalOtros, TotalVales, TotalAbono,R.ValorPasaje,R.Observacion
,NumCheque,Referencia,IdBanco,R.IdClase,R.IdRuta, R.Anulado, R.NumDev, R.FecDev,TipCom,Comprobante,IdCiaCom,Null,R.IdEstado,R.IdUsuario,R.TimeSys
 FROM  Trn_RecBuses  AS R INNER JOIN Trn_Despachos AS D ON R.TipCar=D.TipDoc AND R.Cartulina=D.Cartulina AND R.IdCiaCar=D.IdCia
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo 
 WHERE Modalidad='CARTULINA' AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND  (R.Anulado=ISNULL(@pmAnulado,0) or R.Anulado=ISNULL(@pmAnulado,1))
 ORDER BY  R.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVrecODB]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVrecODB] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS 
--INSERTA RECIBOS DE CARTULINAS
 INSERT INTO tm_EVrec (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmValor,tmValorDev,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdConcepto,tmModalidad,tmTipCar,tmCartulina,tmIdCiaCar,tmFechaRec,tmCentInicial
,tmCentFinal,tmNPasajeros,tmRecorridos,tmValorTotal,tmValorOtros,tmTotalProducido,tmTotalGastos,tmTotalAhorro,tmTotalOtros,tmTotalVales,tmTotalAbono,tmValorPasaje,tmDetalle,tmNumCheque,tmReferencia,tmIdBanco,tmIdClase,tmIdRuta
,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,TipDev, Devolucion,D.IdCia,1,D.Fecha,'RC1',0,D.ValorNeto,D.IdCliente,D.IdVehiculo,D.VehPropio,D.IdConductor,D.IdConcepto,D.Modalidad,TipCar,C.Cartulina,IdCiaCar,FechaRec,R.CentInicial,R.CentFinal, R.NPasajeros,R.Recorridos,D.ValorTotal
,D.ValorOtros,TotalProducido,TotalGastos,TotalAhorro,TotalOtros, TotalVales, TotalAbono,R.ValorPasaje,D.Observacion,D.NumCheque,Referencia,D.IdBanco,D.IdClase,R.IdRuta,D.EnEfectivo,0,Null,D.TipDoc, D.Recibo, IdCiaDoc, FecDoc
,D.IdEstado,D.IdUsuario,D.TimeSys
 FROM  Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses  AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo 
 LEFT JOIN  Trn_Despachos AS C ON R.TipCar=C.TipDoc AND R.Cartulina=C.Cartulina AND R.IdCiaCar=C.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY  D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paInstm_EVrecOTR]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_EVrecOTR] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
--INSERTA RECIBOS DE NO CARTULINAS
 INSERT INTO tm_EVrec (tmEst,tmTipo,tmDocmnto,tmIdCia,tmItem,tmFecha,tmGrupo,tmValor,tmValorDev,tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdConcepto,tmModalidad,tmTipCar,tmCartulina,tmIdCiaCar,tmFechaRec,tmCentInicial
,tmCentFinal,tmNPasajeros,tmRecorridos,tmValorTotal,tmValorOtros,tmTotalProducido,tmTotalGastos,tmTotalAhorro,tmTotalOtros,tmTotalVales,tmTotalAbono,tmValorPasaje,tmDetalle,tmNumCheque,tmReferencia,tmIdBanco,tmIdClase,tmIdRuta,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,tmTimeSys)
 SELECT @pmtmEst,R.TipDoc, Recibo, IdCia,2,Fecha,'ROC',ValorNeto,0,IdCliente,R.IdVehiculo,R.VehPropio,R.IdConductor,IdConcepto,Modalidad,TipCar, Cartulina, IdCiaCar,Null,R.CentInicial,R.CentFinal,NPasajeros, Recorridos,ValorTotal,ValorOtros,TotalProducido,TotalGastos,TotalAhorro,TotalOtros, TotalVales, TotalAbono,ValorPasaje,R.Observacion
,NumCheque,Referencia,IdBanco,R.IdClase,IdRuta, Anulado, NumDev, FecDev,TipCom,Comprobante,IdCiaCom,Null,R.IdEstado,R.IdUsuario,TimeSys
 FROM  Trn_RecBuses  AS R  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo 
 WHERE Modalidad<>'CARTULINA' AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY  IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ExtVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_ExtVeh] @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdConductor VARCHAR(16),@pmtmVehPropio BIT,@pmtmTotaDebito MONEY,@pmtmTotaCredito MONEY
,@pmtmSaldoAnt MONEY,@pmtmSaldoAntCla MONEY,@pmtmSalAntPro MONEY,@pmtmSalAntProCla MONEY,@pmtmTotalProducido MONEY,@pmtmMaxProducido MONEY,@pmtmMinProducido MONEY,@pmtmTotalRecrridos INT,@pmtmTotalPasaj INT
,@pmtmTotalDias INT,@pmtmTotalCausac MONEY,@pmtmGalones DECIMAL(14,4),@pmtmValorComb MONEY
 AS 
 INSERT INTO tm_ExtVeh (tmEst,tmIdPropietario,tmIdVehiculo,tmIdConductor,tmVehPropio,tmTotaDebito,tmTotaCredito,tmSaldoAnt,tmSaldoAntCla,tmSalAntPro,tmSalAntProCla,tmTotalProducido,tmMaxProducido,tmMinProducido,tmTotalRecrridos,tmTotalPasaj,tmTotalDias,tmTotalCausac,tmGalones,tmValorComb)
 VALUES (@pmtmEst,@pmtmIdPropietario,@pmtmIdVehiculo,@pmtmIdConductor,@pmtmVehPropio,@pmtmTotaDebito,@pmtmTotaCredito,@pmtmSaldoAnt,@pmtmSaldoAntCla,@pmtmSalAntPro,@pmtmSalAntProCla,@pmtmTotalProducido,@pmtmMaxProducido,@pmtmMinProducido,@pmtmTotalRecrridos
,@pmtmTotalPasaj,@pmtmTotalDias,@pmtmTotalCausac,@pmtmGalones,@pmtmValorComb)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ExtVehRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_ExtVehRec] @pmtmEst CHAR(2)
AS
 INSERT INTO tm_ExtVeh (tmEst,tmIdPropietario,tmIdVehiculo,tmIdConductor,tmVehPropio,tmTotaDebito,tmTotaCredito,tmTotalProducido,tmMaxProducido,tmMinProducido,tmTotalRecrridos,tmTotalPasaj)
 SELECT tmEst,tmIdCliente,tmIdVehiculo,IdConductor,CASE TipoAfil WHEN 'PROPIO' THEN 1 ELSE 0 END,SUM(tmValorDev),SUM(tmValor),SUM(tmTotalProducido),MAX(tmTotalProducido),MIN(tmTotalProducido),SUM(tmRecorridos),SUM(tmNPasajeros)
 FROM  tm_EVrec AS TR INNER JOIN Vehiculos AS V ON TR.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst
 GROUP BY  tmEst,tmIdCliente,tmIdVehiculo,IdConductor,CASE TipoAfil WHEN 'PROPIO' THEN 1 ELSE 0 END
GO
/****** Object:  StoredProcedure [dbo].[paInstm_FactNeto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_FactNeto] @pmtmEst CHAR(2),@pmtmTipFac VARCHAR(3),@pmtmFactura INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmSubTotal MONEY,@pmtmDescuento MONEY,@pmtmImpuesto MONEY,@pmtmRetencion MONEY,@pmtmReteICA MONEY,@pmtmReteIVA MONEY,@pmtmFletes MONEY,@pmtmOtros MONEY,@pmtmCargos MONEY,@pmtmOtrDcto MONEY,@pmtmCostos MONEY,@pmtmSobretasa MONEY,@pmtmImpGlobal MONEY,@pmtmFaltantes MONEY
,@pmtmAnticipos MONEY,@pmtmNeto MONEY,@pmtmImpCons MONEY,@pmtmReteCREE MONEY,@pmtmEntradas DECIMAL(16,4),@pmtmSalidas DECIMAL(16,4),@pmtmTasaNac DECIMAL(16,4),@pmtmTasaDep DECIMAL(16,4),@pmtmTasaMun DECIMAL(16,4),@pmtmRec_Costo DECIMAL(16,4),@pmtmMgenCont DECIMAL(16,4),@pmtmIvaInf DECIMAL(16,4),@pmtmTarifaIba DECIMAL(16,6),@pmtmVrImpuBa MONEY,@pmtmTarifaCup DECIMAL(16,6),@pmtmVrImpuCup MONEY
 AS 
 INSERT INTO tm_FactNeto (tmEst,tmTipFac,tmFactura,tmIdCia,tmItem,tmSubTotal,tmDescuento,tmImpuesto,tmRetencion,tmReteICA,tmReteIVA,tmFletes,tmOtros,tmCargos,tmOtrDcto,tmCostos,tmSobretasa,tmImpGlobal,tmFaltantes,tmAnticipos,tmNeto,tmImpCons,tmReteCREE,tmEntradas,tmSalidas,tmTasaNac,tmTasaDep,tmTasaMun,tmRec_Costo,tmMgenCont,tmIvaInf,tmTarifaIba,tmVrImpuBa,tmTarifaCup,tmVrImpuCup)
 VALUES (@pmtmEst,@pmtmTipFac,@pmtmFactura,@pmtmIdCia,@pmtmItem,@pmtmSubTotal,@pmtmDescuento,@pmtmImpuesto,@pmtmRetencion,@pmtmReteICA,@pmtmReteIVA,@pmtmFletes,@pmtmOtros,@pmtmCargos,@pmtmOtrDcto,@pmtmCostos,@pmtmSobretasa,@pmtmImpGlobal,@pmtmFaltantes,@pmtmAnticipos,@pmtmNeto,@pmtmImpCons,@pmtmReteCREE,@pmtmEntradas,@pmtmSalidas,@pmtmTasaNac,@pmtmTasaDep,@pmtmTasaMun,@pmtmRec_Costo,@pmtmMgenCont,@pmtmIvaInf,@pmtmTarifaIba,@pmtmVrImpuBa,@pmtmTarifaCup,@pmtmVrImpuCup)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ForItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_ForItems] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmCantidad DECIMAL(14,4),@pmtmVrPrecio MONEY
,@pmtmTarifaIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifaDct DECIMAL(14,4),@pmtmVrDcto MONEY,@pmtmVrBruto MONEY,@pmtmDescripcion VARCHAR(150),@pmtmServcios BIT,@pmtmListaPrec CHAR(1)
,@pmtmCantDev DECIMAL(14,4),@pmtmCantFact DECIMAL(14,4),@pmtmCdOperario VARCHAR(16),@pmtmComsOper DECIMAL(14,4),@pmtmCodTarBa VARCHAR(4),@pmtmTarifaIba DECIMAL(16,6),@pmtmVrImpuBa MONEY
,@pmtmCodTarCup VARCHAR(4),@pmtmTarifaCup DECIMAL(16,6),@pmtmVrImpCup MONEY
 AS 
 INSERT INTO tm_ForItems (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCantidad,tmVrPrecio,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmVrBruto,tmDescripcion,tmServcios,tmListaPrec,tmCantDev,tmCantFact,tmCdOperario,tmComsOper
,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmCantidad,@pmtmVrPrecio,@pmtmTarifaIva,@pmtmVrIva,@pmtmTarifaDct,@pmtmVrDcto,@pmtmVrBruto,@pmtmDescripcion,@pmtmServcios,@pmtmListaPrec,@pmtmCantDev,@pmtmCantFact,@pmtmCdOperario,@pmtmComsOper
,@pmtmCodTarBa,@pmtmTarifaIba,@pmtmVrImpuBa,@pmtmCodTarCup,@pmtmTarifaCup,@pmtmVrImpCup)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ForItems_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_ForItems_Sel] @pmtmNumero VARCHAR(5),@pmTipoRango VARCHAR(3),@pmIdRango INT
,@pmNumSerie VARCHAR(5),@pmNumForma INT
 AS 
 INSERT INTO tm_ForItems (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCantidad,tmVrPrecio,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmVrBruto,tmDescripcion
,tmServcios,tmListaPrec,tmCantDev,tmCantFact,tmCdOperario,tmComsOper,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup)
 SELECT @pmtmNumero,Item,IdProducto,IdBodega,Cantidad,VrPrecio,TarifaIva,VrIva,TarifaDct,VrDcto,VrPrecio,Descripcion,Servicios,ListaPrec,CantDev,CantFact,CdOperario,Comision
,CodTarBa,TarifaIba,VrImpuBa,CodTarCup,TarifaCup,VrImpuCup
 FROM Trn_EdsForItems
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDfc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioDfc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCon)
SELECT @pmtmEst,2,TipDev,Devolucion,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto+VrSobretasa,VrRetencion,VrReteICA,VrReteIVA
,VrFletes,VrCargos,VrOtrDcto,VrImpGlobal,VrOtros,VrCostos,VrNeto,0,VrNeto,0,BaseImp,0,0,'0','','0','',IdVend,TarifaCom,'0',IdUsuario,IdLocEnv,'CREDITO','',Modalidad,'PED',Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,0,Factura,FecDoc,Observacion,TimeSys,VrImpCons
 FROM Trn_DevFcr
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDfo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioDfo] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCon)
SELECT @pmtmEst,1,TipDev,Devolucion,D.IdCia,D.Fecha,D.IdConcepto,D.NitCliente,D.CdAgencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrRetencion,D.VrReteICA,D.VrReteIVA
,D.VrFletes,D.VrCargos,D.VrOtrDcto,0,0,D.VrCostos,D.VrNeto,D.VrEfectivo,D.VrPagosOtr,0,D.BaseImp,TarifaIva,D.EnEfectivo,F.CdForma,F.NumForma
,F.CdBanco,SUBSTRING(F.DetallePago,1,150),D.IdVend,D.TarifaCom,D.nClieCon,D.IdCajero,D.IdLocal,Referncia1,Referncia2,D.Modalidad,'PED',D.Pedido,D.IdCiaPed,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Factura,FecDoc,D.Observacion,D.TimeSys,D.VrImpCons
 FROM Trn_DevFco AS D INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDnp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioDnp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,0,VrSobretasa,0,0,0,0,0,0,VrImpGlobal,VrOtros,VrCostos,VrNeto,VrNeto,0,0,VrSubTotal,0,1,'EFE',''
,'0','',IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','NOTACALIB','0',0,'00',TipCom,Comprobante,IdCiaCom,0,nNota,FecDoc,Observacion,TimeSys
 FROM Trn_DevPas
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioDvp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioDvp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDev,Devolucion,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,VrConDcto+VrCreDcto,VrSobretasa,0,0,0,VrCreTotal+VrConTotal+VrCreImp+VrConImp
,VrSobrantes,VrFaltantes,VrImpGlobal,VrOtros,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos+VrGastComb+VrGastOtros,VrSubTotal,0,0,'EFE',''
,'0','',IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'',Modalidad,'COR',NumCorte,'00',TipCom,Comprobante,IdCiaCom,0,Planilla,FecDoc,Observacion,TimeSys
 FROM Trn_DevPla
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioFco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioFco] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCon)
SELECT @pmtmEst,1,TipDoc,Factura,IdCia,Fecha,IdConcepto,NitCliente,CdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA
,VrFletes,VrCargos,VrOtrDcto,0,0,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,0,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,SUBSTRING(DetallePago,1,150),IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referncia1,Referncia2,Modalidad,TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCons
 FROM Trn_Factcon
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioFcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioFcr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCon)
SELECT @pmtmEst,2,TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto+VrSobretasa,VrRetencion,VrReteICA,VrReteIVA
,VrFletes,VrCargos,VrOtrDcto,VrImpGlobal,VrOtros,VrCostos,VrNeto,0,VrNeto,0,BaseImp,TarifaIva,0,IdForma,''
,'0',SUBSTRING(DetallePago,1,150),IdVend,TarifaCom,'0',IdUsuario,IdLocEnv,'CREDITO','',Modalidad,TipPed,Pedido,IdCiaPed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,VrImpCons
 FROM Trn_Facturas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioPas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioPas] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDoc,nNota,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,0,VrSobretasa,0,0,0,0,0,0,VrImpGlobal,VrOtros,VrCostos,VrNeto,VrNeto,0,0,VrSubTotal,0,1,'EFE',''
,'0','',IdVend,TarifaCom,'0',IdCajero,'0',Referencia,'','NOTACALIB','0',0,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCalibra
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_InfDiarioPla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_InfDiarioPla] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCajero VARCHAR(11)=Null
 AS 
 INSERT INTO tm_InfDiario (tmEst,tmItem,TipDoc,Numero,IdCia,Fecha,IdConcepto,IdTercero,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA
,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,BaseImp,TarifaIva,EnEfectivo,CdForma,NumForma
,CdBanco,DetallePagos,IdVend,TarifaCom,nClieCon,IdCajero,IdLocal,Referencia,Referencia2,Modalidad,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys)
SELECT @pmtmEst,1,TipDoc,Planilla,IdCia,Fecha,IdConcepto,NitTercero,'0',VrSubTotal,VrConDcto+VrCreDcto,VrSobretasa,0,0,0,VrCreTotal+VrConTotal+VrCreImp+VrConImp
,VrSobrantes,VrFaltantes,VrImpGlobal,VrOtros,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos+VrGastComb+VrGastOtros,VrSubTotal,0,0,'EFE',''
,'0','',IdVend,TarifaCom,NitRef,IdCajero,'0',Referencia,'',Modalidad,'COR',NumCorte,'00',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys
 FROM Trn_EdsCortes
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ingresos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Ingresos] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmNMes VARCHAR(6),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmDetalle VARCHAR(100),@pmtmVrBase MONEY,@pmtmCantDevg DECIMAL(10,4),@pmtmCantDed DECIMAL(10,4),@pmtmVrDevngado MONEY,@pmtmVrDeducido MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasBase INT,@pmtmDiasNoRem INT
,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmIdInstala VARCHAR(4),@pmtmVrSalario MONEY,@pmtmCodFondo VARCHAR(8),@pmtmClaseLiq VARCHAR(10),@pmtmOrigenLiq VARCHAR(10),@pmtmBaseRet BIT
,@pmtmEsPstamo BIT,@pmtmEsRetiro BIT,@pmtmNPrestamo INT
 AS 
 INSERT INTO tm_Ingresos (tmEst,tmItem,tmNMes,tmIdEmpleado,tmIdConcepto,tmDetalle,tmVrBase,tmCantDevg,tmCantDed,tmVrDevngado,tmVrDeducido,tmTarifa,tmDiasBase,tmDiasNoRem,tmFecInicial,tmFecFinal,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmIdInstala,tmVrSalario,tmCodFondo,tmClaseLiq,tmOrigenLiq,tmBaseRet,tmEsPstamo,tmEsRetiro,tmNPrestamo)
 VALUES (@pmtmEst,@pmtmItem,@pmtmNMes,@pmtmIdEmpleado,@pmtmIdConcepto,@pmtmDetalle,@pmtmVrBase,@pmtmCantDevg,@pmtmCantDed,@pmtmVrDevngado,@pmtmVrDeducido,@pmtmTarifa,@pmtmDiasBase,@pmtmDiasNoRem,@pmtmFecInicial,@pmtmFecFinal,@pmtmNContrato,@pmtmpVehiculo,@pmtmIdDep,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmIdInstala
,@pmtmVrSalario,@pmtmCodFondo,@pmtmClaseLiq,@pmtmOrigenLiq,@pmtmBaseRet,@pmtmEsPstamo,@pmtmEsRetiro,@pmtmNPrestamo)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_IntAhorro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_IntAhorro] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdVehiculo VARCHAR(10),@pmtmIdTercero VARCHAR(16),@pmtmSaldoBase MONEY
,@pmtmTasa DECIMAL(14,4),@pmtmValor MONEY,@pmtmNmes INT,@pmtmVehPropio BIT,@pmtmIdConductor VARCHAR(16),@pmtmIdPropietario VARCHAR(16)
, @pmtmConductor VARCHAR(100),@pmtmTercero VARCHAR(100),@pmtmRetencion MONEY,@pmtmVrAbono MONEY
 AS
 INSERT INTO tm_IntAhorro (tmEst, tmItem, tmIdVehiculo, tmIdTercero, tmSaldoBase, tmTasa, tmValor, tmNmes, tmVehPropio, tmIdConductor, tmIdPropietario, tmConductor,tmTercero,tmRetencion,tmVrAbono)
 VALUES (@pmtmEst, @pmtmItem, @pmtmIdVehiculo, @pmtmIdTercero, @pmtmSaldoBase, @pmtmTasa, @pmtmValor, @pmtmNmes, @pmtmVehPropio, @pmtmIdConductor
, @pmtmIdPropietario, @pmtmConductor,@pmtmTercero,@pmtmRetencion,@pmtmVrAbono)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_IntNomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_IntNomina] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdVehiculo VARCHAR(10),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConductor VARCHAR(16),@pmtmIdPropietario VARCHAR(16),@pmtmVehPropio BIT,@pmtmConductor VARCHAR(100),@pmtmTercero VARCHAR(100)
,@pmtmCcosto VARCHAR(16),@pmtmValorAbono MONEY
 AS 
 INSERT INTO tm_IntNomina (tmEst,tmItem,tmIdVehiculo,tmIdEmpleado,tmIdConductor,tmIdPropietario,tmVehPropio,tmConductor,tmTercero,tmCcosto,tmValorAbono)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdVehiculo,@pmtmIdEmpleado,@pmtmIdConductor,@pmtmIdPropietario,@pmtmVehPropio,@pmtmConductor,@pmtmTercero
,@pmtmCcosto,@pmtmValorAbono)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_KarUbi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_KarUbi] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16)
,@pmtmIdBodega VARCHAR(4),@pmtmIdUbic VARCHAR(10),@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4)
,@pmtmLinea INT,@pmtmCdNueBod VARCHAR(4),@pmtmCdNueUbic VARCHAR(10)
 AS 
 INSERT INTO tm_KarUbi (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmIdUbic,tmEntradas,tmSalidas,tmLinea,tmCdNueBod,tmCdNueUbic)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmIdUbic,@pmtmEntradas,@pmtmSalidas,@pmtmLinea,@pmtmCdNueBod,@pmtmCdNueUbic)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_KarUbi_Dvn]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_KarUbi_Dvn] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
 AS 
 INSERT INTO tm_KarUbi (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmIdUbic,tmEntradas,tmSalidas,tmLinea)
 SELECT @pmtmNumero,Item,IdProducto,IdBodega,IdUbic,Salidas,Entradas,Linea
 FROM Trn_KarUbic
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_KarUbi_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_KarUbi_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
 AS 
 INSERT INTO tm_KarUbi (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmIdUbic,tmEntradas,tmSalidas,tmLinea)
 SELECT @pmtmNumero,Item,IdProducto,IdBodega,IdUbic,Entradas,Salidas,Linea
 FROM Trn_KarUbic
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmCdTanque VARCHAR(4),@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmIdUnd VARCHAR(4),@pmtmVrUnitario MONEY,@pmtmVrPrecio MONEY,@pmtmVrCostProm MONEY,@pmtmVrProm MONEY
,@pmtmTarifaIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifaDct DECIMAL(14,4),@pmtmVrDcto MONEY,@pmtmTarifaRet DECIMAL(14,4),@pmtmVrRete MONEY,@pmtmTarifaIca DECIMAL(14,4),@pmtmVrIca MONEY,@pmtmVrBruto MONEY,@pmtmCdUbic VARCHAR(10),@pmtmNumLote VARCHAR(30),@pmtmFechLote SMALLDATETIME,@pmtmFecVceLote SMALLDATETIME
,@pmtmIdTercero VARCHAR(16),@pmtmCdAgencia VARCHAR(16),@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmCdLocal VARCHAR(8),@pmtmCdSzona VARCHAR(4),@pmtmpVehiculo VARCHAR(10),@pmtmIdVend VARCHAR(16),@pmtmComision DECIMAL(14,4),@pmtmCdOperario VARCHAR(16),@pmtmComisnOper DECIMAL(14,4),@pmtmReferencia VARCHAR(50)
,@pmtmDescripcion VARCHAR(250),@pmtmComptmntos VARCHAR(50),@pmtmCdProdEquiv VARCHAR(16),@pmtmCdMngra VARCHAR(10),@pmtmNumInicial DECIMAL(14,4),@pmtmNumFinal DECIMAL(14,4),@pmtmSobretasa DECIMAL(14,4),@pmtmTasaNac DECIMAL(14,4),@pmtmTasaDep DECIMAL(14,4),@pmtmTasaMun DECIMAL(14,4),@pmtmSoldicom DECIMAL(14,4)
,@pmtmImpGlobal DECIMAL(14,4),@pmtmOtroImpto DECIMAL(14,4),@pmtmUnidades DECIMAL(14,4),@pmtmServcios BIT,@pmtmNoVentas INT,@pmtmEsCombo BIT,@pmtmEsProdBase INT,@pmtmItemCbo INT,@pmtmCodTarDct VARCHAR(4),@pmtmCodTarIva VARCHAR(4),@pmtmCodTarIca VARCHAR(4),@pmtmCodTarRet VARCHAR(4),@pmtmCodTarCom VARCHAR(4)
,@pmtmCodTarCmc VARCHAR(4),@pmtmCdSubgrupo VARCHAR(8),@pmtmListaPrec CHAR(1),@pmtmVrBase MONEY,@pmtmCdMoneda VARCHAR(5),@pmtmVrTasaCamb MONEY,@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmTipRem VARCHAR(3),@pmtmRemision INT,@pmtmIdCiaRem CHAR(2),@pmtmReferencia2 VARCHAR(50),@pmtmFecOrden SMALLDATETIME
,@pmtmgalsbruto DECIMAL(14,4),@pmtmgalsneto DECIMAL(14,4),@pmtmTemperatura DECIMAL(14,4),@pmtmUmTemp VARCHAR(3),@pmtmDensidad DECIMAL(14,4),@pmtmRec_Costo DECIMAL(14,4),@pmtmMgenCont  DECIMAL(14,4),@pmtmCotizacion INT,@pmtmCiaCotiza CHAR(2),@pmtmVrImvCosto DECIMAL(16,4),@pmtmTarifaIco DECIMAL(14,4),@pmtmVrImpCon DECIMAL(16,4)
,@pmtmCantObseq DECIMAL(14,4),@pmtmIvaObseq MONEY,@pmtmIvaComb DECIMAL(16,4),@pmtmImpCarb DECIMAL(14,4),@pmtmIngCombo DECIMAL(16,4),@pmtmTarifaStc DECIMAL(14,4),@pmtmSobtasaCons DECIMAL(16,4),@pmtmCodTarIco VARCHAR(4),@pmtmBaseIvp MONEY,@pmtmTarifaIvp DECIMAL(14,4),@pmtmIvaIngProd MONEY
,@pmtmTarifaIba DECIMAL(16,6),@pmtmVrImpuBa MONEY,@pmtmCodTarBa VARCHAR(4),@pmtmTarifaCup DECIMAL(16,6),@pmtmVrImpCup MONEY,@pmtmCodTarCup VARCHAR(4),@pmtmTarifaIat DECIMAL(14,4),@pmtmVrAviTab MONEY,@pmtmCodTarIat VARCHAR(4),@pmtmTarifaBom DECIMAL(14,4),@pmtmVrSobBom MONEY,@pmtmCodTarBom VARCHAR(4)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco
,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmCdTanque,@pmtmEntradas,@pmtmSalidas,@pmtmIdUnd,@pmtmVrUnitario,@pmtmVrPrecio,@pmtmVrCostProm,@pmtmVrProm,@pmtmTarifaIva,@pmtmVrIva,@pmtmTarifaDct,@pmtmVrDcto,@pmtmTarifaRet,@pmtmVrRete,@pmtmTarifaIca,@pmtmVrIca,@pmtmVrBruto,@pmtmCdUbic,@pmtmNumLote,@pmtmFechLote,@pmtmFecVceLote
,@pmtmIdTercero,@pmtmCdAgencia,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmCdLocal,@pmtmCdSzona,@pmtmpVehiculo,@pmtmIdVend,@pmtmComision,@pmtmCdOperario,@pmtmComisnOper,@pmtmReferencia,@pmtmDescripcion,@pmtmComptmntos,@pmtmCdProdEquiv,@pmtmCdMngra,@pmtmNumInicial,@pmtmNumFinal,@pmtmSobretasa,@pmtmTasaNac,@pmtmTasaDep,@pmtmTasaMun,@pmtmSoldicom
,@pmtmImpGlobal,@pmtmOtroImpto,@pmtmUnidades,@pmtmServcios,@pmtmNoVentas,@pmtmEsCombo,@pmtmEsProdBase,@pmtmItemCbo,@pmtmCodTarDct,@pmtmCodTarIva,@pmtmCodTarIca,@pmtmCodTarRet,@pmtmCodTarCom,@pmtmCodTarCmc,@pmtmCdSubgrupo,@pmtmListaPrec,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCia
,@pmtmVrBase,@pmtmCdMoneda,@pmtmVrTasaCamb,@pmtmTipRem,@pmtmRemision,@pmtmIdCiaRem,@pmtmReferencia2,@pmtmFecOrden,@pmtmgalsbruto,@pmtmgalsneto,@pmtmTemperatura,@pmtmUmTemp,@pmtmDensidad,@pmtmRec_Costo,@pmtmMgenCont,@pmtmCotizacion,@pmtmCiaCotiza,@pmtmVrImvCosto,@pmtmTarifaIco,@pmtmVrImpCon,@pmtmCantObseq,@pmtmIvaObseq
,@pmtmIvaComb,@pmtmImpCarb,@pmtmIngCombo,@pmtmTarifaStc,@pmtmSobtasaCons,@pmtmCodTarIco,@pmtmBaseIvp,@pmtmTarifaIvp,@pmtmIvaIngProd,@pmtmTarifaIba,@pmtmVrImpuBa,@pmtmCodTarBa,@pmtmTarifaCup,@pmtmVrImpCup,@pmtmCodTarCup,@pmtmTarifaIat,@pmtmVrAviTab,@pmtmCodTarIat,@pmtmTarifaBom,@pmtmVrSobBom,@pmtmCodTarBom)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_Nts]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex_Nts] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo,tmMgenCont
,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmTarifaIba
,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,Entradas,Salidas,K.IdUnd,VrUnitario,VrPrecio,VrCostProm,0,TarifaIva,VrIvaEnt+VrIvaSal,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec
,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN TipOrd ELSE TipDoc END,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN NumOrden ELSE Documento END,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN IdCiaOrd ELSE IdCia END
,VrBase,CdMoneda,VrTasaCamb,'REM',Remision,IdCiaRem,Referencia2,FecOrden,0,0,0,'',0,Rec_Costo,MgenCont,Cotizacion,IdCiaCot,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq,BaseIvaCom,ImpCarbono,IngBaseCom
,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND EsProdBase=0 AND Salidas>0
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_NtsDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex_NtsDev] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo,tmMgenCont
,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,Salidas,Entradas,K.IdUnd,VrUnitario,VrPrecio,VrCostProm,0,TarifaIva,VrIvaEnt+VrIvaSal,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec
,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN TipOrd ELSE TipDoc END,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN NumOrden ELSE Documento END,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN IdCiaOrd ELSE IdCia END
,VrBase,CdMoneda,VrTasaCamb,'REM',Remision,IdCiaRem,Referencia2,FecOrden,0,0,0,'',0,Rec_Costo,MgenCont,Cotizacion,IdCiaCot,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco
,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND EsProdBase=0
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_Ord]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex_Ord] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad
,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,CASE WHEN CantObseq>0 AND (TipDoc='ENT' OR TipDoc='COM' OR SUBSTRING(TipDoc,1,2)='DF' OR SUBSTRING(TipDoc,1,2)='DO') THEN Entradas-CantObseq ELSE Entradas END
,CASE WHEN CantObseq>0 AND (TipDoc='DVE' OR TipDoc='DEI' OR SUBSTRING(TipDoc,1,2)='FC' OR SUBSTRING(TipDoc,1,2)='FO') THEN Salidas-CantObseq 
 WHEN (TipDoc='PED' AND TipDocDev='PPD' AND Unidades>0) THEN Unidades WHEN (TipDoc='PED' OR TipDoc='COT' OR TipDoc='REM') AND CantObseq>0 THEN Salidas-CantObseq ELSE Salidas END
,K.IdUnd,VrUnitario,VrPrecio,VrCostProm,0,TarifaIva,CASE WHEN CantObseq>0 AND VrIvaObseq>0 THEN (VrIvaEnt+VrIvaSal)-VrIvaObseq ELSE VrIvaEnt+VrIvaSal END
,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo,MgenCont,Cotizacion,IdCiaCot,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND EsProdBase=0
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex_Sel] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad
,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,CASE WHEN CantObseq>0 AND (TipDoc='ENT' OR TipDoc='COM' OR SUBSTRING(TipDoc,1,2)='DF' OR SUBSTRING(TipDoc,1,2)='DO') THEN Entradas-CantObseq ELSE Entradas END
,CASE WHEN CantObseq>0 AND (TipDoc='DVE' OR TipDoc='DEI' OR SUBSTRING(TipDoc,1,2)='FC' OR SUBSTRING(TipDoc,1,2)='FO' OR TipDoc='PED' OR TipDoc='COT' OR TipDoc='REM') THEN Salidas-CantObseq ELSE Salidas END,K.IdUnd
,CASE WHEN (VrImpuBa+VrImpuCup)>0 AND (TipDoc='ENT' OR TipDoc='COM' OR TipDoc='DVE' OR TipDoc='DEI' OR TipDoc='ODC') THEN VrUnitario-(VrImpuBa+VrImpuCup) ELSE VrUnitario END
,CASE WHEN (VrImpuBa+VrImpuCup)>0 AND (TipDoc='ENT' OR TipDoc='COM' OR TipDoc='DVE' OR TipDoc='DEI' OR TipDoc='ODC') THEN VrPrecio-(VrImpuBa+VrImpuCup) ELSE VrPrecio END
,VrCostProm,0,TarifaIva,CASE WHEN CantObseq>0 AND VrIvaObseq>0 THEN (VrIvaEnt+VrIvaSal)-VrIvaObseq ELSE VrIvaEnt+VrIvaSal END
,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo,MgenCont,Cotizacion,IdCiaCot,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND EsProdBase=0
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_SelDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex_SelDev] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad,tmRec_Costo,tmMgenCont
,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,CASE WHEN CantObseq>0 AND (TipDoc='DVE' OR TipDoc='DEI' OR SUBSTRING(TipDoc,1,2)='FC' OR SUBSTRING(TipDoc,1,2)='FO' OR TipDoc='PED' OR TipDoc='COT' OR TipDoc='REM') THEN Salidas-CantObseq ELSE Salidas END
,CASE WHEN CantObseq>0 AND (TipDoc='ENT' OR TipDoc='COM' OR SUBSTRING(TipDoc,1,2)='DF' OR SUBSTRING(TipDoc,1,2)='DO') THEN Entradas-CantObseq ELSE Entradas END,K.IdUnd
,CASE WHEN (VrImpuBa+VrImpuCup)>0 AND (TipDoc='ENT' OR TipDoc='COM' OR TipDoc='DVE' OR TipDoc='DEI' OR TipDoc='ODC') THEN VrUnitario-(VrImpuBa+VrImpuCup) ELSE VrUnitario END
,CASE WHEN (VrImpuBa+VrImpuCup)>0 AND (TipDoc='ENT' OR TipDoc='COM' OR TipDoc='DVE' OR TipDoc='DEI' OR TipDoc='ODC') THEN VrPrecio-(VrImpuBa+VrImpuCup) ELSE VrPrecio END
,VrCostProm,0,TarifaIva,CASE WHEN CantObseq>0 AND VrIvaObseq>0 THEN (VrIvaEnt+VrIvaSal)-VrIvaObseq ELSE VrIvaEnt+VrIvaSal END,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,CASE WHEN TipOrd='CPP' AND NumOrden>0 THEN 'OPP' ELSE 'REM' END
,Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo,MgenCont,Cotizacion,IdCiaCot,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia  AND  EsProdBase<=1
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Kdex_SelDve]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Kdex_SelDve] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Kdex (tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete
,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto
,tmUnidades,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmCdSubgrupo
,tmListaPrec,tmTipDoc,tmDocumento,tmIdCia,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp
,tmDensidad,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom)
SELECT @pmtmNumero,Item,K.IdProducto,K.IdBodega,CdTanque,CASE WHEN CantObseq>0 AND (TipDoc='DVE' OR TipDoc='DEI') THEN Salidas-CantObseq ELSE Salidas END
,CASE WHEN CantObseq>0 AND (TipDoc='ENT' OR TipDoc='COM') THEN Entradas-CantObseq ELSE Entradas END,K.IdUnd
,CASE WHEN (NumInicial+VrImpuBa+VrImpuCup)>0 THEN VrUnitario-(NumInicial+VrImpuBa+VrImpuCup) ELSE VrUnitario END
,CASE WHEN (NumInicial+VrImpuBa+VrImpuCup)>0 THEN VrPrecio-(NumInicial+VrImpuBa+VrImpuCup) ELSE VrPrecio END
,VrCostProm,0,TarifaIva,CASE WHEN CantObseq>0 AND VrIvaObseq>0 THEN (VrIvaEnt+VrIvaSal)-VrIvaObseq ELSE VrIvaEnt+VrIvaSal END
,TarifaDct,VrDctoEnt+VrDctoSal,TarifaRet,VrReteEnt+VrReteSal
,TarifaIca,VrIcaEnt+VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,FechLote,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,IdVend
,Comision,CdOperario,ComisnOper,K.Referencia,Descripcion,Comptmntos,CdProdEquiv,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,IdSubgrupo,ListaPrec,TipOrd,NumOrden,IdCiaOrd,VrBase,CdMoneda,VrTasaCamb
,'REM',Remision,IdCiaRem,Referencia2,FecOrden,galsbruto,galsneto,Temperatura,UmTemp,Densidad,Rec_Costo,MgenCont,Cotizacion,IdCiaCot,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_LibOf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_LibOf] @pmtmEst CHAR(2),@pmtmTipCom VARCHAR(3),@pmtmItem INT,@pmtmIdCuenta VARCHAR(16),@pmtmIdTercero VARCHAR(16)
,@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdCia CHAR(2),@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmSaldoAnterior MONEY
,@pmtmSanNit MONEY,@pmtmSanNitcc MONEY,@pmtmSanNitCcSub MONEY
 AS 
 INSERT INTO tm_LibOf (tmEst,tmTipCom,tmItem,tmIdCuenta,tmIdTercero,tmIdCCosto,tmIdSubCos,tmIdCia,tmTotalDebitos,tmTotalCreditos,tmSaldoAnterior,tmSanNit,tmSanNitcc,tmSanNitCcSub)
 VALUES (@pmtmEst,@pmtmTipCom,@pmtmItem,@pmtmIdCuenta,@pmtmIdTercero,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdCia,@pmtmTotalDebitos,@pmtmTotalCreditos
,@pmtmSaldoAnterior,@pmtmSanNit,@pmtmSanNitcc,@pmtmSanNitCcSub)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Liquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Liquida] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmDetalle VARCHAR(100),@pmtmFecUltLiq SMALLDATETIME,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmVrBase MONEY,@pmtmCantidad INT,@pmtmVrLiquida MONEY,@pmtmVrDeducido MONEY,@pmtmFecIniPmd SMALLDATETIME,@pmtmFecFinPmd SMALLDATETIME,@pmtmDiasBase INT
,@pmtmDiasNoRem INT,@pmtmTarifa DECIMAL(10,4),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmLogPmdio VARCHAR(1500),@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrParcial MONEY,@pmtmNitTercero VARCHAR(16)
 AS 
 INSERT INTO tm_Liquida (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,tmVrParcial,tmNitTercero)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdEmpleado,@pmtmIdConcepto,@pmtmDetalle,@pmtmFecUltLiq,@pmtmFecInicial,@pmtmFecFinal,@pmtmVrBase,@pmtmCantidad,@pmtmVrLiquida,@pmtmVrDeducido,@pmtmFecIniPmd,@pmtmFecFinPmd,@pmtmDiasBase,@pmtmDiasNoRem,@pmtmTarifa,@pmtmNPrestamo,@pmtmNCuota,@pmtmLogPmdio
,@pmtmNContrato,@pmtmpVehiculo,@pmtmIdDep,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmVrSalario,@pmtmVrParcial,@pmtmNitTercero)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Liquida_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Liquida_Sel] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmtmNumero VARCHAR(5),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 INSERT INTO tm_Liquida (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd
,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,tmVrParcial,tmNitTercero)
 SELECT @pmtmNumero,Item,IdEmpleado,IdConcepto,Detalle,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd
 ,DiasBase,DiasNoRem,Tarifa,NPrestamo,NCuota,LogPmdio,NContrato,pVehiculo,IdDep,IdCCosto,IdSubCos,IdNom,VrSalario,VrParcial,NitTercero
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ListaPrec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_ListaPrec] @pmtmEst CHAR(2),@pmIdProducto VARCHAR(16),@pmMargen1 DECIMAL(14,4),@pmMargen2 DECIMAL(14,4),@pmMargen3 DECIMAL(14,4),@pmMargen4 DECIMAL(14,4),@pmMargen5 DECIMAL(14,4),@pmTarifDcto1 DECIMAL(14,4)
,@pmTarifDcto2 DECIMAL(14,4),@pmTarifDcto3 DECIMAL(14,4),@pmTarifDcto4 DECIMAL(14,4),@pmTarifDcto5 DECIMAL(14,4),@pmTrmDia1 MONEY,@pmTrmDia2 MONEY,@pmTrmDia3 MONEY,@pmTrmDia4 MONEY,@pmTrmDia5 MONEY,@pmIdCia CHAR(2)
,@pmCostoAnt MONEY,@pmCostoUlt MONEY,@pmCostoPmd MONEY,@pmExistenciaCia DECIMAL(14,4),@pmKarTipDoc VARCHAR(3),@pmKarEntradas DECIMAL(14,4),@pmKarSalidas DECIMAL(14,4),@pmKarCostoEnt MONEY,@pmKarCostoSal MONEY
,@pmCiaPrecio1 MONEY,@pmCiaPrecio2 MONEY,@pmCiaPrecio3 MONEY,@pmCiaPrecio4 MONEY,@pmCiaPrecio5 MONEY,@pmCiaTarifIva DECIMAL(14,4),@pmCiaIvaInc VARCHAR(10),@pmPrecioVenta1 MONEY,@pmPrecioVenta2 MONEY,@pmPrecioVenta3 MONEY
,@pmPrecioVenta4 MONEY,@pmPrecioVenta5 MONEY
 AS 
 INSERT INTO tm_ListaPrec (tmEst,IdProducto,Margen1,Margen2,Margen3,Margen4,Margen5,TarifDcto1,TarifDcto2,TarifDcto3,TarifDcto4,TarifDcto5,TrmDia1,TrmDia2,TrmDia3,TrmDia4,TrmDia5,IdCia,CostoAnt,CostoUlt,CostoPmd,ExistenciaCia,KarTipDoc,KarEntradas,KarSalidas,KarCostoEnt,KarCostoSal
,CiaPrecio1,CiaPrecio2,CiaPrecio3,CiaPrecio4,CiaPrecio5,CiaTarifIva,CiaIvaInc,PrecioVenta1,PrecioVenta2,PrecioVenta3,PrecioVenta4,PrecioVenta5)
 VALUES (@pmtmEst,@pmIdProducto,@pmMargen1,@pmMargen2,@pmMargen3,@pmMargen4,@pmMargen5,@pmTarifDcto1,@pmTarifDcto2,@pmTarifDcto3,@pmTarifDcto4,@pmTarifDcto5,@pmTrmDia1,@pmTrmDia2,@pmTrmDia3,@pmTrmDia4,@pmTrmDia5,@pmIdCia
,@pmCostoAnt,@pmCostoUlt,@pmCostoPmd,@pmExistenciaCia,@pmKarTipDoc,@pmKarEntradas,@pmKarSalidas,@pmKarCostoEnt,@pmKarCostoSal
,@pmCiaPrecio1,@pmCiaPrecio2,@pmCiaPrecio3,@pmCiaPrecio4,@pmCiaPrecio5,@pmCiaTarifIva,@pmCiaIvaInc,@pmPrecioVenta1,@pmPrecioVenta2,@pmPrecioVenta3,@pmPrecioVenta4,@pmPrecioVenta5)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Lot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Lot] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmLinea INT,@pmtmNumLote VARCHAR(30)
,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmCdUbic VARCHAR(10),@pmtmEntradas DECIMAL(14,4)
,@pmtmSalidas DECIMAL(14,4),@pmtmFecha SMALLDATETIME,@pmtmFecVence SMALLDATETIME,@pmtmCdNueUbic VARCHAR(10)
 AS 
 INSERT INTO tm_Lot (tmNumero,tmItem,tmLinea,tmNumLote,tmIdProducto,tmIdBodega,tmCdUbic,tmEntradas,tmSalidas,tmFecha,tmFecVence,tmCdNueUbic)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmLinea,@pmtmNumLote,@pmtmIdProducto,@pmtmIdBodega,@pmtmCdUbic,@pmtmEntradas
,@pmtmSalidas,@pmtmFecha,@pmtmFecVence,@pmtmCdNueUbic)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Lot_DVN]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Lot_DVN] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)=Null,@pmLinea INT=Null
 AS 
 INSERT INTO tm_Lot (tmNumero,tmItem,tmLinea,tmNumLote,tmIdProducto,tmIdBodega,tmCdUbic,tmEntradas,tmSalidas,tmFecha,tmFecVence)
 SELECT @pmtmNumero,Item,Linea,NumLote,IdProducto,IdBodega,CdUbic,Salidas,Entradas,Fecha,FecVence
 FROM Trn_LotMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Linea>=ISNULL(@pmLinea,0)  AND Linea<=ISNULL(@pmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Lot_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Lot_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)=Null,@pmLinea INT=Null
 AS 
 INSERT INTO tm_Lot (tmNumero,tmItem,tmLinea,tmNumLote,tmIdProducto,tmIdBodega,tmCdUbic,tmEntradas,tmSalidas,tmFecha,tmFecVence)
 SELECT @pmtmNumero,Item,Linea,NumLote,IdProducto,IdBodega,CdUbic,Entradas,Salidas,Fecha,FecVence
 FROM Trn_LotMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Linea>=ISNULL(@pmLinea,0)  AND Linea<=ISNULL(@pmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes] @pmtmEst CHAR(2),@pmtmTipDoc VARCHAR(3),@pmtmNumero INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmFecha SMALLDATETIME,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmCargos MONEY,@pmtmAbonos MONEY,@pmtmTimeSys SMALLDATETIME,@pmtmFecVence SMALLDATETIME
,@pmtmCdConcepto VARCHAR(4),@pmtmModalidad VARCHAR(10),@pmtmDetalle VARCHAR(250),@pmtmReferencia VARCHAR(50),@pmtmTipRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmCdLocal VARCHAR(8),@pmtmNumForma VARCHAR(20),@pmtmCdBanco VARCHAR(4),@pmtmBeneficiario VARCHAR(150),@pmtmCdForma VARCHAR(4),@pmtmEnEfectivo BIT,@pmtmTotalAbono MONEY
,@pmtmVrAfavor MONEY,@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCiaCom CHAR(2),@pmtmAnulado BIT,@pmtmNumDev INT,@pmtmFecDev SMALLDATETIME,@pmtmIdUsuario VARCHAR(11),@pmtmSanClie MONEY,@pmtmSanClieCia MONEY,@pmtmSanAge MONEY,@pmtmSanAgeCia MONEY
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 VALUES (@pmtmEst,@pmtmTipDoc,@pmtmNumero,@pmtmIdCia,@pmtmItem,@pmtmFecha,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdVend,@pmtmCargos,@pmtmAbonos,@pmtmTimeSys,@pmtmFecVence,@pmtmCdConcepto,@pmtmModalidad,@pmtmDetalle,@pmtmReferencia,@pmtmTipRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmCdLocal,@pmtmNumForma,@pmtmCdBanco,@pmtmBeneficiario,@pmtmCdForma
,@pmtmEnEfectivo,@pmtmTotalAbono,@pmtmVrAfavor,@pmtmTipCom,@pmtmComprobante,@pmtmIdCiaCom,@pmtmAnulado,@pmtmNumDev,@pmtmFecDev,@pmtmIdUsuario,@pmtmSanClie,@pmtmSanClieCia,@pmtmSanAge,@pmtmSanAgeCia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Dfc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes_Dfc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia
,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDev,Devolucion,IdCia,0,Fecha,IdCliente,IdAgencia,IdVend,0,VrNeto,TimeSys,FecDoc,IdConcepto,Modalidad,Observacion,ModdDev
,TipDoc,Factura,IdCiaDoc,IdLocEnv,'','0','','0',0,0,0,TipCom,Comprobante,IdCiaCom,0,0,Fecha,IdUsuario,0,0,0,0
 FROM Trn_DevFcr
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND DevMasivo<=0 AND VrNeto>0 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Fcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes_Fcr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia
,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,V.TipDoc,V.Factura,V.IdCia,Item,V.Fecha,V.IdCliente,V.IdAgencia,V.IdVend,VrFactura,0,TimeSys,V.FechaVence,V.IdConcepto,Modalidad,Detalle,Referencia
,TipRef,DocRef,IdCiaRef,IdLocEnv,CAST(Pedido AS VARCHAR(20)),'0',NomContac,'0',MulPlazos,VrAbonado,0,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,IdUsuario,0,0,0,0
 FROM Trn_Vencimientos AS V INNER JOIN Trn_Facturas AS F ON V.TipDoc=F.TipDoc  AND V.Factura=F.Factura  AND V.IdCia=F.IdCia
 WHERE V.TipDoc<>'NDB' AND V.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND V.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND V.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND V.IdCia LIKE ISNULL(@pmIdCia,'%%') AND V.IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Ncr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes_Ncr] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia
,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDoc,NumNota,IdCia,0,Fecha,IdCliente,IdAgencia,IdVend,0,VrNeto,TimeSys,FechaVence,IdConcepto,Modalidad,Observacion,Referencia
,TipDcm,Documento,IdCiaDcm,IdLocal,NumCheque,CdBanco,'',CdForma,PrestCaja,0,VrAnticipo,TipCom,Comprobante,IdCiaCom,0,0,Null,IdUsuario,0,0,0,0
 FROM Trn_Notas
 WHERE TipDoc='NCR' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Ndb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes_Ndb] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia
,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,V.TipDoc,V.Factura,V.IdCia,Item,V.Fecha,V.IdCliente,V.IdAgencia,V.IdVend,VrFactura,0,TimeSys,V.FechaVence,V.IdConcepto,Modalidad,Detalle,V.Referencia
,TipRef,DocRef,IdCiaRef,IdLocal,NumCheque,CdBanco,N.Referencia,CdForma,MulPlazos,VrAbonado,VrSancion,TipCom,Comprobante,IdCiaCom,0,Documento,Null,IdUsuario,0,0,0,0
 FROM Trn_Vencimientos AS V INNER JOIN Trn_Notas AS N ON V.TipDoc=N.TipDoc  AND V.Factura=N.NumNota  AND V.IdCia=N.IdCia
 WHERE V.TipDoc='NDB' AND V.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND V.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND V.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND V.IdCia LIKE ISNULL(@pmIdCia,'%%') AND V.IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Odb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes_Odb] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia
,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDev,Devolucion,IdCia,Documento,Fecha,IdCliente,IdAgencia,IdVend,VrNeto,0,TimeSys,FecPago,IdConcepto,Modalidad,Observacion,Referencia
,TipDoc,Recibo,IdCiaDoc,IdLocal,'','0',pVehiculo,'0',EnEfectivo,0,VrAnticipo,TipCom,Comprobante,IdCiaCom,0,0,FecDoc,IdUsuario,0,0,0,0
 FROM Trn_DevRec
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovClientes_Rec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovClientes_Rec] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_MovClientes (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmTimeSys,tmFecVence,tmCdConcepto,tmModalidad,tmDetalle,tmReferencia
,tmTipRef,tmDocRef,tmIdCiaRef,tmCdLocal,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDoc,Recibo,IdCia,0,Fecha,IdCliente,IdAgencia,IdVend,0,VrNeto,TimeSys,FecPago,IdConcepto,Modalidad,Observacion,Referencia
,TipDcm,Documento,IdCiaDcm,IdLocal,NumForma,CdBanco,pVehiculo,CdForma,EnEfectivo,0,VrAnticipo,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,IdUsuario,0,0,0,0
 FROM Trn_Recibos
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_MovCue] @pmtmEst CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmVrBase MONEY,@pmTarifaBase DECIMAL(14,4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmNitDoc VARCHAR(16),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4)
,@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmVehPropio INT,@pmReferncia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
,@pmVrSanCue MONEY,@pmVrSanCueCia MONEY,@pmVrSanNit MONEY,@pmVrSanNitCia MONEY,@pmVrSanVeh MONEY,@pmVrSanVehCia MONEY,@pmVrSanCc MONEY,@pmVrSanCcCia MONEY,@pmVrSanCcSub MONEY,@pmVrSanCcSubCia MONEY,@pmVrSanNitCc MONEY,@pmVrSanNitCcCia MONEY,@pmVrSanNitCcSub MONEY,@pmVrSanNitCcSubCia MONEY
,@pmVrSanNitAge MONEY,@pmVrSanNitAgeCia MONEY,@pmVrSanNitAgeCc MONEY,@pmVrSanNitAgeCcCia MONEY,@pmVrSanNitAgeCcSub MONEY,@pmVrSanNitAgeCcSubCia MONEY,@pmVrSanNitVeh MONEY,@pmVrSanNitVehCia MONEY,@pmVrSanNitVehCc MONEY,@pmVrSanNitVehCcCia MONEY,@pmVrSanVehCc MONEY,@pmVrSanVehCcCia MONEY
,@pmVrSanVehCcSub MONEY,@pmVrSanVehCcSubCia MONEY
 AS 
 INSERT INTO tm_MovCue (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio
,Referncia,TipDocRef,DocRef,IdCiaRef,VrSanCue,VrSanCueCia,VrSanNit,VrSanNitCia,VrSanVeh,VrSanVehCia,VrSanCc,VrSanCcCia,VrSanCcSub,VrSanCcSubCia,VrSanNitCc,VrSanNitCcCia,VrSanNitCcSub,VrSanNitCcSubCia,VrSanNitAge,VrSanNitAgeCia,VrSanNitAgeCc,VrSanNitAgeCcCia,VrSanNitAgeCcSub,VrSanNitAgeCcSubCia,VrSanNitVeh,VrSanNitVehCia,VrSanNitVehCc
,VrSanNitVehCcCia,VrSanVehCc,VrSanVehCcCia,VrSanVehCcSub,VrSanVehCcSubCia)
 VALUES (@pmtmEst,@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmIdCuenta,@pmDetalle,@pmVrDebito,@pmVrCredito,@pmIdTercero,@pmIdVehiculo,@pmIdCCosto,@pmIdSubCos,@pmVrBase,@pmTarifaBase,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmCodConce,@pmNitDoc,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence
,@pmCodCta,@pmNumCheque,@pmIntegrado,@pmTipoAplica,@pmConsolida,@pmCodCargo,@pmNitOtros,@pmCodSubgpo,@pmCiuOrigen,@pmCodAgncia,@pmVehPropio,@pmReferncia,@pmTipDocRef,@pmDocRef,@pmIdCiaRef,@pmVrSanCue,@pmVrSanCueCia,@pmVrSanNit,@pmVrSanNitCia,@pmVrSanVeh,@pmVrSanVehCia,@pmVrSanCc,@pmVrSanCcCia
,@pmVrSanCcSub,@pmVrSanCcSubCia,@pmVrSanNitCc,@pmVrSanNitCcCia,@pmVrSanNitCcSub,@pmVrSanNitCcSubCia,@pmVrSanNitAge,@pmVrSanNitAgeCia,@pmVrSanNitAgeCc,@pmVrSanNitAgeCcCia,@pmVrSanNitAgeCcSub,@pmVrSanNitAgeCcSubCia,@pmVrSanNitVeh,@pmVrSanNitVehCia,@pmVrSanNitVehCc,@pmVrSanNitVehCcCia,@pmVrSanVehCc,@pmVrSanVehCcCia,@pmVrSanVehCcSub,@pmVrSanVehCcSubCia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovCue_Acc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovCue_Acc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdSubCos VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null
,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null
 AS 
 IF @pmCueIni IS NULL
  INSERT INTO tm_MovCue (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef)
  SELECT  @pmtmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,D.IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef
  FROM Trn_ComDetalle AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsAccnista<>0 AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (Integrado=ISNULL(@pmIntegrado,0) or  Integrado=ISNULL(@pmIntegrado,1))
ELSE
  INSERT INTO tm_MovCue (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef)
  SELECT  @pmtmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,D.IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef
  FROM Trn_ComDetalle AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCuenta BETWEEN @pmCueIni AND @pmCueFin AND EsAccnista<>0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (Integrado=ISNULL(@pmIntegrado,0) or  Integrado=ISNULL(@pmIntegrado,1))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovCue_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_MovCue_Sel] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdSubCos VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null
,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null
 AS 
 IF @pmCueIni IS NULL
  INSERT INTO tm_MovCue (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef)
  SELECT  @pmtmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef
  FROM Trn_ComDetalle
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (Integrado=ISNULL(@pmIntegrado,0) or  Integrado=ISNULL(@pmIntegrado,1))
ELSE
  INSERT INTO tm_MovCue (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef)
  SELECT  @pmtmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef
  FROM Trn_ComDetalle
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCuenta BETWEEN @pmCueIni AND @pmCueFin
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (Integrado=ISNULL(@pmIntegrado,0) or  Integrado=ISNULL(@pmIntegrado,1))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovInvent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_MovInvent] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmIdCia CHAR(2),@pmtmTipDoc VARCHAR(3),@pmtmIdConcepto VARCHAR(4),@pmtmIdCliente VARCHAR(16),@pmtmCdAgencia VARCHAR(16)
,@pmtmIdVend VARCHAR(16),@pmtmCdLocal VARCHAR(8),@pmtmCdSubzona VARCHAR(4),@pmtmFecha SMALLDATETIME,@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmCostoEnt MONEY,@pmtmCostoSal MONEY,@pmtmValorEnt MONEY,@pmtmValorSal MONEY
,@pmtmDctosEnt MONEY,@pmtmDctosSal MONEY,@pmtmIvaEnt MONEY,@pmtmIvaSal MONEY,@pmtmOtrosImpEnt MONEY,@pmtmOtrosImpSal MONEY,@pmtmUnidVolumen DECIMAL(14,4),@pmtmEntradas2 DECIMAL(14,4),@pmtmSalidas2 DECIMAL(14,4),@pmtmCostoEnt2 MONEY
,@pmtmCostoSal2 MONEY,@pmtmValorEnt2 MONEY,@pmtmValorSal2 MONEY,@pmtmDctosEnt2 MONEY,@pmtmDctosSal2 MONEY,@pmtmIvaEnt2 MONEY,@pmtmIvaSal2 MONEY,@pmtmOtrosImpEnt2 MONEY,@pmtmOtrosImpSal2 MONEY,@pmtmUnidVolumen2 DECIMAL(14,4)
 AS 
 INSERT INTO tm_MovInvent (tmEst,tmItem,tmIdProducto,tmIdBodega,tmIdCia,tmTipDoc,tmIdConcepto,tmIdCliente,tmCdAgencia,tmIdVend,tmCdLocal,tmCdSubzona,tmFecha,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal,tmValorEnt,tmValorSal,tmDctosEnt,tmDctosSal,tmIvaEnt,tmIvaSal
,tmOtrosImpEnt,tmOtrosImpSal,tmUnidVolumen,tmEntradas2,tmSalidas2,tmCostoEnt2,tmCostoSal2,tmValorEnt2,tmValorSal2,tmDctosEnt2,tmDctosSal2,tmIvaEnt2,tmIvaSal2,tmOtrosImpEnt2,tmOtrosImpSal2,tmUnidVolumen2)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmIdCia,@pmtmTipDoc,@pmtmIdConcepto,@pmtmIdCliente,@pmtmCdAgencia,@pmtmIdVend,@pmtmCdLocal,@pmtmCdSubzona,@pmtmFecha,@pmtmEntradas,@pmtmSalidas,@pmtmCostoEnt,@pmtmCostoSal
,@pmtmValorEnt,@pmtmValorSal,@pmtmDctosEnt,@pmtmDctosSal,@pmtmIvaEnt,@pmtmIvaSal,@pmtmOtrosImpEnt,@pmtmOtrosImpSal,@pmtmUnidVolumen,@pmtmEntradas2,@pmtmSalidas2,@pmtmCostoEnt2,@pmtmCostoSal2,@pmtmValorEnt2,@pmtmValorSal2,@pmtmDctosEnt2
,@pmtmDctosSal2,@pmtmIvaEnt2,@pmtmIvaSal2,@pmtmOtrosImpEnt2,@pmtmOtrosImpSal2,@pmtmUnidVolumen2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovTanques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_MovTanques] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdTanque VARCHAR(4),@pmtmItem INT,@pmtmIdCia CHAR(2),@pmtmFecha SMALLDATETIME
,@pmtmSaldoAnt DECIMAL(14,4),@pmtmCostoAnt MONEY,@pmtmEntradas DECIMAL(14,4),@pmtmCostoEnt MONEY,@pmtmDevEnt DECIMAL(14,4),@pmtmCostoDve MONEY,@pmtmSalidas DECIMAL(14,4)
,@pmtmCostoSal MONEY,@pmtmDevSalidas DECIMAL(14,4),@pmtmCostoDvs MONEY,@pmtmFacturas DECIMAL(14,4),@pmtmCostoFac MONEY,@pmtmDevFact DECIMAL(14,4),@pmtmCostoDfc MONEY
,@pmtmAjusteSob DECIMAL(14,4),@pmtmCostoAjs MONEY,@pmtmAjusteFal DECIMAL(14,4),@pmtmCostoAjf MONEY,@pmtmPlanillas DECIMAL(14,4),@pmtmCostoPla MONEY,@pmtmDevPlanillas DECIMAL(14,4)
,@pmtmCostoDvp MONEY,@pmtmNotasCalib DECIMAL(14,4),@pmtmCostoNot MONEY,@pmtmTraslados DECIMAL(14,4),@pmtmCostoTra MONEY,@pmtmOtros DECIMAL(14,4),@pmtmCostoOtr MONEY
,@pmtmNuevoSaldo DECIMAL(14,4),@pmtmCostoNsal MONEY,@pmtmCantFisico DECIMAL(14,4),@pmtmCantAgua DECIMAL(14,4),@pmtmDiferencia DECIMAL(14,4),@pmtmSaldoAntCia DECIMAL(14,4)
,@pmtmCostoSanCia MONEY,@pmtmSaldoAntTan DECIMAL(14,4),@pmtmCostoSanTan MONEY,@pmtmSaldoAntPro DECIMAL(14,4),@pmtmCostoSanPro MONEY,@pmtmSaldoAntDia DECIMAL(14,4),@pmtmCostoAntDia MONEY
,@pmtmUndsEnt DECIMAL(16,4),@pmtmUndsDve DECIMAL(16,4),@pmtmUndsFac DECIMAL(16,4),@pmtmUndsDfc DECIMAL(16,4),@pmtmUndsSal DECIMAL(16,4),@pmtmUndsDvs DECIMAL(16,4),@pmtmUndsOtr DECIMAL(16,4),@pmtmUndsDot DECIMAL(16,4)
 AS 
 INSERT INTO tm_MovTanques (tmEst,tmIdProducto,tmIdTanque,tmItem,tmIdCia,tmFecha,tmSaldoAnt,tmCostoAnt,tmEntradas,tmCostoEnt,tmDevEnt,tmCostoDve,tmSalidas,tmCostoSal,tmDevSalidas,tmCostoDvs
,tmFacturas,tmCostoFac,tmDevFact,tmCostoDfc,tmAjusteSob,tmCostoAjs,tmAjusteFal,tmCostoAjf,tmPlanillas,tmCostoPla,tmDevPlanillas,tmCostoDvp,tmNotasCalib,tmCostoNot,tmTraslados,tmCostoTra,tmOtros
,tmCostoOtr,tmNuevoSaldo,tmCostoNsal,tmCantFisico,tmCantAgua,tmDiferencia,tmSaldoAntCia,tmCostoSanCia,tmSaldoAntTan,tmCostoSanTan,tmSaldoAntPro,tmCostoSanPro,tmSaldoAntDia,tmCostoAntDia
,tmUndsEnt,tmUndsDve,tmUndsFac,tmUndsDfc,tmUndsSal,tmUndsDvs,tmUndsOtr,tmUndsDot)
 VALUES (@pmtmEst,@pmtmIdProducto,@pmtmIdTanque,@pmtmItem,@pmtmIdCia,@pmtmFecha,@pmtmSaldoAnt,@pmtmCostoAnt,@pmtmEntradas,@pmtmCostoEnt,@pmtmDevEnt,@pmtmCostoDve
,@pmtmSalidas,@pmtmCostoSal,@pmtmDevSalidas,@pmtmCostoDvs,@pmtmFacturas,@pmtmCostoFac,@pmtmDevFact,@pmtmCostoDfc,@pmtmAjusteSob,@pmtmCostoAjs,@pmtmAjusteFal
,@pmtmCostoAjf,@pmtmPlanillas,@pmtmCostoPla,@pmtmDevPlanillas,@pmtmCostoDvp,@pmtmNotasCalib,@pmtmCostoNot,@pmtmTraslados,@pmtmCostoTra,@pmtmOtros,@pmtmCostoOtr
,@pmtmNuevoSaldo,@pmtmCostoNsal,@pmtmCantFisico,@pmtmCantAgua,@pmtmDiferencia,@pmtmSaldoAntCia,@pmtmCostoSanCia,@pmtmSaldoAntTan,@pmtmCostoSanTan,@pmtmSaldoAntPro,@pmtmCostoSanPro,@pmtmSaldoAntDia,@pmtmCostoAntDia
,@pmtmUndsEnt,@pmtmUndsDve,@pmtmUndsFac,@pmtmUndsDfc,@pmtmUndsSal,@pmtmUndsDvs,@pmtmUndsOtr,@pmtmUndsDot)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MovVentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_MovVentas] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmIdCia CHAR(2),@pmtmTipDoc VARCHAR(3),@pmtmIdConcepto VARCHAR(4),@pmtmIdCliente VARCHAR(16)
,@pmtmCdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmCdLocal VARCHAR(8),@pmtmCdSubzona VARCHAR(4),@pmtmFecha SMALLDATETIME,@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmCostoEnt MONEY
,@pmtmCostoSal MONEY,@pmtmValorEnt MONEY,@pmtmValorSal MONEY,@pmtmDctosEnt MONEY,@pmtmDctosSal MONEY,@pmtmIvaEnt MONEY,@pmtmIvaSal MONEY,@pmtmImpGlobalEnt MONEY,@pmtmImpGlobalSal MONEY
,@pmtmOtrosEnt MONEY,@pmtmOtrosSal MONEY,@pmtmUnidVolumen DECIMAL(14,4),@pmtmEntradas2 DECIMAL(14,4),@pmtmSalidas2 DECIMAL(14,4),@pmtmCostoEnt2 MONEY,@pmtmCostoSal2 MONEY,@pmtmValorEnt2 MONEY
,@pmtmValorSal2 MONEY,@pmtmDctosEnt2 MONEY,@pmtmDctosSal2 MONEY,@pmtmIvaEnt2 MONEY,@pmtmIvaSal2 MONEY,@pmtmImpGlobalEnt2 MONEY,@pmtmImpGlobalSal2 MONEY,@pmtmOtrosEnt2 MONEY,@pmtmOtrosSal2 MONEY,@pmtmUnidVolumen2 DECIMAL(14,4)
,@pmtmImpConEnt MONEY,@pmtmImpConSal MONEY,@pmtmImpConEnt2 MONEY,@pmtmImpConSal2 MONEY,@pmtmImpuBaEnt MONEY,@pmtmImpuBaSal MONEY,@pmtmImpuCupEnt MONEY,@pmtmImpuCupSal MONEY,@pmtmImpuBaEnt2 MONEY,@pmtmImpuBaSal2 MONEY,@pmtmImpuCupEnt2 MONEY,@pmtmImpuCupSal2 MONEY
 AS 
 INSERT INTO tm_MovVentas (tmEst,tmItem,tmIdProducto,tmIdBodega,tmIdCia,tmTipDoc,tmIdConcepto,tmIdCliente,tmCdAgencia,tmIdVend,tmCdLocal,tmCdSubzona,tmFecha,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal,tmValorEnt,tmValorSal,tmDctosEnt,tmDctosSal
,tmIvaEnt,tmIvaSal,tmImpGlobalEnt,tmImpGlobalSal,tmOtrosEnt,tmOtrosSal,tmUnidVolumen,tmEntradas2,tmSalidas2,tmCostoEnt2,tmCostoSal2,tmValorEnt2,tmValorSal2,tmDctosEnt2,tmDctosSal2,tmIvaEnt2,tmIvaSal2,tmImpGlobalEnt2,tmImpGlobalSal2,tmOtrosEnt2,tmOtrosSal2,tmUnidVolumen2
,tmImpConEnt,tmImpConSal,tmImpConEnt2,tmImpConSal2,tmImpuBaEnt,tmImpuBaSal,tmImpuCupEnt,tmImpuCupSal,tmImpuBaEnt2,tmImpuBaSal2,tmImpuCupEnt2,tmImpuCupSal2)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmIdCia,@pmtmTipDoc,@pmtmIdConcepto,@pmtmIdCliente,@pmtmCdAgencia,@pmtmIdVend,@pmtmCdLocal,@pmtmCdSubzona,@pmtmFecha,@pmtmEntradas,@pmtmSalidas,@pmtmCostoEnt,@pmtmCostoSal
,@pmtmValorEnt,@pmtmValorSal,@pmtmDctosEnt,@pmtmDctosSal,@pmtmIvaEnt,@pmtmIvaSal,@pmtmImpGlobalEnt,@pmtmImpGlobalSal,@pmtmOtrosEnt,@pmtmOtrosSal,@pmtmUnidVolumen,@pmtmEntradas2,@pmtmSalidas2,@pmtmCostoEnt2,@pmtmCostoSal2,@pmtmValorEnt2
,@pmtmValorSal2,@pmtmDctosEnt2,@pmtmDctosSal2,@pmtmIvaEnt2,@pmtmIvaSal2,@pmtmImpGlobalEnt2,@pmtmImpGlobalSal2,@pmtmOtrosEnt2,@pmtmOtrosSal2,@pmtmUnidVolumen2,@pmtmImpConEnt,@pmtmImpConSal,@pmtmImpConEnt2,@pmtmImpConSal2
,@pmtmImpuBaEnt,@pmtmImpuBaSal,@pmtmImpuCupEnt,@pmtmImpuCupSal,@pmtmImpuBaEnt2,@pmtmImpuBaSal2,@pmtmImpuCupEnt2,@pmtmImpuCupSal2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MttoDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_MttoDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmFecha SMALLDATETIME,@pmtmIdConc VARCHAR(4),@pmtmDescripcion VARCHAR(1000),@pmtmCantidad DECIMAL(14,4),@pmtmVrUnitario DECIMAL(16,6)
,@pmtmUndMed VARCHAR(50),@pmtmCdMtto VARCHAR(4),@pmtmIdEstado VARCHAR(4),@pmtmIdOperario VARCHAR(16),@pmtmNumVehic VARCHAR(10),@pmtmNumParte VARCHAR(20),@pmtmReqRep BIT,@pmtmReqMO BIT,@pmtmTipoServ VARCHAR(10)
,@pmtmCdCentro VARCHAR(4),@pmtmNitTercero VARCHAR(16)
 AS 
 INSERT INTO tm_MttoDetalle (tmNumero,tmItem,tmFecha,tmIdConc,tmDescripcion,tmCantidad,tmVrUnitario,tmUndMed,tmCdMtto,tmIdEstado,tmIdOperario,tmNumVehic,tmNumParte,tmReqRep,tmReqMO,tmTipoServ,tmCdCentro,tmNitTercero)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmFecha,@pmtmIdConc,@pmtmDescripcion,@pmtmCantidad,@pmtmVrUnitario,@pmtmUndMed,@pmtmCdMtto,@pmtmIdEstado,@pmtmIdOperario,@pmtmNumVehic,@pmtmNumParte,@pmtmReqRep,@pmtmReqMO,@pmtmTipoServ,@pmtmCdCentro,@pmtmNitTercero)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_MttoDetalle_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_MttoDetalle_Sel] @pmtmNumero VARCHAR(5),@pmTipOdt VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_MttoDetalle (tmNumero,tmItem,tmFecha,tmIdConc,tmDescripcion,tmCantidad,tmVrUnitario,tmUndMed,tmCdMtto,tmIdEstado,tmIdOperario,tmNumVehic,tmNumParte,tmReqRep,tmReqMO,tmTipoServ,tmCdCentro,tmNitTercero)
 SELECT @pmtmNumero,Item,FechaServ,IdConc,Descripcion,Cantidad,VrUnitario,UndMed,CdMtto,IdEstado,IdOperario,NumVehic,NumParte,Req_Rep,Req_MO,TipoServ,CodCentro,NitCenServ
 FROM Trn_MttoOrdenDet
 WHERE TipOdt=@pmTipOdt AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NiifCom] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16)
,@pmtmIdSubCos VARCHAR(16),@pmtmCodAgncia VARCHAR(16),@pmtmTipo VARCHAR(4),@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY
,@pmtmSaldoAnterior2 MONEY,@pmtmTotalDebitos2 MONEY,@pmtmTotalCreditos2 MONEY,@pmtmNuevoSaldo2 MONEY,@pmtmVrPresupto MONEY
 AS 
 INSERT INTO tm_NiifCom (tmEst,tmIdCuenta,tmIdCia,tmItem,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmNuevoSaldo,tmSaldoAnterior2,tmTotalDebitos2,tmTotalCreditos2,tmNuevoSaldo2,tmVrPresupto)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmIdCia,@pmtmItem,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmCodAgncia,@pmtmTipo,@pmtmSaldoAnterior,@pmtmTotalDebitos
,@pmtmTotalCreditos,@pmtmNuevoSaldo,@pmtmSaldoAnterior2,@pmtmTotalDebitos2,@pmtmTotalCreditos2,@pmtmNuevoSaldo2,@pmtmVrPresupto)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifGen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NiifGen] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2),@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY
,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY
 AS 
 INSERT INTO tm_NiifGen (tmEst,tmIdCuenta,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmIdCia,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmNuevoSaldo,@pmtmSalAnt2,@pmtmDebitos2,@pmtmCreditos2,@pmtmSaldo2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifGyp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NiifGyp] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT,@pmtmIdCia CHAR(2),@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmCodAgncia VARCHAR(16),@pmtmTipo VARCHAR(4),@pmtmTipoAfi INT
,@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY
 AS 
 INSERT INTO tm_NiifGyp (tmEst,tmIdCuenta,tmItem,tmIdCia,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmCodAgncia,tmTipo,tmTipoAfi,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2)
 VALUES (@pmtmEst,@pmtmIdCuenta,@pmtmItem,@pmtmIdCia,@pmtmIdTercero,@pmtmIdVehiculo,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmCodAgncia,@pmtmTipo,@pmtmTipoAfi,@pmtmSaldoAnterior,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmNuevoSaldo,@pmtmSalAnt2,@pmtmDebitos2,@pmtmCreditos2,@pmtmSaldo2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifLib]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NiifLib] @pmtmEst CHAR(2),@pmtmTipCom VARCHAR(3),@pmtmIdCuenta VARCHAR(16),@pmtmIdTercero VARCHAR(16),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdCia CHAR(2)
,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmSaldoAnterior MONEY,@pmtmSanNit MONEY,@pmtmSanNitcc MONEY,@pmtmSanNitCcSub MONEY
 AS 
 INSERT INTO tm_NiifLib (tmEst,tmTipCom,tmIdCuenta,tmIdTercero,tmIdCCosto,tmIdSubCos,tmIdCia,tmTotalDebitos,tmTotalCreditos,tmSaldoAnterior,tmSanNit,tmSanNitcc,tmSanNitCcSub)
 VALUES (@pmtmEst,@pmtmTipCom,@pmtmIdCuenta,@pmtmIdTercero,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdCia,@pmtmTotalDebitos,@pmtmTotalCreditos,@pmtmSaldoAnterior,@pmtmSanNit,@pmtmSanNitcc,@pmtmSanNitCcSub)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NiifMov] @pmtmEst CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmVrBase MONEY,@pmTarifaBase DECIMAL(14,4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmNitDoc VARCHAR(16),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4)
,@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmVehPropio INT,@pmReferncia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
,@pmVrSanCue MONEY,@pmVrSanCueCia MONEY,@pmVrSanNit MONEY,@pmVrSanNitCia MONEY,@pmVrSanVeh MONEY,@pmVrSanVehCia MONEY,@pmVrSanCc MONEY,@pmVrSanCcCia MONEY,@pmVrSanCcSub MONEY,@pmVrSanCcSubCia MONEY,@pmVrSanNitCc MONEY,@pmVrSanNitCcCia MONEY,@pmVrSanNitCcSub MONEY,@pmVrSanNitCcSubCia MONEY
,@pmVrSanNitAge MONEY,@pmVrSanNitAgeCia MONEY,@pmVrSanNitAgeCc MONEY,@pmVrSanNitAgeCcCia MONEY,@pmVrSanNitAgeCcSub MONEY,@pmVrSanNitAgeCcSubCia MONEY,@pmVrSanNitVeh MONEY,@pmVrSanNitVehCia MONEY,@pmVrSanNitVehCc MONEY,@pmVrSanNitVehCcCia MONEY,@pmVrSanVehCc MONEY,@pmVrSanVehCcCia MONEY,@pmVrSanVehCcSub MONEY,@pmVrSanVehCcSubCia MONEY,@pmCodCuentaCG VARCHAR(16)
 AS 
 INSERT INTO tm_NiifMov (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen
,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,VrSanCue,VrSanCueCia,VrSanNit,VrSanNitCia,VrSanVeh,VrSanVehCia,VrSanCc,VrSanCcCia,VrSanCcSub,VrSanCcSubCia,VrSanNitCc,VrSanNitCcCia,VrSanNitCcSub,VrSanNitCcSubCia,VrSanNitAge,VrSanNitAgeCia,VrSanNitAgeCc,VrSanNitAgeCcCia,VrSanNitAgeCcSub,VrSanNitAgeCcSubCia,VrSanNitVeh,VrSanNitVehCia,VrSanNitVehCc,VrSanNitVehCcCia,VrSanVehCc,VrSanVehCcCia,VrSanVehCcSub,VrSanVehCcSubCia,CodCuentaCG)
 VALUES (@pmtmEst,@pmTipCom,@pmComprobante,@pmIdCia,@pmItem,@pmFecha,@pmIdCuenta,@pmDetalle,@pmVrDebito,@pmVrCredito,@pmIdTercero,@pmIdVehiculo,@pmIdCCosto,@pmIdSubCos,@pmVrBase,@pmTarifaBase,@pmTipDoc,@pmDocumento,@pmIdCiaDoc,@pmCodConce,@pmNitDoc,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmCodCta,@pmNumCheque
,@pmIntegrado,@pmTipoAplica,@pmConsolida,@pmCodCargo,@pmNitOtros,@pmCodSubgpo,@pmCiuOrigen,@pmCodAgncia,@pmVehPropio,@pmReferncia,@pmTipDocRef,@pmDocRef,@pmIdCiaRef,@pmVrSanCue,@pmVrSanCueCia,@pmVrSanNit,@pmVrSanNitCia,@pmVrSanVeh,@pmVrSanVehCia,@pmVrSanCc,@pmVrSanCcCia,@pmVrSanCcSub,@pmVrSanCcSubCia,@pmVrSanNitCc,@pmVrSanNitCcCia,@pmVrSanNitCcSub,@pmVrSanNitCcSubCia,@pmVrSanNitAge,@pmVrSanNitAgeCia,@pmVrSanNitAgeCc,@pmVrSanNitAgeCcCia
,@pmVrSanNitAgeCcSub,@pmVrSanNitAgeCcSubCia,@pmVrSanNitVeh,@pmVrSanNitVehCia,@pmVrSanNitVehCc,@pmVrSanNitVehCcCia,@pmVrSanVehCc,@pmVrSanVehCcCia,@pmVrSanVehCcSub,@pmVrSanVehCcSubCia,@pmCodCuentaCG)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifMov_Acc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_NiifMov_Acc] @pmtmEst CHAR(2),@pmTipoNiif VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdSubCos VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null
,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null
 AS 
 IF @pmCueIni IS NULL
  INSERT INTO tm_NiifMov (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG)
  SELECT  @pmtmEst,D.TipCom,D.Comprobante,D.IdCia,D.Item,D.Fecha,D.IdCuenta,Detalle,VrDebito,VrCredito,D.IdTercero,D.IdVehiculo,D.IdCCosto,D.IdSubCos,VrBase,TarifaBase,D.TipDoc,D.Documento,D.IdCiaDoc,D.CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,FecVence,D.CodCta,D.NumCheque,D.Integrado,D.TipoAplica,D.Consolida,CodCargo,NitOtros,CodSubgpo,D.CiuOrigen,D.CodAgncia,D.VehPropio,D.Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
  WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif=@pmTipoNiif AND EsAccnista<>0 AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND D.CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND D.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (D.Integrado=ISNULL(@pmIntegrado,0) or  D.Integrado=ISNULL(@pmIntegrado,1))
ELSE
  INSERT INTO tm_NiifMov (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG)
  SELECT  @pmtmEst,D.TipCom,D.Comprobante,D.IdCia,Item,D.Fecha,D.IdCuenta,Detalle,D.VrDebito,D.VrCredito,D.IdTercero,D.IdVehiculo,D.IdCCosto,D.IdSubCos,D.VrBase,D.TarifaBase,D.TipDoc,D.Documento,D.IdCiaDoc,D.CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,D.FecVence,D.CodCta,D.NumCheque,D.Integrado,D.TipoAplica,D.Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,D.CodAgncia,D.VehPropio,D.Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
   INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif=@pmTipoNiif AND D.IdCuenta BETWEEN @pmCueIni AND @pmCueFin AND EsAccnista<>0
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND D.CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND D.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (D.Integrado=ISNULL(@pmIntegrado,0) or  D.Integrado=ISNULL(@pmIntegrado,1))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NiifMov_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_NiifMov_Sel] @pmtmEst CHAR(2),@pmTipoNiif VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdSubCos VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null
,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null
 AS 
 IF @pmCueIni IS NULL
  INSERT INTO tm_NiifMov (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG)
  SELECT  @pmtmEst,D.TipCom,D.Comprobante,D.IdCia,D.Item,D.Fecha,D.IdCuenta,Detalle,VrDebito,VrCredito,D.IdTercero,D.IdVehiculo,D.IdCCosto,D.IdSubCos,VrBase,TarifaBase,D.TipDoc,D.Documento,D.IdCiaDoc,D.CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,FecVence,D.CodCta,D.NumCheque,D.Integrado,D.TipoAplica,D.Consolida,CodCargo,NitOtros,CodSubgpo,D.CiuOrigen,D.CodAgncia,D.VehPropio,D.Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif=@pmTipoNiif AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND D.CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND D.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (D.Integrado=ISNULL(@pmIntegrado,0) or  D.Integrado=ISNULL(@pmIntegrado,1))
ELSE
  INSERT INTO tm_NiifMov (tmEst,TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,NitDoc,TipFac,Factura
 ,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG)
  SELECT  @pmtmEst,D.TipCom,D.Comprobante,D.IdCia,Item,D.Fecha,D.IdCuenta,Detalle,D.VrDebito,D.VrCredito,D.IdTercero,D.IdVehiculo,D.IdCCosto,D.IdSubCos,D.VrBase,D.TarifaBase,D.TipDoc,D.Documento,D.IdCiaDoc,D.CodConce,NitDoc,TipFac,Factura
  ,IdCiaFac,ItemFac,D.FecVence,D.CodCta,D.NumCheque,D.Integrado,D.TipoAplica,D.Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,D.CodAgncia,D.VehPropio,D.Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG
  FROM Trn_NiifDetalle AS D INNER JOIN Trn_NiifComp AS C ON D.TipCom=C.TipCom AND D.Comprobante=C.Comprobante AND D.IdCia=C.IdCia
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipoNiif=@pmTipoNiif AND D.IdCuenta BETWEEN @pmCueIni AND @pmCueFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND D.CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
 AND D.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND  (D.Integrado=ISNULL(@pmIntegrado,0) or  D.Integrado=ISNULL(@pmIntegrado,1))
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NivCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NivCue] @pmtmIdCuenta VARCHAR(16),@pmtmNivel1 VARCHAR(100)
,@pmtmNivel2 VARCHAR(100),@pmtmNivel4 VARCHAR(100),@pmtmNivel6 VARCHAR(100)
,@pmtmNivel9 VARCHAR(100),@pmtmNivel12 VARCHAR(100)
 AS 
 INSERT INTO tm_NivCue (tmIdCuenta,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12)
 VALUES (@pmtmIdCuenta,@pmtmNivel1,@pmtmNivel2,@pmtmNivel4,@pmtmNivel6,@pmtmNivel9,@pmtmNivel12)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NomHoras]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_NomHoras] @pmtmIdEmpleado VARCHAR(16),@pmtmNContrato INT,@pmtmHorDiurno DECIMAL(14,4),@pmtmHorNocturno DECIMAL(14,4),@pmtmHorExtraDia DECIMAL(14,4),@pmtmHorExtraNoc DECIMAL(14,4),@pmtmHorRecNoc DECIMAL(14,4),@pmtmHorDomDia DECIMAL(14,4)
,@pmtmHorDomNoc DECIMAL(14,4),@pmtmHorExtDom DECIMAL(14,4),@pmtmHorExtDomNoc DECIMAL(14,4),@pmtmVrHoras1 DECIMAL(14,4),@pmtmVrHoras2 DECIMAL(14,4),@pmtmVrHoras3 DECIMAL(14,4),@pmtmVrHoras4 DECIMAL(14,4),@pmtmIdArea VARCHAR(4),@pmtmIdDep VARCHAR(4)
,@pmtmIdInstala VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrATrans MONEY,@pmtmpVehiculo VARCHAR(10),@pmtmTipoLiquida CHAR(1)
 AS 
 INSERT INTO tm_NomHoras (tmIdEmpleado,tmNContrato,tmHorDiurno,tmHorNocturno,tmHorExtraDia,tmHorExtraNoc,tmHorRecNoc,tmHorDomDia,tmHorDomNoc,tmHorExtDom,tmHorExtDomNoc,tmVrHoras1,tmVrHoras2,tmVrHoras3,tmVrHoras4,tmIdArea,tmIdDep,tmIdInstala,tmIdCCosto,tmIdSubCos
,tmIdNom,tmVrSalario,tmVrATrans,tmpVehiculo,tmTipoLiquida)
 VALUES (@pmtmIdEmpleado,@pmtmNContrato,@pmtmHorDiurno,@pmtmHorNocturno,@pmtmHorExtraDia,@pmtmHorExtraNoc,@pmtmHorRecNoc,@pmtmHorDomDia,@pmtmHorDomNoc,@pmtmHorExtDom,@pmtmHorExtDomNoc,@pmtmVrHoras1,@pmtmVrHoras2,@pmtmVrHoras3
,@pmtmVrHoras4,@pmtmIdArea,@pmtmIdDep,@pmtmIdInstala,@pmtmIdCCosto,@pmtmIdSubCos,@pmtmIdNom,@pmtmVrSalario,@pmtmVrATrans,@pmtmpVehiculo,@pmtmTipoLiquida)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Nomina] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT,@pmtmIdConcepto VARCHAR(4),@pmtmClaseCon VARCHAR(10),@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(10,4),@pmtmCantDed DECIMAL(10,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY
,@pmtmUnidad VARCHAR(10),@pmtmClaseLiq VARCHAR(10),@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasCalc DECIMAL(10,4),@pmtmDiasNov DECIMAL(10,4),@pmtmCodFondo VARCHAR(8),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmOrigCargue VARCHAR(10),@pmtmVrBaseLiq MONEY,@pmtmNContto INT,@pmtmFecIni SMALLDATETIME
,@pmtmFecFin SMALLDATETIME,@pmtmIdPeriodo VARCHAR(8),@pmtmFecUltLiq SMALLDATETIME,@pmtmFecIniPmd SMALLDATETIME,@pmtmFecFinPmd SMALLDATETIME,@pmtmLogPmdio VARCHAR(1500),@pmtmVrPension MONEY,@pmtmVrSalud MONEY,@pmtmBasExceso MONEY,@pmtmNitTercero VARCHAR(16),@pmtmHoraInicial DATETIME,@pmtmHoraFinal DATETIME,@pmtmTipoInc VARCHAR(20),@pmtmVrIngNoSal MONEY
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin
,tmIdPeriodo,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmVrPension,tmVrSalud,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal)
 VALUES (@pmtmNumero,@pmtmIdEmpleado,@pmtmItem,@pmtmIdConcepto,@pmtmClaseCon,@pmtmDetalle,@pmtmCantDevg,@pmtmCantDed,@pmtmVrUnitario,@pmtmVrTotDevg,@pmtmVrTotDed,@pmtmUnidad,@pmtmClaseLiq,@pmtmVrOrigen,@pmtmTarifa
,@pmtmDiasCalc,@pmtmDiasNov,@pmtmCodFondo,@pmtmNPrestamo,@pmtmNCuota,@pmtmOrigCargue,@pmtmVrBaseLiq,@pmtmNContto,@pmtmFecIni,@pmtmFecFin,@pmtmIdPeriodo,@pmtmFecUltLiq,@pmtmFecIniPmd,@pmtmFecFinPmd,@pmtmLogPmdio,@pmtmVrPension,@pmtmVrSalud,@pmtmBasExceso,@pmtmNitTercero,@pmtmHoraInicial,@pmtmHoraFinal,@pmtmTipoInc,@pmtmVrIngNoSal)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina_Liq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Nomina_Liq]  @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmFecUltLiq
,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmVrPension,tmVrSalud,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal)
 SELECT @pmtmNumero,Item,D.IdEmpleado,D.IdConcepto,ClaseCon,Detalle
,'CntDev'= CASE  WHEN VrDeducido<=0 THEN Cantidad ELSE 0 END
,'CntDed'= CASE  WHEN VrDeducido>0 THEN Cantidad ELSE 0  END
,VrUnitario,VrDevngado,VrDeducido,Unidad,ClaseLiq,VrBase,D.Tarifa,DiasBase,D.DiasNoRem,CodFondo
,NPrestamo,NCuota,'LIQUDACION',VrBaseLiq,NContrato,FecDesde,FecHasta,IdPeriodo,FecUltLiq,FecIniPmd,FecFinPmd,LogPmdio,0,0,0,'',Null,Null,'',0
 FROM Trn_NomRetDet AS D INNER JOIN Trn_NomRet AS R ON D.IdEmpleado=R.IdEmpleado AND D.Numero=R.Numero
 INNER JOIN  NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 WHERE D.IdEmpleado=@pmIdEmpleado AND D.Numero=@pmNumero  AND  ClaseLiq NOT IN  ('APORTE','PROVISION')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Nomina_Sel] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmVrPension,tmVrSalud,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal)
 SELECT @pmtmNumero,Item,D.IdEmpleado,D.IdConcepto,ClaseCon,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad,ClaseLiq,VrOrigen,D.Tarifa,DiasCalc
,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,NContrato,FecInicial,FecFinal,D.IdPeriodo,0,0,VrBasExceso,NitTercero,HoraInicial,HoraFinal,TipoIncLab,VrIngNoSal
 FROM Trn_NomDetalle AS D INNER JOIN NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdPeriodo=@pmIdPeriodo AND D.KeyRegistro=@pmKeyRegistro 
 AND  ClaseLiq  IN  ('NOMINA','NOVEDAD')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Nomina_Vac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Nomina_Vac]  @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Nomina (tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo,tmVrPension,tmVrSalud,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal)
 SELECT @pmtmNumero,Item,IdEmpleado,D.IdConcepto,ClaseCon,Detalle,0,Cantidad,0,VrDevgado,VrDeducido,Unidad,'NOMINA',VrBaseLiq,D.Tarifa,0,0,D.CodFondo,NPrestamo,NCuota,'VAC',VrCertfcado
,0,getdate(),getdate(),IdPeriodo,VrPension,VrSalud,0,'',Null,Null,'',0
 FROM Trn_NomVacDet  AS D INNER JOIN NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paInstm_NomRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_NomRes] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmItem INT,@pmtmNContrato INT
,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmIdPeriodo VARCHAR(8),@pmtmIdArea VARCHAR(4),@pmtmIdDep VARCHAR(4),@pmtmIdInstala VARCHAR(4)
,@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrATrans MONEY,@pmtmpVehiculo VARCHAR(10)
,@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCiaCom CHAR(2),@pmtmObservacion VARCHAR(250),@pmtmEsRetiro BIT,@pmtmNLiqRet INT
,@pmtmTipoLiq CHAR(1),@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(14,4),@pmtmCantDed DECIMAL(14,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY
,@pmtmUnidad VARCHAR(10),@pmtmClaseLiq VARCHAR(10),@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(14,4),@pmtmDiasCalc DECIMAL(14,4),@pmtmDiasNov DECIMAL(14,4)
,@pmtmCodFondo VARCHAR(8),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmVrBaseLiq MONEY
 AS 
 INSERT INTO tm_NomRes (tmNumero,tmIdEmpleado,tmIdConcepto,tmItem,tmNContrato,tmFecInicial,tmFecFinal,tmIdPeriodo,tmIdArea,tmIdDep,tmIdInstala,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario
,tmVrATrans,tmpVehiculo,tmTipCom,tmComprobante,tmIdCiaCom,tmObservacion,tmEsRetiro,tmNLiqRet,tmTipoLiq,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad
,tmClaseLiq,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmVrBaseLiq)
 VALUES (@pmtmNumero,@pmtmIdEmpleado,@pmtmIdConcepto,@pmtmItem,@pmtmNContrato,@pmtmFecInicial,@pmtmFecFinal,@pmtmIdPeriodo,@pmtmIdArea,@pmtmIdDep,@pmtmIdInstala,@pmtmIdCCosto
,@pmtmIdSubCos,@pmtmIdNom,@pmtmVrSalario,@pmtmVrATrans,@pmtmpVehiculo,@pmtmTipCom,@pmtmComprobante,@pmtmIdCiaCom,@pmtmObservacion,@pmtmEsRetiro,@pmtmNLiqRet,@pmtmTipoLiq
,@pmtmDetalle,@pmtmCantDevg,@pmtmCantDed,@pmtmVrUnitario,@pmtmVrTotDevg,@pmtmVrTotDed,@pmtmUnidad,@pmtmClaseLiq,@pmtmVrOrigen,@pmtmTarifa,@pmtmDiasCalc,@pmtmDiasNov,@pmtmCodFondo,@pmtmNPrestamo,@pmtmNCuota,@pmtmVrBaseLiq)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_OccComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_OccComp] @pmtmTipDoc VARCHAR(3),@pmtmOCargue INT,@pmtmIdCia CHAR(2)
,@pmtmNumComp INT,@pmtmIdProducto VARCHAR(16),@pmtmCantidad DECIMAL(14,4),@pmtmDescProd VARCHAR(50)
,@pmtmComp2 INT,@pmtmIdProd2 VARCHAR(16),@pmtmDescProd2 VARCHAR(50),@pmtmCantidad2 DECIMAL(14,4)
,@pmtmComp3 INT,@pmtmIdProd3 VARCHAR(16),@pmtmDescProd3 VARCHAR(50),@pmtmCantidad3 DECIMAL(14,4)
,@pmtmComp4 INT,@pmtmIdProd4 VARCHAR(16),@pmtmDescProd4 VARCHAR(50),@pmtmCantidad4 DECIMAL(14,4)
,@pmtmComp5 INT,@pmtmIdProd5 VARCHAR(16),@pmtmDescProd5 VARCHAR(50),@pmtmCantidad5 DECIMAL(14,4)
 AS 
 INSERT INTO tm_OccComp (tmTipDoc,tmOCargue,tmIdCia,tmNumComp,tmIdProducto,tmCantidad,tmDescProd,tmComp2,tmIdProd2,tmDescProd2,tmCantidad2
,tmComp3,tmIdProd3,tmDescProd3,tmCantidad3,tmComp4,tmIdProd4,tmDescProd4,tmCantidad4,tmComp5,tmIdProd5,tmDescProd5,tmCantidad5)
 VALUES (@pmtmTipDoc,@pmtmOCargue,@pmtmIdCia,@pmtmNumComp,@pmtmIdProducto,@pmtmCantidad,@pmtmDescProd,@pmtmComp2,@pmtmIdProd2
,@pmtmDescProd2,@pmtmCantidad2,@pmtmComp3,@pmtmIdProd3,@pmtmDescProd3,@pmtmCantidad3,@pmtmComp4,@pmtmIdProd4,@pmtmDescProd4
,@pmtmCantidad4,@pmtmComp5,@pmtmIdProd5,@pmtmDescProd5,@pmtmCantidad5)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Pagos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Pagos] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdForma VARCHAR(4),@pmtmDetalle VARCHAR(150),@pmtmVrPagado MONEY,@pmtmVrCambio MONEY
,@pmtmEsCaja BIT,@pmtmIdBanco VARCHAR(4),@pmtmNitCliente VARCHAR(16),@pmtmCdAgencia VARCHAR(16),@pmtmNumForma VARCHAR(20),@pmtmFecForma SMALLDATETIME,@pmtmCtaForma VARCHAR(30)
,@pmtmBeneficiario VARCHAR(150),@pmtmReferncia1 VARCHAR(50),@pmtmReferncia2 VARCHAR(50),@pmtmCdLocal VARCHAR(8),@pmtmNumAutoriza VARCHAR(30),@pmtmVrDenom MONEY,@pmtmCantidad INT
,@pmtmTipDenom CHAR(1),@pmtmTipRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmItemDoc INT,@pmtmCdCta VARCHAR(4),@pmtmCliente VARCHAR(150)
,@pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmTipAplica VARCHAR(10),@pmtmConsCP BIT,@pmtmCodCueCons VARCHAR(16) 
 AS 
 INSERT INTO tm_Pagos (tmNumero,tmItem,tmIdForma,tmDetalle,tmVrPagado,tmVrCambio,tmEsCaja,tmIdBanco,tmNitCliente,tmCdAgencia,tmNumForma,tmFecForma,tmCtaForma,tmBeneficiario,tmReferncia1,tmReferncia2
,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantidad,tmTipDenom,tmTipRef,tmDocRef,tmIdCiaRef,tmItemDoc,tmCdCta,tmCliente,tmTipDoc,tmDocumento,tmIdCia,tmTipAplica,tmConsCP,tmCodCueCons)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdForma,@pmtmDetalle,@pmtmVrPagado,@pmtmVrCambio,@pmtmEsCaja,@pmtmIdBanco,@pmtmNitCliente,@pmtmCdAgencia,@pmtmNumForma,@pmtmFecForma
,@pmtmCtaForma,@pmtmBeneficiario,@pmtmReferncia1,@pmtmReferncia2,@pmtmCdLocal,@pmtmNumAutoriza,@pmtmVrDenom,@pmtmCantidad,@pmtmTipDenom,@pmtmTipRef,@pmtmDocRef,@pmtmIdCiaRef
,@pmtmItemDoc,@pmtmCdCta,@pmtmCliente,@pmtmTipDoc,@pmtmDocumento,@pmtmIdCia,@pmtmTipAplica,@pmtmConsCP,@pmtmCodCueCons)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Pagos_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Pagos_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_Pagos (tmNumero,tmItem,tmIdForma,tmDetalle,tmVrPagado,tmVrCambio,tmEsCaja,tmIdBanco,tmNitCliente,tmCdAgencia,tmNumForma,tmFecForma,tmCtaForma,tmBeneficiario,tmReferncia1,tmReferncia2
,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantidad,tmTipDenom,tmTipRef,tmDocRef,tmIdCiaRef,tmItemDoc,tmCdCta,tmCliente,tmTipDoc,tmDocumento,tmIdCia,tmConsCP,tmCodCueCons)
 SELECT @pmtmNumero,Item,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma,CtaForma,Beneficiario,Referncia1,Referncia2
,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta,SUBSTRING(RazonSocial,1,150) AS Client,TipDoc,Documento,IdCia,ConsCP,CodCueCons
 FROM Trn_Pagos AS P LEFT JOIN Terceros AS T ON P.NitCliente=T.IdTercero
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Plasueldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Plasueldos] @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30),@pmtmDias DECIMAL(10,4),@pmtmVrBasico MONEY,@pmtmVrAuxtrans MONEY,@pmtmVrHextras MONEY,@pmtmVrRecargos MONEY
,@pmtmVrComision MONEY,@pmtmVrIncapac MONEY,@pmtmVrLicencia MONEY,@pmtmVrVacacnes MONEY,@pmtmVrOtrosDev MONEY,@pmtmVrDctoPen MONEY,@pmtmVrDctoSal MONEY,@pmtmVrDctoFsp MONEY,@pmtmVrRetencion MONEY
,@pmtmVrPrestmos MONEY,@pmtmVrSanciones MONEY,@pmtmVrOtrosDed MONEY,@pmtmObserv VARCHAR(1000),@pmtmVrVacLiquida MONEY,@pmtmVrVacPen MONEY,@pmtmVrVacSal MONEY,@pmtmVrVacFsp MONEY,@pmtmVrVacOtr MONEY
 AS 
 INSERT INTO tm_Plasueldos (tmIdPeriodo,tmKeyRegistro,tmDias,tmVrBasico,tmVrAuxtrans,tmVrHextras,tmVrRecargos,tmVrComision,tmVrIncapac,tmVrLicencia,tmVrVacacnes,tmVrOtrosDev,tmVrDctoPen,tmVrDctoSal,tmVrDctoFsp,tmVrRetencion
,tmVrPrestmos,tmVrSanciones,tmVrOtrosDed,tmObserv,tmVrVacLiquida,tmVrVacPen,tmVrVacSal,tmVrVacFsp,tmVrVacOtr)
 VALUES (@pmtmIdPeriodo,@pmtmKeyRegistro,@pmtmDias,@pmtmVrBasico,@pmtmVrAuxtrans,@pmtmVrHextras,@pmtmVrRecargos,@pmtmVrComision,@pmtmVrIncapac,@pmtmVrLicencia,@pmtmVrVacacnes,@pmtmVrOtrosDev,@pmtmVrDctoPen,@pmtmVrDctoSal,@pmtmVrDctoFsp
,@pmtmVrRetencion,@pmtmVrPrestmos,@pmtmVrSanciones,@pmtmVrOtrosDed,@pmtmObserv,@pmtmVrVacLiquida,@pmtmVrVacPen,@pmtmVrVacSal,@pmtmVrVacFsp,@pmtmVrVacOtr)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_PreAbonos] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipDoc VARCHAR(3),@pmtmIdPrestamo INT,@pmtmIdCiaPre CHAR(2),@pmtmItemPre INT,@pmtmVrAbono MONEY,@pmtmVrBaseCms MONEY
,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmComision DECIMAL(14,4),@pmtmDetalle VARCHAR(150),@pmtmGalones DECIMAL(14,4),@pmtmTipoAplica INT,@pmtmCodTarCom VARCHAR(4),@pmtmTipRec VARCHAR(3),@pmtmRecibo INT
,@pmtmCiaRec CHAR(2),@pmtmItemRec INT,@pmtmFecPago SMALLDATETIME
 AS 
 INSERT INTO tm_PreAbonos (tmNumero,tmItem,tmTipDoc,tmIdPrestamo,tmIdCiaPre,tmItemPre,tmVrAbono,tmVrBaseCms,tmIdCliente,tmIdAgencia,tmIdVend,tmComision,tmDetalle,tmGalones,tmTipoAplica,tmCodTarCom,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipDoc,@pmtmIdPrestamo,@pmtmIdCiaPre,@pmtmItemPre,@pmtmVrAbono,@pmtmVrBaseCms,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdVend,@pmtmComision,@pmtmDetalle,@pmtmGalones,@pmtmTipoAplica
,@pmtmCodTarCom,@pmtmTipRec,@pmtmRecibo,@pmtmCiaRec,@pmtmItemRec,@pmtmFecPago)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreAbonos_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_PreAbonos_Sel]  @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_PreAbonos (tmNumero,tmItem,tmTipDoc,tmIdPrestamo,tmIdCiaPre,tmItemPre,tmVrAbono,tmVrBaseCms,tmIdCliente,tmIdAgencia
,tmIdVend,tmComision,tmDetalle,tmGalones,tmTipoAplica,tmCodTarCom,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago)
SELECT @pmtmNumero,Item,TipDoc,IdPrestamo,IdCiaPre,ItemPre,TotalAbono,VrBaseCms,IdCliente,IdAgencia
,IdVend,Comision,Detalle,CantGal,TipoAplica,'0',TipRec,Recibo,IdCia,Item,FecPago
 FROM Trn_FinAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCartera] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmNumCuota INT,@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrTotal MONEY,@pmVrAbonado MONEY,@pmVrSaldo MONEY
,@pmTipoTasa VARCHAR(10),@pmDTF_EA DECIMAL(16,8),@pmTasaNom DECIMAL(16,8),@pmSpread_TA DECIMAL(16,8),@pmTasaEfe DECIMAL(16,8),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmConcepto VARCHAR(10)
,@pmTipoCuota INT,@pmNumCausacion INT,@pmIdCiaCau CHAR(2),@pmDetalle VARCHAR(250),@pmIdConcepto VARCHAR(4),@pmFecUltPago SMALLDATETIME,@pmFecLiqMora SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmCtaForma VARCHAR(30)
,@pmBeneficiario VARCHAR(150),@pmRefCheque VARCHAR(50),@pmNumCheque VARCHAR(20),@pmCdBanco VARCHAR(4)
 AS 
 INSERT INTO tm_PreCartera (tmEst,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,VrSaldo,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,IdCliente,IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago
,FecLiqMora,FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 VALUES (@pmtmEst,@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmItem,@pmNumCuota,@pmFecha,@pmFechaVence,@pmVrTotal,@pmVrAbonado,@pmVrSaldo,@pmTipoTasa,@pmDTF_EA,@pmTasaNom,@pmSpread_TA,@pmTasaEfe,@pmIdCliente,@pmIdAgencia
,@pmIdVend,@pmConcepto,@pmTipoCuota,@pmNumCausacion,@pmIdCiaCau,@pmDetalle,@pmIdConcepto,@pmFecUltPago,@pmFecLiqMora,@pmFechaCrea,@pmCtaForma,@pmBeneficiario,@pmRefCheque,@pmNumCheque,@pmCdBanco)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Apo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCartera_Apo] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLinea VARCHAR(4)=Null
 AS 
 INSERT INTO tm_PreCartera (tmEst,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,VrSaldo,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,IdCliente,IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,C.NumCuota,C.Fecha,C.FechaVence,C.VrTotal,C.VrAbonado,C.VrTotal-C.VrAbonado,C.TipoTasa,C.DTF_EA,C.TasaNom,C.Spread_TA,C.TasaEfe
,C.IdCliente,C.IdAgencia,CL.IdVend,C.Concepto,C.TipoCuota,C.NumCausacion,C.IdCiaCau,C.Detalle,'0',C.FecUltPago,C.FecLiqMora,C.FechaCrea,'0','','','',CL.IdBanco
 FROM Trn_FinCuotas AS C LEFT JOIN TercCliePrestamo AS CL ON C.IdCliente=CL.IdClie AND C.IdAgencia=CL.IdAgencia
 WHERE C.TipDoc IN ('APO','CVN') AND VrTotal>VrAbonado AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND C.CodLinCred LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Fac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCartera_Fac] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLinea VARCHAR(4)=Null
 AS 
 INSERT INTO tm_PreCartera (tmEst,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,VrSaldo,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,IdCliente,IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,Item,NumCuota,C.Fecha,C.FechaVence,VrTotal,VrAbonado,VrTotal-VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,C.IdCliente,C.IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,'EFE','','FACTURAS','0','0'
 FROM Trn_FinCuotas AS C INNER JOIN  Trn_FinFactint  AS F ON C.TipDoc=F.TipDoc  AND C.IdPrestamo=F.Factura AND C.IdCia=F.IdCia
 WHERE C.TipDoc='FIF' AND VrTotal>VrAbonado AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND C.CodLinCred LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Ndb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCartera_Ndb] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLinea VARCHAR(4)=Null
 AS 
 INSERT INTO tm_PreCartera (tmEst,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,VrSaldo,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,IdCliente,IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,Item,NumCuota,C.Fecha,C.FechaVence,VrTotal,VrAbonado,VrTotal-VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,C.IdCliente,C.IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,CdForma,'',Referencia,NumCheque,CdBanco
 FROM Trn_FinCuotas  AS C INNER JOIN Trn_FinNotas AS N ON C.TipDoc=N.TipDoc  AND C.IdPrestamo=N.NumNota AND C.IdCia=N.IdCia
 WHERE C.TipDoc='ND2' AND VrTotal>VrAbonado AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')   AND N.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND C.CodLinCred LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Pre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCartera_Pre] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLinea VARCHAR(4)=Null
 AS 
 INSERT INTO tm_PreCartera (tmEst,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,VrSaldo,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,IdCliente,IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,Item,NumCuota,C.Fecha,FechaVence,VrTotal,VrAbonado,VrTotal-VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,C.IdCliente,C.IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,'0','','','','0'
 FROM Trn_FinCuotas  AS C  INNER JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc AND C.IdPrestamo=P.IdPrestamo AND C.IdCia=P.IdCia
 WHERE C.TipDoc='PR1' AND VrTotal>VrAbonado AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND P.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND C.CodLinCred LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCartera_Saf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCartera_Saf] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null
 AS 
 INSERT INTO tm_PreCartera (tmEst,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,VrSaldo,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,IdCliente,IdAgencia,IdVend,Concepto,TipoCuota,NumCausacion,IdCiaCau,Detalle,IdConcepto,FecUltPago,FecLiqMora,FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco)
 SELECT @pmtmEst,'SAF',MAX(Recibo),IdCia,0,0,getdate(),getdate(),SUM(VrAFavor-VrOtrosDb),SUM(VrAbono),SUM((VrAFavor-VrOtrosDb)-VrAbono),'0',0,0,0,0
,IdCliente,IdAgencia,IdVend,ISNULL(Concepto,'SAF'),0,0,'00','SALDO A FAVOR','0',NULL,NULL,getdate(),'0','','','','0'
 FROM Trn_FinAfavor
 WHERE  (VrAFavor-VrOtrosDb)>VrAbono AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')   AND IdVend LIKE ISNULL(@pmIdVend,'%')
 GROUP BY IdCia,IdCliente,IdAgencia,IdVend,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCompra_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PreCompra_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2) 
 AS 
 INSERT INTO tm_PreCompra (tmNumero,tmItem,tmFactura,tmFecha,tmFecVence,tmDiasPlazo,tmVrFactura,tmDescripcion)
 SELECT @pmtmNumero,Item,NumFactura,Fecha,FechaVence,DiasPlazo,VrFactura,''
 FROM Trn_FinFacturas
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreCuotas] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipDoc VARCHAR(3),@pmtmPrestamo INT,@pmtmIdCiaPre CHAR(2),@pmtmItemPre INT,@pmtmCuota INT,@pmtmConcepto VARCHAR(10)
,@pmtmFecCausa SMALLDATETIME,@pmtmFecVence SMALLDATETIME,@pmtmVrTotal MONEY,@pmtmTipoTasa VARCHAR(10),@pmtmDTF_EA DECIMAL(16,8),@pmtmTasaNom DECIMAL(16,8),@pmtmSpread DECIMAL(16,8)
,@pmtmTasaEfe DECIMAL(16,8),@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmEstado INT,@pmtmDetalle VARCHAR(250),@pmtmTotAbono MONEY,@pmtmLinCred VARCHAR(4)
,@pmtmFactura VARCHAR(20),@pmtmDiasLiq INT,@pmtmVrIntCorr MONEY,@pmtmVrSaldo MONEY,@pmtmUltCausac SMALLDATETIME,@pmtmVrAcumCap MONEY,@pmtmNitConv VARCHAR(16),@pmtmConvnio INT,@pmtmVrSeguro MONEY
,@pmtmVrProrroga MONEY,@pmtmVrCustodia MONEY,@pmtmTasaCustod DECIMAL(16,8),@pmtmTarifIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifRet DECIMAL(14,4),@pmtmVrRet MONEY,@pmtmPMInicio SMALLDATETIME,@pmtmPMFinal SMALLDATETIME,@pmtmPMDias INT,@pmtmPMValorInt MONEY
 AS 
 INSERT INTO tm_PreCuotas (tmNumero,tmItem,tmTipDoc,tmPrestamo,tmIdCiaPre,tmItemPre,tmCuota,tmConcepto,tmFecCausa,tmFecVence,tmVrTotal,tmTipoTasa,tmDTF_EA,tmTasaNom,tmSpread,tmTasaEfe,tmIdCliente
,tmIdAgencia,tmIdVend,tmEstado,tmDetalle,tmTotAbono,tmLinCred,tmFactura,tmDiasLiq,tmVrIntCorr,tmVrSaldo,tmUltCausac,tmVrAcumCap,tmNitConv,tmConvnio,tmVrSeguro,tmVrProrroga,tmVrCustodia,tmTasaCustod
,tmTarifIva,tmVrIva,tmTarifRet,tmVrRet,tmPMInicio,tmPMFinal,tmPMDias,tmPMValorInt)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipDoc,@pmtmPrestamo,@pmtmIdCiaPre,@pmtmItemPre,@pmtmCuota,@pmtmConcepto,@pmtmFecCausa,@pmtmFecVence,@pmtmVrTotal,@pmtmTipoTasa,@pmtmDTF_EA,@pmtmTasaNom
,@pmtmSpread,@pmtmTasaEfe,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdVend,@pmtmEstado,@pmtmDetalle,@pmtmTotAbono,@pmtmLinCred,@pmtmFactura,@pmtmDiasLiq,@pmtmVrIntCorr,@pmtmVrSaldo,@pmtmUltCausac
,@pmtmVrAcumCap,@pmtmNitConv,@pmtmConvnio,@pmtmVrSeguro,@pmtmVrProrroga,@pmtmVrCustodia,@pmtmTasaCustod,@pmtmTarifIva,@pmtmVrIva,@pmtmTarifRet,@pmtmVrRet,@pmtmPMInicio,@pmtmPMFinal,@pmtmPMDias,@pmtmPMValorInt)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCuotas_Aza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PreCuotas_Aza] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2) 
 AS 
 INSERT INTO tm_PreCuotas (tmNumero,tmItem,tmTipDoc,tmPrestamo,tmIdCiaPre,tmItemPre,tmCuota,tmConcepto,tmFecCausa,tmFecVence,tmVrTotal,tmTipoTasa
,tmDTF_EA,tmTasaNom,tmSpread,tmTasaEfe,tmIdCliente,tmIdAgencia,tmIdVend,tmEstado,tmDetalle,tmTotAbono,tmLinCred,tmFactura
,tmDiasLiq,tmVrIntCorr,tmVrSaldo,tmUltCausac,tmVrAcumCap,tmNitConv,tmConvnio,tmVrSeguro,tmVrProrroga,tmVrCustodia,tmTasaCustod,tmTarifIva,tmVrIva,tmTarifRet,tmVrRet,tmPMInicio,tmPMFinal,tmPMDias,tmPMValorInt)
SELECT @pmtmNumero,Item,TipDoc,IdPrestamo,IdCia,Item,Item,'CAPITAL',FecCausac,FecVence,VrCuota,'VARIABLE',TasaEfeMes,TasaEfeDia,0,TasaEfeMes
,'0','0','0',0,'',0,'0','',NumDias,VrInteres,VrSaldo,Null,VrCapital,'0',0,VrSeguroCuo,VrProrroga,VrCustodia,TasaCustodia,0,0,0,0,FecInicioPM,FecFinalPM,DiasInteresPM,VrInteresPM
 FROM Trn_FinAmtza
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreCuotas_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PreCuotas_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2) 
 AS 
 INSERT INTO tm_PreCuotas (tmNumero,tmItem,tmTipDoc,tmPrestamo,tmIdCiaPre,tmItemPre,tmCuota,tmConcepto,tmFecCausa,tmFecVence,tmVrTotal,tmTipoTasa
,tmDTF_EA,tmTasaNom,tmSpread,tmTasaEfe,tmIdCliente,tmIdAgencia,tmIdVend,tmEstado,tmDetalle,tmTotAbono,tmLinCred,tmFactura,tmDiasLiq,tmVrIntCorr
,tmVrSaldo,tmUltCausac,tmVrAcumCap,tmNitConv,tmConvnio,tmVrSeguro,tmVrProrroga,tmVrCustodia,tmTasaCustod,tmTarifIva,tmVrIva,tmTarifRet,tmVrRet,tmPMInicio,tmPMFinal,tmPMDias,tmPMValorInt)
SELECT @pmtmNumero,Item,TipDoc,IdPrestamo,IdCia,Item,NumCuota,Concepto,Fecha,FechaVence,VrTotal,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,IdCliente
,IdAgencia,'0',1,Detalle,VrAbonado,CodLinCred,NumFactura,DiasLiquida,VrInteresFact,0,FecUltCausac,VrAcumCapital,NitConvenio,Convenio,0,0,0,0
,TarifIvaInt,VrIvaInt,TarifRetInt,VrRetInt,Null,Null,0,0
 FROM Trn_FinCuotas
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExto] @pmtmEst CHAR(2),@pmtmTipDoc VARCHAR(3),@pmtmNumero INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmFecha SMALLDATETIME,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmCargos MONEY,@pmtmAbonos MONEY,@pmtmIdLinea VARCHAR(4),@pmtmConcepto VARCHAR(10),@pmtmDetalle VARCHAR(250),@pmtmReferencia VARCHAR(50),@pmtmCredito VARCHAR(10),@pmtmVrPrestamo MONEY,@pmtmVrCuota MONEY,@pmtmTotAbonos MONEY,@pmtmNCuota INT
,@pmtmIdVend VARCHAR(16),@pmtmTimeSys SMALLDATETIME,@pmtmFecVence SMALLDATETIME,@pmtmTipoAbono INT,@pmtmDTF_EA DECIMAL(16,8),@pmtmTasaNom DECIMAL(16,8),@pmtmTasaEfe DECIMAL(16,8),@pmtmTipRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCiaCom CHAR(2),@pmtmAnulado BIT,@pmtmNumDev INT,@pmtmFecDev SMALLDATETIME,@pmtmSanClie MONEY,@pmtmSanCia MONEY,@pmtmSanAgenc MONEY,@pmtmSanAgeCia MONEY
,@pmtmSanLinea MONEY,@pmtmSanLineaCia MONEY,@pmtmSanConc MONEY,@pmtmSanConcCia MONEY,@pmtmTipoRep INT
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 VALUES (@pmtmEst,@pmtmTipoRep,@pmtmTipDoc,@pmtmNumero,@pmtmIdCia,@pmtmItem,@pmtmFecha,@pmtmIdCliente,@pmtmIdAgencia,@pmtmCargos,@pmtmAbonos,@pmtmIdLinea,@pmtmConcepto,@pmtmDetalle,@pmtmReferencia,@pmtmCredito,@pmtmVrPrestamo,@pmtmVrCuota,@pmtmTotAbonos,@pmtmNCuota,@pmtmIdVend,@pmtmTimeSys,@pmtmFecVence,@pmtmTipoAbono,@pmtmDTF_EA,@pmtmTasaNom,@pmtmTasaEfe,@pmtmTipRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmTipCom,@pmtmComprobante,@pmtmIdCiaCom,@pmtmAnulado,@pmtmNumDev
,@pmtmFecDev,@pmtmSanClie,@pmtmSanCia,@pmtmSanAgenc,@pmtmSanAgeCia,@pmtmSanLinea,@pmtmSanLineaCia,@pmtmSanConc,@pmtmSanConcCia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoApf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoApf] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
--diferencia de cuotas no causadas prestamos refinanciados
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,P.TipDoc,P.IdPrestamo,P.IdCia,0,P.FecPrestamo,P.IdCliente,P.IdAgencia,0,P.VrPrestamo-ISNULL(AB.VrAbono,0),P.IdLinea,'CAPITAL','PRESTAMO REFINANCIADO-CAPITAL NO CAUSADO',P.NumCredito,P.TipoCredito,P.VrPrestamo,P.VrCuota
,P.PagosCapital,P.AcumCuotas,P.IdVend,P.TimeSys,P.FecCorte,-1,0,0,0,P.TipDoc,P.NumPrestRef,ISNULL(P.CiaPrestRef,''),P.TipCom,P.Comprobante,P.IdCiaCom,P.Anulado,P.NumDev,P.FecDev,0,0,0,0,0,0,0,0
FROM Trn_FinPrestamo AS P LEFT JOIN (SELECT A.TipDoc,A.IdPrestamo,A.IdCiaPre,SUM(A.TotalAbono) AS VrAbono
FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
WHERE C.Concepto='CAPITAL' AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GROUP BY A.TipDoc,A.IdPrestamo,A.IdCiaPre) AS AB ON P.TipDoc=AB.TipDoc AND P.IdPrestamo=AB.IdPrestamo AND P.IdCia=AB.IdCiaPre
WHERE ISNULL(P.FecCorte,P.FecPrestamo) BETWEEN @pmFechaIni AND @pmFechaFin AND P.CauAnticipado=0 AND P.Refinanciado=1 AND P.NumPrestRef>0
 AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoApr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoApr] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,A.TipRec,A.Recibo,A.IdCia,A.Item,A.Fecha,A.IdCliente,A.IdAgencia,0,A.TotalAbono,ISNULL(CodLinCred,'0001'),C.Concepto,A.Detalle,C.NumFactura,'PRESTAMO',A.TotalAbono,C.VrTotal
,C.VrAbonado,C.NumCuota,A.IdVend,A.TimeSys,A.FecPago,A.TipoAplica,DTF_EA,TasaNom,TasaEfe,A.TipDoc,A.IdPrestamo,A.IdCiaPre,'0',0,'00',0,0,Null
,0,0,0,0,0,0,0,0
 FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE A.TipRec='PR1' AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoCuo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoCuo] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,C.TipDoc,C.IdPrestamo,C.IdCia,0,MAX(C.Fecha),C.IdCliente,C.IdAgencia,SUM(C.VrTotal),0,P.IdLinea,'CAPITAL','','',P.TipoCredito,P.VrPrestamo,P.VrCuota
,SUM(C.VrAbonado),MAX(NumCuota),P.IdVend,P.TimeSys,MAX(C.FechaVence),0,MAX(DTF_EA),MAX(TasaNom),MAX(TasaEfe),'PR1',0,'',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinCuotas AS C INNER JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc  AND C.IdPrestamo=P.IdPrestamo  AND C.IdCia=P.IdCia
 WHERE C.TipDoc='PR1' AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.Concepto='CAPITAL' 
 AND NOT EXISTS (SELECT * FROM tm_PreExto WHERE tm_PreExto.tmTipDoc='PR1' AND tm_PreExto.tmNumero=C.IdPrestamo AND tm_PreExto.tmIdCia=C.IdCia
 AND tm_PreExto.tmConcepto='CAPITAL')
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  C.TipDoc,C.IdPrestamo,C.IdCia,C.IdCliente,C.IdAgencia,P.IdLinea,P.TipoCredito,P.VrPrestamo,P.VrCuota
,P.IdVend,P.TimeSys,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDfa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoDfa] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,D.TipDev,D.Devolucion,D.IdCia,0,D.Fecha,D.IdCliente,D.IdAgencia,0,D.VrNeto-ISNULL(RecTotAbonos,0),'0004','INTERESES',D.Observacion,'','FACTURAS',D.VrNeto,0
,ISNULL(RecTotAbonos,0),0,D.IdVend,D.TimeSys,D.Fecha,2,0,0,0,D.TipDoc,D.Factura,D.IdCiaDoc,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,D.FecDoc
,0,0,0,0,0,0,0,0
 FROM Trn_FinDevFac AS D INNER JOIN Trn_FinFactint AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 LEFT JOIN (SELECT TipRec,Recibo,IdCia,SUM(TotalAbono) AS RecTotAbonos FROM Trn_FinAbonos WHERE TipRec='DFI'
 GROUP BY TipRec,Recibo,IdCia) AS A ON D.TipDev=A.TipRec AND D.Devolucion=A.Recibo AND D.IdCia=A.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.VrNeto-ISNULL(RecTotAbonos,0))>0
 AND EXISTS (SELECT * FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=D.TipDoc AND Trn_FinCuotas.IdPrestamo=D.Factura AND Trn_FinCuotas.IdCia=D.IdCiaDoc) 
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDfi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoDfi] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,D.TipDev,D.Devolucion,D.IdCia,A.Item,D.Fecha,D.IdCliente,D.IdAgencia,0,A.TotalAbono,ISNULL(CodLinCred,'0001'),C.Concepto,A.Detalle,C.NumFactura,'FACTURAS',D.VrNeto,C.VrTotal
,C.VrAbonado,C.NumCuota,A.IdVend,D.TimeSys,A.FecPago,A.TipoAplica,DTF_EA,TasaNom,TasaEfe,A.TipDoc,A.IdPrestamo,A.IdCiaPre,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,FecDoc
,0,0,0,0,0,0,0,0
 FROM Trn_FinDevFac AS D INNER JOIN Trn_FinAbonos AS A ON D.TipDev=A.TipRec AND D.Devolucion=A.Recibo AND D.IdCia=A.IdCia
 INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDpa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoDpa] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,A.TipRec,A.Recibo,A.IdCia,A.Item,A.Fecha,A.IdCliente,A.IdAgencia,0,A.TotalAbono,ISNULL(C.CodLinCred,P.IdLinea),C.Concepto,A.Detalle,C.NumFactura,P.TipoCredito,P.VrPrestamo,P.VrCuota
,PagosCapital,AcumCuotas,P.IdVend,A.TimeSys,D.FecDoc,-1,0,0,0,A.TipDoc,A.IdPrestamo,A.IdCiaPre,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,Null
,0,0,0,0,0,0,0,0
 FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 INNER JOIN Trn_FinPrestamo AS P ON A.TipDoc=P.TipDoc AND A.IdPrestamo=P.IdPrestamo AND A.IdCiaPre=P.IdCia
 INNER JOIN Trn_FinDevPre AS D ON A.TipRec=D.TipDev AND A.Recibo=D.Devolucion AND A.IdCia=D.IdCia
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipRec='DP1' AND P.CauAnticipado=1
 AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoDpr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoDpr] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,TipDev,Devolucion,D.IdCia,0,D.Fecha,D.IdCliente,D.IdAgencia,0,D.VrPrestamo,P.IdLinea,'CAPITAL',D.Observacion,P.NumCredito,P.TipoCredito,D.VrPrestamo,P.VrCuota
,PagosCapital,AcumCuotas,P.IdVend,D.TimeSys,D.FecDoc,-1,0,0,0,D.TipDoc,D.IdPrestamo,D.IdCiaDoc,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,Null
,0,0,0,0,0,0,0,0
 FROM Trn_FinDevPre AS D INNER JOIN Trn_FinPrestamo AS P ON D.TipDoc=P.TipDoc AND D.IdPrestamo=P.IdPrestamo AND D.IdCiaDoc=P.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND P.CauAnticipado=0
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoFif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoFif] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,C.Fecha,C.IdCliente,C.IdAgencia,C.VrTotal,0,ISNULL(CodLinCred,'0001'),C.Concepto,C.Detalle,C.NumFactura,F.TipoFactInt,0,0
,C.VrAbonado,NumCuota,F.IdVend,F.TimeSys,C.FechaVence,TipoCuota,DTF_EA,TasaNom,TasaEfe,'PR1',NumPreMora,IdCiaCau,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinCuotas AS C INNER JOIN Trn_FinFactint AS F ON C.TipDoc=F.TipDoc AND C.IdPrestamo=F.Factura AND C.IdCia=F.IdCia
 WHERE C.TipDoc='FIF' AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoNca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoNca] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
--notas cred pendiente por aplicar
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,N.TipDoc,NumNota,N.IdCia,0,N.Fecha,N.IdCliente,N.IdAgencia,0,N.VrNeto-ISNULL(RecTotAbonos,0),'0001','INTERESES',N.Observacion,N.Referencia,N.Modalidad,N.VrNeto,0
,ISNULL(RecTotAbonos,0),0,N.IdVend,N.TimeSys,N.Fecha,2,0,0,0,TipDcm,Documento,IdCiaDcm,N.TipCom,N.Comprobante,N.IdCiaCom,N.Anulado,0,Null
,0,0,0,0,0,0,0,0
 FROM Trn_FinNotas AS N LEFT JOIN (SELECT TipRec,Recibo,IdCia,SUM(TotalAbono) AS RecTotAbonos FROM Trn_FinAbonos WHERE TipRec='NC2'
 GROUP BY TipRec,Recibo,IdCia) AS A ON N.TipDoc=A.TipRec AND N.NumNota=A.Recibo AND N.IdCia=A.IdCia
 WHERE N.TipDoc='NC2' AND N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (N.VrNeto-ISNULL(RecTotAbonos,0))>0
 AND N.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoNcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoNcr] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,N.TipDoc,N.NumNota,N.IdCia,A.Item,N.Fecha,N.IdCliente,N.IdAgencia,0,A.TotalAbono,ISNULL(CodLinCred,'0001'),C.Concepto,A.Detalle,N.Referencia,N.Modalidad,N.VrNeto,C.VrTotal
,C.VrAbonado,C.NumCuota,A.IdVend,N.TimeSys,A.FecPago,A.TipoAplica,DTF_EA,TasaNom,TasaEfe,A.TipDoc,A.IdPrestamo,A.IdCiaPre,N.TipCom,N.Comprobante,N.IdCiaCom,N.Anulado,0,Null
,0,0,0,0,0,0,0,0
 FROM Trn_FinNotas AS N INNER JOIN Trn_FinAbonos AS A ON N.TipDoc=A.TipRec AND N.NumNota=A.Recibo AND N.IdCia=A.IdCia
 INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE N.TipDoc='NC2' AND N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND N.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoNdb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoNdb] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,C.Fecha,C.IdCliente,C.IdAgencia,C.VrTotal,0,ISNULL(CodLinCred,'0001'),C.Concepto,C.Detalle,N.Referencia,N.Modalidad,0,0
,C.VrAbonado,NumCuota,N.IdVend,N.TimeSys,C.FechaVence,TipoCuota,DTF_EA,TasaNom,TasaEfe,'PR1',NumPreMora,IdCiaCau,TipCom,Comprobante,IdCiaCom,0,0,Null
,0,0,0,0,0,0,0,0
 FROM Trn_FinCuotas AS C INNER JOIN Trn_FinNotas AS N ON C.TipDoc=N.TipDoc AND C.IdPrestamo=N.NumNota AND C.IdCia=N.IdCia
 WHERE C.TipDoc='ND2' AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoOda]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoOda] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,D.TipDev,D.Devolucion,D.IdCia,0,D.Fecha,D.IdCliente,D.IdAgencia,D.VrNeto-(ISNULL(RecTotAbonos,0)*-1),0,'0001','CAPITAL',D.Observacion,D.Referencia,R.TipoCredito,D.VrNeto,0
,ISNULL(RecTotAbonos,0)*-1,0,D.IdVend,D.TimeSys,D.FecPago,2,0,0,0,D.TipDoc,D.Recibo,D.IdCiaDoc,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,D.FecDoc
,0,0,0,0,0,0,0,0
 FROM Trn_FinDevRec AS D INNER JOIN Trn_FinRecibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 LEFT JOIN (SELECT TipRec,Recibo,IdCia,SUM(TotalAbono) AS RecTotAbonos FROM Trn_FinAbonos WHERE TipRec='OD2'
 GROUP BY TipRec,Recibo,IdCia) AS A ON D.TipDev=A.TipRec AND D.Devolucion=A.Recibo AND D.IdCia=A.IdCia 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.VrNeto-(ISNULL(RecTotAbonos,0)*-1))>0
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoOdb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoOdb] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,D.TipDev,D.Devolucion,D.IdCia,A.Item,D.Fecha,D.IdCliente,D.IdAgencia,A.TotalAbono*-1,0,ISNULL(CodLinCred,'0001'),C.Concepto,A.Detalle,D.Referencia,R.TipoCredito,D.VrNeto,C.VrTotal
,C.VrAbonado,C.NumCuota,A.IdVend,D.TimeSys,A.FecPago,A.TipoAplica,DTF_EA,TasaNom,TasaEfe,A.TipDoc,A.IdPrestamo,A.IdCiaPre,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,FecDoc
,0,0,0,0,0,0,0,0
 FROM Trn_FinDevRec AS D INNER JOIN Trn_FinAbonos AS A ON D.TipDev=A.TipRec AND D.Devolucion=A.Recibo AND D.IdCia=A.IdCia
 INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 INNER JOIN Trn_FinRecibos AS R  ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoPra] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,P.FecPrestamo,C.IdCliente,C.IdAgencia,C.VrTotal,0,ISNULL(CodLinCred,P.IdLinea),C.Concepto,C.Detalle,C.NumFactura,ISNULL(P.TipoCredito,'PRESTAMO'),P.VrPrestamo,P.VrCuota
,C.VrAbonado,NumCuota,P.IdVend,P.TimeSys,C.FechaVence,C.TipoCuota,DTF_EA,TasaNom,TasaEfe,C.TipDoc,NumPrestRef,ISNULL(CiaPrestRef,''),TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinCuotas AS C INNER JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc  AND C.IdPrestamo=P.IdPrestamo  AND C.IdCia=P.IdCia
 WHERE C.TipDoc='PR1' AND P.FecPrestamo BETWEEN @pmFechaIni AND @pmFechaFin AND C.Concepto='CAPITAL' AND P.CauAnticipado=1
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoPre] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,TipDoc,IdPrestamo,IdCia,0,FecPrestamo,IdCliente,IdAgencia,VrPrestamo,0,IdLinea,'CAPITAL',Observacion,NumCredito,TipoCredito,VrPrestamo,VrCuota
,PagosCapital,AcumCuotas,IdVend,TimeSys,FecCorte,-1,0,0,0,TipDoc,NumPrestRef,ISNULL(CiaPrestRef,''),TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinPrestamo
 WHERE FecPrestamo BETWEEN @pmFechaIni AND @pmFechaFin AND CauAnticipado=0
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPri]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoPri] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,C.Fecha,C.IdCliente,C.IdAgencia,C.VrTotal,0,ISNULL(CodLinCred,P.IdLinea),C.Concepto,C.Detalle,C.NumFactura,ISNULL(P.TipoCredito,'PRESTAMO'),P.VrPrestamo,P.VrCuota
,C.VrAbonado,NumCuota,P.IdVend,P.TimeSys,C.FechaVence,C.TipoCuota,DTF_EA,TasaNom,TasaEfe,ISNULL(TipFacInt,''),NumFacInt,ISNULL(CdCiaFacInt,''),TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinCuotas AS C LEFT JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc  AND C.IdPrestamo=P.IdPrestamo  AND C.IdCia=P.IdCia
 WHERE C.TipDoc='PR1' AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.Concepto<>'CAPITAL' AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoPtmo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoPtmo] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
 SELECT @pmtmEst,@pmtmTipoRep,TipDoc,IdPrestamo,IdCia,0,FecPrestamo,IdCliente,IdAgencia,0,0,IdLinea,'CAPITAL',Observacion,NumCredito,TipoCredito,VrPrestamo,VrCuota
,PagosCapital,AcumCuotas,IdVend,TimeSys,FecCorte,-1,0,0,0,TipDoc,NumPrestRef,ISNULL(CiaPrestRef,''),TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinPrestamo
 WHERE FecPrestamo BETWEEN @pmFechaIni AND @pmFechaFin 
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoRca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoRca] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
--recibo de caja pendiente por aplicar
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,R.TipDoc,R.Recibo,R.IdCia,0,R.Fecha,R.IdCliente,R.IdAgencia,0,R.VrNeto-ISNULL(RecTotAbonos,0),CASE R.TipoCredito WHEN 'TC' THEN '0005' WHEN 'FACTURAS' THEN '0004' ELSE '0001' END
,CASE R.TipoCredito WHEN 'FACTURAS' THEN 'INTERESES' ELSE 'CAPITAL' END,R.Observacion,R.Referencia,R.TipoCredito,R.VrNeto,0
,ISNULL(RecTotAbonos,0),0,R.IdVend,R.TimeSys,R.FecPago,2,0,0,0,TipDcm,Documento,IdCiaDcm,R.TipCom,R.Comprobante,R.IdCiaCom,R.Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinRecibos AS R LEFT JOIN (SELECT TipRec,Recibo,IdCia,SUM(TotalAbono) AS RecTotAbonos FROM Trn_FinAbonos WHERE TipRec='RC2'
 GROUP BY TipRec,Recibo,IdCia) AS A ON R.TipDoc=A.TipRec AND R.Recibo=A.Recibo AND R.IdCia=A.IdCia
 WHERE R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (R.VrNeto-ISNULL(RecTotAbonos,0))>0
 AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreExtoRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreExtoRec] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreExto (tmEst,tmTipoRep,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmCargos,tmAbonos,tmIdLinea,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota
,tmTotAbonos,tmNCuota,tmIdVend,tmTimeSys,tmFecVence,tmTipoAbono,tmDTF_EA,tmTasaNom,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia)
SELECT @pmtmEst,@pmtmTipoRep,R.TipDoc,R.Recibo,R.IdCia,A.Item,R.Fecha,R.IdCliente,R.IdAgencia,0,A.TotalAbono,ISNULL(CodLinCred,'0001'),C.Concepto,A.Detalle,R.Referencia,R.TipoCredito,R.VrNeto,C.VrTotal
,C.VrAbonado,C.NumCuota,A.IdVend,R.TimeSys,A.FecPago,A.TipoAplica,DTF_EA,TasaNom,TasaEfe,A.TipDoc,A.IdPrestamo,A.IdCiaPre,R.TipCom,R.Comprobante,R.IdCiaCom,R.Anulado,NumDev,FecDev
,0,0,0,0,0,0,0,0
 FROM Trn_FinRecibos AS R INNER JOIN Trn_FinAbonos AS A ON R.TipDoc=A.TipRec AND R.Recibo=A.Recibo AND R.IdCia=A.IdCia
 INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreFactura] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdConc VARCHAR(4),@pmtmConcepto VARCHAR(250),@pmtmTipoConc VARCHAR(10),@pmtmCantidad DECIMAL(14,4),@pmtmVrUnitario MONEY
,@pmtmVrTotal MONEY,@pmtmTarifIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifRet DECIMAL(14,4),@pmtmVrRetfte MONEY,@pmtmTarifIca DECIMAL(14,4),@pmtmVrRetica MONEY,@pmtmnPrestamo INT,@pmtmCdCiaPrest CHAR(2)
,@pmtmFecIniLiq SMALLDATETIME,@pmtmFecFinLiq SMALLDATETIME,@pmtmCantDias INT,@pmtmCdTarifIva VARCHAR(4),@pmtmCdTarifRet VARCHAR(4),@pmtmCdTarifIca VARCHAR(4),@pmtmTarifDct DECIMAL(14,4),@pmtmVrDcto MONEY
,@pmtmCdTarifDct VARCHAR(4)
 AS 
 INSERT INTO tm_PreFactura (tmNumero,tmItem,tmIdConc,tmConcepto,tmTipoConc,tmCantidad,tmVrUnitario,tmVrTotal,tmTarifIva,tmVrIva,tmTarifRet,tmVrRetfte,tmTarifIca,tmVrRetica,tmTarifDct,tmVrDcto,tmnPrestamo,tmCdCiaPrest,tmFecIniLiq,tmFecFinLiq
,tmCantDias,tmCdTarifIva,tmCdTarifRet,tmCdTarifIca,tmCdTarifDct )
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdConc,@pmtmConcepto,@pmtmTipoConc,@pmtmCantidad,@pmtmVrUnitario,@pmtmVrTotal,@pmtmTarifIva,@pmtmVrIva,@pmtmTarifRet,@pmtmVrRetfte,@pmtmTarifIca,@pmtmVrRetica
,@pmtmTarifDct,@pmtmVrDcto,@pmtmnPrestamo,@pmtmCdCiaPrest,@pmtmFecIniLiq,@pmtmFecFinLiq,@pmtmCantDias,@pmtmCdTarifIva,@pmtmCdTarifRet,@pmtmCdTarifIca,@pmtmCdTarifDct)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreFactura_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreFactura_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_PreFactura (tmNumero,tmItem,tmIdConc,tmConcepto,tmTipoConc,tmCantidad,tmVrUnitario,tmVrTotal,tmTarifIva,tmVrIva,tmTarifRet,tmVrRetfte,tmTarifIca,tmVrRetica,tmTarifDct,tmVrDcto,tmnPrestamo,tmCdCiaPrest,tmFecIniLiq,tmFecFinLiq
,tmCantDias,tmCdTarifIva,tmCdTarifRet,tmCdTarifIca,tmCdTarifDct)
 SELECT @pmtmNumero,Item,IdConcepto,Concepto,TipoReg,Cantidad,VrUnitario,VrTotal,TarifIva,VrIva,TarifRet,VrRetfte,TarifIca,VrRetica,TarifDcto,VrDcto,nPrestamo,CdCiaPrest,FecIniLiq,FecFinLiq,CantDias,CdTarifIva,CdTarifRet,CdTarifIca,CdTarifDct
 FROM Trn_FinFactDet
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreIntMora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreIntMora] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipDoc VARCHAR(3),@pmtmPrestamo INT,@pmtmIdCia CHAR(2),@pmtmItemPre INT,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16)
,@pmtmFecVence SMALLDATETIME,@pmtmVrTotal MONEY,@pmtmVrAbonado MONEY,@pmtmFecUltLiq SMALLDATETIME,@pmtmFecIniLiq SMALLDATETIME,@pmtmFecFinLiq SMALLDATETIME,@pmtmDiasLiq INT,@pmtmDiasGracia INT,@pmtmBaseLiq MONEY
,@pmtmTasaEA DECIMAL(16,8),@pmtmTasaEM DECIMAL(16,8),@pmtmTasaDia DECIMAL(16,8),@pmtmVrLiquida MONEY,@pmtmTarifaIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmEstado INT,@pmtmDetalle VARCHAR(250),@pmtmLinCred VARCHAR(4),@pmtmNCuota INT
,@pmtmTarifaRet DECIMAL(14,4),@pmtmVrRetFte MONEY
 AS 
 INSERT INTO tm_PreIntMora (tmNumero,tmItem,tmTipDoc,tmPrestamo,tmIdCia,tmItemPre,tmIdCliente,tmIdAgencia,tmIdVend,tmFecVence,tmVrTotal,tmVrAbonado,tmFecUltLiq,tmFecIniLiq,tmFecFinLiq,tmDiasLiq,tmDiasGracia,tmBaseLiq,tmTasaEA,tmTasaEM,tmTasaDia
,tmVrLiquida,tmTarifaIva,tmVrIva,tmEstado,tmDetalle,tmLinCred,tmNCuota,tmTarifaRet,tmVrRetFte)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipDoc,@pmtmPrestamo,@pmtmIdCia,@pmtmItemPre,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdVend,@pmtmFecVence,@pmtmVrTotal,@pmtmVrAbonado,@pmtmFecUltLiq,@pmtmFecIniLiq,@pmtmFecFinLiq
,@pmtmDiasLiq,@pmtmDiasGracia,@pmtmBaseLiq,@pmtmTasaEA,@pmtmTasaEM,@pmtmTasaDia,@pmtmVrLiquida,@pmtmTarifaIva,@pmtmVrIva,@pmtmEstado,@pmtmDetalle,@pmtmLinCred,@pmtmNCuota,@pmtmTarifaRet,@pmtmVrRetFte)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreIntMora_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreIntMora_Sel] @pmtmNumero VARCHAR(5),@pmTipoProc VARCHAR(3),@pmNumProc INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_PreIntMora (tmNumero,tmItem,tmTipDoc,tmPrestamo,tmIdCia,tmItemPre,tmIdCliente,tmIdAgencia,tmIdVend,tmFecVence,tmVrTotal,tmVrAbonado
,tmFecUltLiq,tmFecIniLiq,tmFecFinLiq,tmDiasLiq,tmDiasGracia,tmBaseLiq,tmTasaEA,tmTasaEM,tmTasaDia,tmVrLiquida,tmTarifaIva,tmVrIva,tmEstado,tmDetalle,tmLinCred,tmNCuota,tmTarifaRet,tmVrRetFte)
 SELECT @pmtmNumero,Item,TipDoc,IdPrestamo,IdCiaPre,ItemPre,IdCliente,IdAgencia,IdVend,FecVence,VrTotal,VrAbonado,FecUltLiq,FecIniLiq,FecFinLiq,DiasLiquida
,DiasGracia,BaseLiquida,TasaEA,TasaEM,TasaDia,VrLiquida,TarifaIva,VrIvaInt,1,'',CdLinCred,NCuotaLiq,TarifaRet,VrRetFte
 FROM Trn_FinCauMora 
 WHERE TipoProc=@pmTipoProc AND  NumProc=@pmNumProc AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreMora] @pmtmTipDoc VARCHAR(3),@pmtmIdPrestamo INT,@pmtmIdCia CHAR(2)
,@pmtmVrCuota MONEY,@pmtmDescCuota VARCHAR(100),@pmtmVrMora MONEY,@pmtmDiasMora INT
 AS 
 INSERT INTO tm_PreMora (tmTipDoc,tmIdPrestamo,tmIdCia,tmVrCuota,tmDescCuota,tmVrMora,tmDiasMora)
 VALUES (@pmtmTipDoc,@pmtmIdPrestamo,@pmtmIdCia,@pmtmVrCuota,@pmtmDescCuota,@pmtmVrMora,@pmtmDiasMora)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreMovi] @pmtmEst CHAR(2),@pmtmTipDoc VARCHAR(3),@pmtmNumero INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmFecha SMALLDATETIME,@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmCargos MONEY,@pmtmAbonos MONEY,@pmtmNumCuota INT,@pmtmTimeSys SMALLDATETIME,@pmtmFecVence SMALLDATETIME,@pmtmCdConcepto VARCHAR(4),@pmtmConcepto VARCHAR(10)
,@pmtmDetalle VARCHAR(250),@pmtmReferencia VARCHAR(50),@pmtmTipoTasa VARCHAR(10),@pmtmDTF_EA DECIMAL(16,8),@pmtmTasaNom DECIMAL(16,8),@pmtmPuntos DECIMAL(16,8),@pmtmTasaEfe DECIMAL(16,8),@pmtmTipRef VARCHAR(3),@pmtmDocRef INT,@pmtmIdCiaRef CHAR(2),@pmtmNumForma VARCHAR(20),@pmtmCdBanco VARCHAR(4),@pmtmBeneficiario VARCHAR(150),@pmtmCdForma VARCHAR(4),@pmtmEnEfectivo BIT,@pmtmTotalAbono MONEY
,@pmtmVrAfavor MONEY,@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCiaCom CHAR(2),@pmtmAnulado BIT,@pmtmNumDev INT,@pmtmFecDev SMALLDATETIME,@pmtmIdUsuario VARCHAR(11),@pmtmSanClie MONEY,@pmtmSanClieCia MONEY,@pmtmSanAge MONEY,@pmtmSanAgeCia MONEY
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario
,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 VALUES (@pmtmEst,@pmtmTipDoc,@pmtmNumero,@pmtmIdCia,@pmtmItem,@pmtmFecha,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdVend,@pmtmCargos,@pmtmAbonos,@pmtmNumCuota,@pmtmTimeSys,@pmtmFecVence,@pmtmCdConcepto,@pmtmConcepto,@pmtmDetalle,@pmtmReferencia,@pmtmTipoTasa,@pmtmDTF_EA,@pmtmTasaNom,@pmtmPuntos,@pmtmTasaEfe,@pmtmTipRef,@pmtmDocRef,@pmtmIdCiaRef,@pmtmNumForma,@pmtmCdBanco
,@pmtmBeneficiario,@pmtmCdForma,@pmtmEnEfectivo,@pmtmTotalAbono,@pmtmVrAfavor,@pmtmTipCom,@pmtmComprobante,@pmtmIdCiaCom,@pmtmAnulado,@pmtmNumDev,@pmtmFecDev,@pmtmIdUsuario,@pmtmSanClie,@pmtmSanClieCia,@pmtmSanAge,@pmtmSanAgeCia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Abo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Abo]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,'INI',Recibo,A.IdCia,A.Item,A.Fecha,A.IdCliente,A.IdAgencia,IdVend,0,TotalAbono,NumCuota,TimeSys,FecPago,'0',Concepto,A.Detalle,'ABONO SALDO INICIAL'
,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,A.TipDoc,A.IdPrestamo,A.IdCiaPre,'0','0','','0',0,VrAbonado,0,'0',0,'00',0,0,Null,'ADMIN',0,0,0,0
 FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND  A.IdPrestamo=C.IdPrestamo AND  A.IdCiaPre=C.IdCia AND  A.ItemPre=C.Item
 WHERE A.TipRec='PR1' AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND A.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Apo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Apo]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,C.Fecha,C.IdCliente,C.IdAgencia,CL.IdVend,C.VrTotal,0,C.NumCuota,C.FechaCrea,C.FechaVence,'0',C.Concepto,C.Detalle,C.Concepto
,C.TipoTasa,C.DTF_EA,C.TasaNom,C.Spread_TA,C.TasaEfe,'CAU',C.NumCausacion,C.IdCiaCau,C.NumFactura,CL.IdBanco,'','0',0,C.VrAbonado,0,'0',0,'00'
,0,0,Null,CL.IdUsuario,0,0,0,0
 FROM Trn_FinCuotas AS C LEFT JOIN TercCliePrestamo AS CL ON C.IdCliente=CL.IdClie AND C.IdAgencia=CL.IdAgencia
 WHERE C.TipDoc IN ('APO','CVN') AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND C.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Dfa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Dfa]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,0,D.Fecha,D.IdCliente,D.IdAgencia,D.IdVend,0,D.VrNeto,0,D.TimeSys,D.Fecha,D.IdConcepto,'',D.Observacion,'','0',0,0,0,0,D.TipDoc,D.Factura,D.IdCiaDoc
,'','0','','',0,0,0,D.TipCom,D.Comprobante,D.IdCiaCom,0,0,D.Fecha,D.IdUsuario,0,0,0,0
 FROM Trn_FinDevFac AS D INNER JOIN Trn_FinFactint AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 WHERE D.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin 
 AND EXISTS (SELECT * FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=D.TipDoc AND Trn_FinCuotas.IdPrestamo=D.Factura AND Trn_FinCuotas.IdCia=D.IdCiaDoc) 
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND D.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Fac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Fac]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,Item,C.Fecha,C.IdCliente,C.IdAgencia,IdVend,VrTotal,0,NumCuota,TimeSys,C.FechaVence,IdConcepto,Concepto,Detalle,'FACTURAS'
,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,'CAU',NumCausacion,IdCiaCau,'0','0','0','0',0,VrAbonado,0,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,IdUsuario,0,0,0,0
 FROM Trn_FinCuotas AS C INNER JOIN Trn_FinFactint  AS F ON C.TipDoc=F.TipDoc  AND C.IdPrestamo=F.Factura  AND C.IdCia=F.IdCia
 WHERE C.TipDoc='FIF' AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND C.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Ndb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Ndb]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDoc,NumNota,IdCia,0,Fecha,IdCliente,IdAgencia,IdVend,CASE TipDoc WHEN 'ND2' THEN VrNeto ELSE 0 END,CASE TipDoc WHEN 'NC2' THEN VrNeto ELSE 0 END,0,TimeSys,FechaVence,IdConcepto
,Modalidad,Observacion,Referencia,'0',0,0,0,0,TipDcm,Documento,IdCiaDcm,NumCheque,CdBanco,'',CdForma,0,0,VrAnticipo,TipCom,Comprobante,IdCiaCom,Anulado,0,Null,IdUsuario,0,0,0,0
 FROM Trn_FinNotas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente  LIKE ISNULL(@pmIdCliente ,'%') AND  IdAgencia  LIKE ISNULL(@pmIdAgencia ,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Odb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Odb]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDev,Devolucion,IdCia,0,Fecha,IdCliente,IdAgencia,IdVend,VrNeto,0,0,TimeSys,FecDoc,IdConcepto,ModdDev,Observacion,Referencia,'0',0,0,0,0,TipDoc,Recibo,IdCiaDoc,'0','0','','0',EnEfectivo,0,VrAnticipo
,TipCom,Comprobante,IdCiaCom,0,0,Null,IdUsuario,0,0,0,0
 FROM Trn_FinDevRec
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente  LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Pre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Pre]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,C.TipDoc,C.IdPrestamo,C.IdCia,Item,CASE WHEN C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END
,C.IdCliente,C.IdAgencia,IdVend,VrTotal,0,NumCuota,TimeSys,FechaVence,IdConcepto,Concepto,Detalle,Causacion
,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,'CAU',NumCausacion,IdCiaCau,NumCredito,'0',TipoGarantia,'0',0,VrAbonado,0,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,IdUsuario,0,0,0,0
 FROM Trn_FinCuotas AS C INNER JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc  AND C.IdPrestamo=P.IdPrestamo  AND C.IdCia=P.IdCia
 WHERE C.TipDoc='PR1' AND CASE WHEN C.Concepto='CAPITAL' AND ISNULL(P.CauAnticipado,0)=1 THEN P.FecPrestamo ELSE C.Fecha END BETWEEN @pmFechaIni AND @pmFechaFin 
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND C.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreMovi_Rec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_PreMovi_Rec]  @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 INSERT INTO tm_PreMovi (tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmFecha,tmIdCliente,tmIdAgencia,tmIdVend,tmCargos,tmAbonos,tmNumCuota,tmTimeSys,tmFecVence,tmCdConcepto,tmConcepto,tmDetalle,tmReferencia
,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmTipRef,tmDocRef,tmIdCiaRef,tmNumForma,tmCdBanco,tmBeneficiario,tmCdForma,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia)
 SELECT @pmtmEst,TipDoc,Recibo,IdCia,0,Fecha,IdCliente,IdAgencia,IdVend,0,VrNeto,0,TimeSys,FecPago,IdConcepto,pVehiculo,Observacion,Referencia,'0',0,0,0,0,TipDcm,Documento,IdCiaDcm
,NumForma,CdBanco,'',CdForma,EnEfectivo,0,VrAnticipo,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,IdUsuario,0,0,0,0
 FROM Trn_FinRecibos
  WHERE Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PresPagos_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_PresPagos_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2) 
 AS 
 INSERT INTO tm_PresPagos (tmNumero,tmItem,tmNumForma,tmFecha,tmFecPago,tmVrCuota,tmCdBanco,tmCtaCheque,tmDetalle,tmTarifSeguro,tmVrSeguro)
 SELECT @pmtmNumero,Item,Numero,Fecha,FecPago,VrCuota,CdBanco,CtaCheque,Detalle,TarifSeguro,TotalSeguro
 FROM Trn_FinPagos
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreVence]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreVence] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmNumCuota INT,@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME
,@pmNumDias INT,@pmVrCuota MONEY,@pmVrCapital MONEY,@pmVrInteres MONEY,@pmVrIntMora MONEY,@pmVrAbonoCap MONEY,@pmVrAbonoInt MONEY,@pmVrSaldo MONEY
,@pmTasaEfeMes DECIMAL(16,8),@pmTasaEfeDia DECIMAL(16,8),@pmTipoCuota VARCHAR(10)
 AS 
 INSERT INTO tm_PreVence (tmEst,TipDoc,IdPrestamo,IdCia,NumCuota,Fecha,FechaVence,NumDias,VrCuota,VrCapital,VrInteres,VrIntMora,VrAbonoCap,VrAbonoInt,VrSaldo,TasaEfeMes,TasaEfeDia,TipoCuota)
 VALUES (@pmtmEst,@pmTipDoc,@pmIdPrestamo,@pmIdCia,@pmNumCuota,@pmFecha,@pmFechaVence,@pmNumDias,@pmVrCuota,@pmVrCapital,@pmVrInteres,@pmVrIntMora
,@pmVrAbonoCap,@pmVrAbonoInt,@pmVrSaldo,@pmTasaEfeMes,@pmTasaEfeDia,@pmTipoCuota)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_PreVenceAmza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_PreVenceAmza] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_PreVence (tmEst,TipDoc,IdPrestamo,IdCia,NumCuota,Fecha,FechaVence,NumDias,VrCuota,VrCapital,VrInteres,VrIntMora
,VrAbonoCap,VrAbonoInt,VrSaldo,TasaEfeMes,TasaEfeDia,TipoCuota)
 SELECT @pmtmEst,TipDoc,IdPrestamo,IdCia,Item,FecCausac,FecVence,NumDias,VrCuota,VrCapital,VrInteres,0
,0,0,VrSaldo,TasaEfeMes,TasaEfeDia,'PORCAUSAR'
 FROM Trn_FinAmtza 
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_RecAplica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_RecAplica] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipoDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCiaDoc CHAR(2),@pmtmItemDoc INT,@pmtmIdClase VARCHAR(4),@pmtmIdCargo VARCHAR(4),@pmtmValor MONEY,@pmtmIdVehiculo VARCHAR(10),@pmtmVehPropio BIT,@pmtmIdConductor VARCHAR(16),@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmReferencia VARCHAR(20),@pmtmFactura VARCHAR(15),@pmtmDetalle VARCHAR(100),@pmtmComision DECIMAL(14,4),@pmtmDescuento MONEY,@pmtmConductor VARCHAR(100),@pmtmTipRec VARCHAR(3),@pmtmRecibo INT,@pmtmCiaRec CHAR(2),@pmtmFecRec SMALLDATETIME,@pmtmItemRec INT,@pmtmAplAnt BIT
 AS 
 INSERT INTO tm_RecAplica (tmNumero,tmItem,tmTipoDoc,tmDocumento,tmIdCiaDoc,tmItemDoc,tmIdClase,tmIdCargo,tmValor,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdCliente,tmIdAgencia,tmReferencia,tmFactura,tmDetalle,tmComision,tmDescuento,tmConductor,tmTipRec,tmRecibo,tmCiaRec,tmFecRec,tmItemRec,tmAplAnt)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipoDoc,@pmtmDocumento,@pmtmIdCiaDoc,@pmtmItemDoc,@pmtmIdClase,@pmtmIdCargo,@pmtmValor,@pmtmIdVehiculo,@pmtmVehPropio,@pmtmIdConductor,@pmtmIdCliente,@pmtmIdAgencia,@pmtmReferencia,@pmtmFactura,@pmtmDetalle,@pmtmComision,@pmtmDescuento,@pmtmConductor,@pmtmTipRec,@pmtmRecibo,@pmtmCiaRec,@pmtmFecRec,@pmtmItemRec,@pmtmAplAnt)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ReqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_ReqDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmCdProducto VARCHAR(16),@pmtmDescripcion VARCHAR(250)
,@pmtmIdSubgrupo VARCHAR(8),@pmtmCdBodega VARCHAR(4),@pmtmCantidad DECIMAL(14,4),@pmtmIdUnd VARCHAR(4),@pmtmVrUnitario MONEY
,@pmtmTipOrd VARCHAR(3),@pmtmNumOrden INT,@pmtmIdCiaOrd CHAR(2),@pmtmTipSal VARCHAR(3),@pmtmNSalida INT,@pmtmIdCiaSal CHAR(2),@pmtmFechaSal SMALLDATETIME
,@pmtmCantSalida DECIMAL(14,4),@pmtmIdOperario VARCHAR(16),@pmtmCdCenServ VARCHAR(4),@pmtmNitTercero VARCHAR(16),@pmtmNumVehic VARCHAR(10),@pmtmNumParte VARCHAR(20)
,@pmtmEstado INT,@pmtmObservacion VARCHAR(1000),@pmtmCodConc VARCHAR(4),@pmtmVrPrecio MONEY,@pmtmCodCenCto VARCHAR(16),@pmtmCodSubCto VARCHAR(16),@pmtmCantOrden DECIMAL(14,4)
 AS 
 INSERT INTO tm_ReqDetalle (tmNumero,tmItem,tmCdProducto,tmDescripcion,tmIdSubgrupo,tmCdBodega,tmCantidad,tmIdUnd,tmVrUnitario,tmTipOrd,tmNumOrden,tmIdCiaOrd
,tmTipSal,tmNSalida,tmIdCiaSal,tmFechaSal,tmCantSalida,tmIdOperario,tmCdCenServ,tmNitTercero,tmNumVehic,tmNumParte,tmEstado,tmObservacion,tmCodConc,tmVrPrecio,tmCodCenCto,tmCodSubCto,tmCantOrden)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmCdProducto,@pmtmDescripcion,@pmtmIdSubgrupo,@pmtmCdBodega,@pmtmCantidad,@pmtmIdUnd,@pmtmVrUnitario
,@pmtmTipOrd,@pmtmNumOrden,@pmtmIdCiaOrd,@pmtmTipSal,@pmtmNSalida,@pmtmIdCiaSal,@pmtmFechaSal,@pmtmCantSalida,@pmtmIdOperario,@pmtmCdCenServ
,@pmtmNitTercero,@pmtmNumVehic,@pmtmNumParte,@pmtmEstado,@pmtmObservacion,@pmtmCodConc,@pmtmVrPrecio,@pmtmCodCenCto,@pmtmCodSubCto,@pmtmCantOrden)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ReqDetalle_Mtto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_ReqDetalle_Mtto] @pmTipReq VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_ReqDetalle (tmNumero,tmItem,tmCdProducto,tmDescripcion,tmIdSubgrupo,tmCdBodega,tmCantidad
,tmIdUnd,tmVrUnitario,tmTipOrd,tmNumOrden,tmIdCiaOrd,tmTipSal,tmNSalida,tmIdCiaSal,tmFechaSal
,tmCantSalida,tmIdOperario,tmCdCenServ,tmNitTercero,tmNumVehic,tmNumParte,tmEstado,tmObservacion,tmCodConc,tmVrPrecio,tmCodCenCto,tmCodSubCto,tmCantOrden)
 SELECT  @pmtmNumero,Item,R.IdProducto,R.Descripcion,ISNULL(P.IdSubgrupo,'0'),R.CdBodega,R.Cantidad,R.IdUnd,CAST (VrUnitario AS MONEY),TipOdt,NumOrden,IdCiaOdt
,TipSal,NumSalida,IdCiaSal,Null,CantSalida,IdOperario,CdCenServ,NitTercero,NumVehic,NumParte,R.EstadoReq,R.Observacion,R.CdConcServ,VrPrecioUnd,'','',0
 FROM Trn_MttoOrdenReq AS R LEFT JOIN ProdMcias AS P ON R.IdProducto=P.IdProducto
 WHERE TipReq=@pmTipReq AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ReqDetalle_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_ReqDetalle_Sel] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_ReqDetalle (tmNumero,tmItem,tmCdProducto,tmDescripcion,tmIdSubgrupo,tmCdBodega,tmCantidad
,tmIdUnd,tmVrUnitario,tmTipOrd,tmNumOrden,tmIdCiaOrd,tmTipSal,tmNSalida,tmIdCiaSal,tmFechaSal
,tmCantSalida,tmIdOperario,tmCdCenServ,tmNitTercero,tmNumVehic,tmNumParte,tmEstado,tmObservacion,tmCodConc,tmVrPrecio,tmCodCenCto,tmCodSubCto,tmCantOrden)
 SELECT  @pmtmNumero,Item,CdProducto,Descripcion,IdSubgrupo,CdBodega,Cantidad,IdUnd,VrUnitario,TipOrd,NumOrden,IdCiaOrd,TipSal,NSalida,IdCiaSal,FechaSal
,(CantSalida-ISNULL(CantDevSal,0)),'0','','0',PlacaVehDet,'',0,Referencia,'',0,CodCCtoDet,CodSCtoDet,Cant_Orden
 FROM Trn_ReqDetalle
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Saldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Saldos] @pmtmEst CHAR(2),@pmtmIdCia CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdTercero VARCHAR(16),@pmtmCdSubgrupo VARCHAR(8),@pmtmSanCue MONEY
,@pmtmDebitos MONEY,@pmtmCreditos MONEY,@pmtmCostoAnt MONEY,@pmtmCostoEnt MONEY,@pmtmCostoSal MONEY,@pmtmSaldoAnt DECIMAL(14,4),@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4)
 AS 
 INSERT INTO tm_Saldos (tmEst,tmIdCia,tmIdCuenta,tmIdTercero,tmCdSubgrupo,tmSanCue,tmDebitos,tmCreditos,tmCostoAnt,tmCostoEnt,tmCostoSal,tmSaldoAnt,tmEntradas,tmSalidas)
 VALUES (@pmtmEst,@pmtmIdCia,@pmtmIdCuenta,@pmtmIdTercero,@pmtmCdSubgrupo,@pmtmSanCue,@pmtmDebitos,@pmtmCreditos,@pmtmCostoAnt,@pmtmCostoEnt,@pmtmCostoSal,@pmtmSaldoAnt,@pmtmEntradas,@pmtmSalidas)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Saldos_Kar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[paInstm_Saldos_Kar] @pmtmEst CHAR(2),@pmDetCia BIT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmTipoRef VARCHAR(10)=Null,@pmIdSubgrupo VARCHAR(8)=Null
 AS 
 IF @pmDetCia=1 
 BEGIN 
  INSERT INTO tm_Saldos (tmEst,tmIdCia,tmIdCuenta,tmIdTercero,tmCdSubgrupo,tmSanCue,tmDebitos,tmCreditos,tmCostoAnt,tmCostoEnt,tmCostoSal,tmSaldoAnt,tmEntradas,tmSalidas)
  SELECT @pmtmEst,IdCia,IdCuenta,'0',P.IdSubgrupo,0,0,0,0,SUM(VrCostoEnt),SUM(VrCostoSal),0,SUM(Entradas),SUM(Salidas)
  FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
  LEFT JOIN (SELECT IdSubgrupo,IdCuenta  FROM SubgruposCue WHERE IdClase='0001') AS SC ON P.IdSubgrupo=SC.IdSubgrupo
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC','NTS')
  AND TipoRef<>'SERVICIO'  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')
  GROUP BY IdCia,IdCuenta,P.IdSubgrupo 
 END
ELSE
 BEGIN 
  INSERT INTO tm_Saldos (tmEst,tmIdCia,tmIdCuenta,tmIdTercero,tmCdSubgrupo,tmSanCue,tmDebitos,tmCreditos,tmCostoAnt,tmCostoEnt,tmCostoSal,tmSaldoAnt,tmEntradas,tmSalidas)
  SELECT @pmtmEst,'00',IdCuenta,'0',P.IdSubgrupo,0,0,0,0,SUM(VrCostoEnt),SUM(VrCostoSal),0,SUM(Entradas),SUM(Salidas)
  FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
  LEFT JOIN (SELECT IdSubgrupo,IdCuenta  FROM SubgruposCue WHERE IdClase='0001') AS SC ON P.IdSubgrupo=SC.IdSubgrupo
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC','NTS')
  AND TipoRef<>'SERVICIO'  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipoRef LIKE ISNULL(@pmTipoRef,'%')
  AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')
  GROUP BY  IdCuenta,P.IdSubgrupo 
 END
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Semanas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Semanas] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmVehiculo VARCHAR(10)
,@pmtmSemana INT,@pmtmVrTotal MONEY,@pmtmVrPagado MONEY,@pmtmDescripcion VARCHAR(150)
 AS 
 INSERT INTO tm_Semanas (tmNumero,tmItem,tmVehiculo,tmSemana,tmVrTotal,tmVrPagado,tmDescripcion)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmVehiculo,@pmtmSemana,@pmtmVrTotal,@pmtmVrPagado,@pmtmDescripcion)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Semanas_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Semanas_Sel]  @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_Semanas (tmNumero,tmItem,tmVehiculo,tmSemana,tmVrTotal,tmVrPagado,tmDescripcion)
 SELECT  @pmtmNumero,Item, IdVehiculo, nSemana
,0,CASE WHEN VrAbono>0  THEN VrAbono ELSE VrAbono*-1 END,Descripcion
 FROM   Trn_FcAbonos
 WHERE  TipRec=@pmTipRec  AND Recibo=@pmRecibo  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ser]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_Ser] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmNumSerial VARCHAR(30),@pmtmIdCia CHAR(2),@pmtmIdBodega VARCHAR(4),@pmtmCdUbic VARCHAR(10)
,@pmtmIdEstado VARCHAR(4),@pmtmLinea INT,@pmtmDetalle VARCHAR(250),@pmtmReferencia VARCHAR(50),@pmtmRef2 VARCHAR(50),@pmtmFecRef1 SMALLDATETIME,@pmtmFecRef2 SMALLDATETIME,@pmtmUbicacion VARCHAR(50)
,@pmtmIdBodNue VARCHAR(4),@pmtmUbicNue VARCHAR(10),@pmtmNueEstado VARCHAR(4),@pmtmInactivo BIT,@pmtmTipMovi VARCHAR(3)
 AS 
 INSERT INTO tm_Ser (tmNumero,tmItem,tmIdProducto,tmNumSerial,tmIdCia,tmIdBodega,tmCdUbic,tmIdEstado,tmLinea,tmDetalle,tmReferencia,tmRef2,tmFecRef1,tmFecRef2,tmUbicacion,tmIdBodNue,tmUbicNue,tmNueEstado,tmInactivo,tmTipMovi)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdProducto,@pmtmNumSerial,@pmtmIdCia,@pmtmIdBodega,@pmtmCdUbic,@pmtmIdEstado,@pmtmLinea,@pmtmDetalle,@pmtmReferencia,@pmtmRef2,@pmtmFecRef1,@pmtmFecRef2
,@pmtmUbicacion,@pmtmIdBodNue,@pmtmUbicNue,@pmtmNueEstado,@pmtmInactivo,@pmtmTipMovi)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ser_Dvn]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Ser_Dvn] @pmtmNumero VARCHAR(5), @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
 AS 
 INSERT INTO tm_Ser (tmNumero,tmItem,tmIdProducto,tmNumSerial,tmIdCia,tmIdBodega,tmCdUbic,tmIdEstado,tmLinea,tmDetalle,tmReferencia,tmRef2
,tmFecRef1,tmFecRef2,tmUbicacion,tmIdBodNue,tmUbicNue,tmNueEstado,tmInactivo,tmTipMovi)
 SELECT  @pmtmNumero,Item,M.IdProducto,M.NumSerial,M.IdCia,ISNULL(S.IdBodega,M.IdBodega),S.CdUbic,ISNULL(IdEstado,'0001'),Linea,M.Observacion,Referencia,Referncia2
,FecRef1,FecRef2,Ubicacion,M.IdBodega,M.CdUbic,ISNULL(IdEstado,'0001') ,ISNULL(Inactivo,0)
,CASE Movimiento WHEN 'ENT' THEN 'SAL' ELSE 'ENT'  END AS Movmiento
 FROM Trn_SerMov AS M  LEFT JOIN Trn_Seriales AS S ON M.IdProducto=S.IdProducto AND M.NumSerial=S.NumSerial AND M.IdCia=S.IdCia
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND M.IdCia=@pmIdCia 
 AND M.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND M.IdBodega LIKE ISNULL(@pmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ser_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Ser_Sel] @pmtmNumero VARCHAR(5), @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmMovimiento VARCHAR(3)=Null
 AS 
 INSERT INTO tm_Ser (tmNumero,tmItem,tmIdProducto,tmNumSerial,tmIdCia,tmIdBodega,tmCdUbic,tmIdEstado,tmLinea,tmDetalle,tmReferencia,tmRef2
,tmFecRef1,tmFecRef2,tmUbicacion,tmIdBodNue,tmUbicNue,tmNueEstado,tmInactivo,tmTipMovi)
 SELECT  @pmtmNumero,Item,M.IdProducto,M.NumSerial,M.IdCia,ISNULL(S.IdBodega,M.IdBodega),S.CdUbic,ISNULL(IdEstado,'0001'),Linea,M.Observacion,Referencia,Referncia2
,FecRef1,FecRef2,Ubicacion,M.IdBodega,M.CdUbic,ISNULL(IdEstado,'0001') ,ISNULL(Inactivo,0),ISNULL(@pmMovimiento,Movimiento)
 FROM Trn_SerMov AS M  LEFT JOIN Trn_Seriales AS S ON M.IdProducto=S.IdProducto AND M.NumSerial=S.NumSerial AND M.IdCia=S.IdCia
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND M.IdCia=@pmIdCia 
 AND M.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND M.IdBodega LIKE ISNULL(@pmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Sobtasas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Sobtasas] @pmtmIdDec VARCHAR(4),@pmtmNumDeclara INT,@pmtmAcpmCant DECIMAL(14,4)
,@pmtmAcpmBase MONEY,@pmtmAcpmValor MONEY,@pmtmAcpmTarif DECIMAL(14,4),@pmtmAcpmPrecio MONEY
,@pmtmAcpiCant DECIMAL(14,4),@pmtmAcpiBase MONEY,@pmtmAcpiValor MONEY,@pmtmAcpiTarif DECIMAL(14,4)
,@pmtmAcpiPrecio MONEY,@pmtmGcorCant DECIMAL(14,4),@pmtmGcorBase MONEY,@pmtmGcorValor MONEY
,@pmtmGcorTarif DECIMAL(14,4),@pmtmGcorPrecio MONEY,@pmtmGextCant DECIMAL(14,4),@pmtmGextBase MONEY
,@pmtmGextValor MONEY,@pmtmGextTarif DECIMAL(14,4),@pmtmGextPrecio MONEY,@pmtmGimpCant DECIMAL(14,4)
,@pmtmGimpBase MONEY,@pmtmGimpValor MONEY,@pmtmGimpTarif DECIMAL(14,4),@pmtmGimpPrecio MONEY
,@pmtmGcoxCant DECIMAL(14,4),@pmtmGcoxBase MONEY,@pmtmGcoxValor MONEY,@pmtmGcoxTarif DECIMAL(14,4)
,@pmtmGcoxPrecio MONEY,@pmtmGeoxCant DECIMAL(14,4),@pmtmGeoxBase MONEY,@pmtmGeoxValor MONEY,@pmtmGeoxTarif DECIMAL(14,4),@pmtmGeoxPrecio MONEY
,@pmtmAczfCant DECIMAL(14,4),@pmtmAczfBase MONEY,@pmtmAczfValor MONEY,@pmtmAczfTarif DECIMAL(14,4) ,@pmtmAczfPrecio MONEY
,@pmtmGnzfCant DECIMAL(14,4),@pmtmGnzfBase MONEY,@pmtmGnzfValor MONEY,@pmtmGnzfTarif DECIMAL(14,4),@pmtmGnzfPrecio MONEY
,@pmtmGOzfCant DECIMAL(14,4),@pmtmGOzfBase MONEY,@pmtmGOzfValor MONEY,@pmtmGOzfTarif DECIMAL(14,4),@pmtmGOzfPrecio MONEY
 AS 
 INSERT INTO tm_Sobtasas (tmIdDec,tmNumDeclara,tmAcpmCant,tmAcpmBase,tmAcpmValor,tmAcpmTarif,tmAcpmPrecio,tmAcpiCant,tmAcpiBase,tmAcpiValor
,tmAcpiTarif,tmAcpiPrecio,tmGcorCant,tmGcorBase,tmGcorValor,tmGcorTarif,tmGcorPrecio,tmGextCant,tmGextBase,tmGextValor,tmGextTarif,tmGextPrecio
,tmGimpCant,tmGimpBase,tmGimpValor,tmGimpTarif,tmGimpPrecio,tmGcoxCant,tmGcoxBase,tmGcoxValor,tmGcoxTarif,tmGcoxPrecio,tmGeoxCant
,tmGeoxBase,tmGeoxValor,tmGeoxTarif,tmGeoxPrecio,tmAczfCant,tmAczfBase,tmAczfValor,tmAczfTarif,tmAczfPrecio,tmGnzfCant
,tmGnzfBase,tmGnzfValor,tmGnzfTarif,tmGnzfPrecio,tmGOzfCant,tmGOzfBase,tmGOzfValor,tmGOzfTarif,tmGOzfPrecio)
 VALUES (@pmtmIdDec,@pmtmNumDeclara,@pmtmAcpmCant,@pmtmAcpmBase,@pmtmAcpmValor,@pmtmAcpmTarif,@pmtmAcpmPrecio,@pmtmAcpiCant
,@pmtmAcpiBase,@pmtmAcpiValor,@pmtmAcpiTarif,@pmtmAcpiPrecio,@pmtmGcorCant,@pmtmGcorBase,@pmtmGcorValor,@pmtmGcorTarif
,@pmtmGcorPrecio,@pmtmGextCant,@pmtmGextBase,@pmtmGextValor,@pmtmGextTarif,@pmtmGextPrecio,@pmtmGimpCant,@pmtmGimpBase
,@pmtmGimpValor,@pmtmGimpTarif,@pmtmGimpPrecio,@pmtmGcoxCant,@pmtmGcoxBase,@pmtmGcoxValor,@pmtmGcoxTarif,@pmtmGcoxPrecio
,@pmtmGeoxCant,@pmtmGeoxBase,@pmtmGeoxValor,@pmtmGeoxTarif,@pmtmGeoxPrecio,@pmtmAczfCant,@pmtmAczfBase,@pmtmAczfValor,@pmtmAczfTarif 
,@pmtmAczfPrecio,@pmtmGnzfCant,@pmtmGnzfBase,@pmtmGnzfValor,@pmtmGnzfTarif,@pmtmGnzfPrecio,@pmtmGOzfCant,@pmtmGOzfBase,@pmtmGOzfValor,@pmtmGOzfTarif,@pmtmGOzfPrecio)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Tanqueos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Tanqueos] @pmtmNumero VARCHAR(5),@pmtmItem INT, @pmtmFecha SMALLDATETIME, @pmtmDocumento VARCHAR(10), @pmtmIdTipoCom VARCHAR(4), @pmtmCantidad DECIMAL(14,4)
, @pmtmValorUnitario MONEY,@pmtmIdEstacion VARCHAR(4), @pmtmEstacion VARCHAR(50), @pmtmTipoCom  VARCHAR(50)
AS
 INSERT INTO  tm_Tanqueos ( tmNumero, tmItem, tmFecha, tmDocumento, tmIdTipoCom, tmCantidad, tmValorUnitario,tmIdEstacion, tmEstacion, tmTipoCom )
 VALUES (@pmtmNumero, @pmtmItem, @pmtmFecha, @pmtmDocumento, @pmtmIdTipoCom, @pmtmCantidad, @pmtmValorUnitario,@pmtmIdEstacion, @pmtmEstacion, @pmtmTipoCom)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraAnt] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipAnt VARCHAR(3),@pmtmAnticipo INT,@pmtmIdCia CHAR(2)
,@pmtmValor MONEY,@pmtmVrAnticipo MONEY,@pmtmTotalAbonos MONEY,@pmtmDetalle VARCHAR(100),@pmtmCdCueAnt VARCHAR(16)
 AS 
 INSERT INTO tm_TraAnt (tmNumero,tmItem,tmTipAnt,tmAnticipo,tmIdCia,tmValor,tmVrAnticipo,tmTotalAbonos,tmDetalle,tmCdCueAnt)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipAnt,@pmtmAnticipo,@pmtmIdCia,@pmtmValor,@pmtmVrAnticipo,@pmtmTotalAbonos,@pmtmDetalle,@pmtmCdCueAnt)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraAnt_Aos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_TraAnt_Aos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraAnt (tmNumero,tmItem,tmTipAnt,tmAnticipo,tmIdCia,tmValor,tmVrAnticipo,tmTotalAbonos,tmDetalle,tmCdCueAnt)
 SELECT @pmtmNumero,Item,TipAnt,A.Anticipo,IdCiaAnt,A.VrAbono,AN.VrAnticipo,AN.VrAbonado,A.Observacion,CodCuenta
 FROM Trn_TraOrdenAbo AS A INNER JOIN Trn_TraOrdenAnt AS AN ON A.TipAnt=AN.TipDoc AND A.Anticipo=AN.Anticipo AND A.IdCiaAnt=AN.IdCia
 WHERE  A.TipDoc=@pmTipDoc AND A.Documento=@pmDocumento AND A.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraAnt_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_TraAnt_Sel] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraAnt (tmNumero,tmItem,tmTipAnt,tmAnticipo,tmIdCia,tmValor,tmVrAnticipo,tmTotalAbonos,tmDetalle,tmCdCueAnt)
 SELECT @pmtmNumero,Item,TipAnt,A.Anticipo,IdCiaAnt,A.VrAbono,AN.VrAnticipo,AN.VrAbonado,Detalle,CdCuentaAnt
 FROM Trn_TraAntAbonos AS A INNER JOIN Trn_TraAnticipos AS AN ON A.TipAnt=AN.TipDoc AND A.Anticipo=AN.Anticipo AND A.IdCiaAnt=AN.IdCia
 WHERE  A.TipDoc=@pmTipDoc AND A.Documento=@pmDocumento AND A.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraCentrega]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraCentrega] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipRem VARCHAR(3),@pmtmRemesa INT,@pmtmIdCiaRem CHAR(2),@pmtmVrTotal MONEY
,@pmtmVrCosto MONEY,@pmtmVrDeclarado MONEY,@pmtmVrSeguro MONEY,@pmtmTipoVehic VARCHAR(10),@pmtmCdConc VARCHAR(4),@pmtmCdCuenta VARCHAR(16),@pmtmCdCueIng VARCHAR(16)
,@pmtmCdCueSeg VARCHAR(16),@pmtmCdCueOcg VARCHAR(16),@pmtmCdCueOdc VARCHAR(16),@pmtmCdCiudad VARCHAR(8)
 AS 
 INSERT INTO tm_TraCentrega (tmNumero,tmItem,tmTipRem,tmRemesa,tmIdCiaRem,tmVrTotal,tmVrCosto,tmVrDeclarado,tmVrSeguro,tmTipoVehic,tmCdConc,tmCdCuenta,tmCdCueIng,tmCdCueSeg,tmCdCueOcg,tmCdCueOdc,tmCdCiudad)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipRem,@pmtmRemesa,@pmtmIdCiaRem,@pmtmVrTotal,@pmtmVrCosto,@pmtmVrDeclarado,@pmtmVrSeguro,@pmtmTipoVehic,@pmtmCdConc,@pmtmCdCuenta
,@pmtmCdCueIng,@pmtmCdCueSeg,@pmtmCdCueOcg,@pmtmCdCueOdc,@pmtmCdCiudad)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraConc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraConc] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmDescripcion VARCHAR(250),@pmtmTarifa DECIMAL(14,4),@pmtmTipoConc VARCHAR(10),@pmtmRubro VARCHAR(20)
,@pmtmCantidad DECIMAL(14,4),@pmtmVrUnitario MONEY,@pmtmTarifIva DECIMAL(14,4),@pmtmIdConcepto VARCHAR(4),@pmtmCdCuenta VARCHAR(16),@pmtmNitTercero VARCHAR(16),@pmtmVrBase MONEY
,@pmtmTipoTarif CHAR(1),@pmtmRefConc VARCHAR(50),@pmtmFijos BIT,@pmtmBaseRet INT,@pmtmTipDocRef VARCHAR(3),@pmtmNumOrden INT,@pmtmIdCiaOrd CHAR(2),@pmtmItemOrd INT,@pmtmTipoNov INT
 AS 
 INSERT INTO tm_TraConc (tmNumero,tmItem,tmDescripcion,tmTarifa,tmTipoConc,tmRubro,tmCantidad,tmVrUnitario,tmTarifIva,tmIdConcepto,tmCdCuenta,tmNitTercero,tmVrBase,tmTipoTarif,tmRefConc,tmFijos,tmBaseRet,tmTipDocRef,tmNumOrden,tmIdCiaOrd,tmItemOrd,tmTipoNov)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmDescripcion,@pmtmTarifa,@pmtmTipoConc,@pmtmRubro,@pmtmCantidad,@pmtmVrUnitario,@pmtmTarifIva,@pmtmIdConcepto,@pmtmCdCuenta,@pmtmNitTercero,@pmtmVrBase,@pmtmTipoTarif,@pmtmRefConc,@pmtmFijos,@pmtmBaseRet
 ,@pmtmTipDocRef,@pmtmNumOrden,@pmtmIdCiaOrd,@pmtmItemOrd,@pmtmTipoNov)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraConc_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraConc_Sel] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraConc (tmNumero,tmItem,tmDescripcion,tmTarifa,tmTipoConc,tmRubro,tmCantidad,tmVrUnitario,tmTarifIva,tmIdConcepto,tmCdCuenta,tmNitTercero,tmVrBase,tmTipoTarif,tmRefConc,tmFijos,tmBaseRet
,tmTipDocRef,tmNumOrden,tmIdCiaOrd,tmItemOrd,tmTipoNov)
 SELECT @pmtmNumero,Item,Descripcion,Tarifa,TipoConc,RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, CdCuenta, NitTercero,VrBase,TipoTarif,RefConc,Fijos,IncBaseRet
 ,TipLiq,NumLiquida,CiaLiq,Est_Liquida,CASE WHEN (TipLiq='MUC' OR TipLiq='OSA') THEN 1 ELSE 0 END
 FROM Trn_TraConceptos
 WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdMercancia VARCHAR(16),@pmtmDescripMcias VARCHAR(250),@pmtmCantidad DECIMAL(14,4),@pmtmPesoNeto DECIMAL(14,4),@pmtmUndMed VARCHAR(10),@pmtmdmsAlto DECIMAL(14,4),@pmtmdmsAncho DECIMAL(14,4),@pmtmdmsLargo DECIMAL(14,4),@pmtmVolumen DECIMAL(14,4),@pmtmUndVol VARCHAR(10),@pmtmIdUnd VARCHAR(4),@pmtmIdEmp VARCHAR(4),@pmtmIdNat VARCHAR(4),@pmtmIdMnjo VARCHAR(4),@pmtmIdTmcia VARCHAR(4)
,@pmtmCdRango VARCHAR(4),@pmtmCases INT,@pmtmCajas INT,@pmtmPalets INT,@pmtmRemision DECIMAL(18,2),@pmtmNumOrden INT,@pmtmNitRemite VARCHAR(16),@pmtmRemitente VARCHAR(250),@pmtmDirOrigen VARCHAR(250),@pmtmIdOrigen VARCHAR(8),@pmtmNitDestntario VARCHAR(16),@pmtmDestinatario VARCHAR(250),@pmtmDirDestino VARCHAR(250),@pmtmIdDestino VARCHAR(8),@pmtmCdAgencia VARCHAR(16),@pmtmTipoVehic VARCHAR(10),@pmtmTarifClie MONEY,@pmtmTarifPago MONEY,@pmtmTarifTabla MONEY,@pmtmVrDeclarado MONEY,@pmtmVrSeguro MONEY
,@pmtmTarifSeguro DECIMAL(14,4),@pmtmDocCliente VARCHAR(30),@pmtmReferencia1 VARCHAR(50),@pmtmReferencia2 VARCHAR(50),@pmtmReferencia3 VARCHAR(50),@pmtmContenedor1 VARCHAR(50),@pmtmContenedor2 VARCHAR(50),@pmtmUndTarifa VARCHAR(10),@pmtmTipRem VARCHAR(3),@pmtmRemesa INT,@pmtmIdCiaRem CHAR(2),@pmtmItemRem INT,@pmtmNumMintrans DECIMAL(14,2),@pmtmPesoCont DECIMAL(14,4),@pmtmUndTarPago VARCHAR(10),@pmtmCodBodega VARCHAR(4),@pmtmTipoTraslado INT
,@pmtmTieCargue DECIMAL(14,4),@pmtmTieDesc DECIMAL(14,4),@pmtmFecIniCargue SMALLDATETIME,@pmtmFecFinCargue SMALLDATETIME,@pmtmFecInidesc SMALLDATETIME,@pmtmFecFindesc SMALLDATETIME,@pmtmCdTipoVeh VARCHAR(4),@pmtmTipoServicio VARCHAR(10),@pmtmSedeRem VARCHAR(10),@pmtmSedeDest VARCHAR(10),@pmtmFecLlegaCargue SMALLDATETIME,@pmtmFecLlegaDesc SMALLDATETIME,@pmtmMinCargue INT,@pmtmMinDescargue INT,@pmtmTarifOtros MONEY,@pmtmCod_UN VARCHAR(30),@pmtmCod_Corr VARCHAR(8),@pmtmCod_Desg VARCHAR(8),@pmtmDescripRP VARCHAR(500)
,@pmtmTray_Vacio1 MONEY,@pmtmTray_Vacio2 MONEY
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3
,tmContenedor1,tmContenedor2,tmUndTarifa,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh,tmTipoServicio,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmCod_UN,tmCod_Corr,tmCod_Desg,tmDescripRP,tmTray_Vacio1,tmTray_Vacio2)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdMercancia,@pmtmDescripMcias,@pmtmCantidad,@pmtmPesoNeto,@pmtmUndMed,@pmtmdmsAlto,@pmtmdmsAncho,@pmtmdmsLargo,@pmtmVolumen,@pmtmUndVol,@pmtmIdUnd,@pmtmIdEmp,@pmtmIdNat,@pmtmIdMnjo,@pmtmIdTmcia,@pmtmCdRango,@pmtmCases,@pmtmCajas,@pmtmPalets,@pmtmRemision,@pmtmNumOrden,@pmtmNitRemite,@pmtmRemitente,@pmtmDirOrigen,@pmtmIdOrigen,@pmtmNitDestntario,@pmtmDestinatario,@pmtmDirDestino,@pmtmIdDestino,@pmtmCdAgencia,@pmtmTipoVehic
,@pmtmTarifClie,@pmtmTarifPago,@pmtmTarifTabla,@pmtmVrDeclarado,@pmtmVrSeguro,@pmtmTarifSeguro,@pmtmDocCliente,@pmtmReferencia1,@pmtmReferencia2,@pmtmReferencia3,@pmtmContenedor1,@pmtmContenedor2,@pmtmUndTarifa,@pmtmTipRem,@pmtmRemesa,@pmtmIdCiaRem,@pmtmItemRem,@pmtmNumMintrans,@pmtmPesoCont,@pmtmUndTarPago,@pmtmCodBodega,@pmtmTipoTraslado,@pmtmTieCargue,@pmtmTieDesc,@pmtmFecIniCargue,@pmtmFecFinCargue,@pmtmFecInidesc,@pmtmFecFindesc,@pmtmCdTipoVeh,@pmtmTipoServicio,@pmtmSedeRem,@pmtmSedeDest
,@pmtmFecLlegaCargue,@pmtmFecLlegaDesc,@pmtmMinCargue,@pmtmMinDescargue,@pmtmTarifOtros,@pmtmCod_UN,@pmtmCod_Corr,@pmtmCod_Desg,@pmtmDescripRP,@pmtmTray_Vacio1,@pmtmTray_Vacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Crr] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat
,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino
,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc
,tmCdTipoVeh,tmTipoServicio,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,Item,'0',Descripcion,Unidades,PesoNeto,UndMed,0,0,0,Volumen,UndVol,'0','0','0','0','0','0',0,0,0,0,0,CedConductor,'0','0','0',CedConductor,'0','0','0','0','TERCEROS',0,VrUnitario,ValorTotal
,0,0,0,pVehiculo,'','',CAST(FecRemesa AS VARCHAR(20)) ,'','',UndTarifa,TipRem,Remesa,IdCiaRem,0,0,0,UndTarifa,'',0,0,0,Null,Null,Null,Null,'','','','',Null,Null,0,0,0,0,0
 FROM  Trn_TraReexpedidoRem
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Gtc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Gtc] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat
,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino
,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh
,tmTipoServicio,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,D.Item,D.IdMercancia,D.DescripcionMcia,D.Cantidad,D.PesoNeto,D.UndMed,D.dmsAlto,D.dmsAncho,D.dmsLargo,D.Volumen,D.UndVol,D.IdUnd,D.IdEmp,D.IdNat
,D.IdMnjo,D.IdTmcia,D.CdConcepto,0,0,0,D.Remision,G.NumRemesa,G.IdRemitente,G.NomRemitente,G.DirOrigen,G.IdLocOrigen,G.IdDestinatario,G.NomDestinatario,G.DirDestino,G.IdLocDestino
,G.IdAgencia,'TERCEROS',D.VrUnitario,0,0,D.VrDeclarado,D.VrSeguro,D.TarifSeguro,D.DocCliente,D.Referencia1,D.Referencia2,D.Referencia3,'','',D.UndTarifa
,G.TipRem,G.NumRemesa,G.IdCiaRem,0,0,0,D.UndTarifa,'0',0,0,0,Null,Null,Null,Null,'0','0','','',Null,Null,0,0,0,0,0
 FROM Trn_TraGuias AS G INNER JOIN Trn_TraGuiaMcia AS D ON G.TipDoc=D.TipDoc AND G.NumGuia=D.NumGuia AND G.IdCia=D.IdCia
 WHERE G.TipDoc=@pmTipDoc AND G.NumGuia=@pmNumGuia AND G.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Muc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Muc] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat
,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino
,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh,tmTipoServicio
,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmCod_UN,tmCod_Corr,tmCod_Desg,tmDescripRP,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,RM.Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat
,IdMnjo,IdTmcia,CdRango,Cases,Cajas,Palets,Remision,Factura,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino
,CdAgencia,'TERCEROS',TarifClie,RM.TarifPago,RM.TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,UndTarifa
,TipRem,Remesa,IdCiaRem,ItemRem,RemMintrans,PesoCont,UndTarifPago,CodBodDtno,TipTraslado,HorasCargue,HorasDesc,FecInicioCargue,FecFinCargue,FecIniciodesc,FecFindesc,'','',SedeRem,SedeDest,Null,Null,0,0,D.TarifOtros
,D.Cod_UN,D.Cod_Corr,D.Cod_Desg,D.DescripcionRP,RM.RemTrayVacio1,RM.RemTrayVacio2
 FROM Trn_TraManifRem AS RM INNER JOIN Trn_TraRemMcias AS D ON  RM.TipRem=D.TipDoc AND RM.Remesa=D.NumOrden AND RM.IdCiaRem=D.IdCia AND RM.ItemRem=D.Item
 WHERE RM.TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND RM.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Ocv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Ocv] @pmTipDoc VARCHAR(3),@pmNumViaje INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat
,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino
,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh,tmTipoServicio
,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,RM.Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat
,IdMnjo,IdTmcia,CdRango,Cases,Cajas,Palets,Remision,Factura,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino
,CdAgencia,'TERCEROS',TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,UndTarifa
,TipOrden,RM.NumOrden,IdCiaOrd,ItemOrd,0,PesoCont,UndTarifPago,'','',0,0,Null,Null,Null,Null,'','',SedeRem,SedeDest,Null,Null,0,0,D.TarifOtros,0,0
 FROM Trn_TraInfViajesOrd AS RM INNER JOIN Trn_TraRemMcias  AS D ON  RM.TipOrden=D.TipDoc AND RM.NumOrden=D.NumOrden AND RM.IdCiaOrd=D.IdCia AND RM.ItemOrd=D.Item
 WHERE RM.TipDoc=@pmTipDoc AND RM.NumViaje=@pmNumViaje AND RM.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Odp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Odp] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets
,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3
,tmContenedor1,tmContenedor2,tmUndTarifa,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh,tmTipoServicio
,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
 SELECT @pmtmNumero,R.Item,IdMercancia,Detalle,R.Cantidad,R.PesoNeto,R.UndMed,dmsAlto,dmsAncho,dmsLargo,R.Volumen,R.UndVol,IdUnd,IdEmp,IdNat,IdMnjo,IdTmcia,CdRango,R.Cases,R.Cajas,R.Palets,Remision,Cumplido
,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,CdAgencia,'TERCEROS',TarifClie,R.TarifPago,R.TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,DocCliente,Referencia1,Referencia2,Referencia3
,Contenedor1,Contenedor2,D.UndTarifa,TipRem,Remesa,IdCiaRem,ItemRem,0,PesoCont,R.UndTarifa,'',0,0,0,Null,Null,Null,Null,'','',SedeRem,SedeDest,Null,Null,0,0,D.TarifOtros,0,0
 FROM Trn_TraOrdenRemesas AS R INNER JOIN Trn_TraRemMcias AS D ON R.TipRem=D.TipDoc AND  R.Remesa=D.NumOrden AND R.IdCiaRem=D.IdCia AND R.ItemRem=D.Item
 WHERE R.TipDoc=@pmTipDoc AND R.OrdPago=@pmOrdPago  AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Rem]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Rem] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat
,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino
,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh
,tmTipoServicio,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmCod_UN,tmCod_Corr,tmCod_Desg,tmDescripRP,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat
,IdMnjo,IdTmcia,CdRango,Cases,Cajas,Palets,Remision,Factura,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino
,CdAgencia,'TERCEROS',TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,UndTarifa
,CASE WHEN TipDocInv='SAL' AND NumDocInv>0 THEN TipDocInv ELSE TipFac END,CASE WHEN TipDocInv='SAL' AND NumDocInv>0 THEN NumDocInv ELSE Factura END
,CASE WHEN TipDocInv='SAL' AND NumDocInv>0 THEN IdCiaDocInv ELSE IdCiaFac END,CASE WHEN TipDocInv='SAL' AND NumDocInv>0 THEN ItemDocInv ELSE 0 END
,0,PesoCont,UndTarifPago,'',0,0,0,Null,Null,Null,Null,'','',SedeRem,SedeDest,Null,Null,0,0,TarifOtros,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP,0,0
 FROM Trn_TraRemMcias
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetalle_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetalle_Sel] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetalle (tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol,tmIdUnd,tmIdEmp,tmIdNat
,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino
,tmCdAgencia,tmTipoVehic,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc,tmFecFindesc,tmCdTipoVeh
,tmTipoServicio,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmCod_UN,tmCod_Corr,tmCod_Desg,tmDescripRP,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat
,IdMnjo,IdTmcia,CdRango,Cases,Cajas,Palets,0,0,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino
,'0','TERCEROS',TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,UndTarifa
,TipDoc,Pedido,IdCia,Item,0,0,UndTarifPago,'',0,0,0,Null,Null,Null,Null,CdTipoVehic,Tipo_Servicio,SedeRem,SedeDest,Null,Null,0,0,0,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP,0,0
 FROM Trn_TraPedMcias
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetConc] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdConcepto VARCHAR(4),@pmtmDescripcion VARCHAR(250),@pmtmTipoConc VARCHAR(10),@pmtmVrDebito MONEY,@pmtmVrCredito MONEY,@pmtmCdCuenta VARCHAR(16)
,@pmtmNitTercero VARCHAR(16),@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmpVehiculo VARCHAR(10),@pmtmTipoAfiVehic VARCHAR(10),@pmtmVrBase MONEY,@pmtmTarifBase DECIMAL(14,4),@pmtmReferencia VARCHAR(50)
,@pmtmTipDocRef VARCHAR(3),@pmtmDocRef INT,@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15),@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmFecVence SMALLDATETIME,@pmtmCodAgncia VARCHAR(16),@pmtmCantComb DECIMAL(14,4)
,@pmtmDocSop BIT,@pmtmTipoImp VARCHAR(4),@pmtmCodTarImp VARCHAR(4),@pmtmItemBase INT,@pmtmTipoDs VARCHAR(3),@pmtmNumDs INT,@pmtmIdCiaDs CHAR(2),@pmtmTipoNov INT,@pmtmCiaDocRef CHAR(2),@pmtmItemDocRef INT
 AS 
 INSERT INTO tm_TraDetConc (tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos,tmpVehiculo,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef
,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb,tmDocSop,tmTipoImp,tmCodTarImp,tmItemBase,tmTipoDs,tmNumDs,tmIdCiaDs,tmTipoNov,tmCiaDocRef,tmItemDocRef)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdConcepto,@pmtmDescripcion,@pmtmTipoConc,@pmtmVrDebito,@pmtmVrCredito,@pmtmCdCuenta,@pmtmNitTercero,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmpVehiculo,@pmtmTipoAfiVehic
,@pmtmVrBase,@pmtmTarifBase,@pmtmReferencia,@pmtmTipDocRef,@pmtmDocRef,@pmtmTipFac,@pmtmFactura,@pmtmIdCiaFac,@pmtmItemFac,@pmtmFecVence,@pmtmCodAgncia,@pmtmCantComb,@pmtmDocSop,@pmtmTipoImp,@pmtmCodTarImp,@pmtmItemBase,@pmtmTipoDs,@pmtmNumDs,@pmtmIdCiaDs,@pmtmTipoNov,@pmtmCiaDocRef,@pmtmItemDocRef)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Dev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetConc_Dev]  @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetConc (tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos,tmpVehiculo
,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb,tmDocSop,tmTipoImp,tmCodTarImp,tmItemBase,tmTipoDs,tmNumDs,tmIdCiaDs,tmTipoNov,tmCiaDocRef,tmItemDocRef)
 SELECT @pmtmNumero,Item,IdConcepto,Descripcion,TipoConc,VrCredito,VrDebito,CdCuenta,NitTercero,CdCCosto,CdSubCos,pVehiculo
,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,TipFac,Factura,IdCiaFac,ItemFac,FecVence,'0',0,0,'','',0,'0',0,'00',0,IdCiaFac,ItemFac
 FROM Trn_TraCauDetalle
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Dlg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetConc_Dlg]  @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetConc (tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos,tmpVehiculo
,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb,tmDocSop,tmTipoImp,tmCodTarImp,tmItemBase,tmTipoDs,tmNumDs,tmIdCiaDs,tmTipoNov,tmCiaDocRef,tmItemDocRef)
 SELECT @pmtmNumero,Item,IdConcepto,DescConcepto,RubroConc,VrCredito,VrDebito,IdCuenta,IdTercero,CdCCosto,CdSubCos,pVehiculo
,'TERCEROS',VrBase,TarifBase,RefConcep,TipDocNov,NumDocNov,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodAgncia,CantComb,DocSop,TipoImp,CodTarImp,ItemBase,TipSop,NumSoporte,IdCiaSop,TipoNov,CiaDocNov,ItemNov
 FROM Trn_TraLiqDetalle
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Leg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetConc_Leg]  @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetConc (tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos,tmpVehiculo
,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb,tmDocSop,tmTipoImp,tmCodTarImp,tmItemBase,tmTipoDs,tmNumDs,tmIdCiaDs,tmTipoNov,tmCiaDocRef,tmItemDocRef)
 SELECT @pmtmNumero,Item,IdConcepto,DescConcepto,RubroConc,VrDebito,VrCredito,IdCuenta,IdTercero,CdCCosto,CdSubCos,pVehiculo
,'TERCEROS',VrBase,TarifBase,RefConcep,TipDocNov,NumDocNov,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodAgncia,CantComb,DocSop,TipoImp,CodTarImp,ItemBase,TipSop,NumSoporte,IdCiaSop,TipoNov,CiaDocNov,ItemNov
 FROM Trn_TraLiqDetalle
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraDetConc_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_TraDetConc_Sel]  @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraDetConc (tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos,tmpVehiculo
,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb,tmDocSop,tmTipoImp,tmCodTarImp,tmItemBase,tmTipoDs,tmNumDs,tmIdCiaDs,tmTipoNov,tmCiaDocRef,tmItemDocRef)
 SELECT @pmtmNumero,Item,IdConcepto,Descripcion,TipoConc,VrDebito,VrCredito,CdCuenta,NitTercero,CdCCosto,CdSubCos,pVehiculo
,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,TipFac,Factura,IdCiaFac,ItemFac,FecVence,'0',0,0,'','',0,'0',0,'00',0,'',0
 FROM Trn_TraCauDetalle
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraLiqCausac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraLiqCausac] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipCau VARCHAR(3),@pmtmCausacion INT,@pmtmIdCiaCau CHAR(2),@pmtmItemCau INT,@pmtmFecha SMALLDATETIME,@pmtmIdConcepto VARCHAR(4),@pmtmDescripcion VARCHAR(250)
,@pmtmVrAbono MONEY,@pmtmNit VARCHAR(16),@pmtmVehiculo VARCHAR(10),@pmtmTipOdp VARCHAR(3),@pmtmOrdenPago INT,@pmtmIdCiaOdp CHAR(2),@pmtmTipMuc VARCHAR(3),@pmtmManifiesto INT,@pmtmIdCiaMuc CHAR(2),@pmtmItemFact INT,@pmtmVrSaldo MONEY
,@pmtmEsVence BIT,@pmtmCdCuenta VARCHAR(16),@pmtmCuePagar VARCHAR(16),@pmtmFactura VARCHAR(20),@pmtmConcValor MONEY,@pmtmConcAbono MONEY,@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmTipoFac VARCHAR(3),@pmtmReferencia VARCHAR(50)
 AS 
 INSERT INTO tm_TraLiqCausac (tmNumero,tmItem,tmTipCau,tmCausacion,tmIdCiaCau,tmItemCau,tmFecha,tmIdConcepto,tmDescripcion,tmVrAbono,tmNit,tmVehiculo,tmTipOdp,tmOrdenPago,tmIdCiaOdp,tmTipMuc,tmManifiesto,tmIdCiaMuc
,tmItemFact,tmVrSaldo,tmEsVence,tmCdCuenta,tmCuePagar,tmFactura,tmConcValor,tmConcAbono,tmCdCCosto,tmCdSubCos,tmTipoFac,tmReferencia)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipCau,@pmtmCausacion,@pmtmIdCiaCau,@pmtmItemCau,@pmtmFecha,@pmtmIdConcepto,@pmtmDescripcion,@pmtmVrAbono,@pmtmNit,@pmtmVehiculo,@pmtmTipOdp,@pmtmOrdenPago,@pmtmIdCiaOdp
,@pmtmTipMuc,@pmtmManifiesto,@pmtmIdCiaMuc,@pmtmItemFact,@pmtmVrSaldo,@pmtmEsVence,@pmtmCdCuenta,@pmtmCuePagar,@pmtmFactura,@pmtmConcValor,@pmtmConcAbono,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmTipoFac,@pmtmReferencia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraLiqCausac_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_TraLiqCausac_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_TraLiqCausac (tmNumero,tmItem,tmTipCau,tmCausacion,tmIdCiaCau,tmItemCau,tmFecha,tmIdConcepto,tmDescripcion,tmVrAbono,tmNit,tmVehiculo,tmTipOdp,tmOrdenPago,tmIdCiaOdp
,tmTipMuc,tmManifiesto,tmIdCiaMuc,tmItemFact,tmVrSaldo,tmEsVence,tmCdCuenta,tmCuePagar,tmFactura,tmConcValor,tmConcAbono,tmCdCCosto,tmCdSubCos,tmTipoFac,tmReferencia)
 SELECT @pmtmNumero,D.Item,D.TipCau,D.Causacion,D.IdCiaCau,D.ItemCau,D.FechaCau,D.IdConcepto,D.Descripcion,D.VrAbono,D.NitPoseedor,D.pVehiculo,D.TipOdp,D.OrdenPago,D.IdCiaOdp
,D.TipMuc,D.Manifiesto,D.IdCiaMuc,1,D.VrSaldoOrden,D.EsVence,D.CdCuenta,D.CdCuePagar,D.NumFactura,0,0,D.CdCCosto,D.CdSubCos,D.TipOdp,OP.IdVehiculo
 FROM Trn_TraLiquidaDed AS D LEFT JOIN (SELECT TipDoc,OrdPago,IdCia,IdVehiculo,IdPoseedor FROM Trn_TraOrdenManif
 UNION ALL SELECT TipDoc,Liquidacion,IdCia,IdVehiculo,IdPoseedor FROM Trn_TraOrdenLiq WHERE TipDoc='OPT') AS OP ON D.TipOdp=OP.TipDoc AND D.OrdenPago=OP.OrdPago AND D.IdCiaOdp=OP.IdCia
 WHERE D.TipDoc=@pmTipDoc AND D.Liquidacion=@pmLiquidacion AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraMovLiquida] @pmtmEst CHAR(2),@pmtmTipo VARCHAR(3),@pmtmNumero INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmFecha SMALLDATETIME,@pmtmFecVence SMALLDATETIME,@pmtmIdPoseedor VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmIdConcepto VARCHAR(4),@pmtmDescripcion VARCHAR(250),@pmtmVrDebito MONEY,@pmtmVrCredito MONEY,@pmtmVrAbonado MONEY,@pmtmTipoVehic VARCHAR(10)
,@pmtmVrBase MONEY,@pmtmTarifa DECIMAL(14,4),@pmtmReferencia VARCHAR(50),@pmtmTipDocRef VARCHAR(3),@pmtmDocRef INT,@pmtmEstado INT,@pmtmTipoLiq VARCHAR(3),@pmtmLiquida INT,@pmtmCiaLiq CHAR(2),@pmtmSaldoAnt MONEY,@pmtmSaldoCia MONEY,@pmtmSaldoAntVeh MONEY,@pmtmSaldoVehCia MONEY
 AS 
 INSERT INTO tm_TraMovLiquida (tmEst,tmTipo,tmNumero,tmIdCia,tmItem,tmFecha,tmFecVence,tmIdPoseedor,tmIdVehiculo,tmIdConcepto,tmDescripcion,tmVrDebito,tmVrCredito,tmVrAbonado,tmTipoVehic,tmVrBase,tmTarifa,tmReferencia,tmTipDocRef,tmDocRef,tmEstado,tmTipoLiq,tmLiquida,tmCiaLiq,tmSaldoAnt,tmSaldoCia,tmSaldoAntVeh,tmSaldoVehCia)
 VALUES (@pmtmEst,@pmtmTipo,@pmtmNumero,@pmtmIdCia,@pmtmItem,@pmtmFecha,@pmtmFecVence,@pmtmIdPoseedor,@pmtmIdVehiculo,@pmtmIdConcepto,@pmtmDescripcion,@pmtmVrDebito,@pmtmVrCredito,@pmtmVrAbonado,@pmtmTipoVehic,@pmtmVrBase,@pmtmTarifa,@pmtmReferencia,@pmtmTipDocRef,@pmtmDocRef,@pmtmEstado,@pmtmTipoLiq,@pmtmLiquida,@pmtmCiaLiq,@pmtmSaldoAnt,@pmtmSaldoCia,@pmtmSaldoAntVeh,@pmtmSaldoVehCia)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaCau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraMovLiquidaCau] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdPoseedor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
 AS 
 INSERT INTO tm_TraMovLiquida (tmEst,tmTipo,tmNumero,tmIdCia,tmItem,tmFecha,tmFecVence,tmIdPoseedor,tmIdVehiculo,tmIdConcepto,tmDescripcion
,tmVrDebito,tmVrCredito,tmVrAbonado,tmTipoVehic,tmVrBase,tmTarifa,tmReferencia,tmTipDocRef,tmDocRef,tmEstado,tmTipoLiq,tmLiquida,tmCiaLiq,tmSaldoAnt,tmSaldoCia,tmSaldoAntVeh,tmSaldoVehCia)
 SELECT @pmtmEst,D.TipDoc,D.Causacion,D.IdCia,D.Item,C.Fecha,D.FecVence,D.NitTercero,D.pVehiculo,D.IdConcepto,D.Descripcion
,D.VrDebito,D.VrCredito,D.VrAbonado,D.TipoAfiVehic,VrBase,TarifBase,D.Referencia,TipDocRef,DocRef,EstadoReg,D.TipoLiq,D.NumLiquida,D.CiaLiquida,0,0,0,0
 FROM Trn_TraCauDetalle AS D INNER JOIN Trn_TraCausacion AS C ON D.TipDoc=C.TipDoc AND D.Causacion=C.Causacion AND D.IdCia=C.IdCia
 WHERE D.FecVence BETWEEN @pmFechaIni AND @pmFechaFin AND D.TipoConc='CTACOBRAR' AND D.VrDebito>0
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.NitTercero LIKE ISNULL(@pmIdPoseedor,'%') AND D.pVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaDcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paInstm_TraMovLiquidaDcc] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdPoseedor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
 AS 
 INSERT INTO tm_TraMovLiquida (tmEst,tmTipo,tmNumero,tmIdCia,tmItem,tmFecha,tmFecVence,tmIdPoseedor,tmIdVehiculo,tmIdConcepto,tmDescripcion
,tmVrDebito,tmVrCredito,tmVrAbonado,tmTipoVehic,tmVrBase,tmTarifa,tmReferencia,tmTipDocRef,tmDocRef,tmEstado,tmTipoLiq,tmLiquida,tmCiaLiq,tmSaldoAnt,tmSaldoCia,tmSaldoAntVeh,tmSaldoVehCia)
SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,DC.Item,D.Fecha,DC.FecVence,DC.NitTercero,DC.pVehiculo,DC.IdConcepto,DC.Descripcion
,DC.VrCredito,DC.VrDebito,DC.VrAbonado,DC.TipoAfiVehic,DC.VrBase,DC.TarifBase,DC.Referencia,TipDocRef,DocRef,EstadoReg,DC.TipoLiq,DC.NumLiquida,DC.CiaLiquida,0,0,0,0
FROM Trn_TraDevCau AS D INNER JOIN Trn_TraCauDetalle AS DC ON D.TipDoc=DC.TipDoc AND D.Causacion=DC.Causacion AND D.IdCiaDoc=DC.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND DC.TipoConc='CTACOBRAR' AND DC.VrDebito>0
AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND DC.NitTercero LIKE ISNULL(@pmIdPoseedor,'%') AND DC.pVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaDop]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraMovLiquidaDop] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdPoseedor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
 AS 
 INSERT INTO tm_TraMovLiquida (tmEst,tmTipo,tmNumero,tmIdCia,tmItem,tmFecha,tmFecVence,tmIdPoseedor,tmIdVehiculo,tmIdConcepto,tmDescripcion
,tmVrDebito,tmVrCredito,tmVrAbonado,tmTipoVehic,tmVrBase,tmTarifa,tmReferencia,tmTipDocRef,tmDocRef,tmEstado,tmTipoLiq,tmLiquida,tmCiaLiq,tmSaldoAnt,tmSaldoCia,tmSaldoAntVeh,tmSaldoVehCia)
 SELECT @pmtmEst,D.TipDev,D.Devolucion,D.IdCia,M.Item,D.Fecha,D.FecDoc,M.IdPoseedor,M.IdVehiculo,'0','ORDENES DE PAGO'
,M.VrNeto,0,0,'TERCEROS',M.VrTotalFletes-M.VrDescuento,0,M.Referencia,M.TipMuc,M.Manifiesto,M.EdoLiqCausac,'0',0,'00',0,0,0,0
 FROM Trn_TraDevOdp AS D INNER JOIN Trn_TraOrdenManif AS M ON D.TipDoc=M.TipDoc AND D.OrdPago=M.OrdPago AND D.IdCiaDoc=M.IdCia
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%') AND M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraMovLiquidaOdp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraMovLiquidaOdp] @pmtmEst CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdPoseedor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
 AS 
 INSERT INTO tm_TraMovLiquida (tmEst,tmTipo,tmNumero,tmIdCia,tmItem,tmFecha,tmFecVence,tmIdPoseedor,tmIdVehiculo,tmIdConcepto,tmDescripcion
,tmVrDebito,tmVrCredito,tmVrAbonado,tmTipoVehic,tmVrBase,tmTarifa,tmReferencia,tmTipDocRef,tmDocRef,tmEstado,tmTipoLiq,tmLiquida,tmCiaLiq,tmSaldoAnt,tmSaldoCia,tmSaldoAntVeh,tmSaldoVehCia)
 SELECT @pmtmEst,O.TipDoc,O.OrdPago,O.IdCia,M.Item,O.Fecha,O.Fecha,M.IdPoseedor,M.IdVehiculo,'0','ORDENES DE PAGO'
,0,M.VrNeto,ISNULL(TotAbonado,0),'TERCEROS',M.VrTotalFletes-M.VrDescuento,0,M.Referencia,M.TipMuc,M.Manifiesto,M.EdoLiqCausac,'0',0,'00',0,0,0,0
 FROM Trn_TraOrdenPago AS O INNER JOIN Trn_TraOrdenManif AS M ON O.TipDoc=M.TipDoc AND O.OrdPago=M.OrdPago AND O.IdCia=M.IdCia
 LEFT JOIN (SELECT TipDoc,Documento,IdCiaDoc,SUM(VrAbonado) AS TotAbonado FROM Trn_ComFactura WHERE TipFac='ODP' AND TipDoc='ODP' GROUP BY TipDoc,Documento,IdCiaDoc)
 AS ABO ON O.TipDoc=ABO.TipDoc AND O.OrdPago=ABO.Documento AND O.IdCia=ABO.IdCiaDoc
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%') AND M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraOst]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraOst] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdMercancia VARCHAR(16),@pmtmDescripcion VARCHAR(250),@pmtmCantidad DECIMAL(14,4)
,@pmtmUndMed VARCHAR(10),@pmtmVrUnitario MONEY,@pmtmCantCump DECIMAL(14,4),@pmtmTarifaCump MONEY,@pmtmDocCliente VARCHAR(30),@pmtmTarifPago MONEY,@pmtmPagoCump MONEY
 AS 
 INSERT INTO tm_TraOst (tmNumero,tmItem,tmIdMercancia,tmDescripcion,tmCantidad,tmUndMed,tmVrUnitario,tmTarifPago,tmCantCump,tmTarifaCump,tmPagoCump,tmDocCliente)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmIdMercancia,@pmtmDescripcion,@pmtmCantidad,@pmtmUndMed,@pmtmVrUnitario,@pmtmTarifPago,@pmtmCantCump,@pmtmTarifaCump,@pmtmPagoCump,@pmtmDocCliente)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraOstCum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraOstCum] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
AS 
 INSERT INTO tm_TraOst (tmNumero,tmItem,tmIdMercancia,tmDescripcion,tmCantidad,tmUndMed,tmVrUnitario,tmTarifPago,tmCantCump,tmTarifaCump,tmPagoCump,tmDocCliente)
 SELECT @pmtmNumero,Item,IdMercancia,Descripcion,Cantidad,UndMed,VrUnitario,TarifaPago,Cantidad,VrUnitario,TarifaPago,DocCliente
 FROM Trn_TraOrdenCumDet  
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraOstSel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraOstSel] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
AS 
 INSERT INTO tm_TraOst (tmNumero,tmItem,tmIdMercancia,tmDescripcion,tmCantidad,tmUndMed,tmVrUnitario,tmTarifPago,tmCantCump,tmTarifaCump,tmPagoCump,tmDocCliente)
 SELECT @pmtmNumero,Item,IdMercancia,Descripcion,Cantidad,UndMed,VrUnitario,TarifaPago,CantCump,TarifaCump,PagoCump,DocCliente
 FROM  Trn_TraOrdenDet
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraRemCum] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipRem VARCHAR(3),@pmtmRemesa INT,@pmtmIdCiaRem CHAR(2),@pmtmItemRem INT,@pmtmIdMercancia VARCHAR(16),@pmtmDescripMcias VARCHAR(250),@pmtmCantidad DECIMAL(14,4),@pmtmPesoNeto DECIMAL(14,4),@pmtmUndMed VARCHAR(10),@pmtmVolumen DECIMAL(14,4),@pmtmUndVol VARCHAR(10),@pmtmCases INT,@pmtmCajas INT,@pmtmPalets INT,@pmtmTarifClie MONEY
,@pmtmTarifPago MONEY,@pmtmUndTarif VARCHAR(10),@pmtmUndTarifPago VARCHAR(10),@pmtmCantCargue DECIMAL(14,4),@pmtmPesoCargue DECIMAL(14,4),@pmtmVolCargue DECIMAL(14,4),@pmtmCasesCargue INT,@pmtmCajasCargue INT,@pmtmPaletsCargue INT,@pmtmEstadoCump INT,@pmtmRemision DECIMAL(18,2),@pmtmDocCliente VARCHAR(30),@pmtmReferencia1 VARCHAR(50),@pmtmReferencia2 VARCHAR(50),@pmtmReferencia3 VARCHAR(50),@pmtmDetalle VARCHAR(250)
,@pmtmNitRemite VARCHAR(16),@pmtmRemitente VARCHAR(250),@pmtmDirOrigen VARCHAR(250),@pmtmIdOrigen VARCHAR(8),@pmtmNitDestntario VARCHAR(16),@pmtmDestinatario VARCHAR(250),@pmtmDirDestino VARCHAR(250),@pmtmIdDestino VARCHAR(8),@pmtmTarifTabla MONEY,@pmtmTipoCum VARCHAR(3),@pmtmMotivoSusp VARCHAR(3),@pmtmHoraLlegaCargue SMALLDATETIME,@pmtmHoraEntraCargue SMALLDATETIME
,@pmtmHoraSaleCargue SMALLDATETIME,@pmtmHoraLlegaDescargue SMALLDATETIME,@pmtmHoraEntraDescargue SMALLDATETIME,@pmtmHoraSaleDescargue SMALLDATETIME,@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmNitCliente VARCHAR(16),@pmtmTarifOtros MONEY,@pmtmTray_Vacio1 MONEY,@pmtmTray_Vacio2 MONEY
 AS 
 INSERT INTO tm_TraRemCum (tmNumero,tmItem,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifClie,tmTarifPago,tmUndTarif,tmUndTarifPago,tmCantCargue,tmPesoCargue,tmVolCargue,tmCasesCargue,tmCajasCargue,tmPaletsCargue,tmEstadoCump,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmDetalle,tmNitRemite,tmRemitente
,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmTarifTabla,tmTipoCum,tmMotivoSusp,tmHoraLlegaCargue,tmHoraEntraCargue,tmHoraSaleCargue,tmHoraLlegaDescargue,tmHoraEntraDescargue,tmHoraSaleDescargue,tmCdCCosto,tmCdSubCos,tmNitCliente,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipRem,@pmtmRemesa,@pmtmIdCiaRem,@pmtmItemRem,@pmtmIdMercancia,@pmtmDescripMcias,@pmtmCantidad,@pmtmPesoNeto,@pmtmUndMed,@pmtmVolumen,@pmtmUndVol,@pmtmCases,@pmtmCajas,@pmtmPalets,@pmtmTarifClie,@pmtmTarifPago,@pmtmUndTarif,@pmtmUndTarifPago,@pmtmCantCargue,@pmtmPesoCargue,@pmtmVolCargue,@pmtmCasesCargue,@pmtmCajasCargue,@pmtmPaletsCargue
,@pmtmEstadoCump,@pmtmRemision,@pmtmDocCliente,@pmtmReferencia1,@pmtmReferencia2,@pmtmReferencia3,@pmtmDetalle,@pmtmNitRemite,@pmtmRemitente,@pmtmDirOrigen,@pmtmIdOrigen,@pmtmNitDestntario,@pmtmDestinatario,@pmtmDirDestino,@pmtmIdDestino,@pmtmTarifTabla,@pmtmTipoCum,@pmtmMotivoSusp,@pmtmHoraLlegaCargue,@pmtmHoraEntraCargue,@pmtmHoraSaleCargue,@pmtmHoraLlegaDescargue,@pmtmHoraEntraDescargue,@pmtmHoraSaleDescargue,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmNitCliente,@pmtmTarifOtros,@pmtmTray_Vacio1,@pmtmTray_Vacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum_Muc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraRemCum_Muc] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_TraRemCum (tmNumero,tmItem,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifClie,tmTarifPago,tmUndTarif,tmUndTarifPago,tmCantCargue
,tmPesoCargue,tmVolCargue,tmCasesCargue,tmCajasCargue,tmPaletsCargue,tmEstadoCump,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmDetalle,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino
,tmIdDestino,tmTarifTabla,tmTipoCum,tmMotivoSusp,tmHoraLlegaCargue,tmHoraEntraCargue,tmHoraSaleCargue,tmHoraLlegaDescargue,tmHoraEntraDescargue,tmHoraSaleDescargue,tmCdCCosto,tmCdSubCos,tmNitCliente,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,D.Item,TipRem,Remesa,IdCiaRem,ItemRem,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,R.TarifClie,CASE WHEN D.TarifPago>0 THEN D.TarifPago ELSE R.TarifPago END,UndTarifa,UndTarifPago,Cantidad
,PesoNeto,Volumen,Cases,Cajas,Palets,1,Remision,DocCliente,Referencia1,Referencia2,Referencia3,DetalleCump,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,D.TarifTabla
,'','',FecLlegCargue,FecInicioCargue,FecFinCargue,FecLlegdesc,FecIniciodesc,FecFindesc,'','','',R.TarifOtros,D.RemTrayVacio1,D.RemTrayVacio2
 FROM  Trn_TraManifRem AS D INNER JOIN Trn_TraRemMcias AS R ON D.TipRem=R.TipDoc AND D.Remesa=R.NumOrden AND D.IdCiaRem=R.IdCia AND D.ItemRem=R.Item
 WHERE D.TipDoc=@pmTipDoc AND D.Manifiesto=@pmManifiesto AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraRemCum_Sel] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_TraRemCum (tmNumero,tmItem,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifClie,tmTarifPago,tmUndTarif,tmUndTarifPago,tmCantCargue
,tmPesoCargue,tmVolCargue,tmCasesCargue,tmCajasCargue,tmPaletsCargue,tmEstadoCump,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmDetalle,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino
,tmIdDestino,tmTarifTabla,tmTipoCum,tmMotivoSusp,tmHoraLlegaCargue,tmHoraEntraCargue,tmHoraSaleCargue,tmHoraLlegaDescargue,tmHoraEntraDescargue,tmHoraSaleDescargue,tmCdCCosto,tmCdSubCos,tmNitCliente,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,Item,TipRem,Remesa,IdCiaRem,ItemRem,'0','0',Cantidad,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,TarifClie,TarifPago,UndTarifClie,UndTarifPago,CantCargue,PesoCargue,VolCargue,CasesCargue,CajasCargue,PaletsCargue,EstadoCump
,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Detalle,'0','','','0','0','','','0',TarifFlete,TipoCumRemesa,MotivoSuspRem,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue,CodCCosto,CodSubCos,NitClieRem,TarifOtros,VrTray_Vacio1,VrTray_Vacio2
 FROM Trn_TraCumRemesas 
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemCum_Trr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraRemCum_Trr] @pmtmNumero VARCHAR(5),@pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2)
 AS 
 INSERT INTO tm_TraRemCum (tmNumero,tmItem,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifClie,tmTarifPago,tmUndTarif,tmUndTarifPago,tmCantCargue
,tmPesoCargue,tmVolCargue,tmCasesCargue,tmCajasCargue,tmPaletsCargue,tmEstadoCump,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmDetalle,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino
,tmIdDestino,tmTarifTabla,tmTipoCum,tmMotivoSusp,tmHoraLlegaCargue,tmHoraEntraCargue,tmHoraSaleCargue,tmHoraLlegaDescargue,tmHoraEntraDescargue,tmHoraSaleDescargue,tmCdCCosto,tmCdSubCos,tmNitCliente,tmTarifOtros,tmTray_Vacio1,tmTray_Vacio2)
SELECT @pmtmNumero,D.Item,D.TipRem,D.Remesa,D.IdCiaRem,D.ItemRem,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,TarifClie,TarifPago,UndTarifa,UndTarifPago,CantidadCump
,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,0,Remision,DocCliente,Referencia1,Referencia2,Referencia3,D.Comentarios,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,TarifTabla
,'','',Null,Null,Null,Null,Null,Null,'','','',R.TarifOtros,0,0
FROM Trn_TraTrasladoRem AS D INNER JOIN Trn_TraRemMcias AS R ON D.TipRem=R.TipDoc AND D.Remesa=R.NumOrden AND D.IdCiaRem=R.IdCia AND D.ItemRem=R.Item
WHERE D.TipDoc=@pmTipDoc AND D.Traslado=@pmTraslado AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemFact]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraRemFact] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipoReg INT,@pmtmTipRem VARCHAR(3),@pmtmRemesa INT,@pmtmIdCiaRem CHAR(2),@pmtmItemRem INT,@pmtmDescripcion VARCHAR(250),@pmtmCantidad DECIMAL(14,4),@pmtmVrUnitario MONEY,@pmtmVrCosto MONEY,@pmtmUndTarifa VARCHAR(10),@pmtmUndCosto VARCHAR(10),@pmtmUnidades DECIMAL(14,4),@pmtmPesoNeto DECIMAL(14,4),@pmtmUndMed VARCHAR(10),@pmtmVolumen DECIMAL(14,4)
,@pmtmUndVol VARCHAR(10),@pmtmCases INT,@pmtmCajas INT,@pmtmPalets INT,@pmtmTarifaIva DECIMAL(14,4),@pmtmVrIva MONEY,@pmtmTarifaDct DECIMAL(14,4),@pmtmVrDscto MONEY,@pmtmTarifaRet DECIMAL(14,4),@pmtmVrRetFte MONEY,@pmtmTarifaIca DECIMAL(14,4),@pmtmVrReteIca MONEY,@pmtmVrFaltante MONEY,@pmtmRemision DECIMAL(18,2),@pmtmDocCliente VARCHAR(30),@pmtmReferencia1 VARCHAR(50),@pmtmReferencia2 VARCHAR(50),@pmtmReferencia3 VARCHAR(50)
,@pmtmCdMercancia VARCHAR(16),@pmtmCdConc VARCHAR(4),@pmtmCdCCosto VARCHAR(16),@pmtmCdSubCos VARCHAR(16),@pmtmNitTercero VARCHAR(16),@pmtmCdAgencia VARCHAR(16),@pmtmpVehiculo VARCHAR(10),@pmtmTipoVehic VARCHAR(10),@pmtmNitRemite VARCHAR(16),@pmtmRemitente VARCHAR(250),@pmtmDirOrigen VARCHAR(250),@pmtmIdOrigen VARCHAR(8),@pmtmNitDestntario VARCHAR(16),@pmtmDestinatario VARCHAR(250),@pmtmDirDestino VARCHAR(250)
,@pmtmIdDestino VARCHAR(8),@pmtmCantFalt DECIMAL(14,4),@pmtmUnidadFalt VARCHAR(10),@pmtmCdTarRet VARCHAR(4),@pmtmCdTarIca VARCHAR(4),@pmtmCdTarDct VARCHAR(4),@pmtmPedRem INT,@pmtmCiaPed CHAR(2),@pmtmEtdoFact INT,@pmtmFecRemesa SMALLDATETIME,@pmtmIntCumplido INT,@pmtmVrDeclarado MONEY,@pmtmTarifSeguro DECIMAL(14,4),@pmtmVrSeguro MONEY,@pmtmNitAsegurad VARCHAR(16),@pmtmCostoCump MONEY,@pmtmTipoOrd VARCHAR(3),@pmtmNumOrden INT,@pmtmIdCiaOrd CHAR(2)
,@pmtmCantPago DECIMAL(14,4),@pmtmVrAutoIca MONEY,@pmtmRemTransb INT,@pmtmCostoAdic MONEY,@pmtmNitMucTbdo VARCHAR(16),@pmtmTipoNov INT,@pmtmItemOrd INT,@pmtmTarifIat DECIMAL(14,4),@pmtmVrAviTab MONEY,@pmtmCdTarifIat VARCHAR(4),@pmtmTarifBom DECIMAL(14,4),@pmtmVrSobBom MONEY,@pmtmCdTarifBom VARCHAR(4),@pmtmVrAutoIat MONEY,@pmtmVrAutoBom MONEY
,@pmtmEstado INT,@pmtmObserv VARCHAR(500),@pmtmTotFletes MONEY,@pmtmTotOtros MONEY,@pmtmTotCargos MONEY,@pmtmTotDctos MONEY,@pmtmTotCostoAfi MONEY,@pmtmTotCostoRem MONEY,@pmtmReteCree MONEY,@pmtmTarifaCree DECIMAL(14,4),@pmtmCdTarCree VARCHAR(4),@pmtmReteIva MONEY,@pmtmTarifaRiv DECIMAL(14,4),@pmtmCdTarRiv VARCHAR(4),@pmtmTarifaAri DECIMAL(14,4),@pmtmCdTarAri VARCHAR(4),@pmtmBaseIva MONEY,@pmtmBaseRet MONEY,@pmtmBaseIca MONEY,@pmtmBaseRiv MONEY,@pmtmVrNeto MONEY,@pmtmTray_Vacio1 MONEY,@pmtmTray_Vacio2 MONEY
 AS 
 INSERT INTO tm_TraRemFact (tmNumero,tmItem,tmTipoReg,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmDescripcion,tmCantidad,tmVrUnitario,tmVrCosto,tmUndTarifa,tmUndCosto,tmUnidades,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDscto,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrReteIca,tmVrFaltante,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmCdMercancia,tmCdConc,tmCdCCosto,tmCdSubCos,tmNitTercero,tmCdAgencia
,tmpVehiculo,tmTipoVehic,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCantFalt,tmUnidadFalt,tmCdTarRet,tmCdTarIca,tmCdTarDct,tmPedRem,tmCiaPed,tmEtdoFact,tmFecRemesa,tmIntCumplido,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmNitAsegurad,tmCostoCump,tmTipoOrd,tmNumOrden,tmIdCiaOrd,tmCantPago,tmVrAutoIca,tmRemTransb,tmCostoAdic,tmNitMucTbdo,tmTipoNov,tmItemOrd,tmTarifIat,tmVrAviTab,tmCdTarifIat,tmTarifBom,tmVrSobBom,tmCdTarifBom,tmVrAutoIat,tmVrAutoBom
,tmEstado,tmObserv,tmTotFletes,tmTotOtros,tmTotCargos,tmTotDctos,tmTotCostoAfi,tmTotCostoRem,tmReteCree,tmTarifaCree,tmCdTarCree,tmReteIva,tmTarifaRiv,tmCdTarRiv,tmTarifaAri,tmCdTarAri,tmBaseIva,tmBaseRet,tmBaseIca,tmBaseRiv,tmVrNeto,tmTray_Vacio1,tmTray_Vacio2)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipoReg,@pmtmTipRem,@pmtmRemesa,@pmtmIdCiaRem,@pmtmItemRem,@pmtmDescripcion,@pmtmCantidad,@pmtmVrUnitario,@pmtmVrCosto,@pmtmUndTarifa,@pmtmUndCosto,@pmtmUnidades,@pmtmPesoNeto,@pmtmUndMed,@pmtmVolumen,@pmtmUndVol,@pmtmCases,@pmtmCajas,@pmtmPalets,@pmtmTarifaIva,@pmtmVrIva,@pmtmTarifaDct,@pmtmVrDscto,@pmtmTarifaRet,@pmtmVrRetFte,@pmtmTarifaIca,@pmtmVrReteIca,@pmtmVrFaltante,@pmtmRemision
,@pmtmDocCliente,@pmtmReferencia1,@pmtmReferencia2,@pmtmReferencia3,@pmtmCdMercancia,@pmtmCdConc,@pmtmCdCCosto,@pmtmCdSubCos,@pmtmNitTercero,@pmtmCdAgencia,@pmtmpVehiculo,@pmtmTipoVehic,@pmtmNitRemite,@pmtmRemitente,@pmtmDirOrigen,@pmtmIdOrigen,@pmtmNitDestntario,@pmtmDestinatario,@pmtmDirDestino,@pmtmIdDestino,@pmtmCantFalt,@pmtmUnidadFalt,@pmtmCdTarRet,@pmtmCdTarIca,@pmtmCdTarDct,@pmtmPedRem,@pmtmCiaPed,@pmtmEtdoFact,@pmtmFecRemesa,@pmtmIntCumplido
,@pmtmVrDeclarado,@pmtmTarifSeguro,@pmtmVrSeguro,@pmtmNitAsegurad,@pmtmCostoCump,@pmtmTipoOrd,@pmtmNumOrden,@pmtmIdCiaOrd,@pmtmCantPago,@pmtmVrAutoIca,@pmtmRemTransb,@pmtmCostoAdic,@pmtmNitMucTbdo,@pmtmTipoNov,@pmtmItemOrd,@pmtmTarifIat,@pmtmVrAviTab,@pmtmCdTarifIat,@pmtmTarifBom,@pmtmVrSobBom,@pmtmCdTarifBom,@pmtmVrAutoIat,@pmtmVrAutoBom,@pmtmEstado,@pmtmObserv,@pmtmTotFletes,@pmtmTotOtros,@pmtmTotCargos,@pmtmTotDctos,@pmtmTotCostoAfi,@pmtmTotCostoRem,@pmtmReteCree,@pmtmTarifaCree,@pmtmCdTarCree,@pmtmReteIva,@pmtmTarifaRiv,@pmtmCdTarRiv,@pmtmTarifaAri,@pmtmCdTarAri,@pmtmBaseIva,@pmtmBaseRet,@pmtmBaseIca,@pmtmBaseRiv,@pmtmVrNeto,@pmtmTray_Vacio1,@pmtmTray_Vacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_TraRemFact_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_TraRemFact_Sel] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmtmNumero VARCHAR(5)
 AS 
 INSERT INTO tm_TraRemFact (tmNumero,tmItem,tmTipoReg,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmDescripcion,tmCantidad,tmVrUnitario,tmVrCosto,tmUndTarifa,tmUndCosto,tmUnidades,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets
,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDscto,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrReteIca,tmVrFaltante,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmCdMercancia,tmCdConc,tmCdCCosto,tmCdSubCos,tmNitTercero,tmCdAgencia
,tmpVehiculo,tmTipoVehic,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCantFalt,tmUnidadFalt,tmCdTarRet,tmCdTarIca,tmCdTarDct,tmPedRem,tmCiaPed,tmEtdoFact,tmFecRemesa,tmIntCumplido
,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmNitAsegurad,tmCostoCump,tmTipoOrd,tmNumOrden,tmIdCiaOrd,tmCantPago,tmVrAutoIca,tmRemTransb,tmCostoAdic,tmNitMucTbdo,tmTipoNov,tmItemOrd,tmTarifIat,tmVrAviTab,tmCdTarifIat,tmTarifBom,tmVrSobBom,tmCdTarifBom,tmVrAutoIat,tmVrAutoBom
,tmEstado,tmObserv,tmTotFletes,tmTotOtros,tmTotCargos,tmTotDctos,tmTotCostoAfi,tmTotCostoRem,tmReteCree,tmTarifaCree,tmCdTarCree,tmReteIva,tmTarifaRiv,tmCdTarRiv,tmTarifaAri,tmCdTarAri,tmBaseIva,tmBaseRet,tmBaseIca,tmBaseRiv,tmVrNeto,tmTray_Vacio1,tmTray_Vacio2)
 SELECT @pmtmNumero,Item,TipoReg,TipRem,Remesa,IdCiaRem,ItemRem,Descripcion,Cantidad,VrUnitario,VrCosto,UndTarifa,UndCosto,Unidades,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets
,TarifaIva,VrImpuesto,TarifaDct,VrDescuento,TarifaRet,VrRetencion,TarifaIca,VrReteIca,VrFaltante,Remision,DocCliente,Referencia1,Referencia2,Referencia3,CdMercancia,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia
,pVehiculo,TipoAfiVehic,'0','','',IdOrigen,'0','','',IdDestino,CantidadFalt,UnidadFalt,CodTarRet,CodTarIca,CodTarDct,NumPedRem,CiaPedRem,0,FecRemesa,0,VrDeclMcia,TarifaSeg,VrSeguroRem,NitAsegurad,0,TipDocRef,NumDocRef,IdCiaRef,CantPago,VrAutRetIca
,RemTransb,CostoAdicTbdo,NitMucTbdo,TipoNovFact,ItemDocRef,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom,VrAutoIat,VrAutoBom
,0,'',0,0,0,0,0,0,0,0,'',0,0,'',0,'',0,0,0,0,0,VrTray_Vacio1,VrTray_Vacio2
 FROM Trn_TraFacRemesas
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ValesCred]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_ValesCred] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipo VARCHAR(3),@pmtmRango INT,@pmtmNumSerie VARCHAR(5),@pmtmNumVale INT,@pmtmFecha SMALLDATETIME,@pmtmHoraServ VARCHAR(10),@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdCuenta VARCHAR(16)
,@pmtmNumMovil VARCHAR(10),@pmtmCentCosto VARCHAR(50),@pmtmUnidades DECIMAL(14,4),@pmtmHoraRec DECIMAL(14,4),@pmtmHoraEspera DECIMAL(14,4),@pmtmFactUnid BIT,@pmtmFactRutas BIT,@pmtmFactHoras BIT,@pmtmVrPago MONEY,@pmtmVrCobro MONEY,@pmtmPlacaVeh VARCHAR(10),@pmtmCdConductor VARCHAR(16)
,@pmtmConductor VARCHAR(150),@pmtmCantidad INT,@pmtmUsuarios VARCHAR(1000),@pmtmObservacion VARCHAR(1000),@pmtmNumAuto BIT,@pmtmRutas VARCHAR(150),@pmtmRadica INT,@pmtmCiaRad CHAR(2),@pmtmItemRad INT
 AS 
 INSERT INTO tm_ValesCred (tmNumero,tmItem,tmTipo,tmRango,tmNumSerie,tmNumVale,tmFecha,tmHoraServ,tmIdCliente,tmIdAgencia,tmIdCuenta,tmNumMovil,tmCentCosto,tmUnidades,tmHoraRec,tmHoraEspera,tmFactUnid,tmFactRutas,tmFactHoras,tmVrPago,tmVrCobro,tmPlacaVeh
,tmCdConductor,tmConductor,tmCantidad,tmUsuarios,tmObservacion,tmNumAuto,tmRutas,tmRadica,tmCiaRad,tmItemRad)
 VALUES (@pmtmNumero,@pmtmItem,@pmtmTipo,@pmtmRango,@pmtmNumSerie,@pmtmNumVale,@pmtmFecha,@pmtmHoraServ,@pmtmIdCliente,@pmtmIdAgencia,@pmtmIdCuenta,@pmtmNumMovil,@pmtmCentCosto,@pmtmUnidades,@pmtmHoraRec,@pmtmHoraEspera,@pmtmFactUnid,@pmtmFactRutas,@pmtmFactHoras,@pmtmVrPago,@pmtmVrCobro
,@pmtmPlacaVeh,@pmtmCdConductor,@pmtmConductor,@pmtmCantidad,@pmtmUsuarios,@pmtmObservacion,@pmtmNumAuto,@pmtmRutas,@pmtmRadica,@pmtmCiaRad,@pmtmItemRad)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ValesCred_Dev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_ValesCred_Dev]  @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
,@pmNumDev INT,@pmtmNumero VARCHAR(5)
 AS
 INSERT INTO tm_ValesCred (tmNumero,tmItem,tmTipo,tmRango,tmNumSerie,tmNumVale,tmFecha,tmHoraServ,tmIdCliente,tmIdAgencia,tmIdCuenta,tmNumMovil,tmCentCosto,tmUnidades,tmHoraRec
,tmHoraEspera,tmFactUnid,tmFactRutas,tmFactHoras,tmVrPago,tmVrCobro,tmPlacaVeh,tmCdConductor,tmConductor,tmCantidad,tmUsuarios,tmObservacion,tmNumAuto,tmRutas,tmRadica,tmCiaRad,tmItemRad)
 SELECT @pmtmNumero,Item,TipoRango,IdRango,NumSerie,NumForma,Fecha,HoraServ,IdCliente,IdAgencia,IdCuenta,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera
,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,PlacaVeh,CdConductor,NomConductor,CantPasaj,Usuarios,Observacion,0,'',nRadica,IdCia,Item
 FROM Trn_Vales
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia AND Anulado<>0 AND NumDev=@pmNumDev
GO
/****** Object:  StoredProcedure [dbo].[paInstm_ValesCred_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_ValesCred_Sel]  @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
,@pmtmNumero VARCHAR(5)
 AS
 INSERT INTO tm_ValesCred (tmNumero,tmItem,tmTipo,tmRango,tmNumSerie,tmNumVale,tmFecha,tmHoraServ,tmIdCliente,tmIdAgencia,tmIdCuenta,tmNumMovil,tmCentCosto,tmUnidades,tmHoraRec
,tmHoraEspera,tmFactUnid,tmFactRutas,tmFactHoras,tmVrPago,tmVrCobro,tmPlacaVeh,tmCdConductor,tmConductor,tmCantidad,tmUsuarios,tmObservacion,tmNumAuto,tmRutas,tmRadica,tmCiaRad,tmItemRad)
 SELECT @pmtmNumero,Item,TipoRango,IdRango,NumSerie,NumForma,Fecha,HoraServ,IdCliente,IdAgencia,IdCuenta,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera
,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,PlacaVeh,CdConductor,NomConductor,CantPasaj,Usuarios,Observacion,0,'',nRadica,IdCia,Item
 FROM Trn_Vales
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vce]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_vce] @pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmValorFactura MONEY,@pmtmValorAbono MONEY,@pmtmIdVehiculo VARCHAR(10),@pmtmFecUltPago SMALLDATETIME
 AS 
 INSERT INTO tm_vce (tmTipDoc,tmDocumento,tmIdCia,tmItem,tmValorFactura,tmValorAbono,tmIdVehiculo,tmFecUltPago)
 VALUES (@pmtmTipDoc,@pmtmDocumento,@pmtmIdCia,@pmtmItem,@pmtmValorFactura,@pmtmValorAbono,@pmtmIdVehiculo,@pmtmFecUltPago)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paInstm_vence] @pmtmEst CHAR(2), @pmtmTipDoc VARCHAR(3), @pmtmDocumento INT, @pmtmIdCia CHAR(2), @pmtmItem INT, @pmtmFecEmision SMALLDATETIME, @pmtmFecVence SMALLDATETIME, @pmtmValorFactura MONEY
, @pmtmValorAbono MONEY, @pmtmIdPropietario VARCHAR(16), @pmtmIdVehiculo VARCHAR(10),@pmtmIdAgencia VARCHAR(16), @pmtmVehPropio BIT, @pmtmIdConductor VARCHAR(16), @pmtmComision DECIMAL(14,4), @pmtmIdCargo VARCHAR(4), @pmtmIdClase VARCHAR(4)
, @pmtmIdConcepto VARCHAR(4), @pmtmFecUltPago SMALLDATETIME, @pmtmNotaInt INT, @pmtmFecUltLiquida SMALLDATETIME, @pmtmFactura VARCHAR(15),@pmtmReferencia VARCHAR(50), @pmtmDetalle VARCHAR(100), @pmtmObservacion VARCHAR(250)
, @pmtmModalidad VARCHAR(10), @pmtmIdEstado VARCHAR(4), @pmtmIdUsuario VARCHAR(11), @pmtmTipCom VARCHAR(3), @pmtmComprobante INT, @pmtmIdCiaCom CHAR(2), @pmtmTipDcm VARCHAR(3), @pmtmDocmto INT,@pmtmIdCiaDcm CHAR(2), @pmtmTimeSys SMALLDATETIME
, @pmtmVencido MONEY, @pmtmPorVencer MONEY, @pmtmVence1 MONEY, @pmtmVence2 MONEY, @pmtmVence3 MONEY, @pmtmVence4 MONEY
AS
 INSERT INTO tm_vence (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono, tmIdPropietario, tmIdVehiculo, 
                      tmIdAgencia, tmVehPropio, tmIdConductor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmNotaInt, tmFecUltLiquida, tmFactura, 
                      tmReferencia, tmDetalle, tmObservacion, tmModalidad, tmIdEstado, tmIdUsuario, tmTipCom, tmComprobante, tmIdCiaCom, tmTipDcm, tmDocmto, 
                      tmIdCiaDcm, tmTimeSys, tmVencido, tmPorVencer, tmVence1, tmVence2, tmVence3, tmVence4)
 VALUES (@pmtmEst, @pmtmTipDoc, @pmtmDocumento, @pmtmIdCia, @pmtmItem, @pmtmFecEmision, @pmtmFecVence, @pmtmValorFactura, @pmtmValorAbono, @pmtmIdPropietario
, @pmtmIdVehiculo,@pmtmIdAgencia, @pmtmVehPropio, @pmtmIdConductor, @pmtmComision, @pmtmIdCargo, @pmtmIdClase, @pmtmIdConcepto, @pmtmFecUltPago, @pmtmNotaInt, @pmtmFecUltLiquida, @pmtmFactura
,@pmtmReferencia, @pmtmDetalle, @pmtmObservacion, @pmtmModalidad, @pmtmIdEstado, @pmtmIdUsuario, @pmtmTipCom, @pmtmComprobante, @pmtmIdCiaCom, @pmtmTipDcm, @pmtmDocmto
,@pmtmIdCiaDcm, @pmtmTimeSys, @pmtmVencido, @pmtmPorVencer, @pmtmVence1, @pmtmVence2, @pmtmVence3, @pmtmVence4)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Adm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstm_vence_Adm] @pmtmEst CHAR(2),@pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS
  IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
   INSERT INTO tm_vence  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono, tmIdPropietario
 , tmIdVehiculo,tmIdAgencia, tmVehPropio, tmIdConductor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmNotaInt, tmFecUltLiquida, tmFactura
 ,tmReferencia, tmDetalle, tmObservacion, tmModalidad, tmIdEstado, tmIdUsuario, tmTipCom, tmComprobante, tmIdCiaCom, tmTipDcm, tmDocmto
 ,tmIdCiaDcm, tmTimeSys, tmVencido, tmPorVencer, tmVence1, tmVence2, tmVence3, tmVence4)
  SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia,Item,FecEmision,V.FecVence,ValorFactura,ValorAbono,IdCliente, V.IdVehiculo,IdAgencia,V.VehPropio, IdVendedor
 ,Comision ,IdCargo, V.IdClase, V.IdConcepto,FecUltPago,NotaInt,FecUltLiquida,V.Factura, V.Referencia,Detalle,C.Observacion,Modalidad,C.IdEstado,C.IdUsuario,TipCom, Comprobante, IdCiaCom
 ,TipRec,Recibo,IdCiaRec,TimeSys,0,0,0,0,0,0
  FROM Trn_CausacVence AS V INNER JOIN Trn_Causacion AS C ON V.TipDoc=C.TipDoc AND V.Documento=C.Documento AND V.IdCia=C.IdCia
  INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
  WHERE (ValorFactura-ValorAbono)>@pmSaldo  AND  V.TipDoc IN ('ADM','OTR')  AND FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND V.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
  AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.TipDoc LIKE ISNULL(@pmTipDoc,'%')
  ORDER BY V.TipDoc, V.IdCia,V.Documento
ELSE
   INSERT INTO tm_vence  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono, tmIdPropietario
 , tmIdVehiculo,tmIdAgencia, tmVehPropio, tmIdConductor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmNotaInt, tmFecUltLiquida, tmFactura
 ,tmReferencia, tmDetalle, tmObservacion, tmModalidad, tmIdEstado, tmIdUsuario, tmTipCom, tmComprobante, tmIdCiaCom, tmTipDcm, tmDocmto
 ,tmIdCiaDcm, tmTimeSys, tmVencido, tmPorVencer, tmVence1, tmVence2, tmVence3, tmVence4)
  SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia,Item,FecEmision,V.FecVence,ValorFactura,ValorAbono,IdCliente, V.IdVehiculo,IdAgencia,V.VehPropio, IdVendedor
 ,Comision ,IdCargo, V.IdClase, V.IdConcepto,FecUltPago,NotaInt,FecUltLiquida,V.Factura, V.Referencia,Detalle,C.Observacion,Modalidad,C.IdEstado,C.IdUsuario,TipCom, Comprobante, IdCiaCom
 ,TipRec,Recibo,IdCiaRec,TimeSys,0,0,0,0,0,0
  FROM Trn_CausacVence AS V INNER JOIN Trn_Causacion AS C ON V.TipDoc=C.TipDoc AND V.Documento=C.Documento AND V.IdCia=C.IdCia
  INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
  WHERE (ValorFactura-ValorAbono)>@pmSaldo  AND  V.TipDoc IN ('ADM','OTR')   AND V.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
  AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.TipDoc LIKE ISNULL(@pmTipDoc,'%')
  ORDER BY V.TipDoc, V.IdCia,V.Documento
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Fvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_vence_Fvc] @pmtmEst CHAR(2), @pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS
  INSERT INTO tm_vence  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono, tmIdPropietario
 , tmIdVehiculo,tmIdAgencia, tmVehPropio, tmIdConductor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmNotaInt, tmFecUltLiquida, tmFactura
 ,tmReferencia, tmDetalle, tmObservacion, tmModalidad, tmIdEstado, tmIdUsuario, tmTipCom, tmComprobante, tmIdCiaCom, tmTipDcm, tmDocmto
 ,tmIdCiaDcm, tmTimeSys, tmVencido, tmPorVencer, tmVence1, tmVence2, tmVence3, tmVence4)
  SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia,Item,FecEmision,V.FecVence,ValorFactura,ValorAbono,V.IdCliente, V.IdVehiculo,V.IdAgencia,V.VehPropio, V.IdVendedor
 ,V.Comision ,V.IdCargo, V.IdClase, V.IdConcepto,FecUltPago,NotaInt,FecUltLiquida,V.Factura, V.Referencia,Detalle,F.Observacion,'FVC',F.IdEstado,F.IdUsuario,TipCom, Comprobante, IdCiaCom
 ,'FVC',0,'00',TimeSys,0,0,0,0,0,0
  FROM Trn_CausacVence AS V INNER JOIN Trn_CausaVales AS F ON V.TipDoc=F.TipDoc AND V.Documento=F.Documento AND V.IdCia=F.IdCia
  INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
  WHERE (ValorFactura-ValorAbono)>@pmSaldo  AND  V.TipDoc='FVC'
  AND (FecEmision>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecEmision<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
  AND V.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND V.IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND V.IdClase LIKE ISNULL(@pmIdClase,'%') AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Not]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_vence_Not] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3), @pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS
  INSERT INTO tm_vence  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono, tmIdPropietario
 , tmIdVehiculo,tmIdAgencia, tmVehPropio, tmIdConductor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmNotaInt, tmFecUltLiquida, tmFactura
 ,tmReferencia, tmDetalle, tmObservacion, tmModalidad, tmIdEstado, tmIdUsuario, tmTipCom, tmComprobante, tmIdCiaCom, tmTipDcm, tmDocmto
 ,tmIdCiaDcm, tmTimeSys, tmVencido, tmPorVencer, tmVence1, tmVence2, tmVence3, tmVence4)
  SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia,Item,FecEmision,V.FecVence,ValorFactura,ValorAbono,V.IdCliente, V.IdVehiculo,V.IdAgencia,V.VehPropio, V.IdVendedor
 ,V.Comision ,V.IdCargo, V.IdClase, V.IdConcepto,FecUltPago,NotaInt,FecUltLiquida,V.Factura, V.Referencia,Detalle,N.Observacion,'ND1',N.IdEstado,N.IdUsuario,TipCom, Comprobante, IdCiaCom
 ,TipDcm,N.Documento,IdCiaDoc,TimeSys,0,0,0,0,0,0
  FROM Trn_CausacVence AS V INNER JOIN Trn_NotasBuses AS N ON V.TipDoc=N.TipDoc AND V.Documento=N.NumNota AND V.IdCia=N.IdCia
  INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
  WHERE (ValorFactura-ValorAbono)>@pmSaldo  AND  V.TipDoc=@pmTipDoc
  AND (FecEmision>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecEmision<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
  AND V.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND V.IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND V.IdClase LIKE ISNULL(@pmIdClase,'%') AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_vence_Pre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_vence_Pre] @pmtmEst CHAR(2),@pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS
   INSERT INTO tm_vence  (tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono, tmIdPropietario
 , tmIdVehiculo,tmIdAgencia, tmVehPropio, tmIdConductor, tmComision, tmIdCargo, tmIdClase, tmIdConcepto, tmFecUltPago, tmNotaInt, tmFecUltLiquida, tmFactura
 ,tmReferencia, tmDetalle, tmObservacion, tmModalidad, tmIdEstado, tmIdUsuario, tmTipCom, tmComprobante, tmIdCiaCom, tmTipDcm, tmDocmto
 ,tmIdCiaDcm, tmTimeSys, tmVencido, tmPorVencer, tmVence1, tmVence2, tmVence3, tmVence4)
  SELECT @pmtmEst,V.TipDoc, V.Documento, V.IdCia,Item,FecEmision,V.FecVence,ValorFactura,ValorAbono,IdCliente, V.IdVehiculo,IdAgencia,V.VehPropio, IdVendedor
 ,Comision ,IdCargo, V.IdClase, V.IdConcepto,FecUltPago,NotaInt,FecUltLiquida,V.Factura, V.Referencia,Detalle,P.Observacion,TipoCuota,P.IdEstado,P.IdUsuario,TipCom, Comprobante, IdCiaCom
 ,TipRec,Recibo,IdCiaRec,TimeSys,0,0,0,0,0,0
  FROM Trn_CausacVence AS V INNER JOIN Trn_Prestamos AS P ON V.TipDoc=P.TipDoc AND V.Documento=P.PrestamoID AND V.IdCia=P.IdCia
  INNER JOIN Vehiculos AS VH ON V.IdVehiculo=VH.IdVehiculo 
  WHERE (ValorFactura-ValorAbono)>@pmSaldo  AND  V.TipDoc='PRE' 
  AND FecEmision BETWEEN ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME))  AND ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME))
  AND V.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND V.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdClase LIKE ISNULL(@pmIdClase,'%')
  AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.TipDoc LIKE ISNULL(@pmTipDoc,'%')
GO
/****** Object:  StoredProcedure [dbo].[paInstm_Ventas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_Ventas] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmIdCia CHAR(2),@pmtmTipDoc VARCHAR(3)
,@pmtmIdConcepto VARCHAR(4),@pmtmIdCliente VARCHAR(16),@pmtmCdAgencia VARCHAR(16),@pmtmIdVend VARCHAR(16),@pmtmCdLocal VARCHAR(8),@pmtmCdSubzona VARCHAR(4),@pmtmPeriodo VARCHAR(6)
 AS 
 INSERT INTO tm_Ventas (tmEst,tmItem,tmIdProducto,tmIdBodega,tmIdCia,tmTipDoc,tmIdConcepto,tmIdCliente,tmCdAgencia,tmIdVend,tmCdLocal,tmCdSubzona,tmPeriodo)
 VALUES (@pmtmEst,@pmtmItem,@pmtmIdProducto,@pmtmIdBodega,@pmtmIdCia,@pmtmTipDoc,@pmtmIdConcepto,@pmtmIdCliente,@pmtmCdAgencia,@pmtmIdVend
,@pmtmCdLocal,@pmtmCdSubzona,@pmtmPeriodo)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_VentasCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_VentasCom] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmUnidades DECIMAL(14,4),@pmtmVentaNeto MONEY,@pmtmCostoNeto MONEY,@pmtmImpuestos MONEY,@pmtmImpGlobal MONEY
,@pmtmSoldicom MONEY,@pmtmVolumen DECIMAL(14,4),@pmtmUnidades2 DECIMAL(14,4),@pmtmVentaNeto2 MONEY,@pmtmCostoNeto2 MONEY,@pmtmImpuestos2 MONEY,@pmtmImpGlobal2 MONEY
,@pmtmSoldicom2 MONEY,@pmtmVolumen2 DECIMAL(14,4),@pmtmImpConsumo MONEY,@pmtmImpConsumo2 MONEY,@pmtmImpuBa MONEY,@pmtmImpuBa2 MONEY,@pmtmImpuCup MONEY,@pmtmImpuCup2 MONEY
 AS 
 INSERT INTO tm_VentasCom (tmEst,tmItem,tmUnidades,tmVentaNeto,tmCostoNeto,tmImpuestos,tmImpGlobal,tmSoldicom,tmVolumen,tmUnidades2,tmVentaNeto2,tmCostoNeto2,tmImpuestos2,tmImpGlobal2,tmSoldicom2,tmVolumen2,tmImpConsumo,tmImpConsumo2,tmImpuBa,tmImpuBa2,tmImpuCup,tmImpuCup2)
 VALUES (@pmtmEst,@pmtmItem,@pmtmUnidades,@pmtmVentaNeto,@pmtmCostoNeto,@pmtmImpuestos,@pmtmImpGlobal,@pmtmSoldicom,@pmtmVolumen,@pmtmUnidades2,@pmtmVentaNeto2,@pmtmCostoNeto2
,@pmtmImpuestos2,@pmtmImpGlobal2,@pmtmSoldicom2,@pmtmVolumen2,@pmtmImpConsumo,@pmtmImpConsumo2,@pmtmImpuBa,@pmtmImpuBa2,@pmtmImpuCup,@pmtmImpuCup2)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_VentasDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_VentasDet] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmEntradas DECIMAL(14,4),@pmtmSalidas DECIMAL(14,4),@pmtmVtaBrutoEnt MONEY,@pmtmVtaBrutoSal MONEY,@pmtmCostoEnt MONEY,@pmtmCostoSal MONEY
,@pmtmDctosEnt MONEY,@pmtmDctosSal MONEY,@pmtmIvaEnt MONEY,@pmtmIvaSal MONEY,@pmtmReteFteEnt MONEY,@pmtmReteFteSal MONEY,@pmtmReteIcaEnt MONEY,@pmtmReteIcaSal MONEY,@pmtmSobtasaEnt MONEY
,@pmtmSobtasaSal MONEY,@pmtmImpGlobalEnt MONEY,@pmtmImpGlobalSal MONEY,@pmtmSoldicomEnt MONEY,@pmtmSoldicomSal MONEY,@pmtmUnidVolumen DECIMAL(14,4),@pmtmComision DECIMAL(14,4),@pmtmImpConEnt MONEY,@pmtmImpConSal MONEY
,@pmtmImpuBaEnt MONEY,@pmtmImpuBaSal MONEY,@pmtmImpuCupEnt MONEY,@pmtmImpuCupSal MONEY
 AS 
 INSERT INTO tm_VentasDet (tmEst,tmItem,tmEntradas,tmSalidas,tmVtaBrutoEnt,tmVtaBrutoSal,tmCostoEnt,tmCostoSal,tmDctosEnt,tmDctosSal,tmIvaEnt,tmIvaSal,tmReteFteEnt,tmReteFteSal,tmReteIcaEnt,tmReteIcaSal,tmSobtasaEnt,tmSobtasaSal
,tmImpGlobalEnt,tmImpGlobalSal,tmSoldicomEnt,tmSoldicomSal,tmUnidVolumen,tmComision,tmImpConEnt,tmImpConSal,tmImpuBaEnt,tmImpuBaSal,tmImpuCupEnt,tmImpuCupSal)
 VALUES (@pmtmEst,@pmtmItem,@pmtmEntradas,@pmtmSalidas,@pmtmVtaBrutoEnt,@pmtmVtaBrutoSal,@pmtmCostoEnt,@pmtmCostoSal,@pmtmDctosEnt,@pmtmDctosSal,@pmtmIvaEnt,@pmtmIvaSal,@pmtmReteFteEnt,@pmtmReteFteSal
,@pmtmReteIcaEnt,@pmtmReteIcaSal,@pmtmSobtasaEnt,@pmtmSobtasaSal,@pmtmImpGlobalEnt,@pmtmImpGlobalSal,@pmtmSoldicomEnt,@pmtmSoldicomSal,@pmtmUnidVolumen,@pmtmComision,@pmtmImpConEnt,@pmtmImpConSal,@pmtmImpuBaEnt,@pmtmImpuBaSal,@pmtmImpuCupEnt,@pmtmImpuCupSal)
GO
/****** Object:  StoredProcedure [dbo].[paInstm_VentasRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInstm_VentasRes] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmEnero DECIMAL(14,4),@pmtmFebrero DECIMAL(14,4),@pmtmMarzo DECIMAL(14,4)
,@pmtmAbril DECIMAL(14,4),@pmtmMayo DECIMAL(14,4),@pmtmJunio DECIMAL(14,4),@pmtmJulio DECIMAL(14,4),@pmtmAgosto DECIMAL(14,4)
,@pmtmSeptiembre DECIMAL(14,4),@pmtmOctubre DECIMAL(14,4),@pmtmNoviembre DECIMAL(14,4),@pmtmDiciembre DECIMAL(14,4)
 AS 
 INSERT INTO tm_VentasRes (tmEst,tmItem,tmEnero,tmFebrero,tmMarzo,tmAbril,tmMayo,tmJunio,tmJulio,tmAgosto,tmSeptiembre,tmOctubre,tmNoviembre,tmDiciembre)
 VALUES (@pmtmEst,@pmtmItem,@pmtmEnero,@pmtmFebrero,@pmtmMarzo,@pmtmAbril,@pmtmMayo,@pmtmJunio,@pmtmJulio,@pmtmAgosto
,@pmtmSeptiembre,@pmtmOctubre,@pmtmNoviembre,@pmtmDiciembre)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraAntAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraAntAbonos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipAnt VARCHAR(3)
,@pmAnticipo INT,@pmIdCiaAnt CHAR(2),@pmVrAbono MONEY,@pmTipoAplica VARCHAR(10),@pmDetalle VARCHAR(100),@pmCdCuentaAnt VARCHAR(16)
 AS 
 INSERT INTO Trn_TraAntAbonos (TipDoc,Documento,IdCia,Item,Fecha,TipAnt,Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecha,@pmTipAnt,@pmAnticipo,@pmIdCiaAnt,@pmVrAbono,@pmTipoAplica,@pmDetalle,@pmCdCuentaAnt)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraAnticipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraAnticipos] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVrAnticipo MONEY,@pmVrAbonado MONEY
,@pmModalidad VARCHAR(10),@pmTipoPago VARCHAR(10),@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmBeneficiario VARCHAR(150),@pmCantidad DECIMAL(14,4),@pmFechaVence SMALLDATETIME,@pmNumPresAnt INT, @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT
,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCedBenef VARCHAR(16),@pmPreAnticipo INT,@pmNumCargue INT,@pmCiaCargue CHAR(2),@pmVrDeduccion MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraAnticipos (TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,IdPoseedor,IdConductor,VrAnticipo,VrAbonado,Modalidad,TipoPago,NumCheque,FecCheque,IdCta,IdCuenta,Beneficiario,CedBenef,Cantidad,FechaVence,NumPresAnt,PreAnticipo,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,NumCargue,CiaCargue,VrDeduccion)
 VALUES (@pmTipDoc,@pmAnticipo,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmVrAnticipo,@pmVrAbonado,@pmModalidad,@pmTipoPago,@pmNumCheque,@pmFecCheque,@pmIdCta,@pmIdCuenta,@pmBeneficiario,@pmCedBenef,@pmCantidad,@pmFechaVence,@pmNumPresAnt,@pmPreAnticipo,@pmTipCom,@pmComprobante
,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumCargue,@pmCiaCargue,@pmVrDeduccion)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCauDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraCauDetalle] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDescripcion VARCHAR(250),@pmTipoConc VARCHAR(10),@pmVrDebito MONEY,@pmVrCredito MONEY
,@pmCdCuenta VARCHAR(16),@pmNitTercero VARCHAR(16),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmVrBase MONEY,@pmTarifBase DECIMAL(14,4)
,@pmReferencia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME
,@pmEstadoReg INT,@pmTipoLiq VARCHAR(3),@pmNumLiquida INT,@pmCiaLiquida CHAR(2),@pmVrAbonado MONEY
 AS 
 INSERT INTO Trn_TraCauDetalle (TipDoc,Causacion,IdCia,Item,IdConcepto,Descripcion,TipoConc,VrDebito,VrCredito,CdCuenta,NitTercero,CdCCosto,CdSubCos,pVehiculo,TipoAfiVehic,VrBase,TarifBase,Referencia
,TipDocRef,DocRef,TipFac,Factura,IdCiaFac,ItemFac,FecVence,EstadoReg,TipoLiq,NumLiquida,CiaLiquida,VrAbonado)
 VALUES (@pmTipDoc,@pmCausacion,@pmIdCia,@pmItem,@pmIdConcepto,@pmDescripcion,@pmTipoConc,@pmVrDebito,@pmVrCredito,@pmCdCuenta,@pmNitTercero,@pmCdCCosto,@pmCdSubCos,@pmpVehiculo,@pmTipoAfiVehic,@pmVrBase
,@pmTarifBase,@pmReferencia,@pmTipDocRef,@pmDocRef,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmEstadoReg,@pmTipoLiq,@pmNumLiquida,@pmCiaLiquida,@pmVrAbonado)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraCausacion] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmFactura VARCHAR(20),@pmVrTotal MONEY,@pmVrOtros MONEY,@pmVrNeto MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraCausacion (TipDoc,Causacion,IdCia,Fecha,IdConcepto,IdProv,Factura,VrTotal,VrOtros,VrNeto,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmCausacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdProv,@pmFactura,@pmVrTotal,@pmVrOtros,@pmVrNeto,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraConcCausac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraConcCausac] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250)
,@pmIdCuenta VARCHAR(16),@pmTipoConc VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO TraConcCausac (IdConcepto,Concepto,IdCuenta,TipoConc,Inactivo)
 VALUES (@pmIdConcepto,@pmConcepto,@pmIdCuenta,@pmTipoConc,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraConceptos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmDescripcion VARCHAR(250),@pmTarifa DECIMAL(14,4),@pmTipoConc VARCHAR(10),@pmRubroConcep VARCHAR(20)
,@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmTarifIva DECIMAL(14,4),@pmIdConcepto VARCHAR(4),@pmCdCuenta VARCHAR(16),@pmNitTercero VARCHAR(16),@pmCdTipoEsc VARCHAR(4),@pmFechaNov SMALLDATETIME
,@pmVrBase MONEY,@pmTipoTarif CHAR(1),@pmRefConc VARCHAR(50),@pmFijos BIT,@pmIncBaseRet INT,@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmEst_Factura INT,@pmEst_Liquida INT
,@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmCiaFact CHAR(2),@pmVrTotalFact MONEY,@pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmCiaLiq CHAR(2),@pmVrTotalLiq MONEY
 AS 
 INSERT INTO Trn_TraConceptos (TipDoc,Documento,IdCia,Item,Descripcion,Tarifa,TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva,IdConcepto,CdCuenta,NitTercero,CdTipoEsc,FechaNov,VrBase,TipoTarif,RefConc,Fijos,IncBaseRet
,Referencia2,Referencia3,Est_Factura,Est_Liquida,TipFact,NumFactura,CiaFact,VrTotalFact,TipLiq,NumLiquida,CiaLiq,VrTotalLiq)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmDescripcion,@pmTarifa,@pmTipoConc,@pmRubroConcep,@pmCantidad,@pmVrUnitario,@pmTarifIva,@pmIdConcepto,@pmCdCuenta,@pmNitTercero
,@pmCdTipoEsc,@pmFechaNov,@pmVrBase,@pmTipoTarif,@pmRefConc,@pmFijos,@pmIncBaseRet,@pmReferencia2,@pmReferencia3,@pmEst_Factura,@pmEst_Liquida,@pmTipFact,@pmNumFactura,@pmCiaFact,@pmVrTotalFact,@pmTipLiq,@pmNumLiquida,@pmCiaLiq,@pmVrTotalLiq)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCumplido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraCumplido] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmModalidad VARCHAR(10),@pmDiasPlazo INT
,@pmFecPago SMALLDATETIME,@pmTipoMargen VARCHAR(10),@pmMargenFalt DECIMAL(14,4),@pmUndCalcFalt VARCHAR(10),@pmTarifFaltPago MONEY,@pmTarifFaltCobro MONEY,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4)
,@pmNRadicaDoc INT,@pmIdCiaRadic CHAR(2),@pmCdCiaOfic CHAR(2),@pmFecRadic SMALLDATETIME,@pmCdRuta VARCHAR(4),@pmCdOrigen VARCHAR(8),@pmCdDestino VARCHAR(8),@pmTipoComp VARCHAR(3),@pmNumComp INT,@pmCodConcepto VARCHAR(4)
,@pmTipoCumpMT VARCHAR(3),@pmMotivoSusp VARCHAR(3),@pmConsecSusp VARCHAR(3),@pmVrAdicCargue DECIMAL(16,4),@pmVrAdicDescargue DECIMAL(16,4),@pmVrAdicFlete DECIMAL(16,4),@pmMotivoVrAdic VARCHAR(3)
,@pmVrDctoFlete DECIMAL(16,4),@pmMotivoVrDcto VARCHAR(3),@pmVrAdicAnticipo DECIMAL(16,4),@pmFecEntregaDoc SMALLDATETIME,@pmMvoAnulaCump VARCHAR(5),@pmObservAnulado VARCHAR(250),@pmNumViajesCum INT,@pmPesoLiqPago INT,@pmPesoLiqFact INT,@pmCdPlazoPago VARCHAR(4),@pmNumDevCum INT,@pmMvoRechazo INT
,@pmMunOrigVacio1 VARCHAR(8),@pmMunDestVacio1 VARCHAR(8),@pmMunOrigVacio2 VARCHAR(8),@pmMunDestVacio2 VARCHAR(8),@pmVrTrayVacio1 MONEY,@pmVrTrayVacio2 MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraCumplido (TipDoc,Cumplido,IdCia,Fecha,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,Modalidad,DiasPlazo,FecPago,TipoMargen,MargenFalt,UndCalcFalt,TarifFaltPago,TarifFaltCobro,NRadicaDoc,IdCiaRadic,CdCiaOfic,FecRadic,CdRuta,CdOrigen,CdDestino
,Anulado,FecDev,TipoComp,NumComp,CodConcepto,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,TipoCumpMT,MotivoSusp,ConsecSusp,VrAdicCargue,VrAdicDescargue,VrAdicFlete,MotivoVrAdic,VrDctoFlete,MotivoVrDcto,VrAdicAnticipo,FecEntregaDoc,NumRadicaMT,MvoAnulaCump,ObservAnulado,NumViajesCum,PesoLiqPago,PesoLiqFact,CdPlazoPago,NumDevCum,MvoRechazo
,MunOrigVacio1,MunDestVacio1,MunOrigVacio2,MunDestVacio2,VrTrayVacio1,VrTrayVacio2)
 VALUES (@pmTipDoc,@pmCumplido,@pmIdCia,@pmFecha,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmIdVehiculo,@pmModalidad,@pmDiasPlazo,@pmFecPago,@pmTipoMargen,@pmMargenFalt,@pmUndCalcFalt,@pmTarifFaltPago,@pmTarifFaltCobro,@pmNRadicaDoc,@pmIdCiaRadic,@pmCdCiaOfic,@pmFecRadic
,@pmCdRuta,@pmCdOrigen,@pmCdDestino,@pmAnulado,@pmFecDev,@pmTipoComp,@pmNumComp,@pmCodConcepto,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoCumpMT,@pmMotivoSusp,@pmConsecSusp,@pmVrAdicCargue,@pmVrAdicDescargue,@pmVrAdicFlete
,@pmMotivoVrAdic,@pmVrDctoFlete,@pmMotivoVrDcto,@pmVrAdicAnticipo,@pmFecEntregaDoc,0,@pmMvoAnulaCump,@pmObservAnulado,@pmNumViajesCum,@pmPesoLiqPago,@pmPesoLiqFact,@pmCdPlazoPago,@pmNumDevCum,@pmMvoRechazo,@pmMunOrigVacio1,@pmMunDestVacio1,@pmMunOrigVacio2,@pmMunDestVacio2,@pmVrTrayVacio1,@pmVrTrayVacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCumRadica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraCumRadica] @pmNumRadica INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmCdCiaRad CHAR(2),@pmDocAnexos VARCHAR(1000)
,@pmCantDoc INT,@pmFormaEnvio VARCHAR(50),@pmNomRadica VARCHAR(150),@pmCedRadica VARCHAR(16),@pmFuncionario VARCHAR(150),@pmObservacion VARCHAR(2000),@pmNumeroCum INT,@pmIdCiaCum CHAR(2)
,@pmFechaCum SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraCumRadica (NumRadica,IdCia,Fecha,TipMuc,Manifiesto,IdCiaMuc,CdCiaRad,DocAnexos,CantDoc,FormaEnvio,NomRadica,CedRadica,Funcionario,Observacion,NumeroCum,IdCiaCum,FechaCum,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmNumRadica,@pmIdCia,@pmFecha,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmCdCiaRad,@pmDocAnexos,@pmCantDoc,@pmFormaEnvio,@pmNomRadica,@pmCedRadica,@pmFuncionario,@pmObservacion
,@pmNumeroCum,@pmIdCiaCum,@pmFechaCum,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraCumRemesas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraCumRemesas] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipRem VARCHAR(3),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmItemRem INT,@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10)
,@pmCases INT,@pmCajas INT,@pmPalets INT,@pmTarifClie MONEY,@pmTarifPago MONEY,@pmUndTarifClie VARCHAR(10),@pmUndTarifPago VARCHAR(10),@pmCantCargue DECIMAL(14,4),@pmPesoCargue DECIMAL(14,4),@pmVolCargue DECIMAL(14,4),@pmCasesCargue INT,@pmCajasCargue INT,@pmPaletsCargue INT,@pmEstadoCump INT
,@pmRemision DECIMAL(18,2),@pmDocCliente VARCHAR(30),@pmReferencia1 VARCHAR(50),@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmDetalle VARCHAR(250),@pmTarifFlete MONEY,@pmTipoCumRemesa VARCHAR(3),@pmMotivoSuspRem VARCHAR(3),@pmHoraLlegaCargue SMALLDATETIME,@pmHoraEntraCargue SMALLDATETIME
,@pmHoraSaleCargue SMALLDATETIME,@pmHoraLlegaDescargue SMALLDATETIME,@pmHoraEntraDescargue SMALLDATETIME,@pmHoraSaleDescargue SMALLDATETIME,@pmCodCCosto VARCHAR(16),@pmCodSubCos VARCHAR(16),@pmNitClieRem VARCHAR(16),@pmTarifOtros MONEY,@pmVrTray_Vacio1 MONEY,@pmVrTray_Vacio2 MONEY
 AS 
 INSERT INTO Trn_TraCumRemesas (TipDoc,Cumplido,IdCia,Item,TipRem,Remesa,IdCiaRem,ItemRem,Cantidad,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,TarifClie,TarifPago,UndTarifClie,UndTarifPago,CantCargue,PesoCargue,VolCargue,CasesCargue,CajasCargue,PaletsCargue,EstadoCump,Remision,DocCliente
,Referencia1,Referencia2,Referencia3,Detalle,TarifFlete,TipoCumRemesa,MotivoSuspRem,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue,CodCCosto,CodSubCos,NitClieRem,TarifOtros,VrTray_Vacio1,VrTray_Vacio2)
 VALUES (@pmTipDoc,@pmCumplido,@pmIdCia,@pmItem,@pmTipRem,@pmRemesa,@pmIdCiaRem,@pmItemRem,@pmCantidad,@pmPesoNeto,@pmUndMed,@pmVolumen,@pmUndVol,@pmCases,@pmCajas,@pmPalets,@pmTarifClie,@pmTarifPago,@pmUndTarifClie,@pmUndTarifPago,@pmCantCargue,@pmPesoCargue,@pmVolCargue,@pmCasesCargue
,@pmCajasCargue,@pmPaletsCargue,@pmEstadoCump,@pmRemision,@pmDocCliente,@pmReferencia1,@pmReferencia2,@pmReferencia3,@pmDetalle,@pmTarifFlete,@pmTipoCumRemesa,@pmMotivoSuspRem,@pmHoraLlegaCargue,@pmHoraEntraCargue,@pmHoraSaleCargue,@pmHoraLlegaDescargue,@pmHoraEntraDescargue,@pmHoraSaleDescargue,@pmCodCCosto,@pmCodSubCos,@pmNitClieRem,@pmTarifOtros,@pmVrTray_Vacio1,@pmVrTray_Vacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDecAduana]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDecAduana] @pmTipDoc VARCHAR(3),@pmNumDeclara INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdAduCarga VARCHAR(4),@pmIdDestino VARCHAR(8),@pmIdAduOrigen VARCHAR(4),@pmIdAduDestino VARCHAR(4),@pmIdAduFrontera VARCHAR(4),@pmIdDeclarante VARCHAR(16),@pmDeclarante VARCHAR(150),@pmDirDeclara VARCHAR(250),@pmCdLocalDec VARCHAR(8),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirOrigen VARCHAR(250),@pmCdLocalRem VARCHAR(8),@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDestino VARCHAR(250)
,@pmCdLocalDest VARCHAR(8),@pmIdConsig VARCHAR(16),@pmConsignatario VARCHAR(150),@pmDirConsig VARCHAR(250),@pmCdLocalConsig VARCHAR(8),@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmDocAnexos VARCHAR(500),@pmVehiculos VARCHAR(250),@pmRemolques VARCHAR(250),@pmManifiestos VARCHAR(100),@pmContenedores VARCHAR(500),@pmPrecintos VARCHAR(250),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmCondicPago VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDecAduana (TipDoc,NumDeclara,IdCia,Fecha,FecEmision,IdOrigen,IdAduCarga,IdDestino,IdAduOrigen,IdAduDestino,IdAduFrontera,IdDeclarante,Declarante,DirDeclara,CdLocalDec,IdRemitente,Remitente,DirOrigen,CdLocalRem,IdDestinatario,Destinatario,DirDestino,CdLocalDest,IdConsig,Consignatario,DirConsig,CdLocalConsig,IdMoneda,ValorTotal,PesoTotal,DocAnexos,Vehiculos,Remolques,Manifiestos,Contenedores,Precintos,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Negociacion,CondicPago)
 VALUES (@pmTipDoc,@pmNumDeclara,@pmIdCia,@pmFecha,@pmFecEmision,@pmIdOrigen,@pmIdAduCarga,@pmIdDestino,@pmIdAduOrigen,@pmIdAduDestino,@pmIdAduFrontera,@pmIdDeclarante,@pmDeclarante,@pmDirDeclara,@pmCdLocalDec,@pmIdRemitente,@pmRemitente,@pmDirOrigen,@pmCdLocalRem,@pmIdDestinatario,@pmDestinatario,@pmDirDestino,@pmCdLocalDest,@pmIdConsig,@pmConsignatario,@pmDirConsig,@pmCdLocalConsig,@pmIdMoneda,@pmValorTotal,@pmPesoTotal,@pmDocAnexos,@pmVehiculos,@pmRemolques,@pmManifiestos,@pmContenedores,@pmPrecintos,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNegociacion,@pmCondicPago)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDecMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDecMcia] @pmTipDoc VARCHAR(3),@pmNumDeclara INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmCdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(500),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4)
,@pmPesoBruto DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmValorMcia MONEY,@pmIdMoneda VARCHAR(5),@pmIdUnd VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmUndMed VARCHAR(10),@pmUndVol VARCHAR(10),@pmBultos VARCHAR(150),@pmDescripUnid VARCHAR(500)
 AS 
 INSERT INTO Trn_TraDecMcia (TipDoc,NumDeclara,IdCia,Item,TipOrd,NumOrden,IdCiaOrd,CdMercancia,DescripMcias,Cantidad,PesoNeto,PesoBruto,Volumen,ValorMcia,IdMoneda,IdUnd,IdEmp,IdNat,UndMed,UndVol,Bultos,DescripUnid)
 VALUES (@pmTipDoc,@pmNumDeclara,@pmIdCia,@pmItem,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmCdMercancia,@pmDescripMcias,@pmCantidad,@pmPesoNeto,@pmPesoBruto,@pmVolumen,@pmValorMcia,@pmIdMoneda,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmUndMed,@pmUndVol,@pmBultos,@pmDescripUnid)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDespachos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDespachos] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdRuta VARCHAR(4)
,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmNitRemite VARCHAR(16),@pmRemitente VARCHAR(250),@pmNitDestntario VARCHAR(16),@pmDestinatario VARCHAR(250),@pmDescMcia VARCHAR(150),@pmPesoTotal DECIMAL(14,4)
,@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmEstado INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDespachos (TipDoc,Manifiesto,IdCia,Fecha,FecCargue,FecDespacho,IdOrigen,IdDestino,IdRuta,IdVehiculo,IdConductor,IdPoseedor,NitRemite,Remitente,NitDestntario,Destinatario,DescMcia,PesoTotal,NumOrden,IdCiaOrd,Remesa,IdCiaRem,Estado,Anulado,FecDev,Observacion,TimeSys,IdUsuario)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmFecha,@pmFecCargue,@pmFecDespacho,@pmIdOrigen,@pmIdDestino,@pmIdRuta,@pmIdVehiculo,@pmIdConductor,@pmIdPoseedor,@pmNitRemite,@pmRemitente,@pmNitDestntario,@pmDestinatario,@pmDescMcia,@pmPesoTotal,@pmNumOrden
,@pmIdCiaOrd,@pmRemesa,@pmIdCiaRem,@pmEstado,@pmAnulado,@pmFecDev,@pmObservacion,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDespProgram]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDespProgram] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmCdRuta VARCHAR(4),@pmIdPunto INT
,@pmHoraProg SMALLDATETIME,@pmTipoProg INT,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmObservProg VARCHAR(250)
 AS 
 INSERT INTO Trn_TraDespProgram (TipDoc,Manifiesto,IdCia,Item,CdRuta,IdPunto,HoraProg,TipoProg,IdUsuario,FechaCrea,ObservProg)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmItem,@pmCdRuta,@pmIdPunto,@pmHoraProg,@pmTipoProg,@pmIdUsuario,@pmFechaCrea,@pmObservProg)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevAnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVrDevolucion MONEY,@pmCdCta VARCHAR(4),@pmCdCuenta VARCHAR(16),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevAnt (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,VrDevolucion,CdCta,CdCuenta,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmAnticipo,@pmIdCiaDoc,@pmFecDoc,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmVrDevolucion,@pmCdCta,@pmCdCuenta,@pmModdDev,@pmOrigenAdd,@pmTipCom
,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevAos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevAos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrDevolucion MONEY,@pmCdCta VARCHAR(4),@pmCdCuenta VARCHAR(16),@pmModdDev VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevAos (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,VrDevolucion,CdCta,CdCuenta,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmAnticipo,@pmIdCiaDoc,@pmFecDoc,@pmVrDevolucion,@pmCdCta,@pmCdCuenta,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevCau]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevCau] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProv VARCHAR(16),@pmFactura VARCHAR(20),@pmVrTotal MONEY,@pmVrOtros MONEY
,@pmVrNeto MONEY,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevCau (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdProv,Factura,VrTotal,VrOtros,VrNeto,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmCausacion,@pmIdCiaDoc,@pmFecDoc,@pmIdProv,@pmFactura,@pmVrTotal,@pmVrOtros,@pmVrNeto,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevCos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevCos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCiaDoc CHAR(2)
,@pmFecDoc SMALLDATETIME,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevCos (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmCumplido,@pmIdCiaDoc,@pmFecDoc,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevCum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevCum] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmModdDev VARCHAR(10),@pmOrigenAdd VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmTipoAnulacion INT,@pmMvoAnulacion VARCHAR(5),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevCum (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,TimeSys,IdCiaCrea,IdUsuario,TipoAnulacion,MvoAnulacion)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmCumplido,@pmIdCiaDoc,@pmFecDoc,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoAnulacion,@pmMvoAnulacion)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevLeg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevLeg] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(10),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16)
,@pmIdPoseedor VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmVrAnticipos MONEY,@pmVrGastos MONEY,@pmVrCombustible MONEY,@pmVrDiferencia MONEY,@pmgalsComb DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrOtrosCred MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevLeg (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,Modalidad,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,NitEmpresa,VrAnticipos,VrGastos,VrCombustible,VrDiferencia,VrOtrosCred,galsComb,PesoTotal,Cantidad,Volumen,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmLiquidacion,@pmIdCiaDoc,@pmFecDoc,@pmModalidad,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmIdVehiculo,@pmIdConductor,@pmIdPropietario,@pmIdPoseedor,@pmNitEmpresa,@pmVrAnticipos,@pmVrGastos,@pmVrCombustible,@pmVrDiferencia,@pmVrOtrosCred,@pmgalsComb,@pmPesoTotal
,@pmCantidad,@pmVolumen,@pmModdDev,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevLgo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevLgo] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrTotal MONEY,@pmVrCosto MONEY,@pmVrAnticipo MONEY,@pmVrGastos MONEY,@pmVrIva MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY
,@pmVrReteCREE MONEY,@pmVrReteIva MONEY,@pmVrOtros MONEY,@pmVrDescuento MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmCxPagar BIT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmVrImpAvTa MONEY,@pmVrBomberil MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevLgo (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,VrTotal,VrCosto,VrAnticipo,VrGastos,VrIva,VrRetencion,VrReteIca,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrNeto,Cantidad,CxPagar,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdEstado,VrImpAvTa,VrBomberil,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmLiquidacion,@pmIdCiaDoc,@pmFecDoc,@pmVrTotal,@pmVrCosto,@pmVrAnticipo,@pmVrGastos,@pmVrIva,@pmVrRetencion,@pmVrReteIca,@pmVrReteCREE,@pmVrReteIva,@pmVrOtros,@pmVrDescuento,@pmVrNeto,@pmCantidad,@pmCxPagar,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmModdDev,@pmObservacion,@pmIdEstado,@pmVrImpAvTa,@pmVrBomberil,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevLiq] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVrTotal MONEY,@pmModdDev VARCHAR(10),@pmOrigenAdd VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevLiq (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,VrTotal,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmLiquidacion,@pmIdCiaDoc,@pmFecDoc,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmVrTotal,@pmModdDev,@pmOrigenAdd
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevOdp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevOdp] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmCxPagar BIT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevOdp (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,OrdPago,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,CxPagar,ModdDev,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmOrdPago,@pmIdCiaDoc,@pmFecDoc,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmCxPagar,@pmModdDev,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraDevReex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraDevReex] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdEmpTrans VARCHAR(16),@pmNumFactura VARCHAR(15)
,@pmFecFactura SMALLDATETIME,@pmVrTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrOtrosCargos MONEY,@pmVrOtrosDctos MONEY,@pmVrNeto MONEY,@pmPesoTotal DECIMAL(14,4),@pmCxPagar BIT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmModdDev VARCHAR(10),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraDevReex (TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdEmpTrans,NumFactura,FecFactura,VrTotal,VrImpuesto,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto,PesoTotal,CxPagar,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDev,@pmDevolucion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipDoc,@pmCausacion,@pmIdCiaDoc,@pmFecDoc,@pmIdEmpTrans,@pmNumFactura,@pmFecFactura,@pmVrTotal,@pmVrImpuesto,@pmVrRetencion,@pmVrReteIca,@pmVrOtrosCargos,@pmVrOtrosDctos,@pmVrNeto,@pmPesoTotal,@pmCxPagar,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmModdDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraFacRemesas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraFacRemesas] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoReg INT,@pmFechaFact SMALLDATETIME,@pmTipRem VARCHAR(3),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmItemRem INT,@pmFecRemesa SMALLDATETIME,@pmDescripcion VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrCosto MONEY,@pmUndTarifa VARCHAR(10),@pmUndCosto VARCHAR(10),@pmUnidades DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10)
,@pmCases INT,@pmCajas INT,@pmPalets INT,@pmTarifaIva DECIMAL(14,4),@pmVrImpuesto MONEY,@pmTarifaDct DECIMAL(14,4),@pmVrDescuento MONEY,@pmTarifaRet DECIMAL(14,4),@pmVrRetencion MONEY,@pmTarifaIca DECIMAL(14,4),@pmVrReteIca MONEY,@pmVrFaltante MONEY,@pmRemision DECIMAL(18,2),@pmDocCliente VARCHAR(30),@pmReferencia1 VARCHAR(50),@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmCdMercancia VARCHAR(16),@pmCdConcepto VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16)
,@pmNitTercero VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmAnulado INT,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmFecDocRef SMALLDATETIME,@pmCantidadFalt DECIMAL(14,4),@pmUnidadFalt VARCHAR(10),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarDct VARCHAR(4),@pmNumPedRem INT,@pmCiaPedRem CHAR(2),@pmVrDeclMcia MONEY,@pmTarifaSeg DECIMAL(14,4),@pmVrSeguroRem MONEY
,@pmNitAsegurad VARCHAR(16),@pmCantPago DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmRemTransb INT,@pmCostoAdicTbdo MONEY,@pmNitMucTbdo VARCHAR(16),@pmTipoNovFact INT,@pmItemDocRef INT,@pmTarifaIat DECIMAL(14,4),@pmVrAviTab MONEY,@pmCodTarIat VARCHAR(4),@pmTarifaBom DECIMAL(14,4),@pmVrSobBom MONEY,@pmCodTarBom VARCHAR(4),@pmVrAutoIat MONEY,@pmVrAutoBom MONEY,@pmVrTray_Vacio1 MONEY,@pmVrTray_Vacio2 MONEY
 AS 
 INSERT INTO Trn_TraFacRemesas (TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,TipRem,Remesa,IdCiaRem,ItemRem,FecRemesa,Descripcion,Cantidad,VrUnitario,VrCosto,UndTarifa,UndCosto,Unidades,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,TarifaIva,VrImpuesto,TarifaDct,VrDescuento,TarifaRet,VrRetencion,TarifaIca,VrReteIca,VrFaltante,Remision,DocCliente,Referencia1,Referencia2,Referencia3,CdMercancia,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,pVehiculo,TipoAfiVehic,IdOrigen,IdDestino
,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CantidadFalt,UnidadFalt,CodTarRet,CodTarIca,CodTarDct,NumPedRem,CiaPedRem,VrDeclMcia,TarifaSeg,VrSeguroRem,NitAsegurad,CantPago,VrAutRetIca,RemTransb,CostoAdicTbdo,NitMucTbdo,TipoNovFact,ItemDocRef,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom,VrAutoIat,VrAutoBom,VrTray_Vacio1,VrTray_Vacio2)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmItem,@pmTipoReg,@pmFechaFact,@pmTipRem,@pmRemesa,@pmIdCiaRem,@pmItemRem,@pmFecRemesa,@pmDescripcion,@pmCantidad,@pmVrUnitario,@pmVrCosto,@pmUndTarifa,@pmUndCosto,@pmUnidades,@pmPesoNeto,@pmUndMed,@pmVolumen,@pmUndVol,@pmCases,@pmCajas,@pmPalets,@pmTarifaIva,@pmVrImpuesto,@pmTarifaDct,@pmVrDescuento,@pmTarifaRet,@pmVrRetencion,@pmTarifaIca,@pmVrReteIca,@pmVrFaltante,@pmRemision,@pmDocCliente,@pmReferencia1,@pmReferencia2,@pmReferencia3
,@pmCdMercancia,@pmCdConcepto,@pmCdCCosto,@pmCdSubCos,@pmNitTercero,@pmCdAgencia,@pmpVehiculo,@pmTipoAfiVehic,@pmIdOrigen,@pmIdDestino,@pmAnulado,@pmTipDocRef,@pmNumDocRef,@pmIdCiaRef,@pmFecDocRef,@pmCantidadFalt,@pmUnidadFalt,@pmCodTarRet,@pmCodTarIca,@pmCodTarDct,@pmNumPedRem,@pmCiaPedRem,@pmVrDeclMcia,@pmTarifaSeg,@pmVrSeguroRem,@pmNitAsegurad,@pmCantPago,@pmVrAutRetIca,@pmRemTransb,@pmCostoAdicTbdo,@pmNitMucTbdo,@pmTipoNovFact,@pmItemDocRef
,@pmTarifaIat,@pmVrAviTab,@pmCodTarIat,@pmTarifaBom,@pmVrSobBom,@pmCodTarBom,@pmVrAutoIat,@pmVrAutoBom,@pmVrTray_Vacio1,@pmVrTray_Vacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraFijos] @pmNumero INT,@pmIdConcepto VARCHAR(4),@pmDescConc VARCHAR(250),@pmTipoConc VARCHAR(10)
,@pmTarifa DECIMAL(14,4),@pmTipoTarif CHAR(1),@pmTipoAfilVeh VARCHAR(10),@pmCdTipoVeh VARCHAR(4),@pmAnulado BIT,@pmTipoTerc CHAR(1)
,@pmCdCiuOrigen VARCHAR(8),@pmCdCiuDestino VARCHAR(8),@pmpVehiculo VARCHAR(10),@pmCedConductor VARCHAR(16),@pmCdRuta VARCHAR(4)
,@pmTipoVigencia CHAR(1),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmNitCliente VARCHAR(16),@pmCdMercancia VARCHAR(16),@pmIdentProp VARCHAR(16)
 AS 
 INSERT INTO TraFijos (Numero,IdConcepto,DescConc,TipoConc,Tarifa,TipoTarif,TipoAfilVeh,CdTipoVeh,TipoTerc,Anulado,CdCiuOrigen,CdCiuDestino,pVehiculo,CedConductor,CdRuta,TipoVigencia,FechaInicial,FechaFinal,NitCliente,CdMercancia,IdentProp)
 VALUES (@pmNumero,@pmIdConcepto,@pmDescConc,@pmTipoConc,@pmTarifa,@pmTipoTarif,@pmTipoAfilVeh,@pmCdTipoVeh,@pmTipoTerc
,@pmAnulado,@pmCdCiuOrigen,@pmCdCiuDestino,@pmpVehiculo,@pmCedConductor,@pmCdRuta,@pmTipoVigencia,@pmFechaInicial,@pmFechaFinal,@pmNitCliente,@pmCdMercancia,@pmIdentProp)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraGuiaMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraGuiaMcia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdMercancia VARCHAR(16),@pmDescripcionMcia VARCHAR(500),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmdmsAlto DECIMAL(14,4),@pmdmsAncho DECIMAL(14,4),@pmdmsLargo DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10),@pmIdUnd VARCHAR(4)
,@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmVrUnitario MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmTarifSeguro DECIMAL(14,4),@pmUndTarifa VARCHAR(10),@pmRemision DECIMAL(14,4),@pmDocCliente VARCHAR(30),@pmReferencia1 VARCHAR(50),@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmCantFactura DECIMAL(14,4),@pmVrFactura MONEY,@pmCdConcepto VARCHAR(4)
 AS 
 INSERT INTO Trn_TraGuiaMcia (TipDoc,NumGuia,IdCia,Item,IdMercancia,DescripcionMcia,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat,IdTmcia,IdMnjo,VrUnitario,VrDeclarado,VrSeguro,TarifSeguro,UndTarifa,Remision,DocCliente,Referencia1,Referencia2,Referencia3,CantFactura,VrFactura,CdConcepto)
 VALUES (@pmTipDoc,@pmNumGuia,@pmIdCia,@pmItem,@pmIdMercancia,@pmDescripcionMcia,@pmCantidad,@pmPesoNeto,@pmUndMed,@pmdmsAlto,@pmdmsAncho,@pmdmsLargo,@pmVolumen,@pmUndVol,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmIdTmcia,@pmIdMnjo,@pmVrUnitario,@pmVrDeclarado,@pmVrSeguro,@pmTarifSeguro,@pmUndTarifa,@pmRemision,@pmDocCliente,@pmReferencia1,@pmReferencia2,@pmReferencia3,@pmCantFactura,@pmVrFactura,@pmCdConcepto)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraGuias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraGuias] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmModalidad VARCHAR(10),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmNomRemitente VARCHAR(150),@pmIdDestinatario VARCHAR(16),@pmNomDestinatario VARCHAR(150),@pmDirOrigen VARCHAR(250),@pmIdLocOrigen VARCHAR(8),@pmDirDestino VARCHAR(250),@pmIdLocDestino VARCHAR(8),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(150),@pmTelRemitente VARCHAR(30),@pmemlRemitente VARCHAR(150),@pmTelDestinatario VARCHAR(30),@pmemlDestinatario VARCHAR(150),@pmIdResponsable VARCHAR(16),@pmNomResponsable VARCHAR(150),@pmVrTotal MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmVrCargos MONEY,@pmCantidad DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmTipRem VARCHAR(3)
,@pmNumRemesa INT,@pmIdCiaRem CHAR(2),@pmEstFactura INT,@pmTipFac VARCHAR(3),@pmNumFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmCdConcepto VARCHAR(4),@pmCdForma VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmEstLiquida INT,@pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCiaLiq CHAR(2),@pmNumRemision VARCHAR(20),@pmOrigenAdd VARCHAR(10),@pmFechaCrea SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraGuias (TipDoc,NumGuia,IdCia,Fecha,FecDespacho,FecVigencia,Modalidad,IdCliente,IdAgencia,IdRemitente,NomRemitente,IdDestinatario,NomDestinatario,DirOrigen,IdLocOrigen,DirDestino,IdLocDestino,NomContacto,TelContacto,emlContacto,TelRemitente,emlRemitente,TelDestinatario,emlDestinatario,IdResponsable,NomResponsable,VrTotal,VrDeclarado,VrSeguro,VrCargos,Cantidad,PesoTotal,TipRem,NumRemesa,IdCiaRem,EstFactura,TipFac,NumFactura,IdCiaFac,FechaFac,EstLiquida,TipLiq,NumLiquida,IdCiaLiq,CdConcepto,CdForma,TipCom,Comprobante,IdCiaCom,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,IdUsuario,NumRemision)
 VALUES (@pmTipDoc,@pmNumGuia,@pmIdCia,@pmFecha,@pmFecDespacho,@pmFecVigencia,@pmModalidad,@pmIdCliente,@pmIdAgencia,@pmIdRemitente,@pmNomRemitente,@pmIdDestinatario,@pmNomDestinatario,@pmDirOrigen,@pmIdLocOrigen,@pmDirDestino,@pmIdLocDestino,@pmNomContacto,@pmTelContacto,@pmemlContacto,@pmTelRemitente,@pmemlRemitente,@pmTelDestinatario,@pmemlDestinatario,@pmIdResponsable,@pmNomResponsable,@pmVrTotal,@pmVrDeclarado,@pmVrSeguro,@pmVrCargos,@pmCantidad,@pmPesoTotal,@pmTipRem,@pmNumRemesa,@pmIdCiaRem,@pmEstFactura,@pmTipFac,@pmNumFactura,@pmIdCiaFac,@pmFechaFac,@pmEstLiquida,@pmTipLiq,@pmNumLiquida,@pmIdCiaLiq,@pmCdConcepto,@pmCdForma,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmFechaCrea,@pmIdCiaCrea,@pmIdUsuario,@pmNumRemision)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraInfViajes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraInfViajes] @pmTipDoc VARCHAR(3),@pmNumViaje INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdRuta VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10)
,@pmVrFletes MONEY,@pmPesoTotal DECIMAL(14,4),@pmNumManif INT,@pmIdCiaManif CHAR(2),@pmNumMintrans DECIMAL(14,2),@pmMvoAnulacion VARCHAR(5),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraInfViajes (TipDoc,NumViaje,IdCia,Fecha,IdOrigen,IdDestino,IdRuta,IdVehiculo,IdPoseedor,IdConductor,nRemolque,TipoAfiVehic,VrFletes,PesoTotal,NumManif,IdCiaManif,NumMintrans,MvoAnulacion,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmNumViaje,@pmIdCia,@pmFecha,@pmIdOrigen,@pmIdDestino,@pmIdRuta,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmnRemolque,@pmTipoAfiVehic,@pmVrFletes,@pmPesoTotal,@pmNumManif,@pmIdCiaManif,@pmNumMintrans,@pmMvoAnulacion,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiqDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTraLiqDetalle] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDescConcepto VARCHAR(250),@pmIdCuenta VARCHAR(16),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16)
,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmRubroConc VARCHAR(10),@pmVrBase MONEY,@pmTarifBase DECIMAL(14,4),@pmCantComb DECIMAL(14,4),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT
,@pmFecVence SMALLDATETIME,@pmRefConcep VARCHAR(50),@pmTipSop VARCHAR(3),@pmNumSoporte INT,@pmIdCiaSop CHAR(2),@pmDocSop BIT,@pmTipoImp VARCHAR(4),@pmCodTarImp VARCHAR(4),@pmItemBase INT,@pmTipoNov INT,@pmTipDocNov VARCHAR(3),@pmNumDocNov INT,@pmCiaDocNov CHAR(2),@pmItemNov INT

 AS 
 INSERT INTO Trn_TraLiqDetalle (TipDoc,Liquidacion,IdCia,Item,IdConcepto,DescConcepto,IdCuenta,VrDebito,VrCredito,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,RubroConc,VrBase,TarifBase,CantComb,TipFac,Factura,IdCiaFac,ItemFac,FecVence,RefConcep,TipSop,NumSoporte,IdCiaSop
,DocSop,TipoImp,CodTarImp,ItemBase,TipoNov,TipDocNov,NumDocNov,CiaDocNov,ItemNov)
 VALUES (@pmTipDoc,@pmLiquidacion,@pmIdCia,@pmItem,@pmIdConcepto,@pmDescConcepto,@pmIdCuenta,@pmVrDebito,@pmVrCredito,@pmIdTercero,@pmCodAgncia,@pmCdCCosto,@pmCdSubCos,@pmpVehiculo,@pmRubroConc,@pmVrBase,@pmTarifBase
,@pmCantComb,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmFecVence,@pmRefConcep,@pmTipSop,@pmNumSoporte,@pmIdCiaSop,@pmDocSop,@pmTipoImp,@pmCodTarImp,@pmItemBase,@pmTipoNov,@pmTipDocNov,@pmNumDocNov,@pmCiaDocNov,@pmItemNov)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraLiquida] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16)
,@pmIdConductor VARCHAR(16),@pmVrTotal MONEY, @pmCxPagar BIT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmFecIniCau SMALLDATETIME,@pmFecFinCau SMALLDATETIME,@pmFecIniOdp SMALLDATETIME,@pmFecFinOdp SMALLDATETIME,@pmModLiquida VARCHAR(10)
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraLiquida (TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,IdVehiculo,IdPoseedor,IdConductor,VrTotal,CxPagar,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado
,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,ModLiquida,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmLiquidacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmVrTotal,@pmCxPagar,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion
,@pmIdEstado,@pmFecIniCau,@pmFecFinCau,@pmFecIniOdp,@pmFecFinOdp,@pmModLiquida,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiquidaDed]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraLiquidaDed] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipCau VARCHAR(3),@pmCausacion INT,@pmIdCiaCau CHAR(2),@pmItemCau INT,@pmFechaCau SMALLDATETIME,@pmIdConcepto VARCHAR(4)
,@pmDescripcion VARCHAR(250),@pmVrAbono MONEY,@pmNitPoseedor VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmEsVence BIT,@pmTipOdp VARCHAR(3),@pmOrdenPago INT,@pmIdCiaOdp CHAR(2),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2)
,@pmVrSaldoOrden MONEY,@pmCdCuenta VARCHAR(16),@pmCdCuePagar VARCHAR(16),@pmNumFactura VARCHAR(20),@pmCdCCosto  VARCHAR(16),@pmCdSubCos VARCHAR(16)
 AS 
 INSERT INTO Trn_TraLiquidaDed (TipDoc,Liquidacion,IdCia,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,IdConcepto,Descripcion,VrAbono,NitPoseedor,pVehiculo,EsVence,TipOdp,OrdenPago,IdCiaOdp
,TipMuc,Manifiesto,IdCiaMuc,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CdSubCos)
 VALUES (@pmTipDoc,@pmLiquidacion,@pmIdCia,@pmItem,@pmTipCau,@pmCausacion,@pmIdCiaCau,@pmItemCau,@pmFechaCau,@pmIdConcepto,@pmDescripcion,@pmVrAbono,@pmNitPoseedor,@pmpVehiculo,@pmEsVence,@pmTipOdp,@pmOrdenPago,@pmIdCiaOdp
,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmVrSaldoOrden,@pmCdCuenta,@pmCdCuePagar,@pmNumFactura,@pmCdCCosto,@pmCdSubCos)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraLiqViajes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmFechaMuc SMALLDATETIME,@pmIdVehiculo VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmVrAnticipos MONEY,@pmVrGastos MONEY,@pmVrCombustible MONEY,@pmVrDiferencia MONEY,@pmgalsComb DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmVolumen DECIMAL(14,4)
,@pmIdRuta VARCHAR(4),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmReferencia VARCHAR(50),@pmDescMcias VARCHAR(150),@pmkmtInicial DECIMAL(14,4),@pmkmtFinal DECIMAL(14,4),@pmEstFactura INT,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmFecDocRef SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrOtrosCred MONEY,@pmLiqMixto BIT,@pmNum_Ppto INT,@pmVrGuiasCe MONEY,@pmVrGuiasSeg MONEY,@pmVrGuiasOtr MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraLiqViajes (TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,NitEmpresa,VrAnticipos,VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen,IdRuta,IdLocOrigen,IdLocDestino,Referencia,DescMcias
,kmtInicial,kmtFinal,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,LiqMixto,Num_Ppto,VrGuiasCe,VrGuiasSeg,VrGuiasOtr)
 VALUES (@pmTipDoc,@pmLiquidacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmFechaMuc,@pmIdVehiculo,@pmIdConductor,@pmIdPropietario,@pmIdPoseedor,@pmNitEmpresa,@pmVrAnticipos,@pmVrGastos,@pmVrCombustible,@pmVrOtrosCred,@pmVrDiferencia,@pmgalsComb
,@pmPesoTotal,@pmCantidad,@pmVolumen,@pmIdRuta,@pmIdLocOrigen,@pmIdLocDestino,@pmReferencia,@pmDescMcias,@pmkmtInicial,@pmkmtFinal,@pmEstFactura,@pmTipDocRef,@pmNumDocRef,@pmIdCiaRef,@pmFecDocRef,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmLiqMixto,@pmNum_Ppto,@pmVrGuiasCe,@pmVrGuiasSeg,@pmVrGuiasOtr)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifAnexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraManifAnexo] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmkmsTotal DECIMAL(14,4),@pmVrFleteTon MONEY,@pmTipoRuta VARCHAR(10)
,@pmCdLocTrao VARCHAR(8),@pmCdLocTrad VARCHAR(8),@pmKmsTraOri DECIMAL(14,4),@pmKmsTraDes DECIMAL(14,4),@pmIdMneda VARCHAR(5),@pmVrTasa DECIMAL(14,4)
,@pmNomRemite VARCHAR(150),@pmNomDestino VARCHAR(150),@pmLugarFletes VARCHAR(100),@pmNumAnticipo INT,@pmNumCheque VARCHAR(20),@pmTipoMintrans VARCHAR(10)
,@pmMucMintrans INT,@pmContIntegral INT,@pmVolumenCarga DECIMAL(14,4),@pmNumPoliza VARCHAR(30),@pmCdBodDtno VARCHAR(4),@pmTipoTrslado INT,@pmMvoAnulacion VARCHAR(5),@pmMvoSuspension VARCHAR(5)
,@pmWsSeguro BIT,@pmNumRadSeguro DECIMAL(18,2),@pmPuntosRuta DECIMAL(14,4),@pmCantViajes INT,@pmTransbordo INT,@pmNumMucAnu INT,@pmCiaMucAnu CHAR(2),@pmAceptaFirma BIT,@pmTipoValPacto VARCHAR(10)
,@pmMunOrigVacio1 VARCHAR(8),@pmMunDestVacio1 VARCHAR(8),@pmMunOrigVacio2 VARCHAR(8),@pmMunDestVacio2 VARCHAR(8)
 AS 
 INSERT INTO Trn_TraManifAnexo (TipDoc,Manifiesto,IdCia,kmsTotal,VrFleteTon,TipoRuta,CdLocTrao,CdLocTrad,KmsTraOri,KmsTraDes,IdMneda,VrTasa,NomRemite,NomDestino
,LugarFletes,NumAnticipo,NumCheque,TipoMintrans,MucMintrans,ContIntegral,VolumenCarga,NumPoliza,CdBodDtno,TipoTrslado,MvoAnulacion,MvoSuspension,WsSeguro,NumRadSeguro,PuntosRuta,CantViajes,Transbordo,NumMucAnu,CiaMucAnu,AceptaFirma,TipoValPacto,MunOrigVacio1,MunDestVacio1,MunOrigVacio2,MunDestVacio2)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmkmsTotal,@pmVrFleteTon,@pmTipoRuta,@pmCdLocTrao,@pmCdLocTrad,@pmKmsTraOri,@pmKmsTraDes,@pmIdMneda,@pmVrTasa
,@pmNomRemite,@pmNomDestino,@pmLugarFletes,@pmNumAnticipo,@pmNumCheque,@pmTipoMintrans,@pmMucMintrans,@pmContIntegral,@pmVolumenCarga,@pmNumPoliza,@pmCdBodDtno,@pmTipoTrslado,@pmMvoAnulacion,@pmMvoSuspension,@pmWsSeguro
,@pmNumRadSeguro,@pmPuntosRuta,@pmCantViajes,@pmTransbordo,@pmNumMucAnu,@pmCiaMucAnu,@pmAceptaFirma,@pmTipoValPacto,@pmMunOrigVacio1,@pmMunDestVacio1,@pmMunOrigVacio2,@pmMunDestVacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifiesto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraManifiesto] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdRuta VARCHAR(4),@pmIdRutaFle VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmVrFletes MONEY,@pmVrRetencion MONEY
,@pmVrReteIca MONEY,@pmVrDescuento MONEY,@pmVrAnticipo MONEY,@pmVrAntAdic MONEY,@pmVrNeto MONEY,@pmVrPagos MONEY,@pmVrCargos MONEY,@pmVrDctos MONEY,@pmTarifaFlete MONEY,@pmCantidad DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmBaseRet MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmIdLocFletes VARCHAR(8),@pmFechaPago SMALLDATETIME,@pmPagoCargue VARCHAR(50),@pmPagoDescargue VARCHAR(50)
,@pmNumMintrans DECIMAL(14,2),@pmEdoMintrans VARCHAR(5),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmCumplido INT,@pmIdCiaCump CHAR(2),@pmFechaCump SMALLDATETIME,@pmEstCumplido INT,@pmTipOdp VARCHAR(3),@pmOrdPago INT,@pmIdCiaOdp CHAR(2),@pmFechaOdp SMALLDATETIME,@pmEstOrden INT, @pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmVrFleteNeto MONEY,@pmTipInfVia VARCHAR(3),@pmNumViaje INT,@pmCiaInfViaje CHAR(2),@pmCdCatPeaje VARCHAR(4),@pmCdCondRelev VARCHAR(16),@pmVrTrayVacio1 MONEY,@pmVrTrayVacio2 MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraManifiesto (TipDoc,Manifiesto,IdCia,Fecha,FecDespacho,FecEntrega,IdOrigen,IdDestino,IdRuta,IdRutaFle,IdVehiculo,IdConductor,nRemolque,TipoAfiVehic,IdPropietario,IdPoseedor,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,Cantidad,PesoTotal,BaseRet,TarifaRet,TarifaIca,CodTarRet,CodTarIca,IdLocFletes,FechaPago,PagoCargue,PagoDescargue,NumMintrans,EdoMintrans,Remesa
,IdCiaRem,Cumplido,IdCiaCump,FechaCump,EstCumplido,TipOdp,OrdPago,IdCiaOdp,FechaOdp,EstOrden,VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,CdCondRelev,VrTrayVacio1,VrTrayVacio2)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmFecha,@pmFecDespacho,@pmFecEntrega,@pmIdOrigen,@pmIdDestino,@pmIdRuta,@pmIdRutaFle,@pmIdVehiculo,@pmIdConductor,@pmnRemolque,@pmTipoAfiVehic,@pmIdPropietario,@pmIdPoseedor,@pmVrFletes,@pmVrRetencion,@pmVrReteIca,@pmVrDescuento,@pmVrAnticipo,@pmVrAntAdic,@pmVrNeto,@pmVrPagos,@pmVrCargos,@pmVrDctos,@pmTarifaFlete,@pmCantidad,@pmPesoTotal,@pmBaseRet,@pmTarifaRet,@pmTarifaIca
,@pmCodTarRet,@pmCodTarIca,@pmIdLocFletes,@pmFechaPago,@pmPagoCargue,@pmPagoDescargue,@pmNumMintrans,@pmEdoMintrans,@pmRemesa,@pmIdCiaRem,@pmCumplido,@pmIdCiaCump,@pmFechaCump,@pmEstCumplido,@pmTipOdp,@pmOrdPago,@pmIdCiaOdp,@pmFechaOdp,@pmEstOrden,@pmVrFleteNeto,@pmTipInfVia,@pmNumViaje,@pmCiaInfViaje,@pmCdCatPeaje,@pmOrigenAdd,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmCdCondRelev,@pmVrTrayVacio1,@pmVrTrayVacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraManifInt] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdCondRelev VARCHAR(16),@pmNatCarga VARCHAR(50),@pmCdAduana VARCHAR(4),@pmCdAduanaDest VARCHAR(4)
,@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmNumMuc INT,@pmCdCiaMuc CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraManifInt (TipDoc,Manifiesto,IdCia,Fecha,FecEmision,IdOrigen,IdDestino,IdVehiculo,nRemolque,IdConductor,IdCondRelev,NatCarga,CdAduana,CdAduanaDest,IdMoneda,ValorTotal,PesoTotal,NumMuc,CdCiaMuc,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Negociacion)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmFecha,@pmFecEmision,@pmIdOrigen,@pmIdDestino,@pmIdVehiculo,@pmnRemolque,@pmIdConductor,@pmIdCondRelev,@pmNatCarga,@pmCdAduana,@pmCdAduanaDest,@pmIdMoneda,@pmValorTotal,@pmPesoTotal,@pmNumMuc,@pmCdCiaMuc,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNegociacion)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifIntMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraManifIntMcia] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmCdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(500),@pmCantidad DECIMAL(14,4)
,@pmPesoNeto DECIMAL(14,4),@pmPesoBruto DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmValorMcia MONEY,@pmIdMoneda VARCHAR(5),@pmIdUnd VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmUndMed VARCHAR(10),@pmUndVol VARCHAR(10),@pmBultos VARCHAR(150),@pmDescripUnid VARCHAR(500)
 AS 
 INSERT INTO Trn_TraManifIntMcia (TipDoc,Manifiesto,IdCia,Item,TipOrd,NumOrden,IdCiaOrd,CdMercancia,DescripMcias,Cantidad,PesoNeto,PesoBruto,Volumen,ValorMcia,IdMoneda,IdUnd,IdEmp,IdNat,UndMed,UndVol,Bultos,DescripUnid)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmItem,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmCdMercancia,@pmDescripMcias,@pmCantidad,@pmPesoNeto,@pmPesoBruto,@pmVolumen,@pmValorMcia,@pmIdMoneda,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmUndMed,@pmUndVol,@pmBultos,@pmDescripUnid)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifMod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraManifMod] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmVrFleteTotal MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY
,@pmVrAnticipo MONEY,@pmPesoTotal DECIMAL(14,4),@pmNumCump INT,@pmCdCiaCump CHAR(2),@pmIdLugarPago VARCHAR(8),@pmFechaPago SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraManifMod (TipDoc,Manifiesto,IdCia,Item,Fecha,VrFleteTotal,VrRetencion,VrReteIca,VrAnticipo,PesoTotal,NumCump,CdCiaCump,IdLugarPago,FechaPago,TimeSys,IdUsuario)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmItem,@pmFecha,@pmVrFleteTotal,@pmVrRetencion,@pmVrReteIca,@pmVrAnticipo,@pmPesoTotal,@pmNumCump,@pmCdCiaCump,@pmIdLugarPago,@pmFechaPago,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraManifRem]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraManifRem] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipRem VARCHAR(3)
,@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmItemRem INT,@pmTarifTabla MONEY,@pmTarifPago MONEY,@pmRemMintrans DECIMAL(14,2),@pmEdoRemMin VARCHAR(5)
,@pmCodBodDtno VARCHAR(4),@pmTipTraslado INT,@pmHorasCargue DECIMAL(14,4),@pmHorasDesc DECIMAL(14,4),@pmFecInicioCargue SMALLDATETIME,@pmFecFinCargue SMALLDATETIME
,@pmFecIniciodesc SMALLDATETIME,@pmFecFindesc SMALLDATETIME,@pmTiempoCargue DECIMAL(14,4),@pmTiempoDesc DECIMAL(14,4),@pmFecLlegCargue SMALLDATETIME
,@pmFecSalidaCargue SMALLDATETIME,@pmFecLlegdesc SMALLDATETIME,@pmFecSalidadesc SMALLDATETIME,@pmRemTrayVacio1 MONEY,@pmRemTrayVacio2 MONEY
 AS 
 INSERT INTO Trn_TraManifRem (TipDoc,Manifiesto,IdCia,Item,TipRem,Remesa,IdCiaRem,ItemRem,TarifTabla,TarifPago,RemMintrans,EdoRemMin,CodBodDtno,TipTraslado
,HorasCargue,HorasDesc,FecInicioCargue,FecFinCargue,FecIniciodesc,FecFindesc,TiempoCargue,TiempoDesc,FecLlegCargue,FecSalidaCargue,FecLlegdesc,FecSalidadesc,RemTrayVacio1,RemTrayVacio2)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmItem,@pmTipRem,@pmRemesa,@pmIdCiaRem,@pmItemRem,@pmTarifTabla,@pmTarifPago,@pmRemMintrans,@pmEdoRemMin,@pmCodBodDtno,@pmTipTraslado
,@pmHorasCargue,@pmHorasDesc,@pmFecInicioCargue,@pmFecFinCargue,@pmFecIniciodesc,@pmFecFindesc,@pmTiempoCargue,@pmTiempoDesc,@pmFecLlegCargue,@pmFecSalidaCargue
,@pmFecLlegdesc,@pmFecSalidadesc,@pmRemTrayVacio1,@pmRemTrayVacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenAbo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenAbo] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME
,@pmTipAnt VARCHAR(3),@pmAnticipo INT,@pmIdCiaAnt CHAR(2),@pmVrAbono MONEY,@pmTipoAplica VARCHAR(10),@pmObservacion VARCHAR(250),@pmCodCuenta VARCHAR(16)
 AS 
 INSERT INTO Trn_TraOrdenAbo (TipDoc,Documento,IdCia,Item,Fecha,TipAnt,Anticipo,IdCiaAnt,VrAbono,TipoAplica,Observacion,CodCuenta)
 VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,@pmItem,@pmFecha,@pmTipAnt,@pmAnticipo,@pmIdCiaAnt,@pmVrAbono,@pmTipoAplica,@pmObservacion,@pmCodCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenAnt] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipOds VARCHAR(3),@pmNumOrden INT,@pmIdCiaOds CHAR(2),@pmVrAnticipo MONEY,@pmVrAbonado MONEY,@pmTipoPago VARCHAR(10),@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmBeneficiario VARCHAR(150),@pmCedBenef VARCHAR(16),@pmFechaVence SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoAncpo VARCHAR(10),@pmNumPresAnt INT,@pmCantidad DECIMAL(14,4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraOrdenAnt (TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipOds,NumOrden,IdCiaOds,VrAnticipo,VrAbonado,TipoPago,NumCheque,FecCheque,IdCta,IdCuenta,Beneficiario,CedBenef,FechaVence,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,TipoAncpo,NumPresAnt,Cantidad)
 VALUES (@pmTipDoc,@pmAnticipo,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipOds,@pmNumOrden,@pmIdCiaOds,@pmVrAnticipo,@pmVrAbonado,@pmTipoPago,@pmNumCheque,@pmFecCheque,@pmIdCta,@pmIdCuenta,@pmBeneficiario,@pmCedBenef,@pmFechaVence,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipoAncpo,@pmNumPresAnt,@pmCantidad)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenCum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenCum] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipOds VARCHAR(3),@pmNumOrden INT,@pmIdCiaOds CHAR(2),@pmTipoAfiVehic VARCHAR(10),@pmFecDespacho SMALLDATETIME,@pmFecRecibo SMALLDATETIME,@pmFecIngCertif SMALLDATETIME,@pmFecCertificado SMALLDATETIME,@pmDescServicio VARCHAR(100)
,@pmCantidad DECIMAL(14,4),@pmVrTotal MONEY,@pmVrCosto MONEY,@pmRemCliente VARCHAR(30),@pmFuncionario VARCHAR(150),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmNumReferencia VARCHAR(50),@pmNumAprobCO INT,@pmCiaAprobCO CHAR(2),@pmFecAprobCO SMALLDATETIME,@pmObservAprobCO VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraOrdenCum (TipDoc,Cumplido,IdCia,Fecha,IdConcepto,TipOds,NumOrden,IdCiaOds,TipoAfiVehic,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,DescServicio,Cantidad,VrTotal,VrCosto,RemCliente,Funcionario,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,NumReferencia,NumAprobCO,CiaAprobCO,FecAprobCO,ObservAprobCO)
 VALUES (@pmTipDoc,@pmCumplido,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipOds,@pmNumOrden,@pmIdCiaOds,@pmTipoAfiVehic,@pmFecDespacho,@pmFecRecibo,@pmFecIngCertif,@pmFecCertificado,@pmDescServicio,@pmCantidad,@pmVrTotal,@pmVrCosto,@pmRemCliente,@pmFuncionario,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumReferencia,@pmNumAprobCO,@pmCiaAprobCO,@pmFecAprobCO,@pmObservAprobCO)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenDet] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdMercancia VARCHAR(16),@pmDescripcion VARCHAR(250)
,@pmCantidad DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmVrUnitario MONEY,@pmCantCump DECIMAL(14,4),@pmTarifaCump MONEY,@pmDocCliente VARCHAR(30)
,@pmTarifaPago MONEY,@pmPagoCump MONEY
 AS 
 INSERT INTO Trn_TraOrdenDet (TipDoc,NumOrden,IdCia,Item,IdMercancia,Descripcion,Cantidad,UndMed,VrUnitario,TarifaPago,CantCump,TarifaCump,PagoCump,DocCliente)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmItem,@pmIdMercancia,@pmDescripcion,@pmCantidad,@pmUndMed,@pmVrUnitario,@pmTarifaPago,@pmCantCump,@pmTarifaCump,@pmPagoCump,@pmDocCliente)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenLiq] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipOds VARCHAR(3),@pmNumOrden INT,@pmIdCiaOds CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmTipoAfiVehic VARCHAR(10),@pmVrTotal MONEY,@pmVrCosto MONEY
,@pmVrAnticipo MONEY,@pmVrGastos MONEY,@pmVrIva MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrReteCREE MONEY,@pmVrReteIva MONEY,@pmVrOtros MONEY,@pmVrDescuento MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmTarifaPago MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmTarifaImp DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4)
,@pmTarifaIca DECIMAL(16,6),@pmTarifaRiv DECIMAL(14,4),@pmTarifaRtc DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCodTarRtc VARCHAR(4),@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmCdPlazo VARCHAR(4),@pmFechaVence SMALLDATETIME,@pmUndMed VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmNumCheque VARCHAR(20),@pmVrConcCargos MONEY,@pmVrConcDed MONEY,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmNumDocSop INT,@pmCiaDocSop CHAR(2),@pmReferencia2 VARCHAR(50)
,@pmCdTarAvta VARCHAR(4),@pmTarifaAvta DECIMAL(14,4),@pmVrImpAvTa MONEY,@pmCdTarBom VARCHAR(4),@pmTarifaBom DECIMAL(14,4),@pmVrBomberil MONEY,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraOrdenLiq (TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,TipOds,NumOrden,IdCiaOds,IdVehiculo,IdPoseedor,IdConductor,TipoAfiVehic,VrTotal,VrCosto,VrAnticipo,VrGastos,VrIva,VrRetencion,VrReteIca,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrNeto,Cantidad,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv
,TarifaRtc,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarRtc,Referencia,CxPagar,CdPlazo,FechaVence,UndMed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,TipEgr,Egreso,IdCiaEgr,NumCheque,VrConcCargos,VrConcDed,CdCCosto,CdSubCos,NumDocSop,CiaDocSop,Referencia2,CdTarAvta,TarifaAvta,VrImpAvTa,CdTarBom,TarifaBom,VrBomberil)
 VALUES (@pmTipDoc,@pmLiquidacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmTipOds,@pmNumOrden,@pmIdCiaOds,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmTipoAfiVehic,@pmVrTotal,@pmVrCosto,@pmVrAnticipo,@pmVrGastos,@pmVrIva,@pmVrRetencion,@pmVrReteIca,@pmVrReteCREE,@pmVrReteIva,@pmVrOtros,@pmVrDescuento,@pmVrNeto,@pmCantidad,@pmTarifaPago,@pmBaseImp
,@pmBaseRet,@pmBaseIca,@pmTarifaImp,@pmTarifaRet,@pmTarifaIca,@pmTarifaRiv,@pmTarifaRtc,@pmCodTarIva,@pmCodTarRet,@pmCodTarIca,@pmCodTarRiv,@pmCodTarRtc,@pmReferencia,@pmCxPagar,@pmCdPlazo,@pmFechaVence,@pmUndMed,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado
,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTipEgr,@pmEgreso,@pmIdCiaEgr,@pmNumCheque,@pmVrConcCargos,@pmVrConcDed,@pmCdCCosto,@pmCdSubCos,@pmNumDocSop,@pmCiaDocSop,@pmReferencia2,@pmCdTarAvta,@pmTarifaAvta,@pmVrImpAvTa,@pmCdTarBom,@pmTarifaBom,@pmVrBomberil)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenManif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenManif] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmVrTotalFletes MONEY,@pmVrDescuento MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY
,@pmVrAnticipos MONEY,@pmVrFaltantes MONEY,@pmVrSeguros MONEY,@pmVrFondos MONEY,@pmVrAportes MONEY,@pmVrOtrosDctos MONEY,@pmVrImpuestos MONEY,@pmVrEstampilla MONEY,@pmVrOtrosPagos MONEY,@pmVrNeto MONEY,@pmTarifaTabla MONEY,@pmTarifaFlete MONEY,@pmUnidTarifa VARCHAR(10),@pmPesoTotal DECIMAL(14,4),@pmUnidades DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmPesoOrigen DECIMAL(14,4)
,@pmUnidOrigen DECIMAL(14,4),@pmVolOrigen DECIMAL(14,4),@pmPesoDestino  DECIMAL(14,4),@pmUnidDestino DECIMAL(14,4),@pmVolDestino DECIMAL(14,4),@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseSeg MONEY,@pmBaseImp MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaSeg DECIMAL(14,4),@pmTarifaImp DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmTipoLiq INT
,@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmNumCheque VARCHAR(20),@pmReferencia VARCHAR(50),@pmCantFaltante DECIMAL(14,4),@pmUnidadFalt VARCHAR(10),@pmTolFaltNeto DECIMAL(14,4),@pmVrConcPagos MONEY,@pmVrConcDctos MONEY,@pmVrConcFondo MONEY,@pmVrConcSeguro MONEY,@pmVrConcAporte MONEY,@pmVrConcImpuesto MONEY
,@pmEdoLiqCausac INT,@pmVrRemesas MONEY,@pmVrRecCaja MONEY,@pmCdForma VARCHAR(4),@pmFechaEgr SMALLDATETIME,@pmVrSeguroRc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmCdCenCosto VARCHAR(16),@pmCdSubCenCos VARCHAR(16),@pmCodTarifAvta VARCHAR(4),@pmTarifaAvta DECIMAL(14,4),@pmVrImpAvTa MONEY,@pmVrDctoPago MONEY,@pmCodTarifDcpp VARCHAR(4)
,@pmVrTrayVacio1 MONEY,@pmVrTrayVacio2 MONEY
 AS 
 INSERT INTO Trn_TraOrdenManif (TipDoc,OrdPago,IdCia,Item,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,VrTotalFletes,VrDescuento,VrRetencion,VrReteIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,VrNeto,TarifaTabla
,TarifaFlete,UnidTarifa,PesoTotal,Unidades,Volumen,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,BaseRet,BaseIca,BaseSeg,BaseImp,TarifaRet,TarifaIca,TarifaSeg,TarifaImp,CodTarRet,CodTarIca,TipoLiq,TipEgr,Egreso,IdCiaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto
,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,EdoLiqCausac,VrRemesas,VrRecCaja,CdForma,FechaEgr,VrSeguroRc,VrReteCREE,TarifaRtc,CodTarRtc,CdCenCosto,CdSubCenCos,CodTarifAvta,TarifaAvta,VrImpAvTa,VrDctoPago,CodTarifDcpp,VrTrayVacio1,VrTrayVacio2)
 VALUES (@pmTipDoc,@pmOrdPago,@pmIdCia,@pmItem,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmIdVehiculo,@pmIdConductor,@pmIdPropietario,@pmIdPoseedor,@pmVrTotalFletes,@pmVrDescuento,@pmVrRetencion,@pmVrReteIca,@pmVrAnticipos,@pmVrFaltantes,@pmVrSeguros
,@pmVrFondos,@pmVrAportes,@pmVrOtrosDctos,@pmVrImpuestos,@pmVrEstampilla,@pmVrOtrosPagos,@pmVrNeto,@pmTarifaTabla,@pmTarifaFlete,@pmUnidTarifa,@pmPesoTotal,@pmUnidades,@pmVolumen,@pmPesoOrigen,@pmUnidOrigen,@pmVolOrigen,@pmPesoDestino,@pmUnidDestino,@pmVolDestino,@pmBaseRet,@pmBaseIca,@pmBaseSeg,@pmBaseImp,@pmTarifaRet,@pmTarifaIca,@pmTarifaSeg,@pmTarifaImp,@pmCodTarRet,@pmCodTarIca,@pmTipoLiq
,@pmTipEgr,@pmEgreso,@pmIdCiaEgr,@pmNumCheque,@pmReferencia,@pmCantFaltante,@pmUnidadFalt,@pmTolFaltNeto,@pmVrConcPagos,@pmVrConcDctos,@pmVrConcFondo,@pmVrConcSeguro,@pmVrConcAporte,@pmVrConcImpuesto,@pmEdoLiqCausac,@pmVrRemesas,@pmVrRecCaja,@pmCdForma,@pmFechaEgr,@pmVrSeguroRc,@pmVrReteCREE,@pmTarifaRtc,@pmCodTarRtc,@pmCdCenCosto,@pmCdSubCenCos,@pmCodTarifAvta,@pmTarifaAvta,@pmVrImpAvTa,@pmVrDctoPago,@pmCodTarifDcpp,@pmVrTrayVacio1,@pmVrTrayVacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenPago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenPago]  @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmLiqRemesas BIT,@pmCxPagar BIT,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmFechaVence SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmNumDocSop INT,@pmCiaDocSop CHAR(2),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraOrdenPago (TipDoc,OrdPago,IdCia,Fecha,IdConcepto,Modalidad,LiqRemesas,CxPagar,MulPlazos,IdPlazo,FechaVence,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario,NumDocSop,CiaDocSop)
 VALUES (@pmTipDoc,@pmOrdPago,@pmIdCia,@pmFecha,@pmIdConcepto,@pmModalidad,@pmLiqRemesas,@pmCxPagar,@pmMulPlazos,@pmIdPlazo,@pmFechaVence,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumDocSop,@pmCiaDocSop)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenRemesas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenRemesas] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmTipRem VARCHAR(3),@pmRemesa INT,@pmIdCiaRem CHAR(2)
,@pmItemRem INT,@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10),@pmCases INT,@pmCajas INT,@pmPalets INT,@pmTarifPago MONEY,@pmTarifTabla MONEY
,@pmUndTarifa VARCHAR(10),@pmDetalle VARCHAR(250)
 AS 
 INSERT INTO Trn_TraOrdenRemesas (TipDoc,OrdPago,IdCia,Item,TipMuc,Manifiesto,IdCiaMuc,TipRem,Remesa,IdCiaRem,ItemRem,Cantidad,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,TarifPago,TarifTabla,UndTarifa,Detalle)
 VALUES (@pmTipDoc,@pmOrdPago,@pmIdCia,@pmItem,@pmTipMuc,@pmManifiesto,@pmIdCiaMuc,@pmTipRem,@pmRemesa,@pmIdCiaRem,@pmItemRem,@pmCantidad,@pmPesoNeto,@pmUndMed,@pmVolumen,@pmUndVol
,@pmCases,@pmCajas,@pmPalets,@pmTarifPago,@pmTarifTabla,@pmUndTarifa,@pmDetalle)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraOrdenServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecRecibo SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmModalidad VARCHAR(10)
,@pmVrTotal MONEY,@pmVrCosto MONEY,@pmCantidad DECIMAL(14,4),@pmVrAnticipo MONEY,@pmIdDestino VARCHAR(8),@pmTipoOrden VARCHAR(10),@pmIdEstacion VARCHAR(4),@pmNomEstacion VARCHAR(50),@pmTipoResiduo VARCHAR(100),@pmRemCliente VARCHAR(30),@pmNomRecibido VARCHAR(150),@pmFecIngCertif SMALLDATETIME,@pmFecCertificado SMALLDATETIME,@pmNumRemesa INT,@pmCdCiaRem CHAR(2)
,@pmEstCumplido INT,@pmEstFactura INT,@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmCdCiaFact CHAR(2),@pmkmtInicial INT,@pmkmtFinal INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmEstOrden INT,@pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmCdCiaLiq CHAR(2),@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME,@pmUsuAprob VARCHAR(11),@pmObservAprob VARCHAR(250)
,@pmCdRuta VARCHAR(4),@pmIdOrigen VARCHAR(8),@pmCantkms INT,@pmNumCump INT,@pmCdCiaCum CHAR(2),@pmCdTarIva VARCHAR(4),@pmCdTarRiv VARCHAR(4),@pmCdTarRet VARCHAR(4),@pmCdTarIca VARCHAR(4),@pmCdTarRtc VARCHAR(4),@pmNumReferencia VARCHAR(50),@pmCdTarAvta VARCHAR(4),@pmCdTarBom VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraOrdenServ (TipDoc,NumOrden,IdCia,Fecha,FecDespacho,FecRecibo,IdCliente,IdAgencia,IdVehiculo,IdPoseedor,IdConductor,nRemolque,TipoAfiVehic,Modalidad,VrTotal,VrCosto,Cantidad,VrAnticipo,IdDestino,TipoOrden,IdEstacion,NomEstacion,TipoResiduo,RemCliente,NomRecibido,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstCumplido,EstFactura,TipFact,NumFactura,CdCiaFact
,kmtInicial,kmtFinal,EstOrden,TipLiq,NumLiquida,CdCiaLiq,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,CdRuta,IdOrigen,Cantkms,NumCump,CdCiaCum,CdTarIva,CdTarRiv,CdTarRet,CdTarIca,CdTarRtc,NumReferencia,CdTarAvta,CdTarBom)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmFecDespacho,@pmFecRecibo,@pmIdCliente,@pmIdAgencia,@pmIdVehiculo,@pmIdPoseedor,@pmIdConductor,@pmnRemolque,@pmTipoAfiVehic,@pmModalidad,@pmVrTotal,@pmVrCosto,@pmCantidad,@pmVrAnticipo,@pmIdDestino,@pmTipoOrden,@pmIdEstacion,@pmNomEstacion,@pmTipoResiduo,@pmRemCliente,@pmNomRecibido,@pmFecIngCertif,@pmFecCertificado,@pmNumRemesa
,@pmCdCiaRem,@pmEstCumplido,@pmEstFactura,@pmTipFact,@pmNumFactura,@pmCdCiaFact,@pmkmtInicial,@pmkmtFinal,@pmEstOrden,@pmTipLiq,@pmNumLiquida,@pmCdCiaLiq,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNumAprob,@pmIdCiaApr,@pmFecAprob,@pmUsuAprob,@pmObservAprob,@pmCdRuta,@pmIdOrigen,@pmCantkms,@pmNumCump,@pmCdCiaCum,@pmCdTarIva,@pmCdTarRiv,@pmCdTarRet,@pmCdTarIca,@pmCdTarRtc,@pmNumReferencia,@pmCdTarAvta,@pmCdTarBom)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPedAnexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPedAnexo] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmNomCliente VARCHAR(150),@pmNomRemite VARCHAR(150),@pmNomDestino VARCHAR(150),@pmLugarCargue VARCHAR(150),@pmLugarDescargue VARCHAR(150),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmContacDestino VARCHAR(150),@pmTelContacDest VARCHAR(30),@pmemlContacDest VARCHAR(100),@pmPolizaEsp BIT
,@pmNumPolizaEsp VARCHAR(50),@pmNitCiaPoliza VARCHAR(16),@pmNomCiaPoliza VARCHAR(150),@pmFecVencePol SMALLDATETIME,@pmVrLimiteDesp MONEY,@pmSeguros VARCHAR(10),@pmCargue VARCHAR(20),@pmDescargue VARCHAR(20),@pmCdTipoEsc VARCHAR(4),@pmNitSIA VARCHAR(16),@pmNombreSIA VARCHAR(150),@pmContactoSIA VARCHAR(150),@pmTelContacSIA VARCHAR(30),@pmIdLocCont VARCHAR(8),@pmPatioCont VARCHAR(50),@pmCdTipoVeh VARCHAR(4)
,@pmTipoMargen VARCHAR(10),@pmMargenFalt DECIMAL(14,4),@pmEmbAdicional VARCHAR(150),@pmTipoRuta VARCHAR(10),@pmTipoTrans VARCHAR(10),@pmEmbarque VARCHAR(10),@pmCdTipCarga VARCHAR(4),@pmDevContenedor BIT,@pmUndCalcFalt VARCHAR(10),@pmTarifFaltPago MONEY,@pmTarifFaltCobro MONEY,@pmCdRutaTarif VARCHAR(4),@pmTipoServicio VARCHAR(10),@pmCodTipoOper VARCHAR(4)
 AS 
 INSERT INTO Trn_TraPedAnexo (TipDoc,Pedido,IdCia,NomCliente,NomRemite,NomDestino,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,PolizaEsp,NumPolizaEsp,NitCiaPoliza,NomCiaPoliza,FecVencePol,VrLimiteDesp,Seguros,Cargue,Descargue,CdTipoEsc,NitSIA,NombreSIA,ContactoSIA,TelContacSIA
,TipoRuta,TipoTrans,Embarque,CdTipCarga,DevContenedor,IdLocCont,PatioCont,CdTipoVeh,MargenFalt,TipoMargen,UndCalcFalt,TarifFaltPago,TarifFaltCobro,EmbAdicional,CdRutaTarif,TipoServicio,CodTipoOper)
 VALUES (@pmTipDoc,@pmPedido,@pmIdCia,@pmNomCliente,@pmNomRemite,@pmNomDestino,@pmLugarCargue,@pmLugarDescargue,@pmNomContacto,@pmTelContacto,@pmemlContacto,@pmContacDestino,@pmTelContacDest,@pmemlContacDest,@pmPolizaEsp,@pmNumPolizaEsp,@pmNitCiaPoliza,@pmNomCiaPoliza,@pmFecVencePol,@pmVrLimiteDesp,@pmSeguros,@pmCargue,@pmDescargue,@pmCdTipoEsc,@pmNitSIA,@pmNombreSIA,@pmContactoSIA,@pmTelContacSIA
,@pmTipoRuta,@pmTipoTrans,@pmEmbarque,@pmCdTipCarga,@pmDevContenedor, @pmIdLocCont,@pmPatioCont,@pmCdTipoVeh,@pmMargenFalt,@pmTipoMargen,@pmUndCalcFalt,@pmTarifFaltPago,@pmTarifFaltCobro,@pmEmbAdicional,@pmCdRutaTarif,@pmTipoServicio,@pmCodTipoOper)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdClieFact VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmIdDestinatario VARCHAR(16),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmIdVend VARCHAR(16),@pmIdTarifCom VARCHAR(4),@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmTipoTarifa VARCHAR(10)
,@pmVrCobro MONEY,@pmVrPagos MONEY,@pmVrFletes MONEY,@pmVrCargue MONEY,@pmVrDesCargue MONEY,@pmVrEscolta MONEY,@pmVrDevContdor MONEY,@pmVrTraUrbano MONEY,@pmVrEmbalajes MONEY,@pmVrCargos MONEY,@pmVrDctos MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmCantidad DECIMAL(14,4),@pmCantDesp DECIMAL(14,4),@pmIdMneda VARCHAR(5),@pmVrTasa DECIMAL(14,4),@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME,@pmTipOdc VARCHAR(3),@pmOCargue INT,@pmIdCiaOdc CHAR(2)
,@pmFechaOdc SMALLDATETIME,@pmTipRem VARCHAR(3),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmFechaRem SMALLDATETIME,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraPedido (TipDoc,Pedido,IdCia,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,IdAgencia,IdClieFact,IdRemitente,IdDestinatario,IdLocOrigen,IdLocDestino,IdVend,IdTarifCom,Modalidad,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,VrDeclarado,VrSeguro,Cantidad,CantDesp,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmPedido,@pmIdCia,@pmFecha,@pmFechaVence,@pmFecDespacho,@pmFecEntrega,@pmIdCliente,@pmIdAgencia,@pmIdClieFact,@pmIdRemitente,@pmIdDestinatario,@pmIdLocOrigen,@pmIdLocDestino,@pmIdVend,@pmIdTarifCom,@pmModalidad,@pmVigencia,@pmTipoTarifa,@pmVrCobro,@pmVrPagos,@pmVrFletes,@pmVrCargue,@pmVrDesCargue,@pmVrEscolta,@pmVrDevContdor,@pmVrTraUrbano,@pmVrEmbalajes,@pmVrCargos,@pmVrDctos,@pmVrDeclarado,@pmVrSeguro,@pmCantidad,@pmCantDesp,@pmIdMneda,@pmVrTasa,@pmCotizacion,@pmIdCiaCot,@pmNumAprob,@pmIdCiaApr
,@pmFecAprob,@pmTipOdc,@pmOCargue,@pmIdCiaOdc,@pmFechaOdc,@pmTipRem,@pmRemesa,@pmIdCiaRem,@pmFechaRem,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmFechaFac,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPedMcias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPedMcias] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmdmsAlto DECIMAL(14,4),@pmdmsAncho DECIMAL(14,4),@pmdmsLargo DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10),@pmIdUnd VARCHAR(4)
,@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmCdRango VARCHAR(4),@pmCases INT,@pmCajas INT,@pmPalets INT,@pmNitRemite VARCHAR(16),@pmRemitente VARCHAR(250),@pmDirOrigen VARCHAR(250),@pmIdOrigen VARCHAR(8),@pmNitDestntario VARCHAR(16),@pmDestinatario VARCHAR(250),@pmDirDestino VARCHAR(250),@pmIdDestino VARCHAR(8),@pmTarifClie MONEY,@pmTarifPago MONEY
,@pmTarifTabla MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmTarifSeguro DECIMAL(14,4),@pmReferencia1 VARCHAR(50),@pmReferencia2 VARCHAR(50),@pmContenedor1 VARCHAR(50),@pmContenedor2 VARCHAR(50),@pmUndTarifa VARCHAR(10),@pmUndTarifPago VARCHAR(10),@pmDocCliente VARCHAR(30),@pmReferencia3 VARCHAR(50),@pmCdTipoVehic VARCHAR(4),@pmTipo_Servicio VARCHAR(10),@pmSedeRem VARCHAR(10),@pmSedeDest VARCHAR(10)
,@pmCod_UN VARCHAR(30),@pmCod_Corr VARCHAR(8),@pmCod_Desg VARCHAR(8),@pmDescripcionRP VARCHAR(500)
 AS 
 INSERT INTO Trn_TraPedMcias (TipDoc,Pedido,IdCia,Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat,IdMnjo,IdTmcia,CdRango,Cases,Cajas,Palets,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro
,Referencia1,Referencia2,Contenedor1,Contenedor2,UndTarifa,UndTarifPago,DocCliente,Referencia3,CdTipoVehic,Tipo_Servicio,SedeRem,SedeDest,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP)
 VALUES (@pmTipDoc,@pmPedido,@pmIdCia,@pmItem,@pmIdMercancia,@pmDescripMcias,@pmCantidad,@pmPesoNeto,@pmUndMed,@pmdmsAlto,@pmdmsAncho,@pmdmsLargo,@pmVolumen,@pmUndVol,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmIdMnjo,@pmIdTmcia,@pmCdRango,@pmCases,@pmCajas,@pmPalets,@pmNitRemite,@pmRemitente,@pmDirOrigen,@pmIdOrigen,@pmNitDestntario,@pmDestinatario,@pmDirDestino
,@pmIdDestino,@pmTarifClie,@pmTarifPago,@pmTarifTabla,@pmVrDeclarado,@pmVrSeguro,@pmTarifSeguro,@pmReferencia1,@pmReferencia2,@pmContenedor1,@pmContenedor2,@pmUndTarifa,@pmUndTarifPago,@pmDocCliente,@pmReferencia3,@pmCdTipoVehic,@pmTipo_Servicio,@pmSedeRem,@pmSedeDest,@pmCod_UN,@pmCod_Corr,@pmCod_Desg,@pmDescripcionRP)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPorteInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdNotificado VARCHAR(16),@pmNotificado VARCHAR(150),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirOrigen VARCHAR(250)
,@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDestino VARCHAR(250),@pmIdConsig VARCHAR(16),@pmConsignatario VARCHAR(150),@pmDirConsig VARCHAR(250),@pmInsTransporte VARCHAR(1000),@pmDocRemitente VARCHAR(500),@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmManifiesto INT,@pmCdCiaManif CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmCondic_Pago VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraPorteInt (TipDoc,NumOrden,IdCia,Fecha,FecEmision,FecCargue,FecEntrega,IdOrigen,IdDestino,IdNotificado,Notificado,IdRemitente,Remitente,DirOrigen,IdDestinatario,Destinatario,DirDestino,IdConsig,Consignatario,DirConsig,InsTransporte,DocRemitente,IdMoneda,ValorTotal,PesoTotal,Manifiesto,CdCiaManif,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,Negociacion,Condic_Pago)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmFecEmision,@pmFecCargue,@pmFecEntrega,@pmIdOrigen,@pmIdDestino,@pmIdNotificado,@pmNotificado,@pmIdRemitente,@pmRemitente,@pmDirOrigen,@pmIdDestinatario,@pmDestinatario,@pmDirDestino,@pmIdConsig,@pmConsignatario,@pmDirConsig,@pmInsTransporte,@pmDocRemitente,@pmIdMoneda,@pmValorTotal,@pmPesoTotal,@pmManifiesto,@pmCdCiaManif,@pmOrigenAdd
,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmNegociacion,@pmCondic_Pago)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPorteIntMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPorteIntMcia] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmCdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(500),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmPesoBruto DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmValorMcia MONEY
,@pmIdMoneda VARCHAR(5),@pmIdUnd VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmUndMed VARCHAR(10),@pmUndVol VARCHAR(10),@pmBultos VARCHAR(150),@pmObservacion VARCHAR(1000),@pmDescripUnid VARCHAR(500)
 AS 
 INSERT INTO Trn_TraPorteIntMcia (TipDoc,NumOrden,IdCia,Item,CdMercancia,DescripMcias,Cantidad,PesoNeto,PesoBruto,Volumen,ValorMcia,IdMoneda,IdUnd,IdEmp,IdNat,UndMed,UndVol,Bultos,Observacion,DescripUnid)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmItem,@pmCdMercancia,@pmDescripMcias,@pmCantidad,@pmPesoNeto,@pmPesoBruto,@pmVolumen,@pmValorMcia,@pmIdMoneda,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmUndMed,@pmUndVol,@pmBultos,@pmObservacion,@pmDescripUnid)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPresAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraPresAnt] @pmNumPsto INT,@pmFecha SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmVrGastos MONEY,@pmVrComb MONEY,@pmVrPeajes MONEY,@pmVrAnticipo MONEY,@pmCdCat VARCHAR(4)
,@pmCdTipoVeh VARCHAR(4),@pmTipoAfilVeh VARCHAR(10),@pmCdTipoMot VARCHAR(4),@pmCdCom VARCHAR(4),@pmCdRango VARCHAR(4),@pmValorFijo BIT,@pmObservacion VARCHAR(250),@pmInactivo BIT,@pmTipoRuta VARCHAR(10),@pmCdRuta  VARCHAR(4)
,@pmNitCliente VARCHAR(16),@pmCdMercancia VARCHAR(16),@pmTipoServicio INT,@pmCantgalones DECIMAL(14,4),@pmVrExtralegal MONEY,@pmCdTipoCarr VARCHAR(4),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraPresAnt (NumPsto,Fecha,IdOrigen,IdDestino,TipoRuta,CdRuta,FecInicio,FecFinal,VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,CdTipoVeh,TipoAfilVeh,CdTipoMot,CdCom,CdRango,ValorFijo,Observacion,Inactivo,FechaCrea,IdUsuario,NitCliente,CdMercancia,TipoServicio,Cantgalones,VrExtralegal,CdTipoCarr)
 VALUES (@pmNumPsto,@pmFecha,@pmIdOrigen,@pmIdDestino,@pmTipoRuta,@pmCdRuta,@pmFecInicio,@pmFecFinal,@pmVrGastos,@pmVrComb,@pmVrPeajes,@pmVrAnticipo,@pmCdCat,@pmCdTipoVeh,@pmTipoAfilVeh,@pmCdTipoMot,@pmCdCom
,@pmCdRango,@pmValorFijo,@pmObservacion,@pmInactivo,@pmFechaCrea,@pmIdUsuario,@pmNitCliente,@pmCdMercancia,@pmTipoServicio,@pmCantgalones,@pmVrExtralegal,@pmCdTipoCarr)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraPresItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTraPresItems] @pmNumPsto INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDescripcion VARCHAR(250)
,@pmCantidad DECIMAL(14,4),@pmVrUnitario MONEY,@pmVrTotal MONEY,@pmTipoRubro VARCHAR(10),@pmCdClase VARCHAR(4),@pmNitTercero VARCHAR(16),@pmCdTipOper VARCHAR(4)
 AS 
 INSERT INTO Trn_TraPresItems (NumPsto,Item,IdConcepto,Descripcion,Cantidad,VrUnitario,VrTotal,TipoRubro,CdClase,NitTercero,CdTipOper)
 VALUES (@pmNumPsto,@pmItem,@pmIdConcepto,@pmDescripcion,@pmCantidad,@pmVrUnitario,@pmVrTotal,@pmTipoRubro,@pmCdClase,@pmNitTercero,@pmCdTipOper)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraReexpedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraReexpedido] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdEmpTrans VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrOtrosCargos MONEY,@pmVrOtrosDctos MONEY,@pmVrNeto MONEY,@pmPesoTotal DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY
,@pmTarifaImp DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(16,6),@pmCodTarImp VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmCdPlazo VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraReexpedido (TipDoc,Causacion,IdCia,Fecha,IdConcepto,IdEmpTrans,NumFactura,FecFactura,FecVence,VrTotal,VrImpuesto,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto,PesoTotal,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,CodTarImp,CodTarRet,CodTarIca,Referencia,CxPagar,CdPlazo,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmCausacion,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdEmpTrans,@pmNumFactura,@pmFecFactura,@pmFecVence,@pmVrTotal,@pmVrImpuesto,@pmVrRetencion,@pmVrReteIca,@pmVrOtrosCargos,@pmVrOtrosDctos,@pmVrNeto,@pmPesoTotal,@pmBaseImp,@pmBaseRet,@pmBaseIca,@pmTarifaImp,@pmTarifaRet,@pmTarifaIca,@pmCodTarImp,@pmCodTarRet,@pmCodTarIca,@pmReferencia,@pmCxPagar,@pmCdPlazo
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmIdEstado,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraReexpedidoRem]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTraReexpedidoRem] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipRem VARCHAR(3),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmFecRemesa SMALLDATETIME
,@pmDescripcion VARCHAR(250),@pmUnidades DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10),@pmUndTarifa VARCHAR(10),@pmVrUnitario MONEY
,@pmValorTotal MONEY,@pmpVehiculo VARCHAR(10),@pmCedConductor VARCHAR(16)
 AS 
 INSERT INTO Trn_TraReexpedidoRem (TipDoc,Causacion,IdCia,Item,TipRem,Remesa,IdCiaRem,FecRemesa,Descripcion,Unidades,PesoNeto,UndMed,Volumen,UndVol,UndTarifa,VrUnitario,ValorTotal,pVehiculo,CedConductor)
 VALUES (@pmTipDoc,@pmCausacion,@pmIdCia,@pmItem,@pmTipRem,@pmRemesa,@pmIdCiaRem,@pmFecRemesa,@pmDescripcion,@pmUnidades,@pmPesoNeto,@pmUndMed,@pmVolumen,@pmUndVol,@pmUndTarifa
,@pmVrUnitario,@pmValorTotal,@pmpVehiculo,@pmCedConductor)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemAnexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraRemAnexo] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmIdVend VARCHAR(16),@pmIdTarifCom VARCHAR(4),@pmNomCliente VARCHAR(150),@pmNomRemite VARCHAR(150),@pmNomDestino VARCHAR(150),@pmLugarCargue VARCHAR(150),@pmLugarDescargue VARCHAR(150)
,@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmContacDestino VARCHAR(150),@pmTelContacDest VARCHAR(30),@pmemlContacDest VARCHAR(100),@pmPolizaSeguro VARCHAR(50),@pmNitCiaPoliza VARCHAR(16),@pmNomCiaPoliza VARCHAR(150),@pmFecVencePol SMALLDATETIME
,@pmManifMintrans DECIMAL(14,2),@pmRemMintrans DECIMAL(14,2),@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2),@pmNumInvent INT,@pmIdCiaInv CHAR(2),@pmTomadorPoliza CHAR(1),@pmTipoRuta VARCHAR(10),@pmTipoMintrans VARCHAR(10),@pmNitEmpTransp VARCHAR(16),@pmNumFactEmp VARCHAR(20)
,@pmMvoAnulacion VARCHAR(3),@pmPactoCargue BIT,@pmHorasPactoCargue INT,@pmMinPactoCargue INT,@pmHoraCitaCargue SMALLDATETIME,@pmHoraLlegaCargue SMALLDATETIME,@pmHoraEntraCargue SMALLDATETIME,@pmHoraSaleCargue SMALLDATETIME
,@pmPactoDescargue BIT,@pmHorasPactoDescargue INT,@pmMinPactoDescargue INT,@pmHoraCitaDescargue SMALLDATETIME,@pmHoraLlegaDescargue SMALLDATETIME,@pmHoraEntraDescargue SMALLDATETIME,@pmHoraSaleDescargue SMALLDATETIME
,@pmTipoDevRemesa VARCHAR(3),@pmCodCiuTransb VARCHAR(8),@pmMvoTransbordo VARCHAR(3),@pmCantViajes INT,@pmTipOrdMud VARCHAR(3),@pmItemOsm INT,@pmRemMTEstado INT,@pmRem_Descr_Prod VARCHAR(500),@pmRem_FecchaReg DATETIME,@pmPolizaMerPel VARCHAR(30),@pmTipoConsolida VARCHAR(10)
 AS 
 INSERT INTO Trn_TraRemAnexo (TipDoc,NumOrden,IdCia,IdVend,IdTarifCom,NomCliente,NomRemite,NomDestino,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,TomadorPoliza,PolizaSeguro,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans
,TipSal,NumSalida,IdCiaSal,NumInvent,IdCiaInv,TipoRuta,TipoMintrans,NitEmpTransp,NumFactEmp,MvoAnulacion,PactoCargue,HorasPactoCargue,MinPactoCargue,HoraCitaCargue,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue,PactoDescargue,HorasPactoDescargue,MinPactoDescargue,HoraCitaDescargue
,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue,TipoDevRemesa,CodCiuTransb,MvoTransbordo,CantViajes,TipOrdMud,ItemOsm,RemMTEstado,Rem_Descr_Prod,Rem_FecchaReg,PolizaMerPel,TipoConsolida)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmIdVend,@pmIdTarifCom,@pmNomCliente,@pmNomRemite,@pmNomDestino,@pmLugarCargue,@pmLugarDescargue,@pmNomContacto,@pmTelContacto,@pmemlContacto,@pmContacDestino,@pmTelContacDest,@pmemlContacDest,@pmTomadorPoliza,@pmPolizaSeguro,@pmNitCiaPoliza,@pmNomCiaPoliza
,@pmFecVencePol,@pmManifMintrans,@pmRemMintrans,@pmTipSal,@pmNumSalida,@pmIdCiaSal,@pmNumInvent,@pmIdCiaInv,@pmTipoRuta,@pmTipoMintrans,@pmNitEmpTransp,@pmNumFactEmp,@pmMvoAnulacion,@pmPactoCargue,@pmHorasPactoCargue,@pmMinPactoCargue,@pmHoraCitaCargue,@pmHoraLlegaCargue,@pmHoraEntraCargue
,@pmHoraSaleCargue,@pmPactoDescargue,@pmHorasPactoDescargue,@pmMinPactoDescargue,@pmHoraCitaDescargue,@pmHoraLlegaDescargue,@pmHoraEntraDescargue,@pmHoraSaleDescargue,@pmTipoDevRemesa,@pmCodCiuTransb,@pmMvoTransbordo,@pmCantViajes,@pmTipOrdMud,@pmItemOsm,@pmRemMTEstado,@pmRem_Descr_Prod,@pmRem_FecchaReg,@pmPolizaMerPel,@pmTipoConsolida)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemCntdor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraRemCntdor] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdTipoCon VARCHAR(4),@pmNumContdor VARCHAR(50),@pmPesoNeto DECIMAL(14,4),@pmIdTipoPre VARCHAR(4)
,@pmNumPrecinto VARCHAR(30),@pmColorPrecinto VARCHAR(20),@pmSellos VARCHAR(150),@pmPeligroso BIT,@pmPerecedero BIT,@pmToxico BIT,@pmInflamable BIT,@pmDifmanejo BIT,@pmFragil BIT,@pmDevCont BIT
,@pmCdLocCont VARCHAR(8),@pmPatioCont VARCHAR(50),@pmObservacion VARCHAR(150),@pmNumSalidaSello INT,@pmCdCiaSalSello CHAR(2),@pmItemSalSello INT,@pmCdProdSalida VARCHAR(16),@pmNumSerialSello VARCHAR(30)
,@pmNumComodato VARCHAR(50),@pmFecVenceCom SMALLDATETIME
 AS 
 INSERT INTO Trn_TraRemCntdor (TipDoc,NumOrden,IdCia,Item,IdTipoCon,NumContdor,PesoNeto,IdTipoPre,NumPrecinto,ColorPrecinto,Sellos,Peligroso,Perecedero,Toxico,Inflamable,Difmanejo,Fragil,DevCont,CdLocCont,PatioCont
,Observacion,NumSalidaSello,CdCiaSalSello,ItemSalSello,CdProdSalida,NumSerialSello,NumComodato,FecVenceCom)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmItem,@pmIdTipoCon,@pmNumContdor,@pmPesoNeto,@pmIdTipoPre,@pmNumPrecinto,@pmColorPrecinto,@pmSellos,@pmPeligroso,@pmPerecedero,@pmToxico,@pmInflamable
,@pmDifmanejo,@pmFragil,@pmDevCont,@pmCdLocCont,@pmPatioCont,@pmObservacion,@pmNumSalidaSello,@pmCdCiaSalSello,@pmItemSalSello,@pmCdProdSalida,@pmNumSerialSello,@pmNumComodato,@pmFecVenceCom)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemesa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraRemesa] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmHoraLlegada SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdClieFact VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmIdDestinatario VARCHAR(16),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8)
,@pmIdLocFletes VARCHAR(8),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmModalidad VARCHAR(10),@pmTipoTarifa VARCHAR(10),@pmVrCobro MONEY,@pmVrPagos MONEY,@pmVrFletes MONEY,@pmVrCargue MONEY,@pmVrDesCargue MONEY,@pmVrEscolta MONEY,@pmVrDevContdor MONEY,@pmVrTraUrbano MONEY,@pmVrEmbalajes MONEY,@pmVrCargos MONEY
,@pmVrDctos MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmCantidad DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmItems INT,@pmIdMneda VARCHAR(5),@pmVrTasa DECIMAL(14,4),@pmNumPedido INT,@pmIdCiaPed CHAR(2),@pmFechaPed SMALLDATETIME,@pmTipDcm VARCHAR(3),@pmNumDocmto INT,@pmIdCiaDcm CHAR(2),@pmFechaDcm SMALLDATETIME,@pmNumManif INT,@pmIdCiaManif CHAR(2),@pmEstCumplido INT
,@pmEstFactura INT,@pmCdConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCdRutaTarif VARCHAR(4),@pmSerieGuia CHAR(2),@pmNumGuia INT,@pmCdForma VARCHAR(4),@pmNumCausac INT,@pmCdCiaCausac CHAR(2),@pmEdoCausac INT,@pmCdBodega VARCHAR(4),@pmVigenciaOdc INT,@pmVrTray_Vacio1 MONEY,@pmVrTray_Vacio2 MONEY
,@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraRemesa (TipDoc,NumOrden,IdCia,Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,IdAgencia,IdClieFact,IdRemitente,IdDestinatario,IdLocOrigen,IdLocDestino,IdLocFletes,IdVehiculo,IdConductor,nRemolque,TipoAfiVehic,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,VrDeclarado,VrSeguro,Cantidad,PesoTotal,Items,IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed
,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,CdRutaTarif,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac,CdBodega,TipCom,Comprobante,IdCiaCom,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario,VigenciaOdc,VrTray_Vacio1,VrTray_Vacio2)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmFecha,@pmFecDespacho,@pmFecEntrega,@pmHoraLlegada,@pmIdCliente,@pmIdAgencia,@pmIdClieFact,@pmIdRemitente,@pmIdDestinatario,@pmIdLocOrigen,@pmIdLocDestino,@pmIdLocFletes,@pmIdVehiculo,@pmIdConductor,@pmnRemolque,@pmTipoAfiVehic,@pmModalidad,@pmTipoTarifa,@pmVrCobro,@pmVrPagos,@pmVrFletes,@pmVrCargue,@pmVrDesCargue,@pmVrEscolta,@pmVrDevContdor,@pmVrTraUrbano
,@pmVrEmbalajes,@pmVrCargos,@pmVrDctos,@pmVrDeclarado,@pmVrSeguro,@pmCantidad,@pmPesoTotal,@pmItems,@pmIdMneda,@pmVrTasa,@pmNumPedido,@pmIdCiaPed,@pmFechaPed,@pmTipDcm,@pmNumDocmto,@pmIdCiaDcm,@pmFechaDcm,@pmNumManif,@pmIdCiaManif,@pmEstCumplido,@pmEstFactura,@pmCdConcepto,@pmCdRutaTarif,@pmSerieGuia,@pmNumGuia,@pmCdForma,@pmNumCausac,@pmCdCiaCausac,@pmEdoCausac,@pmCdBodega,@pmTipCom,@pmComprobante,@pmIdCiaCom
,@pmOrigenAdd,@pmAnulado,@pmFecDev,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmVigenciaOdc,@pmVrTray_Vacio1,@pmVrTray_Vacio2)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraRemMcias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraRemMcias] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmdmsAlto DECIMAL(14,4),@pmdmsAncho DECIMAL(14,4),@pmdmsLargo DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmUndVol VARCHAR(10),@pmIdUnd VARCHAR(4)
,@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmCdRango VARCHAR(4),@pmCases INT,@pmCajas INT,@pmPalets INT,@pmNitRemite VARCHAR(16),@pmRemitente VARCHAR(250),@pmDirOrigen VARCHAR(250),@pmIdOrigen VARCHAR(8),@pmNitDestntario VARCHAR(16),@pmDestinatario VARCHAR(250),@pmDirDestino VARCHAR(250),@pmIdDestino VARCHAR(8),@pmTarifClie MONEY
,@pmTarifPago MONEY,@pmTarifTabla MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmTarifSeguro DECIMAL(14,4),@pmUndTarifa VARCHAR(10),@pmRemision DECIMAL(18,2),@pmDocCliente VARCHAR(30),@pmReferencia1 VARCHAR(50),@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmContenedor1 VARCHAR(50),@pmContenedor2 VARCHAR(50),@pmCdAgencia VARCHAR(16),@pmCumplido INT,@pmIdCiaCump CHAR(2),@pmFechaCump SMALLDATETIME
,@pmDetalleCump VARCHAR(250),@pmCantidadCump DECIMAL(14,4),@pmPesoCump DECIMAL(14,4),@pmVolCump DECIMAL(14,4),@pmCasesCump INT,@pmCajasCump INT,@pmPaletsCump INT,@pmTarifCump MONEY,@pmPagoCump MONEY,@pmUndTarCump VARCHAR(10),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmTarifClieFac MONEY,@pmTipOdp VARCHAR(3),@pmNumeroOdp INT
,@pmIdCiaOdp CHAR(2),@pmTarifOdp MONEY,@pmPesoCont DECIMAL(14,4),@pmUndTarifPago VARCHAR(10),@pmUndTarPagoCump VARCHAR(10),@pmSedeRem VARCHAR(10),@pmSedeDest VARCHAR(10),@pmTipDocInv VARCHAR(3),@pmNumDocInv INT,@pmIdCiaDocInv CHAR(2),@pmItemDocInv INT,@pmTarifOtros MONEY,@pmCod_UN VARCHAR(30),@pmCod_Corr VARCHAR(8),@pmCod_Desg VARCHAR(8),@pmDescripcionRP VARCHAR(500)

 AS 
 INSERT INTO Trn_TraRemMcias (TipDoc,NumOrden,IdCia,Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat,IdTmcia,IdMnjo,CdRango,Cases,Cajas,Palets,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,CdAgencia
,Cumplido,IdCiaCump,FechaCump,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp,PesoCont,SedeRem,SedeDest,TipDocInv,NumDocInv,IdCiaDocInv,ItemDocInv,TarifOtros,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP)
 VALUES (@pmTipDoc,@pmNumOrden,@pmIdCia,@pmItem,@pmIdMercancia,@pmDescripMcias,@pmCantidad,@pmPesoNeto,@pmUndMed,@pmdmsAlto,@pmdmsAncho,@pmdmsLargo,@pmVolumen,@pmUndVol,@pmIdUnd,@pmIdEmp,@pmIdNat,@pmIdTmcia,@pmIdMnjo,@pmCdRango,@pmCases,@pmCajas,@pmPalets,@pmNitRemite,@pmRemitente,@pmDirOrigen,@pmIdOrigen,@pmNitDestntario,@pmDestinatario,@pmDirDestino,@pmIdDestino,@pmTarifClie
,@pmTarifPago,@pmTarifTabla,@pmVrDeclarado,@pmVrSeguro,@pmTarifSeguro,@pmUndTarifa,@pmUndTarifPago,@pmRemision,@pmDocCliente,@pmReferencia1,@pmReferencia2,@pmReferencia3,@pmContenedor1,@pmContenedor2,@pmCdAgencia,@pmCumplido,@pmIdCiaCump,@pmFechaCump,@pmDetalleCump,@pmCantidadCump,@pmPesoCump,@pmVolCump,@pmCasesCump,@pmCajasCump,@pmPaletsCump,@pmTarifCump,@pmPagoCump,@pmUndTarCump,@pmUndTarPagoCump,@pmTipFac,@pmFactura
,@pmIdCiaFac,@pmFechaFac,@pmTarifClieFac,@pmTipOdp,@pmNumeroOdp,@pmIdCiaOdp,@pmTarifOdp,@pmPesoCont,@pmSedeRem,@pmSedeDest,@pmTipDocInv,@pmNumDocInv,@pmIdCiaDocInv,@pmItemDocInv,@pmTarifOtros,@pmCod_UN,@pmCod_Corr,@pmCod_Desg,@pmDescripcionRP)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraReportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTraReportes] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmCdRuta VARCHAR(4),@pmIdPunto INT,@pmFecReporte SMALLDATETIME,@pmTipoRep VARCHAR(10)
,@pmEstadoRep INT,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmCdNovedad VARCHAR(4),@pmObservRep VARCHAR(250),@pmTipoPunto VARCHAR(10),@pmCdPuesto VARCHAR(4),@pmNomConductor VARCHAR(150)
 AS 
 INSERT INTO Trn_TraReportes (TipDoc,Manifiesto,IdCia,Item,CdRuta,IdPunto,FecReporte,TipoRep,EstadoRep,IdUsuario,FechaCrea,CdNovedad,ObservRep,TipoPunto,CdPuesto,NomConductor)
 VALUES (@pmTipDoc,@pmManifiesto,@pmIdCia,@pmItem,@pmCdRuta,@pmIdPunto,@pmFecReporte,@pmTipoRep,@pmEstadoRep,@pmIdUsuario,@pmFechaCrea,@pmCdNovedad,@pmObservRep,@pmTipoPunto,@pmCdPuesto,@pmNomConductor)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraslados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16)
,@pmVrSubTotal MONEY,@pmCantidad DECIMAL(14,4),@pmNumDcmto INT,@pmNumOrden INT,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmModalidad VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTdOrden VARCHAR(3),@pmCdCiaOrden CHAR(2),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME
,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Traslados (TipDoc,Traslado,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,Cantidad,NumDcmto,NumOrden,IdCCosto,IdSubCos,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion
,IdEstado,TimeSys,IdCiaCrea,IdUsuario,TdOrden,CdCiaOrden)
 VALUES (@pmTipDoc,@pmTraslado,@pmIdCia,@pmFecha,@pmIdConcepto,@pmIdTercero,@pmVrSubTotal,@pmCantidad,@pmNumDcmto,@pmNumOrden,@pmIdCCosto,@pmIdSubCos,@pmModalidad,@pmOrigenAdd
,@pmTipCom,@pmComprobante,@pmIdCiaCom,@pmObservacion,@pmIdEstado,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario,@pmTdOrden,@pmCdCiaOrden)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraTalonarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraTalonarios] @pmIdTalonario INT,@pmFecha SMALLDATETIME,@pmNumSerie CHAR(2),@pmNumInicial INT,@pmNumFinal INT,@pmNumAuto BIT,@pmNumActual INT,@pmIdRespons VARCHAR(16)
,@pmNomRespons VARCHAR(150),@pmAnulado BIT,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraTalonarios (IdTalonario,Fecha,NumSerie,NumInicial,NumFinal,NumAuto,NumActual,IdRespons,NomRespons,Anulado,TimeSys,IdUsuario)
 VALUES (@pmIdTalonario,@pmFecha,@pmNumSerie,@pmNumInicial,@pmNumFinal,@pmNumAuto,@pmNumActual,@pmIdRespons,@pmNomRespons,@pmAnulado,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraTraslados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmTipoTraslado INT,@pmIdBodega VARCHAR(4),@pmIdBodDtno VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmCantidad INT,@pmPesoTotal DECIMAL(14,4)
,@pmManifiesto INT,@pmCdCiaMuc CHAR(2),@pmEstadoRec INT,@pmFechaRec SMALLDATETIME,@pmCedRecibido VARCHAR(16),@pmNomRecibido VARCHAR(150),@pmObservacion VARCHAR(1000),@pmOrigenAdd VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdCiaCrea CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraTraslados (TipDoc,Traslado,IdCia,Fecha,FecDespacho,TipoTraslado,IdBodega,IdBodDtno,IdVehiculo,IdConductor,Cantidad,PesoTotal,Manifiesto,CdCiaMuc,EstadoRec,FechaRec,CedRecibido,NomRecibido,Observacion,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario)
 VALUES (@pmTipDoc,@pmTraslado,@pmIdCia,@pmFecha,@pmFecDespacho,@pmTipoTraslado,@pmIdBodega,@pmIdBodDtno,@pmIdVehiculo,@pmIdConductor,@pmCantidad,@pmPesoTotal,@pmManifiesto,@pmCdCiaMuc,@pmEstadoRec,@pmFechaRec,@pmCedRecibido,@pmNomRecibido,@pmObservacion,@pmOrigenAdd,@pmTimeSys,@pmIdCiaCrea,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsTraTurn]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTraTurn] @pmNumero INT,@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIndTurno INT,@pmFecha SMALLDATETIME
,@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmEstado INT,@pmTipOrd VARCHAR(3)
,@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmFecOrden SMALLDATETIME,@pmNitCliente VARCHAR(16),@pmSedeClie VARCHAR(10),@pmAutorizac INT
,@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_TraTurn (Numero,IdCia,IdVehiculo,IndTurno,Fecha,IdConductor,nRemolque,Estado,TipOrd,NumOrden,IdCiaOrd,FecOrden,IdUsuario,FechaCrea,NitCliente,SedeClie,Autorizac)
 VALUES (@pmNumero,@pmIdCia,@pmIdVehiculo,@pmIndTurno,@pmFecha,@pmIdConductor,@pmnRemolque,@pmEstado
,@pmTipOrd,@pmNumOrden,@pmIdCiaOrd,@pmFecOrden,@pmIdUsuario,@pmFechaCrea,@pmNitCliente,@pmSedeClie,@pmAutorizac)
GO
/****** Object:  StoredProcedure [dbo].[paInsTurnos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTurnos] @pmIdTurno VARCHAR(4),@pmTurno VARCHAR(50),@pmHoraInicial VARCHAR(10),@pmHoraFinal VARCHAR(10),@pmInactivo BIT
 AS 
 INSERT INTO Turnos (IdTurno,Turno,HoraInicial,HoraFinal,Inactivo)
 VALUES (@pmIdTurno,@pmTurno,@pmHoraInicial,@pmHoraFinal,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsUm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsUm] @pmUndMed VARCHAR(10),@pmUnidad VARCHAR(50),@pmCarga BIT,@pmCodUMFE VARCHAR(20)
 AS 
 INSERT INTO Sys_Um (UndMed,Unidad,Carga,CodUMFE)
 VALUES (@pmUndMed,@pmUnidad,@pmCarga,@pmCodUMFE)
GO
/****** Object:  StoredProcedure [dbo].[paInsUndMed]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsUndMed] @pmIdUnd VARCHAR(4),@pmUnidad VARCHAR(50),@pmIdMat VARCHAR(4),@pmIdEmp VARCHAR(4),@pmFormRecp VARCHAR(10),@pmClaseEmp VARCHAR(10),@pmDimAlto DECIMAL(14,4)
,@pmDimAncho DECIMAL(14,4),@pmDimLargo DECIMAL(14,4),@pmDimVolm DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmPesoEpq DECIMAL(14,4),@pmCapcMax DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmSimbUnd VARCHAR(10)
,@pmObserv VARCHAR(250),@pmInactivo BIT
 AS 
 INSERT INTO UndMed (IdUnd,Unidad,IdMat,IdEmp,FormRecp,ClaseEmp,DimAlto,DimAncho,DimLargo,DimVolm,UndMed,PesoEpq,CapcMax,UndCapc,SimbUnd,Observ,Inactivo)
 VALUES (@pmIdUnd,@pmUnidad,@pmIdMat,@pmIdEmp,@pmFormRecp,@pmClaseEmp,@pmDimAlto,@pmDimAncho,@pmDimLargo,@pmDimVolm,@pmUndMed,@pmPesoEpq
,@pmCapcMax,@pmUndCapc,@pmSimbUnd,@pmObserv,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsUOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsUOpciones] @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20),@pmValor VARCHAR(50)
 AS 
 INSERT INTO adm_UOpciones (IdUsuario,NomOpcion,Valor)
 VALUES (@pmIdUsuario,@pmNomOpcion,@pmValor)
GO
/****** Object:  StoredProcedure [dbo].[paInsUsuarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsUsuarios] @pmIdUsuario VARCHAR(11),@pmUsuario VARCHAR(50),@pmPwdLog VARCHAR(30),@pmIdGrupo INT,@pmIdEstacion CHAR(2),@pmIdCargo VARCHAR(4),@pmConectado BIT,@pmFechaAcc SMALLDATETIME
,@pmFechaClave SMALLDATETIME,@pmCaducidad INT,@pmLoginSQL VARCHAR(20),@pmPwdSQL VARCHAR(20),@pmModoSQL VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO adm_Usuarios (IdUsuario,Usuario,PwdLog,IdGrupo,IdEstacion,IdCargo,Conectado,FechaAcc,FechaClave,Caducidad,LoginSQL,PwdSQL,ModoSQL,Inactivo)
 VALUES (@pmIdUsuario,@pmUsuario,@pmPwdLog,@pmIdGrupo,@pmIdEstacion,@pmIdCargo,@pmConectado,@pmFechaAcc,@pmFechaClave,@pmCaducidad,@pmLoginSQL
,@pmPwdSQL,@pmModoSQL,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paInsUsucaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsUsucaja] @pmIdUsuario VARCHAR(11),@pmnFormato VARCHAR(10),@pmCdCajero VARCHAR(11),@pmIdConcepto VARCHAR(4),@pmCdBodega VARCHAR(4)
,@pmLtaPrec CHAR(1),@pmIdVend VARCHAR(16),@pmCdCms VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmAbreCajon VARCHAR(10),@pmFechaAdd SMALLDATETIME
 AS 
 INSERT INTO adm_Usucaja (IdUsuario,nFormato,CdCajero,IdConcepto,CdBodega,LtaPrec,IdVend,CdCms,CdCCosto,CdSubCos,AbreCajon,FechaAdd)
 VALUES (@pmIdUsuario,@pmnFormato,@pmCdCajero,@pmIdConcepto,@pmCdBodega,@pmLtaPrec,@pmIdVend,@pmCdCms,@pmCdCCosto,@pmCdSubCos,@pmAbreCajon,@pmFechaAdd)
GO
/****** Object:  StoredProcedure [dbo].[paInsVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT,@pmFecha SMALLDATETIME
,@pmHoraServ VARCHAR(10),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmNumMovil VARCHAR(10),@pmCentCosto VARCHAR(50),@pmUnidades DECIMAL(14,4),@pmHoraRec DECIMAL(14,4)
,@pmHoraEspera DECIMAL(14,4),@pmFactUnid BIT,@pmFactRutas BIT,@pmFactHoras BIT,@pmVrPago MONEY,@pmVrCobro MONEY,@pmPlacaVeh VARCHAR(10),@pmCdConductor VARCHAR(16),@pmNomConductor VARCHAR(150)
,@pmCantPasaj INT,@pmUsuarios VARCHAR(1000),@pmTipFac VARCHAR(3),@pmNumFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(1000),@pmFechaUp SMALLDATETIME,@pmCdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_Vales (TipDoc,nRadica,IdCia,Item,TipoRango,IdRango,NumSerie,NumForma,Fecha,HoraServ,IdCliente,IdAgencia,IdCuenta,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,PlacaVeh
,CdConductor,NomConductor,CantPasaj,Usuarios,TipFac,NumFactura,IdCiaFac,FechaFac,Anulado,NumDev,FecDev,Observacion,FechaUp,CdUsuario)
 VALUES (@pmTipDoc,@pmnRadica,@pmIdCia,@pmItem,@pmTipoRango,@pmIdRango,@pmNumSerie,@pmNumForma,@pmFecha,@pmHoraServ,@pmIdCliente,@pmIdAgencia,@pmIdCuenta,@pmNumMovil,@pmCentCosto,@pmUnidades
,@pmHoraRec,@pmHoraEspera,@pmFactUnid,@pmFactRutas,@pmFactHoras,@pmVrPago,@pmVrCobro,@pmPlacaVeh,@pmCdConductor,@pmNomConductor,@pmCantPasaj,@pmUsuarios,@pmTipFac,@pmNumFactura,@pmIdCiaFac
,@pmFechaFac,@pmAnulado,@pmNumDev,@pmFecDev,@pmObservacion,@pmFechaUp,@pmCdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsValesRutas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsValesRutas] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdRuta VARCHAR(4)
,@pmTarifPago MONEY,@pmTarifCobro MONEY,@pmDescripRuta VARCHAR(50)
 AS 
 INSERT INTO Trn_ValesRutas (TipDoc,nRadica,IdCia,Item,IdRuta,TarifPago,TarifCobro,DescripRuta)
 VALUES (@pmTipDoc,@pmnRadica,@pmIdCia,@pmItem,@pmIdRuta,@pmTarifPago,@pmTarifCobro,@pmDescripRuta)
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_Contrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVeh_Contrato] @pmNumContrato INT,@pmIdVehiculo VARCHAR(10),@pmIdAdmon VARCHAR(4),@pmIdTipCon VARCHAR(4)
,@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmObservaciones VARCHAR(250)
,@pmNumPagare VARCHAR(20),@pmArchPagare VARCHAR(50),@pmFecUpdate SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Veh_Contrato (NumContrato,IdVehiculo,IdAdmon,IdTipCon,FecIngreso,FecRetiro,FecVigencia,Observaciones,NumPagare,ArchPagare,FecUpdate,IdUsuario)
 VALUES (@pmNumContrato,@pmIdVehiculo,@pmIdAdmon,@pmIdTipCon,@pmFecIngreso,@pmFecRetiro,@pmFecVigencia,@pmObservaciones
,@pmNumPagare,@pmArchPagare,@pmFecUpdate,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_Cupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVeh_Cupos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmValorCupo MONEY,@pmValorSaldo MONEY,@pmFecUpdate SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Veh_Cupos (IdVehiculo,IdClase,ValorCupo,ValorSaldo,FecUpdate,IdUsuario)
 VALUES (@pmIdVehiculo,@pmIdClase,@pmValorCupo,@pmValorSaldo,@pmFecUpdate,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_CuposUni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVeh_CuposUni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
AS 
 IF EXISTS (SELECT * FROM Veh_Cupos WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
  INSERT INTO Veh_Cupos (IdVehiculo,IdClase,ValorCupo,ValorSaldo,FecUpdate,IdUsuario)
  SELECT @pmNewVehiculo,IdClase,SUM(ValorCupo),SUM(ValorSaldo),MAX(FecUpdate),'ADMIN'
  FROM Veh_Cupos WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
  GROUP BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_Saldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVeh_Saldos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmIdCia CHAR(2),@pmValorSaldo MONEY
 AS 
 INSERT INTO Veh_Saldos (IdVehiculo,IdClase,IdCia,ValorSaldo)
 VALUES (@pmIdVehiculo,@pmIdClase,@pmIdCia,@pmValorSaldo)
GO
/****** Object:  StoredProcedure [dbo].[paInsVeh_SaldosUni]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVeh_SaldosUni] @pmIdVehiculo VARCHAR(10),@pmIdVehiculoDos VARCHAR(10),@pmNewVehiculo VARCHAR(10)
AS 
 IF EXISTS (SELECT * FROM Veh_Saldos WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos)
  INSERT INTO Veh_Saldos (IdVehiculo,IdClase,IdCia,ValorSaldo)
  SELECT @pmNewVehiculo,IdClase,IdCia,SUM(ValorSaldo) 
  FROM Veh_Saldos WHERE IdVehiculo=@pmIdVehiculo OR IdVehiculo=@pmIdVehiculoDos
  GROUP BY IdClase,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paInsVehClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehClientes] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmIdTipoVeh VARCHAR(4),@pmIdMarca VARCHAR(4),@pmLinMarca VARCHAR(30),@pmColorVeh VARCHAR(30),@pmIdTipoMot VARCHAR(4),@pmModelo VARCHAR(4),@pmClaseMat VARCHAR(10)
,@pmCilind DECIMAL(14,4),@pmIdCom VARCHAR(4),@pmIdLub VARCHAR(4),@pmIdMarLub VARCHAR(4),@pmIdTlla VARCHAR(4),@pmIdMarlla VARCHAR(4),@pmIdFiltro VARCHAR(4),@pmIdMarFil VARCHAR(4),@pmNumSoat VARCHAR(30),@pmFecSoat SMALLDATETIME,@pmVigSoat SMALLDATETIME
,@pmNitEmpSoat VARCHAR(16),@pmRevTecMec VARCHAR(30),@pmFecTecMec SMALLDATETIME,@pmVigTecMec SMALLDATETIME,@pmCertGases VARCHAR(30),@pmFecCertGas SMALLDATETIME,@pmVigCertGas SMALLDATETIME,@pmKmInicial INT,@pmKmActual INT,@pmNitCliente VARCHAR(16)
,@pmCondPago VARCHAR(10),@pmNumCredito VARCHAR(30),@pmObservacion VARCHAR(250),@pmPathFoto VARCHAR(30),@pmFecPriServ SMALLDATETIME,@pmFecUltServ SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO VehClientes (IdVehiculo,NumVeh,IdTipoVeh,IdMarca,LinMarca,ColorVeh,IdTipoMot,Modelo,ClaseMat,Cilind,IdCom,IdLub,IdMarLub,IdTlla,IdMarlla,IdFiltro,IdMarFil,NumSoat,FecSoat,VigSoat,NitEmpSoat,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,KmInicial,KmActual,NitCliente,CondPago
,NumCredito,Observacion,PathFoto,FecPriServ,FecUltServ,IdEstado,Inactivo,FechaAdd,IdUsuario)
 VALUES (@pmIdVehiculo,@pmNumVeh,@pmIdTipoVeh,@pmIdMarca,@pmLinMarca,@pmColorVeh,@pmIdTipoMot,@pmModelo,@pmClaseMat,@pmCilind,@pmIdCom,@pmIdLub,@pmIdMarLub,@pmIdTlla,@pmIdMarlla,@pmIdFiltro,@pmIdMarFil,@pmNumSoat,@pmFecSoat,@pmVigSoat,@pmNitEmpSoat,@pmRevTecMec
,@pmFecTecMec,@pmVigTecMec,@pmCertGases,@pmFecCertGas,@pmVigCertGas,@pmKmInicial,@pmKmActual,@pmNitCliente,@pmCondPago,@pmNumCredito,@pmObservacion,@pmPathFoto,@pmFecPriServ,@pmFecUltServ,@pmIdEstado,@pmInactivo,@pmFechaAdd,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehConductor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehConductor] @pmIdVehiculo VARCHAR(10),@pmNumero INT,@pmFecha SMALLDATETIME,@pmIdPropietario VARCHAR(16)
,@pmIdConductor VARCHAR(16),@pmIdCondNuevo VARCHAR(16),@pmObservacion VARCHAR(150),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_VehConductor (IdVehiculo,Numero,Fecha,IdPropietario,IdConductor,IdCondNuevo,Observacion,TimeSys,IdUsuario)
 VALUES (@pmIdVehiculo,@pmNumero,@pmFecha,@pmIdPropietario,@pmIdConductor,@pmIdCondNuevo,@pmObservacion,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehiculos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehiculos] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmClaseVeh VARCHAR(10),@pmIdTipoVeh VARCHAR(4),@pmIdMarca VARCHAR(4),@pmIdLinea VARCHAR(10),@pmIdColor VARCHAR(4),@pmIdTipoMot VARCHAR(4),@pmIdCrceria VARCHAR(4),@pmModelo VARCHAR(4),@pmFecRep SMALLDATETIME,@pmConfig VARCHAR(5),@pmVehArtic BIT,@pmNumLlan INT,@pmNumLlans INT,@pmIdCat VARCHAR(4),@pmCdCatv VARCHAR(4)
,@pmClaseMat VARCHAR(10),@pmCilind DECIMAL(14,4),@pmCapTanq DECIMAL(14,4),@pmIdCom VARCHAR(4),@pmIdLub VARCHAR(4),@pmIdTlla VARCHAR(4),@pmIdMarlla VARCHAR(4),@pmPesoVacio DECIMAL(14,4),@pmPesoMax DECIMAL(14,4),@pmNumMotor VARCHAR(30),@pmSerieChasis VARCHAR(30),@pmNumSerie VARCHAR(30),@pmCdRemque VARCHAR(10),@pmLongitud DECIMAL(14,4),@pmCarrAlto DECIMAL(14,4),@pmCarrAncho DECIMAL(14,4),@pmCarrLargo DECIMAL(14,4)
,@pmCarrCapac DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmComptmtos INT,@pmCapComp VARCHAR(50),@pmPasjerosPie INT,@pmPasjerosSen INT,@pmNitEmpresa VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmIdPpd VARCHAR(4),@pmAdquisc VARCHAR(10),@pmNitProv VARCHAR(16),@pmFecCompra SMALLDATETIME,@pmVrComcial MONEY,@pmVrAseg MONEY,@pmVrAvaludo MONEY,@pmVidaUtil INT
,@pmFecSalida SMALLDATETIME,@pmNContrato INT,@pmIdAdmon VARCHAR(4),@pmIdNiv VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmCdGrupR VARCHAR(4),@pmCdTarifa VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmNumSoat VARCHAR(30),@pmFecSoat SMALLDATETIME,@pmVigSoat SMALLDATETIME,@pmNitEmpSoat VARCHAR(16),@pmTarjProp VARCHAR(30),@pmFecTProp SMALLDATETIME
,@pmVigTProp SMALLDATETIME,@pmCdLugTp VARCHAR(8),@pmUlttramite VARCHAR(150),@pmRespCivil VARCHAR(30),@pmFecRCivil SMALLDATETIME,@pmVigRCivil SMALLDATETIME,@pmRegNalCarga VARCHAR(30),@pmFecRegNal SMALLDATETIME,@pmVigRegNal SMALLDATETIME,@pmKmInicial INT,@pmKmActual INT,@pmKm2Actual INT,@pmRegtradora BIT,@pmCentInicial INT,@pmCentFinal INT,@pmVrLmtCred MONEY,@pmVrSaldoAct MONEY,@pmDescripcion VARCHAR(100)
,@pmObservacion VARCHAR(250),@pmCdCenSer VARCHAR(4),@pmCdLocal VARCHAR(8),@pmUbicacion VARCHAR(100),@pmPathFoto VARCHAR(30),@pmFecPriServ SMALLDATETIME,@pmFecUltServ SMALLDATETIME,@pmFecUltAcc SMALLDATETIME,@pmTieneAcc BIT,@pmFecPagImp SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmTipoAfil VARCHAR(10),@pmRevTecMec VARCHAR(30),@pmFecTecMec SMALLDATETIME,@pmVigTecMec SMALLDATETIME,@pmCertGases VARCHAR(30),@pmFecCertGas SMALLDATETIME,@pmVigCertGas SMALLDATETIME,@pmTarjOper VARCHAR(30),@pmFecTarjOper SMALLDATETIME,@pmVigTarjOper SMALLDATETIME,@pmFechaAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
,@pmValorCupo MONEY,@pmObligaTProd BIT,@pmGarantiaAcc BIT,@pmDocCompleta BIT,@pmCertMovilizacion VARCHAR(20),@pmFecCertMovil SMALLDATETIME,@pmVigCertMovil SMALLDATETIME,@pmCdRutaHab VARCHAR(4),@pmDeclaracImp VARCHAR(50),@pmTipoIngreso VARCHAR(4),@pmIdOrgTra VARCHAR(8),@pmGPSoperador VARCHAR(250),@pmGPSUsuario VARCHAR(50),@pmGPSClave VARCHAR(50),@pmCantFiltros DECIMAL(14,4),@pmGPSIdOper VARCHAR(16),@pmLiqFletePropio BIT,@pmEdoVincula INT
 AS 
 INSERT INTO Vehiculos (IdVehiculo,NumVeh,ClaseVeh,IdTipoVeh,IdMarca,IdLinea,IdColor,IdTipoMot,IdCrceria,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans,IdCat,CdCatv,ClaseMat,Cilind,CapTanq,IdCom,IdLub,IdTlla,IdMarlla,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie,PasjerosSen,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,IdPpd,Adquisc,NitProv,FecCompra,VrComcial,VrAseg
,VrAvaludo,VidaUtil,FecSalida,NContrato,IdAdmon,IdNiv,IdGrupo,CdGrupR,CdTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,TarjProp,FecTProp,VigTProp,CdLugTp,Ulttramite,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal,KmInicial,KmActual,Km2Actual,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,Descripcion,Observacion,CdCenSer,CdLocal,Ubicacion,PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,IdEstado,Inactivo
,TipoAfil,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,FechaAdd,IdUsuario,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil,CdRutaHab,DeclaracImp,TipoIngreso,IdOrgTra,GPSoperador,GPSUsuario,GPSClave,CantFiltros,GPSIdOper,LiqFletePropio,EdoVincula)
 VALUES (@pmIdVehiculo,@pmNumVeh,@pmClaseVeh,@pmIdTipoVeh,@pmIdMarca,@pmIdLinea,@pmIdColor,@pmIdTipoMot,@pmIdCrceria,@pmModelo,@pmFecRep,@pmConfig,@pmVehArtic,@pmNumLlan,@pmNumLlans,@pmIdCat,@pmCdCatv,@pmClaseMat,@pmCilind,@pmCapTanq,@pmIdCom,@pmIdLub,@pmIdTlla,@pmIdMarlla,@pmPesoVacio,@pmPesoMax,@pmNumMotor,@pmSerieChasis,@pmNumSerie,@pmCdRemque,@pmLongitud,@pmCarrAlto,@pmCarrAncho,@pmCarrLargo,@pmCarrCapac
,@pmUndCapc,@pmComptmtos,@pmCapComp,@pmPasjerosPie,@pmPasjerosSen,@pmNitEmpresa,@pmIdPropietario,@pmIdPoseedor,@pmIdConductor,@pmIdPpd,@pmAdquisc,@pmNitProv,@pmFecCompra,@pmVrComcial,@pmVrAseg,@pmVrAvaludo,@pmVidaUtil,@pmFecSalida,@pmNContrato,@pmIdAdmon,@pmIdNiv,@pmIdGrupo,@pmCdGrupR,@pmCdTarifa,@pmFecIngreso,@pmFecVigencia,@pmFecRetiro,@pmNumSoat,@pmFecSoat,@pmVigSoat,@pmNitEmpSoat,@pmTarjProp,@pmFecTProp
,@pmVigTProp,@pmCdLugTp,@pmUlttramite,@pmRespCivil,@pmFecRCivil,@pmVigRCivil,@pmRegNalCarga,@pmFecRegNal,@pmVigRegNal,@pmKmInicial,@pmKmActual,@pmKm2Actual,@pmRegtradora,@pmCentInicial,@pmCentFinal,@pmVrLmtCred,@pmVrSaldoAct,@pmDescripcion,@pmObservacion,@pmCdCenSer,@pmCdLocal,@pmUbicacion,@pmPathFoto,@pmFecPriServ,@pmFecUltServ,@pmFecUltAcc,@pmTieneAcc,@pmFecPagImp,@pmIdEstado,@pmInactivo
,@pmTipoAfil,@pmRevTecMec,@pmFecTecMec,@pmVigTecMec,@pmCertGases,@pmFecCertGas,@pmVigCertGas,@pmTarjOper,@pmFecTarjOper,@pmVigTarjOper,@pmFechaAdd,@pmIdUsuario,@pmValorCupo,@pmObligaTProd,@pmGarantiaAcc,@pmDocCompleta,@pmCertMovilizacion,@pmFecCertMovil,@pmVigCertMovil,@pmCdRutaHab,@pmDeclaracImp,@pmTipoIngreso,@pmIdOrgTra,@pmGPSoperador,@pmGPSUsuario,@pmGPSClave,@pmCantFiltros,@pmGPSIdOper,@pmLiqFletePropio,@pmEdoVincula)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehiculos_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehiculos_Sel] @pmIdVehiculo VARCHAR(10),@pmNewVehiculo VARCHAR(10)
 AS 
 INSERT INTO Vehiculos (IdVehiculo,NumVeh,ClaseVeh,IdTipoVeh,IdMarca,IdLinea,IdColor,IdTipoMot,IdCrceria,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans,IdCat,CdCatv,ClaseMat,Cilind,CapTanq,IdCom,IdLub,IdTlla,IdMarlla,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie,PasjerosSen,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,IdPpd,Adquisc,NitProv,FecCompra,VrComcial,VrAseg
,VrAvaludo,VidaUtil,FecSalida,NContrato,IdAdmon,IdNiv,IdGrupo,CdGrupR,CdTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,TarjProp,FecTProp,VigTProp,CdLugTp,Ulttramite,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal,KmInicial,KmActual,Km2Actual,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,Descripcion,Observacion,CdCenSer,CdLocal,Ubicacion,PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,IdEstado,Inactivo
,TipoAfil,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,FechaAdd,IdUsuario,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil,CdRutaHab,DeclaracImp,TipoIngreso,IdOrgTra,GPSoperador,GPSUsuario,GPSClave,CantFiltros,GPSIdOper,LiqFletePropio,EdoVincula)
SELECT  @pmNewVehiculo,NumVeh,ClaseVeh,IdTipoVeh,IdMarca,IdLinea,IdColor,IdTipoMot,IdCrceria,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans,IdCat,CdCatv,ClaseMat,Cilind,CapTanq,IdCom,IdLub,IdTlla,IdMarlla,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie,PasjerosSen,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,IdPpd,Adquisc,NitProv,FecCompra,VrComcial,VrAseg
,VrAvaludo,VidaUtil,FecSalida,NContrato,IdAdmon,IdNiv,IdGrupo,CdGrupR,CdTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,TarjProp,FecTProp,VigTProp,CdLugTp,Ulttramite,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal,KmInicial,KmActual,Km2Actual,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,Descripcion,Observacion,CdCenSer,CdLocal,Ubicacion,PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,IdEstado,Inactivo
,TipoAfil,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,FechaAdd,IdUsuario,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil,CdRutaHab,DeclaracImp,TipoIngreso,IdOrgTra,GPSoperador,GPSUsuario,GPSClave,CantFiltros,GPSIdOper,LiqFletePropio,EdoVincula
 FROM Vehiculos WHERE  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paInsVehLecturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehLecturas] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipoUnidad VARCHAR(3),@pmpVehiculo VARCHAR(10)
,@pmKmsAnterior INT,@pmKmsActual INT,@pmKms2Anterior INT,@pmKms2Actual INT,@pmTipoLectura VARCHAR(10),@pmObservacion VARCHAR(250),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_VehLecturas (TipDoc,Numero,IdCia,Item,Fecha,TipoUnidad,pVehiculo,KmsAnterior,KmsActual,Kms2Anterior,Kms2Actual,TipoLectura,Observacion,TimeSys,IdUsuario)
 VALUES (@pmTipDoc,@pmNumero,@pmIdCia,@pmItem,@pmFecha,@pmTipoUnidad,@pmpVehiculo,@pmKmsAnterior,@pmKmsActual,@pmKms2Anterior,@pmKms2Actual,@pmTipoLectura,@pmObservacion,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehPartes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehPartes] @pmIdVehiculo VARCHAR(10),@pmNumParte VARCHAR(20),@pmDescripParte VARCHAR(250),@pmIdSistema VARCHAR(4),@pmTipoControl INT,@pmIntervalo_km INT,@pmIntervalo_dias INT,@pmkmActual INT,@pmkmCambio INT
,@pmFechaCambio SMALLDATETIME,@pmCdProdRep VARCHAR(16),@pmTipoUnidad CHAR(1),@pmTipoParte VARCHAR(10),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFechaRetiro SMALLDATETIME,@pmIntervalo_Horas INT
,@pmkmManual INT,@pmkmSat INT,@pmkmCambioMan INT,@pmkmCambioSat INT,@pmHorasTrab INT,@pmHsUltCambio INT,@pmMarcaParte VARCHAR(20),@pmModeloParte VARCHAR(20),@pmNumSerie VARCHAR(30),@pmFechaCrea SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO VehPartes (IdVehiculo,NumParte,DescripParte,IdSistema,TipoControl,Intervalo_km,Intervalo_dias,Intervalo_Horas,kmActual,kmManual,kmSat,kmCambio,kmCambioMan,kmCambioSat,FechaCambio,CdProdRep,TipoUnidad,TipoParte
,IdEstado,Inactivo,FechaRetiro,FechaCrea,IdUsuario,HorasTrab,HsUltCambio,MarcaParte,ModeloParte,NumSerie)
 VALUES (@pmIdVehiculo,@pmNumParte,@pmDescripParte,@pmIdSistema,@pmTipoControl,@pmIntervalo_km,@pmIntervalo_dias,@pmIntervalo_Horas,@pmkmActual,@pmkmManual,@pmkmSat,@pmkmCambio,@pmkmCambioMan,@pmkmCambioSat,@pmFechaCambio
,@pmCdProdRep,@pmTipoUnidad,@pmTipoParte,@pmIdEstado,@pmInactivo,@pmFechaRetiro,@pmFechaCrea,@pmIdUsuario,@pmHorasTrab,@pmHsUltCambio,@pmMarcaParte,@pmModeloParte,@pmNumSerie)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehPolizas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsVehPolizas] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmNumero VARCHAR(30),@pmFecEmision SMALLDATETIME
,@pmFecVigencia SMALLDATETIME,@pmNitCompania VARCHAR(16),@pmValor MONEY,@pmComntarios VARCHAR(100),@pmDiasAviso INT
 AS 
 INSERT INTO VehPolizas (IdVehiculo,IdClase,Numero,FecEmision,FecVigencia,NitCompania,Valor,Comntarios,DiasAviso)
 VALUES (@pmIdVehiculo,@pmIdClase,@pmNumero,@pmFecEmision,@pmFecVigencia,@pmNitCompania,@pmValor,@pmComntarios,@pmDiasAviso)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehRemolq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehRemolq] @pmIdRemque VARCHAR(10),@pmIdMarca VARCHAR(4),@pmIdColor VARCHAR(4),@pmIdCrceria VARCHAR(4),@pmModelo VARCHAR(4),@pmNEjes INT,@pmnLlantas INT,@pmAltura DECIMAL(14,4)
,@pmAncho DECIMAL(14,4),@pmLargo DECIMAL(14,4),@pmVlumen DECIMAL(14,4),@pmPesoKg DECIMAL(14,4),@pmCapneta DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmNumComp INT,@pmCapcComp VARCHAR(50),@pmNumSerial VARCHAR(30)
,@pmIdPropietario VARCHAR(16),@pmNitProv VARCHAR(16),@pmFecCompra SMALLDATETIME,@pmVidaUtil INT,@pmVrComercial MONEY,@pmVrAvaludo MONEY,@pmVrAsegurado MONEY,@pmKilmetraje INT,@pmEquipoAdic VARCHAR(50)
,@pmDescripcion VARCHAR(100),@pmCdCenSer VARCHAR(4),@pmCdLocal VARCHAR(8),@pmUbicacion VARCHAR(100),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTarjetaProp VARCHAR(30),@pmFecTarjProp  SMALLDATETIME
,@pmVigTarjProp SMALLDATETIME,@pmConfEjes VARCHAR(5),@pmHidrostatica VARCHAR(30),@pmFecPruebaHid SMALLDATETIME,@pmVigPruebaHid SMALLDATETIME,@pmkmRuta INT,@pmkmOtro INT,@pmKingpin VARCHAR(50),@pmFecKingpin SMALLDATETIME
,@pmVigKingpin SMALLDATETIME,@pmArcFotoRem VARCHAR(50),@pmFecVigExtintor SMALLDATETIME,@pmCdLocTarj VARCHAR(8),@pmOperador_GPS VARCHAR(250),@pmUsuario_GPS VARCHAR(50),@pmClave_GPS VARCHAR(50),@pmIdOper_GPS VARCHAR(16)
,@pmTipo_Afil VARCHAR(10),@pmEdoVincula INT,@pmFechaVincula SMALLDATETIME,@pmFechaRetiro SMALLDATETIME,@pmFecAdd SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO VehRemolq (IdRemque,IdMarca,IdColor,IdCrceria,Modelo,NEjes,nLlantas,ConfEjes,Altura,Ancho,Largo,Vlumen,PesoKg,Capneta,UndCapc,NumComp,CapcComp,NumSerial,IdPropietario,NitProv,FecCompra,VidaUtil,VrComercial,VrAvaludo,VrAsegurado,Kilmetraje
,EquipoAdic,Descripcion,CdCenSer,CdLocal,Ubicacion,Observacion,IdEstado,Inactivo,FecAdd,IdUsuario,TarjetaProp,FecTarjProp,VigTarjProp,Hidrostatica,FecPruebaHid,VigPruebaHid,kmRuta,kmOtro,Kingpin,FecKingpin,VigKingpin,ArcFotoRem,FecVigExtintor
,CdLocTarj,Operador_GPS,Usuario_GPS,Clave_GPS,IdOper_GPS,Tipo_Afil,EdoVincula,FechaVincula,FechaRetiro)
 VALUES (@pmIdRemque,@pmIdMarca,@pmIdColor,@pmIdCrceria,@pmModelo,@pmNEjes,@pmnLlantas,@pmConfEjes,@pmAltura,@pmAncho,@pmLargo,@pmVlumen,@pmPesoKg,@pmCapneta,@pmUndCapc,@pmNumComp,@pmCapcComp,@pmNumSerial,@pmIdPropietario
,@pmNitProv,@pmFecCompra,@pmVidaUtil,@pmVrComercial,@pmVrAvaludo,@pmVrAsegurado,@pmKilmetraje,@pmEquipoAdic,@pmDescripcion,@pmCdCenSer,@pmCdLocal,@pmUbicacion,@pmObservacion,@pmIdEstado,@pmInactivo,@pmFecAdd,@pmIdUsuario
,@pmTarjetaProp,@pmFecTarjProp,@pmVigTarjProp,@pmHidrostatica,@pmFecPruebaHid,@pmVigPruebaHid,@pmkmRuta,@pmkmOtro,@pmKingpin,@pmFecKingpin,@pmVigKingpin,@pmArcFotoRem,@pmFecVigExtintor,@pmCdLocTarj,@pmOperador_GPS,@pmUsuario_GPS,@pmClave_GPS,@pmIdOper_GPS,@pmTipo_Afil,@pmEdoVincula,@pmFechaVincula,@pmFechaRetiro)
GO
/****** Object:  StoredProcedure [dbo].[paInsVehRemolq_Sel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehRemolq_Sel] @pmIdRemque VARCHAR(10),@pmNewId VARCHAR(10)
 AS 
INSERT INTO VehRemolq (IdRemque,IdMarca,IdColor,IdCrceria,Modelo,NEjes,nLlantas,ConfEjes,Altura,Ancho,Largo,Vlumen,PesoKg,Capneta,UndCapc,NumComp,CapcComp,NumSerial,IdPropietario,NitProv,FecCompra,VidaUtil,VrComercial,VrAvaludo,VrAsegurado,Kilmetraje
,EquipoAdic,Descripcion,CdCenSer,CdLocal,Ubicacion,Observacion,IdEstado,Inactivo,FecAdd,IdUsuario,TarjetaProp,FecTarjProp,VigTarjProp,Hidrostatica,FecPruebaHid,VigPruebaHid,kmRuta,kmOtro,Kingpin,FecKingpin,VigKingpin,ArcFotoRem,FecVigExtintor,CdLocTarj,Operador_GPS,Usuario_GPS,Clave_GPS,IdOper_GPS,Tipo_Afil,EdoVincula,FechaVincula,FechaRetiro)
SELECT @pmNewId,IdMarca,IdColor,IdCrceria,Modelo,NEjes,nLlantas,ConfEjes,Altura,Ancho,Largo,Vlumen,PesoKg,Capneta,UndCapc,NumComp,CapcComp,NumSerial,IdPropietario,NitProv,FecCompra,VidaUtil,VrComercial,VrAvaludo,VrAsegurado,Kilmetraje
,EquipoAdic,Descripcion,CdCenSer,CdLocal,Ubicacion,Observacion,IdEstado,Inactivo,FecAdd,IdUsuario,TarjetaProp,FecTarjProp,VigTarjProp,Hidrostatica,FecPruebaHid,VigPruebaHid,kmRuta,kmOtro,Kingpin,FecKingpin,VigKingpin,ArcFotoRem,FecVigExtintor,CdLocTarj,Operador_GPS,Usuario_GPS,Clave_GPS,IdOper_GPS,Tipo_Afil,EdoVincula,FechaVincula,FechaRetiro
FROM VehRemolq WHERE IdRemque=@pmIdRemque
GO
/****** Object:  StoredProcedure [dbo].[paInsVehTraspasos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsVehTraspasos] @pmIdVehiculo VARCHAR(10),@pmNumero INT,@pmFecha SMALLDATETIME,@pmIdPpd VARCHAR(4),@pmIdPropietario VARCHAR(16)
,@pmIdPoseedor VARCHAR(16),@pmIdPropNuevo VARCHAR(16),@pmIdPoseeNuevo VARCHAR(16),@pmIdNewPpd VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmVrComercial MONEY
,@pmVrCupo MONEY,@pmVrAsegurado MONEY,@pmObservacion VARCHAR(150),@pmTipoAfil VARCHAR(10),@pmTipoAfilNew VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 INSERT INTO Trn_VehTraspasos (IdVehiculo,Numero,Fecha,IdPpd,IdPropietario,IdPoseedor,IdPropNuevo,IdPoseeNuevo,IdNewPpd,IdGrupo,VrComercial,VrCupo,VrAsegurado,Observacion,TipoAfil,TipoAfilNew,TimeSys,IdUsuario)
 VALUES (@pmIdVehiculo,@pmNumero,@pmFecha,@pmIdPpd,@pmIdPropietario,@pmIdPoseedor,@pmIdPropNuevo,@pmIdPoseeNuevo,@pmIdNewPpd,@pmIdGrupo,@pmVrComercial,@pmVrCupo
,@pmVrAsegurado,@pmObservacion,@pmTipoAfil,@pmTipoAfilNew,@pmTimeSys,@pmIdUsuario)
GO
/****** Object:  StoredProcedure [dbo].[paInsVencAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsVencAbonos] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmItemFac INT
,@pmVrAbono MONEY,@pmVrDescto MONEY,@pmVrBaseCms MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmComision DECIMAL(14,4),@pmDetalle VARCHAR(150)
,@pmFecPago SMALLDATETIME,@pmTipoAplica VARCHAR(10),@pmTimeSys SMALLDATETIME
 AS 
 INSERT INTO Trn_VencAbonos (TipRec,Recibo,IdCia,Item,Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys)
 VALUES (@pmTipRec,@pmRecibo,@pmIdCia,@pmItem,@pmFecha,@pmTipDoc,@pmFactura,@pmIdCiaFac,@pmItemFac,@pmVrAbono,@pmVrDescto,@pmVrBaseCms,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmComision,@pmDetalle,@pmFecPago,@pmTipoAplica,@pmTimeSys)
GO
/****** Object:  StoredProcedure [dbo].[paInsVencimientos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsVencimientos] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrFactura MONEY,@pmVrAbonado MONEY
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmComision DECIMAL(14,4),@pmTarifDcto DECIMAL(14,4),@pmTipoDcto CHAR(1),@pmTipoBase VARCHAR(10),@pmFecLmtDcto SMALLDATETIME
,@pmIdConcepto VARCHAR(4),@pmReferencia VARCHAR(50),@pmDetalle VARCHAR(150),@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmFecUltPago SMALLDATETIME,@pmNumNota INT,@pmIdCiaNot CHAR(2)
,@pmTarifInt DECIMAL(14,4),@pmFecLiqMora SMALLDATETIME,@pmFecPlazoCal SMALLDATETIME
 AS 
 INSERT INTO Trn_Vencimientos (TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle
,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,FecPlazoCal)
 VALUES (@pmTipDoc,@pmFactura,@pmIdCia,@pmItem,@pmFecha,@pmFechaVence,@pmVrFactura,@pmVrAbonado,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmComision,@pmTarifDcto,@pmTipoDcto
,@pmTipoBase,@pmFecLmtDcto,@pmIdConcepto,@pmReferencia,@pmDetalle,@pmTipRef,@pmDocRef,@pmIdCiaRef,@pmFecUltPago,@pmNumNota,@pmIdCiaNot,@pmTarifInt,@pmFecLiqMora,@pmFecPlazoCal)
GO
/****** Object:  StoredProcedure [dbo].[paInsZonas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsZonas] @pmIdZona VARCHAR(4),@pmZona VARCHAR(50),@pmCdSubCos VARCHAR(16),@pmInactivo BIT
 AS 
 INSERT INTO Zonas (IdZona,Zona,CdSubCos,Inactivo)
 VALUES (@pmIdZona,@pmZona,@pmCdSubCos,@pmInactivo)
GO
/****** Object:  StoredProcedure [dbo].[paListTercAccionistas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paListTercAccionistas]
    @UltimoId VARCHAR(16),
    @Operacion VARCHAR(16),
    @IdTercero VARCHAR(16) 
AS
BEGIN
    SET NOCOUNT ON;
    -- Verificar si hay datos en TercAccionistas
    IF EXISTS (SELECT 1 FROM TercAccionistas)
    BEGIN
		
        -- Operación: Paginación ('p')
        IF @Operacion = 'p'
        BEGIN
            IF @UltimoId IS NOT NULL
            BEGIN
                SELECT --TOP 20 por si se necesita hacer paginacion
                    TC.IdTercero,
                    TC.RazonSocial,
                    TA.Id,
                    TA.NitAccionista,
                    TA.NomAccionista,
                    TA.Participacion
                FROM TercAccionistas AS TA
                INNER JOIN Terceros AS TC 
                    ON TC.IdTercero = TA.IdTercero
                WHERE TC.IdTercero > @UltimoId -- Compara lexicográficamente//por defecto se le envia 0, pero se deja por si se necesita hacer paginacion
                ORDER BY TC.IdTercero; -- Asegurar el orden
            END
            ELSE
            BEGIN
                RAISERROR ('El parámetro @UltimoId no puede ser NULL para la operación "p".', 16, 1);
            END
        END

        -- Operación: Listar por ID ('l')
        ELSE IF @Operacion = 'l'
        BEGIN
		   
            IF @IdTercero IS NOT NULL
            BEGIN				
                SELECT 
                    T.IdTercero,
                    T.RazonSocial,
                    TC.NitAccionista,
                    TC.NomAccionista,
                    TC.Participacion
                FROM Terceros AS T
                INNER JOIN TercAccionistas AS TC 
                    ON T.IdTercero = TC.IdTercero
                WHERE T.IdTercero = @IdTercero;
            END
            ELSE
            BEGIN
                RAISERROR ('El parámetro @UltimoId no puede ser NULL para la operación "p".', 16, 1);
            END
        END

        -- Operación no válida
        ELSE
        BEGIN
            RAISERROR ('Operación no válida. Use "p" para paginación o "l" para listar por ID.',16,1);
        END
    END
    ELSE
     BEGIN
        -- No hay datos en TercAccionistas, retornar DataTable vacío
        SELECT 
            CAST(NULL AS VARCHAR(16)) AS IdTercero,
            CAST(NULL AS NVARCHAR(255)) AS RazonSocial,
            CAST(NULL AS VARCHAR(16)) AS NitAccionista,
            CAST(NULL AS NVARCHAR(255)) AS NomAccionista,
            CAST(NULL AS DECIMAL(18, 2)) AS Participacion
        WHERE 1 = 0; -- No devuelve filas, solo la estructura
    END
END;
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryActivos] @pmIdActivo VARCHAR(30)
 AS 
 SELECT IdActivo,NomActivo,NumSerie,CodInvent,CodBarras,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdCia,IdProv,FecCompra,FecActivacion,NumOrden
,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep,VrMejoras,VrDisminucion,VidaUtil,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo
,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep,FecUltDep,Marca,Modelo,NumPlaca,NumDoc,Referencia,IdEstado,FecRetiro,IdCausal,VrVenta
,TipoContable,VrSalvamento,DepPartes,UndsProd,TipComp,NumComp,CdCiaComp,FecCreacion,IdUsuario
 FROM Activos
 WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_Anexo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivos_Anexo] @pmIdActivo VARCHAR(30)
 AS 
 SELECT IdActivo,IdCuenta,IdCueDep,IdCueGasto,IdCueAjuste,IdCueCorr,IdCueAjuDep,IdCueCorrAD,NumPoliza,NitCiaAseg
,FecPoliza,FecVigencia,VrAsegurado,VrCuotaMes,VendPoliza,TeleVend,DiasGarantia,ComentGarantia,Pignorado
,FecIniPignor,FecFinPignor,GarantPignor,Mantenimiento,NumContrato,FecIniCont,FecFinCont,Periodicidad,FecUltMnmto
,NitEmpMnmto,ComentMnmto,DesUbicacion,Comentarios,ComentRetiro,DatosTecnicos,CodNiifAct,CodNiifDep,CodNiifGasto
 FROM Activos_Anexo
 WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivos_Cr] @pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT IdActivo,NomActivo,NumSerie,CodInvent,CodBarras,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia
,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,Compania,IdProv,T.RazonSocial AS Proveedor,FecCompra,FecActivacion,NumOrden,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep
,VrMejoras,VrDisminucion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep
,FecUltDep,Marca,Modelo,NumPlaca,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado,FecRetiro,A.IdCausal AS CdCausal,Causal,VrVenta,TipoContable,VrSalvamento,DepPartes,UndsProd,TipComp,NumComp,CdCiaComp,FecCreacion,A.IdUsuario AS IdUsuari,Usuario
--datos del proveedor
,T.Codigo AS TercCodigo,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigla,T.Direccion AS TercDirecc,T.IdLocal AS CdLocalidad,Localidad,LC.IdDep AS Cd_Depto,Departamento,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM Activos AS A INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Terceros AS T ON A.IdProv=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal INNER JOIN Departamentos AS D ON LC.IdDep=D.IdDep
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 WHERE A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (FecActivacion>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecActivacion<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY IdActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_Partes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryActivos_Partes] @pmIdActivo VARCHAR(30),@pmItem INT
 AS 
 SELECT IdActivo,Item,DescParte,NumParte,FecIniDep,MetDeprec,VidaUtil,UndsProd,VrCompra,VrBaseDep,VrMejoras,VrDisminuc,VrSalvamento,VrDepAcum,VrDepAcumHis
,VrAjuAcum,VrAjuDepAcum,NitProv,IdEstado,FecCreacion,IdUsuario,CueEnAfijo,IdCuenta,IdCueDep,IdCueGasto,CodNiifAct,CodNiifDep,CodNiifGasto,Fec_Retiro
 FROM Activos_Partes
 WHERE IdActivo=@pmIdActivo AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryActivos_PartesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivos_PartesLta] @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT P.IdActivo AS CdActivo,NomActivo,TipoContable,P.Item,DescParte,NumParte,P.FecIniDep,P.MetDeprec,P.VidaUtil,P.UndsProd,P.VrCompra
,P.VrBaseDep,P.VrMejoras,P.VrDisminuc,P.VrSalvamento,P.VrDepAcum,P.VrDepAcumHis,P.VrAjuAcum,P.VrAjuDepAcum,NitProv,T.RazonSocial AS Proveedor,CueEnAfijo,P.IdCuenta AS CdCuenta,IdCueDep,IdCueGasto
,CodNiifAct,CodNiifDep,CodNiifGasto,P.IdEstado AS CdEstado,EP.Estado AS DescEstado,Fec_Retiro,P.FecCreacion,P.IdUsuario AS CdUsuario,Usuario
--datos activo
,NumSerie,CodInvent,CodBarras,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia
,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,Compania,FecActivacion,A.VrMejoras AS AfVrMejoras,A.VrDisminucion,Ajustable,Contable,Marca,Modelo,NumPlaca,NumDoc,Referencia
,A.IdEstado AS AfCodEstado,ET.Estado AS AFEstado,FecRetiro,A.IdCausal AS CdCausal,Causal,VrVenta,DepPartes,A.FecCreacion AS AfFechaCrea
--datos del proveedor
,T.Codigo AS TercCodigo,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigla,T.Direccion AS TercDirecc,T.IdLocal AS CdLocalidad,Localidad
,LC.IdDep AS Cd_Depto,Departamento,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM Activos_Partes AS P INNER JOIN Activos AS A ON P.IdActivo=A.IdActivo INNER JOIN Terceros AS T ON P.NitProv=T.IdTercero
 INNER JOIN AfEstados AS EP ON P.IdEstado=EP.IdEstado  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN AfEstados AS ET ON A.IdEstado=ET.IdEstado 
 INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal INNER JOIN Departamentos AS D ON LC.IdDep=D.IdDep
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 WHERE (P.FecIniDep>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND P.FecIniDep<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosBar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivosBar] @pmIdActivo VARCHAR(30),@pmCodBarras VARCHAR(30)
 AS 
 SELECT IdActivo,NomActivo,NumSerie,CodInvent,CodBarras,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdCia,IdProv,FecCompra,FecActivacion,NumOrden
,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep,VrMejoras,VrDisminucion,VidaUtil,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo
,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep,FecUltDep,Marca,Modelo,NumPlaca,NumDoc,Referencia,IdEstado,FecRetiro,IdCausal,VrVenta
,TipoContable,VrSalvamento,DepPartes,UndsProd,TipComp,NumComp,CdCiaComp,FecCreacion,IdUsuario
 FROM Activos
 WHERE IdActivo=@pmIdActivo OR (CodBarras=@pmCodBarras AND IdEstado<>'9999')
 ORDER BY  IdActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosDep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivosDep] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT IdActivo,NomActivo,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdCia,IdProv,FecCompra,FecActivacion
,VrBaseDep,VrMejoras,VrDisminucion,VidaUtil,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo
,FecUltDep,IdEstado,FecRetiro,TipoContable,VrSalvamento,DepPartes,UndsProd,VUExtend
 FROM Activos
 WHERE FecActivacion<=@pmFechaFin 
 AND (IdEstado<>'9999'  OR (IdEstado='9999' AND FecRetiro>@pmFechaFin))
 ORDER BY IdActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivosHis] @pmIdActivo VARCHAR(30)=Null
 AS 
 SELECT A.IdActivo AS CdActivo,NomActivo,NumSerie,CodInvent,CodBarras,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CC.CCosto AS ActCentroCosto
,A.IdSubCos AS CdSubcentro,SC.SubCosto AS ActSubCentro,A.IdInstala AS CdInstala,I.Instlacion AS ActInstalacion,A.IdDep AS CdDep,DEP.Dependencia AS NomDependencia
,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,CI.Compania AS NomCia,IdProv,T.RazonSocial AS Proveedor,FecCompra,FecActivacion,NumOrden,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep
,A.VrMejoras AS TotMejoras,A.VrDisminucion AS TotDisminucion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep
,FecUltDep,Marca,Modelo,NumPlaca,NumDoc,Referencia,A.IdEstado AS CdEstado,ED.Estado AS ActEstado,FecRetiro,A.IdCausal AS CdCausal,Causal,VrVenta,TipoContable,VrSalvamento,DepPartes,UndsProd,FecCreacion
--datos de depreciacion
,D.Numero AS NumDeprecia,Fecha,D.IdUsuario AS CdUsuario,Usuario,Item,VrCostoIni,DP.VrMejoras AS ValMejoras,DP.VrDisminucion AS ValDisminuc,VrAcuAjustes,VrDepreciaHis,VrDepreciaMes,VrAjustesInf,VrAjustesDep,VrDepreciaAcum
,VrAjuDepAcum,TarifaAju,DP.IdCia AS DetCodCia,CN.Compania AS DetCompania,CdCCosto,CCD.CCosto AS DetCentroCosto,CdSubCos,SCD.SubCosto AS DetSubCentro,CdInstala,INS.Instlacion AS DetInstacion,CdDep,DE.Dependencia AS DetDependencia
,NitRespons,TRD.RazonSocial AS DetNomResponsable,FecIniDep,MesesVida,MetodoDeprec
 FROM Activos AS A INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DEP ON A.IdDep=DEP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Terceros AS T ON A.IdProv=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 LEFT JOIN  Trn_AfDetalle AS DP ON A.IdActivo=DP.IdActivo  LEFT JOIN Trn_AfDeprecia  AS D ON  DP.Numero=D.Numero
 LEFT JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 LEFT JOIN Companias AS CN ON DP.IdCia=CN.IdCia
 LEFT JOIN CentroCosto AS CCD ON DP.CdCCosto=CCD.IdCCosto LEFT JOIN Instalaciones AS INS ON DP.CdInstala=INS.IdInstala
 LEFT JOIN Dependencias AS DE ON DP.CdDep=DE.IdDep LEFT JOIN Terceros AS TRD ON DP.NitRespons=TRD.IdTercero
 LEFT JOIN SubCentros AS SCD ON DP.CdSubCos=SCD.IdSubCos
 WHERE A.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 ORDER BY NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivosLta] @pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdRespons VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmNumEntrada INT=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT A.IdActivo AS CdActivo,NomActivo,NumSerie,CodInvent,CodBarras,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia
,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,Compania,IdProv,T.RazonSocial AS Proveedor,FecCompra,FecActivacion,NumOrden,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep
,VrMejoras,VrDisminucion,A.VidaUtil AS Vida_util,UndsProd,FecFinDep,MetodoDep,Ajustable,Contable,CueEnGrupo,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep
,FecUltDep,Marca,Modelo,NumPlaca,NumDoc,Referencia,TipComp,NumComp,CdCiaComp,A.IdEstado AS CdEstado,Estado,FecRetiro,A.IdCausal AS CdCausal,Causal,VrVenta,TipoContable,VrSalvamento,DepPartes,FecCreacion,A.IdUsuario AS IdUsuari,Usuario
--datos de anexo
,IdCuenta,IdCueDep,IdCueGasto,IdCueAjuste,IdCueCorr,IdCueAjuDep,IdCueCorrAD
--datos del proveedor
,T.Codigo AS TercCodigo,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigla,T.Direccion AS TercDirecc,T.IdLocal AS CdLocalidad,Localidad,LC.IdDep AS Cd_Depto,Departamento,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM Activos AS A INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Terceros AS T ON A.IdProv=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal INNER JOIN Departamentos AS D ON LC.IdDep=D.IdDep
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 LEFT JOIN Activos_Anexo AS AX ON A.IdActivo=AX.IdActivo
 WHERE A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND A.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND  A.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND A.IdDep LIKE ISNULL(@pmIdDep,'%') AND IdRespons LIKE ISNULL(@pmIdRespons,'%')
 AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%')
 AND (FecActivacion>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecActivacion<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (NumEntrada>=ISNULL(@pmNumEntrada,-1)  AND NumEntrada<=ISNULL(@pmNumEntrada,2147483647))
 AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryActivosMar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryActivosMar] 
 AS 
 SELECT Marca,COUNT(IdActivo)
 FROM Activos
 WHERE IdEstado<>'9999'
 GROUP BY  Marca
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCaja] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 SELECT FechaDia,NumCorte,IdCia,IdUsuario,SaldoAnt,Facturas,DevFacturas,Planillas,DevPlanillas,Recibos,DevRecibos,IngCaja,DevIngCaja
,EgrCaja,DevEgrCaja,Consignac,DevConsig,NotasCalibra,DevCalibra,OtrosIng,OtrosEgr
 FROM AcuCaja
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 ORDER BY IdCia,IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCaja_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCaja_Cr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdUsuario VARCHAR(11)=Null,@pmIdGrupo INT=Null
 AS 
 SELECT A.IdUsuario AS CdUsuario,Usuario,A.IdCia AS CdCia,Compania,FechaDia,SaldoAnt
,Facturas,DevFacturas,Planillas,DevPlanillas,Recibos,DevRecibos,IngCaja,DevIngCaja
,EgrCaja,DevEgrCaja,Consignac,DevConsig,NotasCalibra,DevCalibra,OtrosIng,OtrosEgr
,SaldoAnt+(SaldoAnt+Facturas+Planillas+Recibos+IngCaja+DevEgrCaja+DevConsig+DevCalibra+OtrosIng)
-(DevFacturas+DevPlanillas+DevRecibos+DevIngCaja+EgrCaja+Consignac+NotasCalibra+OtrosEgr) AS NuevoSaldo
,IdEstacion,IdGrupo,U.IdCargo AS CdCargo,Cargo,NumCorte
 FROM AcuCaja AS A INNER JOIN  adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
 LEFT JOIN  Cargos AS C ON U.IdCargo=C.IdCargo
 WHERE FechaDia BETWEEN @pmFechaIni AND @pmFechaFin
 AND A.IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND IdGrupo<=ISNULL(@pmIdGrupo,9999)
 ORDER BY Usuario,A.IdCia,FechaDia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCajaBusesSan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuCajaBusesSan] @pmFecha SMALLDATETIME,@pmIdUsuario VARCHAR(11),@pmIdCia CHAR(2)

AS
 SELECT SUM(SaldoAnterior) AS STotSan,SUM(TotalDebitos) AS STotDeb,SUM(TotalCreditos) AS STotCre,SUM(NuevoSaldo) AS STotSal
 FROM   AcuCajaBuses 
 WHERE  Fecha=@pmFecha AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCajaBusesTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCajaBusesTot] @pmFechaDia SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT  SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS TotalSaldo
 FROM AcuCajaBuses
 WHERE Fecha=@pmFechaDia  AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCajaTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCajaTot] @pmFechaDia SMALLDATETIME,@pmNumCorte INT
,@pmIdCia CHAR(2)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT  SUM(SaldoAnt+Facturas+Planillas+Recibos+IngCaja+DevEgrCaja+DevConsig+DevCalibra+OtrosIng) AS TotalDebitos
,SUM(DevFacturas+DevPlanillas+DevRecibos+DevIngCaja+EgrCaja+Consignac+NotasCalibra+OtrosEgr) AS TotalCreditos
 FROM AcuCaja
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuClientes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
 AS 
 SELECT nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Facturas,DevFacturas,Recibos,DevRecibos,NotasDeb,NotasCre
 FROM AcuClientes
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientesCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuClientesCia] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT IdCliente,IdVend,IdCia,SUM((SaldoAnt+Facturas+DevRecibos+NotasDeb)-(DevFacturas+Recibos+NotasCre)) AS NuevoSaldo
 FROM AcuClientes AS A LEFT JOIN TercCliente AS TC ON A.IdCliente=TC.IdClie
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND ISNULL(IdVend,'0') LIKE ISNULL(@pmIdVend,'%')
 GROUP BY IdCliente,IdVend,IdCia
 HAVING SUM((SaldoAnt+Facturas+DevRecibos+NotasDeb)-(DevFacturas+Recibos+NotasCre))<>0
 ORDER BY IdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientesSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuClientesSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT  nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Facturas,DevFacturas,Recibos,DevRecibos
,NotasDeb,NotasCre,((SaldoAnt+Facturas+DevRecibos+NotasDeb)-(DevFacturas+Recibos+NotasCre)) AS NuevoSaldo
 FROM AcuClientes
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCliente,IdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuClientesSan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuClientesSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT IdCliente,IdVend,IdAgencia,IdCia,SUM((SaldoAnt+Facturas+DevRecibos+NotasDeb)-(DevFacturas+Recibos+NotasCre)) AS NuevoSaldo
 FROM AcuClientes AS A LEFT JOIN TercCliente AS TC ON A.IdCliente=TC.IdClie
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND ISNULL(IdVend,'0') LIKE ISNULL(@pmIdVend,'%')
 GROUP BY IdCliente,IdVend,IdAgencia,IdCia
 HAVING SUM((SaldoAnt+Facturas+DevRecibos+NotasDeb)-(DevFacturas+Recibos+NotasCre))<>0
 ORDER BY IdCliente,IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentas] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
 AS 
 SELECT nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos
 FROM AcuCuentas
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAge]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasAge] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmTipoAcum CHAR(2),@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos
 FROM AcuCuentasAge
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCuenta=@pmIdCuenta
 AND TipoAcum=@pmTipoAcum  AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAgeSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasAgeSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,A.IdCuenta AS CdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior
,TotalDebitos,TotalCreditos,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasAge AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND Tercero=1 AND Agencia=1
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 ORDER BY A.IdCuenta,IdCia,IdTercero,CodAgncia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAgeSalTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasAgeSalTip] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmTipoAcum CHAR(2)=Null
 AS 
 SELECT IdCia,A.IdCuenta AS CdCuenta,IdTercero,CodAgncia,SUM(SaldoAnterior) AS tSaldoAnterior
,SUM(TotalDebitos) AS tTotalDebitos,SUM(TotalCreditos) AS tTotalCreditos
,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
 FROM AcuCuentasAge AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes  AND Tercero<>0 AND Agencia=1 AND TipoAcum=@pmTipoAcum
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 GROUP BY  IdCia,A.IdCuenta,IdTercero,CodAgncia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasAuxItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasAuxItm] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(nReg) AS MXREG
 FROM AcuCuentasAux
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasBG]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasBG] @pmNiv INT,@pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmCue8 VARCHAR(1)=Null,@pmCue9 VARCHAR(1)=Null
AS
  SELECT SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,IdCia,SUM(SaldoAnterior) AS tSaldoAnterior,SUM(TotalDebitos) AS tTotalDebitos
 ,SUM(TotalCreditos) AS tTotalCreditos,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
  FROM  AcuCuentas AS A INNER JOIN  Puc AS P ON A.IdCuenta=P.IdCuenta
  WHERE nAnno=@pmnAnno AND nMes BETWEEN @pmnMesIni AND @pmnMesFin
  AND Movimiento<>0 AND SUBSTRING(A.IdCuenta,1,1) IN ('1','2','3',@pmCue8,@pmCue9)
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasCc] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
 AS 
 SELECT nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior,TotalDebitos,TotalCreditos
 FROM AcuCuentasCc
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCuenta=@pmIdCuenta
 AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCcSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasCcSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,A.IdCuenta AS CdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior
,TotalDebitos,TotalCreditos,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasCc AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND (CentroCosto<>0 OR SubCentro<>0)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 ORDER BY A.IdCuenta,IdCia,IdCCosto,IdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCcSalc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasCcSalc] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT IdCia,A.IdCuenta AS CdCuenta,IdCCosto,SUM(SaldoAnterior) AS tSaldoAnterior
,SUM(TotalDebitos) AS tTotalDebitos,SUM(TotalCreditos) AS tTotalCreditos
,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
 FROM AcuCuentasCc AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND CentroCosto<>0 AND TipoAcum='CC'
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 GROUP BY  IdCia,A.IdCuenta,IdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasCcSalcs]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasCcSalcs] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT IdCia,A.IdCuenta AS CdCuenta,IdCCosto,IdSubCos,SUM(SaldoAnterior) AS tSaldoAnterior
,SUM(TotalDebitos) AS tTotalDebitos,SUM(TotalCreditos) AS tTotalCreditos
,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
 FROM AcuCuentasCc AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND CentroCosto<>0 AND SubCentro<>0  AND TipoAcum='CS'
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 GROUP BY  IdCia,A.IdCuenta,IdCCosto,IdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasGP]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasGP] @pmInc7 CHAR(1),@pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS
  SELECT IdCia,SUM(SaldoAnterior) AS tSaldoAnterior,SUM(TotalDebitos) AS tTotalDebitos,SUM(TotalCreditos) AS tTotalCreditos
  ,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
  FROM  AcuCuentas AS A INNER JOIN  Puc AS P ON A.IdCuenta=P.IdCuenta
  WHERE nAnno=@pmnAnno AND nMes BETWEEN @pmnMesIni AND @pmnMesFin
  AND Movimiento<>0 AND SUBSTRING(A.IdCuenta,1,1) IN ('4','5','6',@pmInc7)
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  GROUP BY  IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasMay]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasMay] @pmnAnno INT,@pmnMes INT,@pmNiv INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT  SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,NomCuenta,Naturaleza
,SUM(SaldoAnterior) AS tSaldoAnterior,SUM(TotalDebitos) AS tTotalDebitos ,SUM(TotalCreditos) AS tTotalCreditos
,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
 FROM AcuCuentas AS A INNER JOIN Puc AS P ON SUBSTRING(A.IdCuenta,1,@pmNiv)=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),NomCuenta,Naturaleza
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasMayCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasMayCia] @pmnAnno INT,@pmnMes INT,@pmNiv INT
,@pmIdCia CHAR(2)=Null
 AS 
 SELECT  SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,NomCuenta,Naturaleza,A.IdCia AS CdCia,Compania
,SUM(SaldoAnterior) AS tSaldoAnterior,SUM(TotalDebitos) AS tTotalDebitos ,SUM(TotalCreditos) AS tTotalCreditos
,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS NuevoSaldo
 FROM AcuCuentas AS A INNER JOIN Puc AS P ON SUBSTRING(A.IdCuenta,1,@pmNiv)=P.IdCuenta
 INNER JOIN Companias AS C ON A.IdCia=C.IdCia
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes  AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),NomCuenta,Naturaleza,A.IdCia,Compania
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasNit] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmIdTercero VARCHAR(16)
 AS 
 SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos
 FROM AcuCuentasNit
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia
 AND IdCuenta=@pmIdCuenta AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasNitSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasNitSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,A.IdCuenta AS CdCuenta,IdTercero,SaldoAnterior,TotalDebitos,TotalCreditos
,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasNit AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND Tercero<>0  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 ORDER BY A.IdCuenta,IdCia,IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdCuenta,SaldoAnterior,TotalDebitos,TotalCreditos
,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentas
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 ORDER BY IdCuenta,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasVeh] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos
 FROM AcuCuentasVeh
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia
 AND IdCuenta=@pmIdCuenta AND IdVehiculo like ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuCuentasVehSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuCuentasVehSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,A.IdCuenta AS CdCuenta,IdVehiculo,SaldoAnterior,TotalDebitos,TotalCreditos
,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasVeh AS A INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND Vehiculo<>0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 ORDER BY A.IdCuenta,IdCia,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuFisCuentasMay]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuFisCuentasMay] @pmnAnno INT,@pmnMes INT,@pmNiv INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,NomCuenta,Naturaleza
,SUM(A.SaldoAnterior) AS tSaldoAnterior,SUM(A.TotalDebitos) AS tTotalDebitos,SUM(A.TotalCreditos) AS tTotalCreditos
,SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos) AS NuevoSaldo
 FROM AcuFisCuentas AS A INNER JOIN PucNiif AS P ON SUBSTRING(A.IdCuenta,1,@pmNiv)=P.IdCuenta
 WHERE A.nAnno=@pmnAnno AND A.nMes=@pmnMes AND (@pmIdCia IS NULL OR A.IdCia=@pmIdCia)
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),NomCuenta,Naturaleza
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuFisCuentasMayCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuFisCuentasMayCia] @pmnAnno INT,@pmnMes INT,@pmNiv INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,NomCuenta,Naturaleza,A.IdCia AS CdCia,Compania
,SUM(A.SaldoAnterior) AS tSaldoAnterior,SUM(A.TotalDebitos) AS tTotalDebitos,SUM(A.TotalCreditos) AS tTotalCreditos
,SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos) AS NuevoSaldo
 FROM AcuFisCuentas AS A INNER JOIN PucNiif AS P ON SUBSTRING(A.IdCuenta,1,@pmNiv)=P.IdCuenta
 INNER JOIN Companias AS C ON A.IdCia=C.IdCia
 WHERE A.nAnno=@pmnAnno AND A.nMes=@pmnMes AND (@pmIdCia IS NULL OR A.IdCia=@pmIdCia)
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),NomCuenta,Naturaleza,A.IdCia,Compania
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuInventario] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4)
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdBodega,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal
 FROM AcuInventario
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdProducto=@pmIdProducto AND IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventario_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInventario_Cr] @pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
 AS 
 SELECT A.IdProducto AS CdProducto,DescripProd,A.IdCia AS CdCia,Compania,A.IdBodega AS CdBodega,Bodega
,nAnno,nMes,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS CostoNuevoSaldo
--datos del producto
,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
,P.IdUnd AS CdUnid,Unidad,ExtciaMin,ExtciaMax,FecUltcom,FecUltVta
 FROM AcuInventario AS A INNER JOIN ProdMcias  AS P ON A.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON A.IdBodega=B.IdBodega  INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 WHERE  nAnno=@pmnAnno AND nMes BETWEEN ISNULL(@pmnMesIni,0) AND ISNULL(@pmnMesFin,2147483647)
 AND A.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 ORDER BY DescripProd,nMes,A.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventarioAju]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInventarioAju] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
 AS 
 SELECT A.IdProducto AS CdProducto,P.IdBodega AS CdBodega,VrCostPmd,DescripProd,Tanques,SUM(SaldoAnt+Entradas-Salidas) AS NuevoSaldo
,SUM(CostoAnt+CostoEnt-CostoSal) AS NuevoCosto
 FROM AcuInventario AS A INNER JOIN ProdMcias AS P ON A.IdProducto=P.IdProducto
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia
 AND NoAjustes=0 AND TipoRef<>'SERVICIO'
 GROUP BY A.IdProducto,P.IdBodega,VrCostPmd,DescripProd,Tanques
 HAVING SUM(SaldoAnt+Entradas-Salidas)<>0
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventarioSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInventarioSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdBodega,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS NuevoCosto
 FROM AcuInventario
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY IdProducto,IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInventarioSanp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInventarioSanp] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
,@pmIdBodega VARCHAR(4)=Null,@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmTanques BIT=Null
 AS 
 SELECT A.IdProducto AS CdProducto,DescripProd,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
,SUM(SaldoAnt+Entradas-Salidas) AS NuevoSaldo,SUM(CostoAnt+CostoEnt-CostoSal) AS CostoTotal
 FROM AcuInventario AS A INNER JOIN ProdMcias  AS PM ON A.IdProducto=PM.IdProducto
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND A.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 AND IdMarca LIKE ISNULL(@pmIdMarca,'%')
 AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
 GROUP BY  A.IdProducto,DescripProd,TipoRef,PM.IdSubgrupo,Subgrupo,S.IdGrupo,Grupo,G.IdLinea,Linea
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvLotes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuInvLotes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmNumLote VARCHAR(30)
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdBodega,NumLote,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal
 FROM AcuInvLotes
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdProducto=@pmIdProducto
 AND IdBodega=@pmIdBodega AND NumLote=@pmNumLote
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvLotes_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInvLotes_Cr] @pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmNumLote VARCHAR(30)=Null
 AS 
 SELECT  A.IdProducto AS CdProducto,DescripProd,A.IdCia AS CdCia,Compania,A.IdBodega AS CdBodega,Bodega
,NumLote,nAnno,nMes,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS CostoNuevoSaldo
--datos del producto
,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
,P.IdUnd AS CdUnid,Unidad,ExtciaMin,ExtciaMax,FecUltcom,FecUltVta,Lotes
 FROM AcuInvLotes AS A INNER JOIN ProdMcias  AS P ON A.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON A.IdBodega=B.IdBodega  INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 WHERE nAnno=@pmnAnno AND nMes BETWEEN ISNULL(@pmnMesIni,0) AND ISNULL(@pmnMesFin,2147483647)
 AND A.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND NumLote LIKE ISNULL(@pmNumLote,'%')
 ORDER BY DescripProd,nMes,A.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvLotesSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInvLotesSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdBodega,NumLote,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS NuevoCosto
 FROM AcuInvLotes
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY IdProducto,IdBodega,NumLote
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuInvTanques] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16),@pmIdTanque VARCHAR(4)
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdTanque,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal
 FROM AcuInvTanques
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdProducto=@pmIdProducto 
AND IdTanque=@pmIdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanques_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInvTanques_Cr] @pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdTanque VARCHAR(4)=Null
 AS 
 SELECT A.IdProducto AS CdProducto,DescripProd,A.IdCia AS CdCia,Compania,A.IdTanque AS CdTanque,Descripcion
,nAnno,nMes,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS CostoNuevoSaldo
--información del tanque
,CapTanq,NivAgua,CapNeta,SaldoActual,TnqGas,TnqUnido,TnqVirtual,NColor
--información de productos
,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
,P.IdUnd AS CdUnid,Unidad,ExtciaMin,ExtciaMax,FecUltcom,FecUltVta
 FROM AcuInvTanques AS A INNER JOIN ProdMcias  AS P ON A.IdProducto=P.IdProducto
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia  INNER JOIN Tanques AS T ON A.IdTanque=T.IdTanque
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 WHERE  nAnno=@pmnAnno AND nMes BETWEEN ISNULL(@pmnMesIni,0) AND ISNULL(@pmnMesFin,2147483647)
 AND A.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdTanque LIKE ISNULL(@pmIdTanque,'%')
 ORDER BY DescripProd,nMes,A.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanquesGru]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInvTanquesGru] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT IdTanque,SUM(SaldoAnt) AS tSaldoAnt,SUM(Entradas) AS tEntradas,SUM(Salidas) AS tSalidas
,SUM(SaldoAnt+Entradas-Salidas) AS NuevoSaldo
,SUM(CostoAnt) AS tCostoAnt,SUM(CostoEnt) AS tCostoEnt,SUM(CostoSal) AS tCostoSal
,SUM(CostoAnt+CostoEnt-CostoSal) AS NuevoCosto
 FROM AcuInvTanques
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY IdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvTanquesSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInvTanquesSal] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdTanque,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS NuevoCosto
 FROM AcuInvTanques
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY IdProducto,IdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvUbica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuInvUbica] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16),@pmIdUbic VARCHAR(10)
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdUbic,SaldoAnt,Entradas,Salidas,CostoAnt,CostoEnt,CostoSal
 FROM AcuInvUbica
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia 
AND IdProducto=@pmIdProducto AND IdUbic=@pmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuInvUbicaSan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuInvUbicaSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT nAnno,nMes,IdCia,IdProducto,IdUbic,SaldoAnt,Entradas,Salidas,SaldoAnt+Entradas-Salidas AS NuevoSaldo
,CostoAnt,CostoEnt,CostoSal,CostoAnt+CostoEnt-CostoSal AS NuevoCosto
 FROM AcuInvUbica
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia LIKE ISNULL(@pmIdCia,'%%')
AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY IdProducto,IdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuNiifCuentasMay]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuNiifCuentasMay] @pmnAnno INT,@pmnMes INT,@pmNiv INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,NomCuenta,Naturaleza
,SUM(A.SaldoAnterior) AS tSaldoAnterior,SUM(A.TotalDebitos) AS tTotalDebitos,SUM(A.TotalCreditos) AS tTotalCreditos
,SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos) AS NuevoSaldo
 FROM AcuNiifCuentas AS A INNER JOIN PucNiif AS P ON SUBSTRING(A.IdCuenta,1,@pmNiv)=P.IdCuenta
 WHERE A.nAnno=@pmnAnno AND A.nMes=@pmnMes AND (@pmIdCia IS NULL OR A.IdCia=@pmIdCia)
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),NomCuenta,Naturaleza
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuNiifCuentasMayCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAcuNiifCuentasMayCia] @pmnAnno INT,@pmnMes INT,@pmNiv INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT SUBSTRING(A.IdCuenta,1,@pmNiv) AS CdCuenta,NomCuenta,Naturaleza,A.IdCia AS CdCia,Compania
,SUM(A.SaldoAnterior) AS tSaldoAnterior,SUM(A.TotalDebitos) AS tTotalDebitos,SUM(A.TotalCreditos) AS tTotalCreditos
,SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos) AS NuevoSaldo
 FROM AcuNiifCuentas AS A INNER JOIN PucNiif AS P ON SUBSTRING(A.IdCuenta,1,@pmNiv)=P.IdCuenta
 INNER JOIN Companias AS C ON A.IdCia=C.IdCia
 WHERE A.nAnno=@pmnAnno AND A.nMes=@pmnMes AND (@pmIdCia IS NULL OR A.IdCia=@pmIdCia)
 GROUP BY SUBSTRING(A.IdCuenta,1,@pmNiv),NomCuenta,Naturaleza,A.IdCia,Compania
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAcuPrestamos] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
 AS 
 SELECT nAnno,nMes,IdCia,IdCliente,IdAgencia,SaldoAnt,Prestamos,DevPrestamos,Recibos,DevRecibos
,NotasDeb,NotasCre,Facturas,DevFacturas
 FROM AcuPrestamos
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia 
AND IdCliente=@pmIdCliente AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryAcuPropietarios]  @pmnMes INT, @pmnAnno INT,@pmIdPropietario VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4), @pmIdCia CHAR(2)
AS
 SELECT IdReg,IdPropietario,IdVehiculo,IdClase, IdCia, nMes, nAnno, SaldoAnterior, TotalDebitos, TotalCreditos
 FROM    AcuPropietarios
 WHERE nMes=@pmnMes AND nAnno=@pmnAnno AND IdPropietario=@pmIdPropietario AND IdVehiculo=@pmIdVehiculo
 AND IdClase=@pmIdClase  AND IdCia=@pmIdCia
 ORDER BY IdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosCla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryAcuPropietariosCla] @pmnAnno INT,@pmnMes INT,@pmIdPropietario VARCHAR(16)=Null
,@pmIdClase VARCHAR(4)=Null, @pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT  P.IdPropietario AS NitPptario,P.IdVehiculo AS PlacaVeh,P.IdClase AS CodClase,V.IdPropietario AS VehNitppt,IdConductor,CASE TipoAfil WHEN 'PROPIO' THEN 1 ELSE 0 END AS VehPropio
,SUM(SaldoAnterior) AS STotSan,SUM(TotalDebitos) AS STotDeb,SUM(TotalCreditos) AS STotCre,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS STotSal
 FROM  AcuPropietarios AS P INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
 WHERE  nAnno=@pmnAnno AND nMes=@pmnMes  AND P.IdPropietario LIKE ISNULL(@pmIdPropietario, '%')
 AND P.IdClase LIKE ISNULL(@pmIdClase,'%') AND IdCia LIKE ISNULL(@pmIdCia ,'%%')
 AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 GROUP BY P.IdPropietario,P.IdVehiculo,P.IdClase,V.IdPropietario,IdConductor,CASE TipoAfil WHEN 'PROPIO' THEN 1 ELSE 0 END
 HAVING SUM(SaldoAnterior+TotalDebitos-TotalCreditos)<>0
 ORDER BY P.IdPropietario,P.IdVehiculo,P.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryAcuPropietariosSal] @pmnAnno INT,@pmnMes INT=Null,@pmIdPropietario VARCHAR(16)=Null, @pmIdClase VARCHAR(4)=Null
, @pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT  IdPropietario,IdVehiculo,IdClase, IdCia, nMes, SUM(SaldoAnterior) AS STotSan,SUM(TotalDebitos) AS STotDeb,SUM(TotalCreditos) AS STotCre
,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS STotSal
 FROM    AcuPropietarios
 WHERE  nAnno=@pmnAnno AND IdPropietario LIKE ISNULL(@pmIdPropietario, '%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND IdClase LIKE ISNULL(@pmIdClase,'%') AND IdCia LIKE ISNULL(@pmIdCia ,'%%')
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 GROUP BY IdPropietario,IdVehiculo,IdClase,IdCia,nMes
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosSalCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryAcuPropietariosSalCue] @pmnAnno INT,@pmnMes INT
,@pmSaldoActual MONEY,@pmIdAdmon VARCHAR(4)
AS
 SELECT V.IdPoseedor AS NitPropietario,SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos) AS StotSal
 FROM  AcuPropietarios AS A INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND V.IdAdmon<>@pmIdAdmon AND V.TipoAfil<>'PROPIO'
 GROUP BY V.IdPoseedor
 HAVING  SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos)<=@pmSaldoActual
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosSalPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryAcuPropietariosSalPro] @pmnAnno INT,@pmnMes INT, @pmIdPropietario VARCHAR(16)
,@pmIdAdmon VARCHAR(4)
AS
 SELECT V.IdVehiculo AS PlacaVeh,V.IdPoseedor AS NitPropietario,NumVeh,IdAdmon,TipoAfil
,IdConductor,RazonSocial,IdGrupo,SUM(A.SaldoAnterior+A.TotalDebitos-A.TotalCreditos) AS StotSal
 FROM  AcuPropietarios AS A INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS T ON V.IdConductor=T.IdTercero
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND V.IdPoseedor=@pmIdPropietario
 AND V.IdAdmon<>@pmIdAdmon AND V.TipoAfil<>'PROPIO'
 GROUP BY  V.IdVehiculo,V.IdPoseedor,NumVeh,IdAdmon,TipoAfil,IdConductor,RazonSocial,IdGrupo
 ORDER BY  V.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryAcuPropietariosVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryAcuPropietariosVeh] @pmnAnno INT,@pmnMes INT,@pmIdPropietario VARCHAR(16)=Null
,@pmIdClase VARCHAR(4)=Null, @pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT  P.IdVehiculo AS PlacaVeh,P.IdClase AS CodClase,V.IdPropietario AS VehNitppt,IdConductor,CASE TipoAfil WHEN 'PROPIO' THEN 1 ELSE 0 END AS VehPropio
,SUM(SaldoAnterior) AS STotSan,SUM(TotalDebitos) AS STotDeb,SUM(TotalCreditos) AS STotCre,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS STotSal
 FROM  AcuPropietarios AS P INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
 WHERE  nAnno=@pmnAnno AND nMes=@pmnMes  AND P.IdPropietario LIKE ISNULL(@pmIdPropietario, '%')
 AND P.IdClase LIKE ISNULL(@pmIdClase,'%') AND IdCia LIKE ISNULL(@pmIdCia ,'%%')
 AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 GROUP BY P.IdVehiculo,P.IdClase,V.IdPropietario,IdConductor,CASE TipoAfil WHEN 'PROPIO' THEN 1 ELSE 0 END
 HAVING SUM(SaldoAnterior+TotalDebitos-TotalCreditos)<>0
 ORDER BY P.IdVehiculo,P.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryAfAmortiza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfAmortiza] @pmNumero INT
 AS 
 SELECT Numero,Fecha,Estado,IdUsuario,FechaCrea,IdCia
 FROM Trn_AfAmortiza
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfAmortizaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfAmortizaLta]  @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT AMZ.Numero AS NumRegistro,Fecha,AMZ.Estado AS EstadoDoc,AMZ.IdUsuario AS CdUsuario,Usuario,FechaCrea,AMZ.IdCia AS CdCia,CI.Compania AS NomCia
,Item,D.IdDiferido AS CdDiferido,NomDiferido, D.ValorTotal AS ValorInicial, D.VrAdiciones AS ValAdiciones, D.VrDisminucion AS ValDisminucion, VrAcuAjustes, VrAmortizaHis, VrAmortizaMes, VrAjustesInf
, VrAjustesAmtza,VrAmtzaHisAcum, VrAmortizaAcum, VrAjuAmtzaAcum, VrCorrMonAcum, VrBaseCorrMon, VrCorrMonDif, TarifaAju
,D.IdCia AS DetIdCia,CID.Compania AS DetNomCia,CdCCosto,CCosto,CdSubCos,SubCosto, CdDep, Dependencia,NitRespons,RazonSocial,FecInicioAmtza, NPeriodos
--datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS DifCdCentro,A.IdSubCos AS DifCdSubcentro
,A.IdDep AS DifCdDep,DesUbicacion,IdRespons,A.IdCia AS DifIdCia,FecInicio,A.ValorTotal AS DifValTotal,A.VrAdiciones AS DifValAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,ED.Estado AS EstadoDif
,Comentarios,A.FecCreacion AS DifFecCrea,VentaGal,CuotaGal,VrInversion,NumPlaca,CodInstala,Instlacion
 FROM Trn_AfAmortiza AS AMZ INNER JOIN Trn_AfAmtDetalle AS D ON AMZ.Numero=D.Numero
 INNER JOIN Companias AS CI ON AMZ.IdCia=CI.IdCia  INNER JOIN adm_Usuarios AS U ON AMZ.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido  INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif  INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN Companias AS CID ON D.IdCia=CID.IdCia 
 INNER JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto 
 INNER JOIN Dependencias AS DP ON D.CdDep=DP.IdDep INNER JOIN Terceros AS T ON D.NitRespons=T.IdTercero
 LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos  LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE  AMZ.Numero BETWEEN @pmNumeroIni  AND @pmNumeroFin
GO
/****** Object:  StoredProcedure [dbo].[paQryAfAmortizaRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfAmortizaRes] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdLinea VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdCia CHAR(2)=Null,@pmIdTipDif VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdRespons VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null
,@pmIdDiferido VARCHAR(30)
 AS 
 SELECT D.IdDiferido AS CdDiferido,NomDiferido,AMZ.Numero AS NumRegistro,Fecha,AMZ.Estado AS EstadoDoc,AMZ.IdUsuario AS CdUsuario,Usuario,FechaCrea,AMZ.IdCia AS CdCia,CI.Compania AS NomCia
,Item,D.ValorTotal AS ValorInicial, D.VrAdiciones AS ValAdiciones, D.VrDisminucion AS ValDisminucion, VrAcuAjustes, VrAmortizaHis, VrAmortizaMes, VrAjustesInf
, VrAjustesAmtza,VrAmtzaHisAcum, VrAmortizaAcum, VrAjuAmtzaAcum, VrCorrMonAcum, VrBaseCorrMon, VrCorrMonDif, TarifaAju
,D.IdCia AS DetIdCia,CID.Compania AS DetNomCia,CdCCosto,CCD.CCosto AS NomCentroCosto,CdSubCos,SCD.SubCosto AS NomSubcentro, CdDep, DPD.Dependencia AS NomDepend
,NitRespons,TRD.RazonSocial AS DetResponsable,FecInicioAmtza, NPeriodos,VentaGal,CuotaGal,VrInversion
--datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro
,CC.CCosto AS DifCentroCosto,A.IdSubCos AS CdSubcentro,SC.SubCosto AS DifSubCentro,A.IdDep AS CdDep,DP.Dependencia AS DifDependencia,DesUbicacion
,IdRespons,T.RazonSocial AS NomResponsable,A.IdCia AS CdCia,CIA.Compania AS DifNomCia,FecInicio,A.ValorTotal AS DifValTotal,A.VrAdiciones AS DifAdiciones,A.VrDisminucion AS DifDisminucion,NumPeriodos
,FecFinAmtza,Ajustable,Contable,VrAjuInfAcum,VrAmtzaAcuHis,VrAmtzaAcum,VrAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,FecUltAmtza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,ED.Estado AS DifEstado
,FecRetiro,A.IdCausal AS CdCausal,Causal,ComentRetiro,Comentarios,NumPlaca,CodInstala,Instlacion,FecCreacion,A.IdUsuario AS IdUsuari
--DATOS DEL DIFERIDO
 FROM Trn_AfAmtDetalle AS D INNER JOIN Trn_AfAmortiza AS  AMZ  ON D.Numero=AMZ.Numero  INNER JOIN Companias AS CI ON AMZ.IdCia=CI.IdCia
 INNER JOIN adm_Usuarios AS U ON AMZ.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos  AS A ON D.IdDiferido=A.IdDiferido  INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN Companias AS CIA ON A.IdCia=CIA.IdCia 
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado   INNER JOIN Companias AS CID ON D.IdCia=CID.IdCia 
 INNER JOIN CentroCosto AS CCD ON D.CdCCosto=CCD.IdCCosto 
 INNER JOIN Dependencias AS DPD ON D.CdDep=DPD.IdDep INNER JOIN Terceros AS TRD ON D.NitRespons=TRD.IdTercero
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 LEFT JOIN SubCentros AS SCD ON D.CdSubCos=SCD.IdSubCos   LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE Fecha BETWEEN  @pmFechaIni  AND @pmFechaFin AND AMZ.Estado<>0 AND D.IdDiferido LIKE ISNULL(@pmIdDiferido ,'%')
 AND AMZ.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND  G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  
 AND D.CdDep LIKE ISNULL(@pmIdDep,'%')  AND D.NitRespons LIKE ISNULL(@pmIdRespons,'%')  AND D.CdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND A.IdTipDif LIKE ISNULL(@pmIdTipDif,'%')
 ORDER BY AMZ.Numero,NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryAfCausales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfCausales] @pmIdCausal VARCHAR(4)
 AS 
 IF  @pmIdCausal IS NULL
 SELECT IdCausal,Causal
 FROM AfCausales
 WHERE Inactivo=0
 ORDER BY IdCausal
 ELSE
 SELECT IdCausal,Causal,Inactivo
 FROM AfCausales
 WHERE IdCausal=@pmIdCausal
GO
/****** Object:  StoredProcedure [dbo].[paQryAfClasesCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfClasesCue] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
 SELECT IdClase,ClaseCue,Concepto
 FROM AfClasesCue
 WHERE  Inactivo=0
 ORDER BY IdClase
 ELSE
 SELECT IdClase,ClaseCue,Concepto,Inactivo
 FROM AfClasesCue
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDeprecia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDeprecia] @pmNumero INT
 AS 
 SELECT Numero,Fecha,Estado,IdUsuario,FechaCrea,IdCia
 FROM Trn_AfDeprecia
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDepreciaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDepreciaLta] @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT D.Numero AS NumDeprecia,Fecha,D.Estado AS EstadoDoc,D.IdUsuario AS CdUsuario,Usuario,FechaCrea,D.IdCia AS CdCia
,Item,DP.IdActivo AS CdActivo,NomActivo,VrCostoIni,DP.VrMejoras AS ValMejoras,DP.VrDisminucion AS ValDisminuc,VrAcuAjustes,VrDepreciaHis,VrDepreciaMes,VrAjustesInf,VrAjustesDep,VrDepreciaAcum
,VrAjuDepAcum,TarifaAju,DP.IdCia AS DetCodCia,Compania,CdCCosto,CCosto,CdSubCos,SubCosto,CdInstala,Instlacion,CdDep,Dependencia,NitRespons,RazonSocial,FecIniDep,MesesVida,MetodoDeprec
,VrSalvamnto,Unidades,Cantidad,Dep_Partes
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,Marca,Modelo,NumPlaca,Referencia,A.IdEstado AS CdEstado,ED.Estado AS NomEstado
,FecActivacion,FecFinDep,Ajustable,Contable
 FROM Trn_AfDeprecia AS D INNER JOIN  Trn_AfDetalle AS DP ON D.Numero=DP.Numero
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON DP.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado INNER JOIN Companias AS CN ON DP.IdCia=CN.IdCia
 INNER JOIN CentroCosto AS CC ON DP.CdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON DP.CdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DE ON DP.CdDep=DE.IdDep INNER JOIN Terceros AS TR ON DP.NitRespons=TR.IdTercero
 LEFT JOIN SubCentros AS SC ON DP.CdSubCos=SC.IdSubCos
 WHERE D.Numero BETWEEN @pmNumeroIni  AND  @pmNumeroFin
 ORDER BY D.Numero,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDepreciaRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDepreciaRes]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdLinea VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdCia CHAR(2)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdRespons VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null
,@pmIdActivo VARCHAR(30)=Null
 AS 
 SELECT DP.IdActivo AS CdActivo,NomActivo,Fecha,D.Numero AS NumDeprecia,D.IdUsuario AS CdUsuario,Usuario,FechaCrea,D.IdCia AS DepCdCia
,Item,VrCostoIni,DP.VrMejoras AS ValMejoras,DP.VrDisminucion AS ValDisminuc,VrAcuAjustes,VrDepreciaHis,VrDepreciaMes,VrAjustesInf,VrAjustesDep,VrDepreciaAcum
,VrAjuDepAcum,TarifaAju,DP.IdCia AS DetCodCia,CN.Compania AS DetCompania,CdCCosto,CCD.CCosto AS DetCentroCosto,CdSubCos,SCD.SubCosto AS DetSubCentro,CdInstala,INS.Instlacion AS DetInstacion
,CdDep,DE.Dependencia AS DetDependencia,NitRespons,TRD.RazonSocial AS DetNomResponsable,FecIniDep,MesesVida,MetodoDeprec
--datos del activo
,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CC.CCosto AS ActCentroCosto,A.IdSubCos AS CdSubcentro,SC.SubCosto AS ActSubCentro,A.IdInstala AS CdInstala,I.Instlacion AS ActInstalacion
,A.IdDep AS CdDep,DEP.Dependencia AS NomDependencia,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,CI.Compania AS NomCia,IdProv,T.RazonSocial AS Proveedor
,FecCompra,FecActivacion,NumOrden,IdCiaOrden,NumEntrada,IdCiaEnt,VrCompra,VrComercial,VrBaseDep,A.VrMejoras AS TotMejoras,A.VrDisminucion AS TotDisminucion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep
,Ajustable,Contable,CueEnGrupo,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju,VrAjuInfDep,NumMesesDep,FecUltDep,Marca,Modelo,NumPlaca,NumDoc,Referencia,NumSerie,CodInvent,CodBarras
,A.IdEstado AS CdEstado,ED.Estado AS ActEstado,FecRetiro,A.IdCausal AS CdCausal,Causal,VrVenta,FecCreacion,VrSalvamnto,Unidades,Cantidad,Dep_Partes,A.TipoContable
 FROM  Trn_AfDetalle AS DP  INNER JOIN Trn_AfDeprecia  AS D ON  DP.Numero=D.Numero INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON DP.IdActivo=A.IdActivo  INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DEP ON A.IdDep=DEP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Terceros AS T ON A.IdProv=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN Companias AS CN ON DP.IdCia=CN.IdCia
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 LEFT JOIN CentroCosto AS CCD ON DP.CdCCosto=CCD.IdCCosto LEFT JOIN Instalaciones AS INS ON DP.CdInstala=INS.IdInstala
 LEFT JOIN Dependencias AS DE ON DP.CdDep=DE.IdDep LEFT JOIN Terceros AS TRD ON DP.NitRespons=TRD.IdTercero
 LEFT JOIN SubCentros AS SCD ON DP.CdSubCos=SCD.IdSubCos
 WHERE  D.Fecha BETWEEN  @pmFechaIni  AND @pmFechaFin AND D.Estado<>0  AND DP.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 AND DP.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND  G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  
 AND DP.CdInstala LIKE ISNULL(@pmIdInstala,'%') AND DP.CdDep LIKE ISNULL(@pmIdDep,'%')
 AND DP.NitRespons LIKE ISNULL(@pmIdRespons,'%')  AND DP.CdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 ORDER BY NomActivo,Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifIngresoCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifIngresoCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2),@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdTipDif VARCHAR(4)=Null,@pmIdDiferido VARCHAR(30)=Null
AS
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumIngreso,M.IdCia AS CdCia,Compania,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
, Item,D.IdDiferido AS CdDiferido,NomDiferido,FecActivacion, D.NumPeriodos AS NumMeses, VrBase, VrMejoras, D.VrDisminucion AS ValDisminuc, D.VrAjuInfAcum AS ValAjuInfAcum, D.VrAmortizaHis AS ValAmzaHis
, VrAmortizaAju,D.VrAjuInfAmtza AS ValAjuInflacAmza, NumMesesAmtza, VrCorrMonDif, NumMesesCorr, D.FecUltAmtza AS FecUltAmortza, Concepto
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,RazonSocial,A.IdCia AS DifIdCia,FecInicio,ValorTotal,VrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,NumPlaca,CodInstala,Instlacion,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifIngreso AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos   LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND D.IdDiferido LIKE ISNULL(@pmIdDiferido,'%')
 AND A.IdTipDif LIKE ISNULL(@pmIdTipDif,'%')
 ORDER BY M.Numero,NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifIngresoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifIngresoLta] @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT
,@pmIdCia CHAR(2)
AS
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumIngreso,M.IdCia AS CdCia,Compania,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
, Item,D.IdDiferido AS CdDiferido,NomDiferido,FecActivacion, D.NumPeriodos AS NumMeses, VrBase, VrMejoras, D.VrDisminucion AS ValDisminuc, D.VrAjuInfAcum AS ValAjuInfAcum, D.VrAmortizaHis AS ValAmzaHis
, VrAmortizaAju,D.VrAjuInfAmtza AS ValAjuInflacAmza, NumMesesAmtza, VrCorrMonDif, NumMesesCorr, D.FecUltAmtza AS FecUltAmortza, Concepto
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,RazonSocial,A.IdCia AS DifIdCia,FecInicio,ValorTotal,VrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,NumPlaca,CodInstala,Instlacion,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifIngreso AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos  LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni  AND @pmNumeroFin  AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifMovi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifMovi] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdMov,Numero,IdCia,Fecha,Anulado,Observacion,TipCom,Comprobante,IdCiaCom,FecCreacion,IdUsuario
 FROM Trn_AfDifMovi
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifRetiroCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifRetiroCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2),@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdTipDif VARCHAR(4)=Null,@pmIdDiferido VARCHAR(30)=Null
AS
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumRetiro,M.IdCia AS CdCia,Compania,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,D.IdDiferido AS CdDiferido,NomDiferido,D.IdCausal AS CdCausal,Causal, VrCostoIni, D.VrAdiciones AS ValAdiciones, D.VrDisminucion AS ValDisminuciones, VrAcuAjustes, VrAmortizaAcum, VrAjuAmtzaAcum, FechaRet, Concepto
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,RazonSocial,A.IdCia AS DifIdCia,FecInicio,ValorTotal,A.VrAdiciones AS DifVrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea,FecRetiro,ComentRetiro
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifRetiro AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN AfCausales AS CR ON D.IdCausal=CR.IdCausal
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos 
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND D.IdDiferido LIKE ISNULL(@pmIdDiferido,'%')
 AND A.IdTipDif LIKE ISNULL(@pmIdTipDif,'%')
 ORDER BY M.Numero,NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifRetiroLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifRetiroLta] @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT
,@pmIdCia CHAR(2)
AS
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumRetiro,M.IdCia AS CdCia,Compania,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,D.IdDiferido AS CdDiferido,NomDiferido,D.IdCausal AS CdCausal,Causal, VrCostoIni, D.VrAdiciones AS ValAdiciones, D.VrDisminucion AS ValDisminuciones, VrAcuAjustes, VrAmortizaAcum, VrAjuAmtzaAcum, FechaRet, Concepto
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,RazonSocial,A.IdCia AS DifIdCia,FecInicio,ValorTotal,A.VrAdiciones AS DifVrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea,FecRetiro,ComentRetiro
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifRetiro AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN AfCausales AS CR ON D.IdCausal=CR.IdCausal
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos 
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni  AND @pmNumeroFin  AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifTraslado] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdMov,Numero,IdCia,Item,IdDiferido,IdGrupo,IdCCosto,IdSubCos,IdDep,IdRespons,Ubicacion,CdCiaDest
,CdGrupoDest,CdCCostoDest,CdSubCosDest,CdDepDest,CdResponsDest,UbicacionDest,Concepto
 FROM Trn_AfDifTraslado
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifTrasladoCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifTrasladoCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2),@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdTipDif VARCHAR(4)=Null,@pmIdDiferido VARCHAR(30)=Null
 AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumTraslado,M.IdCia AS CdCia,CI.Compania AS NomCia,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,D.IdDiferido AS CdDiferido,NomDiferido,D.IdGrupo AS CdGrupoOri,GOR.Grupo AS GrupoOrigen,D.IdCCosto AS CdCentroOrig,CCO.CCosto AS CentroOrigen,D.IdSubCos AS CdSubCosOrig,SCO.SubCosto AS SubCentroOrig
,D.IdDep AS CdDepOrig,DPO.Dependencia AS DepOrigen,D.IdRespons AS IdResponsOrig,TRO.RazonSocial AS ResponsOrigen,Ubicacion,CdCiaDest,CND.Compania  AS CiaDestino,CdGrupoDest,GDT.Grupo AS NomGrupoDestino,CdCCostoDest,CCD.CCosto AS CentroDestino
,CdSubCosDest,SCD.SubCosto AS SubCenDestino,CdDepDest,DPD.Dependencia AS DepDestino,CdResponsDest,TRD.RazonSocial AS NomRespDestino,UbicacionDest,Concepto
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,L.Linea AS LineaDif,A.IdGrupo AS CodGrupo,G.Grupo AS DifGrupo,A.IdCCosto AS CdCentro,CC.CCosto AS DifCentroCosto,A.IdSubCos AS CdSubcentro,SC.SubCosto AS DifSubCentro
,A.IdDep AS CdDep,DP.Dependencia AS DependDif,DesUbicacion,A.IdRespons AS DifNitRespons,T.RazonSocial AS NombreRespons,A.IdCia AS DifIdCia,FecInicio,ValorTotal,VrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado,NumPlaca,CodInstala,Instlacion
,Comentarios,A.FecCreacion AS DifFecCrea
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifTraslado AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN CentroCosto AS CCO ON D.IdCCosto=CCO.IdCCosto  INNER JOIN Dependencias AS DPO ON D.IdDep=DPO.IdDep INNER JOIN Terceros AS TRO ON D.IdRespons=TRO.IdTercero
 INNER JOIN AfGrupos AS  GOR ON D.IdGrupo=GOR.IdGrupo INNER JOIN AfLineas AS LOR ON GOR.IdLinea=LOR.IdLinea
 LEFT JOIN   Companias AS CND ON D.CdCiaDest=CND.IdCia LEFT JOIN AfGrupos AS GDT ON D.CdGrupoDest=GDT.IdGrupo
 LEFT JOIN CentroCosto AS CCD ON D.CdCCostoDest=CCD.IdCCosto 
 LEFT JOIN Dependencias AS DPD ON D.CdDepDest=DPD.IdDep LEFT JOIN Terceros AS TRD ON D.CdResponsDest=TRD.IdTercero
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN SubCentros AS SCO ON D.IdSubCos=SCO.IdSubCos
 LEFT JOIN SubCentros AS SCD ON D.CdSubCosDest=SCD.IdSubCos LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND D.IdDiferido LIKE ISNULL(@pmIdDiferido,'%')
 AND A.IdTipDif LIKE ISNULL(@pmIdTipDif,'%')
 ORDER BY M.Numero,NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifTrasladoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifTrasladoLta] @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumTraslado,M.IdCia AS CdCia,CI.Compania AS NomCia,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,D.IdDiferido AS CdDiferido,NomDiferido,D.IdGrupo AS CdGrupoOri,GOR.Grupo AS GrupoOrigen,D.IdCCosto AS CdCentroOrig,CCO.CCosto AS CentroOrigen,D.IdSubCos AS CdSubCosOrig,SCO.SubCosto AS SubCentroOrig
,D.IdDep AS CdDepOrig,DPO.Dependencia AS DepOrigen,D.IdRespons AS IdResponsOrig,TRO.RazonSocial AS ResponsOrigen,Ubicacion,CdCiaDest,CND.Compania  AS CiaDestino,CdGrupoDest,GDT.Grupo AS NomGrupoDestino,CdCCostoDest,CCD.CCosto AS CentroDestino
,CdSubCosDest,SCD.SubCosto AS SubCenDestino,CdDepDest,DPD.Dependencia AS DepDestino,CdResponsDest,TRD.RazonSocial AS NomRespDestino,UbicacionDest,Concepto
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,L.Linea AS LineaDif,A.IdGrupo AS CodGrupo,G.Grupo AS DifGrupo,A.IdCCosto AS CdCentro,CC.CCosto AS DifCentroCosto,A.IdSubCos AS CdSubcentro,SC.SubCosto AS DifSubCentro
,A.IdDep AS CdDep,DP.Dependencia AS DependDif,DesUbicacion,A.IdRespons AS DifNitRespons,T.RazonSocial AS NombreRespons,A.IdCia AS DifIdCia,FecInicio,ValorTotal,VrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,NumPlaca,CodInstala,Instlacion,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifTraslado AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN CentroCosto AS CCO ON D.IdCCosto=CCO.IdCCosto  INNER JOIN Dependencias AS DPO ON D.IdDep=DPO.IdDep INNER JOIN Terceros AS TRO ON D.IdRespons=TRO.IdTercero
 INNER JOIN AfGrupos AS  GOR ON D.IdGrupo=GOR.IdGrupo INNER JOIN AfLineas AS LOR ON GOR.IdLinea=LOR.IdLinea
 LEFT JOIN   Companias AS CND ON D.CdCiaDest=CND.IdCia LEFT JOIN AfGrupos AS GDT ON D.CdGrupoDest=GDT.IdGrupo
 LEFT JOIN CentroCosto AS CCD ON D.CdCCostoDest=CCD.IdCCosto 
 LEFT JOIN Dependencias AS DPD ON D.CdDepDest=DPD.IdDep LEFT JOIN Terceros AS TRD ON D.CdResponsDest=TRD.IdTercero
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN SubCentros AS SCO ON D.IdSubCos=SCO.IdSubCos
 LEFT JOIN SubCentros AS SCD ON D.CdSubCosDest=SCD.IdSubCos LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin  AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifValoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfDifValoriza] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdMov,Numero,IdCia,Item,IdDiferido,Concepto,Valor,NitProvee
 FROM Trn_AfDifValoriza
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifValorizaCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifValorizaCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2),@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdTipDif VARCHAR(4)=Null,@pmIdDiferido VARCHAR(30)=Null
 AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NroValoriza,M.IdCia AS CdCia,Compania,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,D.IdDiferido AS CdDiferido,NomDiferido,Concepto,Valor,NitProvee,PV.RazonSocial AS Proveedor
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,T.RazonSocial AS NomResponsable,A.IdCia AS DifIdCia,FecInicio,ValorTotal,VrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifValoriza AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN Terceros AS PV ON D.NitProvee=PV.IdTercero
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND D.IdDiferido LIKE ISNULL(@pmIdDiferido,'%')
 AND A.IdTipDif LIKE ISNULL(@pmIdTipDif,'%')
 ORDER BY M.Numero,NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryAfDifValorizaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfDifValorizaLta] @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NroValoriza,M.IdCia AS CdCia,Compania,Fecha,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,D.IdDiferido AS CdDiferido,NomDiferido,Concepto,Valor,NitProvee,PV.RazonSocial AS Proveedor
--Datos del diferido
,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,T.RazonSocial AS Responsable,A.IdCia AS DifIdCia,FecInicio,ValorTotal,VrAdiciones,A.VrDisminucion AS DifValDisminuc,A.NumPeriodos AS DifNumMeses
,FecFinAmtza,Ajustable,Contable,A.VrAjuInfAcum AS DifAjusInfAcum,A.VrAmtzaAcuHis AS DifAmtzaAcuHis,VrAmtzaAcum,A.VrAjuInfAmtza AS DifAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,A.FecUltAmtza AS DifFecUltAmza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado
,Comentarios,A.FecCreacion AS DifFecCrea
 FROM Trn_AfDifMovi AS M INNER JOIN Trn_AfDifValoriza AS D ON M. IdMov=D.IdMov AND M.Numero=D.Numero AND M.IdCia=D.IdCia
 INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov  INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia 
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Diferidos AS A ON D.IdDiferido=A.IdDiferido INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos  LEFT JOIN Terceros AS PV ON D.NitProvee=PV.IdTercero
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin AND  M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfEstados] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
 SELECT IdEstado,Estado,NColor
 FROM AfEstados
 WHERE Inactivo=0
 ORDER BY IdEstado
 ELSE
 SELECT IdEstado,Estado,NColor,Inactivo
 FROM AfEstados
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfGrupos] @pmIdGrupo VARCHAR(4)
 AS 
 SELECT IdGrupo,Grupo,IdLinea,VidaUtil,Inactivo
 FROM AfGrupos
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfGruposCue] @pmIdGrupo VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdGrupo,IdClase,IdCuenta
 FROM AfGruposCue
 WHERE IdGrupo=@pmIdGrupo AND IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposCueLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfGruposCueLta] @pmIdGrupo VARCHAR(4)=Null
 AS 
 SELECT GC.IdGrupo AS CdGrupo,Grupo,GC.IdClase AS CdClase,ClaseCue,GC.IdCuenta AS CdCuenta,NomCuenta
 FROM AfGruposCue AS GC INNER JOIN AfGrupos AS G ON GC.IdGrupo=G.IdGrupo
 INNER JOIN AfClasesCue AS C ON GC.IdClase=C.IdClase
 LEFT JOIN   Puc AS P ON GC.IdCuenta=P.IdCuenta
 WHERE G.Inactivo=0 AND GC.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY Grupo,GC.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfGruposDso] @pmIdLinea VARCHAR(4)=Null
 AS 
 SELECT IdGrupo,Grupo,Grupo+' '+IdGrupo+' ('+Linea+')' AS DsGru
 FROM AfGrupos AS G INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 WHERE G.Inactivo=0 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 ORDER BY G.IdLinea,Grupo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfGruposLin] @pmIdGrupo VARCHAR(4)
 AS 
 SELECT IdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,G.VidaUtil AS Vida_Util,G.Inactivo AS GruInactivo
 FROM AfGrupos AS G INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfGruposLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfGruposLta] @pmIdLinea VARCHAR(4)=Null
 AS 
 SELECT IdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,G.VidaUtil AS Vida_Util
 FROM AfGrupos AS G INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 WHERE G.Inactivo=0 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 ORDER BY G.IdLinea,Grupo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfLineas] @pmIdLinea VARCHAR(4)
 AS 
 IF @pmIdLinea IS NULL
  SELECT IdLinea,Linea,VidaUtil,TarfDep
  FROM AfLineas
  WHERE Inactivo=0
  ORDER BY  IdLinea
 ELSE
  SELECT IdLinea,Linea,VidaUtil,TarfDep,Inactivo
  FROM AfLineas
  WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paQryAfLineasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfLineasDso] 
 AS 
 SELECT IdLinea,Linea,IdLinea+' '+Linea AS DsLin
 FROM AfLineas
 WHERE Inactivo=0 
 ORDER BY IdLinea
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMantnmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfMantnmto] @pmNumero INT
 AS 
 SELECT Numero,IdCia,IdActivo,Fecha,NumContrato,NitEmpresa,NomEmpresa,FinContrato,IdUsuario,Diagnostico,Comentarios,IdMtto,VrMantnmto
 FROM Trn_AfMantnmto
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMantnmtoCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMantnmtoCr] @pmNumeroIni INT,@pmNumeroFin INT
AS
 SELECT Numero,M.IdCia AS CdCia,CM.Compania AS CiaMnmto,Fecha,M.IdActivo AS CdActivo,NomActivo,M.NumContrato AS Num_Contrato,NitEmpresa,NomEmpresa
,FinContrato,Diagnostico,M.Comentarios,M.IdMtto,TM.TipoMtto,M.VrMantnmto,M.IdUsuario AS CdUsuario,Usuario
,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,CI.Compania AS CiaAfijo
,VrBaseDep,VrMejoras,VrDisminucion,FecActivacion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep,Ajustable,Contable
,A.IdEstado AS CdEstado,Estado,FecRetiro
,Mantenimiento,AX.NumContrato AS NContratoActual,FecIniCont,FecFinCont,Periodicidad,FecUltMnmto,NitEmpMnmto,ComentMnmto
 FROM Trn_AfMantnmto AS M INNER JOIN Activos AS A ON M.IdActivo=A.IdActivo INNER JOIN Companias AS CM ON M.IdCia=CM.IdCia
 INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario  INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 LEFT JOIN Activos_Anexo AS AX ON M.IdActivo=AX.IdActivo LEFT JOIN MttoTipos AS TM ON M.IdMtto=TM.IdMtto
 WHERE  Numero BETWEEN @pmNumeroIni  AND @pmNumeroFin
 ORDER BY  Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMantnmtoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMantnmtoLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmNumeroIni INT,@pmNumeroFin INT,@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdActivo VARCHAR(30)=Null
AS
 SELECT Numero,M.IdCia AS CdCia,CM.Compania AS CiaMnmto,Fecha,M.IdActivo AS CdActivo,NomActivo,M.NumContrato AS Num_Contrato,NitEmpresa,NomEmpresa
,FinContrato,Diagnostico,M.Comentarios,M.IdMtto,TM.TipoMtto,M.VrMantnmto,M.IdUsuario AS CdUsuario,Usuario
,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,CI.Compania AS CiaAfijo
,VrBaseDep,VrMejoras,VrDisminucion,FecActivacion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep,Ajustable,Contable
,A.IdEstado AS CdEstado,Estado,FecRetiro
,Mantenimiento,AX.NumContrato AS NContratoActual,FecIniCont,FecFinCont,Periodicidad,FecUltMnmto,NitEmpMnmto,ComentMnmto
 FROM Trn_AfMantnmto AS M INNER JOIN Activos AS A ON M.IdActivo=A.IdActivo INNER JOIN Companias AS CM ON M.IdCia=CM.IdCia
 INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario  INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 LEFT JOIN Activos_Anexo AS AX ON M.IdActivo=AX.IdActivo LEFT JOIN MttoTipos AS TM ON M.IdMtto=TM.IdMtto
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND  A.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND M.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 AND (Numero>=ISNULL(@pmNumeroIni,-1)  AND Numero<=ISNULL(@pmNumeroFin,2147483647))
 ORDER BY  Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovimiento]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfMovimiento] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdMov,Numero,IdCia,Fecha,Documento,Anulado,Observacion,TipCom,Comprobante,IdCiaCom
,TipoCompNiif,NumCompNiif,TipoCompFis,NumCompFis,FecCreacion,IdUsuario
 FROM Trn_AfMovimiento
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovIngreso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfMovIngreso] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT IdMov,Numero,IdCia,Item,IdActivo,FecActivacion,VrMejoras,VrDisminucion,VrAjuInfAcum,VrDepAcuHis,VrDepAcuAju
,VrAjuInfDep,NumMesesDep,FecUltDep,Concepto,NumParte,Cantidad
 FROM Trn_AfMovIngreso
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovIngresoCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovIngresoCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdActivo VARCHAR(30)=Null
AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumIngreso,M.IdCia AS CdCia,Compania,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
--datos del ingreso
,Item,I.IdActivo AS CdActivo,NomActivo,I.FecActivacion AS FecIngreso,VrBaseDep,I.VrMejoras AS ValMejoras,I.VrDisminucion AS ValDisminucion,I.VrAjuInfAcum AS ValAjuInf
,I.VrDepAcuHis AS ValDepHis,I.VrDepAcuAju AS ValDepAcumAju,I.VrAjuInfDep AS ValAjuInfDep,I.NumMesesDep AS NumMeses,I.FecUltDep AS FechaUltDep,Concepto
,A.VidaUtil AS MesesVidaUtil,FecFinDep,MetodoDep,Ajustable,Contable,NumParte,Cantidad
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubCentro,SubCosto,A.IdInstala AS CdInstala,Instlacion
,A.IdDep AS CdDep,Dependencia,Marca,Modelo,NumPlaca
,IdRespons,TR.RazonSocial AS Responsable,IdProv,TP.RazonSocial AS Proveedor,FecCompra,NumOrden,NumEntrada,A.IdEstado AS CdEstado,Estado
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovIngreso AS I ON M.IdMov=I.IdMov AND M.Numero=I.Numero AND M.IdCia=I.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON I.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Terceros AS TP ON A.IdProv=TP.IdTercero INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND I.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 ORDER BY M.Numero,NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovIngresoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovIngresoLta] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumIngreso,M.IdCia AS CdCia,Compania,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
--datos del ingreso
,Item,I.IdActivo AS CdActivo,NomActivo,I.FecActivacion AS FecIngreso,VrBaseDep,I.VrMejoras AS ValMejoras,I.VrDisminucion AS ValDisminucion,I.VrAjuInfAcum AS ValAjuInf
,I.VrDepAcuHis AS ValDepHis,I.VrDepAcuAju AS ValDepAcumAju,I.VrAjuInfDep AS ValAjuInfDep,I.NumMesesDep AS NumMeses,I.FecUltDep AS FechaUltDep,Concepto
,A.VidaUtil AS MesesVidaUtil,FecFinDep,MetodoDep,Ajustable,Contable,NumParte,Cantidad
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubCentro,SubCosto,A.IdInstala AS CdInstala,Instlacion
,A.IdDep AS CdDep,Dependencia,Marca,Modelo,NumPlaca
,IdRespons,TR.RazonSocial AS Responsable,IdProv,TP.RazonSocial AS Proveedor,FecCompra,NumOrden,NumEntrada,A.IdEstado AS CdEstado,Estado
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovIngreso AS I ON M.IdMov=I.IdMov AND M.Numero=I.Numero AND M.IdCia=I.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON I.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN Terceros AS TP ON A.IdProv=TP.IdTercero INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE M.IdMov=@pmIdMov AND M.Numero=@pmNumero AND M.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovRetiroCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovRetiroCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdActivo VARCHAR(30)=Null
 AS
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumRetiro,M.IdCia AS CdCia,Compania,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,R.IdActivo AS CdActivo,NomActivo,R.IdCausal AS CdCausal,Causal,NitTercero, NomTercero, VrCostoIni, R.VrMejoras AS ValMejoras,R.VrDisminucion AS ValDisminuc, VrAcuAjustes, VrDepAcum
,VrAjuDepAcum, VrIngreso,FechaRet, IdCueDeb, IdCueIng, Concepto,NumParte
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubCentro,SubCosto,A.IdInstala AS CdInstala,Instlacion
,A.IdDep AS CdDep,Dependencia,Marca,Modelo,NumPlaca,Referencia,IdRespons,TR.RazonSocial AS Responsable
,FecCompra,NumOrden,NumEntrada,FecActivacion,VrBaseDep,A.VrMejoras AS TotMejoras,A.VrDisminucion AS TotDisminuc,A.VidaUtil AS MesesVida,FecFinDep,MetodoDep,Ajustable,Contable,FecUltDep
,A.IdEstado AS CdEstado,Estado
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovRetiro AS R ON M.IdMov=R.IdMov AND M.Numero=R.Numero AND M.IdCia=R.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN AfCausales AS CR ON R.IdCausal=CR.IdCausal
 INNER JOIN Activos AS A ON R.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND R.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 ORDER BY M.Numero,NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovRetiroLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovRetiroLta] @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT,@pmIdCia CHAR(2)
 AS
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumRetiro,M.IdCia AS CdCia,Compania,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
,Item,R.IdActivo AS CdActivo,NomActivo,R.IdCausal AS CdCausal,Causal,NitTercero, NomTercero, VrCostoIni, R.VrMejoras AS ValMejoras,R.VrDisminucion AS ValDisminuc, VrAcuAjustes, VrDepAcum
,VrAjuDepAcum, VrIngreso,FechaRet, IdCueDeb,IdCueIng,Concepto,NumParte
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubCentro,SubCosto,A.IdInstala AS CdInstala,Instlacion
,A.IdDep AS CdDep,Dependencia,Marca,Modelo,NumPlaca,Referencia,IdRespons,TR.RazonSocial AS Responsable
,FecCompra,NumOrden,NumEntrada,FecActivacion,VrBaseDep,A.VrMejoras AS TotMejoras,A.VrDisminucion AS TotDisminuc,A.VidaUtil AS MesesVida,FecFinDep,MetodoDep,Ajustable,Contable,FecUltDep
,A.IdEstado AS CdEstado,Estado
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovRetiro AS R ON M.IdMov=R.IdMov AND M.Numero=R.Numero AND M.IdCia=R.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN AfCausales AS CR ON R.IdCausal=CR.IdCausal
 INNER JOIN Activos AS A ON R.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin AND M.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfMovTraslado] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdMov,Numero,IdCia,Item,IdActivo,IdGrupo,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,CdCiaDest
,CdGrupoDest,CdCCostoDest,CdSubCosDest,CdInstalaDest,CdDepDest,CdResponsDest,Concepto,Ubicacion,UbicacionDest
 FROM Trn_AfMovTraslado
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovTrasladoCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovTrasladoCr]  @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdActivo VARCHAR(30)=Null
AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumTraslado,M.IdCia AS CdCia,CN.Compania AS CiaOrigen,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
--datos del traslado
,Item,T.IdActivo AS CdActivo,NomActivo,T.IdGrupo AS CdGrupoOri,GOR.Grupo AS GrupoOrigen,GOR.IdLinea AS CdLineaOri,LOR.Linea AS LineaOrigen,T.IdCCosto AS CdCentroOrigen,CCO.CCosto AS CentroOrigen
,T.IdSubCos AS CdSubCosOrig,SCO.SubCosto AS SubCentroOrig,T.IdInstala AS CdInsOrigen,ITO.Instlacion AS InsOrigen,T.IdDep AS CdDepOrig,DPO.Dependencia AS DepOrigen,T.IdRespons AS NitRespOrigen,TRO.RazonSocial AS ResponsOrigen
,CdCiaDest,CND.Compania  AS CiaDestino,CdGrupoDest,GDT.Grupo AS NomGrupoDestino,CdCCostoDest,CCD.CCosto AS CentroDestino,CdSubCosDest,SCD.SubCosto AS SubCenDestino,CdInstalaDest
,IDT.Instlacion AS InsDestino,CdDepDest,DPD.Dependencia AS DepDestino,CdResponsDest,TRD.RazonSocial AS NomRespDestino,Concepto,Ubicacion,UbicacionDest
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,G.Grupo AS ActGrupo,G.IdLinea AS CdLinea,L.Linea AS ActLinea,A.IdCCosto AS CdCentro,CC.CCosto AS ActivoCentro,A.IdSubCos AS CdSubCentro,SC.SubCosto AS ActSubcentro,A.IdInstala AS CdInstala,INS.Instlacion AS ActInstalacion
,A.IdDep AS CdDep,DP.Dependencia AS ActDepend,Marca,Modelo,NumPlaca,Referencia,FecActivacion,A.VidaUtil,FecFinDep,MetodoDep,FecUltDep
,A.IdRespons AS NitReponsb,TR.RazonSocial AS Responsable,A.IdEstado AS CdEstado,Estado
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovTraslado AS T ON M.IdMov=T.IdMov AND M.Numero=T.Numero AND M.IdCia=T.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON T.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN CentroCosto AS CCO ON T.IdCCosto=CCO.IdCCosto INNER JOIN Instalaciones AS ITO ON T.IdInstala=ITO.IdInstala
 INNER JOIN Dependencias AS DPO ON T.IdDep=DPO.IdDep INNER JOIN Terceros AS TRO ON T.IdRespons=TRO.IdTercero
 INNER JOIN AfGrupos AS  GOR ON T.IdGrupo=GOR.IdGrupo INNER JOIN AfLineas AS LOR ON GOR.IdLinea=LOR.IdLinea
 LEFT JOIN   Companias AS CND ON T.CdCiaDest=CND.IdCia LEFT JOIN AfGrupos AS GDT ON T.CdGrupoDest=GDT.IdGrupo
 LEFT JOIN CentroCosto AS CCD ON T.CdCCostoDest=CCD.IdCCosto LEFT JOIN Instalaciones AS IDT ON T.CdInstalaDest=IDT.IdInstala
 LEFT JOIN Dependencias AS DPD ON T.CdDepDest=DPD.IdDep LEFT JOIN Terceros AS TRD ON T.CdResponsDest=TRD.IdTercero
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN SubCentros AS SCO ON T.IdSubCos=SCO.IdSubCos
 LEFT JOIN SubCentros AS SCD ON T.CdSubCosDest=SCD.IdSubCos
 WHERE M.IdMov=@pmIdMov AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND T.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 ORDER BY M.Numero,NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovTrasladoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovTrasladoLta]  @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT,@pmIdCia CHAR(2)
AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumIngreso,M.IdCia AS CdCia,CN.Compania AS CiaOrigen,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario
--datos del traslado
,Item,T.IdActivo AS CdActivo,NomActivo,T.IdGrupo AS CdGrupoOri,GOR.Grupo AS GrupoOrigen,GOR.IdLinea AS CdLineaOri,LOR.Linea AS LineaOrigen,T.IdCCosto AS CdCentroOrigen,CCO.CCosto AS CentroOrigen
,T.IdSubCos AS CdSubCosOrig,SCO.SubCosto AS SubCentroOrig,T.IdInstala AS CdInsOrigen,ITO.Instlacion AS InsOrigen,T.IdDep AS CdDepOrig,DPO.Dependencia AS DepOrigen,T.IdRespons AS NitRespOrigen,TRO.RazonSocial AS ResponsOrigen
,CdCiaDest,CND.Compania  AS CiaDestino,CdGrupoDest,GDT.Grupo AS NomGrupoDestino,CdCCostoDest,CCD.CCosto AS CentroDestino,CdSubCosDest,SCD.SubCosto AS SubCenDestino,CdInstalaDest
,IDT.Instlacion AS InsDestino,CdDepDest,DPD.Dependencia AS DepDestino,CdResponsDest,TRD.RazonSocial AS NomRespDestino,Concepto,Ubicacion,UbicacionDest
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,G.Grupo AS ActGrupo,G.IdLinea AS CdLinea,L.Linea AS ActLinea,A.IdCCosto AS CdCentro,CC.CCosto AS ActivoCentro,A.IdSubCos AS CdSubCentro,SC.SubCosto AS ActSubcentro,A.IdInstala AS CdInstala,INS.Instlacion AS ActInstalacion
,A.IdDep AS CdDep,DP.Dependencia AS ActDepend,Marca,Modelo,NumPlaca,Referencia,FecActivacion,A.VidaUtil,FecFinDep,MetodoDep,FecUltDep
,A.IdRespons AS NitReponsb,TR.RazonSocial AS Responsable,A.IdEstado AS CdEstado,Estado
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovTraslado AS T ON M.IdMov=T.IdMov AND M.Numero=T.Numero AND M.IdCia=T.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON T.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN CentroCosto AS CCO ON T.IdCCosto=CCO.IdCCosto INNER JOIN Instalaciones AS ITO ON T.IdInstala=ITO.IdInstala
 INNER JOIN Dependencias AS DPO ON T.IdDep=DPO.IdDep INNER JOIN Terceros AS TRO ON T.IdRespons=TRO.IdTercero
 INNER JOIN AfGrupos AS  GOR ON T.IdGrupo=GOR.IdGrupo INNER JOIN AfLineas AS LOR ON GOR.IdLinea=LOR.IdLinea
 LEFT JOIN   Companias AS CND ON T.CdCiaDest=CND.IdCia LEFT JOIN AfGrupos AS GDT ON T.CdGrupoDest=GDT.IdGrupo
 LEFT JOIN CentroCosto AS CCD ON T.CdCCostoDest=CCD.IdCCosto LEFT JOIN Instalaciones AS IDT ON T.CdInstalaDest=IDT.IdInstala
 LEFT JOIN Dependencias AS DPD ON T.CdDepDest=DPD.IdDep LEFT JOIN Terceros AS TRD ON T.CdResponsDest=TRD.IdTercero
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN SubCentros AS SCO ON T.IdSubCos=SCO.IdSubCos
 LEFT JOIN SubCentros AS SCD ON T.CdSubCosDest=SCD.IdSubCos
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin  AND M.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovValoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfMovValoriza] @pmIdMov VARCHAR(4),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdMov,Numero,IdCia,Item,IdActivo,Concepto,Valor,NitProvee,FecAdquis,NumDocmto,DescripParte,Num_Parte
 FROM Trn_AfMovValoriza
 WHERE IdMov=@pmIdMov AND Numero=@pmNumero AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovValorizaCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovValorizaCr] @pmIdMov VARCHAR(4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdActivo VARCHAR(30)=Null
 AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumValoriza,M.IdCia AS CdCia,Compania,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario,Item,V.IdActivo AS CdActivo,NomActivo,Num_Parte,Concepto,Valor
,NitProvee,PV.RazonSocial AS Proveedor,FecAdquis,NumDocmto,DescripParte
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubCentro,SubCosto,A.IdInstala AS CdInstala,Instlacion
,A.IdDep AS CdDep,Dependencia,Marca,Modelo,NumPlaca,Referencia,IdRespons,TR.RazonSocial AS Responsable,A.IdEstado AS CdEstado,Estado
,FecActivacion,VrBaseDep,VrMejoras,VrDisminucion,A.VidaUtil AS MesesVida,FecFinDep,MetodoDep
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovValoriza AS V ON M.IdMov=V.IdMov AND M.Numero=V.Numero AND M.IdCia=V.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON V.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS PV ON  V.NitProvee=PV.IdTercero
 WHERE M.IdMov=@pmIdMov AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND V.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 ORDER BY M.Numero,NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQryAfMovValorizaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfMovValorizaLta] @pmIdMov VARCHAR(4),@pmNumeroIni INT,@pmNumeroFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.IdMov AS CdMov,TipoMov,M.Numero AS NumIngreso,M.IdCia AS CdCia,Compania,Fecha,Documento,Anulado,M.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
,M.FecCreacion AS FechaCrea,M.IdUsuario AS CdUsuario,Usuario,Item,V.IdActivo AS CdActivo,NomActivo,Num_Parte,Concepto,Valor
,NitProvee,PV.RazonSocial AS Proveedor,FecAdquis,NumDocmto,DescripParte
--datos del activo
,NumSerie,A.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubCentro,SubCosto,A.IdInstala AS CdInstala,Instlacion
,A.IdDep AS CdDep,Dependencia,Marca,Modelo,NumPlaca,Referencia,IdRespons,TR.RazonSocial AS Responsable,A.IdEstado AS CdEstado,Estado
,FecActivacion,VrBaseDep,VrMejoras,VrDisminucion,A.VidaUtil AS MesesVida,FecFinDep,MetodoDep
 FROM Trn_AfMovimiento AS M  INNER JOIN Trn_AfMovValoriza AS V ON M.IdMov=V.IdMov AND M.Numero=V.Numero AND M.IdCia=V.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN AfTiposMov AS TM ON M.IdMov=TM.IdMov
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Activos AS A ON V.IdActivo=A.IdActivo INNER JOIN AfGrupos AS  G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS INS ON A.IdInstala=INS.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS PV ON V.NitProvee=PV.IdTercero
 WHERE M.IdMov=@pmIdMov AND M.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin AND M.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPartesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfPartesLta] @pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT D.Numero AS NumDeprecia,D.Item,D.IdActivo AS CdActivo,NomActivo,IdParte,DescParte,NumParte,D.VrBaseDep,D.VrCostoIni,D.VrMejoras,D.VrDisminuc
,D.VrAcumAju,D.VrDepAcum,VrDeprecia,VrDepHis,VrAjusteInf,VrAjuDeprec,VrAcumAjuDep,D.VrSalvamnto,D.Unidades,D.Cantidad
,D.FecIniDep,Vida_Util,D.MetDeprec,P.IdEstado AS CdEstado,ED.Estado AS NomEstado,Fec_Retiro
 FROM Trn_AfPartes AS D INNER JOIN Activos AS A ON D.IdActivo=A.IdActivo 
 INNER JOIN Activos_Partes AS P ON D.IdActivo=P.IdActivo AND D.IdParte=P.Item
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado 
 WHERE D.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPignora]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfPignora] @pmNumero INT
 AS 
 SELECT Numero,IdActivo,Fecha,TipoAccion,NomTercero,Comentarios,Garantia,IdUsuario
 FROM Trn_AfPignora
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPignoraCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfPignoraCr]  @pmNumeroIni INT, @pmNumeroFin INT
 AS 
 SELECT Numero,Fecha,P.IdActivo AS CdActivo,NomActivo,TipoAccion,NomTercero,Comentarios,Garantia
,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,Compania
,VrBaseDep,VrMejoras,VrDisminucion,FecActivacion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep,Ajustable,Contable
,A.IdEstado AS CdEstado,Estado,FecRetiro,P.IdUsuario AS IdUsuari,Usuario
 FROM Trn_AfPignora AS P INNER JOIN Activos AS A ON P.IdActivo=A.IdActivo
 INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario  INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE  Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
GO
/****** Object:  StoredProcedure [dbo].[paQryAfPignoraLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfPignoraLta]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmNumeroIni INT,@pmNumeroFin INT,@pmTipoAccion VARCHAR(10)=Null, @pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdActivo VARCHAR(30)=Null
 AS 
 SELECT Numero,Fecha,P.IdActivo AS CdActivo,NomActivo,TipoAccion,NomTercero,Comentarios,Garantia
,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdInstala AS CdInstala,Instlacion,A.IdDep AS CdDep,Dependencia,IdRespons,TR.RazonSocial AS Responsable,A.IdCia AS CdCia,Compania
,VrBaseDep,VrMejoras,VrDisminucion,FecActivacion,A.VidaUtil AS Vida_util,FecFinDep,MetodoDep,Ajustable,Contable
,A.IdEstado AS CdEstado,Estado,FecRetiro,P.IdUsuario AS IdUsuari,Usuario
 FROM Trn_AfPignora AS P INNER JOIN Activos AS A ON P.IdActivo=A.IdActivo
 INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON A.IdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS TR ON A.IdRespons=TR.IdTercero
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario  INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND TipoAccion LIKE ISNULL(@pmTipoAccion,'%') AND  A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND  A.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND P.IdActivo LIKE ISNULL(@pmIdActivo,'%')
 AND (Numero>=ISNULL(@pmNumeroIni,-1)  AND Numero<=ISNULL(@pmNumeroFin,2147483647))
 ORDER BY  Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryAfTiposDif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAfTiposDif] @pmIdTipDif VARCHAR(4)
 AS 
 IF @pmIdTipDif IS NULL
 SELECT IdTipDif,TipoDiferido
 FROM AfTiposDif
 WHERE Inactivo=0
 ORDER BY IdTipDif
 ELSE
 SELECT IdTipDif,TipoDiferido,Inactivo
 FROM AfTiposDif
 WHERE IdTipDif=@pmIdTipDif
GO
/****** Object:  StoredProcedure [dbo].[paQryAfTiposMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfTiposMov] @pmIdMov VARCHAR(4)
 AS 
 IF @pmIdMov IS NULL
  SELECT IdMov,TipoMov,Consecutivo
  FROM AfTiposMov
  WHERE Inactivo=0
  ORDER BY  IdMov
 ELSE
  SELECT IdMov,TipoMov,Consecutivo,Inactivo
  FROM AfTiposMov
  WHERE IdMov=@pmIdMov
GO
/****** Object:  StoredProcedure [dbo].[paQryAfTiposMovDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAfTiposMovDso] @pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='AF'
  SELECT IdMov,TipoMov
  FROM AfTiposMov
  WHERE Inactivo=0 AND IdMov IN ('0001','0002','0003','0004','0005','0006','0007','0008','0009')
  ORDER BY  IdMov
 ELSE
  SELECT IdMov,TipoMov
  FROM AfTiposMov
  WHERE Inactivo=0 AND IdMov LIKE '2%'
  ORDER BY  IdMov
GO
/****** Object:  StoredProcedure [dbo].[paQryAgencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAgencias] @pmIdAgencia VARCHAR(16)
 AS 
 SELECT IdAgencia,CodAgencia,IdClie,Agencia,DirAgncia,IdLocal,TelAgncia,FaxAgncia,NitCont,NomCont,emlCont
,CargoCont,IdSzona,IdPlazo,CdPlazoComb,IdForma,CdBandera,IdVend,CdCms,CdDct,IntMora,DiasGracia,FactFletes,FactSold
,VrCupoCre,VrSaldoAct,FecUpCupo,NContrato,CiaCont,FecIngreso,CodSicom,Referencia,Comentarios,CupoGalones
,IdEstado,Inactivo,TipoZona,FechaAdd,FechaUpdate,IdUsuario,CdTipAgenc,CdSubAgenc,CdGrupAgenc,CdSubGrupAgenc,CdFntePago,PlazoSobtasa,DocFinanc,VolContMes
,VolContTotal,VolViabMes,VolViabTotal,FecPriVenta,InvCtbObra,InvCtbCapital,InvCtbEfectivo,InvCtbImagen,InvCtbMntmto,FecDesemb,InvContObra,InvContCapital,InvContEfectivo
,InvContImagen,CrtlAprovInv,CrtlAprovImg,FecVigCond,TasaIntArranq,AgencOperando,TipoFactFletes,CdCCBonif,CdSubCCBonif,CodRuta,CodDiaEnt,CdGruClie,CupoElectcom
 FROM Agencias
 WHERE IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasCli]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAgenciasCli] @pmIdClie VARCHAR(16)
 AS 
 SELECT IdAgencia,CodAgencia,IdClie,RazonSocial,Codigo,Dv,Agencia,DirAgncia,A.IdLocal AS CdCiudad
,TelAgncia,FaxAgncia,NitCont,NomCont,emlCont,CargoCont,VrCupoCre,VrSaldoAct,Referencia,CodSicom
,IdSzona,IdPlazo,CdPlazoComb,IdForma,CdBandera,IdVend,CdCms,CdDct,IntMora,DiasGracia,FactFletes,FactSold
,FecUpCupo,NContrato,CiaCont,FecIngreso,CupoGalones,A.Inactivo AS Inactvo,A.IdEstado AS Id_Estado,Comentarios,TipoZona,CodRuta,CupoElectcom
,A.FechaAdd AS FecAdd,A.FechaUpdate AS FecUpd,A.IdUsuario AS IdUsuari
 FROM Agencias AS A INNER JOIN Terceros AS T ON A.IdClie=T.IdTercero
 WHERE A.Inactivo=0 AND IdClie=@pmIdClie
 ORDER BY IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasCod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAgenciasCod] @pmIdClie VARCHAR(16),@pmCodAgencia VARCHAR(16)
 AS 
 SELECT IdAgencia,CodAgencia,IdClie,Agencia,DirAgncia,IdLocal,TelAgncia,FaxAgncia,NitCont,NomCont,emlCont
,CargoCont,IdSzona,IdPlazo,CdPlazoComb,IdForma,CdBandera,IdVend,CdCms,CdDct,IntMora,DiasGracia,FactFletes,FactSold
,VrCupoCre,VrSaldoAct,FecUpCupo,NContrato,CiaCont,FecIngreso,CodSicom,Referencia,Comentarios,CupoGalones
,TipoZona,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
,CdTipAgenc,CdSubAgenc,CdGrupAgenc,CdSubGrupAgenc,CdFntePago,PlazoSobtasa,DocFinanc,VolContMes
,VolContTotal,VolViabMes,VolViabTotal,FecPriVenta,InvCtbObra,InvCtbCapital,InvCtbEfectivo,InvCtbImagen,InvCtbMntmto,FecDesemb,InvContObra,InvContCapital,InvContEfectivo
,InvContImagen,CrtlAprovInv,CrtlAprovImg,FecVigCond,TasaIntArranq,AgencOperando,TipoFactFletes,CdCCBonif,CdSubCCBonif,CodRuta,CodDiaEnt,CdGruClie,CupoElectcom
 FROM Agencias
 WHERE IdClie=@pmIdClie AND CodAgencia LIKE ISNULL(@pmCodAgencia,'%')
 ORDER BY IdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAgenciasId]
 AS 
 SELECT COUNT(IdAgencia) AS CANTAGE
 FROM Agencias
GO
/****** Object:  StoredProcedure [dbo].[paQryAgenciasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAgenciasLta] @pmIdClie VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdZona VARCHAR(4)=Null,@pmIdSzona VARCHAR(4)=Null,@pmIdEstrato VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdSector VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 SELECT A.IdClie AS NitCliente,RazonSocial,IdAgencia,CodAgencia,Agencia,DirAgncia,A.IdLocal AS CdCiuAgncia,L.Localidad AS CiudadAgncia
,L.IdDep AS CdDptoAgncia,D.Departamento AS DptoAgncia,TelAgncia,FaxAgncia,NitCont,NomCont,emlCont,CargoCont,VrCupoCre,VrSaldoAct,A.FecUpCupo AS FechaUpCupo,Referencia
,CodSicom,A.NContrato AS NroCont,CiaCont,A.FecIngreso AS Fec_Ingreso,NomCial,SiglaRaz,SZA.IdZona AS Age_CdZona,ZA.Zona AS Age_Zona,A.IdSzona AS Age_IdSubzona,SZA.Subzona AS Age_Subzona
,A.IdPlazo AS CdPlazo,Plazo,NVmto,A.CdPlazoComb AS CdPlazoComb,A.IdForma AS CdForma,FormaPago,A.IdVend AS NitVend,A.CdCms AS CodCms,A.CdDct AS CodDct,IntMora,A.DiasGracia AS Dias_gracia,FactFletes,A.FactSold AS FacturaSold
,A.CupoGalones AS CupoGals,A.CodRuta,Ruta,CodDiaEnt
,TipoId,Dv,Direccion,T.IdLocal AS CdCiuClie,LT.Localidad AS CiuClie,LT.IdDep AS CdDptoClie,DT.Departamento AS DptoClie
,NitRepLeg,NomRepLeg,NitContac,NomContac,C.IdGrupo AS CdGrupo,G.GrupoClie,SZ.IdZona AS CdZona,Z.Zona AS CliZona,C.IdSzona AS CdSubzona,SZ.Subzona AS CliSubZona
,A.CdBandera AS CodBandera,TipoBandera,C.IdEstrato AS CdEstrato,Estrato,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRgmen,Regimen,TipEnte,VrCupo,VrSaldo,Telefono,Fax
,TelMovil,e_mail,C.IdEstado AS CdEstado,Estado,C.Inactivo AS Clie_inactivo,A.IdEstado AS Age_Estado,A.Inactivo AS Age_inactivo,IniStgNom,A.FechaAdd AS FecAdd
,TipoZona,Comentarios,TipoFactFletes,A.CdGruClie AS CdAgeGru,GA.GrupoClie AS GrupoAgenc,A.FechaUpdate AS FecUpd,A.IdUsuario AS IdUsuari,Usuario
--datos nuevos
,CdTipAgenc,CdSubAgenc,CdGrupAgenc,CdSubGrupAgenc,CdFntePago,PlazoSobtasa,DocFinanc,VolContMes
,VolContTotal,VolViabMes,VolViabTotal,FecPriVenta,InvCtbObra,InvCtbCapital,InvCtbEfectivo,InvCtbImagen,InvCtbMntmto,FecDesemb,InvContObra,InvContCapital,InvContEfectivo
,InvContImagen,CrtlAprovInv,CrtlAprovImg,FecVigCond,TasaIntArranq,AgencOperando,CdCCBonif,CdSubCCBonif,CupoElectcom
 FROM Agencias AS A INNER JOIN Terceros AS T ON A.IdClie=T.IdTercero
 INNER JOIN TercCliente AS C ON A.IdClie=C.IdClie INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON A.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN Subzonas AS SZA ON A.IdSzona=SZA.IdSzona INNER JOIN Zonas AS ZA ON SZA.IdZona=ZA.IdZona
 INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal  INNER JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN Estratos AS EC ON C.IdEstrato=EC.IdEstrato
 INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS E ON C.IdEstado=E.IdEstado INNER JOIN Plazos AS PZ ON A.IdPlazo=PZ.IdPlazo
 INNER JOIN Formaspago AS FP ON A.IdForma=FP.IdForma
 LEFT JOIN TiposBan AS TB ON A.CdBandera=TB.IdBandera LEFT JOIN Rutas AS RT ON A.CodRuta=RT.IdRuta
 LEFT JOIN GruposCli AS GA ON A.CdGruClie=GA.IdGrupo 
 WHERE  A.IdClie LIKE ISNULL(@pmIdClie,'%') AND A.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND C.IdGrupo LIKE ISNULL(@pmIdGrupo ,'%') AND SZA.IdZona LIKE ISNULL(@pmIdZona,'%') AND A.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND C.IdEstrato LIKE ISNULL(@pmIdEstrato,'%') AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND T.IdSector LIKE ISNULL(@pmIdSector,'%')
 AND (A.Inactivo=ISNULL(@pmInactivo,0) or  A.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY RazonSocial,Agencia
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAjuInv] @pmTipDoc VARCHAR(3),@pmAjuste INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Ajuste,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,Cantidad,BaseAjuInf,TarifPaag,NumDcmto
,NumOrden,IdCCosto,IdSubCos,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado
,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_AjuInv
 WHERE TipDoc=@pmTipDoc AND Ajuste=@pmAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInv_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAjuInv_Cr] @pmTipDoc VARCHAR(3),@pmAjusteIni INT,@pmAjusteFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT A.TipDoc AS TDoc,TipoDoc,Ajuste,A.IdCia AS CdCia,Compania,A.Fecha AS FechaDoc,A.IdConcepto AS CdConcepto,Concepto,A.IdTercero AS NitTercero,RazonSocial
,VrSubTotal,Cantidad,BaseAjuInf,TarifPaag,NumDcmto,A.NumOrden AS NroOrden,A.IdCCosto AS CdCcosto,CC.CCosto AS CentCosto,A.IdSubCos AS CdSubcosto,SC.SubCosto AS SubcCosto
,Modalidad,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado
,A.TimeSys AS Time_Sys,A.FecUpdate AS Fec_Update,IdCiaCrea,A.IdUsuario AS IdUsuari,Usuario,Leyenda
,TipoId,Dv,Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
--datos del kardex
,Item,K.IdProducto AS CodProducto,DescripProd,DescripAbrv,K.IdBodega AS CdBodega,Bodega,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,KC.CCosto AS Kar_Ccosto,CdSubCos,KS.SubCosto AS Kar_Subcentro
,pVehiculo,K.Referencia AS Kar_Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,K.NumOrden AS Kar_NOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev
,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_AjuInv AS A  INNER JOIN Trn_Kardex AS K ON A.TipDoc=K.TipDoc AND A.Ajuste=K.Documento AND A.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON A.IdTercero=T.IdTercero  INNER JOIN  Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN TiposCom AS TC ON A.TipCom=TC.IdCom  
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 WHERE A.TipDoc=@pmTipDoc AND Ajuste BETWEEN @pmAjusteIni AND @pmAjusteFin  AND A.IdCia=@pmIdCia
 ORDER BY A.IdCia,Ajuste,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInvLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAjuInvLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmAjusteIni INT=Null,@pmAjusteFin INT=Null
,@pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Ajuste,IdCia,Fecha,A.IdConcepto AS CdConcepto,Concepto,A.IdTercero AS NitTercero,RazonSocial,VrSubTotal,Cantidad,BaseAjuInf,TarifPaag,NumDcmto
,NumOrden,A.IdCCosto AS CdCcosto,CCosto,IdSubCos,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado
,TimeSys,FecUpdate,IdCiaCrea,A.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_AjuInv AS A  INNER JOIN Terceros AS T ON A.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Ajuste BETWEEN ISNULL(@pmAjusteIni,0) AND ISNULL(@pmAjusteFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,Ajuste
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInvOrd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAjuInvOrd] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT TipDoc,Ajuste,IdCia,Fecha,IdConcepto,NumOrden,NumDcmto
 FROM Trn_AjuInv
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY  IdCia,Ajuste
GO
/****** Object:  StoredProcedure [dbo].[paQryAjuInvRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAjuInvRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Ajuste,A.IdCia AS CdCia,Compania,Fecha,A.IdConcepto AS CdConcepto,Concepto,A.IdTercero AS NitTercero,RazonSocial
,VrSubTotal,Cantidad,BaseAjuInf,TarifPaag,NumDcmto,NumOrden,A.IdCCosto AS CdCcosto,CCosto,A.IdSubCos AS CdSubcosto,SubCosto
,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado
,TimeSys,A.FecUpdate AS Fec_Update,IdCiaCrea,A.IdUsuario AS IdUsuari,Usuario
,TipoId,Dv,Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
 FROM Trn_AjuInv AS A INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON A.IdTercero=T.IdTercero  INNER JOIN  Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND A.IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND A.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND A.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
AND  Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY A.IdCia,Ajuste
GO
/****** Object:  StoredProcedure [dbo].[paQryAlmBodegas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAlmBodegas] @pmIdBodega VARCHAR(4)
 AS 
 IF @pmIdBodega IS NULL
  SELECT IdBodega,Bodega,Direccion,TelBodega
  FROM AlmBodegas
  WHERE Inactivo=0
 ORDER BY IdBodega
 ELSE
 SELECT IdBodega,Bodega,Direccion,TelBodega,Inactivo
 FROM AlmBodegas
 WHERE IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryAprobacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryAprobacion] @pmTipDoc VARCHAR(3),@pmAprobacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Aprobacion,IdCia,Fecha,TipoPed,Pedido,IdCiaPed,FecPedido,IdCliente,IdAgencia,pVehiculo,VrCupoCred,VrSaldoAct
,ChequesDev,ClienteMora,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Aprobacion
 WHERE TipDoc=@pmTipDoc AND Aprobacion=@pmAprobacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAprobacion_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAprobacion_Cr] @pmTipDoc VARCHAR(3),@pmAprobacionIni INT,@pmAprobacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Aprobacion,A.IdCia AS CdCia,Compania,Fecha,TipoPed,Pedido,IdCiaPed,FecPedido,IdCliente,RazonSocial,A.IdAgencia AS CdAgencia
,Agencia,pVehiculo,VrCupoCred,A.VrSaldoAct AS SaldoActual,ChequesDev,ClienteMora,OrigenAdd,Anulado,FecDev,A.Observacion AS Observ
,A.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,A.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_Aprobacion AS A INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
 LEFT JOIN Agencias AS AG ON A.IdAgencia=AG.IdAgencia
 WHERE TipDoc=@pmTipDoc AND  Aprobacion BETWEEN  @pmAprobacionIni  AND @pmAprobacionFin
 AND A.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAprobacionLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAprobacionLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmAprobacionIni INT=Null,@pmAprobacionFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmPedido INT=Null
 AS 
 SELECT  Aprobacion,A.IdCia AS CdCia,Compania,Fecha,TipoPed,Pedido,IdCiaPed,FecPedido,IdCliente,RazonSocial,IdAgencia
,pVehiculo,VrCupoCred,VrSaldoAct,ChequesDev,ClienteMora,OrigenAdd,Anulado,FecDev,A.Observacion AS Observ
,A.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,A.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Aprobacion AS A INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Aprobacion BETWEEN ISNULL(@pmAprobacionIni,0) AND ISNULL(@pmAprobacionFin,2147483647)
  AND A.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
  AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (Pedido>=ISNULL(@pmPedido,0)  AND Pedido<=ISNULL(@pmPedido,2147483647))
 ORDER BY A.IdCia,Aprobacion
GO
/****** Object:  StoredProcedure [dbo].[paQryAreas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAreas] @pmIdArea VARCHAR(4)
 AS 
  SELECT IdArea,Area,JefeArea,IdCCosto,Inactivo
  FROM Areas
  WHERE IdArea=@pmIdArea
GO
/****** Object:  StoredProcedure [dbo].[paQryAreasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAreasLta]
 AS 
  SELECT IdArea,Area,JefeArea,A.IdCCosto AS IdCcost,CCosto
  FROM Areas AS A INNER JOIN CentroCosto AS C ON A.IdCCosto=C.IdCCosto
  WHERE A.Inactivo=0
  ORDER BY Area
GO
/****** Object:  StoredProcedure [dbo].[paQryAutoriza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAutoriza] @pmTipAut VARCHAR(3),@pmAutoriza INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipAut,Autoriza,IdCia,Fecha,IdConcepto,NumAutoriza,IdUsuarioAut,IdEstacion,NitTercero,pVehiculo,TipoDoc,Documento
,IdCiaDoc,FechaDoc,DocRef,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,VrAprobado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Autoriza
 WHERE TipAut=@pmTipAut AND Autoriza=@pmAutoriza AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryAutoriza_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAutoriza_Cr] @pmTipAut VARCHAR(3),@pmAutorizaIni INT,@pmAutorizaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipAut,TD.TipoDoc AS TipoDocAut,Autoriza,A.IdCia AS CodCia,Compania,Fecha,A.IdConcepto AS CdConcepto,ConceptoAut,NumAutoriza,IdUsuarioAut,UA.Usuario AS UsuarioAtzdo
,UA.IdGrupo AS NivelUsuario,UA.IdCargo AS CdCago,CA.Cargo AS CargoUsuario,A.IdEstacion AS CdEstacion,NitTercero,RazonSocial,pVehiculo,A.TipoDoc AS Tip_Doc,Documento,IdCiaDoc,FechaDoc,DocRef
,VrAprobado,OrigenAdd,Anulado,FecDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,A.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
,U.IdGrupo AS UsuNivel,U.IdCargo AS UsuIdCargo,CU.Cargo AS UsuNomCargo,Leyenda
 FROM Trn_Autoriza AS A INNER JOIN Sys_Autoriza AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS T ON A.NitTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia
 INNER JOIN adm_Usuarios AS UA ON A.IdUsuarioAut=UA.IdUsuario 
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 INNER JOIN Sys_TiposDoc AS TD ON A.TipAut=TD.IdDoc
 LEFT JOIN Cargos AS CU ON U.IdCargo=CU.IdCargo
 LEFT JOIN Cargos AS CA ON UA.IdCargo=CA.IdCargo
 WHERE TipAut=@pmTipAut AND Autoriza BETWEEN @pmAutorizaIni AND @pmAutorizaFin AND A.IdCia=@pmIdCia
 ORDER BY A.IdCia,Autoriza
GO
/****** Object:  StoredProcedure [dbo].[paQryAutorizaDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAutorizaDoc] @pmTipoDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipAut,Autoriza,IdCia,Fecha,IdConcepto,NumAutoriza,IdUsuarioAut,IdEstacion,NitTercero,pVehiculo,TipoDoc,Documento
,IdCiaDoc,FechaDoc,DocRef,VrAprobado,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Autoriza
 WHERE TipoDoc=@pmTipoDoc AND Documento=@pmDocumento AND IdCiaDoc LIKE ISNULL(@pmIdCiaDoc,'%%')
 ORDER BY IdCia,Autoriza
GO
/****** Object:  StoredProcedure [dbo].[paQryAutorizaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAutorizaLta]  @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmAutorizaIni INT=Null,@pmAutorizaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdUsuarioAut VARCHAR(11)=Null,@pmNitTercero VARCHAR(16)=Null,@pmTipoDoc VARCHAR(3)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT Autoriza,IdCia,Fecha,A.IdConcepto AS CdConcepto,ConceptoAut,NumAutoriza,IdUsuarioAut,UA.Usuario AS UsuarioAtzdo,A.IdEstacion AS CdEstacion,NitTercero,RazonSocial,pVehiculo
,TipoDoc,Documento,IdCiaDoc,FechaDoc,DocRef,VrAprobado,OrigenAdd,Anulado,FecDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado,A.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TimeSys,FecUpdate,IdCiaCrea
 FROM Trn_Autoriza AS A INNER JOIN Sys_Autoriza AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS T ON A.NitTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS UA ON A.IdUsuarioAut=UA.IdUsuario 
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Autoriza BETWEEN ISNULL(@pmAutorizaIni,0) AND ISNULL(@pmAutorizaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') 
 AND IdUsuarioAut LIKE ISNULL(@pmIdUsuarioAut,'%') AND NitTercero LIKE ISNULL(@pmNitTercero,'%')
 AND TipoDoc LIKE ISNULL(@pmTipoDoc,'%')  AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND A.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Autoriza
GO
/****** Object:  StoredProcedure [dbo].[paQryAutorizaNum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryAutorizaNum] @pmNumAutoriza INT,@pmIdCia CHAR(2)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipAut,Autoriza,IdCia,Fecha,IdConcepto,NumAutoriza,IdUsuarioAut,IdEstacion,NitTercero,pVehiculo,TipoDoc,Documento
,IdCiaDoc,FechaDoc,DocRef,VrAprobado,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Autoriza
 WHERE NumAutoriza=@pmNumAutoriza AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY Autoriza
GO
/****** Object:  StoredProcedure [dbo].[paQryBancos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryBancos] @pmIdBanco VARCHAR(4)
 AS 
 IF @pmIdBanco IS NULL
  SELECT IdBanco,Banco,CodEntidad,B.IdClase AS CodClase,ClaseBanco,Direccion,Contacto,Comision
  FROM Bancos AS B INNER JOIN ClaseBan AS C ON B.IdClase=C.IdClase
  WHERE B.Inactivo=0
  ORDER BY IdBanco
 ELSE
  SELECT IdBanco,Banco,IdClase,CodEntidad,Direccion,Contacto,Comision,Inactivo
  FROM Bancos
  WHERE IdBanco=@pmIdBanco
GO
/****** Object:  StoredProcedure [dbo].[paQryBancosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryBancosDso]
AS
 SELECT  IdBanco,Banco,IdBanco+'  '+ Banco AS DsBan  
 FROM   Bancos  
 WHERE Inactivo=0   
 ORDER BY  IdBanco
GO
/****** Object:  StoredProcedure [dbo].[paQryBancosEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryBancosEnt] @pmCodEntidad VARCHAR(20)
 AS 
  SELECT IdBanco,Banco,IdClase,CodEntidad,Direccion,Contacto,Comision,Inactivo
  FROM Bancos
  WHERE CodEntidad=@pmCodEntidad
GO
/****** Object:  StoredProcedure [dbo].[paQryBodegas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBodegas] @pmIdBodega VARCHAR(4)
 AS 
 SELECT IdBodega,Bodega,Descrip,LtaPre,TipoInv,Inactivo
 FROM Bodegas
 WHERE IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryBodegasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBodegasDso] @pmTipoInv VARCHAR(10)=Null,@pmIdCia CHAR(2)=Null
 AS 
 IF @pmIdCia IS NULL
  SELECT IdBodega,Bodega,Bodega+' '+IdBodega AS DsBod
  FROM Bodegas  WHERE  Inactivo=0 AND TipoInv LIKE ISNULL(@pmTipoInv,'%')
  ORDER BY Bodega 
 ELSE
  SELECT B.IdBodega  AS IdBodega,Bodega,Bodega+' '+B.IdBodega AS DsBod
  FROM Bodegas AS B LEFT JOIN BodegasCias AS C ON B.IdBodega=C.IdBodega
   WHERE  B.Inactivo=0 AND B.TipoInv LIKE ISNULL(@pmTipoInv,'%')
  AND (C.IdCia=@pmIdCia OR C.IdCia IS NULL)
  ORDER BY Bodega
GO
/****** Object:  StoredProcedure [dbo].[paQryBodegasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryBodegasLta] @pmTipoInv VARCHAR(10)=Null
 AS 
 SELECT IdBodega,Bodega,Descrip,LtaPre,TipoInv
 FROM Bodegas
 WHERE  Inactivo=0 AND TipoInv LIKE ISNULL(@pmTipoInv,'%')
 ORDER BY IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBodUbic] @pmIdUbic VARCHAR(10)
 AS 
 SELECT IdUbic,Ubicacion,IdBodega,Pasillo,Nivel,Profdad,DimAltura,DimAnch,DimLong,CapcVolm
,UndCapc,CapcPeso,UndPes,CdTmcia,CdMnjo,Notas,Inactivo
 FROM BodUbic
 WHERE IdUbic=@pmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbicCan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryBodUbicCan] @pmIdBodega VARCHAR(4)
 AS 
 SELECT COUNT(IdUbic) AS SCANT 
 FROM BodUbic
 WHERE  Inactivo=0 AND IdBodega=@pmIdBodega AND IdUbic<>'0'
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbicDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBodUbicDso] @pmIdBodega VARCHAR(4)=Null
 AS 
 SELECT IdUbic,Ubicacion,IdUbic+'  (calle: '+Pasillo+' nivel:'+Nivel+'  Prof:'+Profdad + ') ' + Ubicacion AS DsUbi
 FROM BodUbic
 WHERE (Inactivo=0  AND IdBodega LIKE ISNULL(@pmIdBodega,'%')) OR IdUbic='0'
 ORDER BY IdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryBodUbicLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBodUbicLta] @pmIdBodega VARCHAR(4)=Null,@pmPasillo VARCHAR(10)=Null,@pmNivel VARCHAR(10)=Null
,@pmProfdad VARCHAR(10)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdUbic,Ubicacion,U.IdBodega AS CdBodg,Bodega,Pasillo,Nivel,Profdad,DimAltura,DimAnch,DimLong,CapcVolm
,UndCapc,CapcPeso,UndPes,CdTmcia,TipoMcia,CdMnjo,ManejoMcia,Notas,U.Inactivo AS Inactiv,Descrip,LtaPre,TipoInv
 FROM BodUbic AS U INNER JOIN Bodegas AS B ON U.IdBodega=B.IdBodega
 LEFT JOIN  TiposMcia AS TM ON U.CdTmcia=TM.IdTmcia
 LEFT JOIN TiposMnjo AS TJ ON U.CdMnjo=TJ.IdMnjo
 WHERE U.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND Pasillo LIKE ISNULL(@pmPasillo,'%')
 AND Nivel LIKE ISNULL(@pmNivel,'%') AND Profdad LIKE ISNULL(@pmProfdad,'%')
 AND (U.Inactivo=ISNULL(@pmInactivo,0) or  U.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY U.IdBodega,IdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryBusClaseCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBusClaseCue] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL 
  SELECT IdClase,ClaseCuenta,Prioridad
  FROM BusClaseCue
  WHERE  Inactivo=0 
  ORDER BY ClaseCuenta
 ELSE
  SELECT IdClase,ClaseCuenta,Prioridad,Inactivo
  FROM BusClaseCue
  WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryCalndario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCalndario] @pmFechaDia SMALLDATETIME
 AS 
 IF @pmFechaDia IS NULL
  SELECT FechaDia,TipoFtvo  FROM Calndario  ORDER BY FechaDia
 ELSE
  SELECT FechaDia,TipoFtvo
  FROM Calndario
  WHERE FechaDia=@pmFechaDia
GO
/****** Object:  StoredProcedure [dbo].[paQryCalndarioMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCalndarioMes] @pmMes INT,@pmAnno INT
 AS 
 SELECT FechaDia,TipoFtvo  FROM Calndario 
 WHERE MONTH(FechaDia)=@pmMes AND YEAR(FechaDia)=@pmAnno
 ORDER BY FechaDia
GO
/****** Object:  StoredProcedure [dbo].[paQryCargos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCargos] @pmIdCargo VARCHAR(4)
 AS 
 IF @pmIdCargo IS NULL
   SELECT IdCargo,Cargo,Funciones
   FROM Cargos 
   WHERE  Inactivo=0
  ORDER BY Cargo
 ELSE
  SELECT IdCargo,Cargo,Funciones,Inactivo
  FROM Cargos 
  WHERE IdCargo=@pmIdCargo
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCausacion] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Fecha,IdConcepto,Factura,IdProveedor,FecFactura,FecVence,Referencia,Modalidad,IdVehiculo,IdPropietario,IdConductor,VehPropio,ValorTotal,ValorDcto,ValorIva,ValorReteFte,ValorReteIva,ValorReteIca,ValorOtros,ValorFletes,ValorNeto,ValorCCobrar,BaseIva,BaseRet,TarifaIva,TarifaRet,TarifaIca,IdTarIva,IdTarRet,IdTarIca,MulPlazos,IdPlazo,CxPagar,CxcVarios,TipEgr,Egreso,IdCiaEgr,Anulado,NumDev,FecDev,TipCom,Comprobante,IdCiaCom
,Observacion,IdEstado,CierreCte,IndFactura,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Causacion
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacion_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacion_Cr] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
AS
SELECT  C.TipDoc AS CodTipDoc,TipoDoc, C.Documento AS nDocumento, C.IdCia AS CodCia,Compania, Fecha, C.IdConcepto AS CodConcepto,CC.Concepto AS Concept, C.Factura AS NumFactura, C.IdProveedor AS NitProveedor,NV.RazonSocial AS Proveedor
,FecFactura, C.FecVence AS FechaVence, C.Referencia AS Referenc, C.Modalidad AS ModCausac
,C.IdVehiculo AS PlacaVeh,C.IdPropietario AS NitPropietario, C.IdConductor AS CedConductor, C.VehPropio AS VehProp, ValorTotal, ValorDcto, ValorIva, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorFletes, ValorNeto,ValorCCobrar
, BaseIva, BaseRet, TarifaIva,TarifaRet, C.TarifaIca AS PorceIca, IdTarIva, IdTarRet, IdTarIca, MulPlazos, C.IdPlazo AS CodPlazo,Plazo,DiasPago,NVmto, CxPagar,CxcVarios, TipEgr, Egreso, IdCiaEgr, Anulado, NumDev, FecDev,TipCom,TM.TipoCom  AS TipoComprobante
,Comprobante, IdCiaCom, C.Observacion AS Observ, C.IdEstado AS IdEstadDoc,ED.Estado AS EstadDoc,IndFactura,TimeSys, FecUpdate, IdCiaCrea, C.IdUsuario AS IdUsuari,Usuario,Leyenda
--detalles
,Item,VF.FecVence AS FecVenceFac,ValorFactura,ValorAbono,IdCliente,IdAgencia,VF.IdVehiculo AS PlacaVehvce,IdVendedor,VF.IdCargo AS IdCarg,F.Concepto AS NomCargo,VF.IdClase AS CodClase
,ClaseCuenta,FecUltPago,VF.Factura AS NFacVce,VF.Referencia AS RefVce,Detalle,TipRec,Recibo,IdCiaRec,ValorAtcpo,IdCuenta,CierreCte,VF.BaseImpu,VF.Tarifa_Iva,VF.VrIva,VF.Tarifa_Ret,VF.VrRetFte,VF.Tarifa_Ica,VF.VrRetIca,VF.TipDocFac,VF.NumDocFac,VF.CdCiaFac
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_Causacion  AS C  INNER JOIN Trn_CausacVence AS VF ON C.TipDoc = VF.TipDoc AND C.Documento = VF.Documento AND C.IdCia =VF.IdCia
  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc   INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
  INNER JOIN Conceptos AS CC ON C.IdConcepto=CC.IdConcepto
  INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
  INNER JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo 
  INNER JOIN Terceros AS  NV ON C.IdProveedor=NV.IdTercero
  INNER JOIN Terceros AS NP ON VF.IdCliente=NP.IdTercero  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Terceros AS NC ON VF.IdVendedor=NC.IdTercero INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN Fijos AS F ON VF.IdCargo=F.IdCargo   INNER JOIN BusClaseCue AS CU ON VF.IdClase=CU.IdClase
    INNER JOIN Vehiculos AS V ON VF.IdVehiculo=V.IdVehiculo   INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TiposCom AS TM ON C.TipCom=TM.IdCom   LEFT JOIN TercCndtores AS CT ON VF.IdVendedor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE   C.TipDoc=@pmTipDoc  AND C.Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin  AND  C.IdCia=@pmIdCia
 ORDER BY C.IdCia,C.Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacion_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacion_Crr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME ,@pmIdCia CHAR(2)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProveedor VARCHAR(16)=Null, @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmCxPagar BIT=Null,@pmAnulado BIT=Null
,@pmIdEstado VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT TipDoc,Documento,C.IdCia AS CodCia,Compania,Fecha,Factura,FecFactura,C.IdPlazo AS CodPlazo,Plazo,DiasPago,NVmto,MulPlazos,FecVence,C.Modalidad AS ModCausacion,C.IdProveedor AS NitProveed, NV.RazonSocial AS Proveedor
,C.IdVehiculo AS PlacaVeh,C.VehPropio AS VhPropio,C.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,ValorTotal, ValorDcto, ValorIva, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorFletes, ValorNeto,ValorCCobrar
, C.IdConcepto AS CodConcepto,Concepto,CxPagar,CxcVarios, BaseIva, BaseRet, TarifaIva,TarifaRet, TarifaIca,Anulado, NumDev, FecDev,TipCom,TipoCom,Comprobante,IdCiaCom, C.Observacion AS Observ,Referencia, C.IdEstado AS IdEstadDoc
,ED.Estado AS EstadDoc,IndFactura, IdCiaCrea, C.IdUsuario AS IdUsuari,Usuario,TipEgr, Egreso, IdCiaEgr,TipoDoc,TimeSys, FecUpdate
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_Causacion  AS C  INNER JOIN Sys_TiposDoc  AS TD ON C.TipDoc=TD.IdDoc   INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Conceptos AS CC ON C.IdConcepto=CC.IdConcepto  INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo 
 INNER JOIN Terceros AS  NV ON C.IdProveedor=NV.IdTercero
 INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero 
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TiposCom AS TM ON  C.TipCom=TM.IdCom   LEFT JOIN TercCndtores AS CT ON C.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  TipDoc LIKE ISNULL(@pmTipDoc,'%')  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.Modalidad LIKE ISNULL(@pmModalidad,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND C.IdProveedor LIKE ISNULL(@pmIdProveedor,'%')
 AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') 
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (CxPagar=ISNULL(@pmCxPagar,0) or CxPagar=ISNULL(@pmCxPagar,1))
 ORDER BY TipDoc,C.IdCia,Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionCie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionCie] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10)=Null,@pmIdCia CHAR(2)=Null
AS
 SELECT  TipDoc, Documento, IdCia, Fecha,Factura,Modalidad 
 FROM    Trn_Causacion 
 WHERE  TipDoc=@pmTipDoc AND CierreCte<>0 AND Anulado=0 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY  Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionCue] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT VC.IdCargo AS CodCargo,Concepto,V.IdAdmon,TipoAdmon,FC.IdCuentaDeb AS IdCuentDeb,FC.IdCuentaCre AS IdCuentCre
,FC.IdCueDebVp AS IdCueDbVp,FC.IdCueCreVp AS IdCueCrVp,FC.IdCuentaIva,FC.IdCuentaRet,FC.IdCuentaIca,SUM(ValorFactura) AS SvalFac
,SUM(VC.BaseImpu) AS BaseIva,SUM(VC.VrIva) AS TotalIva,SUM(VC.VrRetFte) AS TotalRet,SUM(VC.VrRetIca) AS TotalIca
 FROM Trn_Causacion AS C INNER JOIN Trn_CausacVence AS VC ON C.TipDoc=VC.TipDoc AND C.Documento=VC.Documento AND C.IdCia=VC.IdCia
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
 INNER JOIN Fijos AS F ON VC.IdCargo=F.IdCargo LEFT JOIN Fijos_Cue AS FC ON VC.IdCargo=FC.IdCargo AND V.IdAdmon=FC.IdAdmon
 WHERE Anulado=0 AND Comprobante<=0 AND C.TipDoc=@pmTipDoc AND Modalidad IN ('DIARIO','OCASIONAL')
 AND FecFactura BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY VC.IdCargo,Concepto,V.IdAdmon,TipoAdmon,FC.IdCuentaDeb,FC.IdCuentaCre,FC.IdCueDebVp,FC.IdCueCreVp,FC.IdCuentaIva,FC.IdCuentaRet,FC.IdCuentaIca
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionD_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionD_Cr] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT C.TipDoc AS TDoc,C.Documento AS NumDoc,C.IdCia AS CodCia,Fecha,FecFactura,IdCliente AS NitPropietario,RazonSocial,V.IdVehiculo AS PlacaVeh,V.VehPropio AS Espropio,IdVendedor AS CedConductor,V.IdCargo AS CodCargo,Concepto
,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,CdCuentaIva,CdCuentaRet,SUM(ValorFactura) AS SvalFac,SUM(V.BaseImpu) AS BaseIva,SUM(V.VrIva) AS TotalIva,SUM(V.VrRetFte) AS TotalRet
 FROM Trn_Causacion AS C INNER JOIN Trn_CausacVence AS V ON C.TipDoc=V.TipDoc AND C.Documento=V.Documento AND C.IdCia=V.IdCia
 INNER JOIN Fijos AS F ON V.IdCargo=F.IdCargo INNER JOIN Terceros AS P ON V.IdCliente=P.IdTercero
 WHERE Anulado=0 AND Comprobante<=0  AND Modalidad IN ('DIARIO','OCASIONAL')  AND C.TipDoc=@pmTipDoc
 AND FecFactura BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY C.TipDoc,C.Documento,C.IdCia,Fecha,FecFactura,IdCliente,RazonSocial,V.IdVehiculo,V.VehPropio,IdVendedor,V.IdCargo,Concepto,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,CdCuentaIva,CdCuentaRet
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionDia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionDia] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmDocumentoIni INT=Null ,@pmDocumentoFin INT=Null
AS
SELECT Documento,IdCia,Fecha,Referencia,Modalidad,IdVehiculo, IdPropietario,T.RazonSocial AS Propietario, IdConductor,O.RazonSocial AS Conductor,VehPropio,ValorNeto,Anulado,NumDev,FecDev,IndFactura
,TipCom,Comprobante,IdCiaCom,C.Observacion AS Observ,C.IdEstado AS IdEstad,Estado, TimeSys, FecUpdate, IdCiaCrea,C.IdUsuario AS IdUsuari
FROM  Trn_Causacion AS C LEFT JOIN Terceros AS T ON C.IdPropietario=T.IdTercero
LEFT JOIN Terceros AS O ON C.IdConductor=O.IdTercero LEFT JOIN EstadoDoc  AS E ON C.IdEstado=E.IdEstado
WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND Documento BETWEEN ISNULL(@pmDocumentoIni,0) AND ISNULL(@pmDocumentoFin,2147483647)
ORDER BY IdCia,Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCausacionFac] @pmFactura VARCHAR(15),@pmIdProveedor VARCHAR(16)

AS
SELECT   TipDoc, Documento, IdCia, Fecha, Factura, IdProveedor, FecFactura, FecVence
FROM     Trn_Causacion
WHERE  Factura=@pmFactura AND IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionFec] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmModalidad  VARCHAR(10),@pmFecha SMALLDATETIME

AS
SELECT     TipDoc, Documento, IdCia, Fecha, IdConcepto, Factura, IdProveedor, FecFactura, FecVence, Referencia, Modalidad, ValorNeto, Anulado, NumDev, FecDev, TipCom,Comprobante, IdCiaCom
FROM     Trn_Causacion
WHERE  Anulado=0  AND  TipDoc=@pmTipDoc  AND  IdCia=@pmIdCia AND Modalidad=@pmModalidad AND Fecha=@pmFecha
ORDER BY Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFfa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCausacionFfa] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmModalidad  VARCHAR(10),@pmFecFactura SMALLDATETIME

AS
SELECT     TipDoc, Documento, IdCia, Fecha, IdConcepto, Factura, IdProveedor, FecFactura, FecVence, Referencia, Modalidad, ValorNeto, Anulado, NumDev, FecDev, TipCom, 
                      Comprobante, IdCiaCom
FROM     Trn_Causacion
WHERE Anulado=0  AND  TipDoc=@pmTipDoc  AND  IdCia=@pmIdCia AND Modalidad=@pmModalidad AND FecFactura=@pmFecFactura
ORDER BY Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFij]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionFij] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT  IdCliente,VC.IdVehiculo AS PlacaVeh,V.IdAdmon AS CodAdm,TipoAdmon,VC.VehPropio AS Espropio,IdVendedor,VC.IdCargo AS CodCargo,Concepto,IdCuentaDeb,IdCuentaCre
,IdCueDebVp,IdCueCreVp,CdCuentaIva,CdCuentaRet,CdCuentaIca,SUM(ValorFactura) AS SvalFac,SUM(VC.BaseImpu) AS BaseIva,SUM(VC.VrIva) AS TotalIva
,SUM(VC.VrRetFte) AS TotalRet,SUM(VC.VrRetIca) AS TotalIca,MAX(VC.Tarifa_Iva) AS TarifIva,MAX(VC.Tarifa_Ret) AS TarifRet,MAX(VC.Tarifa_Ica) AS TarifIca
 FROM Trn_Causacion AS C INNER JOIN Trn_CausacVence AS VC ON C.TipDoc=VC.TipDoc AND C.Documento=VC.Documento AND C.IdCia=VC.IdCia
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
 INNER JOIN Fijos AS F ON VC.IdCargo=F.IdCargo
 WHERE Anulado=0 AND Comprobante<=0  AND Modalidad IN ('DIARIO','OCASIONAL')  AND C.TipDoc=@pmTipDoc
 AND FecFactura BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,VC.IdVehiculo,V.IdAdmon,TipoAdmon,VC.VehPropio,IdVendedor,VC.IdCargo,Concepto,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,CdCuentaIva,CdCuentaRet,CdCuentaIca
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionFijTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionFijTot] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT  SUM(ValorFactura) AS SValTot
 FROM Trn_Causacion AS C INNER JOIN Trn_CausacVence AS V ON C.TipDoc=V.TipDoc AND C.Documento=V.Documento AND C.IdCia=V.IdCia
 WHERE Anulado=0 AND Comprobante<=0 AND Modalidad IN ('DIARIO','OCASIONAL')  AND C.TipDoc=@pmTipDoc
 AND FecFactura BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionInt] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT   C.TipDoc AS Tdoc, C.Documento AS NDoc, C.IdCia AS CodCia, Fecha,C.Factura AS NumFact, FecFactura,ValorTotal,Anulado,TipCom,Comprobante, IdCiaCom,IdEstado,SUM(ValorFactura) AS SValFac
 FROM    Trn_Causacion AS C INNER JOIN Trn_CausacVence AS V ON C.TipDoc=V.TipDoc AND C.Documento=V.Documento AND C.IdCia=V.IdCia 
 WHERE  Anulado=0 AND Modalidad IN ('DIARIO','OCASIONAL')  AND  C.TipDoc=@pmTipDoc  AND FecFactura BETWEEN @pmFechaIni AND @pmFechaFin AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY C.TipDoc, C.Documento, C.IdCia, Fecha, C.Factura, FecFactura,ValorTotal,Anulado,TipCom,Comprobante, IdCiaCom,IdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacionOtr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacionOtr] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdVehiculo VARCHAR(10)
,@pmIdProveedor VARCHAR(16),@pmDocumentoIni INT=Null,@pmDocumentoFin INT=Null
AS
SELECT Documento,IdCia, Fecha, IdConcepto, Factura, IdProveedor,P.RazonSocial AS Proveedor, FecFactura, FecVence, Referencia, Modalidad, IdVehiculo, IdPropietario,O.RazonSocial AS Propietario,IdConductor
,D.RazonSocial AS Conductor, VehPropio, ValorTotal, ValorDcto, ValorIva, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorFletes, ValorNeto,ValorCCobrar, BaseIva, BaseRet, TarifaIva
,TarifaRet, TarifaIca, IdTarIva, IdTarRet, IdTarIca, MulPlazos,C.IdPlazo AS IdPlaz, CxPagar,CxcVarios, TipEgr, Egreso, IdCiaEgr, Anulado, NumDev, FecDev, TipCom,Comprobante, IdCiaCom,C.Observacion AS Observ
,C.IdEstado AS IdEstad,Estado,CierreCte,IndFactura,TimeSys, FecUpdate, IdCiaCrea, C.IdUsuario AS IdUsuari
FROM Trn_Causacion AS C  INNER JOIN Terceros AS P ON C.IdProveedor=P.IdTercero
 INNER JOIN Terceros AS O ON C.IdPropietario=O.IdTercero INNER JOIN Terceros AS D ON C.IdConductor=D.IdTercero
 INNER JOIN EstadoDoc  AS E ON C.IdEstado=E.IdEstado
WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia ,'%%')
 AND IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%')
 AND Documento BETWEEN ISNULL(@pmDocumentoIni,0) AND ISNULL(@pmDocumentoFin,2147483647)
ORDER BY IdCia,Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVence]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCausacVence] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,FecEmision,FecVence,ValorFactura,ValorAbono,IdCliente,IdAgencia,IdVehiculo,VehPropio,IdVendedor,Comision
,IdCargo,IdClase,IdConcepto,FecUltPago,NotaInt,FecUltLiquida,Factura,Referencia,Detalle,TipRec,Recibo,IdCiaRec,ValorAtcpo,IdCuenta,CombCant,CombValor
,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca,CodTarifIva,CodTarifRet,CodTarifIca,TipDocFac,NumDocFac,CdCiaFac
 FROM Trn_CausacVence
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVence_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVence_Cr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmSaldo DECIMAL(14,2),@pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdClase VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdVendedor VARCHAR(16)=Null,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT IdCliente,NP.RazonSocial AS Propietario,VC.IdVehiculo AS PlacaVeh,TipDoc,TipoDoc,Documento,VC.IdCia AS CodCia,Item, FecEmision, FecVence, ValorFactura, ValorAbono, ValorFactura-ValorAbono AS TotalSaldo
,VC.IdClase AS IdClas,ClaseCuenta,VC.IdCargo AS IdCarg,F.Concepto AS ConceptoCargo,Factura,Referencia,Detalle,VC.IdConcepto AS IdConcep,C.Concepto AS ConcepDoc,IdVendedor AS CedConductor
,NC.RazonSocial AS Conductor,Compania,FecUltPago,NotaInt,FecUltLiquida,TipRec, Recibo, IdCiaRec,ValorAtcpo,IdCuenta,VC.VehPropio AS VhPropio,CombCant,CombValor,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca
,CodTarifIva,CodTarifRet,CodTarifIca,TipDocFac,NumDocFac,CdCiaFac
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_CausacVence AS VC INNER JOIN Terceros AS NP ON VC.IdCliente=NP.IdTercero
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo INNER JOIN Sys_TiposDoc  AS TD ON VC.TipDoc=TD.IdDoc
 INNER JOIN Companias  AS CI ON VC.IdCia=CI.IdCia INNER JOIN BusClaseCue  AS CU ON VC.IdClase=CU.IdClase
 INNER JOIN Fijos AS F ON VC.IdCargo=F.IdCargo INNER JOIN Conceptos AS C ON VC.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS NC ON VC.IdVendedor=NC.IdTercero  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON VC.IdVendedor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE FecVence BETWEEN @pmFechaIni AND @pmFechaFin AND (ValorFactura-ValorAbono)>@pmSaldo AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  VC.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND VC.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND VC.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND VC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdVendedor LIKE ISNULL(@pmIdVendedor,'%') AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY NP.RazonSocial,VC.IdVehiculo,TipDoc,VC.IdCia,Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVence_Cra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVence_Cra] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmSaldo DECIMAL(14,2),@pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdClase VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdVendedor VARCHAR(16)=Null,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT VC.IdCliente AS NitCliente,NP.RazonSocial AS Propietario,VC.IdVehiculo AS PlacaVeh,VC.TipDoc AS CdTipDoc,TipoDoc,VC.Documento AS NumDoc,VC.IdCia AS CodCia,VC.Item AS NumItem, FecEmision, FecVence, ValorFactura, VC.ValorAbono AS TotalAbonos, ValorFactura-VC.ValorAbono AS TotalSaldo
,VC.IdClase AS IdClas,ClaseCuenta,VC.IdCargo AS IdCarg,F.Concepto AS ConceptoCargo,Factura,Referencia,VC.Detalle AS DetalleVence,VC.IdConcepto AS IdConcep,C.Concepto AS ConcepDoc,VC.IdVendedor AS CedConductor
,NC.RazonSocial AS Conductor,Compania,FecUltPago,NotaInt,FecUltLiquida,ValorAtcpo,IdCuenta,VC.VehPropio AS VhPropio,CombCant,CombValor,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca,CodTarifIva,CodTarifRet,CodTarifIca,TipDocFac,NumDocFac,CdCiaFac
,R.TipRec AS TipDocApl, R.Recibo AS NumRecibo, R.IdCia AS IdCiaApl, R.Item AS ItmApl,Fecha,R.ValorAbono AS VrAbonado,Devolucion, R.Detalle AS DetalleApl,FecPago
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_CausacVence AS VC INNER JOIN Terceros AS NP ON VC.IdCliente=NP.IdTercero
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo INNER JOIN Sys_TiposDoc  AS TD ON VC.TipDoc=TD.IdDoc
 INNER JOIN Companias  AS CI ON VC.IdCia=CI.IdCia INNER JOIN BusClaseCue  AS CU ON VC.IdClase=CU.IdClase
 INNER JOIN Fijos AS F ON VC.IdCargo=F.IdCargo INNER JOIN Conceptos AS C ON VC.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS NC ON VC.IdVendedor=NC.IdTercero  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON VC.IdVendedor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN Trn_RecFactura AS R ON VC.TipDoc = R.TipDoc AND VC.Documento = R.Documento AND VC.IdCia = R.IdCiaDoc AND VC.Item = R.ItemDoc 
 WHERE FecVence BETWEEN @pmFechaIni AND @pmFechaFin AND (ValorFactura-VC.ValorAbono)>@pmSaldo AND VC.TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  VC.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND VC.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND VC.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND VC.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND VC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND VC.IdVendedor LIKE ISNULL(@pmIdVendedor,'%') AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY NP.RazonSocial,VC.IdVehiculo,VC.TipDoc,VC.IdCia,VC.Documento,VC.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceAbb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceAbb] @pmIdVehiculo VARCHAR(10)
AS
 SELECT  TipDoc,Documento,IdCia,Item,ValorFactura,ValorAbono,FecEmision,FecVence,V.IdCargo AS IdCargo,V.IdClase AS CodClase
,ClaseCuenta,Prioridad,Detalle,TipoDcto,DctoPpago,OrdenAbono
 FROM  Trn_CausacVence AS V INNER JOIN BusClaseCue AS C ON V.IdClase=C.IdClase
 LEFT JOIN Fijos AS F ON V.IdCargo=F.IdCargo
 WHERE  IdVehiculo=@pmIdVehiculo AND ValorFactura>ValorAbono
 ORDER BY FecVence,OrdenAbono
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceApl]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceApl] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
AS
 SELECT   V.TipDoc AS TipoDoc, V.Documento AS Document, V.IdCia AS CodCia, V.Item AS NV,FecEmision,FecVence, ValorFactura, V.ValorAbono AS TotalAbono
 , R.TipRec AS TipoRec, R.Recibo AS NumRecibo, R.IdCia AS CiaRec, R.Item AS ItemRec,Fecha , 
                     R.ValorAbono AS ValorAplicado, Devolucion, Descuento,V.IdCliente AS IdClient,V.IdVehiculo AS IdVehic
 FROM  Trn_CausacVence AS  V LEFT JOIN Trn_RecFactura R ON V.TipDoc = R.TipDoc AND V.Documento = R.Documento AND V.IdCia = R.IdCiaDoc AND V.Item = R.ItemDoc 
 WHERE   V.TipDoc =@pmTipDoc AND V.Documento=@pmDocumento AND  V.IdCia=@pmIdCia
 AND (V.Item>=ISNULL(@pmItem,0)  AND V.Item<=ISNULL(@pmItem,2147483647))
 ORDER BY V.Item, R.IdCia,R.TipRec,R.Recibo,R.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceCli]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceCli]  @pmIdCliente VARCHAR(16)
AS
 IF @pmIdCliente IS NULL
  SELECT IdCliente,SUM(ValorFactura) AS STotFac,SUM(ValorAbono) AS StotAbo,SUM(ValorAtcpo) AS STotAnt
  FROM     Trn_CausacVence
  GROUP BY  IdCliente
 ELSE
  SELECT IdCliente,SUM(ValorFactura) AS STotFac,SUM(ValorAbono) AS StotAbo,SUM(ValorAtcpo) AS STotAnt
  FROM     Trn_CausacVence
  WHERE  IdCliente=@pmIdCliente
 GROUP BY  IdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceEvo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceEvo] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
--causaciones prestamos y ndb
AS
 SELECT TipDoc,IdCia,IdCliente,VC.IdVehiculo AS PlacaVeh,IdConductor,VC.IdClase AS CodClase,IdConcepto
,SUM(ValorFactura) AS STotal
 FROM  Trn_CausacVence AS VC  INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo
 WHERE TipDoc IN ('ND1','PRE','FVC') AND  FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND VC.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 GROUP BY TipDoc,IdCia,IdCliente,VC.IdVehiculo,IdConductor,VC.IdClase,IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceExt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceExt] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
,@pmAnulado BIT=Null
--causaciones solamente
AS
 SELECT VC.TipDoc AS TipoDcm,VC.IdCia AS CodCia,IdCliente,VC.IdVehiculo AS PlacaVeh,V.IdConductor AS IdCondtor,VC.IdClase AS CodClase,VC.IdConcepto AS CodCocepto,IdCargo
,SUM(ValorFactura) AS STotal,SUM(CombCant) AS STotGal,SUM(CombValor) AS SValComb
 FROM  Trn_CausacVence AS VC  INNER JOIN Trn_Causacion AS C ON VC.TipDoc=C.TipDoc  AND  VC.Documento=C.Documento AND  VC.IdCia=C.IdCia
 INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo
 WHERE VC.TipDoc IN ('ADM','OTR')  AND  FecEmision BETWEEN @pmFechaIni AND @pmFechaFin  AND VC.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND VC.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 GROUP BY VC.TipDoc,VC.IdCia,IdCliente,VC.IdVehiculo,V.IdConductor,VC.IdClase,VC.IdConcepto,IdCargo
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceLca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceLca] @pmIdVehiculo VARCHAR(10)
AS
SELECT  TipDoc, Documento, IdCia, Item,V.IdCargo AS IdCarg,Concepto,Detalle,ValorFactura-ValorAbono AS ValorSaldo,ValorFactura,ValorAbono,FecEmision,FecVence, IdCliente,T.RazonSocial AS NomCliente,IdAgencia
, IdVehiculo,VehPropio,IdVendedor,C.RazonSocial AS Conductor,V.IdClase AS CodClase,ClaseCuenta,Factura, Referencia,TipRec, Recibo, IdCiaRec,ValorAtcpo,CombCant
 FROM   Trn_CausacVence AS V INNER JOIN Terceros AS T ON  V.IdCliente=T.IdTercero
 INNER JOIN  BusClaseCue AS U ON  V.IdClase=U.IdClase
 INNER JOIN Terceros AS C ON  V.IdVendedor=C.IdTercero
 INNER JOIN  Fijos AS F ON  V.IdCargo=F.IdCargo
 WHERE  ValorFactura>ValorAbono  AND  IdVehiculo=@pmIdVehiculo
ORDER BY Prioridad,FecVence
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmFechaAct SMALLDATETIME,@pmSaldo DECIMAL(14,4)
,@pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT  TipDoc,Documento, IdCia, Item, FecEmision, FecVence,DATEDIFF(Day,FecVence,@pmFechaAct) AS DiasMora,ValorFactura, ValorAbono,ValorFactura-ValorAbono AS ValorSaldo,IdCliente,T.RazonSocial AS NomCliente,IdVehiculo,VehPropio
 ,IdVendedor AS IdCondctor,C.RazonSocial AS NomConductor,V.IdCargo AS IdCarg,Concepto,V.IdClase AS CodClase, IdConcepto,Factura, Referencia, Detalle,FecUltPago, TipRec, Recibo, IdCiaRec,ValorAtcpo,NotaInt,FecUltLiquida,IdAgencia,Comision
,CombCant,CombValor,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca,CodTarifIva,CodTarifRet,CodTarifIca,TipDocFac,NumDocFac,CdCiaFac
  FROM Trn_CausacVence AS V INNER JOIN Terceros AS T ON  V.IdCliente=T.IdTercero
  INNER JOIN Terceros AS C ON  V.IdVendedor=C.IdTercero
  INNER JOIN  Fijos AS F ON  V.IdCargo=F.IdCargo
  WHERE (ValorFactura-ValorAbono)>@pmSaldo 
  AND (FecVence>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecVence<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
  AND  IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
  AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  IdCia LIKE ISNULL(@pmIdCia ,'%%')  AND V.IdClase LIKE ISNULL(@pmIdClase ,'%')
 ORDER BY FecVence DESC,IdCia,TipDoc,Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceMor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceMor] @pmTipDoc VARCHAR(3),@pmIdClase VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdVehiculo VARCHAR(10)
AS
SELECT   TipDoc, Documento, IdCia, Item, FecEmision, FecVence, ValorFactura, ValorAbono, IdCliente, IdAgencia, IdVehiculo, IdCargo,IdClase, Factura, Referencia, Detalle
FROM     Trn_CausacVence
WHERE ValorFactura>ValorAbono AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND IdClase LIKE ISNULL(@pmIdClase,'%')
  AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
ORDER BY FecVence
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceNMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceNMes] @pmAnno INT,@pmMes INT=Null,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdClase VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS --ACUMULADOS MENSUALES POR VEHICULO Y COMPAÑIA
 SELECT  IdCliente,IdVehiculo,IdCia,IdClase,Month(FecEmision) AS nMes,SUM(ValorFactura) AS StotFac,SUM(ValorAbono) AS StotAbo
 FROM   Trn_CausacVence
 WHERE Year(FecEmision)=@pmAnno AND  Month(FecEmision)=ISNULL(@pmMes, Month(FecEmision))
 AND IdCia like ISNULL(@pmIdCia,'%%') AND   TipDoc like ISNULL(@pmTipDoc,'%') AND IdCliente like ISNULL(@pmIdCliente,'%')
 AND IdClase like ISNULL(@pmIdClase,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 GROUP BY IdCliente,IdVehiculo,IdCia,IdClase,Month(FecEmision)
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceTot] @pmTipDoc VARCHAR(3), @pmDocumento INT, @pmIdCia CHAR(2)
AS
SELECT  IdCliente,IdVehiculo,SUM(ValorFactura) AS SValFac,SUM(ValorAbono) AS SValAbo
FROM     Trn_CausacVence
WHERE   TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia
GROUP BY IdCliente, IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceTpa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceTpa] @pmIdVehiculo VARCHAR(10)
AS
 IF @pmIdVehiculo IS NULL
  SELECT  SUM(ValorFactura) AS STotFac,SUM(ValorAbono) AS STotAbo,SUM(ValorAtcpo) AS STotAnt 
  FROM  Trn_CausacVence 
 ELSE
  SELECT  SUM(ValorFactura) AS STotFac,SUM(ValorAbono) AS STotAbo,SUM(ValorAtcpo) AS STotAnt 
  FROM  Trn_CausacVence 
  WHERE  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceVeh]  @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
IF @pmIdVehiculo IS NULL 
 SELECT V.IdVehiculo AS IdVehic,V.IdClase AS IdClas, IdCia, SUM(ValorFactura) AS STotFac,SUM(ValorAbono) AS StotAbo,SUM(ValorAtcpo) AS STotAnt
 FROM  Trn_CausacVence AS V INNER JOIN Vehiculos AS H ON V.IdVehiculo=H.IdVehiculo
 WHERE IdPropietario like ISNULL(@pmIdPropietario,'%') 
 GROUP BY  V.IdVehiculo,V.IdClase ,IdCia
ELSE --POR VEHICULO
 SELECT V.IdVehiculo AS IdVehic,V.IdClase AS IdClas, IdCia, SUM(ValorFactura) AS STotFac,SUM(ValorAbono) AS StotAbo,SUM(ValorAtcpo) AS STotAnt
 FROM     Trn_CausacVence AS V 
 WHERE V.IdVehiculo=@pmIdVehiculo
 GROUP BY  V.IdVehiculo,V.IdClase ,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceVFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceVFec] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdClase VARCHAR(4)=Null
AS 
 SELECT IdCliente,IdVehiculo,SUM(ValorFactura) AS StotFac,SUM(ValorAbono) AS StotAbo
 FROM   Trn_CausacVence
 WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND IdClase LIKE ISNULL(@pmIdClase,'%')
 GROUP BY IdCliente,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryCausacVenceVp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausacVenceVp] @pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT TipDoc,Documento,IdCia,Item,FecEmision, FecVence, ValorFactura, ValorAbono, IdCliente, IdAgencia, IdVehiculo, VehPropio, IdVendedor
,Comision,IdCargo,V.IdClase AS CodClase,ClaseCuenta,Prioridad,IdConcepto,FecUltPago, NotaInt, FecUltLiquida, Factura, Referencia, Detalle, TipRec, Recibo, IdCiaRec
,ValorAtcpo,IdCuenta,CombCant,CombValor,BaseImpu,Tarifa_Iva,VrIva,Tarifa_Ret,VrRetFte,Tarifa_Ica,VrRetIca,CodTarifIva,CodTarifRet,CodTarifIca,TipDocFac,NumDocFac,CdCiaFac
,ISNULL(tmValorAbono,0) AS TotaAbonos
 FROM  Trn_CausacVence AS V INNER JOIN BusClaseCue AS C ON V.IdClase=C.IdClase
 LEFT JOIN tm_vce AS TV ON V.TipDoc=TV.tmTipDoc AND V.Documento=TV.tmDocumento AND V.IdCia=TV.tmIdCia AND V.Item=TV.tmItem
 WHERE ValorFactura>(ISNULL(tmValorAbono,0)+0.5)  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND   IdCliente like ISNULL(@pmIdCliente,'%')  
 ORDER BY Prioridad,FecVence,TipDoc,Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCausaVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCausaVales] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos
,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,TarifaIva,TarifaRet,TarifaIca,CodTarIva,CodTarRet,CodTarIca,IdVend,TarifaCom,CodTarCom,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_CausaVales
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCausaVales_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausaVales_Cr] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipDoc AS CdTipDoc,TipoDoc,F.Documento AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaFact,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS Id_agencia,Agencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,F.TarifaIva AS TarifIva
,F.TarifaRet AS TarifRet,F.TarifaIca AS TarifIca,F.CodTarIva AS CdTarifIva,F.CodTarRet AS CdTarifRet,F.CodTarIca AS CdTarifIca,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,F.CodTarCom AS CdTarifCom
,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado
,F.TimeSys AS Fecha_Add,FecUpdate,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm
,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,VrBruto,K.Referencia AS KarReferencia,Descripcion
,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarRemision,K.IdCiaRem AS KarCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev,Unidades,pVehiculo
,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,Referencia2,CodTarCmc
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_CausaVales AS F  INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Documento=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TCM ON F.TipCom=TCM.IdCom
 WHERE F.TipDoc=@pmTipDoc AND F.Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND F.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY F.Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCausaValesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCausaValesLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDocumentoIni INT=Null, @pmDocumentoFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Documento,F.IdCia AS CdCia,Compania,Fecha,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,Agencia
,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,TarifaIva,TarifaRet,TarifaIca
,CodTarIva,CodTarRet,CodTarIca,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,TipCom,TipoCom,Comprobante,IdCiaCom,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,OrigenAdd,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 FROM Trn_CausaVales AS F  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario  INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON F.TipCom=TC.IdCom
 WHERE Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND (Documento>=ISNULL(@pmDocumentoIni,0)  AND Documento<=ISNULL(@pmDocumentoFin,2147483647))
 AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY F.IdCia,Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryCentroCosto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCentroCosto] @pmIdCCosto VARCHAR(16)
 AS 
 IF @pmIdCCosto IS NULL
  SELECT IdCCosto,CCosto,CodCias,FechaAdd,FechaUpdate 
  FROM CentroCosto
  WHERE Inactivo=0
  ORDER BY CCosto
ELSE
  SELECT IdCCosto,CCosto,CodCias,FechaAdd,FechaUpdate,Inactivo 
  FROM CentroCosto
  WHERE IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paQryCentroCostoCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCentroCostoCia] @pmCodCias VARCHAR(2)
 AS 
  SELECT IdCCosto,CCosto,CCosto+' '+IdCCosto AS DsCco
  FROM CentroCosto
  WHERE (ISNULL(CodCias,'') LIKE '%'+@pmCodCias+'%' OR LEN(ISNULL(CodCias,''))=0 OR ISNULL(CodCias,'')='0')
  AND Inactivo=0
  ORDER BY CCosto
GO
/****** Object:  StoredProcedure [dbo].[paQryCentroCostoDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCentroCostoDso] @pmInactivo BIT=Null
 AS 
  SELECT IdCCosto,CCosto,CCosto+' '+IdCCosto AS DsCco 
  FROM CentroCosto
  WHERE   (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY CCosto
GO
/****** Object:  StoredProcedure [dbo].[paQryCentrosServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCentrosServ] @pmIdCenSer VARCHAR(4)
 AS 
 SELECT IdCenSer,CentroServ,DirCentro,IdLocal,Telefonos,TipoCentro,NitResp,Respnsable,Inactivo
 FROM CentrosServ
 WHERE IdCenSer=@pmIdCenSer
GO
/****** Object:  StoredProcedure [dbo].[paQryCentrosServLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCentrosServLta] 
 AS 
 SELECT IdCenSer,CentroServ,DirCentro,C.IdLocal AS CodCiudad,Localidad,L.IdDep AS CodDpto,Departamento
,Telefonos,TipoCentro,NitResp,Respnsable
 FROM CentrosServ AS C INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE C.Inactivo=0
 ORDER BY CentroServ
GO
/****** Object:  StoredProcedure [dbo].[paQryCheques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCheques] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 SELECT TipForma,Numero,IdBanco,IdCia,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle,NitCliente,CdAgencia,CdVend,IdLocal
,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,Anulado,FecDev,IdEstado,IdCiaCrea,IdUsuario
 FROM Trn_Cheques
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesCns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryChequesCns]  @pmNitCliente VARCHAR(16)=Null,@pmCdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT TipForma,Numero,C.IdBanco AS CodBanco,Banco,C.IdCia AS CodCia,Compania,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle
,NitCliente,T.RazonSocial AS NomCliente,CdAgencia,CdVend,V.RazonSocial AS NomVendedor,C.IdLocal AS CodCiudad,Localidad,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc
,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,C.IdEstado AS CdEstado,Estado,C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Cheques AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS T ON C.NitCliente=T.IdTercero
 LEFT JOIN Terceros AS V ON C.CdVend=V.IdTercero 
 WHERE Anulado=0 AND NumConsig<=0 AND  NitCliente LIKE ISNULL(@pmNitCliente,'%') AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%')
  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Fecha,TipForma,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryChequesDoc]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipForma,Numero,IdBanco,IdCia,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle,NitCliente,CdAgencia,CdVend,IdLocal
,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,Anulado,FecDev,IdEstado,IdCiaCrea,IdUsuario
 FROM Trn_Cheques
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
 AND  IdCia=@pmIdCiaDoc
 ORDER BY TipForma,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryChequesLta] @pmTipForma VARCHAR(3)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNitCliente VARCHAR(16)=Null,@pmCdVend VARCHAR(16)=Null
,@pmTipRec VARCHAR(3)=Null,@pmTipDoc VARCHAR(3)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmDocumentoIni INT=Null,@pmDocumentoFin INT=Null
 AS 
 SELECT TipForma,Numero,C.IdBanco AS CodBanco,Banco,C.IdCia AS CodCia,Compania,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle
,NitCliente,T.RazonSocial AS NomCliente,CdAgencia,Agencia,CdVend,V.RazonSocial AS NomVendedor,C.IdLocal AS CodCiudad,Localidad,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig
,IdCiaCon,FecConsig,CdCta,Anulado,FecDev,C.IdEstado AS CdEstado,Estado,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Cheques AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS T ON C.NitCliente=T.IdTercero
 LEFT JOIN Terceros AS V ON C.CdVend=V.IdTercero 
 LEFT JOIN Agencias AS A ON C.CdAgencia=A.IdAgencia
 WHERE  TipForma LIKE ISNULL(@pmTipForma,'%') AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND NitCliente LIKE ISNULL(@pmNitCliente,'%') AND CdVend LIKE ISNULL(@pmCdVend,'%')
 AND TipRec LIKE ISNULL(@pmTipRec,'%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND Recibo BETWEEN ISNULL(@pmReciboIni,-1) AND ISNULL(@pmReciboFin,2147483647)
 AND Documento BETWEEN ISNULL(@pmDocumentoIni,-1) AND ISNULL(@pmDocumentoFin,2147483647)
 ORDER BY Fecha,TipForma,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryChequesPen]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT TipForma,Numero,IdBanco,IdCia,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle,NitCliente,CdAgencia,CdVend,IdLocal
,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,Anulado,FecDev,IdEstado,IdCiaCrea,IdUsuario
 FROM Trn_Cheques
 WHERE Anulado=0  AND Documento<=0 AND IdEstado<>'9998'  AND TipRec='CHE' AND Recibo>0
  AND  Fecha BETWEEN @pmFechaIni  AND @pmFechaFin  AND NitCliente LIKE ISNULL(@pmIdCliente,'%')
  AND CdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND CdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesPos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryChequesPos] @pmFecPago SMALLDATETIME,@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 SELECT TipForma,Numero,C.IdBanco AS CodBanco,Banco,C.IdCia AS CodCia,Compania,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2
,Detalle,NitCliente,CdAgencia,CdVend,RazonSocial,C.IdLocal AS CodCiudad,Localidad,TipRec,Recibo
,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,C.IdEstado AS CodEstado,Estado 
 FROM Trn_Cheques AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 LEFT JOIN Terceros AS V ON C.CdVend=V.IdTercero 
 WHERE  Anulado=0  AND Recibo>0 AND Documento<=0 AND FecPago<=@pmFecPago
 AND NitCliente=@pmNitCliente AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY FecPago,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryChequesRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryChequesRec]  @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipForma,Numero,IdBanco,IdCia,Fecha,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle,NitCliente,CdAgencia,CdVend,IdLocal
,TipRec,Recibo,TipDoc,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,Anulado,FecDev,IdEstado,IdCiaCrea,IdUsuario
 FROM Trn_Cheques
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo  AND IdCia=@pmIdCia
 ORDER BY TipForma,IdBanco,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseBan] @pmIdClase VARCHAR(4)
 AS 
IF @pmIdClase IS NULL
  SELECT IdClase,ClaseBanco 
  FROM ClaseBan
  WHERE Inactivo=0
 ORDER BY ClaseBanco
ELSE 
  SELECT IdClase,ClaseBanco,Inactivo
  FROM ClaseBan
  WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseCapac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseCapac] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,NomClase FROM ClaseCapac WHERE Inactivo=0
 ELSE
  SELECT IdClase,NomClase,Inactivo FROM ClaseCapac WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseCta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClaseCta] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,ClaseCuenta
  FROM ClaseCta
  WHERE Inactivo=0
  ORDER BY ClaseCuenta
 ELSE
  SELECT IdClase,ClaseCuenta,Inactivo
  FROM ClaseCta
  WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseDiv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClaseDiv] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
 SELECT IdClase,NomClase
 FROM ClaseDiv
 WHERE Inactivo=0
 ORDER BY IdClase
 ELSE
 SELECT IdClase,NomClase,Inactivo
 FROM ClaseDiv
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseDivDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClaseDivDso] @pmGrupo VARCHAR(20)
 AS 
 IF @pmGrupo='FACTURA' 
   SELECT IdClase,NomClase FROM ClaseDiv  WHERE Inactivo=0 AND IdClase<>'1001' AND IdClase<>'1002' ORDER BY  IdClase
 ELSE -- GASTOS,EGRESOS,INGRESOS,OTROS
   SELECT IdClase,NomClase FROM ClaseDiv  WHERE Inactivo=0 AND IdClase IN ('1001','1002') ORDER BY  IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseDocCond]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseDocCond] @pmIdDoc VARCHAR(4)
 AS 
 IF @pmIdDoc IS NULL
  BEGIN
   SELECT IdDoc,Documento,Vigencia FROM ClaseDocCond
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdDoc,Documento,Vigencia,Inactivo FROM ClaseDocCond
   WHERE IdDoc=@pmIdDoc
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseFon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClaseFon] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,ClaseFondo
  FROM ClaseFon
  WHERE  Inactivo=0
  ORDER BY  IdClase
 ELSE
  SELECT IdClase,ClaseFondo,Inactivo
  FROM ClaseFon
  WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClasePol]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClasePol] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
 SELECT IdClase,ClasePoliza
 FROM ClasePol
 WHERE Inactivo=0
 ORDER BY IdClase
 ELSE
 SELECT IdClase,ClasePoliza,Inactivo
 FROM ClasePol
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseRie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseRie] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,ClaseRiesgo,Tarifa,CodClase
  FROM ClaseRie
  WHERE  Inactivo=0
  ORDER  BY IdClase
 ELSE
  SELECT IdClase,ClaseRiesgo,Tarifa,CodClase,Inactivo
  FROM ClaseRie
  WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseRieDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClaseRieDso]
 AS 
  SELECT IdClase,ClaseRiesgo,Tarifa,ClaseRiesgo+ ' ' + STR(Tarifa,5,3) AS DsRie
  FROM ClaseRie
  WHERE  Inactivo=0
  ORDER  BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseSub] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
 SELECT IdClase,NomClase
 FROM ClaseSub
 WHERE Inactivo=0
 ORDER BY  IdClase
 ELSE
 SELECT IdClase,NomClase,Inactivo
 FROM ClaseSub
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseTar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseTar] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
  SELECT IdClase,NomClase
  FROM ClaseTar
  WHERE Inactivo=0
  ORDER BY IdClase
 ELSE
  SELECT IdClase,NomClase,Inactivo
  FROM ClaseTar
  WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClaseTarImp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClaseTarImp]
 AS 
  SELECT IdClase,NomClase
  FROM ClaseTar
  WHERE Inactivo=0 AND IdClase IN ('DEP','GLO','ICA','IVA','MUN','NAC','RET','RIV','SOB','SOL','MGM','PRE','TSN','TSD','TSM','SUB','MAR','COS','IVI','IGP','MGC','MGN','CSE','INC','BIM','BIC','ICO','BIP','IVP','BPC','DTR','TST','PRD','PRM','PRT','PRN')
  ORDER BY NomClase
GO
/****** Object:  StoredProcedure [dbo].[paQryClieContado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryClieContado] @pmIdCliente VARCHAR(16)
 AS 
 SELECT IdCliente,Nombre,TipoId,Dv,Direccion,IdLocal,Telefono,email,Excento,PosIniNom,Inactivo,FechaAdd,FechaUpdate
 FROM ClieContado
 WHERE IdCliente=@pmIdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryClieContadoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClieContadoLta] @pmIdLocal VARCHAR(8)=Null
 AS 
 SELECT IdCliente,Nombre,TipoId,Dv,Direccion,C.IdLocal AS CodCiudad,Localidad,L.IdDep AS CdDep,Departamento
,Telefono,email,Excento,PosIniNom,FechaAdd,FechaUpdate
 FROM ClieContado AS C INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE C.Inactivo=0 AND C.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 ORDER BY Nombre
GO
/****** Object:  StoredProcedure [dbo].[paQryClieContadoTel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryClieContadoTel] @pmTelefono VARCHAR(20)
 AS 
 SELECT IdCliente,Nombre,TipoId,Dv,Direccion,IdLocal,Telefono,email,Excento,PosIniNom,Inactivo,FechaAdd,FechaUpdate
 FROM ClieContado
 WHERE Telefono=@pmTelefono
 ORDER BY IdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCnxextna] @pmIdReg INT
 AS 
 SELECT IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd
,CnxOwner,CnxObserv,CnxPpties,CnxDriver,CnxPort,CnxTerminal
 FROM Sys_Cnxextna
 WHERE IdReg=@pmIdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextnaItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCnxextnaItm] 
 AS 
 SELECT MAX(IdReg) AS MXITM
 FROM Sys_Cnxextna
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextnaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCnxextnaLta] @pmCnxTipo VARCHAR(10)=Null
 AS 
 SELECT IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxOwner,CnxObserv
,CnxPpties,CnxDriver,CnxPort,CnxTerminal,CnxPwd
 FROM Sys_Cnxextna
 WHERE  CnxTipo LIKE ISNULL(@pmCnxTipo,'%')
 ORDER BY IdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryCnxextnaTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCnxextnaTip] @pmCnxTipo VARCHAR(10)
 AS 
 SELECT IdReg,CnxTipo,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxObserv
,CnxPpties,CnxDriver,CnxPort,CnxTerminal
 FROM Sys_Cnxextna
 WHERE  CnxTipo=@pmCnxTipo
 ORDER BY IdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComDetalle] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza,CdCuentaNiif
 FROM Trn_ComDetalle
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalle_Crd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalle_Crd] @pmTipCom VARCHAR(3),@pmComprobanteIni INT,@pmComprobanteFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,TipoCom,Comprobante,D.IdCia AS CdCia,Compania,Item,Fecha,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,RazonSocial,IdVehiculo
,D.IdCCosto AS CdCentCosto,CCosto,D.IdSubCos AS CdSubCentro,SubCosto,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_ComDetalle AS D INNER JOIN Companias AS C ON D.IdCia=C.IdCia
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 INNER JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 WHERE TipCom=@pmTipCom AND Comprobante BETWEEN @pmComprobanteIni AND @pmComprobanteFin AND D.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleAge]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleAge] @pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
 AS 
  SELECT  IdCia,D.IdCuenta AS CdCuenta,IdTercero,CodAgncia AS CdAgncia
,SUM(VrDebito) AS TotalDeb,SUM(VrCredito) AS TotalCre
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento=1 AND Tercero=1 AND Agencia=1
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') 
  GROUP BY  IdCia,D.IdCuenta,IdTercero,CodAgncia
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleChe]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleChe] @pmNumCheque VARCHAR(20),@pmCodCta VARCHAR(4), @pmTipCom VARCHAR(3),@pmIdCia CHAR(2)
AS
 SELECT TipCom, Comprobante, IdCia, Item, Fecha,CodCta, NumCheque
 FROM    Trn_ComDetalle
 WHERE NumCheque=@pmNumCheque AND CodCta like ISNULL(@pmCodCta,'%') AND TipCom like ISNULL(@pmTipCom,'%') AND  IdCia like ISNULL(@pmIdCia,'%%')
 ORDER BY  TipCom,IdCia,Comprobante,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleCueNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleCueNit] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmCodAgncia VARCHAR(16)=Null,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null
,@pmIdCueIni VARCHAR(16)=Null,@pmIdCueFin VARCHAR(16)=Null
 AS 
 IF @pmIdCueIni IS NULL
  SELECT D.IdCuenta AS CdCuenta,IdTercero,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Tercero<>0  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,IdTercero,TipCom,IdCia
ELSE
  SELECT D.IdCuenta AS CdCuenta,IdTercero,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Tercero<>0  AND  D.IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin
   AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,IdTercero,TipCom,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleCueTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleCueTip] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmCodAgncia VARCHAR(16)=Null,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null
,@pmIdCueIni VARCHAR(16)=Null,@pmIdCueFin VARCHAR(16)=Null
 AS 
 IF @pmIdCueIni IS NULL
  SELECT D.IdCuenta AS CdCuenta,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,TipCom,IdCia
ELSE
  SELECT D.IdCuenta AS CdCuenta,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  D.IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin
   AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,TipCom,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleDia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleDia]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIntegrado BIT=Null,@pmCueIni VARCHAR(16)=Null,@pmCueFin VARCHAR(16)=Null
AS
 IF @pmCueIni IS NULL --NO RANGOS
  SELECT IdVehiculo,IdTercero,Fecha,SUM(VrDebito) AS  tValorDebito,SUM(VrCredito) AS tValorCredito,SUM(VrCredito-VrDebito) AS ValorDiario
  FROM  Trn_ComDetalle AS D INNER JOIN Puc  AS P ON D.IdCuenta=P.IdCuenta
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND Tercero<>0 AND  IdCia like ISNULL(@pmIdCia,'%%') AND D.IdCuenta like ISNULL(@pmIdCuenta,'%') 
  AND IdTercero like ISNULL(@pmIdTercero,'%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 AND   (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
  GROUP BY  IdVehiculo,IdTercero,Fecha
  ORDER BY IdVehiculo,IdTercero,Fecha
 ELSE --RANGOS Y LIKE
  BEGIN
  IF @pmCueIni='LIKE'
   SELECT IdVehiculo,IdTercero,Fecha,SUM(VrDebito) AS  tValorDebito,SUM(VrCredito) AS tValorCredito,SUM(VrCredito-VrDebito) AS ValorDiario
   FROM  Trn_ComDetalle AS D INNER JOIN Puc  AS P ON D.IdCuenta=P.IdCuenta
   WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND Tercero<>0 AND D.IdCuenta LIKE @pmIdCuenta AND IdCia LIKE ISNULL(@pmIdCia,'%%')
   AND IdTercero LIKE ISNULL(@pmIdTercero,'%')   AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')   
  AND   (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
   GROUP BY IdVehiculo,IdTercero,Fecha
   ORDER BY  IdVehiculo,IdTercero,Fecha
  ELSE --RANGO DE CUENTAS
   SELECT  IdVehiculo,IdTercero,Fecha,SUM(VrDebito) AS  tValorDebito,SUM(VrCredito) AS tValorCredito,SUM(VrCredito-VrDebito) AS ValorDiario
   FROM  Trn_ComDetalle AS D INNER JOIN Puc  AS P ON D.IdCuenta=P.IdCuenta
   WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Movimiento<>0 AND Tercero<>0  AND  D.IdCuenta BETWEEN @pmCueIni AND @pmCueFin  AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
   AND IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
  AND   (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
   GROUP BY  IdVehiculo,IdTercero,Fecha
   ORDER BY IdVehiculo,IdTercero,Fecha
 END
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleDmto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComDetalleDmto] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,TipoCom,Comprobante,D.IdCia AS CdCia,Compania,Item,Fecha,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero
,IdVehiculo,D.IdCCosto AS CdCCosto,CCosto,D.IdSubCos AS CdSubCosto,SubCosto,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,Concepto
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumeroCta,CTA.IdBanco AS CdBanco,Banco,NumCheque,Integrado,TipoAplica,Consolida,CodCargo
,NitOtros,N.RazonSocial AS NomTerceroOtros,CodSubgpo,CiuOrigen,Localidad,CodAgncia,A.Agencia AS NomAgencia,Referncia,NitDoc,TipDocRef,DocRef,IdCiaRef
,TimeSys,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_ComDetalle AS D INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 LEFT JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto  LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Agencias AS A ON D.CodAgncia=A.IdAgencia LEFT JOIN Conceptos AS CN ON D.CodConce=CN.IdConcepto
 LEFT JOIN CtasCorrientes AS CTA ON D.CodCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Terceros AS N ON D.NitOtros=N.IdTercero LEFT JOIN Localidades AS DL ON D.CiuOrigen=DL.IdLocal
 WHERE TipDoc=@pmTipDoc AND Documento  BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND D.IdCia=@pmIdCia
 AND Integrado=1
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComDetalleDoc]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmIntegrado BIT=Null
 AS 
 IF @pmIntegrado IS NULL
  SELECT TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
 ,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
  FROM Trn_ComDetalle
  WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
  ORDER BY TipCom,Comprobante,Item
 ELSE
  SELECT TipCom,Comprobante,IdCia,Item,Fecha,IdCuenta,Detalle,VrDebito,VrCredito,IdTercero,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
 ,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia
,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
  FROM Trn_ComDetalle
  WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
  AND Integrado=@pmIntegrado  AND IdCia=@pmIdCiaDoc
  ORDER BY TipCom,Comprobante,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmTipDoc VARCHAR(3)=Null,@pmEsEgreso BIT=Null,@pmIntegrado BIT=Null
,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT C.TipCom AS IdTipoComp,TipoCom,C.Comprobante AS NumComp,C.IdCia AS CdCia,Compania,C.Fecha AS FecComp,C.IdTercero AS Nit,T.RazonSocial AS RaznSocial
,VrTotal,C.IdCta AS CodCta,NumeroCta,CTE.IdBanco AS CodBanco,Banco,EnEfectivo,C.NumCheque AS NroCheque,FecCheque,C.TipDoc AS IdTipoDoc,TipoDoc,C.Documento AS NroDoc,C.IdCiaDoc AS CdCiaDoc
,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,C.VehPropio AS EsVehPropio,C.CodConce AS CdConcep,Concepto,Beneficiario,C.Integrado AS EsIntegrado,C.EsEgreso AS EsCompEgreso
,Anticipo,NiifTipo,NiifNumero,FisTipo,FisNumero,C.Observacion AS Observ,C.IdEstado AS CodEstado,Estado,Propddes
--detalles de comprobantes
,Item,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,IdVehiculo
,D.IdCCosto AS CdCentCosto,CCosto,D.IdSubCos AS CdSubCentro,SubCosto,VrBase,TarifaBase
,D.TipDoc AS DetTipDoc,D.Documento AS DetNumDoc,D.IdCiaDoc AS DetCiaDoc,D.CodConce AS DetConcept,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,D.NumCheque AS DetNumCheque
,TipoAplica,Consolida,CodCargo,NitOtros,NIO.RazonSocial AS NomNitOtros,CodSubgpo,Subgrupo,CiuOrigen,LD.Localidad AS NomCiudad,CodAgncia,Referncia
,NitDoc,ND.RazonSocial AS NomNitDoc,TipDocRef,DocRef,IdCiaRef,CdCuentaNiif
,C.TimeSys AS FechaAdd,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,VrDivisa1,VrDivisa2,VrDivisa3,TC.IdDiario AS CdDiario,Diario
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_Comprobantes AS C INNER JOIN Trn_ComDetalle AS D ON C.TipCom=D.TipCom AND C.Comprobante=D.Comprobante
 AND C.IdCia=D.IdCia  INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN  Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN CtasCorrientes AS CTE ON C.IdCta=CTE.IdCta INNER JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero
 INNER JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NIO ON D.NitOtros=NIO.IdTercero
 LEFT JOIN Terceros AS ND ON D.NitDoc=ND.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN Localidades AS LD ON D.CiuOrigen=LD.IdLocal
 LEFT JOIN SubGrupos AS SG ON  D.CodSubgpo=SG.IdSubgrupo
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND C.TipDoc LIKE ISNULL(@pmTipDoc,'%')  AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND (C.EsEgreso=ISNULL(@pmEsEgreso,0) or C.EsEgreso=ISNULL(@pmEsEgreso,1))
 AND (C.Integrado=ISNULL(@pmIntegrado,0) or C.Integrado=ISNULL(@pmIntegrado,1))
 ORDER BY  C.TipCom,C.IdCia,C.Comprobante,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleMud]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComDetalleMud] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT D.TipCom,TipoCom,D.Comprobante,D.IdCia AS CdCia,Compania,D.Item,D.Fecha,D.IdCuenta AS CdCuenta,NomCuenta,D.Detalle,D.VrDebito,D.VrCredito
,D.IdTercero AS NitTercero,T.RazonSocial,D.IdVehiculo,D.IdCCosto,CCosto,D.IdSubCos,SubCosto,D.VehPropio,D.VrBase,D.TarifaBase,D.TipDoc,TipoDoc,D.Documento,D.IdCiaDoc
,CodConce,Concepto,D.TipFac,D.Factura,D.IdCiaFac,D.ItemFac,D.FecVence,D.CodCta,D.NumCheque,D.Integrado,D.TipoAplica,D.Consolida,D.CodCargo,D.NitOtros,NT.RazonSocial AS NomTercOtros
,D.CodSubgpo,D.CiuOrigen,LD.Localidad AS NomCiudad,D.CodAgncia,D.Referncia,D.NitDoc,ND.RazonSocial AS NomTercDoc,D.TipDocRef,D.DocRef,D.IdCiaRef,D.CdConcTrib,D.CdTarifTrib
,D.NumEstablec,D.PtoEmision,D.Num_Autoriza,D.FechAutoriza,D.CdCuentaNiif,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaAct,D.IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
,P.Movimiento,P.Tercero,P.Vehiculo
 FROM Trn_ComDetalle AS D INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 LEFT JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Sys_TiposDoc AS TD ON D.TipDoc=TD.IdDoc LEFT JOIN Conceptos AS CN ON D.CodConce=CN.IdConcepto
 LEFT JOIN Localidades AS LD ON D.CiuOrigen=LD.IdLocal LEFT JOIN Terceros AS ND ON D.NitDoc=ND.IdTercero
 LEFT JOIN Terceros AS NT ON D.NitOtros=NT.IdTercero
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND (SUBSTRING(D.IdCuenta,1,1)='5' OR SUBSTRING(D.IdCuenta,1,1)='6' OR SUBSTRING(D.IdCuenta,1,1)='2')
 AND (@pmIdCia IS NULL OR D.IdCia=@pmIdCia)
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleNitCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleNitCc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmCodAgncia VARCHAR(16)=Null,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null
,@pmIdCueIni VARCHAR(16)=Null,@pmIdCueFin VARCHAR(16)=Null
 AS 
 IF @pmIdCueIni IS NULL
  SELECT D.IdCuenta AS CdCuenta,IdTercero,IdCCosto,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Tercero<>0 AND CentroCosto<>0  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,IdTercero,IdCCosto,TipCom,IdCia
ELSE
  SELECT D.IdCuenta AS CdCuenta,IdTercero,IdCCosto,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Tercero<>0  AND CentroCosto<>0 AND  D.IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin
   AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,IdTercero,IdCCosto,TipCom,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleNitSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleNitSub] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmCodAgncia VARCHAR(16)=Null,@pmTipCom VARCHAR(3)=Null,@pmIntegrado BIT=Null
,@pmIdCueIni VARCHAR(16)=Null,@pmIdCueFin VARCHAR(16)=Null
 AS 
 IF @pmIdCueIni IS NULL
  SELECT D.IdCuenta AS CdCuenta,IdTercero,IdCCosto,IdSubCos,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Tercero<>0 AND CentroCosto<>0 AND SubCentro<>0
   AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,IdTercero,IdCCosto,IdSubCos,TipCom,IdCia
ELSE
  SELECT D.IdCuenta AS CdCuenta,IdTercero,IdCCosto,IdSubCos,TipCom,IdCia,SUM(VrDebito) AS STOTDEB,SUM(VrCredito) AS STOTCRE 
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta 
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Tercero<>0  AND CentroCosto<>0  AND  SubCentro<>0
  AND  D.IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin
   AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
  AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%')
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 GROUP BY D.IdCuenta,IdTercero,IdCCosto,IdSubCos,TipCom,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleRet] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCuenta VARCHAR(16)=Null
,@pmIdCueIni VARCHAR(16)=Null,@pmIdCueFin VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmTipCom VARCHAR(3)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null,@pmBaseGravable BIT=Null,@pmTercero BIT=Null,@pmIntegrado BIT=Null
 AS 
 IF @pmIdCueIni IS NULL
  SELECT D.IdCuenta AS CdCuenta,NomCuenta,Tercero,Naturaleza,BaseGravable,Porcntaje,D.IdTercero AS NitTercero,RazonSocial,TipoId,Dv,D.IdCia AS CdCia,Compania
,ISNULL(SA.SaldoAnterior,0) AS Saldo_Anterior,SUM(VrDebito-VrCredito) AS ValorTotal,SUM(VrBase) AS TotalBase,MAX(TarifaBase) AS TarifBase,SUM(VrDebito) AS TotalDeb,SUM(VrCredito) AS TotalCre
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta  INNER JOIN Terceros  AS T ON D.IdTercero=T.IdTercero  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
  LEFT JOIN (SELECT IdCuenta,IdTercero,IdCia,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS SaldoAnterior FROM AcuCuentasNit 
  WHERE  nAnno=YEAR(DATEADD (Month ,-1, @pmFechaIni))  AND nMes=MONTH(DATEADD (Month ,-1, @pmFechaIni))
   AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')   AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
 GROUP BY IdCuenta,IdTercero,IdCia) AS SA ON D.IdCia=SA.IdCia AND D.IdCuenta=SA.IdCuenta AND D.IdTercero=SA.IdTercero
  WHERE Movimiento<>0 AND Fecha  BETWEEN  @pmFechaIni AND @pmFechaFin AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND (BaseGravable=ISNULL(@pmBaseGravable,0) or BaseGravable=ISNULL(@pmBaseGravable,1))
  AND (Tercero=ISNULL(@pmTercero,0) or Tercero=ISNULL(@pmTercero,1))
  AND (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
  GROUP BY D.IdCuenta,NomCuenta,Tercero,Naturaleza,BaseGravable,Porcntaje,D.IdTercero,RazonSocial,TipoId,Dv,D.IdCia,Compania,SA.SaldoAnterior
 ELSE
  SELECT D.IdCuenta AS CdCuenta,NomCuenta,Tercero,Naturaleza,BaseGravable,Porcntaje,D.IdTercero AS NitTercero,RazonSocial,TipoId,Dv,D.IdCia AS CdCia,Compania
 ,ISNULL(SA.SaldoAnterior,0) AS Saldo_Anterior,SUM(VrDebito-VrCredito) AS ValorTotal,SUM(VrBase) AS TotalBase,MAX(TarifaBase) AS TarifBase,SUM(VrDebito) AS TotalDeb,SUM(VrCredito) AS TotalCre
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta   INNER JOIN Terceros  AS T ON D.IdTercero=T.IdTercero   INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
  LEFT JOIN (SELECT IdCuenta,IdTercero,IdCia,SUM(SaldoAnterior+TotalDebitos-TotalCreditos) AS SaldoAnterior FROM AcuCuentasNit 
  WHERE  nAnno=YEAR(DATEADD (Month ,-1, @pmFechaIni))  AND nMes=MONTH(DATEADD (Month ,-1, @pmFechaIni))
   AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin  AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
 GROUP BY IdCuenta,IdTercero,IdCia) AS SA ON D.IdCia=SA.IdCia AND D.IdCuenta=SA.IdCuenta AND D.IdTercero=SA.IdTercero
  WHERE Movimiento<>0 AND Fecha  BETWEEN  @pmFechaIni AND @pmFechaFin AND D.IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND (BaseGravable=ISNULL(@pmBaseGravable,0) or BaseGravable=ISNULL(@pmBaseGravable,1))
  AND (Tercero=ISNULL(@pmTercero,0) or Tercero=ISNULL(@pmTercero,1))
  AND (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
  GROUP BY D.IdCuenta,NomCuenta,Tercero,Naturaleza,BaseGravable,Porcntaje,D.IdTercero,RazonSocial,TipoId,Dv,D.IdCia,Compania,SA.SaldoAnterior
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleRetTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleRetTot] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCuenta VARCHAR(16)=Null
,@pmIdCueIni VARCHAR(16)=Null,@pmIdCueFin VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmTipCom VARCHAR(3)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmCodAgncia VARCHAR(16)=Null,@pmBaseGravable BIT=Null,@pmTercero BIT=Null,@pmIntegrado BIT=Null
 AS 
 IF @pmIdCueIni IS NULL
  SELECT SUM(VrDebito-VrCredito) AS ValorTotal,SUM(VrBase) AS TotalBase
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
  WHERE Movimiento<>0 AND Fecha  BETWEEN  @pmFechaIni AND @pmFechaFin AND D.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND  IdTercero LIKE ISNULL(@pmIdTercero,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND (BaseGravable=ISNULL(@pmBaseGravable,0) or BaseGravable=ISNULL(@pmBaseGravable,1))
  AND (Tercero=ISNULL(@pmTercero,0) or Tercero=ISNULL(@pmTercero,1))
  AND (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 ELSE
  SELECT SUM(VrDebito-VrCredito) AS ValorTotal,SUM(VrBase) AS TotalBase
  FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
  WHERE Movimiento<>0 AND Fecha  BETWEEN  @pmFechaIni AND @pmFechaFin AND D.IdCuenta BETWEEN @pmIdCueIni AND @pmIdCueFin
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipCom LIKE ISNULL(@pmTipCom,'%')
  AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
  AND (BaseGravable=ISNULL(@pmBaseGravable,0) or BaseGravable=ISNULL(@pmBaseGravable,1))
  AND (Tercero=ISNULL(@pmTercero,0) or Tercero=ISNULL(@pmTercero,1))
  AND (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComDetalleTot] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
AS
 SELECT SUM(VrDebito) AS TotalDeb,SUM(VrCredito) AS TotalCre,SUM(VrBase) AS TotalBaseGrav
 FROM  Trn_ComDetalle 
 WHERE TipCom=@pmTipCom 
 AND (Comprobante>=ISNULL(@pmComprobante,0)  AND Comprobante<=ISNULL(@pmComprobante,2147483647))
 AND IdCia like ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleVen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComDetalleVen] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,C.IdCuenta AS CodCuenta,Detalle,VrDebito,VrCredito,IdTercero,CodAgncia,IdVehiculo,IdCCosto,IdSubCos,VehPropio,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,Referncia,NitDoc,TipDocRef,DocRef,IdCiaRef,TimeSys,FecUpdate,IdCiaCrea
 FROM Trn_ComDetalle AS C INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia 
 AND  Vencimiento<>0  AND (TipoAplica='A' OR TipoAplica='C' ) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComDetalleVis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComDetalleVis] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,D.IdCuenta AS CodCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,RazonSocial,IdVehiculo,D.IdCCosto AS IdCcsto,CCosto
,D.IdSubCos AS IdSbcosto,SubCosto,VrBase,TarifaBase,TipDoc,Documento,IdCiaDoc,CodConce,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,Integrado
,TipoAplica,Consolida,CodCargo,NitOtros,CodSubgpo,CiuOrigen,CodAgncia,Referncia,NitDoc,TipDocRef,DocRef,IdCiaRef,D.IdUsuario AS IdUsuari,Usuario,TimeSys,D.FecUpdate AS FecUpdte,IdCiaCrea
 FROM Trn_ComDetalle AS D INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 INNER JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComFactura] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmIdProveedor VARCHAR(16),@pmItem INT
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom
,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob,FecProgPago,ObservAprob
 FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia AND IdProveedor=@pmIdProveedor
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFactura_Ent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryComFactura_Ent]  @pmTipFac VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16)=Null,@pmFactura VARCHAR(15)=Null
 AS 
 SELECT TipFac,Factura,C.IdCia AS CdCia,Compania,Item,IdProveedor,RazonSocial,C.IdCuenta AS CdCuenta,NomCuenta,TipDoc,Documento,IdCiaDoc
,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob
 FROM Trn_ComFactura AS C INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero
 INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta INNER JOIN  Companias AS CI ON C.IdCia=CI.IdCia
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin
 AND C.IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia  AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%')
 AND  Factura LIKE ISNULL(@pmFactura,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaAbo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComFacturaAbo] @pmFecActual SMALLDATETIME,@pmIdCuenta VARCHAR(16)=Null,@pmIdProveedor VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null,@pmTipFac VARCHAR(3)=Null,@pmTipDoc VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT C.IdCuenta AS CdCuenta,NomCuenta,C.IdProveedor AS NitProveedor,RazonSocial,C.TipFac AS CdTipoFac,TipoDoc,C.Factura AS NumFactura,C.IdCia AS CdCia,CI.Compania AS NomCompania
,C.Item AS NumVence,VrFactura,VrAbonado,VrFactura-VrAbonado AS ValorSaldo,FecEmision,FecVence,DATEDIFF(day,FecVence,@pmFecActual) AS DiasMora
,C.TipDoc AS CdTipDoc,C.Documento AS NumDoc,C.IdCiaDoc AS CdCiaDoc,C.TipCom AS IdTipComFact,TC.TipoCom AS TipComFact,C.Comprobante AS NumComFact
,C.ItemCom AS ItemComFact,Detalle,Referencia,C.pVehiculo AS PlacaVeh,TipRef,DocRef,IdCiaRef
--Datos de abonos
,EG.TipCom AS CdTipoEgr,TEG.TipoCom AS TipoEgreso,EG.Comprobante AS NumEgreso,EG.IdCia AS CdCiaEgreso,CEG.Compania AS NomCiaEgreso
,EG.Item AS ItemAbono,EG.Fecha AS FecAbono,VrAbono,EG.EsEgreso AS Es_Egreso,DetAbono,EG.ItemCom AS ItemEgreso,EG.pVehiculo AS PlacaVehAbono,TipDev,EG.NumDev AS Num_Dev
--datos del egreso
,VrTotal,CM.IdCta AS CodCta,NumeroCta,CTE.IdBanco AS CodBanco,B.Banco AS NomBanco,EnEfectivo,NumCheque,FecCheque,Beneficiario,CM.Observacion AS ComObserv
--datos del proveedor
,TipoId,Dv,T.Codigo AS CodigoProv,NomCial,SiglaRaz,T.Direccion AS DirProveedor,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDep,Departamento
,Telefono,Fax,e_mail,SitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,BP.Banco AS BancoCuenta,Autoret
 FROM Trn_ComFactura AS C INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero
 INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta INNER JOIN  Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TiposCom AS TC ON C.TipCom=TC.IdCom  LEFT JOIN Sys_TiposDoc AS TD ON C.TipFac=TD.IdDoc
 LEFT JOIN TercProvee AS TP ON C.IdProveedor=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 LEFT JOIN Trn_EgrFactura AS EG ON C.TipFac=EG.TipFac AND C.Factura=EG.Factura AND C.IdCia=EG.IdCiaFac 
 AND C.Item=EG.ItemFac AND C.IdProveedor=EG.IdProveedor
 LEFT JOIN TiposCom AS TEG ON EG.TipCom=TEG.IdCom
 LEFT JOIN  Companias AS CEG ON EG.IdCia=CEG.IdCia
 LEFT JOIN Trn_Comprobantes AS CM ON EG.TipCom=CM.TipCom  AND EG.Comprobante=CM.Comprobante  AND EG.IdCia=CM.IdCia
 LEFT  JOIN CtasCorrientes AS CTE ON CM.IdCta=CTE.IdCta  LEFT JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 WHERE  C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND C.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND C.TipFac LIKE ISNULL(@pmTipFac,'%')
 AND (FecEmision>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecEmision<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY C.IdCuenta,RazonSocial,FecVence
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaCmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComFacturaCmp] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante
,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr
 FROM Trn_ComFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 ORDER BY TipFac,Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDab]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryComFacturaDab]  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15)
 AS 
 SELECT C.Factura AS NumFact,C.Item AS NItem,C.IdProveedor AS NitProvee,C.ItemCom AS ItmComp
,VrFactura,VrAbonado,SUM(VrAbono) AS STOTABO
 FROM Trn_ComFactura AS C LEFT JOIN Trn_EgrFactura AS E ON C.TipFac=E.TipFac AND C.Factura=E.Factura
 AND C.IdCia=E.IdCiaFac AND C.Item=E.ItemFac AND C.IdProveedor=E.IdProveedor
 WHERE C.TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND C.IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND C.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  C.Factura LIKE ISNULL(@pmFactura,'%')
 GROUP BY  C.Factura,C.Item,C.IdProveedor,C.ItemCom,VrFactura,VrAbonado
 ORDER BY  C.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryComFacturaDoc]  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15),@pmItemCom INT
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante
,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob
 FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  Factura LIKE ISNULL(@pmFactura,'%')
 AND (ItemCom>=ISNULL(@pmItemCom,-10)  AND ItemCom<=ISNULL(@pmItemCom,0)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComFacturaDso] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null,@pmTipFac VARCHAR(3)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmIdProveedor VARCHAR(16)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmpVehiculo VARCHAR(10)=Null,@pmTipCom VARCHAR(3)=Null,@pmComprobante INT=Null
AS
 SELECT  TipFac, Factura, IdCia, Item,IdCuenta,IdProveedor,T.RazonSocial AS Proveedor,TipDoc, Documento, IdCiaDoc, FecEmision, FecVence, VrFactura,VrAbonado,VrFactura-VrAbonado AS ValorSaldo
,TipCom, Comprobante, ItemCom, Referencia, Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob,FecProgPago,ObservAprob
 FROM Trn_ComFactura AS V INNER JOIN Terceros AS T ON V.IdProveedor=T.IdTercero
 WHERE V.FecVence BETWEEN @pmFechaIni AND @pmFechaFin AND (VrFactura-VrAbonado)>=@pmSaldo AND IdCia like ISNULL(@pmIdCia,'%%') AND TipFac like ISNULL(@pmTipFac,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND (Comprobante>=ISNULL(@pmComprobante,-1)  AND Comprobante<=ISNULL(@pmComprobante,2147483647)) 
ORDER BY TipFac,Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaDve]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComFacturaDve] @pmIdProveedor VARCHAR(16),@pmTipDoc VARCHAR(3)=Null,@pmDocumento INT=Null,@pmIdCiaDoc CHAR(2)=Null
AS 
 SELECT TipFac,Factura,IdCia,Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado,FecEmision,FecVence,TipDoc,Documento,IdCiaDoc
,Referencia,Detalle,IdProveedor,RazonSocial, F.IdCuenta AS IdCuent,NomCuenta,TipCom,Comprobante, ItemCom,TipRef,DocRef,IdCiaRef,pVehiculo,VehPropio
 FROM  Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 WHERE (IdProveedor=@pmIdProveedor OR (TipFac=@pmTipDoc AND TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc))
 AND VrFactura>VrAbonado 
 ORDER BY FecVence,TipFac,IdCia,Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaGnit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComFacturaGnit] @pmSaldo DECIMAL(14,2),@pmIdProveedor VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmTipDoc VARCHAR(3)=Null,@pmTipFac VARCHAR(3)=Null
,@pmFecEmiIni SMALLDATETIME=Null,@pmFecEmiFin SMALLDATETIME=Null,@pmFecVenceIni SMALLDATETIME=Null,@pmFecVenceFin SMALLDATETIME=Null
AS
SELECT  IdProveedor,RazonSocial,SUM(VrFactura-VrAbonado) AS ValorSaldo,SUM(VrFactura) AS StotalFact,SUM(VrAbonado) AS StotalAbo
 FROM Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero
 WHERE (VrFactura-VrAbonado)>@pmSaldo AND F.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND F.IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND TipFac LIKE ISNULL(@pmTipFac,'%')
 AND (FecEmision>=ISNULL(@pmFecEmiIni,CAST('19100101' AS SMALLDATETIME)) AND FecEmision<=ISNULL(@pmFecEmiFin,CAST('20781230' AS SMALLDATETIME)))
 AND (FecVence>=ISNULL(@pmFecVenceIni,CAST('19100101' AS SMALLDATETIME)) AND FecVence<=ISNULL(@pmFecVenceFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY IdProveedor,RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComFacturaLta] @pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME
,@pmIdCuenta VARCHAR(16)=Null,@pmIdProveedor VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmTipFac VARCHAR(3)=Null,@pmTipDoc VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT C.IdCuenta AS CdCuenta,NomCuenta,C.IdProveedor,RazonSocial,C.TipFac,TipoDoc,C.Factura,C.IdCia AS CdCia,Compania
,Item,VrFactura,VrAbonado,VrFactura-VrAbonado AS ValorSaldo,FecEmision,FecVence,DATEDIFF(day,FecVence,@pmFecActual) AS DiasMora
,C.TipDoc,C.Documento,C.IdCiaDoc,C.TipCom,TipoCom,C.Comprobante,C.ItemCom,CM.Fecha AS FechaComp,Detalle,C.Referencia,C.pVehiculo,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob,FecProgPago,ObservAprob
--datos del proveedor
,TipoId,Dv,T.Codigo AS CodigoProv,NomCial,SiglaRaz,T.Direccion AS DirProveedor,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDep,Departamento
,Telefono,Fax,e_mail,SitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_ComFactura AS C INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero
 INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta INNER JOIN  Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TiposCom AS TC ON C.TipCom=TC.IdCom  LEFT JOIN Sys_TiposDoc AS TD ON C.TipFac=TD.IdDoc
 LEFT JOIN TercProvee AS TP ON C.IdProveedor=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 LEFT JOIN Trn_Comprobantes AS CM ON C.TipCom=CM.TipCom AND C.Comprobante=CM.Comprobante AND C.IdCia=CM.IdCia
 WHERE (VrFactura-VrAbonado)>@pmSaldo AND C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND C.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND C.TipFac LIKE ISNULL(@pmTipFac,'%')
 AND (FecEmision>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecEmision<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY C.IdCuenta,RazonSocial,FecVence
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComFacturaNit] @pmIdProveedor VARCHAR(16),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmTipFac VARCHAR(3)=Null,@pmpVehiculo VARCHAR(10)=Null
 AS 
--**** NO cambiar posición de los primeros 4 campos
 SELECT TipFac,Factura,IdCia,Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado,TipDoc,Documento,IdCiaDoc,TipRef,DocRef,IdCiaRef,FecEmision,FecVence
,F.IdCuenta AS IdCuent,NomCuenta,TipCom,Comprobante,ItemCom,Referencia,Detalle,IdProveedor,RazonSocial,pVehiculo,VehPropio,EstadoApr,MontoAprob
 FROM Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 WHERE VrFactura>VrAbonado AND IdProveedor=@pmIdProveedor AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND TipFac LIKE ISNULL(@pmTipFac,'%') 
 --AND TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
ORDER BY FecVence,TipFac,IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaRef]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryComFacturaRef]  @pmTipFac VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmFactura VARCHAR(15),@pmReferencia VARCHAR(50)
 AS 
 SELECT TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante
,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr
 FROM Trn_ComFactura
 WHERE TipFac=@pmTipFac AND TipDoc=@pmTipFac AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdCiaDoc=@pmIdCia
 AND Referencia=@pmReferencia AND ItemCom=0
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  Factura LIKE ISNULL(@pmFactura,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComFacturaSal] @pmFechaAct SMALLDATETIME,@pmSaldo DECIMAL(14,2),@pmIdProveedor VARCHAR(16)=Null, @pmIdCia CHAR(2)=Null
,@pmIdCuenta VARCHAR(16)=Null,@pmTipDoc VARCHAR(3)=Null,@pmTipFac VARCHAR(3)=Null
AS
SELECT  TipFac, Factura, IdCia, Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado, FecEmision, FecVence,DATEDIFF(day,FecVence,@pmFechaAct) AS DiasMora,TipDoc, Documento, IdCiaDoc 
,IdProveedor,RazonSocial, F.IdCuenta AS IdCuent,NomCuenta,TipCom, Comprobante, ItemCom, Referencia, Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob
 FROM Trn_ComFactura AS F INNER JOIN Terceros AS T ON F.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 WHERE (VrFactura-VrAbonado)>@pmSaldo AND F.IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%' ) AND TipFac LIKE ISNULL(@pmTipFac,'%')
ORDER BY RazonSocial,F.IdCuenta,FecVence,TipFac,IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryComFacturaTnit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComFacturaTnit] @pmIdProveedor VARCHAR(16)
 AS 
 SELECT  COUNT(Documento) AS SCANT,SUM(VrFactura) AS STOTFAC,SUM(VrAbonado) AS STOTABO
 FROM Trn_ComFactura
 WHERE IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paQryCompanias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCompanias] @pmIdCia CHAR(2)
 AS 
 SELECT IdCia,Compania,DirInterface,FechaActual,PeriodoActual,IdCCosto,IdSubCos,IdTercero
,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,TipoEDS,CodPlanta,CodBodega,FecModPrest,AutoIca,FechaAdd,FechaUpdate,Inactivo
 FROM Companias
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCompanias_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCompanias_Cr] @pmInactivo BIT=Null
 AS 
 SELECT IdCia,Compania,DirInterface,FechaActual,PeriodoActual,C.IdCCosto AS CodCcosto,CCosto,C.IdSubCos AS CodSubCosto,SubCosto
,IdTercero,CodSucsal,DireccSuc,TelefSuc,FaxSuc,C.IdLocal AS CodCiu,Localidad,TipoEDS,CodPlanta,CodBodega,FecModPrest,AutoIca
,C.FechaAdd AS Fecha_Add,C.FechaUpdate AS FecUpd,C.Inactivo AS Inactvo
 FROM Companias AS C INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto 
 INNER JOIN  SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal
 WHERE (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCompaniasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompaniasDso]
AS
  SELECT  IdCia, Compania,IdCia+'  '+Compania AS DsCia
  FROM Companias WHERE  Inactivo=0 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCompaniasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCompaniasLta] @pmIdCia CHAR(2)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdCia,Compania,DirInterface,FechaActual,PeriodoActual,Inactivo,IdCCosto,IdSubCos,IdTercero
,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,TipoEDS,CodPlanta,CodBodega,FecModPrest,AutoIca,FechaAdd,FechaUpdate
 FROM Companias
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCaja]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompCaja] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,IdConcepto,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,CdCta,IdTercero,CdAgencia,IdCCosto,IdSubCos,IdCajero
,NumForma,CdBanco,Referencia,NumVehiculo,FacCalidad,SemInicial,SemFinal,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_CompCaja
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCaja_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompCaja_Cr] @pmTipDoc VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS Tip_Doc,TipoDoc,R.Recibo AS NumRecibo,R.IdCia AS CdCia,Compania,R.Fecha AS FechaDoc,R.IdConcepto AS CdConcepto,CN.Concepto AS ConceptoDoc
,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco
,R.IdTercero AS Nit_Tercero,T.RazonSocial AS NomTercero,CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,R.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,R.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto
,IdCajero,UC.Usuario AS NomCajero,NumForma,CdBanco,BR.Banco AS DocBanco,R.Referencia AS DocReferencia,FacCalidad,SemInicial,SemFinal,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,R.FecUpdate AS Fec_Update,IdCiaCrea,R.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario,Leyenda,NumVehiculo
--detalle de cuentas
,Item,D.IdConcepto AS DetCodConcepto,CD.Concepto AS DetConcepto,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,NitTercero,DT.RazonSocial AS DetRazonSocial
,pVehiculo,CdCCosto,DC.CCosto AS DetCentCosto,CdSubCos,DS.SubCosto AS DetSubCentCos,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,NumCheque,TipoAplica
,NitOtros,D.CodAgencia AS DetCodAgencia,DA.Agencia AS DetAgencia,Referncia,D.TipDocRef,D.DocRef,D.IdCiaRef,D.DocSop,D.TipSop,D.NumSoporte,D.IdCiaSop,D.TipoImp,D.CodTarImp,D.ItemBase
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--agencia
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DAG.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_CompCaja AS R INNER JOIN Trn_CompCajaDet AS D ON R.TipDoc=D.TipDoc AND R.Recibo=D.Recibo AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON R.IdCajero=UC.IdUsuario INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto 
 INNER JOIN Conceptos AS CN ON R.IdConcepto=CN.IdConcepto INNER JOIN Terceros AS T ON R.IdTercero =T.IdTercero
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN CtasCorrientes AS CTA ON R.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Agencias  AS A ON R.CdAgencia=A.IdAgencia LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos
 LEFT JOIN Bancos AS BR ON R.CdBanco=BR.IdBanco  LEFT JOIN TiposCom AS TCM ON R.TipCom=TCM.IdCom
 LEFT JOIN Terceros AS DT ON D.NitTercero=DT.IdTercero  LEFT JOIN CentroCosto AS DC ON D.CdCCosto=DC.IdCCosto 
 LEFT JOIN SubCentros AS DS ON D.CdSubCos=DS.IdSubCos LEFT JOIN Agencias AS DA ON D.CodAgencia=DA.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN Departamentos AS DAG ON LA.IdDep=DAG.IdDep
 WHERE R.TipDoc=@pmTipDoc AND R.Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND R.IdCia=@pmIdCia
 ORDER BY R.Recibo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaBus]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCompCajaBus] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT Recibo,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CdConcepto,Concepto,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,NumVehiculo
,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,B.Banco AS CtaBanco,C.IdTercero AS NitTercero,RazonSocial,CdAgencia,C.IdCCosto AS CdCcosto,CCosto,C.IdSubCos AS CdSubCosto,IdCajero,UC.Usuario AS NomCajero
,NumForma,CdBanco,BC.Banco AS NomBanco,Referencia,FacCalidad,SemInicial,SemFinal,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ
,C.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDoc
 FROM Trn_CompCaja AS C INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero  INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto
 LEFT JOIN CtasCorrientes AS CTA ON C.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Bancos AS BC ON C.CdBanco=BC.IdBanco
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND C.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY C.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaBusDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompCajaBusDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdUsuario VARCHAR(11)=Null
,@pmCdCta VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT R.TipDoc AS Tip_Doc,R.Recibo AS NumRecibo,R.IdCia AS CdCia,Compania,R.Fecha AS FechaDoc,R.IdConcepto AS CdConcepto,CN.Concepto AS ConceptoDoc
,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco,NumVehiculo
,R.IdTercero AS Nit_Tercero,T.RazonSocial AS NomTercero,CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,R.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,R.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto
,IdCajero,UC.Usuario AS NomCajero,NumForma,CdBanco,BR.Banco AS DocBanco,R.Referencia AS DocReferencia,OrigenAdd,TipCom,Comprobante,IdCiaCom,FacCalidad,SemInicial,SemFinal
,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,R.FecUpdate AS Fec_Update,IdCiaCrea,R.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario
--detalle de cuentas
,Item,D.IdConcepto AS DetCodConcepto,CD.Concepto AS DetConcepto,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,NitTercero,DT.RazonSocial AS DetRazonSocial
,pVehiculo,CdCCosto,DC.CCosto AS DetCentCosto,CdSubCos,DS.SubCosto AS DetSubCentCos,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,NumCheque,TipoAplica
,NitOtros,D.CodAgencia AS DetCodAgencia,DA.Agencia AS DetAgencia,Referncia,TipDocRef,DocRef,IdCiaRef
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_CompCaja AS R INNER JOIN Trn_CompCajaDet AS D ON R.TipDoc=D.TipDoc AND R.Recibo=D.Recibo AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON R.IdCajero=UC.IdUsuario  INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto 
 INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto  INNER JOIN Terceros AS T ON R.IdTercero =T.IdTercero
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto  INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  CtasCorrientes AS CTA ON R.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Agencias  AS A ON R.CdAgencia=A.IdAgencia LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos
 LEFT JOIN Bancos AS BR ON R.CdBanco=BR.IdBanco  
 LEFT JOIN Terceros AS DT ON D.NitTercero=DT.IdTercero  LEFT JOIN CentroCosto AS DC ON D.CdCCosto=DC.IdCCosto 
 LEFT JOIN SubCentros AS DS ON D.CdSubCos=DS.IdSubCos LEFT JOIN Agencias AS DA ON D.CodAgencia=DA.IdAgencia
 WHERE R.TipDoc=@pmTipDoc AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND R.Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND CdCta LIKE ISNULL(@pmCdCta,'%')  AND R.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')  AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND R.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY R.IdCia,R.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaBusPag]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCompCajaBusPag] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdUsuario VARCHAR(11)=Null
,@pmIdForma VARCHAR(4)=Null
 AS 
 SELECT Recibo,C.IdCia AS CdCia,Compania,C.Fecha AS FechaRec,C.IdConcepto AS CdConcepto,Concepto,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo
,C.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,C.IdCCosto AS CdCcosto,CCosto,C.IdSubCos AS CdSubCosto,IdCajero,UC.Usuario AS NomCajero,NumVehiculo
,Referencia,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,FacCalidad,SemInicial,SemFinal
,C.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalles pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS CodBanco,B.Banco AS NomBanco,NitCliente,TP.RazonSocial AS PagNomTercero
,P.NumForma AS NumCheque,FecForma,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,LF.Localidad AS CiudadPlaza,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
,P.CdCta AS CtaCod,NumeroCta,CTA.IdBanco AS CtaIdBanco,BC.Banco AS CtaBanco
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
 FROM Trn_CompCaja AS C INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero  INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto 
 INNER JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND  C.Recibo=P.Documento AND  C.IdCia=P.IdCia
 INNER JOIN Bancos AS B ON P.IdBanco=B.IdBanco   INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma
 LEFT JOIN CtasCorrientes AS CTA ON P.CdCta=CTA.IdCta LEFT JOIN Bancos AS BC ON CTA.IdBanco=BC.IdBanco
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Terceros AS TP ON P.NitCliente=TP.IdTercero
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
  WHERE C.TipDoc=@pmTipDoc AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND C.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND P.IdForma LIKE ISNULL(@pmIdForma,'%')
 ORDER BY C.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompCajaDet] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Recibo,IdCia,Item,IdConcepto,IdCuenta,Detalle,VrDebito,VrCredito,NitTercero,pVehiculo,CdCCosto,CdSubCos
,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumCheque,TipoAplica,NitOtros,CodAgencia,Referncia,TipDocRef,DocRef,IdCiaRef
,DocSop,TipSop,NumSoporte,IdCiaSop,TipoImp,CodTarImp,ItemBase,ConcAsociado
 FROM Trn_CompCajaDet
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompCajaLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Recibo,IdCia,Fecha,C.IdConcepto AS CdConcepto,Concepto,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,CdCta,C.IdTercero AS NitTercero,RazonSocial,CdAgencia,IdCCosto,IdSubCos
,IdCajero,UC.Usuario AS NomCajero,NumForma,CdBanco,Referencia,FacCalidad,SemInicial,SemFinal,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDoc,NumVehiculo
 FROM Trn_CompCaja AS C INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryCompCajaRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompCajaRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmCdCta VARCHAR(4)=Null,@pmEnEfectivo BIT=Null,@pmIdTercero VARCHAR(16)=Null,@pmCdAgencia VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmAnulado BIT=Null
 AS 
 SELECT R.TipDoc AS Tip_Doc,R.Recibo AS NumRecibo,R.IdCia AS CdCia,Compania,R.Fecha AS FechaDoc,R.IdConcepto AS CdConcepto,CN.Concepto AS ConceptoDoc
,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,EnEfectivo,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco
,R.IdTercero AS Nit_Tercero,T.RazonSocial AS NomTercero,CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,R.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,R.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto
,IdCajero,UC.Usuario AS NomCajero,NumForma,CdBanco,BR.Banco AS DocBanco,R.Referencia AS DocReferencia,FacCalidad,SemInicial,SemFinal,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,R.FecUpdate AS Fec_Update,IdCiaCrea,R.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario
--detalle de cuentas
,Item,D.IdConcepto AS DetCodConcepto,CD.Concepto AS DetConcepto,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,NitTercero,DT.RazonSocial AS DetRazonSocial
,pVehiculo,CdCCosto,DC.CCosto AS DetCentCosto,CdSubCos,DS.SubCosto AS DetSubCentCos,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,NumCheque,TipoAplica
,NitOtros,D.CodAgencia AS DetCodAgencia,DA.Agencia AS DetAgencia,Referncia,D.TipDocRef,D.DocRef,D.IdCiaRef,D.DocSop,D.TipSop,D.NumSoporte,D.IdCiaSop,D.TipoImp,D.CodTarImp,D.ItemBase
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--agencia
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DAG.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,NumVehiculo
 FROM Trn_CompCaja AS R INNER JOIN Trn_CompCajaDet AS D ON R.TipDoc=D.TipDoc AND R.Recibo=D.Recibo AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON R.IdCajero=UC.IdUsuario  INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto 
 INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto  INNER JOIN Terceros AS T ON R.IdTercero =T.IdTercero
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto  INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  CtasCorrientes AS CTA ON R.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Agencias  AS A ON R.CdAgencia=A.IdAgencia LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos
 LEFT JOIN Bancos AS BR ON R.CdBanco=BR.IdBanco  
 LEFT JOIN Terceros AS DT ON D.NitTercero=DT.IdTercero  LEFT JOIN CentroCosto AS DC ON D.CdCCosto=DC.IdCCosto 
 LEFT JOIN SubCentros AS DS ON D.CdSubCos=DS.IdSubCos LEFT JOIN Agencias AS DA ON D.CodAgencia=DA.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN Departamentos AS DAG ON LA.IdDep=DAG.IdDep
 WHERE R.TipDoc=@pmTipDoc AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND CdCta LIKE ISNULL(@pmCdCta,'%')  AND R.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%')  AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY R.IdCia,R.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryCompGastos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompGastos] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,IdPlantilla,IdTercero,TipFact,Factura,FecFactura,FecVence,VrTotal
,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_CompGastos
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCompGastosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCompGastosLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdPlantilla VARCHAR(4)=Null
 AS 
 SELECT TipCom,TipoCom,Comprobante,C.IdCia AS CdCia,Compania,Fecha,C.IdPlantilla AS CdPlantilla,DescPlantilla,C.IdTercero AS NitTercero,RazonSocial,TipFact,Factura,FecFactura,FecVence,VrTotal
,Anulado,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
 FROM Trn_CompGastos AS C  INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Plantillas AS PL ON C.IdPlantilla=PL.IdPlantilla
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND C.IdPlantilla LIKE ISNULL(@pmIdPlantilla,'%') 
 ORDER BY  TipCom,C.IdCia,Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComprobantes] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr
,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,Observacion
,IdEstado,Propddes,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,NiifTipo,NiifNumero,FisTipo,FisNumero
,DocSoporte,CodRes,DescServicio
 FROM Trn_Comprobantes
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantes_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantes_Cr] @pmTipCom VARCHAR(3),@pmComprobanteIni INT,@pmComprobanteFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipCom AS IdTipoComp,TipoCom,C.Comprobante AS NumComprob,C.IdCia AS CdCia,Compania,C.Fecha AS FechaComp
,C.IdTercero AS ComNitTercero,T.RazonSocial AS ComNomTercero,VrTotal,C.IdCta AS IdCtaCte,NumeroCta,CTA.IdBanco AS CdBanco,Banco
,EnEfectivo,C.NumCheque AS ComNumCheque,FecCheque,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,C.VehPropio AS VehEsPropio
,CedCondtor,CD.RazonSocial AS NomConductor,C.CodConce AS CodConcepto,CN.Concepto,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3
,PermEditar,C.Integrado AS EsIntegracion,C.EsEgreso AS ComEsEgreso,Anticipo,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,C.DocSoporte,C.CodRes,C.DescServicio
,Propddes,C.TimeSys AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut
--detalle
,Item,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,IdVehiculo,D.VehPropio AS DetVehPropio
,D.IdCCosto AS CdCentCosto,CCosto,D.IdSubCos AS CdSubCentro,SubCosto,VrBase,TarifaBase,D.TipDoc AS TipoDoc,D.Documento AS NumDoc,D.IdCiaDoc AS CdCiaDoc
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,D.NumCheque AS DetNumCheque,TipoAplica,Consolida,CodCargo
,NitOtros,DO.RazonSocial AS NombreOtros,CodSubgpo,Subgrupo,CiuOrigen,DL.Localidad AS NomCiudadOrigen,CodAgncia,DA.Agencia AS NomAgencia,CodAgencia,Referencia
,Referncia,NitDoc,DND.RazonSocial AS NombreNitDoc,TipDocRef,DocRef,IdCiaRef,CdConcTrib,TB.Concepto AS DescConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza
--informacion del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,RS.Resolucion,RS.Prefijo,RS.NumInicial,RS.NumFinal,RS.FechaExpRes,RS.FechaVigencia,RS.Establecimiento
 FROM Trn_Comprobantes  AS C INNER JOIN Trn_ComDetalle AS D ON C.TipCom=D.TipCom AND C.Comprobante=D.Comprobante AND C.IdCia=D.IdCia
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero  LEFT JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 LEFT JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Terceros AS CD ON C.CedCondtor=CD.IdTercero LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS DO ON D.NitOtros=DO.IdTercero
 LEFT JOIN SubGrupos AS S ON D.CodSubgpo=S.IdSubgrupo
 LEFT JOIN Localidades AS DL ON D.CiuOrigen=DL.IdLocal
 LEFT JOIN Agencias AS DA ON D.CodAgncia=DA.IdAgencia
 LEFT JOIN Terceros AS DND ON D.NitDoc=DND.IdTercero LEFT JOIN ConceptosTrib AS TB ON D.CdConcTrib=TB.IdConcepto
 LEFT JOIN TiposComRes AS RS ON C.CodRes=RS.IdRes
 WHERE C.Comprobante BETWEEN @pmComprobanteIni AND @pmComprobanteFin AND C.IdCia=@pmIdCia
 AND  C.TipCom LIKE ISNULL(@pmTipCom,'%') 
 ORDER BY C.Comprobante,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComprobantesCaj] @pmFecha SMALLDATETIME,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
 AS 
 SELECT  TipCom,IdCia,IdUsuario,SUM(VrTotal) AS STOTAL
 FROM Trn_Comprobantes
 WHERE Fecha=@pmFecha AND EsEgreso=1 AND EnEfectivo=1 AND TipDoc<>'DVA' AND TipDoc<>'DAO'
 AND TipDoc<>'DAE' AND TipDoc<>'ANE'
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND  IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 GROUP BY TipCom,IdCia,IdUsuario 
 UNION ALL
 SELECT 'DEG',IdCia,IdUsuario,SUM(VrTotal) AS STOTAL
 FROM Trn_Comprobantes
 WHERE Fecha=@pmFecha AND EsEgreso=1 AND EnEfectivo=1 AND TipDoc IN ('DVA','DAO') AND Integrado=1
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 GROUP BY IdCia,IdUsuario 
 ORDER BY IdCia,IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesChe]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantesChe] @pmNumCheque VARCHAR(20),@pmIdCta VARCHAR(4), @pmIdCia CHAR(2), @pmTipCom VARCHAR(3),@pmEsEgreso BIT
AS
 SELECT TipCom, Comprobante, IdCia, Fecha, IdCta, EnEfectivo, NumCheque,FecCheque,EsEgreso
 FROM  Trn_Comprobantes 
 WHERE NumCheque=@pmNumCheque AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCta LIKE ISNULL(@pmIdCta,'%')
 AND TipCom LIKE ISNULL(@pmTipCom,'%')  AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 ORDER BY  TipCom,IdCia,Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesChx]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantesChx] @pmNumCheque VARCHAR(20),@pmIdCta VARCHAR(4), @pmIdCia CHAR(2),@pmEsEgreso BIT
--CONSULTA : SI EXISTE EL CHEQUE EN LA CUENTA
AS
 SELECT TipCom, Comprobante, IdCia, Fecha, IdCta, EnEfectivo, NumCheque,EsEgreso
 FROM  Trn_Comprobantes  
 WHERE EnEfectivo=0 AND Anulado=0 AND NumCheque=@pmNumCheque AND IdCta=@pmIdCta AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 ORDER BY  TipCom,IdCia,Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComprobantesDoc]  @pmTipDoc VARCHAR(3), @pmDocumento INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr
,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,Observacion,IdEstado
,Propddes,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,NiifTipo,NiifNumero,FisTipo,FisNumero
,DocSoporte,CodRes,DescServicio 
 FROM Trn_Comprobantes
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento  AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY  TipCom,IdCia, Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComprobantesDso] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME, @pmTipCom VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmAnulado BIT=Null,@pmIntegrado BIT=Null,@pmEsEgreso BIT=Null,@pmAnticipo BIT=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT TipCom,Comprobante,C.IdCia AS CodCia,Compania,Fecha,C.IdTercero AS NitTercero,RazonSocial,VrTotal,C.IdCta AS CodCta,NumeroCta,Tipo_Pago,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr
,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,C.Observacion AS Observ,C.IdEstado AS IdEstad,Estado
,NiifTipo,NiifNumero,FisTipo,FisNumero,Propddes,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,CdSustento,Establec,PEmision,Autorizac,FechaAut,DocSoporte,CodRes,DescServicio
 FROM Trn_Comprobantes AS C INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipCom LIKE ISNULL(@pmTipCom,'%') AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND  (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1)) 
AND (Anticipo=ISNULL(@pmAnticipo,0) or Anticipo=ISNULL(@pmAnticipo,1)) 
 ORDER BY TipCom,C.IdCia,Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesEgo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComprobantesEgo] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null
 AS 
 SELECT C.TipCom AS CdTipEgr,TipoCom,C.Comprobante AS NumEgreso,C.IdCia AS CdCiaEgr,Compania,C.Fecha AS FecEgreso,T.TipoId AS TercTipo,C.IdTercero AS NitTercero,T.Dv AS TercDv
,T.RazonSocial AS NomTercero,C.VrTotal,C.IdCta AS CdCtaCte,NumeroCta,CTA.IdBanco AS CdBanco,Banco,C.EnEfectivo,C.NumCheque AS NoCheque,C.FecCheque
,C.TipDoc,C.Documento,C.IdCiaDoc,C.Anulado,C.NumDev,C.FecDev,C.pVehiculo,C.VehPropio AS VehEsPropio,C.CedCondtor,CD.RazonSocial AS NomConductor,C.Beneficiario,C.Anticipo,C.Observacion AS Observ
,OP.TipDoc AS TipOdp,OP.OrdPago,OP.IdCia AS CiaOdp,OP.TipMuc,OP.Manifiesto,OP.IdCiaMuc
 FROM Trn_Comprobantes AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 LEFT JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Terceros AS CD ON C.CedCondtor=CD.IdTercero 
 LEFT JOIN (SELECT TipDoc,OrdPago,IdCia,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo FROM Trn_TraOrdenManif
 UNION ALL SELECT TipDoc,Liquidacion,IdCia,TipOds,NumOrden,IdCiaOds,IdVehiculo FROM Trn_TraOrdenLiq) AS OP ON C.TipDoc=OP.TipDoc AND C.Documento=OP.OrdPago AND C.IdCiaDoc=OP.IdCia
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.EsEgreso=1 
 AND (C.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (C.IdTercero=@pmIdTercero OR @pmIdTercero IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesEgr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantesEgr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCta VARCHAR(4)=Null
,@pmFecEgrIni SMALLDATETIME=Null,@pmFecEgrFin SMALLDATETIME=Null
 AS 
 SELECT TipCom,Comprobante,C.IdCia AS CdCia,Compania,Fecha,NumCheque,FecCheque,VrTotal,C.IdCta AS CodCta,NumeroCta
,CTE.IdBanco AS CodBanco,Banco,C.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,Beneficiario,pVehiculo
,C.CedCondtor AS NitOtros,CT.RazonSocial AS NomNitOtros,C.EsEgreso AS EsCompEgreso,Anticipo,C.Observacion AS Observ
,TipDoc,Documento,IdCiaDoc,C.IdEstado AS CdEstado,Propddes,TimeSys,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario
,TipoCom,TC.IdDiario AS CdDiario,Diario
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_Comprobantes AS C INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN CtasCorrientes AS CTE ON C.IdCta=CTE.IdCta INNER JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS CT ON C.CedCondtor=CT.IdTercero
 WHERE  ((FecCheque BETWEEN @pmFechaIni AND @pmFechaFin) OR FecCheque IS NULL) 
 AND (C.EsEgreso<>0 OR Anticipo<>0)  AND EnEfectivo=0  AND Anulado=0
 AND TipCom LIKE ISNULL(@pmTipCom,'%') AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND C.IdCta LIKE ISNULL(@pmIdCta,'%')
 AND (Fecha>=ISNULL(@pmFecEgrIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFecEgrFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Fecha,TipCom,C.IdCia,Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantesLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmTipDoc VARCHAR(3)=Null,@pmEsEgreso BIT=Null,@pmIntegrado BIT=Null
 AS 
 SELECT TipCom,TipoCom,Comprobante,C.IdCia AS CdCia,Compania,Fecha,C.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrTotal,C.IdCta AS CodCta,NumeroCta
,CTE.IdBanco AS CodBanco,Banco,EnEfectivo,NumCheque,FecCheque,TipDoc,TipoDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,VehPropio
,C.CedCondtor AS NitOtros,CT.RazonSocial AS NomNitOtros,CodConce,Concepto,Beneficiario,Integrado,C.EsEgreso AS EsCompEgreso,Anticipo
,NiifTipo,NiifNumero,FisTipo,FisNumero,C.Observacion AS Observ,C.IdEstado AS CodEstado,Estado,Propddes
,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,DocSoporte,CodRes,DescServicio
,VrDivisa1,VrDivisa2,VrDivisa3,TC.IdDiario AS CdDiario,Diario
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,TCA.NitAutoriza,NC.RazonSocial AS NomAutorizado
 FROM Trn_Comprobantes AS C INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN CtasCorrientes AS CTE ON C.IdCta=CTE.IdCta INNER JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS CT ON C.CedCondtor=CT.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN (SELECT IdTercero,NumCuenta,MAX(NitTercAut) AS NitAutoriza FROM TercCuentas GROUP BY IdTercero,NumCuenta) AS TCA ON C.IdTercero=TCA.IdTercero AND C.Establec=TCA.NumCuenta
 LEFT JOIN Terceros AS NC ON TCA.NitAutoriza=NC.IdTercero
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipCom LIKE ISNULL(@pmTipCom,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%') 
 AND (C.EsEgreso=ISNULL(@pmEsEgreso,0) or C.EsEgreso=ISNULL(@pmEsEgreso,1))
 AND (Integrado=ISNULL(@pmIntegrado,0) or Integrado=ISNULL(@pmIntegrado,1))
 ORDER BY  TipCom,C.IdCia,Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesNit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantesNit] @pmTipCom VARCHAR(3),@pmComprobanteIni INT,@pmComprobanteFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipCom AS CdTipComp,C.Comprobante AS NumComp,C.IdCia AS CdCia
,D.IdCuenta AS CdCuenta,NomCuenta,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,SUM(VrCredito) AS TotalCre
 FROM Trn_Comprobantes  AS C INNER JOIN Trn_ComDetalle AS D ON C.TipCom=D.TipCom AND C.Comprobante=D.Comprobante AND C.IdCia=D.IdCia
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta  LEFT JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero 
 WHERE C.TipCom=@pmTipCom AND C.Comprobante BETWEEN @pmComprobanteIni AND @pmComprobanteFin AND C.IdCia=@pmIdCia
 AND VrCredito>0
 GROUP BY  C.TipCom,C.Comprobante,C.IdCia,D.IdCuenta,NomCuenta,D.IdTercero,DT.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryComprobantesNom]  @pmTipDoc VARCHAR(3), @pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4)
,@pmNEgreso INT=Null,@pmIdTercero VARCHAR(16)=Null
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,Integrado
 FROM Trn_Comprobantes
 WHERE Anulado=0 AND  Propddes='NOMINA'  AND TipDoc=@pmTipDoc AND Documento=@pmDocumento 
 AND CodConce=@pmCodConce AND NEgreso<=@pmNEgreso AND IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND  IdCiaDoc LIKE ISNULL(@pmIdCiaDoc,'%%')
 ORDER BY  TipCom,IdCia, Comprobante
GO
/****** Object:  StoredProcedure [dbo].[paQryComprobantesTotCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryComprobantesTotCaj] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT  TipCom,SUM(CASE EnEfectivo WHEN 1 THEN VrTotal ELSE 0 END)  AS  STOTCAJA
,SUM(CASE EnEfectivo WHEN 0 THEN  VrTotal ELSE 0 END)  AS  STOTOTROS
 FROM Trn_Comprobantes
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsEgreso=1 AND Anticipo=0
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND  IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 GROUP BY TipCom
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDivCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDivCue] @pmIdConcepto VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdConcepto,IdClase,IdCuenta,CdCueDev,TipoMov,TipoTerc,FecAdd,FecUpdate
 FROM ConcDivCue
 WHERE IdConcepto=@pmIdConcepto
 AND IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDivCueLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDivCueLta] @pmIdConcepto VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null
,@pmGrupo VARCHAR(20)=Null,@pmEsServicio BIT=Null
 AS 
 SELECT D.IdConcepto AS CdConcepto,Concepto,D.IdClase AS CdClase,NomClase,D.IdCuenta AS IdCue,P.NomCuenta AS NombreCue
,CdCueDev,PD.NomCuenta AS NomCueDev,TipoMov,TipoTerc,Grupo,EsServicio,DeManfsto,FecAdd,FecUpdate
 FROM ConcDivCue AS D INNER JOIN  ConcDiversos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta INNER JOIN ClaseDiv AS CD ON D.IdClase=CD.IdClase
 LEFT JOIN Puc AS PD ON D.CdCueDev=PD.IdCuenta
 WHERE C.Inactivo=0 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND D.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND Grupo LIKE ISNULL(@pmGrupo,'%')
 AND (EsServicio=ISNULL(@pmEsServicio,0) or EsServicio=ISNULL(@pmEsServicio,1))
 ORDER BY D.IdConcepto,D.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConcDiversos] @pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,Grupo,EsServicio,DeManfsto,CdIva,CdRet,CdIca,IdCueDeb,IdCueCre,Inactivo
,CdAutoret,OrdenServ,NovedadNom,CdConcDeveng,CdConcDed,RubroConc,MudReajuste,CodFEDian,TipoConcGat,FechaAdd,FechaUpdate,IdUsuario
 FROM ConcDiversos
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDiversosDso] @pmGrupo VARCHAR(20)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT C.IdConcepto,Concepto,Grupo,Concepto+' '+C.IdConcepto+' ('+Grupo+')' AS DsCon
 FROM ConcDiversos AS C LEFT JOIN ConcDivCia AS CN ON C.IdConcepto=CN.IdConcepto
 WHERE C.Inactivo=0 AND C.Grupo LIKE ISNULL(@pmGrupo,'%')
 AND (CN.IdCia=@pmIdCia OR CN.IdCia IS NULL)
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDiversosFac] @pmIdCia CHAR(2) 
 AS 
 SELECT C.IdConcepto,Concepto,Grupo,Concepto+' '+C.IdConcepto AS DsCon
 FROM ConcDiversos AS C LEFT JOIN ConcDivCia AS CN ON C.IdConcepto=CN.IdConcepto
 WHERE C.Grupo='FACTURA' AND C.Inactivo=0 AND (CN.IdCia=@pmIdCia OR CN.IdCia IS NULL)
 ORDER BY C.Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosGas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDiversosGas] @pmIdCia CHAR(2) 
 AS 
 SELECT C.IdConcepto,Concepto,Grupo,Concepto+' '+C.IdConcepto AS DsCon
 FROM ConcDiversos AS C LEFT JOIN ConcDivCia AS CN ON C.IdConcepto=CN.IdConcepto
 WHERE C.Grupo IN ('GASTOS','OTROS') AND C.Inactivo=0
 AND (CN.IdCia=@pmIdCia OR CN.IdCia IS NULL)
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConcDiversosLta] @pmGrupo VARCHAR(20)=Null,@pmEsServicio BIT=Null
 AS 
 SELECT IdConcepto,Concepto,Grupo,EsServicio,DeManfsto,CdIva,TI.Tarifa AS TarfIva,CdRet
,TR.Tarifa AS TarfRet,CdIca,TC.Tarifa AS TarfIca,CdAutoret,IdCueDeb,PD.NomCuenta AS NomCueDeb,IdCueCre,PC.NomCuenta AS NomCueCre
,D.Inactivo AS Inactvo,OrdenServ,NovedadNom,CdConcDeveng,CdConcDed,RubroConc,MudReajuste,CodFEDian,TipoConcGat
,D.IdUsuario AS IdUsuari,Usuario,D.FechaAdd AS Fech_Add,D.FechaUpdate AS Fech_Update
 FROM ConcDiversos AS D INNER JOIN  adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 LEFT JOIN  Tablapor AS TI ON D.CdIva=TI.IdTarifa
 LEFT JOIN  Tablapor AS TR ON D.CdRet=TR.IdTarifa
 LEFT JOIN  Tablapor AS TC ON D.CdIca=TC.IdTarifa
 LEFT JOIN Puc AS PD ON D.IdCueDeb=PD.IdCuenta
 LEFT JOIN Puc AS PC ON D.IdCueCre=PC.IdCuenta
 WHERE Grupo LIKE ISNULL(@pmGrupo,'%')
 AND  (EsServicio=ISNULL(@pmEsServicio,0) or EsServicio=ISNULL(@pmEsServicio,1))
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDiversosNov] 
 AS 
 SELECT IdConcepto,Concepto,Grupo,Concepto+' '+IdConcepto AS DsCon
 FROM ConcDiversos 
 WHERE Grupo IN ('FACTURA','OTROS') AND Inactivo=0
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConcDiversosOsm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConcDiversosOsm] @pmIdCia CHAR(2) 
 AS 
 SELECT C.IdConcepto,Concepto,Grupo,Concepto+' '+C.IdConcepto AS DsCon
 FROM ConcDiversos AS C LEFT JOIN ConcDivCia AS CN ON C.IdConcepto=CN.IdConcepto
 WHERE C.Grupo='FACTURA' AND C.EsServicio=1 AND C.OrdenServ=3 AND C.Inactivo=0 
 AND (CN.IdCia=@pmIdCia OR CN.IdCia IS NULL)
 ORDER BY C.Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptos] @pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,IdDoc,IdCom,Vcmto,Imptos,Retfte,RetIca,Observacion,Pdterminado
,TrfaSanc,RndTotal,Inactivo,DcmtoEquiv,TipoContab,CdComNiif,CdComFiscal,CodCiaTdo,TipoConRev
,FechaAdd,FechaUpdate,IdUsuario
 FROM Conceptos
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosAdmon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosAdmon] @pmIdConcepto VARCHAR(4)
,@pmIdAdmon VARCHAR(4),@pmIdClase INT
 AS 
 SELECT IdConcepto,IdAdmon,IdClase,IdCuenta,FechaAdd,FechaUpdate
 FROM ConceptosAdmon
 WHERE IdConcepto=@pmIdConcepto AND IdAdmon=@pmIdAdmon 
 AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosAdmonLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConceptosAdmonLta] @pmIdConcepto VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null,@pmIdDoc VARCHAR(3)=Null
 AS
 SELECT A.IdAdmon AS IdAdm,TipoAdmon,A.IdCuenta AS IdCuent,NomCuenta,A.IdConcepto AS IdConcept,Concepto
,IdClase,IdDoc,A.FechaAdd AS FechAdd,A.FechaUpdate AS FechUpdate
 FROM ConceptosAdmon AS A INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN TiposAdm AS TA ON A.IdAdmon=TA.IdAdmon
 INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND  A.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
  AND IdDoc LIKE ISNULL(@pmIdDoc,'%')
 ORDER BY A.IdConcepto,A.IdAdmon,IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosCia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConceptosCia] @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT C.IdConcepto,Concepto,Concepto+' '+C.IdConcepto+ '  ('+ IdDoc+')' AS DsCon
 FROM Conceptos AS C LEFT JOIN ConceptosCia AS CN ON C.IdConcepto=CN.IdConcepto
 WHERE Inactivo=0 AND IdDoc=@pmIdDoc AND (CN.IdCia=@pmIdCia OR CN.IdCia IS NULL)
 ORDER BY IdDoc,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosCue] @pmIdConcepto VARCHAR(4),@pmIdClase INT
 AS 
 SELECT IdConcepto,IdClase,Descripcion,IdCuenta,TipoMov,DetalleMov,CdCCosto,CdSubCos,TipoTerc,FecAdd,FecUpdate
 FROM ConceptosCue
 WHERE IdConcepto=@pmIdConcepto
 AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosCueLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosCueLta] @pmIdConcepto VARCHAR(4)=Null,@pmIdDoc VARCHAR(3)=Null
,@pmInactivo BIT=Null
 AS 
 SELECT CC.IdConcepto AS CdConcep,Concepto,IdClase,Descripcion,CC.IdCuenta AS CdCuenta,NomCuenta,TipoMov,DetalleMov,CdCCosto,CdSubCos
,C.IdDoc AS CdTipo,TipoDoc,C.IdCom AS CdComp,TipoCom,TipoTerc,CC.FecAdd,CC.FecUpdate,CT.CCosto,SC.SubCosto
 FROM ConceptosCue AS CC INNER JOIN Conceptos AS C ON CC.IdConcepto=C.IdConcepto
 INNER JOIN Puc AS P ON CC.IdCuenta=P.IdCuenta
 INNER JOIN  Sys_TiposDoc AS T ON C.IdDoc=T.IdDoc
 INNER JOIN TiposCom AS TC ON C.IdCom=TC.IdCom
 LEFT JOIN CentroCosto AS CT ON CC.CdCCosto=CT.IdCCosto LEFT JOIN SubCentros AS SC ON CC.CdSubCos=SC.IdSubCos
 WHERE CC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND C.IdDoc LIKE ISNULL(@pmIdDoc,'%')
 AND  (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY CC.IdConcepto,IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConceptosDso] @pmIdDoc VARCHAR(3)=Null
 AS 
 SELECT IdConcepto,Concepto,Pdterminado,Concepto+' '+IdConcepto+ '  ('+ IdDoc+')' AS DsCon
 FROM Conceptos
 WHERE Inactivo=0 AND IdDoc LIKE ISNULL(@pmIdDoc,'%')
 ORDER BY IdDoc,Concepto

SET ANSI_NULLS ON
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosLta] @pmIdDoc VARCHAR(3)=Null,@pmIdCom VARCHAR(3)=Null,@pmPdterminado INT=Null
,@pmInactivo  BIT=Null
 AS 
 SELECT IdConcepto,Concepto,C.IdDoc AS CdTipo,TipoDoc,C.IdCom AS CdTcmp,TipoCom,Vcmto,Imptos,Retfte,RetIca,Observacion,Pdterminado
,TrfaSanc,RndTotal,DcmtoEquiv,TipoContab,CdComNiif,CdComFiscal,CodCiaTdo,TipoConRev
,C.FechaAdd AS Fec_Add,C.FechaUpdate AS Fec_Upd,C.IdUsuario AS IdUsuari,Usuario,C.Inactivo AS Inactiv
 FROM Conceptos AS C INNER JOIN Sys_TiposDoc AS T ON C.IdDoc=T.IdDoc
 INNER JOIN TiposCom AS TC ON C.IdCom=TC.IdCom
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE C.IdDoc LIKE ISNULL(@pmIdDoc,'%') AND C.IdCom LIKE ISNULL(@pmIdCom,'%')
 AND (Pdterminado>=ISNULL(@pmPdterminado,-1)  AND Pdterminado<=ISNULL(@pmPdterminado,2147483647))
 AND  (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY C.IdDoc,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosTrib]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosTrib] @pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,CodigoConc,IdClase,CdTarifa,Inactivo
 FROM ConceptosTrib WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosTribDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosTribDso] @pmIdClase VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,Concepto+' '+CodigoConc AS DsCon
 FROM ConceptosTrib
 WHERE IdClase LIKE ISNULL(@pmIdClase,'%') AND Inactivo=0
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryConceptosTribLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosTribLta] @pmIdClase VARCHAR(4)=Null
 AS 
 SELECT IdConcepto,Concepto,CodigoConc,C.IdClase AS CdClase,NomClase,CdTarifa,Tarifa 
 FROM ConceptosTrib AS C INNER JOIN ClaseTar AS CL ON C.IdClase=CL.IdClase
 LEFT JOIN Tablapor AS T ON C.CdTarifa=T.IdTarifa
 WHERE C.IdClase LIKE ISNULL(@pmIdClase,'%') AND C.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryConsigna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConsigna] @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Consignacion,IdCia,Fecha,IdConcepto,VrEfectivo,VrOtros,VrTotal,EnEfectivo,IdCta,IdCuenta,IdCliente,IdCCosto,IdSubCos,IdCajero,NitDeptante,Depositante
,TelDeptante,Referencia,Referncia2,NumConsigna,RangosDoc,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FecConsig,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Consigna
 WHERE TipDoc=@pmTipDoc AND Consignacion=@pmConsignacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryConsigna_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConsigna_Cr] @pmTipDoc VARCHAR(3),@pmConsignacionIni INT,@pmConsignacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS Tip_Doc,TipoDoc,Consignacion,C.IdCia AS CodCia,Compania,C.Fecha AS FechaDoc,C.IdConcepto AS CdConcepto,Concepto,VrEfectivo,VrOtros,VrTotal,EnEfectivo
,C.IdCta AS CdCta,NumeroCta,CT.IdBanco AS CdBanco,B.Banco AS BancoCta,B.IdClase AS CdBanClase,B.CodEntidad AS BanCodigo,B.Direccion AS BanDireccion,B.Contacto AS BanContacto
,C.IdCuenta AS CdCuenta,NomCuenta,IdCliente,T.RazonSocial AS RaznSocial,C.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,C.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS NomCajero
,NitDeptante,Depositante,TelDeptante,C.Referencia AS CnsReferencia,C.Referncia2 AS CnsReferencia2,NumConsigna,RangosDoc,FecConsig,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,C.FecUpdate AS Fec_Update,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--detalle de pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco,NitCliente,PC.RazonSocial AS NomCliente,CdAgencia,A.Agencia AS NomAgencia
,CodAgencia,A.Referencia AS AgeReferencia,NumForma,FecForma,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS PagReferencia2,CdLocal,LF.Localidad AS CiudadPlaza,LF.IdDep AS CdDptoPlaza,DF.Departamento AS DptoPlaza
,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 FROM Trn_Consigna AS C  INNER JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND C.Consignacion=P.Documento AND C.IdCia=P.IdCia
 INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN CtasCorrientes AS CT ON C.IdCta=CT.IdCta INNER JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero INNER JOIN Puc AS PU ON C.IdCuenta=PU.IdCuenta
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos  LEFT JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep 
 LEFT JOIN Terceros AS PC ON P.NitCliente=PC.IdTercero  LEFT JOIN Agencias  AS A ON P.CdAgencia=A.IdAgencia
 WHERE C.TipDoc=@pmTipDoc AND Consignacion BETWEEN @pmConsignacionIni AND @pmConsignacionFin AND C.IdCia=@pmIdCia
 ORDER BY Consignacion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryConsignaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConsignaLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmConsignacionIni INT=Null
,@pmConsignacionFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdCta VARCHAR(4)=Null,@pmEnEfectivo BIT=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Consignacion,IdCia,Fecha,C.IdConcepto AS CdConcepto,Concepto,VrEfectivo,VrOtros,VrTotal,EnEfectivo,C.IdCta AS CdCta,NumeroCta,CT.IdBanco AS CdBanco,Banco,C.IdCuenta AS CdCuenta,IdCliente,RazonSocial
,IdCCosto,IdSubCos,IdCajero,UC.Usuario AS NomCajero,NitDeptante,Depositante,TelDeptante,Referencia,Referncia2,NumConsigna,RangosDoc,FecConsig,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_Consigna AS C INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN CtasCorrientes AS CT ON C.IdCta=CT.IdCta INNER JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Consignacion BETWEEN ISNULL(@pmConsignacionIni,0) AND ISNULL(@pmConsignacionFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdCta LIKE ISNULL(@pmIdCta,'%') AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY IdCia,Consignacion
GO
/****** Object:  StoredProcedure [dbo].[paQryConsignaRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConsignaRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCta VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
,@pmIdCliente VARCHAR(16)=Null,@pmAnulado BIT=Null
 AS 
 SELECT C.TipDoc AS Tip_Doc,Consignacion,C.IdCia AS CodCia,Compania,C.Fecha AS FechaDoc,C.IdConcepto AS CdConcepto,Concepto,VrEfectivo,VrOtros,VrTotal,EnEfectivo
,C.IdCta AS CdCta,NumeroCta,CT.IdBanco AS CdBanco,B.Banco AS BancoCta,B.IdClase AS CdBanClase,B.CodEntidad AS BanCodigo,B.Direccion AS BanDireccion,B.Contacto AS BanContacto
,C.IdCuenta AS CdCuenta,NomCuenta,IdCliente,T.RazonSocial AS RaznSocial,C.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,C.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS NomCajero
,NitDeptante,Depositante,TelDeptante,C.Referencia AS CnsReferencia,C.Referncia2 AS CnsReferencia2,NumConsigna,RangosDoc,FecConsig,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,C.FecUpdate AS Fec_Update,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalle de pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco,NitCliente,PC.RazonSocial AS NomCliente,CdAgencia,A.Agencia AS NomAgencia
,CodAgencia,A.Referencia AS AgeReferencia,NumForma,FecForma,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS PagReferencia2,CdLocal,LF.Localidad AS CiudadPlaza,LF.IdDep AS CdDptoPlaza,DF.Departamento AS DptoPlaza
,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 FROM Trn_Consigna AS C  INNER JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND C.Consignacion=P.Documento AND C.IdCia=P.IdCia
 INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  
 INNER JOIN CtasCorrientes AS CT ON C.IdCta=CT.IdCta INNER JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero INNER JOIN Puc AS PU ON C.IdCuenta=PU.IdCuenta
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos 
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep 
 LEFT JOIN Terceros AS PC ON P.NitCliente=PC.IdTercero  LEFT JOIN Agencias  AS A ON P.CdAgencia=A.IdAgencia
 WHERE C.TipDoc=@pmTipDoc  AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdCta LIKE ISNULL(@pmIdCta,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY C.IdCia,Consignacion
GO
/****** Object:  StoredProcedure [dbo].[paQryCorrResiduos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCorrResiduos] @pmIdCorr VARCHAR(8)
 AS 
 IF @pmIdCorr IS NULL
  BEGIN
   SELECT IdCorr,GrupoRP,CodigoCR,CorrResiduo,Inactivo
   FROM CorrResiduos
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdCorr,GrupoRP,CodigoCR,CorrResiduo,Inactivo
   FROM CorrResiduos
   WHERE IdCorr=@pmIdCorr
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCotizacion] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Cotizacion,IdCia,Fecha,FechaVence,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,VrImpuBA,VrImpuCUP,IdVend,TarifaCom
,CodTarCom,DirContacto,IdLocal,DiasVigencia,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,TipFac,Factura,IdCiaFac,FechaFact
,Modalidad,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,NumAprob,FecAprob,CdUsuAprob,NumPedido,CdCiaPed,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Cotizacion
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacion_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCotizacion_Cr] @pmTipDoc VARCHAR(3),@pmCotizacionIni INT,@pmCotizacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc AS Tip_Doc,TipoDoc,O.Cotizacion AS NumCotizacion,O.IdCia AS CdCia,Compania,O.Fecha AS FechaDoc,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NombreCliente
,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,O.VrNeto,O.Cantidad,O.VrImpuBA,O.VrImpuCUP
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirContacto,O.IdLocal AS CdCiudEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DiasVigencia,O.NitContac AS CotNitContac,O.NomContac AS CotNomContac,O.TelContac AS CotTelContac,O.emlContac AS CotEmailContac,CargoContac,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago
,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact,Modalidad,NumAprob,FecAprob,CdUsuAprob,NumPedido,CdCiaPed,OrigenAdd,Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,O.TimeSys AS Fec_Add,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--Detalles
,K.Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarRemision,K.IdCiaRem AS CdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev
,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,K.ListaPrec AS KarLtaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5,ImagenBin,NomArchivo
 FROM Trn_Cotizacion AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Cotizacion=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN (SELECT IdProducto,ImagenBin,NomArchivo FROM ProdImagenes WHERE IdImagen=1) AS IMG ON K.IdProducto=IMG.IdProducto
 WHERE O.TipDoc=@pmTipDoc AND O.Cotizacion BETWEEN @pmCotizacionIni AND @pmCotizacionFin AND O.IdCia=@pmIdCia
 ORDER BY O.Cotizacion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCotizacionDet]  @pmCotizacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,K.IdProducto AS CdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,Salidas,VrPrecio,Salidas*VrPrecio AS VrSubTotal
,TarifaDct,VrDctoSal,TarifaIva,VrIvaSal,((Salidas*VrPrecio)-VrDctoSal)+VrIvaSal AS VrTotal,VrBruto,K.ListaPrec AS LtaPrec,VrBase,K.Referencia AS Referncia,Referencia2,Unidades
,CodTarDct,CodTarIva,K.IdVend AS NitVend,V.RazonSocial AS Vendedor,Comision,K.CodTarCom AS CdTarifCom,DescripProd,Servcios,Tanques,CdTanque,CdMoneda,VrTasaCamb
,C.Fecha AS FecPedido,FechaVence,IdCliente,T.RazonSocial AS Cliente,IdAgencia,Modalidad,C.Factura AS NumFactura,IdCiaFac,FechaFact,CantObseq,VrIvaObseq,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
 FROM Trn_Cotizacion AS C INNER JOIN Trn_Kardex AS K ON C.TipDoc=K.TipDoc AND C.Cotizacion=K.Documento AND C.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Terceros AS  V ON K.IdVend=V.IdTercero
 WHERE C.Cotizacion=@pmCotizacion  AND C.IdCia=@pmIdCia
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCotizacionFac] @pmFactura INT,@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT Cotizacion,IdCia,Fecha,FechaVence,C.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros
,VrOtrDcto,VrNeto,Cantidad,C.VrImpuBA,C.VrImpuCUP,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirContacto,C.IdLocal AS CdCiudad,DiasVigencia,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma
,DetallePago,MulPlazos,IdPlazo,CdMney,Modalidad,NumPedido,CdCiaPed,C.Observacion AS Observ,TimeSys,IdCiaCrea
 FROM Trn_Cotizacion AS C INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Factura<=@pmFactura
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,Cotizacion
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionFact]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCotizacionFact] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmCotizacionIni INT=Null,@pmCotizacionFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaFacIni SMALLDATETIME=Null,@pmFechaFacFin SMALLDATETIME=Null
,@pmTipoVentaIni INT=Null,@pmTipoVentaFin INT=Null
 AS 
 SELECT  O.Cotizacion AS NumCotizacion,O.IdCia AS CdCia,Compania,O.Fecha AS FechaCotiza,FechaVence,K.IdProducto AS CodProducto,DescripProd
,SUM(Salidas) AS CantPedido,SUM(Unidades) AS Unidades
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,Unidad,IdCliente,T.RazonSocial AS NombreCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Modalidad,O.IdConcepto AS CdConcepto,Concepto
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,VrFletes,DiasVigencia,NitContac,NomContac,NumAprob,FecAprob
,O.Observacion AS Observ,DetallePago,O.IdEstado AS CdEstado,Estado
,MAX(VrPrecio) AS CotValorUnit,SUM(Salidas*VrPrecio) AS CotValorTotal,SUM(VrIvaSal) AS CotIva,SUM(VrDctoSal) AS CotDcto
 FROM Trn_Cotizacion AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia 
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Cotizacion=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
  LEFT JOIN (SELECT  Cotizacion,IdCiaCot,K.TipDoc AS TipoFact,K.Documento AS NumFactura,K.IdCia AS CdCiaFac,KC.Compania AS NomCiaFac
  ,TipOrd,NumOrden,IdCiaOrd,K.Fecha AS FecFactura,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd
,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaEnt) AS IvaEntradas
,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoEnt) AS DctoEntradas,SUM(VrDctoSal) AS DctoSalidas,SUM(K.Unidades) AS TotalUnidades
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE NoVentas BETWEEN ISNULL(@pmTipoVentaIni,1) AND ISNULL(@pmTipoVentaFin,4) AND Cotizacion>0
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaFacIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFacFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY  Cotizacion,IdCiaCot,K.TipDoc,K.Documento,K.IdCia,KC.Compania,TipOrd,NumOrden,IdCiaOrd,K.Fecha,K.IdProducto,PM.DescripProd) AS FA 
 ON  O.Cotizacion=FA.Cotizacion AND O.IdCia=FA.IdCiaCot AND K.IdProducto=FA.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND O.Cotizacion  BETWEEN ISNULL(@pmCotizacionIni,0) AND ISNULL(@pmCotizacionFin,2147483647)
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
GROUP BY  O.Cotizacion,O.IdCia,Compania,O.Fecha,FechaVence,K.IdProducto,DescripProd
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,Modalidad,O.IdConcepto,Concepto
,O.IdVend,VN.RazonSocial,VrFletes,DiasVigencia,NitContac,NomContac,NumAprob,FecAprob
,O.Observacion,DetallePago,O.IdEstado,Estado
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCotizacionLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmCotizacionIni INT=Null,@pmCotizacionFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Cotizacion,IdCia,Fecha,FechaVence,C.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,C.VrImpuBA,C.VrImpuCUP
,VrOtrDcto,C.VrNeto,C.Cantidad,C.IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirContacto,C.IdLocal AS CdCiudad,DiasVigencia,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma
,DetallePago,MulPlazos,IdPlazo,CdMney,TipFac,Factura,IdCiaFac,FechaFact,Modalidad,NumAprob,FecAprob,CdUsuAprob,NumPedido,CdCiaPed,OrigenAdd,Anulado,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado
,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Cotizacion AS C INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Cotizacion BETWEEN ISNULL(@pmCotizacionIni,0) AND ISNULL(@pmCotizacionFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Cotizacion
GO
/****** Object:  StoredProcedure [dbo].[paQryCotizacionRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCotizacionRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Cotizacion,O.IdCia AS CdCia,Compania,Fecha,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NombreCliente
,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,O.VrNeto,O.Cantidad,O.VrImpuBA,O.VrImpuCUP
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirContacto,O.IdLocal AS CdCiudEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DiasVigencia,O.NitContac AS CotNitContac,O.NomContac AS CotNomContac,O.TelContac AS CotTelContac,O.emlContac AS CotEmailContac,CargoContac,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago
,TipFac,Factura,IdCiaFac,FechaFact,NumPedido,CdCiaPed,Modalidad,NumAprob,FecAprob,CdUsuAprob,OrigenAdd,Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,TimeSys,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_Cotizacion AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,O.Cotizacion
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientes]    Script Date: 10/12/2025 8:11:24 ******/
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
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesDsa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryCtasCorrientesDsa] @pmIdBanco VARCHAR(4)=Null
AS
  SELECT  IdCta,NumeroCta,IdCta+ ' ' +NumeroCta+' ' + Banco AS DsCta,C.IdBanco AS CodBanco,Banco
  FROM   CtasCorrientes AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
  WHERE C.Inactivo=0  AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
  ORDER BY  IdCta
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCtasCorrientesDso] @pmIdBanco VARCHAR(4),@pmIdCiaDef CHAR(2)=Null
AS
  SELECT  C.IdCta,NumeroCta,C.IdCta+ ' ' +NumeroCta+' ' + Banco AS DsCta,C.IdBanco AS CodBanco,Banco
  FROM   CtasCorrientes AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
  LEFT JOIN CtasCorrCia AS CN ON C.IdCta=CN.IdCta
  WHERE C.Inactivo=0   AND (CN.IdCia=@pmIdCiaDef OR CN.IdCia IS NULL)
  AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
  ORDER BY  C.IdCta
GO
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesLta]    Script Date: 10/12/2025 8:11:24 ******/
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
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesNum]    Script Date: 10/12/2025 8:11:24 ******/
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
/****** Object:  StoredProcedure [dbo].[paQryCtasCorrientesPuc]    Script Date: 10/12/2025 8:11:24 ******/
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
/****** Object:  StoredProcedure [dbo].[paQryDepartamentos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDepartamentos] @pmIdDep VARCHAR(8)
 AS 
 IF @pmIdDep IS NULL
  SELECT IdDep,Departamento,Codigo,IdPais  FROM Departamentos
  WHERE Inactivo=0
  ORDER BY Departamento
 ELSE
  SELECT IdDep,Departamento,Codigo,IdPais,Inactivo
  FROM Departamentos
  WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paQryDependencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDependencias] @pmIdDep VARCHAR(4)
 AS 
 SELECT IdDep,Dependencia,JefeDep,IdArea,IdSubCos,TipRiesgo,Inactivo
 FROM Dependencias
 WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paQryDependenciasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDependenciasLta] @pmIdArea VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdDep,Dependencia,D.IdArea AS CodArea,Area,D.IdSubCos AS IdSubcc,SubCosto,JefeDep,D.Inactivo AS Inactvo
 FROM Dependencias AS D INNER JOIN Areas AS A ON D.IdArea=A.IdArea INNER JOIN SubCentros AS S ON D.IdSubCos=S.IdSubCos
 WHERE D.IdArea LIKE ISNULL(@pmIdArea,'%') 
 AND (D.Inactivo=ISNULL(@pmInactivo,0) or D.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Dependencia
GO
/****** Object:  StoredProcedure [dbo].[paQryDesagregaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDesagregaciones] @pmIdDrp VARCHAR(8)
 AS 
 SELECT IdDrp,CodigoDR,Desagregacion,CodigoCR,Inactivo
 FROM Desagregaciones
 WHERE IdDrp=@pmIdDrp
GO
/****** Object:  StoredProcedure [dbo].[paQryDesagregacionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDesagregacionesLta] @pmInactivo BIT=Null
 AS 
 SELECT D.IdDrp,D.CodigoDR,D.Desagregacion,D.CodigoCR AS IdCorrRes,C.GrupoRP,C.CorrResiduo,C.CodigoCR,D.Inactivo
 FROM Desagregaciones AS D INNER JOIN CorrResiduos AS C ON D.CodigoCR=C.IdCorr
 WHERE (D.Inactivo=@pmInactivo OR @pmInactivo IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDespachos] @pmTipDoc VARCHAR(3),@pmCartulina INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Cartulina,IdCia,Fecha,IdRuta,NumOrden,FechaRec,IdVehiculo,IdPropietario,IdConductor,IdConductor1,IdRelevador,VehPropio,CentInicial
,CentFinal,NPasajeros,Recorridos,ValorProducido,ValorGastos,ValorAhorro,ValorOtros,ValorVales,ValorAbono,ValorPasaje,TipoAdmon,IdTipRec
,ReciboCaja,IdCiaRec,NumAutoriza,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Despachos
 WHERE TipDoc=@pmTipDoc AND Cartulina=@pmCartulina AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachos_Cr] @pmTipDoc VARCHAR(3),@pmCartulinaIni INT=Null,@pmCartulinaFin INT=Null
,@pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 SELECT TipDoc,TipoDoc, Cartulina, D.IdCia AS CodCia,Compania, Fecha, D.IdRuta AS CodRuta,Ruta,NumOrden,FechaRec,D.IdVehiculo AS PlacaVeh,D.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario, D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor
 , IdConductor1,NC1.RazonSocial AS Conductor1,IdRelevador,NR.RazonSocial AS Relevador,D.VehPropio AS VehcPropio,D.CentInicial AS CenInicial,D.CentFinal AS CenFinal,NPasajeros, Recorridos, ValorProducido, ValorGastos, ValorAhorro, ValorOtros, ValorVales, ValorAbono, ValorPasaje
 , IdTipRec, ReciboCaja, IdCiaRec, NumAutoriza,Anulado, NumDev, FecDev, D.Observacion AS Observ,D.IdEstado AS IdEstadoDoc,ED.Estado AS EstadDoc, TimeSys,FecUpdate, IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,D.TipoAdmon AS TipoAdmon,Leyenda
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TA.TipoAdmon AS VehTipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,ES.RazonSocial AS VehEmpresaSoat,KmActual,V.CentInicial AS VehCentInicial,V.CentFinal AS VehCentFinal
,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo,RespCivil,VigRCivil,CertGases,VigCertGas,TarjOper,VigTarjOper,CertMovilizacion,VigCertMovil,V.Observacion AS VehObservacion
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,CT.TipoSangre AS CondTipoSangre,CT.FactorRh AS CondRH,CT.FecNacmto AS CondFechNaci,CT.LugarNacmto AS CondLugarNacmto,CT.Sexo AS CondSexo
,CT.CertJudicial AS CondCertJudicial,CT.VigJudicial AS CondVigJudicial,CT.Licencia AS CondLicencia,CT.CatLicencia AS CondCategoria,CT.VigLicencia AS CondVigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
--datos reelevador
,CTR.CertJudicial AS RelvCertJudicial,CTR.VigJudicial AS RelvVigJudicial,CTR.Licencia AS RelvLicencia,CTR.CatLicencia AS RelvCategoria,CTR.VigLicencia AS RelvVigLicencia
  FROM  Trn_Despachos   AS D INNER JOIN Sys_TiposDoc  AS TD ON D.TipDoc=TD.IdDoc   INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
  INNER JOIN Rutas AS R ON D.IdRuta=R.IdRuta  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero
  INNER JOIN Terceros AS NC1 ON D.IdConductor1=NC1.IdTercero
  INNER JOIN Terceros AS NR ON D.IdRelevador=NR.IdTercero  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor 
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN Terceros AS ES ON V.NitEmpSoat=ES.IdTercero 
  LEFT JOIN TercCndtores AS CTR ON D.IdRelevador=CTR.IdConductor 
  WHERE  TipDoc=@pmTipDoc  AND Cartulina BETWEEN ISNULL(@pmCartulinaIni,0) AND ISNULL(@pmCartulinaFin,2147483647)
  AND  D.IdCia like ISNULL(@pmIdCia,'%%')
  AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY D.IdCia,Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachos_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachos_Crr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdRuta VARCHAR(4)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null,@pmTipoAdmon VARCHAR(10)=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmFechaRecIni SMALLDATETIME=Null,@pmFechaRecFin SMALLDATETIME=Null
AS
 SELECT Cartulina, D.IdCia AS CodCia,Compania, Fecha, D.IdRuta AS CodRuta,Ruta, NumOrden,FechaRec,D.IdVehiculo AS PlacaVeh,D.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario, D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor
 , IdConductor1,NC1.RazonSocial AS Conductor1,IdRelevador,NR.RazonSocial AS Relevador,D.VehPropio AS VehcPropio,D.CentInicial AS CenInicial,D.CentFinal AS CenFinal,NPasajeros, Recorridos, ValorProducido, ValorGastos,ValorVales,ValorGastos+ValorVales AS TotalGastos,ValorAhorro,ValorOtros,ValorAbono
,ValorAhorro+ValorOtros+ValorAbono AS TotalLiquida,ValorPasaje , IdTipRec, ReciboCaja, IdCiaRec, NumAutoriza,Anulado, NumDev, FecDev, D.Observacion AS Observ,D.IdEstado AS IdEstadoDoc,ED.Estado AS EstadDoc, TimeSys,FecUpdate, IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,D.TipoAdmon AS TipAdmon,Leyenda,TipDoc,TipoDoc
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TA.TipoAdmon AS VehTipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,V.CentInicial AS VehCentInicial,V.CentFinal AS VehCentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,CT.TipoSangre AS CondTipoSangre,CT.FactorRh AS CondRH,CT.FecNacmto AS CondFechaNcmto,CT.LugarNacmto AS CondLugarNac,CT.Sexo AS CondSexo,CT.CertJudicial AS CondCertJudicial
,CT.VigJudicial AS CondVigCert,CT.Licencia AS CondLicencia,CT.CatLicencia AS CondCategoria,CT.VigLicencia AS CondVigLicencia,CT.IdLugar AS CdLugarLic,ELC.LugarLic AS CondLugarLic
,RT.IdModd AS RelvCdMod,MCR.Modalidad AS ModReelevador,RT.TipoSangre AS RelvTipoSangre,RT.FactorRh AS RelvRh,RT.FecNacmto AS RelvFechaNcmto,RT.LugarNacmto AS RelvLugarNacmto,RT.Sexo AS RelvSexo,RT.CertJudicial AS RelvCertJudic
,RT.VigJudicial AS RelvVigCertJudi,RT.Licencia AS RelvLicencia,RT.CatLicencia AS RelvCategoria,RT.VigLicencia AS RelvVigLicencia,RT.IdLugar AS RelvIdLugar,ELR.LugarLic AS RelvLugarLic
  FROM  Trn_Despachos   AS D INNER JOIN Sys_TiposDoc  AS TD ON D.TipDoc=TD.IdDoc   INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
  INNER JOIN Rutas AS R ON D.IdRuta=R.IdRuta  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero
  INNER JOIN Terceros AS NC1 ON D.IdConductor1=NC1.IdTercero   INNER JOIN Terceros AS NR ON D.IdRelevador=NR.IdTercero  
  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor    INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa    LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN TercCndtores AS RT ON D.IdRelevador=RT.IdConductor   LEFT JOIN ExpLicencias AS ELR ON RT.IdLugar=ELR.IdLugar
  LEFT JOIN TiposMod AS MCR ON RT.IdModd=MCR.IdModd
  WHERE  TipDoc=@pmTipDoc  AND ( Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND  Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
  AND ( FechaRec>=ISNULL(@pmFechaRecIni,CAST('19100101' AS SMALLDATETIME)) AND  FechaRec<=ISNULL(@pmFechaRecFin,CAST('20781230' AS SMALLDATETIME)))
  AND  D.IdCia LIKE ISNULL(@pmIdCia,'%%')   AND D.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND D.TipoAdmon LIKE ISNULL(@pmTipoAdmon,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY D.IdCia,Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosAbi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachosAbi] @pmTipDoc VARCHAR(3),@pmIdVehiculo VARCHAR(10),@pmTipoAdmon VARCHAR(10)
AS
SELECT    TipDoc, Cartulina, IdCia, Fecha, IdRuta, NumOrden,FechaRec, IdVehiculo, IdPropietario, IdConductor
, IdTipRec, ReciboCaja, IdCiaRec,Anulado, NumDev, FecDev, IdEstado
FROM        Trn_Despachos
WHERE  TipDoc=@pmTipDoc  AND IdVehiculo=@pmIdVehiculo AND Anulado=0  
AND TipoAdmon=@pmTipoAdmon  AND IdEstado<>'0002'
ORDER BY IdCia,Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosFre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachosFre] @pmTipDoc VARCHAR(3),@pmIdVehiculo VARCHAR(10), @pmFechaRec SMALLDATETIME
AS
 SELECT    TipDoc, Cartulina, IdCia, Fecha, IdRuta, NumOrden,FechaRec, IdVehiculo, IdConductor,IdTipRec, ReciboCaja, IdCiaRec, Anulado,FecDev,IdEstado,TipoAdmon
 FROM         Trn_Despachos   
 WHERE  TipDoc=@pmTipDoc  AND IdVehiculo=@pmIdVehiculo AND FechaRec=@pmFechaRec AND Anulado=0
 ORDER BY IdCia,Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachosLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmReciboCaja INT,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
,@pmTipoAdmon VARCHAR(10)=Null
AS
SELECT Cartulina, IdCia, Fecha, IdRuta, NumOrden,FechaRec,D.IdVehiculo AS IdVehicul,NumVeh,D.IdPropietario AS IdPropiet,P.RazonSocial AS Propietario,D.IdConductor AS IdCond,C.RazonSocial AS Conductor, IdConductor1, IdRelevador,RV.RazonSocial AS Relevador,D.VehPropio AS VehProp,IdTipRec,ReciboCaja,IdCiaRec 
, D.CentInicial AS CenInicial,D.CentFinal AS CenFinal,NPasajeros, Recorridos,ValorPasaje, ValorProducido, ValorGastos,ValorVales, ValorGastos+ValorVales AS TotalGastos,ValorAhorro, ValorOtros,ValorAbono,ValorAhorro+ ValorOtros+ ValorAbono AS TotalRecibido
,TipoAdmon, Anulado,NumDev,FecDev, D.Observacion AS Observ,D.IdEstado AS IdEstad,Estado,TimeSys,FecUpdate, IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,NumAutoriza
FROM  Trn_Despachos  AS D  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
INNER JOIN Terceros AS P ON D.IdPropietario=P.IdTercero INNER JOIN Terceros AS C ON D.IdConductor=C.IdTercero
INNER JOIN  EstadoDoc AS E ON D.IdEstado=E.IdEstado INNER JOIN Terceros AS RV ON D.IdRelevador=RV.IdTercero
WHERE   Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND ReciboCaja<=@pmReciboCaja AND Anulado=0 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND TipoAdmon LIKE ISNULL(@pmTipoAdmon,'%')
ORDER BY IdCia, Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachosPen] @pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmReciboCaja INT,@pmIdVehiculo VARCHAR(10)=Null,@pmTipoAdmon VARCHAR(10)=Null
AS
SELECT    Cartulina, IdCia, Fecha, IdRuta, NumOrden,FechaRec,D.IdVehiculo AS IdVehicul,NumVeh,D.IdPropietario AS IdPropiet,P.RazonSocial AS Propietario,D.IdConductor AS IdCond,C.RazonSocial AS Conductor, IdConductor1, IdRelevador,D.VehPropio AS VehProp,IdTipRec,ReciboCaja,IdCiaRec 
, D.CentInicial AS CenInicial,D.CentFinal AS CenFinal,NPasajeros, Recorridos,ValorPasaje, ValorProducido,ValorAhorro+ ValorOtros+ ValorAbono AS TotalRecibido,TipoAdmon, Anulado,NumDev,FecDev, D.Observacion AS Observ,D.IdEstado AS IdEstad,Estado,TimeSys,FecUpdate, IdCiaCrea,D.IdUsuario AS IdUsuari,NumAutoriza
FROM   Trn_Despachos  AS D  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
                 INNER JOIN Terceros AS P ON D.IdPropietario=P.IdTercero  INNER  JOIN Terceros AS C ON D.IdConductor=C.IdTercero
                 INNER  JOIN  EstadoDoc AS E ON D.IdEstado=E.IdEstado
WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia=@pmIdCia AND ReciboCaja<=@pmReciboCaja AND Anulado=0
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND TipoAdmon LIKE ISNULL(@pmTipoAdmon,'%')
ORDER BY Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDespachosVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDespachosVeh] @pmTipDoc VARCHAR(3),@pmIdVehiculo VARCHAR(10),@pmReciboCaja INT

AS
 SELECT    TipDoc, Cartulina, IdCia, Fecha, IdRuta, NumOrden,FechaRec, IdVehiculo, IdPropietario, IdConductor, IdTipRec, ReciboCaja, IdCiaRec,Anulado, NumDev, FecDev, IdEstado,TimeSys
 FROM        Trn_Despachos
 WHERE  TipDoc=@pmTipDoc  AND IdVehiculo=@pmIdVehiculo AND Anulado=0  AND ReciboCaja<=@pmReciboCaja
 ORDER BY FechaRec,TimeSys,IdCia,Cartulina
GO
/****** Object:  StoredProcedure [dbo].[paQryDetCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDetCuentas] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmConcepto VARCHAR(10),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac
,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
 FROM Trn_DetCuentas
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND (Concepto=@pmConcepto OR @pmConcepto IS NULL)
 AND (Item>=ISNULL(@pmItem,0) AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDetCuentas_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDetCuentas_Cr] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2),@pmConcepto VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Documento,D.IdCia AS CdCia,Compania,Concepto,Item,D.IdCuenta AS CdCuenta,NomCuenta,Valor,Detalle,D.IdTercero AS NitTercero,RazonSocial,D.CodAgncia AS IdAgncia,A.Agencia AS NomAgencia,CodAgencia
,CdCCosto,CCosto,CdSubCos,SubCosto,pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Localidad,D.Referencia AS Referncia,VrTarifa,TipoTarif,CodConc,CodTarif
 FROM Trn_DetCuentas AS D  INNER JOIN Companias AS C ON D.IdCia=C.IdCia
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN CentroCosto AS O ON D.CdCCosto=O.IdCCosto
 LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN Agencias AS A ON D.CodAgncia=A.IdAgencia
 LEFT JOIN Localidades AS L ON D.CiuOrigen=L.IdLocal
 WHERE TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND D.IdCia=@pmIdCia 
 AND Concepto LIKE ISNULL(@pmConcepto,'%')
 ORDER BY Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDetCuentasRci]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDetCuentasRci] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
AS 
SELECT D.TipDoc,D.Documento,D.IdCia AS CdCia,D.Concepto,D.IdCuenta,NomCuenta,D.VrBase,D.VrTarifa AS Tarifa,D.TipoTarif
,D.Valor,D.CodTarif,T.CdLocdad,L.Localidad,L.IdDep,DP.Departamento
FROM Trn_DetCuentas AS D INNER JOIN (SELECT TipDoc,Recibo,IdCia,Fecha,IdCliente,VrNeto FROM Trn_Recibos WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
UNION ALL SELECT TipDev,Devolucion,IdCia,Fecha,IdCliente,VrNeto FROM Trn_DevRec WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin) AS R ON D.TipDoc=R.TipDoc AND D.Documento=R.Recibo AND D.IdCia=R.IdCia
LEFT JOIN Tablapor AS T ON D.CodTarif=T.IdTarifa LEFT JOIN Localidades AS L ON T.CdLocdad=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
WHERE D.TipDoc IN ('REC','ODB') AND D.Concepto='ICA' AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (R.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevCaj] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito
,IdTercero,IdAgencia,IdCCosto,IdSubCos,IdCajero,EnEfectivo,CdCta,NumForma,CdBanco,Referencia,NumAutoriza,ModdDev,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,NumVehiculo
 FROM Trn_DevCaj
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCaj_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCaj_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,CN.Concepto AS DevConcepto
,DV.TipDoc AS TipRec,DV.Recibo AS NumRecibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,DV.IdTercero AS DevNitTercero,T.RazonSocial AS DevNomTercero
,DV.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,DV.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto
,DV.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS UsuCajero,EnEfectivo
,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco,NumForma,CdBanco,BR.Banco AS DocBanco
,DV.Referencia AS DevReferencia,NumAutoriza,ModdDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,DV.Observacion AS Observ
,DV.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,DV.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda,NumVehiculo
--detalles de cuentas
,Item,D.IdConcepto AS DetCodConcepto,CD.Concepto AS DetConcepto,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,NitTercero,DT.RazonSocial AS DetRazonSocial
,pVehiculo,CdCCosto,DC.CCosto AS DetCentCosto,CdSubCos,DS.SubCosto AS DetSubCentCos,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,NumCheque,TipoAplica
,NitOtros,D.CodAgencia AS DetCodAgencia,DA.Agencia AS DetAgencia,Referncia,TipDocRef,DocRef,IdCiaRef
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--agencia
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DAG.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_DevCaj AS DV INNER JOIN Trn_CompCajaDet AS D ON DV.TipDoc=D.TipDoc AND DV.Recibo=D.Recibo AND DV.IdCiaDoc=D.IdCia
 INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON DV.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON DV.IdCajero=UC.IdUsuario  INNER JOIN CentroCosto AS CC ON DV.IdCCosto=CC.IdCCosto 
 INNER JOIN  Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto  INNER JOIN Terceros AS T ON DV.IdTercero =T.IdTercero
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto  INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  CtasCorrientes AS CTA ON DV.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Agencias  AS A ON DV.IdAgencia=A.IdAgencia LEFT JOIN SubCentros AS SC ON DV.IdSubCos=SC.IdSubCos
 LEFT JOIN Bancos AS BR ON DV.CdBanco=BR.IdBanco   LEFT JOIN TiposCom AS TCM ON DV.TipCom=TCM.IdCom
 LEFT JOIN Terceros AS DT ON D.NitTercero=DT.IdTercero  LEFT JOIN CentroCosto AS DC ON D.CdCCosto=DC.IdCCosto 
 LEFT JOIN SubCentros AS DS ON D.CdSubCos=DS.IdSubCos LEFT JOIN Agencias AS DA ON D.CodAgencia=DA.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN Departamentos AS DAG ON LA.IdDep=DAG.IdDep
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
 ORDER BY  Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajBus]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevCajBus] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Recibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,D.IdTercero AS NitTercero,RazonSocial
,IdAgencia,D.IdCCosto AS CdCCosto,CCosto,D.IdSubCos AS CdSubCentro,IdCajero,UC.Usuario AS UsuCajero,EnEfectivo,NumForma,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,B.Banco AS CtaBanco,NumVehiculo
,CdBanco,BC.Banco AS NomBanco,Referencia,NumAutoriza,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev
 FROM Trn_DevCaj AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario  INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 LEFT JOIN CtasCorrientes AS CTA ON D.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Bancos AS BC ON D.CdBanco=BC.IdBanco
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL (@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND  Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  ModdDev LIKE ISNULL(@pmModdDev,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajBusPag]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCajBusPag] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null,@pmIdForma VARCHAR(4)=Null
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipRec,Recibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero
,IdAgencia,NumVehiculo,D.IdCCosto AS CdCCosto,CCosto,D.IdSubCos AS CdSubCentro,IdCajero,UC.Usuario AS UsuCajero,EnEfectivo,D.NumForma AS DocNumForma,Referencia,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev
--detalles pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS CodBanco,B.Banco AS NomBanco,NitCliente,TP.RazonSocial AS PagNomTercero
,P.NumForma AS NumCheque,FecForma,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,LF.Localidad AS CiudadPlaza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
,P.CdCta AS CtaCod,NumeroCta,CTA.IdBanco AS CtaIdBanco,BC.Banco AS CtaBanco
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
 FROM Trn_DevCaj AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario  INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 INNER JOIN Trn_Pagos AS P ON D.TipDev=P.TipDoc AND  D.Devolucion=P.Documento AND  D.IdCia=P.IdCia
 INNER JOIN Bancos AS B ON P.IdBanco=B.IdBanco   INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma
 LEFT JOIN CtasCorrientes AS CTA ON P.CdCta=CTA.IdCta LEFT JOIN Bancos AS BC ON CTA.IdBanco=BC.IdBanco
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Terceros AS TP ON P.NitCliente=TP.IdTercero
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 WHERE TipDev=@pmTipDev  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL (@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND  Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  ModdDev LIKE ISNULL(@pmModdDev,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')
  AND P.IdForma LIKE ISNULL(@pmIdForma,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCajDoc] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,IdTercero,TipCom,Comprobante,IdCiaCom,IdEstado
 FROM Trn_DevCaj
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCajLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Recibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,D.IdTercero AS NitTercero,RazonSocial,IdAgencia,IdCCosto,IdSubCos
,IdCajero,UC.Usuario AS UsuCajero,EnEfectivo,CdCta,NumForma,CdBanco,Referencia,NumAutoriza,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev,NumVehiculo
 FROM Trn_DevCaj AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL (@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND  Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  ModdDev LIKE ISNULL(@pmModdDev,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCajRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCajRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmCdCta VARCHAR(4)=Null,@pmEnEfectivo BIT=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,CN.Concepto AS DevConcepto
,DV.TipDoc AS TipRec,DV.Recibo AS NumRecibo,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,VrTotDebito,VrTotCredito,DV.IdTercero AS DevNitTercero,T.RazonSocial AS DevNomTercero
,DV.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,DV.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto
,DV.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS UsuCajero,EnEfectivo
,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco,NumForma,CdBanco,BR.Banco AS DocBanco
,DV.Referencia AS DevReferencia,NumAutoriza,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,DV.Observacion AS Observ
,DV.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,DV.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,NumVehiculo
--detalles de cuentas
,Item,D.IdConcepto AS DetCodConcepto,CD.Concepto AS DetConcepto,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,NitTercero,DT.RazonSocial AS DetRazonSocial
,pVehiculo,CdCCosto,DC.CCosto AS DetCentCosto,CdSubCos,DS.SubCosto AS DetSubCentCos,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,NumCheque,TipoAplica
,NitOtros,D.CodAgencia AS DetCodAgencia,DA.Agencia AS DetAgencia,Referncia,TipDocRef,DocRef,IdCiaRef
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--agencia
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DAG.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_DevCaj AS DV INNER JOIN Trn_CompCajaDet AS D ON DV.TipDoc=D.TipDoc AND DV.Recibo=D.Recibo AND DV.IdCiaDoc=D.IdCia
 INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia  
 INNER JOIN EstadoDoc AS ED ON DV.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON DV.IdCajero=UC.IdUsuario  INNER JOIN CentroCosto AS CC ON DV.IdCCosto=CC.IdCCosto 
 INNER JOIN  Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto  INNER JOIN Terceros AS T ON DV.IdTercero =T.IdTercero
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto  INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  CtasCorrientes AS CTA ON DV.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Agencias  AS A ON DV.IdAgencia=A.IdAgencia LEFT JOIN SubCentros AS SC ON DV.IdSubCos=SC.IdSubCos
 LEFT JOIN Bancos AS BR ON DV.CdBanco=BR.IdBanco 
 LEFT JOIN Terceros AS DT ON D.NitTercero=DT.IdTercero  LEFT JOIN CentroCosto AS DC ON D.CdCCosto=DC.IdCCosto 
 LEFT JOIN SubCentros AS DS ON D.CdSubCos=DS.IdSubCos LEFT JOIN Agencias AS DA ON D.CodAgencia=DA.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN Departamentos AS DAG ON LA.IdDep=DAG.IdDep
 WHERE TipDev=@pmTipDev AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND DV.IdCia LIKE ISNULL(@pmIdCia,'%%') AND DV.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND CdCta LIKE ISNULL(@pmCdCta,'%')  AND DV.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND DV.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')  AND DV.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY DV.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacion]  @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)

AS
 SELECT     TipDev, Devolucion, IdCia, Fecha, IdConcepto, TipDoc, Documento, IdCiaDoc, FecDoc, IdVehiculo, IdConductor, IdPropietario, VehPropio, ValorTotal, 
                      ValorDcto, ValorIva, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorFletes, ValorNeto, ValorCxc, IdPlazo, CxPagar, Factura, IdProveedor, 
                      TipCom, Comprobante, IdCiaCom, Observacion, IdEstado, TimeSys, IdCiaCrea, IdUsuario
 FROM        Trn_DevCausacion
 WHERE  TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacion_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacion_Cr]  @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
AS
 SELECT TipDev,TD.TipoDoc AS TipoDev,D.Devolucion AS NDevolucion, D.IdCia AS CodCia,Compania, D.Fecha AS FechaDev, D.IdConcepto AS Concept,CC.Concepto AS ConceptoDev,D.TipDoc AS IdTipoDoc,TDC.TipoDoc AS TipoCausacion, D.Documento AS NCausacion, D.IdCiaDoc AS CiaDoc , FecDoc
, D.IdVehiculo AS PlacaVehc, D.IdConductor AS CedConductor,D.IdPropietario AS NitCedProp,D.VehPropio AS VehicProp, D.ValorTotal,D.ValorDcto,D.ValorIva, D.ValorReteFte, D.ValorReteIva,D.ValorReteIca, D.ValorOtros, D.ValorFletes, D.ValorNeto,ValorCxc, D.IdPlazo AS Idpzo,Plazo,DiasPago,NVmto, D.CxPagar, D.Factura, D.IdProveedor AS IdProveed, NV.RazonSocial AS Proveedor
,D.TipCom AS IdTipoComp,TM.TipoCom AS TipoComp, D.Comprobante,D.IdCiaCom, D.Observacion AS Observ, D.IdEstado AS IdEstadDev,ED.Estado AS EstadDoc, D.TimeSys, D.IdCiaCrea, D.IdUsuario AS IdUsuari,Usuario,TD.Leyenda
,Item,RF.TipDoc AS TipoDocApl,RF.Documento AS NCausacionApl,RF.IdCiaDoc AS CiaDocApl,ItemDoc,RF.IdCargo AS CodCargo,F.Concepto AS Cargo,RF.IdClase AS CodClase,ClaseCuenta,ValorAbono,IdCliente,IdAgencia,RF.IdVehiculo AS PlacaVehApl,RF.VehPropio AS VehPropApl,IdVendedor,Detalle,FecPago
,FecFactura,FecVence,Referencia,BaseIva,BaseRet,TarifaIva,TarifaRet,DTC.TarifaIca,MulPlazos,CxcVarios
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM   Trn_DevCausacion AS D INNER JOIN Sys_TiposDoc  AS TD ON D.TipDev=TD.IdDoc  INNER JOIN Sys_TiposDoc  AS TDC ON D.TipDoc=TDC.IdDoc
 INNER JOIN Trn_Causacion AS DTC ON D.TipDoc=DTC.TipDoc AND D.Documento=DTC.Documento AND D.IdCiaDoc=DTC.IdCia
 INNER JOIN Trn_RecFactura AS RF ON D.TipDev=RF.TipRec AND D.Devolucion=RF.Recibo AND D.IdCia=RF.IdCia
 INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia INNER JOIN Conceptos AS CC ON D.IdConcepto=CC.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON  D.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON D.IdPlazo=PZ.IdPlazo  
 INNER JOIN Terceros AS  NV ON D.IdProveedor=NV.IdTercero INNER JOIN Vehiculos AS V ON RF.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NP ON RF.IdCliente=NP.IdTercero INNER JOIN Terceros AS NC ON RF.IdVendedor=NC.IdTercero
 INNER JOIN Fijos AS F ON RF.IdCargo=F.IdCargo INNER JOIN BusClaseCue AS CU ON RF.IdClase=CU.IdClase
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON RF.IdVendedor=CT.IdConductor  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal
  LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN TiposCom AS TM ON D.TipCom=TM.IdCom
 WHERE  TipDev=@pmTipDev AND D.Devolucion between @pmDevolucionIni  AND @pmDevolucionFin
  AND D.IdCia=@pmIdCia
 ORDER BY D.IdCia,D.Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacion_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacion_Crr]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipDev VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
,@pmModalidad VARCHAR(10)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdProveedor VARCHAR(16)=Null, @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmCxPagar BIT=Null,@pmDocumento INT=Null,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT TipDev, Devolucion,D.IdCia AS CodCia,Compania,D.Fecha AS FechaDev,D.TipDoc AS TipDocm, D.Documento AS NumCausac, IdCiaDoc, FecDoc,D.Factura AS NumFact,FecFactura,C.Modalidad AS DevModalidad
,D.IdProveedor AS NitProveed,NV.RazonSocial AS Proveedor,D.IdVehiculo AS PlacaVeh,D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,D.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,D.VehPropio AS VhPropio,D.ValorTotal AS VrTotal,D.ValorDcto AS VrDcto, D.ValorIva AS VrIva, D.ValorReteFte AS VrReteFte, D.ValorReteIva AS VrReteIva, D.ValorReteIca AS VrReteIca, D.ValorOtros AS VrOtros, D.ValorFletes AS VrFletes, D.ValorNeto AS VrNeto
, ValorCxc, D.IdConcepto AS CodConcepto,Concepto,D.CxPagar AS Cxpagr,D.IdPlazo AS CodPlazo,Plazo,DiasPago,NVmto,D.TipCom AS TComp,TipoCom,D.Comprobante AS Comprob, D.IdCiaCom AS CodCiaComp,D.Observacion AS Observ, D.IdEstado AS IdEstad,ED.Estado AS EstadDoc, D.TimeSys AS FechaAdd,D.IdCiaCrea AS IdCiaCre
,TipoDoc, D.IdUsuario AS IdUsuari,Usuario
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_DevCausacion AS D INNER JOIN Trn_Causacion AS C ON D.TipDoc=C.TipDoc AND D.Documento=C.Documento AND D.IdCiaDoc=C.IdCia
 INNER JOIN Sys_TiposDoc  AS TD ON D.TipDev=TD.IdDoc   INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Conceptos AS CC ON D.IdConcepto=CC.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Plazos AS PZ ON D.IdPlazo=PZ.IdPlazo 
 INNER JOIN Terceros AS  NV ON D.IdProveedor=NV.IdTercero
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero
 INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero 
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
 INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
 LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
 LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa   LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor
 LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
 LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN TiposCom AS TM ON D.TipCom=TM.IdCom
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  TipDev LIKE ISNULL(@pmTipDev,'%')  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.Modalidad LIKE ISNULL(@pmModalidad,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND D.IdProveedor LIKE ISNULL(@pmIdProveedor,'%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') 
 AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')   AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND (D.CxPagar=ISNULL(@pmCxPagar,0) or D.CxPagar=ISNULL(@pmCxPagar,1))
 AND (D.Documento>=ISNULL(@pmDocumento,0)  AND D.Documento<=ISNULL(@pmDocumento,2147483647))
 ORDER BY TipDev, D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacionLta]  @pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
AS
 SELECT    Devolucion, IdCia, Fecha,D.IdConcepto AS IdConcept,Concepto,TipDoc, Documento, IdCiaDoc, FecDoc, IdVehiculo, IdConductor,O.RazonSocial AS Conductor, IdPropietario,P.RazonSocial AS Propietario,VehPropio, ValorTotal, 
                     ValorDcto, ValorIva, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorFletes, ValorNeto, ValorCxc, D.IdPlazo AS IdPlaz, CxPagar, Factura, IdProveedor,N.RazonSocial AS Proveedor,
                      TipCom, Comprobante, IdCiaCom,D.Observacion AS Observ, D.IdEstado AS IdEstad,Estado, TimeSys, IdCiaCrea, D.IdUsuario AS IdUsuari
 FROM  Trn_DevCausacion AS D INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
  INNER JOIN  Terceros AS O ON D.IdConductor=O.IdTercero
  INNER JOIN  Terceros AS P ON D.IdPropietario=P.IdTercero
  INNER JOIN  Terceros AS N ON D.IdProveedor=N.IdTercero
  INNER JOIN  EstadoDoc AS E ON D.IdEstado=E.IdEstado
 WHERE   Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionNMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacionNMes] @pmAnno INT,@pmMes INT=Null,@pmIdCia CHAR(2)=Null,@pmIdPropietario VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT  IdCliente,VC.IdVehiculo AS PlacaVeh,D.IdCia AS CodCia,D.TipDoc AS TipoDcm,Month(Fecha) AS nMes,SUM(ValorFactura) AS SValNet
 FROM  Trn_DevCausacion AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Documento=VC.Documento AND D.IdCiaDoc=VC.IdCia
 WHERE Year(Fecha)=@pmAnno AND  Month(Fecha)=ISNULL(@pmMes, Month(Fecha))
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.TipDoc LIKE ISNULL(@pmTipDoc,'%') AND IdCliente LIKE ISNULL(@pmIdPropietario,'%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 GROUP BY IdCliente,VC.IdVehiculo,D.IdCia,D.TipDoc,Month(Fecha)
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionVc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacionVc] @pmIdPropietario VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT VC.TipDoc AS TDoc,VC.Documento AS NumDoc,VC.IdCia AS CodCia,Item,ValorFactura,IdCliente,IdAgencia,VC.IdVehiculo AS PlacaVeh
,VC.VehPropio AS VhProp,IdVendedor,Comision,IdCargo,IdClase,VC.IdConcepto AS CodConcp,VC.Factura AS NumFact,Referencia,Detalle,Devolucion,TipDev,D.IdCia AS CiaDev,Fecha,FecDoc,ValorCxc,ValorNeto
 FROM  Trn_DevCausacion AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Documento=VC.Documento AND D.IdCiaDoc=VC.IdCia
 WHERE IdCliente LIKE ISNULL(@pmIdPropietario,'%') AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY TipDev,Devolucion,D.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCausacionVFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCausacionVFec]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdPropietario VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmTipDoc VARCHAR(3)=Null
AS
 SELECT IdCliente,VC.IdVehiculo AS IdVehic,SUM(ValorFactura) AS SValNet
 FROM  Trn_DevCausacion AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Documento=VC.Documento AND D.IdCiaDoc=VC.IdCia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdPropietario,'%')
 GROUP BY IdCliente,VC.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCns] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Consignacion,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,EnEfectivo,IdCta,IdCuenta,IdCliente
,IdCCosto,IdSubCos,IdCajero,Referencia,Referncia2,NumConsigna,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevCns
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCns_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCns_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto
,D.TipDoc AS TipCons,Consignacion,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,EnEfectivo,D.IdCta AS DevCodCta,NumeroCta
,CT.IdBanco AS DevCodBanco,B.Banco AS DevBanco,D.IdCuenta AS CdCuenta,IdCliente,T.RazonSocial AS NomCliente
,D.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,D.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS NomCajero
,D.Referencia AS DevReferencia,D.Referncia2 AS DevReferncia2,NumConsigna,ModdDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--detalle de pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco,NitCliente,PC.RazonSocial AS PagNomCliente,CdAgencia,A.Agencia AS NomAgencia
,CodAgencia,A.Referencia AS AgeReferencia,NumForma,FecForma,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS PagReferencia2,CdLocal,LF.Localidad AS CiudadPlaza,LF.IdDep AS CdDptoPlaza,DF.Departamento AS DptoPlaza
,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 FROM Trn_DevCns AS D  INNER JOIN Trn_Pagos AS P ON D.TipDev=P.TipDoc AND D.Devolucion=P.Documento AND D.IdCia=P.IdCia
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN CtasCorrientes AS CT ON D.IdCta=CT.IdCta INNER JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Puc AS PU ON D.IdCuenta=PU.IdCuenta
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos  LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep 
 LEFT JOIN Terceros AS PC ON P.NitCliente=PC.IdTercero  LEFT JOIN Agencias  AS A ON P.CdAgencia=A.IdAgencia
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCnsDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCnsDoc] @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Consignacion,IdCiaDoc,FecDoc
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,IdEstado
 FROM Trn_DevCns
 WHERE TipDoc=@pmTipDoc AND Consignacion=@pmConsignacion AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCnsLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCnsLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmConsignacionIni INT=Null,@pmConsignacionFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdCta VARCHAR(4)=Null,@pmEnEfectivo BIT=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Consignacion,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,EnEfectivo,D.IdCta AS CodCta,NumeroCta,CT.IdBanco AS CdBanco,Banco
,D.IdCuenta AS CdCuenta,IdCliente,RazonSocial,IdCCosto,IdSubCos,IdCajero,UC.Usuario AS NomCajero,Referencia,Referncia2,NumConsigna,ModdDev,OrigenAdd
,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_DevCns AS D  INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN CtasCorrientes AS CT ON D.IdCta=CT.IdCta INNER JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND Consignacion BETWEEN ISNULL(@pmConsignacionIni,0) AND ISNULL(@pmConsignacionFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdCta LIKE ISNULL(@pmIdCta,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevCnsRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevCnsRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCta VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmEnEfectivo BIT=Null
,@pmIdCliente VARCHAR(16)=Null 
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto
,D.TipDoc AS TipCons,Consignacion,IdCiaDoc,FecDoc,VrEfectivo,VrOtros,VrTotal,EnEfectivo,D.IdCta AS DevCodCta,NumeroCta
,CT.IdBanco AS DevCodBanco,B.Banco AS DevBanco,D.IdCuenta AS CdCuenta,IdCliente,T.RazonSocial AS NomCliente
,D.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,D.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS NomCajero
,D.Referencia AS DevReferencia,D.Referncia2 AS DevReferncia2,NumConsigna,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalle de pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco,NitCliente,PC.RazonSocial AS PagNomCliente,CdAgencia,A.Agencia AS NomAgencia
,CodAgencia,A.Referencia AS AgeReferencia,NumForma,FecForma,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS PagReferencia2,CdLocal,LF.Localidad AS CiudadPlaza,LF.IdDep AS CdDptoPlaza,DF.Departamento AS DptoPlaza
,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 FROM Trn_DevCns AS D  INNER JOIN Trn_Pagos AS P ON D.TipDev=P.TipDoc AND D.Devolucion=P.Documento AND D.IdCia=P.IdCia
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia 
 INNER JOIN CtasCorrientes AS CT ON D.IdCta=CT.IdCta INNER JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Puc AS PU ON D.IdCuenta=PU.IdCuenta
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos 
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep 
 LEFT JOIN Terceros AS PC ON P.NitCliente=PC.IdTercero  LEFT JOIN Agencias  AS A ON P.CdAgencia=A.IdAgencia
 WHERE TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdCta LIKE ISNULL(@pmIdCta,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDeveloper]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDeveloper]
AS
 SELECT NitCia,Nombre,Direccion,Telefono,Fax,Ciudad,Internet,Email,RepLegal
 FROM Sys_Developer
 ORDER BY NitCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevEnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Entrada,IdCiaDoc,FecDoc,IdProv,Factura,VrSubTotal,VrDescuento,VrImpuesto
,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,FletesCosto,VrIvaMvc,CxPagar,DocEquiv
,BaseImp,BaseRet,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,CdCCosto,CdSubCos,Modalidad,ModdDev,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,VrImpuCons,VrSobtasaCons,BaseIvaIgp,VrIvaIngProd,ImpAviTab,TarifaAvta
,VrImpuBA,VrImpuCUP,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevEnt
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEntDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevEntDoc] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Entrada,IdCiaDoc,FecDoc,CxPagar,VrSubTotal,VrDescuento,VrImpuesto,VrNeto
,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevEnt
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEntLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevEntLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmEntradaIni INT=Null,@pmEntradaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Entrada,IdCiaDoc,FecDoc,IdProv,RazonSocial,Factura,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrOtros,VrSobretasa,VrImpGlobal,VrImpCarbono,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,FletesCosto,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons
,BaseIvaIgp,VrIvaIngProd,ImpAviTab,TarifaAvta,D.VrImpuBA,D.VrImpuCUP,CxPagar,DocEquiv,BaseImp,BaseRet,CdCCosto,CdSubCos,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TipDev,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
 FROM Trn_DevEnt AS D INNER JOIN Terceros AS T ON D.IdProv=T.IdTercero
 INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipDev=@pmTipDev
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND Entrada BETWEEN ISNULL(@pmEntradaIni,0) AND ISNULL(@pmEntradaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevEntRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevEntRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmCxPagar BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Entrada,IdCiaDoc,FecDoc
,D.IdProv AS NitProvee,RazonSocial,Factura,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal
,VrCargos,VrOtrDcto,VrImpCarbono,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,FletesCosto,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons
,BaseIvaIgp,VrIvaIngProd,ImpAviTab,TarifaAvta,D.VrImpuBA,D.VrImpuCUP,CxPagar,DocEquiv,BaseImp,BaseRet,CdCCosto,CCosto,CdSubCos,SubCosto,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_DevEnt AS D INNER JOIN Terceros AS T ON D.IdProv=T.IdTercero 
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON D.IdProv=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 WHERE TipDev=@pmTipDev AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdProv LIKE ISNULL(@pmIdProv,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND  ModdDev LIKE ISNULL(@pmModdDev,'%')
 AND (CxPagar=ISNULL(@pmCxPagar,0) or CxPagar=ISNULL(@pmCxPagar,1)) 
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevFco] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,BaseImp,BaseRet,IdCajero,IdVend,TarifaCom,CodTarCom,NitCliente,CdAgencia,IdCCosto
,IdSubCos,IdLocal,EnEfectivo,Pedido,IdCiaPed,Remision,IdCiaRem,FecPedido,Modalidad,ModdDev,OrigenAdd,NumAutoriza,PlacaVehic,KmtVehic,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc
,BaseIvaObsq,VrIvaObsequio,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP,ImpAviTab,TarifaAvta,VrBomberil,TarifaBom,VrAutRetIat,VrAutRetBom,CdMotDev
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevFco
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFco_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFco_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipoFac,D.Factura AS NumFactura,IdCiaDoc,FecDoc
,nClieCon,Nombre,CC.TipoId AS CliTipoId,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad,LE.Localidad AS CiudadClie
,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo
,VrPagosOtr,Cantidad,CantPuntos,BaseImp,BaseRet,IdCajero,UC.Usuario AS Cajero,D.IdVend AS NitVendedor,V.RazonSocial AS Vendedor
,TarifaCom,NitCliente,T.RazonSocial AS NomCliente,D.CdAgencia AS IdAgncia,Agencia,CodAgencia,D.IdCCosto AS IdCentCost,CCosto,D.IdSubCos AS IdSubCent,SubCosto
,D.IdLocal AS CodCiudad,LD.Localidad AS DocCiudad,EnEfectivo,Pedido,IdCiaPed,D.Remision AS NumRemision,D.IdCiaRem AS CdCiaRem,FecPedido,Modalidad,ModdDev,NumAutoriza,PlacaVehic,KmtVehic
,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,D.ImpAviTab,D.TarifaAvta,D.VrBomberil,D.TarifaBom,D.VrAutRetIat,D.VrAutRetBom
,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.CdMotDev,MotivoDev,D.TimeSys AS Fec_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,CdSubCos,pVehiculo,K.Referencia AS KarReferencia,Descripcion,TipOrd,NumOrden,IdCiaOrd
,K.Factura AS KarFactura,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_DevFco AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ClieContado AS CC ON D.nClieCon=CC.IdCliente
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero  INNER JOIN  Localidades AS LD ON D.IdLocal=LD.IdLocal
 INNER JOIN Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN Terceros AS T ON D.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON D.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 LEFT JOIN CentroCosto AS CT ON D.IdCCosto=CT.IdCCosto LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposMotdev AS MD ON D.CdMotDev=MD.IdMotDev
 LEFT JOIN Trn_Face AS FE ON D.TipDev=FE.TipDoc AND D.Devolucion=FE.Documento AND D.IdCia=FE.IdCia
 WHERE TipDev=@pmTipDev  AND Devolucion BETWEEN  @pmDevolucionIni AND @pmDevolucionFin  AND D.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcoDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcoDoc]  @pmTipDoc VARCHAR(3),@pmFactura INT ,@pmIdCiaDoc CHAR(2)
AS
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,nClieCon,VrNeto,VrEfectivo,VrPagosOtr
,Modalidad,ModdDev,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevFco
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcoLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmnClieCon VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null
,@pmNitCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc,nClieCon,Nombre,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseImp,BaseRet,IdCajero,UC.Usuario AS Cajero,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,NitCliente
,T.RazonSocial AS NomCliente,CdAgencia,IdCCosto,IdSubCos,D.IdLocal AS CodCiudad,EnEfectivo,Pedido,IdCiaPed,Remision,IdCiaRem,FecPedido,Modalidad,ModdDev,NumAutoriza,PlacaVehic,KmtVehic,BaseIvaObsq,VrIvaObsequio
,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,ImpAviTab,TarifaAvta,VrBomberil,TarifaBom,VrAutRetIat,VrAutRetBom,CdMotDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,D.TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev
 FROM Trn_DevFco AS D INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN ClieContado AS C ON D.nClieCon=C.IdCliente
 LEFT JOIN  Terceros AS T ON D.NitCliente=T.IdTercero
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND nClieCon LIKE ISNULL(@pmnClieCon,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND NitCliente LIKE ISNULL(@pmNitCliente,'%') 
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%') 
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcoRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcoRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmnClieCon VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend  VARCHAR(16)=Null
,@pmNitCliente VARCHAR(16)=Null,@pmEnEfectivo BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc
,nClieCon,Nombre,CC.TipoId AS CliTipoId,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad,LE.Localidad AS CiudadClie
,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo
,VrPagosOtr,Cantidad,CantPuntos,BaseImp,BaseRet,IdCajero,UC.Usuario AS Cajero,D.IdVend AS NitVendedor,V.RazonSocial AS Vendedor
,TarifaCom,NitCliente,T.RazonSocial AS NomCliente,D.CdAgencia AS IdAgncia,Agencia,CodAgencia,D.IdCCosto AS IdCentCost,CCosto,D.IdSubCos AS IdSubCent,SubCosto
,D.IdLocal AS CodCiudad,LD.Localidad AS DocCiudad,EnEfectivo,Pedido,IdCiaPed,Remision,IdCiaRem,FecPedido,Modalidad,ModdDev,NumAutoriza,PlacaVehic,KmtVehic,VrImpCons
,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,D.ImpAviTab,D.TarifaAvta,D.VrBomberil,D.TarifaBom,D.VrAutRetIat,D.VrAutRetBom
,D.CdMotDev,MotivoDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys,D.IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_DevFco AS D INNER JOIN ClieContado AS CC ON D.nClieCon=CC.IdCliente
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero  INNER JOIN  Localidades AS LD ON D.IdLocal=LD.IdLocal
 INNER JOIN Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS T ON D.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON D.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN CentroCosto AS CT ON D.IdCCosto=CT.IdCCosto LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN TercCliente AS CLI ON D.NitCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 LEFT JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN TiposMotdev AS MD ON D.CdMotDev=MD.IdMotDev
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipDev LIKE ISNULL(@pmTipDev,'%')
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND nClieCon LIKE ISNULL(@pmnClieCon,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND NitCliente LIKE ISNULL(@pmNitCliente ,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')  AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevFcr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA
,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrIvaIngProd,VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,BaseIvaIgp,IdCCosto,IdSubCos,IdVend,TarifaCom
,CodTarCom,IdLocEnv,Pedido,IdCiaPed,Remision,IdCiaRem,Cotizacion,IdCiaCot,FecPedido,PlacaVehic,KmtVehic,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Observacion,IdEstado,ZonaFrontera,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,DevMasivo,NumRecibo,CdCiaRec,CdMotDev,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP
,ImpAviTab,TarifaAvta,VrBomberil,TarifaBom,VrAutRetIat,VrAutRetBom,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevFcr
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcr_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcr_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipFact,D.Factura AS NumFactura
,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,D.VrImpCarbono,D.VrIvaIngProd,VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,D.BaseIvaIgp
,VrReteCREE,TarifaRtc,CodTarRtc,D.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,D.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,D.IdVend AS NitVend,VN.RazonSocial AS Vendedor
,TarifaCom,D.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,Pedido,IdCiaPed,D.Remision AS NumRemision,D.IdCiaRem AS CdCiaRem
,D.Cotizacion AS NumCotizacion,D.IdCiaCot AS CdCiaCot,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,ZonaFrontera,VrImpCons,BaseIvaObsq,VrIvaObsequio,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,D.VrImpuBA,D.VrImpuCUP
,D.ImpAviTab,D.TarifaAvta,D.VrBomberil,D.TarifaBom,D.VrAutRetIat,D.VrAutRetBom,DevMasivo,NumRecibo,CdCiaRec,CdMotDev,MotivoDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdAgencia,KA.Agencia AS KarAgencia,KA.CodAgencia AS KarCodAgencia,KA.NContrato AS KarAgeContrato,KA.Referencia AS KarAgeRefencia,CdLocal,KL.Localidad AS KarCiudad
,CdCCosto,KC.CCosto AS Kar_Ccosto,K.CdSubCos AS CodSubCos,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,K.Cotizacion AS KarNumCotiza,K.IdCiaCot AS KarCiaCotiza,K.Remision AS KarRemision,K.IdCiaRem AS KarCiaRem
,K.Factura AS KarFactura,TipDocDev,NumDocDev,K.IdVend AS KarNitVend,KV.RazonSocial AS KarVendedor,K.Comision AS KarTarifaCom,CdOperario,KO.RazonSocial AS NomOperario,ComisnOper,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase
,ListaPrec,VrBase,BaseIvp,TarifaIvp,IvaIngProd,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
,CdMngra,NumInicial,NumFinal
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_DevFcr AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS VN ON D.IdVend=VN.IdTercero INNER JOIN Agencias  AS A ON D.IdAgencia=A.IdAgencia 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON D.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos 
 LEFT JOIN Agencias  AS KA ON K.CdAgencia=KA.IdAgencia LEFT JOIN Localidades AS KL ON K.CdLocal=KL.IdLocal
 LEFT JOIN Terceros AS KV ON K.IdVend=KV.IdTercero  LEFT JOIN Terceros AS KO ON K.CdOperario=KO.IdTercero
 LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom LEFT JOIN TiposMotdev AS MD ON D.CdMotDev=MD.IdMotDev
 LEFT JOIN Trn_Face AS FE ON D.TipDev=FE.TipDoc AND D.Devolucion=FE.Documento AND D.IdCia=FE.IdCia
 WHERE TipDev=@pmTipDev  AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcr40]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:	Heiman Daza Tamayo
-- Create date(dd/MM/yyyy): 03/10/2019
-- Description:	procedimiento que busca las devoluciones factura para ser enviada a la DIAN en Syscom40 (Factura Electrónica).
-- =============================================
CREATE PROCEDURE [dbo].[paQryDevFcr40]
	--@pmTipFact VARCHAR(20),--Tipo de documento que se desea buscar módulo
	@pmTipDev VARCHAR(3),--Tipo de documento que se desea buscar
	@pmDevolucion INT, --Número de documento que se desea buscar
	@pmIdCia CHAR(2), --Compañía de documento que se desea buscar
	@pmModalidad VARCHAR(30) = NULL,
	@Origen VARCHAR(16)= NULL
AS
BEGIN
	IF EXISTS (SELECT Modalidad FROM Trn_DevFcr WHERE TipDev = @pmTipDev AND Devolucion = @pmDevolucion AND IdCia = @pmIdCia)
    BEGIN
       SELECT @pmModalidad = Modalidad, @Origen = OrigenAdd FROM Trn_DevFcr WHERE TipDev = @pmTipDev AND Devolucion = @pmDevolucion AND IdCia = @pmIdCia
    END
	IF @pmTipDev IN ('DF1','DF2','DF3','DF4','DF5','DFC','DFV','FCE','DFE')
	BEGIN
		IF @pmModalidad IN ('INVENTARIO','VALES','COMBUSTBLE') AND @Origen IN ('MAIN', 'PRODCOM')
			BEGIN ----Dev Crédito    	
				SELECT D.TipDev AS TipDoc,  TD.TipoDoc,  D.Devolucion AS NumNota,  D.IdCia, C.Compania, D.Fecha,D.TimeSys, D.IdAgencia, D.VrNeto, D.VrSubTotal, D.VrImpuesto, D.IdCliente,
				D.Observacion, D.TipDoc AS TipDcm, D.Factura AS Documento, D.IdCiaDoc AS IdCiaDcm, D.ModdDev, D.Modalidad,  D.VrImpCons, D.VrRetencion, D.VrReteICA,  D.VrReteIVA,  
				D.VrOtros, D.VrCargos,  D.VrOtrDcto,  D.VrSobretasa, D.VrImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS VrAnticipos, D.VrImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS VrAplicado, 
				D.Cantidad, D.BaseImp, CAST('0' AS DECIMAL(14, 4)) AS BaseICO, D.BaseRet, D.BaseImp AS BaseIca, D.VrImpuesto AS BaseRiv, CAST('0' AS DECIMAL(14, 4)) AS TarifaIva, CAST('0' AS DECIMAL(14, 4)) AS TarifaRet,
				CAST('0' AS DECIMAL(14, 4)) AS TarifaIca, CAST('0' AS DECIMAL(14, 4)) AS TarifaRiv, CAST('0' AS DECIMAL(14, 4)) AS ETarifaIco, D.TarifaAri, D.VrAutRetIca AS VrAutRetIcaNoTTE,  D.TarifaArf, D.VrAutRetFte,
				--Detalles
				DD.Item, DD.CodProducto, DD.CodProductoDIAN, DD.DescripProd, DD.Cant, DD.CdUndMed, DD.VrUnitario, DD.VrDctoSal, DD.TarifaDct, DD.TipoReg, DD.CantObseq, DD.CdMoneda, DD.VrTasaCamb, DD.TarifaIco, 
				DD.VrImpCon, DD.BaseIcoDet, DD.TarifaIvaDet, DD.VrIvaDet, DD.BaseIvaDet, DD.TarifaRetDet, DD.VrRetDet, DD.TarifaIcaDet, DD.VrIcaDet, 
				--Versión 10
				DD.VrAutRetIca, DD.BaseAutoIcaDet, 
				DD.ExcluidoImp, DD.ImpCarbono, DD.ImpGlobal, 
				DD.Sobretasa, DD.Soldicom, DD.TarifaIvp, DD.BaseIvp, DD.IvaIngProd, DD.EsCombo, DD.ItemCombo, DD.Entradas, DD.IvaDetCombo, DD.Mandatario, DD.MandatarioDV, DD.MandatarioTipDoc, DD.Referencia1,CAST('0' AS int) TipoNotaFE,OrigenAdd,
				CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem
				FROM Trn_DevFcr AS D
				JOIN
				(
					SELECT  K.TipDoc, K.Documento AS Devolucion, K.IdCia, K.Item, K.IdProducto AS CodProducto, ISNULL(P.CodFEDian, K.IdProducto) AS CodProductoDIAN, P.DescripProd, K.Entradas AS Cant, 
					(CASE WHEN @pmModalidad = 'INVENTARIO' AND K.ItemCombo > 0 AND K.EsCombo = 0 AND K.EsProdBase > 0  THEN CAST((K.IngBaseCom / K.Entradas) AS decimal(14, 4))  ELSE K.VrPrecio END) AS VrUnitario, K.VrDctoEnt AS VrDctoSal, K.TarifaDct,
					ISNULL(UM.CodUMFE, P.UndMed) AS CdUndMed, 0 AS TipoReg, K.CantObseq, K.CdMoneda, K.VrTasaCamb, K.TarifaIco, K.VrImpCon, (CASE WHEN VrImpCon > 0 THEN ((K.Entradas * K.VrPrecio) - K.VrDctoEnt)  ELSE 0 END) AS BaseIcoDet, 
					K.TarifaIva AS TarifaIvaDet, K.VrIvaEnt AS VrIvaDet, (CASE WHEN @pmModalidad = 'COMBUSTBLE' THEN K.BaseIvaCom  ELSE ((K.Entradas * K.VrPrecio) - K.VrDctoEnt) END) AS BaseIvaDet, K.TarifaRet AS TarifaRetDet, K.VrReteEnt AS VrRetDet, 
					K.TarifaIca AS TarifaIcaDet, K.VrIcaEnt AS VrIcaDet,
					--Versión 10
					CAST('0' AS DECIMAL(14,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(14,4))  AS BaseAutoIcaDet,
					P.ExcluidoImp, K.ImpCarbono, K.ImpGlobal, K.Sobretasa, K.Soldicom, K.TarifaIvp, K.BaseIvp, K.IvaIngProd, K.EsCombo, 
					--K.ItemCombo, 
					--Arreglo Colanta
					(CASE WHEN K.EsCombo = 0 AND k.EsProdBase = 1 THEN 1 ELSE 0 END) AS ItemCombo,
					K.Salidas AS Entradas, P.IvaDetCombo, -- Ojo aquí las entradas corresponden a las salidas para los combos porq es una devolución
					(CASE WHEN P.TipoZonaFront = 'IT' THEN  K.CdOperario ELSE '' END) AS Mandatario, TM.Dv AS MandatarioDV, TM.TipoId AS MandatarioTipDoc, '' AS Referencia1
					FROM Trn_Kardex AS K
					JOIN ProdMcias AS P ON K.IdProducto = P.IdProducto
					LEFT JOIN ProdCombo AS PC ON P.Idproducto = PC.IdProducto
					LEFT JOIN Terceros AS TM ON K.CdOperario = TM.IdTercero
					JOIN Sys_Um AS UM ON P.UndMed = UM.UndMed		
				) AS DD ON D.TipDev = DD.TipDoc AND D.Devolucion = DD.Devolucion AND D.IdCia = DD.IdCia
				JOIN Companias AS C ON D.IdCia = C.IdCia
				JOIN Sys_TiposDoc AS TD ON D.TipDev = TD.IdDoc
				JOIN Terceros AS T ON D.IdCliente = T.IdTercero
				--LEFT JOIN Trn_Face AS FE ON D.TipDev = FE.TipDoc AND D.Devolucion = FE.Documento AND D.IdCia = FE.IdCia
				WHERE D.TipDev = @pmTipDev AND D.Devolucion = @pmDevolucion AND D.IdCia = @pmIdCia
			END
		ELSE IF @pmModalidad IN ('TRANSPORTE') AND @Origen IN ('TRANSPORTE')
			BEGIN --Dev Crédito Transporte
				SELECT D.TipDev AS TipDoc,  TD.TipoDoc,  D.Devolucion AS NumNota,  D.IdCia, C.Compania, D.Fecha,D.TimeSys, D.IdAgencia, D.VrNeto, D.VrSubTotal, D.VrImpuesto, D.IdCliente,
				D.Observacion, D.TipDoc AS TipDcm, D.Factura AS Documento, D.IdCiaDoc AS IdCiaDcm, D.ModdDev, D.Modalidad,  D.VrImpCons, D.VrRetencion, D.VrReteICA,  D.VrReteIVA,  
				D.VrOtros,CASE WHEN DD.TipRem ='GTC' THEN 0 ELSE VrCargos END VrCargos,  D.VrOtrDcto,  D.VrSobretasa, D.VrImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS VrAnticipos, D.VrImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS VrAplicado, 
				D.Cantidad, D.BaseImp, CAST('0' AS DECIMAL(14, 4)) AS BaseICO, D.BaseRet, D.BaseImp AS BaseIca, D.VrImpuesto AS BaseRiv, CAST('0' AS DECIMAL(14, 4)) AS TarifaIva, CAST('0' AS DECIMAL(14, 4)) AS TarifaRet,
				CAST('0' AS DECIMAL(14, 4)) AS TarifaIca, CAST('0' AS DECIMAL(14, 4)) AS TarifaRiv, CAST('0' AS DECIMAL(14, 4)) AS ETarifaIco, D.TarifaAri, D.VrAutRetIca AS VrAutRetIcaNoTTE,  D.TarifaArf, D.VrAutRetFte,
				--Detalles
				DD.Item, DD.CodProducto, DD.CodProductoDIAN, DD.DescripProd, DD.Cant, DD.CdUndMed, DD.VrUnitario, DD.VrDctoSal, DD.TarifaDct, DD.TipoReg, DD.CantObseq, DD.CdMoneda, DD.VrTasaCamb, DD.TarifaIco, 
				DD.VrImpCon, DD.BaseIcoDet, DD.TarifaIvaDet, DD.VrIvaDet, DD.BaseIvaDet, DD.TarifaRetDet, DD.VrRetDet, DD.TarifaIcaDet, DD.VrIcaDet, 
				--Versión 10
				DD.VrAutRetIca, DD.BaseAutoIcaDet, 
				DD.ExcluidoImp, DD.ImpCarbono, DD.ImpGlobal, 
				DD.Sobretasa, DD.Soldicom, DD.TarifaIvp, DD.BaseIvp, DD.IvaIngProd, DD.EsCombo, DD.ItemCombo, DD.Entradas, DD.IvaDetCombo, DD.Mandatario, DD.MandatarioDV, DD.MandatarioTipDoc, DD.Referencia1,CAST('0' AS int) TipoNotaFE,OrigenAdd,
				DD.VrSeguroRem				
	, ISNULL(A.numorden, '') OrdenOSM
				FROM Trn_DevFcr AS D
				JOIN
				(
					--Detalle de Crédito Transporte
					SELECT	R.TipDoc, R.Factura Devolucion, R.IdCia, R.Item,CASE WHEN R.TipRem ='GTC'  THEN '999' ELSE R.CdConcepto END AS CodProducto,CASE WHEN R.TipRem ='GTC'  THEN '999' ELSE ISNULL(CD.CodFEDian, R.CdConcepto) END AS CodProductoDIAN, 
					CASE WHEN R.TipRem ='GTC' THEN ('GUIA TRANSPORTE: '+R.TipRem+' '+CAST(R.Remesa AS varchar)+' '+R.IdCiaRem) ELSE ISNULL(CD.Concepto, Descripcion) END AS DescripProd, Cantidad AS Cant,CASE WHEN R.TipRem ='GTC'  THEN (VrUnitario+CostoAdicTbdo) ELSE VrUnitario END VrUnitario, VrDescuento AS VrDctoSal,  R.TarifaDct,
					'94' AS CdUndMed, TipoReg,CAST('0' AS DECIMAL(14,4)) AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(14, 4)) AS VrTasaCamb, CAST('0' AS DECIMAL(14, 4)) AS TarifaIco, CAST('0' AS DECIMAL(14,4)) AS VrImpCon, 
					CAST('0' AS DECIMAL(14, 4)) AS BaseIcoDet, R.TarifaIva AS TarifaIvaDet, R.VrImpuesto AS VrIvaDet, ((R.Cantidad * R.VrUnitario) - R.VrDescuento) AS BaseIvaDet, R.TarifaRet AS  TarifaRetDet, 
					R.VrRetencion AS VrRetDet, R.TarifaIca AS TarifaIcaDet, (case when R.TarifaIca > 0 then (((R.Cantidad * R.VrUnitario) - R.VrDescuento) * (R.TarifaIca / 100)) else CAST('0' AS DECIMAL(14,4)) end)  AS VrIcaDet,
					--R.VrReteIca AS VrIcaDet, 
					--Versión 10 no es reteICA sino AutoICA
					VrAutRetIca, (case when R.TarifaIca > 0 AND VrAutRetIca > 0  then CAST(ROUND((VrAutRetIca * 100/TarifaIca),2) AS DECIMAL(14, 4))  else CAST('0' AS DECIMAL(14,4)) end)  AS BaseAutoIcaDet,
					CAST(1 AS BIT) AS ExcluidoImp, CAST('0' AS DECIMAL(14, 4)) AS ImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS ImpGlobal, 
					CAST('0' AS DECIMAL(14, 4)) AS Sobretasa, CAST('0' AS DECIMAL(14, 4)) AS Soldicom, CAST('0' AS DECIMAL(14, 4)) AS TarifaIvp, CAST('0' AS DECIMAL(14, 4)) AS BaseIvp, CAST('0' AS DECIMAL(14, 4)) AS IvaIngProd, 
					CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(14, 4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo, '' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc, Referencia1,
					--datos gia de transporte
					R.TipRem,R.Remesa,R.IdCiaRem,
					CASE WHEN (select Valor from adm_opciones where IdOpc='FSG') = 1 THEN  (CASE WHEN tarifaseg = 0 THEN CAST((VrSeguroRem/Cantidad) AS DECIMAL(18,4)) ELSE CAST(((VrDeclMcia/Cantidad)*(tarifaseg/100)) AS DECIMAL(18,4)) END) ELSE 0 END VrSeguroRem
					FROM Trn_TraFacRemesas AS R
					JOIN ConcDiversos AS CD ON R.CdConcepto = CD.IdConcepto
				) AS DD ON D.TipDev = DD.TipDoc AND D.Devolucion = DD.Devolucion AND D.IdCia = DD.IdCia
				JOIN Companias AS C ON D.IdCia = C.IdCia
				JOIN Sys_TiposDoc AS TD ON D.TipDev = TD.IdDoc
				JOIN Terceros AS T ON D.IdCliente = T.IdTercero
				LEFT JOIN Trn_TraFacRemesas AS RR ON RR.IdCia = D.IdCia and RR.TipDoc = D.TipDoc and RR.Factura = D.Factura
			    LEFT JOIN Trn_TraRemAnexo AS A ON A.NumInvent = RR.Remesa AND A.TipOrdMud = 'OSM' AND RR.Referencia3 = 'TRANSPORTE'		
				--LEFT JOIN Trn_Face AS FE ON D.TipDev = FE.TipDoc AND D.Devolucion = FE.Documento AND D.IdCia = FE.IdCia
				WHERE D.TipDev = @pmTipDev AND D.Devolucion = @pmDevolucion AND D.IdCia = @pmIdCia
			END
		ELSE IF @pmModalidad IN ('TRANSPORTE')  AND @Origen IN ('TRAES')
			BEGIN --Dev Crédito Transporte Especial
				SELECT D.TipDev AS TipDoc,  TD.TipoDoc,  D.Devolucion AS NumNota,  D.IdCia, C.Compania, D.Fecha,D.TimeSys, D.IdAgencia, D.VrNeto, D.VrSubTotal, D.VrImpuesto, D.IdCliente,
				D.Observacion, D.TipDoc AS TipDcm, D.Factura AS Documento, D.IdCiaDoc AS IdCiaDcm, D.ModdDev, D.Modalidad,  D.VrImpCons, D.VrRetencion, D.VrReteICA,  D.VrReteIVA,  
				D.VrOtros, D.VrCargos,  D.VrOtrDcto,  D.VrSobretasa, D.VrImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS VrAnticipos, D.VrImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS VrAplicado, 
				D.Cantidad, D.BaseImp, CAST('0' AS DECIMAL(14, 4)) AS BaseICO, D.BaseRet, D.BaseImp AS BaseIca, D.VrImpuesto AS BaseRiv, CAST('0' AS DECIMAL(14, 4)) AS TarifaIva, CAST('0' AS DECIMAL(14, 4)) AS TarifaRet,
				CAST('0' AS DECIMAL(14, 4)) AS TarifaIca, CAST('0' AS DECIMAL(14, 4)) AS TarifaRiv, CAST('0' AS DECIMAL(14, 4)) AS ETarifaIco, D.TarifaAri, D.VrAutRetIca AS VrAutRetIcaNoTTE,  D.TarifaArf, D.VrAutRetFte,
				--Detalles
				DD.Item, DD.CodProducto, DD.CodProductoDIAN, DD.DescripProd, DD.Cant, DD.CdUndMed, DD.VrUnitario, DD.VrDctoSal, DD.TarifaDct, DD.TipoReg, DD.CantObseq, DD.CdMoneda, DD.VrTasaCamb, DD.TarifaIco, 
				DD.VrImpCon, DD.BaseIcoDet, DD.TarifaIvaDet, DD.VrIvaDet, DD.BaseIvaDet, DD.TarifaRetDet, DD.VrRetDet, DD.TarifaIcaDet, DD.VrIcaDet, 
				--Versión 10
				DD.VrAutRetIca, DD.BaseAutoIcaDet, 
				DD.ExcluidoImp, DD.ImpCarbono, DD.ImpGlobal, 
				DD.Sobretasa, DD.Soldicom, DD.TarifaIvp, DD.BaseIvp, DD.IvaIngProd, DD.EsCombo, DD.ItemCombo, DD.Entradas, DD.IvaDetCombo, DD.Mandatario, DD.MandatarioDV, DD.MandatarioTipDoc, DD.Referencia1,CAST('0' AS int) TipoNotaFE,OrigenAdd,
				CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem
				FROM Trn_DevFcr AS D
				JOIN
				(
					--Detalle de devolución Crédito Transporte Especial
					SELECT	R.TipDoc, R.Factura Devolucion, R.IdCia, R.Item, R.CdConcepto AS CodProducto, ISNULL(CD.CodFEDian, R.CdConcepto) AS CodProductoDIAN, ISNULL(CD.Concepto, Descripcion) AS DescripProd, Cantidad AS Cant, VrUnitario, VrDescuento AS VrDctoSal,  R.TarifaDct,
					'94' AS CdUndMed, TipoReg,CAST('0' AS DECIMAL(14,4)) AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(14, 4)) AS VrTasaCamb, CAST('0' AS DECIMAL(14, 4)) AS TarifaIco, CAST('0' AS DECIMAL(14,4)) AS VrImpCon, 
					CAST('0' AS DECIMAL(14, 4)) AS BaseIcoDet, R.TarifaIva AS TarifaIvaDet, R.VrImpuesto AS VrIvaDet, ((R.Cantidad * R.VrUnitario) - R.VrDescuento) AS BaseIvaDet, R.TarifaRet AS  TarifaRetDet, 
					R.VrRetencion AS VrRetDet, R.TarifaIca AS TarifaIcaDet, (case when R.TarifaIca > 0 then (((R.Cantidad * R.VrUnitario) - R.VrDescuento) * (R.TarifaIca / 100)) else CAST('0' AS DECIMAL(14,4)) end)  AS VrIcaDet,
					--R.VrReteIca AS VrIcaDet,
					CAST('0' AS DECIMAL(14,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(14,4))  AS BaseAutoIcaDet,	
					CAST(1 AS BIT) AS ExcluidoImp, CAST('0' AS DECIMAL(14, 4)) AS ImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS ImpGlobal, 
					CAST('0' AS DECIMAL(14, 4)) AS Sobretasa, CAST('0' AS DECIMAL(14, 4)) AS Soldicom, CAST('0' AS DECIMAL(14, 4)) AS TarifaIvp, CAST('0' AS DECIMAL(14, 4)) AS BaseIvp, CAST('0' AS DECIMAL(14, 4)) AS IvaIngProd, 
					CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(14, 4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo, '' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc, Referencia1
					FROM Trn_TraEspFacReservas AS R
					JOIN ConcDiversos AS CD ON R.CdConcepto = CD.IdConcepto
				) AS DD ON D.TipDev = DD.TipDoc AND D.Devolucion = DD.Devolucion AND D.IdCia = DD.IdCia
				JOIN Companias AS C ON D.IdCia = C.IdCia
				JOIN Sys_TiposDoc AS TD ON D.TipDev = TD.IdDoc
				JOIN Terceros AS T ON D.IdCliente = T.IdTercero
				--LEFT JOIN Trn_Face AS FE ON D.TipDev = FE.TipDoc AND D.Devolucion = FE.Documento AND D.IdCia = FE.IdCia
				WHERE D.TipDev = @pmTipDev AND D.Devolucion = @pmDevolucion AND D.IdCia = @pmIdCia
			END
	END
	ELSE IF @pmTipDev IN ('DFO','DO1','DO2','DO3','DO4','DO5')
		SELECT D.TipDev AS TipDoc,  TD.TipoDoc,  D.Devolucion AS NumNota,  D.IdCia, C.Compania, D.Fecha,D.TimeSys, '0' AS IdAgencia, D.VrNeto, D.VrSubTotal, D.VrImpuesto, D.nClieCon AS IdCliente,
		D.Observacion, D.TipDoc AS TipDcm, D.Factura AS Documento, D.IdCiaDoc AS IdCiaDcm, D.ModdDev, D.Modalidad, D.VrImpCons, D.VrRetencion, D.VrReteICA,  D.VrReteIVA,  
		D.VrOtrDcto AS VrOtros, CASE WHEN D.TipCom ='GTC' THEN 0 ELSE VrCargos END VrCargos,  D.VrOtrDcto,  CAST('0' AS DECIMAL(14, 4)) AS VrSobretasa, CAST('0' AS DECIMAL(14, 4)) AS VrImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS VrAnticipos, 
		CAST('0' AS DECIMAL(14, 4)) AS VrImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS VrAplicado, D.Cantidad, D.BaseImp, D.VrSubTotal AS BaseICO, D.BaseRet, 
		D.BaseImp AS BaseIca, D.VrImpuesto AS BaseRiv, CAST('0' AS DECIMAL(14, 4)) AS TarifaIva, CAST('0' AS DECIMAL(14, 4)) AS TarifaRet,
		CAST('0' AS DECIMAL(14, 4)) AS TarifaIca, CAST('0' AS DECIMAL(14, 4)) AS TarifaRiv, CAST('0' AS DECIMAL(14, 4)) AS ETarifaIco, D.TarifaAri, D.VrAutRetIca AS VrAutRetIcaNoTTE,  D.TarifaArf, D.VrAutRetFte,
		--Detalles
		CASE WHEN D.TipCom ='GTC' THEN 1 ELSE K.Item END Item,CASE WHEN D.TipCom ='GTC' THEN '999' ELSE K.IdProducto END AS CodProducto,CASE WHEN D.TipCom ='GTC' THEN '999' ELSE ISNULL(P.CodFEDian, K.IdProducto) END AS CodProductoDIAN, 
		CASE WHEN D.TipCom ='GTC' THEN ('GUIA TRANSPORTE: '+CAST(D.Remision AS varchar)+' '+D.IdCiaRem) ELSE P.DescripProd END AS DescripProd, 
		CASE WHEN D.TipCom ='GTC' THEN CAST(1 AS decimal(12,2)) ELSE K.Entradas END AS Cant,CASE WHEN D.TipCom ='GTC' THEN '94' ELSE ISNULL(UM.CodUMFE, P.UndMed) END AS CdUndMed, 
		CASE WHEN D.TipCom ='GTC' THEN VrNeto ELSE 
		(CASE WHEN  @pmModalidad  = 'INVENTARIO' AND K.ItemCombo > 0 AND K.EsCombo = 0 AND K.EsProdBase > 0  THEN CAST((K.IngBaseCom / K.Entradas) AS decimal(14, 4)) ELSE ISNULL(K.VrPrecio,0) END) END AS VrUnitario, 
		ISNULL(K.VrDctoEnt,0) AS VrDctoSal,  ISNULL(K.TarifaDct,0) TarifaDct, 0 AS TipoReg,ISNULL(K.CantObseq,CAST('0' AS DECIMAL(14,4))) CantObseq, K.CdMoneda, K.VrTasaCamb, ISNULL(K.TarifaIco,0) TarifaIco, ISNULL(K.VrImpCon,0) VrImpCon, 
		(CASE WHEN VrImpCon > 0 THEN ((K.Entradas * K.VrPrecio) - K.VrDctoEnt)  ELSE 0 END) AS BaseIcoDet,ISNULL(K.TarifaIva,0) AS TarifaIvaDet, ISNULL(K.VrIvaEnt,0) AS VrIvaDet,
		ISNULL(((K.Entradas * K.VrPrecio) - K.VrDctoEnt),0) AS BaseIvaDet, ISNULL(K.TarifaRet,0) AS TarifaRetDet, ISNULL(K.VrReteEnt,0) AS VrRetDet, ISNULL(K.TarifaIca,0) AS TarifaIcaDet, ISNULL(K.VrIcaEnt,0) AS VrIcaDet, 
		--Versión 10
		CAST('0' AS DECIMAL(14,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(14,4))  AS BaseAutoIcaDet,
		ISNULL(P.ExcluidoImp,1) ExcluidoImp, CAST('0' AS DECIMAL(14, 4)) AS ImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS ImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS Sobretasa, CAST('0' AS DECIMAL(14, 4)) AS Soldicom,  
		CAST('0' AS DECIMAL(14, 4)) AS TarifaIvp, CAST('0' AS DECIMAL(14, 4)) AS BaseIvp, CAST('0' AS DECIMAL(14, 4)) AS IvaIngProd,ISNULL(K.EsCombo,0) EsCombo, 
		--K.ItemCombo, 
		--Arreglo Colanta
		(CASE WHEN K.EsCombo = 1 AND k.EsProdBase <= 0 THEN 0 ELSE 1 END) AS ItemCombo,
		ISNULL(K.Salidas,0) AS Entradas, ISNULL(P.IvaDetCombo,0) IvaDetCombo, -- Ojo aquí las entradas corresponden a las salidas para los combos porq es una devolución
		(CASE WHEN P.TipoZonaFront = 'IT' THEN  K.CdOperario ELSE '' END) AS Mandatario, TM.Dv AS MandatarioDV, TM.TipoId AS MandatarioTipDoc, K.Referencia AS Referencia1,CAST('0' AS int) TipoNotaFE,OrigenAdd,
		CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem
		--Inforamción de factura electrónica
		--FE.EstadoFE, FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion, FE.RangoNum, FE.FecVigencia, 
		--FE.CUFE_QR AS QR,
		--Otros
		FROM Trn_DevFco AS D
		LEFT JOIN Trn_Kardex AS K ON D.TipDev = K.TipDoc AND D.Devolucion = K.Documento AND D.IdCia = K.IdCia
		LEFT JOIN ProdMcias AS P ON K.IdProducto = P.IdProducto
		LEFT JOIN ProdCombo AS PC ON P.Idproducto = PC.IdProducto
		LEFT JOIN Sys_Um AS UM ON P.UndMed = UM.UndMed
		LEFT JOIN Companias AS C ON D.IdCia = C.IdCia
		LEFT JOIN Sys_TiposDoc AS TD ON D.TipDev = TD.IdDoc
		LEFT JOIN Terceros AS T ON D.nClieCon = T.IdTercero
		LEFT JOIN Terceros AS TM ON K.CdOperario = TM.IdTercero
		LEFT JOIN Trn_Face AS FE ON D.TipDoc = FE.TipDoc AND D.Factura = FE.Documento AND D.IdCia = FE.IdCia
		--LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
		WHERE D.TipDev = @pmTipDev AND D.Devolucion = @pmDevolucion AND D.IdCia = @pmIdCia
	ELSE
		SELECT D.TipDev AS TipDoc,  TD.TipoDoc,  D.Devolucion AS NumNota,  D.IdCia, C.Compania, D.Fecha,D.TimeSys, '0' AS IdAgencia, D.VrNeto, D.VrSubTotal, D.VrImpuesto, D.IdCliente,
		D.Observacion, D.TipDoc AS TipDcm, D.Factura AS Documento, D.IdCiaDoc AS IdCiaDcm, D.ModdDev,  'INTERESES' AS Modalidad, CAST('0' AS DECIMAL(14, 4)) AS VrImpCons, D.VrRetencion, 
		D.VrReteICA,  D.VrReteIVA, D.VrOtrDcto AS VrOtros,  D.VrCargos,  D.VrOtrDcto,  CAST('0' AS DECIMAL(14, 4)) AS VrSobretasa, CAST('0' AS DECIMAL(14, 4)) AS VrImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS VrAnticipos, 
		CAST('0' AS DECIMAL(14, 4)) AS VrImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS VrAplicado, CAST('1' AS DECIMAL(14, 4)) AS Cantidad, D.VrSubTotal AS BaseImp, CAST('0' AS DECIMAL(14, 4)) AS BaseICO, D.VrSubTotal AS BaseRet, 
		D.VrSubTotal AS BaseIca, D.VrImpuesto AS BaseRiv, CAST('0' AS DECIMAL(14, 4)) AS TarifaIva, CAST('0' AS DECIMAL(14, 4)) AS TarifaRet,
		CAST('0' AS DECIMAL(14, 4)) AS TarifaIca, CAST('0' AS DECIMAL(14, 4)) AS TarifaRiv, CAST('0' AS DECIMAL(14, 4)) AS ETarifaIco, D.TarifaAri, D.VrAutRetIca AS VrAutRetIcaNoTTE,  D.TarifaArf, D.VrAutRetFte,
		--Detalles
		DD.Item, DD.IdConcepto AS CodProducto, ISNULL(CD.CodFEDian, DD.IdConcepto) AS CodProductoDIAN, DD.Concepto AS DescripProd, Cantidad AS Cant, '94' AS CdUndMed, DD.VrUnitario, DD.VrDcto AS VrDctoSal, DD.TarifDcto AS TarifaDct,
		0 AS TipoReg,CAST('0' AS DECIMAL(14,4)) AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(14, 4)) AS VrTasaCamb, CAST('0' AS DECIMAL(14, 4)) AS TarifaIco, CAST('0' AS DECIMAL(14, 4)) AS VrImpCon, 
		CAST('0' AS DECIMAL(14, 4)) AS BaseIcoDet, DD.TarifIva AS TarifaIvaDet,  DD.VrIva AS VrIvaDet,  DD.VrTotal AS BaseIvaDet, DD.TarifRet AS TarifaRetDet, DD.VrRetfte AS VrRetDet, DD.TarifIca AS TarifaIcaDet, 
		DD.VrRetica AS VrIcaDet, 
		--Versión 10
		CAST('0' AS DECIMAL(14,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(14,4))  AS BaseAutoIcaDet,
		CAST(0 AS BIT) AS ExcluidoImp,  CAST('0' AS DECIMAL(14, 4)) AS ImpCarbono,  CAST('0' AS DECIMAL(14, 4)) AS ImpGlobal, CAST('0' AS DECIMAL(14, 4)) AS Sobretasa, CAST('0' AS DECIMAL(14, 4)) AS Soldicom,
		CAST('0' AS DECIMAL(14, 4)) AS TarifaIvp, CAST('0' AS DECIMAL(14, 4)) AS BaseIvp, CAST('0' AS DECIMAL(14, 4)) AS IvaIngProd,  CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(14, 4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo,
		'' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc, '' AS Referencia1,CAST('0' AS int) TipoNotaFE,OrigenAdd,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem
		--Inforamción de factura electrónica
		--FE.EstadoFE, FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion, FE.RangoNum, FE.FecVigencia, 
		--FE.CUFE_QR AS QR,
		--Otros
		FROM Trn_FinDevFac AS D
		JOIN Trn_FinFactDet AS DD ON D.TipDoc = DD.TipDoc AND D.Factura = DD.Factura AND D.IdCia = DD.IdCia
		JOIN FinConcFactura AS CD ON DD.IdConcepto = CD.IdConcepto
		JOIN Companias AS C ON D.IdCia = C.IdCia
		JOIN Sys_TiposDoc AS TD ON D.TipDev = TD.IdDoc
		JOIN Terceros AS T ON D.IdCliente = T.IdTercero
		--LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
		WHERE D.TipDev = @pmTipDev AND D.Devolucion = @pmDevolucion AND D.IdCia = @pmIdCia
END
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrAcu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryDevFcrAcu] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
AS
 SELECT IdCliente,IdAgencia,IdCia,SUM(VrNeto) AS STOTNET
 FROM Trn_DevFcr
 WHERE YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes AND DevMasivo<=0 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY  IdCliente,IdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevFcrDoc]  @pmTipDoc VARCHAR(3),@pmFactura INT ,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrNeto
,Modalidad,ModdDev,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevFcr
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcrFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,DF.IdCia AS CdCia,Compania,Fecha,DF.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,DF.TipDoc AS TipoFac,DF.Factura AS NumFactura,IdCiaDoc,FecDoc
,IdCliente,T.RazonSocial AS NomCliente,DF.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrSubTotal,DF.VrDescuento AS VrDcto,DF.VrImpuesto AS VrIva,DF.VrRetencion AS VrRetFte,DF.VrReteICA AS VrRetIca,VrReteIVA
,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,DF.Cantidad AS CantTotal,BaseImp,BaseRet,VrReteCREE,TarifaRtc,CodTarRtc,DF.TarifaArf,DF.VrAutRetFte,DF.TarifaAri,DF.VrAutRetIca AS VrTotalAri
,DF.ImpAviTab,DF.TarifaAvta,DF.VrBomberil,DF.TarifaBom,DF.VrAutRetIat,DF.VrAutRetBom,DF.IdVend AS CdVend,VN.RazonSocial AS Vendedor,TarifaCom,DF.IdLocEnv AS CdLocEnv,LE.Localidad AS CiudadEnvio,Pedido,IdCiaPed,Cotizacion,IdCiaCot
,FecPedido,Modalidad,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom,DF.Observacion AS Observ,TimeSys,IdCiaCrea,DF.IdUsuario AS CdUsuario,Usuario,Leyenda
--detalles
,Item,TipoReg,FechaFact,D.TipRem AS TipRemesa,D.Remesa AS NumRemesa,D.IdCiaRem AS CdCiaRem,ItemRem,Descripcion,D.Cantidad AS Cant,VrUnitario,VrCosto,UndTarifa,UndCosto,Unidades,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,Volumen,UndVol,Cases,Cajas,Palets,CantPago
,D.TarifaIva AS DetTarifIva,D.VrImpuesto AS DetVrIva,TarifaDct,D.VrDescuento AS DetVrDcto,D.TarifaRet AS DetTarifRet,D.VrRetencion AS DetVrRetFte,D.TarifaIca AS DetTarifIca,D.VrReteIca AS DetVrRetIca,VrFaltante,D.Remision AS DetNumRemsion,DocCliente,Referencia1,Referencia2,Referencia3
,CdMercancia,DescripMcia,CdConcepto,CF.Concepto AS DetConcepto,CdCCosto,CCosto,D.CdSubCos AS CdSubCosto,SubCosto,NitTercero,NT.RazonSocial AS DetTercero,CdAgencia,D.pVehiculo AS PlacaVeh,TipoAfiVehic,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.Anulado AS DetAnulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CantidadFalt,UnidadFalt,NumPedRem,CiaPedRem
--Información del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,Autoret,VrCupo,VrSaldo
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_DevFcr AS DF INNER JOIN  Trn_TraFacRemesas AS D ON DF.TipDev=D.TipDoc  AND DF.Devolucion=D.Factura  AND DF.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON DF.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON DF.TipDev=TD.IdDoc
 INNER JOIN  Conceptos AS C ON DF.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON DF.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS VN ON DF.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON DF.IdCliente=T.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  
 INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliente AS CLI ON DF.IdCliente=CLI.IdClie  INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Agencias  AS A ON DF.IdAgencia=A.IdAgencia 
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN  Localidades AS LE ON DF.IdLocEnv=LE.IdLocal   LEFT JOIN TiposCom AS TCM ON DF.TipCom=TCM.IdCom  
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN Mercancias AS MC ON D.CdMercancia=MC.IdMercancia LEFT JOIN  ConcDiversos AS CF ON D.CdConcepto=CF.IdConcepto
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero
 LEFT JOIN Trn_Face AS FE ON DF.TipDev=FE.TipDoc AND DF.Devolucion=FE.Documento AND DF.IdCia=FE.IdCia
 WHERE DF.TipDev=@pmTipDev AND DF.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DF.IdCia=@pmIdCia
 ORDER BY  DF.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrFmtb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcrFmtb] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDev,TipoDoc,D.Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipFact,D.Factura AS NumFactura
,D.IdCiaDoc,D.FecDoc,D.IdCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrRetencion
,D.VrReteICA,D.VrReteIVA,D.VrFletes,D.VrOtros,D.VrCargos,D.VrOtrDcto,D.VrCostos,D.VrImpCarbono,D.VrIvaIngProd,D.VrNeto,D.Cantidad AS CantTotal,D.BaseImp,D.BaseRet,D.BaseIvaIgp
,D.VrReteCREE,D.TarifaRtc,D.CodTarRtc,D.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,D.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,D.IdVend AS NitVend,VN.RazonSocial AS Vendedor
,D.TarifaCom,D.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,Pedido,IdCiaPed,D.Remision,D.IdCiaRem
,D.FecPedido,D.Modalidad,D.ModdDev,D.PlacaVehic,D.ZonaFrontera,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.CdMotDev,MotivoDev
,D.TipCom,TipoCom,D.Comprobante,D.IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,D.IdCiaCrea,D.IdUsuario,Usuario,D.OrigenAdd
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DT.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,ExcIva,Autoret,VrCupo,VrSaldo
--Detalles
,DP.Item,DP.IdTanque,DP.IdProducto,PM.DescripProd,DP.Descripcion,DP.Cantidad,DP.UndMed,UM.Unidad,DP.VrUnitario,DP.TarifaDct,DP.VrDcto,DP.TarifaIva,DP.VrIva,DP.TarifaRet,DP.VrRetFte,DP.VrBaseRet,DP.TarifaIca,DP.VrRetIca,DP.FleteUnd,DP.CostoUnit
,DP.ItemDet,DP.TipoProd,DP.TipGuia,DP.NumGuia,DP.IdCiaGuia,DP.ItemGuia,DP.CantGuia,DP.IndMezcla,DP.ItemMezcla,DP.FactorMezcla,DP.CodTarIva,DP.CodTarDct,DP.CodTarRet,DP.CodTarIca,DP.CodSicomPro,DP.CodBodega,Bodega
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_DevFcr AS D INNER JOIN Trn_OilDevFacProd AS DP ON D.TipDev=DP.TipDev AND D.Devolucion=DP.Devolucion AND D.IdCia=DP.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero INNER JOIN Agencias AS A ON D.IdAgencia=A.IdAgencia
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DT ON L.IdDep=DT.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON DP.IdProducto=PM.IdProducto INNER JOIN Sys_Um AS UM ON DP.UndMed=UM.UndMed
 LEFT JOIN Localidades AS LE ON D.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos 
 LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom LEFT JOIN TiposMotdev AS MD ON D.CdMotDev=MD.IdMotDev
 LEFT JOIN Tanques AS TQ ON DP.IdTanque=TQ.IdTanque  LEFT JOIN Bodegas AS B ON DP.CodBodega=B.IdBodega
 LEFT JOIN Trn_Face AS FE ON D.TipDev=FE.TipDoc AND D.Devolucion=FE.Documento AND D.IdCia=FE.IdCia
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 AND DP.IndMezcla<>2
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcrLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrImpCarbono,VrIvaIngProd,VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,BaseIvaIgp,IdCCosto,IdSubCos
,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,IdLocEnv,Pedido,IdCiaPed,Remision,IdCiaRem,Cotizacion,IdCiaCot,FecPedido,PlacaVehic,KmtVehic,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,ImpAviTab,TarifaAvta,VrBomberil,TarifaBom,VrAutRetIat,VrAutRetBom,DevMasivo,NumRecibo,CdCiaRec,Modalidad,ModdDev,ZonaFrontera,CdMotDev,D.OrigenAdd
,D.TipCom,D.Comprobante,D.IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,TipDev
 FROM Trn_DevFcr AS D INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND ModdDev LIKE ISNULL(@pmModdDev,'%') 
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcrRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente
,D.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos
,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,D.VrImpCarbono,VrFaltantes,VrAnticipos,VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,D.IdCCosto AS IdCenCost,CCosto,D.IdSubCos AS IdSubCent,SubCosto
,D.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,D.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,Pedido,IdCiaPed,Remision,IdCiaRem,Cotizacion,IdCiaCot,FecPedido,PlacaVehic,KmtVehic,Modalidad,ModdDev,ZonaFrontera,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,D.ImpAviTab,D.TarifaAvta,D.VrBomberil,D.TarifaBom,D.VrAutRetIat,D.VrAutRetBom,DevMasivo,NumRecibo,CdCiaRec,D.CdMotDev
,MotivoDev,D.OrigenAdd,D.TipCom,D.Comprobante,D.IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,CdFntePago,FuentePago
 FROM Trn_DevFcr AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS VN ON D.IdVend=VN.IdTercero INNER JOIN Agencias  AS A ON D.IdAgencia=A.IdAgencia 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON D.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN TiposMotdev AS MD ON D.CdMotDev=MD.IdMotDev
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipDev LIKE ISNULL(@pmTipDev ,'%') 
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND D.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrRelTra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcrRelTra] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT DF.TipDev,DF.Devolucion,DF.IdCia AS CdCia,Compania,DF.Fecha,DF.IdConcepto AS CdConcepto,C.Concepto AS ConcDesc,DF.TipDoc AS TipoFac,DF.Factura AS NumFactura,DF.IdCiaDoc,DF.FecDoc,DF.IdCliente,T.RazonSocial AS NomCliente
,DF.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,DF.VrSubTotal,DF.VrDescuento AS VrDcto,DF.VrImpuesto AS VrIva,DF.VrRetencion AS VrRetFte,DF.VrReteICA AS VrRetIca,DF.VrReteIVA,DF.VrFletes,DF.VrOtros,DF.VrCargos
,DF.VrOtrDcto,DF.VrCostos,DF.VrSobretasa,DF.VrImpGlobal,DF.VrFaltantes,DF.VrAnticipos,DF.VrNeto,DF.Cantidad AS CantTotal,DF.CantPuntos,DF.BaseImp,DF.BaseRet,DF.VrImpCons AS VrAutoICA,DF.ZonaFrontera AS EstAutoICA
,DF.IdVend AS NitVend,VN.RazonSocial AS Vendedor,DF.TarifaCom,DF.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DF.Pedido,DF.IdCiaPed,DF.Cotizacion,DF.IdCiaCot,DF.FecPedido,DF.VrReteCREE,DF.TarifaRtc,DF.CodTarRtc,DF.ImpAviTab,DF.TarifaAvta,DF.VrBomberil,DF.TarifaBom,DF.VrAutRetIat,DF.VrAutRetBom,DF.Modalidad,F.TipoOperTra,DF.ModdDev,DF.OrigenAdd,DF.TipCom,DF.Comprobante,DF.IdCiaCom,DF.Observacion AS Observ,DF.IdEstado AS CdEstado
,DF.TimeSys,DF.IdCiaCrea,DF.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_DevFcr AS DF INNER JOIN Trn_Facturas AS F ON DF.TipDoc=F.TipDoc AND DF.Factura=F.Factura AND DF.IdCiaDoc=F.IdCia
 INNER JOIN Companias AS CN ON DF.IdCia=CN.IdCia INNER JOIN Terceros AS T ON DF.IdCliente=T.IdTercero 
 INNER JOIN Conceptos AS C ON DF.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON DF.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS VN ON DF.IdVend=VN.IdTercero INNER JOIN Agencias AS A ON DF.IdAgencia=A.IdAgencia 
 INNER JOIN TercCliente AS CLI ON DF.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LE ON DF.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
 WHERE  DF.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  DF.TipDev LIKE ISNULL(@pmTipDev,'%')
 AND DF.IdCia LIKE ISNULL(@pmIdCia,'%%') AND DF.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND DF.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND DF.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY DF.IdCia,DF.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFcrRelTraDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFcrRelTraDet] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT DF.TipDev,DF.Devolucion,DF.IdCia AS CdCia,Compania,DF.Fecha,DF.IdConcepto AS CdConcepto,C.Concepto AS ConcDesc,DF.TipDoc AS TipoFac,DF.Factura AS NumFactura,DF.IdCiaDoc,DF.FecDoc,DF.IdCliente,T.RazonSocial AS NomCliente
,DF.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,DF.VrSubTotal,DF.VrDescuento AS VrDcto,DF.VrImpuesto AS VrIva,DF.VrRetencion AS VrRetFte,DF.VrReteICA AS VrRetIca,DF.VrReteIVA,DF.VrFletes,DF.VrOtros,DF.VrCargos
,DF.VrOtrDcto,DF.VrCostos,DF.VrSobretasa,DF.VrImpGlobal,DF.VrFaltantes,DF.VrAnticipos,DF.VrNeto,DF.Cantidad AS CantTotal,DF.CantPuntos,DF.BaseImp,DF.BaseRet
,DF.IdVend AS NitVend,VN.RazonSocial AS Vendedor,DF.TarifaCom,DF.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DF.Pedido,DF.IdCiaPed,DF.Cotizacion,DF.IdCiaCot,DF.FecPedido,DF.VrReteCREE,DF.TarifaRtc,DF.CodTarRtc,DF.VrImpCons AS VrAutoICA,DF.ZonaFrontera AS EstAutoICA,DF.ImpAviTab,DF.TarifaAvta,DF.VrBomberil,DF.TarifaBom,DF.VrAutRetIat,DF.VrAutRetBom
,DF.Modalidad,F.TipoOperTra,DF.ModdDev,DF.OrigenAdd,DF.TipCom,DF.Comprobante,DF.IdCiaCom,DF.Observacion AS Observ,DF.IdEstado AS CdEstado
,DF.TimeSys,DF.IdCiaCrea,DF.IdUsuario AS IdUsuari,Usuario
--detalles
,Item,TipoReg,FechaFact,D.TipRem AS TipRemesa,D.Remesa AS NumRemesa,D.IdCiaRem AS CdCiaRem,ItemRem,FecRemesa,Descripcion,D.Cantidad AS Cant,VrUnitario,VrCosto,UndTarifa,UndCosto,Unidades,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,Volumen,UndVol,Cases,Cajas,Palets,CantPago
,D.TarifaIva AS DetTarifIva,D.VrImpuesto AS DetVrIva,TarifaDct,D.VrDescuento AS DetVrDcto,D.TarifaRet AS DetTarifRet,D.VrRetencion AS DetVrRetFte,D.TarifaIca AS DetTarifIca,D.VrReteIca AS DetVrRetIca,D.VrAutRetIca AS DetAutoICA,VrFaltante,D.Remision AS DetNumRemsion,DocCliente,Referencia1,Referencia2,Referencia3
,CdMercancia,DescripMcia,CdConcepto,CF.Concepto AS DetConcepto,CdCCosto,CCosto,D.CdSubCos AS CdSubCosto,SubCosto,NitTercero,NT.RazonSocial AS DetTercero,CdAgencia,D.pVehiculo AS PlacaVeh,TipoAfiVehic,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.Anulado AS DetAnulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CantidadFalt,UnidadFalt,NumPedRem,CiaPedRem
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_DevFcr AS DF INNER JOIN Trn_Facturas AS F ON DF.TipDoc=F.TipDoc AND DF.Factura=F.Factura AND DF.IdCiaDoc=F.IdCia
 INNER JOIN Trn_TraFacRemesas AS D ON DF.TipDev=D.TipDoc AND DF.Devolucion=D.Factura  AND DF.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON DF.IdCia=CN.IdCia INNER JOIN Terceros AS T ON DF.IdCliente=T.IdTercero 
 INNER JOIN Conceptos AS C ON DF.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON DF.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS VN ON DF.IdVend=VN.IdTercero INNER JOIN Agencias  AS A ON DF.IdAgencia=A.IdAgencia 
 INNER JOIN TercCliente AS CLI ON DF.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN Localidades AS LE ON DF.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN Mercancias AS MC ON D.CdMercancia=MC.IdMercancia LEFT JOIN  ConcDiversos AS CF ON D.CdConcepto=CF.IdConcepto
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero
 WHERE DF.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  DF.TipDev LIKE ISNULL(@pmTipDev,'%')
 AND DF.IdCia LIKE ISNULL(@pmIdCia,'%%') AND DF.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND DF.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND DF.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY DF.IdCia,DF.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevFvc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento
,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca
,IdVend,TarifaCom,CodTarCom,ModdDev,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_DevFvc
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvc_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFvc_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDev,F.IdConcepto AS CdConcepto,Concepto,F.TipDoc AS TipFact,F.Factura AS NumFactura
,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca
,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,F.CodTarCom AS CdTarifCom,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom
,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,OrigenAdd,F.TimeSys AS Fecha_Add,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,Entradas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm
,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,VrBruto,K.Referencia AS KarReferencia,Descripcion
,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarRemision,K.IdCiaRem AS KarCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev,Unidades,CodTarCmc,pVehiculo
,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,Referencia2
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_DevFvc AS F INNER JOIN Trn_Kardex AS K ON F.TipDev=K.TipDoc AND F.Devolucion=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON F.TipDev=TD.IdDoc
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TCM ON F.TipCom=TCM.IdCom
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND F.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY F.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFvcDoc]  @pmTipDoc VARCHAR(3),@pmFactura INT ,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia
,VrNeto,ModdDev,TipCom,Comprobante,IdCiaCom
 FROM  Trn_DevFvc
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY Devolucion,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFvcLta]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null, @pmDevolucionFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT TipDev,Devolucion,F.IdCia AS CdCia,Compania,Fecha,F.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,Agencia
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrCostos,VrNeto,BaseImp,BaseRet,BaseIca,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca
,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,TipCom,TipoCom,Comprobante,IdCiaCom
, ModdDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,OrigenAdd,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 FROM Trn_DevFvc AS F INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario  INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON F.TipCom=TC.IdCom
 WHERE Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND (Devolucion>=ISNULL(@pmDevolucionIni,0)  AND Devolucion<=ISNULL(@pmDevolucionFin,2147483647))
 AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY F.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcNMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFvcNMes] @pmAnno INT,@pmMes INT=Null,@pmIdCia CHAR(2)=Null,@pmIdPropietario VARCHAR(16)=Null
,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT  VC.IdCliente AS NitCliente,VC.IdVehiculo AS PlacaVeh,D.IdCia AS CodCia,Month(Fecha) AS nMes,SUM(ValorFactura) AS SValNet
 FROM  Trn_DevFvc AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Factura=VC.Documento AND D.IdCiaDoc=VC.IdCia
 WHERE Year(Fecha)=@pmAnno AND  Month(Fecha)=ISNULL(@pmMes, Month(Fecha))
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND VC.IdCliente LIKE ISNULL(@pmIdPropietario,'%')
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 GROUP BY VC.IdCliente,VC.IdVehiculo,D.IdCia,Month(Fecha)
GO
/****** Object:  StoredProcedure [dbo].[paQryDevFvcVFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevFvcVFec]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdPropietario VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null 
AS
 SELECT VC.IdCliente AS NitCliente,VC.IdVehiculo AS IdVehic,SUM(ValorFactura) AS SValNet
 FROM  Trn_DevFvc AS D INNER JOIN Trn_CausacVence AS VC ON D.TipDoc=VC.TipDoc AND D.Factura=VC.Documento AND D.IdCiaDoc=VC.IdCia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  
 AND VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND VC.IdCliente LIKE ISNULL(@pmIdPropietario,'%')
 GROUP BY VC.IdCliente,VC.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNpr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevNpr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumNota,IdCiaDoc,FecDoc,IdTercero,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden
,IdCCosto,IdSubCos,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevNpr
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNpr_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevNpr_Cr]   @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipNota,NumNota,IdCiaDoc,FecDoc
,D.IdTercero AS NitTercero,RazonSocial,VrSubTotal,VrCostos,CantEnt,CantSal,D.NumOrden AS NroOrden,D.IdCCosto AS IdCenCosto,CC.CCosto AS NomCentCosto
,D.IdSubCos AS CodSubCentro,SC.SubCosto AS NomSubCentro,Modalidad,ModdDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,Leyenda
--INFORMACION DEL TERCERO
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
--DETALLES
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,VrReteEnt,VrReteSal,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,pVehiculo,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,K.NumOrden AS KarNumOrden,IdCiaOrd,Cotizacion,IdCiaCot
,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_DevNpr AS D  INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd  
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 WHERE  TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNprDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevNprDoc] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumNota,IdCiaDoc,FecDoc,IdTercero,VrSubTotal,VrCostos
,NumOrden,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevNpr
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNprLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevNprLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmNumNotaIni INT=Null,@pmNumNotaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,NumNota,IdCiaDoc,FecDoc,D.IdTercero AS NitTercero,RazonSocial,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden
,D.IdCCosto AS IdCenCosto,CCosto,IdSubCos,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
 FROM Trn_DevNpr AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND NumNota BETWEEN ISNULL(@pmNumNotaIni,0) AND ISNULL(@pmNumNotaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevNprRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevNprRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,NumNota,IdCiaDoc,FecDoc
,D.IdTercero AS NitTercero,RazonSocial,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden,D.IdCCosto AS IdCenCosto,CCosto
,D.IdSubCos AS CodSubCentro,SubCosto,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--INFORMACION DEL TERCERO
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
 FROM Trn_DevNpr AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 WHERE  TipDev=@pmTipDev AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND D.IdCCosto LIKE ISNULL(@pmIdCCosto ,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPas] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,nNota,IdCiaDoc,FecDoc,NitTercero,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto,Cantidad,IdCajero
,IdVend,TarifaCom,CodTarCom,IdCCosto,IdSubCos,Referencia,ModdDev,NumAutoriza,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevPas
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPas_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPas_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipoNota,nNota,IdCiaDoc,FecDoc
,NitTercero,T.RazonSocial AS NomCliente,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto
,Cantidad,IdCajero,UC.Usuario AS UsuCajero,D.IdVend AS NitVendedor,V.RazonSocial AS NomVendedor,TarifaCom,D.Referencia AS DocReferencia,ModdDev,NumAutoriza,OrigenAdd
,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,D.TimeSys AS Fec_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,CCosto,CdSubCos,SubCosto,pVehiculo,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd
,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,CdMngra,NumInicial,NumFinal
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_DevPas AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN  Conceptos AS CNC ON D.IdConcepto=CNC.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN  Terceros AS V ON D.IdVend=V.IdTercero  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero  LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPasDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPasDoc] @pmTipDoc VARCHAR(3),@pmnNota  INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,nNota,IdCiaDoc,FecDoc,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevPas
 WHERE TipDoc=@pmTipDoc  AND  nNota=@pmnNota   AND  IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPasLta]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmnNotaIni INT=Null,@pmnNotaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmCdJornada VARCHAR(4)=Null
,@pmNitTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmModdDev VARCHAR(10)=Null 
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,nNota,IdCiaDoc,FecDoc,NitTercero,T.RazonSocial AS NomCliente,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto
,Cantidad,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,IdCCosto,IdSubCos,Referencia,ModdDev,NumAutoriza,OrigenAdd
,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev
 FROM Trn_DevPas AS D INNER JOIN  Terceros AS T ON D.NitTercero=T.IdTercero
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND nNota BETWEEN ISNULL(@pmnNotaIni,0) AND ISNULL(@pmnNotaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND CdJornada LIKE ISNULL(@pmCdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')  AND NitTercero LIKE ISNULL(@pmNitTercero,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%')  AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPla] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Planilla,IdCiaDoc,FecDoc,NitTercero,IdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos
,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero
,IdVend,TarifaCom,CodTarCom,NitRef,IdCCosto,IdSubCos,Referencia,Modalidad,FecCorte,NumCorte,ModdDev,NumAutoriza,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevPla
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPla_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPla_Cr]  @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipPla,Planilla,IdCiaDoc,FecDoc
,NitTercero,T.RazonSocial AS NomCliente,D.IdJornada AS CdJornada,Jornada,VrSubTotal,VrSobretasa,VrImpGlobal
,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal
,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,UC.Usuario AS UsuCajero
,D.IdVend AS NitVendedor,VN.RazonSocial AS NomVendedor,TarifaCom,NitRef,D.Referencia AS DocReferencia,Modalidad,FecCorte,NumCorte,ModdDev
,NumAutoriza,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,D.TimeSys AS Fec_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,CCosto,CdSubCos,SubCosto,pVehiculo,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd
,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,K.IdVend AS KarNitVend,KV.RazonSocial AS KarVendedor,Comision,CdOperario,KO.RazonSocial AS NomOperario,ComisnOper,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,CdMngra,NumInicial,NumFinal
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_DevPla  AS D  INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN  Conceptos AS CNC ON D.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON D.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario INNER JOIN  Terceros AS VN ON D.IdVend=VN.IdTercero
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero  LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN Terceros AS KV ON K.IdVend=KV.IdTercero  LEFT JOIN Terceros AS KO ON K.CdOperario=KO.IdTercero
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin  AND D.IdCia=@pmIdCia
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPlaDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPlaDoc] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Planilla,IdCiaDoc,FecDoc,NitTercero,IdJornada,VrSubTotal,VrNeto
,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevPla
 WHERE TipDoc=@pmTipDoc AND Planilla=@pmPlanilla  AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPlaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPlaLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmPlanillaIni INT=Null,@pmPlanillaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdJornada VARCHAR(4)=Null
,@pmNitTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmModdDev VARCHAR(10)=Null 
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Planilla,IdCiaDoc,FecDoc,NitTercero,T.RazonSocial AS NomCliente,D.IdJornada AS CdJornada,Jornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb
,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,NitRef,IdCCosto,IdSubCos,Referencia,Modalidad
,FecCorte,NumCorte,ModdDev,NumAutoriza,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev
 FROM Trn_DevPla  AS D INNER JOIN  Terceros AS T ON D.NitTercero=T.IdTercero
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN Jornadas AS J ON D.IdJornada=J.IdJornada
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND Planilla BETWEEN ISNULL(@pmPlanillaIni,0) AND ISNULL(@pmPlanillaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND D.IdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')  AND NitTercero LIKE ISNULL(@pmNitTercero,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')  AND IdVend LIKE ISNULL(@pmIdVend,'%')  
 AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPlaRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPlaRel]  @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdJornada VARCHAR(4)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Planilla,IdCiaDoc,FecDoc
,NitTercero,T.RazonSocial AS NomCliente,D.IdJornada AS CdJornada,Jornada,VrSubTotal,VrSobretasa,VrImpGlobal
,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal
,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,UC.Usuario AS UsuCajero
,D.IdVend AS NitVendedor,VN.RazonSocial AS NomVendedor,TarifaCom,NitRef,D.Referencia AS DocReferencia,Modalidad,FecCorte,NumCorte,ModdDev
,NumAutoriza,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_DevPla  AS D   INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia
 INNER JOIN  Conceptos AS CNC ON D.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON D.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario INNER JOIN  Terceros AS VN ON D.IdVend=VN.IdTercero
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero 
 WHERE TipDev=@pmTipDev AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdJornada LIKE ISNULL(@pmIdJornada,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevPrestamos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Prestamo,IdCiaDoc,FecDoc,FechaPrest,TipoPlazo,NumCuotas,TipoCuota,IdVehiculo,IdPropietario,IdConductor,VehPropio,ValorTotal,TasaInteres,CxPagar,Factura,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_DevPrestamos
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPrestamos_Cr] @pmTipDev VARCHAR(3), @pmDevolucionIni INT=Null, @pmDevolucionFin INT=Null, @pmIdCia CHAR(2)=Null
 AS
 SELECT   TipDev,TipoDoc,Devolucion, D.IdCia AS CodCia,Compania, Fecha, D.IdConcepto AS IdConcept,Concepto,TipDoc, Prestamo, IdCiaDoc, FecDoc, FechaPrest, TipoPlazo, NumCuotas, TipoCuota, D.IdVehiculo AS PlacaVeh
,D.IdPropietario AS NitPropietario, D.IdConductor AS CedConductor, D.VehPropio AS VhPropio, ValorTotal, TasaInteres, CxPagar, Factura, TipCom,TipoCom, Comprobante
, IdCiaCom, D.Observacion AS Observ,D.IdEstado AS IdEstad,ED.Estado AS EstadDoc,TimeSys,IdCiaCrea, D.IdUsuario AS IdUsuari,Usuario
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM   Trn_DevPrestamos AS D INNER JOIN Sys_TiposDoc  AS TD ON D.TipDev=TD.IdDoc   INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa    LEFT JOIN TiposCom AS TM ON D.TipCom=TM.IdCom
   LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal 
 LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
   WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni  AND  @pmDevolucionFin
  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamos_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPrestamos_Crr]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmTipoPlazo VARCHAR(10)=Null,@pmTipoCuota VARCHAR(10)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmPrestamo INT=Null,@pmFechaPrest SMALLDATETIME=Null
 AS
 SELECT   Devolucion, D.IdCia AS CodCia,Compania, Fecha, D.IdConcepto AS IdConcept,Concepto,TipDoc, Prestamo, IdCiaDoc, FecDoc, FechaPrest, TipoPlazo, NumCuotas, TipoCuota, D.IdVehiculo AS PlacaVeh
,D.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario, D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor, D.VehPropio AS VhPropio, ValorTotal, TasaInteres, CxPagar, Factura, TipCom,TipoCom, Comprobante
, IdCiaCom, D.Observacion AS Observ,D.IdEstado AS IdEstad,ED.Estado AS EstadDoc, D.IdUsuario AS IdUsuari,Usuario,TipDev,TipoDoc,TimeSys,IdCiaCrea
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM   Trn_DevPrestamos AS D INNER JOIN Sys_TiposDoc  AS TD ON D.TipDev=TD.IdDoc   INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa   LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN TiposCom AS TM ON D.TipCom=TM.IdCom
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
  AND TipoPlazo LIKE ISNULL(@pmTipoPlazo,'%') AND TipoCuota LIKE ISNULL(@pmTipoCuota,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND D.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (Prestamo>=ISNULL(@pmPrestamo,0)  AND Prestamo<=ISNULL(@pmPrestamo,2147483647))
 AND (FechaPrest>=ISNULL(@pmFechaPrest,CAST('19100101' AS SMALLDATETIME)) AND FechaPrest<=ISNULL(@pmFechaPrest,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevPrestamosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevPrestamosLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS
 SELECT  Devolucion, IdCia, Fecha, D.IdConcepto AS IdConcept,Concepto,TipDoc,Prestamo, IdCiaDoc, FecDoc, FechaPrest, TipoPlazo, NumCuotas, TipoCuota, D.IdVehiculo AS PlacaVeh,NumVeh
,D.IdPropietario AS NitPropietario, T.RazonSocial AS Propietario,D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor, D.VehPropio AS VhPropio, ValorTotal, TasaInteres, CxPagar, Factura
, TipCom, Comprobante, IdCiaCom, D.Observacion AS Observ, D.IdEstado AS IdEstad,Estado,TimeSys,IdCiaCrea, D.IdUsuario AS IdUsuari,Usuario
 FROM   Trn_DevPrestamos AS D  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto 
 INNER JOIN Terceros AS T ON D.IdPropietario=T.IdTercero INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
 INNER JOIN  EstadoDoc AS E ON D.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE TipDev=@pmTipDev AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND IdCia like ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,IdAgencia,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo
,VrEfectivo,BaseRet,BaseIca,BaseRiv,IdCCosto,IdSubCos,IdCajero,IdVend,TarifaCom,CodTarCom,IdLocal,EnEfectivo,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,NumAutoriza,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom
,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevRec
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRec_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRec_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc ,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS Tip_Rec
,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS  IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo
,VrEfectivo,BaseRet,BaseIca,BaseRiv,D.IdCCosto AS IdCenCost,CCosto,D.IdSubCos AS IdSubCent,SubCosto
,IdCajero,UC.Usuario AS NomCajero,D.IdVend AS NitVendedor,V.RazonSocial AS Vendedor,TarifaCom,D.IdLocal AS CdCiudadRec,LR.Localidad AS CiudadRecibo
,EnEfectivo,D.Referencia AS DocReferncia,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,TipDcm,D.Documento AS NumDoc,IdCiaDcm
,VrReteCREE,TarifaRtc,CodTarRtc,D.VrBomberil,D.TarifaBom,D.CodTarifBom,D.ImpAviTab,D.TarifaAvta,D.CodTarifAvta,D.NumAutoriza AS NAutoriza,D.Modalidad,D.ModdDev
,D.OrigenAdd,D.TipCom,TipoCom,D.Comprobante,D.IdCiaCom,D.Observacion AS Observ
,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario,Leyenda
--detalle de pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco,NitCliente,PC.RazonSocial AS NomCliente
,CdAgencia,PA.Agencia AS PagNomAgencia,PA.CodAgencia AS PagCodAgencia,PA.Referencia AS PagRefeAgencia,P.NumForma AS PagNumForma,FecForma,CtaForma,Beneficiario,Referncia1
,P.Referncia2 AS PagReferencia2,CdLocal,LF.Localidad AS CiudadPlaza,P.NumAutoriza AS PagAutorizacion,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_DevRec AS D  INNER JOIN Trn_Pagos AS P ON D.TipDev=P.TipDoc AND D.Devolucion=P.Documento AND D.IdCia=P.IdCia
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero  INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN Agencias  AS A ON D.IdAgencia=A.IdAgencia
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LR ON D.IdLocal=LR.IdLocal LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom
 LEFT JOIN Terceros AS TC ON D.CdConductor=TC.IdTercero
 LEFT JOIN Terceros AS PC ON P.NitCliente=PC.IdTercero  LEFT JOIN Agencias  AS PA ON P.CdAgencia=PA.IdAgencia
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal 
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecAcu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryDevRecAcu] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT IdCliente,IdAgencia,IdCia,SUM(VrNeto) AS STOTNET
 FROM Trn_DevRec
 WHERE YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY  IdCliente,IdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBuses] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)

AS
 SELECT    TipDev, Devolucion, IdCia, Fecha, IdConcepto, TipDoc, Recibo, IdCiaDoc, FecDoc, IdCliente, IdAgencia, IdVehiculo, IdConductor, VehPropio, Modalidad, 
                      ValorRecibido, ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorOtrosDct, ValorPagMas,ValorAhorro,ValorOConce, ValorNeto, ValorAplicado, 
                      ValorAnticipo, IdVendedor, Comision, IdTarCom, IdCta, EnEfectivo, NumCheque, IdBanco, EsParcial, IdClase, TipCom, Comprobante, IdCiaCom, 
                      Observacion, IdEstado, TimeSys, IdCiaCrea, IdUsuario
 FROM     Trn_DevRecBuses
 WHERE TipDev=@pmTipDev AND Devolucion= @pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBuses_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBuses_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)

AS
 SELECT D.TipDev AS IdTipoDev,TD.TipoDoc AS TipoDev, D.Devolucion AS NDevolucion, D.IdCia AS CodCia,Compania, D.Fecha AS FechaDev, D.IdConcepto AS IdConcept, CC.Concepto AS ConceptoDev,D.TipDoc AS IdTipoDoc,TDC.TipoDoc AS TipoRecibo, D.Recibo AS nRecibo
, D.IdCiaDoc AS IdCiaRecibo, FecDoc, D.IdCliente AS NitPropietario,NP.RazonSocial AS Propietario, D.IdAgencia, D.IdVehiculo AS PlacaVeh, D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor, D.VehPropio AS VehEsPropio, D.Modalidad,D.ValorRecibido, D.ValorTotal, D.ValorDcto, D.ValorReteFte
, D.ValorReteIva, D.ValorReteIca, D.ValorOtros, D.ValorOtrosDct, D.ValorPagMas,ValorAhorro,ValorOConce, D.ValorNeto, D.ValorAplicado,D.ValorAnticipo, D.IdVendedor,D.Comision, D.IdTarCom, D.IdCta AS CodCta, D.EnEfectivo, D.NumCheque, D.IdBanco AS CodBanco,Banco, EsParcial, D.TipCom AS IdTipoCom,TM.TipoCom AS TipoComprobante
,D.Comprobante, D.IdCiaCom,D.Observacion AS Observ, D.IdEstado AS IdEstadDev,ED.Estado AS EstadoDev,D.TimeSys, D.IdCiaCrea, D.IdUsuario AS IdUsuari,Usuario,TD.Leyenda
,TipCar,Cartulina,IdCiaCar,R.CentInicial AS CenInicial,R.CentFinal AS CenFinal,ValorPasaje
,Item,RF.TipDoc AS TipoFactura,Documento,RF.IdCiaDoc AS CiaFactura,ItemDoc,RF.IdCargo AS CodCargo,F.Concepto AS Cargo,RF.IdClase AS CodClase,ClaseCuenta,RF.ValorAbono AS ValorAbonado,RF.Devolucion AS ValorDevolucion,Descuento,Detalle,FecPago
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,V.CentInicial AS VehCentInicial,V.CentFinal AS VehCentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM   Trn_DevRecBuses  AS D INNER JOIN Sys_TiposDoc  AS TD ON D.TipDev=TD.IdDoc  INNER JOIN Sys_TiposDoc  AS TDC ON D.TipDoc=TDC.IdDoc 
 INNER JOIN Trn_RecBuses AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia  INNER JOIN Conceptos AS CC ON D.IdConcepto=CC.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON  D.IdUsuario=U.IdUsuario
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS NP ON D.IdCliente=NP.IdTercero
 INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero  INNER JOIN Bancos AS B ON D.IdBanco=B.IdBanco
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa    LEFT JOIN TercCndtores AS CT ON D.IdVendedor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN Trn_RecFactura AS RF ON D.TipDev=RF.TipRec AND D.Devolucion=RF.Recibo AND D.IdCia=RF.IdCia
 LEFT JOIN Fijos AS F ON RF.IdCargo=F.IdCargo  LEFT JOIN BusClaseCue  AS CU ON RF.IdClase=CU.IdClase
 LEFT JOIN TiposCom AS TM ON D.TipCom=TM.IdCom
 WHERE TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin 
  AND D.IdCia=@pmIdCia 
 ORDER BY D.IdCia,D.Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBuses_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBuses_Crr] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmRecibo INT=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null,@pmIdUsuario VARCHAR(11)=Null
AS
 SELECT TipDev,Devolucion,D.IdCia AS CodCia,Compania, D.Fecha AS FechaDev,D.TipDoc AS IdTipoRec,D.Recibo AS nRecibo,IdCiaDoc,FecDoc,D.IdCliente AS NitPropietario,NP.RazonSocial AS Propietario,D.IdVehiculo AS PlacaVeh
,D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor, D.VehPropio AS VehEsPropio, D.Modalidad AS Modaldad,D.ValorRecibido, D.ValorTotal, D.ValorDcto, D.ValorReteFte, D.ValorReteIva, D.ValorReteIca, D.ValorOtros, D.ValorOtrosDct, D.ValorPagMas
,ValorAhorro,ValorOConce, D.ValorNeto AS VrNeto, D.ValorAplicado,D.ValorAnticipo,D.IdConcepto AS IdConcept,Concepto,D.IdCta AS CodCta, D.EnEfectivo AS Efectivo,D.NumCheque, D.IdBanco AS CodBanco,Banco,D.TipCom AS IdTipoCom,TipoCom,D.Comprobante
,D.IdCiaCom,D.Observacion AS Observ, D.IdEstado AS IdEstadDev,ED.Estado AS EstadoDev,D.TimeSys AS FechaAdd, D.IdCiaCrea AS IdCiaCre, D.IdUsuario AS IdUsuari,Usuario,TipoDoc,TipCar,Cartulina,IdCiaCar,R.CentInicial AS CenInicial,R.CentFinal AS CenFinal,ValorPasaje
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,V.CentInicial AS VehCentInicio,V.CentFinal AS VehCentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
 INNER JOIN Sys_TiposDoc  AS TD ON D.TipDev=TD.IdDoc  INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Conceptos AS CC ON D.IdConcepto=CC.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON  D.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NP ON D.IdCliente=NP.IdTercero  INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero
 INNER JOIN Bancos AS B ON D.IdBanco=B.IdBanco  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON  D.IdVendedor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN TiposCom AS TM ON D.TipCom=TM.IdCom
  WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  TipDev=@pmTipDev AND D.IdCia like ISNULL(@pmIdCia,'%%')
  AND ( D.Recibo>=ISNULL(@pmRecibo,0)  AND  D.Recibo<=ISNULL(@pmRecibo,2147483647))
 AND D.IdConcepto like ISNULL(@pmIdConcepto,'%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND D.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBusesAnt]  @pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null
AS
  SELECT D.IdVehiculo AS IdVehic,R.IdClase AS IdClas,D.IdCia AS CodCia,SUM(R.ValorAnticipo) AS StotAnt,SUM(ValorAbono) AS STotAbo 
  FROM Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses AS R ON D.TipDoc=R.TipDoc  AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
  WHERE R.ValorAnticipo>0 AND D.IdVehiculo  LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 GROUP BY   D.IdVehiculo,R.IdClase,D.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesAntc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBusesAntc]  @pmIdCliente VARCHAR(16)=Null
AS
 --devolucion de recibos anticipos por cliente
  SELECT D.IdCliente AS IdClie,SUM(R.ValorAnticipo) AS StotAnt,SUM(ValorAbono) AS STotAbo 
  FROM Trn_DevRecBuses AS D INNER JOIN Trn_RecBuses AS R ON D.TipDoc=R.TipDoc  AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
  WHERE R.ValorAnticipo>0 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 GROUP BY   D.IdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBusesLta] @pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCliente VARCHAR(16),@pmIdVehiculo VARCHAR(10)

AS
 SELECT  Devolucion, IdCia, Fecha,D.IdConcepto AS IdConcept,Concepto,TipDoc, Recibo, IdCiaDoc, FecDoc, IdCliente,T.RazonSocial AS Cliente, IdAgencia, IdVehiculo, IdConductor,O.RazonSocial AS Conductor,VehPropio, Modalidad, 
                      ValorRecibido, ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorOtrosDct, ValorPagMas,ValorAhorro,ValorOConce, ValorNeto, ValorAplicado, 
                      ValorAnticipo, IdVendedor, D.Comision AS Comison, IdTarCom, IdCta, EnEfectivo, NumCheque,D.IdBanco AS IdBanc,Banco, EsParcial,D.IdClase AS IdClas,ClaseCuenta, TipCom, Comprobante, IdCiaCom, 
                      D.Observacion AS Observ, D.IdEstado AS IdEstad,Estado, TimeSys, IdCiaCrea, D.IdUsuario AS IdUsuari
 FROM Trn_DevRecBuses  AS D INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
   INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero
   INNER JOIN Terceros AS O ON D.IdConductor=O.IdTercero
   LEFT JOIN Bancos AS B ON D.IdBanco=B.IdBanco
   LEFT JOIN BusClaseCue AS L ON D.IdClase=L.IdClase
   LEFT JOIN EstadoDoc AS E ON D.IdEstado=E.IdEstado
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesNMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBusesNMes] @pmAnno INT,@pmMes INT=Null, @pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdClase VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT IdCliente,IdVehiculo,IdCia,IdClase,Month(Fecha) AS NMes,SUM(ValorTotal) AS SvalTot,SUM(ValorNeto) AS SValNet
 FROM     Trn_DevRecBuses
 WHERE Year(Fecha)=@pmAnno AND Month(Fecha)=ISNULL(@pmMes,Month(Fecha))  AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 GROUP BY  IdCliente,IdVehiculo,IdCia,IdClase,Month(Fecha)
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecBusesVFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecBusesVFec] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16),@pmIdVehiculo VARCHAR(10)=Null,@pmIdClase VARCHAR(4)=Null
AS
 SELECT IdCliente,IdVehiculo,SUM(ValorTotal) AS SvalTot,SUM(ValorNeto) AS SValNet
 FROM   Trn_DevRecBuses
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  IdCia like ISNULL(@pmIdCia,'%%') 
 AND IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdClase like ISNULL(@pmIdClase,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY IdCliente,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecDoc] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,IdAgencia
,TipCom,Comprobante,IdCiaCom,IdEstado,Modalidad
 FROM Trn_DevRec
 WHERE  TipDoc=@pmTipDoc AND Recibo=@pmRecibo  AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmReciboIni INT=Null,@pmReciboFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmEnEfectivo BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto
,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,IdCCosto,IdSubCos,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,D.IdLocal AS CodLocal,EnEfectivo,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,NumAutoriza,Modalidad,ModdDev
,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDev
 FROM Trn_DevRec  AS D INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL (@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND  Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND D.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevRecRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevRecRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmEnEfectivo BIT=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,T.RazonSocial AS NomCliente
,D.IdAgencia AS  IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto
,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,D.IdCCosto AS IdCenCost,CCosto,D.IdSubCos AS IdSubCent,SubCosto
,IdCajero,UC.Usuario AS NomCajero,D.IdVend AS NitVendedor,V.RazonSocial AS Vendedor,TarifaCom,D.IdLocal AS CdCiudadRec,LR.Localidad AS CiudadRecibo
,EnEfectivo,D.Referencia AS DocReferncia,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,TipDcm,D.Documento AS NumDoc,IdCiaDcm
,D.NumAutoriza AS NAutoriza,Modalidad,ModdDev,VrReteCREE,TarifaRtc,CodTarRtc,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,CdFntePago,FuentePago
 FROM Trn_DevRec AS D  INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero  INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN Agencias  AS A ON D.IdAgencia=A.IdAgencia  INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LR ON D.IdLocal=LR.IdLocal LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS TC ON D.CdConductor=TC.IdTercero
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND D.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND  IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND  D.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevSal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Salida,IdCiaDoc,FecDoc,IdTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp
,IdCCosto,IdSubCos,TipOrd,NumOrden,IdCiaOrd,pVehiculo,NContrato,IdCiaCont,NitCliente,CdAgencia,ModRequis,VrImpuBA,VrImpuCUP
,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevSal
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSal_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevSal_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipoSal
,Salida,IdCiaDoc,FecDoc,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,D.VrImpuBA,D.VrImpuCUP
,D.IdCCosto AS IdCenCosto,CC.CCosto AS NomCentCosto,D.IdSubCos AS IdSubCosto,SC.SubCosto AS SubCentCosto,D.TipOrd AS TipoOrden
,D.NumOrden AS NroOrden,D.IdCiaOrd AS CodCiaOrden,NContrato,IdCiaCont,NitCliente,ModRequis
,Modalidad,ModdDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--Detalle
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,KT.RazonSocial AS KarNomTercero,K.CdAgencia AS KarAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,CdLocal,KL.Localidad AS KarCiudad,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,K.TipOrd AS KarTipOrden,K.NumOrden AS KarNumOrden,K.IdCiaOrd AS KarCiaOrden,Cotizacion,IdCiaCot
,Remision,IdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBA,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_DevSal AS D INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd INNER JOIN Terceros AS KT ON K.IdTercero=KT.IdTercero
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos LEFT JOIN Localidades AS KL ON K.CdLocal=KL.IdLocal
 LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND  @pmDevolucionFin AND D.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY Devolucion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSalDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDevSalDoc] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Salida,IdCiaDoc,FecDoc,VrSubTotal,VrImpuesto,VrCostos,VrNeto
,TipCom,Comprobante,IdCiaCom
 FROM Trn_DevSal
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCiaDoc=@pmIdCiaDoc
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSalLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevSalLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
,@pmSalidaIni INT=Null,@pmSalidaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmModdDev VARCHAR(10)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Devolucion,IdCia,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Salida,IdCiaDoc,FecDoc,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero
,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,D.VrImpuBA,D.VrImpuCUP,D.IdCCosto AS IdCenCosto,CCosto,IdSubCos,TipOrd,NumOrden,IdCiaOrd,pVehiculo,NContrato,IdCiaCont
,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,ModRequis,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
 FROM Trn_DevSal AS D INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 LEFT JOIN Terceros AS CL ON D.NitCliente=CL.IdTercero
 WHERE TipDev=@pmTipDev AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0)  AND ISNULL(@pmDevolucionFin,2147483647)
 AND Salida BETWEEN ISNULL(@pmSalidaIni,0) AND ISNULL(@pmSalidaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevSalRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevSalRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Salida,IdCiaDoc,FecDoc,D.IdTercero AS NitTercero
,T.RazonSocial AS NomTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,D.VrImpuBA,D.VrImpuCUP,D.IdCCosto AS IdCenCosto,CCosto,D.IdSubCos AS IdSubCosto,SubCosto,TipOrd
,NumOrden,IdCiaOrd,NContrato,IdCiaCont,NitCliente,ModRequis,Modalidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_DevSal AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')  AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevVal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevVal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,nRadica,IdCiaDoc,FecDoc,IdTercero,TotalPagos,TotalCobros,Referencia,CxPagar,VrDescuento,ModdDev,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DevVal
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDevVal_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevVal_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipRad,D.nRadica AS NumRadica,IdCiaDoc,FecDoc
,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,TotalPagos,TotalCobros,D.Referencia AS DocReferencia,CxPagar,VrDescuento,ModdDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
--detalles
,Item,TipoRango,IdRango,NumSerie,NumForma,V.Fecha AS FechaServ,HoraServ,IdCliente,CL.RazonSocial AS NomCliente,V.IdAgencia AS ValAgencia,Agencia,IdCuenta,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera
,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,PlacaVeh,CdConductor,NomConductor,CantPasaj,Usuarios,TipFac,NumFactura,IdCiaFac,FechaFac,V.Anulado AS ValAnulado,V.NumDev AS ValNumAnul,V.FecDev AS ValFechaDev
,V.Observacion AS ValObserv,FechaUp,CdUsuario
--datos del cliente
,CL.TipoId AS CliTipoId,CL.Dv AS CliDv,CL.Codigo AS CliCodigo,CL.NomCial AS CliNomCial,CL.Direccion AS CliDireccion,CL.IdLocal AS CliCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,CL.Telefono AS CliTelefono,CL.Fax AS CliFax,CL.e_mail AS CliEmail,CL.IdSector AS CdSector,SectorEco,CL.IdRegimen AS CdRegimen,Regimen,CL.TipEnte AS CliTipoEnte
 FROM Trn_DevVal AS D INNER JOIN Trn_Vales AS V ON D.TipDoc=V.TipDoc AND D.nRadica=V.nRadica AND D.IdCiaDoc=V.IdCia
 INNER JOIN  Terceros AS T ON D.IdTercero=T.IdTercero  INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS CL ON V.IdCliente=CL.IdTercero
 INNER JOIN Localidades AS L ON CL.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON CL.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON CL.IdSector=SE.IdSector
 LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDevValDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevValDoc] @pmTipDoc VARCHAR(3),@pmnRadica  INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,nRadica,IdCiaDoc,FecDoc,TipCom,Comprobante,IdCiaCom,ModdDev,CxPagar
 FROM Trn_DevVal
 WHERE TipDoc=@pmTipDoc  AND  nRadica=@pmnRadica   AND  IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryDevValLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDevValLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmModdDev VARCHAR(10)=Null
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,nRadica,IdCiaDoc,FecDoc,D.IdTercero AS NitTercero,RazonSocial,TotalPagos,TotalCobros
,Referencia,CxPagar,VrDescuento,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,TipDev
 FROM Trn_DevVal AS D  INNER JOIN  Terceros AS T ON D.IdTercero=T.IdTercero  INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE Fecha BETWEEN   @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND D.IdConcepto  LIKE ISNULL(@pmIdConcepto,'%') AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND ModdDev LIKE ISNULL(@pmModdDev,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryDiarios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDiarios] @pmIdDiario VARCHAR(4)
 AS 
 IF @pmIdDiario IS NULL
  SELECT IdDiario,Diario,CodTransac
  FROM Diarios
  WHERE Inactivo=0
  ORDER BY IdDiario
 ELSE
  SELECT IdDiario,Diario,CodTransac,Inactivo
  FROM Diarios
  WHERE IdDiario=@pmIdDiario
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDiferidos] @pmIdDiferido VARCHAR(30)
 AS 
 SELECT IdDiferido,NomDiferido,IdTipDif,IdGrupo,IdCCosto,IdSubCos,IdDep,IdRespons,IdCia,FecInicio,ValorTotal,VrAdiciones,VrDisminucion,NumPeriodos
,FecFinAmtza,Ajustable,Contable,VrAjuInfAcum,VrAmtzaAcuHis,VrAmtzaAcum,VrAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,FecUltAmtza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,DesUbicacion,IdEstado
,FecRetiro,IdCausal,ComentRetiro,Comentarios,FecCreacion,IdUsuario,TipoAmtza,NitCliente,AgenCliente,CantGalones,IdProv
,NumPlaca,CodInstala,TipoInvers,TipoContable,CodNiifDif,CodNiifAmtza,TipComp,NumComp,CdCiaComp
 FROM Diferidos
 WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidosAmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDiferidosAmt] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT IdDiferido,NomDiferido,IdTipDif,IdGrupo,IdCCosto,IdSubCos,IdDep,IdRespons,IdCia,FecInicio,ValorTotal,VrAdiciones,VrDisminucion,NumPeriodos
,FecFinAmtza,Ajustable,Contable,CorrMonDiferida,NumMesesDif,FecUltAmtza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA
,IdEstado,FecRetiro,TipoAmtza,NitCliente,AgenCliente,CantGalones,IdProv,NumPlaca,CodInstala,TipoInvers,TipoContable,CodNiifDif,CodNiifAmtza
 FROM Diferidos
 WHERE FecInicio<=@pmFechaFin
  AND (IdEstado<>'9999'  OR (IdEstado='9999' AND FecRetiro>=@pmFechaIni))
 ORDER BY IdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidosHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDiferidosHis] @pmIdDiferido VARCHAR(30)
 AS 
 SELECT A.IdDiferido AS CdDiferido,NomDiferido,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro
,CC.CCosto AS DifCentroCosto,A.IdSubCos AS CdSubcentro,SC.SubCosto AS DifSubCentro,A.IdDep AS CdDep,DP.Dependencia AS DifDependencia,DesUbicacion
,IdRespons,T.RazonSocial AS NomResponsable,A.IdCia AS CdCia,CIA.Compania AS DifNomCia,FecInicio,A.ValorTotal AS DifValTotal,A.VrAdiciones AS DifAdiciones,A.VrDisminucion AS DifDisminucion,NumPeriodos
,FecFinAmtza,Ajustable,Contable,VrAjuInfAcum,VrAmtzaAcuHis,VrAmtzaAcum,VrAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,FecUltAmtza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumDoc,Referencia,A.IdEstado AS CdEstado,ED.Estado AS DifEstado
,FecRetiro,A.IdCausal AS CdCausal,Causal,ComentRetiro,Comentarios,TipoInvers,FecCreacion,A.IdUsuario AS IdUsuari
--DATOS DEL DIFERIDO
,AMZ.Numero AS NumRegistro,Fecha,AMZ.Estado AS EstadoDoc,AMZ.IdUsuario AS CdUsuario,Usuario,FechaCrea,AMZ.IdCia AS CdCia,CI.Compania AS NomCia
,Item,D.ValorTotal AS ValorInicial, D.VrAdiciones AS ValAdiciones, D.VrDisminucion AS ValDisminucion, VrAcuAjustes, VrAmortizaHis, VrAmortizaMes, VrAjustesInf
, VrAjustesAmtza,VrAmtzaHisAcum, VrAmortizaAcum, VrAjuAmtzaAcum, VrCorrMonAcum, VrBaseCorrMon, VrCorrMonDif, TarifaAju
,D.IdCia AS DetIdCia,CID.Compania AS DetNomCia,CdCCosto,CCD.CCosto AS NomCentroCosto,CdSubCos,SCD.SubCosto AS NomSubcentro, CdDep, DPD.Dependencia AS NomDepend
,NitRespons,TRD.RazonSocial AS DetResponsable,FecInicioAmtza, NPeriodos,TipoAmtza,NitCliente,AgenCliente,CantGalones
,IdProv,PV.RazonSocial AS NomProveedor,NumPlaca,CodInstala,Instlacion,TipoContable
 FROM Diferidos  AS A INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN Companias AS CIA ON A.IdCia=CIA.IdCia  INNER JOIN Terceros AS PV ON A.IdProv=PV.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 LEFT JOIN Trn_AfAmtDetalle AS D ON A.IdDiferido=D.IdDiferido LEFT  JOIN Trn_AfAmortiza AS AMZ  ON D.Numero=AMZ.Numero
 LEFT JOIN Companias AS CI ON AMZ.IdCia=CI.IdCia  LEFT JOIN adm_Usuarios AS U ON AMZ.IdUsuario=U.IdUsuario
 LEFT JOIN Companias AS CID ON D.IdCia=CID.IdCia 
 LEFT JOIN CentroCosto AS CCD ON D.CdCCosto=CCD.IdCCosto 
 LEFT JOIN Dependencias AS DPD ON D.CdDep=DPD.IdDep LEFT JOIN Terceros AS TRD ON D.NitRespons=TRD.IdTercero
 LEFT JOIN SubCentros AS SCD ON D.CdSubCos=SCD.IdSubCos  LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE A.IdDiferido LIKE ISNULL(@pmIdDiferido ,'%')
 ORDER BY NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryDiferidosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDiferidosLta] @pmIdGrupo VARCHAR(4)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipDif VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdRespons VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT IdDiferido,NomDiferido,A.IdTipDif AS CdTipDif,TipoDiferido,G.IdLinea AS CodLinea,Linea,A.IdGrupo AS CodGrupo,Grupo,A.IdCCosto AS CdCentro,CCosto,A.IdSubCos AS CdSubcentro,SubCosto
,A.IdDep AS CdDep,Dependencia,DesUbicacion,IdRespons,T.RazonSocial  AS NomResponsable,A.IdCia AS CdCia,Compania,FecInicio,ValorTotal,VrAdiciones,VrDisminucion,NumPeriodos
,FecFinAmtza,Ajustable,Contable,VrAjuInfAcum,VrAmtzaAcuHis,VrAmtzaAcum,VrAjuInfAmtza,CuotasAmtza,VrCorrMonDifAcu,CorrMonDiferida,NumMesesDif
,FecUltAmtza,CueEnGrupo,IdCuenta,IdCueAmortiza,IdCueAjuDif,IdCueCorrDif,IdCueAjuAmtza,IdCueCorrAA,NumPlaca,NumDoc,Referencia,A.IdEstado AS CdEstado,Estado
,FecRetiro,A.IdCausal AS CdCausal,Causal,ComentRetiro,Comentarios,FecCreacion,A.IdUsuario AS IdUsuari,Usuario,TipoAmtza,NitCliente,AgenCliente,CantGalones
,IdProv,PV.RazonSocial AS NomProveedor,CodInstala,Instlacion,TipoInvers,TipoContable,CodNiifDif,CodNiifAmtza,TipComp,NumComp,CdCiaComp
--datos del responsable
,T.Codigo AS TercCodigo,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigla,T.Direccion AS TercDirecc,T.IdLocal AS CdLocalidad,Localidad
,LC.IdDep AS Cd_Depto,Departamento,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM Diferidos  AS A INNER JOIN AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN CentroCosto AS CC ON A.IdCCosto=CC.IdCCosto INNER JOIN AfTiposDif AS TD ON A.IdTipDif=TD.IdTipDif
 INNER JOIN Dependencias AS DP ON A.IdDep=DP.IdDep INNER JOIN Terceros AS T ON A.IdRespons=T.IdTercero
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Terceros AS PV ON A.IdProv=PV.IdTercero
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal INNER JOIN Departamentos AS D ON LC.IdDep=D.IdDep
 LEFT JOIN SubCentros AS SC ON A.IdSubCos=SC.IdSubCos LEFT JOIN AfCausales AS CA ON A.IdCausal=CA.IdCausal
 LEFT JOIN Instalaciones AS I ON A.CodInstala=I.IdInstala
 WHERE A.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND A.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND  A.IdTipDif LIKE ISNULL(@pmIdTipDif,'%')
 AND A.IdDep LIKE ISNULL(@pmIdDep,'%') AND IdRespons LIKE ISNULL(@pmIdRespons,'%')
 AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (FecInicio>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicio<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQryDisciplinario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDisciplinario] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Numero,IdCia,Fecha,FecSuceso,IdVehiculo,IdPropietario,IdConductor,IdRuta,Lugar,NomReporta,CedReporta,VehiculoRep,RepCond
,Coordinador,Despachador,CitaDescargos,FecCita,MemoCita,Imputacion,Descargos,FecDesc,RecibeDesc,TipoSancion,DescSancion,FecSancion,CantSancion
,CodInfracc,Referencia,Observacion,Anulado,NumDev,FecDev,IdEstado,TipoInf,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Disciplinario
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDisciplinarioFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDisciplinarioFmt] @pmTipDoc VARCHAR(3),@pmNumeroIni INT,@pmNumeroFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.Numero AS NumInf,D.IdCia AS CdCia,Compania,Fecha,FecSuceso,D.IdVehiculo AS PlacaVeh,NumVeh,D.IdPropietario AS NitPropietario,P.RazonSocial AS Propietario
,D.IdConductor AS CedConductor,C.RazonSocial AS Conductor,D.IdRuta AS CdRuta,Ruta,Lugar,NomReporta,CedReporta,VehiculoRep,RepCond
,Coordinador,Despachador,CitaDescargos,FecCita,MemoCita,Imputacion,Descargos,FecDesc,RecibeDesc,TipoSancion,DescSancion,FecSancion,CantSancion
,CodInfracc,I.Infraccion AS NomInfracc,Referencia,D.Observacion AS Observ,TipoInf,Anulado,NumDev,FecDev,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
,Item,DT.Infraccion AS DescInfracc
--datos del vehículo
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo
,C.Codigo AS CondCodigo,C.Direccion AS CondDireccion,C.IdLocal AS CondCdCiudad,L.Localidad AS CondCiudad,L.IdDep AS CondCdDpto,DP.Departamento AS CondDpto
,C.Telefono AS CondTelefono,C.Fax AS CondFax,C.TelMovil AS CondTelMovil,C.e_mail AS CondEmail,C.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,C.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MC.Modalidad AS ModConductor,CT.CertJudicial AS CondCertJudicial,CT.VigJudicial AS CondVigJudicial,CT.Licencia AS CondLicencia
,CT.CatLicencia AS CondCategoria,CT.VigLicencia AS CondVigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM Trn_Disciplinario AS D INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS P ON D.IdPropietario=P.IdTercero
 INNER JOIN Terceros AS C ON D.IdConductor=C.IdTercero INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Trn_DisInfraccion AS DT ON D.TipDoc=DT.TipDoc   AND  D.Numero=DT.Numero  AND  D.IdCia=DT.IdCia 
 INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Infracciones AS I ON D.CodInfracc=I.NumInf LEFT JOIN Rutas AS R ON D.IdRuta=R.IdRuta
 LEFT JOIN  Localidades AS LCE ON C.IdLugarCed=LCE.IdLocal
 LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor  LEFT JOIN TiposMod AS MC ON CT.IdModd=MC.IdModd
 LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE D.TipDoc=@pmTipDoc AND D.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin  AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDisciplinarioLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDisciplinarioLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT D.Numero AS NumInf,D.IdCia AS CdCia,Compania,Fecha,FecSuceso,D.IdVehiculo AS PlacaVeh,NumVeh,D.IdPropietario AS NitPropietario,P.RazonSocial AS Propietario
,D.IdConductor AS CedConductor,C.RazonSocial AS Conductor,D.IdRuta AS CdRuta,Ruta,Lugar,NomReporta,CedReporta,VehiculoRep,RepCond
,Coordinador,Despachador,CitaDescargos,FecCita,MemoCita,Imputacion,Descargos,FecDesc,RecibeDesc,TipoSancion,DescSancion,FecSancion,CantSancion
,CodInfracc,I.Infraccion AS NomInfracc,Referencia,D.Observacion AS Observ,TipoInf,Anulado,NumDev,FecDev,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
--datos del vehículo
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo
,C.Codigo AS CondCodigo,C.Direccion AS CondDireccion,C.IdLocal AS CondCdCiudad,L.Localidad AS CondCiudad,L.IdDep AS CondCdDpto,DP.Departamento AS CondDpto
,C.Telefono AS CondTelefono,C.Fax AS CondFax,C.TelMovil AS CondTelMovil,C.e_mail AS CondEmail,C.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,C.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MC.Modalidad AS ModConductor,CT.CertJudicial AS CondCertJudicial,CT.VigJudicial AS CondVigJudicial,CT.Licencia AS CondLicencia
,CT.CatLicencia AS CondCategoria,CT.VigLicencia AS CondVigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM Trn_Disciplinario AS D INNER JOIN Companias  AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS P ON D.IdPropietario=P.IdTercero
 INNER JOIN Terceros AS C ON D.IdConductor=C.IdTercero INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Infracciones AS I ON D.CodInfracc=I.NumInf LEFT JOIN Rutas AS R ON D.IdRuta=R.IdRuta
 LEFT JOIN  Localidades AS LCE ON C.IdLugarCed=LCE.IdLocal
 LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor  LEFT JOIN TiposMod AS MC ON CT.IdModd=MC.IdModd
 LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 WHERE D.TipDoc=@pmTipDoc AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND D.IdEstado LIKE ISNULL(@pmIdEstado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryDocMemo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDocMemo] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
 FROM Trn_DocMemo
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSopDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDocSopDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumDoc,IdCiaDoc,FecDoc,IdTercero,SubTotal,Descuento,Retencion,ReteIca,Bomberil,ImpAviTab,OtrosCargos,OtrosDctos,ValorTotal,BaseRet,BaseBom,CodRes,DescServicio,CdCCosto,CdSubCos,TipDocRef,NumDocRef,IdCiaRef,NitCueProv,CodCueProv,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,VrOtrosImpu,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_DocSopDev
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSopDevFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDocSopDevFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
AS 
 SELECT DV.TipDev,TD.TipoDoc,DV.Devolucion,DV.IdCia,CI.Compania,DV.Fecha,DV.TipDoc,TS.TipoDoc AS DescTipDoc,DV.NumDoc,DV.IdCiaDoc,CD.Compania AS CiaDoc,DV.FecDoc,DV.IdTercero,T.RazonSocial,DV.SubTotal,DV.Descuento,DV.Retencion,DV.ReteIca,DV.Bomberil,DV.ImpAviTab
,DV.OtrosCargos,DV.OtrosDctos,DV.VrOtrosImpu,DV.ValorTotal,DV.BaseRet,DV.BaseBom,DS.TarifaRet,DS.TarifaIca,DS.TarifaBom,DS.TarifaAvta,DS.CodTarRet,DS.CodTarIca,DS.CodTarifBom,DS.CodTarifAvta
,DS.IdMedPago,MedioPago,DS.MetPago,DS.NumFactura,DS.FechaFac,DS.FechaVence,DS.IdAdquiriente,N.RazonSocial AS Adquiriente,DV.IdConcepto,Concepto,DV.DescServicio,DV.CdCCosto,CCosto,DV.CdSubCos,SubCosto
,DV.TipDocRef,DV.NumDocRef,DV.IdCiaRef,DV.NitCueProv,NP.RazonSocial AS NomProveedor,DV.CodCueProv,DV.TipCom,TipoCom,DV.Comprobante,DV.IdCiaCom,DV.Observacion,DV.OrigenAdd AS OrigenCrea,DV.TimeSys AS FechaCrea,DV.IdCiaCrea,DV.IdUsuario,Usuario
--detalles
,DT.Item,DT.IdProducto,P.DescripProd,DT.Descripcion,DT.Cantidad,DT.VrUnitario,DT.ValorOper,DT.VrDcto,DT.VrRetencion,DT.VrRetIca,DT.VrBomberil,DT.VrAviTab,DT.TarifaDct AS PorcDcto
,DT.TarifaRet AS PorcRet,DT.TarifaIca AS PorcICA,DT.TarifaBom AS PorcBom,DT.TarifaAvta AS PorcAvta,DT.CodTarDct AS DetCodDcto,DT.CodTarRet AS DetCodRet
,DT.CodTarIca AS DetCodIca,DT.CodTarifBom AS DetCodBom,DT.CodTarifAvta AS DetCodAvta,DT.ItemCom,DT.CdCuenta,PC.NomCuenta,DT.CdCueCre,DT.PlacaVeh,DT.Veh_Propio,DT.NitCliente,DT.CodAgencia
--Datos resolución
,DV.CodRes,R.Resolucion,R.Prefijo,R.NumInicial,R.NumFinal,R.FechaExpRes,R.FechaVigencia,R.Establecimiento
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad
,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco
,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,FC.EstadoFE,FC.Prefijo AS FEPrefijo,FC.NumFace,FC.CUFE,FC.CUFE_QR,FC.Resolucion AS FENumResol,FC.RangoNum AS FERangoNum,FC.FecVigencia AS FEVigencia,FC.FechaValidacion AS FEFecValida
FROM Trn_DocSopDev AS DV INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia
INNER JOIN Sys_TiposDoc AS TS ON DV.TipDoc=TS.IdDoc INNER JOIN Companias AS CD ON DV.IdCiaDoc=CD.IdCia
INNER JOIN Terceros AS T ON DV.IdTercero=T.IdTercero INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario
INNER JOIN Trn_DocSoporte AS DS ON DV.TipDoc=DS.TipDoc AND DV.NumDoc=DS.NumDoc AND DV.IdCiaDoc=DS.IdCia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Trn_DocSopDevDet AS DT ON DV.TipDev=DT.TipDev AND DV.Devolucion=DT.Devolucion AND DV.IdCia=DT.IdCia
LEFT JOIN ProdMcias AS P ON DT.IdProducto=P.IdProducto
LEFT JOIN Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto LEFT JOIN NomMediosPago AS MP ON DS.IdMedPago=MP.IdMedPago
LEFT JOIN TiposComRes AS R ON DV.CodRes=R.IdRes LEFT JOIN Terceros AS N ON DS.IdAdquiriente=N.IdTercero
LEFT JOIN TiposCom AS TC ON DV.TipCom=TC.IdCom LEFT JOIN CentroCosto AS CC ON DV.CdCCosto=CC.IdCCosto
LEFT JOIN SubCentros AS SC ON DV.CdSubCos=SC.IdSubCos LEFT JOIN Puc AS PC ON DT.CdCuenta=PC.IdCuenta
LEFT JOIN Terceros AS NP ON DV.NitCueProv=NP.IdTercero
LEFT JOIN Trn_Face AS FC ON DV.TipDev=FC.TipDoc AND DV.Devolucion=FC.Documento AND DV.IdCia=FC.IdCia
WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSopDevLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDocSopDevLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT DV.TipDev,DV.Devolucion,DV.IdCia,CI.Compania,DV.Fecha,DV.TipDoc,DV.NumDoc,DV.IdCiaDoc,DV.FecDoc,DV.IdTercero,T.RazonSocial,DV.SubTotal,DV.Descuento,DV.Retencion,DV.ReteIca,DV.Bomberil,DV.ImpAviTab
,DV.OtrosCargos,DV.OtrosDctos,DV.VrOtrosImpu,DV.ValorTotal,DV.BaseRet,DV.BaseBom,DS.NumFactura,DS.Modalidad,DV.IdConcepto,Concepto,DV.CodRes,DV.DescServicio,DV.CdCCosto,CCosto,DV.CdSubCos,SubCosto
,DV.TipDocRef,DV.NumDocRef,DV.IdCiaRef,DV.NitCueProv,NP.RazonSocial AS NomProveedor,DV.CodCueProv,DV.TipCom,DV.Comprobante,DV.IdCiaCom,DV.Observacion,DV.OrigenAdd AS OrigenCrea,DV.TimeSys AS FechaCrea,DV.IdCiaCrea,DV.IdUsuario,Usuario
 FROM Trn_DocSopDev AS DV INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia INNER JOIN Terceros AS T ON DV.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario
 INNER JOIN Trn_DocSoporte AS DS ON DV.TipDoc=DS.TipDoc AND DV.NumDoc=DS.NumDoc AND DV.IdCiaDoc=DS.IdCia
 LEFT JOIN CentroCosto AS CC ON DV.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON DV.CdSubCos=SC.IdSubCos 
 LEFT JOIN Terceros AS NP ON DV.NitCueProv=NP.IdTercero LEFT JOIN Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto
 WHERE DV.TipDev=@pmTipDev AND DV.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND (DV.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSoporte]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryDocSoporte] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumDoc,IdCia,Fecha,IdTercero,IdAdquiriente,IdConcepto,IdMedPago,MetPago,Modalidad,NumFactura,FechaFac,FechaVence,SubTotal,Descuento,Retencion,ReteIca,Bomberil
,ImpAviTab,OtrosCargos,OtrosDctos,ValorTotal,BaseRet,BaseBom,TarifaRet,TarifaIca,TarifaBom,TarifaAvta,CodTarRet,CodTarIca,CodTarifBom,CodTarifAvta,DescServicio,CodRes,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom
,TipDocRef,NumDocRef,IdCiaRef,Anulado,TipDocDev,NumDev,CdCiaDev,FecDev,Observacion,IdEstado,NitCueProv,CodCueProv,VrOtrosImpu,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_DocSoporte
 WHERE TipDoc=@pmTipDoc AND NumDoc=@pmNumDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSoporteFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDocSoporteFmt] @pmTipDoc VARCHAR(3),@pmNumDocIni INT,@pmNumDocFin INT,@pmIdCia CHAR(2)
AS 
 SELECT D.TipDoc,TipoDoc,D.NumDoc,D.IdCia AS CdCia,CI.Compania,D.Fecha,D.IdTercero AS NitTercero,T.RazonSocial,D.IdAdquiriente,N.RazonSocial AS Adquiriente
 ,D.Modalidad,D.IdConcepto,Concepto,D.IdMedPago,MedioPago,D.MetPago,D.NumFactura,D.FechaFac,D.FechaVence,D.SubTotal,D.Descuento,D.Retencion,D.ReteIca,D.Bomberil,D.ImpAviTab,D.OtrosCargos,D.OtrosDctos,D.VrOtrosImpu,D.ValorTotal
 ,D.BaseRet,D.BaseBom,D.TarifaRet,D.TarifaIca,D.TarifaBom,D.TarifaAvta,D.CodTarRet,D.CodTarIca,D.CodTarifBom,D.CodTarifAvta,D.DescServicio
,D.CdCCosto,CCosto,D.CdSubCos,SubCosto,D.TipCom,TipoCom,D.Comprobante,D.IdCiaCom,D.TipDocRef,D.NumDocRef,D.IdCiaRef,D.CodCueProv,D.NitCueProv,NP.RazonSocial AS NomProveedor,D.Anulado,D.TipDocDev,D.NumDev,D.CdCiaDev,D.FecDev
,D.Observacion,D.IdEstado AS CdEstado,ED.Estado,D.TimeSys AS FechaCrea,D.OrigenAdd,D.FecUpdate,D.IdCiaCrea,D.IdUsuario,Usuario
--detalles
,DT.Item,DT.IdProducto,P.DescripProd,DT.Descripcion,DT.Cantidad,DT.VrUnitario,DT.ValorOper,DT.VrDcto,DT.VrRetencion,DT.VrRetIca,DT.VrBomberil,DT.VrAviTab,DT.TarifaDct AS PorcDcto
,DT.TarifaRet AS PorcRet,DT.TarifaIca AS PorcICA,DT.TarifaBom AS PorcBom,DT.TarifaAvta AS PorcAvta,DT.CodTarDct AS DetCodDcto,DT.CodTarRet AS DetCodRet
,DT.CodTarIca AS DetCodIca,DT.CodTarifBom AS DetCodBom,DT.CodTarifAvta AS DetCodAvta,DT.ItemCom,DT.CdCuenta,PC.NomCuenta,DT.CdCueCre,DT.PlacaVeh,DT.Veh_Propio,DT.NitCliente,DT.CodAgencia
--Datos resolución
,D.CodRes,R.Resolucion,R.Prefijo,R.NumInicial,R.NumFinal,R.FechaExpRes,R.FechaVigencia,R.Establecimiento
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad
,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco
,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,FC.EstadoFE,FC.Prefijo AS FEPrefijo,FC.NumFace,FC.CUFE,FC.CUFE_QR,FC.Resolucion AS FENumResol,FC.RangoNum AS FERangoNum,FC.FecVigencia AS FEVigencia,FC.FechaValidacion AS FEFecValida
,FD.CUFE AS CUDSDEV
FROM Trn_DocSoporte AS D INNER JOIN Sys_TiposDoc AS TD ON D.TipDoc=TD.IdDoc
INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Trn_DocSoporteDet AS DT ON D.TipDoc=DT.TipDoc AND D.NumDoc=DT.NumDoc AND D.IdCia=DT.IdCia
LEFT JOIN ProdMcias AS P ON DT.IdProducto=P.IdProducto
LEFT JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto LEFT JOIN NomMediosPago AS MP ON D.IdMedPago=MP.IdMedPago
LEFT JOIN TiposComRes AS R ON D.CodRes=R.IdRes LEFT JOIN Terceros AS N ON D.IdAdquiriente=N.IdTercero
LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto
LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos LEFT JOIN Puc AS PC ON DT.CdCuenta=PC.IdCuenta
LEFT JOIN Terceros AS NP ON D.NitCueProv=NP.IdTercero
LEFT JOIN Trn_Face AS FC ON D.TipDoc=FC.TipDoc AND D.NumDoc=FC.Documento AND D.IdCia=FC.IdCia
LEFT JOIN Trn_Face AS FD ON D.TipDocDev=FD.TipDoc AND D.NumDev=FD.Documento AND D.CdCiaDev=FD.IdCia
WHERE D.TipDoc=@pmTipDoc AND D.NumDoc BETWEEN @pmNumDocIni AND @pmNumDocFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryDocSoporteRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryDocSoporteRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmnIdTercero VARCHAR(16)=Null
AS 
 SELECT D.TipDoc,TipoDoc,D.NumDoc,D.IdCia AS CdCia,CI.Compania,D.Fecha,D.IdTercero AS NitTercero,T.RazonSocial,D.IdAdquiriente,N.RazonSocial AS Adquiriente
 ,D.Modalidad,D.IdConcepto,Concepto,D.IdMedPago,MedioPago,D.MetPago,D.NumFactura,D.FechaFac,D.FechaVence,D.SubTotal,D.Descuento,D.Retencion,D.ReteIca,D.Bomberil,D.ImpAviTab,D.OtrosCargos,D.OtrosDctos,D.ValorTotal,D.VrOtrosImpu
 ,D.BaseRet,D.BaseBom,D.TarifaRet,D.TarifaIca,D.TarifaBom,D.TarifaAvta,D.CodTarRet,D.CodTarIca,D.CodTarifBom,D.CodTarifAvta,D.DescServicio
 ,D.CodRes,R.Resolucion,R.Prefijo,R.NumInicial,R.NumFinal,R.FechaExpRes,R.FechaVigencia,R.Establecimiento,D.CdCCosto,CCosto,D.CdSubCos,SubCosto,D.TipCom,TipoCom,D.Comprobante,D.IdCiaCom,D.TipDocRef,D.NumDocRef,D.IdCiaRef
,D.CodCueProv,D.NitCueProv,NP.RazonSocial AS NomProveedor,D.Anulado,D.TipDocDev,D.NumDev,D.CdCiaDev,D.FecDev,D.Observacion,D.IdEstado AS CdEstado,ED.Estado,D.TimeSys AS FechaCrea,D.OrigenAdd,D.FecUpdate,D.IdCiaCrea,D.IdUsuario,Usuario
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad
,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco
,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
FROM Trn_DocSoporte AS D INNER JOIN Sys_TiposDoc AS TD ON D.TipDoc=TD.IdDoc
INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN TiposComRes AS R ON D.CodRes=R.IdRes LEFT JOIN Terceros AS N ON D.IdAdquiriente=N.IdTercero
LEFT JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto LEFT JOIN NomMediosPago AS MP ON D.IdMedPago=MP.IdMedPago
LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto
LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos LEFT JOIN Terceros AS NP ON D.NitCueProv=NP.IdTercero
WHERE D.TipDoc=@pmTipDoc AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND D.IdTercero LIKE ISNULL(@pmnIdTercero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryDocumentoSOP40_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Heiman Daza Tamayo
-- Create date(dd/MM/yyyy): 28/07/2022
-- Description:	procedimiento que busca un documento soporte para ser enviada a la DIAN en Syscom40 (Documentos Electronicos).
-- =============================================
CREATE PROCEDURE [dbo].[paQryDocumentoSOP40_Cr]
	@pmTipDoc VARCHAR(3),--Tipo de documento que se desea buscar
	@pmDocumento INT, --Número de documento que se desea buscar
	@pmIdCia CHAR(2) --Compañía de documento que se desea buscar
AS
BEGIN
SELECT S.TipDoc,S.NumDoc,S.IdCia,S.Fecha,S.FechaVence,S.TimeSys,S.idTercero, T.RazonSocial NomTercero,S.ValorTotal,S.SubTotal,S.OtrosDctos,S.OtrosCargos,D.VrDcto,S.Observacion,MetPago,IdMedPago,OrigenAdd,
Item,D.IdProducto,ISNULL(P.CodFEDian,D.IdProducto) CodProductoDIAN,Descripcion,Cantidad,'94' CdUndMed,VrUnitario,VrDcto,TarifaDct,CASE WHEN D.TarifaRet = 0 THEN S.TarifaRet ELSE D.TarifaRet END TarifaRet,CASE WHEN D.TarifaIca = 0 THEN S.TarifaIca ELSE D.TarifaIca END TarifaIca,D.TarifaBom,D.TarifaAvta,CodTarDct,D.CodTarRet,
D.CodTarIca,D.CodTarifBom,D.CodTarifAvta,S.OrigenAdd,'COP' CdMoneda,
--Inforamción de factura electrónica
FE.EstadoFE,FE.Prefijo,FE.NumFace NumDocSOP,FE.CUFE CUDS,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
FROM Trn_DocSoporte S
INNER JOIN Trn_DocSoporteDet D ON S.TipDoc=D.TipDoc AND S.NumDoc=D.NumDoc AND S.IdCia=D.IdCia
INNER JOIN Terceros AS T ON S.idTercero = T.IdTercero
LEFT JOIN ProdMcias AS P ON D.IdProducto = P.IdProducto
LEFT JOIN Trn_Face AS FE ON S.TipDoc=FE.TipDoc AND S.NumDoc=FE.Documento AND S.IdCia=FE.IdCia
WHERE S.TipDoc=@pmTipDoc AND S.NumDoc=@pmDocumento AND S.IdCia=@pmIdCia
END
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCalibra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsCalibra] @pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,nNota,IdCia,Fecha,IdConcepto,NitTercero,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto
,Cantidad,IdCajero,IdVend,TarifaCom,CodTarCom,IdCCosto,IdSubCos,Referencia,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_EdsCalibra
 WHERE TipDoc=@pmTipDoc AND nNota=@pmnNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCalibra_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCalibra_Cr] @pmTipDoc VARCHAR(3),@pmnNotaIni INT,@pmnNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS Tip_Doc,TipoDoc,nNota,C.IdCia AS CdCia,Compania,C.Fecha AS FechaDoc,C.IdConcepto AS CdConcepto,Concepto
,NitTercero,T.RazonSocial AS NomTercero,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto,Cantidad
,IdCajero,UC.Usuario AS NomCajero,C.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom
,C.Referencia AS DocReferencia,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,C.TimeSys AS Fec_Add,C.FecUpdate AS Fec_Update
,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,CCosto,CdSubCos,SubCosto,pVehiculo,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd
,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,CdMngra,NumInicial,NumFinal
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_EdsCalibra AS C INNER JOIN Trn_Kardex AS K ON C.TipDoc=K.TipDoc AND C.nNota=K.Documento AND C.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN  Conceptos AS CNC ON C.IdConcepto=CNC.IdConcepto  INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado  
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario
 INNER JOIN  Terceros AS VN ON C.IdVend=VN.IdTercero  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero  LEFT JOIN TiposCom AS TCM ON C.TipCom=TCM.IdCom
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 WHERE C.TipDoc=@pmTipDoc AND nNota BETWEEN @pmnNotaIni AND @pmnNotaFin AND C.IdCia=@pmIdCia
 ORDER BY nNota,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCalibraLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCalibraLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmnNotaIni INT=Null,@pmnNotaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmNitTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT nNota,IdCia,Fecha,N.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,CdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrCostos,VrNeto,Cantidad
,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,IdCCosto,IdSubCos,Referencia,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev
,FecDev,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,N.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDoc
 FROM Trn_EdsCalibra AS N  INNER JOIN Terceros AS T ON N.NitTercero=T.IdTercero
 INNER JOIN Terceros AS V ON N.IdVend=V.IdTercero
 INNER JOIN Conceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON N.IdCajero=UC.IdUsuario 
-- INNER JOIN Jornadas AS J ON N.IdJornada=J.IdJornada
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND nNota BETWEEN ISNULL(@pmnNotaIni,0) AND ISNULL(@pmnNotaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') 
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')  AND NitTercero LIKE ISNULL(@pmNitTercero,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%')  AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,nNota
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsCortes] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Planilla,IdCia,Fecha,IdConcepto,NitTercero,IdJornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros
,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,IdVend,TarifaCom,CodTarCom,NitRef,IdCCosto,IdSubCos,Referencia,Modalidad
,FecCorte,NumCorte,NumTurno,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TipoInt,VrDctoClie,VrExcedClie,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_EdsCortes
 WHERE TipDoc=@pmTipDoc AND Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortes_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCortes_Cr] @pmTipDoc VARCHAR(3),@pmPlanillaIni INT,@pmPlanillaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS Tip_Doc,TipoDoc,Planilla,C.IdCia AS CdCia,Compania,C.Fecha AS FechaDoc,C.IdConcepto AS CodConcepto,Concepto
,NitTercero,T.RazonSocial AS NomTercero,C.IdJornada AS CdJornada,Jornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros
,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,VrDctoClie,VrExcedClie
,IdCajero,UC.Usuario AS NomCajero,C.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,NitRef,TR.RazonSocial AS NomTerceroRef,C.Referencia AS DocReferencia,Modalidad
,FecCorte,NumCorte,NumTurno,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TipoInt,C.TimeSys AS Fec_Add,C.FecUpdate AS Fec_Update,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,CCosto,CdSubCos,SubCosto,pVehiculo,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd
,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,K.IdVend AS KarNitVend,KV.RazonSocial AS KarVendedor,Comision,CdOperario,KO.RazonSocial AS NomOperario,ComisnOper,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto
,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,CdMngra,NumInicial,NumFinal
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_EdsCortes  AS C  INNER JOIN Trn_Kardex AS K ON C.TipDoc=K.TipDoc AND C.Planilla=K.Documento AND C.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN  Conceptos AS CNC ON C.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario INNER JOIN  Terceros AS VN ON C.IdVend=VN.IdTercero
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero LEFT JOIN Terceros AS TR ON C.NitRef=TR.IdTercero
 LEFT JOIN TiposCom AS TCM ON C.TipCom=TCM.IdCom
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN Terceros AS KV ON K.IdVend=KV.IdTercero  LEFT JOIN Terceros AS KO ON K.CdOperario=KO.IdTercero
 WHERE C.TipDoc=@pmTipDoc AND Planilla BETWEEN @pmPlanillaIni AND @pmPlanillaFin  AND C.IdCia=@pmIdCia
 ORDER BY Planilla,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesCor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCortesCor] @pmFecCorte SMALLDATETIME,@pmNumCorte INT,@pmModalidad VARCHAR(10)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 SELECT TipDoc,Planilla,IdCia,Fecha,Modalidad,FecCorte,NumCorte,NumTurno,Anulado,NumDev,FecDev
 FROM Trn_EdsCortes
 WHERE FecCorte=@pmFecCorte AND NumCorte=@pmNumCorte AND Modalidad LIKE ISNULL(@pmModalidad,'%')
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,Planilla
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsCortesLta]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmPlanillaIni INT=Null,@pmPlanillaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdJornada VARCHAR(4)=Null
,@pmNitTercero VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Planilla,IdCia,Fecha,C.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,C.IdJornada AS  CdJornada,Jornada,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros
,VrPagosOtr,Cantidad,VrConTotal,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,NitRef,IdCCosto,IdSubCos,Referencia,Modalidad
,FecCorte,NumCorte,NumTurno,TipoInt,VrDctoClie,VrExcedClie,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,TipDoc
 FROM Trn_EdsCortes AS C  INNER JOIN Terceros AS T ON C.NitTercero=T.IdTercero
 INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero
 INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario 
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Planilla BETWEEN ISNULL(@pmPlanillaIni,0) AND ISNULL(@pmPlanillaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND C.IdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')  AND NitTercero LIKE ISNULL(@pmNitTercero,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')  AND IdVend LIKE ISNULL(@pmIdVend,'%')  
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Planilla
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesNet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCortesNet]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdJornada VARCHAR(4)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Planilla,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CodConcepto,Concepto,NitTercero,T.RazonSocial AS NomTercero,C.IdJornada AS CdJornada,Jornada
,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal,VrConImp
,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant
,IdCajero,UC.Usuario AS NomCajero,C.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,NitRef,TR.RazonSocial AS NomTerceroRef,C.Referencia AS DocReferencia,Modalidad
,FecCorte,NumCorte,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,C.FecUpdate AS Fec_Update,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_EdsCortes  AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN  Conceptos AS CNC ON C.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario INNER JOIN  Terceros AS VN ON C.IdVend=VN.IdTercero
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero LEFT JOIN Terceros AS TR ON C.NitRef=TR.IdTercero
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND C.IdJornada LIKE ISNULL(@pmIdJornada,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,D.IdJornada AS CdJornada,Jornada
,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal
,VrConImp,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,IdCajero,UC.Usuario AS UsuCajero
,D.IdVend AS NitVendedor,VN.RazonSocial AS NomVendedor,TarifaCom,NitRef,TR.RazonSocial AS NomTerceroRef,D.Referencia AS DocReferencia,Modalidad
,FecCorte,NumCorte,TipCom,Comprobante,IdCiaCom,0,Planilla,FecDoc,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_DevPla  AS D   INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia
 INNER JOIN  Conceptos AS CNC ON D.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON D.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario INNER JOIN  Terceros AS VN ON D.IdVend=VN.IdTercero
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN Terceros AS TR ON D.NitRef=TR.IdTercero
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.IdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 UNION
 SELECT TipDoc,nNota,N.IdCia AS CdCia,Compania,Fecha,N.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,CdJornada,Jornada
,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,0,0,VrCostos,VrNeto,0,0,0,0,0,Cantidad,0,0,0,0,0,0,0,0,0,0
,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS NomVendedor,TarifaCom,'0','',Referencia,'',Null,0,TipCom,Comprobante,IdCiaCom,Anulado,NumDev
,FecDev,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,N.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_EdsCalibra AS N  INNER JOIN Terceros AS T ON N.NitTercero=T.IdTercero
 INNER JOIN Terceros AS V ON N.IdVend=V.IdTercero
 INNER JOIN Conceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON N.IdCajero=UC.IdUsuario
 INNER JOIN Companias AS CI ON N.IdCia=CI.IdCia 
 LEFT JOIN Jornadas AS J ON N.CdJornada=J.IdJornada
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND CdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')  AND IdVend LIKE ISNULL(@pmIdVend,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,CdJornada,Jornada
,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,0,0,VrCostos,VrNeto,0,0,0,0,0,Cantidad,0,0,0,0,0,0,0,0,0,0
,IdCajero,UC.Usuario AS UsuCajero,IdVend,V.RazonSocial AS NomVendedor,TarifaCom,'0','',Referencia,ModdDev,Null,0
,TipCom,Comprobante,IdCiaCom,0,nNota,FecDoc,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario 
 FROM Trn_DevPas AS D INNER JOIN  Terceros AS T ON D.NitTercero=T.IdTercero
 INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia 
 INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 LEFT JOIN Jornadas AS J ON D.CdJornada=J.IdJornada
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND CdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')   AND IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY C.IdCia,Planilla
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesNetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCortesNetDet]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdJornada VARCHAR(4)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
 AS 
 SELECT C.TipDoc AS TipoPla,Planilla,C.IdCia AS CdCia,Compania,C.Fecha AS FechaPla,C.IdConcepto AS CodConcepto,Concepto,NitTercero,T.RazonSocial AS NomTercero,C.IdJornada AS CdJornada,Jornada
,VrOtros,VrSobrantes,VrFaltantes,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,IdCajero,UC.Usuario AS NomCajero
,NitRef,TR.RazonSocial AS NomTerceroRef,C.Referencia AS DocReferencia,Modalidad,FecCorte,NumCorte,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,C.TimeSys AS Fecha_Add,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalles
,K.IdProducto AS CdProducto,DescripProd,Item,CdTanque,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom
,ImpGlobal,CdMngra,NumInicial,NumFinal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,K.Comision AS TarifCom
,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper,CdCCosto,CCosto,CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.pVehiculo AS KarPlacaVeh
,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,TarifaDct,VrDctoEnt,VrDctoSal
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
 FROM Trn_EdsCortes  AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN  Conceptos AS CNC ON C.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario 
 INNER JOIN Trn_Kardex AS K ON C.TipDoc=K.TipDoc AND C.Planilla=K.Documento AND C.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN CentroCosto AS CCT ON K.CdCCosto=CCT.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero LEFT JOIN Terceros AS TR ON C.NitRef=TR.IdTercero
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND C.IdJornada LIKE ISNULL(@pmIdJornada,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND C.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,D.IdJornada AS CdJornada,Jornada
,VrOtros,VrSobrantes,VrFaltantes,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,IdCajero,UC.Usuario AS UsuCajero
,NitRef,TR.RazonSocial AS NomTerceroRef,D.Referencia AS DocReferencia,Modalidad,FecCorte,NumCorte,TipCom,Comprobante,IdCiaCom,0,Planilla,FecDoc
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fecha_Add,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalles
,K.IdProducto AS CdProducto,DescripProd,Item,CdTanque,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom
,ImpGlobal,CdMngra,NumInicial,NumFinal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,K.Comision AS TarifCom
,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper,CdCCosto,CCosto,CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.pVehiculo
,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,TarifaDct,VrDctoEnt,VrDctoSal
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
 FROM Trn_DevPla  AS D   INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia
 INNER JOIN  Conceptos AS CNC ON D.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON D.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN CentroCosto AS CCT ON K.CdCCosto=CCT.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN Terceros AS TR ON D.NitRef=TR.IdTercero
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND D.IdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND D.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
--pasadas
 UNION
 SELECT N.TipDoc AS TipoNota,nNota,N.IdCia AS CdCia,Compania,N.Fecha AS FechaNota,N.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,CdJornada,Jornada
,VrOtros,0,0,VrNeto,0,0,0,0,0,IdCajero,UC.Usuario AS UsuCajero,'0','',N.Referencia AS Refncia,'',Null,0,TipCom,Comprobante,IdCiaCom,Anulado,NumDev
,FecDev,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,N.TimeSys AS FechaAdd,IdCiaCrea,N.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalles
,K.IdProducto AS CdProducto,DescripProd,Item,CdTanque,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom
,ImpGlobal,CdMngra,NumInicial,NumFinal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,K.Comision AS TarifCom
,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper,CdCCosto,CCosto,CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.pVehiculo
,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,TarifaDct,VrDctoEnt,VrDctoSal
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
 FROM Trn_EdsCalibra AS N  INNER JOIN Terceros AS T ON N.NitTercero=T.IdTercero
 INNER JOIN Conceptos AS CN ON N.IdConcepto=CN.IdConcepto INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario  INNER JOIN adm_Usuarios AS UC ON N.IdCajero=UC.IdUsuario
 INNER JOIN Companias AS CI ON N.IdCia=CI.IdCia 
 INNER JOIN Trn_Kardex AS K ON N.TipDoc=K.TipDoc AND N.nNota=K.Documento AND N.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN CentroCosto AS CCT ON K.CdCCosto=CCT.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero  LEFT JOIN Jornadas AS J ON N.CdJornada=J.IdJornada
 WHERE N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND CdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')  AND N.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,NitTercero,T.RazonSocial AS NomCliente,CdJornada,Jornada
,VrOtros,0,0,VrNeto,0,0,0,0,0,IdCajero,UC.Usuario AS UsuCajero,'0','',D.Referencia AS Refcia,ModdDev,Null,0
,TipCom,Comprobante,IdCiaCom,0,nNota,FecDoc,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS FechaAdd,IdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario 
--detalles
,K.IdProducto AS CdProducto,DescripProd,Item,CdTanque,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom
,ImpGlobal,CdMngra,NumInicial,NumFinal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,K.Comision AS TarifCom
,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper,CdCCosto,CCosto,CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.pVehiculo
,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,TarifaDct,VrDctoEnt,VrDctoSal
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
 FROM Trn_DevPas AS D INNER JOIN  Terceros AS T ON D.NitTercero=T.IdTercero  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia 
 INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario  INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN CentroCosto AS CCT ON K.CdCCosto=CCT.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero  LEFT JOIN Jornadas AS J ON D.CdJornada=J.IdJornada
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND CdJornada LIKE ISNULL(@pmIdJornada,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')   AND D.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 ORDER BY  C.IdCia,Planilla
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCortesRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdJornada VARCHAR(4)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Planilla,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CodConcepto,Concepto,NitTercero,T.RazonSocial AS NomTercero,C.IdJornada AS CdJornada,Jornada
,VrSubTotal,VrSobretasa,VrImpGlobal,VrOtros,VrSobrantes,VrFaltantes,VrCostos,VrNeto,VrEfectivo,VrCreditos,VrGastComb,VrGastOtros,VrPagosOtr,Cantidad,VrConTotal,VrConImp
,VrConDcto,VrConCos,ConCant,VrCreTotal,VrCreImp,VrCreDcto,VrCreCos,CreCant,VrDctoClie,VrExcedClie
,IdCajero,UC.Usuario AS NomCajero,C.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,NitRef,TR.RazonSocial AS NomTerceroRef,C.Referencia AS DocReferencia,Modalidad
,FecCorte,NumCorte,TipoInt,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,C.FecUpdate AS Fec_Update,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
 FROM Trn_EdsCortes  AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN  Conceptos AS CNC ON C.IdConcepto=CNC.IdConcepto INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario INNER JOIN  Terceros AS VN ON C.IdVend=VN.IdTercero
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero LEFT JOIN Terceros AS TR ON C.NitRef=TR.IdTercero
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND C.IdJornada LIKE ISNULL(@pmIdJornada,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY C.IdCia,Planilla
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsCortesUlt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsCortesUlt] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Planilla,IdCia,Fecha,IdConcepto
 FROM Trn_EdsCortes
 WHERE TipDoc=@pmTipDoc AND Planilla>@pmPlanilla AND IdCia=@pmIdCia AND Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsForItems]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsForItems] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT,@pmItem INT
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumForma,Item,IdProducto,IdBodega,Cantidad,VrPrecio,TarifaIva,VrIva,TarifaDct,VrDcto,Servicios,Descripcion
,ListaPrec,CantDev,CantFact,CdOperario,Comision,CodTarBa,TarifaIba,VrImpuBa,CodTarCup,TarifaCup,VrImpuCup
 FROM Trn_EdsForItems
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie
 AND NumForma=@pmNumForma 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER  BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormas] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumForma,Planilla,IdCia,Fecha,VrTotal,IdCliente,IdAgencia,IdCuenta,pVehiculo,nVehiculo,IdCajero
,IdVend,CdProducto,Cantidad,IdForma,Item,Referencia,CantPuntos,Observacion,TipDcm,Documento,IdCiaDcm,FechaDcm
,AgencDcm,Anulado,NumDev,FecDev,CdCCosto,CdSubCos,VrPrecio,NumRef2,VrBase,VrPrecioEsp
 FROM Trn_EdsFormas
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormas_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormas_Cr]  @pmTipoRango VARCHAR(3),@pmIdRango INT
,@pmNumSerie VARCHAR(5),@pmNumFormaIni INT,@pmNumFormaFin INT
 AS 
 SELECT F.TipoRango AS TipRango,F.IdRango AS NumRango,F.NumSerie AS NroSerie,F.NumForma AS NumVale
,Fecha,VrTotal,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,F.IdCuenta AS  CdCuenta,NomCuenta
,pVehiculo,nVehiculo,IdCajero,Usuario,F.IdVend AS CdVend,V.RazonSocial AS Vendedor
,F.Referencia AS Referncia,NumRef2,F.Observacion AS Observ,CantPuntos,TipDcm,Documento,IdCiaDcm,FechaDcm,AgencDcm
,Anulado,NumDev,FecDev,Planilla,F.IdCia AS CdCia,Compania,F.VrPrecio AS VrPrecioUnd,F.VrBase,F.VrPrecioEsp
--detalles
,D.Item AS nItem,D.IdProducto AS CdProducto,DescripProd,D.IdBodega AS CdBodega,Bodega,D.Cantidad AS Cant,D.VrPrecio,TarifaIva,VrIva,TarifaDct,VrDcto
,Servicios,Descripcion,ListaPrec,PM.IdUnd AS CdUnid,Unidad,CdCCosto,CdSubCos,D.CantDev,D.CantFact,D.CdOperario,OP.RazonSocial AS Operario,D.Comision
 FROM Trn_EdsFormas AS F INNER JOIN Trn_EdsForItems AS D ON F.TipoRango=D.TipoRango
 AND F.IdRango=D.IdRango AND F.NumSerie=D.NumSerie AND F.NumForma=D.NumForma
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia
 INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 INNER JOIN adm_Usuarios AS U ON F.IdCajero=U.IdUsuario
 INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
 INNER JOIN ProdMcias AS PM ON D.IdProducto=PM.IdProducto 
 INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 LEFT JOIN Companias AS C ON F.IdCia=C.IdCia
 LEFT JOIN Terceros AS OP ON D.CdOperario=OP.IdTercero
 WHERE F.TipoRango=@pmTipoRango AND F.IdRango=@pmIdRango
 AND F.NumSerie=@pmNumSerie  AND F.NumForma BETWEEN @pmNumFormaIni AND @pmNumFormaFin
 ORDER  BY D.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasCos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasCos] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
SELECT F.Planilla,F.IdCia,Compania,F.Fecha,F.IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia,A.Agencia AS NomAgencia,F.CdProducto,DescripProd,F.Cantidad,F.VrTotal
,K.VrUnitario AS CostoUnid,K.VrUnitario*F.Cantidad AS CostoTotal,F.TipoRango,F.NumSerie,F.NumForma,F.Referencia,F.NumRef2,F.IdVend,V.RazonSocial AS Vendedor,F.pVehiculo,F.nVehiculo
FROM Trn_EdsFormas AS F LEFT JOIN (SELECT TipDoc,Documento,IdCia,Item,IdProducto,CdTanque,Entradas,Salidas,VrUnitario,VrPrecio,VrCostoEnt,VrCostoSal
FROM Trn_Kardex WHERE TipDoc='PLA' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (IdCia=@pmIdCia OR @pmIdCia IS NULL)
) AS K ON F.Planilla=K.Documento AND F.IdCia=K.IdCia AND F.CdProducto=K.IdProducto
INNER JOIN Companias AS C ON F.IdCia=C.IdCia
INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
INNER JOIN ProdMcias AS P ON F.CdProducto=P.IdProducto 
LEFT JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia
WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin --F.TipoRango='VAL'
AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND F.Anulado=0
UNION ALL
SELECT P.Documento,P.IdCia,Compania,P.Fecha,P.NitCliente,T.RazonSocial,P.CdAgencia,A.Agencia,P.CdProducto,DescripProd,P.Cant_Gals,P.VrPagado
,K.VrUnitario AS CostoUnid,K.VrUnitario*P.Cant_Gals AS CostoTotal,P.IdForma,'',P.NumForma,P.Referncia1,P.Referncia2,'','',P.Referncia2,''
FROM Trn_Pagos AS P LEFT JOIN (SELECT TipDoc,Documento,IdCia,Item,IdProducto,CdTanque,Entradas,Salidas,VrUnitario,VrPrecio,VrCostoEnt,VrCostoSal
FROM Trn_Kardex WHERE TipDoc='PLA' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (IdCia=@pmIdCia OR @pmIdCia IS NULL)
) AS K ON P.TipDoc=K.TipDoc AND P.Documento=K.Documento AND P.IdCia=K.IdCia AND P.CdProducto=K.IdProducto
INNER JOIN Companias AS C ON P.IdCia=C.IdCia INNER JOIN Terceros AS T ON P.NitCliente=T.IdTercero 
INNER JOIN ProdMcias AS PM ON P.CdProducto=PM.IdProducto 
LEFT JOIN Agencias AS A ON P.CdAgencia=A.IdAgencia
WHERE P.TipDoc='PLA' AND P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
AND (P.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND P.FE_Ticket=1
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasFac] @pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 SELECT COUNT(NumForma) AS SCANT
 FROM Trn_EdsFormas
 WHERE Planilla=@pmPlanilla AND IdCia=@pmIdCia AND Documento>0 AND TipDcm<>'PLA' AND TipDcm<>'0'
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT F.TipoRango,F.IdRango,F.NumSerie,F.NumForma,F.Planilla,F.IdCia AS CdCia,Compania,F.Item,F.Fecha,F.VrTotal,F.IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia
,F.IdCuenta AS CdCuenta,NomCuenta,F.pVehiculo,F.nVehiculo,F.IdCajero,Usuario,F.IdVend AS CdVend,V.RazonSocial AS Vendedor,F.CdProducto,DescripProd,F.Cantidad,F.IdForma AS CdForma,FormaPago
,F.Referencia AS Referncia,F.NumRef2,F.CantPuntos,F.Observacion AS Observ,F.TipDcm,F.Documento,F.IdCiaDcm,F.FechaDcm,AgencDcm,F.Anulado,F.NumDev,F.FecDev,F.CdCCosto,F.CdSubCos,F.VrPrecio,F.VrBase,F.VrPrecioEsp
,ISNULL(D.Cant_Neto,0) AS Cant_Neto,ISNULL(D.Cant_Dev,0) AS Cant_Dev,(ISNULL(D.STOTDEV,0)-ISNULL(D.SDCTDEV,0)+ISNULL(D.SIVADEV,0)) AS TotalDev
FROM Trn_EdsFormas AS F INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia
 INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta INNER JOIN adm_Usuarios AS U ON F.IdCajero=U.IdUsuario
 INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN Companias AS C ON F.IdCia=C.IdCia
 LEFT JOIN ProdMcias AS R ON F.CdProducto=R.IdProducto  
 LEFT JOIN (SELECT TipoRango,IdRango,NumSerie,NumForma,SUM(Cantidad-CantDev) AS Cant_Neto,SUM(CantDev) AS Cant_Dev,SUM((Cantidad-CantDev)*VrPrecio) AS SUBTOTAL
,SUM(CASE WHEN (CantDev>0 AND TarifaDct>0 AND VrDcto>0) THEN (((Cantidad-CantDev)*VrPrecio)*TarifaDct)/100 ELSE VrDcto END) AS STOTDCT
,SUM(CASE WHEN (CantDev>0 AND TarifaIva>0 AND VrIva>0) THEN ((((Cantidad-CantDev)*VrPrecio)-((((Cantidad-CantDev)*VrPrecio)*TarifaDct)/100))*TarifaIva)/100 ELSE VrIva END) AS STOTIVA
,SUM(CantDev*VrPrecio) AS STOTDEV,SUM(((CantDev*VrPrecio)*TarifaDct)/100) AS SDCTDEV
,SUM((((CantDev*VrPrecio)-(((CantDev*VrPrecio)*TarifaDct)/100))*TarifaIva)/100) AS SIVADEV
FROM Trn_EdsForItems GROUP BY TipoRango,IdRango,NumSerie,NumForma) AS D ON F.TipoRango=D.TipoRango AND F.IdRango=D.IdRango AND F.NumSerie=D.NumSerie AND F.NumForma=D.NumForma
WHERE (F.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND F.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (F.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasLtp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasLtp] @pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipoRango,F.IdRango,F.NumSerie,F.NumForma,F.Planilla,F.IdCia AS CdCia,Compania,F.Item,F.Fecha,F.VrTotal,F.IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia
,F.IdCuenta AS CdCuenta,NomCuenta,F.pVehiculo,F.nVehiculo,F.IdCajero,Usuario,F.IdVend AS CdVend,V.RazonSocial AS Vendedor,F.CdProducto,DescripProd,F.Cantidad,F.IdForma AS CdForma,FormaPago
,F.Referencia AS Referncia,F.NumRef2,F.CantPuntos,F.Observacion AS Observ,F.TipDcm,F.Documento,F.IdCiaDcm,F.FechaDcm,AgencDcm,F.Anulado,F.NumDev,F.FecDev,F.CdCCosto,F.CdSubCos,F.VrPrecio,F.VrBase,F.VrPrecioEsp
,ISNULL(D.Cant_Neto,0) AS Cant_Neto,ISNULL(D.Cant_Dev,0) AS Cant_Dev,(ISNULL(D.STOTDEV,0)-ISNULL(D.SDCTDEV,0)+ISNULL(D.SIVADEV,0)) AS TotalDev
FROM Trn_EdsFormas AS F INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia
 INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta INNER JOIN adm_Usuarios AS U ON F.IdCajero=U.IdUsuario
 INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN Companias AS C ON F.IdCia=C.IdCia
 LEFT JOIN ProdMcias AS R ON F.CdProducto=R.IdProducto  
 LEFT JOIN (SELECT TipoRango,IdRango,NumSerie,NumForma,SUM(Cantidad-CantDev) AS Cant_Neto,SUM(CantDev) AS Cant_Dev,SUM((Cantidad-CantDev)*VrPrecio) AS SUBTOTAL
,SUM(CASE WHEN (CantDev>0 AND TarifaDct>0 AND VrDcto>0) THEN (((Cantidad-CantDev)*VrPrecio)*TarifaDct)/100 ELSE VrDcto END) AS STOTDCT
,SUM(CASE WHEN (CantDev>0 AND TarifaIva>0 AND VrIva>0) THEN ((((Cantidad-CantDev)*VrPrecio)-((((Cantidad-CantDev)*VrPrecio)*TarifaDct)/100))*TarifaIva)/100 ELSE VrIva END) AS STOTIVA
,SUM(CantDev*VrPrecio) AS STOTDEV,SUM(((CantDev*VrPrecio)*TarifaDct)/100) AS SDCTDEV
,SUM((((CantDev*VrPrecio)-(((CantDev*VrPrecio)*TarifaDct)/100))*TarifaIva)/100) AS SIVADEV
FROM Trn_EdsForItems GROUP BY TipoRango,IdRango,NumSerie,NumForma) AS D ON F.TipoRango=D.TipoRango AND F.IdRango=D.IdRango AND F.NumSerie=D.NumSerie AND F.NumForma=D.NumForma
WHERE F.Planilla=@pmPlanilla AND F.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasPla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasPla] @pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumForma,Planilla,IdCia,Fecha,VrTotal,IdCliente,IdAgencia,IdCuenta,pVehiculo,nVehiculo,IdCajero
,IdVend,CdProducto,Cantidad,IdForma,Item,Referencia,NumRef2,CantPuntos,Observacion,TipDcm,Documento,IdCiaDcm
,FechaDcm,AgencDcm,Anulado,NumDev,FecDev,CdCCosto,CdSubCos
 FROM Trn_EdsFormas
 WHERE Planilla=@pmPlanilla  AND IdCia=@pmIdCia
 ORDER BY TipoRango,IdRango,NumSerie,NumForma
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasRan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasRan] @pmTipoRango VARCHAR(3),@pmIdRango INT
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumForma,Planilla,IdCia,Fecha
 FROM Trn_EdsFormas
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasRel] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT F.TipoRango,F.NumSerie,F.NumForma,F.Planilla AS NumPlanilla,F.IdCia AS CdCia,Compania,F.Fecha AS FechaVale,F.VrTotal,F.IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS Id_Agencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,F.pVehiculo,F.nVehiculo,F.IdCajero AS CdCajero,Usuario,F.IdVend AS NitVend,V.RazonSocial AS Vendedor
,F.CdProducto,DescripProd,F.Cantidad AS Cant,F.VrPrecio AS VrPrecioPub,F.IdCuenta AS CodCuenta,NomCuenta,F.IdForma AS CdForma,FormaPago,F.Referencia AS Referncia,F.NumRef2,F.Observacion AS Observ
,F.TipDcm,F.Documento,F.IdCiaDcm,F.FechaDcm,AgencDcm,AD.Agencia AS DocAgencia,F.Anulado AS EstaAnulado,F.FecDev AS FechaDev
,F.IdRango,F.Item,CP.IdJornada AS CdJornada,Jornada,NumCorte,FecCorte
,ISNULL(D.Cant_Neto,0) AS Cant_Neto,ISNULL(D.Cant_Dev,0) AS Cant_Dev,(ISNULL(D.STOTDEV,0)-ISNULL(D.SDCTDEV,0)+ISNULL(D.SIVADEV,0)) AS TotalDev
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,CdCCosto,F.CdSubCos AS CodSubCos
 FROM Trn_EdsFormas AS F INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 INNER JOIN adm_Usuarios AS U ON F.IdCajero=U.IdUsuario  INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
 INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma  INNER JOIN Companias AS C ON F.IdCia=C.IdCia
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN ProdMcias AS R ON F.CdProducto=R.IdProducto   LEFT JOIN Agencias AS AD ON F.AgencDcm=AD.IdAgencia
 LEFT JOIN Trn_EdsCortes AS CP ON F.Planilla=CP.Planilla AND F.IdCia=CP.IdCia  LEFT JOIN Jornadas AS J ON CP.IdJornada=J.IdJornada
 LEFT JOIN (SELECT TipoRango,IdRango,NumSerie,NumForma,SUM(Cantidad-CantDev) AS Cant_Neto,SUM(CantDev) AS Cant_Dev,SUM((Cantidad-CantDev)*VrPrecio) AS SUBTOTAL
,SUM(CASE WHEN (CantDev>0 AND TarifaDct>0 AND VrDcto>0) THEN (((Cantidad-CantDev)*VrPrecio)*TarifaDct)/100 ELSE VrDcto END) AS STOTDCT
,SUM(CASE WHEN (CantDev>0 AND TarifaIva>0 AND VrIva>0) THEN ((((Cantidad-CantDev)*VrPrecio)-((((Cantidad-CantDev)*VrPrecio)*TarifaDct)/100))*TarifaIva)/100 ELSE VrIva END) AS STOTIVA
,SUM(CantDev*VrPrecio) AS STOTDEV,SUM(((CantDev*VrPrecio)*TarifaDct)/100) AS SDCTDEV
,SUM((((CantDev*VrPrecio)-(((CantDev*VrPrecio)*TarifaDct)/100))*TarifaIva)/100) AS SIVADEV
,SUM(Cantidad) AS Det_Cant,SUM(Cantidad*VrPrecio) AS Det_Total,SUM(VrDcto) AS Det_VrDcto,SUM(VrIva) AS Det_VrIva
FROM Trn_EdsForItems GROUP BY TipoRango,IdRango,NumSerie,NumForma) AS D ON F.TipoRango=D.TipoRango AND F.IdRango=D.IdRango AND F.NumSerie=D.NumSerie AND F.NumForma=D.NumForma
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL)
 AND (F.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasRelDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasRelDet] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT F.TipoRango AS TipRango,F.NumSerie AS Num_Serie,F.NumForma AS NumVale,F.IdCia AS CdCia,Compania,F.Fecha AS FechaVale
--detalle del vale
,FD.Item AS NumItem,FD.IdProducto AS CodProducto,DescripProd,FD.IdBodega AS CdBodega,Bodega,FD.Cantidad AS Cant,FD.VrPrecio,FD.Cantidad*FD.VrPrecio AS ValorTotal,TarifaDct,VrDcto,TarifaIva,VrIva
,Servicios,Descripcion,ListaPrec,FD.CantDev,FD.CantFact,VrTotal AS ValorVale,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS Id_Agencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,pVehiculo,nVehiculo,F.VrPrecio AS VrPrecioPub,F.IdCajero AS CdCajero,Usuario,F.IdVend AS NitVend,V.RazonSocial AS Vendedor
,F.IdCuenta AS CodCuenta,NomCuenta,F.IdForma AS CdForma,FormaPago,F.Referencia AS Referncia,F.NumRef2,F.Observacion AS Observ
,TipDcm,Documento,IdCiaDcm,FechaDcm,AgencDcm,AD.Agencia AS DocAgencia,F.Anulado AS EstaAnulado,F.FecDev AS FechaDev,F.IdRango AS NumRango,Planilla
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,CdCCosto,F.CdSubCos AS CodSubCos,FD.CdOperario,OP.RazonSocial AS Operario,FD.Comision
 FROM Trn_EdsFormas AS F INNER JOIN Trn_EdsForItems AS FD ON F.TipoRango=FD.TipoRango AND F.IdRango=FD.IdRango
 AND F.NumSerie=FD.NumSerie AND F.NumForma=FD.NumForma INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 INNER JOIN adm_Usuarios AS U ON F.IdCajero=U.IdUsuario  INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
 INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma  INNER JOIN Companias AS C ON F.IdCia=C.IdCia
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN ProdMcias AS R ON FD.IdProducto=R.IdProducto INNER JOIN  Bodegas AS B ON FD.IdBodega=B.IdBodega
 LEFT JOIN Agencias AS AD ON F.AgencDcm=AD.IdAgencia LEFT JOIN Terceros AS OP ON FD.CdOperario=OP.IdTercero
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL)
 AND (F.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasTot] @pmPlanilla INT,@pmIdCia CHAR(2)
 AS 
 SELECT SUM(VrTotal) AS STOT,SUM(Cantidad) AS SCANT
 FROM Trn_EdsFormas
 WHERE  Planilla=@pmPlanilla  AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasTotCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasTotCaj]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCajero VARCHAR(11)=Null
 AS 
 SELECT SUM(VrTotal) AS STOTVAL
 FROM Trn_EdsFormas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsFormasVC]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEdsFormasVC] @pmTipDcm VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
AS 
 SELECT TipoRango,NumSerie,NumForma,F.Planilla AS NumPlanilla,F.IdCia AS CdCia,Compania,F.Fecha AS FechaVale,VrTotal,IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS Id_Agencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,pVehiculo,nVehiculo,F.IdCajero AS CdCajero,Usuario,F.IdVend AS NitVend,V.RazonSocial AS Vendedor
,CdProducto,DescripProd,F.Cantidad AS Cant,F.VrPrecio AS VrPrecioPub,F.IdCuenta AS CodCuenta,NomCuenta,F.IdForma AS CdForma,FormaPago,F.Referencia AS Referncia,F.Observacion AS Observ
,TipDcm,Documento,IdCiaDcm,FechaDcm,AgencDcm,AD.Agencia AS DocAgencia,F.Anulado AS EstaAnulado,F.FecDev AS FechaDev
,IdRango,Item,CP.IdJornada AS CdJornada,Jornada,NumCorte,FecCorte
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,CdCCosto,F.CdSubCos AS CodSubCos
 FROM Trn_EdsFormas AS F INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Puc AS P ON F.IdCuenta=P.IdCuenta
 INNER JOIN adm_Usuarios AS U ON F.IdCajero=U.IdUsuario  INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
 INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma  INNER JOIN Companias AS C ON F.IdCia=C.IdCia
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN ProdMcias AS R ON F.CdProducto=R.IdProducto   LEFT JOIN Agencias AS AD ON F.AgencDcm=AD.IdAgencia
 LEFT JOIN Trn_EdsCortes AS CP ON F.Planilla=CP.Planilla AND F.IdCia=CP.IdCia  LEFT JOIN Jornadas AS J ON CP.IdJornada=J.IdJornada
 WHERE TipDcm=@pmTipDcm AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND IdCiaDcm=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsRangos] @pmTipoRango VARCHAR(3),@pmIdRango INT
 AS 
 SELECT TipoRango,IdRango,IdForma,Fecha,FecVence,IdCliente,IdAgencia,pVehiculo,nVehiculo,IdCuenta,NumSerie,NumInicial,NumFinal
,NumTarjeta,VrCupo,VrConsumos,TipoConsumo,ReqPlaca,ReqProd,ReqGalones,VldAgencia,VldPlaca
,Modalidad,Anulado,Observacion,IdEstado,NumAuto,NumActual,Cod_CCosto,Cod_SubCosto,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_EdsRangos
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosFor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsRangosFor] @pmTipoRango VARCHAR(3),@pmNumSerie VARCHAR(5)
,@pmNumForma INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipoRango,IdRango,IdForma,Fecha,FecVence,IdCliente,IdAgencia,pVehiculo,nVehiculo,IdCuenta,NumSerie,NumInicial,NumFinal
,NumTarjeta,VrCupo,VrConsumos,TipoConsumo,ReqPlaca,ReqProd,ReqGalones,VldAgencia,VldPlaca
,Modalidad,Anulado,Observacion,IdEstado,NumAuto,NumActual,Cod_CCosto,Cod_SubCosto,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_EdsRangos
 WHERE TipoRango=@pmTipoRango AND NumSerie=@pmNumSerie
 AND @pmNumForma BETWEEN NumInicial AND NumFinal AND Anulado=0 AND IdCiaCrea=@pmIdCia
 ORDER BY IdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsRangosId] @pmTipoRango VARCHAR(3)
 AS 
 SELECT MAX(IdRango) AS MXITM 
 FROM Trn_EdsRangos
 WHERE TipoRango=@pmTipoRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsRangosLta] @pmTipoRango VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmRangoIni INT=Null,@pmRangoFin INT=Null,@pmIdCliente VARCHAR(16)=Null,@pmNumSerie VARCHAR(5)=Null,@pmAnulado BIT=Null
,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT TipoRango,IdRango,R.IdForma AS CdForma,FormaPago,Fecha,FecVence,IdCliente,RazonSocial,R.IdAgencia AS Id_Agencia,A.Agencia AS NomAgencia,pVehiculo,nVehiculo
,R.IdCuenta AS CdCuenta,NomCuenta,NumSerie,NumInicial,NumFinal,NumTarjeta,VrCupo,VrConsumos,TipoConsumo,ReqPlaca,ReqProd,ReqGalones,VldAgencia,VldPlaca
,Modalidad,R.Observacion AS Observ,Anulado,R.IdEstado AS IdEstad,Estado,NumAuto,NumActual,R.Cod_CCosto,R.Cod_SubCosto,R.IdUsuario AS IdUsuari,Usuario,TimeSys,FecUpdate,IdCiaCrea
 FROM Trn_EdsRangos  AS R INNER JOIN  Formaspago AS F ON R.IdForma=F.IdForma
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero  INNER JOIN Puc AS P ON R.IdCuenta=P.IdCuenta
 INNER JOIN EstadoDoc AS E ON R.IdEstado=E.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 LEFT JOIN  Agencias AS A ON R.IdAgencia=A.IdAgencia
 WHERE TipoRango LIKE ISNULL(@pmTipoRango,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND NumSerie  LIKE ISNULL(@pmNumSerie ,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (IdRango>=ISNULL(@pmRangoIni,0)  AND IdRango<=ISNULL(@pmRangoFin,2147483647))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY TipoRango,IdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosSer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsRangosSer] @pmTipoRango VARCHAR(3),@pmNumSerie VARCHAR(5)
,@pmNumInicial INT,@pmNumFinal INT,@pmIdRango INT
 AS 
 SELECT TipoRango,IdRango,IdForma,Fecha,IdCliente,NumSerie,NumInicial,NumFinal,NumAuto,NumActual
 FROM Trn_EdsRangos
 WHERE TipoRango=@pmTipoRango AND Anulado=0 AND NumSerie=@pmNumSerie
 AND NumInicial<=@pmNumFinal AND NumFinal>=@pmNumInicial AND IdRango<>@pmIdRango
 ORDER BY IdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsRangosTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsRangosTip] @pmTipoRango VARCHAR(3)
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumInicial,NumFinal,NumAuto,NumActual,VrCupo,Modalidad
 FROM Trn_EdsRangos
 WHERE TipoRango=@pmTipoRango AND Anulado=0
 ORDER BY IdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsServicio]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsServicio] @pmIdEstacion VARCHAR(4)
 AS 
 IF @pmIdEstacion IS NULL
  SELECT IdEstacion,EstServicio,Direccion
  FROM EdsServicio
  WHERE Inactivo=0
 ORDER BY EstServicio
 ELSE
  SELECT IdEstacion,EstServicio,Direccion,Inactivo
  FROM EdsServicio
  WHERE IdEstacion=@pmIdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsUnion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsUnion] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,CdTanque,Capacidad,Cantidad,NivAgua,TipoTrasl,NumTraslado,OrigenAdd,Anulado,FecDev,Observacion,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_EdsUnion
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEdsUnion_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEdsUnion_Cr] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc AS Tip_Doc,TipoDoc,N.NumNota,N.IdCia AS CdCia,Compania,N.Fecha,N.CdTanque AS TanqNuevo,T.IdProducto,T.Descripcion,N.Capacidad,N.Cantidad,N.NivAgua
,N.TipoTrasl,N.NumTraslado,N.Anulado,N.FecDev,N.Observacion AS Observ,N.TimeSys AS Fec_Add,N.FecUpdate AS Fec_Update,N.IdCiaCrea,N.IdUsuario AS CdUsuario,U.Usuario AS NomUsuario,N.OrigenAdd
,D.Item,D.IdTanque AS CdTanque,TQ.IdProducto AS CdProducto,TQ.Descripcion AS TanDescripcion,D.Capacidad AS TanCapacidad,D.NivelAgua AS TanNivelAgua,D.Cantidad AS SaldoActual
 FROM Trn_EdsUnion AS N INNER JOIN Trn_EdsUnionItems AS D ON N.TipDoc=D.TipDoc AND N.NumNota=D.NumNota AND N.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Tanques AS TQ ON D.IdTanque=TQ.IdTanque
 LEFT JOIN Tanques AS T ON N.CdTanque=T.IdTanque
 WHERE N.TipDoc=@pmTipDoc AND N.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrAnticipoApl]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrAnticipoApl] @pmSaldo DECIMAL(14,2),@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmTipCom VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT A.IdCuenta AS CdCuenta,NomCuenta,A.IdTercero AS NitTercero,RazonSocial,A.TipCom AS CdTipCom,TC.TipoCom AS TipoComAnt,A.Comprobante AS NumComp
,A.IdCia AS CdCia,CI.Compania AS CompaniaAnt,A.Item AS ItemAnt,A.Fecha AS FechaAnt,VrAnticipo,VrAplicado,VrAnticipo-VrAplicado AS ValorSaldo
,F.TipCom AS FacCdTipo,TCF.TipoCom AS FacTipoComp,F.Comprobante AS FacNumComp,F.IdCia AS FacCiaCom,CIF.Compania AS FacCompania,F.Item AS FacItemCom,VrAbonado,TipFac,Factura,IdCiaFac
,ItemFac,FecFactura,ItemCom
--datos del proveedor
,TipoId,Dv,T.Codigo AS CodigoProv,NomCial,SiglaRaz,T.Direccion AS DirProveedor,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDep,Departamento
,Telefono,Fax,e_mail,SitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_EgrAnticipo AS A INNER JOIN Terceros AS T ON A.IdTercero=T.IdTercero
 INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta INNER JOIN  Companias AS CI ON A.IdCia=CI.IdCia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TiposCom AS TC ON A.TipCom=TC.IdCom  
 LEFT JOIN TercProvee AS TP ON A.IdTercero=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 LEFT JOIN Trn_EgrAntAbonos AS F ON A.TipCom=F.TipCan AND A.Comprobante=F.nAnticipo AND A.IdCia=F.IdCiaAnt AND A.Item=F.ItemAnt
 LEFT JOIN TiposCom AS TCF ON F.TipCom=TCF.IdCom  LEFT JOIN  Companias AS CIF ON F.IdCia=CIF.IdCia
 WHERE (A.VrAnticipo-A.VrAplicado)>@pmSaldo AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND A.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.TipCom LIKE ISNULL(@pmTipCom,'%' )
 AND (A.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND A.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY A.IdCuenta,RazonSocial,A.Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrAnticipoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrAnticipoLta] @pmSaldo DECIMAL(14,2),@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmTipCom VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT A.IdCuenta AS CdCuenta,NomCuenta,A.IdTercero AS NitTercero,RazonSocial,TipCom,TipoCom,Comprobante,A.IdCia AS CdCia,Compania
,Item,Fecha,VrAnticipo,VrAplicado,VrAnticipo-VrAplicado AS ValorSaldo
--datos del proveedor
,TipoId,Dv,T.Codigo AS CodigoProv,NomCial,SiglaRaz,T.Direccion AS DirProveedor,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDep,Departamento
,Telefono,Fax,e_mail,SitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_EgrAnticipo AS A INNER JOIN Terceros AS T ON A.IdTercero=T.IdTercero
 INNER JOIN Puc AS P ON A.IdCuenta=P.IdCuenta INNER JOIN  Companias AS CI ON A.IdCia=CI.IdCia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TiposCom AS TC ON A.TipCom=TC.IdCom  
 LEFT JOIN TercProvee AS TP ON A.IdTercero=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 WHERE (VrAnticipo-VrAplicado)>@pmSaldo AND A.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND A.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND  A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.TipCom LIKE ISNULL(@pmTipCom,'%' )
 AND (A.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND A.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY A.IdCuenta,RazonSocial,Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEgrFactura] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono
,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFactura_Crc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFactura_Crc] @pmTipCom VARCHAR(3),@pmComprobanteIni INT,@pmComprobanteFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT E.TipCom AS CodTipoCom,TipoCom,E.Comprobante AS NumComp,E.IdCia AS IdCiaComp,CI.Compania AS CiaComp,E.Item AS nItem
,Fecha,E.TipFac AS TipoFact,TipoDoc,E.Factura AS NumFactura,IdCiaFac,CF.Compania AS FactCompania
,ItemFac,E.IdProveedor AS NitProveedor,RazonSocial,E.IdCuenta AS CdCuenta,NomCuenta,VrAbono,E.EsEgreso AS Es_Egreso,E.ItemCom AS Item_Comp
,E.pVehiculo AS PlacaVeh,E.VehPropio AS Veh_Espropio,TipDev,NumDev,DetAbono
--datos del vencimiento
,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,C.VrAbonado AS TotalAbonos,C.TipCom AS VencTipCom,C.Comprobante AS VencComp
,C.ItemCom AS VencItemComp,Referencia,Detalle,TipRef,DocRef,IdCiaRef
 FROM Trn_EgrFactura AS E INNER JOIN Trn_ComFactura AS C ON E.TipFac=C.TipFac AND  E.Factura=C.Factura
  AND  E.IdCiaFac=C.IdCia AND  E.ItemFac=C.Item AND  E.IdProveedor=C.IdProveedor
 INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero  INNER JOIN Puc AS P ON E.IdCuenta=P.IdCuenta
 INNER JOIN  Companias AS CI ON E.IdCia=CI.IdCia INNER JOIN Companias AS CF ON E.IdCiaFac=CF.IdCia
 LEFT JOIN Sys_TiposDoc AS TD ON E.TipFac=TD.IdDoc LEFT JOIN  TiposCom AS TC ON E.TipCom=TC.IdCom
 WHERE E.TipCom=@pmTipCom  AND E.Comprobante BETWEEN @pmComprobanteIni AND @pmComprobanteFin  AND E.IdCia=@pmIdCia
 ORDER BY  E.Comprobante,E.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFactura_Fac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFactura_Fac] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2)
,@pmIdProveedor VARCHAR(16),@pmItemFac INT=Null
 AS 
 SELECT  TipCom,TipoCom,Comprobante,E.IdCia AS IdCiaComp,Compania,Item,Fecha,VrAbono,DetAbono,ItemFac
,E.IdCuenta AS IdCuent,NomCuenta,E.EsEgreso AS Es_Egreso,TipDev,NumDev,IdProveedor,RazonSocial,E.ItemCom AS Item_Comp,pVehiculo
 FROM Trn_EgrFactura AS E INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero 
 INNER JOIN Puc AS P ON E.IdCuenta=P.IdCuenta  INNER JOIN  Companias AS CI ON E.IdCia=CI.IdCia
 LEFT JOIN  TiposCom AS TC ON E.TipCom=TC.IdCom
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura  AND IdCiaFac=@pmIdCiaFac AND IdProveedor=@pmIdProveedor
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647))
 ORDER BY Fecha,Comprobante,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaAbo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFacturaAbo] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15) ,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16)
 AS 
 SELECT  SUM(VrAbono) AS StotAbo
 FROM Trn_EgrFactura
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND  IdCiaFac=@pmIdCiaFac  AND IdProveedor=@pmIdProveedor 
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaApl]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFacturaApl] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipFac, Factura, IdCiaFac, ItemFac,IdProveedor,SUM(VrAbono) AS STOTABO
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 GROUP BY TipFac, Factura, IdCiaFac, ItemFac,IdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaDap]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFacturaDap] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmFactura VARCHAR(15)=Null,@pmIdProveedor VARCHAR(16)=Null
 AS 
 SELECT TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,SUM(VrAbono) AS STOTABO
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND TipDev=@pmTipCom AND NumDev=@pmComprobante AND EsEgreso=0
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND Factura LIKE ISNULL(@pmFactura,'%')
 GROUP BY TipFac,Factura,IdCiaFac,ItemFac,IdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFacturaDev] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmFactura VARCHAR(15)=Null,@pmIdProveedor VARCHAR(16)=Null
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono
,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND TipDev=@pmTipCom AND NumDev=@pmComprobante AND EsEgreso=0
 AND IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND Factura LIKE ISNULL(@pmFactura,'%')
ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEgrFacturaDoc] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15) ,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16)
 AS 
 SELECT TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,VehPropio,TipDev,NumDev,DetAbono
 FROM Trn_EgrFactura
 WHERE  TipFac=@pmTipFac AND Factura=@pmFactura AND  IdCiaFac=@pmIdCiaFac AND IdProveedor=@pmIdProveedor
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647)) 
 ORDER BY  TipCom, Comprobante, IdCia, Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEgrFacturaTnit]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEgrFacturaTnit]  @pmIdProveedor VARCHAR(16)
 AS 
 SELECT SUM(VrAbono) AS STOTABO
 FROM Trn_EgrFactura
 WHERE IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_CentrosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_CentrosLta] @pmNContrato INT
 AS 
 SELECT EC.NContrato AS NumContrato,C.IdEmpleado AS IdEmplado,Apellidos,Nombres,FecIngreso,FecRetiro,Indefinido
,EC.IdCCosto AS CdCCosto,CCosto,CodSubCosto,SubCosto,Tarifa,C.Inactivo AS ConInactivo
 FROM Emp_Centros AS EC INNER JOIN Emp_Contrato AS C ON EC.NContrato=C.NContrato
 INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado
 INNER JOIN CentroCosto AS CO ON EC.IdCCosto=CO.IdCCosto
 LEFT JOIN SubCentros AS SC ON EC.CodSubCosto=SC.IdSubCos
 WHERE (EC.NContrato>=ISNULL(@pmNContrato,0)  AND EC.NContrato<=ISNULL(@pmNContrato,2147483647)) 
 ORDER BY EC.NContrato,EC.IdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_Contrato]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_Contrato] @pmNContrato INT
 AS 
 SELECT NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,IdCargo,IdJornada,IdDep,IdArea,IdInstala,IdCCosto,IdSubCos,IdCia,IdNom
,IdClase,TipoTrabj,IdCot,IdGrupo,VrUpc,TipoLiquida,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP
,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,IdEstado,Inactivo,SubTipoCot,DsoSabado,FspFinmes,FecFinPrueba
,TipoPrendDot,TipoMedSent,BenefPacto,TipoTraspaso,FechaTraspaso,ContratoRef,IdMedPago,IdActEco,IdConvCT,CodGrupoCT,CodBaseCT,CodEscfon,FecAdd,FecUpdate,IdUsuario
 FROM Emp_Contrato
 WHERE NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoAct]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoAct] @pmIdEmpleado VARCHAR(16),@pmInactivo BIT=Null
 AS 
 SELECT NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,TipoLiquida,VrSalario,VrAuxTrans,IdEstado,Inactivo,Notas
 FROM Emp_Contrato
 WHERE IdEmpleado=@pmIdEmpleado
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY FecIngreso,NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoAnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoAnt] @pmIdEmpleado VARCHAR(16),@pmNContratoExc INT
 AS 
 SELECT NContrato,IdEmpleado,IdTipCon,FecIngreso,FecVigencia,FecRetiro,Indefinido,IdCargo,IdJornada,IdDep,IdArea,IdInstala,IdCCosto,IdSubCos,IdCia,IdNom
,TipoTrabj,IdCot,IdGrupo,VrUpc,TipoLiquida,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP
,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,IdEstado,Inactivo,SubTipoCot,DsoSabado,FspFinmes,TipoTraspaso,FechaTraspaso,ContratoRef
,FecAdd,FecUpdate,IdUsuario
 FROM Emp_Contrato
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato<>@pmNContratoExc
 ORDER BY FecIngreso,NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoDso] @pmIdEmpleado VARCHAR(16)=Null,@pmIndefinido BIT=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmTipoLiquida CHAR(1)=Null
,@pmSalMinimo BIT=Null,@pmSalIntegral BIT=Null,@pmFPnomina VARCHAR(10)=Null,@pmModoRet INT=Null,@pmIdClase VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmNContrato INT=Null,@pmFecIngresoIni SMALLDATETIME=Null,@pmFecIngresoFin SMALLDATETIME=Null,@pmATFinMes BIT=Null,@pmSegFinMes BIT=Null,@pmDchDotacion BIT=Null
--parametros de empleados
,@pmTipoSangre CHAR(2)=Null,@pmFactorRh CHAR(1)=Null,@pmSexo CHAR(1)=Null,@pmIdEstCivil VARCHAR(4)=Null,@pmClaseLib INT=Null, @pmIdProf VARCHAR(4)=Null,@pmTallaCam VARCHAR(5)=Null
,@pmTallaPan VARCHAR(5)=Null,@pmTallaZap VARCHAR(5)=Null,@pmIdFonPen VARCHAR(8)=Null,@pmIdFonEps VARCHAR(8)=Null,@pmIdFonArp VARCHAR(8)=Null,@pmIdFonCes VARCHAR(8)=Null,@pmIdCajaCom VARCHAR(8)=Null
,@pmIdBanco VARCHAR(4)=Null,@pmEmp_IdEstado VARCHAR(4)=Null,@pmEmp_Inactivo BIT=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null
 AS 
 SELECT  C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,C.FecIngreso,C.FecVigencia,C.FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo
,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania
,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,FspFinmes,DenyPEN,DenyEPS,DenyARP
,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,DsoSabado,FecFinPrueba,TipoPrendDot,TipoMedSent,BenefPacto,C.TipoTraspaso,C.FechaTraspaso,C.ContratoRef,C.IdMedPago,MedioPago,C.IdActEco,AC.IdSector,AC.CodAdicional,AC.DescActividad
,C.IdConvCT,C.CodGrupoCT,C.CodBaseCT,C.CodEscfon,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,C.FecAdd AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,IdCot,C.IdGrupo AS GrupAR,VrUpc
--empleados
,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,E.Telefono,E.TelMovil,E.e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion
,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,E.IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja
,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,E.pVehiculo,V.IdPropietario,NP.RazonSocial AS Propietario,V.IdPoseedor,NT.RazonSocial AS Propietario,V.TipoAfil,V.CdRemque
,FotoEmp,FotoLic,FotoFirma,E.Observacion,E.IdEstado AS Emp_IdEstado,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,E.TipoId,E.Codigo,ET.NColor AS EmpEstcolor,E.FechaAdd AS EmpFecAdd,E.FechaUpdate AS EmpFecupd,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario,SubTipoCot
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 LEFT JOIN NomMediosPago AS MP ON C.IdMedPago=MP.IdMedPago LEFT JOIN NomActividades AS AC ON C.IdActEco=AC.IdActEco
 LEFT JOIN Vehiculos AS V ON E.pVehiculo=V.IdVehiculo LEFT JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero LEFT JOIN Terceros AS NT ON V.IdPoseedor=NT.IdTercero
 WHERE C.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND C.IdSubCos LIKE ISNULL(@pmIdSubCos,'%')  AND C.IdNom LIKE ISNULL(@pmIdNom,'%') 
 AND C.TipoLiquida LIKE ISNULL(@pmTipoLiquida,'%') AND FPnomina LIKE ISNULL(@pmFPnomina,'%')  AND C.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (C.NContrato>=ISNULL(@pmNContrato,0)  AND C.NContrato<=ISNULL(@pmNContrato,2147483647)) 
 AND (ModoRet>=ISNULL(@pmModoRet,0)  AND ModoRet<=ISNULL(@pmModoRet,2147483647)) 
 AND (SalMinimo=ISNULL(@pmSalMinimo,0) or SalMinimo=ISNULL(@pmSalMinimo,1))
 AND (Indefinido=ISNULL(@pmIndefinido,0) or Indefinido=ISNULL(@pmIndefinido,1))
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (ATFinMes=ISNULL(@pmATFinMes,0) or ATFinMes=ISNULL(@pmATFinMes,1))
 AND (SegFinMes=ISNULL(@pmSegFinMes,0) or SegFinMes=ISNULL(@pmSegFinMes,1))
 AND (DchDotacion=ISNULL(@pmDchDotacion,0) or DchDotacion=ISNULL(@pmDchDotacion,1))
 AND (C.FecIngreso>=ISNULL(@pmFecIngresoIni,CAST('19100101' AS SMALLDATETIME)) AND C.FecIngreso<=ISNULL(@pmFecIngresoFin,CAST('20781230' AS SMALLDATETIME)))
 AND TipoSangre LIKE ISNULL(@pmTipoSangre,'%%') AND FactorRh LIKE ISNULL(@pmFactorRh,'%') AND Sexo LIKE ISNULL(@pmSexo,'%')
 AND IdEstCivil LIKE ISNULL(@pmIdEstCivil,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%') AND TallaCam LIKE ISNULL(@pmTallaCam,'%%')
 AND TallaPan LIKE ISNULL(@pmTallaPan,'%%') AND TallaZap LIKE ISNULL(@pmTallaZap,'%%') AND IdFonPen LIKE ISNULL(@pmIdFonPen,'%')
 AND IdFonCes LIKE ISNULL(@pmIdFonCes,'%') AND IdFonArp LIKE ISNULL(@pmIdFonArp,'%') AND IdFonEps LIKE ISNULL(@pmIdFonEps,'%')
 AND IdCajaCom LIKE ISNULL(@pmIdCajaCom ,'%') AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND E.IdEstado LIKE ISNULL(@pmEmp_IdEstado,'%')
 AND (ClaseLib>=ISNULL(@pmClaseLib,0)  AND ClaseLib<=ISNULL(@pmClaseLib,2147483647)) 
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoEca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoEca] @pmIdCargo VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmIdProf VARCHAR(4)=Null,@pmSexo CHAR(1)=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null
AS 
 SELECT C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,TipoId,Codigo,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo
,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia
,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps
,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo
,FotoEmp,FotoLic,FotoFirma,DsoSabado,FecFinPrueba,TipoPrendDot,TipoMedSent,Observacion,E.IdEstado AS Emp_IdEstado,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,ET.NColor AS EmpEstcolor,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario
--datos del contrato
,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion
,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,DchDotacion,DchCafeteria,Reclmto,Notas,C.TipoTraspaso,C.FechaTraspaso,C.ContratoRef,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,SubTipoCot,C.IdMedPago
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE   C.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')  AND C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND Sexo LIKE ISNULL(@pmSexo,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoId]
 AS 
 SELECT MAX(NContrato) AS MXNCON
 FROM Emp_Contrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoLab]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoLab] @pmNContrato INT,@pmInactivo BIT=Null
 AS 
 SELECT  C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo
,C.IdJornada AS IdJrnada,J.Jornada,J.TurnoRotativo,Rangos,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdClase AS CodCla,ClaseRiesgo,Tarifa,TipoTrabj,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdNom AS CodNom
,TipoNomina,Asistencia,NoDevenga,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,FspFinmes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac
,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,DsoSabado,TipoPrendDot,TipoMedSent,C.TipoTraspaso,C.FechaTraspaso,C.ContratoRef,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,C.Inactivo AS Inactvo,IdCot,C.IdGrupo AS GrupAR,VrUpc,SubTipoCot,FecFinPrueba,TN.NomDiario
,C.IdConvCT,C.CodGrupoCT,C.CodBaseCT,C.CodEscfon
--datos del empleado
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp
,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,DecRenta
,E.IdProf AS CodProf,Profesion,Observacion,E.IdEstado AS Emp_IdEstdo,ET.Estado AS Emp_Estdo,E.Inactivo AS Emp_Inactivo
,C.FecAdd AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdUsuario AS IdUsuari,Usuario,LiqEspSalud,DctoSalud,PagoSalud
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado
 WHERE  C.NContrato=@pmNContrato  AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoNom] @pmNContrato INT
 AS 
 SELECT  IdEmpleado,NContrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo
,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdClase AS CodClase,ClaseRiesgo,TipoTrabj,C.IdCCosto AS IdCCto,CCosto
,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdNom AS CodNom,TipoNomina,C.IdEstado AS IdEstdCon,Estado,C.Inactivo AS Inactvo,C.IdUsuario AS IdUsuari,Usuario
 FROM Emp_Contrato AS C  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ContratoVce]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmp_ContratoVce] @pmFecAct SMALLDATETIME,@pmIdTipCon VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmFecIngresoIni SMALLDATETIME=Null,@pmFecIngresoFin SMALLDATETIME=Null,@pmIndefinido BIT=Null,@pmSalIntegral BIT=Null,@pmInactivo BIT=Null
AS
 SELECT C.IdEmpleado AS IdEmplado,Apellidos,Nombres,C.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,Duracion,FecIngreso,FecVigencia,DATEDIFF(day,ISNULL(FecVigencia,@pmFecAct),@pmFecAct) AS DiasVig
,FecFinPrueba,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,C.IdCCosto AS IdCCto,CCosto
,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,ModPromdio,VrSalario,VrAuxTrans,VrUpc,SalMinimo,SalIntegral,FPnomina,ModoRet
,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon
,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,FecRetiro,DsoSabado,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,IdCot,C.IdGrupo AS GrupAR,C.IdJornada AS IdJrnada,Jornada
--empleados
,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion
,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja
,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS Emp_IdEstado
,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,TipoId,Codigo,ET.NColor AS EmpEstcolor,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario
 FROM Emp_Contrato AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE  C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (Indefinido=ISNULL(@pmIndefinido,0) or Indefinido=ISNULL(@pmIndefinido,1))
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (FecIngreso>=ISNULL(@pmFecIngresoIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngresoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_Estudios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_Estudios] @pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT IdEmpleado,Item,Estblecmto,Titulo,Fecha,FecVence,IdClase,Habilitado
 FROM Emp_Estudios
 WHERE IdEmpleado=@pmIdEmpleado 
 AND (Item>=ISNULL(@pmItem,0) AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_EstudiosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_EstudiosDso] @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT ER.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Item,Estblecmto,Titulo,Fecha,FecVence,ER.IdClase,NomClase,Habilitado
 FROM Emp_Estudios AS ER INNER JOIN Empleados AS E ON ER.IdEmpleado=E.IdEmpleado
 LEFT JOIN ClaseCapac AS C ON ER.IdClase=C.IdClase
 WHERE ER.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY ER.IdEmpleado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ExpLaboral]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_ExpLaboral] @pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT IdEmpleado,Item,Empresa,Cargo,FecInicio,FecRetiro,DirEmpresa,TelEmpresa
 FROM Emp_ExpLaboral
 WHERE IdEmpleado=@pmIdEmpleado  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ExpLaboralDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_ExpLaboralDso] @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT L.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Item,Empresa,Cargo,FecInicio,FecRetiro,DirEmpresa,TelEmpresa
 FROM Emp_ExpLaboral AS L INNER JOIN Empleados AS E ON L.IdEmpleado=E.IdEmpleado
 WHERE L.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY L.IdEmpleado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_Parientes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_Parientes] @pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT IdEmpleado,Item,Parntsco,Nombre,FecNacmto,UltGrado,Dirccion,Telefno,TipoRef,NitRef,EmailRef,CargoRef
 FROM Emp_Parientes
 WHERE IdEmpleado=@pmIdEmpleado  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647)) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEmp_ParientesDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmp_ParientesDso] @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT P.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Item,Parntsco,Nombre,P.FecNacmto AS FechaNaci,UltGrado,Dirccion,Telefno
,TipoRef,NitRef,EmailRef,CargoRef
 FROM Emp_Parientes AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado
 WHERE P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY P.IdEmpleado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpaques]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpaques] @pmIdEmp VARCHAR(4)
 AS 
 IF @pmIdEmp IS NULL
 SELECT IdEmp,Empaque,CodMintra
 FROM Empaques
 WHERE Inactivo=0
 ORDER BY IdEmp
 ELSE
 SELECT IdEmp,Empaque,CodMintra,Inactivo
 FROM Empaques
 WHERE IdEmp=@pmIdEmp
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleados] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte
,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,CdFonAvp,IdClase,NumCuenta
,IdBanco,CdLocCue,NContrato,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,DecRenta,FotoEmp,FotoLic,FotoFirma,Observacion,NivelEduc,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosBus]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosBus] @pmCodigo VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte
,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,CdFonAvp,IdClase,NumCuenta
,IdBanco,CdLocCue,NContrato,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,FotoEmp,FotoLic,FotoFirma,EsCondtor,pVehiculo,DecRenta,Observacion,NivelEduc,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Empleados
 WHERE  Codigo=@pmCodigo
 ORDER BY IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCna]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosCna] @pmIdNom VARCHAR(4),@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT E.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.NContrato AS NumContrato,IdArea,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
 WHERE E.Inactivo=0 AND  IdNom=@pmIdNom  AND IdArea LIKE ISNULL(@pmIdArea,'%') AND IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER  BY E.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosCnt] @pmIdNom VARCHAR(4),@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT E.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.TipoId,E.Dv,IdLugarCed,LC.Localidad AS LugarCed,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom
,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,E.NContrato AS NumContrato,FecUltIng,FecUltRet,FecVincula,NCAnterior,FecIngAnt,FecRetAnt
,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,FecUltAum,FecUltCes
,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,FecUltParc,EsCondtor,pVehiculo,DecRenta,E.IdEstado AS IdEst_Emp,ET.Estado AS Estad_Emp,E.Inactivo AS Inctivo,Codigo,E.IdUsuario  AS IdUsuar
--datos del contrato
,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,J.Jornada,J.TurnoRotativo,Rangos,C.IdArea AS CodArea,Area,C.IdDep AS CodDep
,Dependencia,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac
,DenyHex,DenyDcto,BasePrest,BaseSeg,DchDotacion,DchCafeteria,TipoTrabj,IdCot,SubTipoCot,IdGrupo,VrUpc,Reclmto,Notas,C.IdEstado AS IdEst_Con,EC.Estado AS Estad_Con,C.Inactivo AS Inactvo,CdFonAvp,FspFinmes,FecFinPrueba
,LiqEspSalud,DctoSalud,PagoSalud,TN.NomDiario,C.TipoTraspaso,C.FechaTraspaso,C.ContratoRef,C.IdConvCT,C.CodGrupoCT,C.CodBaseCT,C.CodEscfon
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
 INNER JOIN  Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado
 WHERE E.Inactivo=0 AND  C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER  BY E.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCod]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosCod] @pmIdEmpleado VARCHAR(16),@pmCodigo VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,TipoId,Dv,IdLugarCed,Direccion,IdLocal,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte
,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdProf,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,CdFonAvp,IdClase,NumCuenta
,IdBanco,CdLocCue,NContrato,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecVincula,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,FotoEmp,FotoLic,FotoFirma,EsCondtor,pVehiculo,DecRenta,Observacion,NivelEduc,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado or Codigo=@pmCodigo
 ORDER BY IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosCon] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT E.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.NContrato AS NContrto,Indefinido,IdDep,IdCCosto,IdNom,TipoLiquida,IdInstala,C.IdClase AS IdClaRie,ClaseRiesgo,Tarifa,TipoTrabj
,ModPromdio,VrSalario,FecVincula,NCAnterior,FecIngAnt,FecRetAnt,VrAuxTrans,SalMinimo,SalIntegral,E.IdEstado AS Emp_IdEstdo,E.Inactivo AS Emp_Inactivo,C.IdEstado AS Con_IdEstdo,C.Inactivo AS Con_Inactivo,C.IdConvCT
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato AND E.IdEmpleado=C.IdEmpleado
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 WHERE E.IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosDso] @pmTipoSangre CHAR(2)=Null,@pmFactorRh CHAR(1)=Null,@pmSexo CHAR(1)=Null,@pmIdEstCivil VARCHAR(4)=Null,@pmClaseLib INT=Null, @pmIdProf VARCHAR(4)=Null,@pmTallaCam VARCHAR(5)=Null
,@pmTallaPan VARCHAR(5)=Null,@pmTallaZap VARCHAR(5)=Null,@pmIdFonPen VARCHAR(8)=Null,@pmIdFonEps VARCHAR(8)=Null,@pmIdFonArp VARCHAR(8)=Null,@pmIdFonCes VARCHAR(8)=Null,@pmIdCajaCom VARCHAR(8)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmNContrato INT=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT Apellidos,Nombres,TipoId,IdEmpleado,IdLugarCed,LC.Localidad AS LugarCed,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,LibMilitar,ClaseLib
,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo
,ConyFing,ConyTel,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,NContrato,FecVincula
,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,DecRenta,NivelEduc,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS IdEstdo,Estado,E.Inactivo AS Inctivo,Dv,Codigo,NColor,FechaAdd,FechaUpdate,E.IdUsuario AS IdUsuari,Usuario,CdFonAvp
 FROM Empleados AS E INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 WHERE IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND TipoSangre LIKE ISNULL(@pmTipoSangre,'%%') AND FactorRh LIKE ISNULL(@pmFactorRh,'%') AND Sexo LIKE ISNULL(@pmSexo,'%')
 AND IdEstCivil LIKE ISNULL(@pmIdEstCivil,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%') AND TallaCam LIKE ISNULL(@pmTallaCam,'%%')
 AND TallaPan LIKE ISNULL(@pmTallaPan,'%%') AND TallaZap LIKE ISNULL(@pmTallaZap,'%%') AND IdFonPen LIKE ISNULL(@pmIdFonPen,'%')
 AND IdFonCes LIKE ISNULL(@pmIdFonCes,'%') AND IdFonArp LIKE ISNULL(@pmIdFonArp,'%') AND IdFonEps LIKE ISNULL(@pmIdFonEps,'%')
 AND IdCajaCom LIKE ISNULL(@pmIdCajaCom ,'%') AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (ClaseLib>=ISNULL(@pmClaseLib,0)  AND ClaseLib<=ISNULL(@pmClaseLib,2147483647)) 
 AND (NContrato>=ISNULL(@pmNContrato,-1)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (E.Inactivo=ISNULL(@pmInactivo,0) or E.Inactivo=ISNULL(@pmInactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosFam]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosFam] @pmTipoSangre CHAR(2)=Null,@pmFactorRh CHAR(1)=Null,@pmSexo CHAR(1)=Null,@pmIdEstCivil VARCHAR(4)=Null,@pmClaseLib INT=Null, @pmIdProf VARCHAR(4)=Null,@pmTallaCam CHAR(2)=Null
,@pmTallaPan CHAR(2)=Null,@pmTallaZap CHAR(2)=Null,@pmIdFonPen VARCHAR(8)=Null,@pmIdFonEps VARCHAR(8)=Null,@pmIdFonArp VARCHAR(8)=Null,@pmIdFonCes VARCHAR(8)=Null,@pmIdCajaCom VARCHAR(8)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmNContrato INT=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmEsCondtor BIT=Null,@pmFecNacmtoIni SMALLDATETIME=Null,@pmFecNacmtoFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT Apellidos,Nombres,TipoId,E.IdEmpleado,IdLugarCed,LC.Localidad AS LugarCed,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,E.FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,LibMilitar,ClaseLib
,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap,UsaGafas,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo
,ConyFing,ConyTel,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,NContrato,FecVincula
,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,DecRenta,NivelEduc,FotoEmp,FotoLic,FotoFirma,Observacion,E.IdEstado AS IdEstdo,Estado,E.Inactivo AS Inctivo,Dv,Codigo,NColor,FechaAdd,FechaUpdate,E.IdUsuario AS IdUsuari,Usuario,CdFonAvp
--familiares
,Item,Parntsco,Nombre,EF.FecNacmto AS FechaNcmto,UltGrado,Dirccion,Telefno
 FROM Empleados AS E INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 LEFT JOIN Emp_Parientes AS EF ON E.IdEmpleado=EF.IdEmpleado
 WHERE E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND TipoSangre LIKE ISNULL(@pmTipoSangre,'%%') AND FactorRh LIKE ISNULL(@pmFactorRh,'%') AND Sexo LIKE ISNULL(@pmSexo,'%')
 AND IdEstCivil LIKE ISNULL(@pmIdEstCivil,'%') AND E.IdProf LIKE ISNULL(@pmIdProf,'%') AND TallaCam LIKE ISNULL(@pmTallaCam,'%%')
 AND TallaPan LIKE ISNULL(@pmTallaPan,'%%') AND TallaZap LIKE ISNULL(@pmTallaZap,'%%') AND IdFonPen LIKE ISNULL(@pmIdFonPen,'%')
 AND IdFonCes LIKE ISNULL(@pmIdFonCes,'%') AND IdFonArp LIKE ISNULL(@pmIdFonArp,'%') AND IdFonEps LIKE ISNULL(@pmIdFonEps,'%')
 AND IdCajaCom LIKE ISNULL(@pmIdCajaCom ,'%') AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (ClaseLib>=ISNULL(@pmClaseLib,0)  AND ClaseLib<=ISNULL(@pmClaseLib,2147483647)) 
 AND (NContrato>=ISNULL(@pmNContrato,-1)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (E.Inactivo=ISNULL(@pmInactivo,0) or E.Inactivo=ISNULL(@pmInactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (E.FecNacmto>=ISNULL(@pmFecNacmtoIni,CAST('19100101' AS SMALLDATETIME)) AND E.FecNacmto<=ISNULL(@pmFecNacmtoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosLab]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosLab] @pmIdEmpleado VARCHAR(16),@pmCodigo VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,TipoId,Dv,IdLugarCed,LC.Localidad AS LugarCed,E.IdProf AS CodProf,Profesion,TallaCam,TallaPan,TallaZap
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom
,CC.Fondo AS CajaComp,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,CdLocCue,NContrato,FecVincula
,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,FecUltAum,FecUltCes
,FecUltPri,FecUltVac,FecUltIng,FecUltRet,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,DecRenta,NivelEduc
,E.IdEstado AS IdEstdo,Estado,E.Inactivo AS Inctivo,Codigo,IdUsuario,CdFonAvp
 FROM Empleados AS E INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado
 WHERE IdEmpleado=@pmIdEmpleado OR Codigo=@pmCodigo
 ORDER  BY IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosReg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosReg] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,Codigo,Direccion,IdLocal,Telefono,e_mail,NContrato,FecVincula
 FROM Empleados
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosSue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosSue] @pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null
,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmSalMinimo BIT=Null,@pmSalIntegral BIT=Null,@pmIdEmpleado VARCHAR(16),@pmInactivo BIT=Null
,@pmEmp_Inactivo BIT=Null,@pmEsCondtor BIT=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT E.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Codigo,FecNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco
,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes,IdCajaCom,CC.Fondo AS CajaComp,FecUltAum,FecVincula,FecUltDot,FecUltParc,NCAnterior,FecIngAnt
,FecRetAnt,EsCondtor,pVehiculo,E.IdEstado AS Emp_IdEstdo,ET.Estado AS Emp_Estado,E.Inactivo AS Emp_Inactvo
--datos del contrato
,E.NContrato AS NCntrato,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion
,C.IdCCosto AS IdCCto,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina
,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,DenyHex,BasePrest,BaseSeg,DchDotacion,DchCafeteria,Reclmto,Notas,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor
,C.Inactivo AS Inactvo,C.FecAdd AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdUsuario AS IdUsuari,Usuario
 FROM Empleados  AS E INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo  INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo 
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado 
 INNER JOIN Emp_Contrato AS C  ON E.IdEmpleado=C.IdEmpleado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 WHERE  C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')  AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')   AND  C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND  E.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (SalMinimo=ISNULL(@pmSalMinimo,0) or SalMinimo=ISNULL(@pmSalMinimo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Apellidos,Nombres,E.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosVac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosVac] @pmDias INT,@pmFecVacIni SMALLDATETIME,@pmFecVacFin SMALLDATETIME,@pmIdProf VARCHAR(4)=Null
,@pmEmp_IdEstado VARCHAR(4)=Null,@pmEmp_Inactivo BIT=Null,@pmEsCondtor BIT=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmFecIngresoIni SMALLDATETIME=Null,@pmFecIngresoFin SMALLDATETIME=Null,@pmSalIntegral BIT=Null
 AS 
 SELECT E.IdEmpleado AS IdEmplado,Apellidos,Nombres,Codigo,TipoId,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,FecNacmto,LugarNacmto,TipoSangre
,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia
,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase
,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
,IdCajaCom,CC.Fondo AS CajaComp,E.NContrato AS NCntrato,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,FecUltParc,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo,FotoEmp,FotoLic
,FotoFirma,Observacion,E.IdEstado AS Emp_IdEstado,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,ET.NColor AS EmpEstcolor,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario
--Datos del contrato
,C.IdTipCon AS CodTCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdJornada AS IdJrnada,Jornada,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdCCosto AS IdCCto
,CCosto,C.IdSubCos AS IdSubcen,SubCosto,C.IdCia AS CodCia,Compania,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,ModPromdio,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina
,ModoRet,FecAfiSeg,ATFinMes,SegFinMes,DenyCes,DenyPri,DenyVac,DchDotacion,DchCafeteria,C.IdEstado AS IdEstdCon,EC.Estado AS EstdoCon,EC.NColor AS ConEstcolor,C.Inactivo AS Inactvo,C.IdUsuario AS IdUsuari,U.Usuario AS Con_Usuario,VrUpc
,IdCot,C.IdGrupo AS GrupAR
--Dias parciales disfrutados SP Original
--,dbo.FuncNomVacParcial(E.IdEmpleado,ISNULL(FecUltVac,FecIngreso),@pmFecVacFin) AS DiasDisf
--,dbo.FuncNomVacParcRem(E.IdEmpleado,ISNULL(FecUltVac,FecIngreso),@pmFecVacFin) AS DiasRem
--Dias parciales disfrutados Func modificadas por Dpto. Soporte Feb 6/2024
,dbo.FuncNomVacParcial(E.IdEmpleado,DATEADD(day,1,ISNULL(FecUltVac,FecIngreso)),@pmFecVacFin) AS DiasDisf
,dbo.FuncNomVacParcRem(E.IdEmpleado,DATEADD(day,0,ISNULL(FecUltVac,FecIngreso)),@pmFecVacFin) AS DiasRem
 FROM Empleados AS E INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo 
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada INNER JOIN Dependencias AS D ON C.IdDep=D.IdDep 
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala 
 INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom 
 INNER JOIN EstadoDoc AS EC ON C.IdEstado=EC.IdEstado  INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 WHERE DATEADD(day,@pmDias,ISNULL(FecUltVac,FecIngreso)) BETWEEN @pmFecVacIni AND @pmFecVacFin AND E.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND E.IdEstado LIKE ISNULL(@pmEmp_IdEstado,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND C.IdCargo LIKE ISNULL(@pmIdCargo,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (EsCondtor=ISNULL(@pmEsCondtor,0) or EsCondtor=ISNULL(@pmEsCondtor,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (SalIntegral=ISNULL(@pmSalIntegral,0) or SalIntegral=ISNULL(@pmSalIntegral,1))
 AND (FecIngreso>=ISNULL(@pmFecIngresoIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngresoFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryEmpleadosVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEmpleadosVeh]  @pmpVehiculo VARCHAR(10),@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdEmpleado,Apellidos,Nombres,NContrato,EsCondtor,pVehiculo
 FROM Empleados
 WHERE Inactivo=0 AND pVehiculo=@pmpVehiculo AND  IdEmpleado<>@pmIdEmpleado
 ORDER BY IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryEntArticulosPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntArticulosPro] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4)=Null
 AS 
 SELECT Item,IdProducto,IdBodega,Entradas,Salidas,VrUnitario,TarifaIva,VrIva,TarifaDct,VrDcto
,TipOrd,NumOrden,IdCiaOrd,TipSal,NumSalida,IdCiaSal
 FROM Trn_EntArticulos
  WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia 
 AND IdProducto=@pmIdProducto AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEntidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntidades] @pmIdTabla VARCHAR(20)
 AS 
 SELECT IdTabla,NivelRel,CamposPK,FngKey,Sp_Qry,Sp_Qpmt,Sp_Ins,Sp_Upd,Sp_Del
 FROM Sys_Entidades
 WHERE IdTabla LIKE ISNULL(@pmIdTabla,'%')
 ORDER BY IdTabla
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Entrada,IdCia,Fecha,IdConcepto,IdProv,Factura,FechaFac,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,BaseIvaIgp,VrIvaIngProd
,TipOdc,OCompra,IdCiaOdc,MulPlazos,IdPlazo,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv
,CdCCosto,CdSubCos,TipEgr,Egreso,IdCiaEgr,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion
,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,VrImpuCons,VrSobtasaCons
,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop,ImpAviTab,TarifaAvta,CodTarifAvta,VrImpuBA,VrImpuCUP
 FROM Trn_Entradas
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradas_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradas_Cr]  @pmTipDoc VARCHAR(3),@pmEntradaIni INT,@pmEntradaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT E.TipDoc AS Tip_Doc,TipoDoc,Entrada,E.IdCia AS CdCia,Compania,E.Fecha AS FechaDoc,E.IdConcepto AS CdConcepto,Concepto,E.IdProv AS NitPrevee,RazonSocial,E.Factura AS NumFactura,E.FechaFac,E.FechaVence
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrImpCarbono,VrIvaIngProd,VrNeto
,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CxPagar,DocEquiv,E.BaseImp,E.BaseRet,E.BaseIca,BaseRiv,BaseIvaIgp
,E.TarifaIva AS TarifIva,E.TarifaRet AS TarifRet,E.TarifaIca AS TarifIca,TarifaRiv,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,E.CodTarifBom,E.VrBomberil,E.TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons,E.ImpAviTab,E.TarifaAvta,E.CodTarifAvta
,E.VrImpuBA,E.VrImpuCUP,E.CdCCosto AS CodCenCosto,CC.CCosto AS CentCosto,E.CdSubCos AS CodSubCent,SC.SubCosto AS SubcCosto,E.TipEgr,E.Egreso,E.IdCiaEgr,E.Modalidad,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop
,E.TipCom,TipoCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.NumDev,E.FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,E.OrigenAdd,E.TimeSys AS Fec_add,E.FecUpdate AS Fec_Update,E.IdCiaCrea,E.IdUsuario AS CdUsuario,Usuario,Leyenda
--Información del tercero
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
--Detalle
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo,K.Referencia AS KarReferencia,Descripcion,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,K.Factura AS KarFactura,K.TipDocDev,K.NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,K.CdMoneda,K.VrTasaCamb,K.VrDivisa1,K.VrDivisa2,K.VrDivisa3,Referencia2,FecOrden,CodTarIco,TarifaIco,VrImpCon,TarifaStc,SobtasaCons,VrImvCosto,K.BaseIvp,K.TarifaIvp,K.IvaIngProd
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
--datos memo
,Comentarios,CantImp
--datos de resolucion doc. equivalente
,DS.CodRes,DS.DescServicio,RS.Resolucion,RS.Prefijo,RS.NumInicial,RS.NumFinal,RS.FechaExpRes,RS.FechaVigencia,RS.Establecimiento
 FROM Trn_Entradas AS E INNER JOIN Trn_Kardex AS K ON E.TipDoc=K.TipDoc AND E.Entrada=K.Documento AND E.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON E.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN TiposCom AS TC ON E.TipCom=TC.IdCom
 LEFT JOIN CentroCosto AS CC ON E.CdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON E.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON E.IdProv=TP.IdProv 
 LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 LEFT JOIN Trn_DocMemo AS MM ON E.TipDoc=MM.TipDoc AND E.Entrada=MM.Documento AND E.IdCia=MM.IdCia
 --datos de resolucion
 LEFT JOIN Trn_DocSoporte DS ON E.TipSop=DS.TipDoc AND E.NumDocSop=DS.NumDoc AND E.CdCiaSop=DS.IdCia
 LEFT JOIN TiposComRes AS RS ON DS.CodRes=RS.IdRes
 WHERE E.TipDoc=@pmTipDoc AND Entrada BETWEEN @pmEntradaIni AND @pmEntradaFin  AND E.IdCia=@pmIdCia
 ORDER BY Entrada,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasEqv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasEqv] @pmFactura VARCHAR(15),@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Entrada,IdCia,Fecha,IdProv,Factura,FechaFac,FechaVence,CxPagar,Anulado
 FROM Trn_Entradas
 WHERE  Factura=@pmFactura AND IdCia=@pmIdCia
 ORDER BY Entrada
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasFac] @pmIdProv VARCHAR(16),@pmFactura VARCHAR(15),@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Entrada,IdCia,Fecha,IdProv,Factura,FechaFac,FechaVence,CxPagar,Anulado
 FROM Trn_Entradas
 WHERE IdProv=@pmIdProv AND Factura=@pmFactura AND IdCia=@pmIdCia
 ORDER BY Entrada
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasIns]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasIns]  @pmTipDoc VARCHAR(3),@pmEntradaIni INT=Null,@pmEntradaFin INT=Null,@pmIdCia CHAR(2)=Null
,@pmIdProv VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT Entrada,E.IdCia AS CdCia,Compania,E.Fecha AS FechaDoc,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega
,Entradas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,Entradas*VrUnitario AS CostoTotal,K.TarifaIva AS KarTarifIva,VrIvaEnt
,TarifaDct,VrDctoEnt,K.Referencia AS KarReferencia,Descripcion,Unidades,TipOrd,NumOrden,IdCiaOrd,Remision,IdCiaRem
,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro
,E.IdProv AS NitPrevee,RazonSocial,E.Factura AS NumFactura,E.IdConcepto AS CdConcepto,Concepto,E.Observacion AS Observ
 FROM Trn_Entradas AS E INNER JOIN Trn_Kardex AS K ON E.TipDoc=K.TipDoc AND E.Entrada=K.Documento AND E.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero
 INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto 
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega  INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 WHERE E.TipDoc=@pmTipDoc AND Anulado=0
 AND Entrada BETWEEN ISNULL(@pmEntradaIni,0) AND ISNULL(@pmEntradaFin,2147483647)
 AND E.IdCia LIKE ISNULL(@pmIdCia,'%%') AND E.IdProv LIKE ISNULL(@pmIdProv,'%')
 AND (E.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND E.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY E.IdCia,Entrada,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmEntradaIni INT=Null,@pmEntradaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Entrada,IdCia,Fecha,E.IdConcepto AS CdConcepto,Concepto,IdProv,RazonSocial,Factura,FechaFac,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros
,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrBomberil,VrIvaIngProd,VrNeto,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,IdPlazo,CxPagar,DocEquiv
,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaBom,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarifBom,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,ImpAviTab,TarifaAvta,CodTarifAvta
,E.VrImpuBA,E.VrImpuCUP,CdCCosto,CdSubCos,TipEgr,Egreso,IdCiaEgr,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,VrImpuCons,VrSobtasaCons,Modalidad,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,E.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_Entradas AS E INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero
 INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Entrada BETWEEN ISNULL(@pmEntradaIni,0) AND ISNULL(@pmEntradaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%') AND E.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND E.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Entrada
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasNet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasNet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmCxPagar BIT=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Entrada,E.IdCia AS CdCia,Compania,Fecha,E.IdConcepto AS CdConcepto,Concepto,E.IdProv AS NitPrevee,T.RazonSocial AS NomProveedor,Factura,FechaFac,FechaVence
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrReteCREE,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrBomberil,VrIvaIngProd,VrNeto
,Cantidad,NitFletes,TF.RazonSocial AS NomFletes,VrRetFlete,VrIcaFlete,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIvaIgp
,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,TarifaBom,VrIvaMvc,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons,E.ImpAviTab,E.TarifaAvta,E.CodTarifAvta,E.VrImpuBA,E.VrImpuCUP,CdCCosto,CCosto,CdSubCos,SubCosto,Modalidad
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,TimeSys,E.FecUpdate AS Fec_Update,IdCiaCrea,E.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDV,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCodLocal,Localidad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS TercCodSector,SectorEco,T.IdRegimen AS TercCodRegimen,Regimen,T.TipEnte AS TercTipoEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga,Autoret
 FROM Trn_Entradas AS E INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN CentroCosto AS CC ON E.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON E.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON E.IdProv=TP.IdProv LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Terceros AS TF ON E.NitFletes=TF.IdTercero
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
  AND E.IdCia LIKE ISNULL(@pmIdCia,'%%') AND E.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND E.IdProv LIKE ISNULL(@pmIdProv,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (CxPagar=ISNULL(@pmCxPagar,0) or CxPagar=ISNULL(@pmCxPagar,1))
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.IdProv AS NitProvee,T.RazonSocial AS NomProveedor
,D.Factura AS NumFactura,FechaFac,FechaVence,D.VrSubTotal AS SubTotal,D.VrDescuento AS Descuento,D.VrImpuesto AS Impuesto,D.VrRetencion AS ReteFte,D.VrReteICA AS ReteICA
,D.VrReteIVA AS ReteIva,D.VrReteCREE,D.VrFletes AS Fletes,D.VrOtros AS ValOtros,D.VrSobretasa AS Sobretasas,D.VrImpGlobal AS ImpGlobal,D.VrCargos AS OtrosCargos,D.VrOtrDcto AS OtrosDctos
,D.VrBomberil,D.VrIvaIngProd,D.VrNeto AS TotalNeto,D.Cantidad AS CantDev,D.NitFletes AS Nit_Fletes,TF.RazonSocial AS NomFletes,D.VrRetFlete,D.VrIcaFlete,D.FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago
,D.CxPagar AS Cx_Pagar,D.DocEquiv AS DocEquival,D.BaseImp AS VrBaseIva,D.BaseRet AS VrBaseRet,D.BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,D.TarifaRtc,D.TarifaBom,D.VrIvaMvc,D.BaseIvaObsq,D.VrIvaObsequio,D.VrImpuCons,D.VrSobtasaCons
,D.ImpAviTab,D.TarifaAvta,E.CodTarifAvta,D.VrImpuBA,D.VrImpuCUP,D.CdCCosto AS CodCcost,CCosto,D.CdSubCos AS CodSubCent,SubCosto,D.Modalidad AS ModalidadEnt,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CodCiaComp,0,D.Entrada AS NumEntrada,FecDoc
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS FecAdd,D.FecUpdate AS Fec_Update,D.IdCiaCrea AS CodCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDV,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCodLocal,Localidad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS TercCodSector,SectorEco,T.IdRegimen AS TercCodRegimen,Regimen,T.TipEnte AS TercTipoEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga,Autoret
 FROM Trn_DevEnt AS D INNER JOIN Terceros AS T ON D.IdProv=T.IdTercero 
 INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_Entradas AS E ON D.TipDoc=E.TipDoc AND D.Entrada=E.Entrada AND D.IdCiaDoc=E.IdCia
 INNER JOIN Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON D.IdProv=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Terceros AS TF ON D.NitFletes=TF.IdTercero
 WHERE D.TipDoc=@pmTipDoc AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND E.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdProv LIKE ISNULL(@pmIdProv,'%') AND D.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (D.CxPagar=ISNULL(@pmCxPagar,0) or D.CxPagar=ISNULL(@pmCxPagar,1)) 
 ORDER BY E.IdCia,Entrada
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasNetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasNetDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
 SELECT E.TipDoc,E.Entrada,E.IdCia AS CdCia,Compania,E.Fecha,E.IdConcepto AS CdConcepto,Concepto,E.IdProv AS NitPrevee,T.RazonSocial AS NomProveedor,E.Factura,E.FechaFac,E.FechaVence
,E.VrSubTotal,E.VrDescuento,E.VrImpuesto,E.VrRetencion,E.VrReteICA,E.VrReteIVA,E.VrReteCREE,E.VrFletes,E.VrOtros,E.VrSobretasa,E.VrImpGlobal,E.VrCargos,E.VrOtrDcto,E.VrBomberil,E.VrNeto
,E.NitFletes,TF.RazonSocial AS NomFletes,E.VrRetFlete,E.VrIcaFlete,E.FletesCosto,E.TipOdc,E.OCompra,E.IdCiaOdc,E.MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,E.CxPagar,E.DocEquiv,E.BaseImp,E.BaseRet
,E.TarifaRet,E.TarifaIca,E.TarifaRiv,E.TarifaRtc,E.TarifaBom,E.VrIvaMvc,E.VrImpuCons,E.VrSobtasaCons,E.ImpAviTab,E.TarifaAvta,E.CodTarifAvta,E.VrImpuBA,E.VrImpuCUP,E.Modalidad
--detalles
 ,K.Item,K.IdProducto AS CdProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,K.Entradas,K.Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,K.VrUnitario
,VrCostoEnt,VrCostoSal,K.TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaIva,VrIvaEnt,VrIvaSal,K.Sobretasa,K.Soldicom,K.ImpGlobal,K.VrCostProm,K.Unidades,K.Descripcion,K.Referencia,Referencia2
,K.TipOrd,K.NumOrden,K.IdCiaOrd,TipDocDev,K.NumDocDev,OtroImpto,K.VrBruto,K.VrBase,K.Servcios,K.VrImvCosto,K.TarifaIco,K.VrImpCon,K.CantObseq,K.VrIvaObseq,K.BaseIvp,K.TarifaIvp,K.IvaIngProd,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarBa,K.TarifaCup,K.VrImpuCup AS KarImpuCup,K.CodTarCup
,K.CdTanque,K.CdCCosto,CCosto,K.CdSubCos,SubCosto,E.TipCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.NumDev,FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,E.TimeSys,E.FecUpdate AS Fec_Update,IdCiaCrea,E.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDV,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCodLocal,Localidad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS TercCodSector,SectorEco,T.IdRegimen AS TercCodRegimen,Regimen,T.TipEnte AS TercTipoEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga,Autoret
 FROM Trn_Entradas AS E INNER JOIN Trn_Kardex AS K ON E.TipDoc=K.TipDoc AND E.Entrada=K.Documento AND E.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero
 INNER JOIN Conceptos AS C ON E.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario INNER JOIN  Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON E.IdProv=TP.IdProv LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Terceros AS TF ON E.NitFletes=TF.IdTercero
 WHERE E.TipDoc=@pmTipDoc AND E.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND E.IdCia LIKE ISNULL(@pmIdCia,'%%')
 UNION ALL
 SELECT D.TipDev,D.Devolucion,D.IdCia,Compania,D.Fecha,D.IdConcepto,Concepto,D.IdProv,T.RazonSocial,D.Factura,E.FechaFac,E.FechaVence
,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrRetencion,D.VrReteICA,D.VrReteIVA,D.VrReteCREE,D.VrFletes,D.VrOtros,D.VrSobretasa,D.VrImpGlobal,D.VrCargos,D.VrOtrDcto,D.VrBomberil,D.VrNeto
,D.NitFletes,TF.RazonSocial,D.VrRetFlete,D.VrIcaFlete,D.FletesCosto,E.TipOdc,E.OCompra,E.IdCiaOdc,MulPlazos,E.IdPlazo,Plazo,NVmto,DiasPago,D.CxPagar,D.DocEquiv,D.BaseImp,D.BaseRet
,E.TarifaRet,E.TarifaIca,E.TarifaRiv,D.TarifaRtc,D.TarifaBom,D.VrIvaMvc,D.VrImpuCons,D.VrSobtasaCons,D.ImpAviTab,D.TarifaAvta,E.CodTarifAvta,D.VrImpuBA,D.VrImpuCUP,D.Modalidad
,K.Item,K.IdProducto,DescripProd,K.IdBodega,Bodega,K.Entradas,K.Salidas,K.IdUnd,UM.Unidad,K.VrUnitario
,VrCostoEnt,VrCostoSal,K.TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaIva,VrIvaEnt,VrIvaSal,K.Sobretasa,K.Soldicom,K.ImpGlobal,K.VrCostProm,K.Unidades,K.Descripcion,K.Referencia,Referencia2
,K.TipOrd,K.NumOrden,K.IdCiaOrd,TipDocDev,K.NumDocDev,OtroImpto,K.VrBruto,K.VrBase,K.Servcios,K.VrImvCosto,K.TarifaIco,K.VrImpCon,K.CantObseq,K.VrIvaObseq,K.BaseIvp,K.TarifaIvp,K.IvaIngProd,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarBa,K.TarifaCup,K.VrImpuCup AS KarImpuCup,K.CodTarCup
,K.CdTanque,K.CdCCosto,CCosto,K.CdSubCos,SubCosto,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Entrada,FecDoc,D.Observacion,D.IdEstado,Estado,D.TimeSys,D.FecUpdate,D.IdCiaCrea,D.IdUsuario,Usuario
,T.TipoId,T.Dv,T.Codigo,T.NomCial,T.Direccion,T.IdLocal,Localidad,L.IdDep,Departamento,T.Telefono,T.Fax,T.e_mail,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,TP.IdGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga,Autoret
 FROM Trn_DevEnt AS D INNER JOIN Trn_Entradas AS E ON D.TipDoc=E.TipDoc AND D.Entrada=E.Entrada AND D.IdCiaDoc=E.IdCia
 INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Terceros AS T ON D.IdProv=T.IdTercero INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto 
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
 INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector INNER JOIN Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN ProdMcias AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON D.IdProv=TP.IdProv  LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Terceros AS TF ON D.NitFletes=TF.IdTercero
 WHERE D.TipDoc=@pmTipDoc AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasNFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasNFac] @pmFactura VARCHAR(15),@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Entrada,IdCia,Fecha,IdProv,Factura,FechaFac,FechaVence,CxPagar,Anulado
 FROM Trn_Entradas
 WHERE Factura=@pmFactura AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%')
 ORDER BY Entrada
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasOdc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasOdc] @pmOCompra INT,@pmIdCiaOdc CHAR(2),@pmIdProv VARCHAR(16)=Null
 AS 
 SELECT  Entrada,E.IdCia AS CdCia,E.Fecha AS FecEntrada,IdProv,RazonSocial,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque
,Entradas,VrPrecio AS CostoBruto,Entradas*VrPrecio AS SubTotal,TarifaDct,VrDctoEnt,VrUnitario AS CostoNeto,Entradas*VrUnitario AS CostoTotal,K.TarifaIva AS TarfIva,VrIvaEnt
,Referencia,Unidades,Servcios,NumDocDev,Modalidad,CxPagar,E.Factura AS NumFact,FechaFac,FechaVence
 FROM Trn_Entradas AS E INNER JOIN Trn_Kardex AS  K ON E.Entrada=K.Documento AND E.IdCia=K.IdCia
 AND E.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipOdc='ODC' AND OCompra=@pmOCompra AND IdCiaOdc=@pmIdCiaOdc  AND Anulado=0
AND IdProv LIKE ISNULL(@pmIdProv,'%')
ORDER BY E.IdCia,Entrada,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryEntradasRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEntradasRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmCxPagar BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Entrada,E.IdCia AS CdCia,Compania,Fecha,E.IdConcepto AS CdConcepto,Concepto,E.IdProv AS NitPrevee,RazonSocial,Factura,FechaFac,FechaVence
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrSobretasa,VrImpGlobal,VrCargos,VrOtrDcto,VrImpCarbono,VrIvaIngProd,VrNeto
,Cantidad,NitFletes,VrRetFlete,VrIcaFlete,CodTarRetFle,CodTarIcaFle,FletesCosto,TipOdc,OCompra,IdCiaOdc,MulPlazos,E.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CxPagar,DocEquiv,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaIgp
,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifBom,VrBomberil,TarifaBom,BaseIvaObsq,VrIvaObsequio,VrImpuCons,VrSobtasaCons,E.ImpAviTab,E.TarifaAvta,E.CodTarifAvta,E.VrImpuBA,E.VrImpuCUP,CdCCosto,CCosto,CdSubCos,SubCosto
,TipEgr,Egreso,IdCiaEgr,E.Modalidad,TipoSA,NumSalAlm,CdCiaSA,TipSop,NumDocSop,CdCiaSop,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,E.Observacion AS Observ,E.IdEstado AS CdEstado,Estado,TimeSys,E.FecUpdate AS Fec_Update,IdCiaCrea,E.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_Entradas AS E INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON E.IdProv=T.IdTercero INNER JOIN  Conceptos AS C ON E.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON E.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN CentroCosto AS CC ON E.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON E.CdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON E.IdProv=TP.IdProv LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
  AND E.IdCia LIKE ISNULL(@pmIdCia,'%%') AND E.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND E.IdProv LIKE ISNULL(@pmIdProv,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (CxPagar=ISNULL(@pmCxPagar,0) or CxPagar=ISNULL(@pmCxPagar,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY E.IdCia,Entrada
GO
/****** Object:  StoredProcedure [dbo].[paQryEstaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstaciones] @pmIdEstacion CHAR(2)
 AS 
 SELECT IdEstacion,Estacion
 FROM Sys_Estaciones
 WHERE IdEstacion LIKE ISNULL(@pmIdEstacion,'%%')
 ORDER BY IdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paQryEstacionesDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstacionesDso]
 AS 
 SELECT IdEstacion,Estacion,IdEstacion+' '+Estacion AS DsEst
 FROM Sys_Estaciones
 ORDER BY IdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoCiv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstadoCiv] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,EstCivil  FROM EstadoCiv
  WHERE  Inactivo=0
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,EstCivil,Inactivo
  FROM EstadoCiv
  WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEstadoDoc] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor,CodDcmto
  FROM EstadoDoc
  WHERE Inactivo=0
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,CodDcmto,Inactivo
  FROM EstadoDoc
  WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoDocDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstadoDocDso] @pmCodDcmto VARCHAR(3)=Null
 AS 
 IF @pmCodDcmto IS NULL
  SELECT IdEstado,Estado,NColor,CodDcmto
  FROM EstadoDoc
  WHERE Inactivo=0 
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,CodDcmto
  FROM EstadoDoc
  WHERE Inactivo=0 AND ( CodDcmto=@pmCodDcmto OR CodDcmto='0' OR LEN(CodDcmto)=0)
  ORDER BY  IdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEstadoGuia] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  BEGIN
   SELECT IdEstado,Estado,NColor
   FROM EstadoGuia
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdEstado,Estado,NColor,Inactivo
   FROM EstadoGuia
   WHERE IdEstado=@pmIdEstado
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoOper]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEstadoOper] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor
  FROM EstadoOper
  WHERE Inactivo=0
 ELSE
  SELECT IdEstado,Estado,NColor,Inactivo
  FROM EstadoOper
  WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstadoPro] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
 SELECT IdEstado,Estado,NColor
 FROM EstadoPro
 WHERE  Inactivo=0 
 ORDER BY  IdEstado
ELSE
  SELECT IdEstado,Estado,NColor,Inactivo
 FROM EstadoPro
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoSer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryEstadoSer] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
 SELECT IdEstado,Estado,NColor
 FROM EstadoSer
 WHERE Inactivo=0
 ORDER BY IdEstado
 ELSE
 SELECT IdEstado,Estado,NColor,Inactivo
 FROM EstadoSer
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoTer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstadoTer] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor
  FROM EstadoTer
  WHERE Inactivo=0
  ORDER BY IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,Inactivo
  FROM EstadoTer
  WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstadoVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstadoVeh] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
 SELECT IdEstado,Estado,NColor,OutDemand
 FROM EstadoVeh
 WHERE Inactivo=0
 ORDER BY IdEstado
 ELSE
 SELECT IdEstado,Estado,NColor,OutDemand,Inactivo
 FROM EstadoVeh
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryEstratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryEstratos] @pmIdEstrato VARCHAR(4)
 AS 
 IF @pmIdEstrato IS NULL
 SELECT IdEstrato,Estrato
 FROM Estratos
 WHERE  Inactivo=0
 ORDER BY IdEstrato
 ELSE
 SELECT IdEstrato,Estrato,Inactivo
 FROM Estratos
 WHERE IdEstrato=@pmIdEstrato
GO
/****** Object:  StoredProcedure [dbo].[paQryExpLicencias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryExpLicencias] @pmIdLugar VARCHAR(8)
 AS 
 IF @pmIdLugar IS NULL
  SELECT IdLugar,LugarLic,CodDpto,Dpto  FROM ExpLicencias
  WHERE Inactivo=0
  ORDER BY LugarLic
 ELSE
  SELECT IdLugar,LugarLic,CodDpto,Dpto,Inactivo 
  FROM ExpLicencias
  WHERE IdLugar=@pmIdLugar
GO
/****** Object:  StoredProcedure [dbo].[paQryExpLicenciasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryExpLicenciasDso]
 AS 
 SELECT IdLugar,LugarLic,Dpto,LugarLic+' ('+ Dpto + ')' AS DsLug  FROM ExpLicencias
 WHERE Inactivo=0
 ORDER BY LugarLic
GO
/****** Object:  StoredProcedure [dbo].[paQryFactcon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFactcon] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Factura,IdCia,Fecha,IdConcepto,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr
,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCajero,IdVend,TarifaCom,CodTarCom
,NitCliente,CdAgencia,IdCCosto,IdSubCos,IdLocal,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido
,Modalidad,PlacaVehic,KmtVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,Observacion,IdEstado
,TipoFE,FechaFE,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP,ImpAviTab,TarifaAvta,CodTarifAvta,VrBomberil,TarifaBom,CodTarifBom,VrAutRetIat,VrAutRetBom,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Factcon
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFactcon_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFactcon_Cr] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipDoc AS Tip_Doc,TipoDoc,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaFac,F.IdConcepto AS CdConcepto,Concepto
,nClieCon,Nombre,CC.TipoId AS CliTipoId,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad,LE.Localidad AS CiudadClie,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie
,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr
,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,F.TarifaIva AS TarifIva,F.TarifaRet AS TarifRet,F.TarifaIca AS TarifIca,TarifaRiv,IdCajero,UC.Usuario AS UsuCajero,UC.IdEstacion AS UsuEstacion
,F.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,NitCliente,T.RazonSocial AS NombreClie,F.CdAgencia AS CodAgencClie,Agencia,CodAgencia
,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,Banco,TipPed,Pedido,IdCiaPed,TipRem,F.Remision AS NumRemision,F.IdCiaRem AS CdCiaRem,FecPedido
,F.VrImpuBA,F.VrImpuCUP,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.Modalidad,PlacaVehic,KmtVehic,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,TipoFE,FechaFE
,OrigenAdd,TipCom,Comprobante,TipoCom,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,F.TimeSys AS Fec_Add,FecUpdate,IdCiaCrea,F.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdCCosto,CdSubCos,pVehiculo,K.Referencia AS KarReferencia,Descripcion,TipOrd,NumOrden,IdCiaOrd
,K.Factura AS KarFactura,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,K.TarifaIco,K.VrImpCon AS VrImpuCon,K.CantObseq,K.VrIvaObseq
,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup,K.TarifaIat AS KarTarifIat,K.VrAviTab AS KarAvisoTab,K.CodTarIat AS KarCodTarifIat,K.TarifaBom AS KarTarifBom,K.VrSobBom AS KarSobBomb,K.CodTarBom AS KarCodTarifBom
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5,CantImp
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_Factcon AS F INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
 INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON F.IdCajero=UC.IdUsuario
 INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN ClieContado AS CC ON F.nClieCon=CC.IdCliente
 LEFT JOIN  Localidades AS LE ON CC.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS T ON F.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON F.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Bancos AS BF ON F.CdBanco=BF.IdBanco LEFT JOIN TiposCom AS TC ON F.TipCom=TC.IdCom
 LEFT JOIN Trn_DocMemo AS MM ON F.TipDoc=MM.TipDoc AND F.Factura=MM.Documento AND F.IdCia=MM.IdCia
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFactconLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmFacturaIni INT=Null,@pmFacturaFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmnClieCon VARCHAR(16)=Null
,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT F.Factura,F.IdCia,FE.Prefijo,FE.NumFace,F.Fecha,F.nClieCon,Nombre,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr
,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,F.IdConcepto AS CdConcepto,Concepto,IdCajero,UC.Usuario AS UsuCajero,IdVend,RazonSocial,TarifaCom,CodTarCom
,NitCliente,CdAgencia,IdCCosto,IdSubCos,F.IdLocal AS CdCiudad,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido
,F.VrImpuBA,F.VrImpuCUP,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.Modalidad,PlacaVehic,KmtVehic,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
,TipoFE,FechaFE,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,F.TimeSys,F.FecUpdate,F.IdCiaCrea,F.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,F.TipDoc
 FROM Trn_Factcon AS F INNER JOIN ClieContado AS CC ON F.nClieCon=CC.IdCliente
 INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON F.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON F.IdCajero=UC.IdUsuario 
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND F.Factura BETWEEN ISNULL(@pmFacturaIni,0) AND ISNULL(@pmFacturaFin,2147483647)
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.nClieCon LIKE ISNULL(@pmnClieCon,'%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND F.IdCajero LIKE ISNULL(@pmIdCajero,'%') AND F.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND F.IdVend LIKE ISNULL(@pmIdVend,'%')  AND F.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (F.Anulado=ISNULL(@pmAnulado,0) or F.Anulado=ISNULL(@pmAnulado,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconNet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFactconNet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmnClieCon VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Factura,F.IdCia AS CdCia,Compania,Fecha,F.IdConcepto AS CdConcepto,Concepto,nClieCon,Nombre,CC.TipoId AS CliTipoId,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad
,LE.Localidad AS CiudadClie,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrReteCREE,VrFletes
,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,IdCajero,UC.Usuario AS UsuCajero,UC.IdEstacion AS UsuEstacion
,F.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,NitCliente,T.RazonSocial AS NombreClie,F.CdAgencia AS CodAgencClie,Agencia,CodAgencia
,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,Banco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido,Modalidad,PlacaVehic,KmtVehic,VrImpCons,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca
,F.VrImpuBA,F.VrImpuCUP,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado
,F.TimeSys,F.FecUpdate,F.IdCiaCrea,F.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--datos del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_Factcon AS F  INNER JOIN ClieContado AS CC ON F.nClieCon=CC.IdCliente  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON F.IdCajero=UC.IdUsuario
 INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN  Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS T ON F.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON F.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TercCliente AS CLI ON F.NitCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Bancos AS BF ON F.CdBanco=BF.IdBanco  
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND nClieCon LIKE ISNULL(@pmnClieCon,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND NitCliente LIKE ISNULL(@pmNitCliente,'%')  AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.nClieCon AS NitClieCon,Nombre,CC.TipoId AS CliTipoId
,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad,LE.Localidad AS CiudadClie,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie
,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento,D.VrSubTotal AS SubTotal,D.VrDescuento AS Descuento,D.VrImpuesto AS Impuestos,D.VrRetencion AS ReteFte
,D.VrReteICA AS ReteICA,D.VrReteIVA AS ReteIVA,D.VrReteCREE,D.VrFletes AS Fletes,D.VrCargos AS OtrosCargos,D.VrOtrDcto AS OtrosDctos,D.VrCostos AS TotalCostos,D.VrNeto AS TotalNeto
,D.VrEfectivo AS TotalEfectivo,D.VrPagosOtr AS OtrosPagos,D.Cantidad AS CantDev,D.CantPuntos AS CantPuntosDev,PuntosAcum,D.BaseImp AS VrBaseImp,D.BaseRet AS VrBaseRet
,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,D.TarifaRtc,D.IdCajero AS CdCajero,UC.Usuario AS Cajero,UC.IdEstacion AS UsuEstacion,D.IdVend AS NitVendedor,V.RazonSocial AS Vendedor,D.TarifaCom AS TarifCom
,D.NitCliente AS DevNitCliente,T.RazonSocial AS NomCliente,D.CdAgencia AS IdAgncia,Agencia,CodAgencia,D.EnEfectivo AS DevEnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,Banco,TipPed
,D.Pedido AS NumPedido,D.IdCiaPed AS CdCiaPed,TipRem,D.Remision AS NumRemision,D.IdCiaRem AS CdCiaRem,D.FecPedido AS FechaPed,D.Modalidad AS ModDoc
,D.PlacaVehic AS DevPlacaVehic,D.KmtVehic AS DevKmtVehic,D.VrImpCons,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,D.ImpAviTab,D.TarifaAvta,F.CodTarifAvta,D.VrBomberil,D.TarifaBom,F.CodTarifBom,D.VrAutRetIat,D.VrAutRetBom
,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CodCiaCom,0,D.Factura AS NumFactura,FecDoc,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,D.FecUpdate AS Fec_Update,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_DevFco AS D INNER JOIN ClieContado AS CC ON D.nClieCon=CC.IdCliente
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia   INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN  Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN  Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 LEFT JOIN Terceros AS T ON D.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON D.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TercCliente AS CLI ON  D.NitCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Bancos AS BF ON F.CdBanco=BF.IdBanco  
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.nClieCon LIKE ISNULL(@pmnClieCon,'%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.NitCliente LIKE ISNULL(@pmNitCliente ,'%')
 AND (D.EnEfectivo=ISNULL(@pmEnEfectivo,0) or D.EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND D.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY F.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconNetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFactconNetDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmnClieCon VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null
,@pmIdSubgrupo VARCHAR(8)=Null,@pmTipoRef VARCHAR(10)=Null
 AS 
 SELECT F.TipDoc AS TipoFact,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDoc,F.IdConcepto AS CdConcepto,Concepto,nClieCon,Nombre,CC.TipoId AS CliTipoId,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad
,LE.Localidad AS CiudadClie,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,VrNeto,VrEfectivo,VrPagosOtr,CantPuntos,PuntosAcum,IdCajero,UC.Usuario AS UsuCajero,UC.IdEstacion AS UsuEstacion
,NitCliente,T.RazonSocial AS NombreClie,F.CdAgencia AS CodAgencClie,Agencia,CodAgencia,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,Banco
,TipPed,Pedido,IdCiaPed,TipRem,F.Remision AS NumRemision,F.IdCiaRem AS CdCiaRem,FecPedido,Modalidad,PlacaVehic,KmtVehic,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca,F.VrImpuBA,F.VrImpuCUP
,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.TipCom,F.Comprobante,F.IdCiaCom
,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,F.TimeSys AS Fech_Add,IdCiaCrea,F.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalles 
,K.IdProducto AS CdProducto,DescripProd,Item,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,K.TarifaRet AS TarifRet,VrReteEnt,VrReteSal
,K.TarifaIca AS TarifIca,VrIcaEnt,VrIcaSal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden
,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,K.Comision AS TarifCom,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper
,K.pVehiculo AS KarPlacaVeh,CdLocal,LK.Localidad AS KarCiudad,CdCCosto,CCosto,K.CdSubCos AS CodSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarNumRemision
,K.IdCiaRem AS KarCdCiaRem,K.Cotizacion AS KarNumCotizacion,K.IdCiaCot AS KarCiaCotiza,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
,K.TarifaIat AS KarTarifIat,K.VrAviTab AS KarAvisoTab,K.CodTarIat AS KarCodTarifIat,K.TarifaBom AS KarTarifBom,K.VrSobBom AS KarSobBomb,K.CodTarBom AS KarCodTarifBom
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_Factcon AS F  INNER JOIN ClieContado AS CC ON F.nClieCon=CC.IdCliente  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON F.IdCajero=UC.IdUsuario
 INNER JOIN  Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN Terceros AS T ON F.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON F.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TercCliente AS CLI ON F.NitCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Bancos AS BF ON F.CdBanco=BF.IdBanco  
 LEFT JOIN CentroCosto AS CCT ON K.CdCCosto=CCT.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN  Localidades AS LK ON K.CdLocal=LK.IdLocal  LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsProdBase=0 AND F.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND nClieCon LIKE ISNULL(@pmnClieCon,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND NitCliente LIKE ISNULL(@pmNitCliente,'%')  AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.nClieCon AS NitClieCon,Nombre,CC.TipoId AS CliTipoId
,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad,LE.Localidad AS CiudadClie,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie
,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento,D.VrRetencion AS ReteFte,D.VrReteICA AS ReteICA,D.VrReteIVA AS ReteIVA,D.VrFletes AS Fletes
,D.VrCargos AS OtrosCargos,D.VrOtrDcto AS OtrosDctos,D.VrNeto AS TotalNeto,D.VrEfectivo AS TotalEfectivo,D.VrPagosOtr AS OtrosPagos
,D.CantPuntos AS CantPuntosDev,PuntosAcum,D.IdCajero AS CdCajero,UC.Usuario AS Cajero,UC.IdEstacion AS UsuEstacion
,D.NitCliente AS DevNitCliente,T.RazonSocial AS NomCliente,D.CdAgencia AS IdAgncia,Agencia,CodAgencia,D.EnEfectivo AS DevEnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,Banco
,TipPed,D.Pedido AS NumPedido,D.IdCiaPed AS CdCiaPed,TipRem,D.Remision AS NumRemision,D.IdCiaRem AS CdCiaRem,D.FecPedido AS FechaPed,D.Modalidad AS ModDoc,D.PlacaVehic AS DevPlacaVeh,D.KmtVehic AS DevKmtVehic
,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,D.ImpAviTab,D.TarifaAvta,F.CodTarifAvta,D.VrBomberil,D.TarifaBom,F.CodTarifBom,D.VrAutRetIat,D.VrAutRetBom,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CodCiaCom,0,D.Factura AS NumFactura,FecDoc
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--detalles 
,K.IdProducto AS CdProducto,DescripProd,Item,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,K.TarifaRet AS TarifRet,VrReteEnt,VrReteSal
,K.TarifaIca AS TarifIca,VrIcaEnt,VrIcaSal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden
,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,K.Comision AS TarifCom,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper
,K.pVehiculo AS KarPlacaVeh,CdLocal,LK.Localidad AS KarCiudad,CdCCosto,CCosto,K.CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarNumRemision
,K.IdCiaRem AS KarCdCiaRem,K.Cotizacion AS KarNumCotizacion,K.IdCiaCot AS KarCiaCotiza,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
,K.TarifaIat,K.VrAviTab,K.CodTarIat,K.TarifaBom,K.VrSobBom,K.CodTarBom
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_DevFco AS D INNER JOIN ClieContado AS CC ON D.nClieCon=CC.IdCliente
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia   INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario
 INNER JOIN  Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN Terceros AS T ON D.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON D.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TercCliente AS CLI ON D.NitCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Bancos AS BF ON F.CdBanco=BF.IdBanco
 LEFT JOIN CentroCosto AS CCT ON K.CdCCosto=CCT.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN  Localidades AS LK ON K.CdLocal=LK.IdLocal  LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsProdBase=0 AND D.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.nClieCon LIKE ISNULL(@pmnClieCon,'%') AND D.IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.NitCliente LIKE ISNULL(@pmNitCliente ,'%')
 AND (D.EnEfectivo=ISNULL(@pmEnEfectivo,0) or D.EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 AND D.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY F.IdCia,F.Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFactconRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFactconRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmnClieCon VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null,@pmIdVend VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null
,@pmEnEfectivo BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT F.TipDoc,F.Factura,F.IdCia AS CdCia,Compania,F.Fecha,FE.Prefijo,FE.NumFace,F.IdConcepto AS CdConcepto,Concepto,nClieCon,Nombre,CC.TipoId AS CliTipoId,CC.Dv AS CliDV,CC.Direccion AS CliDireccion,CC.IdLocal AS CliCodCiudad
,LE.Localidad AS CiudadClie,LE.IdDep AS CdDepClie,DE.Departamento AS DptoClie,CC.Telefono AS CliTelefono,CC.email AS ClieEmail,Excento,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,IdCajero,UC.Usuario AS UsuCajero,UC.IdEstacion AS UsuEstacion
,F.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,NitCliente,T.RazonSocial AS NombreClie,F.CdAgencia AS CodAgencClie,Agencia,CodAgencia
,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,Banco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido,Modalidad,PlacaVehic,KmtVehic,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca,F.VrImpuBA,F.VrImpuCUP,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ
,F.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,F.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_Factcon AS F INNER JOIN ClieContado AS CC ON F.nClieCon=CC.IdCliente  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario INNER JOIN adm_Usuarios AS UC ON F.IdCajero=UC.IdUsuario
 INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS LE ON CC.IdLocal=LE.IdLocal  INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS T ON F.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON F.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN TercCliente AS CLI ON F.NitCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Bancos AS BF ON F.CdBanco=BF.IdBanco  
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND F.nClieCon LIKE ISNULL(@pmnClieCon,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND F.NitCliente LIKE ISNULL(@pmNitCliente,'%')  AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND F.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (F.EnEfectivo=ISNULL(@pmEnEfectivo,0) or F.EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND (F.Anulado=ISNULL(@pmAnulado,0) or F.Anulado=ISNULL(@pmAnulado,1))
 ORDER BY F.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFacturas] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv
,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga
,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta
,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,CodAutoRet,OrigenAdd,TipCom,Comprobante,IdCiaCom
,ZonaFrontera,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,VrImpCons,VrReteCREE,VrImpCarbono,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,VrImpuBA,VrImpuCUP
,TipoFE,FechaFE,BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,ImpAviTab,TarifaAvta,CodTarifAvta,VrBomberil,TarifaBom,CodTarifBom,VrAutRetIat,VrAutRetBom,TipoOperTra
,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Facturas
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturas_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturas_Cr] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipDoc AS Tip_Doc,TipoDoc,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDoc,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrImpCarbono,F.VrIvaIngProd,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaIgp
,F.TarifaIva AS TarifIva,F.TarifaRet AS TarifRet,F.TarifaIca AS TarifIca,TarifaRiv,F.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,F.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom
,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,DiasEntraga
,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,CargoContac,F.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans
,F.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor,F.CdRuta,Ruta,TipPed,Pedido,IdCiaPed,TipRem,F.Remision AS NumRemision,F.IdCiaRem AS CdCiaRem,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CiaCotiza,FecPedido
,AutzaMora,AutzaCupo,Modalidad,KmtVehic,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,VrImpCons,BaseIvaObsq,VrIvaObsequio,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,F.Observacion AS Observ,ZonaFrontera,VrReteCREE,TarifaRtc,CodTarRtc,F.VrImpuBA,F.VrImpuCUP,Parqueadero,FecCuotaParq,TipoFE,FechaFE,F.CodTarArf,F.TarifaArf,F.VrAutRetFte,F.CodTarAri,F.TarifaAri,F.VrAutRetIca
,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.IdEstado AS CdEstado,Estado,F.TimeSys AS Fec_Add,F.FecUpdate AS Fec_Update,F.IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.CodSicom
--Detalles
,K.Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,CdAgencia,KA.Agencia AS KarAgencia,KA.CodAgencia AS KarCodAgencia,KA.NContrato AS KarAgeContrato,KA.Referencia AS KarAgeRefencia,CdLocal,KL.Localidad AS KarCiudad
,CdCCosto,KC.CCosto AS Kar_Ccosto,K.CdSubCos AS CodSubCos,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,K.Cotizacion AS KarNumCotiza,K.IdCiaCot AS KarCiaCotiza,K.Remision AS KarRemision,K.IdCiaRem AS KarCiaRem
,K.Factura AS KarFactura,TipDocDev,NumDocDev,K.IdVend AS KarNitVend,KV.RazonSocial AS KarVendedor,K.Comision AS KarTarifaCom,CdOperario,KO.RazonSocial AS NomOperario,ComisnOper,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase
,ListaPrec,VrBase,BaseIvp,TarifaIvp,IvaIngProd,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
,CdMngra,NumInicial,NumFinal,K.TarifaIco,K.VrImpCon AS DetVrImpCon,K.BaseIvaCom,k.ImpCarbono,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup,K.TarifaIat AS KarTarifIat,K.VrAviTab AS KarAvisoTab,K.CodTarIat AS KarCodTarifIat,K.TarifaBom AS KarTarifBom,K.VrSobBom AS KarSobBomb,K.CodTarBom AS KarCodTarifBom
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
--campos de memo
,DM.Comentarios AS Comentario,Nota1,Nota2,Nota3,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_Facturas AS F  INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos 
 LEFT JOIN Agencias  AS KA ON K.CdAgencia=KA.IdAgencia LEFT JOIN Localidades AS KL ON K.CdLocal=KL.IdLocal
 LEFT JOIN Terceros AS KV ON K.IdVend=KV.IdTercero  LEFT JOIN Terceros AS KO ON K.CdOperario=KO.IdTercero
 LEFT JOIN TiposCom AS TCM ON F.TipCom=TCM.IdCom
 LEFT JOIN Trn_DocMemo AS DM ON F.TipDoc=DM.TipDoc AND F.Factura=DM.Documento AND F.IdCia=DM.IdCia
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturas40_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO





-- =============================================
-- Author:	Cesar Carreño
-- Update: 21/02/2024
-- Description:	procedimiento que busca las factura para ser enviada a la DIAN en Syscom40 (Factura Electrónica).
-- =============================================
CREATE PROCEDURE [dbo].[paQryFacturas40_Cr]
	--@pmTipFact VARCHAR(20),--Tipo de documento que se desea buscar módulo
	@pmTipDoc VARCHAR(3),--Tipo de documento que se desea buscar
	@pmNroFactura INT, --Número de documento que se desea buscar
	@pmIdCia CHAR(2), --Compañía de documento que se desea buscar
	@pmIdCliente VARCHAR(16)= NULL, --Id de Cliente de documento que se desea buscar
	@Modalidad VARCHAR(16)= NULL,
	@Origen VARCHAR(16)= NULL
AS
BEGIN
	IF @pmTipDoc IN ('FC1','FC2','FC3','FC4','FC5','FCR','FVC','FCE')--Credito		
		SELECT @Modalidad = Modalidad,@Origen = Origenadd  FROM Trn_Facturas WHERE TipDoc = @pmTipDoc AND Factura = @pmNroFactura AND IdCia = @pmIdCia
		IF @Modalidad IN ('INVENTARIO','VALES','COMBUSTBLE') AND @Origen IN ('MAIN', 'PRODCOM')
			SELECT F.TipDoc AS Tip_Doc,  TD.TipoDoc,  F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS  CdConceptoP,
			F.IdCliente, T.RazonSocial AS NomCliente,F.IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails, F.FechaVence,  F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  F.VrImpCons, 
			F.VrRetencion, F.VrReteICA,  F.VrReteIVA,  F.VrOtros,  F.VrCargos,  F.VrOtrDcto,  F.VrSobretasa, F.VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  F.VrImpCarbono,  
			F.VrNeto,  F.VrAplicado, F.Cantidad, F.BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO, F.BaseRet, F.BaseIca, F.BaseRiv, F.TarifaIva, F.TarifaRet, F.TarifaIca, F.TarifaRiv, 
			CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE, F.TarifaArf, F.VrAutRetFte,
			---nuevos campos para gestion de PDF
			F.VrFletes,F.VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,F.Remision AS NumRemision,f.IdCiaRem,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CiaCotiza,F.TipPed,F.Pedido,F.IdCiaPed,F.IdUsuario AS CdUsuario,Usuario,
			F.IdPlazo AS CdPlazo,Plazo,MulPlazos,F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.DetallePago,T.IdRegimen AS CdRegimen,Regimen,
			F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.pVehiculo AS PlacaVeh,
			--Detalles
			FD.Item, FD.CodProducto, FD.CodProductoDIAN, FD.DescripProd, FD.DescripProd1, FD.Cant, FD.CdUndMed, FD.VrUnitario, FD.VrDctoSal, FD.TarifaDct, FD.TipoReg, FD.CantObseq, FD.CdMoneda, FD.VrTasaCamb, FD.TarifaIco, 
			FD.VrImpCon, CAST(FD.BaseIcoDet AS DECIMAL(18,4)) AS BaseIcoDet, FD.TarifaIvaDet, FD.VrIvaDet, FD.BaseIvaDet, FD.TarifaRetDet, FD.VrRetDet, FD.TarifaIcaDet, FD.VrIcaDet, 
			--Versión 10
			F.VrAutRetIca, FD.BaseAutoIcaDet, 
			FD.ExcluidoImp, FD.ImpCarbono, FD.ImpGlobal, FD.Sobretasa, FD.Soldicom, FD.TarifaIvp, FD.BaseIvp, FD.IvaIngProd, FD.EsCombo, FD.ItemCombo, FD.Entradas, FD.IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet, FD.Mandatario, FD.MandatarioDV, FD.MandatarioTipDoc,
			FD.Referencia1, FD.Referencia2,FD.Referencia3,
			--Inforamción de factura electrónica
			FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
			--Otros
			F.Observacion AS Observ, CASE WHEN DiasPago = '0' THEN 1 ELSE 2 END As FormaPago, F.IdForma AS CdForma, F.Modalidad,F.Origenadd,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem, FD.Volumen, FD.TipoICO, FD.TarifaIba, FD.VrImpuBa, FD.TarifaCup, FD.VrImpuCup, FD.MedVolm
			FROM Trn_Facturas AS F
			JOIN
			(
				--Detalle de Crédito Comercial
				
select        
      k.[TipDoc]
      ,k.[Factura]
      ,k.[IdCia]
      ,k.[Item]
      ,k.[CodProducto]
      ,k.[CodProductoDIAN]
      ,k.[DescripProd]
      ,k.[DescripProd1]
      ,k.[Cant]
      ,k.[VrUnitario]
	  --modificamos el valor de descuento 
	  --,case when k.SumaVrPrecio > 0 then k.SumaVrPrecio
		--else k.[VrDctoSal] end 
		,k.VrDctoSal     
	--  ,case when k.SumaVrPrecio > 0 then (k.SumaVrPrecio *100)/k.VrUnitario
		--else k.TarifaDct end 
		,k.TarifaDct
      ,k.[CdUndMed]
      ,k.[TipoReg]
      ,k.[CantObseq]
      ,k.[CdMoneda]
      ,k.[VrTasaCamb]
      ,k.[TarifaIco]
      ,k.[VrImpCon]
      ,k.[BaseIcoDet]
      ,k.[TipoICO]
      ,k.[TarifaIvaDet]
      ,k.[VrIvaDet]
      ,k.[BaseIvaDet]
      ,k.[TarifaRetDet]
      ,k.[VrRetDet]
      ,k.[TarifaIcaDet]
      ,k.[VrIcaDet]
      ,k.[VrAutRetIca]
      ,k.[BaseAutoIcaDet]
      ,k.[ExcluidoImp]
      ,k.[ImpCarbono]
      ,k.[ImpGlobal]
      ,k.[Sobretasa]
      ,k.[Soldicom]
      ,k.[TarifaIvp]
      ,k.[BaseIvp]
      ,k.[IvaIngProd]
      ,0 as EsCombo
      ,0 as ItemCombo
      ,k.[Entradas]
      ,k.[IvaDetCombo]
      ,k.[Mandatario]
      ,k.[MandatarioDV]
      ,k.[MandatarioTipDoc]
      ,k.[Referencia1]
      ,k.[Referencia2]
      ,k.[Referencia3]
      ,k.[Volumen]
      ,k.[TarifaIba]
      ,k.[VrImpuBa]
      ,k.[TarifaCup]
      ,k.[VrImpuCup]
      ,k.[MedVolm]
		from(
		-- primeros datos con productos
                SELECT  distinct 
			    CASE 
					WHEN k.EsCombo = 0 AND k.ItemCombo = 0 THEN 'Pro'
					WHEN k.EsCombo = 1 AND k.IngBaseCom = 0 THEN 'SinDet'
					WHEN k.EsProdBase = 1 AND k.IngBaseCom > 0 THEN 'ConDet'
					ELSE 'no' 
				END AS Val, 			
				sumak.SumaVrPrecio,
				K.TipDoc, K.Documento AS Factura, K.IdCia, K.Item, K.IdProducto AS CodProducto, ISNULL(P.CodFEDian, K.IdProducto) AS CodProductoDIAN, P.DescripProd,P.DescripProd DescripProd1, K.Salidas AS Cant, 
				(CASE 
				WHEN k.EsProdBase = 1 and k.IngBaseCom > 0 then k.IngBaseCom
				WHEN (SELECT Modalidad FROM Trn_Facturas WHERE TipDoc = @pmTipDoc AND Factura = @pmNroFactura AND IdCia = @pmIdCia) = 'INVENTARIO' AND K.ItemCombo > 0 AND K.EsCombo = 0 AND K.EsProdBase > 0  THEN CAST((K.IngBaseCom / Case when k.EsProdBase = 1 and k.Salidas = 0 then 1 else K.Salidas end) AS DECIMAL(18,4))  ELSE K.VrPrecio END) AS VrUnitario, K.VrDctoSal, K.TarifaDct,
				ISNULL(UM.CodUMFE, P.UndMed) AS CdUndMed, 0 AS TipoReg, K.CantObseq, K.CdMoneda, K.VrTasaCamb, K.TarifaIco, K.VrImpCon, (CASE WHEN VrImpCon > 0 THEN ((K.Salidas * K.VrPrecio) - K.VrDctoSal)  ELSE 0 END) AS BaseIcoDet,CASE WHEN TP.Simbolo='$' AND TP.IdClase ='ICO' THEN 'Nominal' ELSE 'Porcentual' END TipoICO,
				K.TarifaIva AS TarifaIvaDet, K.VrIvaSal AS VrIvaDet, (CASE WHEN (SELECT Modalidad FROM Trn_Facturas WHERE TipDoc = @pmTipDoc AND Factura = @pmNroFactura AND IdCia = @pmIdCia) = 'COMBUSTBLE' THEN K.BaseIvaCom  ELSE CAST(((K.Salidas * K.VrPrecio) - K.VrDctoSal) AS DECIMAL(18,4)) END) AS BaseIvaDet, K.TarifaRet AS TarifaRetDet, 
				K.VrReteSal AS VrRetDet, K.TarifaIca AS TarifaIcaDet, K.VrIcaSal AS VrIcaDet, 
				--Versión 10
				CAST('0' AS DECIMAL(18,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(18,4))  AS BaseAutoIcaDet,
				P.ExcluidoImp, K.ImpCarbono, K.ImpGlobal, K.Sobretasa, K.Soldicom, K.TarifaIvp, K.BaseIvp, K.IvaIngProd, K.EsCombo, 
				--Arreglo Colanta
				--K.ItemCombo,
				(CASE WHEN K.EsCombo = 0 AND k.EsProdBase = 1 THEN 1 ELSE 0 END) AS ItemCombo,
				K.Entradas, P.IvaDetCombo, (CASE WHEN P.TipoZonaFront = 'IT' THEN  K.CdOperario ELSE '' END) AS Mandatario,
				TM.Dv AS MandatarioDV, TM.TipoId AS MandatarioTipDoc, K.Referencia AS Referencia1, K.Referencia2 AS Referencia2, '' AS Referencia3, K.Unidades Volumen, k.TarifaIba, k.VrImpuBa, k.TarifaCup, k.VrImpuCup, p.MedVolm
				FROM Trn_Kardex AS K
				JOIN ProdMcias AS P ON K.IdProducto = P.IdProducto
				LEFT JOIN ProdCombo AS PC ON P.Idproducto = PC.IdProducto
				LEFT JOIN Terceros AS TM ON K.CdOperario = TM.IdTercero
				LEFT JOIN Tablapor AS TP ON K.CodTarIco=TP.IdTarifa
				JOIN Sys_Um AS UM ON P.UndMed = UM.UndMed
				left join (
					select  	
					case when (sum(en.BaseIvaCom) - det.VrPrecio) < 0 then 0 
						when En.IngBaseCom = sum(Det.VrPrecio) then (sum(det.BaseIvaCom) - ((det.VrPrecio - Det.VrDctoSal)))
						else  0
					end as SumaVrPrecio, 
	
					En.ItemCombo, en.VrPrecio, en.EsProdBase, en.IngBaseCom, en.Item, en.BaseIvaCom
	

					from Trn_Kardex En	

					left join Trn_Kardex Det on 
					En.TipDoc = Det.TipDoc 
					and En.Documento = Det.Documento 
					and En.IdCia = Det.IdCia 	
					and Det.Item = En.ItemCombo	

					where En.TipDoc = @pmTipDoc and En.Documento = @pmNroFactura and En.IdCia = @pmIdCia
					GROUP BY En.ItemCombo, en.VrPrecio, en.EsProdBase, en.IngBaseCom, en.Item, en.BaseIvaCom, det.VrPrecio, Det.VrDctoSal
					)  AS SumaK ON SumaK.Item = k.Item

				
				) as k	
				
				


				where k.TipDoc = @pmTipDoc and k.Factura = @pmNroFactura and k.Val != 'no'


			) AS FD ON F.TipDoc = FD.TipDoc AND F.Factura = FD.Factura AND F.IdCia = FD.IdCia
			JOIN Companias AS C ON F.IdCia = C.IdCia
			JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
			JOIN Terceros AS T ON F.IdCliente = T.IdTercero
			INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
			INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
			INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
			INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario		
			LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
			LEFT JOIN Agencias AS AG ON F.IdAgencia = AG.IdAgencia AND F.IdCliente = AG.IdClie
			LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
			WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
		ELSE IF @Modalidad IN ('TRANSPORTE') AND @Origen IN ('TRANSPORTE')
			SELECT F.TipDoc AS Tip_Doc,  TD.TipoDoc,  F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS  CdConceptoP,
			F.IdCliente, T.RazonSocial AS NomCliente,F.IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails, F.FechaVence,  F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  F.VrImpCons, 
			F.VrRetencion, F.VrReteICA,  F.VrReteIVA,  F.VrOtros,  CASE WHEN FD.TipRem ='GTC'  THEN CAST('0' AS DECIMAL(18,4)) ELSE F.VrCargos END VrCargos,  F.VrOtrDcto,  F.VrSobretasa, F.VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  F.VrImpCarbono,  
			F.VrNeto,  F.VrAplicado, F.Cantidad, F.BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO, F.BaseRet, F.BaseIca, F.BaseRiv, F.TarifaIva, F.TarifaRet, F.TarifaIca, F.TarifaRiv, 
			CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE, F.TarifaArf, F.VrAutRetFte,
			---nuevos campos para gestion de PDF
			F.VrFletes,F.VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,F.Remision AS NumRemision,f.IdCiaRem,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CiaCotiza,F.TipPed,F.Pedido,F.IdCiaPed,F.IdUsuario AS CdUsuario,Usuario,
			F.IdPlazo AS CdPlazo,Plazo,MulPlazos,F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.DetallePago,T.IdRegimen AS CdRegimen,Regimen,
			F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.pVehiculo AS PlacaVeh,
			--Detalles
			FD.Item, FD.CodProducto, FD.CodProductoDIAN, FD.DescripProd, FD.DescripProd1, FD.Cant, FD.CdUndMed, FD.VrUnitario, FD.VrDctoSal, FD.TarifaDct, FD.TipoReg, FD.CantObseq, FD.CdMoneda, FD.VrTasaCamb, FD.TarifaIco, 
			FD.VrImpCon, CAST(FD.BaseIcoDet AS DECIMAL(18,4)) AS BaseIcoDet, FD.TarifaIvaDet, FD.VrIvaDet, FD.BaseIvaDet, FD.TarifaRetDet, FD.VrRetDet, FD.TarifaIcaDet, FD.VrIcaDet, 
			--Versión 10
			F.VrAutRetIca, FD.BaseAutoIcaDet, 
			FD.ExcluidoImp, FD.ImpCarbono, FD.ImpGlobal, FD.Sobretasa, FD.Soldicom, FD.TarifaIvp, FD.BaseIvp, FD.IvaIngProd, FD.EsCombo, FD.ItemCombo, FD.Entradas, FD.IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet, FD.Mandatario, FD.MandatarioDV, FD.MandatarioTipDoc,
			FD.Referencia1, FD.Referencia2,FD.Referencia3,
			--Inforamción de factura electrónica
			FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
			--Otros
			F.Observacion AS Observ, CASE WHEN DiasPago = '0' THEN 1 ELSE 2 END As FormaPago, F.IdForma AS CdForma, F.Modalidad,F.Origenadd, FD.VrSeguroRem, CAST('0' AS DECIMAL(14, 4)) Volumen,CAST('Porcentual' AS varchar)TipoICO, CASE 
        WHEN FD.TipRem = 'RMT' THEN 'SI' 
        ELSE 'NO' 
    END AS 'REM', F.TipoOperTra
	, ISNULL(A.numorden, '') OrdenOSM
			FROM Trn_Facturas AS F
			JOIN
			(
				--Detalle de Crédito Transporte
				SELECT	R.TipDoc, R.Factura, R.IdCia, R.Item, CASE WHEN R.TipRem ='GTC'  THEN '999' ELSE R.CdConcepto END  AS CodProducto,CASE WHEN R.TipRem ='GTC'  THEN '999' ELSE ISNULL(CD.CodFEDian, R.CdConcepto) END  AS CodProductoDIAN,CASE WHEN R.TipRem ='GTC' THEN ('GUIA TRANSPORTE: '+R.TipRem+' '+CAST(R.Remesa AS varchar)+' '+R.IdCiaRem) ELSE ISNULL(CD.Concepto, Descripcion) END  AS DescripProd,R.Descripcion AS DescripProd1, Cantidad AS Cant,CASE WHEN R.TipRem ='GTC'  THEN (VrUnitario+CostoAdicTbdo) ELSE VrUnitario END VrUnitario, VrDescuento AS VrDctoSal,  R.TarifaDct,
				'94' AS CdUndMed, TipoReg, CAST('0' AS DECIMAL(18,4)) AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(18,4)) AS VrTasaCamb, CAST('0' AS DECIMAL(18,4)) AS TarifaIco, CAST('0' AS DECIMAL(18,4)) AS VrImpCon, 
				CAST('0' AS DECIMAL(18,4)) AS BaseIcoDet, R.TarifaIva AS TarifaIvaDet, R.VrImpuesto AS VrIvaDet, CAST(((R.Cantidad * R.VrUnitario) - R.VrDescuento) AS DECIMAL(18,4)) AS BaseIvaDet, R.TarifaRet AS  TarifaRetDet, 
				R.VrRetencion AS VrRetDet, R.TarifaIca AS TarifaIcaDet, (case when R.TarifaIca > 0 then (((R.Cantidad * R.VrUnitario) - R.VrDescuento) * (R.TarifaIca / 100)) else CAST('0' AS DECIMAL(18,4)) end)  AS VrIcaDet,
				--Versión 10 no es reteICA sino AutoICA
				VrAutRetIca, (case when R.TarifaIca > 0 AND VrAutRetIca > 0  then CAST(ROUND((VrAutRetIca * 100/TarifaIca),2) AS DECIMAL(18,4))  else CAST('0' AS DECIMAL(18,4)) end)  AS BaseAutoIcaDet,
				--R.VrReteIca AS VrIcaDet, 
				CAST(1 AS BIT) AS ExcluidoImp, CAST('0' AS DECIMAL(18,4)) AS ImpCarbono,  CAST('0' AS DECIMAL(18,4)) AS ImpGlobal, 
				CAST('0' AS DECIMAL(18,4)) AS Sobretasa, CAST('0' AS DECIMAL(18,4)) AS Soldicom, CAST('0' AS DECIMAL(18,4)) AS TarifaIvp, CAST('0' AS DECIMAL(18,4)) AS BaseIvp, CAST('0' AS DECIMAL(18,4)) AS IvaIngProd, 
				CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(18,4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo, '' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc, Referencia1, Referencia2,Referencia3,
				CASE WHEN (select Valor from adm_opciones where IdOpc='FSG') = 1 THEN  (CASE WHEN tarifaseg = 0 THEN CAST((VrSeguroRem/Cantidad) AS DECIMAL(18,4)) ELSE CAST(((VrDeclMcia/Cantidad)*(tarifaseg/100)) AS DECIMAL(18,4)) END) ELSE 0 END VrSeguroRem,R.TipRem
				FROM Trn_TraFacRemesas AS R
				JOIN ConcDiversos AS CD ON R.CdConcepto = CD.IdConcepto
			) AS FD ON F.TipDoc = FD.TipDoc AND F.Factura = FD.Factura AND F.IdCia = FD.IdCia
			JOIN Companias AS C ON F.IdCia = C.IdCia
			JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
			JOIN Terceros AS T ON F.IdCliente = T.IdTercero
			INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
			INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
			INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
			INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario		
			LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
			LEFT JOIN Agencias AS AG ON F.IdAgencia = AG.IdAgencia AND F.IdCliente = AG.IdClie
			LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
			LEFT JOIN Trn_TraFacRemesas AS RR ON RR.IdCia = f.IdCia and RR.TipDoc = f.TipDoc and RR.Factura = F.Factura
			LEFT JOIN Trn_TraRemAnexo AS A ON A.NumInvent = RR.Remesa AND A.TipOrdMud = 'OSM' AND RR.Referencia3 = 'TRANSPORTE'		
			WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
		ELSE IF @Modalidad IN ('TRANSPORTE') AND @Origen IN ('TRAES')
			SELECT F.TipDoc AS Tip_Doc,  TD.TipoDoc,  F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS  CdConceptoP,
			F.IdCliente, T.RazonSocial AS NomCliente,F.IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails, F.FechaVence,  F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  F.VrImpCons, 
			F.VrRetencion, F.VrReteICA,  F.VrReteIVA,  F.VrOtros,  F.VrCargos,  F.VrOtrDcto,  F.VrSobretasa, F.VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  F.VrImpCarbono,  
			F.VrNeto,  F.VrAplicado, F.Cantidad, F.BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO, F.BaseRet, F.BaseIca, F.BaseRiv, F.TarifaIva, F.TarifaRet, F.TarifaIca, F.TarifaRiv, 
			CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE, F.TarifaArf, F.VrAutRetFte,
			---nuevos campos para gestion de PDF
			F.VrFletes,F.VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,F.Remision AS NumRemision,f.IdCiaRem,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CiaCotiza,F.TipPed,F.Pedido,F.IdCiaPed,F.IdUsuario AS CdUsuario,Usuario,
			F.IdPlazo AS CdPlazo,Plazo,MulPlazos,F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.DetallePago,T.IdRegimen AS CdRegimen,Regimen,
			F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.pVehiculo AS PlacaVeh,
			--Detalles
			FD.Item, FD.CodProducto, FD.CodProductoDIAN, FD.DescripProd, FD.DescripProd1, FD.Cant, FD.CdUndMed, FD.VrUnitario, FD.VrDctoSal, FD.TarifaDct, FD.TipoReg, FD.CantObseq, FD.CdMoneda, FD.VrTasaCamb, FD.TarifaIco, 
			FD.VrImpCon, CAST(FD.BaseIcoDet AS DECIMAL(18,4)) AS BaseIcoDet, FD.TarifaIvaDet, FD.VrIvaDet, FD.BaseIvaDet, FD.TarifaRetDet, FD.VrRetDet, FD.TarifaIcaDet, FD.VrIcaDet, 
			--Versión 10
			F.VrAutRetIca, FD.BaseAutoIcaDet, 
			FD.ExcluidoImp, FD.ImpCarbono, FD.ImpGlobal, FD.Sobretasa, FD.Soldicom, FD.TarifaIvp, FD.BaseIvp, FD.IvaIngProd, FD.EsCombo, FD.ItemCombo, FD.Entradas, FD.IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet, FD.Mandatario, FD.MandatarioDV, FD.MandatarioTipDoc,
			FD.Referencia1, FD.Referencia2,FD.Referencia3,
			--Inforamción de factura electrónica
			FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
			--Otros
			F.Observacion AS Observ, CASE WHEN DiasPago = '0' THEN 1 ELSE 2 END As FormaPago, F.IdForma AS CdForma, F.Modalidad,F.Origenadd	,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem, CAST('0' AS DECIMAL(14, 4)) Volumen,CAST('Porcentual' AS varchar)TipoICO
			FROM Trn_Facturas AS F
			JOIN
			(
				--Detalle de Crédito Transporte Especial
				SELECT	R.TipDoc, R.Factura, R.IdCia, R.Item, R.CdConcepto AS CodProducto, ISNULL(CD.CodFEDian, R.CdConcepto) AS CodProductoDIAN, ISNULL(CD.Concepto, Descripcion) AS DescripProd,ISNULL(CD.Concepto, Descripcion) AS DescripProd1, Cantidad AS Cant, VrUnitario, VrDescuento AS VrDctoSal,  R.TarifaDct,
				'94' AS CdUndMed, TipoReg, CAST('0' AS DECIMAL(18,4)) AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(18,4)) AS VrTasaCamb, CAST('0' AS DECIMAL(18,4)) AS TarifaIco, CAST('0' AS DECIMAL(18,4)) AS VrImpCon, 
				CAST('0' AS DECIMAL(18,4)) AS BaseIcoDet, R.TarifaIva AS TarifaIvaDet, R.VrImpuesto AS VrIvaDet, CAST(((R.Cantidad * R.VrUnitario) - R.VrDescuento) AS DECIMAL(18,4)) AS BaseIvaDet, R.TarifaRet AS  TarifaRetDet, 
				R.VrRetencion AS VrRetDet, R.TarifaIca AS TarifaIcaDet, (case when R.TarifaIca > 0 then (((R.Cantidad * R.VrUnitario) - R.VrDescuento) * (R.TarifaIca / 100)) else CAST('0' AS DECIMAL(18,4)) end)  AS VrIcaDet,
				--Versión 10
				CAST('0' AS DECIMAL(18,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(18,4))  AS BaseAutoIcaDet,
				--R.VrReteIca AS VrIcaDet, 
				CAST(1 AS BIT) AS ExcluidoImp, CAST('0' AS DECIMAL(18,4)) AS ImpCarbono,  CAST('0' AS DECIMAL(18,4)) AS ImpGlobal, 
				CAST('0' AS DECIMAL(18,4)) AS Sobretasa, CAST('0' AS DECIMAL(18,4)) AS Soldicom, CAST('0' AS DECIMAL(18,4)) AS TarifaIvp, CAST('0' AS DECIMAL(18,4)) AS BaseIvp, CAST('0' AS DECIMAL(18,4)) AS IvaIngProd, 
				CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(18,4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo, '' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc, Referencia1, Referencia2,'' Referencia3
				FROM Trn_TraEspFacReservas AS R
				JOIN ConcDiversos AS CD ON R.CdConcepto = CD.IdConcepto
			) AS FD ON F.TipDoc = FD.TipDoc AND F.Factura = FD.Factura AND F.IdCia = FD.IdCia
			JOIN Companias AS C ON F.IdCia = C.IdCia
			JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
			JOIN Terceros AS T ON F.IdCliente = T.IdTercero
			INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
			INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
			INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
			INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario		
			LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
			LEFT JOIN Agencias AS AG ON F.IdAgencia = AG.IdAgencia AND F.IdCliente = AG.IdClie
			LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
			WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
		ELSE IF @Modalidad IN ('TRANSPORTE') AND @Origen IN ('BUSES')
			SELECT F.TipDoc AS Tip_Doc,  TD.TipoDoc,  F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS  CdConceptoP,
			F.IdCliente, T.RazonSocial AS NomCliente,F.IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails, F.FechaVence,  F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  F.VrImpCons, 
			F.VrRetencion, F.VrReteICA,  F.VrReteIVA,  F.VrOtros,  F.VrCargos,  F.VrOtrDcto,  F.VrSobretasa, F.VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  F.VrImpCarbono,  
			F.VrNeto,  F.VrAplicado, F.Cantidad, F.BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO, F.BaseRet, F.BaseIca, F.BaseRiv, F.TarifaIva, F.TarifaRet, F.TarifaIca, F.TarifaRiv, 
			CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE, F.TarifaArf, F.VrAutRetFte,
			---nuevos campos para gestion de PDF
			F.VrFletes,F.VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,F.Remision AS NumRemision,f.IdCiaRem,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CiaCotiza,F.TipPed,F.Pedido,F.IdCiaPed,F.IdUsuario AS CdUsuario,Usuario,
			F.IdPlazo AS CdPlazo,Plazo,MulPlazos,F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.DetallePago,T.IdRegimen AS CdRegimen,Regimen,
			F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.pVehiculo AS PlacaVeh,
			--Detalles
			FD.Item, FD.CodProducto, FD.CodProductoDIAN, FD.DescripProd, FD.DescripProd1, FD.Cant, FD.CdUndMed, FD.VrUnitario, FD.VrDctoSal, FD.TarifaDct, FD.TipoReg, FD.CantObseq, FD.CdMoneda, FD.VrTasaCamb, FD.TarifaIco, 
			FD.VrImpCon, CAST(FD.BaseIcoDet AS DECIMAL(18,4)) AS BaseIcoDet, FD.TarifaIvaDet, FD.VrIvaDet, FD.BaseIvaDet, FD.TarifaRetDet, FD.VrRetDet, FD.TarifaIcaDet, FD.VrIcaDet, 
			--Versión 10
			F.VrAutRetIca, FD.BaseAutoIcaDet, 
			FD.ExcluidoImp, FD.ImpCarbono, FD.ImpGlobal, FD.Sobretasa, FD.Soldicom, FD.TarifaIvp, FD.BaseIvp, FD.IvaIngProd, FD.EsCombo, FD.ItemCombo, FD.Entradas, FD.IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet, FD.Mandatario, FD.MandatarioDV, FD.MandatarioTipDoc,
			FD.Referencia1, FD.Referencia2,FD.Referencia3,
			--Inforamción de factura electrónica
			FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
			--Otros
			F.Observacion AS Observ, 1 As FormaPago, F.IdForma AS CdForma, F.Modalidad,F.Origenadd,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem, CAST('0' AS DECIMAL(14, 4)) Volumen,CAST('Porcentual' AS varchar)TipoICO
			FROM Trn_Facturas AS F
			JOIN
			(
				--Detalle de Crédito Buses
				SELECT	MAX(D.TipDoc) AS TipDoc, MAX(D.Factura) AS Factura, MAX(D.IdCia) AS IdCia, SUM(D.Item) AS Item, D.IdCargo  AS CodProducto, ISNULL(MAX(CF.CodFEDian), D.IdCargo) AS CodProductoDIAN, MAX(Descripcion +' (' ++ D.IdVehiculo + ')') AS DescripProd,MAX(Descripcion) AS DescripProd1, CAST('1' AS DECIMAL(18,4)) AS Cant, 
				SUM(D.ValorCargo) AS VrUnitario, CAST('0' AS DECIMAL(18,4)) AS VrDctoSal,  CAST('0' AS DECIMAL(18,4)) AS TarifaDct, '94' AS CdUndMed, 0 AS TipoReg, CAST('0' AS DECIMAL(18,4)) AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(18,4)) AS VrTasaCamb, 
				CAST('0' AS DECIMAL(18,4)) AS TarifaIco, CAST('0' AS DECIMAL(18,4)) AS VrImpCon, CAST('0' AS DECIMAL(18,4)) AS BaseIcoDet, MAX(D.TarifaIva) AS TarifaIvaDet, SUM(D.VrIva) AS VrIvaDet, CAST((CAST('1' AS DECIMAL(18,4)) * SUM(D.ValorCargo)) AS DECIMAL(18,4)) AS BaseIvaDet, 
				MAX(D.TarifaRet) AS  TarifaRetDet, SUM(D.VrRetencion) AS VrRetDet, MAX(D.TarifaIca) AS TarifaIcaDet, SUM(D.VrReteIca)  AS VrIcaDet, 
				--Versiónn 10
				CAST('0' AS DECIMAL(18,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(18,4))  AS BaseAutoIcaDet, 
				CAST(0 AS BIT) AS ExcluidoImp, CAST('0' AS DECIMAL(18,4)) AS ImpCarbono,  CAST('0' AS DECIMAL(18,4)) AS ImpGlobal, 
				CAST('0' AS DECIMAL(18,4)) AS Sobretasa, CAST('0' AS DECIMAL(18,4)) AS Soldicom, CAST('0' AS DECIMAL(18,4)) AS TarifaIvp, CAST('0' AS DECIMAL(18,4)) AS BaseIvp, CAST('0' AS DECIMAL(18,4)) AS IvaIngProd, 
				CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(18,4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo, '' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc,  '' AS Referencia1, '' AS Referencia2, '' AS Referencia3
				FROM Trn_FactCausacion  AS D
				JOIN Fijos AS CF ON D.IdCargo = CF.IdCargo
				WHERE TipDoc=@pmTipDoc AND Factura=@pmNroFactura AND IdCia=@pmIdCia
				GROUP BY D.IdVehiculo, D.IdCargo
			) AS FD ON F.TipDoc = FD.TipDoc AND F.Factura = FD.Factura AND F.IdCia = FD.IdCia
			JOIN Companias AS C ON F.IdCia = C.IdCia
			JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
			JOIN Terceros AS T ON F.IdCliente = T.IdTercero
			INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
			INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
			INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
			INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario		
			LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
			LEFT JOIN Agencias AS AG ON F.IdAgencia = AG.IdAgencia AND F.IdCliente = AG.IdClie
			LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
			WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
	ELSE IF @pmTipDoc IN ('FCO','FO1','FO2','FO3','FO4','FO5')--Contado	
		SELECT F.TipDoc AS Tip_Doc, TD.TipoDoc, F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS CdConceptoP,  
		F.nClieCon IdCliente,  T.RazonSocial AS NomCliente,  F.CdAgencia AS IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails,  F.Fecha AS FechaVence,   F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  F.VrImpCons, 
		F.VrRetencion, F.VrReteICA,  VrReteIVA, CAST('0' AS DECIMAL(18,4)) AS VrOtros,CASE WHEN F.TipCom ='GTC' THEN 0 ELSE VrCargos END VrCargos,  VrOtrDcto,  CAST('0' AS DECIMAL(18,4)) AS VrSobretasa,
		CAST('0' AS DECIMAL(18,4)) AS VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  CAST('0' AS DECIMAL(18,4)) AS VrImpCarbono,  
		VrNeto,  CAST('0' AS DECIMAL(18,4)) AS VrAplicado, Cantidad, BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO,  BaseRet,  BaseIca,  BaseRiv, F.TarifaIva, 
		F.TarifaRet,  F.TarifaIca, F.TarifaRiv, CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE,  F.TarifaArf, F.VrAutRetFte,
		---nuevos campos para gestion de PDF
		F.VrFletes,F.VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,F.Remision AS NumRemision,f.IdCiaRem,'' TipCot,0 AS NumCotizacion,'' AS CiaCotiza,F.TipPed,F.Pedido,F.IdCiaPed,'' AS CdPlazo,'' Plazo,CAST(0 as BIT) MulPlazos,F.IdUsuario AS CdUsuario,Usuario,
		F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.DetallePago,T.IdRegimen AS CdRegimen,Regimen,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,'' PlacaVeh,
		--Detalles
		CASE WHEN F.TipCom ='GTC' THEN 1 ELSE K.Item END Item, CASE WHEN F.TipCom ='GTC' THEN '999' ELSE K.IdProducto END  AS CodProducto,CASE WHEN F.TipCom ='GTC' THEN '999' ELSE ISNULL(P.CodFEDian, K.IdProducto) END AS CodProductoDIAN,CASE WHEN F.TipCom ='GTC' THEN ('GUIA TRANSPORTE: '+F.TipRem+' '+CAST(F.Remision AS varchar)+' '+F.IdCiaRem)  ELSE DescripProd END  AS DescripProd,
		'' AS DescripProd1, CASE WHEN F.TipCom ='GTC' THEN CAST(1 AS decimal(12,2)) ELSE Salidas END Cant, CASE WHEN F.TipCom ='GTC' THEN '94' ELSE ISNULL(UM.CodUMFE, P.UndMed) END  AS CdUndMed, 
		CASE WHEN F.TipCom ='GTC' THEN VrNeto ELSE  
		(CASE WHEN (SELECT Modalidad FROM Trn_Facturas WHERE TipDoc = @pmTipDoc AND Factura = @pmNroFactura AND IdCia = @pmIdCia) = 'INVENTARIO' AND K.ItemCombo > 0 AND K.EsCombo = 0 AND K.EsProdBase > 0  THEN CAST((K.IngBaseCom / K.Salidas) AS DECIMAL(18,4)) ELSE K.VrPrecio END) END AS VrUnitario, 
		ISNULL(K.VrDctoSal,0) VrDctoSal,  ISNULL(K.TarifaDct,CAST('0' AS DECIMAL(18,4))) TarifaDct, 0 AS TipoReg, ISNULL(K.CantObseq,CAST('0' AS DECIMAL(18,4))) CantObseq,ISNULL(K.CdMoneda,'COP') CdMoneda, ISNULL(K.VrTasaCamb,0) VrTasaCamb,  ISNULL(K.TarifaIco,CAST('0' AS DECIMAL(18,4))) TarifaIco, ISNULL(K.VrImpCon,CAST('0' AS DECIMAL(18,4))) VrImpCon, 
		(CASE WHEN VrImpCon > 0 THEN ((K.Salidas * K.VrPrecio) - K.VrDctoSal)  ELSE 0 END) AS BaseIcoDet, ISNULL(K.TarifaIva,CAST('0' AS DECIMAL(18,4)))  AS TarifaIvaDet,  ISNULL(K.VrIvaSal,CAST('0' AS DECIMAL(18,4))) AS VrIvaDet,
		ISNULL(CAST(((K.Salidas * K.VrPrecio) - K.VrDctoSal) AS DECIMAL(18,4)),CAST('0' AS DECIMAL(18,4))) AS BaseIvaDet, ISNULL(K.TarifaRet,CAST('0' AS DECIMAL(18,4))) AS TarifaRetDet,ISNULL(K.VrReteSal,CAST('0' AS DECIMAL(18,4))) AS VrRetDet, 
		ISNULL(K.TarifaIca,CAST('0' AS DECIMAL(18,4))) AS TarifaIcaDet, ISNULL(K.VrIcaSal,CAST('0' AS DECIMAL(18,4)))  AS VrIcaDet,
		--Versiónn 10
		CAST('0' AS DECIMAL(18,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(18,4))  AS BaseAutoIcaDet, 
		ISNULL(P.ExcluidoImp,0) ExcluidoImp, CAST('0' AS DECIMAL(18,4)) AS ImpCarbono,  CAST('0' AS DECIMAL(18,4)) AS ImpGlobal, CAST('0' AS DECIMAL(18,4)) AS Sobretasa, CAST('0' AS DECIMAL(18,4)) AS Soldicom,  
		CAST('0' AS DECIMAL(18,4)) AS TarifaIvp, CAST('0' AS DECIMAL(18,4)) AS BaseIvp, CAST('0' AS DECIMAL(18,4)) AS IvaIngProd,ISNULL(CAST(K.EsCombo AS bit), 0) EsCombo, 
		--Arreglo Colanta
		--K.ItemCombo, 
		(CASE WHEN K.EsCombo = 0 AND k.EsProdBase = 1 THEN 1 ELSE 0 END) AS ItemCombo, ISNULL(K.Entradas,CAST('0' AS DECIMAL(18,4))) Entradas,ISNULL(P.IvaDetCombo,0) IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet,
		(CASE WHEN P.TipoZonaFront = 'IT' THEN  K.CdOperario ELSE '' END) AS Mandatario, TM.Dv  AS MandatarioDV, TM.TipoId AS MandatarioTipDoc, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3,
		--Inforamción de factura electrónica
		FE.EstadoFE, FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion, FE.RangoNum, FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
		--Otros
		F.Observacion AS Observ, 1 AS FormaPago, F.CdForma, F.Modalidad,F.Origenadd,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem, CAST('0' AS DECIMAL(14, 4)) Volumen,CASE WHEN TP.Simbolo='$' AND TP.IdClase ='ICO' THEN 'Nominal' ELSE 'Porcentual' END TipoICO, 
		 isnull(k.TarifaIba, 0) as TarifaIba, k.VrImpuBa, ISNULL(k.TarifaCup, 0) AS TarifaCup, k.VrImpuCup, p.MedVolm
		FROM Trn_Factcon AS F
		LEFT JOIN Trn_Kardex AS K ON F.TipDoc = K.TipDoc AND F.Factura = K.Documento AND F.IdCia = K.IdCia
		LEFT JOIN ProdMcias AS P ON K.IdProducto = P.IdProducto
		LEFT JOIN ProdCombo AS PC ON P.Idproducto = PC.IdProducto
		LEFT JOIN Sys_Um AS UM ON P.UndMed = UM.UndMed
		INNER JOIN Companias AS C ON F.IdCia = C.IdCia
		INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
		INNER JOIN Terceros AS T ON F.nClieCon = T.IdTercero
		INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
		INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
		INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
		LEFT JOIN Terceros AS TM ON K.CdOperario = TM.IdTercero
		LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
		LEFT JOIN Agencias AS AG ON F.CdAgencia = AG.IdAgencia AND F.NitCliente = AG.IdClie
		LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
		LEFT JOIN Tablapor AS TP ON K.CodTarIco=TP.IdTarifa
		WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.nClieCon LIKE ISNULL(@pmIdCliente,'%')
	ELSE--Intereses
		SELECT F.TipDoc AS Tip_Doc, TD.TipoDoc, F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS CdConceptoP,  
		F.IdCliente,  T.RazonSocial AS NomCliente,  F.IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails, F.Fecha AS FechaVence, F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  CAST('0' AS DECIMAL(18,4)) AS VrImpCons, 
		F.VrRetencion, F.VrReteICA,  VrReteIVA, CAST('0' AS DECIMAL(18,4)) AS VrOtros,  VrCargos,  VrOtrDcto,  0 AS VrSobretasa, CAST('0' AS DECIMAL(18,4)) AS VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  
		CAST('0' AS DECIMAL(18,4)) AS VrImpCarbono,  VrNeto,  CAST('0' AS DECIMAL(18,4)) AS VrAplicado, 1 AS Cantidad, BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO,  BaseRet,  BaseIca,  
		BaseRiv, F.TarifaIva, F.TarifaRet,  F.TarifaIca, CAST('0' AS DECIMAL(18,4)) AS TarifaRiv, CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE,  F.TarifaArf, F.VrAutRetFte,
		---nuevos campos para gestion de PDF
		0 VrFletes,0 VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,0 AS NumRemision,'' IdCiaRem,'',0 AS NumCotizacion,'' AS CiaCotiza,'' TipPed,'' Pedido,'' IdCiaPed,F.IdPlazo AS CdPlazo,Plazo,MulPlazos,F.IdUsuario AS CdUsuario,Usuario,
		F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,'' DetallePago,T.IdRegimen AS CdRegimen,Regimen,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,'' PlacaVeh,
		--Detalles
		FD.Item, FD.IdConcepto AS CodProducto, ISNULL(CD.CodFEDian, FD.IdConcepto) AS CodProductoDIAN, FD.Concepto AS DescripProd,FD.Concepto AS DescripProd1, Cantidad AS Cant, '94' AS CdUndMed, FD.VrUnitario, FD.VrDcto AS VrDctoSal, FD.TarifDcto AS TarifaDct,
		0 AS TipoReg,0 AS CantObseq, 'COP' AS CdMoneda, CAST('0' AS DECIMAL(18,4)) AS VrTasaCamb, CAST('0' AS DECIMAL(18,4)) AS TarifaIco, CAST('0' AS DECIMAL(18,4)) AS VrImpCon, 
		CAST('0' AS DECIMAL(18,4)) AS BaseIcoDet, FD.TarifIva AS TarifaIvaDet,  FD.VrIva AS VrIvaDet,  FD.VrTotal AS BaseIvaDet, FD.TarifRet AS TarifaRetDet, FD.VrRetfte AS VrRetDet, FD.TarifIca AS TarifaIcaDet, 
		FD.VrRetica AS VrIcaDet, 
		--Versión 10
		CAST('0' AS DECIMAL(18,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(18,4))  AS BaseAutoIcaDet,
		CAST(0 AS BIT) AS ExcluidoImp,  CAST('0' AS DECIMAL(18,4)) AS ImpCarbono,  CAST('0' AS DECIMAL(18,4)) AS ImpGlobal, CAST('0' AS DECIMAL(18,4)) AS Sobretasa, CAST('0' AS DECIMAL(18,4)) AS Soldicom,
		CAST('0' AS DECIMAL(18,4)) AS TarifaIvp, CAST('0' AS DECIMAL(18,4)) AS BaseIvp, CAST('0' AS DECIMAL(18,4)) AS IvaIngProd,  CAST(0 AS BIT) AS EsCombo, 0 AS ItemCombo, CAST('0' AS DECIMAL(18,4)) AS Entradas, CAST(0 AS BIT) AS IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet,
		'' AS Mandatario, '' AS MandatarioDV, '' AS MandatarioTipDoc, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3,
		--Inforamción de factura electrónica
		FE.EstadoFE, FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion, FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
		--Otros
		F.Observacion AS Observ, CASE WHEN DiasPago = '0' THEN 1 ELSE 2 END AS FormaPago, 'ZZZ' AS CdForma, 'INTERESES' AS Modalidad,F.Origenadd,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem, CAST('0' AS DECIMAL(14, 4)) Volumen,CAST('Porcentual' AS varchar)TipoICO
		FROM Trn_FinFactint AS F
		JOIN Trn_FinFactDet AS FD ON F.TipDoc = FD.TipDoc AND F.Factura = FD.Factura AND F.IdCia = FD.IdCia
		JOIN FinConcFactura AS CD ON FD.IdConcepto = CD.IdConcepto
		JOIN Companias AS C ON F.IdCia = C.IdCia
		JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
		JOIN Terceros AS T ON F.IdCliente = T.IdTercero
		INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
		INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
		INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
		INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
		LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
		LEFT JOIN Agencias AS AG ON F.IdAgencia = AG.IdAgencia AND F.IdCliente = AG.IdClie
		LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
		WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
END

GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasCom] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Factura,F.IdCia AS CdCia,Compania,Fecha,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia
,A.CodAgencia AS Cod_Agencia,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor
,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,CargoContac
,NitEmpTrans,EmpTrans,F.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor,CdRuta,Ruta,TipPed,Pedido,IdCiaPed
,TipRem,F.Remision AS NumGuia,F.IdCiaRem AS CdCiaGuia,Modalidad,ZonaFrontera,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdUsuario AS CdUsuario,Usuario
--datos del contenedor
,tmNumComp,tmIdProducto,tmCantidad,tmDescProd,tmComp2,tmIdProd2,tmDescProd2,tmCantidad2
,tmComp3,tmIdProd3,tmDescProd3,tmCantidad3,tmComp4,tmIdProd4,tmDescProd4,tmCantidad4
,tmComp5,tmIdProd5,tmDescProd5,tmCantidad5
 FROM Trn_Facturas AS F  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero  INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia 
 LEFT JOIN tm_OccComp AS CMP ON F.TipDoc =CMP.tmTipDoc  AND F.Factura=CMP.tmOCargue AND F.IdCia=CMP.tmIdCia
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 WHERE  TipDoc=@pmTipDoc AND Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasCot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasCot] @pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT F.Factura AS NumFact,F.IdCia AS CodCia,F.Fecha AS FechaFact,FechaVence,IdCliente,RazonSocial,IdAgencia,Modalidad
,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,K.TarifaIva AS TarfIva,VrIvaSal
,TarifaDct,VrDctoSal,((VrPrecio*Salidas)-VrDctoSal)+VrIvaSal AS SValTotal,VrUnitario,VrCostoSal,K.TarifaRet AS TarfRet,VrReteSal,K.TarifaIca AS TarfIca,VrIcaSal,VrBruto
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,K.IdVend AS CdVend,Comision,Referencia,Unidades,Pedido,FecPedido,K.Remision AS Remsion
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS  K ON F.Factura=K.Documento AND F.IdCia=K.IdCia
 AND F.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipCot='COT' AND F.Cotizacion=@pmCotizacion AND F.IdCiaCot=@pmIdCiaCot  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY F.IdCia,F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFacturasFmt] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipDoc AS Tip_Doc,TipoDoc,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDoc,F.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,F.IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,F.VrDescuento AS VrDcto,F.VrImpuesto AS VrIva,F.VrRetencion AS VrRetFte,F.VrReteICA AS VrRetIca,F.VrReteIVA,F.VrFletes
,F.VrOtros,F.VrCargos,F.VrOtrDcto,F.VrCostos,F.VrSobretasa,F.VrImpGlobal,F.VrFaltantes,F.VrAnticipos,F.VrNeto,VrAplicado,F.Cantidad AS CantTotal,F.PesoTotal,F.UnidTotal,F.VolTotal,CantFalt,F.VrCostoRem,F.VrCostoAfi,F.BaseImp,F.BaseRet,F.BaseIca,F.BaseRiv
,F.TarifaIva AS TarifIva,F.TarifaRet AS TarifRet,F.TarifaIca AS TarifIca,TarifaRiv,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom
,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,DiasEntraga,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,CargoContac
,F.IdForma AS CdForma,F.DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,F.TipPed,F.Pedido,F.IdCiaPed,F.TipRem AS TipRemision,F.Remision AS NumRemision,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CiaCotiza,F.FecPedido
,AutzaMora,AutzaCupo,F.Modalidad,KmtVehic,F.TipCom,TipoCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.Observacion AS Observ,VrReteCREE,TarifaRtc,CodTarRtc,F.CodTarArf,F.TarifaArf,F.VrAutRetFte,F.CodTarAri,F.TarifaAri,F.VrAutRetIca,F.VrImpuBA,F.VrImpuCUP
,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.TipoFE,F.FechaFE,F.IdEstado AS CdEstado
,F.TimeSys AS Fec_Add,F.FecUpdate AS Fec_Update,F.IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,Leyenda
--detales
,D.Item,D.TipoReg,D.FechaFact,D.TipRem AS TipRemesa,D.Remesa AS NumRemesa,D.IdCiaRem AS CdCiaRem,ItemRem,D.FecRemesa,D.Descripcion,D.Cantidad AS Cant,D.VrUnitario,D.VrCosto,D.UndTarifa,D.UndCosto,D.Unidades,D.PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Volumen,D.UndVol,D.Cases,D.Cajas,D.Palets,D.CantPago
,D.TarifaIva AS DetTarifIva,D.VrImpuesto AS DetVrIva,TarifaDct,D.VrDescuento AS DetVrDcto,D.TarifaRet AS DetTarifRet,D.VrRetencion AS DetVrRetFte,D.TarifaIca AS DetTarifIca,D.VrReteIca AS DetVrRetIca,VrFaltante,D.VrTray_Vacio1,D.VrTray_Vacio2,D.Remision AS DetNumRemsion,D.DocCliente,D.Referencia1,D.Referencia2,D.Referencia3,D.CdMercancia,DescripMcia
,D.CdConcepto,CF.Concepto AS DetConcepto,D.CdCCosto,CCosto,D.CdSubCos AS CdSubCentro,SubCosto,NitTercero,NT.RazonSocial AS DetTercero,D.CdAgencia,D.pVehiculo AS PlacaVeh,D.TipoAfiVehic,D.IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,D.IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.Anulado AS DetAnulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CantidadFalt,UnidadFalt,NumPedRem,CiaPedRem,VrDeclMcia,TarifaSeg,VrSeguroRem,NitAsegurad,R.CdRutaTarif,RT.Ruta
,RM.SedeRem,SDR.NomSede AS NomSedeRem,RM.SedeDest,SDD.NomSede AS NomSedeDest
--Información del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,Autoret,VrCupo,VrSaldo
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,R.IdDestinatario AS Iddest,TDE.RazonSocial as NomDest,TDE.Direccion as DirDest,TRE.RazonSocial as NomRem,TRE.Direccion as DirRem,R.NumManif,R.SerieGuia,R.NumGuia
,DM.cantimp,DM.Comentarios
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_Facturas AS F INNER JOIN Trn_TraFacRemesas AS D ON F.TipDoc=D.TipDoc  AND F.Factura=D.Factura AND F.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
 INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  
 INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie  INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia 
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal   LEFT JOIN TiposCom AS TCM ON F.TipCom=TCM.IdCom  
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN Mercancias AS MC ON D.CdMercancia=MC.IdMercancia LEFT JOIN  ConcDiversos AS CF ON D.CdConcepto=CF.IdConcepto
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero
 LEFT JOIN Trn_TraRemesa AS R ON D.TipRem=R.TipDoc AND D.Remesa=R.NumOrden AND D.IdCiaRem=R.IdCia
 LEFT JOIN Rutas AS RT ON R.CdRutaTarif=RT.IdRuta 
 LEFT JOIN Trn_DocMemo AS DM ON F.TipDoc=DM.TipDoc AND F.Factura=DM.Documento AND F.IdCia=DM.IdCia
 LEFT JOIN Trn_TraRemMcias AS RM ON D.TipRem=RM.TipDoc AND D.Remesa=RM.NumOrden AND D.IdCiaRem=RM.IdCia AND D.ItemRem=RM.Item
 LEFT JOIN TercSedes AS SDR ON RM.NitRemite=SDR.IdTercero AND RM.SedeRem=SDR.IdSede LEFT JOIN TercSedes AS SDD ON RM.NitDestntario=SDD.IdTercero AND RM.SedeDest=SDD.IdSede
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 LEFT JOIN Terceros AS TDE ON R.IdDestinatario=TDE.IdTercero LEFT JOIN Terceros As TRE ON R.IdRemitente=TRE.IdTercero
 WHERE F.TipDoc=@pmTipDoc AND F.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasFmtb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasFmtb] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipDoc AS Tip_Doc,TipoDoc,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDoc,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrOtros,VrCargos,VrOtrDcto,VrImpCarbono,F.VrIvaIngProd,F.VrReteCREE,F.VrAutRetIca,F.VrAutRetFte,F.VrNeto,F.VrAplicado,F.Cantidad AS CantTotal,F.BaseImp,F.BaseRet,F.BaseIca,F.BaseRiv,F.BaseIvaIgp
,F.TarifaIva AS TarifIva,F.TarifaRet AS TarifRet,F.TarifaIca AS TarifIca,TarifaRiv,F.TarifaRtc,F.TarifaArf,F.TarifaAri,F.IdCCosto,CC.CCosto AS CentCosto,F.IdSubCos,SC.SubCosto AS SubcCosto
,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.TarifaCom,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,F.DiasEntraga
,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,F.CargoContac,F.IdForma AS CdForma,FormaPago,F.DetallePago
,F.MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,F.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor,F.TipRem,F.Remision,F.IdCiaRem,F.FecPedido
,F.AutzaMora,F.AutzaCupo,F.Modalidad,F.TipCom,TCM.TipoCom,F.Comprobante,F.IdCiaCom,F.Anulado,F.NumDev,F.FecDev,F.Observacion,F.ZonaFrontera,TipoFE,FechaFE,F.IdEstado AS CdEstado,Estado
,F.TimeSys AS Fec_Add,F.FecUpdate AS Fec_Update,F.IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,F.OrigenAdd,TD.Leyenda AS TdcDescripcion
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,NitRepLeg,NomRepLeg,ExcIva,Autoret,VrCupo,VrSaldo,A.CodSicom
--Detalles
,D.Item,D.IdTanque,D.IdProducto AS CodProducto,D.Descripcion,PM.DescripProd,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TarifaDct,D.VrDcto,D.TarifaIva,D.VrIva,D.TarifaRet,D.VrRetFte,D.VrBaseRet,D.TarifaIca,D.VrRetIca,D.FleteUnd,D.CostoUnit
,D.Temperatura,D.TempLab,D.UnidTemp,D.ValorAPI,D.API_Corregido,D.Densidad,D.TipoProd,D.TipGuia,D.NumGuia,D.IdCiaGuia,D.ItemGuia,D.CantGuia,D.IndMezcla,D.ItemMezcla,D.FactorMezcla,D.NumTasas,D.TasaBrent,D.TasaWti,D.TRMdolar,D.Puntos
,D.CodTarIva,D.CodTarDct,D.CodTarRet,D.CodTarIca,D.CdMoneda,D.CodSicomPro,D.CodBodega,Bodega,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo
,DM.Comentarios AS Comentario,Nota1,Nota2,Nota3,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_Facturas AS F INNER JOIN Trn_OilFacturaProd AS D ON F.TipDoc=D.TipDoc AND F.Factura=D.Factura AND F.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias AS PM ON D.IdProducto=PM.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 LEFT JOIN Bodegas AS B ON D.CodBodega=B.IdBodega LEFT JOIN Tanques AS TQ ON D.IdTanque=TQ.IdTanque
 LEFT JOIN Localidades AS LE ON F.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TCM ON F.TipCom=TCM.IdCom
 LEFT JOIN Trn_DocMemo AS DM ON F.TipDoc=DM.TipDoc AND F.Factura=DM.Documento AND F.IdCia=DM.IdCia
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
 AND D.IndMezcla<>2
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasFmtc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFacturasFmtc] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.TipDoc AS Tip_Doc,TipoDoc,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDoc,F.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,F.IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,FechaVence,VrSubTotal,F.VrDescuento AS VrDcto,F.VrImpuesto AS VrIva,F.VrRetencion AS VrRetFte,F.VrReteICA AS VrRetIca,F.VrReteIVA,F.VrFletes
,F.VrOtros,F.VrCargos,F.VrOtrDcto,F.VrCostos,F.VrSobretasa,F.VrImpGlobal,F.VrFaltantes,F.VrAnticipos,F.VrNeto,VrAplicado,F.Cantidad AS CantTotal,F.BaseImp,F.BaseRet,F.BaseIca
,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,CargoContac
,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,F.TipRem AS TipRemision,F.Remision AS NumRemision,F.FecPedido,F.Modalidad,F.TipCom,F.Comprobante,F.IdCiaCom
,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.Observacion AS Observ,TipoFE,FechaFE,F.IdEstado AS CdEstado,F.TimeSys AS Fec_Add,F.FecUpdate AS Fec_Update,F.IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,Leyenda
--detales
,D.Item,D.IdCargo,CG.Concepto AS Cargo,D.Descripcion,D.ValorCargo,D.TarifaIva,D.VrIva AS DetVrIva,D.TarifaRet,D.VrRetencion AS DetVrRetencion,D.TarifaIca,D.VrReteIca AS DetVerIca,D.CdAgencia
,D.IdVehiculo AS PlacaVeh,D.Referencia,D.CodTarIva,D.CodTarRet,D.CodTarIca,D.CdClaseCue,D.TipCausac,D.NumCausac,D.CiaCausac,D.ItemCausac
,CG.CodFEDian,CG.IdCuentaDeb,CG.IdCuentaCre,CG.IdCueDebVp,CG.IdCueCreVp,CG.CdCuentaIva,CG.CdCuentaRet,CG.CdCuentaIca,CG.IvaIncluido
--Información del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,Autoret,VrCupo,VrSaldo
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia, FE.CUFE_QR
 FROM Trn_Facturas AS F INNER JOIN  Trn_FactCausacion AS D ON F.TipDoc=D.TipDoc  AND F.Factura=D.Factura AND F.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
 INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  
 INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Fijos AS CG ON D.IdCargo=CG.IdCargo
 LEFT JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie LEFT JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona
 LEFT JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia 
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasGui]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasGui] @pmRemision INT,@pmIdCiaRem CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT F.Factura AS NumFact,F.IdCia AS CodCia,F.Fecha AS FechaFact,FechaVence,IdCliente,RazonSocial,IdAgencia,Modalidad
,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,K.TarifaIva AS TarifIva,VrIvaSal
,VrUnitario,VrCostoSal,K.TarifaRet AS TarifRet,VrReteSal,K.TarifaIca AS TarifIca,VrIcaSal,VrBruto
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,K.pVehiculo AS PlacaVeh,K.IdVend AS CdVend,Comision,Referencia,Unidades,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,TipPed,Pedido,IdCiaPed,TipCot,F.Cotizacion AS OCargue,F.IdCiaCot AS IdCiaOcc
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS  K ON F.Factura=K.Documento AND F.IdCia=K.IdCia
 AND F.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipRem='GUI' AND F.Remision=@pmRemision AND F.IdCiaRem=@pmIdCiaRem  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY F.IdCia,F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasIca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasIca] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
AS 
SELECT F.TipDoc,F.Factura,F.IdCia,Compania,F.Fecha,F.IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia,A.Agencia AS NomAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrIvaObsequio,VrRetencion,VrReteICA,VrReteCREE,VrReteIVA,VrImpCons
,VrOtros,VrCargos,VrOtrDcto,VrFletes,F.VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaObsq,F.TarifaIva,F.TarifaRet,F.TarifaIca,F.TarifaRiv,F.TarifaRtc,F.CodTarIca
,F.IdLocEnv AS IdLocal,LE.Localidad,LE.IdDep AS CdDpto,DE.Departamento,F.IdVend,VN.RazonSocial AS Vendedor,F.TarifaCom,F.Modalidad,F.IdConcepto,Concepto,F.NitContac,F.NomContac,F.TipPed,F.Pedido,F.IdCiaPed,F.TipRem,F.Remision,F.IdCiaRem,F.TipCom,F.Comprobante,F.IdCiaCom
,F.Anulado,'' AS TipDev,F.NumDev,F.IdCiaCrea AS IdCiaDev,F.FecDev,F.Observacion,TipoDoc
--datos terceros
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.IdLocal AS TercCdCiudad,L.Localidad AS TercNomCiudad,L.IdDep AS TercCdDpto,DP.Departamento AS TercDpto,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CL.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CL.IdGrupo AS CdGrupoCli,GrupoClie,LEV.IdDep AS ClCdDptoEnv,DEV.Departamento AS ClDptoEnvio,CL.IdLocEnv AS ClIdCiuEnv,LEV.Localidad AS ClCiuEnvio,CL.ExcIva,CL.Autoret
,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto 
FROM Trn_Facturas AS F INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
INNER JOIN TercCliente AS CL ON F.IdCliente=CL.IdClie INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
INNER JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal INNER JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
INNER JOIN Localidades AS LE ON F.IdLocEnv=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (F.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
UNION ALL
SELECT D.TipDev,D.Devolucion,D.IdCia,Compania,D.Fecha,D.IdCliente,T.RazonSocial,D.IdAgencia,A.Agencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrIvaObsequio,D.VrRetencion,D.VrReteICA,D.VrReteCREE,D.VrReteIVA,D.VrImpCons
,D.VrOtros,D.VrCargos,D.VrOtrDcto,D.VrFletes,D.VrNeto,D.BaseImp,D.BaseRet,D.BaseRet,D.VrImpuesto,D.BaseIvaObsq,F.TarifaIva,F.TarifaRet,F.TarifaIca,F.TarifaRiv,D.TarifaRtc,F.CodTarIca
,D.IdLocEnv,LE.Localidad,LE.IdDep,DE.Departamento,D.IdVend,VN.RazonSocial,D.TarifaCom,D.Modalidad,D.IdConcepto,Concepto,'','','PED',D.Pedido,D.IdCiaPed,'REM',D.Remision,D.IdCiaRem,D.TipCom,D.Comprobante,D.IdCiaCom
,0,D.TipDoc,D.Factura,D.IdCiaDoc,D.FecDoc,D.Observacion,TipoDoc
--datos terceros
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,L.IdDep,DP.Departamento,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CL.IdSzona,Subzona,SZ.IdZona,Zona,CL.IdGrupo,GrupoClie,LEV.IdDep,DEV.Departamento,CL.IdLocEnv,LEV.Localidad,CL.ExcIva,CL.Autoret
,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento
FROM Trn_DevFcr AS D INNER JOIN Trn_Facturas AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
INNER JOIN TercCliente AS CL ON D.IdCliente=CL.IdClie INNER JOIN Agencias AS A ON D.IdAgencia=A.IdAgencia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
INNER JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal INNER JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
INNER JOIN Localidades AS LE ON D.IdLocEnv=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (D.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
UNION ALL
SELECT F.TipDoc,F.Factura,F.IdCia,Compania,F.Fecha,F.NitCliente,T.RazonSocial,F.CdAgencia,A.Agencia,VrSubTotal,VrDescuento,VrImpuesto,VrIvaObsequio,VrRetencion,VrReteICA,VrReteCREE,VrReteIVA,VrImpCons
,0,VrCargos,VrOtrDcto,VrFletes,VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,BaseIvaObsq,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,F.CodTarIca
,F.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,F.IdVend,VN.RazonSocial,F.TarifaCom,F.Modalidad,F.IdConcepto,Concepto,F.nClieCon,CT.Nombre,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,TipCom,Comprobante,IdCiaCom
,F.Anulado,'',F.NumDev,F.IdCiaCrea,F.FecDev,F.Observacion,TipoDoc
--datos de terceros
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,L.IdDep,DP.Departamento,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CL.IdSzona,Subzona,SZ.IdZona,Zona,CL.IdGrupo,GrupoClie,LEV.IdDep,DEV.Departamento,CL.IdLocEnv,LEV.Localidad,CL.ExcIva,CL.Autoret
,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento
FROM Trn_Factcon AS F INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc=TD.IdDoc
INNER JOIN Localidades AS LE ON F.IdLocal=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
LEFT JOIN Terceros AS T ON F.NitCliente=T.IdTercero LEFT JOIN TercCliente AS CL ON F.NitCliente=CL.IdClie
LEFT JOIN Agencias AS A ON F.CdAgencia=A.IdAgencia
LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
LEFT JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona LEFT JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
LEFT JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo 
LEFT JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal LEFT JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
LEFT JOIN ClieContado AS CT ON F.nClieCon=CT.IdCliente
WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (F.NitCliente=@pmIdCliente OR @pmIdCliente IS NULL)
UNION ALL
SELECT D.TipDev,D.Devolucion,D.IdCia,Compania,D.Fecha,D.NitCliente,T.RazonSocial,D.CdAgencia,A.Agencia,D.VrSubTotal,D.VrDescuento,D.VrImpuesto,D.VrIvaObsequio,D.VrRetencion,D.VrReteICA,D.VrReteCREE,D.VrReteIVA,D.VrImpCons
,0,D.VrCargos,D.VrOtrDcto,D.VrFletes,D.VrNeto,D.BaseImp,D.BaseRet,D.BaseRet,D.VrImpuesto,D.BaseIvaObsq,F.TarifaIva,F.TarifaRet,F.TarifaIca,F.TarifaRiv,D.TarifaRtc,F.CodTarIca
,D.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,D.IdVend,VN.RazonSocial,D.TarifaCom,D.Modalidad,D.IdConcepto,Concepto,D.nClieCon,CT.Nombre,'PED',D.Pedido,D.IdCiaPed,'REM',D.Remision,D.IdCiaRem,D.TipCom,D.Comprobante,D.IdCiaCom
,0,D.TipDoc,D.Factura,D.IdCiaDoc,D.FecDoc,D.Observacion,TipoDoc
--datos de terceros
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,L.IdDep,DP.Departamento,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CL.IdSzona,Subzona,SZ.IdZona,Zona,CL.IdGrupo,GrupoClie,LEV.IdDep,DEV.Departamento,CL.IdLocEnv,LEV.Localidad,CL.ExcIva,CL.Autoret
,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento
FROM Trn_DevFco AS D INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
INNER JOIN Localidades AS LE ON D.IdLocal=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
LEFT JOIN Terceros AS T ON D.NitCliente=T.IdTercero LEFT JOIN TercCliente AS CL ON D.NitCliente=CL.IdClie
LEFT JOIN Agencias AS A ON D.CdAgencia=A.IdAgencia
LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
LEFT JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona LEFT JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
LEFT JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo 
LEFT JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal LEFT JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
LEFT JOIN ClieContado AS CT ON D.nClieCon=CT.IdCliente
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (D.NitCliente=@pmIdCliente OR @pmIdCliente IS NULL)
UNION ALL
SELECT N.TipDoc,N.NumNota,N.IdCia,Compania,N.Fecha,N.IdCliente,T.RazonSocial,N.IdAgencia,A.Agencia,VrSubTotal,0,VrImpuesto,0,VrRetencion,VrReteICA,VrReteCREE,VrReteIVA,0
,VrOtros,VrSancion,0,0,N.VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,0,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,N.CodTarIca
,N.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,N.IdVend,VN.RazonSocial,N.TarifaCom,N.Modalidad,N.IdConcepto,Concepto,N.CdConductor,N.Referencia,TipDcm,Documento,IdCiaDcm,'RMT',nRemesa,CdCiaRem,TipCom,Comprobante,IdCiaCom
,0,TipDcm,Documento,IdCiaDcm,FecDcm,N.Observacion,TipoDoc
--datos de terceros
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,L.IdDep,DP.Departamento,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CL.IdSzona,Subzona,SZ.IdZona,Zona,CL.IdGrupo,GrupoClie,LEV.IdDep,DEV.Departamento,CL.IdLocEnv,LEV.Localidad,CL.ExcIva,CL.Autoret
,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento
FROM Trn_Notas AS N INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON N.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON N.IdVend=VN.IdTercero
INNER JOIN TercCliente AS CL ON N.IdCliente=CL.IdClie INNER JOIN Agencias AS A ON N.IdAgencia=A.IdAgencia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc
INNER JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal INNER JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
INNER JOIN Localidades AS LE ON N.IdLocal=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
WHERE N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (N.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (N.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
UNION ALL
SELECT R.TipDoc,R.Recibo,R.IdCia,Compania,R.Fecha,R.IdCliente,T.RazonSocial,R.IdAgencia,A.Agencia,VrSubTotal,VrDescuento,0,0,VrRetencion,VrReteICA,VrReteCREE,VrReteIVA,0
,VrOtros,VrPagosMas,VrOtrDcto,VrAhorro,R.VrNeto,0,BaseRet,BaseIca,BaseRiv,0,0,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,R.CodTarIca
,R.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,R.IdVend,VN.RazonSocial,R.TarifaCom,R.Modalidad,R.IdConcepto,Concepto,R.CdConductor,R.Referencia,R.TipDcm,R.Documento,R.IdCiaDcm,'',0,'',R.TipCom,R.Comprobante,R.IdCiaCom
,R.Anulado,'',R.NumDev,R.IdCiaCrea,R.FecDev,R.Observacion,TipoDoc
--datos de terceros
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,L.IdDep,DP.Departamento,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CL.IdSzona,Subzona,SZ.IdZona,Zona,CL.IdGrupo,GrupoClie,LEV.IdDep,DEV.Departamento,CL.IdLocEnv,LEV.Localidad,CL.ExcIva,CL.Autoret
,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento
FROM Trn_Recibos AS R INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON R.IdVend=VN.IdTercero
INNER JOIN TercCliente AS CL ON R.IdCliente=CL.IdClie INNER JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
INNER JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal INNER JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
INNER JOIN Localidades AS LE ON R.IdLocal=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
WHERE R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (R.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (R.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
UNION ALL
SELECT D.TipDev,D.Devolucion,D.IdCia,Compania,D.Fecha,D.IdCliente,T.RazonSocial,D.IdAgencia,A.Agencia,D.VrSubTotal,D.VrDescuento,0,0,D.VrRetencion,D.VrReteICA,D.VrReteCREE,D.VrReteIVA,0
,D.VrOtros,D.VrPagosMas,D.VrOtrDcto,D.VrAhorro,D.VrNeto,0,D.BaseRet,D.BaseIca,D.BaseRiv,0,0,R.TarifaRet,R.TarifaIca,R.TarifaRiv,D.TarifaRtc,R.CodTarIca
,D.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,D.IdVend,VN.RazonSocial,D.TarifaCom,D.Modalidad,D.IdConcepto,Concepto,D.CdConductor,D.Referencia,D.TipDcm,D.Documento,D.IdCiaDcm,'',0,'',D.TipCom,D.Comprobante,D.IdCiaCom
,0,D.TipDoc,D.Recibo,D.IdCiaDoc,D.FecDoc,D.Observacion,TipoDoc
--datos de terceros
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,L.IdDep,DP.Departamento,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CL.IdSzona,Subzona,SZ.IdZona,Zona,CL.IdGrupo,GrupoClie,LEV.IdDep,DEV.Departamento,CL.IdLocEnv,LEV.Localidad,CL.ExcIva,CL.Autoret
,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento
FROM Trn_DevRec AS D INNER JOIN Trn_Recibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
INNER JOIN TercCliente AS CL ON D.IdCliente=CL.IdClie INNER JOIN Agencias AS A ON D.IdAgencia=A.IdAgencia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Subzonas AS SZ ON CL.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
INNER JOIN Localidades AS LEV ON CL.IdLocEnv=LEV.IdLocal INNER JOIN Departamentos AS DEV ON LEV.IdDep=DEV.IdDep
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep
INNER JOIN Localidades AS LE ON D.IdLocal=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND (D.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFacturasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmFacturaIni INT=Null,@pmFacturaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT F.Factura,F.IdCia,FE.Prefijo,FE.NumFace,Fecha,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes
,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrImpCarbono,VrIvaIngProd,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca
,BaseRiv,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,F.IdConcepto AS CdConcepto,Concepto,IdCCosto,IdSubCos,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio
,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans
,EmpTrans,pVehiculo,CdConductor,KmtVehic,CdRuta,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,CodAutoRet
,OrigenAdd,TipCom,Comprobante,IdCiaCom,ZonaFrontera,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,F.VrImpuBA,F.VrImpuCUP
,ImpAviTab,TarifaAvta,CodTarifAvta,VrBomberil,TarifaBom,CodTarifBom,VrAutRetIat,VrAutRetBom,Parqueadero,FecCuotaParq,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
,TipoFE,FechaFE,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,F.IdUsuario AS IdUsuari,Usuario,F.TipDoc
 FROM Trn_Facturas F INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON F.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON F.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario 
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.Factura BETWEEN ISNULL(@pmFacturaIni,0) AND ISNULL(@pmFacturaFin,2147483647)
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND F.IdVend LIKE ISNULL(@pmIdVend,'%') AND F.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND F.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (F.Anulado=ISNULL(@pmAnulado,0) OR F.Anulado=ISNULL(@pmAnulado,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasNet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFacturasNet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Factura,F.IdCia AS CdCia,Compania,Fecha,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia
,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal
,VrFaltantes,VrAnticipos,VrIvaIngProd,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,F.IdCCosto AS IdCenCost,CCosto
,F.IdSubCos AS IdSubCent,SubCosto,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio
,DE.Departamento AS DptoEnvio,DiasEntraga,F.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,pVehiculo
,CdConductor,TC.RazonSocial AS Conductor,F.CdRuta,Ruta,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,KmtVehic,VrImpCons,VrReteCREE,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca
,F.VrImpuBA,F.VrImpuCUP,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.Modalidad,F.TipCom,F.Comprobante,F.IdCiaCom
,F.Anulado,F.NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,TimeSys,F.FecUpdate AS Fec_Update,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,SZ.Subzona,SZ.IdZona AS CdZona,Z.Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.CdFntePago AS CdFuente,FuentePago,TipoZona,A.IdSzona AS AgeCdSubzona,SZA.Subzona AS AgeSubzona,SZA.IdZona AS AgeCdZona,ZA.Zona AS AgeZona
 FROM Trn_Facturas AS F  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LE ON F.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Subzonas AS SZA ON A.IdSzona=SZA.IdSzona LEFT JOIN Zonas AS ZA ON SZA.IdZona=ZA.IdZona 
 WHERE TipDoc LIKE ISNULL(@pmTipDoc,'%') AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND F.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND F.IdVend LIKE ISNULL(@pmIdVend,'%') AND F.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente
,D.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,FechaVence,D.VrSubTotal AS SubTotal,D.VrDescuento AS Descuentos,D.VrImpuesto AS Impuestos
,D.VrRetencion AS ReteFte,D.VrReteICA AS ReteIca,D.VrReteIVA AS ReteIVA,D.VrFletes AS Fletes,D.VrOtros AS Otros,D.VrCargos AS OtrosCargos,D.VrOtrDcto AS OtrosDctos,D.VrCostos AS TotalCostos
,D.VrSobretasa AS Sobretasas,D.VrImpGlobal AS ImpGlobal,D.VrFaltantes AS Faltantes,D.VrAnticipos AS Anticipos,D.VrIvaIngProd,D.VrNeto AS TotalNeto,0,D.Cantidad AS CantDev,D.CantPuntos AS CantPuntDev,0
,D.BaseImp AS BaseIVA,D.BaseRet AS BaseRetFte,D.BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,D.TarifaRtc,D.IdCCosto AS IdCenCost,CCosto,D.IdSubCos AS IdSubCent,SubCosto,D.IdVend AS NitVend,VN.RazonSocial AS Vendedor
,D.TarifaCom AS TarifCom,DirEnvio,D.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,DiasEntraga,F.IdForma AS CdForma,FormaPago,DetallePago
,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,F.CdRuta,Ruta,TipPed,D.Pedido AS NumPedido,D.IdCiaPed AS CdCiaPed
,TipRem,D.Remision AS NumRemision,D.IdCiaRem AS CdCiaRem,TipCot,D.Cotizacion AS NumCotizacion,D.IdCiaCot AS CdCiaCotiza,D.FecPedido AS FechaPed,D.KmtVehic AS DevKmtVeh,D.VrImpCons,D.VrReteCREE,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.VrImpuBA,D.VrImpuCUP
,D.ImpAviTab,D.TarifaAvta,F.CodTarifAvta,D.VrBomberil,D.TarifaBom,F.CodTarifBom,D.VrAutRetIat,D.VrAutRetBom,D.Modalidad AS ModFactura,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CodCiaCom,0,D.Factura AS NumFactura
,FecDoc,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fech_Sys,D.FecUpdate AS Fech_Update,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,SZ.Subzona,SZ.IdZona AS CdZona,Z.Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.CdFntePago AS CdFuente,FuentePago,TipoZona,A.IdSzona,SZA.Subzona,SZA.IdZona,ZA.Zona
 FROM Trn_DevFcr AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero INNER JOIN Agencias AS A ON D.IdAgencia=A.IdAgencia 
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_Facturas AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma INNER JOIN  Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
 LEFT JOIN  Localidades AS LE ON D.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN Subzonas AS SZA ON A.IdSzona=SZA.IdSzona LEFT JOIN Zonas AS ZA ON SZA.IdZona=ZA.IdZona 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.TipDoc LIKE ISNULL(@pmTipDoc ,'%') 
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND D.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND D.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY F.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasNetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFacturasNetDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmTipoRef VARCHAR(10)=Null
 AS 
 SELECT F.TipDoc AS TipoFact,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha AS FechaDoc,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,FechaVence,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto
,VrNeto,CantPuntos,PuntosAcum,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,F.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor,F.CdRuta,Ruta
,TipPed,Pedido,IdCiaPed,TipRem,F.Remision AS NumRemision,F.IdCiaRem AS CdCiaRem,TipCot,F.Cotizacion AS NumCotizacion,F.IdCiaCot AS CdCiaCotiza,FecPedido,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca
,F.VrImpuBA,F.VrImpuCUP,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,F.Modalidad,KmtVehic,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,F.TimeSys AS Fecha_Add,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--detalles
,K.IdProducto AS CdProducto,DescripProd,Item,K.IdBodega AS CdBodega,Bodega,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,K.TarifaRet AS TarifRet,VrReteEnt,VrReteSal
,K.TarifaIca AS TarifIca,VrIcaEnt,VrIcaSal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden
,CdAgencia,KA.Agencia AS KarAgencia,KA.CodAgencia AS KarCodAgencia,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,Comision,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper
,K.pVehiculo AS KarPlacaVeh,CdLocal,LK.Localidad AS KarCiudad,CdCCosto,CCosto,K.CdSubCos AS CodSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarNumRemision,K.IdCiaRem AS KarCdCiaRem,K.Cotizacion AS KarNumCotizacion
,K.IdCiaCot AS KarCiaCotiza,ListaPrec,VrBruto,VrBase,BaseIvp,TarifaIvp,IvaIngProd,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
,K.TarifaIat AS KarTarifIat,K.VrAviTab AS KarAvisoTab,K.CodTarIat AS KarCodTarifIat,K.TarifaBom AS KarTarifBom,K.VrSobBom AS KarSobBomb,K.CodTarBom AS KarCodTarifBom
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,SZ.Subzona,SZ.IdZona AS CdZona,Z.Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.CdFntePago AS CdFuente,FuentePago,A.TipoZona AS TipoZona,A.IdSzona AS AgeCdSubzona,SZA.Subzona AS AgeSubzona,SZA.IdZona AS AgeCdZona,ZA.Zona AS AgeZona
 FROM Trn_Facturas AS F  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo  INNER JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia 
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero LEFT JOIN Agencias  AS KA ON K.CdAgencia=KA.IdAgencia
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN  Localidades AS LK ON K.CdLocal=LK.IdLocal 
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Subzonas AS SZA ON A.IdSzona=SZA.IdSzona LEFT JOIN Zonas AS ZA ON SZA.IdZona=ZA.IdZona 
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsProdBase=0 AND F.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND F.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND F.IdVend LIKE ISNULL(@pmIdVend,'%') AND F.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 UNION
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente
,D.IdAgencia AS IdAgncia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,FechaVence,D.VrRetencion AS ReteFte,D.VrReteICA AS ReteIca,D.VrReteIVA AS ReteIVA,D.VrFletes AS Fletes
,D.VrOtros AS Otros,D.VrCargos AS OtrosCargos,D.VrOtrDcto AS OtrosDctos,D.VrNeto AS TotalNeto,D.CantPuntos AS CantPuntDev,0,D.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio
,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,F.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor
,F.CdRuta,Ruta,TipPed,D.Pedido AS NumPedido,D.IdCiaPed AS CdCiaPed,TipRem,D.Remision AS NumRemision,D.IdCiaRem AS CdCiaRem,TipCot,D.Cotizacion AS NumCotizacion,D.IdCiaCot AS CdCiaCotiza
,D.FecPedido AS FechaPed,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.VrImpuBA,D.VrImpuCUP,D.ImpAviTab,D.TarifaAvta,F.CodTarifAvta,D.VrBomberil,D.TarifaBom,F.CodTarifBom,D.VrAutRetIat,D.VrAutRetBom
,D.Modalidad AS ModFactura,D.KmtVehic AS DevKmtVeh,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CodCiaCom,0,D.Factura AS NumFactura,FecDoc,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado
,D.TimeSys AS Fech_Sys,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--detalles
,K.IdProducto AS CdProducto,DescripProd,Item,K.IdBodega AS CdBodega,Bodega,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario
,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaIva AS TarifIva,VrIvaEnt,VrIvaSal,K.TarifaRet AS TarifRet,VrReteEnt,VrReteSal
,K.TarifaIca AS TarifIca,VrIcaEnt,VrIcaSal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden
,CdAgencia,KA.Agencia AS KarAgencia,KA.CodAgencia AS KarCodAgencia,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,Comision,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper
,K.pVehiculo AS KarPlacaVeh,CdLocal,LK.Localidad AS KarCiudad,CdCCosto,CCosto,K.CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,K.Remision AS KarNumRemision,K.IdCiaRem AS KarCdCiaRem,K.Cotizacion AS KarNumCotizacion
,K.IdCiaCot AS KarCiaCotiza,ListaPrec,VrBruto,VrBase,BaseIvp,TarifaIvp,IvaIngProd,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo,K.CodTarBa,K.TarifaIba,K.VrImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup
,K.TarifaIat,K.VrAviTab,K.CodTarIat,K.TarifaBom,K.VrSobBom,K.CodTarBom
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,DescripLong,DescripAbrv,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,SZ.Subzona,SZ.IdZona AS CdZona,Z.Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.CdFntePago AS  CdFuente,FuentePago,A.TipoZona,A.IdSzona,SZA.Subzona,SZA.IdZona,ZA.Zona
 FROM Trn_DevFcr AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Agencias  AS A ON D.IdAgencia=A.IdAgencia 
 INNER JOIN TercCliente AS CLI ON D.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_Facturas AS F ON D.TipDoc=F.TipDoc AND D.Factura=F.Factura AND D.IdCiaDoc=F.IdCia
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
 INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero LEFT JOIN Agencias  AS KA ON K.CdAgencia=KA.IdAgencia
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN  Localidades AS LK ON K.CdLocal=LK.IdLocal  LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 LEFT JOIN  Localidades AS LE ON D.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Subzonas AS SZA ON A.IdSzona=SZA.IdSzona LEFT JOIN Zonas AS ZA ON SZA.IdZona=ZA.IdZona 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsProdBase=0 AND D.TipDoc LIKE ISNULL(@pmTipDoc ,'%') 
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND D.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND D.Modalidad LIKE ISNULL(@pmModalidad,'%') AND  K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 ORDER BY F.IdCia,F.Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasOcc] @pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT F.Factura AS NumFact,F.IdCia AS CodCia,F.Fecha AS FechaFact,FechaVence,IdCliente,RazonSocial,IdAgencia,Modalidad
,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,K.TarifaIva AS TarifIva,VrIvaSal
,VrUnitario,VrCostoSal,K.TarifaRet AS TarifRet,VrReteSal,K.TarifaIca AS TarifIca,VrIcaSal,VrBruto
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,K.pVehiculo AS PlacaVeh,K.IdVend AS CdVend,Comision,Referencia,Unidades,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,TipPed,Pedido,IdCiaPed,TipRem,F.Remision AS NumGuia,F.IdCiaRem AS CodCiaGuia
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS  K ON F.Factura=K.Documento AND F.IdCia=K.IdCia
 AND F.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipCot='OCC' AND F.Cotizacion=@pmCotizacion AND F.IdCiaCot=@pmIdCiaCot  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY F.IdCia,F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOdc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasOdc] @pmTipCot VARCHAR(3),@pmCotizacion INT,@pmIdCiaCot CHAR(2)
,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,TipCot,Cotizacion,IdCiaCot
 FROM Trn_Facturas
 WHERE TipCot=@pmTipCot AND Cotizacion=@pmCotizacion AND IdCiaCot=@pmIdCiaCot
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOdp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasOdp] @pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2)
,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,TipPed,Pedido,IdCiaPed
 FROM Trn_Facturas
 WHERE TipPed=@pmTipPed AND Pedido=@pmPedido AND IdCiaPed=@pmIdCiaPed
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasOdr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasOdr] @pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2)
,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,TipRem,Remision,IdCiaRem
 FROM Trn_Facturas
 WHERE  TipRem=@pmTipRem AND Remision=@pmRemision AND IdCiaRem=@pmIdCiaRem
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasPed]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasPed] @pmPedido INT,@pmIdCiaPed CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT F.Factura AS NumFact,F.IdCia AS CodCia,F.Fecha AS FechaFact,FechaVence,IdCliente,RazonSocial,IdAgencia,Modalidad
,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,K.TarifaIva AS TarfIva,VrIvaSal
,TarifaDct,VrDctoSal,((VrPrecio*Salidas)-VrDctoSal)+VrIvaSal AS SValTotal,VrUnitario,VrCostoSal,K.TarifaRet AS TarfRet,VrReteSal,K.TarifaIca AS TarifIca,VrIcaSal,VrBruto
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,K.IdVend AS CdVend,Comision,Referencia,Unidades
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS  K ON F.Factura=K.Documento AND F.IdCia=K.IdCia
 AND F.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipPed='PED' AND Pedido=@pmPedido AND IdCiaPed=@pmIdCiaPed  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY F.IdCia,F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT F.TipDoc,F.Factura,F.IdCia AS CdCia,Compania,F.Fecha,FE.Prefijo,FE.NumFace,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia
,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal
,VrFaltantes,VrAnticipos,VrImpCarbono,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet ,TarifaIca,TarifaRiv,F.IdCCosto AS IdCenCost,CCosto
,F.IdSubCos AS IdSubCent,SubCosto,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio
,DE.Departamento AS DptoEnvio,DiasEntraga,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,CargoContac
,F.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,pVehiculo,KmtVehic,CdConductor,TC.RazonSocial AS Conductor
,F.CdRuta,Ruta,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,VrImpCons,F.VrImpuBA,F.VrImpuCUP
,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,BaseIvaObsq,VrIvaObsequio,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca,OrigenAdd,TipCom,Comprobante,IdCiaCom
,F.Anulado,NumDev,FecDev,F.Observacion AS Observ,ZonaFrontera,VrReteCREE,TarifaRtc,CodTarRtc,F.IdEstado AS CdEstado,Estado,F.TimeSys,F.FecUpdate AS Fec_Update,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,CdFntePago,FuentePago
 FROM Trn_Facturas AS F  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos 
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc LIKE ISNULL(@pmTipDoc,'%') AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND F.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND F.IdVend LIKE ISNULL(@pmIdVend,'%') AND F.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND F.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (F.Anulado=ISNULL(@pmAnulado,0) or F.Anulado=ISNULL(@pmAnulado,1))
 ORDER BY F.IdCia,F.Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRelTra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasRelTra] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT F.TipDoc,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha,FE.Prefijo,FE.NumFace,F.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia
,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal
,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet ,TarifaIca,TarifaRiv,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi
,VrImpCons AS VrAutoICA,ZonaFrontera AS EstAutoICA,F.IdCCosto AS IdCenCost,CCosto,F.IdSubCos AS IdSubCent,SubCosto,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio
,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,DiasEntraga,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac
,CargoContac,F.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,pVehiculo,KmtVehic,CdConductor,TC.RazonSocial AS Conductor
,F.CdRuta,Ruta,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,AutzaMora,AutzaCupo,VrReteCREE,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,TarifaRtc,CodTarRtc,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom
,F.Anulado AS FacAnulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,TimeSys,F.FecUpdate AS Fec_Update,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_Facturas AS F  INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON F.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos 
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY F.IdCia,F.Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRelTraDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasRelTraDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT F.TipDoc AS TipoFact,F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,F.Fecha,FE.Prefijo,FE.NumFace,F.IdConcepto AS CdConcepto,C.Concepto AS ConcDescrip,IdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia
,A.CodAgencia AS Cod_Agencia,FechaVence,VrSubTotal,F.VrDescuento AS VrDcto,F.VrImpuesto AS VrIva,F.VrRetencion AS VrRetFte,F.VrReteICA AS VrRetIca,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal
,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,BaseImp,BaseRet,BaseIca,BaseRiv,F.TarifaIva AS TarifIva,F.TarifaRet AS TarifRet,F.TarifaIca AS TarifIca,TarifaRiv,PesoTotal,UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,F.VrImpCons AS VrAutoICA,F.ZonaFrontera AS EstAutoICA
,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio
,DE.Departamento AS DptoEnvio,DiasEntraga,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,CargoContac
,F.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,NitEmpTrans,EmpTrans,CdConductor,TC.RazonSocial AS Conductor
,F.CdRuta,Ruta,TipPed,Pedido,IdCiaPed,AutzaMora,AutzaCupo,VrReteCREE,TarifaRtc,CodTarRtc,F.ImpAviTab,F.TarifaAvta,F.CodTarifAvta,F.VrBomberil,F.TarifaBom,F.CodTarifBom,F.VrAutRetIat,F.VrAutRetBom,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom
,F.Anulado AS FacAnulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,TimeSys,F.FecUpdate AS Fec_Update,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--detalles
,Item,TipoReg,FechaFact,D.TipRem AS TipRemesa,D.Remesa AS NumRemesa,D.IdCiaRem AS CdCiaRem,ItemRem,FecRemesa,Descripcion,D.Cantidad AS Cant,VrUnitario,VrCosto,UndTarifa,UndCosto,Unidades,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,Volumen,UndVol,Cases,Cajas,Palets,CantPago
,D.TarifaIva AS DetTarifIva,D.VrImpuesto AS DetVrIva,TarifaDct,D.VrDescuento AS DetVrDcto,D.TarifaRet AS DetTarifRet,D.VrRetencion AS DetVrRetFte,D.TarifaIca AS DetTarifIca,D.VrReteIca AS DetVrRetIca,D.VrAutRetIca AS DetAutoICA,VrFaltante,D.VrTray_Vacio1,D.VrTray_Vacio2
,D.Remision AS DetNumRemsion,DocCliente,Referencia1,Referencia2,Referencia3,CdMercancia,DescripMcia,CdConcepto,CF.Concepto AS DetConcepto
,CdCCosto,CCosto,D.CdSubCos AS CdSubCentro,SubCosto,NitTercero,NT.RazonSocial AS DetTercero,CdAgencia,D.pVehiculo AS PlacaVeh,TipoAfiVehic,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.Anulado AS DetAnulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CantidadFalt,UnidadFalt,NumPedRem,CiaPedRem,VrDeclMcia,TarifaSeg,VrSeguroRem,NitAsegurad
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_Facturas AS F  INNER JOIN  Trn_TraFacRemesas AS D ON F.TipDoc=D.TipDoc  AND F.Factura=D.Factura  AND F.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN  Localidades AS LE ON F.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN Mercancias AS MC ON D.CdMercancia=MC.IdMercancia LEFT JOIN  ConcDiversos AS CF ON D.CdConcepto=CF.IdConcepto
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY F.IdCia,F.Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFacturasRem]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFacturasRem] @pmRemision INT,@pmIdCiaRem CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT F.Factura AS NumFact,F.IdCia AS CodCia,F.Fecha AS FechaFact,FechaVence,IdCliente,RazonSocial,IdAgencia,Modalidad
,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,K.TarifaIva AS TarifIva,VrIvaSal
,TarifaDct,VrDctoSal,((VrPrecio*Salidas)-VrDctoSal)+VrIvaSal AS SValTotal,VrUnitario,VrCostoSal,K.TarifaRet AS TarifRet,VrReteSal,K.TarifaIca AS TarifIca,VrIcaSal,VrBruto
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,K.IdVend AS CdVend,Comision,Referencia,Unidades
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS  K ON F.Factura=K.Documento AND F.IdCia=K.IdCia
 AND F.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipRem='REM' AND F.Remision=@pmRemision AND F.IdCiaRem=@pmIdCiaRem  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY F.IdCia,F.Factura,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFactVales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFactVales] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumForma,Fecha,HoraServ,IdCliente,RazonSocial,V.IdAgencia AS CdAgencia,Agencia
,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,IdCuenta
,CantPasaj,Usuarios,V.Observacion AS Observ,TipFac,NumFactura,IdCiaFac,FechaFac,Anulado,NumDev,FecDev
,F.nRadica AS NumRadica,IdCiaRad,ItemRad,Factura,F.Item AS Fac_Item
 FROM Trn_FactVales AS F INNER JOIN Trn_Vales AS V ON F.TipRad=V.TipDoc AND F.nRadica=V.nRadica
  AND F.IdCiaRad=V.IdCia AND F.ItemRad=V.Item
 INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia
 WHERE F.TipDoc=@pmTipDoc AND F.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND F.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFaeFmtos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================================
-- Author:	Hedinver
-- Create date(dd/MM/yyyy): 16/09/2021
-- Description:	Imprimir Formato de Factura Electronica desde XML
-- =============================================================
CREATE PROCEDURE [dbo].[paQryFaeFmtos]
AS
BEGIN
	DECLARE @VrDef VARCHAR(1) = '1'
	-- Emcabezado
	SELECT CAST('' AS INT) AS NumFactura, '' AS CiaFactura, '' AS TipFactura, CAST('' AS datetime) AS FechaFactura, CAST('' AS datetime) AS FechaVence, CAST('' AS datetime) AS FecElabora
	,CAST('' AS INT) AS Remision, '' AS CiaRemision,CAST('' AS INT) AS Cotizacion, '' AS Modulo, '' AS Plazo
	,'' AS PlacaVeh, '' AS Usuario, '' AS TipComprobante, CAST('' AS INT)AS NroComprobante,CAST('' AS BIT)AS Devuleto, CAST('' AS INT)AS NroDevolucion,CAST('' AS BIT)AS MultiplesPagos
	,'' AS Observacion,'' FormaPago, '' AS CiaPedido,CAST('' AS INT) AS Pedido
	--Impuestos
	,CAST(@VrDef AS DECIMAL(14,4)) AS VrSubtotal,CAST(@VrDef AS DECIMAL(14,4)) AS baseiva,CAST(@VrDef AS DECIMAL(14,4)) AS VrIva, CAST(@VrDef AS DECIMAL(14,4))AS VrDescuento, CAST(@VrDef AS DECIMAL(14,4))AS VrAutRetICA
	,CAST(@VrDef AS DECIMAL(14,4))AS VrAutRetFte, CAST(@VrDef AS DECIMAL(14,4))AS VrOtrosImpuestos, CAST(@VrDef AS DECIMAL(14,4))AS VrOtros, CAST(@VrDef AS DECIMAL(14,4))AS OtrosPAgos
	,CAST(@VrDef AS DECIMAL(14,4))AS VrNeto, CAST(@VrDef AS DECIMAL(14,4))AS VrReteIva, CAST(@VrDef AS DECIMAL(14,4))AS VrRetecree, CAST(@VrDef AS DECIMAL(14,4))AS VrFletes
	,CAST(@VrDef AS DECIMAL(14,4))AS TarRetecree, CAST(@VrDef AS DECIMAL(14,4))AS OtrosDescuentos,CAST(@VrDef AS DECIMAL(14,4)) AS tarifaica,  CAST(@VrDef AS DECIMAL(14,4)) AS baseica
	,CAST(@VrDef AS DECIMAL(14,4)) AS valorica,CAST(@VrDef AS DECIMAL(14,4)) AS tarifaretef,  CAST(@VrDef AS DECIMAL(14,4)) AS baseretef, CAST(@VrDef AS DECIMAL(14,4)) AS valorretef
	--Datos FAE	
	,CAST('' AS image) AS CUFE_QR,CAST('' AS INT) AS NumFace,'' AS CUFE, CAST(@VrDef AS DECIMAL(14,4)) AS Resolucion, '' AS RangoNum, '' AS FecVigencia,'' AS PrefijoFace,CAST('' AS datetime) AS FechaValida
	--Datos Cliente
	,'' AS idcliente,'' AS dvcli, '' AS codidenfiscli, '' AS razonsocialcli, ''  AS direccioncli, '' AS telcli, '' AS celularcli,'' AS codlocalidad, '' AS localidad, '' AS codreg,'' AS regimen
	,'' AS NomVendedor, '' AS NitVendedor,'' AS NomAgencia, '' AS AgeDireccion, '' AS AgeTelefono,'' AS AgeCodCiudad,'' AS AgeCiudad,'' AS AgeEmail
	--Detalle
    ,CAST('' AS INT) AS Item,'' AS CodProducto,CAST(@VrDef AS DECIMAL(14,4)) AS CantSalida,'' AS NombreProducto,'' AS NombreProducto1,CAST(@VrDef AS BIT) AS Escombo,CAST(@VrDef AS DECIMAL(14,4)) IvaDetCombo, '' AS Unidad, '' AS CodigoFE/*, '' Tamano*/
	,CAST(@VrDef AS DECIMAL(14,4)) AS VrUnitario,CAST(@VrDef AS DECIMAL(14,4)) AS VrSubtotalItem,CAST(@VrDef AS DECIMAL(14,4)) AS PorcentajeIvaDetalle,CAST(@VrDef AS DECIMAL(14,4)) AS BaseIvaDetalle,CAST(@VrDef AS DECIMAL(14,4)) AS VrIvaDetalle
	,CAST(@VrDef AS DECIMAL(14,4)) PorcentajeDcto,CAST(@VrDef AS DECIMAL(14,4)) AS BaseDcto,CAST(@VrDef AS DECIMAL(14,4)) AS DesctoSalidas,CAST(@VrDef AS DECIMAL(14,4)) AS PorcetajeICO
	,CAST(@VrDef AS DECIMAL(14,4)) AS BaseICO, CAST(@VrDef AS DECIMAL(14,4)) AS VrImpConsumo,/*CAST(@VrDef AS DECIMAL(14,4)) AS PorcetajeSobtsa,CAST(@VrDef AS DECIMAL(14,4)) AS VrSobretasa
	,CAST(@VrDef AS DECIMAL(14,4)) AS PorcetajeImpGlobal,CAST(@VrDef AS DECIMAL(14,4)) AS VrImpGlobal,CAST(@VrDef AS DECIMAL(14,4)) AS PorcetajeImpCarbono,CAST(@VrDef AS DECIMAL(14,4)) AS VrImpCarbono
	,CAST(@VrDef AS DECIMAL(14,4)) AS PorRetDet,*/CAST(@VrDef AS DECIMAL(14,4)) AS ValorRetDet,/*CAST(@VrDef AS DECIMAL(14,4)) BaseIvp,CAST(@VrDef AS DECIMAL(14,4)) TarifaIvp,CAST(@VrDef AS DECIMAL(14,4)) IvaIngProd
	--Detalle de Transporte
	,CAST('' AS INT) AS ItemRem, CAST('' AS INT) AS Remesa, '' AS CiaRemesa, CAST('' AS INT) AS LineaRem,CAST('' AS datetime) AS FechaRem,'' AS NombreProductoT,CAST(@VrDef AS DECIMAL(14,4)) AS Volumen
	,CAST(@VrDef AS DECIMAL(14,4)) AS Peso,*/'' AS Referencia,'' AS Referencia2,'' AS Referencia3,/*CAST(@VrDef AS DECIMAL(14,4)) AS TarifaCobro, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaPago,'' AS CiuDestino,'' AS CiuOrigen
	,'' IdCiuOrigen,CAST('' AS INT) AS Manifiesto,'' AS CiaMuc,CAST('' AS INT) AS OrdenPago,CAST('' AS INT) AS OrdCargue, '' AS CiaOrdCargue,'' AS Vehiculo,'' AS ConceptoFact,'' AS CdConFac
	,'' AS ConFacServ,'' IDCCosto, '' CC_Descrp, '' AS Unidades, '' Conductor, '' TipoVehiculo,*/CAST(@VrDef AS DECIMAL(14,4)) VrDolar, CAST('' AS datetime) FecDolar
END
GO
/****** Object:  StoredProcedure [dbo].[paQryFcCausacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFcCausacion] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumDoc,IdCia,Fecha,FecCausac,IdConcepto,VrNeto,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FcCausacion
 WHERE TipDoc=@pmTipDoc AND NumDoc=@pmNumDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFcCausacionFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFcCausacionFmt] @pmTipDoc VARCHAR(3),@pmNumDocIni INT,@pmNumDocFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  NumDoc,C.IdCia AS CdCia,Compania,C.Fecha AS FecDoc,FecCausac,C.IdConcepto AS CdConcepto,Concepto,VrNeto,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,OrigenAdd,C.TimeSys AS FechaCrea,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,TipDoc
--DETALLES
,F.IdVehiculo AS PlacaVeh,NumVeh,nSemana,TipoSem,F.Fecha AS FecSemana,FecVence,VrCargo,VrOtros,VrPagado,TipRec,Recibo,IdCiaRec,FechaPago,FecSemIni,FecSemFin
--datos del vehículo
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,Modelo,IdPropietario,T.RazonSocial AS Propietario
,IdPoseedor,P.RazonSocial AS Poseedor,IdConductor,CD.RazonSocial AS Conductor,TipoAfil,FecIngreso,V.FechaAdd AS VehFecCrea,V.Inactivo AS VehInactivo
 FROM Trn_FcCausacion AS C INNER JOIN Trn_FcSemanas AS F ON C.NumDoc=F.NumCargue AND C.IdCia=F.CiaCargue
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Vehiculos AS V ON F.IdVehiculo=V.IdVehiculo
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN Terceros AS T ON V.IdPropietario=T.IdTercero INNER JOIN Terceros AS P ON V.IdPoseedor=P.IdTercero
 INNER JOIN Terceros AS CD ON V.IdConductor=CD.IdTercero
 WHERE C.TipDoc=@pmTipDoc AND C.NumDoc BETWEEN @pmNumDocIni AND @pmNumDocFin AND  C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFcNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFcNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdVehiculo,IdPropietario,IdConductor,VehPropio,VrNota,VrNeto,VrAplicado,CdCCosto,CdSubCos
,Referencia,TipRec,ReciboFc,IdCiaRec,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FcNotas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFcNotasFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFcNotasFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  NumNota,N.IdCia AS CdCia,Compania,N.Fecha AS FecNota,N.IdConcepto AS CdConcepto,Concepto,N.IdVehiculo AS PlacaVeh,NumVeh,N.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,N.IdConductor AS CedConductor,CDT.RazonSocial AS Conductor
,VehPropio,VrNota,VrNeto,VrAplicado,CdCCosto,CCosto,CdSubCos,SubCosto,Referencia,N.TipRec AS TipRecFc,ReciboFc,IdCiaRec,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,FecDev,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,IdCiaCrea,N.IdUsuario AS CdUsuario,Usuario,TipDoc
--datos detalle
,Item,nSemana,VrAbono,A.Descripcion AS DetallePago
--datos del vehículo
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,Modelo,TipoAfil,FecIngreso,V.Inactivo AS VehInactivo
--tablas
 FROM Trn_FcNotas AS N INNER JOIN Companias AS CI ON N.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
  INNER JOIN  Conceptos AS CN ON N.IdConcepto=CN.IdConcepto  INNER JOIN Terceros AS T ON N.IdPropietario=T.IdTercero
  INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
  INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo 
  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  LEFT JOIN Terceros AS CDT ON N.IdConductor=CDT.IdTercero LEFT JOIN CentroCosto AS CC ON N.CdCCosto=CC.IdCCosto
  LEFT JOIN  SubCentros AS SC ON N.CdSubCos=SC.IdSubCos LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom
  LEFT JOIN Trn_FcAbonos AS A ON N.TipDoc=A.TipRec  AND N.NumNota=A.Recibo AND N.IdCia=A.IdCia
  WHERE N.TipDoc=@pmTipDoc AND N.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
  ORDER BY NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryFcNotasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFcNotasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
 AS 
 SELECT TipDoc,NumNota,N.IdCia AS CdCia,Compania,N.Fecha AS FecNota,N.IdConcepto AS CdConcepto,Concepto,N.IdVehiculo AS PlacaVeh,NumVeh,N.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,N.IdConductor AS CedConductor,CDT.RazonSocial AS Conductor
,VehPropio,VrNota,VrNeto,VrAplicado,CdCCosto,CCosto,CdSubCos,SubCosto,Referencia,N.TipRec AS TipRecFc,ReciboFc,IdCiaRec,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,FecDev,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,IdCiaCrea,N.IdUsuario AS CdUsuario,Usuario
--datos del vehículo
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,Modelo,TipoAfil,FecIngreso,V.Inactivo AS VehInactivo
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
--tablas
 FROM Trn_FcNotas AS N INNER JOIN Companias AS CI ON N.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
  INNER JOIN  Conceptos AS CN ON N.IdConcepto=CN.IdConcepto  INNER JOIN Terceros AS T ON N.IdPropietario=T.IdTercero
  INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
  INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo 
  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
  LEFT JOIN Terceros AS CDT ON N.IdConductor=CDT.IdTercero LEFT JOIN CentroCosto AS CC ON N.CdCCosto=CC.IdCCosto
  LEFT JOIN  SubCentros AS SC ON N.CdSubCos=SC.IdSubCos LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom
  WHERE N.TipDoc=@pmTipDoc AND N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND N.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND N.IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 ORDER BY N.IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryFcSemanas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFcSemanas] @pmIdVehiculo VARCHAR(10),@pmnSemana INT
 AS 
 SELECT IdVehiculo,nSemana,NumCargue,CiaCargue,TipoSem,Fecha,FecVence,VrCargo,VrOtros,VrPagado,TipRec,Recibo,IdCiaRec
,FechaPago,Observacion,FecSemIni,FecSemFin,TimeSys,IdUsuario
 FROM Trn_FcSemanas
 WHERE IdVehiculo=@pmIdVehiculo AND nSemana=@pmnSemana
GO
/****** Object:  StoredProcedure [dbo].[paQryFcSemanasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFcSemanasLta] @pmIdVehiculo VARCHAR(10)=Null,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT F.IdVehiculo AS PlacaVeh,NumVeh,nSemana,NumCargue,CiaCargue,TipoSem,Fecha,FecVence,VrCargo,VrOtros,VrPagado
,TipRec,Recibo,IdCiaRec,FechaPago,FecSemIni,FecSemFin,F.Observacion AS Observ,TimeSys,F.IdUsuario AS CdUsuario,Usuario
--datos del vehículo
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,Modelo,IdPropietario,T.RazonSocial AS Propietario
,IdPoseedor,P.RazonSocial AS Poseedor,IdConductor,CD.RazonSocial AS Conductor,TipoAfil,FecIngreso,V.FechaAdd AS FechaCrea,V.Inactivo AS VehInactivo
 FROM Trn_FcSemanas AS F INNER JOIN Vehiculos AS V ON F.IdVehiculo=V.IdVehiculo
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN Terceros AS T ON V.IdPropietario=T.IdTercero INNER JOIN Terceros AS P ON V.IdPoseedor=P.IdTercero
 INNER JOIN Terceros AS CD ON V.IdConductor=CD.IdTercero
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 WHERE F.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY F.IdVehiculo,nSemana
GO
/****** Object:  StoredProcedure [dbo].[paQryFields]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFields] @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20)=Null
 AS 
 SELECT IdEntidad,IdCampo,Descripcion,TipoDato,LongMax,Requerido,PmryKey,FmtValue,DftValue,AliasFld,AliasQry2,IndField
,TipoEntidad,LstTipo,LstClnaValor,LstClnaLista,LstQuery,Inactivo
 FROM Sys_Fields
 WHERE IdEntidad=@pmIdEntidad AND IdCampo LIKE ISNULL(@pmIdCampo,'%')
 ORDER BY IndField
GO
/****** Object:  StoredProcedure [dbo].[paQryFieldsLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFieldsLta] @pmIdEntidad VARCHAR(30),@pmTipoEntidad VARCHAR(5)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdEntidad,IdCampo,Descripcion,TipoDato,LongMax,Requerido,PmryKey,FmtValue,DftValue,AliasFld,AliasQry2,IndField
,TipoEntidad,LstTipo,LstClnaValor,LstClnaLista,LstQuery,Inactivo
 FROM Sys_Fields
 WHERE IdEntidad=@pmIdEntidad AND TipoEntidad LIKE ISNULL(@pmTipoEntidad,'%') 
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IndField
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos] @pmIdCargo VARCHAR(4)
 AS 
 SELECT IdCargo,Concepto,Obligatorio,TipoAplica,DiasSemana,DiasMes,ValorMensual,ValorDiario
,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,NCuotas,DiasVcmto,OrdenAbono,TipoDcto,DctoPpago,VrCargoAdic
,FecLimiteIni,FecLimiteFin,Inactivo,CdTarifaIva,CdTarifaRet,CdCuentaIva,CdCuentaRet,CdCuentaIca,CodFEDian,IvaIncluido,FechaAdd,FechaUpdate,IdUsuario
 FROM Fijos
 WHERE IdCargo=@pmIdCargo
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Cla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_Cla] @pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdCargo,IdClase,ValorMensual,ValorDiario
 FROM Fijos_Cla
 WHERE IdCargo=@pmIdCargo AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_ClaDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_ClaDso] @pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 SELECT C.IdCargo AS CdCargo,Concepto,IdClase,Descripcion,C.ValorMensual AS ValorMes,C.ValorDiario AS ValorDia
 FROM Fijos_Cla AS C  INNER JOIN Fijos AS F ON C.IdCargo=F.IdCargo
 INNER JOIN TarifBuses AS TB ON C.IdClase=TB.IdTarifa
 WHERE C.IdCargo=@pmIdCargo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_ClaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_ClaLta] @pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 SELECT C.IdCargo AS CdCargo,Concepto,IdClase,Descripcion,C.ValorMensual AS ValorMes,C.ValorDiario AS ValorDia
 FROM Fijos_Cla AS C  INNER JOIN Fijos AS F ON C.IdCargo=F.IdCargo
 INNER JOIN TarifBuses AS TB ON C.IdClase=TB.IdTarifa
 WHERE C.IdCargo like ISNULL(@pmIdCargo,'%') AND IdClase like isnull(@pmIdClase,'%')
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_ClaTar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFijos_ClaTar] @pmIdCargo VARCHAR(4)
 AS 
 SELECT IdCargo,IdClase,Descripcion,ValorMensual,ValorDiario
 FROM Fijos_Cla AS C INNER JOIN TarifBuses AS TB ON C.IdClase=TB.IdTarifa
 WHERE IdCargo=@pmIdCargo
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Cue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_Cue] @pmIdCargo VARCHAR(4),@pmIdAdmon VARCHAR(4)
 AS 
 SELECT IdCargo,IdAdmon,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,IdCuentaIva,IdCuentaRet,IdCuentaIca
 FROM Fijos_Cue
 WHERE IdCargo=@pmIdCargo AND IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Cue_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryFijos_Cue_Cr] @pmIdCargo VARCHAR(4)=Null, @pmIdAdmon VARCHAR(4)=Null,@pmInactivo BIT=Null
AS
 SELECT  FC.IdAdmon AS IdAdmn,TipoAdmon, FC.IdCuentaDeb AS IdCuentDeb,P.NomCuenta AS NomCueDb, FC.IdCuentaCre AS IdCuentCre,PC.NomCuenta AS NomCueCr, FC.IdCueDebVp AS IdCueDbVp,FC.IdCueCreVp AS IdCueCrVp
,FC.IdCargo AS CodCargo,Concepto ,TipoAplica,DiasSemana,DiasMes, ValorMensual, ValorDiario,F.Inactivo AS Fij_Inactivo
,FC.IdCuentaIva,PV.NomCuenta AS NomCueIVA,FC.IdCuentaRet,PR.NomCuenta AS NomCueRet,FC.IdCuentaIca
,F.FechaAdd AS FecAdd, F.FechaUpdate AS FecUpdate, F.IdUsuario AS IdUsuari,Usuario
 FROM Fijos_Cue AS FC INNER JOIN TiposAdm AS TA ON FC.IdAdmon=TA.IdAdmon
 INNER JOIN Fijos AS F ON FC. IdCargo=F.IdCargo  
 INNER JOIN Puc AS P ON FC.IdCuentaDeb=P.IdCuenta INNER JOIN Puc AS PC ON  FC.IdCuentaCre=PC.IdCuenta
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 LEFT JOIN Puc AS PV ON FC.IdCuentaIva=PV.IdCuenta LEFT JOIN Puc AS PR ON FC.IdCuentaRet=PR.IdCuenta
  WHERE FC.IdCargo like ISNULL(@pmIdCargo,'%')  AND FC.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 AND (F.Inactivo=ISNULL(@pmInactivo,0) or F.Inactivo=ISNULL(@pmInactivo,1))
ORDER BY FC.IdAdmon,FC.IdCargo
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_CueDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_CueDso] @pmIdCargo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS 
 SELECT FC.IdAdmon AS IdAdmn,TipoAdmon, FC.IdCuentaDeb AS IdCuentDeb, FC.IdCuentaCre AS IdCuentCre, FC.IdCueDebVp AS IdCueDbVp
, FC.IdCueCreVp AS IdCueCrVp,FC.IdCargo AS CodCargo,Concepto,IdCuentaIva,IdCuentaRet,IdCuentaIca 
 FROM Fijos_Cue AS FC INNER JOIN TiposAdm AS TA ON FC.IdAdmon=TA.IdAdmon
  INNER JOIN Fijos AS F ON FC. IdCargo=F.IdCargo
 WHERE FC.IdCargo like ISNULL(@pmIdCargo,'%') AND FC.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY FC.IdAdmon,FC.IdCargo
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_Veh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_Veh] @pmIdCargo VARCHAR(4),@pmIdVehiculo VARCHAR(10)
 AS 
 SELECT IdCargo,IdVehiculo,ValorMensual,ValorDiario,Excluir
 FROM Fijos_Veh
 WHERE IdCargo=@pmIdCargo AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_VehDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_VehDso] @pmIdCargo VARCHAR(4),@pmIdVehiculo VARCHAR(10)
 AS 
 SELECT C.IdCargo AS IdCon,Concepto,IdVehiculo,C.ValorMensual AS ValorMes,C.ValorDiario AS ValorDia,Excluir
 FROM Fijos_Veh AS C INNER JOIN Fijos AS F ON C.IdCargo=F.IdCargo
 WHERE C.IdCargo=@pmIdCargo AND IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryFijos_VehLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijos_VehLta] @pmIdCargo VARCHAR(4),@pmIdVehiculo VARCHAR(10)
AS
  SELECT  F.IdCargo AS IdCon,Concepto,F.IdVehiculo AS PlacaVeh,NumVeh,F.ValorDiario AS ValorDia,F.ValorMensual AS ValorMes, Excluir
  FROM  Fijos_Veh AS F INNER JOIN Fijos ON F.IdCargo=Fijos.IdCargo
  INNER JOIN Vehiculos AS V ON F.IdVehiculo=V.IdVehiculo
  WHERE  F.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND F.IdVehiculo LIKE ISNULL(@pmIdVehiculo ,'%')
  ORDER BY Concepto,F.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryFijosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijosDso]
AS
  SELECT     IdCargo, Concepto,Concepto +  '  ' + IdCargo AS DsCar  FROM  Fijos WHERE Inactivo=0 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryFijosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFijosLta]  @pmInactivo BIT=Null
AS
  SELECT  IdCargo, Concepto,Obligatorio,TipoAplica,DiasSemana, DiasMes, ValorMensual, ValorDiario
,IdCuentaDeb, IdCuentaCre, IdCueDebVp, IdCueCreVp,NCuotas,DiasVcmto,OrdenAbono,TipoDcto,DctoPpago,VrCargoAdic
,FecLimiteIni,FecLimiteFin,CdTarifaIva,IvaIncluido,CdTarifaRet,CdCuentaIva,CdCuentaRet,CdCuentaIca,CodFEDian,Inactivo,FechaAdd, FechaUpdate, IdUsuario
 FROM Fijos 
 WHERE  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdCargo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosExto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAbonosExto] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2),@pmFecCorte SMALLDATETIME
 AS 
 SELECT TipRec,Recibo,A.IdCia AS CdCia,A.Item AS ItemRec,FecPago,A.Fecha AS FechaRec,A.TipDoc AS Tip_Doc,A.IdPrestamo AS NumPtmo,IdCiaPre,ItemPre
,TotalAbono,VrBaseCms,A.Detalle AS DetallePago,TipoAplica
--Datos de la cuota
,NumCuota,Concepto,C.Fecha AS FechaCausa,FechaVence,VrTotal,VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,TipoCuota
,NumCausacion,IdCiaCau,C.Detalle AS DetalleCuota,FecUltPago,FecLiqMora,C.FechaCrea AS Fecha_Crea
 FROM  Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE A.TipDoc=@pmTipDoc AND A.FecPago BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinAbonosFmt] @pmTipRec VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2) 
 AS 
 SELECT TipRec,Recibo,A.IdCia AS CdCia,Compania,A.Item AS ItemRec,A.Fecha AS FechaRec,A.TipDoc AS Tip_Doc,A.IdPrestamo AS NumPtmo,IdCiaPre,ItemPre
,TotalAbono,VrBaseCms,A.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,A.IdAgencia AS CdAgencia,NomAgencia AS Agencia,A.IdVend AS CdVend,V.RazonSocial AS NomVendedor,Comision
,CantGal, A.Detalle AS DetallePago,TipoAplica,FecPago,TimeSys,TipoDoc
--Datos de la cuota
,NumCuota,Concepto,C.Fecha AS FechaCausa,FechaVence,VrTotal,VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,TipoCuota
,NumCausacion,IdCiaCau,C.Detalle AS DetalleCuota,FecUltPago,FecLiqMora,C.FechaCrea AS Fecha_Crea
 FROM  Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON A.IdVend=V.IdTercero 
 LEFT JOIN TercCliePrestamo AS CLI ON  A.IdCliente=CLI.IdClie AND A.IdAgencia=CLI.IdAgencia
 LEFT JOIN Sys_TiposDoc AS TD ON A.TipRec=TD.IdDoc
 WHERE A.TipRec=@pmTipRec AND A.Recibo BETWEEN @pmReciboIni AND  @pmReciboFin AND A.IdCia=@pmIdCia
 ORDER BY A.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosRca]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAbonosRca] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=NULL
,@pmIdCliente VARCHAR(16)=Null
AS 
SELECT RA.IdCliente AS NitClie,T.RazonSocial AS NomCliente,RA.IdAgencia AS CdAgencia,NomAgencia AS Agencia,RA.TipDoc AS TipPre,RA.IdPrestamo AS NumPrestamo
,IdCiaPre,CP.Compania AS NomCiaPre,ItemPre,NumCuota,C.Fecha AS FecEmision,FechaVence,Concepto,C.VrTotal AS VrCuota,VrAbonado
--datos del pago
,TipRec,Recibo,RA.IdCia AS CdCia,CI.Compania AS NomCiaAbono,RA.Item AS ItemPago,RA.Fecha AS FecRecibo,FecPago,TotalAbono,RA.Detalle AS DescPago,TipoAplica
,RA.IdVend AS CedVend,VN.RazonSocial AS Vendedor,Comision,DTF_EA,TasaNom,Spread_TA,TasaEfe,TipoCuota,C.TipoCausac AS TipCausac,NumCausacion,IdCiaCau,C.Detalle AS DescCuota
,CodLinCred,LinCredito,NumFactura,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,CLI.IdGrupo AS CdGrupo,GrupoClie
,VrPrestamo,P.VrCuota AS VrCuoPrest,NPlazos,Causacion,TipoCredito,P.TipoCausac AS Tipo_Causac,NumCredito,P.IdVend AS PreCedVend,VND.RazonSocial AS PreVendedor,P.Observacion AS Observ
FROM Trn_FinAbonos AS RA INNER JOIN Trn_FinCuotas AS C ON RA.TipDoc=C.TipDoc AND RA.IdPrestamo=C.IdPrestamo AND RA.IdCiaPre=C.IdCia AND RA.ItemPre=C.Item
INNER JOIN Companias AS CI ON RA.IdCia=CI.IdCia INNER JOIN Terceros AS T ON RA.IdCliente=T.IdTercero
INNER JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero INNER JOIN Companias AS CP ON RA.IdCiaPre=CP.IdCia 
LEFT JOIN LineasCred AS L ON C.CodLinCred=L.IdLinea
LEFT JOIN TercCliePrestamo AS CLI ON RA.IdCliente=CLI.IdClie AND RA.IdAgencia=CLI.IdAgencia
LEFT JOIN TiposTerc AS TC ON CLI.IdTipoTerc=TC.IdTipoTerc LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
LEFT JOIN Trn_FinPrestamo AS P ON RA.TipDoc=P.TipDoc AND RA.IdPrestamo=P.IdPrestamo AND RA.IdCiaPre=P.IdCia
LEFT JOIN Terceros AS VND ON P.IdVend=VND.IdTercero
WHERE RA.FecPago BETWEEN @pmFechaIni AND @pmFechaFin AND RA.IdCia LIKE ISNULL(@pmIdCia,'%%')
AND RA.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAbonosRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAbonosRes] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)
 AS 
 SELECT A.TipRec,TR.TipoDoc AS TipoDocRec,A.Recibo,A.IdCia,CI.Compania,A.Item AS ItemRec,A.Fecha AS FechaRec,A.FecPago
,A.TipDoc,TD.TipoDoc,A.IdPrestamo AS NumDoc,A.IdCiaPre,CD.Compania AS NomCiaDoc,A.ItemPre,A.TotalAbono,A.Detalle AS DetallePago
,A.IdCliente,T.RazonSocial AS NomCliente,A.IdAgencia,CL.NomAgencia,A.IdVend,VN.RazonSocial AS Vendedor,A.VrBaseCms,A.Comision,A.TipoAplica
,C.FechaVence,C.NumCuota,C.Concepto,C.CodLinCred
 FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia  INNER JOIN Companias AS CD ON A.IdCiaPre=CD.IdCia
 INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc INNER JOIN Sys_TiposDoc AS TR ON A.TipRec=TR.IdDoc
 INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero
 LEFT JOIN TercCliePrestamo AS CL ON A.IdCliente=CL.IdClie AND A.IdAgencia=CL.IdAgencia
 LEFT JOIN Terceros AS VN ON A.IdVend=VN.IdTercero 
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCiaPre=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAfavor]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAfavor] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,VrAFavor,VrOtrosDb,VrAbono,IdCliente,IdAgencia,IdVend,CodLinCred,Concepto
 FROM Trn_FinAfavor
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAlmacenes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAlmacenes] @pmIdAlmacen VARCHAR(4)
 AS 
 IF @pmIdAlmacen IS NULL
  SELECT IdAlmacen,Almacen
  FROM FinAlmacenes
 WHERE Inactivo=0
 ORDER BY IdAlmacen
 ELSE
  SELECT IdAlmacen,Almacen,Inactivo
  FROM FinAlmacenes
  WHERE IdAlmacen=@pmIdAlmacen
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAportes] @pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipLiq,NumLiquida,IdCia,Fecha,FecLiquida,CodCia,CodGrupo,CodTipoTerc,ValorTotal,BaseApo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,Anulado,NumDev,FecDev,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_FinAportes
 WHERE TipLiq=@pmTipLiq AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinAportesFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinAportesFmt] @pmTipLiq VARCHAR(3),@pmNumLiquidaIni INT,@pmNumLiquidaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT L.TipLiq,L.NumLiquida,L.IdCia,CI.Compania,L.Fecha,L.FecLiquida,L.CodCia,L.CodGrupo,GrupoClie,L.CodTipoTerc,TipoTercero,L.ValorTotal,L.BaseApo
,L.TipCom,TipoCom,L.Comprobante,L.IdCiaCom,L.Observacion,L.IdEstado,ED.Estado,L.Anulado,L.NumDev,L.FecDev,L.FechaCrea,L.IdCiaCrea,L.OrigenAdd,L.IdUsuario,Usuario
,D.Item,D.FecVence,D.IdCliente,T.RazonSocial AS NomCliente,D.IdAgencia,NomAgencia,D.BaseAporte,D.TarifaApo,D.VrAporte,D.CdTarifApo,D.Descripcion
,D.FecUltPago,D.FecUltLiq,D.DctoNom,D.CodConcNom,D.PeriodoNom
 FROM Trn_FinAportes AS L INNER JOIN Trn_FinAportesDet AS D ON L.TipLiq=D.TipLiq AND L.NumLiquida=D.NumLiquida AND L.IdCia=D.IdCia
 INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON L.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON L.IdCia=CI.IdCia INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero 
 INNER JOIN TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 LEFT JOIN TiposCom AS TC ON L.TipCom=TC.IdCom
 LEFT JOIN GruposCli AS GC ON L.CodGrupo=GC.IdGrupo LEFT JOIN TiposTerc AS TT ON L.CodTipoTerc=TT.IdTipoTerc
 WHERE L.TipLiq=@pmTipLiq AND L.NumLiquida BETWEEN @pmNumLiquidaIni AND @pmNumLiquidaFin AND L.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCanAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinCanAportes] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdCliente,IdAgencia,ValorTotal,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,FecDev,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_FinCanAportes
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCanAportesFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinCanAportesFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc,C.NumNota,C.IdCia,Compania,C.Fecha,C.IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia,NomAgencia,C.ValorTotal,C.TipCom,TipoCom,C.Comprobante,C.IdCiaCom
,C.Observacion,C.Anulado,C.FecDev,C.FechaCrea,C.IdCiaCrea,C.OrigenAdd,C.IdUsuario,Usuario
--ABONOS
,A.Item AS ItemRec,A.Fecha AS FechaRec,A.TipDoc AS TipDocApo,A.IdPrestamo AS NumAporte,A.IdCiaPre AS IdCiaApo,A.ItemPre
,A.TotalAbono,A.VrBaseCms,A.IdVend AS CdVend,V.RazonSocial AS NomVendedor,A.Comision,A.CantGal,A.Detalle AS DetallePago,A.TipoAplica,A.FecPago
,CU.NumCuota,CU.Concepto,CU.Fecha AS FechaLiq,CU.FechaVence,CU.VrTotal,CU.VrAbonado,CU.TipoTasa,CU.DTF_EA,CU.TasaNom,CU.Spread_TA,CU.TasaEfe,CU.TipoCuota
,CU.Detalle AS DetalleCuota,CU.FecUltPago,CU.FecLiqMora
 FROM Trn_FinCanAportes AS C INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero 
 INNER JOIN TercCliePrestamo AS CLI ON C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 INNER JOIN Trn_FinAbonos AS A ON C.TipDoc=A.TipRec AND C.NumNota=A.Recibo AND C.IdCia=A.IdCia
 INNER JOIN Trn_FinCuotas AS CU ON A.TipDoc=CU.TipDoc AND A.IdPrestamo=CU.IdPrestamo AND A.IdCiaPre=CU.IdCia AND A.ItemPre=CU.Item
 INNER JOIN Terceros AS V ON A.IdVend=V.IdTercero 
 LEFT JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 WHERE C.TipDoc=@pmTipDoc AND C.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCauMoraFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paQryFinCauMoraFmt] @pmTipoProc VARCHAR(3),@pmNumProcIni INT,@pmNumProcFin INT,@pmIdCia CHAR(2)
AS
 SELECT  CM.NumProc AS NumCausac,CM.IdCia AS CdCia,Compania,Fecha,Item,TipDoc, IdPrestamo, IdCiaPre, ItemPre,NCuotaLiq, IdCliente,T.RazonSocial AS NomCliente,CM.IdAgencia AS CdAgencia,NomAgencia AS Agencia
,CM.IdVend AS CdVend,V.RazonSocial AS NomVendedor,FecVence,VrTotal, VrAbonado, FecUltLiq,FecIniLiq, FecFinLiq, DiasLiquida, CM.DiasGracia AS Dias_Gracia
, BaseLiquida, TasaEA, TasaEM, TasaDia, VrLiquida, TarifaIva, VrIvaInt,TarifaRet,VrRetFte, NumNotaDb, NumComp,C.Observacion AS Observ,CdLinCred,C.Anulado AS Anuldo,C.IdUsuario AS CdUsuario,Usuario,TipoCred
 FROM  Trn_FinCauMora  AS CM INNER JOIN Trn_FinCausacion AS C ON CM.TipoProc=C.TipoProc AND CM.NumProc=C.NumProc  AND CM.IdCia=C.IdCia
 INNER JOIN Companias AS CI ON CM.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON  C.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS T ON CM.IdCliente=T.IdTercero   INNER JOIN Terceros AS V ON CM.IdVend=V.IdTercero
 LEFT JOIN TercCliePrestamo AS CLI ON CM.IdCliente=CLI.IdClie AND CM.IdAgencia=CLI.IdAgencia
 WHERE CM.TipoProc=@pmTipoProc  AND  CM.NumProc BETWEEN @pmNumProcIni AND @pmNumProcFin AND CM.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCausacionFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCausacionFmt] @pmTipoProc VARCHAR(3),@pmNumProcIni INT,@pmNumProcFin INT,@pmIdCia CHAR(2) 
 AS 
 SELECT  NumProc,FC.IdCia AS CdCia,Compania,FC.Fecha AS FecCausac,FC.TipCom AS TipComp,FC.Comprobante AS NumComp,FC.Anulado AS Anuldo
 ,FC.Observacion AS CauObserv,TipoLiquida,C.TipDoc AS Tip_Doc,C.IdPrestamo AS NumPstmo,Item,NumCuota,FechaVence
,VrTotal,VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,C.IdCliente AS NitCliente,RazonSocial,C.IdAgencia AS  CdAgencia,NomAgencia AS Agencia
,TipoCuota,Concepto,Detalle,FecUltPago,FecLiqMora,C.FechaCrea AS CuoFecCrea,EdoCausac,FC.TimeSys AS CauFechaCrea,FC.IdUsuario AS CdUsuario,Usuario
--datos del prestamo
,FecPrestamo,FecCorte,NPlazos,Causacion,VrPrestamo,NumCredito,P.Observacion AS Observ,TipoCred
 FROM  Trn_FinCausacion AS FC INNER JOIN Trn_FinCuotas AS C ON FC.TipoProc=C.TipoCausac AND FC.NumProc=C.NumCausacion AND FC.IdCia=C.IdCiaCau
 INNER JOIN Companias AS CI ON FC.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON FC.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero   
 INNER JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc AND C.IdPrestamo=P.IdPrestamo AND C.IdCia=P.IdCia
 LEFT JOIN TercCliePrestamo AS CLI ON  C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 WHERE TipoProc=@pmTipoProc AND  NumProc BETWEEN @pmNumProcIni AND  @pmNumProcFin AND FC.IdCia=@pmIdCia
 AND C.TipDoc='PR1'
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCiAportesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCiAportesLta] @pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT A.Item,A.IdCliente,T.RazonSocial AS NomCliente,A.IdAgencia,CL.NomAgencia,A.ValorTotal,A.FecInicio,A.FecFinal,A.CantCuotas
 ,A.Descripcion,A.FechaCrea,A.IdCiaCrea,Compania,A.IdUsuario,Usuario,[Id]
 FROM Trn_FinCiAportes AS A INNER JOIN TercCliePrestamo AS CL ON A.IdCliente=CL.IdClie AND A.IdAgencia=CL.IdAgencia
 INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero INNER JOIN Companias AS CI ON A.IdCiaCrea=CI.IdCia
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 WHERE (A.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL) AND CL.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryFinClieSaldosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinClieSaldosLta] @pmIdClie VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS
 SELECT  F.IdClie AS NitClie,RazonSocial,CdAgencia,NomAgencia AS  Agencia,F.IdCia AS CdCia,Compania,F.VrSaldo AS SaldoActual
 FROM  FinClieSaldos AS F INNER JOIN  Terceros AS T ON F.IdClie=T.IdTercero
 INNER JOIN TercCliePrestamo AS CLI ON F.IdClie=CLI.IdClie AND F.CdAgencia=CLI.IdAgencia
 INNER JOIN Companias AS CI ON F.IdCia=CI.IdCia
  WHERE F.IdClie LIKE ISNULL(@pmIdClie,'%') AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY RazonSocial,F.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinConcFacturaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinConcFacturaLta] @pmTipoConc VARCHAR(10)=Null
 AS 
 SELECT IdConcepto,Concepto,TipoConc,Gravado,CodTarIva,TIV.Tarifa AS TarifIva,CodTarRet,TR.Tarifa AS TarifRet,CodTarIca,TIC.Tarifa AS TarifIca
,C.IdCuenta AS CdCuenta,NomCuenta,CdCueIva,CdCueRet,CdCueIca,CodFEDian,C.Inactivo AS Inactvo,C.FechaAdd AS FechaCrea,C.FechaUpdate AS FechaAct,C.IdUsuario AS CdUsuario,Usuario
 FROM FinConcFactura AS C INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 LEFT JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 LEFT JOIN Tablapor AS TIV ON C.CodTarIva=TIV.IdTarifa  LEFT JOIN Tablapor AS TR ON C.CodTarRet=TR.IdTarifa
 LEFT JOIN Tablapor AS TIC ON C.CodTarIca=TIC.IdTarifa
 WHERE TipoConc LIKE ISNULL(@pmTipoConc,'%')
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryFinConvenios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinConvenios] @pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipLiq,NumLiquida,IdCia,Fecha,IdConcepto,IdProveedor,NumFactura,FecFactura,FecVence,ValorTotal,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,NumDev,FecDev,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_FinConvenios
 WHERE TipLiq=@pmTipLiq AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinConveniosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinConveniosFmt] @pmTipLiq VARCHAR(3),@pmNumLiquidaIni INT,@pmNumLiquidaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipLiq,C.NumLiquida,C.IdCia,Compania,C.Fecha,C.IdConcepto,CN.Concepto,C.IdProveedor,T.RazonSocial,C.NumFactura,C.FecFactura,C.FecVence,C.ValorTotal
,C.TipCom,TipoCom,C.Comprobante,C.IdCiaCom,C.Observacion,C.Anulado,C.NumDev,C.FecDev,C.FechaCrea,C.IdCiaCrea,C.OrigenAdd,C.IdUsuario,Usuario
,CU.Item,CU.Fecha AS FecEmision,CU.FechaVence,CU.VrTotal,CU.VrAbonado,CU.IdCliente,TC.RazonSocial AS NomCliente,CU.IdAgencia AS CodAgencia,CL.NomAgencia,CU.Detalle,CU.FecUltPago,CU.NumFactura AS CodCuenta
 FROM Trn_FinConvenios AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero  
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Trn_FinCuotas AS CU ON C.TipLiq=CU.TipDoc AND C.NumLiquida=CU.IdPrestamo AND C.IdCia=CU.IdCia
 INNER JOIN Terceros AS TC ON CU.IdCliente=TC.IdTercero
 LEFT JOIN TercCliePrestamo AS CL ON CU.IdCliente=CL.IdClie AND CU.IdAgencia=CL.IdAgencia
 LEFT JOIN TiposCom AS TCO ON C.TipCom=TCO.IdCom
 WHERE C.TipLiq=@pmTipLiq AND C.NumLiquida BETWEEN @pmNumLiquidaIni AND @pmNumLiquidaFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinCuotas] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2) 
 AS 
 SELECT TipDoc,IdPrestamo,IdCia,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe
,IdCliente,IdAgencia,TipoCuota,Concepto,TipoCausac,NumCausacion,IdCiaCau,Detalle,FecUltPago,FecLiqMora,FechaCrea,CodLinCred,NumFactura
,VrInteresFact,DiasLiquida,FecUltCausac,VrAcumCapital,Convenio,NitConvenio,NumPreMora,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt
,TarifIvaInt,VrIvaInt,TarifRetInt,VrRetInt
 FROM Trn_FinCuotas
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasAbo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasAbo] @pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT C.TipDoc AS CdTipDoc,C.IdPrestamo AS NumDcmto,C.IdCia AS CdCia,CI.Compania AS NomCiaDoc,C.Item AS ItemDcmto,NumCuota,C.Fecha AS FecEmision,FechaVence
,Concepto,VrTotal,VrAbonado,VrTotal-VrAbonado AS VrSaldo,C.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,NomAgencia AS Agencia
,C.Detalle AS DetalleCuota,TipoCuota,C.TipoCausac AS TipoCau,NumCausacion,IdCiaCau,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,FecUltCausac,DiasLiquida,NumFactura,VrInteresFact,VrAcumCapital
,CodLinCred,LinCredito,Convenio,NitConvenio,NumPreMora,FecUltPago,FecLiqMora,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt,C.FechaCrea AS Fecha_Crea
--Datos del prestamo
,FecPrestamo,VrPrestamo,VrSeguro,VrCuota,NPlazos,Causacion,P.NContrato AS NumContrato,CdCiaCon,NActaJunta,NumCredito,P.IdVend AS CdAsesor,VN.RazonSocial AS Asesor
,TipoCredito,P.TipoCausac AS PreTipoCausac,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora,P.Observacion AS Observ
,P.Anulado AS PreAnulado,P.IdEstado AS CdEstado
--datos de pagos
,TipRec,Recibo,A.IdCia AS CdCiaAbo,CA.Compania AS NomCiaAbono,A.Item AS ItemAbo,A.Fecha AS FecAbono,A.FecPago AS Fec_Pago,TotalAbono,A.Detalle AS DetalleAbono,TipoAplica
,A.IdVend AS NitVend,VNC.RazonSocial AS NomVendedor,VrBaseCms,Comision,OrigenRc 
--Datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,Comentarios
,TipoSalario,MaxDcto,VrSalBasico
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinCuotas AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliePrestamo AS CLI ON C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN LineasCred AS LC ON C.CodLinCred=LC.IdLinea
 LEFT JOIN Trn_FinAbonos AS A ON C.TipDoc=A.TipDoc AND C.IdPrestamo=A.IdPrestamo AND C.IdCia=A.IdCiaPre AND C.Item=A.ItemPre
 LEFT JOIN Terceros AS VNC ON A.IdVend=VNC.IdTercero LEFT JOIN Companias AS CA ON A.IdCia=CA.IdCia
 LEFT JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc AND C.IdPrestamo=P.IdPrestamo AND C.IdCia=P.IdCia
 LEFT JOIN Terceros AS VN ON P.IdVend=VN.IdTercero 
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN (SELECT R.TipDoc AS RecTipo,R.Recibo AS RecNumero,R.IdCia AS RecCia,R.OrigenAdd AS OrigenRc FROM Trn_FinRecibos AS R 
 UNION ALL SELECT D.TipDev,D.Devolucion,D.IdCia,RC.OrigenAdd FROM Trn_FinDevRec AS D INNER JOIN Trn_FinRecibos AS RC ON D.TipDoc=RC.TipDoc AND D.Recibo=RC.Recibo AND D.IdCiaDoc=RC.IdCia)
 AS RCJ ON A.TipRec=RCJ.RecTipo AND A.Recibo=RCJ.RecNumero AND A.IdCia=RCJ.RecCia
 WHERE C.TipDoc LIKE ISNULL(@pmTipDoc,'%')   AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasExto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasExto] @pmFechaIni SMALLDATETIME,@pmFecCorte SMALLDATETIME
 AS 
 SELECT TipDoc,IdPrestamo,C.IdCia AS CdCia,Compania,Item,NumCuota,Fecha,FechaVence,DATEDIFF(day,FechaVence,@pmFecCorte) AS DiasMora,VrTotal,VrAbonado
,IdCliente,RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,NomAgencia AS Agencia,Concepto,Detalle,TipoCuota,NumFactura,NumCausacion,IdCiaCau,FecUltCausac
,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,DiasLiquida,VrAcumCapital,Convenio,NitConvenio,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt
,FecUltPago,FecLiqMora
 FROM Trn_FinCuotas AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN TercCliePrestamo AS CLI ON  C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 WHERE Fecha<@pmFechaIni AND VrTotal>VrAbonado
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasFmt] @pmTipDoc VARCHAR(3),@pmIdPrestamoIni INT,@pmIdPrestamoFin INT,@pmIdCia CHAR(2) 
 AS 
 SELECT TipDoc, IdPrestamo,C.IdCia AS CdCia,Compania,Item,NumCuota,Fecha,FechaVence,VrTotal,VrAbonado
,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,IdCliente,RazonSocial,C.IdAgencia AS  CdAgencia,NomAgencia AS Agencia,TipoCuota,Concepto
,TipoCausac,NumCausacion,IdCiaCau,Detalle,FecUltPago,FecLiqMora,C.FechaCrea AS Fecha_crea,CodLinCred,NumFactura
,VrInteresFact,DiasLiquida,FecUltCausac,VrAcumCapital,TipDoc,Convenio,NitConvenio,NumPreMora,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt
,TarifIvaInt,VrIvaInt,TarifRetInt,VrRetInt
 FROM Trn_FinCuotas AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero  
 LEFT JOIN TercCliePrestamo AS CLI ON  C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 WHERE TipDoc=@pmTipDoc AND IdPrestamo BETWEEN @pmIdPrestamoIni AND  @pmIdPrestamoFin AND C.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasInt] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT F.TipDoc AS TipoPrest,F.IdPrestamo AS NumPrest,F.IdCia AS CdCia,Compania,Item,NumCuota,F.Fecha AS FecCausac,FechaVence,VrTotal,VrAbonado
,TipoTasa,F.DTF_EA AS TasasDTFea,TasaNom,F.Spread_TA AS TasaPuntos,TasaEfe,F.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS  CdAgencia,NomAgencia AS Agencia
,TipoCuota,F.Concepto AS ConcepCuota,F.TipoCausac AS TipoDocCau,NumCausacion,IdCiaCau,Detalle,FecUltPago,FecLiqMora,NumFactura,DiasLiquida,FecUltCausac,VrAcumCapital,Convenio,NitConvenio
,NumPreMora,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt
--datos del prestamo
,NumCredito,P.Fecha AS FecRadica,FecPrestamo,FecCorte,VrPrestamo,VrSeguro,VrCuota,NPlazos,TipoPlazo,Causacion,P.IdLinea AS CdLinea,LinCredito,TipoCredito,P.TipoCausac AS Tipo_Causac,P.IdTasa AS CdTasa,DescTasa
,AcumCapital,AcumIntereses,VrPrestamo-AcumCapital AS SaldoCapital,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas
,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,P.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,P.Anulado AS PreAnulado,P.Observacion AS Observ
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad
,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinCuotas AS F INNER JOIN Companias AS CI ON F.IdCia=CI.IdCia  INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero 
 INNER JOIN TercCliePrestamo AS CLI ON  F.IdCliente=CLI.IdClie AND F.IdAgencia=CLI.IdAgencia  
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Trn_FinPrestamo AS P ON F.TipDoc=P.TipDoc AND F.IdPrestamo=P.IdPrestamo AND  F.IdCia=P.IdCia
 LEFT JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea 
 LEFT JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa LEFT JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  F.Concepto IN ('INTERESES','INTMORA')
 AND  F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasLta] @pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT C.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,NomAgencia AS Agencia,C.TipDoc AS CdTipDoc,TipoDoc,C.IdPrestamo AS NumDcmto,C.IdCia AS CdCia,Compania
,Item,VrTotal,VrAbonado,VrTotal-VrAbonado AS ValorSaldo,C.Fecha AS FechaEmision,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
,Concepto,NumCuota,Detalle,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,TipoCuota,C.TipoCausac AS TipoCau,NumCausacion,IdCiaCau,FecUltPago,FecLiqMora,C.FechaCrea AS Fecha_Crea,CodLinCred
,NumFactura,VrInteresFact,DiasLiquida,FecUltCausac,VrAcumCapital,Convenio,NitConvenio,NumPreMora,FacturaInt,TipFacInt,NumFacInt,CdCiaFacInt,FechaFacInt,TarifIvaInt,VrIvaInt,TarifRetInt,VrRetInt
--Datos del prestamo
,FecPrestamo,VrPrestamo,NPlazos,Causacion,P.NContrato AS NumContrato,CdCiaCon,NActaJunta,NumCredito,ISNULL(P.IdVend,CLI.IdVend) AS CdVend,ISNULL(VN.RazonSocial,VNC.RazonSocial) AS Vendedor,P.IdLinea AS CdLinea,LinCredito
--Datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,Comentarios
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinCuotas AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliePrestamo AS CLI ON  C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Terceros AS VNC ON CLI.IdVend=VNC.IdTercero
 INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc  
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Trn_FinPrestamo AS P ON C.TipDoc=P.TipDoc AND C.IdPrestamo=P.IdPrestamo AND C.IdCia=P.IdCia
 LEFT JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 WHERE  (VrTotal-VrAbonado)>@pmSaldo AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasRac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasRac] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmAnnoAnt INT,@pmMesAnt INT,@pmIdCia CHAR(2)
 AS 
SELECT C.IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia,CL.NomAgencia,C.TipoReg,C.TipDoc,TD.TipoDoc,C.IdPrestamo,C.IdCia,CI.Compania,C.Item,C.NumCuota,C.Fecha,C.FechaVence
,C.Concepto,C.Detalle,C.CodLinCred,LC.LinCredito,C.VrTotal,C.VrAbono,C.TotalAbonado,C.VrOtros
,C.TipDocRef,C.NumDocRef,C.IdCiaRef,C.ItemDocRef,C.IdVend,VN.RazonSocial AS Vendedor,C.TipoAplica,C.FechaCrea
,CASE WHEN C.Concepto='APORTES' THEN [dbo].[FuncAcuPrestamosLinA](@pmAnnoAnt,@pmMesAnt,Null,C.IdCliente,C.IdAgencia,Null,C.Concepto) ELSE [dbo].[FuncAcuPrestamosLin](@pmAnnoAnt,@pmMesAnt,Null,C.IdCliente,C.IdAgencia,C.CodLinCred,C.Concepto) END AS SaldoAnt
,CASE WHEN C.Concepto='APORTES' THEN [dbo].[FuncAcuPrestamosLinA](@pmAnnoAnt,@pmMesAnt,C.IdCia,C.IdCliente,C.IdAgencia,Null,C.Concepto) ELSE [dbo].[FuncAcuPrestamosLin](@pmAnnoAnt,@pmMesAnt,C.IdCia,C.IdCliente,C.IdAgencia,C.CodLinCred,C.Concepto) END AS SaldoAntCia
,CASE WHEN C.Concepto='APORTES' THEN [dbo].[FuncAcuPrestamosLinA](@pmAnnoAnt,@pmMesAnt,Null,C.IdCliente,C.IdAgencia,C.CodLinCred,C.Concepto) ELSE [dbo].[FuncAcuPrestamosLin](@pmAnnoAnt,@pmMesAnt,Null,C.IdCliente,C.IdAgencia,C.CodLinCred,Null) END AS SaldoAntLinea
,CASE WHEN C.Concepto='APORTES' THEN [dbo].[FuncAcuPrestamosLinA](@pmAnnoAnt,@pmMesAnt,C.IdCia,C.IdCliente,C.IdAgencia,C.CodLinCred,C.Concepto) ELSE [dbo].[FuncAcuPrestamosLin](@pmAnnoAnt,@pmMesAnt,C.IdCia,C.IdCliente,C.IdAgencia,C.CodLinCred,Null) END AS SaldoAntLinCia
,CASE WHEN C.Concepto='APORTES' THEN [dbo].[FuncAcuPrestamosLinA](@pmAnnoAnt,@pmMesAnt,Null,C.IdCliente,C.IdAgencia,Null,C.Concepto) ELSE [dbo].[FuncAcuPrestamosLin](@pmAnnoAnt,@pmMesAnt,Null,C.IdCliente,C.IdAgencia,Null,Null) END AS SaldoAntClie
,CASE WHEN C.Concepto='APORTES' THEN [dbo].[FuncAcuPrestamosLinA](@pmAnnoAnt,@pmMesAnt,C.IdCia,C.IdCliente,C.IdAgencia,Null,C.Concepto) ELSE [dbo].[FuncAcuPrestamosLin](@pmAnnoAnt,@pmMesAnt,C.IdCia,C.IdCliente,C.IdAgencia,Null,Null) END AS SaldoAntClieCia
--datos de terceros
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono,T.TelMovil,T.e_mail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,CL.IdGrupo AS CdGrupoCli,GrupoClie,CL.IdTipoTerc AS CdTipoTerc,TipoTercero
--SUBCONSULTA DE TABLAS UNIDAS
FROM (SELECT C.IdCliente,C.IdAgencia,1 AS TipoReg,C.TipDoc,C.IdPrestamo,C.IdCia,C.Item,NumCuota,C.Fecha,C.FechaVence,C.Concepto,C.Detalle,C.CodLinCred
,C.VrTotal,C.VrAbonado*0 AS VrAbono,C.VrAbonado AS TotalAbonado,C.VrAcumCapital*0 AS VrOtros,C.TipoCausac AS TipDocRef,C.NumCausacion AS NumDocRef,C.IdCiaCau AS IdCiaRef,C.NumCuota AS ItemDocRef
,CL.IdVend,C.TipoCuota AS TipoAplica,C.FechaCrea
FROM Trn_FinCuotas AS C LEFT JOIN TercCliePrestamo AS CL ON C.IdCliente=CL.IdClie AND C.IdAgencia=CL.IdAgencia
WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (C.IdCia=@pmIdCia OR @pmIdCia IS NULL) 
UNION ALL
SELECT A.IdCliente,A.IdAgencia,2,A.TipRec,A.Recibo,A.IdCia,A.Item,C.NumCuota,A.Fecha,A.FecPago,C.Concepto,A.Detalle,C.CodLinCred
,0,A.TotalAbono,C.VrAbonado,0,A.TipDoc,A.IdPrestamo,A.IdCiaPre,A.ItemPre,A.IdVend,A.TipoAplica,A.TimeSys
FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL)  
AND A.TipRec<>'RC2' AND A.TipRec<>'OD2'
UNION ALL
SELECT A.IdCliente,A.IdAgencia,2,A.TipRec,A.Recibo,A.IdCia,A.Item,C.NumCuota,A.Fecha,A.FecPago,C.Concepto,A.Detalle,C.CodLinCred
,0,A.TotalAbono,C.VrAbonado,CASE WHEN R.VrPagosMas>0 THEN ISNULL(DC.VrOtrosApo,0) ELSE 0 END 
,A.TipDoc,A.IdPrestamo,A.IdCiaPre,A.ItemPre,A.IdVend,A.TipoAplica,A.TimeSys
FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
INNER JOIN Trn_FinRecibos AS R ON A.TipRec=R.TipDoc AND A.Recibo=R.Recibo AND A.IdCia=R.IdCia
LEFT JOIN (SELECT TipDoc,Documento,IdCia,SUM(Valor) AS VrOtrosApo FROM Trn_DetCuentas WHERE TipDoc='RC2' AND Concepto='OTR'
AND CodConc='_APO' GROUP BY TipDoc,Documento,IdCia) AS DC ON A.TipRec=DC.TipDoc AND A.Recibo=DC.Documento AND A.IdCia=DC.IdCia
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND A.TipRec='RC2'
UNION ALL
SELECT A.IdCliente,A.IdAgencia,2,A.TipRec,A.Recibo,A.IdCia,A.Item,C.NumCuota,A.Fecha,A.FecPago,C.Concepto,A.Detalle,C.CodLinCred
,0,A.TotalAbono,C.VrAbonado,CASE WHEN D.VrPagosMas>0 THEN ISNULL(DC.VrOtrosApo,0)*-1 ELSE 0 END 
,A.TipDoc,A.IdPrestamo,A.IdCiaPre,A.ItemPre,A.IdVend,A.TipoAplica,A.TimeSys
FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
INNER JOIN Trn_FinDevRec AS D ON A.TipRec=D.TipDev AND A.Recibo=D.Devolucion AND A.IdCia=D.IdCia
INNER JOIN Trn_FinRecibos AS R ON D.TipDoc=R.TipDoc AND D.Recibo=R.Recibo AND D.IdCiaDoc=R.IdCia
LEFT JOIN (SELECT TipDoc,Documento,IdCia,SUM(Valor) AS VrOtrosApo FROM Trn_DetCuentas WHERE TipDoc='RC2' AND Concepto='OTR'
AND CodConc='_APO' GROUP BY TipDoc,Documento,IdCia) AS DC ON D.TipDoc=DC.TipDoc AND D.Recibo=DC.Documento AND D.IdCiaDoc=DC.IdCia
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND A.TipRec='OD2'
UNION ALL
SELECT A.IdCliente,A.IdAgencia,2,A.TipDoc,A.Recibo,A.IdCia,0,0,A.Fecha,R.FecPago
,A.Concepto,'SALDOS A FAVOR',A.CodLinCred,0,(A.VrAFavor-A.VrOtrosDb)-A.VrAbono,A.VrAbono,0
,R.TipDcm,R.Documento,R.IdCiaDcm,0,A.IdVend,1,R.TimeSys
FROM Trn_FinAfavor AS A LEFT JOIN (SELECT TipDoc,Recibo,IdCia,Fecha,FecPago,TipDcm,Documento,IdCiaDcm,TimeSys FROM Trn_FinRecibos
WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
UNION ALL
SELECT TipDoc,NumNota,IdCia,Fecha,Fecha,TipDcm,Documento,IdCiaDcm,TimeSys FROM Trn_FinNotas WHERE TipDoc='NC2'
AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin) AS R ON A.TipDoc=R.TipDoc AND A.Recibo=R.Recibo AND A.IdCia=R.IdCia
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (A.VrAFavor-A.VrOtrosDb)>A.VrAbono
UNION ALL
SELECT A.IdCliente,A.IdAgencia,0,'SIA',A.Id,A.IdCiaCrea,A.Item,A.CantCuotas,A.FecInicio,A.FecFinal,'APORTES',A.Descripcion,'0'
,A.ValorTotal,A.ValorTotal,A.ValorTotal,0,'SIA',0,'00',0,CL.IdVend,0,A.FechaCrea
FROM Trn_FinCiAportes AS A LEFT JOIN TercCliePrestamo AS CL ON A.IdCliente=CL.IdClie AND A.IdAgencia=CL.IdAgencia 
WHERE A.FecFinal BETWEEN @pmFechaIni AND @pmFechaFin
AND (A.IdCiaCrea=@pmIdCia OR @pmIdCia IS NULL) 
) AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN TercCliePrestamo AS CL ON C.IdCliente=CL.IdClie AND C.IdAgencia=CL.IdAgencia
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CL.IdTipoTerc=TTC.IdTipoTerc
LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc LEFT JOIN LineasCred AS LC ON C.CodLinCred=LC.IdLinea
LEFT JOIN Terceros AS VN ON C.IdVend=VN.IdTercero
--FIN SUBCONSULTA 
-- UNION CON SALDOS ANTERIORES -NO REGISTRADO
UNION ALL

SELECT S.IdCliente,T.RazonSocial,S.IdAgencia,CL.NomAgencia,-1,'SA','SALDO ANTERIOR',0,S.IdCia,CI.Compania,0,0,@pmFechaIni,@pmFechaIni
,S.Concepto,'SALDO ANTERIOR',S.IdLinea,LC.LinCredito,0,0,0,0,'SA',0,'00',0,CL.IdVend,VN.RazonSocial,-1,@pmFechaIni
,CASE WHEN S.Concepto='APORTES' THEN (S.SaAportes+S.Recibos+S.OtrosAbonos)-(S.DevRecibos+S.DevAportes) ELSE S.SaldoAnt+S.TotalCargos-S.TotalAbonos END
,0,0,0,0,0
--datos de terceros
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono,T.TelMovil,T.e_mail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,CL.IdGrupo AS CdGrupoCli,GrupoClie,CL.IdTipoTerc AS CdTipoTerc,TipoTercero
FROM AcuPrestamosLin AS S INNER JOIN Companias AS CI ON S.IdCia=CI.IdCia INNER JOIN Terceros AS T ON S.IdCliente=T.IdTercero 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN TercCliePrestamo AS CL ON S.IdCliente=CL.IdClie AND S.IdAgencia=CL.IdAgencia
LEFT JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo LEFT JOIN TiposTerc AS TTC ON CL.IdTipoTerc=TTC.IdTipoTerc
LEFT JOIN LineasCred AS LC ON S.IdLinea=LC.IdLinea LEFT JOIN Terceros AS VN ON CL.IdVend=VN.IdTercero
WHERE S.nAnno=@pmAnnoAnt AND S.nMes=@pmMesAnt AND (S.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND NOT EXISTS (SELECT * FROM (SELECT IdCliente,IdAgencia,TipDoc,IdPrestamo,IdCia,Concepto,CodLinCred FROM Trn_FinCuotas
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (IdCia=@pmIdCia OR @pmIdCia IS NULL) 
 UNION ALL
 SELECT A.IdCliente,A.IdAgencia,A.TipRec,A.Recibo,A.IdCia,C.Concepto,C.CodLinCred
 FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL)  
 UNION ALL
 SELECT A.IdCliente,A.IdAgencia,A.TipDoc,A.Recibo,A.IdCia,A.Concepto,A.CodLinCred
 FROM Trn_FinAfavor AS A 
 WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND (A.VrAFavor-A.VrOtrosDb)>A.VrAbono) AS RC 
 WHERE RC.IdCliente=S.IdCliente AND RC.IdAgencia=S.IdAgencia AND RC.IdCia=S.IdCia AND RC.Concepto=S.Concepto AND RC.CodLinCred=S.IdLinea)
 AND (CASE WHEN S.Concepto='APORTES' THEN (S.SaAportes+S.Recibos+S.OtrosAbonos)-(S.DevRecibos+S.DevAportes) ELSE S.SaldoAnt+S.TotalCargos-S.TotalAbonos END)<>0
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasRmc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasRmc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)
 AS 
SELECT C.IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia,CL.NomAgencia,C.TipDoc,TD.TipoDoc,C.IdPrestamo,C.IdCia,CI.Compania,C.Item,C.Fecha,C.FechaVence
,C.Concepto,C.Detalle,C.VrTotal,C.VrAbonado AS TotalAbonado,C.NumCuota
,A.TipRec,TR.TipoDoc AS TipoRecibo,A.Recibo,A.IdCia AS CdCiaRec,CR.Compania AS NomCiaRecibo,A.Fecha AS FecRecibo,A.FecPago,A.TotalAbono AS VrAbono,A.Detalle AS DetalleAbono
--Datos tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono,T.TelMovil,T.e_mail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,CL.IdGrupo AS CdGrupoCli,GrupoClie,CL.IdTipoTerc AS CdTipoTerc,TipoTercero
FROM Trn_FinCuotas AS C LEFT JOIN Trn_FinAbonos AS A ON C.TipDoc=A.TipDoc AND C.IdPrestamo=A.IdPrestamo AND C.IdCia=A.IdCiaPre AND C.Item=A.ItemPre
INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN TercCliePrestamo AS CL ON C.IdCliente=CL.IdClie AND C.IdAgencia=CL.IdAgencia
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CL.IdTipoTerc=TTC.IdTipoTerc
LEFT JOIN Sys_TiposDoc AS TR ON A.TipRec=TR.IdDoc LEFT JOIN Companias AS CR ON A.IdCia=CR.IdCia
WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (C.IdCia=@pmIdCia OR @pmIdCia IS NULL) 
UNION ALL
SELECT A.IdCliente,T.RazonSocial,A.IdAgencia,CL.NomAgencia,'SIA','SALDO INICIAL DE APORTES',A.Id,A.IdCiaCrea,CI.Compania,A.Item,A.FecInicio,A.FecFinal
,'APORTES',A.Descripcion,A.ValorTotal,A.ValorTotal,A.CantCuotas
,'SIA','ABONOS SALDOS INICIALES',A.Id,A.IdCiaCrea,CI.Compania,A.FecInicio,A.FecFinal,A.ValorTotal,'SALDOS INCINIALES DE APORTES'
--Datos del tercero
,T.TipoId,T.Dv,T.Direccion,T.IdLocal,L.Localidad,L.IdDep,D.Departamento,T.Telefono,T.TelMovil,T.e_mail,T.IdSector,SectorEco,T.IdRegimen,Regimen,CL.IdGrupo,GrupoClie,CL.IdTipoTerc,TipoTercero
FROM Trn_FinCiAportes AS A INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero INNER JOIN Companias AS CI ON A.IdCiaCrea=CI.IdCia
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN TercCliePrestamo AS CL ON A.IdCliente=CL.IdClie AND A.IdAgencia=CL.IdAgencia
INNER JOIN GruposCli AS GC ON CL.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CL.IdTipoTerc=TTC.IdTipoTerc
WHERE A.FecFinal BETWEEN @pmFechaIni AND @pmFechaFin
AND (A.IdCiaCrea=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryFinCuotasSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinCuotasSal] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2) 
 AS 
 SELECT C.TipDoc AS TipPre,C.IdPrestamo AS NumPrest,C.IdCia AS CdCia,C.Item AS Item_Pre,VrTotal,VrAbonado,ISNULL(TotalAbo,0) AS TotAbonado
 FROM Trn_FinCuotas AS C LEFT JOIN (SELECT TipDoc,IdPrestamo,IdCiaPre,ItemPre,SUM(TotalAbono) AS TotalAbo
 FROM Trn_FinAbonos WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCiaPre=@pmIdCia
 GROUP BY TipDoc,IdPrestamo,IdCiaPre,ItemPre) AS A ON C.TipDoc=A.TipDoc  AND C.IdPrestamo=A.IdPrestamo
 AND C.IdCia=A.IdCiaPre AND C.Item=A.ItemPre
 WHERE C.TipDoc=@pmTipDoc AND C.IdPrestamo=@pmIdPrestamo AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinDevFac] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto
,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,IdVend,IdLocal,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion
,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinDevFac
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevFacCr] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia
,NomAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,D.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,D.IdLocal AS CdLocal
,LD.Localidad AS CiudadFact,ModdDev,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca
,D.TimeSys,D.FecUpdate,D.IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,TipDev
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad
,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
 FROM Trn_FinDevFac AS D INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado  INNER JOIN Localidades AS LD ON D.IdLocal=LD.IdLocal 
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 WHERE  D.TipDev=@pmTipDev  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY D.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevFacDoc] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,ModdDev
 FROM Trn_FinDevFac
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura  AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevFacFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,C.Concepto AS DevConcepto,D.TipDoc AS TipoFact,D.Factura AS NumFact,IdCiaDoc,FecDoc
,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia,NomAgencia,VrSubTotal,VrDescuento,VrImpuesto
,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,D.VrNeto,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,D.IdLocal AS CdLocal,CF.Localidad AS NomCiudad
,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,TipDev
,Item,FD.IdConcepto AS CdConc,FD.Concepto AS DescConcepto,TipoReg,Cantidad,VrUnitario,VrTotal,TarifDcto,VrDcto,TarifIva,VrIva,TarifRet,VrRetfte,TarifIca,VrRetica
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia
,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
 FROM Trn_FinDevFac AS D  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
 INNER JOIN Localidades AS CF ON D.IdLocal=CF.IdLocal 
 INNER JOIN  TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 INNER JOIN Trn_FinFactDet AS FD ON D.TipDoc=FD.TipDoc  AND D.Factura=FD.Factura  AND D.IdCiaDoc=FD.IdCia
 LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND  @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevFacLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevFacLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia
,NomAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,D.TarifaArf,D.VrAutRetFte,D.TarifaAri,D.VrAutRetIca,D.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,D.IdLocal AS CdLocal
,Localidad,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,TipDev
 FROM  Trn_FinDevFac AS D INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON D.IdLocal=L.IdLocal 
 INNER JOIN  TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 WHERE  D.TipDev=@pmTipDev  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY D.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinDevPre] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,IdPrestamo,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrPrestamo,IdVend,CxPagar,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinDevPre
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevPreCr] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipDocPre,D.IdPrestamo AS NumPrestamo,IdCiaDoc,FecDoc,FecPrestamo,FecCorte
,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia,NomAgencia AS Agencia,D.VrPrestamo AS ValorDev,D.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,NumCuotaIni,AcumCapital,AcumCuotas
,NPlazos,TipoPlazo,Causacion,NActaJunta,NumCredito,P.NContrato AS NumContrato,CdCiaCon,D.CxPagar AS Cx_pagar,ModdDev,D.TipCom AS Tip_Comp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp
,DiaCausac ,DiaCausac2,DiasVence,P.IdLinea AS CdLinea,LinCredito,TipoCredito
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.OrigenAdd AS Origen_Crea,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaAct,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
--datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia
,CLI.IdLocalAge  AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinDevPre AS D INNER JOIN Trn_FinPrestamo AS P ON D.TipDoc=P.TipDoc AND  D.IdPrestamo=P.IdPrestamo  AND D.IdCiaDoc=P.IdCia
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom 
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 WHERE TipDev=@pmTipDev   AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY  D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevPreDoc] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,IdPrestamo,IdCiaDoc,FecDoc,IdCliente,ModdDev
 FROM Trn_FinDevPre
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevPreFmt] @pmTipDev VARCHAR(3), @pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipDocPre,D.IdPrestamo AS NumPrestamo,IdCiaDoc,FecDoc,FecPrestamo,FecCorte
,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia,NomAgencia AS Agencia,D.VrPrestamo AS ValorDev,P.IdTasa AS CdTasa,DescTasa,TI.TipoInteres AS Tipo_Int
,TasaEfectiva,P.IdMora AS CdMora,DescMora,D.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,NPlazos,TipoPlazo,Causacion,P.NContrato AS NumContrato,CdCiaCon,TipoAprob,NActaJunta
,DiaCausac,DiaCausac2,DiasVence,P.IdLinea AS CdLinea,LinCredito
,NumCredito,D.CxPagar AS Cx_pagar,ModdDev,D.TipCom AS Tip_Comp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.OrigenAdd AS Origen_Crea,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaAct,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
--datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia
,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
 FROM  Trn_FinDevPre AS D INNER JOIN Trn_FinPrestamo AS P ON D.TipDoc=P.TipDoc AND  D.IdPrestamo=P.IdPrestamo  AND D.IdCiaDoc=P.IdCia
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN  TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TasasIntmora AS TIM ON P.IdMora=TIM.IdMora LEFT JOIN TiposCom AS TC ON D.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 WHERE D.TipDev=@pmTipDev  AND  Devolucion  BETWEEN @pmDevolucionIni AND @pmDevolucionFin  AND D.IdCia=@pmIdCia
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevPreLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevPreLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipDocPre,D.IdPrestamo AS NumPrestamo,IdCiaDoc,FecDoc,FecPrestamo,FecCorte
,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia,D.VrPrestamo AS ValorDev,D.IdVend AS CdVend,VN.RazonSocial AS NomVendedor
,NPlazos,Causacion,NActaJunta,NumCredito,D.CxPagar AS Cx_pagar,ModdDev,D.TipCom AS Tip_Comp,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.OrigenAdd AS Origen_Crea,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaAct,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_FinDevPre AS D INNER JOIN Trn_FinPrestamo AS P ON D.TipDoc=P.TipDoc AND  D.IdPrestamo=P.IdPrestamo  AND D.IdCiaDoc=P.IdCia
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON D.IdVend=VN.IdTercero
 WHERE TipDev=@pmTipDev   AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY  D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,IdAgencia,VrRecibido,VrSubTotal,VrRetencion
,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,IdVend,TarifaCom,CodTarCom,EnEfectivo
,Referencia,NumAutoriza,ModdDev,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinDevRec
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevRecCr] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,T.RazonSocial AS NomCliente
,D.IdAgencia AS CdAgencia,NomAgencia AS Agencia,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv
,D.IdVend AS CdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,EnEfectivo,D.Referencia AS Refrencia,NumAutoriza,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero
--agencias
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
 FROM Trn_FinDevRec AS D  INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo  AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevRecDoc] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Recibo,IdCiaDoc,FecDoc,IdCliente,ModdDev
 FROM Trn_FinDevRec
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevRecFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT, @pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipRec,Recibo,IdCiaDoc,FecDoc,FecPago
,D.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,D.IdAgencia AS CdAgencia,NomAgencia AS NomAgencia,VrRecibido,VrSubTotal,VrRetencion
,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,D.IdVend AS CdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,EnEfectivo
,D.Referencia AS DevRefrencia,D.NumAutoriza AS NumAutza,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
--datos de forma de pago
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco
,P.NumForma AS PagNumForma,FecForma,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS PagReferencia2
,CdLocal,LF.Localidad AS CiudadPlaza,P.NumAutoriza AS PagAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,Comentarios
--agencias
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM  Trn_FinDevRec AS D  INNER JOIN Trn_Pagos AS P ON D.TipDev=P.TipDoc AND D.Devolucion=P.Documento AND D.IdCia=P.IdCia
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario   INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo AS CLI ON D.IdCliente=CLI.IdClie AND D.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom   LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal 
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE TipDev=@pmTipDev  AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
 ORDER BY Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinDevRecLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinDevRecLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Recibo,IdCiaDoc,FecDoc,FecPago,IdCliente,T.RazonSocial AS NomCliente,IdAgencia
,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv
,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,EnEfectivo,Referencia,NumAutoriza,ModdDev,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
 FROM Trn_FinDevRec AS D  INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Terceros AS V ON D.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND D.IdVend LIKE ISNULL(@pmIdVend,'%') 
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactint]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinFactint] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos
,VrOtrDcto,VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend
,TarifaCom,CodTarCom,IdLocal,MulPlazos,IdPlazo,TipoFactInt,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado
,CodTarRtc,TarifaRtc,TipoFE,FechaFE,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinFactint
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactintCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinFactintCr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT F.Factura,F.IdCia AS CdCia,Compania,F.Fecha,F.IdConcepto AS CdConcepto,Concepto,F.IdCliente AS CdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,NomAgencia,FechaVence,VrSubTotal,VrDescuento
,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv
,F.IdCCosto AS CdCCosto,CCosto,F.IdSubCos AS CdSubCos,SubCosto,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,F.IdLocal AS CdLocalFact,FL.Localidad AS CiudadFact,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto
,TipoFactInt,TipoFE,FechaFE,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado
,F.TimeSys,F.FecUpdate AS FechaAct,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,F.TipDoc
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad
,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia
 FROM Trn_FinFactint AS F INNER JOIN Companias AS CI ON F.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Localidades AS FL ON F.IdLocal=FL.IdLocal 
 INNER JOIN  TercCliePrestamo AS CLI ON F.IdCliente=CLI.IdClie AND F.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos
 LEFT JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo LEFT JOIN TiposCom AS TC ON F.TipCom=TC.IdCom
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc  AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND F.IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactintFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinFactintFmt] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT F.Factura AS NumFactura,F.IdCia AS CdCia,Compania,Fecha,F.IdConcepto AS CdConcepto,C.Concepto AS ConceptoFact,F.IdCliente AS CdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,NomAgencia,FechaVence,VrSubTotal,VrDescuento
,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv
,F.IdCCosto AS CdCCosto,CCosto,F.IdSubCos AS CdSubCos,SubCosto,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,F.IdLocal AS CdLocal,CF.Localidad AS NomCiudad,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto
,TipoFactInt,TipoFE,FechaFE,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,CodTarRtc,TarifaRtc
,F.TimeSys,F.FecUpdate AS FechaAct,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,F.TipDoc AS TipoDoc
--detalles
,Item,FD.IdConcepto AS CdConc,FD.Concepto AS DescConcepto,TipoReg,Cantidad,VrUnitario,VrTotal,TarifDcto,VrDcto,TarifIva,VrIva,TarifRet,VrRetfte,TarifIca,VrRetica
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia
,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia
 FROM Trn_FinFactint AS F INNER JOIN Companias AS CI ON F.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS CF ON F.IdLocal=CF.IdLocal 
 INNER JOIN TercCliePrestamo AS CLI ON F.IdCliente=CLI.IdClie AND F.IdAgencia=CLI.IdAgencia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 INNER JOIN Trn_FinFactDet AS FD ON F.TipDoc=FD.TipDoc  AND F.Factura=FD.Factura  AND F.IdCia=FD.IdCia
 LEFT JOIN TiposCom AS TC ON F.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos
 LEFT JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc  AND  F.Factura  BETWEEN  @pmFacturaIni AND @pmFacturaFin  AND F.IdCia=@pmIdCia
 ORDER BY  F.Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactintLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinFactintLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT F.Factura,F.IdCia AS CdCia,Compania,FE.Prefijo,FE.NumFace,F.Fecha,F.IdCliente AS CdCliente,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,NomAgencia,FechaVence,VrSubTotal,VrDescuento
,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCargos,VrOtrDcto,VrNeto,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,F.IdConcepto AS CdConcepto,Concepto
,F.IdCCosto AS CdCCosto,CCosto,F.IdSubCos AS CdSubCos,SubCosto,F.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,TarifaCom,CodTarCom,F.IdLocal AS CdLocal,Localidad,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto
,TipoFactInt,TipoFE,FechaFE,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,F.Observacion AS Observ,F.IdEstado AS CdEstado,Estado,CodTarRtc,TarifaRtc,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
,F.TimeSys,F.FecUpdate AS FechaAct,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario,F.TipDoc
 FROM Trn_FinFactint AS F INNER JOIN Companias AS CI ON F.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON F.IdLocal=L.IdLocal 
 INNER JOIN  TercCliePrestamo AS CLI ON F.IdCliente=CLI.IdClie AND F.IdAgencia=CLI.IdAgencia
 LEFT JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos
 LEFT JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
 LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
 WHERE F.TipDoc=@pmTipDoc AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND F.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFactSeguroFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinFactSeguroFmt] @pmTipDoc VARCHAR(3), @pmIdPrestamoIni INT,@pmIdPrestamoFin INT,@pmIdCia CHAR(2)
 AS 
SELECT TipDoc,IdPrestamo,IdCia,Item,Fecha,VrSaldoIni,VrPagos,TarifSeguro,VrSeguro
FROM  Trn_FinFactSeguro
WHERE TipDoc=@pmTipDoc  AND IdPrestamo BETWEEN @pmIdPrestamoIni AND @pmIdPrestamoFin  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFacturas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinFacturas] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,IdPrestamo,IdCia,Item,NumFactura,Fecha,FechaVence,VrFactura,VrInteres,DiasLiq,TasaEfeMes,TasaEfeDia,FechaPago
,FechaLiq,FecInicio,FecFinal,VrAbono,ItemPago,Facturado,TipFac,FacturaInt,CdCiaFac,FecFactura,DiasPlazo
 FROM Trn_FinFacturas
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryFinFacturasInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinFacturasInt]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME, @pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT P.TipDoc AS TipPrest,P.IdPrestamo AS NumPrest,P.IdCia AS CdCia,Compania,Item,NumFactura,F.Fecha AS FecCausac,FechaVence,VrFactura,VrInteres,DiasLiq,TasaEfeMes,TasaEfeDia,FechaPago
,FechaLiq,FecInicio,FecFinal,VrAbono,ItemPago,Facturado,TipFac,FacturaInt,CdCiaFac,FecFactura,DiasPlazo
,T.RazonSocial AS NomCliente,IdCliente,NomAgencia AS Agencia,P.IdAgencia AS CdAgencia,NumCredito,P.Fecha AS FecRadica,FecPrestamo,FecCorte
,VrPrestamo,VrSeguro,VrCuota,NPlazos,TipoPlazo,Causacion,P.IdLinea AS CdLinea,LinCredito,TipoCredito,TipoCausac,P.IdTasa AS CdTasa,DescTasa
,AcumCapital,AcumIntereses,VrPrestamo-AcumCapital AS SaldoCapital,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas
,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,P.IdConcepto AS CdConcepto,Concepto,P.Observacion AS Observ
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad
,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM  Trn_FinPrestamo AS P INNER JOIN Trn_FinFacturas AS F ON P.TipDoc=F.TipDoc AND P.IdPrestamo=F.IdPrestamo AND P.IdCia=F.IdCia
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE F.FechaLiq BETWEEN @pmFechaIni AND @pmFechaFin AND P.TipoCredito='FACTURAS'  AND P.Anulado=0
 AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrSancion,VrOtros,VrNeto,VrAplicado,VrAnticipo,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv
,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,FecDcm,CdForma,NumCheque,CdBanco,MulPlazos,IdPlazo,Modalidad,TipCom,Comprobante,IdCiaCom
,Observacion,Anulado,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinNotas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotasCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinNotasCr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT  NumNota,N.IdCia AS CdCia,Compania,Fecha,N.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,N.IdAgencia AS CdAgencia,NomAgencia AS Agencia
,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrSancion,VrOtros,VrNeto,VrAplicado,VrAnticipo,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv
,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,N.IdCCosto AS CdcCosto,CCosto,N.IdSubCos AS CdSubCost,SubCosto,N.IdVend AS CdVend,V.RazonSocial AS Vendedor
,TarifaCom,CodTarCom,N.Referencia AS Refrencia,pVehiculo,CdConductor,CD.RazonSocial AS Conductor,TipDcm,Documento,IdCiaDcm,FecDcm,CdForma,NumCheque
,CdBanco,Banco,MulPlazos,N.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,Modalidad,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ,Anulado
,N.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,N.FecUpdate AS FechaAct,IdCiaCrea,N.IdUsuario AS CdUsuario,Usuario
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,Comentarios
--agencias
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinNotas AS N INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON N.IdCia=CI.IdCia INNER JOIN Terceros AS V ON N.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado  INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN  Plazos AS PZ ON N.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliePrestamo AS CLI ON N.IdCliente=CLI.IdClie AND N.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TiposCom AS TC ON N.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Bancos AS BN ON N.CdBanco=BN.IdBanco LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS CD ON N.CdConductor=CD.IdTercero
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
  AND N.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND N.IdVend LIKE ISNULL(@pmIdVend,'%')
 ORDER BY N.IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotasFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinNotasFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT, @pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  NumNota,N.IdCia AS CdCia,Compania,N.Fecha AS FechaNota,N.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,N.IdAgencia AS CdAgencia,NomAgencia AS NomAgencia
,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrSancion,VrOtros,VrNeto,VrAplicado,VrAnticipo,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv
,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,N.IdCCosto AS CdcCosto,CC.CCosto AS NotCenCosto,N.IdSubCos AS CdSubCost,SC.SubCosto AS NotSubCentro,N.IdVend AS CdVend,V.RazonSocial AS Vendedor
,TarifaCom,CodTarCom,N.Referencia AS NotReferencia,pVehiculo,CdConductor,TipDcm,N.Documento AS NumDcmto,IdCiaDcm,FecDcm,CdForma,N.NumCheque AS NroCheque,CdBanco,BN.Banco AS NomBanco,MulPlazos
,N.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,Modalidad,N.TipCom AS TipComp,TipoCom,N.Comprobante AS NumComp,IdCiaCom,N.Observacion AS Observ,Anulado,N.IdEstado AS CdEstado,Estado
,OrigenAdd,N.TimeSys AS FechaCrea,N.FecUpdate AS FechaAct,N.IdCiaCrea  AS CdCiaCrea,N.IdUsuario AS CdUsuario,Usuario
--detalle del comprobante
,Item,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,IdVehiculo,D.IdCCosto AS DetCodCentCost,DC.CCosto AS DetCentCost
,D.IdSubCos AS DetCodSubCentro,DS.SubCosto  AS DetSubCentro,VrBase,TarifaBase,D.TipDoc AS DetTipoDoc,D.Documento AS DetNumDoc,IdCiaDoc,TipFac,Factura,IdCiaFac,ItemFac
,FecVence,D.NumCheque AS DetNumCheque,TipoAplica,NitOtros,Referncia
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,CLI.Comentarios AS ClieComentarios
--agencias
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinNotas AS N INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  Conceptos AS CN ON N.IdConcepto=CN.IdConcepto INNER JOIN  Companias AS CI ON N.IdCia=CI.IdCia
 INNER JOIN Terceros AS V ON N.IdVend=V.IdTercero  INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado  INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN  Plazos AS PZ ON N.IdPlazo=PZ.IdPlazo
 INNER JOIN  TercCliePrestamo AS CLI ON N.IdCliente=CLI.IdClie AND N.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Agencias  AS A ON N.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON N.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Bancos AS BN ON N.CdBanco=BN.IdBanco LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 LEFT JOIN  Trn_ComDetalle AS D ON N.TipCom=D.TipCom AND N.Comprobante=D.Comprobante AND N.IdCiaCom=D.IdCia
 LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta LEFT JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero
 LEFT JOIN CentroCosto AS DC ON D.IdCCosto=DC.IdCCosto  LEFT JOIN SubCentros AS DS ON D.IdSubCos=DS.IdSubCos
 WHERE N.TipDoc=@pmTipDoc  AND NumNota BETWEEN  @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
 ORDER BY NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryFinNotasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinNotasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT  NumNota,N.IdCia AS CdCia,Compania,Fecha,N.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrSancion,VrOtros,VrNeto
,VrAplicado,VrAnticipo,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,N.IdCCosto AS CdcCosto,N.IdSubCos AS CdSubCost,IdVend,V.RazonSocial AS Vendedor
,TarifaCom,CodTarCom,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,FecDcm,CdForma,NumCheque,CdBanco,MulPlazos,IdPlazo,Modalidad,TipCom,Comprobante,IdCiaCom
,N.Observacion AS Observ,Anulado,N.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,N.IdUsuario AS CdUsuario,Usuario
 FROM Trn_FinNotas AS N INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON N.IdCia=CI.IdCia INNER JOIN Terceros AS V ON N.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
  AND N.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
  ORDER BY N.IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPagosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPagosFmt] @pmTipDoc VARCHAR(3),@pmIdPrestamoIni INT,@pmIdPrestamoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  P.IdPrestamo,P.TipDoc,P.IdCia ,P.Item ,Numero ,P.Fecha,FecPago,P.VrCuota,EdoForma,CdBanco,Banco,CtaCheque,Detalle,TipRec,Recibo,IdCiaRec
,VrLiqMora,FecLiqMora,VrRecCaja,CLI.IncRetFte AS CalRteFte
 --Detalle facturas
 ,FF.VrInteres,FF.ItemPago ,TarifSeguro As PorcSeguro, TotalSeguro As VrSeguro
 FROM Trn_FinFacturas AS FF 
 inner join Trn_FinPrestamo FP ON FF.TipDoc =FP.TipDoc AND FF.IdPrestamo =FP.IdPrestamo AND FF.IdCia =FP.IdCia 
 INNER JOIN TercCliePrestamo CLI ON FP.IdCliente=CLI.IdClie AND FP.IdAgencia =CLI.IdAgencia 
 inner join   Trn_FinPagos  AS P ON FF.TipDoc =P.TipDoc and FF.IdPrestamo = P.IdPrestamo 
 and FF.IdCia =P.IdCia  and FF.ItemPago =P.Item 
 
  LEFT JOIN Bancos AS B ON P.CdBanco=B.IdBanco
 WHERE P.TipDoc=@pmTipDoc AND P.IdPrestamo BETWEEN @pmIdPrestamoIni AND @pmIdPrestamoFin AND P.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamo] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,IdPrestamo,IdCia,Fecha,FecPrestamo,FecCorte,IdConcepto,IdCliente,IdAgencia,VrPrestamo,IdTasa,NPlazos,Causacion,IdMora,NContrato,CdCiaCon,NActaJunta,NumCredito
,IdVend,pVehiculo,CdConductor,TipoGarantia,VrGarantia,DescGarantia,CxPagar,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora
,CuotasPagadas,CuotasMora,TipoAprob,TipoCausac,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,DiaCausac ,DiaCausac2,DiasVence,IdLinea,TipoPlazo
,CdTasa2,VrSeguro,VrIntereses,VrNeto,VrCuota,TipoCredito,CalcIntMora,NitEmpConv,CuotasConv,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CdAlmacen,CauAnticipado
,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdCtaPago,VrInteresPM,CantDiasPM,NumNotaIni,NumNotaFin,FechaFinPM,IndDebAuto
 FROM Trn_FinPrestamo
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoAcum]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoAcum]  @pmIdCia CHAR(2)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmTipoCredito VARCHAR(10)=Null
 AS 
 SELECT T.RazonSocial AS NomCliente,IdCliente,NomAgencia AS Agencia,P.IdAgencia AS CdAgencia,P.IdPrestamo AS NumPrest,P.IdCia AS CdCia,Compania
,NumCredito,P.Fecha AS FecRadica,FecPrestamo,FecCorte,DiaCausac,DiaCausac2,P.DiasVence AS DiasVce,P.TipoAprob AS TipAprob,NActaJunta,VrPrestamo,VrSeguro,VrIntereses,VrNeto,VrCuota,NPlazos,P.TipoPlazo AS TipPlazo,Causacion
,P.IdLinea AS CdLinea,LinCredito,P.IdTasa AS CdTasa,DescTasa,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora,NumCuotaIni
,TipoCredito,P.TipoCausac AS Tipo_Causac,P.CalcIntMora AS CalcMora,NitEmpConv,P.CuotasConv AS NCuoConv,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor,P.NContrato AS NumContrato,CdCiaCon
,P.TipoGarantia AS TipoGarant,P.DescGarantia AS Desc_Garant,P.VrGarantia AS ValGarant,P.Observacion AS Observ,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,P.IdConcepto AS CdConcepto,Concepto,P.IdEstado AS CdEstado,Estado
,Anulado,TI.TipoInteres AS Tipo_Int,TasaEfectiva,TipoPeriodo,CausaInteres,DTF_EA,Spread_TA,OpcCompra,CdAlmacen,Almacen
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,CupoCredito,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad
,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinPrestamo AS P  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto   INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado 
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc INNER JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN TercClieLineas AS LCR ON P.IdCliente=LCR.IdClie AND P.IdAgencia=LCR.IdAgencia AND P.IdLinea=LCR.IdLinea
 LEFT JOIN FinAlmacenes AS FA ON P.CdAlmacen=FA.IdAlmacen
 WHERE  P.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND P.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND P.TipoCredito LIKE ISNULL(@pmTipoCredito,'%')  
 ORDER BY P.IdCia,P.IdPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoCr] @pmTipDoc VARCHAR(3), @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdTasa VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT IdPrestamo,P.IdCia AS CdCia,Compania,Fecha,FecPrestamo,FecCorte,P.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,P.IdAgencia AS CdAgencia,NomAgencia AS Agencia
,VrPrestamo,VrSeguro,VrIntereses,VrNeto,VrCuota,P.IdTasa AS CdTasa,DescTasa,TI.TipoInteres AS Tipo_Int,TasaEfectiva,TipoPeriodo,CausaInteres,DTF_EA,Spread_TA,OpcCompra,NPlazos,Causacion
,P.IdMora AS CdMora,DescMora,TIM.TipoInteres AS TipoIntMora,TasaEA,TasaEM,TIM.DiasGracia AS Dias_Gracia,P.NContrato AS NumContrato,CdCiaCon,TipoAprob,NActaJunta,NumCredito,P.IdVend AS CdVend,VN.RazonSocial AS NomVendedor
,pVehiculo,CdConductor,CD.RazonSocial AS NomConductor,TipoGarantia,VrGarantia,DescGarantia,CxPagar,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas
,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,P.Observacion AS Observ,DiaCausac ,DiaCausac2,DiasVence,P.IdLinea AS CdLinea,LinCredito,TipoPlazo,CdTasa2
,TipoCredito,P.CalcIntMora AS CaclMora,NitEmpConv,CuotasConv,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CdAlmacen,CauAnticipado,VrInteresPM,CantDiasPM,NumNotaIni,NumNotaFin,FechaFinPM,IndDebAuto
,P.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS Cdusuario,Usuario,TipDoc
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad
,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
 FROM Trn_FinPrestamo AS P  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado  INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TasasIntmora AS TIM ON P.IdMora=TIM.IdMora LEFT JOIN TiposCom AS TC ON P.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Terceros AS CD ON P.CdConductor=CD.IdTercero  
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 WHERE TipDoc=@pmTipDoc  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND P.IdVend LIKE ISNULL(@pmIdVend,'%') AND P.IdTasa LIKE ISNULL(@pmIdTasa,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY P.IdCia,IdPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoDsb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoDsb] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmTipoCredito VARCHAR(10)=Null
,@pmIdLinea VARCHAR(4)=Null
AS 
 SELECT P.IdPrestamo AS NumPrest,P.IdCia AS CdCia,Compania,P.Fecha AS FecRadica,FecPrestamo,FecCorte
,T.RazonSocial AS NomCliente,IdCliente,NomAgencia AS Agencia,P.IdAgencia AS CdAgencia,P.IdConcepto AS CdConcepto,Concepto
,VrPrestamo,VrSeguro,VrIntereses,VrNeto,VrCuota,P.IdLinea AS CdLinea,LinCredito,P.IdTasa AS CdTasa,DescTasa,DTF_EA,Spread_TA,TasaEfectiva
,NPlazos,TipoPlazo,Causacion,TipoCredito,TipoCausac,P.CalcIntMora AS CalcMora,P.IdMora AS CdMora,DescMora,TasaEA,TasaEM,NumCredito,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor
,CxPagar,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora
,CuotasConv,TipoAprob,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CauAnticipado,P.IdEstado AS CdEstado,Estado,P.Observacion AS Observ
,Anulado,NumDev,FecDev
,TipEgr,NumEgreso,IdCiaEgr,FecEgreso,VrEgreso
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad
,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinPrestamo AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado 
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero  INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 LEFT JOIN Trn_FinPrestEgreso AS EG ON P.TipDoc=EG.TipDoc AND P.IdPrestamo=EG.IdPrestamo AND P.IdCia=EG.IdCia
 LEFT JOIN TasasIntmora AS TIM ON P.IdMora=TIM.IdMora
 WHERE P.TipDoc=@pmTipDoc AND P.IdCia LIKE ISNULL(@pmIdCia,'%%') AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND P.TipoCredito LIKE ISNULL(@pmTipoCredito,'%') AND P.IdLinea LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoExto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoExto] @pmFecCorte SMALLDATETIME, @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT P.TipDoc AS TipPrest,P.IdPrestamo AS NumPrest,P.IdCia AS CdCia,Compania,FecPrestamo,P.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,P.IdAgencia AS CdAgencia,NomAgencia AS Agencia
,VrPrestamo,P.VrSeguro AS VrCuoSeguro,VrCuota,NPlazos,Causacion,NumCuotaIni,P.IdLinea AS CdLinea,LinCredito,TipoCredito,P.TipoCausac AS PreTipoCausac,P.IdTasa AS CdTasa,DescTasa,P.CalcIntMora AS CalcIMora
,NumCredito,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor,P.TipoGarantia AS TipoGarntia,P.VrGarantia AS VlrGarantia,P.DescGarantia AS DesGarantia,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,P.IdEstado AS CdEstado,Estado,P.Observacion AS Observ
,TI.TipoInteres AS TipoIntPre,TasaEfectiva,TipoPeriodo,CausaInteres,TI.DTF_EA AS DTFEA,TI.Spread_TA AS Puntos,OpcCompra
--acumulados 
,AcumCuotas,CuotasPagadas,CuotasMora,AcumCapital,PagosCapital,AcumIntereses,PagosIntereses,AcumIntMora,PagosIntMora
--acum Causaciones
,ISNULL((SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='CAPITAL'),0) AS TotCapitalCau
--causaciones de intereses prstamos y facturas
,ISNULL((SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='INTERESES'),0) AS TotInteresCau
,ISNULL((SELECT COUNT(NumCuota) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto=(CASE WHEN P.TipoCredito='PRESTAMO' AND P.TipoCausac=2 THEN 'INTERESES' ELSE 'CAPITAL' END)),0) AS CantCuotasCau
,ISNULL((SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc='ND2' AND Trn_FinCuotas.NumPreMora=P.IdPrestamo AND Trn_FinCuotas.IdCiaCau=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte  AND Trn_FinCuotas.Concepto='INTMORA'),0) AS TotInteresMora
--INT MORA DEL PERIODO
,ISNULL((SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc='ND2' AND Trn_FinCuotas.NumPreMora=P.IdPrestamo AND Trn_FinCuotas.IdCiaCau=P.IdCia
   AND Trn_FinCuotas.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Trn_FinCuotas.Concepto='INTMORA'),0) AS IntMoraPeriodo
,ISNULL((SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='SEGURO'),0) AS TotSeguroCau
,ISNULL(PC.VrPagosCapital,0) AS TotPagosCapital,P.VrPrestamo-ISNULL(PC.VrPagosCapital,0) AS PreSaldoCap
--PAGOS DE INTERESES
,ISNULL(CASE TipoCredito WHEN 'FACTURAS' THEN (SELECT SUM(Trn_FinAbonos.TotalAbono) FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas
 ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo  AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
  WHERE Trn_FinCuotas.NumPreMora=P.IdPrestamo AND Trn_FinCuotas.IdCiaCau=P.IdCia  AND (CASE Trn_FinAbonos.Tipoaplica WHEN 2 THEN Trn_FinCuotas.Fecha ELSE Trn_FinAbonos.Fecha END)<=@pmFecCorte  AND Trn_FinCuotas.TipDoc='FIF')
 ELSE (SELECT SUM(Trn_FinAbonos.TotalAbono) FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo
  AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
  WHERE Trn_FinAbonos.TipDoc=P.TipDoc AND Trn_FinAbonos.IdPrestamo=P.IdPrestamo AND Trn_FinAbonos.IdCiaPre=P.IdCia AND  (CASE  Trn_FinAbonos.Tipoaplica WHEN 2 THEN Trn_FinCuotas.Fecha ELSE Trn_FinAbonos.Fecha END)<=@pmFecCorte
  AND Trn_FinCuotas.Concepto='INTERESES') END,0) AS TotPagosInteres
,ISNULL((SELECT SUM(Trn_FinAbonos.TotalAbono) FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo
  AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
  WHERE Trn_FinCuotas.TipDoc='ND2' AND Trn_FinCuotas.NumPreMora=P.IdPrestamo AND Trn_FinCuotas.IdCiaCau=P.IdCia AND Trn_FinCuotas.Concepto='INTMORA' AND Trn_FinAbonos.Fecha<=@pmFecCorte),0) AS TotPagosIMora
,ISNULL((SELECT SUM(Trn_FinAbonos.TotalAbono) FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo
  AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
  WHERE Trn_FinAbonos.TipDoc=P.TipDoc AND Trn_FinAbonos.IdPrestamo=P.IdPrestamo AND Trn_FinAbonos.IdCiaPre=P.IdCia AND Trn_FinAbonos.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='SEGURO'),0) AS TotPagosSeguro
,ISNULL((SELECT COUNT(*) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.VrTotal<=(Trn_FinCuotas.VrAbonado+0.5) AND Trn_FinCuotas.Concepto=(CASE WHEN P.TipoCredito='PRESTAMO' AND P.TipoCausac=2 THEN 'INTERESES' ELSE 'CAPITAL' END)),0) AS CantCuotasPagos
,ISNULL((SELECT COUNT(*) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
   AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.FechaVence<@pmFecCorte AND Trn_FinCuotas.VrTotal>Trn_FinCuotas.VrAbonado
  AND Trn_FinCuotas.Concepto=(CASE WHEN P.TipoCredito='PRESTAMO' AND P.TipoCausac=2 THEN 'INTERESES' ELSE 'CAPITAL' END)),0) AS CantCuotasMora
,ISNULL((SELECT SUM(Trn_FinCuotas.VrTotal-Trn_FinCuotas.VrAbonado) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=P.TipDoc AND Trn_FinCuotas.IdPrestamo=P.IdPrestamo AND Trn_FinCuotas.IdCia=P.IdCia
  AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.FechaVence<@pmFecCorte AND Trn_FinCuotas.VrTotal>Trn_FinCuotas.VrAbonado),0) AS TotCuotasMora
--datos de cuota del periodo
,NumCuota,CT.Fecha AS FecCausac,CT.FechaVence AS FecVence,NumDias,TasaEfe,TasaDia,CT.DTF_EA AS TasaDTF,VrCapital,CT.VrIntereses AS VrInteresCorr,CT.VrSeguro AS Vr_Seguro,VrTotalCuota,VrPagado
--datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,T.TipEnte AS TercEnte,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,CupoCredito
 FROM Trn_FinPrestamo AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  INNER JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TercClieLineas TLC ON P.IdLinea =TLC.IdLinea AND P.IdCliente =TLC.IdClie AND P.IdAgencia=TLC.IdAgencia 
   --Cuotas del periodo
 LEFT JOIN (SELECT TipDoc,IdPrestamo,IdCia,NumCuota,Fecha,FechaVence,DTF_EA,TasaEfe,TasaNom AS TasaDia,SUM(CASE Concepto WHEN 'CAPITAL' THEN VrTotal ELSE 0 END) AS VrCapital
 ,SUM(CASE Concepto WHEN 'INTERESES' THEN VrTotal ELSE 0 END) AS VrIntereses,SUM(CASE Concepto WHEN 'SEGURO' THEN VrTotal ELSE 0 END) AS VrSeguro
 ,SUM(VrTotal) AS VrTotalCuota,SUM(VrAbonado) AS VrPagado,SUM(CASE Concepto WHEN 'INTERESES' THEN DiasLiquida ELSE 0 END) AS NumDias FROM Trn_FinCuotas WHERE Trn_FinCuotas.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 GROUP BY TipDoc,IdPrestamo,IdCia,NumCuota,Fecha,FechaVence,DTF_EA,TasaEfe,TasaNom) AS CT ON P.TipDoc=CT.TipDoc AND P.IdPrestamo=CT.IdPrestamo AND P.IdCia=CT.IdCia
--pagos a capital
 LEFT JOIN (SELECT A.TipDoc AS TipoPrest,A.IdPrestamo AS NumPrest,A.IdCiaPre AS CdCiaPrest,SUM(A.TotalAbono) AS  VrPagosCapital FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo
  AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item WHERE A.Fecha<=@pmFecCorte AND C.Concepto='CAPITAL'  GROUP BY A.TipDoc,A.IdPrestamo,A.IdCiaPre) AS PC ON P.TipDoc=PC.TipoPrest AND P.IdPrestamo=PC.NumPrest AND P.IdCia=PC.CdCiaPrest
  LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE FecPrestamo<=@pmFechaFin AND P.Anulado=0
 ORDER BY P.TipDoc,P.IdPrestamo,P.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoFac] @pmTipDoc VARCHAR(3), @pmIdPrestamoIni INT,@pmIdPrestamoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT P.TipDoc,P.IdPrestamo AS NumPtmo,P.IdCia AS CdCia,Compania,P.Fecha AS FechaPtmo,FecPrestamo,FecCorte,P.IdConcepto AS CdConcepto,C.Concepto AS DescConcept,P.IdCliente AS NitCliente
,T.RazonSocial AS NomCliente,P.IdAgencia AS CdAgencia,NomAgencia AS Agencia,VrPrestamo,P.IdTasa AS CdTasa,DescTasa,TI.TipoInteres AS Tipo_Int,TasaEfectiva,NPlazos,TipoPlazo,P.Causacion AS TipoCausac,P.IdMora AS CdMora,DescMora
,TIM.TipoInteres AS Tipo_IntMora,TasaEM,P.NContrato AS NumContrato,CdCiaCon,TipoAprob,NActaJunta,NumCredito
,P.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,pVehiculo,CdConductor,TipoGarantia,VrGarantia,DescGarantia,CxPagar,CdTasa2,VrSeguro,VrIntereses,VrNeto,P.VrCuota AS ValCuota,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas
,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,P.Observacion AS Observ,DiaCausac ,DiaCausac2,DiasVence,P.IdLinea AS CdLinea,LinCredito
,TipoCredito,P.CalcIntMora AS CaclMora,NitEmpConv,CuotasConv,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CdAlmacen,CauAnticipado
,P.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS Cdusuario,Usuario
--Datos de facturas
,Item,NumFactura,DF.Fecha AS FechaFact,FechaVence,VrFactura,VrInteres,DiasLiq,TasaEfeMes,TasaEfeDia,FechaPago,FechaLiq,FecInicio,FecFinal,VrAbono,ItemPago,Facturado,TipFac,FacturaInt,CdCiaFac,FecFactura,DiasPlazo
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia
,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios
 FROM Trn_FinPrestamo AS P  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN  TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 INNER JOIN Trn_FinFacturas AS DF ON P.TipDoc=DF.TipDoc AND P.IdPrestamo=DF.IdPrestamo AND P.IdCia=DF.IdCia
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 LEFT JOIN TasasIntmora AS TIM ON P.IdMora=TIM.IdMora LEFT JOIN TiposCom AS TC ON P.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE P.TipDoc=@pmTipDoc  AND P.IdPrestamo BETWEEN @pmIdPrestamoIni AND @pmIdPrestamoFin  AND P.IdCia=@pmIdCia
 ORDER BY  P.IdPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoFmt] @pmTipDoc VARCHAR(3), @pmIdPrestamoIni INT,@pmIdPrestamoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT P.IdPrestamo AS NumPtmo,P.IdCia AS CdCia,Compania,P.Fecha AS FechaPtmo,FecPrestamo,FecCorte,P.IdConcepto AS CdConcepto,C.Concepto AS DescConcept,P.IdCliente AS NitCliente
,T.RazonSocial AS NomCliente,P.IdAgencia AS CdAgencia,NomAgencia AS Agencia,VrPrestamo,P.IdTasa AS CdTasa,DescTasa,TI.TipoInteres AS Tipo_Int,TasaEfectiva,NPlazos,TipoPlazo,P.Causacion AS TipoCausac,P.IdMora AS CdMora,DescMora
,TIM.TipoInteres AS Tipo_IntMora,TasaEM,P.NContrato AS NumContrato,CdCiaCon,TipoAprob,NActaJunta,NumCredito
,P.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,pVehiculo,CdConductor,TipoGarantia,VrGarantia,DescGarantia,CxPagar,CdTasa2,VrSeguro,VrIntereses,VrNeto,P.VrCuota AS ValCuota,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas
,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,P.Observacion AS Observ,DiaCausac ,DiaCausac2,DiasVence,P.IdLinea AS CdLinea,LinCredito
,TipoCredito,P.CalcIntMora AS CaclMora,NitEmpConv,CuotasConv,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CdAlmacen,CauAnticipado,P.VrInteresPM,P.CantDiasPM,P.NumNotaIni,P.NumNotaFin,P.FechaFinPM,P.IndDebAuto
,P.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS Cdusuario,Usuario
--Datos del detalle
,PC.Item,FecCausac,FecVence,NumDias,PC.VrCuota AS TotalCuota,VrCapital,VrInteres,VrSaldo,TasaEfeMes,TasaEfeDia,PC.Causacion AS NumCausac,CdCiaCausac,VrCuoCausac,VrIntCausac,VrSaldoCausac,VrCustodia,VrProrroga,TasaCustodia
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,TPS.Tarifa AS TarSeg
,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,Comentarios,CLI.IncRetFte AS CalcularReteFte 
 FROM Trn_FinPrestamo AS P  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN  TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT join Trn_FinPrestSeguro PS ON P.TipDoc =PS.TipDoc AND P.IdPrestamo=PS.IdPrestamo AND P.IdCia =PS.IdCia 
LEFT JOIN Tablapor TPS ON PS.CdTarSeguro = TPS.IdTarifa 
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 LEFT JOIN TasasIntmora AS TIM ON P.IdMora=TIM.IdMora LEFT JOIN TiposCom AS TC ON P.TipCom=TC.IdCom
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Trn_FinAmtza AS PC ON P.TipDoc=PC.TipDoc AND P.IdPrestamo=PC.IdPrestamo AND P.IdCia=PC.IdCia
 WHERE P.TipDoc=@pmTipDoc  AND P.IdPrestamo BETWEEN @pmIdPrestamoIni AND @pmIdPrestamoFin  AND P.IdCia=@pmIdCia
 ORDER BY  P.IdPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoLta] @pmTipDoc VARCHAR(3), @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdTasa VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT IdPrestamo,P.IdCia AS CdCia,Compania,Fecha,FecPrestamo,FecCorte,DiaCausac ,DiaCausac2,DiasVence,P.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrPrestamo,P.IdTasa AS CdTasa,DescTasa
,NPlazos,TipoPlazo,Causacion,IdLinea,IdMora,VrSeguro,VrIntereses,VrNeto,VrCuota,NContrato,CdCiaCon,TipoAprob,TipoCausac,NActaJunta,NumCredito,IdVend,VN.RazonSocial AS NomVendedor,pVehiculo,CdConductor,TipoGarantia,VrGarantia,DescGarantia
,CxPagar,NumCuotaIni,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora
,CuotasPagadas,CuotasMora,CdTasa2,TipoCredito,CalcIntMora,NitEmpConv,CuotasConv,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,CdAlmacen,CdCtaPago,CauAnticipado,P.VrInteresPM,P.CantDiasPM,P.NumNotaIni,P.NumNotaFin,P.FechaFinPM
,P.IndDebAuto,P.TipCom,P.Comprobante,P.IdCiaCom,P.Anulado,P.NumDev,P.FecDev,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS Cdusuario,Usuario
 FROM Trn_FinPrestamo AS P  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 WHERE TipDoc=@pmTipDoc  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')  AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND P.IdVend LIKE ISNULL(@pmIdVend,'%') AND P.IdTasa LIKE ISNULL(@pmIdTasa,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY P.IdCia,IdPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestamoRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestamoRes] @pmSaldo DECIMAL(12,2),@pmTipDoc VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdTasa VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT T.RazonSocial AS NomCliente,IdCliente,NomAgencia AS Agencia,P.IdAgencia AS CdAgencia,P.IdPrestamo AS NumPrest,P.IdCia AS CdCia,Compania
,NumCredito,P.Fecha AS FecRadica,FecPrestamo,DiaCausac,DiaCausac2,DiasVence,TipoAprob,NActaJunta,VrPrestamo,VrSeguro,VrIntereses,VrNeto,VrCuota,NPlazos,TipoPlazo,Causacion,P.IdLinea AS CdLinea,LinCredito,P.IdTasa AS CdTasa,DescTasa
,tmVrCuota AS VrCuotaDTF,tmDescCuota AS DescripCuota,tmVrMora AS VrEnMora,AcumCapital,AcumIntereses,VrPrestamo-AcumCapital AS SaldoCapital,tmDiasMora AS PromDiasMora
,CausaMora,GestionClie,AcuerdosClie,TipoGarantia,DescGarantia,VrGarantia,NumCuotaIni,AcumCuotas,CuotasMora
,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CdTasa2,TipoCredito,P.CalcIntMora AS CalcMora,NitEmpConv,CuotasConv,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor,P.NContrato AS NumContrato,CdCiaCon,P.Observacion AS Observ
,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,P.IdConcepto AS CdConcepto,Concepto,CauAnticipado,P.IdEstado AS CdEstado,Estado
,TI.TipoInteres AS Tipo_Int,TasaEfectiva,TipoPeriodo,CausaInteres,DTF_EA,Spread_TA,OpcCompra
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad
,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinPrestamo AS P  INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto   INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado 
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Trn_FinObserv AS PD ON P.TipDoc=PD.TipDoc AND P.IdPrestamo=PD.IdPrestamo AND P.IdCia=PD.IdCia
 LEFT JOIN tm_PreMora AS PM ON P.TipDoc=PM.tmTipDoc AND P.IdPrestamo=PM.tmIdPrestamo AND P.IdCia=PM.tmIdCia
 LEFT JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 WHERE P.TipDoc=@pmTipDoc  AND P.Anulado=0   AND (VrPrestamo-AcumCapital)>=@pmSaldo
 AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
  AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND P.IdVend LIKE ISNULL(@pmIdVend,'%') 
 AND P.IdTasa LIKE ISNULL(@pmIdTasa,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY P.IdCia,P.IdPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestGarant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestGarant] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,IdPrestamo,IdCia,Item,TipoGarant,DescGarant,CdInmueble,CdTipoVeh,VrGarantia,VrAvaluo,PesoBruto,PesoNeto,IdUsuario,Propietario,DirInmueble,CdCiudad,Matricula,Escritura,NumNotaria,MarcaVeh,Modelo,CdBanco,FecCheque,NumCheque,OtroTipoVehic,OtroInmueble
,CedFmnte1,NomFmnte1,CedFmnte2,NomFmnte2,CedFmnte3,NomFmnte3,CedFmnte4,NomFmnte4,CedFmnte5,NomFmnte5,CedFmnte6,NomFmnte6,ArchivoImg
 FROM Trn_FinPrestGarant
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestGarantLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestGarantLta] @pmIdCliente VARCHAR(16)=Null,@pmTipoGarant VARCHAR(20)=Null,@pmIdCia CHAR(2)=Null
AS 
 SELECT G.TipDoc AS TipPrest,G.IdPrestamo AS NumPrest,G.IdCia AS CdCia,Compania,Item,TipoGarant,DescGarant,CdInmueble,TipoInmueble,CdTipoVeh,TipoVehiculo,G.VrGarantia AS VrGarant,VrAvaluo
,G.PesoBruto AS Peso_Bruto,PesoNeto,Propietario,DirInmueble,CdCiudad,Localidad,Matricula,Escritura,NumNotaria,MarcaVeh,Modelo,CdBanco,Banco,FecCheque,NumCheque
,CedFmnte1,NomFmnte1,CedFmnte2,NomFmnte2,CedFmnte3,NomFmnte3,CedFmnte4,NomFmnte4,CedFmnte5,NomFmnte5,CedFmnte6,NomFmnte6,ArchivoImg,G.IdUsuario AS CdUsuario,Usuario
--datos del prestamo
,FecPrestamo,FecCorte,VrPrestamo,VrCuota,IdCliente,T.RazonSocial AS NomCliente,P.IdAgencia AS CdAgencia,NomAgencia AS Agencia
,NPlazos,NumCredito,P.Observacion AS Observ,P.IdLinea AS CdLinea,LinCredito,TipoCredito,Anulado
 FROM Trn_FinPrestGarant AS G INNER JOIN Trn_FinPrestamo AS P ON G.TipDoc=P.TipDoc AND G.IdPrestamo=P.IdPrestamo AND G.IdCia=P.IdCia
 INNER JOIN Companias AS CI ON G.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero
 LEFT JOIN LineasCred AS L ON P.IdLinea=L.IdLinea
 LEFT JOIN TiposInm AS IM ON G.CdInmueble=IM.IdTipoInm LEFT JOIN TiposVeh AS TV ON G.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Bancos AS B ON G.CdBanco=B.IdBanco LEFT JOIN Localidades AS LC ON G.CdCiudad=LC.IdLocal
 WHERE G.IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipoGarant LIKE ISNULL(@pmTipoGarant,'%')
 AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinPrestResEgr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinPrestResEgr]  @pmIdCia CHAR(2)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmTipoCredito VARCHAR(10)=Null
 AS 
 SELECT T.RazonSocial AS NomCliente,IdCliente,NomAgencia AS Agencia,P.IdAgencia AS CdAgencia,P.IdPrestamo AS NumPrest,P.IdCia AS CdCia,Compania
,NumCredito,P.Fecha AS FecRadica,FecPrestamo,FecCorte,DiaCausac,DiaCausac2,P.DiasVence AS DiasVce,P.TipoAprob AS TipAprob,NActaJunta,VrPrestamo,VrSeguro,VrIntereses,VrNeto,VrCuota,NPlazos,P.TipoPlazo AS TipPlazo,Causacion
,P.IdLinea AS CdLinea,LinCredito,P.IdTasa AS CdTasa,DescTasa,AcumCapital,AcumIntereses,AcumIntMora,AcumCuotas,PagosCapital,PagosIntereses,PagosIntMora,CuotasPagadas,CuotasMora,NumCuotaIni
,TipoCredito,P.TipoCausac AS Tipo_Causac,P.CalcIntMora AS CalcMora,NitEmpConv,P.CuotasConv AS NCuoConv,P.IdVend AS CdVend,VN.RazonSocial AS NomAsesor,P.NContrato AS NumContrato,CdCiaCon
,P.TipoGarantia AS TipoGarant,P.DescGarantia AS Desc_Garant,P.VrGarantia AS ValGarant,P.Observacion AS Observ,Refinanciado,NumPrestRef,CiaPrestRef,VrRefinanc,DescRefinanc,P.IdConcepto AS CdConcepto,Concepto,P.IdEstado AS CdEstado,Estado
,p.Anulado,TI.TipoInteres AS Tipo_Int,TasaEfectiva,TipoPeriodo,CausaInteres,DTF_EA,Spread_TA,OpcCompra
,FA.Almacen 
--cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,CupoCredito,EsExento,FecIngreso,VrSalBasico,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad
,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
,PE.VrEgreso ,PE.FecEgreso As Fechaegreso,CE.NumCheque, CE.FecCheque,CE.FecDev, CE.IdCta,CP.NumeroCta, CP.IdCuenta AS CtaContBanco,CE.EnEfectivo  
 FROM Trn_FinPrestamo AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto   INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado 
 INNER JOIN TasasInteres AS TI ON P.IdTasa=TI.IdTasa
 INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero   INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliePrestamo AS CLI ON P.IdCliente=CLI.IdClie AND P.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc INNER JOIN LineasCred AS LC ON P.IdLinea=LC.IdLinea
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN TercClieLineas AS LCR ON P.IdCliente=LCR.IdClie AND P.IdAgencia=LCR.IdAgencia AND P.IdLinea=LCR.IdLinea
 LEFT JOIN FinAlmacenes AS FA ON P.CdAlmacen=FA.IdAlmacen
 LEFT JOIN Trn_FinPrestEgreso PE ON P.TipDoc=PE.TipDoc AND P.IdPrestamo =PE.IdPrestamo AND P.IdCia =PE.IdCia 
 LEFT JOIN Trn_Comprobantes CE ON PE.TipEgr =CE.TipCom AND PE.NumEgreso =CE.Comprobante AND PE.IdCiaEgr=CE.IdCia 
 LEFT JOIN CtasCorrientes CP ON CE.IdCta=CP.IdCta 
  WHERE  P.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND P.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND P.TipoCredito LIKE ISNULL(@pmTipoCredito,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrEfectivo
,VrAnticipo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,IdVend,TarifaCom,CodTarCom,EnEfectivo,CdForma,NumForma,DetallePago,CdBanco
,CdCta,Referencia,pVehiculo,CdConductor,TipoCredito,TipDcm,Documento,IdCiaDcm,VrAboCapital,LiqAboCapital,VrAboOtros,VrPagoCuotas,VrPagoAportes,VrPagoConvenio,VrAboCuotas,VrAboAportes,VrAboConvenio,VrAntPrestamo,VrAntAportes,VrAntConvenio
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinRecibos
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosCr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinRecibosCr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null 
 AS 
 SELECT  Recibo,R.IdCia AS CdCia,Compania,Fecha,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,NomAgencia AS Agencia,FecPago
,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrEfectivo,VrAnticipo,VrAboOtros,BaseRet,BaseIca,BaseRiv
,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,R.IdVend AS CdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,EnEfectivo,CdForma,NumForma
,DetallePago,CdBanco,Banco,CdCta,R.Referencia AS Refrencia,TipoCredito,pVehiculo,CdConductor,CD.RazonSocial AS Conductor,TipDcm,Documento,IdCiaDcm,VrAboCapital,LiqAboCapital
,VrPagoCuotas,VrPagoAportes,VrPagoConvenio,VrAboCuotas,VrAboAportes,VrAboConvenio,VrAntPrestamo,VrAntAportes,VrAntConvenio
,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario,TipDoc
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,Comentarios
--agencias
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinRecibos AS R  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo AS CLI ON R.IdCliente=CLI.IdClie AND R.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona   INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TiposCom AS TCM ON R.TipCom=TCM.IdCom  
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Bancos AS B ON R.CdBanco=B.IdBanco  LEFT JOIN Terceros AS CD ON R.CdConductor=CD.IdTercero
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND R.IdVend LIKE ISNULL(@pmIdVend,'%')  AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY R.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinRecibosDoc]  @pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmTipDcm VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrEfectivo
,VrAnticipo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,IdVend,TarifaCom,CodTarCom,EnEfectivo,CdForma,NumForma,DetallePago,CdBanco
,CdCta,Referencia,pVehiculo,CdConductor,TipoCredito,TipDcm,Documento,IdCiaDcm,VrAboCapital,LiqAboCapital,VrAboOtros,VrPagoCuotas,VrPagoAportes,VrPagoConvenio,VrAboCuotas,VrAboAportes,VrAboConvenio,VrAntPrestamo,VrAntAportes,VrAntConvenio
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_FinRecibos
 WHERE Documento=@pmDocumento AND IdCiaDcm=@pmIdCiaDcm AND TipDcm LIKE ISNULL(@pmTipDcm,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinRecibosFmt] @pmTipDoc VARCHAR(3),@pmReciboIni INT, @pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Recibo,R.IdCia AS CdCia,Compania,R.Fecha AS FecRecibo,R.IdConcepto AS CdConcepto,Concepto,R.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,NomAgencia AS NomAgencia
,FecPago,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrEfectivo,VrAnticipo
,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,R.IdVend AS CdVend,V.RazonSocial AS Vendedor
,TarifaCom,CodTarCom,EnEfectivo,CdForma,R.NumForma AS RecNumForma,DetallePago,CdBanco,BR.Banco AS RecBanco,R.CdCta AS RecCodCta,R.Referencia AS RecReferncia,pVehiculo,CdConductor
,TipoCredito,TipDcm,R.Documento AS NumDcmto,IdCiaDcm,VrAboCapital,LiqAboCapital,VrAboOtros,VrPagoCuotas,VrPagoAportes,VrPagoConvenio,VrAboCuotas,VrAboAportes,VrAboConvenio,VrAntPrestamo,VrAntAportes,VrAntConvenio
,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario
--datos de forma de pago
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco
,P.NumForma AS PagNumForma,FecForma,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS PagReferencia2
,CdLocal,LF.Localidad AS CiudadPlaza,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,Comentarios
--agencias
,DirAgencia,CLI.IdLocalAge AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_FinRecibos AS R  INNER JOIN Trn_Pagos AS P ON R.TipDoc=P.TipDoc AND R.Recibo=P.Documento AND R.IdCia=P.IdCia
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario   INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  TercCliePrestamo AS CLI ON R.IdCliente=CLI.IdClie AND R.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN TiposCom AS TCM ON R.TipCom=TCM.IdCom  LEFT JOIN Bancos AS BR ON R.CdBanco=BR.IdBanco
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal 
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE R.TipDoc=@pmTipDoc  AND Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND R.IdCia=@pmIdCia
 ORDER BY  R.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryFinRecibosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFinRecibosLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 SELECT  Recibo,R.IdCia AS CdCia,Compania,Fecha,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrRetencion,VrReteICA,VrReteIVA
,VrOtros,VrOtrDcto,VrPagosMas,VrNeto,VrAplicado,VrAboOtros,VrEfectivo,VrAnticipo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,IdVend,V.RazonSocial AS Vendedor
,TarifaCom,CodTarCom,EnEfectivo,CdForma,NumForma,DetallePago,CdBanco,CdCta,Referencia,pVehiculo,CdConductor,TipoCredito,VrPagoCuotas,VrPagoAportes,VrPagoConvenio,VrAboCuotas,VrAboAportes,VrAboConvenio,VrAntPrestamo,VrAntAportes,VrAntConvenio
,TipDcm,Documento,IdCiaDcm,TipCom,Comprobante,IdCiaCom,VrAboCapital,LiqAboCapital,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario
 FROM Trn_FinRecibos AS R  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN  Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') 
 ORDER BY R.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFmtDoc] @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2)
 AS 
 SELECT IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
 FROM Sys_FmtDoc
 WHERE IdDoc LIKE ISNULL(@pmIdDoc,'%')  AND IdForma LIKE ISNULL(@pmIdForma,'%%')
 ORDER BY IdDoc,IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtDocDft]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFmtDocDft] @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2)=Null,@pmDescripcion VARCHAR(100)=Null
AS 
 IF @pmIdForma IS NULL And @pmDescripcion IS NULL
  SELECT IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
  FROM Sys_FmtDoc
  WHERE IdDoc=@pmIdDoc AND Predtmnado<>0
  ORDER BY IdForma
 ELSE
  SELECT IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
  FROM Sys_FmtDoc
  WHERE IdDoc=@pmIdDoc AND IdForma LIKE ISNULL(@pmIdForma,'%%') AND Descripcion LIKE ISNULL(@pmDescripcion,'%')
  ORDER BY IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtDocDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFmtDocDso] @pmIdDoc VARCHAR(3)
 AS
  SELECT IdDoc,IdForma,Descripcion,Formato,IdForma + ' '+Descripcion AS DsFor
  FROM Sys_FmtDoc
  WHERE IdDoc=@pmIdDoc
 ORDER BY IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtFactura]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFmtFactura] @pmnFormato VARCHAR(10)
 AS 
 SELECT nFormato,IdDoc,CdForma
 FROM Sys_FmtFactura
 WHERE nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryFmtFacturaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFmtFacturaLta] @pmTipFac VARCHAR(3)=Null
 AS 
  SELECT FF.nFormato AS IdFmto,FmtoFactura,IdDoc,CdForma
  FROM Sys_FmtFactura AS FF INNER JOIN Sys_TFmtos AS TF ON FF.nFormato=TF.nFormato
  WHERE TipFac LIKE ISNULL(@pmTipFac,'%')
  ORDER BY FF.nFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryFondos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFondos] @pmIdFondo VARCHAR(8)
 AS 
  SELECT IdFondo,Fondo,IdClase,IdTercero,CodigoEps,CodigoPen,CodigoArp,Inactivo
  FROM Fondos
  WHERE IdFondo=@pmIdFondo
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosCla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFondosCla] @pmIdClase VARCHAR(4)
 AS 
  SELECT IdFondo,Fondo,IdClase,IdTercero,CodigoEps,CodigoPen,CodigoArp,Inactivo
  FROM Fondos
  WHERE IdClase=@pmIdClase
  ORDER BY IdFondo
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFondosDso] @pmIdClase VARCHAR(4)
 AS
 IF @pmIdClase IS NULL
  SELECT IdFondo,Fondo,IdTercero  FROM Fondos  WHERE Inactivo=0  ORDER BY Fondo
 ELSE
  SELECT IdFondo,Fondo,IdTercero  FROM Fondos
  WHERE Inactivo=0 AND (IdClase=@pmIdClase OR IdClase='0')
  ORDER BY Fondo
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFondosLta] @pmIdClase VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS
  SELECT IdFondo,Fondo,F.IdClase AS CodClase,ClaseFondo,IdTercero,CodigoEps,CodigoPen,CodigoArp,F.Inactivo AS Inctivo
  FROM Fondos AS F INNER JOIN ClaseFon AS C ON F.IdClase=C.IdClase
  WHERE F.IdClase LIKE ISNULL(@pmIdClase,'%') 
  AND (F.Inactivo=ISNULL(@pmInactivo,0) or F.Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Fondo
GO
/****** Object:  StoredProcedure [dbo].[paQryFondosPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFondosPen] @pmIdClase VARCHAR(4)
 AS
  SELECT IdFondo,Fondo,IdTercero  FROM Fondos
  WHERE Inactivo=0 AND (IdClase=@pmIdClase OR IdClase='0' OR IdClase='0008')
  ORDER BY Fondo
GO
/****** Object:  StoredProcedure [dbo].[paQryFormasCue]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFormasCue] @pmIdForma VARCHAR(4),@pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdForma,IdConcepto,IdCuenta,FechaAdd,FechaUpdate
 FROM FormasCue
 WHERE IdConcepto=@pmIdConcepto AND IdForma LIKE ISNULL(@pmIdForma,'%')
 ORDER BY IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryFormasCueLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFormasCueLta] @pmIdForma VARCHAR(4),@pmIdConcepto VARCHAR(4)
 AS 
 SELECT FC.IdForma AS CdForma,FormaPago,C.IdDoc AS CdTipo,TipoDoc,FC.IdConcepto AS CdConcep,Concepto
,FC.IdCuenta AS CdCuenta,NomCuenta
,Consecutivo,CuadreCaja,RefDcmto,RefNit,RefBco,RefFech,RefAtza,RefOtro,VldRangos
,FC.FechaAdd AS Fec_Add,FC.FechaUpdate AS Fec_Upd
 FROM FormasCue AS FC INNER JOIN Formaspago AS F ON FC.IdForma=F.IdForma
 INNER JOIN Conceptos AS C ON FC.IdConcepto=C.IdConcepto
 INNER JOIN Puc AS P ON FC.IdCuenta=P.IdCuenta
 INNER JOIN  Sys_TiposDoc AS T ON C.IdDoc=T.IdDoc
 WHERE FC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND FC.IdForma LIKE ISNULL(@pmIdForma,'%')
 ORDER BY FC.IdForma,C.IdDoc,FC.IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryFormaspago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFormaspago] @pmIdForma VARCHAR(4)
 AS 
 IF @pmIdForma IS NULL
  SELECT IdForma,FormaPago,Consecutivo,CuadreCaja,RefDcmto,RefNit,RefBco,RefFech,RefAtza,RefOtro,VldRangos,VleConsumo
,CodIntegrity,CodValera,CodIntCom,RefProducto,FactTicket,CdMedPago,ValCtaPago
  FROM Formaspago
  WHERE Inactivo=0
  ORDER BY Consecutivo
 ELSE
  SELECT IdForma,FormaPago,Consecutivo,CuadreCaja,RefDcmto,RefNit,RefBco,RefFech,RefAtza,RefOtro,VldRangos,VleConsumo
,CodIntegrity,CodValera,CodIntCom,RefProducto,FactTicket,CdMedPago,ValCtaPago,Inactivo
  FROM Formaspago
  WHERE IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryFormaspagoChe]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFormaspagoChe] 
 AS 
  SELECT IdForma,FormaPago,Consecutivo
  FROM Formaspago
  WHERE (IdForma IN ('CHE','BON','CON','TRA') OR  IdForma LIKE 'CH%')  AND Inactivo=0 
  ORDER BY Consecutivo
GO
/****** Object:  StoredProcedure [dbo].[paQryFormaspagoID]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFormaspagoID]
 AS 
  SELECT MAX(Consecutivo) AS MXCON
  FROM Formaspago
GO
/****** Object:  StoredProcedure [dbo].[paQryFuentesPago]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFuentesPago] @pmIdFuente VARCHAR(4)
 AS 
 IF @pmIdFuente IS NULL
  SELECT IdFuente,FuentePago 
  FROM FuentesPago
  WHERE Inactivo=0
  ORDER BY IdFuente
 ELSE
  SELECT IdFuente,FuentePago,Inactivo 
  FROM FuentesPago
  WHERE IdFuente=@pmIdFuente
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAdicionales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatAdicionales] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumRegistro,IdCia,Fecha,IdConcepto,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrAporte,VrSaldo,VrAvaluo,TipoBaseLiq,TipoAfiVeh,Referencia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatAdicionales
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatAjustes] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumAjuste,IdCia,Fecha,FechaVence,IdConcepto,Modalidad,VrAjustes,Referencia,TipDocRef,NumDocRef,CiaDocRef,TipCau,Causacion,IdCiaCau
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatAjustes
 WHERE TipDoc=@pmTipDoc AND NumAjuste=@pmNumAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAjustesPror]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatAjustesPror] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumAjuste,IdCia,Fecha,IdConcepto,Modalidad,TipPror,NumProceso,IdCiaPror,VrAjustes,Referencia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatAjustesPror
 WHERE TipDoc=@pmTipDoc AND NumAjuste=@pmNumAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatAportes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatAportes] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT [Id],TipDoc,NumRegistro,IdCia,Item,FecEmision,FecVence,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,Concepto,Importe,VrAvaluo,VrComercial,VrAsegurado
,TipoBaseLiq,Cantidad,TarifaApo,CodTarifApo,CantDiasAnt,VrDiasAnt,VrDevolucion,Descripcion,Referencia,TipDocRef,NumDocRef,TipCom,Comprobante,TipoAfiVeh,FecLiqApo,FechaCrea
 FROM Trn_GatAportes
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevAdicional]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevAdicional] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumRegistro,IdCiaDoc,FecDoc,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevAdicional
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevAjuPror]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevAjuPror] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumAjuste,IdCiaDoc,FecDoc,Modalidad,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevAjuPror
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevAjustes] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumAjuste,IdCiaDoc,FecDoc,Modalidad,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevAjustes
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevLiquida] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumLiquida,IdCiaDoc,FecDoc,Modalidad,VrDevolucion,VrBaseLiq,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevLiquida
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevProrr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevProrr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumProceso,IdCiaDoc,FecDoc,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevProrr
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevRetiros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevRetiros] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumRetiro,IdCiaDoc,FecDoc,TipoRetiro,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevRetiros
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevTraslado] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,Modalidad,TipDoc,NumTraslado,IdCiaDoc,FecDoc,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,IdAsociadoDtn,UndVehicDtn,IdVehiculoDtn,VrDevolucion,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevTraslado
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatDevVinc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatDevVinc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumDocVinc,IdCiaDoc,FecDoc,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrIngresos,VrTraslados,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatDevVinc
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatLiquida] @pmTipDoc VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumLiquida,IdCia,Fecha,FechaLiquida,FechaVence,IdConcepto,Modalidad,Periodos,TarifaLiq,VrAportes,Referencia,VrBaseLiq,CdTarifLiq,TipCau,Causacion,IdCiaCau
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatLiquida
 WHERE TipDoc=@pmTipDoc AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatProrrateos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatProrrateos] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumProceso,IdCia,Fecha,IdConcepto,Modalidad,TipDocActa,NumDocActa,IdCiaActa,FecSuceso,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrAprobado,VrAvaluo,TipoAfiVeh,Referencia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatProrrateos
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatRetiros]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatRetiros] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumRegistro,IdCia,Fecha,FechaRetiro,IdConcepto,TipoRetiro,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrRetiro,VrAportes,VrVinculacion,VrSaldoVinc,VrGarantia,VrSaldoApo,VrTotalApo,VrAvaluo,TipoBaseLiq,TipoAfiVeh,Referencia,FechaCorte,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatRetiros
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatSaldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatSaldos] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumRegistro,IdCia,Fecha,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,VrAportes,VrVinculacion,VrAvaluo,VrComercial,VrAsegurado,TipoBaseLiq,Cantidad,FecVincAsoc,FecLiquidaApo,TipoAfiVeh,Anulado,Observacion,IdUsuario,FechaCrea
 FROM Trn_GatSaldos
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatTraslados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatTraslados] @pmTipDoc VARCHAR(3),@pmNumTraslado INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumTraslado,IdCia,Fecha,IdConcepto,Modalidad,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,IdAsociadoDtn,UndVehicDtn,IdVehiculoDtn,VrTraslado,VrAportes,VrVinculacion,VrSaldoVinc,VrGarantia,VrSaldoApo,VrTotalApo,VrAvaluo,TipoBaseLiq,TipoAfiVeh,Referencia,FechaCorte,VrAbonos,TipDocRef,NumDocRef,CiaDocRef,TarifaGar,UndTarifGar
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FechaDev,Observacion,ComentarioGar,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatTraslados
 WHERE TipDoc=@pmTipDoc AND NumTraslado=@pmNumTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGatVincula]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGatVincula] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumRegistro,IdCia,Fecha,FechaIngreso,IdConcepto,IdAsociado,UndVehiculo,IdVehiculo,nRemolque,TarifaVinc,VrVinculacion,VrIngresos,VrTraslados,VrAvaluo,VrComercial,VrAsegurado,TipoBaseLiq,TipoAfiVeh,Referencia,CdTarifVinc,TipCom,Comprobante,IdCiaCom,FecUltLiqApo,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_GatVincula
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGrupos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGrupos] @pmIdGrupo VARCHAR(8)
 AS 
 SELECT IdGrupo,Grupo,IdLinea,TipoInvent,Inactivo
 FROM Grupos
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposAgenc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGruposAgenc] @pmIdGrupo VARCHAR(4)
 AS 
 IF @pmIdGrupo IS NULL
  SELECT IdGrupo,GrupoAgenc
  FROM GruposAgenc
  WHERE Inactivo=0
 ORDER BY IdGrupo
 ELSE
 SELECT IdGrupo,GrupoAgenc,Inactivo
 FROM GruposAgenc
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposAR]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposAR] @pmIdGrupo VARCHAR(4)
 AS 
 IF @pmIdGrupo IS NULL
  SELECT IdGrupo,AltoRiesgo,TarfaTrab,TarfaEmp
  FROM GruposAR
  WHERE Inactivo=0
  ORDER BY IdGrupo
 ELSE
  SELECT IdGrupo,AltoRiesgo,TarfaTrab,TarfaEmp,Inactivo
  FROM GruposAR
  WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposCli]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGruposCli] @pmIdGrupo VARCHAR(4)
 AS 
 SELECT IdGrupo,GrupoClie,ModApp,Inactivo
 FROM GruposCli
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposCliLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGruposCliLta] @pmModApp VARCHAR(10)=Null
 AS 
 SELECT IdGrupo,GrupoClie,ModApp
 FROM GruposCli
 WHERE Inactivo=0 AND ModApp like ISNULL(@pmModApp,'%')
 ORDER BY IdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposDso]  @pmIdLinea VARCHAR(8)=Null,@pmTipoInvent VARCHAR(10)=Null
 AS 
 SELECT IdGrupo,Grupo,Grupo+' '+IdGrupo + ' ('+Linea+')'  AS DsGru
 FROM Grupos AS G INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE G.Inactivo=0 AND  G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND G.TipoInvent LIKE ISNULL(@pmTipoInvent,'%')
 ORDER BY Linea,Grupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposLin]  @pmIdGrupo VARCHAR(8)=Null
 AS 
 SELECT IdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,G.Inactivo AS Inactiv,G.TipoInvent AS TipoInv
 FROM Grupos AS G INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY Linea,Grupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposLta]  @pmIdLinea VARCHAR(8)=Null,@pmTipoInvent VARCHAR(10)=Null
 AS 
 SELECT IdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,G.TipoInvent AS TipoInventario
 FROM Grupos AS G INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE G.Inactivo=0 AND  G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND G.TipoInvent LIKE ISNULL(@pmTipoInvent,'%')
 ORDER BY Linea,Grupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposMcia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGruposMcia] @pmIdGrupo VARCHAR(10)
 AS 
 IF @pmIdGrupo IS NULL
  SELECT IdGrupo,GrupoMcia
  FROM GruposMcia
  WHERE Inactivo=0
 ORDER BY GrupoMcia
 ELSE
  SELECT IdGrupo,GrupoMcia,Inactivo
  FROM GruposMcia
  WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposObj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposObj] @pmIdGrupo VARCHAR(6),@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdGrupo,GrupoObjeto,nModulo
 FROM Sys_GruposObj
 WHERE IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY nModulo,IdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposPro] @pmIdGrupo VARCHAR(4)
 AS 
 IF @pmIdGrupo IS NULL
 SELECT IdGrupo,GrupoProp
 FROM GruposPro
 WHERE Inactivo=0 
 ORDER BY GrupoProp
 ELSE
 SELECT IdGrupo,GrupoProp,Inactivo
 FROM GruposPro
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposRot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposRot] @pmIdGrupo VARCHAR(4)
 AS 
 IF @pmIdGrupo IS NULL
 SELECT IdGrupo,GrupoRot
 FROM GruposRot
 WHERE Inactivo=0
 ORDER BY GrupoRot
 ELSE
 SELECT IdGrupo,GrupoRot,Inactivo
 FROM GruposRot
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposUsu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposUsu] @pmIdGrupo INT
 AS 
 SELECT IdGrupo,Grupo,Descripcion
 FROM Sys_GruposUsu
 WHERE (IdGrupo>=ISNULL(@pmIdGrupo,0)  AND IdGrupo<=ISNULL(@pmIdGrupo,2147483647)) 
 ORDER BY IdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGruposUsuDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGruposUsuDso] @pmIdGrupo INT
 AS 
 SELECT IdGrupo,Grupo,Descripcion,STR(IdGrupo,2,0)+'  '+Grupo AS DsGru
 FROM Sys_GruposUsu
 WHERE  IdGrupo<=@pmIdGrupo
 ORDER BY IdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGuia] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Guia,IdCia,Fecha,FechaDesp,FechaVence,IdCliente,IdAgencia,Cantidad,DirEnvio,IdLocal,LugarEnv,HorasVig
,IdVehiculo,IdConductor,NitEmpTrans,EmpTrans,CdRuta,CdCiuOrigen,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,Factura,IdCiaFac,FechaFact
,OrigenAdd,ZonaFrontera,TipoTemp,Temperatura,TipoOCargue,Remolque,Anulado,FecDev,Observacion,IdEstado,NumVerifica,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Guia
 WHERE TipDoc=@pmTipDoc AND Guia=@pmGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryGuia_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGuia_Cr] @pmTipDoc VARCHAR(3),@pmGuiaIni INT,@pmGuiaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  O.TipDoc AS Tip_Doc,TipoDoc,Guia,O.IdCia AS CdCia,Compania,O.Fecha AS FechaDoc,FechaDesp,FechaVence,IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Cantidad,DirEnvio,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,HorasVig,O.IdVehiculo,O.IdConductor AS CedConductor,TC.RazonSocial AS Conductor,LibMilitar,ClaseLib,FechaLib,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,NumTarjeta,VigTarjeta
,O.NitEmpTrans,EmpTrans,CdRuta,Ruta,CdCiuOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CdDepOrigen,DO.Departamento AS DptoOrigen
,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact,OrigenAdd,ZonaFrontera,Anulado,TipoTemp,O.Temperatura,TipoOCargue,Remolque,NumVerifica,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado
,O.TimeSys AS Fec_Add,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,CLI.NumCuenta AS NumeroCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,CdCCosto,K.CdSubCos AS CodSubCos,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia
,K.Descripcion AS KarDescricion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,K.Remision AS KarRemision,K.IdCiaRem AS CdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase
,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5,Compania
--Inf. vehículo
,CdRemque,VehArtic,NumVeh,K.Temperatura As Temdetalle,galsneto ,Densidad ,codsicom
 FROM  Trn_Guia AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Guia=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero 
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia   INNER JOIN Terceros AS TC ON O.IdConductor=TC.IdTercero
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Localidades AS LO ON O.CdCiuOrigen=LO.IdLocal  LEFT JOIN Departamentos AS DO ON LO.IdDep=DO.IdDep 
 LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN TercCndtores AS TCD ON O.IdConductor=TCD.IdConductor
 LEFT JOIN Vehiculos AS VH ON O.IdVehiculo=VH.IdVehiculo
 WHERE O.TipDoc=@pmTipDoc AND Guia BETWEEN @pmGuiaIni  AND @pmGuiaFin AND O.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY Guia,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGuiaDet] @pmGuia INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Item,K.IdProducto AS CdProducto,Descripcion,CdTanque,Salidas,VrPrecio,Salidas*VrPrecio AS VrSubTotal,Comptmntos
,VrBruto,K.ListaPrec AS LtaPrec,VrBase,K.Referencia AS Referncia,Unidades,Referencia2,K.IdVend AS NitVend,V.RazonSocial AS Vendedor,Comision,K.CodTarCom AS CdTarifCom
,DescripProd,Servcios,Tanques,K.IdBodega AS CdBodega,Bodega
,G.Fecha AS FecGuia,FechaDesp,FechaVence,IdCliente,T.RazonSocial AS Cliente,IdAgencia,DirEnvio,LugarEnv,HorasVig
,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor,NitEmpTrans,EmpTrans,Referncia,TipOcc,OCargue,IdCiaOcc
,G.Factura AS NumFactura,IdCiaFac,FechaFact,G.Observacion AS Observ
 FROM Trn_Guia AS G  INNER JOIN Trn_Kardex AS K ON G.TipDoc=K.TipDoc AND G.Guia=K.Documento AND G.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN Terceros AS V ON K.IdVend=V.IdTercero
 INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero
 INNER JOIN Terceros AS CD ON G.IdConductor=CD.IdTercero
 WHERE Guia=@pmGuia AND G.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGuiaFac] @pmFactura  INT,@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT Guia,IdCia,Fecha,T.RazonSocial AS NomCliente,IdCliente,IdAgencia,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor
,Cantidad,DirEnvio,G.IdLocal AS CdCiudad,LugarEnv,FechaDesp,FechaVence,HorasVig
,NitEmpTrans,EmpTrans,CdRuta,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,Factura,IdCiaFac,FechaFact
,G.Observacion AS Observ,G.IdEstado AS CdEstado,Estado,TimeSys,IdCiaCrea
 FROM Trn_Guia AS G  INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero
 INNER JOIN Terceros AS CD ON G.IdConductor=CD.IdTercero
 INNER JOIN EstadoDoc AS ED ON G.IdEstado=ED.IdEstado
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Factura<=@pmFactura
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND G.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY IdCia,Guia
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaFact]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGuiaFact] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmGuiaIni INT=Null,@pmGuiaFin INT=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmCdCiuOrigen VARCHAR(8)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaFacIni SMALLDATETIME=Null,@pmFechaFacFin SMALLDATETIME=Null
 AS 
 SELECT Guia,O.IdCia AS CdCia,Compania,O.Fecha AS FechaGuia,FechaDesp,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantOrden,SUM(Unidades) AS Unidades
--datos de factura
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,NumPedido,CdCiaPedido,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas
,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades,FacTarifSob,FacTarifSol,FacTarifIglobal
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia
,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,HorasVig,IdVehiculo,CdCiuOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CdDepOrigen,DO.Departamento AS DptoOrigen
,Referncia,TipOcc,OCargue,IdCiaOcc,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
 FROM  Trn_Guia AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero  INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Guia=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Localidades AS LO ON O.CdCiuOrigen=LO.IdLocal  LEFT JOIN Departamentos AS DO ON LO.IdDep=DO.IdDep 
 LEFT JOIN (SELECT Remision,IdCiaRem,TipOrd,NumOrden,IdCiaOrd,K.TipDoc AS TipoFact,K.Documento AS NumFactura,K.IdCia AS CdCiaFac,KC.Compania AS NomCiaFac
,K.Fecha AS FecFactura,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd,K.Cotizacion AS NumPedido,K.IdCiaCot  AS CdCiaPedido
,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaEnt) AS IvaEntradas
,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoEnt) AS DctoEntradas,SUM(VrDctoSal) AS DctoSalidas,SUM(K.Unidades) AS TotalUnidades
,MAX(Sobretasa) AS FacTarifSob,MAX(Soldicom) AS FacTarifSol,MAX(ImpGlobal) AS FacTarifIglobal
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE NoVentas BETWEEN 1 AND 4  AND Remision>0 AND TipOrd='OCC'
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaFacIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFacFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY Remision,IdCiaRem,TipOrd,NumOrden,IdCiaOrd,K.TipDoc,K.Documento,K.IdCia,KC.Compania,K.Fecha,K.IdProducto
,PM.DescripProd,K.Cotizacion,K.IdCiaCot) AS FA ON  O.Guia=FA.Remision AND O.IdCia=FA.IdCiaRem AND K.IdProducto=FA.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%') AND CdCiuOrigen LIKE ISNULL(@pmCdCiuOrigen,'%')
 AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND Guia  BETWEEN ISNULL(@pmGuiaIni,0) AND ISNULL(@pmGuiaFin,2147483647)
 GROUP BY Guia,O.IdCia,Compania,O.Fecha,FechaDesp,K.IdProducto,DescripProd
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,NumPedido,CdCiaPedido,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas
,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades,FacTarifSob,FacTarifSol,FacTarifIglobal
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,O.IdLocal,LE.Localidad
,LE.IdDep,DE.Departamento,LugarEnv,HorasVig,IdVehiculo,CdCiuOrigen,LO.Localidad,LO.IdDep,DO.Departamento
,Referncia,TipOcc,OCargue,IdCiaOcc,O.Observacion,O.IdEstado,Estado
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGuiaLta]  @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmGuiaIni INT=Null,@pmGuiaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Guia,IdCia,Fecha,FechaDesp,FechaVence,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,Cantidad,DirEnvio,G.IdLocal AS CdCiudad,LugarEnv,HorasVig
,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor,NitEmpTrans,EmpTrans,CdRuta,CdCiuOrigen,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,Factura,IdCiaFac,FechaFact
,OrigenAdd,ZonaFrontera,TipoTemp,Temperatura,TipoOCargue,Remolque,NumVerifica,Anulado,FecDev,G.Observacion AS Observ,G.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,G.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Guia AS G  INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero
 INNER JOIN Terceros AS CD ON G.IdConductor=CD.IdTercero
 INNER JOIN EstadoDoc AS ED ON G.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Guia BETWEEN ISNULL(@pmGuiaIni,0) AND ISNULL(@pmGuiaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND G.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Guia
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaPed]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryGuiaPed] @pmOCargue INT,@pmIdCiaOcc CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT Guia,G.IdCia AS CodCia,G.Fecha AS FechaGuia,FechaDesp,FechaVence,IdCliente,RazonSocial,IdAgencia,IdVehiculo
,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,TarifaIva,VrIvaSal
,Sobretasa,Soldicom,ImpGlobal,Comptmntos,VrUnitario,VrCostoSal,pVehiculo,K.IdVend AS CedVend,Comision,Referencia,Referencia2,K.Unidades AS Unddes
,G.Factura AS NumFactura,IdCiaFac,FechaFact
 FROM Trn_Guia AS G INNER JOIN Trn_Kardex AS  K ON G.Guia=K.Documento AND G.IdCia=K.IdCia
 AND G.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipOcc='OCC' AND OCargue=@pmOCargue AND IdCiaOcc=@pmIdCiaOcc  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY G.IdCia,Guia,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGuiaRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmCdCiuOrigen VARCHAR(8)=Null,@pmIdLocal VARCHAR(8)=Null
,@pmIdConductor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Guia,O.IdCia AS CdCia,Compania,Fecha,FechaDesp,FechaVence,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia
,Cantidad,DirEnvio,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,HorasVig,IdVehiculo,O.IdConductor AS CedConductor,TC.RazonSocial AS Conductor,LibMilitar,ClaseLib,FechaLib,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,NumTarjeta,VigTarjeta
,O.NitEmpTrans,EmpTrans,CdRuta,Ruta,CdCiuOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CdDepOrigen,DO.Departamento AS DptoOrigen
,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,Factura,IdCiaFac,FechaFact,OrigenAdd,ZonaFrontera,TipoTemp,Temperatura,TipoOCargue,Remolque,NumVerifica,Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,TimeSys,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,CLI.NumCuenta AS NumeroCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM  Trn_Guia AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero 
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia   INNER JOIN Terceros AS TC ON O.IdConductor=TC.IdTercero
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Localidades AS LO ON O.CdCiuOrigen=LO.IdLocal  LEFT JOIN Departamentos AS DO ON LO.IdDep=DO.IdDep 
 LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN TercCndtores AS TCD ON O.IdConductor=TCD.IdConductor
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%') AND CdCiuOrigen LIKE ISNULL(@pmCdCiuOrigen,'%')
 AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,Guia
GO
/****** Object:  StoredProcedure [dbo].[paQryGuiaRelDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryGuiaRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmCdCiuOrigen VARCHAR(8)=Null,@pmIdLocal VARCHAR(8)=Null
,@pmIdConductor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT O.TipDoc AS CdTipDoc,Guia,O.IdCia AS CdCia,Compania,O.Fecha AS FechaGuia,FechaDesp,FechaVence,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia
,Cantidad,DirEnvio,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,HorasVig,IdVehiculo,O.IdConductor AS CedConductor,TC.RazonSocial AS Conductor,LibMilitar,ClaseLib,FechaLib,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,NumTarjeta,VigTarjeta
,O.NitEmpTrans,EmpTrans,CdRuta,Ruta,CdCiuOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CdDepOrigen,DO.Departamento AS DptoOrigen
,Referncia,TipOcc,OCargue,IdCiaOcc,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact,OrigenAdd,ZonaFrontera,TipoOCargue,Remolque,NumVerifica,Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,O.TimeSys,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,CLI.NumCuenta AS NumeroCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--datos de kardex
,K.IdProducto AS CdProducto,Salidas,K.Referencia,DescripProd,Descripcion
 FROM  Trn_Guia AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero 
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia   INNER JOIN Terceros AS TC ON O.IdConductor=TC.IdTercero
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Guia=K.Documento  AND  O.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Localidades AS LO ON O.CdCiuOrigen=LO.IdLocal  LEFT JOIN Departamentos AS DO ON LO.IdDep=DO.IdDep 
 LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN TercCndtores AS TCD ON O.IdConductor=TCD.IdConductor
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%') AND CdCiuOrigen LIKE ISNULL(@pmCdCiuOrigen,'%')
 AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,Guia
GO
/****** Object:  StoredProcedure [dbo].[paQryInstalaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryInstalaciones] @pmIdInstala VARCHAR(4)
 AS 
 SELECT IdInstala,Instlacion,DirInstala,CodCiu,CodCia,IdClase,Inactivo
 FROM Instalaciones
 WHERE IdInstala=@pmIdInstala
GO
/****** Object:  StoredProcedure [dbo].[paQryInstalacionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInstalacionesLta] @pmCodCia CHAR(2)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdInstala,Instlacion,DirInstala,CodCiu,Localidad,CodCia,Compania,I.IdClase AS CodClase,ClaseRiesgo,Tarifa,I.Inactivo AS Inctivo
 FROM Instalaciones AS I INNER JOIN ClaseRie AS CR ON I.IdClase=CR.IdClase
 LEFT JOIN Localidades AS L ON I.CodCiu=L.IdLocal LEFT JOIN  Companias AS C ON I.CodCia=C.IdCia 
 WHERE CodCia LIKE ISNULL(@pmCodCia,'%%') 
 AND (I.Inactivo=ISNULL(@pmInactivo,0) or I.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Instlacion
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalle] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,nInventario,IdCia,Item,IdProducto,IdBodega,CdUbic,CdTanque,Cantidad,VrUnitario,CantExist
,Descripcion,Unidades,UndAforo,UndAgua,CantAgua,NoConteo,IdUsuario,IdEstacion,FechaAdd
 FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleDso] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdUsuario VARCHAR(11)=Null,@pmIdEstacion CHAR(2)=Null
 AS 
 SELECT Item,D.IdProducto AS CdProducto,DescripProd,D.IdBodega AS CdBodega,Bodega,CdUbic,CdTanque
,Cantidad,CantExist,VrUnitario,Cantidad*VrUnitario AS CostoTotal --Cantidad-CantExist AS CantDif
,Descripcion,Unidades,NoConteo,D.IdUsuario AS IdUsuari,Usuario,D.IdEstacion AS CdEstacion
,D.FechaAdd AS Fec_Add,UndAforo,UndAgua,CantAgua
 FROM Trn_InvDetalle AS D  INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 INNER JOIN  Bodegas AS B ON D.IdBodega=B.IdBodega
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND D.IdEstacion LIKE ISNULL(@pmIdEstacion,'%%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleEtq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleEtq] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmCdTanque VARCHAR(4),@pmItem INT
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND CdTanque=@pmCdTanque  AND Item<>@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleExi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleExi] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia  AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleExp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleExp] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4)
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND  IdProducto=@pmIdProducto AND IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleFal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleFal] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdEstacion CHAR(2)=Null
 AS 
 SELECT D.IdProducto AS CdProducto,DescripProd,D.IdBodega AS CdBodega,Bodega
,SUM(Cantidad) AS CantFisico,CantExist,SUM(Cantidad)-CantExist AS CantDif
 FROM Trn_InvDetalle AS D  INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 INNER JOIN  Bodegas AS B ON D.IdBodega=B.IdBodega
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND IdEstacion LIKE ISNULL(@pmIdEstacion,'%%')
 GROUP BY  D.IdProducto,DescripProd,D.IdBodega,Bodega,CantExist
 HAVING (SUM(Cantidad)-CantExist)<0
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleFalTq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleFalTq] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
SELECT D.IdProducto AS CdProducto,DescripProd,D.CdTanque,D.Cantidad,D.CantExist
,CASE T.TnqUnido WHEN 1 THEN 0 ELSE (D.Cantidad-D.CantExist) END AS CantDif
,D.UndAforo,D.UndAgua,D.CantAgua
 FROM Trn_InvDetalle AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 LEFT JOIN Tanques AS T ON D.CdTanque=T.IdTanque
 WHERE D.TipDoc=@pmTipDoc AND D.nInventario=@pmnInventario AND D.IdCia=@pmIdCia 
 AND (D.Cantidad-D.CantExist)<0 AND T.TnqUnido=0
 ORDER BY DescripProd,D.CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleItm] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetallePro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetallePro] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Item,D.IdProducto AS CdProducto,DescripProd,TipoRef,D.IdBodega AS CdBodega,CdUbic,CdTanque,Cantidad,VrUnitario,CantExist
,Unidades,UndAforo,UndAgua,CantAgua,NoConteo,ExtciaAct,Tanques,Seriales,Lotes,VrCostPmd,VrCosto
 FROM Trn_InvDetalle AS D  INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleSob]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleSob] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdEstacion CHAR(2)=Null
 AS 
 SELECT D.IdProducto AS CdProducto,DescripProd,D.IdBodega AS CdBodega,Bodega
,SUM(Cantidad) AS CantFisico,CantExist,SUM(Cantidad)-CantExist AS CantDif
 FROM Trn_InvDetalle AS D  INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 INNER JOIN  Bodegas AS B ON D.IdBodega=B.IdBodega
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND IdEstacion LIKE ISNULL(@pmIdEstacion,'%%')
 GROUP BY  D.IdProducto,DescripProd,D.IdBodega,Bodega,CantExist
 HAVING (SUM(Cantidad)-CantExist)>0
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleSobTq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleSobTq] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.IdProducto AS CdProducto,DescripProd,D.CdTanque,D.Cantidad,D.CantExist
,CASE T.TnqUnido WHEN 1 THEN 0 ELSE (D.Cantidad-D.CantExist) END AS CantDif
,D.UndAforo,D.UndAgua,D.CantAgua
 FROM Trn_InvDetalle AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 LEFT JOIN Tanques AS T ON D.CdTanque=T.IdTanque
 WHERE D.TipDoc=@pmTipDoc AND D.nInventario=@pmnInventario AND D.IdCia=@pmIdCia 
 AND (D.Cantidad-D.CantExist)>0 AND T.TnqUnido=0
 ORDER BY DescripProd,D.CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleTan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleTan] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,D.IdProducto AS CdProducto,DescripProd,D.IdBodega AS CdBodega,CdTanque,UndAforo,UndAgua,D.Cantidad,CantAgua,CantExist
,CASE T.TnqUnido WHEN 1 THEN 0 ELSE (Cantidad-CantExist) END AS CantDif,VrUnitario
,CASE T.TnqVirtual WHEN 1 THEN 0 ELSE (Cantidad*VrUnitario) END AS CostoTotal
,D.Descripcion,D.Unidades,NoConteo,D.IdUsuario AS IdUsuari,Usuario,D.IdEstacion AS CdEstacion
,D.FechaAdd AS Fec_Add
 FROM Trn_InvDetalle AS D  INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Tanques AS T ON D.CdTanque=T.IdTanque
 WHERE D.TipDoc=@pmTipDoc AND D.nInventario=@pmnInventario AND D.IdCia=@pmIdCia 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleTco]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleTco] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT COUNT(CASE T.TnqVirtual WHEN 1 THEN 0 ELSE D.Item END) AS SITEMS
,SUM(CASE T.TnqVirtual WHEN 1 THEN 0 ELSE D.Cantidad END) AS SCANT
,SUM(CASE T.TnqVirtual WHEN 1 THEN 0 ELSE (D.VrUnitario*D.Cantidad) END) AS SCOSTOT
,SUM(CASE T.TnqUnido WHEN 1 THEN 0 ELSE D.CantExist END) AS SCANEXI
,SUM(CASE T.TnqUnido WHEN 1 THEN 0 ELSE (D.VrUnitario*D.CantExist) END) AS SEXITOT
,SUM(CASE T.TnqVirtual WHEN 1 THEN 0 ELSE D.CantAgua END) AS SCANTAGUA
,SUM(CASE T.TnqVirtual WHEN 1 THEN 0 ELSE D.Unidades END) AS STOTUNI
 FROM Trn_InvDetalle AS D INNER JOIN Tanques AS T ON D.CdTanque=T.IdTanque
 WHERE D.TipDoc=@pmTipDoc AND D.nInventario=@pmnInventario AND D.IdCia=@pmIdCia 
 AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryInvDetalleTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvDetalleTot] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT COUNT(Item) AS SITEMS,SUM(Cantidad) AS SCANT,SUM(VrUnitario*Cantidad) AS SCOSTOT
,SUM(CantExist) AS SCANEXI,SUM(VrUnitario*CantExist) AS SEXITOT,SUM(CantAgua) AS SCANTAGUA
,SUM(Unidades) AS STOTUNI
 FROM Trn_InvDetalle
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia 
 AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisico]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisico] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,nInventario,IdCia,Fecha,Modalidad,CdBodega,CantFisico,VrTotalFisico,Existencias,VrTotalCosto
,OrigenAdd,Procesado,FecProceso,NumAjuSob,NumAjuFal,Anulado,FecDev,Observacion,IdEstado,FCodBodega,FCodMarca,FCodSubGrupo,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_InvFisico
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisico_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisico_Cr] @pmTipDoc VARCHAR(3),@pmnInventarioIni INT,@pmnInventarioFin INT
,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)=Null,@pmIdEstacion CHAR(2)=Null
 AS 
 SELECT F.nInventario AS NumeroInv,F.IdCia AS CdCia,Compania,Fecha,Modalidad,CantFisico,VrTotalFisico,Existencias,VrTotalCosto
,Procesado,FecProceso,NumAjuSob,NumAjuFal,Anulado,FecDev,Observacion,F.IdEstado AS CdEstado,Estado
,FCodBodega,FB.Bodega AS InvBodega,FCodMarca,FM.Marca AS InvMarca,FCodSubGrupo,FS.Subgrupo AS InvSubgrupo
,F.TimeSys,F.FecUpdate,F.IdCiaCrea,F.IdUsuario AS CdUsuarioCrea,U.Usuario AS UsuarioCrea
--Detalles de inventario
,Item,D.IdProducto AS CodProducto,DescripProd,D.IdBodega AS CdBodega,B.Bodega,CdTanque,Cantidad,PM.IdUnd AS CdUnidad,UM.Unidad AS UnidPresenta,VrUnitario,CantExist
,Descripcion,Unidades,UndAforo,UndAgua,CantAgua,NoConteo,D.IdUsuario AS DetIdUsuario,UD.Usuario AS DetUsuario,D.IdEstacion AS CdTerminal,D.FechaAdd AS Fech_Add
--información del producto
,B.Descrip AS DesBodega,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,S.Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,M.Marca
,Tamano,PM.UndMed AS CdUndMed,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_InvFisico AS F INNER JOIN Trn_InvDetalle AS D ON F.TipDoc=D.TipDoc AND F.nInventario=D.nInventario AND F.IdCia=D.IdCia
 INNER JOIN Companias AS C ON F.IdCia=C.IdCia INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS E ON F.IdEstado=E.IdEstado INNER JOIN ProdMcias AS PM ON D.IdProducto=PM.IdProducto
 INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega INNER JOIN adm_Usuarios AS UD ON D.IdUsuario=UD.IdUsuario
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed  INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 LEFT JOIN Marcas AS FM ON F.FCodMarca=FM.IdMarca LEFT JOIN Bodegas AS FB ON F.FCodBodega=FB.IdBodega
 LEFT JOIN SubGrupos AS FS ON F.FCodSubGrupo=FS.IdSubgrupo
 WHERE F.TipDoc=@pmTipDoc AND F.nInventario BETWEEN @pmnInventarioIni AND @pmnInventarioFin  AND F.IdCia=@pmIdCia
 AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND D.IdEstacion LIKE ISNULL(@pmIdEstacion,'%%')
 ORDER BY F.nInventario,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoDia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisicoDia] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME
,@pmModalidad VARCHAR(10),@pmnInventario INT
 AS 
 SELECT TipDoc,nInventario,IdCia,Fecha,Modalidad,Procesado,FecProceso,NumAjuSob,NumAjuFal,CdBodega,IdEstado
 FROM Trn_InvFisico
 WHERE TipDoc=@pmTipDoc AND IdCia=@pmIdCia AND Modalidad=@pmModalidad
 AND Fecha=@pmFecha AND Anulado=0 AND  nInventario<>@pmnInventario
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisicoLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmModalidad VARCHAR(10)=Null,@pmProcesado BIT=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmnInventarioIni INT=Null,@pmnInventarioFin INT=Null
 AS 
 SELECT nInventario,F.IdCia AS CdCia,Compania,Fecha,Modalidad,F.CdBodega,CantFisico,VrTotalFisico,Existencias,VrTotalCosto
,OrigenAdd,Procesado,FecProceso,NumAjuSob,NumAjuFal,Anulado,FecDev,F.Observacion,FCodBodega,FCodMarca,FCodSubGrupo
,F.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
 FROM Trn_InvFisico AS F INNER JOIN Companias AS C ON F.IdCia=C.IdCia
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 INNER JOIN EstadoDoc AS E ON F.IdEstado=E.IdEstado
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND F.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND nInventario BETWEEN ISNULL(@pmnInventarioIni,0) AND ISNULL(@pmnInventarioFin,2147483647)
 AND (Procesado=ISNULL(@pmProcesado,0) or Procesado=ISNULL(@pmProcesado,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY F.IdCia,nInventario
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisicoPen] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2)
,@pmModalidad VARCHAR(10),@pmnInventario INT
 AS 
 SELECT TipDoc,nInventario,IdCia,Fecha,Modalidad,Procesado,FecProceso,NumAjuSob,NumAjuFal,CdBodega,IdEstado
 FROM Trn_InvFisico
 WHERE TipDoc=@pmTipDoc AND IdCia=@pmIdCia AND Modalidad=@pmModalidad AND Procesado=0
 AND Anulado=0 AND  nInventario<>@pmnInventario
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisicoRel] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
SELECT F.nInventario,F.IdCia AS CdCia,Compania,F.Fecha,F.Modalidad,F.CdBodega,B.Bodega,CantFisico,VrTotalFisico,Existencias,VrTotalCosto
,F.Procesado,F.FecProceso,F.NumAjuSob,F.NumAjuFal,F.Anulado,F.FecDev,F.Observacion AS Observ
,FCodBodega,FB.Bodega AS InvBodega,FCodMarca,FM.Marca AS InvMarca,FCodSubGrupo,FS.Subgrupo AS InvSubgrupo
,F.IdEstado AS CdEstado,Estado,F.TimeSys AS FechaCrea,F.FecUpdate AS FechaModif,F.IdCiaCrea,F.IdUsuario AS CdUsuario,U.Usuario,F.OrigenAdd
--detalles
,D.Item,D.IdProducto AS CdProducto,DescripProd,D.IdBodega AS DetCdBodega,BD.Bodega AS DetBodega,D.CdTanque,D.Cantidad,D.VrUnitario,D.CantExist,D.Descripcion
,D.Unidades,D.UndAforo,D.UndAgua,D.CantAgua,D.NoConteo,D.IdUsuario AS DetCdUsuario,UD.Usuario DetUsuario,D.IdEstacion AS CdEstacion,ET.Estacion,D.FechaAdd AS DetFechaCrea,D.CdUbic
,P.UndMed,UP.Unidad AS UmPeso,P.IdUnd AS CdUnid,UM.Unidad,P.TipoRef,P.IdSubgrupo AS CdSubgrupo,SG.Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
,P.Referencia,P.CodBarras,P.DescripAbrv,P.ExtciaMin,P.ExtciaMax,P.ExtciaAct,P.Seriales,P.Lotes,P.Combo,P.Tanques
,TQ.Descripcion AS TanqDescrip,TQ.CapTanq AS TanqCapacidad,TQ.NivAgua AS TanqNivAgua,TQ.CapNeta AS TanqCapNeta,TQ.SaldoActual AS TanqSaldo,TQ.TnqGas,TQ.TnqUnido,TQ.TnqVirtual
,P.IdMarca AS CdMarca,M.Marca
FROM Trn_InvFisico AS F INNER JOIN Companias AS C ON F.IdCia=C.IdCia INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
INNER JOIN EstadoDoc AS E ON F.IdEstado=E.IdEstado
INNER JOIN Trn_InvDetalle AS D ON F.TipDoc=D.TipDoc AND F.nInventario=D.nInventario AND F.IdCia=D.IdCia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Bodegas AS BD ON D.IdBodega=BD.IdBodega
INNER JOIN Sys_Um AS UP ON P.UndMed=UP.UndMed INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
LEFT JOIN Tanques AS TQ ON D.CdTanque=TQ.IdTanque
LEFT JOIN Sys_Estaciones AS ET ON D.IdEstacion=ET.IdEstacion LEFT JOIN Bodegas AS B ON F.CdBodega=B.IdBodega
LEFT JOIN adm_Usuarios AS UD ON D.IdUsuario=UD.IdUsuario
LEFT JOIN Marcas AS FM ON F.FCodMarca=FM.IdMarca LEFT JOIN Bodegas AS FB ON F.FCodBodega=FB.IdBodega
LEFT JOIN SubGrupos AS FS ON F.FCodSubGrupo=FS.IdSubgrupo
WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryInvFisicoTan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryInvFisicoTan] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmCdTanque VARCHAR(4)=Null
 AS 
 SELECT Fecha,SUM(Cantidad) AS SaldoFisico,SUM(CantAgua) AS NivelAgua
 FROM Trn_InvFisico AS F INNER JOIN Trn_InvDetalle AS D ON F.TipDoc=D.TipDoc AND F.nInventario=D.nInventario  AND F.IdCia=D.IdCia
 INNER JOIN ProdMcias AS PM ON D.IdProducto=PM.IdProducto 
 WHERE Fecha BETWEEN @pmFechaIni AND  @pmFechaFin AND Modalidad='COMBUSTBLE' AND Anulado=0
  AND F.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND CdTanque LIKE ISNULL(@pmCdTanque,'%')
 GROUP BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryJornadas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJornadas] @pmIdJornada VARCHAR(4)
 AS 
 IF @pmIdJornada IS NULL
  SELECT IdJornada,Jornada,HorasDia,Rangos,TurnoRotativo
  FROM Jornadas
  WHERE Inactivo=0
  ORDER BY IdJornada
 ELSE
  SELECT IdJornada,Jornada,HorasDia,Rangos,TurnoRotativo,Inactivo 
  FROM Jornadas
  WHERE IdJornada=@pmIdJornada
GO
/****** Object:  StoredProcedure [dbo].[paQryJurActas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurActas] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumProceso,IdCia,Fecha,NumActa,FechaActa,Modalidad,ValorTotal,Referencia,EstadoPror,TipPror,NumPror,IdCiaPror,Anulado,NumDev,FechaDev,Observacion,IdUsuario,FechaCrea,IdCiaCrea,ModuloCrea
 FROM Trn_JurActas
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurAutoridades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurAutoridades] @pmIdAutoridad VARCHAR(4)
 AS 
 IF @pmIdAutoridad IS NULL
 SELECT IdAutoridad,NomAutoridad,Direccion
 FROM JurAutoridades
 WHERE Inactivo=0
 ORDER BY NomAutoridad
 ELSE
 SELECT IdAutoridad,NomAutoridad,Direccion,Inactivo
 FROM JurAutoridades
 WHERE IdAutoridad=@pmIdAutoridad
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCalifica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCalifica] @pmIdCalifica VARCHAR(4)
 AS 
 SELECT IdCalifica,CalificaCaso,IdClase,Inactivo
 FROM JurCalifica
 WHERE IdCalifica=@pmIdCalifica
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCalificaDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCalificaDso] @pmIdClase VARCHAR(4)=Null
 AS 
 SELECT IdCalifica,CalificaCaso,C.IdClase AS CdClase,ClaseAccdte
 FROM JurCalifica AS C INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase
 WHERE C.Inactivo=0 AND C.IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY CalificaCaso
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCasos] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,CasoID,IdCia,Fecha,Radicacion,IdVehiculo,IdPropietario,IdConductor,SinRecorrido,TipCar,Cartulina,IdCiaCar,FechaSuc,IdRuta,IdAbogado,IdAuxiliar,IdAutoridad,IdTipoPro,IdClase,IdCalifica,LugarAcc,CausaAcc
,Comentario,Observacion,Contraparte,DirContraparte,TelContraparte,ValDanosCParte,ValDanosEmp,ValDeducible,EmpAsegdora,AuxMutuo,ArchivoCaso,Documntos,Croquis,Anulado,FecDev,IdEstado,Reclamaciones
,CdCausal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,UndVehiculo,NumRemolque,TipActaJur,NumActaJur,CiaActaJur,EstadoProc,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_JurCasos
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasos_Cr] @pmTipDoc VARCHAR(3),@pmCasoIDIni INT,@pmCasoIDFin INT,@pmIdCia CHAR(2)
AS 
SELECT C.CasoID AS NumCaso,C.IdCia AS CodCia,Compania,C.Fecha,C.Radicacion,C.UndVehiculo,C.IdVehiculo AS PlacaVeh,C.NumRemolque,C.IdPropietario AS NitPropiterio,C.IdConductor AS CedConductor,SinRecorrido,C.TipCar,C.Cartulina,C.IdCiaCar,C.FechaSuc,C.IdRuta AS CodRuta,R.Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso,C.LugarAcc,C.CausaAcc,C.Comentario,C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,Item,QT.IdPregunta AS IdPregnta,PreguntaBas,QT.Descripcion AS RptaPregunta,Anulado, FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm
,Reclamaciones,CdCausal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,C.TipActaJur,C.NumActaJur,C.CiaActaJur,C.EstadoProc,C.IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,C.TipDoc AS CodTipo,TipoDoc,C.FecUpdate,C.TimeSys
--Datos del vehículo
,V.NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,V.Modelo,V.FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,V.NumMotor,V.SerieChasis,V.PasjerosPie,V.PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,V.TipoAfil,V.NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,V.EdoVincula,V.FecIngreso,V.FecVigencia,V.FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
--Datos remolque
,RQ.Modelo AS RemModelo,RQ.IdCrceria AS RemIdCar,TCR.TipoCar AS RemTipoCar,RQ.NumSerial,RQ.IdPropietario AS RemIdProp,PR.RazonSocial AS RemPropietario,RQ.VrComercial AS RemVrComercial,RQ.VrAvaludo AS RemVrAvaluo,RQ.VrAsegurado AS RemVrAsegurado,RQ.Descripcion AS RemDescripcion
,RQ.Tipo_Afil,RQ.EdoVincula AS RemEdoVincula,RQ.FechaVincula,RQ.FechaRetiro AS RemFecRetiro
 FROM Trn_JurCasos AS C INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero 
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 LEFT JOIN Rutas AS R ON C.IdRuta=R.IdRuta LEFT JOIN Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal 
 LEFT JOIN Trn_JurCasosQtn AS QT ON C.TipDoc=QT.TipDoc AND C.CasoID=QT.CasoID AND C.IdCia=QT.IdCia
 LEFT JOIN JurPreguntas AS JP ON QT.IdPregunta=JP.IdPregunta
 --tablas vehículo
 LEFT JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo LEFT JOIN TiposCol AS CO ON V.IdColor=CO.IdColor
 LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 LEFT JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero LEFT JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
 LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
 LEFT JOIN TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa
 --REMOLQUE
 LEFT JOIN VehRemolq AS RQ ON C.NumRemolque=RQ.IdRemque LEFT JOIN TiposCar AS TCR ON RQ.IdCrceria=TCR.IdCrceria
 LEFT JOIN Terceros AS PR ON RQ.IdPropietario=PR.IdTercero 
 WHERE C.TipDoc=@pmTipDoc AND C.CasoID BETWEEN @pmCasoIDIni AND @pmCasoIDFin
 AND (@pmIdCia IS NULL OR C.IdCia=@pmIdCia)
 ORDER BY C.IdCia,C.CasoID,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_Crh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasos_Crh] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT=Null
AS 
SELECT C.CasoID AS NumCaso, C.IdCia AS CodCia,Compania,C.Fecha,C.Radicacion,C.UndVehiculo,C.IdVehiculo AS PlacaVeh,C.NumRemolque,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,C.IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
,C.Contraparte,C.DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,ActualizaID, FechaUp, Historial, EstadoAct, CierreProc, ArchivoProc, NombreCparte, DirCparte, TelCparte,DanosCParte,DanosEmp,ValorDeducible,Aseguradora
,C.Reclamaciones,CdCausal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,AuxilioMutuo,C.TipActaJur,C.NumActaJur,C.CiaActaJur,C.EstadoProc,H.IdEstado AS His_IdEstado,H.IdUsuario AS His_IdUsuario,UH.Usuario AS His_Usuario,C.Anulado,C.FecDev
,C.IdEstado AS IdEstad,E.Estado AS EstadDocm,IdCiaCrea,C.IdUsuario AS IdUsuari,U.Usuario AS Cas_Usuario,C.TipDoc AS CodTipo,TipoDoc,C.FecUpdate,C.TimeSys
,V.NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,V.Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,V.NumMotor,V.SerieChasis,V.PasjerosPie,V.PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,V.EdoVincula,V.FecIngreso,V.FecVigencia,V.FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
--Datos remolque
,RQ.Modelo AS RemModelo,RQ.IdCrceria AS RemIdCar,TCR.TipoCar AS RemTipoCar,RQ.NumSerial,RQ.IdPropietario AS RemIdProp,PR.RazonSocial AS RemPropietario,RQ.VrComercial AS RemVrComercial,RQ.VrAvaludo AS RemVrAvaluo,RQ.VrAsegurado AS RemVrAsegurado,RQ.Descripcion AS RemDescripcion
,RQ.Tipo_Afil,RQ.EdoVincula AS RemEdoVincula,RQ.FechaVincula,RQ.FechaRetiro AS RemFecRetiro
 FROM Trn_JurCasos AS C INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN Trn_JurCasosHis AS H ON C.TipDoc=H.TipDoc AND C.CasoID=H.CasoID AND C.IdCia=H.IdCia
 INNER JOIN adm_Usuarios AS UH ON H.IdUsuario=UH.IdUsuario 
 LEFT JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo LEFT JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
 LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 LEFT JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero LEFT JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
 LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
 LEFT JOIN TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal
 LEFT JOIN Rutas AS R ON C.IdRuta=R.IdRuta
 LEFT JOIN VehRemolq AS RQ ON C.NumRemolque=RQ.IdRemque LEFT JOIN TiposCar AS TCR ON RQ.IdCrceria=TCR.IdCrceria
 LEFT JOIN Terceros AS PR ON RQ.IdPropietario=PR.IdTercero 
 WHERE  C.TipDoc=@pmTipDoc
 AND ( C.CasoID>=ISNULL(@pmCasoID,0)  AND  C.CasoID<=ISNULL(@pmCasoID,2147483647))
 AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND  ActualizaID<=ISNULL(@pmActualizaID,2147483647))
ORDER BY C.IdCia,C.CasoID,ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasos_Crr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
,@pmIdAbogado VARCHAR(16)=Null,@pmIdAuxiliar VARCHAR(16)=Null,@pmIdAutoridad VARCHAR(4)=Null,@pmIdTipoPro VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCalifica VARCHAR(4)=Null,@pmSinRecorrido BIT=Null
,@pmRadicacion VARCHAR(20)=Null,@pmCasoID INT=Null,@pmCartulina INT=Null,@pmFechaSuc SMALLDATETIME=Null,@pmIdRuta VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null
AS 
SELECT CasoID,C.IdCia AS CodCia,C.Fecha,C.Radicacion,C.UndVehiculo,C.IdVehiculo AS PlacaVeh,C.NumRemolque,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,C.IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso,C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,Reclamaciones,CdCausal,Causal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,C.TipActaJur,C.NumActaJur,C.CiaActaJur,C.EstadoProc
,Anulado,FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm,C.IdUsuario AS IdUsuari,Usuario,Compania,TipDoc,C.IdCiaCrea,C.FecUpdate,C.TimeSys
--Datos del vehículo
,V.NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,V.Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,V.NumMotor,V.SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,V.EdoVincula,V.FecIngreso,V.FecVigencia,V.FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
--Datos remolque
,RQ.Modelo AS RemModelo,RQ.IdCrceria AS RemIdCar,TCR.TipoCar AS RemTipoCar,RQ.NumSerial,RQ.IdPropietario AS RemIdProp,PR.RazonSocial AS RemPropietario,RQ.VrComercial AS RemVrComercial,RQ.VrAvaludo AS RemVrAvaluo,RQ.VrAsegurado AS RemVrAsegurado,RQ.Descripcion AS RemDescripcion
,RQ.Tipo_Afil,RQ.EdoVincula AS RemEdoVincula,RQ.FechaVincula,RQ.FechaRetiro AS RemFecRetiro
 FROM Trn_JurCasos AS C INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase
 INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 LEFT JOIN Rutas AS R ON C.IdRuta=R.IdRuta
 LEFT JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo LEFT JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
 LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 LEFT JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero LEFT JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
 LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
 LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa LEFT JOIN TercCndtores AS CT ON C.IdConductor=CT.IdConductor
 LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
 LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 LEFT JOIN VehRemolq AS RQ ON C.NumRemolque=RQ.IdRemque LEFT JOIN TiposCar AS TCR ON RQ.IdCrceria=TCR.IdCrceria
 LEFT JOIN Terceros AS PR ON RQ.IdPropietario=PR.IdTercero 
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  C.IdCia like ISNULL(@pmIdCia,'%%') AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND C.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND IdAbogado LIKE ISNULL(@pmIdAbogado,'%')
 AND IdAuxiliar LIKE ISNULL(@pmIdAuxiliar,'%') AND C.IdAutoridad LIKE ISNULL(@pmIdAutoridad,'%') AND C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 AND  C.IdClase LIKE ISNULL(@pmIdClase,'%') AND C.IdCalifica LIKE ISNULL(@pmIdCalifica,'%')   AND Radicacion LIKE ISNULL(@pmRadicacion,'%')
 AND (CasoID>=ISNULL(@pmCasoID,0)  AND CasoID<=ISNULL(@pmCasoID,2147483647))
  AND (Cartulina>=ISNULL(@pmCartulina,0)  AND Cartulina<=ISNULL(@pmCartulina,2147483647))
  AND (FechaSuc>=ISNULL(@pmFechaSuc,CAST('19100101' AS SMALLDATETIME)) AND FechaSuc<=ISNULL(@pmFechaSuc,CAST('20781230' AS SMALLDATETIME)))
  AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%') 
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
  AND  (SinRecorrido=ISNULL(@pmSinRecorrido,0) or SinRecorrido=ISNULL(@pmSinRecorrido,1))
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY C.IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasos_CrrH]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCasos_CrrH] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
,@pmIdAbogado VARCHAR(16)=Null,@pmIdAuxiliar VARCHAR(16)=Null,@pmIdAutoridad VARCHAR(4)=Null,@pmIdTipoPro VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCalifica VARCHAR(4)=Null,@pmSinRecorrido BIT=Null
,@pmRadicacion VARCHAR(20)=Null,@pmCasoID INT=Null,@pmCartulina INT=Null,@pmFechaSuc SMALLDATETIME=Null,@pmIdRuta VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmActualizaID INT=Null
AS 
SELECT C.CasoID AS NumCaso,C.IdCia AS CodCia,C.Fecha,C.Radicacion,C.UndVehiculo,C.IdVehiculo AS PlacaVeh,C.NumRemolque,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso,C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis,ActualizaID, FechaUp, Historial, EstadoAct, CierreProc, ArchivoProc,CedContparte, NombreCparte, DirCparte, TelCparte,DanosCParte,DanosEmp, ValorDeducible, Aseguradora
,AuxilioMutuo,Reclamaciones,CdCausal,Causal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,C.TipActaJur,C.NumActaJur,C.CiaActaJur,C.EstadoProc,H.IdEstado AS His_IdEstado,EH.Estado AS His_Estado,H.IdUsuario AS His_IdUsuario,UH.Usuario AS His_Usuario
,Anulado,FecDev,C.IdEstado AS IdEstad,E.Estado AS EstadDocm,C.IdUsuario AS IdUsuari,U.Usuario AS Usuario_Doc,Compania,C.TipDoc AS IdTipDcm,IdCiaCrea,C.FecUpdate,C.TimeSys
,V.NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,V.Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,V.NumMotor,V.SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,V.EdoVincula,V.FecIngreso,V.FecVigencia,V.FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.RazonSocial AS Propietario,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.RazonSocial AS Conductor,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
--Datos remolque
,RQ.Modelo AS RemModelo,RQ.IdCrceria AS RemIdCar,TCR.TipoCar AS RemTipoCar,RQ.NumSerial,RQ.IdPropietario AS RemIdProp,PR.RazonSocial AS RemPropietario,RQ.VrComercial AS RemVrComercial,RQ.VrAvaludo AS RemVrAvaluo,RQ.VrAsegurado AS RemVrAsegurado,RQ.Descripcion AS RemDescripcion
,RQ.Tipo_Afil,RQ.EdoVincula AS RemEdoVincula,RQ.FechaVincula,RQ.FechaRetiro AS RemFecRetiro
 FROM Trn_JurCasos AS C INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN Trn_JurCasosHis AS H ON C.TipDoc=H.TipDoc AND C.CasoID=H.CasoID AND C.IdCia=H.IdCia
 INNER JOIN adm_Usuarios AS UH ON H.IdUsuario=UH.IdUsuario INNER JOIN JurEstados AS EH ON H.IdEstado=EH.IdEstado
 LEFT JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo LEFT JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
 LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 LEFT JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero LEFT JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
 LEFT JOIN TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa  LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 LEFT JOIN Rutas AS R ON C.IdRuta=R.IdRuta LEFT JOIN TercCndtores AS CT ON C.IdConductor=CT.IdConductor
 LEFT JOIN Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
 LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN VehRemolq AS RQ ON C.NumRemolque=RQ.IdRemque LEFT JOIN TiposCar AS TCR ON RQ.IdCrceria=TCR.IdCrceria
 LEFT JOIN Terceros AS PR ON RQ.IdPropietario=PR.IdTercero 
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  C.IdCia like ISNULL(@pmIdCia,'%%') AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND C.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND IdAbogado LIKE ISNULL(@pmIdAbogado,'%')
 AND IdAuxiliar LIKE ISNULL(@pmIdAuxiliar,'%') AND C.IdAutoridad LIKE ISNULL(@pmIdAutoridad,'%') AND C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 AND  C.IdClase LIKE ISNULL(@pmIdClase,'%') AND C.IdCalifica LIKE ISNULL(@pmIdCalifica,'%')   AND Radicacion LIKE ISNULL(@pmRadicacion,'%')
 AND (C.CasoID>=ISNULL(@pmCasoID,0)  AND C.CasoID<=ISNULL(@pmCasoID,2147483647))
  AND (Cartulina>=ISNULL(@pmCartulina,0)  AND Cartulina<=ISNULL(@pmCartulina,2147483647))
  AND (FechaSuc>=ISNULL(@pmFechaSuc,CAST('19100101' AS SMALLDATETIME)) AND FechaSuc<=ISNULL(@pmFechaSuc,CAST('20781230' AS SMALLDATETIME)))
  AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%') 
AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
  AND  (SinRecorrido=ISNULL(@pmSinRecorrido,0) or SinRecorrido=ISNULL(@pmSinRecorrido,1))
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
  AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
 ORDER BY C.IdCia,C.CasoID,ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCasosHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT
 AS 
 SELECT TipDoc,CasoID,IdCia,ActualizaID,FechaUp,Historial,EstadoAct,CierreProc,ArchivoProc,NombreCparte,DirCparte,TelCparte,DanosCParte,DanosEmp,ValorDeducible,Aseguradora,AuxilioMutuo,CedContparte,IdEstado,IdUsuario
 FROM Trn_JurCasosHis
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
 ORDER BY ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosHisItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCasosHisItm]  @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2)
AS
 SELECT MAX(ActualizaID) AS MxItem
 FROM  Trn_JurCasosHis
 WHERE  TipDoc= @pmTipDoc AND CasoID= @pmCasoID AND IdCia= @pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosHisLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCasosHisLta]  @pmTipDoc VARCHAR(3), @pmCasoID INT=Null, @pmIdCia CHAR(2)=Null, @pmActualizaID INT=Null
,@pmFechaUp SMALLDATETIME=Null,@pmCierreProc BIT=Null,@pmIdEstado VARCHAR(4)=Null
AS
 SELECT  CasoID, ActualizaID, FechaUp, Historial, EstadoAct, CierreProc, ArchivoProc,CedContparte, NombreCparte, DirCparte, TelCparte
, DanosCParte,DanosEmp, ValorDeducible, Aseguradora, AuxilioMutuo,H.IdEstado AS IdEstad,Estado, H.IdUsuario AS IdUsuari,Usuario,TipDoc,IdCia
 FROM  Trn_JurCasosHis AS H INNER JOIN JurEstados AS E ON H.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON H.IdUsuario=U.IdUsuario
 WHERE  TipDoc= @pmTipDoc  AND (CasoID>=ISNULL(@pmCasoID,0)  AND CasoID<=ISNULL(@pmCasoID,2147483647))
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
  AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
  AND (FechaUp>=ISNULL(@pmFechaUp,CAST('19100101' AS SMALLDATETIME)) AND FechaUp<=ISNULL(@pmFechaUp,CAST('20781230' AS SMALLDATETIME)))
 AND (CierreProc=ISNULL(@pmCierreProc,0) or CierreProc=ISNULL(@pmCierreProc,1))
 AND H.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY IdCia,CasoID,ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasosLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmAnulado BIT=Null,@pmIdVehiculo VARCHAR(10)=Null
AS 
SELECT C.CasoID,C.IdCia,C.Fecha,C.Radicacion,C.UndVehiculo,C.IdVehiculo AS PlacaVeh,V.NumVeh,C.NumRemolque,C.IdPropietario AS NitPropiterio,T.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido,C.TipCar,C.Cartulina,C.IdCiaCar,C.FechaSuc,C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso,C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso,C.LugarAcc,CausaAcc,C.Comentario,C.Observacion AS Observ
,Cedtraparte,Contraparte,DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora,C.AuxMutuo,C.ArchivoCaso,C.Documntos,C.Croquis,Reclamaciones,CdCausal,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,TipActaJur,NumActaJur,CiaActaJur,EstadoProc,C.Anulado,C.FecDev,C.IdEstado AS IdEstad,Estado
,C.IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,TipDoc,C.FecUpdate,C.TimeSys
 FROM Trn_JurCasos AS C INNER JOIN Terceros AS T ON C.IdPropietario=T.IdTercero INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero 
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 LEFT JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo
 LEFT JOIN Rutas AS R ON C.IdRuta=R.IdRuta 
 WHERE C.TipDoc=@pmTipDoc AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND C.IdCia like ISNULL(@pmIdCia,'%%')
 AND C.IdVehiculo like ISNULL(@pmIdVehiculo,'%')
 AND (C.Anulado=ISNULL(@pmAnulado,0) or C.Anulado=ISNULL(@pmAnulado,1))
ORDER BY IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasosPen] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmAnulado BIT=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdTipoPro VARCHAR(4)=Null
,@pmIdClase VARCHAR(4)=Null
AS 
SELECT CasoID, IdCia, Fecha, Radicacion,C.IdVehiculo AS PlacaVeh,NumVeh,C.IdPropietario AS NitPropiterio,T.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, C.IdRuta AS CodRuta,Ruta
,IdAbogado,A.RazonSocial AS Abogado,IdAuxiliar,AX.RazonSocial AS Auxiliar,C.IdAutoridad AS IdAutrdad,NomAutoridad, C.IdTipoPro AS IdTProc,TipoProceso, C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso, LugarAcc, CausaAcc, Comentario, C.Observacion AS Observ
, Contraparte, DirContraparte,TelContraparte,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis, Anulado, FecDev,C.IdEstado AS IdEstad,Estado,Reclamaciones,CdCausal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg
,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,TipDoc,FecUpdate,TimeSys
 FROM Trn_JurCasos AS C  INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS T ON C.IdPropietario=T.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad
 INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta INNER JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro
 INNER JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase INNER JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
WHERE  TipDoc=@pmTipDoc AND C.IdEstado<>'9998' AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
  AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND C.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 AND C.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosQtnLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasosQtnLta] @pmTipDoc VARCHAR(3), @pmCasoID INT=Null, @pmIdCia CHAR(2)=Null, @pmItem INT=Null
,@pmIdPregunta VARCHAR(4)=Null
AS
 SELECT CasoID, Item, Q.IdPregunta AS IdPregnta,PreguntaBas,Descripcion,TipDoc,IdCia
 FROM  Trn_JurCasosQtn AS Q INNER JOIN JurPreguntas AS P ON Q.IdPregunta=P.IdPregunta
 WHERE  TipDoc=@pmTipDoc   
  AND (CasoID>=ISNULL(@pmCasoID,0)  AND CasoID<=ISNULL(@pmCasoID,2147483647))
  AND  IdCia like ISNULL(@pmIdCia,'%%') 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
  AND Q.IdPregunta like ISNULL(@pmIdPregunta,'%')
 ORDER BY IdCia,CasoID,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCasosRad]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCasosRad] @pmTipDoc VARCHAR(3),@pmRadicacion VARCHAR(20), @pmIdCia CHAR(2)=Null
AS 
SELECT   TipDoc, CasoID, IdCia, Fecha, Radicacion, IdVehiculo, IdPropietario, IdConductor, SinRecorrido, TipCar, Cartulina, IdCiaCar, FechaSuc, IdRuta
,IdAbogado, IdAuxiliar, IdAutoridad, IdTipoPro, IdClase, IdCalifica, LugarAcc, CausaAcc, Comentario, Observacion, Contraparte, DirContraparte,TelContraparte
,ValDanosCParte, ValDanosEmp, ValDeducible, EmpAsegdora, AuxMutuo, ArchivoCaso, Documntos, Croquis, Reclamaciones
,CdCausal,Cedtraparte,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,Anulado, FecDev,IdEstado, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
 FROM Trn_JurCasos
 WHERE  TipDoc=@pmTipDoc AND Radicacion=@pmRadicacion  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY  IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCausales]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurCausales] @pmIdCausal VARCHAR(4)
 AS 
 SELECT IdCausal,Causal,IdTipoPro,Inactivo
 FROM JurCausales
 WHERE IdCausal=@pmIdCausal
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCausalesDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCausalesDso] @pmIdTipoPro VARCHAR(4)=Null
 AS 
 SELECT IdCausal,Causal,Causal+' ('+ TipoProceso +') '+IdCausal AS DsCau
 FROM JurCausales AS C INNER JOIN JurTipos AS T ON C.IdTipoPro=T.IdTipoPro
 WHERE C.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')  AND  C.Inactivo=0
 ORDER BY Causal
GO
/****** Object:  StoredProcedure [dbo].[paQryJurCausalesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurCausalesLta] 
 AS 
 SELECT IdCausal,Causal,C.IdTipoPro AS CdTipoProc,TipoProceso
 FROM JurCausales AS C INNER JOIN JurTipos AS T ON C.IdTipoPro=T.IdTipoPro
 WHERE C.Inactivo=0
 ORDER BY Causal
GO
/****** Object:  StoredProcedure [dbo].[paQryJurClaseAcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurClaseAcc] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
 SELECT IdClase,ClaseAccdte
 FROM JurClaseAcc
 WHERE Inactivo=0 
 ORDER BY ClaseAccdte
 ELSE
 SELECT IdClase,ClaseAccdte,Inactivo
 FROM JurClaseAcc
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryJurDocumtos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurDocumtos] @pmIdDoc VARCHAR(4)
 AS 
 IF @pmIdDoc IS NULL
  SELECT IdDoc,Documnto
  FROM JurDocumtos
  WHERE Inactivo=0
 ORDER BY Documnto
 ELSE
  SELECT IdDoc,Documnto,Inactivo
  FROM JurDocumtos
  WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryJurEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurEstados] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor 
  FROM JurEstados
  WHERE  Inactivo=0
 ORDER BY IdEstado
 ELSE
 SELECT IdEstado,Estado,Inactivo,NColor
 FROM JurEstados
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvesHis]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurInvesHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT
 AS 
 SELECT TipDoc,CasoID,IdCia,ActualizaID,FechaUp,Historial,EstadoAct,Pruebas,Documntos,CierreProc,ArchivoProc
,NombreCparte,DirCparte,TelCparte,CedContparte,IdEstado,IdUsuario
 FROM Trn_JurInvesHis
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvesHisDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurInvesHisDso] @pmTipDoc VARCHAR(3), @pmCasoID INT=Null, @pmIdCia CHAR(2)=Null, @pmActualizaID INT=Null
,@pmFechaUp SMALLDATETIME=Null,@pmCierreProc BIT=Null,@pmIdEstado VARCHAR(4)=Null
AS
SELECT CasoID, ActualizaID, FechaUp, Historial, EstadoAct, Pruebas, Documntos, CierreProc, ArchivoProc,CedContparte, NombreCparte, DirCparte
, TelCparte,H.IdEstado AS IdEstad,Estado,H.IdUsuario AS IdUsuari ,Usuario,TipDoc,IdCia
 FROM  Trn_JurInvesHis AS H INNER JOIN JurEstados AS E ON H.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON H.IdUsuario=U.IdUsuario
 WHERE TipDoc=@pmTipDoc 
 AND (CasoID>=ISNULL(@pmCasoID,0)  AND CasoID<=ISNULL(@pmCasoID,2147483647))
 AND IdCia like ISNULL(@pmIdCia,'%%') 
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
 AND (FechaUp>=ISNULL(@pmFechaUp,CAST('19100101' AS SMALLDATETIME)) AND FechaUp<=ISNULL(@pmFechaUp,CAST('20781230' AS SMALLDATETIME)))
 AND  (CierreProc=ISNULL(@pmCierreProc,0) or CierreProc=ISNULL(@pmCierreProc,1))
 AND H.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY IdCia,CasoID,ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvesHisItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurInvesHisItm] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2)
AS
 SELECT MAX(ActualizaID) AS MxItem
 FROM  Trn_JurInvesHis
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurInvestiga] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,CasoID,IdCia,Fecha,Radicacion,IdAbogado,IdAuxiliar,IdAutoridad,IdEmpresa,Observacion,Contraparte,DirContraparte,TelContraparte
,ArchivoCaso,Anulado,FecDev,IdEstado,Cedtraparte,CdTipoPro,CdCausal,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_JurInvestiga
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryJurInvestiga_Cr]  @pmTipDoc VARCHAR(3),@pmCasoIDIni INT,@pmCasoIDFin INT,@pmIdCia CHAR(2)
AS
SELECT CasoID, C.IdCia AS CodCia, Fecha, Radicacion, IdAbogado,A.RazonSocial AS Abogado, IdAuxiliar,AX.RazonSocial AS Auxiliar, C.IdAutoridad AS IdAutordad,NomAutoridad,IdEmpresa,T.RazonSocial AS Empresa,T.Dv AS Emp_DvNit
,CdTipoPro,TipoProceso,CdCausal,Causal,C.Observacion AS Observ, Cedtraparte,Contraparte, DirContraparte,TelContraparte,ArchivoCaso, Anulado, FecDev, C.IdEstado AS IdEstad,Estado,C.IdUsuario AS IdUsuari,Usuario
,TipDoc,TipoDoc,Compania,IdCiaCrea,FecUpdate,TimeSys
 FROM Trn_JurInvestiga AS C  INNER JOIN  Terceros AS T ON C.IdEmpresa=T.IdTercero 
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero  INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero 
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Sys_TiposDoc  AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN JurTipos AS TP ON C.CdTipoPro=TP.IdTipoPro LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 WHERE  TipDoc=@pmTipDoc AND CasoID BETWEEN  @pmCasoIDIni AND @pmCasoIDFin 
 AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
ORDER BY C.IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_Crh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryJurInvestiga_Crh]  @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT=Null
AS
SELECT C.CasoID AS NumCaso, C.IdCia AS CodCia, Fecha, Radicacion, IdAbogado,A.RazonSocial AS Abogado, IdAuxiliar,AX.RazonSocial AS Auxiliar, C.IdAutoridad AS IdAutordad,NomAutoridad,IdEmpresa,T.RazonSocial AS Empresa,T.Dv AS Emp_DvNit
,CdTipoPro,TipoProceso,CdCausal,Causal,Cedtraparte,Contraparte, DirContraparte,TelContraparte,ArchivoCaso,C.Observacion AS Observ,ActualizaID, FechaUp, Historial, EstadoAct, Pruebas, Documntos, CierreProc, ArchivoProc,CedContparte, NombreCparte, DirCparte
, TelCparte,H.IdEstado AS His_IdEstado,HE.Estado AS His_Estado,H.IdUsuario AS His_IdUsuario ,UH.Usuario AS His_Usuario, Anulado, FecDev, C.IdEstado AS IdEstad,E.Estado AS EstadDoc,C.IdUsuario AS IdUsuari,U.Usuario AS Dcm_Usuario
,C.TipDoc AS TipDcm,TipoDoc,Compania,IdCiaCrea,FecUpdate,TimeSys
 FROM Trn_JurInvestiga AS C INNER JOIN Trn_JurInvesHis AS H ON C.TipDoc=H.TipDoc AND C.CasoID=H.CasoID AND C.IdCia=H.IdCia
 INNER JOIN  Terceros AS T ON C.IdEmpresa=T.IdTercero  INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero  
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero  INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad 
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN Companias   AS CI ON C.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc  AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN JurEstados AS HE ON H.IdEstado=HE.IdEstado INNER JOIN adm_Usuarios  AS UH ON H.IdUsuario=UH.IdUsuario 
 LEFT JOIN JurTipos AS TP ON C.CdTipoPro=TP.IdTipoPro LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 WHERE  C.TipDoc=@pmTipDoc 
 AND ( C.CasoID>=ISNULL(@pmCasoID,0)  AND  C.CasoID<=ISNULL(@pmCasoID,2147483647))
 AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND  ActualizaID<=ISNULL(@pmActualizaID,2147483647))
ORDER BY C.IdCia,C.CasoID,ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryJurInvestiga_Crr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdAbogado VARCHAR(16)=Null
,@pmIdAuxiliar VARCHAR(16)=Null,@pmIdEmpresa VARCHAR(16)=Null,@pmIdAutoridad VARCHAR(4)=Null,@pmRadicacion VARCHAR(20)=Null,@pmCasoID INT=Null
,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null
AS
SELECT CasoID, C.IdCia AS CodCia, Fecha, Radicacion, IdAbogado,A.RazonSocial AS Abogado, IdAuxiliar,AX.RazonSocial AS Auxiliar, C.IdAutoridad AS IdAutordad,NomAutoridad,IdEmpresa,T.RazonSocial AS Empresa,T.Dv AS Emp_DvNit
,C.Observacion AS Observ, CdTipoPro,TipoProceso,CdCausal,Causal,Cedtraparte,Contraparte, DirContraparte,TelContraparte,ArchivoCaso, Anulado, FecDev, C.IdEstado AS IdEstad,Estado,C.IdUsuario AS IdUsuari,Usuario,TipDoc,Compania,IdCiaCrea,FecUpdate,TimeSys
 FROM Trn_JurInvestiga AS C  INNER JOIN  Terceros AS T ON C.IdEmpresa=T.IdTercero 
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero  INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero 
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 LEFT JOIN JurTipos AS TP ON C.CdTipoPro=TP.IdTipoPro LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdAbogado LIKE ISNULL(@pmIdAbogado,'%')
 AND IdAuxiliar LIKE ISNULL(@pmIdAuxiliar,'%') AND IdEmpresa LIKE ISNULL(@pmIdEmpresa,'%') AND C.IdAutoridad LIKE ISNULL(@pmIdAutoridad,'%')
 AND (CasoID>=ISNULL(@pmCasoID,0)  AND CasoID<=ISNULL(@pmCasoID,2147483647))
 AND Radicacion LIKE ISNULL(@pmRadicacion,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
ORDER BY C.IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestiga_CrrH]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryJurInvestiga_CrrH]  @pmTipDoc VARCHAR(3), @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdAbogado VARCHAR(16)=Null
,@pmIdAuxiliar VARCHAR(16)=Null,@pmIdEmpresa VARCHAR(16)=Null,@pmIdAutoridad VARCHAR(4)=Null,@pmRadicacion VARCHAR(20)=Null,@pmCasoID INT=Null
,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmActualizaID INT=Null
AS
SELECT C.CasoID AS NumCaso, C.IdCia AS CodCia, Fecha, Radicacion, IdAbogado,A.RazonSocial AS Abogado, IdAuxiliar,AX.RazonSocial AS Auxiliar, C.IdAutoridad AS IdAutordad,NomAutoridad,IdEmpresa,T.RazonSocial AS Empresa,T.Dv AS Emp_DvNit
,C.Observacion AS Observ, CdTipoPro,TipoProceso,CdCausal,Causal,Cedtraparte,Contraparte, DirContraparte,TelContraparte,ArchivoCaso,ActualizaID, FechaUp, Historial, EstadoAct, Pruebas, Documntos, CierreProc, ArchivoProc,CedContparte, NombreCparte, DirCparte, TelCparte
,H.IdEstado AS His_IdEstado,HE.Estado AS His_Estado,H.IdUsuario AS His_IdUsuario ,UH.Usuario AS His_Usuario
,Anulado, FecDev, C.IdEstado AS IdEstad,E.Estado AS EstadoDcm,C.IdUsuario AS IdUsuari,U.Usuario AS UsuarioDcm,C.TipDoc AS TipDcm,Compania,IdCiaCrea,FecUpdate,TimeSys
 FROM Trn_JurInvestiga  AS C INNER JOIN Trn_JurInvesHis AS H ON C.TipDoc=H.TipDoc AND C.CasoID=H.CasoID AND C.IdCia=H.IdCia
 INNER JOIN  Terceros AS T ON C.IdEmpresa=T.IdTercero  INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero  
 INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero  INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad 
 INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia INNER JOIN JurEstados AS HE ON H.IdEstado=HE.IdEstado
 INNER JOIN adm_Usuarios AS UH ON H.IdUsuario=UH.IdUsuario 
 LEFT JOIN JurTipos AS TP ON C.CdTipoPro=TP.IdTipoPro LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 WHERE C.TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdAbogado LIKE ISNULL(@pmIdAbogado,'%')
 AND IdAuxiliar LIKE ISNULL(@pmIdAuxiliar,'%') AND IdEmpresa LIKE ISNULL(@pmIdEmpresa,'%') AND C.IdAutoridad LIKE ISNULL(@pmIdAutoridad,'%')
 AND (C.CasoID>=ISNULL(@pmCasoID,0)  AND C.CasoID<=ISNULL(@pmCasoID,2147483647))
 AND Radicacion LIKE ISNULL(@pmRadicacion,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (ActualizaID>=ISNULL(@pmActualizaID,0)  AND ActualizaID<=ISNULL(@pmActualizaID,2147483647))
ORDER BY C.IdCia,C.CasoID,ActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestigaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paQryJurInvestigaLta]  @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmAnulado BIT=Null,@pmIdAbogado VARCHAR(16)=Null,@pmIdEmpresa VARCHAR(16)=Null
AS
SELECT CasoID, C.IdCia AS CodCia, Fecha, Radicacion, IdAbogado,A.RazonSocial AS Abogado, IdAuxiliar,AX.RazonSocial AS Auxiliar, C.IdAutoridad AS IdAutordad,NomAutoridad,IdEmpresa,T.RazonSocial AS Empresa
,C.Observacion AS Observ,CdTipoPro,TipoProceso,CdCausal,Causal,Cedtraparte,Contraparte, DirContraparte,TelContraparte,ArchivoCaso, Anulado, FecDev, C.IdEstado AS IdEstad,Estado,C.IdUsuario AS IdUsuari,Usuario,TipDoc,Compania,IdCiaCrea,FecUpdate,TimeSys
 FROM Trn_JurInvestiga AS C  INNER JOIN  Terceros AS T ON C.IdEmpresa=T.IdTercero 
 INNER JOIN Terceros AS A ON C.IdAbogado=A.IdTercero  INNER JOIN Terceros AS AX ON C.IdAuxiliar=AX.IdTercero 
 INNER JOIN JurAutoridades AS AU ON C.IdAutoridad=AU.IdAutoridad INNER JOIN JurEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 LEFT JOIN JurTipos AS TP ON C.CdTipoPro=TP.IdTipoPro LEFT JOIN JurCausales AS CS ON C.CdCausal=CS.IdCausal
 WHERE  TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdAbogado like ISNULL(@pmIdAbogado,'%') AND IdEmpresa LIKE ISNULL(@pmIdEmpresa,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY C.IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurInvestigaRad]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryJurInvestigaRad]  @pmTipDoc VARCHAR(3),@pmRadicacion VARCHAR(20), @pmIdCia CHAR(2)=Null
AS
SELECT TipDoc, CasoID, IdCia, Fecha, Radicacion, IdAbogado, IdAuxiliar, IdAutoridad, IdEmpresa, Observacion, Contraparte, DirContraparte
, TelContraparte,Cedtraparte,CdTipoPro,CdCausal,ArchivoCaso, Anulado, FecDev, IdEstado, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
 FROM   Trn_JurInvestiga
 WHERE  TipDoc=@pmTipDoc AND Radicacion=@pmRadicacion  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY  IdCia,CasoID
GO
/****** Object:  StoredProcedure [dbo].[paQryJurPreguntas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurPreguntas] @pmIdPregunta VARCHAR(4)
 AS 
 SELECT IdPregunta,PreguntaBas,IdTipoPro,TipoDato,Inactivo
 FROM JurPreguntas
 WHERE IdPregunta=@pmIdPregunta
GO
/****** Object:  StoredProcedure [dbo].[paQryJurPreguntasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurPreguntasDso] @pmIdTipoPro VARCHAR(4)
 AS 
 SELECT IdPregunta,PreguntaBas,JP.IdTipoPro AS CdTipoPro,TipoProceso,TipoDato
 FROM JurPreguntas AS JP INNER JOIN JurTipos AS JT ON JP.IdTipoPro=JT.IdTipoPro
 WHERE JP.Inactivo=0 AND JP.IdTipoPro LIKE ISNULL(@pmIdTipoPro,'%')
 ORDER BY PreguntaBas
GO
/****** Object:  StoredProcedure [dbo].[paQryJurReclamac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurReclamac] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Reclamac,IdCia,Fecha,FechaRec,TipSin,Siniestro,IdCiaSin,IdReclamnte,IdTipoRec,VrReclamac,Observacion,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_JurReclamac
 WHERE TipDoc=@pmTipDoc AND Reclamac=@pmReclamac AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurReclamacFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryJurReclamacFmt] @pmTipDoc VARCHAR(3),@pmReclamacIni INT,@pmReclamacFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS TipRec,TipoDoc,R.Reclamac AS NumReclam,R.IdCia AS CdCia,Compania,R.Fecha AS FechaReclam,FechaRec,TipSin,Siniestro,IdCiaSin,FechaSuc,IdReclamnte,T.RazonSocial AS NomReclamante
,R.IdTipoRec AS CdTipoRec,TipReclamante,VrReclamac,R.Observacion AS Observ,R.OrigenAdd,R.TimeSys AS FechaCreacion,R.IdCiaCrea AS CdCiaCrea,R.IdUsuario AS CdUsuario,Usuario
,C.Radicacion,C.IdVehiculo AS PlacaVeh,NumVeh,C.IdPropietario AS NitPropiterio,NP.RazonSocial AS Propietario,C.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,SinRecorrido,TipCar,Cartulina,IdCiaCar
,IdAbogado,A.RazonSocial AS Abogado,C.IdTipoPro AS IdTProc,TipoProceso,C.IdClase AS IdClaAcc,ClaseAccdte, C.IdCalifica AS IdCalf,CalificaCaso,LugarAcc,CausaAcc,Comentario,C.Observacion AS SntroObserv
,Reclamaciones,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg
--detalles
,Item,FechaOfrec,VrOfrecmto,OfcAceptado,FecAceptado,OfcPagado,NumSolGiro,Comentarios
 FROM Trn_JurReclamac AS R INNER JOIN Companias  AS CI ON R.IdCia=CI.IdCia INNER JOIN Terceros AS T ON R.IdReclamnte=T.IdTercero
 INNER JOIN JurTiposRec AS TR ON R.IdTipoRec=TR.IdTipoRec  INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc 
 LEFT JOIN (SELECT TipDoc,CasoID,IdCia,Fecha,Radicacion,IdVehiculo,IdPropietario,IdConductor,SinRecorrido,TipCar,Cartulina,IdCiaCar,FechaSuc
,IdAbogado,IdTipoPro,IdClase,IdCalifica,LugarAcc,CausaAcc,Comentario,Observacion,Reclamaciones,PolizaResCivil,VigencResCivil,NitEmpAseg,NombreAseg,ArchivoCaso
 FROM Trn_JurCasos
 UNION ALL
 SELECT TipDoc,CasoID,IdCia,Fecha,Radicacion,'',IdEmpresa,IdAuxiliar,0,'0',0,'00',Fecha
,IdAbogado,CdTipoPro,'0','0','','','',Observacion,'','',Null,'','',ArchivoCaso FROM Trn_JurInvestiga) AS C ON R.TipSin=C.TipDoc AND R.Siniestro=C.CasoID AND R.IdCiaSin=C.IdCia
 LEFT JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo LEFT JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 LEFT JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero LEFT JOIN Terceros AS A ON C.IdAbogado=A.IdTercero
 LEFT JOIN JurTipos AS TP ON C.IdTipoPro=TP.IdTipoPro LEFT JOIN JurClaseAcc AS CA ON C.IdClase=CA.IdClase
 LEFT JOIN JurCalifica AS CL ON C.IdCalifica=CL.IdCalifica
 LEFT JOIN Trn_JurRecOfrecmto AS RO ON R.TipDoc=RO.TipDoc AND R.Reclamac=RO.Reclamac AND R.IdCia=RO.IdCia
 WHERE R.TipDoc=@pmTipDoc AND R.Reclamac BETWEEN @pmReclamacIni AND @pmReclamacFin AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryJurTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurTipos] @pmIdTipoPro VARCHAR(4)
 AS 
 IF @pmIdTipoPro IS NULL 
  SELECT IdTipoPro,TipoProceso 
  FROM JurTipos
  WHERE Inactivo=0
 ORDER BY IdTipoPro
 ELSE
  SELECT IdTipoPro,TipoProceso,Inactivo 
  FROM JurTipos
  WHERE IdTipoPro=@pmIdTipoPro
GO
/****** Object:  StoredProcedure [dbo].[paQryJurTiposRec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryJurTiposRec] @pmIdTipoRec VARCHAR(4)
 AS 
 IF @pmIdTipoRec IS NULL 
  SELECT IdTipoRec,TipReclamante
  FROM JurTiposRec
  WHERE Inactivo=0
 ORDER BY IdTipoRec
 ELSE
  SELECT IdTipoRec,TipReclamante,Inactivo
  FROM JurTiposRec
  WHERE IdTipoRec=@pmIdTipoRec
GO
/****** Object:  StoredProcedure [dbo].[paQryKardex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardex] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona
,pVehiculo,IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev
,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct
,CodTarIva,CodTarIca,CodTarRet,CodTarCom,CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,Temperatura
,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo,MgenCont,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq,BaseIvaCom,ImpCarbono,IngBaseCom,TarifaStc,SobtasaCons,CodTarIco,BaseIvp,TarifaIvp,IvaIngProd
,TarifaIba,VrImpuBa,CodTarBa,TarifaCup,VrImpuCup,CodTarCup,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardex_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardex_Cr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipDoc VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmnAnnoAnt INT=Null,@pmnMesAnt INT=Null
 AS 
 SELECT  K.IdProducto AS CdProducto,DescripProd,TipDoc,Documento,K.IdCia AS CdCia,Compania,Fecha,Item,K.IdBodega AS CdBodega,Bodega
,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,VrUnitario,VrCostoEnt,VrCostoSal,VrCostProm,VrPrecio,VrPrecio*(Entradas+Salidas) AS VrTotal,TarifaDct,VrDctoEnt,VrDctoSal
,TarifaIva,VrIvaEnt,VrIvaSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,VrIcaEnt,VrIcaSal,Unidades,K.Descripcion AS KarDescripcion,K.Referencia AS Referncia,Referencia2,FecOrden
,K.IdConcepto AS CdConcepto,Concepto,K.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,CdAgencia,Agencia,CodAgencia,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor,Comision
,CdOperario,OP.RazonSocial AS NomOperario,ComisnOper,pVehiculo,CdLocal,LK.Localidad AS KarCiudad,CdCCosto,CCosto,CdSubCos,SubCosto,TipOrd,NumOrden,IdCiaOrd,Factura,Remision,IdCiaRem,Cotizacion,IdCiaCot
,TipDocDev,NumDocDev,CdUbic,NumLote,FechLote,Comptmntos,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun
,Soldicom,ImpGlobal,OtroImpto,Rec_Costo,MgenCont,BaseIvaCom,ImpCarbono,BaseIvp,TarifaIvp,IvaIngProd,ListaPrec,VrBruto,VrBase,Servcios,NoVentas,EsCombo,EsProdBase,ItemCombo
,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,VrImvCosto,TarifaIco,VrImpCon,CodTarIco,TarifaStc,SobtasaCons,CantObseq,VrIvaObseq,IngBaseCom,K.CodTarBa,K.TarifaIba,K.VrImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup
,K.TarifaIat,K.VrAviTab,K.CodTarIat,K.TarifaBom,K.VrSobBom,K.CodTarBom,K.TimeSys,K.IdUsuario AS IdUsuari,Usuario,TipoDoc
--Datos del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono
--datos del producto
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,Tamano,Color,PM.UndMed AS CdUndMed,SU.Unidad AS ProdUnidad,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,IvaInc,IdTarIva,Tarifa,Simbolo
,Seriales,Lotes,Combo,Tanques,DescripLong,DescripAbrv,Precio1,Precio2,Precio3,Precio4,Precio5,IdProv,PV.RazonSocial AS NomProveedor
,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo AS ProdInactivo
--Información del saldo anterior
,SaldoAntProd,CostoAntProd,SaldoAntBod,CostoAntBod
 FROM Trn_Kardex AS K INNER JOIN Companias AS CN ON K.IdCia=CN.IdCia 
 INNER JOIN Sys_TiposDoc AS TD ON K.TipDoc=TD.IdDoc
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed   INNER JOIN Terceros AS PV ON PM.IdProv=PV.IdTercero
 INNER JOIN  Conceptos AS C ON K.IdConcepto=C.IdConcepto 
 INNER JOIN Terceros AS T ON K.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON K.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN Agencias  AS A ON K.CdAgencia=A.IdAgencia
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN  Localidades AS LK ON K.CdLocal=LK.IdLocal 
 LEFT JOIN Terceros AS OP ON K.CdOperario=OP.IdTercero
 LEFT JOIN Tablapor AS TI ON PM.IdTarIva=TI.IdTarifa
--Saldos anteriores
 LEFT JOIN (SELECT IdProducto,SUM(SaldoAnt+Entradas-Salidas) AS SaldoAntProd,SUM(CostoAnt+CostoEnt-CostoSal) AS CostoAntProd 
 FROM  AcuInventario
 WHERE  nAnno=@pmnAnnoAnt AND nMes=@pmnMesAnt
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 GROUP BY IdProducto) AS SP ON K.IdProducto=SP.IdProducto
--Saldos por bodega
 LEFT JOIN (SELECT IdProducto,IdBodega,SUM(SaldoAnt+Entradas-Salidas) AS SaldoAntBod,SUM(CostoAnt+CostoEnt-CostoSal) AS CostoAntBod
 FROM  AcuInventario
 WHERE  nAnno=@pmnAnnoAnt AND nMes=@pmnMesAnt
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 GROUP BY IdProducto,IdBodega) AS SB ON K.IdProducto=SB.IdProducto AND K.IdBodega=SB.IdBodega
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.TipDoc LIKE ISNULL(@pmTipDoc,'%') 
 AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND K.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexAdi]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexAdi] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)
 AS 
 SELECT IdCia,K.IdProducto AS CdProducto,DescripProd,SUM(Entradas) AS SCANENT,SUM(Salidas) AS SCANSAL
,SUM(VrCostoEnt) AS SCOSENT,SUM(VrCostoSal) AS SCOSSAL
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc IN ('FCR','FC1','FC2','FC3','FC4','FC5','DFC','DF1','DF2','DF3','DF4','DF5')
 AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia=@pmIdCia AND EsProdBase=0
 AND TipoRef='PRODUCTO' AND K.IdProducto IN (SELECT IdProducto FROM ProdAditivos)
 GROUP BY IdCia,K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexBDev] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT TipDev,Devolucion,F.IdCia AS CdCia,F.Fecha AS FechaDev,F.TipDoc AS TipoFact,F.Factura AS NumFact
,IdCiaDoc,FecDoc,IdCliente,IdAgencia,F.IdVend AS CdVend,TarifaCom,Modalidad,ModdDev
--datos del kardex
,K.IdProducto AS CdProducto,DescripProd,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,P.IdUnd AS CdUnid,Tanques
,SUM(Entradas) AS STOTENT,SUM(VrCostoEnt) AS STOTCOS,SUM(Entradas*VrPrecio) AS SVALTOT
,SUM(VrIvaEnt) AS STOTIVA,SUM(VrDctoEnt) AS STOTDCT
 FROM Trn_DevFcr AS F INNER JOIN Trn_Kardex AS K ON F.TipDev=K.TipDoc AND F.Devolucion=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
 WHERE TipDev IN ('DFC','DF1','DF2','DF3','DF4','DF5')  AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND NoVentas>0
 AND IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  TipDev,Devolucion,F.IdCia,F.Fecha,F.TipDoc,F.Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia
,F.IdVend,TarifaCom,Modalidad,ModdDev,K.IdProducto,DescripProd,TipoRef,P.IdSubgrupo,Subgrupo,P.IdUnd,Tanques
 ORDER BY TipDev,Devolucion,F.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBFcr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexBFcr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT F.TipDoc AS TipoFact,F.Factura AS NumFact,F.IdCia AS CdCia,F.Fecha AS FecFact,FechaVence,IdCliente,IdAgencia,IdCCosto,IdSubCos
,F.IdVend AS CdVend,TarifaCom,Modalidad,Anulado,NumDev
--datos del kardex
,K.IdProducto AS CdProducto,DescripProd,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,P.IdUnd AS CdUnid,Tanques
,SUM(Salidas) AS STOTSAL,SUM(VrCostoSal) AS STOTCOS,SUM(Salidas*VrPrecio) AS SVALTOT
,SUM(VrIvaSal) AS STOTIVA,SUM(VrDctoSal) AS STOTDCT
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
 WHERE F.TipDoc IN  ('FCR','FC1','FC2','FC3','FC4','FC5') AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND NoVentas>0
 AND IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY F.TipDoc,F.Factura,F.IdCia,F.Fecha,FechaVence,IdCliente,IdAgencia,IdCCosto,IdSubCos,F.IdVend,TarifaCom
,Modalidad,Anulado,NumDev,K.IdProducto,DescripProd,TipoRef,P.IdSubgrupo,Subgrupo,P.IdUnd,Tanques
 ORDER BY  F.TipDoc,F.Factura,F.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBIva]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexBIva] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT
,@pmIdCia CHAR(2)
 AS 
 SELECT Documento,TarifaIva,SUM((VrPrecio*Entradas)-VrDctoEnt) AS SBASEENT,SUM((VrPrecio*Salidas)-VrDctoSal) AS SBASESAL
,SUM(VrIvaEnt) AS SIVAENT,SUM(VrIvaSal) AS SIVASAL
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin
 AND IdCia=@pmIdCia AND (VrIvaEnt>0 OR VrIvaSal>0)
 GROUP BY  Documento,TarifaIva
 ORDER BY Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBIvac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexBIvac] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT
,@pmIdCia CHAR(2)
 AS 
 SELECT Documento,K.IdProducto AS CodProducto,DescripProd
,SUM(Entradas*TarifaIva) AS SIVAENT,SUM(Salidas*TarifaIva) AS SIVASAL
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin
 AND IdCia=@pmIdCia AND TarifaIva>0 AND Tanques<>0
 GROUP BY  Documento,K.IdProducto,DescripProd
 ORDER BY Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexBon] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,P.IdUnd AS CdUnid,Tanques
,SUM(Salidas) AS STOTSAL,SUM(VrCostoSal) AS STOTCOS,SUM(Salidas*VrPrecio) AS SVALTOT
,SUM(VrIvaSal) AS STOTIVA,SUM(VrDctoSal) AS STOTDCT
 FROM Trn_Facturas AS F INNER JOIN Trn_Kardex AS K ON F.TipDoc=K.TipDoc AND F.Factura=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
 WHERE F.TipDoc IN  ('FCR','FC1','FC2','FC3','FC4','FC5') AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND NoVentas>0
 AND IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  K.IdProducto,DescripProd,TipoRef,P.IdSubgrupo,Subgrupo,P.IdUnd,Tanques
 ORDER BY P.IdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexBond]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexBond] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,P.IdUnd AS CdUnid,Tanques
,SUM(Entradas) AS STOTENT,SUM(VrCostoEnt) AS STOTCOS,SUM(Entradas*VrPrecio) AS SVALTOT
,SUM(VrIvaEnt) AS STOTIVA,SUM(VrDctoEnt) AS STOTDCT
 FROM Trn_DevFcr AS F INNER JOIN Trn_Kardex AS K ON F.TipDev=K.TipDoc AND F.Devolucion=K.Documento AND F.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
 WHERE TipDev IN ('DFC','DF1','DF2','DF3','DF4','DF5')  AND F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND NoVentas>0
 AND IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  K.IdProducto,DescripProd,TipoRef,P.IdSubgrupo,Subgrupo,P.IdUnd,Tanques
 ORDER BY P.IdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexCc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)
 AS 
 SELECT IdProducto AS tmIdProducto,CdCCosto AS tmCdCCosto,CdSubCos AS tmCdSubCos
,CdLocal AS tmCdLocal,CodTarIca AS tmCodTarIca,CodTarRet AS tmCodTarRet,CodTarIat AS tmCodTarIat,CodTarBom AS tmCodTarBom
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexDoc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CodBodega,Bodega,CdTanque,Entradas+Salidas AS Cantidad,K.IdUnd AS IdUndad,Unidad,VrUnitario,(Entradas+Salidas)*VrUnitario AS CostoTotal
,VrPrecio,(Entradas+Salidas)*VrPrecio AS ValorTotal,K.Referencia AS Refncia,Descripcion,Unidades,TarifaDct,VrDctoEnt+VrDctoSal AS TotalDcto,TarifaIva,VrIvaEnt+VrIvaSal AS ValorIva
,TarifaRet,VrReteEnt+VrReteSal AS ValorRetFte,TarifaIca,VrIcaEnt+VrIcaSal AS ValorRetIca,K.TarifaIat,K.VrAviTab,K.TarifaBom,K.VrSobBom,ImpGlobal,CdMngra,NumInicial,NumFinal
,Servcios,TipoRef,Seriales,Lotes,Combo,Tanques,EsCombo,EsProdBase,ItemCombo,CdCCosto,CdSubCos,CdLocal,TipDocDev,NumDocDev
,IdVend,Comision,CdOperario,ComisnOper,CodTarDct,CodTarIva,CodTarRet,CodTarIca,CodTarCom,VrBruto,CdAgencia,pVehiculo,Comptmntos
,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,IvaIngProd,TipDoc,Documento,IdCia,Referencia2,TarifaIco,VrImpCon,CodTarBa,TarifaIba,VrImpuBa,CodTarCup,TarifaCup,VrImpuCup
--,VrCostProm,VrCostoEnt,VrCostoSal,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdSzona
--,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,Factura
--,,OtroImpto,NoVentas,CodTarCmc,ListaPrec,VrDivisa1,VrDivisa2,VrDivisa3,,FecOrden,TimeSys,IdUsuario,Fecha
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS U ON K.IdUnd=U.IdUnd
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexGTan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexGTan] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmEsCombo BIT=Null
 AS 
 SELECT  CdTanque,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND EsProdBase<2  AND Tanques<>0  AND TipoRef<>'SERVICIO'
 AND (EsCombo=ISNULL(@pmEsCombo,0) or EsCombo=ISNULL(@pmEsCombo,1))
 GROUP BY CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexMng]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexMng] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT CdMngra,NumInicial,NumFinal,K.IdProducto AS CdProducto,CdTanque,Entradas,Salidas,Servcios
 FROM Trn_Kardex  AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND Tanques<>0
 ORDER BY CdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexMovinv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexMovinv] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmCdLocal VARCHAR(8)=Null,@pmVentaIni INT=Null,@pmVentaFin INT=Null
 AS 
 SELECT TipDoc,K.IdCia AS CdCia,Compania,K.IdProducto AS CdProducto,DescripProd,K.IdBodega AS CdBodega,Bodega
,K.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,CdAgencia,Agencia,K.IdVend AS NitVend,VN.RazonSocial AS Vendedor
,CdLocal,Localidad,L.IdDep AS CodDep,Departamento,CdSzona,Subzona,SZ.IdZona AS CdZona,Zona,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed
--datos del producto
,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripAbrv,Precio1,Precio2,Precio3,Precio4,Precio5,IdProv,PV.RazonSocial AS NomProveedor
,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo AS ProdInactivo
--Datos del cliente
,T.IdSector AS CdSector,SectorEco,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.CdBandera AS CodBandera,TipoBandera
,SUM(Entradas) AS CantEnt,SUM(Salidas) AS CantSal,SUM(VrCostoEnt) AS CostoEnt,SUM(VrCostoSal) AS CostoSal
,SUM(VrPrecio*Entradas) AS ValorEnt,SUM(VrPrecio*Salidas) AS ValorSal,SUM(VrDctoEnt) AS DctosEnt,SUM(VrDctoSal) AS DctosSal
,SUM(VrIvaEnt) AS TotalIvaEnt,SUM(VrIvaSal) AS TotalIvaSal
,SUM(CASE WHEN Entradas>0 THEN K.Unidades ELSE K.Unidades*-1 END) AS UnidVolumen
 FROM Trn_Kardex AS K INNER JOIN Companias AS CN ON K.IdCia=CN.IdCia 
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS PV ON PM.IdProv=PV.IdTercero INNER JOIN Terceros AS T ON K.IdTercero=T.IdTercero
 INNER JOIN Terceros AS VN ON K.IdVend=VN.IdTercero
 LEFT JOIN Localidades AS L ON K.CdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN TercCliente AS CLI ON K.IdTercero=CLI.IdClie  LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera
 LEFT JOIN Agencias  AS A ON K.CdAgencia=A.IdAgencia
 LEFT JOIN  Subzonas AS SZ ON K.CdSzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND K.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND K.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND K.IdVend LIKE ISNULL(@pmIdVend,'%') AND CdLocal LIKE ISNULL(@pmCdLocal,'%')
 AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 AND PM.IdMarca LIKE ISNULL(@pmIdMarca,'%')
 AND NoVentas BETWEEN ISNULL(@pmVentaIni,0) AND ISNULL(@pmVentaFin,999999)
 GROUP BY  TipDoc,K.IdCia,Compania,K.IdProducto,DescripProd,K.IdBodega,Bodega
,K.IdTercero,T.RazonSocial,CdAgencia,Agencia,K.IdVend,VN.RazonSocial
,CdLocal,Localidad,L.IdDep,Departamento,CdSzona,Subzona,SZ.IdZona,Zona,K.IdUnd,UM.Unidad
,TipoRef,PM.IdSubgrupo,Subgrupo,S.IdGrupo,Grupo,G.IdLinea,Linea,PM.IdMarca,Marca
,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripAbrv,Precio1,Precio2,Precio3,Precio4,Precio5,IdProv,PV.RazonSocial
,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo
,T.IdSector,SectorEco,CLI.IdGrupo,GrupoClie,CLI.CdBandera,TipoBandera
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexMovTan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexMovTan] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,CdTanque,SUM(Entradas) AS TotalEnt,SUM(Salidas) AS TotalSal
,SUM(VrCostoEnt) AS TotalCosEnt,SUM(VrCostoSal) AS TotalCosSal
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE  Fecha  BETWEEN @pmFechaIni AND @pmFechaFin AND TipDoc NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','VCC')
 AND TipoRef<>'SERVICIO' AND Tanques=1 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY K.IdProducto,CdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexOdcCom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexOdcCom] @pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,COUNT(Documento) AS SCANT,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL
,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS  P ON K.IdProducto=P.IdProducto
 WHERE TipDoc IN ('COM','DEI')  AND  TipOrd=@pmTipOrd AND NumOrden=@pmNumOrden AND IdCiaOrd=@pmIdCiaOrd
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND  Servcios=0  
 GROUP BY  K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexOdcEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexOdcEnt] @pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,COUNT(Documento) AS SCANT,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL
,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS  P ON K.IdProducto=P.IdProducto
 WHERE TipDoc IN ('ENT','DVE')  AND  TipOrd=@pmTipOrd AND NumOrden=@pmNumOrden AND IdCiaOrd=@pmIdCiaOrd
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND  Servcios=0  
 GROUP BY  K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexOrd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexOrd] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Item,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,TipDocDev,NumDocDev
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPar] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmTipDocDev VARCHAR(3)
,@pmNumDocDev INT,@pmIdProducto VARCHAR(16),@pmItem INT
 AS 
 SELECT SUM(Entradas) AS SEnt,SUM(Salidas) AS SSal
 FROM Trn_Kardex
 WHERE TipDoc=@pmTipDoc AND IdCia=@pmIdCia AND TipDocDev=@pmTipDocDev AND NumDocDev=@pmNumDocDev
 AND IdProducto LIKE ISNULL(@pmIdProducto ,'%')
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPbas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPbas] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmIdProducto VARCHAR(16)
 AS 
 SELECT Item,K.IdProducto AS CdProducto,DescripProd,K.IdBodega AS CdBodega,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,VrUnitario,VrPrecio,VrCostProm
,VrBruto,K.Referencia AS Refncia,Descripcion,CdProdEquiv,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase
,ListaPrec,VrBase,TipoRef,Combo,Lotes,Seriales,Tanques
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND ItemCombo=@pmItem AND EsProdBase=1 AND EsCombo=0 AND CdProdEquiv=@pmIdProducto
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPedFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPedFac] @pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,COUNT(Documento) AS SCANT,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL
,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS  P ON K.IdProducto=P.IdProducto
 WHERE TipDoc IN ('FCO','FO1','FO2','FO3','FO4','FO5','DFO','DO1','DO2','DO3','DO4','DO5','FCR','FC1','FC2','FC3','FC4','FC5','DFC','DF1','DF2','DF3','DF4','DF5')
  AND  TipOrd=@pmTipOrd AND NumOrden=@pmNumOrden AND IdCiaOrd=@pmIdCiaOrd AND  Servcios=0
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') 
 GROUP BY  K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPedOcc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPedOcc] @pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmTipDoc VARCHAR(3),@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,COUNT(Documento) AS SCANT,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL
,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS  P ON K.IdProducto=P.IdProducto
 INNER JOIN Trn_OComb AS O ON K.TipDoc=O.TipDoc AND K.Documento=O.OCargue AND K.IdCia=O.IdCia
 WHERE TipOrd=@pmTipOrd AND NumOrden=@pmNumOrden AND IdCiaOrd=@pmIdCiaOrd
 AND K.TipDoc=@pmTipDoc AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND Anulado=0 AND Servcios=0 AND Tanques<>0
 GROUP BY  K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPedSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPedSal] @pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,COUNT(Documento) AS SCANT,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL
,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS  P ON K.IdProducto=P.IdProducto
 WHERE TipDoc IN ('SAL','DVS')  AND  TipOrd=@pmTipOrd AND NumOrden=@pmNumOrden AND IdCiaOrd=@pmIdCiaOrd
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND  Servcios=0  
 GROUP BY  K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPre] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT K.IdProducto AS CodProducto,DescripProd,TipoRef,VrCosto,VrCostPmd,IdTarIva,Tarifa,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,CdDctCom
,SUM(Entradas) AS STOTENT
 FROM Trn_Kardex  AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto INNER JOIN Tablapor AS T ON P.IdTarIva=T.IdTarifa
 WHERE TipDoc=@pmTipDoc  AND  Documento BETWEEN @pmDocumentoIni  AND @pmDocumentoFin
 AND IdCia=@pmIdCia
 GROUP BY K.IdProducto,DescripProd,TipoRef,VrCosto,VrCostPmd,IdTarIva,Tarifa,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,CdDctCom
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexPro] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,K.IdProducto AS CodProducto,DescripProd,Descripcion,ExtciaAct,VrCosto,VrCostPmd,K.IdBodega AS CodBodega,Bodega,CdTanque
,Entradas,Salidas,VrUnitario,VrUnitario*Entradas AS SCOSENT,VrUnitario*Salidas AS SCOSSAL
,VrPrecio,VrPrecio*Entradas AS SVALENT,VrPrecio*Salidas AS SVALSAL
,VrCostProm,VrBruto,CdProdEquiv,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase
,ExtciaMin,ExtciaMax,Seriales,Lotes,Combo,Tanques,Tallaje
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND TipoRef<>'SERVICIO'
 ORDER BY  K.IdProducto,K.IdBodega,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexProCc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexProCc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdSubgrupo,K.IdProducto AS tmIdProducto,DescripProd,TipoRef,IdProv,CdCCosto,CdSubCos
,CodTarIca,CodTarRet,pVehiculo,SUM(VrCostoEnt) AS SCOSENT,SUM(VrCostoSal) AS SCOSSAL
,SUM(VrPrecio*Entradas) AS SVALENT,SUM(VrPrecio*Salidas) AS SVALSAL
,SUM(VrBruto*Entradas) AS SBRUENT,SUM(VrBruto*Salidas) AS SBRUSAL
,SUM(CASE WHEN  Salidas>0 THEN VrIvaSal ELSE VrIvaEnt END) AS SIVA
,SUM(CASE WHEN  Salidas>0 THEN VrDctoSal ELSE VrDctoEnt END) AS SDCT
,SUM(CASE WHEN  Salidas>0 THEN VrReteSal ELSE VrReteEnt END) AS SRET
,SUM(CASE WHEN  Salidas>0 THEN VrIcaSal ELSE VrIcaEnt END) AS SICA
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc  AND Documento=@pmDocumento AND IdCia=@pmIdCia
 GROUP BY  IdSubgrupo,K.IdProducto,DescripProd,TipoRef,IdProv,CdCCosto,CdSubCos,CodTarIca,CodTarRet,pVehiculo
 ORDER BY IdSubgrupo,K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexReqSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexReqSal] @pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,COUNT(Documento) AS SCANT,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL
,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS  P ON K.IdProducto=P.IdProducto
 WHERE TipDoc IN ('SAI','DSI')  AND  TipOrd=@pmTipOrd AND NumOrden=@pmNumOrden AND IdCiaOrd=@pmIdCiaOrd
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND  Servcios=0  
 GROUP BY  K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSob]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexSob] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT CdLocal,K.IdProducto AS CdProducto,DescripProd,ISNULL(ZonaFrontera,0) AS ZonaFront
,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL,SUM(VrPrecio*Entradas) AS SVALENT,SUM(VrPrecio*Salidas) AS SVALSAL
,SUM(VrDctoEnt) AS SDCTENT,SUM(VrDctoSal) AS SDCTSAL
,SUM(Sobretasa*Entradas) AS SSOBENT,SUM(Sobretasa*Salidas) AS SSOBSAL
,SUM(TasaNac*Entradas) AS SNACENT,SUM(TasaNac*Salidas) AS SNACSAL
,SUM(TasaDep*Entradas) AS SDEPENT,SUM(TasaDep*Salidas) AS SDEPSAL
,SUM(TasaMun*Entradas) AS SMUNENT,SUM(TasaMun*Salidas) AS SMUNSAL
,SUM(Soldicom*Entradas) AS SSOLENT,SUM(Soldicom*Salidas) AS SSOLSAL
,SUM(ImpGlobal*Entradas) AS SGLOENT,SUM(ImpGlobal*Salidas) AS SGLOSAL
,SUM(VrBase*Entradas) AS SBASEENT,SUM(VrBase*Salidas) AS SBASESAL
,MAX(Sobretasa) AS MAXSOB,MAX(TasaNac) AS MAXNAC,MAX(TasaDep) AS MAXDEP
,MAX(TasaMun) AS MAXMUN
,MAX(VrPrecio) AS MAXPRECIO,MAX(VrBase) AS MAXBASE,MAX(VrBruto) AS MAXBRUTO
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 LEFT JOIN (SELECT TipDoc,Factura,IdCia,ZonaFrontera FROM Trn_Facturas WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Modalidad='COMBUSTBLE'
 UNION ALL SELECT TipDev,Devolucion,IdCia,ZonaFrontera FROM Trn_DevFcr WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Modalidad='COMBUSTBLE')
 AS F ON K.TipDoc=F.TipDoc AND K.Documento=F.Factura AND K.IdCia=F.IdCia
 WHERE K.TipDoc IN ('FCR','FC1','FC2','FC3','FC4','FC5','DFC','DF1','DF2','DF3','DF4','DF5','PLA','DVP','PAS','DNP')
 AND  K.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND P.Tanques<>0 AND K.NoVentas>0
 GROUP BY CdLocal,K.IdProducto,DescripProd,ISNULL(ZonaFrontera,0)
 ORDER BY CdLocal,K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSobtasa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexSobtasa] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null,@pmCdLocal VARCHAR(8)=Null,@pmIdDep VARCHAR(8)=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
 AS 
 SELECT K.IdTercero AS NitCliente,RazonSocial,CdAgencia,Agencia,CodAgencia,K.IdCia AS CdCia,Compania
,CdLocal,Localidad,LK.IdDep AS CodDep,Departamento,K.IdProducto AS  CdProducto,DescripProd,PM.IdUnd AS CdUnid,Unidad
,SUM(Entradas) AS TotalEnt,SUM(Salidas) AS TotalSal,SUM((Entradas*VrPrecio)-VrDctoEnt) AS VrTotalEnt,SUM((Salidas*VrPrecio)-VrDctoSal) AS VrTotalSal
,SUM(Sobretasa*Entradas) AS SobTasaEnt,SUM(Sobretasa*Salidas) AS SobTasaSal
,SUM(TasaNac*Entradas) AS TasaNacEnt,SUM(TasaNac*Salidas) AS TasaNacSal
,SUM(TasaDep*Entradas) AS TasaDepEnt,SUM(TasaDep*Salidas) AS TasaDepSal
,SUM(TasaMun*Entradas) AS TasaMunEnt,SUM(TasaMun*Salidas) AS TasaMunSal
,SUM(Soldicom*Entradas) AS SoldicomEnt,SUM(Soldicom*Salidas) AS SoldicomSal
,SUM(ImpGlobal*Entradas) AS ImpGlobalEnt,SUM(ImpGlobal*Salidas) AS ImpGlobalSal
,SUM(VrIvaEnt) AS TotalIvaEnt,SUM(VrIvaSal) AS TotalIvaSal,SUM(VrCostoEnt) AS CostoEnt,SUM(VrCostoSal) AS CostoSal
,MAX(VrPrecio) AS PrecioUnit,MAX(TarifaIva) AS TarifIva,MAX(Sobretasa) AS TarifSobtasa
,MAX(TasaNac) AS TarifNac,MAX(TasaDep) AS TarifDep,MAX(TasaMun) AS TarifMun,MAX(Soldicom) AS TarifSol,MAX(ImpGlobal) AS TarifIGlobal
,MAX(VrBruto) AS PrecioBase,MAX(VrBase) AS PrecioLista
,TipoId,Dv,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,DescripAbrv
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN UndMed AS U ON PM.IdUnd=U.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Companias AS CN ON K.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON K.IdTercero=T.IdTercero
 LEFT JOIN Localidades AS LK ON K.CdLocal=LK.IdLocal LEFT JOIN Departamentos AS DP ON LK.IdDep=DP.IdDep 
 LEFT JOIN Agencias  AS A ON K.CdAgencia=A.IdAgencia
 WHERE NoVentas IN (1,2,5,6) AND Tanques<>0 AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND EsProdBase<1 
 AND (Sobretasa>0 OR Soldicom>0 OR ImpGlobal>0)
 AND K.IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND K.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND CdLocal LIKE ISNULL(@pmCdLocal,'%') AND LK.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
 GROUP BY K.IdTercero,RazonSocial,CdAgencia,Agencia,CodAgencia,K.IdCia,Compania
,CdLocal,Localidad,LK.IdDep,Departamento,K.IdProducto,DescripProd,PM.IdUnd,Unidad
,TipoId,Dv,TipoRef,PM.IdSubgrupo,Subgrupo,S.IdGrupo,Grupo,G.IdLinea,Linea,DescripAbrv
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexSub] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdSubgrupo,K.IdProducto AS tmIdProducto,DescripProd,TipoRef,Combo,EsProdBase AS tmEsProdBase
,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo,COUNT(Item) AS SCANT,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
,SUM(CASE TipDoc WHEN 'ENT' THEN VrCostoEnt-((NumInicial*Entradas)+(VrImpuBa*Entradas)+(VrImpuCup*Entradas)) WHEN 'COM' THEN VrCostoEnt-((NumInicial*Entradas)+(VrImpuBa*Entradas)+(VrImpuCup*Entradas))
 ELSE VrCostoEnt END) AS SCOSENT
,SUM(CASE TipDoc WHEN 'DVE' THEN VrCostoSal-((NumInicial*Salidas)+(VrImpuBa*Salidas)+(VrImpuCup*Salidas)) WHEN 'DEI' THEN VrCostoSal-((NumInicial*Salidas)+(VrImpuBa*Salidas)+(VrImpuCup*Salidas))
 ELSE VrCostoSal END) AS SCOSSAL
,SUM(CASE WHEN CantObseq>0 AND Entradas>0 THEN VrPrecio*(Entradas-CantObseq) ELSE VrPrecio*Entradas END) AS SVALENT
,SUM(CASE WHEN CantObseq>0 AND Salidas>0 THEN VrPrecio*(Salidas-CantObseq) ELSE VrPrecio*Salidas END) AS SVALSAL
,SUM(CASE WHEN CantObseq>0 AND Entradas>0 THEN VrBruto*(Entradas-CantObseq) ELSE VrBruto*Entradas END) AS SBRUENT
,SUM(CASE WHEN CantObseq>0 AND Salidas>0 THEN VrBruto*(Salidas-CantObseq) ELSE VrBruto*Salidas END) AS SBRUSAL
,SUM(Entradas*ImpGlobal) AS SGLOENT,SUM(Salidas*ImpGlobal) AS SGLOSAL
,SUM(Sobretasa*Entradas) AS SSOBENT,SUM(Sobretasa*Salidas) AS SSOBSAL
,SUM(TasaNac*Entradas) AS SNACENT,SUM(TasaNac*Salidas) AS SNACSAL
,SUM(TasaDep*Entradas) AS SDEPENT,SUM(TasaDep*Salidas) AS SDEPSAL
,SUM(TasaMun*Entradas) AS SMUNENT,SUM(TasaMun*Salidas) AS SMUNSAL
,SUM(Soldicom*Entradas) AS SSOLENT,SUM(Soldicom*Salidas) AS SSOLSAL
,SUM(CASE WHEN Salidas>0 THEN (CASE WHEN CantObseq>0 THEN VrIvaSal-VrIvaObseq ELSE VrIvaSal END)
 ELSE (CASE WHEN CantObseq>0 THEN VrIvaEnt-VrIvaObseq ELSE VrIvaEnt END) END) AS SIVA
--SUM(CASE WHEN Salidas>0 THEN VrIvaSal ELSE VrIvaEnt END) AS SIVA
,SUM(CASE WHEN  Salidas>0 THEN VrDctoSal ELSE VrDctoEnt END) AS SDCT
,SUM(CASE WHEN  Salidas>0 THEN VrReteSal ELSE VrReteEnt END) AS SRET
,SUM(CASE WHEN  Salidas>0 THEN VrIcaSal ELSE VrIcaEnt END) AS SICA
,SUM(OtroImpto*Entradas) AS SOTRENT,SUM(OtroImpto*Salidas) AS SOTRSAL
,SUM(Rec_Costo*Entradas) AS SRCOSENT,SUM(Rec_Costo*Salidas) AS SRCOSSAL
,SUM(MgenCont*Entradas) AS SMGENENT,SUM(MgenCont*Salidas) AS SMGENSAL,SUM(VrImpCon) AS SVICO
,SUM(CASE WHEN CantObseq>0 THEN VrIvaObseq ELSE 0 END) AS SIVAOBSQ
,SUM(CantObseq*VrUnitario) AS SBASCOSOBSQ,SUM(CantObseq*VrPrecio) AS SBASEOBSQ
,SUM(BaseIvaCom*Entradas) AS BASEIVAENT,SUM(BaseIvaCom*Salidas) AS BASEIVASAL 
,SUM(ImpCarbono*Entradas) AS IMPCARBENT,SUM(ImpCarbono*Salidas) AS IMPCARBSAL 
,SUM(CASE WHEN (TarifaIva>0 AND P.TipoZonaFront='F') THEN ((Entradas*BaseIvaCom)*TarifaIva)/100 ELSE 0 END) AS SIVAZFENT
,SUM(CASE WHEN (TarifaIva>0 AND P.TipoZonaFront='F') THEN ((Salidas*BaseIvaCom)*TarifaIva)/100 ELSE 0 END) AS SIVAZFSAL
--Para los ajustes con cantidad en cero (0)
,SUM(VrUnitario) AS SCOSAJU,SUM(OtroImpto) AS SDVEAJU,SUM(VrImvCosto) AS SIMVCOS
,SUM(CASE WHEN Combo=0 AND EsProdBase=1 THEN BaseIvaCom ELSE 0 END) AS BASEIVACOM
,SUM(CASE WHEN Combo=1 AND IvaDetCombo=1 THEN IngBaseCom ELSE 0 END) AS INGBASECOM
,SUM(CASE WHEN Combo=0 AND EsProdBase=1 THEN IngBaseCom ELSE 0 END) AS SBASEING
,SUM(SobtasaCons) AS SOBTCON
,SUM(BaseIvp*Entradas) AS BASEIVPENT,SUM(BaseIvp*Salidas) AS BASEIVAING,SUM(IvaIngProd) AS SIVAINGP,MAX(TarifaIvp) AS TARIVAING
,SUM(VrImpuBa*(Entradas+Salidas+CantObseq)) AS SIMPUBA,SUM(VrImpuCup*(Entradas+Salidas+CantObseq)) AS SIMPUCUP
,SUM(VrAviTab) AS SIAT,SUM(VrSobBom) AS SBOM,SUM(CantObseq) AS CANTOBSQ
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 GROUP BY  IdSubgrupo,K.IdProducto,DescripProd,TipoRef,Combo,EsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo
 ORDER BY IdSubgrupo,K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSubc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexSubc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdSubgrupo,K.IdProducto AS tmIdProducto,DescripProd
,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
,SUM(VrCostoEnt) AS SCOSENT,SUM(VrCostoSal) AS SCOSSAL
,SUM(VrPrecio*Entradas) AS SVALENT,SUM(VrPrecio*Salidas) AS SVALSAL
,SUM(CASE WHEN  Salidas>0 THEN VrIvaSal ELSE VrIvaEnt END) AS SIVA
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND EsCombo<>0 AND Combo<>0 AND TipoRef<>'SERVICIO'  AND  EsProdBase=0
 GROUP BY IdSubgrupo,K.IdProducto,DescripProd
 ORDER BY IdSubgrupo,K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexSubOpe]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKardexSubOpe] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdSubgrupo,K.IdProducto AS tmIdProducto,DescripProd,TipoRef,Combo,EsProdBase AS tmEsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo,CdOperario AS tmCdOperario
,COUNT(Item) AS SCANT,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
,SUM(CASE TipDoc WHEN 'ENT' THEN VrCostoEnt-((NumInicial*Entradas)+(VrImpuBa*Entradas)+(VrImpuCup*Entradas)) WHEN 'COM' THEN VrCostoEnt-((NumInicial*Entradas)+(VrImpuBa*Entradas)+(VrImpuCup*Entradas))
 ELSE VrCostoEnt END) AS SCOSENT
,SUM(CASE TipDoc WHEN 'DVE' THEN VrCostoSal-((NumInicial*Salidas)+(VrImpuBa*Salidas)+(VrImpuCup*Salidas)) WHEN 'DEI' THEN VrCostoSal-((NumInicial*Salidas)+(VrImpuBa*Salidas)+(VrImpuCup*Salidas))
 ELSE VrCostoSal END) AS SCOSSAL
,SUM(CASE WHEN CantObseq>0 AND Entradas>0 THEN VrPrecio*(Entradas-CantObseq) ELSE VrPrecio*Entradas END) AS SVALENT
,SUM(CASE WHEN CantObseq>0 AND Salidas>0 THEN VrPrecio*(Salidas-CantObseq) ELSE VrPrecio*Salidas END) AS SVALSAL
,SUM(CASE WHEN CantObseq>0 AND Entradas>0 THEN VrBruto*(Entradas-CantObseq) ELSE VrBruto*Entradas END) AS SBRUENT
,SUM(CASE WHEN CantObseq>0 AND Salidas>0 THEN VrBruto*(Salidas-CantObseq) ELSE VrBruto*Salidas END) AS SBRUSAL
,SUM(Entradas*ImpGlobal) AS SGLOENT,SUM(Salidas*ImpGlobal) AS SGLOSAL
,SUM(Sobretasa*Entradas) AS SSOBENT,SUM(Sobretasa*Salidas) AS SSOBSAL
,SUM(TasaNac*Entradas) AS SNACENT,SUM(TasaNac*Salidas) AS SNACSAL
,SUM(TasaDep*Entradas) AS SDEPENT,SUM(TasaDep*Salidas) AS SDEPSAL
,SUM(TasaMun*Entradas) AS SMUNENT,SUM(TasaMun*Salidas) AS SMUNSAL
,SUM(Soldicom*Entradas) AS SSOLENT,SUM(Soldicom*Salidas) AS SSOLSAL
,SUM(CASE WHEN Salidas>0 THEN (CASE WHEN CantObseq>0 THEN VrIvaSal-VrIvaObseq ELSE VrIvaSal END)
 ELSE (CASE WHEN CantObseq>0 THEN VrIvaEnt-VrIvaObseq ELSE VrIvaEnt END) END) AS SIVA
--,SUM(CASE WHEN  Salidas>0 THEN VrIvaSal ELSE VrIvaEnt END) AS SIVA
,SUM(CASE WHEN  Salidas>0 THEN VrDctoSal ELSE VrDctoEnt END) AS SDCT
,SUM(CASE WHEN  Salidas>0 THEN VrReteSal ELSE VrReteEnt END) AS SRET
,SUM(CASE WHEN  Salidas>0 THEN VrIcaSal ELSE VrIcaEnt END) AS SICA
,SUM(OtroImpto*Entradas) AS SOTRENT,SUM(OtroImpto*Salidas) AS SOTRSAL
,SUM(Rec_Costo*Entradas) AS SRCOSENT,SUM(Rec_Costo*Salidas) AS SRCOSSAL
,SUM(MgenCont*Entradas) AS SMGENENT,SUM(MgenCont*Salidas) AS SMGENSAL,SUM(VrImpCon) AS SVICO
,SUM(CASE WHEN CantObseq>0 THEN VrIvaObseq ELSE 0 END) AS SIVAOBSQ
,SUM(CantObseq*VrUnitario) AS SBASCOSOBSQ,SUM(CantObseq*VrPrecio) AS SBASEOBSQ
,SUM(BaseIvaCom*Entradas) AS BASEIVAENT,SUM(BaseIvaCom*Salidas) AS BASEIVASAL 
,SUM(ImpCarbono*Entradas) AS IMPCARBENT,SUM(ImpCarbono*Salidas) AS IMPCARBSAL 
,SUM(CASE WHEN (TarifaIva>0 AND P.TipoZonaFront='F') THEN ((Entradas*BaseIvaCom)*TarifaIva)/100 ELSE 0 END) AS SIVAZFENT
,SUM(CASE WHEN (TarifaIva>0 AND P.TipoZonaFront='F') THEN ((Salidas*BaseIvaCom)*TarifaIva)/100 ELSE 0 END) AS SIVAZFSAL
--Para los ajustes con cantidad en cero (0)
,SUM(VrUnitario) AS SCOSAJU,SUM(OtroImpto) AS SDVEAJU,SUM(VrImvCosto) AS SIMVCOS
,SUM(CASE WHEN Combo=0 AND EsProdBase=1 THEN BaseIvaCom ELSE 0 END) AS BASEIVACOM
,SUM(CASE WHEN Combo=1 AND IvaDetCombo=1 THEN IngBaseCom ELSE 0 END) AS INGBASECOM
,SUM(CASE WHEN Combo=0 AND EsProdBase=1 THEN IngBaseCom ELSE 0 END) AS SBASEING
,SUM(SobtasaCons) AS SOBTCON
,SUM(BaseIvp*Entradas) AS BASEIVPENT,SUM(BaseIvp*Salidas) AS BASEIVAING,SUM(IvaIngProd) AS SIVAINGP,MAX(TarifaIvp) AS TARIVAING
,SUM(VrImpuBa*(Entradas+Salidas+CantObseq)) AS SIMPUBA,SUM(VrImpuCup*(Entradas+Salidas+CantObseq)) AS SIMPUCUP
,SUM(VrAviTab) AS SIAT,SUM(VrSobBom) AS SBOM,SUM(CantObseq) AS CANTOBSQ
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 GROUP BY  IdSubgrupo,K.IdProducto,DescripProd,TipoRef,Combo,EsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo,CdOperario
 ORDER BY IdSubgrupo,K.IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexTan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexTan] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,K.IdProducto AS CodProducto,DescripProd,Descripcion,ExtciaAct,VrCosto,VrCostPmd,K.IdBodega AS CodBodega,CdTanque
,Entradas,Salidas,VrUnitario,VrUnitario*Entradas AS SCOSENT,VrUnitario*Salidas AS SCOSSAL
,VrPrecio,VrPrecio*Entradas AS SVALENT,VrPrecio*Salidas AS SVALSAL
,VrCostProm,VrBruto,CdProdEquiv,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase
,ExtciaMin,ExtciaMax,Seriales,Lotes,Combo,TipoRef
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND  Tanques<>0
 ORDER BY  K.IdProducto,CdTanque,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKardexTdoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKardexTdoc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT K.IdProducto AS CodProducto,DescripProd,SUM(Entradas) AS STOTENT,SUM(Salidas) AS STOTSAL,SUM(Unidades) AS STOTUNI
 FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY K.IdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryKarUbic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryKarUbic] @pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,IdProducto,IdBodega,IdUbic,Entradas,Salidas,Fecha,Linea
 FROM Trn_KarUbic
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento 
 AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryKarUbicGru]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryKarUbicGru] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT U.IdProducto AS CodProducto,DescripProd,U.IdBodega AS CodBodega,U.IdUbic AS CodUbic,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
 FROM Trn_KarUbic AS U INNER JOIN ProdMcias AS P ON U.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento  AND IdCia=@pmIdCia 
 AND TipoRef<>'SERVICIO' 
 GROUP BY  U.IdProducto,DescripProd,U.IdBodega,U.IdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryLineas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLineas] @pmIdLinea VARCHAR(8)
 AS 
 SELECT IdLinea,Linea,TipoInvent,Inactivo
 FROM Lineas
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasCredCueLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLineasCredCueLta] @pmIdLinea VARCHAR(4)=Null
AS 
SELECT LN.IdLinea AS CdLinea,LinCredito,LN.IdTipoTerc AS CdTipoTerc,TipoTercero,Concepto,IdCuentaDb,P.NomCuenta AS NomCueDebito,IdCuentaCr,PC.NomCuenta AS NomCueCredito
FROM LineasCredCue AS LN INNER JOIN LineasCred AS L ON LN.IdLinea=L.IdLinea INNER JOIN TiposTerc AS T ON LN.IdTipoTerc=T.IdTipoTerc
LEFT JOIN Puc AS P ON LN.IdCuentaDb=P.IdCuenta LEFT JOIN Puc AS PC ON LN.IdCuentaCr=PC.IdCuenta
WHERE LN.IdLinea LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasCredLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLineasCredLta]
 AS 
 SELECT  IdLinea,LinCredito,CdTasaDef,TipoInteres,TasaEfectiva,CdTarifIva
,TIV.Tarifa AS TarifIva,CdTarifRet,TR.Tarifa AS TarifRet,PuntosTI
 FROM LineasCred AS L LEFT JOIN Tablapor AS TIV ON L.CdTarifIva=TIV.IdTarifa
 LEFT JOIN Tablapor AS TR ON L.CdTarifRet=TR.IdTarifa
 LEFT JOIN TasasInteres AS TA ON L.CdTasaDef=TA.IdTasa
 WHERE L.Inactivo=0
 ORDER BY LinCredito
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLineasDso] @pmTipoInvent VARCHAR(10)=Null
 AS 
 SELECT IdLinea,Linea,Linea+ ' '+IdLinea AS DsLin
 FROM Lineas
 WHERE Inactivo=0 AND TipoInvent LIKE ISNULL(@pmTipoInvent,'%')
 ORDER BY Linea
GO
/****** Object:  StoredProcedure [dbo].[paQryLineasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLineasLta] @pmTipoInvent VARCHAR(10)=Null
 AS 
  SELECT IdLinea,Linea,TipoInvent
  FROM Lineas
  WHERE Inactivo=0 AND TipoInvent LIKE ISNULL(@pmTipoInvent,'%')
  ORDER BY Linea
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLocalidades] @pmIdLocal VARCHAR(8)
 AS 
 SELECT IdLocal,Localidad,IdDep,TipLocal,Dist_Kmt,Time_hh,DistSede,TimeSede,CelRow,CelCol,CodAlias,Inactivo
 FROM Localidades
 WHERE IdLocal=@pmIdLocal
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesDep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLocalidadesDep] @pmIdLocal VARCHAR(8)
 AS 
 SELECT IdLocal,Localidad,L.IdDep AS CodDep,Departamento,TipLocal
 FROM Localidades AS L INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE IdLocal=@pmIdLocal
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLocalidadesDso] @pmIdDep VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdLocal,Localidad,L.IdDep AS CodDep,Departamento,TipLocal
, Localidad+ '  ('+ Departamento + ')' AS NomCiudad 
 FROM Localidades AS L INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE  L.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND (L.Inactivo=ISNULL(@pmInactivo,0) or  L.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Localidad,Departamento
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLocalidadesLta] @pmIdDep VARCHAR(8)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdLocal,Localidad,L.IdDep AS CodDep,Departamento,TipLocal,Dist_Kmt,Time_hh
,DistSede,TimeSede,CelRow,CelCol,CodAlias,L.Inactivo AS Inactvo
 FROM Localidades AS L INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE  L.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND (L.Inactivo=ISNULL(@pmInactivo,0) or  L.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Localidad
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLocalidadesNom] @pmLocalidad VARCHAR(50)
 AS 
 SELECT IdLocal,Localidad,IdDep,TipLocal
 FROM Localidades
 WHERE Localidad=@pmLocalidad
 ORDER BY IdLocal
GO
/****** Object:  StoredProcedure [dbo].[paQryLocalidadesPais]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLocalidadesPais] @pmIdPais VARCHAR(8)
 AS 
 SELECT L.IdLocal,L.Localidad,L.IdDep AS CodDep,D.Departamento,L.TipLocal
,L.Localidad+ ' ('+ D.Departamento +' '+P.CodISO+')' AS NomCiudad 
 FROM Localidades AS L INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN adm_Paises AS P ON D.IdPais=P.IdPais
 WHERE D.IdPais=@pmIdPais AND L.Inactivo=0
 ORDER BY Localidad
GO
/****** Object:  StoredProcedure [dbo].[paQryLog_Nomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLog_Nomina] @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8)
 AS 
 SELECT IdPeriodo,IdNom,Cerrado,IntCtaCte,LogCtaCte
 FROM Log_Nomina
 WHERE IdNom LIKE ISNULL(@pmIdNom,'%') AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 ORDER BY IdPeriodo,IdNom
GO
/****** Object:  StoredProcedure [dbo].[paQryLog_Periodos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLog_Periodos] @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdCia,Anno,Ene,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic,CierreAnno
 FROM Log_Periodos
 WHERE IdCia=@pmIdCia  AND Anno=@pmAnno
GO
/****** Object:  StoredProcedure [dbo].[paQryLog_PeriodosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLog_PeriodosLta] @pmAnno INT,@pmIdCia CHAR(2)
 AS 
 SELECT L.IdCia AS CdCia,Compania,Anno,Ene,Feb,Mar,Abr,May,Jun,Jul,Ago,Sep,Oct,Nov,Dic,CierreAnno
 FROM Log_Periodos AS L INNER JOIN Companias AS C ON L.IdCia=C.IdCia
 WHERE (Anno>=ISNULL(@pmAnno,0)  AND Anno<=ISNULL(@pmAnno,2147483647))
 AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER  BY L.IdCia,Anno
GO
/****** Object:  StoredProcedure [dbo].[paQryLotes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotes] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
,@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10)
 AS 
 SELECT NumLote,IdProducto,IdCia,IdBodega,IdUbic,Fecha,FecVence,SaldoActual,NitProv,TipDoc,Entrada,TimeSys
 FROM Trn_Lotes
 WHERE NumLote=@pmNumLote AND IdProducto=@pmIdProducto AND IdCia=@pmIdCia
 AND IdBodega=@pmIdBodega AND IdUbic LIKE ISNULL(@pmIdUbic,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryLotes_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotes_Cr] @pmFecha SMALLDATETIME,@pmSaldoActual DECIMAL(14,4),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmFecVenceIni SMALLDATETIME,@pmFecVenceFin SMALLDATETIME,@pmNumLote VARCHAR(30)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdBodega VARCHAR(4)=Null,@pmProdInac BIT=Null
,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null
 AS 
 SELECT L.IdCia AS CdCia,Compania,L.IdProducto AS CdProducto,DescripProd,NumLote,L.IdBodega AS CdBodega,Bodega
,Fecha,FecVence,DATEDIFF(day,@pmFecha,FecVence) AS DiasVence,SaldoActual,NitProv,RazonSocial,TipDoc,Entrada,L.IdUbic AS CdUbic,TimeSys
--datos del producto
,Referencia,CodBarras,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
,Tamano,P.IdUnd AS CdUnid,Unidad,Seriales,Combo,DescripLong,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5
,FecUltcom,FecUltVta,P.Inactivo AS Pro_Inactivo
 FROM Trn_Lotes AS L INNER JOIN ProdMcias AS P  ON L.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON L.IdBodega=B.IdBodega  INNER JOIN Companias AS CI ON L.IdCia=CI.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd 
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 LEFT JOIN Terceros AS T ON L.NitProv=T.IdTercero
 WHERE SaldoActual>@pmSaldoActual AND  NumLote LIKE ISNULL(@pmNumLote,'%')
 AND L.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND L.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND SG.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%') AND P.IdMarca LIKE ISNULL(@pmIdMarca,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME))) 
 AND (FecVence>=ISNULL(@pmFecVenceIni,CAST('19100101' AS SMALLDATETIME)) AND FecVence<=ISNULL(@pmFecVenceFin,CAST('20781230' AS SMALLDATETIME)))
 AND (P.Inactivo=ISNULL(@pmProdInac,0) or P.Inactivo=ISNULL(@pmProdInac,1))
 ORDER BY L.IdProducto,L.IdBodega,FecVence,NumLote
GO
/****** Object:  StoredProcedure [dbo].[paQryLotesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotesLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmFecVenceIni SMALLDATETIME,@pmFecVenceFin SMALLDATETIME,@pmNumLote VARCHAR(30)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdBodega VARCHAR(4)=Null,@pmProdInac BIT=Null
 AS 
 SELECT NumLote,Fecha,FecVence,SaldoActual,L.IdProducto AS CdProducto,DescripProd,L.IdBodega AS CdBodega,Bodega
,L.IdUbic AS IdUbica,NitProv,RazonSocial,TipDoc,Entrada,IdCia,TimeSys
 FROM Trn_Lotes AS L INNER JOIN ProdMcias AS P  ON L.IdProducto=P.IdProducto
  INNER JOIN Bodegas AS B ON L.IdBodega=B.IdBodega
 LEFT JOIN Terceros AS T ON L.NitProv=T.IdTercero
 WHERE NumLote LIKE ISNULL(@pmNumLote,'%') AND L.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND L.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME))) 
 AND (FecVence>=ISNULL(@pmFecVenceIni,CAST('19100101' AS SMALLDATETIME)) AND FecVence<=ISNULL(@pmFecVenceFin,CAST('20781230' AS SMALLDATETIME)))
 AND (P.Inactivo=ISNULL(@pmProdInac,0) or P.Inactivo=ISNULL(@pmProdInac,1))
 ORDER BY L.IdProducto,L.IdBodega,FecVence,NumLote
GO
/****** Object:  StoredProcedure [dbo].[paQryLotesPro]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotesPro] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)=Null
,@pmIdBodega VARCHAR(4)=Null,@pmIdUbic VARCHAR(10)=Null
 AS 
 SELECT NumLote,IdProducto,IdCia,IdBodega,IdUbic,Fecha,FecVence,SaldoActual,NitProv,TipDoc,Entrada,TimeSys
 FROM Trn_Lotes
 WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%') AND IdUbic LIKE ISNULL(@pmIdUbic,'%')
 ORDER BY IdBodega,IdCia,FecVence
GO
/****** Object:  StoredProcedure [dbo].[paQryLotesSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotesSal] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
,@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10)=Null
 AS 
 SELECT SUM(SaldoActual) AS SSALDO
 FROM Trn_Lotes
 WHERE NumLote=@pmNumLote AND IdProducto=@pmIdProducto AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdBodega LIKE ISNULL(@pmIdBodega,'%') AND IdUbic LIKE ISNULL(@pmIdUbic,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryLotMov] @pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,NumLote,IdProducto,IdBodega,CdUbic,Entradas,Salidas,Fecha,FecVence,Linea
 FROM Trn_LotMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMov_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotMov_Cr] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT M.TipDoc AS TipoDoc,Documento,M.IdCia AS CdCia,Item,M.NumLote AS Num_Lote,M.IdProducto AS CdProducto,DescripProd,M.IdBodega AS CdBodega,Bodega
,CdUbic,Entradas,Salidas,M.Fecha AS FechaDoc,M.FecVence AS Fec_Vence,Linea
--datos de lotes
,L.Fecha AS LotFecha,L.FecVence AS LotFecVence,SaldoActual,NitProv,RazonSocial,L.TipDoc AS TipoDocEnt,Entrada
 FROM Trn_LotMov  AS M INNER JOIN Trn_Lotes AS L ON M.NumLote=L.NumLote AND M.IdProducto=L.IdProducto
 AND M.IdCia=L.IdCia AND M.IdBodega=L.IdBodega
 INNER JOIN ProdMcias AS P ON M.IdProducto=P.IdProducto INNER JOIN Bodegas AS B ON M.IdBodega=B.IdBodega
 LEFT JOIN Terceros AS T ON L.NitProv=T.IdTercero 
 WHERE M.TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin  AND M.IdCia=@pmIdCia
 AND M.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMovGru]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotMovGru] @pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCia CHAR(2)
 AS 
 SELECT NumLote,M.IdProducto AS CodProducto,DescripProd,M.IdBodega AS CdBodega,CdUbic
,SUM(Entradas) AS SENT,SUM(Salidas) AS SSAL
 FROM  Trn_LotMov  AS M INNER JOIN ProdMcias AS P ON M.IdProducto=P.IdProducto
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 GROUP BY NumLote,M.IdProducto,DescripProd,M.IdBodega,CdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQryLotMovLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLotMovLta] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmLinea INT=Null
 AS 
 SELECT NumLote,FecVence,Linea,Entradas,Salidas,M.IdProducto AS CdProducto,DescripProd,M.IdBodega AS CdBodega
,Bodega,CdUbic,Fecha,Item,TipDoc,Documento,IdCia
 FROM Trn_LotMov  AS M INNER JOIN ProdMcias AS P ON M.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON M.IdBodega=B.IdBodega
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
 AND M.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND M.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND (Linea>=ISNULL(@pmLinea,0)  AND Linea<=ISNULL(@pmLinea,2147483647))
 ORDER BY NumLote
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMarcas] @pmIdMarca VARCHAR(4)
 AS 
 SELECT IdMarca,Marca,TipoMarca,CodigoMT,Inactivo
 FROM Marcas
 WHERE IdMarca=@pmIdMarca
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLin]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMarcasLin] @pmIdLinea VARCHAR(10)
 AS 
 SELECT IdLinea,LineaVeh,IdMarca,CodMT,Inactivo
 FROM MarcasLin
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLinDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMarcasLinDso] @pmIdMarca VARCHAR(4)=Null
 AS 
 SELECT IdLinea,LineaVeh,LineaVeh+IdLinea+' ('+Marca+')' AS DsLin
 FROM MarcasLin AS L INNER JOIN Marcas AS M ON L.IdMarca=M.IdMarca
 WHERE L.Inactivo=0 AND L.IdMarca LIKE ISNULL(@pmIdMarca,'%')
 ORDER BY Marca,LineaVeh
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLinLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMarcasLinLta] @pmIdMarca VARCHAR(4)=Null
 AS 
 SELECT IdLinea,LineaVeh,L.IdMarca AS CdMarca,Marca,CodMT,TipoMarca
 FROM MarcasLin AS L INNER JOIN Marcas AS M ON L.IdMarca=M.IdMarca
 WHERE L.Inactivo=0 AND L.IdMarca LIKE ISNULL(@pmIdMarca,'%')
 ORDER BY Marca,LineaVeh
GO
/****** Object:  StoredProcedure [dbo].[paQryMarcasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMarcasLta]  @pmTipoMarca VARCHAR(20)=Null
 AS 
 SELECT IdMarca,Marca,TipoMarca,CodigoMT
 FROM Marcas
 WHERE Inactivo=0  AND ( TipoMarca='GENERAL'  OR  TipoMarca LIKE ISNULL(@pmTipoMarca,'%') )
 ORDER BY Marca
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAgenciasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayAgenciasLta] @pmNContratoIni INT,@pmNContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Item,CA.IdAgencia AS CdAgencia,Agencia,CodAgencia,A.IdClie AS NitCliente,RazonSocial,A.IdLocal AS CdCiuAgenc,L.Localidad AS CiudadAgenc
,L.IdDep AS CdDptoAgenc,D.Departamento AS DptoAgenc,TelAgncia,FaxAgncia,CodSicom,A.FecIngreso AS Fec_Ingreso
,A.TipoZona AS AgeTipoZona,CdTipAgenc,TipoAgencia,CdSubAgenc,SubTipoAgenc,CdGrupAgenc,GrupoAgenc,CdSubGrupAgenc,SubGrupoAgenc
,Comentarios,A.Inactivo AS AgeInactivo,CA.NContrato AS NumContrato,IdCia
 FROM Trn_MayAgencias AS CA INNER JOIN Agencias AS A ON CA.IdAgencia=A.IdAgencia
 INNER JOIN Terceros AS T ON A.IdClie=T.IdTercero
 INNER JOIN Localidades AS L ON A.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN TiposAgenc AS TAG ON A.CdTipAgenc=TAG.IdTipAgenc LEFT JOIN TiposComAgenc AS STA ON A.CdSubAgenc=STA.IdSubAgenc
 LEFT JOIN GruposAgenc AS GA ON A.CdGrupAgenc=GA.IdGrupo LEFT JOIN SubGruposAgenc AS SGA ON A.CdSubGrupAgenc=SGA.IdSubAgenc
 WHERE CA.NContrato BETWEEN @pmNContratoIni AND @pmNContratoFin AND CA.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAnotaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayAnotaciones] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT Item,Fecha,Detalle,IdUsuario,NContrato,IdCia
 FROM Trn_MayAnotaciones
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAnotacionesItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayAnotacionesItm] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM Trn_MayAnotaciones
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayAnotacionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayAnotacionesLta] @pmNContratoIni INT,@pmNContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,Fecha,Detalle,A.IdUsuario AS CdUsuario,Usuario,NContrato,IdCia
 FROM Trn_MayAnotaciones AS A INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 WHERE NContrato BETWEEN @pmNContratoIni AND @pmNContratoFin AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayBonCuentas] @pmIdBonif VARCHAR(4),@pmTipoCue INT,@pmCdTipo VARCHAR(4)
 AS 
 SELECT IdBonif,TipoCue,CdTipo,IdCuenta
 FROM MayBonCuentas
 WHERE IdBonif=@pmIdBonif AND TipoCue=@pmTipoCue AND CdTipo=@pmCdTipo
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonCuentasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayBonCuentasLta] @pmIdBonif VARCHAR(4)=Null
 AS 
 SELECT C.IdBonif AS CdBonif,TipoBonif,TipoCue,CdTipo,C.IdCuenta AS CdCuenta,NomCuenta
 FROM MayBonCuentas AS C INNER JOIN MayTiposBonif  AS B ON C.IdBonif=B.IdBonif
 INNER JOIN  Puc AS P ON C.IdCuenta=P.IdCuenta
 WHERE C.IdBonif LIKE ISNULL(@pmIdBonif ,'%')
 ORDER BY C.IdBonif,TipoCue
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonCuentasTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayBonCuentasTip] @pmIdBonif VARCHAR(4),@pmCdTipo VARCHAR(4)
 AS 
 SELECT IdBonif,TipoCue,CdTipo,IdCuenta
 FROM MayBonCuentas
 WHERE IdBonif=@pmIdBonif  AND (CdTipo=@pmCdTipo  OR CdTipo='0')
 ORDER BY TipoCue,CdTipo
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayBonif] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT NContrato,IdCia,Item,TipoProd,VrInicial,VrFinal,Unidad,Tarifa,TipoTarifa,Periodo
,CdProducto,CdSubgrupo,TipoMargen,IntvExcluido,IntvGlobal,IvaIncluido
 FROM Trn_MayBonif
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia  
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifCant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayBonifCant] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT  COUNT(Item) AS SCANT
 FROM Trn_MayBonif
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayBonifDet] @pmNContrato INT,@pmIdCia CHAR(2),@pmTipoProd VARCHAR(20)=Null
 AS 
 SELECT Item,TipoProd,VrInicial,VrFinal,Unidad,Tarifa,TipoTarifa,Periodo,CdSubgrupo,TipoMargen,IntvExcluido,IntvGlobal,IvaIncluido
 FROM Trn_MayBonif
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia  AND CdSubgrupo<>'0'
 AND TipoProd LIKE ISNULL(@pmTipoProd,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayBonifItm] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM Trn_MayBonif
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayBonifLta] @pmNContratoIni INT,@pmNContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,TipoProd,VrInicial,VrFinal,Unidad,Periodo,IntvExcluido,TipoTarifa,Tarifa,TipoMargen
,CdSubgrupo,Subgrupo,IntvGlobal,IvaIncluido,NContrato,IdCia
 FROM Trn_MayBonif  AS  B  LEFT JOIN SubGrupos AS S ON B.CdSubgrupo=S.IdSubgrupo
 WHERE NContrato BETWEEN @pmNContratoIni AND @pmNContratoFin AND  IdCia=@pmIdCia  
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayBonifSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayBonifSub] @pmNContrato INT,@pmIdCia CHAR(2),@pmCdSubgrupo VARCHAR(8)=Null
,@pmTipoProd VARCHAR(20)=Null
 AS 
 SELECT Item,TipoProd,VrInicial,VrFinal,Unidad,Tarifa,TipoTarifa,Periodo,CdSubgrupo,TipoMargen,IntvExcluido,IntvGlobal,IvaIncluido
 FROM Trn_MayBonif
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia  
  AND CdSubgrupo LIKE ISNULL(@pmCdSubgrupo,'%')
  AND TipoProd LIKE ISNULL(@pmTipoProd,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContDoc] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT NContrato,IdCia,Item,IdDoc,FechaRad,Dependencia,Estado,FechaAprob,Comentarios,CdUsuario
 FROM Trn_MayContDoc
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocDep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContDocDep] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT Dependencia,COUNT(Item) AS SCANT
 FROM Trn_MayContDoc
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 GROUP BY Dependencia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayContDocItm] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM Trn_MayContDoc
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContDocLta] @pmNContratoIni INT,@pmNContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,Dependencia,D.IdDoc AS CdDoc,NombreDoc,FechaRad,Estado,Comentarios,FechaAprob
,CdUsuario,NContrato,IdCia
 FROM Trn_MayContDoc AS D INNER JOIN MayTiposDoc AS T ON D.IdDoc=T.IdDoc
 WHERE NContrato BETWEEN @pmNContratoIni AND @pmNContratoFin AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContDocPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContDocPen] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM Trn_MayContDoc
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia AND Estado<>'APROBADO'
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayContratos] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT NContrato,IdCia,Fecha,IdCliente,IdAgencia,IdTipo,IdBonif,ConvBonif,CuotaFija,CondPago,DiasGracia,ModPlazo,Plazo
,FechaVence,ModRecursos,VrInversion,VrInventario,VrCuota,ModCuota,IdBandera,IdVend,AprobJunta,FechaAprob,ObservAprob
,Observacion,IdEstado,FechaInicio,CuotaMin,TipoAprob,NumInterno,InvCombus,CuotaBase,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
,FechaFirma,CdAprobNeg,ArchivoAprob,ClaseContrato,DescTipoCont,GarantHipoteca,GarantPrenda,GarantPoliza,GarantBanco,GarantPagare
,GarantOtro,CdTipoBien,VrAvaludo,NroEscritura,CdTipoPoliza,DescPoliza,VigencPoliza,FecVencPoliza,ValorPoliza,EdoGarantias
,DescGarantOtro,InverContab,InverContrac,VolContMes,VolContTotal,VolViabMes,VolViabTotal,InvCtbObra,InvCtbCapital,InvCtbEfectivo,InvCtbImagen
,InvCtbMntmto,FecDesemb,InvContObra,InvContCapital,InvContEfectivo,InvContImagen,CrtlAprovInv,CrtlAprovImg,CdTipoBloq,EdoDocmtos,DescEdoDoc,RentabInicial,GraciaBonif
,ActFechaIni,CdZonaCont,ContVigente,VolContrac,DescHipotec,VrAvaComerc,FecRegEscritura,NotariaEsc,CdTipPrenda,VrAvaPrenda,PolizaPrenda,FecVigPrenda,VrAsegPrenda,ContOperando
 FROM Trn_MayContratos
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayContratos_Cr]  @pmNContratoIni INT=Null,@pmNContratoFin INT=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT C.NContrato AS NumContrato,C.IdCia AS CdCia,Compania,NumInterno,Fecha,FechaInicio,ActFechaIni,FechaFirma,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia
,ClaseContrato,C.IdTipo AS CdTipo,TipContrato,DescTipoCont,C.IdBonif AS CdBonif,TipoBonif,ConvBonif,CuotaFija,CondPago,C.DiasGracia AS Dias_Gracia
,ModPlazo,C.Plazo AS PlazoCont,FechaVence,VrCuota,ModCuota,CuotaMin,CuotaBase,GraciaBonif,C.IdBandera AS CdBandera,TipoBandera,CdZonaCont,TZN.TipoZona AS TipoZonaCont
,C.IdVend AS CdVend,V.RazonSocial AS Vendedor,AprobJunta,FechaAprob,ObservAprob,CdAprobNeg,TA.TipoAprob AS Tipo_Aprob,ArchivoAprob,C.Observacion AS Observ
,GarantHipoteca,GarantPrenda,GarantPoliza,GarantBanco,GarantPagare,GarantOtro,CdTipoBien,TipoBien,VrAvaludo,VrAvaComerc,NroEscritura,FecRegEscritura,NotariaEsc,DescHipotec
,CdTipoPoliza,TipoPoliza,DescPoliza,VigencPoliza,FecVencPoliza,ValorPoliza,CdTipPrenda,TipoPrenda,VrAvaPrenda,PolizaPrenda,FecVigPrenda,VrAsegPrenda,EdoGarantias,DescGarantOtro
,VolContrac,C.VolContMes AS VlmContMes,C.VolContTotal AS VlmContTotal,C.VolViabMes AS VlmViabMes,C.VolViabTotal AS VlmViabTotal,InverContab,InverContrac,C.InvCtbObra AS InvCntbObra,C.InvCtbCapital AS InvCntbCapital
,C.InvCtbEfectivo AS InvCntbEfe,C.InvCtbImagen AS InvCntbImagen,C.InvCtbMntmto AS InvCntbMnto,C.InvContObra AS InvConObra,C.InvContCapital AS InvConCapital,C.InvContEfectivo AS InvConEfe
,C.InvContImagen AS InvConImagen,C.FecDesemb AS FechaDesemb,C.CrtlAprovInv AS CntrolAprobInv,C.CrtlAprovImg AS CntrolAprobImagen,RentabInicial,ModRecursos,VrInversion,VrInventario,InvCombus
,ContVigente,ContOperando,C.IdEstado AS CdEstado,Estado,NColor,CdTipoBloq,TBO.TipoBloqueo AS ConTipoBloq,EdoDocmtos,C.DescEdoDoc AS ConDescEstdo,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
--datos de bonificaciones
,Item,TipoProd,VrInicial,VrFinal,Unidad,Tarifa,TipoTarifa,Periodo,CdProducto,DescripProd,CdSubgrupo,Subgrupo,TipoMargen,IntvExcluido,IntvGlobal
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo
,CLI.FecUpCupo AS FechaActCupo,Cmntario1,Cmntario2,Cmntario3,CLI.IdPlazo AS CliCdPlazo,PZ.Plazo AS PlazoCli,CLI.CdPlazoComb AS CdPlazoComb,PZC.Plazo AS PlazoComb,CdTipBloq,TBC.TipoBloqueo AS CliTipoBloq
,CLI.DescEdoDoc AS CliDescEdoDoc,EdoRadicaDoc,FecPlazoDoc
--agencias
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
,A.Referencia AS AgeReferencia,A.IdPlazo AS AgeCdPlazo,PZA.Plazo AS AgePlazo,A.CdPlazoComb AS AgeCdPlazoComb,PZAC.Plazo AS AgePlazoComb,VrCupoCre,A.FecUpCupo AS AgeFecActCupo,CodSicom
,A.FecIngreso AS AgeFecIngreso,Comentarios,A.TipoZona AS AgeTipoZona,CdTipAgenc,TipoAgencia,CdSubAgenc,SubTipoAgenc,CdGrupAgenc,GrupoAgenc
,CdSubGrupAgenc,SubGrupoAgenc,CdFntePago,FuentePago,PlazoSobtasa,DocFinanc,FecVigCond,TasaIntArranq
 FROM Trn_MayContratos AS C INNER JOIN MayTipos AS TC ON C.IdTipo=TC.IdTipo INNER JOIN MayTiposBonif AS B ON C.IdBonif=B.IdBonif
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia  INNER JOIN  MayEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN  TiposBan AS TB ON C.IdBandera=TB.IdBandera INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON C.IdCliente=CLI.IdClie
 INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo  INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 INNER JOIN Trn_MayBonif AS MB ON C.NContrato=MB.NContrato AND C.IdCia=MB.IdCia
 LEFT JOIN  TiposBloq AS TBO ON C.CdTipoBloq=TBO.IdTipBloq LEFT JOIN MayTiposAprob AS TA ON C.CdAprobNeg=TA.IdAprob
 LEFT JOIN MayTiposBienes AS TBN ON C.CdTipoBien=TBN.IdTipBien LEFT JOIN MayTiposPoliza AS TPZ ON C.CdTipoPoliza=TPZ.IdTipoPol
 LEFT JOIN TiposPrend AS TPD ON C.CdTipPrenda=TPD.IdPrend LEFT JOIN TiposZona AS TZN ON C.CdZonaCont=TZN.IdTipZona
 LEFT JOIN Plazos AS PZC ON CLI.CdPlazoComb=PZC.IdPlazo LEFT JOIN TiposBloq AS TBC ON CLI.CdTipBloq=TBC.IdTipBloq
 LEFT JOIN  Agencias   AS A ON C.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Plazos AS PZA ON A.IdPlazo=PZA.IdPlazo LEFT JOIN Plazos AS PZAC ON A.CdPlazoComb=PZAC.IdPlazo
 LEFT JOIN TiposAgenc AS TAG ON A.CdTipAgenc=TAG.IdTipAgenc LEFT JOIN TiposComAgenc AS STA ON A.CdSubAgenc=STA.IdSubAgenc
 LEFT JOIN GruposAgenc AS GA ON A.CdGrupAgenc=GA.IdGrupo LEFT JOIN SubGruposAgenc AS SGA ON A.CdSubGrupAgenc=SGA.IdSubAgenc
 LEFT JOIN FuentesPago AS FP ON A.CdFntePago=FP.IdFuente 
 LEFT JOIN SubGrupos AS SG ON MB.CdSubgrupo=SG.IdSubgrupo  LEFT JOIN ProdMcias AS PM ON MB.CdProducto=PM.IdProducto
 WHERE   C.NContrato BETWEEN ISNULL(@pmNContratoIni,0) AND ISNULL(@pmNContratoFin,2147483647)
 AND  C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosAct]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContratosAct]  @pmIdCia CHAR(2)=Null
 AS 
 SELECT C.NContrato AS NumContrato,IdCia,Fecha,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia
,IdTipo,C.IdBonif AS CdBonif,TipoBonif,AboCartera,AboPstmo,ConvBonif,CuotaFija,CondPago,C.DiasGracia AS Dias_Gracia,ModPlazo,C.Plazo AS PlazoCont
,FechaVence,VrCuota,ModCuota,C.IdBandera AS CdBandera,C.IdVend AS CdVend,C.IdEstado AS CdEstado,FechaInicio,CuotaMin,TipoAprob,NumInterno,InvCombus,CuotaBase
,FechaFirma,ClaseContrato,EdoDocmtos,GraciaBonif,ActFechaIni,ContOperando,ContVigente
--datos del cliente
,CL.IdPlazo AS CliCdPlazo,PZ.Plazo AS CliPlazo,PZ.NVmto AS CliNVce,PZ.DiasPago AS CliDiasPago
,CL.IdVend AS CliVend,VrCupo,VrSaldo,CL.IdEstado AS CliEstado
--datos de agencia
,A.IdPlazo AS AgeCdPlazo,PA.Plazo AS AgePlazo,PA.NVmto AS AgeNVce,PA.DiasPago AS AgeDiasPago
,A.IdVend AS AgeCdVend,VrCupoCre,VrSaldoAct,Referencia,A.IdEstado AS AgeEstado,A.Inactivo AS AgeInactivo
,FecVigCond,TasaIntArranq,AgencOperando,DocFinanc
 FROM Trn_MayContratos AS C INNER JOIN MayTiposBonif AS B ON C.IdBonif=B.IdBonif
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero  INNER JOIN TercCliente AS CL ON C.IdCliente=CL.IdClie
 INNER JOIN Plazos AS PZ ON CL.IdPlazo=PZ.IdPlazo
 LEFT JOIN  Agencias   AS A ON C.IdAgencia=A.IdAgencia  LEFT JOIN Plazos AS PA ON A.IdPlazo=PA.IdPlazo
 WHERE   C.IdEstado<>'0002' AND C.IdEstado<>'9999' AND AprobJunta>0 
 AND ( ConvBonif<>0 OR CuotaFija<>0) AND CL.Inactivo=0
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosCli]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContratosCli] @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmNContrato INT
 AS 
 SELECT NContrato,IdCia,Fecha,IdCliente,IdAgencia,IdTipo,IdBonif
 FROM Trn_MayContratos
 WHERE IdCliente=@pmIdCliente AND IdEstado IN ('0001','0002') AND (IdAgencia=@pmIdAgencia OR IdAgencia='0')
 AND NContrato<>@pmNContrato
 ORDER BY IdCia,NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContratosId] @pmIdCia CHAR(2)
 AS 
 SELECT MAX(NContrato) AS MXITM
 FROM Trn_MayContratos
 WHERE  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContratosLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdTipo VARCHAR(4)=Null
 AS 
 SELECT C.NContrato AS NumContrato,C.IdCia AS CdCia,Compania,Fecha,FechaInicio,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia,ClaseContrato,C.IdTipo AS CdTipo,TipContrato
,DescTipoCont,C.IdBonif AS CdBonif,TipoBonif,ConvBonif,CuotaFija,CondPago,C.DiasGracia AS Dias_Gracia,ModPlazo,Plazo,FechaVence,ModRecursos,VrInversion,VrInventario,VrCuota,CuotaMin,CuotaBase,ModCuota
,C.IdBandera AS CdBandera,TipoBandera,C.IdVend AS CdVend,V.RazonSocial AS Vendedor,TipoAprob,AprobJunta,FechaAprob,ObservAprob,C.Observacion AS Observ,NumInterno,InvCombus
,FechaFirma,CdAprobNeg,ArchivoAprob,GarantHipoteca,GarantPrenda,GarantPoliza,GarantBanco,GarantPagare
,GarantOtro,CdTipoBien,VrAvaludo,NroEscritura,CdTipoPoliza,DescPoliza,VigencPoliza,FecVencPoliza,ValorPoliza,EdoGarantias
,DescGarantOtro,InverContab,InverContrac,C.VolContMes AS VlmenContMes,C.VolContTotal AS VlmenContTotal,C.VolViabMes AS VlmenViabMes,C.VolViabTotal AS VlmenViabTotal,C.InvCtbObra AS VrCtbObra,C.InvCtbCapital AS VrCtbCapital
,C.InvCtbEfectivo AS VrCtbEfectivo,C.InvCtbImagen AS VrCtbImagen,C.InvCtbMntmto AS VrCtbMnto,C.FecDesemb AS FechDesemb,C.InvContObra AS VrContObra,C.InvContCapital AS VrContCaptial,C.InvContEfectivo AS VrContEfectivo,C.InvContImagen AS VrContImagen
,C.CrtlAprovInv AS ConCrtlInv,C.CrtlAprovImg AS ConCrtlImag,CdTipoBloq,EdoDocmtos,DescEdoDoc,RentabInicial,GraciaBonif,ActFechaIni,CdZonaCont,ContVigente,VolContrac,DescHipotec,VrAvaComerc,FecRegEscritura
,NotariaEsc,CdTipPrenda,VrAvaPrenda,PolizaPrenda,FecVigPrenda,VrAsegPrenda,ContOperando,C.IdEstado AS CdEstado,Estado,NColor,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
 FROM Trn_MayContratos AS C INNER JOIN MayTipos AS TC ON C.IdTipo=TC.IdTipo
 INNER JOIN MayTiposBonif AS B ON C.IdBonif=B.IdBonif INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia  INNER JOIN  MayEstados AS E ON C.IdEstado=E.IdEstado
 INNER JOIN  TiposBan AS TB ON C.IdBandera=TB.IdBandera INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero  LEFT JOIN  Agencias   AS A ON C.IdAgencia=A.IdAgencia
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND C.IdTipo LIKE ISNULL(@pmIdTipo,'%') 
 ORDER BY C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryMayContratosRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayContratosRel]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdTipo VARCHAR(4)=Null
 AS 
 SELECT C.NContrato AS NumContrato,C.IdCia AS CdCia,Compania,Fecha,FechaInicio,FechaFirma,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia,ClaseContrato,C.IdTipo AS CdTipo,TipContrato
,DescTipoCont,C.IdBonif AS CdBonif,TipoBonif,ConvBonif,CuotaFija,CondPago,C.DiasGracia AS Dias_Gracia,ModPlazo,C.Plazo AS PlazoContrato,FechaVence,VrCuota,CuotaMin,CuotaBase,ModCuota
,C.IdBandera AS CdBandera,TipoBandera,C.IdVend AS CdVend,V.RazonSocial AS Vendedor,CdAprobNeg,TA.TipoAprob AS Tipo_Aprob,AprobJunta,FechaAprob,ObservAprob,ArchivoAprob,C.Observacion AS Observ,NumInterno
,GarantHipoteca,GarantPrenda,GarantPoliza,GarantBanco,GarantPagare,GarantOtro,CdTipoBien,TipoBien,VrAvaludo,NroEscritura,CdTipoPoliza,TipoPoliza,DescPoliza,VigencPoliza,FecVencPoliza,ValorPoliza,EdoGarantias
,DescGarantOtro,InverContab,InverContrac,C.VolContMes AS VlmenContMes,C.VolContTotal AS VlmenContTotal,C.VolViabMes AS VlmenViabMes,C.VolViabTotal AS VlmenViabTotal,C.InvCtbObra AS VrCtbObra,C.InvCtbCapital AS VrCtbCapital
,ModRecursos,VrInversion,VrInventario,InvCombus,C.InvCtbEfectivo AS VrCtbEfectivo,C.InvCtbImagen AS VrCtbImagen,C.InvCtbMntmto AS VrCtbMnto,C.FecDesemb AS FechDesemb,C.InvContObra AS VrContObra,C.InvContCapital AS VrContCaptial
,C.InvContEfectivo AS VrContEfectivo,C.InvContImagen AS VrContImagen,C.CrtlAprovInv AS ConCrtlInv,C.CrtlAprovImg AS ConCrtlImag,CdTipoBloq,TBO.TipoBloqueo AS ConTipoBloq,EdoDocmtos,C.DescEdoDoc AS ConDescEstdo,RentabInicial,GraciaBonif
,ActFechaIni,CdZonaCont,TZN.TipoZona AS TipoZonaCont,ContVigente,VolContrac,DescHipotec,VrAvaComerc,FecRegEscritura,NotariaEsc,CdTipPrenda,TipoPrenda,VrAvaPrenda,PolizaPrenda,FecVigPrenda,VrAsegPrenda,ContOperando
,C.IdEstado AS CdEstado,Estado,NColor,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,dbo.FuncMayAgencias(C.NContrato,C.IdCia) AS CantAgencias,dbo.FuncMayBonifTarif(C.NContrato,C.IdCia)  AS TarifBonif
,dbo.FuncMayNomAgencia(C.NContrato,C.IdCia) AS NombreEds
--datos cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,CLI.FecUpCupo AS FechaActCupo,Cmntario1,Cmntario2,Cmntario3
,CLI.IdPlazo AS CliCdPlazo,PZ.Plazo AS PlazoCli,CLI.CdPlazoComb AS CdPlazoComb,PZC.Plazo AS PlazoComb,CdTipBloq,TBC.TipoBloqueo AS CliTipoBloq ,CLI.DescEdoDoc AS CliDescEdoDoc,EdoRadicaDoc,FecPlazoDoc
--agencia
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.IdPlazo AS AgeCdPlazo,PZA.Plazo AS AgePlazo,A.CdPlazoComb AS AgeCdPlazoComb,PZAC.Plazo AS AgePlazoComb,VrCupoCre,A.FecUpCupo AS AgeFecActCupo,CodSicom,A.FecIngreso AS AgeFecIngreso,Comentarios
,A.TipoZona AS AgeTipoZona,CdTipAgenc,TipoAgencia,CdSubAgenc,SubTipoAgenc,CdGrupAgenc,GrupoAgenc,CdSubGrupAgenc,SubGrupoAgenc,CdFntePago,FuentePago,PlazoSobtasa,DocFinanc,FecVigCond,TasaIntArranq
 FROM Trn_MayContratos AS C INNER JOIN MayTipos AS TC ON C.IdTipo=TC.IdTipo
 INNER JOIN MayTiposBonif AS B ON C.IdBonif=B.IdBonif INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliente AS CLI ON C.IdCliente=CLI.IdClie  INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia 
 INNER JOIN  MayEstados AS E ON C.IdEstado=E.IdEstado INNER JOIN  TiposBan AS TB ON C.IdBandera=TB.IdBandera
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero 
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo 
 LEFT JOIN  TiposBloq AS TBO ON C.CdTipoBloq=TBO.IdTipBloq LEFT JOIN MayTiposAprob AS TA ON C.CdAprobNeg=TA.IdAprob
 LEFT JOIN MayTiposBienes AS TBN ON C.CdTipoBien=TBN.IdTipBien LEFT JOIN MayTiposPoliza AS TPZ ON C.CdTipoPoliza=TPZ.IdTipoPol
 LEFT JOIN TiposPrend AS TPD ON C.CdTipPrenda=TPD.IdPrend LEFT JOIN TiposZona AS TZN ON C.CdZonaCont=TZN.IdTipZona
 LEFT JOIN Plazos AS PZC ON CLI.CdPlazoComb=PZC.IdPlazo LEFT JOIN TiposBloq AS TBC ON CLI.CdTipBloq=TBC.IdTipBloq
 LEFT JOIN  Agencias   AS A ON C.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Plazos AS PZA ON A.IdPlazo=PZA.IdPlazo LEFT JOIN Plazos AS PZAC ON A.CdPlazoComb=PZAC.IdPlazo
 LEFT JOIN TiposAgenc AS TAG ON A.CdTipAgenc=TAG.IdTipAgenc LEFT JOIN TiposComAgenc AS STA ON A.CdSubAgenc=STA.IdSubAgenc
 LEFT JOIN GruposAgenc AS GA ON A.CdGrupAgenc=GA.IdGrupo LEFT JOIN SubGruposAgenc AS SGA ON A.CdSubGrupAgenc=SGA.IdSubAgenc
 LEFT JOIN FuentesPago AS FP ON A.CdFntePago=FP.IdFuente 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND C.IdTipo LIKE ISNULL(@pmIdTipo,'%') 
 ORDER BY C.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryMayEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayEstados] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  SELECT IdEstado,Estado,NColor
  FROM MayEstados
  WHERE Inactivo=0
 ORDER BY  IdEstado
 ELSE
  SELECT IdEstado,Estado,NColor,Inactivo
  FROM MayEstados
  WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayInventario] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT NContrato,IdCia,Item,IdArticulo,Detalle,Cantidad,VrUnitario,VrTotal,TipoArticulo,Referencia,IdTipo
,TipDoc,Documento,IdCiaDoc,CantEntrega,FecEntrega,Estado
,CdProd,NumReq,IdCiaReq,CantReq,NumOrden,IdCiaOrd,CantOrden
 FROM Trn_MayInventario
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia  
  AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventarioItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayInventarioItm] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM  FROM Trn_MayInventario
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventarioLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayInventarioLta] @pmNContratoIni INT,@pmNContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,I.IdArticulo AS CodArticulo,Detalle,Cantidad,UndMed,VrUnitario,VrTotal,TipoArticulo,Referencia
,I.IdTipo AS CdTipo,TipContrato,Estado,NumReq,IdCiaReq,CantReq,NumOrden,IdCiaOrd,CantOrden
,TipDoc,Documento,IdCiaDoc,CantEntrega,FecEntrega,NContrato,IdCia,CdProd,Descrpcion
 FROM Trn_MayInventario AS I INNER JOIN MayItemsInv AS R ON I.IdArticulo=R.IdArticulo
 INNER JOIN MayTipos AS T ON I.IdTipo=T.IdTipo
 WHERE NContrato BETWEEN @pmNContratoIni AND @pmNContratoFin AND IdCia=@pmIdCia  
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayInventarioTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayInventarioTot] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT COUNT(Item) AS SCOUNT,SUM(Cantidad) AS SCANT,SUM(VrTotal) AS SVALTOT
,SUM(CantEntrega) AS SCANENT,SUM(CantReq) AS SCANTREQ,SUM(CantOrden) AS SCANTODC
 FROM Trn_MayInventario
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayItemsInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayItemsInv] @pmIdArticulo VARCHAR(16)
 AS 
 SELECT IdArticulo,Descrpcion,UndMed,GrupoArt,CdProducto,Inactivo
 FROM MayItemsInv
 WHERE IdArticulo=@pmIdArticulo
GO
/****** Object:  StoredProcedure [dbo].[paQryMayItemsInvGru]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayItemsInvGru]
 AS 
 SELECT GrupoArt,count(IdArticulo) AS SCANT
 FROM MayItemsInv
 WHERE Inactivo=0
 GROUP BY GrupoArt
GO
/****** Object:  StoredProcedure [dbo].[paQryMayItemsInvLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayItemsInvLta] @pmInactivo BIT=Null
 AS 
 SELECT IdArticulo,Descrpcion,I.UndMed AS Umed,Unidad,GrupoArt,CdProducto,DescripProd,I.Inactivo AS Inactiv
 FROM MayItemsInv AS I INNER JOIN   Sys_Um AS U ON I.UndMed=U.UndMed
 LEFT JOIN  ProdMcias AS P ON I.CdProducto=P.IdProducto
 WHERE  (I.Inactivo=ISNULL(@pmInactivo,0) or I.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Descrpcion
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqDetalleLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiqDetalleLta] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.NContrato AS NumContrato,IdCiaCon,Item,D.IdSubgrupo AS CdSubgrupo,Subgrupo,Combustible,VenGalones,Unidades,UnidDev
,Unidades-UnidDev AS UnidNeto,VenTotal,ValorTotal,ValorDev,ValorTotal-ValorDev AS VrTotal,Intervalo,TipoTarifa,Tarifa,VrLiquida
,VrBaseIva,PorcIvaCom,VrIvaCom,IvaIncBonif,TipoMargen,Margen,Subsidio,MgnNeto,LogDetalle,CantExcluido,FechaInicio
,IdCliente,RazonSocial,D.CdAgenc AS Id_Agencia,Agencia
 FROM Trn_MayLiqDetalle AS D  INNER JOIN Trn_MayContratos AS CN ON D.NContrato=CN.NContrato AND D.IdCiaCon=CN.IdCia
 INNER JOIN  SubGrupos AS S ON D.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Terceros AS T ON CN.IdCliente=T.IdTercero
 LEFT JOIN Agencias AS A ON D.CdAgenc=A.IdAgencia
 WHERE NLiquida=@pmNLiquida AND D.IdCia=@pmIdCia 
 ORDER BY D.NContrato,IdCiaCon,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesAbo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayLiqTotalesAbo] @pmNLiquida INT,@pmIdCia CHAR(2),@pmTipoNcr VARCHAR(3)
 AS 
 SELECT Item,T.NContrato AS NumContrato,IdCiaCon,T.IdCliente AS NitCliente,RazonSocial,T.IdAgencia AS Id_Agencia,Agencia
,Unidades,VrBonif,VrAbono,VrCuotaFija,T.DiasGracia AS Dias_Gracia,NotaCred,IdCiaNot
,L.Fecha AS FechaLiq,TipCom,Comprobante,IdCiaCom,L.Observacion AS Observ
,CN.IdVend AS CdVend,TC.IdLocal AS CdCiuClie,A.IdLocal AS CdCiuAge,BaseIvaBonif,VrIvaBonif
 FROM Trn_MayLiquida AS L INNER JOIN Trn_MayLiqTotales  AS T ON L.NLiquida=T.NLiquida AND L.IdCia=T.IdCia
 INNER JOIN Terceros AS TC ON T.IdCliente=TC.IdTercero
 LEFT JOIN Trn_MayContratos AS CN ON T.NContrato=CN.NContrato AND T.IdCiaCon=CN.IdCia
 LEFT JOIN Agencias AS A ON T.IdAgencia=A.IdAgencia
 WHERE L.NLiquida=@pmNLiquida AND L.IdCia=@pmIdCia AND Estado<>2 AND VrAbono>0
 AND TipoNcr=@pmTipoNcr AND NotaCred<=0
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesAbp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayLiqTotalesAbp] @pmNLiquida INT,@pmIdCia CHAR(2),@pmTipoNcr VARCHAR(3)
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM  Trn_MayLiqTotales 
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia AND TipoNcr=@pmTipoNcr AND NotaCred<=0 AND VrAbono>0
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesLog]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiqTotalesLog] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,T.NContrato AS NumContrato,IdCiaCon,T.IdCliente AS NitCliente,RazonSocial,T.IdAgencia AS Id_Agencia,Agencia
,Unidades,VrBonif,VrAbono,VrCuotaFija,T.DiasGracia AS Dias_Gracia,NotaCred,IdCiaNot,LogLiquida,L.Fecha AS FechaLiq
,IdTipo,IdBonif,CN.IdVend AS CdVend,TC.IdLocal AS CdCiuClie,A.IdLocal AS CdCiuAge,CdCCBonif,CdSubCCBonif,BaseIvaBonif,VrIvaBonif
,CN.ClaseContrato,VrBonifNeto
 FROM Trn_MayLiquida AS L INNER JOIN Trn_MayLiqTotales  AS T ON L.NLiquida=T.NLiquida AND L.IdCia=T.IdCia
 INNER JOIN Terceros AS TC ON T.IdCliente=TC.IdTercero
 LEFT JOIN Trn_MayContratos AS CN ON T.NContrato=CN.NContrato AND T.IdCiaCon=CN.IdCia
 LEFT JOIN Agencias AS A ON T.IdAgencia=A.IdAgencia
 WHERE L.NLiquida=@pmNLiquida AND L.IdCia=@pmIdCia AND Estado=0
 AND (VrBonif<>0 OR VrCuotaFija>0) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiqTotalesLta] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT T.NContrato AS NumContrato,IdCiaCon,T.IdCliente AS NitCliente,TC.RazonSocial AS NombreCliente,T.IdAgencia AS Id_Agencia,Agencia
,Unidades,VrBonif,BaseIvaBonif,VrIvaBonif,VrBonifNeto,VrAbono,T.DiasGracia AS Dias_Gracia,L.Fecha AS FechaLiq,Item,LogLiquida
--datos del contrato
,CN.Fecha AS FechaContrato,FechaInicio,FechaVence,CN.IdTipo AS CdTipo,TipContrato,CN.IdBonif AS CdBonif,TipoBonif
,CN.IdVend AS CdVend,V.RazonSocial AS Vendedor,CN.IdBandera AS CdBandera,TipoBandera
,TipCom,Comprobante,IdCiaCom,L.Observacion AS Observ,TipoNcr,NotaCred,IdCiaNot,VrCuotaFija
--datos del cliente
,TC.TipoId AS TipIdClie,TC.Dv AS DvCliente,TC.NomCial AS NomCialClie,TC.SiglaRaz AS SiglaClie,TC.IdLocal AS CdCiuClie,LT.Localidad AS CiudadCliente
,DP.Departamento AS DptoClie,A.IdLocal AS CdCiuAge,LA.Localidad AS CiudadAgencia,DA.Departamento AS DptoAgencia
 FROM Trn_MayLiquida AS L INNER JOIN Trn_MayLiqTotales  AS T ON L.NLiquida=T.NLiquida AND L.IdCia=T.IdCia
 INNER JOIN Terceros AS TC ON T.IdCliente=TC.IdTercero
 INNER JOIN Localidades AS LT ON TC.IdLocal=LT.IdLocal  INNER JOIN Departamentos AS DP ON LT.IdDep=DP.IdDep 
 LEFT JOIN Trn_MayContratos AS CN ON T.NContrato=CN.NContrato AND T.IdCiaCon=CN.IdCia
 LEFT JOIN Agencias AS A ON T.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Terceros AS V ON CN.IdVend=V.IdTercero
 LEFT JOIN  MayTipos AS TCN ON CN.IdTipo=TCN.IdTipo
 LEFT JOIN  MayTiposBonif AS TB ON CN.IdBonif=TB.IdBonif
 LEFT JOIN  TiposBan AS B ON CN.IdBandera=B.IdBandera
 WHERE L.NLiquida=@pmNLiquida AND L.IdCia=@pmIdCia 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesNot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayLiqTotalesNot] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM  Trn_MayLiqTotales 
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia AND NotaCred>0 AND VrAbono>0
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiqTotalesTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayLiqTotalesTot] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT SUM(Unidades) AS STOTUNI,SUM(VrBonif) AS STOTBON,SUM(VrAbono) AS STOTABO
,SUM(VrCuotaFija) AS STOTFIJ,SUM(VrIvaBonif) AS STOTIVA,SUM(BaseIvaBonif) AS STOTBASE
,SUM(VrBonifNeto) AS STOTNETO
 FROM  Trn_MayLiqTotales
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiquida] @pmNLiquida INT,@pmIdCia CHAR(2)
 AS 
 SELECT NLiquida,IdCia,Fecha,Observacion,Estado,FecDev,TipCom,Comprobante,IdCiaCom,TimeSys,IdUsuario
 FROM Trn_MayLiquida
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaEst]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiquidaEst] @pmFecha SMALLDATETIME,@pmIdCia CHAR(2),@pmEstado INT
 AS 
 SELECT NLiquida,IdCia,Fecha,Estado,TipCom,Comprobante,IdCiaCom
 FROM Trn_MayLiquida
 WHERE  Fecha=@pmFecha  AND  IdCia=@pmIdCia AND Estado=@pmEstado
 ORDER BY NLiquida
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiquidaFec] @pmFecha SMALLDATETIME,@pmIdCia CHAR(2)
,@pmNLiquida INT
 AS 
 --Verifica si ya tiene liq. cerradas en el mes
 SELECT NLiquida,IdCia,Fecha,Estado,TipCom,Comprobante,IdCiaCom
 FROM Trn_MayLiquida
 WHERE Fecha=@pmFecha AND Estado=1 AND IdCia=@pmIdCia AND NLiquida<>@pmNLiquida
 ORDER BY NLiquida
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayLiquidaId] @pmIdCia CHAR(2)
 AS 
 SELECT MAX(NLiquida) AS MXID
 FROM Trn_MayLiquida
 WHERE   IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayLiquidaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayLiquidaLta] @pmIdCia CHAR(2)=Null,@pmEstado INT=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT NLiquida,L.IdCia AS CdCia,Compania,Fecha,Observacion,Estado,FecDev
,TipCom,Comprobante,IdCiaCom,L.IdUsuario AS CdUsuario,Usuario,TimeSys
 FROM Trn_MayLiquida AS L INNER JOIN Companias AS C ON L.IdCia=C.IdCia
 INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario
 WHERE L.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND (Estado>=ISNULL(@pmEstado,0)  AND Estado<=ISNULL(@pmEstado,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY NLiquida
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPspto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayPspto] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT NContrato,IdCia,Item,TipoProd,Cantidad,Unidad,CantMes,CdProducto,CdSubgrupo
 FROM Trn_MayPspto
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPsptoCant]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayPsptoCant] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT COUNT(Item) AS SCANT
 FROM Trn_MayPspto
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPsptoItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayPsptoItm] @pmNContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT  MAX(Item) AS MXITM
 FROM Trn_MayPspto
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMayPsptoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayPsptoLta] @pmNContratoIni INT,@pmNContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,TipoProd,Cantidad,Unidad,CantMes,CdSubgrupo,Subgrupo,NContrato,IdCia
 FROM Trn_MayPspto AS PS  LEFT JOIN SubGrupos AS S ON PS.CdSubgrupo=S.IdSubgrupo
 WHERE NContrato BETWEEN @pmNContratoIni AND @pmNContratoFin AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayTipos] @pmIdTipo VARCHAR(4)
 AS 
 IF @pmIdTipo IS NULL
  SELECT IdTipo,TipContrato
  FROM MayTipos
  WHERE Inactivo=0
  ORDER BY IdTipo
 ELSE
  SELECT IdTipo,TipContrato,Inactivo
  FROM MayTipos
  WHERE IdTipo=@pmIdTipo
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposAprob]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayTiposAprob] @pmIdAprob VARCHAR(4)
 AS 
 IF @pmIdAprob IS NULL
  SELECT IdAprob,TipoAprob
  FROM MayTiposAprob
  WHERE Inactivo=0
 ORDER BY TipoAprob
 ELSE
  SELECT IdAprob,TipoAprob,Inactivo
  FROM MayTiposAprob
  WHERE IdAprob=@pmIdAprob
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposBienes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayTiposBienes] @pmIdTipBien VARCHAR(4)
 AS 
 IF @pmIdTipBien IS NULL
  SELECT IdTipBien,TipoBien
  FROM MayTiposBienes
  WHERE Inactivo=0
 ORDER BY TipoBien
 ELSE
  SELECT IdTipBien,TipoBien,Inactivo
  FROM MayTiposBienes
  WHERE IdTipBien=@pmIdTipBien
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposBonif]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayTiposBonif] @pmIdBonif VARCHAR(4)
 AS 
 IF @pmIdBonif IS NULL
  SELECT IdBonif,TipoBonif,AboCartera,AboPstmo
  FROM MayTiposBonif
  WHERE Inactivo=0
  ORDER BY IdBonif
 ELSE
 SELECT IdBonif,TipoBonif,AboCartera,AboPstmo,Inactivo
 FROM MayTiposBonif
 WHERE IdBonif=@pmIdBonif
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMayTiposDoc] @pmIdDoc VARCHAR(4)
 AS 
 IF @pmIdDoc IS NULL
  SELECT IdDoc,NombreDoc
  FROM MayTiposDoc
  WHERE Inactivo=0
  ORDER BY  IdDoc
 ELSE
  SELECT IdDoc,NombreDoc,Inactivo
  FROM MayTiposDoc
  WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryMayTiposPoliza]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMayTiposPoliza] @pmIdTipoPol VARCHAR(4)
 AS 
 IF @pmIdTipoPol IS NULL
 SELECT IdTipoPol,TipoPoliza
 FROM MayTiposPoliza
 WHERE Inactivo=0
 ORDER BY TipoPoliza
 ELSE
 SELECT IdTipoPol,TipoPoliza,Inactivo
 FROM MayTiposPoliza
 WHERE IdTipoPol=@pmIdTipoPol
GO
/****** Object:  StoredProcedure [dbo].[paQryMercancias]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMercancias] @pmIdMercancia VARCHAR(16)
 AS 
 SELECT IdMercancia,DescripMcia,CodigoMcia,IdGrupo,UndMed,IdUnd,IdEmp,IdNat,IdMnjo,IdTmcia,EstadoMcia,Contenedor,IdProducto
,IdEstado,Inactivo,UmCapac,CodigoUN,UM_Prod,CodArancel,CodSubpartida,FechaAdd,FechaUpdate,IdUsuario
 FROM Mercancias
 WHERE IdMercancia=@pmIdMercancia
GO
/****** Object:  StoredProcedure [dbo].[paQryMercanciasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMercanciasLta] @pmIdGrupo VARCHAR(10)=Null,@pmIdNat VARCHAR(4)=Null,@pmIdTmcia VARCHAR(4)=Null
,@pmInactivo BIT=Null
 AS 
 SELECT IdMercancia,DescripMcia,M.IdGrupo AS CdGrupo,GrupoMcia,M.UndMed AS Und_Med,UT.Unidad AS UM_PesoTra,M.IdUnd AS CdUndPre,UM.Unidad,UM.IdEmp AS CdEmp
,M.IdNat AS CdNat,Natlzaprod,M.IdMnjo AS CdMnjo,ManejoMcia,M.IdTmcia AS CdTmcia,TipoMcia,Contenedor,M.IdProducto AS CdProducto,DescripProd,CodigoMcia
,M.IdEmp AS CdEmp,Empaque,EstadoMcia,M.UmCapac,M.UM_Prod,UP.Unidad AS DescUMprod,M.CodArancel,M.CodSubpartida,M.CodigoUN,UN.Designacion,UN.Clase AS ClaseUN,UN.PeligroSec,UN.GrupoEmb
,UN.IdCoRes,CR.GrupoRP,CR.CodigoCR,CR.CorrResiduo,UN.IdCRdes,DG.CodigoDR,DG.Desagregacion
,M.IdEstado AS CdEstado,Estado,M.Inactivo AS Inactvo,M.FechaAdd AS FechaCrea,M.FechaUpdate AS FechaAct,M.IdUsuario AS CdUsuario,Usuario
 FROM Mercancias AS M INNER JOIN GruposMcia AS G ON M.IdGrupo=G.IdGrupo INNER JOIN Sys_Um AS UT ON M.UndMed=UT.UndMed
 INNER JOIN UndMed AS UM ON M.IdUnd=UM.IdUnd INNER JOIN TiposNat AS N ON M.IdNat=N.IdNat
 INNER JOIN TiposMnjo AS MM ON M.IdMnjo=MM.IdMnjo INNER JOIN TiposMcia AS TM ON M.IdTmcia=TM.IdTmcia
 INNER JOIN EstadoPro AS EP ON M.IdEstado=EP.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario 
 LEFT JOIN ProdMcias AS P ON M.IdProducto=P.IdProducto LEFT JOIN Empaques AS E ON M.IdEmp=E.IdEmp
 LEFT JOIN Sys_Um AS UP ON M.UM_Prod=UP.UndMed
 LEFT JOIN ResiduosPeligrosos AS UN ON M.CodigoUN=UN.CodigoUN LEFT JOIN CorrResiduos AS CR ON UN.IdCoRes=CR.IdCorr
 LEFT JOIN Desagregaciones AS DG ON UN.IdCRdes=DG.IdDrp
 WHERE M.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND M.IdNat LIKE ISNULL(@pmIdNat,'%') AND M.IdTmcia LIKE ISNULL(@pmIdTmcia,'%')
  AND (M.Inactivo=ISNULL(@pmInactivo,0) or  M.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY DescripMcia
GO
/****** Object:  StoredProcedure [dbo].[paQryModulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryModulos] @pmIdMod VARCHAR(3),@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdMod,Consecutivo,Descripcion,Valor,nModulo
 FROM Sys_Modulos
 WHERE IdMod LIKE ISNULL(@pmIdMod,'%') AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY Consecutivo
GO
/****** Object:  StoredProcedure [dbo].[paQryModulosId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryModulosId] @pmnModulo VARCHAR(10)=Null
 AS 
 SELECT MAX(Consecutivo) AS MXconce
 FROM Sys_Modulos
 WHERE nModulo LIKE ISNULL(@pmnModulo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrymonedas] @pmIdMneda VARCHAR(5)
 AS 
 SELECT IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo
 FROM adm_monedas
 WHERE IdMneda=@pmIdMneda
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedasDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrymonedasDso]
 AS 
 SELECT IdMneda,Mneda,Mneda+' ('+Simbolo +') '+ IdMneda AS DsMon
 FROM adm_monedas
 WHERE  Inactivo=0
 ORDER BY Mneda
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedasLoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrymonedasLoc]
 AS 
 SELECT IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo
 FROM adm_monedas
 WHERE Inactivo=0 AND MneLocal<>0
 ORDER BY  IdMneda
GO
/****** Object:  StoredProcedure [dbo].[paQrymonedasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrymonedasLta] @pmInactivo BIT=Null
 AS 
 SELECT IdMneda,Mneda,Simbolo,MneLocal,VrCambio,Inactivo
 FROM adm_monedas
 WHERE  (Inactivo=ISNULL(@pmInactivo,0) or  Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Mneda
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoConceptos] @pmIdConc VARCHAR(4)
 AS 
 SELECT IdConc,Concepto,IdSistema,IdMtto,TipoControl,Intervalo_km,Intervalo_dias,Req_Parte,Intervalo_Horas,CodigoMO
,CantHoras,TarifaCosto,TarifaClie,IntvAlarma,Inactivo,FechaCrea,IdUsuario
 FROM MttoConceptos
 WHERE IdConc=@pmIdConc
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoConceptosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoConceptosLta] @pmIdSistema VARCHAR(4)=Null,@pmIdMtto VARCHAR(4)=Null
 AS 
 SELECT IdConc,Concepto,C.IdSistema AS CdSistema,Sistema,C.IdMtto AS CdMtto,TipoMtto,TipoControl
,Intervalo_km,Intervalo_dias,Intervalo_Horas,Req_Parte,CodigoMO,DescripProd,CantHoras,TarifaCosto,TarifaClie,IntvAlarma
,C.Inactivo,C.FechaCrea,C.IdUsuario AS CdUsuario,Usuario
 FROM MttoConceptos AS C INNER JOIN MttoSistemas AS S ON C.IdSistema=S.IdSistema
 INNER JOIN MttoTipos AS TM ON C.IdMtto=TM.IdMtto
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 LEFT JOIN ProdMcias AS P ON C.CodigoMO=P.IdProducto
 WHERE C.IdSistema LIKE ISNULL(@pmIdSistema,'%') AND C.IdMtto LIKE ISNULL(@pmIdMtto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoControles]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoControles] @pmTipoUnidad CHAR(1),@pmNumUnidad VARCHAR(10),@pmIdConc VARCHAR(4)
 AS 
 SELECT TipoUnidad,NumUnidad,IdConc,TipoControl,Intervalo_km,Intervalo_dias,Intervalo_Horas,kmUltMtto,kmUltMttoRuta,kmUltMttoSat
,FecUltMtto,HsUltMtto,Comentarios,Inactivo,FechaCrea,IdUsuario
 FROM MttoControles
 WHERE TipoUnidad=@pmTipoUnidad AND NumUnidad=@pmNumUnidad AND IdConc=@pmIdConc
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoControlesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoControlesLta] @pmNumUnidad VARCHAR(10)=Null,@pmIdConc VARCHAR(4)=Null
 AS 
 SELECT M.TipoUnidad,M.NumUnidad AS IdVehiculo,M.IdConc AS CodConc,Concepto,C.IdSistema AS CdSistema,Sistema,C.IdMtto AS CdMtto,TipoMtto
,M.TipoControl,M.Intervalo_km,M.Intervalo_dias,M.Intervalo_Horas,M.kmUltMtto,M.kmUltMttoRuta,M.kmUltMttoSat,M.FecUltMtto,HsUltMtto
,C.TipoControl AS ConcControl,C.Intervalo_km AS ConcKm,C.Intervalo_dias AS ConcDias,C.Intervalo_Horas AS ConcHoras,C.Req_Parte,C.CantHoras,C.TarifaCosto
,M.Comentarios,M.Inactivo,M.FechaCrea,M.IdUsuario AS CdUsuario,Usuario
--campos de subconsulta vehiculos
,CdTipoVeh,TipoVehiculo,CdMarca,Marca,CdColor,NomColor,Modelo,Config,CdComb,TipoComb,SerieChasis,IdPropietario,NP.RazonSocial AS Propietario
,VigSoat,VigRCivil,VigRegNal,VigTecMec,KmInicial,VehKmActual,VehKmRuta,VehKmOtro,VH.Descripcion,VehInactivo
,VehEstado,Estado,EV.NColor AS EdoNumColor,EV.OutDemand AS EdoDisponible,HR.CantHoras AS AcumHoras,VH.IdGrupo AS CdGrupo,GrupoProp
FROM MttoControles AS M INNER JOIN MttoConceptos AS C ON M.IdConc=C.IdConc INNER JOIN MttoSistemas AS S ON C.IdSistema=S.IdSistema
INNER JOIN MttoTipos AS TM ON C.IdMtto=TM.IdMtto INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
--subconsulta vehiculos
LEFT JOIN (SELECT IdVehiculo AS VehPlaca,NumVeh,IdTipoVeh AS CdTipoVeh,IdMarca AS CdMarca,IdLinea AS CdLinea,IdColor AS CdColor,Modelo,Config,IdCom AS CdComb
,NumMotor,SerieChasis,CdRemque,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,TipoAfil,FecCompra,FecIngreso,NumSoat,VigSoat,VigRCivil,VigRegNal,VigTecMec
,KmInicial,KmActual AS VehKmActual,Km2Actual AS VehKmRuta,CentFinal AS VehKmOtro,Descripcion,Inactivo AS VehInactivo,IdEstado AS VehEstado,IdGrupo
FROM Vehiculos UNION ALL SELECT IdRemque,'0','0',IdMarca,'0',IdColor,Modelo,ConfEjes,'0','',NumSerial,'',NitProv,IdPropietario,IdPropietario,'0','',FecCompra
,FecAdd,'',Null,Null,Null,VigPruebaHid,0,Kilmetraje,kmRuta,kmOtro,Descripcion,Inactivo,IdEstado,'0' FROM VehRemolq) AS VH ON M.NumUnidad=VH.VehPlaca
LEFT JOIN TiposVeh AS TV ON VH.CdTipoVeh=TV.IdTipoVeh LEFT JOIN Marcas AS MV ON VH.CdMarca=MV.IdMarca
LEFT JOIN TiposCol AS CL ON VH.CdColor=CL.IdColor LEFT JOIN TiposFuel AS TC ON VH.CdComb=TC.IdCom
LEFT JOIN Terceros AS NP ON VH.IdPropietario=NP.IdTercero LEFT JOIN EstadoVeh AS EV ON VH.VehEstado=EV.IdEstado
LEFT JOIN VehHoras AS HR ON M.TipoUnidad=HR.TipoUnidad AND M.NumUnidad=HR.NumUnidad
LEFT JOIN GruposPro AS GP ON VH.IdGrupo=GP.IdGrupo
WHERE M.NumUnidad LIKE ISNULL(@pmNumUnidad,'%') AND M.IdConc LIKE ISNULL(@pmIdConc,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoDiagnFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoDiagnFmt] @pmTipOdt VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2) 
AS 
 SELECT DG.TipOdt,DG.NumOrden,DG.IdCia AS CdCia,Compania,DG.NumDiagn,FechaDiagn,TipoUnidad,NumVehic,DG.IdOperario,T.RazonSocial AS NomOperario
,DG.FechaCrea,DG.IdUsuario AS CdUsuario,Usuario,FechaOrden,O.IdTipoOdt AS CdTipoOdt,TipoOrden,O.IdCenSer AS CdCenSer,CentroServ
,O.Modalidad,O.kmVehiculo,O.kmRemolque,O.IdEstado AS CdEstado,Estado
,Item,D.IdInspec AS CdInspec,Inspeccion,ValorInspec,UndMedida,NumColor,D.Req_Mtto,D.Intervalo,D.Observacion AS Observ
,I.IdSistema AS CdSistema,Sistema,I.IdMtto AS CdMtto,TipoMtto,TipoDato
FROM Trn_MttoDiagn AS DG INNER JOIN Trn_MttoDiagnDet AS D ON DG.TipOdt=D.TipOdt AND DG.NumOrden=D.NumOrden AND DG.IdCia=D.IdCia AND DG.NumDiagn=D.NumDiagn
INNER JOIN Companias AS CN ON DG.IdCia=CN.IdCia INNER JOIN Terceros AS T ON DG.IdOperario=T.IdTercero
INNER JOIN adm_Usuarios AS U ON DG.IdUsuario=U.IdUsuario 
INNER JOIN MttoInspecciones AS I ON D.IdInspec=I.IdInspec INNER JOIN MttoSistemas AS S ON I.IdSistema=S.IdSistema
INNER JOIN MttoTipos AS TM ON I.IdMtto=TM.IdMtto
INNER JOIN Trn_MttoOrden AS O ON DG.TipOdt=O.TipDoc AND DG.NumOrden=O.NumOrden AND DG.IdCia=O.IdCia
INNER JOIN MttoTiposOdt AS TOT ON O.IdTipoOdt=TOT.IdTipoOdt INNER JOIN CentrosServ AS CS ON O.IdCenSer=CS.IdCenSer
INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado 
WHERE DG.TipOdt=@pmTipOdt AND DG.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND DG.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoEstados] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  BEGIN
  SELECT IdEstado,Estado,NColor FROM MttoEstados WHERE Inactivo=0
  END 
 ELSE
  BEGIN
   SELECT IdEstado,Estado,NColor,Inactivo FROM MttoEstados WHERE IdEstado=@pmIdEstado
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoInspecciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoInspecciones] @pmIdInspec VARCHAR(4)
 AS 
 SELECT IdInspec,Inspeccion,IdSistema,IdMtto,TipoDato,UndMed,Inactivo
 FROM MttoInspecciones
 WHERE IdInspec=@pmIdInspec
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoInspeccionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoInspeccionesLta] @pmIdSistema VARCHAR(4)
 AS 
 SELECT I.IdInspec,Inspeccion,I.IdSistema AS CdSistema,Sistema,I.IdMtto AS CdMtto,TipoMtto,TipoDato,UndMed,I.Inactivo
,Item,Estado,ValorInicial,ValorFinal,NColor,ReqMtto,CdConc,Concepto
 FROM MttoInspecciones AS I INNER JOIN MttoSistemas AS S ON I.IdSistema=S.IdSistema
 INNER JOIN MttoTipos AS TM ON I.IdMtto=TM.IdMtto
 LEFT JOIN MttoInspecRangos AS R ON I.IdInspec=R.IdInspec 
 LEFT JOIN MttoConceptos AS C ON R.CdConc=C.IdConc
 WHERE I.IdSistema LIKE ISNULL(@pmIdSistema,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrden]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,FechaOrden,FechaVence,IdTipoOdt,IdCenSer,IdVehiculo,nRemolque,IdConductor,IdOperario,IdSupervisor,Modalidad,kmVehiculo,kmRemolque,VrServicios,VrRepuestos,VrManoObra,VrOtros,FechaCierre,NitCenSer
,CdEstadoVeh,IdEstado,Anulado,NumDev,FecDev,Observacion,TipFact,NumFactura,IdCiaFact,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_MttoOrden
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoOrdenDet] @pmTipOdt VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipOdt,NumOrden,IdCia,Item,FechaServ,IdConc,Descripcion,Cantidad,VrUnitario,UndMed,CdMtto
,IdEstado,IdOperario,NumVehic,NumParte,Req_Rep,Req_MO,TipoServ,FechaCrea,IdUsuario,CodCentro,NitCenServ
 FROM Trn_MttoOrdenDet
 WHERE TipOdt=@pmTipOdt AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoOrdenFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2) 
AS 
 SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,Fecha,FechaOrden,FechaVence,O.IdVehiculo,NumVeh,kmVehiculo,nRemolque,kmRemolque,O.IdTipoOdt AS CdTipoOdt,TipoOrden,O.IdCenSer AS CdCenSer,CentroServ
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdOperario AS NitOperario,T.RazonSocial AS NomOperario,IdSupervisor,NSU.RazonSocial AS Supervisor,O.Modalidad
,VrServicios,VrRepuestos,VrManoObra,VrOtros,FechaCierre,NitCenSer,O.CdEstadoVeh,EV.Estado AS EstadoVeh,EV.NColor AS EdvNColor,EV.OutDemand,O.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,ED.NColor AS EdNumColor
,O.Anulado,NumDev,FecDev,O.Observacion AS Observ,O.TipFact,O.NumFactura,O.IdCiaFact,O.TimeSys AS FechaCrea,O.FecUpdate AS FecActualiza,O.IdCiaCrea AS CdCIaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
,D.Item,FechaServ,D.IdConc,D.Descripcion,Concepto,D.Cantidad,D.VrUnitario,UndMed,D.CdMtto,TipoMtto,D.IdEstado AS DetIdEstado,ESV.Estado AS DetEstado,ESV.NColor AS DetNumColor
,D.IdOperario AS DetNitOperario,NOD.RazonSocial AS DetOperario,NumVehic,NumParte,Req_Rep,Req_MO,CO.TarifaClie,D.FechaCrea AS DetFecCrea,D.IdUsuario AS DetCdUsuario,TipoServ,CO.IdSistema AS CdSistema,Sistema 
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion,KmInicial,KmActual,Km2Actual,V.Ubicacion
,V.IdEstado AS VehCdEstado,EVH.Estado AS VehEstado,EVH.NColor AS VehEstColor,EVH.OutDemand AS VehNoDisponible,V.Inactivo AS VehInactivo
,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_MttoOrden AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN MttoTiposOdt AS TOT ON O.IdTipoOdt=TOT.IdTipoOdt INNER JOIN CentrosServ AS CS ON O.IdCenSer=CS.IdCenSer
 INNER JOIN Terceros AS T ON O.IdOperario=T.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS NSU ON O.IdSupervisor=NSU.IdTercero
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_MttoOrdenDet AS D ON O.TipDoc=D.TipOdt AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN MttoConceptos AS CO ON D.IdConc=CO.IdConc INNER JOIN MttoSistemas AS S ON CO.IdSistema=S.IdSistema
 LEFT JOIN Terceros AS NOD ON D.IdOperario=NOD.IdTercero LEFT JOIN MttoTipos AS TM ON D.CdMtto=TM.IdMtto
 LEFT JOIN MttoEstados AS ESV ON D.IdEstado=ESV.IdEstado
 LEFT JOIN EstadoVeh AS EV ON O.CdEstadoVeh=EV.IdEstado 
 LEFT JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
 LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria LEFT JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN EstadoVeh AS EVH ON V.IdEstado=EVH.IdEstado
 WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoOrdenLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT NumOrden,O.IdCia AS CdCia,Compania,Fecha,FechaOrden,FechaVence,O.IdVehiculo,kmVehiculo,nRemolque,kmRemolque,O.IdTipoOdt AS CdTipoOdt,TipoOrden,O.IdCenSer AS CdCenSer,CentroServ
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdOperario AS NitOperario,T.RazonSocial AS NomOperario,IdSupervisor,NS.RazonSocial AS Supervisor,O.Modalidad
,VrServicios,VrRepuestos,VrManoObra,VrOtros,FechaCierre,NitCenSer,O.CdEstadoVeh,EV.Estado AS EstadoVeh,O.IdEstado AS CdEstado,ED.Estado AS EstadoDoc
,O.Anulado,NumDev,FecDev,O.Observacion AS Observ,O.TipFact,O.NumFactura,O.IdCiaFact,O.TimeSys AS FechaCrea,O.FecUpdate AS FecActualiza,O.IdCiaCrea AS CdCIaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
 FROM Trn_MttoOrden AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN MttoTiposOdt AS TOT ON O.IdTipoOdt=TOT.IdTipoOdt INNER JOIN CentrosServ AS CS ON O.IdCenSer=CS.IdCenSer
 INNER JOIN Terceros AS T ON O.IdOperario=T.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS NS ON O.IdSupervisor=NS.IdTercero
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 LEFT JOIN EstadoVeh AS EV ON O.CdEstadoVeh=EV.IdEstado
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoOrdenRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null
AS 
 SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,Fecha,FechaOrden,FechaVence,O.IdVehiculo,NumVeh,kmVehiculo,nRemolque,kmRemolque,O.IdTipoOdt AS CdTipoOdt,TipoOrden,O.IdCenSer AS CdCenSer,CentroServ
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdOperario AS NitOperario,T.RazonSocial AS NomOperario,IdSupervisor,NSU.RazonSocial AS Supervisor,O.Modalidad
,VrServicios,VrRepuestos,VrManoObra,VrOtros,FechaCierre,NitCenSer,O.CdEstadoVeh,EV.Estado AS EstadoVeh,EV.NColor AS EdvNColor,EV.OutDemand,O.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,ED.NColor AS EdNumColor
,O.Anulado,NumDev,FecDev,O.Observacion AS Observ,O.TipFact,O.NumFactura,O.IdCiaFact,O.TimeSys AS FechaCrea,O.FecUpdate AS FecActualiza,O.IdCiaCrea AS CdCIaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario,Leyenda
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion,KmInicial,KmActual,Km2Actual,V.Ubicacion
,V.IdEstado AS VehCdEstado,EVH.Estado AS VehEstado,EVH.NColor AS VehEstColor,EVH.OutDemand AS VehNoDisponible,V.Inactivo AS VehInactivo,V.IdGrupo AS CdGrupo,GrupoProp
,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
,ISNULL(RS.ReqAprob,0) AS Req_Aprob,ISNULL(RS.ReqNoAprob,0) AS Req_NoAprob
 FROM Trn_MttoOrden AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN MttoTiposOdt AS TOT ON O.IdTipoOdt=TOT.IdTipoOdt INNER JOIN CentrosServ AS CS ON O.IdCenSer=CS.IdCenSer
 INNER JOIN Terceros AS T ON O.IdOperario=T.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS NSU ON O.IdSupervisor=NSU.IdTercero
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 LEFT JOIN EstadoVeh AS EV ON O.CdEstadoVeh=EV.IdEstado 
 LEFT JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
 LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria LEFT JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN EstadoVeh AS EVH ON V.IdEstado=EVH.IdEstado LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
--consulta requisiciones aprobadas
 LEFT JOIN (SELECT R.TipOdt,R.NumOrden,R.IdCiaOdt,SUM(CASE WHEN (RQ.IdEstado='0002' OR RQ.NumAprob<=0) THEN 1 ELSE 0 END) AS ReqNoAprob
 ,SUM(CASE WHEN RQ.IdEstado<>'0002' AND RQ.NumAprob>0 THEN 1 ELSE 0 END) AS ReqAprob
  FROM Trn_MttoOrdenReq AS R INNER JOIN Trn_Requisicion AS RQ ON R.TipReq=RQ.TipDoc AND R.Requisicion=RQ.Requisicion AND R.IdCia=RQ.IdCia
  WHERE RQ.Anulado=0 GROUP BY R.TipOdt,R.NumOrden,R.IdCiaOdt) AS RS ON O.TipDoc=RS.TipOdt AND O.NumOrden=RS.NumOrden AND O.IdCia=RS.IdCiaOdt
--fin consulta requisiciones aprobadas
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenRelDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoOrdenRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null
AS 
 SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,Fecha,FechaOrden,FechaVence,O.IdVehiculo,NumVeh,kmVehiculo,nRemolque,kmRemolque,O.IdTipoOdt AS CdTipoOdt,TipoOrden
,O.IdCenSer AS CdCenSer,CentroServ,NitCenSer,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,IdSupervisor,NSU.RazonSocial AS Supervisor
--<campos de detalles
,D.Item,D.TipoItem,D.IdConc AS CdConc,D.Descripcion,D.Cantidad,D.IdUnd,D.UndMed,D.VrUnitario,D.TipoServ,D.IdOperario AS NitOperario,T.RazonSocial AS Operario,D.IdEstado AS CdEstadoServ,ESV.Estado AS EstadoServ,ESV.NColor AS ES_NumColor
,D.CdMtto,TipoMtto,C.IdSistema AS CdSistema,Sistema,Seccion,Concepto,D.IdProducto,DescripProd,D.FechaServ,D.NumParte,D.TipReq,D.Requisicion,D.IdCiaReq,TipSal,NumSalida,IdCiaSal,CantSalida,D.EstadoReq,C.TarifaClie,Req_Rep,Req_MO
,CASE ISNULL(D.TipoReg,0) WHEN 0 THEN 'SERVICIO' ELSE 'REQ' END AS Tipo_Reg
--campos de detalles>
,O.Modalidad,VrServicios,VrRepuestos,VrManoObra,VrOtros,O.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,ED.NColor AS EdNumColor,FechaCierre,O.Anulado,NumDev,FecDev
,O.Observacion AS Observ,O.TipFact,O.NumFactura,O.IdCiaFact,O.TimeSys AS FechaCrea,O.FecUpdate AS FecActualiza,O.IdCiaCrea AS CdCIaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario,Leyenda
--campos de vehículo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config,V.IdGrupo AS CdGrupo,GrupoProp
,PesoVacio,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion,KmInicial,KmActual,Km2Actual AS kmRuta,CentFinal AS KmOtro,V.Ubicacion
,V.IdEstado AS VehCdEstado,EV.Estado AS VehEstado,EV.NColor AS VehEstColor,EV.OutDemand AS VehNoDisponible,V.Inactivo AS VehInactivo
,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
,ISNULL(RS.ReqAprob,0) AS Req_Aprob,ISNULL(RS.ReqNoAprob,0) AS Req_NoAprob
 FROM Trn_MttoOrden AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN MttoTiposOdt AS TOT ON O.IdTipoOdt=TOT.IdTipoOdt INNER JOIN CentrosServ AS CS ON O.IdCenSer=CS.IdCenSer
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS NSU ON O.IdSupervisor=NSU.IdTercero
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
  --<subconsulta detalles
 INNER JOIN (SELECT DS.TipOdt,DS.NumOrden,DS.IdCia,DS.Item,DS.FechaServ,DS.IdConc,DS.Descripcion,DS.Cantidad,DS.VrUnitario,'0' AS IdUnd,DS.UndMed,DS.CdMtto,DS.IdEstado,DS.IdOperario
 ,DS.NumVehic,DS.NumParte,DS.TipoServ,DS.FechaCrea,DS.IdUsuario,'0' AS TipReq,0 AS Requisicion,'00' AS IdCiaReq
 ,CASE DS.TipoServ WHEN 'EXTERNA' THEN 'MO' ELSE 'REPUESTO' END AS TipoItem,'0' AS IdProducto,0 AS EstadoReq,'0' AS TipSal,0 AS NumSalida,'00' AS IdCiaSal,0 AS CantSalida,0 AS TipoReg
,DS.Req_Rep,DS.Req_MO
 FROM Trn_MttoOrdenDet AS DS INNER JOIN Trn_MttoOrden AS O ON DS.TipOdt=O.TipDoc AND DS.NumOrden=O.NumOrden AND DS.IdCia=O.IdCia
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND DS.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 UNION ALL
 SELECT R.TipOdt,R.NumOrden,R.IdCiaOdt,R.Item,R.FechaCrea,R.CdConcServ,R.Descripcion,R.Cantidad,R.VrUnitario,R.IdUnd,Unidad,C.IdMtto
 ,CASE R.EstadoReq WHEN -1 THEN '9999' WHEN 0 THEN '0001' WHEN 1 THEN '9998' ELSE '0001' END,R.IdOperario
 ,R.NumVehic,R.NumParte,'INTERNA',R.FechaCrea,R.IdUsuario,R.TipReq,R.Requisicion,R.IdCia,R.TipoItem,R.IdProducto,R.EstadoReq
 ,R.TipSal,R.NumSalida,R.IdCiaSal,R.CantSalida,1 AS TipoReg,0,0
 FROM Trn_MttoOrdenReq AS R INNER JOIN Trn_MttoOrden AS O ON R.TipOdt=O.TipDoc AND R.NumOrden=O.NumOrden AND R.IdCiaOdt=O.IdCia
 INNER JOIN Trn_Requisicion AS RQ ON R.TipReq=RQ.TipDoc AND R.Requisicion=RQ.Requisicion AND R.IdCia=RQ.IdCia 
 LEFT JOIN MttoConceptos AS C ON R.CdConcServ=C.IdConc LEFT JOIN UndMed AS UM ON R.IdUnd=UM.IdUnd
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.IdCiaOdt LIKE ISNULL(@pmIdCia,'%%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') ) AS D ON O.TipDoc=D.TipOdt AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 --subconsulta detalles>
 INNER JOIN Terceros AS T ON D.IdOperario=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 LEFT JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
 LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria LEFT JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN MttoConceptos AS C ON D.IdConc=C.IdConc LEFT JOIN MttoSistemas AS S ON C.IdSistema=S.IdSistema
 LEFT JOIN MttoTipos AS TM ON D.CdMtto=TM.IdMtto LEFT JOIN MttoEstados AS ESV ON D.IdEstado=ESV.IdEstado
 LEFT JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
--<consulta requisiciones aprobadas
 LEFT JOIN (SELECT R.TipOdt,R.NumOrden,R.IdCiaOdt,SUM(CASE WHEN (RQ.IdEstado='0002' OR RQ.NumAprob<=0) THEN 1 ELSE 0 END) AS ReqNoAprob
 ,SUM(CASE WHEN RQ.IdEstado<>'0002' AND RQ.NumAprob>0 THEN 1 ELSE 0 END) AS ReqAprob
  FROM Trn_MttoOrdenReq AS R INNER JOIN Trn_Requisicion AS RQ ON R.TipReq=RQ.TipDoc AND R.Requisicion=RQ.Requisicion AND R.IdCia=RQ.IdCia
  WHERE RQ.Anulado=0 GROUP BY R.TipOdt,R.NumOrden,R.IdCiaOdt) AS RS ON O.TipDoc=RS.TipOdt AND O.NumOrden=RS.NumOrden AND O.IdCia=RS.IdCiaOdt
--fin consulta requisiciones aprobadas>
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoOrdenReqFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryMttoOrdenReqFmt] @pmTipOdt VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCiaOdt CHAR(2)
 AS 
 SELECT R.TipDoc,R.Requisicion,R.IdCia AS CdCia,Compania,R.Fecha,Item,TipoItem,D.IdProducto AS CdProducto,D.Descripcion,DescripProd
,D.Cantidad,D.IdUnd AS CdUnd,Unidad,D.VrUnitario,D.CdBodega,Bodega,TipoRef,D.TipOdt,D.NumOrden AS Num_Orden,D.IdCiaOdt,EstadoReq
,D.TipSal,D.NumSalida,D.IdCiaSal,D.CantSalida,D.IdOperario AS CedOperario,T.RazonSocial AS Operario,D.CdCenServ,CentroServ
,D.NitTercero,NC.RazonSocial,D.NumVehic,D.NumParte,D.Observacion AS Observ,D.CdConcServ,Concepto,D.VrPrecioUnd,D.FechaCrea,D.IdUsuario AS CdUsuario,U.Usuario
,R.Modalidad,NumAprob,FecAprob,CdUsuAprob,CN.TarifaClie
,T.TipoId,T.Codigo,T.Dv,T.Telefono,T.TelMovil,T.e_mail
 FROM Trn_MttoOrdenReq AS D INNER JOIN Trn_Requisicion AS R ON D.TipReq=R.TipDoc AND D.Requisicion=R.Requisicion AND D.IdCia=R.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd LEFT JOIN Terceros AS T ON D.IdOperario=T.IdTercero
 LEFT JOIN Terceros AS NC ON D.NitTercero=NC.IdTercero LEFT JOIN Bodegas AS BG ON D.CdBodega=BG.IdBodega
 LEFT JOIN CentrosServ AS CS ON D.CdCenServ=CS.IdCenSer LEFT JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario 
 LEFT JOIN MttoConceptos AS CN ON D.CdConcServ=CN.IdConc
 WHERE D.TipOdt=@pmTipOdt AND D.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND D.IdCiaOdt=@pmIdCiaOdt
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoSistemas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoSistemas] @pmIdSistema VARCHAR(4)
 AS 
 IF @pmIdSistema IS NULL
  BEGIN
   SELECT IdSistema,Sistema,Seccion FROM MttoSistemas WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdSistema,Sistema,Seccion,Inactivo FROM MttoSistemas WHERE IdSistema=@pmIdSistema
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoTipos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoTipos] @pmIdMtto VARCHAR(4)
 AS 
 IF @pmIdMtto IS NULL
  BEGIN
   SELECT IdMtto,TipoMtto FROM MttoTipos WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdMtto,TipoMtto,Inactivo FROM MttoTipos WHERE IdMtto=@pmIdMtto
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryMttoTiposOdt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMttoTiposOdt] @pmIdTipoOdt VARCHAR(4)
 AS 
 IF @pmIdTipoOdt IS NULL
  BEGIN
   SELECT IdTipoOdt,TipoOrden FROM MttoTiposOdt WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdTipoOdt,TipoOrden,Inactivo FROM MttoTiposOdt WHERE IdTipoOdt=@pmIdTipoOdt
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryMudArticulos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudArticulos] @pmIdArticulo VARCHAR(16)
 AS 
 SELECT IdArticulo,Articulo,IdSeccion,Inactivo
 FROM MudArticulos
 WHERE IdArticulo=@pmIdArticulo
GO
/****** Object:  StoredProcedure [dbo].[paQryMudArticulosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudArticulosLta] 
 AS 
 SELECT IdArticulo,Articulo,A.IdSeccion AS CdSeccion,Seccion,A.Inactivo
 FROM MudArticulos AS A INNER JOIN MudSecciones AS S ON A.IdSeccion=S.IdSeccion
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContFactRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContFactRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT C.NumContrato,C.IdCia AS CdCia,C.Fecha,C.FechaInicio,C.FechaFinal,C.IdCliente,C.TipOrden,C.NumOrden,C.IdCiaOrden
,FC.TipFac,FC.NumFactura,FC.IdCiaFac,FC.Fecha AS FecFact,FC.ValorTotal,FC.Anulado
,D.Item AS FacItem,D.CdConcepto,D.Descripcion,CD.Concepto,D.Cantidad,D.VrUnitario,D.VrCosto,D.PesoNeto,D.Volumen,D.TarifaIva,D.VrImpuesto,D.TarifaSeg,D.VrSeguroRem
,D.Remision,D.DocCliente,D.Referencia1,D.Referencia2,D.Referencia3,D.TipDocRef,D.NumDocRef,D.IdCiaRef,F.VrNeto,F.Observacion AS Observ,F.Anulado AS FacAnulado
 FROM Trn_MudContratos AS C INNER JOIN Trn_MudContFact AS FC ON C.TipDoc=FC.TipDoc AND C.NumContrato=FC.NumContrato AND C.IdCia=FC.IdCia
 INNER JOIN Trn_TraFacRemesas AS D ON FC.TipFac=D.TipDoc AND FC.NumFactura=D.Factura AND FC.IdCiaFac=D.IdCia
 INNER JOIN Trn_Facturas AS F ON FC.TipFac=F.TipDoc AND FC.NumFactura=F.Factura AND FC.IdCiaFac=F.IdCia
 LEFT JOIN ConcDiversos AS CD ON D.CdConcepto=CD.IdConcepto
 WHERE C.TipDoc=@pmTipDoc AND C.FechaInicio BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContNov_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContNov_Cr] @pmTipDoc VARCHAR(3),@pmContratoIni INT,@pmContratoFin INT,@pmIdCia CHAR(2)
 AS 
SELECT D.TipDoc,D.NumContrato,D.IdCia AS CdCia,D.Item,D.Fecha,D.TipoNov,D.Descripcion,D.TarifaServ,D.TipInv,D.NumInvent,D.CdCiaInv,D.ItemInv
,D.CdArticulo,D.Cantidad,D.CdEstado,Estado,D.CdBodega,B.Bodega AS BodegaOrig,D.CdBodDest,BD.Bodega AS BodegaDest,D.NumDocRef,D.IdUsuario,Usuario
,D.Notas
FROM Trn_MudContNov AS D INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
LEFT JOIN AlmBodegas AS B ON D.CdBodega=B.IdBodega LEFT JOIN AlmBodegas AS BD ON D.CdBodDest=BD.IdBodega
LEFT JOIN MudEstados AS E ON D.CdEstado=E.IdEstado
WHERE D.TipDoc=@pmTipDoc AND D.NumContrato BETWEEN @pmContratoIni AND @pmContratoFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContNovRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContNovRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
SELECT C.NumContrato,C.IdCia AS CdCia,C.Fecha,C.FechaInicio,C.FechaFinal,C.IdCliente,C.TipOrden,C.NumOrden,C.IdCiaOrden
,D.Item,D.Fecha,D.TipoNov,D.Descripcion,D.TarifaServ,D.TipInv,D.NumInvent,D.CdCiaInv,D.ItemInv
,D.CdArticulo,Articulo,A.IdSeccion AS CdSeccion,Seccion,D.Cantidad,D.CdEstado,Estado,D.CdBodega,B.Bodega AS BodegaOrig
,D.CdBodDest,BD.Bodega AS BodegaDest,D.NumDocRef,D.IdUsuario,Usuario,D.Notas
FROM Trn_MudContratos AS C INNER JOIN Trn_MudContNov AS D ON C.TipDoc=D.TipDoc AND C.NumContrato=D.NumContrato AND C.IdCia=D.IdCia
INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
LEFT JOIN AlmBodegas AS B ON D.CdBodega=B.IdBodega LEFT JOIN AlmBodegas AS BD ON D.CdBodDest=BD.IdBodega
LEFT JOIN MudEstados AS E ON D.CdEstado=E.IdEstado LEFT JOIN MudArticulos AS A ON D.CdArticulo=A.IdArticulo
LEFT JOIN MudSecciones AS SC ON A.IdSeccion=SC.IdSeccion
WHERE C.TipDoc=@pmTipDoc AND C.FechaInicio BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContratos] @pmTipDoc VARCHAR(3),@pmNumContrato INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumContrato,IdCia,Fecha,FechaInicio,FechaFinal,IdCliente,IdAgencia,IdBodega,CdBodega2,VrServicio,VrImpuesto,VrDeclarado,VrSeguro,TipOrden,NumOrden,IdCiaOrden,FechaRetiro,NomContacto,TelsContacto,emlContacto
,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_MudContratos
 WHERE TipDoc=@pmTipDoc AND NumContrato=@pmNumContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContratos_Cr] @pmTipDoc VARCHAR(3),@pmContratoIni INT,@pmContratoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc,TipoDoc,C.NumContrato,C.IdCia AS CdCia,Compania,C.Fecha,C.FechaInicio,C.FechaFinal,C.IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia
,C.IdBodega,B.Bodega,CdBodega2,BA.Bodega AS BodegaAdic,C.VrServicio,C.VrImpuesto,C.VrDeclarado,C.VrSeguro,C.TipOrden,C.NumOrden,C.IdCiaOrden,C.FechaRetiro,C.NomContacto,C.TelsContacto,C.emlContacto
,C.Anulado,C.FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado
,D.Item,D.IdConcepto AS CdConcepto,D.Descripcion,CD.Concepto,D.ValorTotal,D.TarifaIva,D.TarifSeguro,D.TipoRubro,D.CdCuenta,D.CodTarIva,D.CodTarSeg
,C.TimeSys AS FechaCrea,C.FecUpdate,C.IdCiaCrea,C.OrigenAdd,C.IdUsuario AS CdUsuario,Usuario
 FROM Trn_MudContratos AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Trn_MudContConc AS D ON C.TipDoc=D.TipDoc AND C.NumContrato=D.NumContrato AND C.IdCia=D.IdCia
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto 
 INNER JOIN AlmBodegas AS B ON C.IdBodega=B.IdBodega 
 LEFT JOIN AlmBodegas AS BA ON C.CdBodega2=BA.IdBodega LEFT JOIN Agencias AS A ON C.IdAgencia=A.IdAgencia 
 WHERE C.TipDoc=@pmTipDoc AND C.NumContrato BETWEEN @pmContratoIni AND @pmContratoFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContratosLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT C.NumContrato,C.IdCia AS CdCia,Compania,C.Fecha,C.FechaInicio,C.FechaFinal,C.IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia
,C.IdBodega,B.Bodega,CdBodega2,BA.Bodega AS BodegaAdic,C.VrServicio,C.VrImpuesto,C.VrDeclarado,C.VrSeguro,C.TipOrden,C.NumOrden,C.IdCiaOrden,C.FechaRetiro,C.NomContacto,C.TelsContacto,C.emlContacto
,C.Anulado,C.FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,C.TimeSys AS FechaCrea,C.FecUpdate,C.IdCiaCrea,C.OrigenAdd,C.IdUsuario AS CdUsuario,Usuario
 FROM Trn_MudContratos AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN AlmBodegas AS B ON C.IdBodega=B.IdBodega 
 LEFT JOIN AlmBodegas AS BA ON C.CdBodega2=BA.IdBodega
 LEFT JOIN Agencias AS A ON C.IdAgencia=A.IdAgencia 
 WHERE C.TipDoc=@pmTipDoc AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudContratosRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudContratosRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT C.NumContrato,C.IdCia AS CdCia,Compania,C.Fecha,C.FechaInicio,C.FechaFinal,C.IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia
,C.IdBodega,B.Bodega,CdBodega2,BA.Bodega AS BodegaAdic,C.VrServicio,C.VrImpuesto,C.VrDeclarado,C.VrSeguro,C.TipOrden,C.NumOrden,C.IdCiaOrden
,O.FecDespacho AS OrdFecDespacho,O.IdTipoServ AS CdTipoServ,TipoServicio,O.IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen
,O.IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino
,O.IdVend,VN.RazonSocial AS NomVendedor,O.TipInv,O.NumInvent,O.IdCiaInv,O.TipoRuta,O.EstadoBod,C.NomContacto,C.TelsContacto,C.emlContacto
--detalle
,D.Item,D.IdConcepto AS CdConcepto,D.Descripcion,CD.Concepto,D.ValorTotal,D.TarifaIva,D.TarifSeguro,D.TipoRubro,D.CdCuenta,D.CodTarIva,D.CodTarSeg
,C.Anulado,C.FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,C.FechaRetiro,C.TimeSys AS FechaCrea,C.FecUpdate,C.IdCiaCrea,C.OrigenAdd,C.IdUsuario AS CdUsuario,Usuario
--datos del cliente
,T.Codigo AS TercCod,T.TipoId,T.Dv,T.Direccion,T.IdLocal AS TercCdLocal,L.Localidad AS TercLocalidad,T.Telefono AS TercTelefono,T.TelMovil AS TercTerCelular,T.e_mail AS TercEmail
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupo,GrupoClie,CLI.IdPlazo AS CdPlazo,Plazo
,ISNULL(FC.FacNumero,0) AS FacNumero,ISNULL(FC.FacTotal,0) AS FacVrTotal
 FROM Trn_MudContratos AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN TercCliente AS CLI ON C.IdCliente=CLI.IdClie
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Trn_MudContConc AS D ON C.TipDoc=D.TipDoc AND C.NumContrato=D.NumContrato AND C.IdCia=D.IdCia
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto INNER JOIN AlmBodegas AS B ON C.IdBodega=B.IdBodega
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 LEFT JOIN AlmBodegas AS BA ON C.CdBodega2=BA.IdBodega LEFT JOIN Agencias AS A ON C.IdAgencia=A.IdAgencia 
 LEFT JOIN Trn_MudOrdenServ AS O ON C.TipOrden=O.TipDoc AND C.NumOrden=O.NumOrden AND C.IdCiaOrden=O.IdCia
 LEFT JOIN Terceros AS VN ON O.IdVend=VN.IdTercero LEFT JOIN MudServicios AS TS ON O.IdTipoServ=TS.IdTipoServ
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep LEFT JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN (SELECT TipDoc,NumContrato,IdCia,COUNT(Item) AS FacItems,MAX(NumFactura) AS FacNumero,SUM(ValorTotal) AS FacTotal FROM Trn_MudContFact
 WHERE Anulado=0 GROUP BY TipDoc,NumContrato,IdCia) AS FC ON C.TipDoc=FC.TipDoc AND C.NumContrato=FC.NumContrato AND C.IdCia=FC.IdCia
 WHERE C.TipDoc=@pmTipDoc AND C.FechaInicio BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudEstados]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudEstados] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  BEGIN
   SELECT IdEstado,Estado,NColor
   FROM MudEstados
   WHERE Inactivo=0
   ORDER BY IdEstado
  END
 ELSE
  BEGIN
   SELECT IdEstado,Estado,NColor,Inactivo
   FROM MudEstados
   WHERE IdEstado=@pmIdEstado
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventario]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudInventario] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumInvent,IdCia,Fecha,FecDespacho,IdTipoServ,IdCliente,IdAgencia,IdRemitente,Remitente,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,IdDestinatario,Destinatario,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,IdOrigen,IdDestino,IdVend,pVehiculo,CdConductor,nRemolque
,TipoAfiVehic,NitEmpresa,NomEmpresa,CajasEmp,CajasClie,VrDeclarado,VrServicio,NumCotizac,NumPlanilla,NumActa,TipOsm,NumOrden,IdCiaOsm,NomContacto,TelsContacto,emlContacto,Responsable,FormaPago,ContactoDest,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_MudInventario
 WHERE TipDoc=@pmTipDoc AND NumInvent=@pmNumInvent AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventario_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudInventario_Cr] @pmTipDoc VARCHAR(3),@pmNumInventIni INT,@pmNumInventFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc,TipoDoc,M.NumInvent,M.IdCia AS CdCia,Compania,M.Fecha,M.FecDespacho,M.IdTipoServ AS CdTipoServ,TipoServicio,M.IdCliente,T.RazonSocial AS NomCliente,M.IdAgencia AS CdAgencia,Agencia
,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest
,M.IdOrigen,LO.Localidad AS CiuOrigen,DPO.Departamento AS DptoOrigen,M.IdDestino,LD.Localidad AS CiuDestino,DPD.Departamento AS DptoDestino,M.pVehiculo,M.CdConductor,NC.RazonSocial AS Conductor
,M.nRemolque,M.TipoAfiVehic,M.NitEmpresa,M.NomEmpresa,CajasEmp,CajasClie,M.VrDeclarado,M.VrServicio,M.NumCotizac,M.NumPlanilla,NumActa,M.TipOsm,M.NumOrden,M.IdCiaOsm,M.NomContacto,M.TelsContacto
,M.emlContacto,M.Responsable,M.FormaPago,M.Remitente AS ContactoCargue,M.Destinatario AS ContactoDestino,M.ContactoDest,M.Anulado,M.FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,ED.Estado
,M.OrigenAdd,M.TimeSys AS FechaCrea,M.FecUpdate,M.IdCiaCrea AS CdCiaCrea,M.IdUsuario AS CdUsuario,U.Usuario
,D.Item,D.IdArticulo AS CdArticulo,D.Descripcion,D.Cantidad,D.CantSalida,D.IdEstado AS CdEstadoArt,EA.Estado AS EstadoArt,D.Observacion AS DetObserv,Articulo,MA.IdSeccion AS CdSeccion,Seccion,EA.NColor AS NColorEst
,D.TipoIngreso,D.FechaReg,D.CdUsuario AS DetCdUsuario,UD.Usuario AS DetUsuario
FROM Trn_MudInventario AS M INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN Terceros AS T ON M.IdCliente=T.IdTercero
INNER JOIN MudServicios AS TS ON M.IdTipoServ=TS.IdTipoServ INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc
INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
INNER JOIN Trn_MudInventDet AS D ON M.TipDoc=D.TipDoc AND M.NumInvent=D.NumInvent AND M.IdCia=D.IdCia
INNER JOIN MudArticulos AS MA ON D.IdArticulo=MA.IdArticulo INNER JOIN MudSecciones AS SC ON MA.IdSeccion=SC.IdSeccion
INNER JOIN MudEstados AS EA ON D.IdEstado=EA.IdEstado
LEFT JOIN Terceros AS NC ON M.CdConductor=NC.IdTercero LEFT JOIN Agencias AS A ON M.IdAgencia=A.IdAgencia 
LEFT JOIN adm_Usuarios AS UD ON D.CdUsuario=UD.IdUsuario 
WHERE M.TipDoc=@pmTipDoc AND M.NumInvent BETWEEN @pmNumInventIni AND @pmNumInventFin AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventarioLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudInventarioLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT M.NumInvent,M.IdCia AS CdCia,Compania,M.Fecha,M.FecDespacho,M.IdTipoServ AS CdTipoServ,TipoServicio,M.IdCliente,T.RazonSocial AS NomCliente,M.IdAgencia AS CdAgencia,Agencia
,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest
,M.IdOrigen,LO.Localidad AS CiuOrigen,M.IdDestino,LD.Localidad AS CiuDestino,M.pVehiculo,M.CdConductor,NC.RazonSocial AS Conductor,M.nRemolque,M.TipoAfiVehic,M.NitEmpresa,M.NomEmpresa
,CajasEmp,CajasClie,M.VrDeclarado,M.VrServicio,M.NumCotizac,M.NumPlanilla,NumActa,M.TipOsm,M.NumOrden,M.IdCiaOsm,M.NomContacto,M.TelsContacto,M.emlContacto,M.Responsable,M.FormaPago
,M.Anulado,M.FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.OrigenAdd,M.TimeSys AS FechaCrea,M.FecUpdate,M.IdCiaCrea AS CdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
,M.IdRemitente,M.Remitente,M.IdDestinatario,M.Destinatario,M.IdVend,M.ContactoDest
FROM Trn_MudInventario AS M INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN Terceros AS T ON M.IdCliente=T.IdTercero
INNER JOIN MudServicios AS TS ON M.IdTipoServ=TS.IdTipoServ INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal
LEFT JOIN Terceros AS NC ON M.CdConductor=NC.IdTercero LEFT JOIN Agencias AS A ON M.IdAgencia=A.IdAgencia 
WHERE M.TipDoc=@pmTipDoc AND M.FecDespacho BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudInventarioOsm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudInventarioOsm] @pmTipOsm VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc,TipoDoc,M.NumInvent,M.IdCia AS CdCia,Compania,M.Fecha,M.FecDespacho,M.IdTipoServ AS CdTipoServ,TipoServicio,M.IdCliente,T.RazonSocial AS NomCliente,M.IdAgencia AS CdAgencia,Agencia
,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest
,M.IdOrigen,LO.Localidad AS CiuOrigen,DPO.Departamento AS DptoOrigen,M.IdDestino,LD.Localidad AS CiuDestino,DPD.Departamento AS DptoDestino,M.pVehiculo,M.CdConductor,NC.RazonSocial AS Conductor
,M.nRemolque,M.TipoAfiVehic,M.NitEmpresa,M.NomEmpresa,CajasEmp,CajasClie,M.VrDeclarado,M.VrServicio,M.NumCotizac,M.NumPlanilla,NumActa,M.TipOsm,M.NumOrden,M.IdCiaOsm,M.NomContacto,M.TelsContacto
,M.emlContacto,M.Responsable,M.FormaPago,M.Remitente AS ContactoCargue,M.Destinatario AS ContactoDestino,M.Anulado,M.FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,ED.Estado
,M.OrigenAdd,M.TimeSys AS FechaCrea,M.FecUpdate,M.IdCiaCrea AS CdCiaCrea,M.IdUsuario AS CdUsuario,U.Usuario
,D.Item,D.IdArticulo AS CdArticulo,D.Descripcion,D.Cantidad,D.CantSalida,D.IdEstado AS CdEstadoArt,EA.Estado AS EstadoArt,D.Observacion AS DetObserv,Articulo,MA.IdSeccion AS CdSeccion,Seccion,EA.NColor AS NColorEst
,D.TipoIngreso,D.FechaReg,D.CdUsuario AS DetCdUsuario,UD.Usuario AS DetUsuario
FROM Trn_MudInventario AS M INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN Terceros AS T ON M.IdCliente=T.IdTercero
INNER JOIN MudServicios AS TS ON M.IdTipoServ=TS.IdTipoServ INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc
INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
INNER JOIN Trn_MudInventDet AS D ON M.TipDoc=D.TipDoc AND M.NumInvent=D.NumInvent AND M.IdCia=D.IdCia
INNER JOIN MudArticulos AS MA ON D.IdArticulo=MA.IdArticulo INNER JOIN MudSecciones AS SC ON MA.IdSeccion=SC.IdSeccion
INNER JOIN MudEstados AS EA ON D.IdEstado=EA.IdEstado
LEFT JOIN Terceros AS NC ON M.CdConductor=NC.IdTercero LEFT JOIN Agencias AS A ON M.IdAgencia=A.IdAgencia 
LEFT JOIN adm_Usuarios AS UD ON D.CdUsuario=UD.IdUsuario 
WHERE M.TipDoc='MUD' AND M.TipOsm=@pmTipOsm AND M.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND M.IdCiaOsm=@pmIdCia
AND M.Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenConcLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenConcLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.TipDoc,O.NumOrden,O.IdCia,O.FecDespacho,O.IdCliente,D.Item,D.IdConcepto AS CdConcepto,D.Descripcion,CD.Concepto,D.ValorTotal,D.TarifaIva,D.TipoConc,D.TipoRubro
,D.CdCuenta,D.NitTercero,NT.RazonSocial AS NomTercero,D.Referencia,D.NumDocRef,D.TipoReg,D.TarifSeguro,D.CodTarSeg,D.PlacaVehic,D.TarifaPago
,D.NumDocFac,D.IndFactItem,D.FechaReg,D.CdUsuario,U.Usuario,CD.RubroConc,CD.MudReajuste
--datos de facturas
,FC.FacNumero,FC.FacFecha,ISNULL(FC.FacValor,0) AS FacVrTotal,ISNULL(FC.FacCosto,0) AS FacVrCosto,ISNULL(FC.FacImpuesto,0) AS FacVrIva,ISNULL(FC.FacSeguro,0) AS FacVrSeguro
,FacBaseIngreso,DfcBaseIngreso,FacReajuste,DfcReajuste
 FROM Trn_MudOrdenServ AS O INNER JOIN Trn_MudOrdenConc AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero LEFT JOIN adm_Usuarios AS U ON D.CdUsuario=U.IdUsuario
 --Facturas item por item
 LEFT JOIN (SELECT TipRem AS FacTipOrd,Remesa AS FacNumOrden,IdCiaRem AS FacIdCiaOrd,ItemRem AS FacItemOrd,MAX(FecRemesa) AS FacFecha
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE Cantidad*VrUnitario END) AS FacValor
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN (Cantidad*VrCosto)*-1 ELSE Cantidad*VrCosto END) AS FacCosto
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN VrImpuesto*-1 ELSE VrImpuesto END) AS FacImpuesto
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN VrSeguroRem*-1 ELSE VrSeguroRem END) AS FacSeguro
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='FC' THEN VrDeclMcia ELSE 0 END) AS FacDeclarado
,MAX(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='FC' THEN FR.Factura ELSE 0 END) AS FacNumero
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND SUBSTRING(FR.TipDoc,1,2)='FC' THEN Cantidad*VrUnitario ELSE 0 END) AS FacBaseIngreso
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND SUBSTRING(FR.TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE 0 END) AS DfcBaseIngreso
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND C.MudReajuste=1 AND SUBSTRING(FR.TipDoc,1,2)='FC' THEN Cantidad*VrUnitario ELSE 0 END) AS FacReajuste
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND C.MudReajuste=1 AND SUBSTRING(FR.TipDoc,1,2)='DF' THEN Cantidad*VrUnitario ELSE 0 END) AS DfcReajuste
 FROM Trn_TraFacRemesas AS FR LEFT JOIN ConcDiversos AS C ON FR.CdConcepto=C.IdConcepto
 WHERE FR.TipRem='OSM' GROUP BY TipRem,Remesa,IdCiaRem,ItemRem) AS FC ON D.TipDoc=FC.FacTipOrd AND D.NumOrden=FC.FacNumOrden AND D.IdCia=FC.FacIdCiaOrd AND D.Item=FC.FacItemOrd
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenNovRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenNovRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
SELECT O.TipDoc,O.NumOrden,O.IdCia,O.FecDespacho,O.IdCliente,N.Item,N.Fecha,N.TipoNov,N.Descripcion,N.EstadoBod,N.CdBodAnt,BA.Bodega AS BodAnterior,N.CdBodega,B.Bodega
,N.FechaIngBod,N.FechaRetBod,N.CdConcepto,CD.Concepto,N.ValorTotal,N.Referencia,N.IdUsuario,Usuario,N.FechaCrea
FROM Trn_MudOrdenServ AS O INNER JOIN Trn_MudOrdenNov AS N ON O.TipDoc=N.TipDoc AND O.NumOrden=N.NumOrden AND O.IdCia=N.IdCia
INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
LEFT JOIN ConcDiversos AS CD ON N.CdConcepto=CD.IdConcepto
LEFT JOIN AlmBodegas AS B ON N.CdBodega=B.IdBodega LEFT JOIN AlmBodegas AS BA ON N.CdBodAnt=BA.IdBodega
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenOper_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenOper_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc,O.NumOrden,O.IdCia,O.Item,O.IdOperario,NomOperario,O.IdTipoOper,TipoOperario
,O.CdConcepto,C.Concepto,C.IdCuenta,C.TipoConc,TarifaCargo,O.PlacaVehic,O.Descripcion,O.TipoReg,O.FechaReg,O.CdUsuario,Usuario
 FROM Trn_MudOrdenOper AS O INNER JOIN TiposOperarios AS TP ON O.IdTipoOper=TP.IdOper
 LEFT JOIN Terceros AS T ON O.IdOperario=T.IdTercero
 LEFT JOIN TraConcCausac AS C ON O.CdConcepto=C.IdConcepto
 LEFT JOIN adm_Usuarios AS U ON O.CdUsuario=U.IdUsuario
 WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenOperRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenOperRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
SELECT O.TipDoc,O.NumOrden,O.IdCia,O.FecDespacho,O.IdCliente,D.Item,D.IdOperario,NomOperario,D.IdTipoOper,TipoOperario
,D.CdConcepto,C.Concepto,C.IdCuenta,C.TipoConc,D.TarifaCargo,D.PlacaVehic,D.Descripcion,D.TipoReg,D.FechaReg,D.CdUsuario,Usuario
,V.NumVeh,V.IdMarca AS CdMarca,M.Marca,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.Modelo,V.IdColor AS CdColor,NomColor,V.Config
,V.IdPoseedor AS CdPoseedor,T.RazonSocial AS Poseedor,V.TipoAfil
FROM Trn_MudOrdenServ AS O INNER JOIN Trn_MudOrdenOper AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
INNER JOIN TiposOperarios AS TP ON D.IdTipoOper=TP.IdOper LEFT JOIN TraConcCausac AS C ON D.CdConcepto=C.IdConcepto
LEFT JOIN Vehiculos AS V ON D.PlacaVehic=V.IdVehiculo
LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor
LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh LEFT JOIN Terceros AS T ON V.IdPoseedor=T.IdTercero
LEFT JOIN adm_Usuarios AS U ON D.CdUsuario=U.IdUsuario 
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServ]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdTipoServ,IdCliente,IdAgencia,IdVend,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,IdOrigen,IdDestino,VrServicio,VrEmpaque,VrBodega,VrOtros,VrDescuento,VrImpuesto,VrNeto,VrDeclarado,VrSeguro,Servicios,FormaPago,Referencia,TipInv,NumInvent,IdCiaInv,TipRem,NumRemesa,IdCiaRem,EstFactura,TipFact,NumFactura,CdCiaFact
,TipCausac,Causacion,CdCiaCau,NomContacto,TelsContacto,emlContacto,ContactoDest,emlContDest,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,EstCumplido,FechaCump,TipoRuta,Volumen,EstadoBod,CdBodega,FechaIngBod,FechaRetBod,NitRemitente,Remitente,NitDestinatario,Destinatario,NumAutCupo,NumAutMora,Referencias,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_MudOrdenServ
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServ_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenServ_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecDespacho,O.IdTipoServ AS CdTipoServ,TipoServicio,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia
,O.IdOrigen,LO.Localidad AS CiuOrigen,O.IdDestino,LD.Localidad AS CiuDestino,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest
,O.VrServicio,O.VrEmpaque,O.VrBodega,O.VrOtros,O.VrDescuento,O.VrImpuesto,O.VrNeto,O.VrDeclarado,O.VrSeguro,O.IdVend,VN.RazonSocial AS NomVendedor
,O.NomContacto,O.TelsContacto,O.emlContacto,O.ContactoDest,O.emlContDest,O.Servicios,O.FormaPago,O.Referencia,O.TipInv,O.NumInvent,O.IdCiaInv,O.TipRem,O.NumRemesa,O.IdCiaRem
,O.EstFactura,O.TipFact,O.NumFactura,O.CdCiaFact,O.TipCausac,O.Causacion,O.CdCiaCau,EstCumplido,FechaCump,TipoRuta,O.Volumen,EstadoBod,O.CdBodega,FechaIngBod,FechaRetBod
,O.NitRemitente,O.Remitente,O.NitDestinatario,O.Destinatario,O.Anulado,O.FecDev,O.Observacion AS Observ,O.Referencias,O.IdEstado AS CdEstado,Estado,O.NumAutCupo,O.NumAutMora
,D.Item,D.IdConcepto AS CdConcepto,D.Descripcion,CD.Concepto,D.ValorTotal,D.TarifaIva,D.TipoConc,D.TipoRubro,D.CdCuenta,D.NitTercero,NT.RazonSocial AS NomTercero
,D.Referencia AS DetReferencia,D.NumDocRef,D.NumDocFac,D.IndFactItem,D.TipoReg,D.TarifSeguro,D.CodTarSeg,D.PlacaVehic,D.TarifaPago,D.FechaReg,D.CdUsuario AS DetCdUsuario,UC.Usuario AS DetUsuario,TS.Transporte,TS.Bodega,TS.Empaque,TS.Personal
,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,U.Usuario
,T.Codigo AS TercCod,T.TipoId,T.Dv,T.Direccion,T.IdLocal AS TercCdLocal,L.Localidad AS TercLocalidad,T.Telefono AS TercTelefono,T.TelMovil AS TercTerCelular,T.e_mail AS TercEmail
 FROM Trn_MudOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie
 INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN MudServicios AS TS ON O.IdTipoServ=TS.IdTipoServ
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_MudOrdenConc AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto 
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN adm_Usuarios AS UC ON D.CdUsuario=UC.IdUsuario
 WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenServLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecDespacho,O.IdTipoServ AS CdTipoServ,TipoServicio,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia
,O.IdOrigen,LO.Localidad AS CiuOrigen,O.IdDestino,LD.Localidad AS CiuDestino,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest
,O.VrServicio,O.VrEmpaque,O.VrBodega,O.VrOtros,O.VrDescuento,O.VrImpuesto,O.VrNeto,O.VrDeclarado,O.VrSeguro,O.IdVend,VN.RazonSocial AS NomVendedor
,O.NomContacto,O.TelsContacto,O.emlContacto,O.ContactoDest,O.emlContDest,O.Servicios,O.FormaPago,O.Referencia,O.TipInv,O.NumInvent,O.IdCiaInv,O.TipRem,O.NumRemesa,O.IdCiaRem
,O.EstFactura,O.TipFact,O.NumFactura,O.CdCiaFact,O.TipCausac,O.Causacion,O.CdCiaCau,EstCumplido,FechaCump,TipoRuta,O.Volumen,EstadoBod,O.CdBodega,FechaIngBod,FechaRetBod
,O.NitRemitente,O.Remitente,O.NitDestinatario,O.Destinatario,O.Anulado,O.FecDev,O.Observacion AS Observ,O.Referencias,O.IdEstado AS CdEstado,Estado,O.NumAutCupo,O.NumAutMora
,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
 FROM Trn_MudOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN MudServicios AS TS ON O.IdTipoServ=TS.IdTipoServ 
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 WHERE O.TipDoc=@pmTipDoc AND O.FecDespacho BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenServRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecDespacho,O.IdTipoServ AS CdTipoServ,TipoServicio,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia
,O.IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino
,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,O.VrServicio,O.VrEmpaque,O.VrBodega,O.VrOtros,O.VrDescuento,O.VrImpuesto,O.VrNeto,O.VrDeclarado,O.VrSeguro
,O.IdVend,VN.RazonSocial AS NomVendedor,O.NomContacto,O.TelsContacto,O.emlContacto,O.ContactoDest,O.emlContDest,O.NitRemitente,O.Remitente,O.NitDestinatario,O.Destinatario,O.Servicios,O.FormaPago,O.Referencia,O.TipInv,O.NumInvent,O.IdCiaInv,O.TipRem,O.NumRemesa,O.IdCiaRem
,O.EstFactura,O.TipCausac,O.Causacion,O.CdCiaCau,O.EstCumplido,O.FechaCump,O.TipoRuta,O.Volumen,EstadoBod,O.CdBodega,B.Bodega AS NomBodega,FechaIngBod,FechaRetBod,O.Anulado,O.FecDev,O.Observacion AS Observ,O.Referencias,O.IdEstado AS CdEstado,Estado
--Detalles de orden
,D.Item,D.IdConcepto AS CdConcepto,D.Descripcion,CD.Concepto,D.ValorTotal,D.TarifaIva,D.TipoConc,D.TipoRubro,D.CdCuenta,D.NitTercero,NT.RazonSocial AS NomTercero
,D.Referencia AS DetReferencia,D.NumDocRef,D.TipoReg,D.TarifSeguro,D.CodTarSeg,D.PlacaVehic,D.TarifaPago,D.NumDocFac,D.IndFactItem,D.FechaReg,D.CdUsuario AS DetCdUsuario,UC.Usuario AS DetUsuario,TS.Transporte,TS.Bodega,TS.Empaque,TS.Personal
--datos de facturas
,FC.FacNumero,FC.FacFecha,ISNULL(FC.FacValor,0) AS FacVrTotal,ISNULL(FC.FacCosto,0) AS FacVrCosto,ISNULL(FC.FacImpuesto,0) AS FacVrIva,ISNULL(FC.FacSeguro,0) AS FacVrSeguro,FacBaseIngreso,DfcBaseIngreso,FacReajuste,DfcReajuste
--datos del tercero
,T.Codigo AS TercCod,T.TipoId,T.Dv,T.Direccion,T.IdLocal AS TercCdLocal,L.Localidad AS TercLocalidad,T.Telefono AS TercTelefono,T.TelMovil AS TercTerCelular,T.e_mail AS TercEmail
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupo,GrupoClie,CLI.IdPlazo AS CdPlazo,Plazo
,V.NumVeh,V.TipoAfil,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,V.Modelo,V.IdPoseedor AS NitPoseedor,NP.RazonSocial AS Poseedor
,V.IdConductor AS CedConductor,CDT.RazonSocial AS Conductor,V.NumSoat,V.VigSoat
,O.NumAutCupo,O.NumAutMora,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,U.Usuario
 FROM Trn_MudOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie
 INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN MudServicios AS TS ON O.IdTipoServ=TS.IdTipoServ
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_MudOrdenConc AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN ConcDiversos AS CD ON D.IdConcepto=CD.IdConcepto 
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 LEFT JOIN Terceros AS NT ON D.NitTercero=NT.IdTercero LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 LEFT JOIN AlmBodegas AS B ON O.CdBodega=B.IdBodega
 LEFT JOIN Vehiculos AS V ON D.PlacaVehic=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca LEFT JOIN TiposCol AS CLR ON V.IdColor=CLR.IdColor
 LEFT JOIN Terceros AS NP ON V.IdPoseedor=NP.IdTercero LEFT JOIN Terceros AS CDT ON V.IdConductor=CDT.IdTercero
 LEFT JOIN adm_Usuarios AS UC ON D.CdUsuario=UC.IdUsuario
 --Facturas item por item
 LEFT JOIN (SELECT TipRem AS FacTipOrd,Remesa AS FacNumOrden,IdCiaRem AS FacIdCiaOrd,ItemRem AS FacItemOrd,MAX(FecRemesa) AS FacFecha
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE Cantidad*VrUnitario END) AS FacValor
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN (Cantidad*VrCosto)*-1 ELSE Cantidad*VrCosto END) AS FacCosto
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN VrImpuesto*-1 ELSE VrImpuesto END) AS FacImpuesto
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='DF' THEN VrSeguroRem*-1 ELSE VrSeguroRem END) AS FacSeguro
,SUM(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='FC' THEN VrDeclMcia ELSE 0 END) AS FacDeclarado
,MAX(CASE WHEN SUBSTRING(FR.TipDoc,1,2)='FC' THEN FR.Factura ELSE 0 END) AS FacNumero
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND SUBSTRING(FR.TipDoc,1,2)='FC' THEN Cantidad*VrUnitario ELSE 0 END) AS FacBaseIngreso
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND SUBSTRING(FR.TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE 0 END) AS DfcBaseIngreso
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND C.MudReajuste=1 AND SUBSTRING(FR.TipDoc,1,2)='FC' THEN Cantidad*VrUnitario ELSE 0 END) AS FacReajuste
,SUM(CASE WHEN FR.Referencia3='TRANSPORTE' AND C.MudReajuste=1 AND SUBSTRING(FR.TipDoc,1,2)='DF' THEN Cantidad*VrUnitario ELSE 0 END) AS DfcReajuste
 FROM Trn_TraFacRemesas AS FR LEFT JOIN ConcDiversos AS C ON FR.CdConcepto=C.IdConcepto
 WHERE FR.TipRem='OSM' GROUP BY TipRem,Remesa,IdCiaRem,ItemRem) AS FC ON D.TipDoc=FC.FacTipOrd AND D.NumOrden=FC.FacNumOrden AND D.IdCia=FC.FacIdCiaOrd AND D.Item=FC.FacItemOrd
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServReq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenServReq] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecDespacho,O.IdTipoServ AS CdTipoServ,TipoServicio,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia
,O.IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino
,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,O.VrServicio,O.VrEmpaque,O.VrBodega,O.VrOtros,O.VrDescuento,O.VrImpuesto,O.VrNeto,O.VrDeclarado,O.VrSeguro
,O.IdVend,VN.RazonSocial AS NomVendedor,O.NomContacto,O.TelsContacto,O.emlContacto,O.ContactoDest,O.emlContDest,O.Servicios,O.FormaPago,O.Referencia,O.TipInv,O.NumInvent,O.IdCiaInv,O.TipRem,O.NumRemesa,O.IdCiaRem
,O.EstFactura,O.TipCausac,O.Causacion,O.CdCiaCau,O.EstCumplido,O.FechaCump,O.TipoRuta,O.Volumen,EstadoBod,O.CdBodega,B.Bodega AS NomBodega,FechaIngBod,FechaRetBod,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,ED.Estado
,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
--datos de la requisc
,RQ.TipReq,RQ.Requisicion,RQ.CdCiaReq,RQ.FechaReq,RQ.IdRespons,NR.RazonSocial AS Responsable,RQ.CdDep,Dependencia,RQ.NumAprob,RQ.FecAprob,RQ.TipoVigencia,RQ.Observacion AS ReqObservacion,RQ.IdEstado AS ReqIdEstado,ER.Estado AS ReqEstado
,RQ.Item,RQ.CdProducto,DescripProd,RQ.Descripcion,RQ.IdSubgrupo,Subgrupo,RQ.CdBodega AS ReqCdBodega,BG.Bodega AS ReqBodega,RQ.Cantidad,RQ.IdUnd AS CdUnd,Unidad,RQ.VrUnitario,RQ.TipOrd AS TipOdc,RQ.OrdenComp,RQ.IdCiaOc
,RQ.TipSal,RQ.NSalida,RQ.IdCiaSal,RQ.FechaSal,RQ.CantSalida,RQ.CantDevSal,RQ.Referencia AS ReqReferencia
--datos del tercero
,T.Codigo AS TercCod,T.TipoId,T.Dv,T.Direccion,T.IdLocal AS TercCdLocal,L.Localidad AS TercLocalidad,T.Telefono AS TercTelefono,T.TelMovil AS TercTerCelular,T.e_mail AS TercEmail
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupo,GrupoClie,CLI.IdPlazo AS CdPlazo,Plazo
 FROM Trn_MudOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie
 INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN MudServicios AS TS ON O.IdTipoServ=TS.IdTipoServ
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN AlmBodegas AS B ON O.CdBodega=B.IdBodega
 --requisiciones
 LEFT JOIN (SELECT R.NContrato AS NumOrden,R.IdCiaCont AS CdCiaOrden,R.TipDoc AS TipReq,R.Requisicion,R.IdCia AS CdCiaReq,R.Fecha AS FechaReq
,R.IdRespons,R.IdDep AS CdDep,R.NumAprob,R.FecAprob,R.NivelAprob,R.TipoVigencia,R.Num_Vehic,R.Observacion,R.IdEstado
,D.Item,D.CdProducto,D.Descripcion,D.IdSubgrupo,D.CdBodega,D.Cantidad,D.IdUnd,D.VrUnitario,D.TipOrd,D.NumOrden AS OrdenComp,D.IdCiaOrd AS IdCiaOc
,D.TipSal,D.NSalida,D.IdCiaSal,D.FechaSal,D.CantSalida,D.CantDevSal,D.Referencia
FROM Trn_Requisicion AS R INNER JOIN Trn_ReqDetalle AS D ON R.TipDoc=D.TipDoc AND R.Requisicion=D.Requisicion AND R.IdCia=D.IdCia
WHERE R.TipDoc='REQ' AND R.Modalidad='MUDANZAS' AND R.Anulado=0) AS RQ ON O.NumOrden=RQ.NumOrden AND O.IdCia=RQ.CdCiaOrden
 LEFT JOIN Terceros AS NR ON RQ.IdRespons=NR.IdTercero LEFT JOIN Dependencias AS DP ON RQ.CdDep=DP.IdDep
 LEFT JOIN EstadoDoc AS ER ON RQ.IdEstado=ER.IdEstado LEFT JOIN ProdMcias AS P ON RQ.CdProducto=P.IdProducto
 LEFT JOIN UndMed AS UM ON RQ.IdUnd=UM.IdUnd LEFT JOIN SubGrupos AS SG ON RQ.IdSubgrupo=SG.IdSubgrupo
 LEFT JOIN Bodegas AS BG ON RQ.CdBodega=BG.IdBodega
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenServVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenServVeh] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecDespacho,O.IdTipoServ AS CdTipoServ,TipoServicio,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia
,O.IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino
,DirCargue,TipoInmRem,PisoCargue,TelsRemite,CelRemite,DirDescargue,TipoInmDest,PisoDescargue,TelsDest,CelDest,O.VrServicio,O.VrEmpaque,O.VrBodega,O.VrOtros,O.VrDescuento,O.VrImpuesto,O.VrNeto,O.VrDeclarado,O.VrSeguro
,O.IdVend,VN.RazonSocial AS NomVendedor,O.NomContacto,O.TelsContacto,O.emlContacto,O.ContactoDest,O.emlContDest,O.NitRemitente,O.Remitente,O.NitDestinatario,O.Destinatario,O.Servicios,O.FormaPago,O.Referencia,O.TipInv,O.NumInvent,O.IdCiaInv
,O.EstFactura,O.TipCausac,O.Causacion,O.CdCiaCau,O.EstCumplido,O.FechaCump,O.TipoRuta,O.Volumen,EstadoBod,O.CdBodega,B.Bodega AS NomBodega,FechaIngBod,FechaRetBod,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
--Detalles de vehículos
,VH.Item,VH.IdVehiculo,VH.TipoAfiVehic,VH.NitEmpresa,NomEmpresa,VH.nRemolque,VH.IdConductor,NC.RazonSocial AS Conductor,IdCondAux,NA.RazonSocial AS CondAuxiliar,VH.TipDocRef AS TipRem,VH.NumDocRef AS NumRemesa,VH.CdCiaRef AS CdCiaRem
,VH.CdTipoOper,TipoOperacion,VH.TipoIngreso,VH.TarifaIng,VH.VrIngreso,V.NumVeh,V.IdMarca AS CdMarca,MV.Marca,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.Modelo,V.IdColor AS CdColor,NomColor,V.Config,V.IdPoseedor AS CdPoseedor,NP.RazonSocial AS Poseedor
,V.NumSoat,VigSoat,V.NitEmpSoat,EST.RazonSocial AS NomEmpSoat,V.SerieChasis,V.CarrCapac,V.UndCapc
,CDT.Licencia AS NumLicencia,CDT.CatLicencia,CDT.VigLicencia,CDA.Licencia AS AuxNumLicencia,CDA.CatLicencia AS AuxCategLic,CDA.VigLicencia AS AuxVigLicencia
--datos de remesas
,ISNULL(RM.RemVrTotal,0) AS RemVrTotal,ISNULL(RM.RemVrPago,0) AS RemVrPago,ISNULL(RM.MucNumero,0) AS MucNumero,ISNULL(RM.MucVrPago,0) AS MucVrPago
,ISNULL(OP.OdpNumero,0) AS NumOrdPago,ISNULL(OP.OdpVrPago,0) AS OdpVrPago,ISNULL(OP.OdpTarifa,0) AS OdpTarifa,ISNULL(OP.OdpVrTotal,0) AS OdpTotal
--datos del tercero
,T.Codigo AS TercCod,T.TipoId,T.Dv,T.Direccion,T.IdLocal AS TercCdLocal,L.Localidad AS TercLocalidad,T.Telefono AS TercTelefono,T.TelMovil AS TercTerCelular,T.e_mail AS TercEmail
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupo,GrupoClie,CLI.IdPlazo AS CdPlazo,Plazo
,TS.Transporte,TS.Bodega,TS.Empaque,TS.Personal,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,U.Usuario
 FROM Trn_MudOrdenServ AS O INNER JOIN Trn_MudOrdenVeh AS VH ON O.TipDoc=VH.TipDoc AND O.NumOrden=VH.NumOrden AND O.IdCia=VH.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie
 INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN MudServicios AS TS ON O.IdTipoServ=TS.IdTipoServ
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN Vehiculos AS V ON VH.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS NC ON VH.IdConductor=NC.IdTercero  
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca
 INNER JOIN TiposCol AS CLR ON V.IdColor=CLR.IdColor INNER JOIN Terceros AS NP ON V.IdPoseedor=NP.IdTercero
 LEFT JOIN TercCndtores AS CDT ON VH.IdConductor=CDT.IdConductor
 LEFT JOIN Terceros AS NA ON VH.IdCondAux=NA.IdTercero LEFT JOIN TercCndtores AS CDA ON VH.IdCondAux=CDA.IdConductor
 LEFT JOIN Terceros AS EST ON V.NitEmpSoat=EST.IdTercero LEFT JOIN TiposOperac AS TP ON VH.CdTipoOper=TP.IdTipoOper
 LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN AlmBodegas AS B ON O.CdBodega=B.IdBodega
 LEFT JOIN (SELECT D.TipDoc AS RemTipo,D.NumOrden AS RemNumero,D.IdCia AS RemIdCia
 ,SUM(CASE D.UndTarifa WHEN 'PESO' THEN D.PesoNeto*D.TarifClie WHEN 'UNIDADES' THEN D.Cantidad*D.TarifClie WHEN 'VOLUMEN' THEN D.Volumen*D.TarifClie ELSE D.PesoNeto*D.TarifClie END) AS RemVrTotal
 ,SUM(CASE D.UndTarifPago WHEN 'PESO' THEN D.PesoNeto*D.TarifPago WHEN 'UNIDADES' THEN D.Cantidad*D.TarifPago WHEN 'VOLUMEN' THEN D.Volumen*D.TarifPago ELSE D.PesoNeto*D.TarifPago END) AS RemVrPago
 ,SUM(CASE D.UndTarifPago WHEN 'PESO' THEN D.PesoNeto*MR.TarifPago WHEN 'UNIDADES' THEN D.Cantidad*MR.TarifPago WHEN 'VOLUMEN' THEN D.Volumen*MR.TarifPago ELSE D.PesoNeto*MR.TarifPago END) AS MucVrPago
 ,MAX(MR.Manifiesto) AS MucNumero
  FROM Trn_TraRemMcias AS D INNER JOIN Trn_TraRemesa AS R ON D.TipDoc=R.TipDoc AND D.NumOrden=R.NumOrden AND D.IdCia=R.IdCia
  LEFT JOIN Trn_TraManifRem AS MR ON D.TipDoc=MR.TipRem AND D.NumOrden=MR.Remesa AND D.IdCia=MR.IdCiaRem AND D.Item=MR.ItemRem
  LEFT JOIN Trn_TraManifiesto AS M ON MR.TipDoc=M.TipDoc AND MR.Manifiesto=M.Manifiesto AND MR.IdCia=M.IdCia
  WHERE D.TipDoc='RMT' AND R.Anulado=0 AND ISNULL(M.Anulado,0)=0 GROUP BY D.TipDoc,D.NumOrden,D.IdCia) AS RM ON VH.TipDocRef=RM.RemTipo AND VH.NumDocRef=RM.RemNumero AND VH.CdCiaRef=RM.RemIdCia
 LEFT JOIN (SELECT OD.TipRem,OD.Remesa,OD.IdCiaRem,MAX(OD.OrdPago) AS OdpNumero,MAX(OD.Manifiesto) AS OdpNumManif
 ,SUM(CASE OD.UndTarifa WHEN 'PESO' THEN OD.PesoNeto*OD.TarifPago WHEN 'UNIDADES' THEN OD.Cantidad*OD.TarifPago WHEN 'VOLUMEN' THEN OD.Volumen*OD.TarifPago ELSE OD.PesoNeto*OD.TarifPago END) AS OdpVrPago
 ,MAX(OM.TarifaFlete) AS OdpTarifa,SUM(OM.VrTotalFletes-OM.VrDescuento) AS OdpVrTotal
 FROM Trn_TraOrdenRemesas AS OD INNER JOIN Trn_TraOrdenManif AS OM ON OD.TipDoc=OM.TipDoc AND OD.OrdPago=OM.OrdPago AND OD.IdCia=OM.IdCia
 INNER JOIN Trn_TraOrdenPago AS O ON OD.TipDoc=O.TipDoc AND OD.OrdPago=O.OrdPago AND OD.IdCia=O.IdCia
 WHERE OD.TipRem='RMT' AND O.Anulado=0 GROUP BY OD.TipRem,OD.Remesa,OD.IdCiaRem) AS OP ON VH.TipDocRef=OP.TipRem AND VH.NumDocRef=OP.Remesa AND VH.CdCiaRef=OP.IdCiaRem
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenVeh_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenVeh_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT VH.TipDoc,VH.NumOrden,VH.IdCia,VH.Item,VH.IdVehiculo,VH.TipoAfiVehic,VH.NitEmpresa,NomEmpresa,VH.nRemolque
,VH.IdConductor,NC.RazonSocial AS Conductor,IdCondAux,NA.RazonSocial AS CondAuxiliar,TipDocRef,VH.NumDocRef,CdCiaRef,VH.CdTipoOper,TipoOperacion
,VH.TipoIngreso,VH.TarifaIng,VH.VrIngreso
,V.NumVeh,V.IdMarca AS CdMarca,MV.Marca,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.Modelo,V.IdColor AS CdColor,NomColor,V.Config
,V.IdPoseedor AS CdPoseedor,T.RazonSocial AS Poseedor,V.NumSoat,VigSoat,V.SerieChasis,V.CarrCapac,V.UndCapc
,CDT.Licencia AS NumLicencia,CDT.CatLicencia,CDT.VigLicencia
,CDA.Licencia AS AuxNumLicencia,CDA.CatLicencia AS AuxCategLic,CDA.VigLicencia AS AuxVigLicencia
 FROM Trn_MudOrdenVeh AS VH INNER JOIN Vehiculos AS V ON VH.IdVehiculo=V.IdVehiculo
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN TiposCol AS C ON V.IdColor=C.IdColor
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Terceros AS T ON V.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS NC ON VH.IdConductor=NC.IdTercero
 LEFT JOIN Terceros AS NA ON VH.IdCondAux=NA.IdTercero
 LEFT JOIN TercCndtores AS CDT ON VH.IdConductor=CDT.IdConductor LEFT JOIN TercCndtores AS CDA ON VH.IdCondAux=CDA.IdConductor
 LEFT JOIN TiposOperac AS TP ON VH.CdTipoOper=TP.IdTipoOper
 WHERE VH.TipDoc=@pmTipDoc AND VH.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND VH.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryMudOrdenVehRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudOrdenVehRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.TipDoc,O.NumOrden,O.IdCia,O.FecDespacho,O.IdCliente,VH.Item,VH.IdVehiculo,VH.TipoAfiVehic,VH.NitEmpresa,NomEmpresa,VH.nRemolque
,VH.IdConductor,NC.RazonSocial AS Conductor,IdCondAux,NA.RazonSocial AS CondAuxiliar,VH.TipDocRef AS TipRem,VH.NumDocRef AS NumRemesa,VH.CdCiaRef AS CdCiaRem
,VH.CdTipoOper,TipoOperacion,VH.TipoIngreso,VH.TarifaIng,VH.VrIngreso
,V.NumVeh,V.IdMarca AS CdMarca,MV.Marca,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.Modelo,V.IdColor AS CdColor,NomColor,V.Config
,V.IdPoseedor AS CdPoseedor,T.RazonSocial AS Poseedor,V.NumSoat,VigSoat,V.NitEmpSoat,EST.RazonSocial AS NomEmpSoat,V.SerieChasis,V.CarrCapac,V.UndCapc
,CDT.Licencia AS NumLicencia,CDT.CatLicencia,CDT.VigLicencia
,CDA.Licencia AS AuxNumLicencia,CDA.CatLicencia AS AuxCategLic,CDA.VigLicencia AS AuxVigLicencia
--datos de remesas
,ISNULL(RM.RemVrTotal,0) AS RemVrTotal,ISNULL(RM.RemVrPago,0) AS RemVrPago,ISNULL(RM.MucNumero,0) AS MucNumero,ISNULL(RM.MucVrPago,0) AS MucVrPago
,ISNULL(OP.OdpNumero,0) AS NumOrdPago,ISNULL(OP.OdpVrPago,0) AS OdpVrPago,ISNULL(OP.OdpTarifa,0) AS OdpTarifa,ISNULL(OP.OdpVrTotal,0) AS OdpTotal
 FROM Trn_MudOrdenServ AS O INNER JOIN Trn_MudOrdenVeh AS VH ON O.TipDoc=VH.TipDoc AND O.NumOrden=VH.NumOrden AND O.IdCia=VH.IdCia
 INNER JOIN Vehiculos AS V ON VH.IdVehiculo=V.IdVehiculo
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN TiposCol AS C ON V.IdColor=C.IdColor
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Terceros AS T ON V.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS NC ON VH.IdConductor=NC.IdTercero 
 LEFT JOIN Terceros AS NA ON VH.IdCondAux=NA.IdTercero LEFT JOIN Terceros AS EST ON V.NitEmpSoat=EST.IdTercero
 LEFT JOIN TercCndtores AS CDT ON VH.IdConductor=CDT.IdConductor LEFT JOIN TercCndtores AS CDA ON VH.IdCondAux=CDA.IdConductor
 LEFT JOIN TiposOperac AS TP ON VH.CdTipoOper=TP.IdTipoOper
 LEFT JOIN (SELECT D.TipDoc AS RemTipo,D.NumOrden AS RemNumero,D.IdCia AS RemIdCia
 ,SUM(CASE D.UndTarifa WHEN 'PESO' THEN D.PesoNeto*D.TarifClie WHEN 'UNIDADES' THEN D.Cantidad*D.TarifClie WHEN 'VOLUMEN' THEN D.Volumen*D.TarifClie ELSE D.PesoNeto*D.TarifClie END) AS RemVrTotal
 ,SUM(CASE D.UndTarifPago WHEN 'PESO' THEN D.PesoNeto*D.TarifPago WHEN 'UNIDADES' THEN D.Cantidad*D.TarifPago WHEN 'VOLUMEN' THEN D.Volumen*D.TarifPago ELSE D.PesoNeto*D.TarifPago END) AS RemVrPago
 ,SUM(CASE D.UndTarifPago WHEN 'PESO' THEN D.PesoNeto*MR.TarifPago WHEN 'UNIDADES' THEN D.Cantidad*MR.TarifPago WHEN 'VOLUMEN' THEN D.Volumen*MR.TarifPago ELSE D.PesoNeto*MR.TarifPago END) AS MucVrPago
 ,MAX(MR.Manifiesto) AS MucNumero
  FROM Trn_TraRemMcias AS D INNER JOIN Trn_TraRemesa AS R ON D.TipDoc=R.TipDoc AND D.NumOrden=R.NumOrden AND D.IdCia=R.IdCia
  LEFT JOIN Trn_TraManifRem AS MR ON D.TipDoc=MR.TipRem AND D.NumOrden=MR.Remesa AND D.IdCia=MR.IdCiaRem AND D.Item=MR.ItemRem
  LEFT JOIN Trn_TraManifiesto AS M ON MR.TipDoc=M.TipDoc AND MR.Manifiesto=M.Manifiesto AND MR.IdCia=M.IdCia
  WHERE D.TipDoc='RMT' AND R.Anulado=0 AND ISNULL(M.Anulado,0)=0 GROUP BY D.TipDoc,D.NumOrden,D.IdCia) AS RM ON VH.TipDocRef=RM.RemTipo AND VH.NumDocRef=RM.RemNumero AND VH.CdCiaRef=RM.RemIdCia
 LEFT JOIN (SELECT OD.TipRem,OD.Remesa,OD.IdCiaRem,MAX(OD.OrdPago) AS OdpNumero,MAX(OD.Manifiesto) AS OdpNumManif
 ,SUM(CASE OD.UndTarifa WHEN 'PESO' THEN OD.PesoNeto*OD.TarifPago WHEN 'UNIDADES' THEN OD.Cantidad*OD.TarifPago WHEN 'VOLUMEN' THEN OD.Volumen*OD.TarifPago ELSE OD.PesoNeto*OD.TarifPago END) AS OdpVrPago
 ,MAX(OM.TarifaFlete) AS OdpTarifa,SUM(OM.VrTotalFletes-OM.VrDescuento) AS OdpVrTotal
 FROM Trn_TraOrdenRemesas AS OD INNER JOIN Trn_TraOrdenManif AS OM ON OD.TipDoc=OM.TipDoc AND OD.OrdPago=OM.OrdPago AND OD.IdCia=OM.IdCia
 INNER JOIN Trn_TraOrdenPago AS O ON OD.TipDoc=O.TipDoc AND OD.OrdPago=O.OrdPago AND OD.IdCia=O.IdCia
 WHERE OD.TipRem='RMT' AND O.Anulado=0 GROUP BY OD.TipRem,OD.Remesa,OD.IdCiaRem) AS OP ON VH.TipDocRef=OP.TipRem AND VH.NumDocRef=OP.Remesa AND VH.CdCiaRef=OP.IdCiaRem
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryMudSecciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudSecciones] @pmIdSeccion VARCHAR(4)
 AS 
 IF @pmIdSeccion IS NULL
  BEGIN
   SELECT IdSeccion,Seccion FROM MudSecciones
   WHERE Inactivo=0
   ORDER BY Seccion
  END
 ELSE
  BEGIN
   SELECT IdSeccion,Seccion,Inactivo 
   FROM MudSecciones WHERE IdSeccion=@pmIdSeccion
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryMudServicios]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudServicios] @pmIdTipoServ VARCHAR(4)
 AS 
 SELECT IdTipoServ,TipoServicio,Transporte,Bodega,Empaque,Personal,Inactivo
 FROM MudServicios
 WHERE IdTipoServ=@pmIdTipoServ
GO
/****** Object:  StoredProcedure [dbo].[paQryMudServiciosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryMudServiciosDso]  
 AS 
 SELECT IdTipoServ,TipoServicio,TipoServicio+' '+IdTipoServ AS DsServ
 FROM MudServicios
 WHERE Inactivo=0
 ORDER BY TipoServicio
GO
/****** Object:  StoredProcedure [dbo].[paQryNERecordLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNERecordLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
AS 
SELECT N.TipoReg,N.NumRegistro,N.IdCia,N.Fecha,N.IdEmpleado,E.Apellidos,E.Nombres,N.NContrato,N.IdPeriodo,N.FecInicial,N.FecFinal
,N.Cantidad,N.CantNoRem,N.VrDevengado,N.VrDeducido,N.IdDep,Dependencia,N.IdInstala,IST.Instlacion,N.IdCCosto,CCosto,N.IdSubCos,SubCosto
,N.IdNom,TipoNomina,N.TipoLiq,N.VrSalario,N.VrATransMes,N.EsRetiro,N.NLiqRet,N.pVehiculo,N.FecIniPmd,N.FecFinPmd,N.TipCom,N.Comprobante,N.IdCiaCom
,N.CdTipoCot,N.SubTipo_Cot,N.Sal_Integral,N.TipoIdent,N.NotasAportante,N.Observacion,N.IdEstado,EN.Estado AS Nom_Estado,N.FechaCrea,N.IdUsuario,Usuario
,N.CantModifica,N.NE_Estado,N.NE_Prefijo,N.NE_Numero,N.NE_FecEnvio,N.NE_CUNE,N.NE_CntAju,N.NE_Ajustes,N.IdRegNom
--,N.DiasVac,N.NPeriodos,N.CantRem,N.VrRemndo,N.EsParcial,N.NumLiquida,N.NumSemLiq
,D.Item,D.IdConcepto,CN.Concepto,CN.ClaseCon,D.Detalle,D.CantDevg,D.VrUnitario,D.VrTotDevg,D.CantDed,D.VrTotDed,D.Unidad,D.ClaseLiq,D.VrOrigen,D.Tarifa,D.DiasCalc,D.DiasNov
,D.CodFondo,F.Fondo,D.NPrestamo,D.NCuota,D.OrigCargue,D.VrBaseLiq,D.VrBasExceso,D.NitTercero,T.RazonSocial,D.HoraInicial,D.HoraFinal,D.TipoIncLab
--datos del contrato
,E.Codigo,E.Direccion,E.Telefono,E.TelMovil,E.e_mail,E.IdProf,Profesion,C.IdCargo,Cargo,C.IdTipCon,TipoContrato,C.FecIngreso,C.FecRetiro,C.Indefinido
,C.FPnomina,C.ATFinMes,C.SegFinMes,C.IdEstado AS Con_IdEstado,ECO.Estado AS Con_Estado,C.Inactivo AS Con_Inactivo
FROM Trn_NERecord AS N INNER JOIN Trn_NERecordDet AS D ON N.TipoReg=D.TipoReg AND N.NumRegistro=D.NumRegistro AND N.IdCia=D.IdCia
INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom 
INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep INNER JOIN Instalaciones AS IST ON N.IdInstala=IST.IdInstala
INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado
INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado
INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
LEFT JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN Fondos AS F ON D.CodFondo=F.IdFondo
WHERE N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (N.IdPeriodo=@pmIdPeriodo OR @pmIdPeriodo IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifComp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNiifComp] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipCom,Comprobante,IdCia,Fecha,IdTercero,VrTotal,IdCta,EnEfectivo,NumCheque,FecCheque,TipDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,VehPropio,CedCondtor,CodConce,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3,PermEditar,Integrado,EsEgreso,Anticipo,Observacion,IdEstado
,Propddes,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,TipoNiif,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,CtbTipo,CtbNumero,FisTipo,FisNumero
 FROM Trn_NiifComp
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifComp_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNiifComp_Cr] @pmTipCom VARCHAR(3),@pmComprobanteIni INT,@pmComprobanteFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipCom AS IdTipoComp,TipoCom,C.Comprobante AS NumComprob,C.IdCia AS CdCia,Compania,C.Fecha AS FechaComp
,C.IdTercero AS ComNitTercero,T.RazonSocial AS ComNomTercero,VrTotal,C.IdCta AS IdCtaCte,NumeroCta,CTA.IdBanco AS CdBanco,Banco
,EnEfectivo,C.NumCheque AS ComNumCheque,FecCheque,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,C.VehPropio AS VehEsPropio
,CedCondtor,CD.RazonSocial AS NomConductor,C.CodConce AS CodConcepto,CN.Concepto,Beneficiario,VrDivisa1,VrDivisa2,VrDivisa3
,PermEditar,C.Integrado AS EsIntegracion,C.EsEgreso AS ComEsEgreso,Anticipo,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TipoNiif
,Propddes,C.TimeSys AS Fec_Add,C.FecUpdate AS Fec_Update,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut
,CtbTipo,CtbNumero,FisTipo,FisNumero
--detalle
,Item,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,IdVehiculo,D.VehPropio AS DetVehPropio
,D.IdCCosto AS CdCentCosto,CCosto,D.IdSubCos AS CdSubCentro,SubCosto,VrBase,TarifaBase,D.TipDoc AS TipoDoc,D.Documento AS NumDoc,D.IdCiaDoc AS CdCiaDoc
,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,D.NumCheque AS DetNumCheque,TipoAplica,Consolida,CodCargo
,NitOtros,DO.RazonSocial AS NombreOtros,CodSubgpo,Subgrupo,CiuOrigen,DL.Localidad AS NomCiudadOrigen,CodAgncia,DA.Agencia AS NomAgencia,CodAgencia,Referencia
,Referncia,NitDoc,DND.RazonSocial AS NombreNitDoc,TipDocRef,DocRef,IdCiaRef,CdConcTrib,TB.Concepto AS DescConcTrib,CdTarifTrib,NumEstablec,PtoEmision,Num_Autoriza,FechAutoriza,CodCuentaCG
--informacion del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_NiifComp AS C INNER JOIN Trn_NiifDetalle AS D ON C.TipCom=D.TipCom AND C.Comprobante=D.Comprobante AND C.IdCia=D.IdCia
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero  LEFT JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 LEFT JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Terceros AS CD ON C.CedCondtor=CD.IdTercero LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS DO ON D.NitOtros=DO.IdTercero
 LEFT JOIN SubGrupos AS S ON D.CodSubgpo=S.IdSubgrupo
 LEFT JOIN Localidades AS DL ON D.CiuOrigen=DL.IdLocal
 LEFT JOIN Agencias AS DA ON D.CodAgncia=DA.IdAgencia
 LEFT JOIN Terceros AS DND ON D.NitDoc=DND.IdTercero LEFT JOIN ConceptosTrib AS TB ON D.CdConcTrib=TB.IdConcepto
 WHERE C.TipCom=@pmTipCom AND C.Comprobante BETWEEN @pmComprobanteIni AND @pmComprobanteFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifCompLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNiifCompLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmTipoNiif VARCHAR(10)=Null
 AS 
 SELECT TipCom,TipoCom,Comprobante,C.IdCia AS CdCia,Compania,Fecha,C.TipoNiif,C.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrTotal,C.IdCta AS CodCta,NumeroCta
,CTE.IdBanco AS CodBanco,Banco,EnEfectivo,NumCheque,FecCheque,TipDoc,TipoDoc,Documento,IdCiaDoc,Anulado,NumDev,FecDev,TipEgr,NEgreso,CtbTipo,CtbNumero,FisTipo,FisNumero,pVehiculo,VehPropio
,C.CedCondtor AS NitOtros,CT.RazonSocial AS NomNitOtros,CodConce,Concepto,Beneficiario,Integrado,C.EsEgreso AS EsCompEgreso,Anticipo,C.Observacion AS Observ,C.IdEstado AS CodEstado,Estado,Propddes
,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,CdSustento,Tipo_Pago,Establec,PEmision,Autorizac,FechaAut,VrDivisa1,VrDivisa2,VrDivisa3,TC.IdDiario AS CdDiario,Diario
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_NiifComp AS C INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTE ON C.IdCta=CTE.IdCta LEFT JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 LEFT JOIN Terceros AS CT ON C.CedCondtor=CT.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND (@pmTipCom IS NULL OR TipCom=@pmTipCom)
 AND (@pmIdCia IS NULL OR C.IdCia=@pmIdCia)
 AND (@pmTipoNiif IS NULL OR C.TipoNiif=@pmTipoNiif)
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifDetalleLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNiifDetalleLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmTipoNiif VARCHAR(10)=Null
 AS 
 SELECT C.TipCom AS IdTipoComp,TipoCom,C.Comprobante AS NumComp,C.IdCia AS CdCia,Compania,C.Fecha AS FecComp,C.TipoNiif,C.IdTercero AS Nit,T.RazonSocial AS RaznSocial
,VrTotal,C.IdCta AS CodCta,NumeroCta,CTE.IdBanco AS CodBanco,Banco,EnEfectivo,C.NumCheque AS NroCheque,FecCheque,C.TipDoc AS IdTipoDoc,TipoDoc,C.Documento AS NroDoc,C.IdCiaDoc AS CdCiaDoc
,Anulado,NumDev,FecDev,TipEgr,NEgreso,pVehiculo,C.VehPropio AS EsVehPropio,C.CodConce AS CdConcep,Concepto,Beneficiario,C.Integrado AS EsIntegrado,C.EsEgreso AS EsCompEgreso
,Anticipo,C.Observacion AS Observ,C.IdEstado AS CodEstado,Estado,Propddes,FisTipo,FisNumero,pVehiculo
--detalles de comprobantes
,Item,D.IdCuenta AS CdCuenta,P.NomCuenta,CodCuentaCG,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,IdVehiculo
,D.IdCCosto AS CdCentCosto,CCosto,D.IdSubCos AS CdSubCentro,SubCosto,VrBase,TarifaBase
,D.TipDoc AS DetTipDoc,D.Documento AS DetNumDoc,D.IdCiaDoc AS DetCiaDoc,D.CodConce AS DetConcept,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,D.NumCheque AS DetNumCheque
,TipoAplica,Consolida,CodCargo,NitOtros,NIO.RazonSocial AS NomNitOtros,CodSubgpo,Subgrupo,CiuOrigen,LD.Localidad AS NomCiudad,CodAgncia,Referncia
,NitDoc,ND.RazonSocial AS NomNitDoc,TipDocRef,DocRef,IdCiaRef
,C.TimeSys AS FechaAdd,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,VrDivisa1,VrDivisa2,VrDivisa3,TC.IdDiario AS CdDiario,Diario
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_NiifComp AS C INNER JOIN Trn_NiifDetalle AS D ON C.TipCom=D.TipCom AND C.Comprobante=D.Comprobante AND C.IdCia=D.IdCia
 INNER JOIN TiposCom AS TC ON C.TipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN PucNiif AS P ON D.IdCuenta=P.IdCuenta
 INNER JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero
 INNER JOIN CentroCosto AS O ON D.IdCCosto=O.IdCCosto
 LEFT JOIN CtasCorrientes AS CTE ON C.IdCta=CTE.IdCta LEFT JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NIO ON D.NitOtros=NIO.IdTercero
 LEFT JOIN Terceros AS ND ON D.NitDoc=ND.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN Localidades AS LD ON D.CiuOrigen=LD.IdLocal
 LEFT JOIN SubGrupos AS SG ON  D.CodSubgpo=SG.IdSubgrupo
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND (@pmTipCom IS NULL OR C.TipCom=@pmTipCom)
 AND (@pmIdCia IS NULL OR C.IdCia=@pmIdCia)
 AND (@pmTipoNiif IS NULL OR C.TipoNiif=@pmTipoNiif)
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifPoliticasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNiifPoliticasLta]
 AS 
 SELECT [Id],P.IdPolitica,P.Descripcion,ClasePol,Objetivo,Alcance,Reconocimiento,Med_Inicial,Med_Final
,PdoVigencia,Vigencia,Notas,Anexo,P.Inactivo,P.FechaCrea,P.IdUsuario AS CdUsuario,Usuario
,CdCuenta,NomCuenta
 FROM Trn_NiifPoliticas AS P INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Trn_NiifPolCuentas AS C ON P.IdPolitica=C.IdPolitica
 LEFT JOIN (SELECT IdCuenta,NomCuenta,Movimiento FROM Puc UNION SELECT IdCuenta,NomCuenta,Movimiento FROM PucNiif) AS PC ON C.CdCuenta=PC.IdCuenta
 WHERE P.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifRevelacLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNiifRevelacLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT R.TipCom,TipoCom,R.Comprobante AS NumComp,R.IdCia AS CdCia,Compania,C.Fecha,C.IdTercero AS NitTercero,T.RazonSocial,C.VrTotal,C.IdCta AS CdCta,NumeroCta
,CTA.IdBanco AS CdBanco,Banco,EnEfectivo,C.NumCheque AS ComNumCheque,FecCheque,Anulado,NumDev,FecDev,pVehiculo,C.VehPropio,CedCondtor,CD.RazonSocial AS NomConductor
,C.CodConce,CN.Concepto,Beneficiario,C.Integrado AS EsIntegracion,C.EsEgreso AS ComEsEgreso,C.Observacion AS Observ,C.IdEstado AS CdEstado
,TipoNiif,CtbTipo,CtbNumero,FisTipo,FisNumero,R.Item,R.TipoRev,R.Titulo,R.Comentario,R.CdCuenta,NomCuenta,R.FechaCrea,R.IdUsuario AS CdUsuario,Usuario
 FROM Trn_NiifRevelac AS R INNER JOIN Trn_NiifComp AS C ON R.TipCom=C.TipCom AND R.Comprobante=C.Comprobante AND R.IdCia=C.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia  INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN TiposCom AS TC ON R.TipCom=TC.IdCom INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto LEFT JOIN Terceros AS CD ON C.CedCondtor=CD.IdTercero 
 LEFT JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN PucNiif AS P ON R.CdCuenta=P.IdCuenta
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryNiifRevelacLtc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNiifRevelacLtc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipCom VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT R.TipCom,TipoCom,R.Comprobante AS NumComp,R.IdCia AS CdCia,Compania,C.Fecha,C.IdTercero AS NitTercero,T.RazonSocial,C.VrTotal,C.IdCta AS CdCta,NumeroCta
,CTA.IdBanco AS CdBanco,Banco,EnEfectivo,C.NumCheque AS ComNumCheque,FecCheque,Anulado,NumDev,FecDev,pVehiculo,C.VehPropio,CedCondtor,CD.RazonSocial AS NomConductor
,C.CodConce,CN.Concepto,Beneficiario,C.Integrado AS EsIntegracion,C.EsEgreso AS ComEsEgreso,C.Observacion AS Observ,C.IdEstado AS CdEstado,NiifTipo,NiifNumero,FisTipo,FisNumero
,R.Item,R.TipoRev,R.Titulo,R.Comentario,R.CdCuenta,NomCuenta,R.FechaCrea,R.IdUsuario AS CdUsuario,Usuario
 FROM Trn_NiifRevelac AS R INNER JOIN Trn_Comprobantes AS C ON R.TipCom=C.TipCom AND R.Comprobante=C.Comprobante AND R.IdCia=C.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia  INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN TiposCom AS TC ON R.TipCom=TC.IdCom INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto LEFT JOIN Terceros AS CD ON C.CedCondtor=CD.IdTercero 
 LEFT JOIN CtasCorrientes AS CTA ON C.IdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON CTA.IdBanco=BCT.IdBanco
 LEFT JOIN Puc AS P ON R.CdCuenta=P.IdCuenta
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.TipCom LIKE ISNULL(@pmTipCom,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAbonos] @pmNPrestamo INT,@pmItem INT
 AS 
 SELECT NPrestamo,Item,IdEmpleado,FechaAbo,VrAbono,nCuotas,Dscto,IdPeriodo,Detalle,NLiquida
 FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAbonosId] @pmNPrestamo INT
 AS 
 SELECT MAX(Item) AS MXITEM
 FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAbonosLiq] @pmDscto VARCHAR(3),@pmNLiquida INT,@pmIdEmpleado VARCHAR(16)=Null
AS 
 SELECT NPrestamo,SUM(VrAbono) AS SABONO,SUM(nCuotas) AS SCUOTAS
 FROM Trn_NomAbonos
 WHERE Dscto=@pmDscto AND NLiquida=@pmNLiquida  AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')
 GROUP BY NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosPer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAbonosPer] @pmIdPeriodo VARCHAR(8),@pmDscto VARCHAR(3),@pmIdEmpleado VARCHAR(16)=Null
AS 
 SELECT NPrestamo,SUM(VrAbono) AS SABONO,SUM(nCuotas) AS SCUOTAS
 FROM Trn_NomAbonos
 WHERE IdPeriodo=@pmIdPeriodo AND Dscto LIKE ISNULL(@pmDscto,'%')  AND IdEmpleado LIKE  ISNULL(@pmIdEmpleado,'%')
 GROUP BY NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAbonosPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAbonosPre] @pmNPrestamo INT,@pmIdPeriodo VARCHAR(8)=Null,@pmDscto VARCHAR(3)=Null
,@pmNLiquida INT=Null
AS 
 SELECT SUM(VrAbono) AS SABONO,SUM(nCuotas) AS SCUOTAS
 FROM Trn_NomAbonos
 WHERE NPrestamo=@pmNPrestamo AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND Dscto LIKE ISNULL(@pmDscto,'%') 
 AND  (NLiquida>=ISNULL(@pmNLiquida,0)  AND NLiquida<=ISNULL(@pmNLiquida,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomActividades]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomActividades] @pmIdActEco VARCHAR(10)
 AS 
 SELECT IdActEco,IdSector,CodAdicional,DescActividad,Inactivo
 FROM NomActividades WHERE IdActEco=@pmIdActEco
GO
/****** Object:  StoredProcedure [dbo].[paQryNomActividadesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomActividadesLta] 
 AS 
 SELECT A.IdActEco,A.IdSector,SectorEco,A.CodAdicional,A.DescActividad,A.Inactivo
 FROM NomActividades AS A INNER JOIN SectoresEco AS S ON A.IdSector=S.IdSector
 WHERE A.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAjustes] @pmTipNota VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipNota,NumNota,IdCia,IdEmpleado,NContrato,IdPeriodo,FechaInicial,FechaFinal,IdRegNom,NumLiquida,NumSemLiq,IdNom,TipoLiq,Observacion,NA_Estado,NA_Prefijo,NA_Numero,NA_FecEnvio,NA_CUNE,NA_QR
,NE_Prefijo,NE_Numero,NE_CUNE,NE_QR,NE_TipoAju,FechaCrea,IdCiaCrea,IdUsuario
 FROM Trn_NomAjustes
 WHERE TipNota=@pmTipNota AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAjustesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAjustesLta] @pmTipNota VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT A.TipNota,TD.TipoDoc,A.NumNota,A.IdCia,Compania,A.IdPeriodo,A.FechaInicial,A.FechaFinal,A.IdEmpleado,E.Apellidos,E.Nombres,A.NContrato
,D.Item,D.IdConcepto,C.Concepto,C.ClaseCon,D.Detalle,D.CantDevg,D.CantDed,D.VrUnitario,D.VrTotDevg,D.VrTotDed,D.VrBaseLiq,D.VrBasExceso,D.Unidad,D.ClaseLiq,D.VrOrigen,D.Tarifa
,D.DiasCalc,D.DiasNov,D.FecInicial AS DetFecFinal,D.FecFinal AS DetFecInicial,D.CodFondo,FN.Fondo,D.NPrestamo,D.NCuota,D.OrigCargue,D.NitTercero,T.RazonSocial AS NomTercero,D.TipoIncLab
,A.IdRegNom,A.NumLiquida,A.NumSemLiq,A.IdNom,TipoNomina,A.TipoLiq,A.Observacion,A.NA_Estado,A.NA_Prefijo,A.NA_Numero,A.NA_FecEnvio,A.NA_CUNE,A.NA_QR
,A.NE_Prefijo,A.NE_Numero,A.NE_CUNE,A.NE_QR,A.NE_TipoAju,A.FechaCrea,A.IdCiaCrea,A.IdUsuario,Usuario
--contrato/empleado
,CN.IdArea,Area,CN.IdDep AS CodDep,DP.Dependencia,CN.IdCargo,Cargo,CN.IdTipCon,TipoContrato,CN.FecIngreso,CN.FecVigencia,CN.FecRetiro,CN.VrSalario,CN.VrAuxTrans,CN.Inactivo
,E.Codigo,E.IdLugarCed,LC.Localidad,E.Direccion,E.Telefono,E.TelMovil,E.e_mail,E.IdProf AS CodProf,Profesion
FROM Trn_NomAjustes AS A INNER JOIN Trn_NomAjustesDet AS D ON A.TipNota=D.TipNota AND A.NumNota=D.NumNota AND A.IdCia=D.IdCia
INNER JOIN Empleados AS E ON A.IdEmpleado=E.IdEmpleado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
INNER JOIN TiposNom AS TN ON A.IdNom=TN.IdNom INNER JOIN NomConceptos AS C ON D.IdConcepto=C.IdConcepto
INNER JOIN Emp_Contrato AS CN ON A.NContrato=CN.NContrato INNER JOIN Dependencias AS DP ON CN.IdDep=DP.IdDep
INNER JOIN Areas AS AR ON CN.IdArea=AR.IdArea INNER JOIN Cargos AS CG ON CN.IdCargo=CG.IdCargo 
INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
INNER JOIN TiposCon AS TC ON CN.IdTipCon=TC.IdTipCon
LEFT JOIN Sys_TiposDoc AS TD ON A.TipNota=TD.IdDoc LEFT JOIN Fondos AS FN ON D.CodFondo=FN.IdFondo
LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
WHERE A.FechaInicial BETWEEN @pmFechaIni AND @pmFechaFin AND (A.TipNota=@pmTipNota OR @pmTipNota IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAlqDet] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,IdEmpleado,NContrato,Apellido1,Apellido2,Nombre1,Nombre2,IdFonPen,IdFonSal,IdFonRie,IdCajCom,SalBasico,VrIBCPen,DiasPen,TarifPen,VrPension,VrApoFsp,VrApoFsu,VrApoVolAfi,VrApoVolApt
,VrNoReten,VrIBCSal,DiasSal,TarifSal,VrSalud,VrUpc,VrIncap,VrLicencia,NumAutInc,NumAutLic,VrIBCRie,DiasRie,TarifRie,VrRiesgos,VrIncIrp,NumAutIrp,IdInstala,VrIBCRef,VrIBCCajas,DiasCom,TarifCom,VrCajas,TarifSen,VrSena,TarifIcb
,VrICBF,TarifEsap,VrESAP,TarifEdu,VrMinEdu,TarifFsp,TarifFsu,CdFonAvp,VrIBCparaf,CantHoras,TipoSalario,IdActEco
 FROM Trn_NomAlqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAlqNov] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,IdEmpleado,NovIng,NovRet,NovTde,NovTae,NovTdp,NovTap,NovVsp,NovVte,NovVst,NovSln,NovIge,NovLma,NovVac,NovAvp
,NovVct,NovIrp,CodNewPen,CodNewSal,CodNewIns,CodNewRie,CodNewGru,DiasNov,DiasSan,DiasDnrPen,DiasDnrSal,NovDsr,FecNovIng,FecNovRet,FecNovVsp
,FecIniSln,FecFinSln,FecIniIge,FecFinIge,FecIniLma,FecFinLma,FecIniVac,FecFinVac,FecIniVct,FecFinVct,FecIniIrl,FecFinIrl
 FROM Trn_NomAlqNov
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAlqTot] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,TipAdm,IdFondo,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora
,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF,TipoReg
 FROM Trn_NomAlqTot
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAlqTot_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAlqTot_Cr] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmTipAdm VARCHAR(3)=Null
,@pmIdFondo VARCHAR(8)=Null
 AS 
 SELECT TipoLiq,Numero,Item,TipAdm,T.IdFondo AS CodFondo,Fondo,F.IdTercero AS NitFondo,RazonSocial,TipoId,Dv,CodTipoApo,VrTotalCot,VrTotalFsp,VrTotalFsu,VrTotalAva,VrTotalAve,VrTotalUpc
,VrTotalLic,VrTotalInc,VrTotalOtr,DiasMora,TarifMora,VrIntMora,VrIMoraOtr,VrTotalSAF,VrSAFUpc,VrTotalPagar,VrTotalFon,TotalAfi,NumAutLic,NumAutInc,NumPlaSAF,TipoReg
 FROM Trn_NomAlqTot AS T LEFT JOIN Fondos AS F ON T.IdFondo=F.IdFondo
 LEFT JOIN Terceros AS TF ON F.IdTercero=TF.IdTercero
 WHERE TipoLiq=@pmTipoLiq AND Numero LIKE ISNULL(@pmNumero,'%') AND TipAdm LIKE ISNULL(@pmTipAdm,'%')
 AND T.IdFondo LIKE ISNULL(@pmIdFondo,'%')
 ORDER BY Numero,TipoReg,TipAdm,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAportante]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAportante] @pmIdAportnte VARCHAR(16)
 AS 
 SELECT IdAportnte,RazonSocial,TipoId,DvNit,IdRepLegal,Direccion,IdLocal,Telefono,Fax,e_mail,ClaseApo,TipoEco,TipoPersna,CIIUDane,FecIniCndato
,TipAccCndato,FecFinCndato,CodOperInfo,TipoApo,FecMatMerc,ExonParaf,ExonCajas,CondEspecial,FecAdd,FecUpdate,IdUsuario
 FROM NomAportante
 WHERE IdAportnte LIKE ISNULL(@pmIdAportnte,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAportanteReg]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAportanteReg]
 AS 
 SELECT COUNT(IdAportnte) AS SCanApo
 FROM NomAportante
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstncia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAstncia] @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME
 AS 
 SELECT IdEmpleado,FechaDia,HHDiurno,HHNocturno,HEDiurno,HENocturno,TipoJrnada,EsDmncal,Horario,CodTurno,Horas_Dia,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomAstncia
 WHERE IdEmpleado=@pmIdEmpleado AND FechaDia=@pmFechaDia
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstnciaLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAstnciaLta] @pmIdEmpleado VARCHAR(16)=Null,@pmFecInicio SMALLDATETIME=Null,@pmFecFinal SMALLDATETIME=Null
,@pmEsDmncal BIT=Null,@pmTipoJrnada VARCHAR(10)=Null
 AS 
 SELECT A.IdEmpleado AS IdEmplado,Apellidos,Nombres,FechaDia,HHDiurno,HHNocturno,HEDiurno,HENocturno,TipoJrnada,EsDmncal,Horario,TimeSys,A.FecUpdate AS FecUpd
,A.IdUsuario AS IdUsuari,Usuario,E.NContrato AS NumContrato,FecIngreso,FecRetiro,VrSalario,VrAuxTrans,C.IdNom AS CodNom,TipoNomina,pVehiculo,CodTurno,Horas_Dia
 FROM Trn_NomAstncia AS A INNER JOIN Empleados AS E ON A.IdEmpleado=E.IdEmpleado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 WHERE  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal AND A.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
  AND TipoJrnada LIKE ISNULL(@pmTipoJrnada,'%')
 AND (EsDmncal=ISNULL(@pmEsDmncal,0) or EsDmncal=ISNULL(@pmEsDmncal,1))
 ORDER BY Apellidos,Nombres,FechaDia
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstnciaTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAstnciaTip] @pmTipo CHAR(1),@pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
 AS 
 IF @pmTipo='D' --descansos
  SELECT Count(FechaDia) AS Cant,SUM(HHDiurno) AS STotHHD,SUM(HHNocturno) AS STotHHN,SUM(HEDiurno) AS STotHED ,SUM(HENocturno) AS STotHEN
  ,SUM(Horas_Dia) AS CantHorasDia
  FROM Trn_NomAstncia
  WHERE IdEmpleado=@pmIdEmpleado AND  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal 
   AND TipoJrnada IN ('DESCANSO','DSCSINCOMP')
 ELSE --SIN COMPENSATORIOS
  SELECT Count(FechaDia) AS Cant,SUM(HHDiurno) AS STotHHD,SUM(HHNocturno) AS STotHHN,SUM(HEDiurno) AS STotHED ,SUM(HENocturno) AS STotHEN
  ,SUM(Horas_Dia) AS CantHorasDia
  FROM Trn_NomAstncia
  WHERE IdEmpleado=@pmIdEmpleado AND  FechaDia BETWEEN @pmFecInicio AND @pmFecFinal 
   AND TipoJrnada IN ('SINCOMP','DSCSINCOMP')
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAstnciaTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAstnciaTot] @pmIdEmpleado VARCHAR(16)=Null,@pmFecInicio SMALLDATETIME=Null,@pmFecFinal SMALLDATETIME=Null
,@pmEsDmncal BIT=Null,@pmTipoJrnada VARCHAR(10)=Null
 AS 
 SELECT Count(FechaDia) AS Cant,SUM(HHDiurno) AS STotHHD,SUM(HHNocturno) AS STotHHN,SUM(HEDiurno) AS STotHED ,SUM(HENocturno) AS STotHEN
 ,SUM(CASE WHEN (TipoJrnada='DESCANSO' OR TipoJrnada='DSCSINCOMP') THEN Horas_Dia ELSE 0 END) AS STotDesc
 FROM Trn_NomAstncia
 WHERE FechaDia BETWEEN @pmFecInicio AND @pmFecFinal 
 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (TipoJrnada=@pmTipoJrnada OR @pmTipoJrnada IS NULL)
 AND (EsDmncal=ISNULL(@pmEsDmncal,0) or EsDmncal=ISNULL(@pmEsDmncal,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAutoliq] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20)
 AS 
 SELECT TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,IdAportnte,Presentacion,CodCia,CodFondo,CodArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,VrPension,VrSalud,VrRiesgos,VrCajas,VrSena,VrIcbf,VrEsap,VrMinEduc,TotalAfipen,TotalAfiSal
,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,Observacion,LogAdmon,RedoMiles,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario,TipoPlanilla
 FROM Trn_NomAutoliq
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliq_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomAutoliq_Cr] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmPerAutoliq VARCHAR(6)=Null
AS
 SELECT  A.TipoLiq AS TipoPla,A.Numero AS NumPla,Fecha,PerAutoliq,PerAutoSal,FechaPago,A.IdAportnte AS NitAportnte,NA.RazonSocial AS NomAportante,Presentacion,A.CodCia AS CodSucur,Compania,CodSucsal,DireccSuc,TelefSuc,CI.IdLocal AS CodCiuSuc
,LC.Localidad AS CiudadSuc,LC.IdDep AS CodDepSuc,CodFondo,F.Fondo AS NomFondo,CodArp,FRP.Fondo AS FondoArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,A.VrPension AS Total_Pen,A.VrSalud AS Total_Sal,A.VrRiesgos AS Total_Rie,A.VrCajas AS Total_Caj
,A.VrSena AS Total_Sen,A.VrIcbf AS Total_ICB,A.VrEsap AS Total_ESA,VrMinEduc,TotalAfipen,TotalAfiSal,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,A.Observacion AS Observ,LogAdmon,RedoMiles
,Anulado,A.IdEstado AS IdEstdo,Estado,TimeSys,A.FecUpdate AS Fec_Update,A.IdUsuario AS IdUsuari,Usuario
--datos del aportante
,NA.TipoId AS Apo_TipID,DvNit,IdRepLegal,RLG.RazonSocial AS NomRepLegal,RLG.TipoId AS RLegTID,RLG.Dv AS RLegDV,NA.Direccion AS Apo_dirccion,NA.IdLocal AS Apo_CodCiu,LA.Localidad AS Apo_NomCiu,LA.IdDep AS Apo_CodDep,Departamento,NA.Telefono AS Apo_tel,NA.Fax AS Apo_Fax,NA.e_mail AS Apo_email
,ClaseApo,TipoEco,TipoPersna,CIIUDane,FecIniCndato,TipAccCndato,FecFinCndato,CodOperInfo,TipoApo,FecMatMerc,ExonParaf,ExonCajas
--datos del detalle
,D.Item AS DetItem,D.IdEmpleado AS IdEmpldo,D.NContrato AS NumContrato,Apellido1,Apellido2,Nombre1,Nombre2,D.IdFonPen AS IdFdoPen,FP.Fondo AS FondoPen,TFP.TipoId AS Pen_TipID,FP.IdTercero AS Pen_Nit,TFP.Dv AS Pen_DV,TFP.RazonSocial AS Pen_Nombre
,IdFonSal,FS.Fondo AS FondoSal,TFS.TipoId AS Sal_TipID,FS.IdTercero AS Sal_Nit,TFS.Dv AS Sal_Dv,TFS.RazonSocial AS Sal_Nombre,IdFonRie,FR.Fondo AS FondoRie,TFR.TipoId AS Rie_TipID,FR.IdTercero AS Rie_nit,TFR.Dv AS Rie_Dv,TFR.RazonSocial AS Rie_nombre
,IdCajCom,FC.Fondo AS FondoCc,TFC.TipoId AS CC_TipId,FC.IdTercero AS CC_Nit,TFC.Dv AS CC_DV,TFC.RazonSocial AS cc_Nombre,SalBasico,VrIBCPen,DiasPen,TarifPen,D.VrPension AS VlrPension,VrApoFsp,VrApoFsu,VrApoVolAfi,VrApoVolApt,VrNoReten,VrIBCSal,DiasSal,TarifSal,D.VrSalud AS VlrSalud,D.VrUpc AS VlrUpc
,VrIncap,VrLicencia,NumAutInc,NumAutLic,VrIBCRie,DiasRie,TarifRie,D.VrRiesgos AS VlrRiesgos,VrIncIrp,NumAutIrp,D.IdInstala AS CodInstla,I.Instlacion AS CentroTrabaj,I.CodCiu AS CiuInstala
,VrIBCRef,VrIBCCajas,DiasCom,TarifCom,D.VrCajas AS VlrCajas,TarifSen,D.VrSena AS VlrSena,TarifIcb,D.VrICBF AS Vlricbf,TarifEsap,D.VrESAP AS VlrESAP,TarifEdu,VrMinEdu,TarifFsp,TarifFsu,VrIBCparaf,CantHoras,TipoSalario,D.IdActEco,AC.IdSector,AC.CodAdicional
--datos de novedades
,NovIng,NovRet,NovTde,NovTae,NovTdp,NovTap,NovVsp,NovVte,NovVst,NovSln,NovIge,NovLma,NovVac,NovAvp,NovVct,NovIrp,CodNewPen,FNP.Fondo AS NewFonPen,CodNewSal,FNS.Fondo AS NewFonEPS,CodNewIns,NI.Instlacion AS NewCentroTrabj,CodNewRie,CRN.Tarifa AS New_TarRie,CodNewGru
,NGR.TarfaTrab AS NewTarfTrab,NGR.TarfaEmp AS NewTarfEmp,DiasNov,DiasSan,DiasDnrPen,DiasDnrSal,DN.NovDsr,DN.FecNovIng,DN.FecNovRet,DN.FecNovVsp,DN.FecIniSln,DN.FecFinSln,DN.FecIniIge,DN.FecFinIge,DN.FecIniLma,DN.FecFinLma
,DN.FecIniVac,DN.FecFinVac,DN.FecIniVct,DN.FecFinVct,DN.FecIniIrl,DN.FecFinIrl
--datos del empleado
,Apellidos,Nombres,E.Codigo AS EmpCodigo,E.TipoId AS Emp_TipID,E.Dv AS Emp_Dv,E.IdLugarCed AS Emp_IdLugrCed,L.Localidad AS Lugar_Ced,L.IdDep AS Emp_CodDep,E.Direccion AS Dirccion,E.Telefono AS Emp_Telfono,E.TelMovil AS Emp_TelMovil,E.e_mail AS Emp_Email,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,NumCuenta
,E.IdBanco AS CodBanco,EsCondtor,pVehiculo,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,Licencia,CatLicencia,VigLicencia,TallaCam,TallaPan,TallaZap,IdEstCivil,EstCivil,NHijos,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDepe,Dependencia,C.IdCCosto AS CodCcto,CCosto,C.IdSubCos AS CodScost,SubCosto,C.IdNom AS CodTipNom,TipoNomina,C.IdClase AS CodClaRie,CR.ClaseRiesgo AS ClasRiesgo
,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,C.VrUpc AS Con_VrUpc,SalMinimo,SalIntegral,FPnomina,C.TipoLiquida AS TipLiq,FecAfiSeg,C.IdCot AS CodCotz,Cotizante,C.IdGrupo AS CodGrup,GAR.TarfaTrab AS Con_TrfaTrab,GAR.TarfaEmp AS TrfaEmp,TipoTrabj
,ATFinMes,SegFinMes,C.IdEstado AS Con_IdEstdo,C.Inactivo AS Con_inactivo,IdJornada,DenyPEN,DenyEPS,DenyARP,DenyCaj,D.CdFonAvp AS CodFondoAvp,E.CdFonAvp AS Emp_FondoAVP,TipoPlanilla,SubTipoCot,CR.CodClase AS CodClaseRie,TN.NomDiario,C.IdActEco AS Con_CodActRl,AL.IdSector AS Con_CodSector,AL.CodAdicional AS Con_CodAdic
 FROM Trn_NomAutoliq AS A INNER JOIN Trn_NomAlqDet AS D ON A.TipoLiq=D.TipoLiq AND A.Numero=D.Numero 
 INNER JOIN NomAportante AS NA ON A.IdAportnte=NA.IdAportnte  INNER JOIN Terceros AS RLG ON NA.IdRepLegal=RLG.IdTercero
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario INNER JOIN Localidades AS LA ON NA.IdLocal=LA.IdLocal
 INNER JOIN Departamentos AS DE ON LA.IdDep=DE.IdDep
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado INNER JOIN Fondos AS FP ON D.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON D.IdFonSal=FS.IdFondo INNER JOIN Fondos AS FR ON D.IdFonRie=FR.IdFondo
 INNER JOIN Fondos AS FC ON D.IdCajCom=FC.IdFondo INNER JOIN Terceros AS TFP ON FP.IdTercero=TFP.IdTercero
 INNER JOIN Terceros AS TFS ON FS.IdTercero=TFS.IdTercero  INNER JOIN Terceros AS TFR ON FR.IdTercero=TFR.IdTercero
 INNER JOIN Terceros AS TFC ON FC.IdTercero=TFC.IdTercero  INNER JOIN Instalaciones AS I ON D.IdInstala=I.IdInstala
 INNER JOIN Emp_Contrato AS C ON D.NContrato=C.NContrato  INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep 
 INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom  INNER JOIN TiposCot AS TCZ ON C.IdCot=TCZ.IdCot
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 LEFT JOIN GruposAR AS GAR ON C.IdGrupo=GAR.IdGrupo
 LEFT JOIN Trn_NomAlqNov AS DN ON D.TipoLiq=DN.TipoLiq AND D.Numero=DN.Numero AND D.Item=DN.Item
 LEFT JOIN Fondos AS F ON A.CodFondo=F.IdFondo LEFT JOIN Fondos AS FRP ON A.CodArp=FRP.IdFondo
 LEFT JOIN Companias AS CI ON A.CodCia=CI.IdCia LEFT JOIN Localidades AS LC ON CI.IdLocal=LC.IdLocal
 LEFT JOIN Fondos AS FNP ON DN.CodNewPen=FNP.IdFondo  LEFT JOIN Fondos AS FNS ON DN.CodNewSal=FNS.IdFondo
 LEFT JOIN Instalaciones AS NI ON DN.CodNewIns=NI.IdInstala LEFT JOIN ClaseRie AS CRN ON DN.CodNewRie=CRN.IdClase
 LEFT JOIN GruposAR AS NGR ON DN.CodNewGru=NGR.IdGrupo
 LEFT JOIN NomActividades AS AC ON D.IdActEco=AC.IdActEco LEFT JOIN NomActividades AS AL ON C.IdActEco=AL.IdActEco
 WHERE A.TipoLiq=@pmTipoLiq AND A.Numero LIKE ISNULL(@pmNumero,'%') AND PerAutoliq LIKE ISNULL(@pmPerAutoliq,'%')
 ORDER BY A.Numero,Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliqDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAutoliqDso] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipoLiq VARCHAR(3)=Null,@pmNumero VARCHAR(20)=Null
,@pmPerAutoliq VARCHAR(6)=Null,@pmCodFondo VARCHAR(8)=Null,@pmEsCorr BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmPresentacion CHAR(1)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,A.IdAportnte AS NitAportnte,RazonSocial,Presentacion,CodCia,CodFondo,F.Fondo AS NomFondo,CodArp,FR.Fondo AS FondoArp,CodOper,EsCorr,PerCorr,NumCorr,TotalEmp,VrNomina,VrPension,VrSalud,VrRiesgos
,VrCajas,VrSena,VrIcbf,VrEsap,VrMinEduc,TotalAfipen,TotalAfiSal,TotalAfiRie,TotalAfiCaj,TotalAfiSen,TotalAfiIcb,TotalAfiEsa,TotalAfiEduc,TotAdmPen,TotAdmSal,TotAdmRie,TotAdmCom,Observacion
,LogAdmon,RedoMiles,Anulado,A.IdEstado AS IdEstdo,Estado,TipoPlanilla,TimeSys,A.FecUpdate AS Fec_Updte,A.IdUsuario AS IdUsuari,Usuario
 FROM Trn_NomAutoliq AS A INNER JOIN NomAportante AS NA ON A.IdAportnte=NA.IdAportnte
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Fondos AS F ON A.CodFondo=F.IdFondo LEFT JOIN Fondos AS FR ON A.CodArp=FR.IdFondo
 WHERE TipoLiq LIKE ISNULL(@pmTipoLiq,'%') AND Numero LIKE ISNULL(@pmNumero,'%') AND PerAutoliq LIKE ISNULL(@pmPerAutoliq,'%')
 AND CodFondo LIKE ISNULL(@pmCodFondo,'%') AND A.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND Presentacion LIKE ISNULL(@pmPresentacion,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EsCorr=ISNULL(@pmEsCorr,0) or EsCorr=ISNULL(@pmEsCorr,1))
 ORDER BY TipoLiq,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomAutoliqPer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomAutoliqPer] @pmTipoLiq VARCHAR(3),@pmPerAutoliq VARCHAR(6),@pmNumero VARCHAR(20),@pmPresentacion CHAR(1)=Null
,@pmCodCia CHAR(2)=Null,@pmCodFondo VARCHAR(8)=Null,@pmEsCorr BIT=Null
 AS 
 SELECT TipoLiq,Numero,Fecha,PerAutoliq,PerAutoSal,FechaPago,Presentacion,CodCia,CodFondo,EsCorr
 FROM Trn_NomAutoliq
 WHERE TipoLiq=@pmTipoLiq AND PerAutoliq=@pmPerAutoliq AND Anulado=0 AND Numero<>@pmNumero AND Presentacion LIKE ISNULL(@pmPresentacion,'%')
 AND CodCia LIKE ISNULL(@pmCodCia,'%%') AND CodFondo LIKE ISNULL(@pmCodFondo,'%')
 AND  (EsCorr=ISNULL(@pmEsCorr,0) or EsCorr=ISNULL(@pmEsCorr,1))
 ORDER BY  Fecha,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomBasesConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomBasesConv] @pmIdBase VARCHAR(4)
 AS 
 IF @pmIdBase IS NULL 
  BEGIN
   SELECT IdBase,NombreBase,Inactivo
   FROM NomBasesConv
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdBase,NombreBase,Inactivo
   FROM NomBasesConv
   WHERE IdBase=@pmIdBase 
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomCAdmon] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,ClaseAdmon,FecIniNov,NNovedad,IdFondo,IdFonNew,Observacion,Anulado,TimeSys,IdUsuario
 FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmon_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomCAdmon_Cr]   @pmIdEmpleado VARCHAR(16)=Null,@pmNumero INT=Null,@pmClaseAdmon VARCHAR(10)=Null,@pmIdFondo VARCHAR(8)=Null
,@pmIdFonNew VARCHAR(8)=Null,@pmAnulado BIT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT CA.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Numero,Fecha,CA.NContrato AS NumCtrato,ClaseAdmon,FecIniNov,NNovedad,CA.IdFondo AS IdFonAnt,FAN.Fondo AS FondoAnt
,IdFonNew,FNE.Fondo AS FondoNuevo,CA.Observacion AS Observ,Anulado,TimeSys,CA.IdUsuario AS IdUsuari,Usuario
 --datos del empleado
,Codigo,E.IdProf AS CodProf,Profesion,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdFonCes,FC.Fondo AS FondoCes,IdCajaCom,CC.Fondo AS CajaComp
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion
,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo 
 FROM Trn_NomCAdmon AS CA INNER JOIN Empleados AS E ON CA.IdEmpleado=E.IdEmpleado INNER JOIN Fondos AS FAN ON CA.IdFondo=FAN.IdFondo
 INNER JOIN Fondos AS FNE ON CA.IdFonNew=FNE.IdFondo  INNER JOIN adm_Usuarios AS U ON CA.IdUsuario=U.IdUsuario
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo  INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo
 LEFT JOIN  Emp_Contrato AS C ON CA.NContrato=C.NContrato  LEFT JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 LEFT JOIN Dependencias AS DP ON C.IdDep=DP.IdDep  LEFT JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom LEFT JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado 
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo LEFT JOIN Areas AS AR ON C.IdArea=AR.IdArea
 LEFT JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 WHERE CA.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND ClaseAdmon LIKE ISNULL(@pmClaseAdmon,'%')
 AND CA.IdFondo LIKE ISNULL(@pmIdFondo,'%') AND IdFonNew LIKE ISNULL(@pmIdFonNew,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmonCla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomCAdmonCla] @pmIdEmpleado VARCHAR(16),@pmClaseAdmon VARCHAR(10)
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,ClaseAdmon,FecIniNov,NNovedad,IdFondo,IdFonNew,Anulado
 FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado  AND Anulado=0 AND ClaseAdmon=@pmClaseAdmon
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCAdmonId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomCAdmonId] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomCAdmon
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCapacitacionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomCapacitacionesLta] @pmIdClase VARCHAR(4)=Null
 AS 
 SELECT C.IdClase AS CdClase,NomClase,Item,Vigencia,C.CdEmpleado,E.Apellidos,E.Nombres
,CdProf,Profesion,CdCargo,Cargo,CdArea,Area,CdDep,Dependencia,Cumplimto,C.Inactivo AS Inactvo
 FROM NomCapacitaciones AS C INNER JOIN ClaseCapac AS CP ON C.IdClase=CP.IdClase
 LEFT JOIN Empleados AS E ON C.CdEmpleado=E.IdEmpleado
 LEFT JOIN Cargos AS CG ON C.CdCargo=CG.IdCargo LEFT JOIN Profesiones AS P ON C.CdProf=P.IdProf
 LEFT JOIN Dependencias AS D ON C.CdDep=D.IdDep LEFT JOIN Areas AS A ON C.CdArea=A.IdArea
 WHERE C.IdClase LIKE ISNULL(@pmIdClase,'%') AND CP.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCausalesRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomCausalesRet] @pmIdCausa VARCHAR(4)
 AS 
 IF @pmIdCausa IS NULL
  SELECT IdCausa,CausalRet,Indmnizar
  FROM NomCausalesRet
  WHERE Inactivo=0
  ORDER BY  IdCausa
 ELSE
  SELECT IdCausa,CausalRet,Indmnizar,Inactivo
  FROM NomCausalesRet
  WHERE IdCausa=@pmIdCausa
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCertf]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomCertf] @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20)
 AS 
 SELECT IdEmpleado,NumCertf,nAnno,nMes,ClaseCert,VrCertf,Observacion,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomCertf
 WHERE IdEmpleado=@pmIdEmpleado AND NumCertf=@pmNumCertf
 ORDER BY NumCertf
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCertfLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomCertfLta] @pmnAnno INT,@pmnMes INT=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNumCertf VARCHAR(20)=Null,@pmObservacion VARCHAR(100)=Null,@pmClaseCert VARCHAR(10)=Null
 AS 
 SELECT C.IdEmpleado AS IdEmpledo,Apellidos,Nombres,NumCertf,nAnno,nMes,ClaseCert,VrCertf,C.Observacion AS Observ
,C.IdUsuario AS IdUsuari,Usuario,FecAdd,FecUpdate,NContrato
 FROM Trn_NomCertf AS C INNER JOIN Empleados AS E ON C.IdEmpleado=E.IdEmpleado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE nAnno=@pmnAnno AND  C.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND NumCertf  LIKE ISNULL(@pmNumCertf ,'%') AND C.Observacion LIKE ISNULL(@pmObservacion,'%')
 AND ClaseCert LIKE ISNULL(@pmClaseCert,'%')
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 ORDER BY C.IdEmpleado,nMes,NumCertf
GO
/****** Object:  StoredProcedure [dbo].[paQryNomCertfMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomCertfMes] @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT
,@pmClaseCert VARCHAR(10)=Null
 AS 
 SELECT ClaseCert,SUM(VrCertf) AS STOTCER
 FROM Trn_NomCertf
 WHERE IdEmpleado=@pmIdEmpleado AND nAnno=@pmnAnno AND nMes=@pmnMes
 AND ClaseCert LIKE ISNULL(@pmClaseCert,'%')
 GROUP BY ClaseCert
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAuto]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConAuto] @pmIdReg INT
 AS 
 SELECT IdReg,IdConcepto,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,CodNom,CodDep,CodCcto
,CodSubCos,CritSelect,FecFinal,Exceptuar,Observacion,Inactivo,NumPerMes,NitTercero,AplicaPrima,AplicaVac,PdoAplicaEsp,VrAplicaEsp,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomConAuto
 WHERE IdReg=@pmIdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAutoId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConAutoId] 
 AS 
 SELECT MAX(IdReg) AS MXIDREG
 FROM Trn_NomConAuto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAutoLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConAutoLta] @pmIdConcepto VARCHAR(4)=Null,@pmCedEmpleado VARCHAR(16)=Null,@pmCodNom VARCHAR(4)=Null,@pmCodDep VARCHAR(4)=Null
 ,@pmCodCcto VARCHAR(16)=Null,@pmCodSubCos VARCHAR(16)=Null,@pmInactivo BIT=Null,@pmFecInicioIni SMALLDATETIME=Null,@pmFecInicioFin SMALLDATETIME=Null
,@pmFrecAplica VARCHAR(10)=Null,@pmFecFinalIni SMALLDATETIME=Null,@pmFecFinalFin SMALLDATETIME=Null
 AS 
 SELECT IdReg,A.IdConcepto AS CodConcept,Concepto,ClaseCon,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,Apellidos,Nombres,NContrato,CodNom
,TipoNomina,CodDep,Dependencia,CodCcto,CCosto,CodSubCos,SubCosto,CritSelect,FecFinal,Exceptuar,NumPerMes,A.Observacion AS Observ,A.Inactivo AS Inactvo
,A.NitTercero,RazonSocial,AplicaPrima,AplicaVac,PdoAplicaEsp,VrAplicaEsp,A.FecAdd AS Fecha_Add,A.FecUpdate AS FecUpd,A.IdUsuario AS IdUsuari,Usuario,E.Inactivo AS Emp_Inactivo
 FROM Trn_NomConAuto AS A INNER JOIN NomConceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Empleados AS E ON A.CedEmpleado=E.IdEmpleado  LEFT JOIN TiposNom AS TN ON A.CodNom=TN.IdNom
 LEFT JOIN Dependencias AS DP ON A.CodDep=DP.IdDep  LEFT JOIN CentroCosto AS CO ON A.CodCcto=CO.IdCCosto
 LEFT JOIN SubCentros AS SC ON A.CodSubCos=SC.IdSubCos LEFT JOIN Terceros AS T ON A.NitTercero=T.IdTercero
 WHERE A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND CedEmpleado LIKE ISNULL(@pmCedEmpleado,'%') AND CodNom LIKE ISNULL(@pmCodNom,'%')
 AND CodDep LIKE ISNULL(@pmCodDep,'%') AND CodCcto LIKE ISNULL(@pmCodCcto,'%') AND CodSubCos LIKE ISNULL(@pmCodSubCos,'%')
 AND FrecAplica LIKE ISNULL(@pmFrecAplica,'%')
 AND (A.Inactivo=ISNULL(@pmInactivo,0) or A.Inactivo=ISNULL(@pmInactivo,1))
 AND (FecInicio>=ISNULL(@pmFecInicioIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicio<=ISNULL(@pmFecInicioFin,CAST('20781230' AS SMALLDATETIME)))
-- AND (FecFinal>=ISNULL(@pmFecFinalIni,CAST('19100101' AS SMALLDATETIME)) AND FecFinal<=ISNULL(@pmFecFinalFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY IdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConAutoPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConAutoPen] @pmFecFin SMALLDATETIME,@pmCedEmpleado VARCHAR(16),@pmCodNom VARCHAR(4)
,@pmCodDep VARCHAR(4),@pmCodCcto VARCHAR(16),@pmCodSubCos VARCHAR(16)
 AS 
 SELECT IdReg,IdConcepto,FecInicio,VrAplicar,Modalidad,OrigenBase,FrecAplica,CedEmpleado,CodNom,CodDep,CodCcto
,CodSubCos,CritSelect,FecFinal,Exceptuar,Observacion,Inactivo,NumPerMes,NitTercero
,AplicaPrima,AplicaVac,PdoAplicaEsp,VrAplicaEsp,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomConAuto
 WHERE FecInicio<=@pmFecFin AND Inactivo=0 AND FrecAplica<>'PRIMA' AND FrecAplica<>'VACACIONES'
 AND ( CedEmpleado=@pmCedEmpleado OR CedEmpleado IS NULL OR LEN(CedEmpleado)=0)
 AND ( CodNom=@pmCodNom OR CodNom  IS NULL OR LEN(CodNom)=0)
 AND ( CodDep=@pmCodDep  OR CodDep  IS NULL OR LEN(CodDep)=0)
 AND ( CodCcto=@pmCodCcto  OR CodCcto  IS NULL OR LEN(CodCcto)=0)
 AND ( CodSubCos=@pmCodSubCos  OR CodSubCos  IS NULL OR LEN(CodSubCos)=0)
 ORDER BY IdConcepto,IdReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConcCondLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConcCondLta] @pmPeriodoIni INT,@pmPeriodoFin INT
 AS 
 SELECT CN.Id,CN.IdConc,CN.Item,CN.CodCond,EstadoConv AS DescCond,NColor
 FROM Trn_NomConcCond AS CN INNER JOIN Trn_NomConcConv AS CF ON CN.IdConc=CF.Id
 LEFT JOIN NomEstadosConv AS E ON CN.CodCond=E.IdEstado
 WHERE TipoEnte='ESTADOS' AND CF.IdPeriodo BETWEEN ISNULL(@pmPeriodoIni,0) AND ISNULL(@pmPeriodoFin,2147483647)
 UNION ALL
 SELECT CN.Id,CN.IdConc,CN.Item,CN.CodCond,NombreBase,0
 FROM Trn_NomConcCond AS CN INNER JOIN Trn_NomConcConv AS CF ON CN.IdConc=CF.Id
 LEFT JOIN NomBasesConv AS B ON CN.CodCond=B.IdBase
 WHERE TipoEnte='BASES' AND CF.IdPeriodo BETWEEN ISNULL(@pmPeriodoIni,0) AND ISNULL(@pmPeriodoFin,2147483647)
 UNION ALL 
 SELECT CN.Id,CN.IdConc,CN.Item,CN.CodCond,C.Concepto,0
 FROM Trn_NomConcCond AS CN INNER JOIN Trn_NomConcConv AS CF ON CN.IdConc=CF.Id
 LEFT JOIN NomConceptos AS C ON CN.CodCond=C.IdConcepto
 WHERE TipoEnte='NOVEDADES' AND CF.IdPeriodo BETWEEN ISNULL(@pmPeriodoIni,0) AND ISNULL(@pmPeriodoFin,2147483647)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConcConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConcConv] @pmId INT
 AS 
 SELECT [Id],IdPeriodo,FecInicio,FecFinal,IdConv,IdGrupo,CodEscfon,CodZona,TipoNom,IdConcepto,Descripcion,Unidad,Importe,Observaciones,IdUsuario,FechaCrea,Inactivo
 FROM Trn_NomConcConv
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConcConvLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConcConvLta] @pmPeriodoIni INT,@pmPeriodoFin INT,@pmIdConvIni INT,@pmIdConvFin INT
 AS 
 SELECT C.Id,C.IdPeriodo,C.FecInicio,C.FecFinal,C.IdConv,CV.Proyecto,C.IdGrupo,G.GrupoConv,C.CodEscfon,E.Escalafon,E.IdCargo,CG.Cargo
,C.CodZona,ZonaConv,C.TipoNom,C.IdConcepto,CN.Concepto,CN.ClaseCon,C.Descripcion,C.Unidad,C.Importe,C.Observaciones
,C.IdUsuario,Usuario,C.FechaCrea,C.Inactivo
 FROM Trn_NomConcConv AS C INNER JOIN NomConvenciones AS CV ON C.IdConv=CV.Id INNER JOIN NomGruposConv AS G ON C.IdGrupo=G.IdGrupo
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN NomConceptos AS CN ON C.IdConcepto=CN.IdConcepto
 LEFT JOIN NomEscalafones AS E ON C.CodEscfon=E.IdEscfon LEFT JOIN Cargos AS CG ON E.IdCargo=CG.IdCargo
 LEFT JOIN NomZonasConv AS Z ON C.CodZona=Z.IdZona
 WHERE C.IdPeriodo BETWEEN ISNULL(@pmPeriodoIni,0) AND ISNULL(@pmPeriodoFin,2147483647)
 AND C.IdConv BETWEEN ISNULL(@pmIdConvIni,0) AND ISNULL(@pmIdConvFin,2147483647)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConceptos] @pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,ClaseCon,Unidad,Tarifa,BaseTrfa,Pdtermnado,Inactivo,TarifaEmp,DiasEmp,IdConcNE,FechaAdd,FechaUpdate,IdUsuario
 FROM NomConceptos
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosDsc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConceptosDsc]
 AS 
 SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
 FROM NomConceptos
 WHERE  Inactivo=0 AND ClaseCon IN ('DEVENGADO','DEDUCIDO')  
 AND IdConcepto NOT IN ('AXT','DNR','DSR','DCP','DCS','FSP','FSU','IGE','IRP','LIC','RET','BAS','VAC')
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConceptosDso] @pmClaseCon VARCHAR(10)=Null,@pmPdtermnado BIT=Null,@pmInactivo BIT=Null
,@pmGrupo CHAR(1)=Null
 AS 
 IF @pmGrupo='N'--NOMINA
  SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
  FROM NomConceptos
  WHERE ClaseCon IN ('DEVENGADO','DEDUCIDO')  
  AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
  AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Concepto
 ELSE 
  BEGIN 
  IF @pmGrupo='V' --NOVEDADES
   SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
   FROM NomConceptos
   WHERE IdConcepto IN ('DNR','DSR','IGE','IRP','LIC','SAN','VAC','STC','AVP')  AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
   AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
   AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
   ORDER BY Concepto
  ELSE
   SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
   FROM NomConceptos
   WHERE ClaseCon LIKE ISNULL(@pmClaseCon,'%') 
   AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
   AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Concepto
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConceptosLiq] @pmPdtermnado BIT=Null,@pmInactivo BIT=Null
 AS 
  SELECT IdConcepto,Concepto,Concepto + ' ' + IdConcepto  AS DsCon
  FROM NomConceptos
  WHERE ( ClaseCon IN ('DEVENGADO','DEDUCIDO')  OR IdConcepto IN ('CES','PRI','VAC','INT') )
  AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
  AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
  ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConceptosLta] @pmClaseCon VARCHAR(10)=Null,@pmPdtermnado BIT=Null,@pmInactivo BIT=Null
 AS 
 SELECT C.IdConcepto,C.Concepto,C.ClaseCon,C.Unidad,C.Tarifa,C.BaseTrfa,C.Pdtermnado,C.TarifaEmp,C.DiasEmp
,C.IdConcNE,ConceptoNE,C.Inactivo,C.FechaAdd,C.FechaUpdate,C.IdUsuario
 FROM NomConceptos AS C LEFT JOIN NomConcDian AS CD ON C.IdConcNE=CD.IdConcNE
 WHERE C.ClaseCon LIKE ISNULL(@pmClaseCon,'%')
  AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
  AND  (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY C.Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosPre]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConceptosPre] 
 AS 
  SELECT C.IdConcepto AS IdConcept,Concepto,Concepto + ' ' + C.IdConcepto  AS DsCon
  FROM NomConceptos AS C INNER JOIN NomConOpciones AS O ON C.IdConcepto=O.IdConcepto
  WHERE Inactivo=0 AND IdOpc=13 AND Asignado<>0
  ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConceptosTar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConceptosTar] @pmIdConcepto VARCHAR(4)=Null,@pmPdtermnado BIT=Null
 AS 
 SELECT IdConcepto,Concepto,Tarifa,Pdtermnado
 FROM NomConceptos
 WHERE IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND  (Pdtermnado=ISNULL(@pmPdtermnado,0) or Pdtermnado=ISNULL(@pmPdtermnado,1))
 ORDER BY IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentas] @pmIdConcepto VARCHAR(4),@pmItem INT
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc,Tipo_Nom
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasCla]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentasCla] @pmIdConcepto VARCHAR(4),@pmNClase INT
,@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmTipo_Nom VARCHAR(10)=Null
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc,Tipo_Nom
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase
 AND (CodNom=@pmCodNom OR CodNom IS NULL OR LEN(CodNom)=0 )
 AND (CodDep=@pmCodDep OR CodDep IS NULL OR LEN(CodDep)=0)
 AND (ISNULL(Tipo_Nom,'')=@pmTipo_Nom OR @pmTipo_Nom IS NULL OR LEN(ISNULL(Tipo_Nom,''))=0)
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasCls]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentasCls] @pmIdConcepto VARCHAR(4),@pmNClase INT
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodNom,CodDep,CodFon,NitTerc
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasFon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentasFon] @pmIdConcepto VARCHAR(4),@pmNClase INT,@pmCodFon VARCHAR(8)
 AS 
 SELECT IdConcepto,Item,NClase,IdCuenta,TipoMov,CodFon,NitTerc
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto AND NClase=@pmNClase  AND CodFon=@pmCodFon
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentasId] @pmIdConcepto VARCHAR(4)
 AS 
 SELECT MAX(Item) AS MXITEM
 FROM NomConCuentas
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConCuentasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConCuentasLta] @pmIdConcepto VARCHAR(4)=Null,@pmCodNom VARCHAR(4)=Null,@pmCodDep VARCHAR(4)=Null
,@pmInactivo BIT=Null
 AS 
 SELECT NC.IdConcepto AS CodConcept,Concepto,Item,NClase,Tipo_Nom,NC.IdCuenta AS CodCuenta,NomCuenta,TipoMov
,CodNom,TipoNomina,CodDep,Dependencia,CodFon,Fondo,ClaseCon,Unidad,Tarifa,Pdtermnado,NitTerc
 FROM NomConCuentas AS NC INNER JOIN NomConceptos AS C ON NC.IdConcepto=C.IdConcepto
 INNER JOIN Puc AS P ON NC.IdCuenta=P.IdCuenta 
 LEFT JOIN TiposNom AS TN ON NC.CodNom=TN.IdNom
 LEFT JOIN Dependencias AS D ON NC.CodDep=D.IdDep
 LEFT JOIN Fondos AS F ON NC.CodFon=F.IdFondo
 WHERE NC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND CodNom LIKE ISNULL(@pmCodNom,'%')
 AND CodDep LIKE ISNULL(@pmCodDep,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY NC.IdConcepto,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConOpciones] @pmIdConcepto VARCHAR(4),@pmIdOpc INT=Null
 AS 
 SELECT IdConcepto,IdOpc,NomOpcion,Asignado
 FROM NomConOpciones
 WHERE IdConcepto=@pmIdConcepto 
 AND (IdOpc>=ISNULL(@pmIdOpc,0)  AND IdOpc<=ISNULL(@pmIdOpc,2147483647))
 ORDER BY IdOpc
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConOpcionesId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomConOpcionesId] @pmIdConcepto VARCHAR(4),@pmIdOpc INT,@pmAsignado BIT
 AS 
 SELECT count(IdOpc) AS SCANT -- IdConcepto,IdOpc,NomOpcion,Asignado
 FROM NomConOpciones
 WHERE IdConcepto=@pmIdConcepto  AND IdOpc=@pmIdOpc AND Asignado=@pmAsignado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConvenciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConvenciones] @pmId INT
 AS 
 SELECT Id,Fecha,Proyecto,FecInicio,FecFinal,IdLocal,NitTercero,Observacion,FecProrroga,FechaCrea,Inactivo
 FROM NomConvenciones
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConvencionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConvencionesLta]
 AS 
 SELECT C.Id,C.Proyecto,C.Fecha,C.FecInicio,C.FecFinal,C.IdLocal AS CodCiudad,L.Localidad AS NomCiudad,L.IdDep,D.Departamento
,C.NitTercero,RazonSocial,C.Observacion,C.FecProrroga,C.FechaCrea,C.Inactivo
 FROM NomConvenciones AS C INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomConvZonasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomConvZonasLta] @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
 AS 
SELECT Z.Id,Z.IdPeriodo,Z.IdEmpleado,E.Apellidos,E.Nombres,Z.NContrato,Z.FechaInicio,Z.FechaFinal,Z.IdConv,CV.Proyecto,Z.CodGrupo,G.GrupoConv
,Z.IdZona,ZN.ZonaConv,Z.FechaCrea,Z.IdUsuario,Usuario
FROM Trn_NomConvZonas AS Z INNER JOIN Empleados AS E ON Z.IdEmpleado=E.IdEmpleado 
INNER JOIN adm_Usuarios AS U ON Z.IdUsuario=U.IdUsuario INNER JOIN NomConvenciones AS CV ON Z.IdConv=CV.Id
INNER JOIN NomZonasConv AS ZN ON Z.IdZona=ZN.IdZona
LEFT JOIN NomGruposConv AS G ON Z.CodGrupo=G.IdGrupo
WHERE ((Z.FechaInicio BETWEEN @pmFecInicio AND @pmFecFinal) OR (Z.FechaFinal BETWEEN @pmFecInicio AND @pmFecFinal)
 OR (Z.FechaInicio>=@pmFecInicio AND Z.FechaFinal<=@pmFecFinal))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDefault]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomDefault] @pmnAnno INT,@pmIdOpc VARCHAR(3)
 AS 
 SELECT nAnno,IdOpc,Descripcion,Valor
 FROM NomDefault
 WHERE nAnno=@pmnAnno AND IdOpc LIKE ISNULL(@pmIdOpc,'%')
 ORDER BY IdOpc
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalle]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomDetalle] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmItem INT
 AS 
 SELECT IdPeriodo,KeyRegistro,Item,IdEmpleado,IdConcepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,Unidad,ClaseLiq,VrOrigen,Tarifa,DiasCalc
,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,NitTercero,HoraInicial,HoraFinal,TipoIncLab,VrIngNoSal
 FROM Trn_NomDetalle
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleAcu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleAcu] @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecIni SMALLDATETIME
,@pmFecFin SMALLDATETIME,@pmIdConcepto VARCHAR(4)=Null,@pmConcBas BIT=Null
 AS 
 IF @pmConcBas=1 --SOLO CONCEPTOS DEL BASICO
  SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
  FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
  WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
  AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0 AND IdConcepto IN ('BAS','LIC','IGE','IRP','DSR','VAC')
  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
  GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2)
 ELSE -- CONCEPTOS DEVENGADOS
  SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
  FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
  WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
  AND  ClaseLiq IN ('NOMINA','NOVEDAD')  AND VrBaseLiq>0 AND IdConcepto IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC','HFD','HFN')
  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
  GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleAux]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleAux] @pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
 AS 
    SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,VrATransMes
    ,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV
   ,SUM(VrBaseLiq) AS SBASELIQ
    FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
    WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
    AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
    AND IdConcepto='AXT' AND ClaseLiq IN ('NOMINA','NOVEDAD') AND (VrBaseLiq>0 OR VrTotDevg>0)
    GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),VrATransMes
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleBas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleBas] @pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16)
,@pmIdConcepto VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmTipBas VARCHAR(3),@pmClaseLiq VARCHAR(10),@pmPerMax INT
 AS 
 IF @pmTipBas='SD' --SALARIO BASICO
 SELECT IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(CantDed) AS SCANDED,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED
 ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ,SUM(VrBasExceso) AS STOTBEXC
 ,SUM(CASE WHEN IdConcepto='IGE' AND VrBasExceso>0 THEN VrBasExceso ELSE VrBaseLiq END) AS SBASEIGE 
 FROM Trn_NomDetalle 
 WHERE KeyRegistro=@pmKeyRegistro  AND IdEmpleado=@pmIdEmpleado AND SUBSTRING(IdPeriodo,1,6)=@pmMes
 AND IdPeriodo<>@pmIdPeriodo  AND CAST(SUBSTRING(IdPeriodo,7,2) AS INT)<@pmPerMax
 AND (IdConcepto NOT IN ('BAS','HHD','HHN','LIC','IGE','IRP','DSR','VAC','DCP','DCS','FSP','FSU','RET') OR (IdConcepto IN ('BAS','HHD','HHN') AND OrigCargue='CONVENCION'))
 AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 GROUP BY IdConcepto

 ELSE --TOTAL DEVENGADO

 SELECT IdConcepto, SUM(CantDevg) AS SCANDEV,SUM(CantDed) AS SCANDED,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED
 ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ,SUM(VrBasExceso) AS STOTBEXC
 ,SUM(CASE WHEN IdConcepto='IGE' AND VrBasExceso>0 THEN VrBasExceso ELSE VrBaseLiq END) AS SBASEIGE
 FROM Trn_NomDetalle 
 WHERE KeyRegistro=@pmKeyRegistro  AND IdEmpleado=@pmIdEmpleado AND SUBSTRING(IdPeriodo,1,6)=@pmMes
 AND IdPeriodo<>@pmIdPeriodo  AND CAST(SUBSTRING(IdPeriodo,7,2) AS INT)<@pmPerMax
 AND IdConcepto NOT IN ('DCP','DCS','FSP','FSU','RET')
 AND ClaseLiq IN ('NOMINA','NOVEDAD') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 GROUP BY IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleDia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleDia] @pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4)
,@pmIdPeriodo VARCHAR(8),@pmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT SUM(DiasCalc) AS SDiasCalc,SUM(DiasNov) AS SDiasNov,SUM(DiasCalc-DiasNov) AS DiasNeto
 FROM Trn_NomDetalle
 WHERE  KeyRegistro=@pmKeyRegistro AND IdEmpleado=@pmIdEmpleado AND IdConcepto=@pmIdConcepto
 AND SUBSTRING(IdPeriodo,1,6)=@pmMes AND IdPeriodo<>@pmIdPeriodo AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleDsp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleDsp] @pmIdPeriodo VARCHAR(8)=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
-- listado de carga inicial de promedios
 SELECT D.IdEmpleado AS CodEmpleado,Apellidos,Nombres,D.IdPeriodo AS IdPerdo,Item,IdConcepto,Detalle,VrBaseLiq,N.NContrato AS NumCont
,FecInicial,FecFinal,N.KeyRegistro AS KeyRegtro,VrDevengado,TimeSys,N.IdUsuario AS IdUsuari
 FROM Trn_NomDetalle AS D INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado 
 WHERE NLiqRet=-1 AND  D.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,D.IdPeriodo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleHex]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleHex]  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmIdEmpleado VARCHAR(16)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmEsRetiro BIT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdDep AS CodDepe,N.IdInstala AS CdInstala,N.IdCCosto AS CodCcosto
,N.IdSubCos AS CdSubcen,N.IdNom AS TipNom,N.VrSalario AS VrBasico,VrATransMes
,N.pVehiculo AS PlacaVeh,EsRetiro,IdArea,TipoLiq,D.IdConcepto AS CodConcepto,Concepto
,SUM(CantDevg) AS SCantDev,SUM(VrTotDevg) AS STotDev,SUM(CantDed) AS SCantDed,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc-DiasNov) AS TotalDias,SUM(VrBaseLiq) AS STotLiq
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE'  AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND ClaseCon='DEVENGADO'
 AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom like ISNULL(@pmIdNom,'%')  AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') 
 AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY N.IdEmpleado,Apellidos,Nombres,N.NContrato,N.IdDep,N.IdInstala,N.IdCCosto
,N.IdSubCos,N.IdNom,N.VrSalario,VrATransMes,N.pVehiculo,EsRetiro,IdArea,TipoLiq,D.IdConcepto,Concepto
 ORDER BY  N.IdEmpleado,N.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetallePer]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetallePer] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)=Null,@pmIdNom VARCHAR(4)=Null
 AS 
 SELECT D.IdEmpleado AS CedEmpleado,Apellidos,Nombres,Item,D.IdConcepto AS IdConcept,Detalle,ClaseCon,CantDevg,VrUnitario,VrTotDevg,CantDed,VrTotDed
,D.Unidad AS Undad,VrOrigen,D.Tarifa AS Tarfa,VrBaseLiq,DiasCalc,DiasNov,DiasCalc-DiasNov AS DiasNeto,ClaseLiq,NPrestamo,NCuota,OrigCargue,CodFondo,D.KeyRegistro AS Kyregistro
,D.TipoIncLab,D.HoraInicial,D.HoraFinal,D.VrIngNoSal
 FROM Trn_NomDetalle AS D INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN  NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Trn_Nomina AS N ON D.IdPeriodo=N.IdPeriodo AND D.KeyRegistro=N.KeyRegistro
 WHERE D.IdPeriodo=@pmIdPeriodo AND D.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') AND IdNom like ISNULL(@pmIdNom,'%')
 ORDER BY Apellidos,Nombres,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetallePmd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetallePmd] @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmModoPmd CHAR(1),@pmFecIni SMALLDATETIME
,@pmFecFin SMALLDATETIME,@pmIdConcepto VARCHAR(4)=Null
 AS 
 IF @pmModoPmd='F' --SALARIOS FIJO
  SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV,SUM(VrBaseLiq) AS SBASELIQ
  FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
  WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
  AND (IdConcepto NOT IN ('BAS','HHD','HHN','AXT','LIC','IGE','IRP','DSR','VAC') OR (IdConcepto IN ('BAS','HHD','HHN','AXT') AND OrigCargue='CONVENCION'))
  AND ClaseLiq IN ('NOMINA','NOVEDAD') AND VrBaseLiq>0 
  GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),IdConcepto
 ELSE 
  BEGIN
   IF @pmModoPmd='B' --SALARIO BASICO
    SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes,IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
   ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV
  ,SUM(CASE  WHEN IdConcepto IN ('DNR','SAN','STC') THEN CantDed*VrUnitario WHEN IdConcepto IN ('IGE','IRP') THEN (N.VrSalario/30)*CantDevg  ELSE VrBaseLiq END) AS SBASELIQ
    FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
    WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
   AND  ClaseLiq IN ('NOMINA','NOVEDAD') AND IdConcepto IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC','DNR','SAN','STC')
   AND (VrBaseLiq>0 OR IdConcepto='DNR' OR IdConcepto='SAN' OR IdConcepto='STC')
   GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),IdConcepto
  ELSE --SALARIO VARIABLE
   SELECT SUBSTRING(N.IdPeriodo,1,4) AS nAnno,SUBSTRING(N.IdPeriodo,5,2) AS nMes, IdConcepto,SUM(CantDevg) AS SCANDEV,SUM(VrTotDevg) AS STOTDEV
  ,SUM(DiasCalc) AS SDIASCAL,SUM(DiasNov) AS SDIASNOV
 ,SUM(CASE  WHEN IdConcepto IN ('DNR','SAN','STC') THEN CantDed*VrUnitario WHEN IdConcepto IN ('IGE','IRP') THEN (N.VrSalario/30)*CantDevg  ELSE VrBaseLiq END) AS SBASELIQ
   FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON  N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
   WHERE N.IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND FecInicial>=@pmFecIni AND FecFinal<=@pmFecFin
   AND  ClaseLiq IN ('NOMINA','NOVEDAD') AND (VrBaseLiq>0 OR IdConcepto='DNR' OR IdConcepto='SAN' OR IdConcepto='STC')
   AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
   GROUP BY  SUBSTRING(N.IdPeriodo,1,4),SUBSTRING(N.IdPeriodo,5,2),IdConcepto
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleRcon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleRcon] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null,@pmNPrestamo INT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumCntrato,D.IdConcepto AS CodConcept,Concepto,ClaseCon,SUBSTRING(N.IdPeriodo,1,6)  AS nMES
 ,SUM(CantDevg) AS SCantDevg,SUM(VrTotDevg) AS STotDevg,SUM(CantDed) AS SCantDed,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc) AS SCanDia,SUM(DiasNov) AS SDiasNov,SUM(DiasCalc-DiasNov) AS SDiasNeto,SUM(VrBaseLiq) AS SBaseLiq
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,N.NContrato,D.IdConcepto,Concepto,ClaseCon,SUBSTRING(N.IdPeriodo,1,6)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleRes] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null,@pmNPrestamo INT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumCntrato,N.KeyRegistro AS KeyReg,N.IdPeriodo AS NumPeriodo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdNom AS CodNmna,TipoNomina,N.IdDep AS CodDep,Dependencia,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcos,SubCosto,N.IdInstala AS CodIstala,Instlacion
,N.VrSalario AS SalBasico,N.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS IdEstdo,ED.Estado AS Nom_Estado,EsRetiro,NLiqRet,TipoLiq,TimeSys
,N.FecUpdate AS Fec_Update,N.IdUsuario AS IdUsuari,Usuario
--datos del detalle
,D.Item,D.IdConcepto AS CodConcept,Concepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,ClaseCon,D.Unidad AS Undad,ClaseLiq,VrOrigen,D.Tarifa AS Tarfa,DiasCalc,DiasNov,CodFondo,FCO.Fondo AS NomFondo
,NPrestamo,NCuota,OrigCargue,VrBaseLiq,VrBasExceso,D.HoraInicial,D.HoraFinal,D.TipoIncLab,D.VrIngNoSal
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,FC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS VlrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj,C.IdGrupo AS CodGrup
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala  INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom  LEFT JOIN Fondos AS FCO ON D.CodFondo=FCO.IdFondo
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
--Descuentos en vacaciones
UNION ALL
 SELECT V.IdEmpleado,Apellidos,Nombres,V.NContrato,V.IdEmpleado,D.IdPeriodo,V.FecInicial,V.FecFinal,V.Cantidad,0,V.VrLiquida,V.VrTotDed
,C.IdNom,TipoNomina,C.IdDep,Dependencia,C.IdCCosto,CCosto,C.IdSubCos,SubCosto,C.IdInstala,Instlacion,V.VrSalario,V.pVehiculo,V.TipCom,TipoCom,V.Comprobante,V.IdCiaCom
,V.Observacion,V.IdEstado,ED.Estado,0,V.Numero,C.TipoLiquida,V.TimeSys,V.FecUpdate,V.IdUsuario,Usuario
,D.Item,D.IdConcepto,Concepto,D.Detalle,0,CASE D.IdConcepto WHEN 'DCP' THEN 0 WHEN 'DCS' THEN 0 WHEN 'FSP' THEN 0 WHEN 'FSU' THEN 0 ELSE D.Cantidad END AS CantDed,0,D.VrDevgado,D.VrDeducido,ClaseCon,'%','NOMINA',D.VrBaseLiq,D.Tarifa
,CASE D.IdConcepto WHEN 'DCP' THEN 0 WHEN 'DCS' THEN 0 WHEN 'FSP' THEN 0 WHEN 'FSU' THEN 0 ELSE D.Cantidad END AS DiasCalc,0,D.CodFondo,FD.Fondo,D.NPrestamo,D.NCuota,'VAC',D.VrBaseLiq,0,Null,Null,'',0
,E.Codigo,E.IdLugarCed,Localidad,E.Direccion,E.Telefono,E.TelMovil,E.e_mail,E.IdProf,Profesion,E.IdClase,ClaseCuenta,NumCuenta,E.IdBanco,Banco,IdFonPen,FP.Fondo
,IdFonEps,FS.Fondo,IdFonArp,FR.Fondo,IdCajaCom,FC.Fondo,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo
,C.IdTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo,Cargo,C.IdArea,Area,C.IdClase,ClaseRiesgo,CR.Tarifa,C.VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina
,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado,ECO.Estado,C.Inactivo,C.IdJornada,Jornada,TipoTrabj,C.IdGrupo
 FROM Trn_NomVac AS V INNER JOIN Trn_NomVacDet AS D ON V.IdEmpleado=D.IdEmpleado AND V.Numero=D.Numero
 INNER JOIN Empleados AS E ON V.IdEmpleado=E.IdEmpleado INNER JOIN Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN Dependencias AS DPD ON C.IdDep=DPD.IdDep
 INNER JOIN CentroCosto AS CC ON C.IdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado INNER JOIN EstadoDoc AS ED ON V.IdEstado=ED.IdEstado
 LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos LEFT JOIN TiposCom AS TCM ON V.TipCom=TCM.IdCom
 LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE V.Anulado=0 
 AND (SUBSTRING(D.IdPeriodo,1,6)>=SUBSTRING(CONVERT(VARCHAR(30),@pmFecIni,112),1,6) AND SUBSTRING(D.IdPeriodo,1,6)<=SUBSTRING(CONVERT(VARCHAR(30),@pmFecFin,112),1,6))
 AND D.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND V.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND V.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (V.NContrato>=ISNULL(@pmNContrato,0)  AND V.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (D.NPrestamo>=ISNULL(@pmNPrestamo,0)  AND D.NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleResN]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleResN] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmEsRetiro BIT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null
 AS 
SELECT N.IdEmpleado AS IdEmple,N.NContrato AS NumContrato,FecInicial,FecFinal,N.IdPeriodo AS IdPerdo,IdArea,N.IdDep AS nDepe,N.IdInstala AS nInstala
,N.IdCCosto AS CodCcosto,N.IdSubCos AS CodSubcentro,N.IdNom AS CdNom,N.VrSalario AS vSalario,VrATransMes,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom
,N.Observacion AS Observ,EsRetiro,NLiqRet,TipoLiq
--Detales
,D.IdConcepto AS CdConcepto,Item,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad AS Und,ClaseLiq,VrOrigen,D.Tarifa AS Tarif,DiasCalc,DiasNov,CodFondo
,NPrestamo,NCuota,VrBaseLiq,HoraInicial,HoraFinal,TipoIncLab,VrIngNoSal
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%')  AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY  FecInicial, N.IdEmpleado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleRtot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleRtot] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmClaseLiq VARCHAR(10)=Null,@pmClaseCon VARCHAR(10)=Null,@pmNPrestamo INT=Null
 AS 
 SELECT SUM(CantDevg) AS SCantDevg,SUM(VrTotDevg) AS STotDevg,SUM(CantDed) AS SCantDevg,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc) AS SCantDias,SUM(DiasNov) AS SDiasNoRem,SUM(DiasCalc-DiasNov) AS SDiasNet,SUM(VrBaseLiq) AS STotLiq
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN  Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND  N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 AND ClaseCon LIKE ISNULL(@pmClaseCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDetalleTar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDetalleTar] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT D.IdConcepto AS CodConcepto,Concepto,CN.Tarifa AS TrifaDft,D.Tarifa AS Tarfa,SUM(VrTotDevg) AS STotDev,SUM(VrTotDed) AS StotDed
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D  ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND NLiqRet>=0 AND D.IdConcepto IN ('DCP','DCS','PEN','RIE','SAL','FSP','FSU','SEN','ICB','COM')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND ClaseLiq LIKE ISNULL(@pmClaseLiq,'%')
 GROUP BY  D.IdConcepto,Concepto,CN.Tarifa,D.Tarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDiarioLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomDiarioLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdEmpleado VARCHAR(16)=Null
 AS 
SELECT N.IdEmpleado AS CdEmpleado,Apellidos,Nombres,N.Fecha,N.ValorDia,N.DctoPension,N.DctoSalud,N.AporteRP,N.AporteParaf,N.PrestSocial
,E.NContrato,C.FecIngreso,C.FecRetiro,C.Indefinido,C.IdCargo AS CdCargo,Cargo,C.IdArea AS CdArea,Area,C.IdDep AS CdDep,Dependencia
,C.IdInstala AS CdInstala,Instlacion,C.IdCia AS CdCia,Compania,C.IdNom AS CdNom,TipoNomina,C.TipoLiquida,C.VrSalario,C.VrAuxTrans,C.SalMinimo
,C.ATFinMes,SegFinMes,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyCes,DenyPri,DenyVac,E.Direccion,E.IdLocal AS CdLocal,Localidad,E.Telefono,E.TelMovil,E.e_mail
,E.IdProf AS CdProf,Profesion,N.FechaCrea,N.IdUsuario AS CdUsuario,Usuario,N.Id
FROM Trn_NomDiario AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN Emp_Contrato AS C ON E.NContrato=C.NContrato
INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
INNER JOIN Areas AS A ON C.IdArea=A.IdArea INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom 
INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
WHERE N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (@pmIdEmpleado IS NULL OR N.IdEmpleado=@pmIdEmpleado)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDotacion]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomDotacion] @pmIdCia CHAR(2),@pmNumero INT
 AS 
 SELECT IdCia,Numero,Fecha,TipoDotac,TipoEntrega,PlazoEntrega,FecVence,TipoReg,Anulado,FechaCrea,IdUsuario,Observacion,CritFiltros
 FROM Trn_NomDotacion
 WHERE IdCia=@pmIdCia AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDotacion_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomDotacion_Cr] @pmIdCia CHAR(2),@pmNumeroIni INT,@pmNumeroFin INT
 AS 
 SELECT DT.IdCia AS CdCia,CI.Compania,DT.Numero AS NumReg,DT.Fecha AS FechaEnt,TipoDotac,TipoEntrega,PlazoEntrega,FecVence
,TipoReg,DT.Anulado,FechaCrea,DT.IdUsuario AS CdUsuario,Usuario,DT.Observacion AS Observ,CritFiltros
,Item,D.IdEmpleado AS CdEmpleado,Apellidos,Nombres,D.NContrato AS NumCont,D.IdPrend AS CdPrend,DescPrenda,D.Descripcion,Cantidad,Unidad,D.VrUnitario
,C.IdTipCon AS CdTipCon,TipoContrato,FecIngreso,C.IdArea AS CdArea,Area,C.IdDep AS CdDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdCargo AS CodCargo,Cargo
,C.IdCia AS ConCdCia,CN.Compania AS ConCompania,C.IdNom AS CdNom,TipoNomina,C.TipoLiquida AS TipoLiq,DchDotacion,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,E.Codigo,e_mail,E.Sexo,E.IdProf AS CodProf,Profesion,FecUltDot
 FROM Trn_NomDotacion AS DT INNER JOIN Trn_NomDotacionDet AS D ON DT.IdCia=D.IdCia AND DT.Numero=D.Numero
 INNER JOIN Companias AS CI ON DT.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON DT.IdUsuario=U.IdUsuario
 INNER JOIN NomPrendas AS PN ON D.IdPrend=PN.IdPrend
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf 
 LEFT JOIN Emp_Contrato AS C ON D.NContrato=C.NContrato LEFT JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo LEFT JOIN Dependencias AS DP ON C.IdDep=DP.IdDep
 LEFT JOIN Areas AS AR ON C.IdArea=AR.IdArea LEFT JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 LEFT JOIN Companias AS CN ON C.IdCia=CN.IdCia  LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 WHERE DT.IdCia=@pmIdCia AND DT.Numero BETWEEN @pmNumeroIni AND @pmNumeroFin
GO
/****** Object:  StoredProcedure [dbo].[paQryNomDotacionLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomDotacionLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT DT.IdCia AS CdCia,CI.Compania,DT.Numero AS NumReg,DT.Fecha AS FechaEnt,TipoDotac,TipoEntrega,PlazoEntrega,FecVence
,TipoReg,DT.Anulado,FechaCrea,DT.IdUsuario AS CdUsuario,Usuario,DT.Observacion AS Observ,CritFiltros
,Item,D.IdEmpleado AS CdEmpleado,Apellidos,Nombres,D.NContrato AS NumCont,D.IdPrend AS CdPrend,DescPrenda,D.Descripcion,Cantidad,Unidad,D.VrUnitario
,C.IdTipCon AS CdTipCon,TipoContrato,FecIngreso,C.IdArea AS CdArea,Area,C.IdDep AS CdDep,Dependencia,C.IdInstala AS IdInstla,Instlacion,C.IdCargo AS CodCargo,Cargo
,C.IdCia AS ConCdCia,CN.Compania AS ConCompania,C.IdNom AS CdNom,TipoNomina,C.TipoLiquida AS TipoLiq,DchDotacion,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,E.Codigo,e_mail,E.Sexo,E.IdProf AS CodProf,Profesion,FecUltDot
 FROM Trn_NomDotacion AS DT INNER JOIN Trn_NomDotacionDet AS D ON DT.IdCia=D.IdCia AND DT.Numero=D.Numero
 INNER JOIN Companias AS CI ON DT.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON DT.IdUsuario=U.IdUsuario
 INNER JOIN NomPrendas AS PN ON D.IdPrend=PN.IdPrend
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf 
 LEFT JOIN Emp_Contrato AS C ON D.NContrato=C.NContrato LEFT JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo LEFT JOIN Dependencias AS DP ON C.IdDep=DP.IdDep
 LEFT JOIN Areas AS AR ON C.IdArea=AR.IdArea LEFT JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 LEFT JOIN Companias AS CN ON C.IdCia=CN.IdCia  LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 WHERE DT.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND DT.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryNomEscalafones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomEscalafones] @pmIdEscfon VARCHAR(4)
 AS 
 SELECT IdEscfon,Escalafon,IdConv,IdGrupo,IdCargo,Inactivo
 FROM NomEscalafones
 WHERE IdEscfon=@pmIdEscfon
GO
/****** Object:  StoredProcedure [dbo].[paQryNomEscalafonesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomEscalafonesLta]
 AS 
 SELECT E.IdEscfon,E.Escalafon,E.IdConv,C.Proyecto,E.IdGrupo,G.GrupoConv,E.IdCargo,CG.Cargo
 ,C.Fecha,C.FecInicio,C.FecFinal,C.IdLocal AS CodCiudad,L.Localidad AS NomCiudad,L.IdDep,D.Departamento
 ,C.NitTercero,RazonSocial,E.Inactivo
 FROM NomEscalafones AS E INNER JOIN Cargos AS CG ON E.IdCargo=CG.IdCargo
 INNER JOIN NomConvenciones AS C ON E.IdConv=C.Id INNER JOIN NomGruposConv AS G ON E.IdGrupo=G.IdGrupo
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomEstadosConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomEstadosConv] @pmIdEstado VARCHAR(4)
 AS 
 IF @pmIdEstado IS NULL
  BEGIN
   SELECT IdEstado,EstadoConv,NColor,Inactivo
   FROM NomEstadosConv
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdEstado,EstadoConv,NColor,Inactivo
   FROM NomEstadosConv
   WHERE IdEstado=@pmIdEstado  
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryNomFijos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomFijos] @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT
 AS 
 SELECT IdEmpleado,nAnno,nMes,Tarifa,VrBase,VrSalarios,VrPrima,VrVacacnes,VrSIntExcto,VrOtrosIng,VrIngresos,VrPensiones,VrSalud,VrDedcido,VrExcento,VrCertEdu,VrCertVda
,VrCertAFC,VrCertfcado,VrTotalBase,Periodos,OrignPorc,IngNoSalario,PagosMedicPre,AportesVolPen,GastosRep,Indemnizac,FecAdd,FecUpdate,IdUsuario
 FROM Trn_NomFijos
 WHERE IdEmpleado=@pmIdEmpleado AND nAnno=@pmnAnno AND nMes=@pmnMes
GO
/****** Object:  StoredProcedure [dbo].[paQryNomFijosLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomFijosLta] @pmIdEmpleado VARCHAR(16)=Null,@pmnAnno INT=Null,@pmnMes INT=Null
 AS 
 SELECT F.IdEmpleado AS IdEmpledo,Apellidos,Nombres,nAnno,nMes,Tarifa,VrBase,VrSalarios,VrPrima,VrVacacnes,VrOtrosIng,VrSIntExcto
,IngNoSalario,VrIngresos,VrCertVda,VrCertEdu,PagosMedicPre,VrSalud,VrDedcido,VrPensiones,AportesVolPen
,VrCertAFC,GastosRep,Indemnizac,VrCertfcado,VrExcento,VrTotalBase,Periodos,OrignPorc,Codigo,NContrato,FecUltIng,F.IdUsuario AS IdUsuari,Usuario,FecAdd,FecUpdate
 FROM Trn_NomFijos AS F INNER JOIN Empleados AS E ON F.IdEmpleado=E.IdEmpleado
 INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
 WHERE F.IdEmpleado like ISNULL(@pmIdEmpleado,'%')
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))
 AND (nMes>=ISNULL(@pmnMes,0)  AND nMes<=ISNULL(@pmnMes,2147483647))
 ORDER BY Apellidos,Nombres,nAnno,nMes
GO
/****** Object:  StoredProcedure [dbo].[paQryNomGruposConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomGruposConv] @pmIdGrupo VARCHAR(4)
 AS 
 SELECT IdGrupo,GrupoConv,IdConv,Inactivo
 FROM NomGruposConv
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomGruposConvLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomGruposConvLta] 
 AS 
 SELECT G.IdGrupo,G.GrupoConv,G.IdConv,C.Proyecto,C.Fecha,C.FecInicio,C.FecFinal
 ,C.IdLocal AS CodCiudad,L.Localidad AS NomCiudad,L.IdDep,D.Departamento
,C.NitTercero,RazonSocial,G.Inactivo
 FROM NomGruposConv AS G INNER JOIN NomConvenciones AS C ON G.IdConv=C.Id
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomina]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomina] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,NContrato,IdDep,IdInstala,IdCCosto,IdSubCos,IdNom
,VrSalario,VrATransMes,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,EsRetiro,NLiqRet,TipoLiq,TimeSys,FecUpdate,IdUsuario
,CdTipoCot,SubTipo_Cot,Sal_Integral,TipoIdent,NotasAportante,CantModifica,NE_Estado,NE_Prefijo,NE_Numero,NE_FecEnvio,NE_CUNE,NE_QR,NE_ComAju,NE_CntAju,NE_Ajustes
 FROM Trn_Nomina
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%')
 ORDER BY KeyRegistro
GO
/****** Object:  StoredProcedure [dbo].[paQryNomina_Cpn]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomina_Cpn]  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdPeriodo AS IdPerdo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdDep AS CodDep,Dependencia,N.IdInstala AS CodInst,Instlacion,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcen,SubCosto,N.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,TipoLiq,N.VrSalario AS VrSalBasico,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS Nom_IdEstdo,EN.Estado AS Nom_Estado,EsRetiro,NLiqRet
,N.CantModifica,N.NE_Estado,N.NE_Prefijo,N.NE_Numero,N.NE_FecEnvio,N.NE_CUNE,N.NE_QR,N.KeyRegistro AS KeyRegstro,N.NE_ComAju,N.NE_CntAju,N.NE_Ajustes,N.TimeSys,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario
--datos detalle de nomina
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad AS Undad,ClaseLiq,VrOrigen,D.Tarifa AS TarifaBase,DiasCalc,DiasNov,CodFondo,FD.Fondo AS Det_Fondo
,NPrestamo,NCuota,OrigCargue,VrBaseLiq,ClaseCon
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj
,NumVeh,TipoAdmon,VehPropio,VrATransMes
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado 
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 LEFT JOIN NomVehiculos AS VH ON N.pVehiculo=VH.IdVehiculo
 WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND ClaseLiq IN ('NOMINA','NOVEDAD','LIQUDACION')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') 
 AND N.IdNom like ISNULL(@pmIdNom,'%') AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY N.KeyRegistro,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomina_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomina_Cr]  @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdPeriodo AS IdPerdo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdDep AS CodDep,Dependencia,N.IdInstala AS CodInst,Instlacion,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcen,SubCosto,N.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,TipoLiq,N.VrSalario AS VrSalBasico,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS Nom_IdEstdo,EN.Estado AS Nom_Estado,EsRetiro,NLiqRet
,N.CantModifica,N.NE_Estado,N.NE_Prefijo,N.NE_Numero,N.NE_FecEnvio,N.NE_CUNE,N.NE_QR,N.KeyRegistro AS KeyRegstro,N.NE_ComAju,N.NE_CntAju,N.NE_Ajustes,N.TimeSys,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario
--datos detalle de nomina
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,D.Unidad AS Undad,ClaseLiq,VrOrigen,D.Tarifa AS TarifaBase,DiasCalc,DiasNov,CodFondo,FD.Fondo AS Det_Fondo
,NPrestamo,NCuota,OrigCargue,VrBaseLiq,ClaseCon
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj
,NumVeh,TipoAdmon,VehPropio,VrATransMes
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado 
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 LEFT JOIN NomVehiculos AS VH ON N.pVehiculo=VH.IdVehiculo
 WHERE N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') AND N.IdNom like ISNULL(@pmIdNom,'%')
 AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY N.KeyRegistro,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaApo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaApo] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmCodFondo VARCHAR(8)=Null,@pmIdCia CHAR(2)=Null
AS 
 SELECT N.KeyRegistro AS KeyReg,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContto,FecInicial,FecFinal,N.IdDep AS CodDep,N.IdInstala AS CodInstala,N.IdCCosto AS CodCcto
,N.IdSubCos AS CodSubcc,N.IdNom AS CodNom,N.pVehiculo AS PlacaVeh,N.VrSalario AS Salbasico,EsRetiro,NLiqRet,IdFonPen,IdFonEps,IdFonArp,IdFonCes,IdCajaCom,FecIngreso,FecRetiro,IdArea,C.IdClase AS CodClaRie
,CR.Tarifa AS TarRie,TipoTrabj,VrAuxTrans,VrUpc,SalIntegral,SalMinimo,C.Inactivo AS Con_Inctivo,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,CN.Tarifa AS TarifDft,ClaseLiq,CantDevg,CantDed,VrTotDevg,VrTotDed,VrOrigen,D.Tarifa AS Tarfa
,DiasCalc,DiasNov,DiasCalc-DiasNov AS DiasNeto,CodFondo,IdCot,SubTipoCot,DenyPEN,DenyEPS,DenyARP,DenyCaj,DenyDcto,LiqEspSalud,DctoSalud,PagoSalud,D.VrBaseLiq,TN.NomDiario
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase  INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND NLiqRet>=0 AND D.IdConcepto IN ('PEN','RIE','SAL','FSP','FSU','SEN','ICB','COM','DCP','DCS','AVP','AVA')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND N.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND CodFondo LIKE ISNULL(@pmCodFondo,'%')
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 UNION ALL
 SELECT D.IdPeriodo,V.IdEmpleado,Apellidos,Nombres,V.NContrato,V.FecInicial,V.FecFinal,C.IdDep,C.IdInstala,C.IdCCosto,C.IdSubCos,C.IdNom,V.pVehiculo
,V.VrSalario,0,0,IdFonPen,E.IdFonEps,IdFonArp,IdFonCes,IdCajaCom,C.FecIngreso,C.FecRetiro,C.IdArea,C.IdClase,0,C.TipoTrabj,C.VrAuxTrans,C.VrUpc
,C.SalIntegral,C.SalMinimo,C.Inactivo,D.IdConcepto,Concepto,ClaseCon,CN.Tarifa,'NOMINA',0,D.Cantidad,D.VrDevgado,D.VrDeducido,D.VrBaseLiq,D.Tarifa
,D.Cantidad,0,D.Cantidad,E.IdFonEps,C.IdCot,C.SubTipoCot,C.DenyPEN,C.DenyEPS,C.DenyARP,C.DenyCaj,C.DenyDcto,LiqEspSalud,DctoSalud,PagoSalud,D.VrBaseLiq,TN.NomDiario
 FROM Trn_NomVac AS V INNER JOIN Trn_NomVacDet AS D ON V.IdEmpleado=D.IdEmpleado AND V.Numero=D.Numero
 INNER JOIN Empleados AS E ON V.IdEmpleado=E.IdEmpleado INNER JOIN Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE SUBSTRING(D.IdPeriodo,1,6)=@pmMes AND D.IdConcepto IN ('DCP','DCS','FSP','FSU') AND V.Anulado=0
 AND D.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY  N.IdEmpleado,N.NContrato,D.IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaAux]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaAux] @pmIdEmpleado VARCHAR(16),@pmNContrato INT
,@pmnMes VARCHAR(2),@pmnAnno VARCHAR(4)
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,NContrato,VrSalario,VrATransMes
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
 AND SUBSTRING(IdPeriodo,5,2)=@pmnMes AND  SUBSTRING(IdPeriodo,1,4)=@pmnAnno 
 ORDER BY IdPeriodo
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaBan] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,N.NContrato AS NumContrato,TipoLiq,Cargo
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN ClaseCta AS CTA ON E.IdClase=CTA.IdClase
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes  AND FPnomina='TRANS' AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,N.NContrato,TipoLiq,Cargo
 ORDER BY Apellidos,Nombres,N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBanl]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaBanl] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
--Nomina + liq prima+intereses
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,N.NContrato AS NumContrato,TipoLiq,Cargo,'NOM' AS TipProc,'NOMI' AS CodConcepto
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS,SUM(VrTotDevg-VrTotDed) AS SNETLIQ
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN ClaseCta AS CTA ON E.IdClase=CTA.IdClase
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes  AND FPnomina='TRANS' AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,N.NContrato,TipoLiq,Cargo
UNION ALL
SELECT D.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,D.NContrato,C.TipoLiquida,Cargo,L.TipoLiq,D.IdConcepto
,SUM(VrLiquida),SUM(VrDeducido),SUM(VrParcial),SUM(VrLiquida-VrDeducido) 
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN Emp_Contrato AS C ON D.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND ((L.TipoLiq='CES' AND Semstre=0) OR L.TipoLiq='PRI') 
 AND L.Anulado=0 AND FPnomina='TRANS'
 AND D.IdNom LIKE ISNULL(@pmIdNom,'%') AND D.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
GROUP BY D.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,D.NContrato,C.TipoLiquida,Cargo,L.TipoLiq,D.IdConcepto
ORDER BY Apellidos,Nombres,N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBanlv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaBanlv] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
--Nomina + liq prima+intereses+vac
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,N.NContrato AS NumContrato,TipoLiq,Cargo,'NOM' AS TipProc,'NOMI' AS CodConcepto
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS,SUM(VrTotDevg-VrTotDed) AS SNETLIQ
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN ClaseCta AS CTA ON E.IdClase=CTA.IdClase
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes  AND FPnomina='TRANS' AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,N.NContrato,TipoLiq,Cargo
UNION ALL
SELECT D.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,D.NContrato,C.TipoLiquida,Cargo,L.TipoLiq,D.IdConcepto
,SUM(VrLiquida),SUM(VrDeducido),SUM(VrParcial),SUM(VrLiquida-VrDeducido) 
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN Emp_Contrato AS C ON D.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND ((L.TipoLiq='CES' AND Semstre=0) OR L.TipoLiq='PRI') 
 AND L.Anulado=0 AND FPnomina='TRANS'
 AND D.IdNom LIKE ISNULL(@pmIdNom,'%') AND D.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
GROUP BY D.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,D.NContrato,C.TipoLiquida,Cargo,L.TipoLiq,D.IdConcepto
--vacaciones
UNION ALL
SELECT V.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,V.NContrato,C.TipoLiquida,Cargo,'VAC','VA'
,VrLiquida,VrTotDed,VrRemndo,(VrLiquida+VrRemndo)-VrTotDed
 FROM Trn_NomVac AS V INNER JOIN Empleados AS E ON V.IdEmpleado=E.IdEmpleado  
 INNER JOIN Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE V.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0 AND FPnomina='TRANS' 
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
ORDER BY Apellidos,Nombres,N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaBanNv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaBanNv] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
--Nomina +vacaciones
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,N.NContrato AS NumContrato,TipoLiq,Cargo,'NOM' AS TipProc,'NOMI' AS CodConcepto
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS,SUM(VrTotDevg-VrTotDed) AS SNETLIQ
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN ClaseCta AS CTA ON E.IdClase=CTA.IdClase
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE SUBSTRING(N.IdPeriodo,1,6)=@pmMes  AND FPnomina='TRANS' AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY  N.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,N.NContrato,TipoLiq,Cargo
--vacaciones
UNION ALL
SELECT V.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
,E.IdBanco,Banco,CodEntidad,CdLocCue,E.Direccion,TelMovil,e_mail,Telefono,V.NContrato,C.TipoLiquida,Cargo,'VAC','VA'
,VrLiquida,VrTotDed,VrRemndo,(VrLiquida+VrRemndo)-VrTotDed
 FROM Trn_NomVac AS V INNER JOIN Empleados AS E ON V.IdEmpleado=E.IdEmpleado  
 INNER JOIN Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE V.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0 AND FPnomina='TRANS' 
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
ORDER BY Apellidos,Nombres,N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCa]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaCa] @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT KeyRegistro,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NCtto,TipCom,Comprobante,IdCiaCom,N.IdEstado AS IdEstdo
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 WHERE IdPeriodo=@pmIdPeriodo  AND IdNom=@pmIdNom AND EsRetiro=0 AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY  KeyRegistro
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCed]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaCed] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaCip] @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecha SMALLDATETIME
 AS 
 SELECT IdPeriodo,KeyRegistro,IdEmpleado,FecInicial,FecFinal,NContrato,EsRetiro,NLiqRet
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato AND NLiqRet<>-1 AND FecFinal<=@pmFecha
 ORDER BY IdPeriodo,FecInicial
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNominaCon] @pmIdEmpleado VARCHAR(16),@pmNContrato INT
 AS 
 SELECT IdPeriodo,IdEmpleado,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,NContrato
,TipCom,Comprobante,IdCiaCom,IdEstado,EsRetiro,NLiqRet
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
 ORDER BY IdPeriodo
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaDia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaDia] @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmnMes VARCHAR(6)
 AS 
 SELECT  SUM(Cantidad) AS SDIAS,SUM(CantNoRem) AS SNOREM,SUM(Cantidad-CantNoRem) AS SDIASNET
 FROM Trn_Nomina
 WHERE IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato 
 AND SUBSTRING(IdPeriodo,1,6)=@pmnMes
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNominaDso] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdNom VARCHAR(4)=Null
 AS 
 SELECT KeyRegistro,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,IdPeriodo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,N.NContrato AS NumContrato,N.IdNom AS CodNom,TipoNomina
,N.IdDep AS CodDep,Dependencia,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcos,SubCosto,N.IdInstala
,N.VrSalario,N.pVehiculo AS PlacaVeh,N.TipCom,N.Comprobante,N.IdCiaCom,N.Observacion AS Observ,N.IdEstado AS IdEstdo,Estado,N.EsRetiro,N.NLiqRet,N.TipoLiq
,N.VrATransMes,N.CdTipoCot,N.SubTipo_Cot,N.Sal_Integral,N.TipoIdent,N.NotasAportante,N.CantModifica,N.NE_Estado,N.NE_Prefijo,N.NE_Numero,N.NE_FecEnvio,N.NE_CUNE,N.NE_QR,N.NE_ComAju,N.NE_CntAju,N.NE_Ajustes
,N.IdUsuario AS IdUsuari,Usuario,N.TimeSys,N.FecUpdate AS FecUpdte
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN Dependencias AS D ON N.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 WHERE IdPeriodo=@pmIdPeriodo AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND N.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 ORDER BY  N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaElectronica]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[paQryNominaElectronica] 
	-- Add the parameters for the stored procedure here
	@IdEmpleado  varchar(16),
	@IdPeriodo varchar(6),
	@liqNomn int = null,
	@fecIni date = null,
	@fecFIn date = null
AS
BEGIN --INFORMACION NOMINA DEL EMPLEADO
	SELECT
	--PERIODO
	SUBSTRING(N.IdPeriodo,1,6) IdPeriodo,MIN(N.FecInicial) FecInicial,MAX(N.FecFinal) FecFinal,SUM(N.Cantidad) DiasTrabajados
	,(CASE WHEN DAY(MAX(N.FecFinal)) > 30 THEN 30 ELSE DAY(MAX(N.FecFinal)) END-CASE WHEN DAY(MIN(EC.FecIngreso)) > 30 THEN 30 ELSE DAY(MIN(EC.FecIngreso)) END+1+DATEDIFF(MONTH, MIN(EC.FecIngreso), MAX(N.FecFinal))*30) TiempoLaborado
	--DATOS EMPLEADO
	,EM.TipoId TipoDocumento,EM.Apellidos ApellidosTrabajador,EM.Nombres NombresTrabajador,N.IdEmpleado,CASE WHEN EC.FecIngreso < ECA.FecIngreso THEN EC.FecIngreso ELSE ECA.FecIngreso END FecIngreso,EC.FecRetiro
	,EC.IdCot TipoTrabajador,CASE WHEN EC.IdGrupo <> 0 THEN 1 ELSE 0 END AltoRiesgoPension,Ap.CodISO LugarTrabajoPais,DEP.IdDep LugarTrabajoDepartamento
	,INS.CodCiu LugarTrabajoMunicipioCiudad,INS.DirInstala LugarTrabajoDireccion,EC.SalIntegral SalarioIntegral,TC.CodDIAN TipoContrato,EC.VrSalario Sueldo
	,EC.IdMedPago MetodoPago,B.Banco,CL.ClaseCuenta,EM.NumCuenta,EC.IdCia Prefijo
	--DATOS EMPLEADOR
	,TE.TipoId TipoIdEmpleador,TE.IdTercero NitEmpleador
	--ENVIO DIAN
	,NE_Prefijo,NE_Numero,NE_CUNE,NE_FecEnvio FechaCrea
	FROM (SELECT SUBSTRING(N.IdPeriodo,1,6) IdPeriodo,N.IdEmpleado,MIN(N.FecInicial) FecInicial,MAX(N.FecFinal) FecFinal,min(EC.FecIngreso) FecIngreso,SUM(N.Cantidad) Cantidad,
	MAX(N.NContrato) NContrato,MIN(N.NContrato) ContratoAnt,NE_Prefijo,NE_Numero,NE_CUNE,NE_FecEnvio
	FROM Trn_Nomina N
	LEFT JOIN Emp_Contrato EC on N.IdEmpleado=EC.IdEmpleado AND EC.Inactivo=0
	WHERE SUBSTRING(N.IdPeriodo,1,6) = @IdPeriodo AND N.IdEmpleado=@IdEmpleado
	GROUP BY SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado,NE_Prefijo,NE_Numero,NE_CUNE,NE_FecEnvio) N
	INNER JOIN Emp_Contrato EC on N.IdEmpleado=EC.IdEmpleado AND N.NContrato = EC.NContrato 
	INNER JOIN Adm_Registro AR on AR.IdCia=(SELECT TOP 1 IdCia FROM Adm_Registro)
	INNER JOIN Terceros TE on TE.IdTercero=AR.IdEmpresa
	INNER JOIN Empleados as EM on EC.IdEmpleado=EM.IdEmpleado
	INNER JOIN Instalaciones as INS on INS.IdInstala=EC.IdInstala
	INNER JOIN Departamentos as DEP on DEP.IdDep=SUBSTRING(INS.CodCiu,0,3)
	INNER JOIN Adm_Paises as AP on AP.IdPais=DEP.IdPais
	INNER JOIN ClaseCta AS CL on EM.IdClase = CL.IdClase
	LEFT JOIN TiposCon AS TC on EC.IdTipCon = TC.IdTipCon
	LEFT JOIN Bancos AS B on EM.IdBanco = B.IdBanco
	LEFT JOIN Emp_Contrato ECA on N.IdEmpleado=ECA.IdEmpleado AND N.ContratoAnt = ECA.NContrato 
	WHERE SUBSTRING(N.IdPeriodo,1,6) = @IdPeriodo AND N.IdEmpleado=@IdEmpleado
	GROUP BY N.NContrato,SUBSTRING(N.IdPeriodo,1,6),EM.TipoId,EM.Apellidos,EM.Nombres,N.IdEmpleado,EC.FecRetiro,EC.IdCot,
	EC.IdGrupo,Ap.CodISO,DEP.IdDep,INS.CodCiu,INS.DirInstala,EC.SalIntegral,TC.CodDIAN,EC.VrSalario,EC.IdMedPago,B.Banco,
	CL.ClaseCuenta,EM.NumCuenta,EC.IdCia,TE.TipoId,TE.IdTercero,CASE WHEN EC.FecIngreso < ECA.FecIngreso THEN EC.FecIngreso ELSE ECA.FecIngreso END
	,NE_Prefijo,NE_Numero,NE_CUNE,NE_FecEnvio
END
BEGIN --NOMINA 
	SELECT IdConcepto,Detalle,ISNULL(IdConcNE,IdConcepto) IdConcNE,Tarifa,SUM(ISNULL(CASE WHEN IdConcepto='VAC' THEN V.vrliquida WHEN IdConcepto='VCO' THEN VrRemndo ELSE VrTotDevg END,0)) VrTotDevg,
	SUM(N.VrTotDed) VrTotDed,SUM(CASE WHEN IdConcepto='VCO' THEN V.CantRem ELSE N.Cantidad END) Cantidad,HoraInicial,HoraFinal,FecInicioNov,FecFinalNov,N.NContrato,EsRetiro,
	V.FecIniPmd,V.FecFinPmd,ISNULL(CAST(V.DiasDom AS decimal(12,2)),0) DiasDom,ISNULL(CAST((V.DiasVac+v.DiasAjuste) AS decimal(12,2)),0) DiasVac
	FROM (SELECT N.IdEmpleado,N.NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,MAX(D.Tarifa) Tarifa,SUM(VrTotDevg) VrTotDevg,SUM(D.VrTotDed) VrTotDed
	, 
	CASE 
    WHEN ISNULL(dbo.Func180(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado),0) >= 180 and D.IdConcepto = 'IGE' THEN
	CASE 
		WHEN NC.IdConcepto = 'IGE' THEN 
			-- Comprobar que el mes de inicio sea igual al mes y la fecha de fin
			CASE 
				WHEN MONTH(dbo.FuncNovFechasIni(Detalle)) = MONTH(dbo.FuncNovFechasFin(Detalle)) THEN 		
					CASE 
						WHEN DAY(dbo.FuncNovFechasFin(Detalle)) = 31 THEN 31- DAY(dbo.FuncNovFechasIni(Detalle))
						WHEN (DATEDIFF(day, dbo.FuncNovFechasIni(Detalle), dbo.FuncNovFechasFin(Detalle)) + 1) > 30 THEN
							30
						ELSE
							(DATEDIFF(day, dbo.FuncNovFechasIni(Detalle), dbo.FuncNovFechasFin(Detalle)) + 1)
					END
				-- Comprobar que la fecha de inicio esté en el período de búsqueda 
				WHEN MONTH(dbo.FuncNovFechasIni(Detalle)) = CONVERT(INT, RIGHT(@IdPeriodo, 2)) THEN
					CASE 
						WHEN (30-(DAY(dbo.FuncNovFechasIni(Detalle))) +1) > 30 THEN
							30
						ELSE
						   (30-(DAY(dbo.FuncNovFechasIni(Detalle))) +1) 
					END
				-- Comprobar que la fecha de fin esté en el período de búsqueda
				WHEN MONTH(dbo.FuncNovFechasFin(Detalle)) = CONVERT(INT, RIGHT(@IdPeriodo, 2)) THEN
					CASE 
						WHEN DAY(dbo.FuncNovFechasFin(Detalle)) > 30 THEN
							30
						ELSE
						   DAY(dbo.FuncNovFechasFin(Detalle))
					END
					-- si no cumple ninguna de las anteriores condiciones el mes completo esta en incapacidad 
				ELSE
					30
			END
		END
    ELSE 
        SUM(
            CASE 
                WHEN NC.IdConcNE = 'LicenciaNR' THEN CantDed 
                ELSE CantDevg 
            END
        )
END AS Cantidad

					
	,HoraInicial,HoraFinal
	,CASE WHEN DAY(dbo.FuncNovFechasFin(Detalle)) = DAY(EOMONTH(dbo.FuncNovFechasFin(Detalle)))
	THEN CONVERT(DATE, DATEFROMPARTS(YEAR(dbo.FuncNovFechasFin(Detalle)), MONTH(dbo.FuncNovFechasFin(Detalle)), 30))
	ELSE CONVERT(DATE,dbo.FuncNovFechasFin(Detalle))
	END  AS FecFinalNov,
	CONVERT(date,dbo.FuncNovFechasIni(Detalle)) FecInicioNov, 
	--CONVERT(date,dbo.FuncNovFechasFin(Detalle)) FecFinalNov, 
	EsRetiro 
	FROM Trn_Nomina N 
	INNER JOIN Trn_NomDetalle D ON  N.KeyRegistro=D.KeyRegistro AND N.IdPeriodo=D.IdPeriodo
	INNER JOIN NomConceptos AS NC on D.IdConcepto = NC.Idconcepto	
	WHERE SUBSTRING(N.IdPeriodo,1,6) = @IdPeriodo AND N.IdEmpleado=@IdEmpleado AND ClaseLiq in ('NOMINA','NOVEDAD') and EsRetiro = 0 --and NC.Idconcepto='VAC'
	GROUP BY N.IdEmpleado,N.NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,HoraInicial,HoraFinal,EsRetiro,NC.IdConcepto,SUBSTRING(N.IdPeriodo,1,6)
	,CONVERT(date,dbo.FuncNovFechasIni(Detalle)), CONVERT(date,dbo.FuncNovFechasFin(Detalle))) N
	LEFT JOIN Trn_NomVac AS V ON V.IdEmpleado=N.IdEmpleado AND V.NContrato=N.NContrato AND CONVERT(date,dbo.FuncNovFechasIni(Detalle))=V.FecInicial AND CONVERT(date,dbo.FuncNovFechasFin(Detalle))=V.FecFinal AND V.Anulado=0
	GROUP BY IdConcepto,Detalle,ISNULL(IdConcNE,IdConcepto),Tarifa,ISNULL(CASE WHEN IdConcepto='VAC' THEN V.vrliquida WHEN IdConcepto='VCO' THEN VrRemndo ELSE VrTotDevg END,0),
	N.VrTotDed,HoraInicial,HoraFinal,FecInicioNov,FecFinalNov,N.NContrato,EsRetiro,
	V.FecIniPmd,V.FecFinPmd,ISNULL(CAST(V.DiasDom AS decimal(12,2)),0),ISNULL(CAST((V.DiasVac+v.DiasAjuste) AS decimal(12,2)),0)
END
BEGIN --LIQUIDACION DEFINITIVA
	SELECT IdConcepto,Detalle,ISNULL(IdConcNE,IdConcepto) IdConcNE,Tarifa,ISNULL(CASE WHEN IdConcepto='VAC' THEN (CASE WHEN VrTotDevg = 0 THEN (V.vrliquida/DiasVac) * L.Cantidad ELSE VrTotDevg END) WHEN IdConcepto='VCO' THEN VrRemndo ELSE VrTotDevg END,0) VrTotDevg,
	L.VrTotDed,L.Cantidad,HoraInicial,HoraFinal,FecInicioNov,FecFinalNov,L.NContrato,ClaseLiq,V.FecIniPmd,V.FecFinPmd,ISNULL(CAST(V.DiasDom AS decimal(12,2)),0) DiasDom,ISNULL(CAST((V.DiasVac+v.DiasAjuste) AS decimal(12,2)),0) DiasVac
	FROM (SELECT TNLD.IdEmpleado,LD.NContrato,TNLD.IdConcepto,Detalle,NC.IdConcNE,TNLD.Tarifa,TNLD.VrDevngado VrTotDevg,TNLD.VrDeducido VrTotDed,TNLD.Cantidad,null HoraInicial,null HoraFinal,
	CONVERT(date,dbo.FuncNovFechasIni(Detalle)) FecInicioNov, CONVERT(date,dbo.FuncNovFechasFin(Detalle)) FecFinalNov,TNLD.ClaseLiq
	FROM Trn_NomRetDet AS TNLD
	INNER JOIN Trn_nomret LD ON TNLD.IdEmpleado=LD.IdEmpleado AND TNLD.Numero=LD.Numero AND LD.ANULADO=0 AND TNLD.ClaseLiq IN ('LIQUDACION','NOMINA','NOVEDAD')
	INNER JOIN NomConceptos AS NC on TNLD.IdConcepto = NC.Idconcepto
	WHERE TNLD.IdEmpleado = ISNULL(@IdEmpleado, TNLD.IdEmpleado) AND  SUBSTRING(LD.IdPeriodo,1,6) = @IdPeriodo
	) L
	LEFT JOIN Trn_NomVac AS V ON V.IdEmpleado=L.IdEmpleado AND V.NContrato=L.NContrato AND CONVERT(date,dbo.FuncNovFechasIni(Detalle))=V.FecInicial AND CONVERT(date,dbo.FuncNovFechasFin(Detalle))=V.FecFinal AND V.Anulado=0
END
BEGIN --VACACIONES
	SELECT 
	DV.IdConcepto,DV.Detalle,ISNULL(NC.IdConcNE,DV.IdConcepto) IdConcNE,DV.VrDevgado AS VrTotDevg,
	CASE WHEN YEAR(V.FecInicial) = SUBSTRING(@IdPeriodo,1,4) AND RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2) = SUBSTRING(@IdPeriodo,5,2) THEN DV.VrDeducido ELSE 0 END AS VrTotDed,DV.Tarifa,
	V.FecIniciaL,V.FecFinal,CASE WHEN YEAR(V.FecInicial) = SUBSTRING(@IdPeriodo,1,4) AND RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2) = SUBSTRING(@IdPeriodo,5,2) THEN V.VrLiquida ELSE 0 END ValorVac,
	CASE WHEN @IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) THEN V.VrRemndo ELSE 0 END AS PagoCompensadas,
	CASE WHEN @IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) THEN V.CantRem ELSE 0 END AS CantVacCompensa
	FROM Trn_NomVac AS V
	LEFT JOIN Trn_NomVacDet DV ON V.IdEmpleado = DV.IdEmpleado AND V.Numero = DV.Numero AND 
	(@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) OR
	@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecFinal))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecFinal)))),2)))	
	INNER JOIN NomConceptos AS NC on DV.IdConcepto = NC.Idconcepto
	WHERE V.IdEmpleado = ISNULL(@IdEmpleado, V.IdEmpleado) AND 
	(@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) OR	@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecFinal))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecFinal)))),2)))
	AND V.Anulado=0 
END
BEGIN --LIQUIDACIONES DE PRESTACIONES
	SELECT L.IdConcepto,CASE WHEN L.IdConcepto = 'CES' THEN 'CESANTIAS' ELSE L.Detalle END Detalle,NC.IdConcNE,L.Tarifa,CAST(Cantidad AS decimal(18,2)) Cantidad,SUM(CASE WHEN L.IdConcepto = 'PRI' THEN L.VrLiquida ELSE (L.VrLiquida-L.VrParcial) END)  ValorPagado,L.Tarifa Porcentaje,SUM(VrDeducido) VrTotDed
	FROM Trn_NomLiqDet L
	INNER JOIN Trn_NomLiquida N ON L.TipoLiq=N.TipoLiq AND L.Numero=N.Numero
	INNER JOIN NomConceptos AS NC on L.IdConcepto = NC.Idconcepto
	WHERE IdEmpleado = ISNULL(@IdEmpleado, L.IdEmpleado) AND  (CONVERT(varchar(4), YEAR(CASE WHEN L.TipoLiq = 'PAR' THEN L.FecFinal ELSE L.FecFinal END))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(CASE WHEN L.TipoLiq = 'PAR' THEN L.FecFinal ELSE L.FecFinal END)))),2)) = @IdPeriodo AND (L.VrLiquida > 0 OR L.VrDeducido > 0) 
	AND N.Anulado=0 and (L.IdConcepto in ('CES','INT','PRI','RET'))
	GROUP BY L.IdConcepto,CASE WHEN L.IdConcepto = 'CES' THEN 'CESANTIAS' ELSE L.Detalle END,NC.IdConcNE,L.Tarifa,Cantidad,L.Tarifa
EXCEPT
SELECT 
	L.IdConcepto,CASE WHEN L.IdConcepto = 'CES' THEN 'CESANTIAS' ELSE L.Detalle END Detalle,NC.IdConcNE,L.Tarifa,CAST(Cantidad AS decimal(18,2)) Cantidad,SUM(CASE WHEN L.IdConcepto = 'PRI' THEN L.VrLiquida ELSE (L.VrLiquida-L.VrParcial) END)  ValorPagado,L.Tarifa Porcentaje,SUM(VrDeducido) VrTotDed
	FROM Trn_NomLiqDet L
	INNER JOIN NomConceptos AS NC on L.IdConcepto = NC.Idconcepto
	WHERE IdEmpleado = ISNULL(@IdEmpleado, L.IdEmpleado) AND  (CONVERT(varchar(4), YEAR(CASE WHEN L.TipoLiq = 'PAR' THEN L.FecFinal ELSE L.FecFinal END))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(CASE WHEN L.TipoLiq = 'PAR' THEN L.FecFinal ELSE L.FecFinal END)))),2)) = @IdPeriodo AND (L.VrLiquida > 0 OR L.VrDeducido > 0) 
	AND (L.IdConcepto = 'PRI' AND MONTH(L.FecFinal) IN (5,11))
	GROUP BY L.IdConcepto,CASE WHEN L.IdConcepto = 'CES' THEN 'CESANTIAS' ELSE L.Detalle END,NC.IdConcNE,L.Tarifa,Cantidad,L.Tarifa
END
BEGIN --VALIDACIONES
	SELECT 
	T.IdNom,t.TipoNomina,T.TipoLiquida,T.Asistencia,T.NomDiario,C.SalIntegral,C.IdCot,SUM(CASE WHEN ISNULL(l.Cerrado,0)= 0 THEN 0 ELSE 1 END) NomLiq,
	CAST(SUBSTRING(N.IdPeriodo,5,2) AS INT) mes, CAST((CASE WHEN ISNULL(dbo.Func180(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado),0) >= 180 THEN 1 ELSE 0 END) AS bit) D180,
	CASE WHEN(CASE WHEN T.TipoLiquida='M' AND  SUM(CASE WHEN ISNULL(l.Cerrado,0)= 0 THEN 0 ELSE 1 END) > 1 THEN 1 ELSE SUM(CASE WHEN ISNULL(l.Cerrado,0)= 0 THEN 0 ELSE 1 END) END)=dbo.FuncPeriodos(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado,C.NContrato) THEN CAST(1 as bit) ELSE CAST(1 as bit) END liquidar
	FROM Trn_Nomina N 
	INNER JOIN Emp_Contrato C ON C.IdEmpleado=N.IdEmpleado AND C.NContrato = N.NContrato --and N.EsRetiro=0
	INNER JOIN TiposNom T ON C.IdNom=T.IdNom
	LEFT JOIN Log_Nomina L  ON T.IdNom=L.IdNom AND L.IdPeriodo=N.IdPeriodo
	WHERE N.IdEmpleado=ISNULL(@IdEmpleado,N.IdEmpleado) AND ISNULL(SUBSTRING(N.IdPeriodo,1,6),@IdPeriodo) = @IdPeriodo
	GROUP BY N.IdEmpleado,SUBSTRING(N.IdPeriodo,1,6),T.IdNom,t.TipoNomina,T.TipoLiquida,T.Asistencia,T.NomDiario,C.SalIntegral,C.IdCot,CAST(SUBSTRING(N.IdPeriodo,5,2) AS INT),dbo.FuncPeriodos(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado,C.NContrato)
END
BEGIN --CONSOLIDADO DE VACACIONES
	SELECT 
	VrLiquida FROM Trn_NomLiqDet 
	WHERE 
	TipoLiq= 'VAC' and 
	IdEmpleado=@IdEmpleado and 
	year(fecFinal)=SUBSTRING(@IdPeriodo,1,4) and
	Numero = (select max(Numero) from Trn_NomLiqDet where TipoLiq= 'VAC' and IdEmpleado=@IdEmpleado and year(fecFinal)=SUBSTRING(@IdPeriodo,1,4)) and
	MONTH(fecFinal)=12
END
BEGIN --PROVISIONES MENSUALES
	SELECT MENSUAL.IdConcepto,MENSUAL.Detalle,MENSUAL.IdConcNE,MENSUAL.NContrato,MENSUAL.VrTotDevg,ISNULL(DIFERENCIAL.VrDebito,0) VrDebito,ISNULL(DIFERENCIAL.VrCredito,0) VrCredito
	FROM (
		--Consulta para calcular la provision Mensual 
		SELECT  IdEmpleado,Periodo,NContrato,IdConcepto,Detalle,IdConcNE,SUM(VrTotDevg) VrTotDevg,SUM(Cantidad) Cantidad FROM (
			--consulta de liquidacion de provisiones de nomina
			SELECT N.IdEmpleado,SUBSTRING(N.IdPeriodo,1,6) Periodo,max(N.NContrato) NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,SUM(D.VrTotDevg) VrTotDevg,SUM(CantDevg) Cantidad
			FROM Trn_Nomina N 
			INNER JOIN Trn_NomDetalle D ON  N.KeyRegistro=D.KeyRegistro AND N.IdPeriodo=D.IdPeriodo AND ClaseLiq = 'PROVISION'
			INNER JOIN NomConceptos AS NC on D.IdConcepto = NC.Idconcepto	
			WHERE SUBSTRING(N.IdPeriodo,1,6) = @IdPeriodo AND N.IdEmpleado=@IdEmpleado  and EsRetiro = 0 AND D.IdConcepto IN ('CES','INT','PRI','VAC')
			GROUP BY N.IdEmpleado,SUBSTRING(N.IdPeriodo,1,6),D.IdConcepto,D.Detalle,NC.IdConcNE,D.ClaseLiq
		UNION ALL
			--consulta de liquidacion de provisiones de liquidaciones definitivas
			SELECT TNLD.IdEmpleado,SUBSTRING(LD.IdPeriodo,1,6),LD.NContrato,TNLD.IdConcepto,Detalle,NC.IdConcNE,TNLD.VrDevngado VrTotDevg,TNLD.Cantidad
			FROM Trn_NomRetDet AS TNLD
			INNER JOIN Trn_nomret LD ON TNLD.IdEmpleado=LD.IdEmpleado AND TNLD.Numero=LD.Numero AND LD.ANULADO=0 AND TNLD.ClaseLiq = 'PROVISION'
			INNER JOIN NomConceptos AS NC on TNLD.IdConcepto = NC.Idconcepto
			WHERE TNLD.IdEmpleado = ISNULL(@IdEmpleado, TNLD.IdEmpleado) AND  SUBSTRING(LD.IdPeriodo,1,6) = @IdPeriodo
		UNION ALL
			--consulta para incluir dotacion
			SELECT D.IdEmpleado,CAST(YEAR(Fecha) AS varchar(4))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(Fecha)))),2),D.NContrato,'DOT','DOTACION','Dotación',SUM((D.Cantidad*D.VrUnitario)),SUM(D.Cantidad) 
			FROM Trn_NomDotacion N
			INNER JOIN Trn_NomDotacionDet D ON N.IdCia=D.IdCia AND N.Numero=D.Numero
			WHERE D.IdEmpleado=@IdEmpleado AND ANULADO=0 AND
			YEAR(Fecha) = SUBSTRING(@IdPeriodo,1,4) AND 
			MONTH(Fecha) = CAST(SUBSTRING(@IdPeriodo,5,2) AS INT)
			GROUP BY D.IdEmpleado,CAST(YEAR(Fecha) AS varchar(4))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(Fecha)))),2),D.NContrato
			) MENSUAL
			GROUP BY IdEmpleado,Periodo,NContrato,IdConcepto,Detalle,IdConcNE
		) MENSUAL
		LEFT JOIN 
		(SELECT DD.IdEmpleado,SUBSTRING(D.IdPeriodo,1,6) Periodo,DD.NContrato,IdConcepto,DD.VrDebito,dd.VrCredito from Trn_NomProvAju D 
		LEFT JOIN Trn_NomProvAjuDet DD on D.TipDoc=DD.TipDoc and D.NumAjuste=DD.NumAjuste and D.IdCia=DD.IdCia
		where DD.IdEmpleado=@IdEmpleado AND	SUBSTRING(D.IdPeriodo,1,6) = @IdPeriodo AND D.ANULADO=0
		) DIFERENCIAL ON 
		MENSUAL.IdEmpleado=DIFERENCIAL.IdEmpleado AND MENSUAL.Periodo=DIFERENCIAL.Periodo AND MENSUAL.NContrato=DIFERENCIAL.NContrato AND MENSUAL.IdConcepto=DIFERENCIAL.IdConcepto
END
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaElectronicaAjuste]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[paQryNominaElectronicaAjuste] 
	 --Add the parameters for the stored procedure here
		@TipNota VARCHAR(3),
		@NroNota INT,
		@IdCia CHAR(2),
		@IdEmpleado  varchar(16) = NULL,
		@IdPeriodo varchar(6) = NULL,
		@fecIni date = null,
		@fecFIn date = null
AS
BEGIN --INFORMACION NOMINA DEL EMPLEADO	
	SELECT @IdPeriodo = SUBSTRING(IdPeriodo,1,6),@IdEmpleado=IdEmpleado FROM Trn_NomAjustes WHERE TipNota = @TipNota AND NumNota = @NroNota AND IdCia = @IdCia
	SELECT 
	--PERIODO
	SUBSTRING(N.IdPeriodo,1,6) IdPeriodo,N.NumNota,MIN(N.FechaInicial) FecInicial,MAX(N.FechaFinal) FecFinal,DATEDIFF(D,MIN(N.FechaInicial),MAX(N.FechaFinal))+(case when day(MAX(N.FechaFinal))=31 then 0 else 1 end) DiasTrabajados
	,(CASE WHEN DAY(MAX(N.FechaInicial)) > 30 THEN 30 ELSE DAY(MAX(N.FechaFinal)) END-CASE WHEN DAY(EC.FecIngreso) > 30 THEN 30 ELSE DAY(EC.FecIngreso) END+1+DATEDIFF(MONTH, EC.FecIngreso, MAX(N.FechaFinal))*30) TiempoLaborado
	--DATOS EMPLEADO
	,EM.TipoId TipoDocumento,EM.Apellidos ApellidosTrabajador,EM.Nombres NombresTrabajador,N.IdEmpleado,EC.FecIngreso,EC.FecRetiro
	,EC.IdCot TipoTrabajador,CASE WHEN EC.IdGrupo <> 0 THEN 1 ELSE 0 END AltoRiesgoPension,Ap.CodISO LugarTrabajoPais,DEP.IdDep LugarTrabajoDepartamento
	,INS.CodCiu LugarTrabajoMunicipioCiudad,INS.DirInstala LugarTrabajoDireccion,EC.SalIntegral SalarioIntegral,TC.CodDIAN TipoContrato,EC.VrSalario Sueldo
	,EC.IdMedPago MetodoPago,B.Banco,CL.ClaseCuenta,EM.NumCuenta
	----DATOS EMPLEADOR
	,TNOM.CdCiaInt Prefijo,TE.TipoId TipoIdEmpleador,TE.IdTercero NitEmpleador
	----ENVIO DIAN
	,NA_Prefijo,NA_Numero,NA_CUNE,NA_FecEnvio,NE_Prefijo,NE_Numero,NE_CUNE,FechaCrea
	FROM Trn_NomAjustes N
	INNER JOIN Emp_Contrato EC on N.IdEmpleado=EC.IdEmpleado AND N.NContrato = EC.NContrato
	INNER JOIN TiposNom TNOM on TNOM.IdNom=N.IdNom
	INNER JOIN Adm_Registro AR on AR.IdCia=(SELECT TOP 1 IdCia FROM Adm_Registro)
	INNER JOIN Terceros TE on TE.IdTercero=AR.IdEmpresa
	INNER JOIN Empleados as EM on EC.IdEmpleado=EM.IdEmpleado
	INNER JOIN Instalaciones as INS on INS.IdInstala=EC.IdInstala
	INNER JOIN Departamentos as DEP on DEP.IdDep=SUBSTRING(INS.CodCiu,0,3)
	INNER JOIN Adm_Paises as AP on AP.IdPais=DEP.IdPais
	INNER JOIN ClaseCta AS CL on EM.IdClase = CL.IdClase
	LEFT JOIN TiposCon AS TC on EC.IdTipCon = TC.IdTipCon
	LEFT JOIN Bancos AS B on EM.IdBanco = B.IdBanco
	WHERE N.TipNota = @TipNota AND N.NumNota = @NroNota AND N.IdCia = @IdCia
	GROUP BY SUBSTRING(N.IdPeriodo,1,6),N.NumNota,EC.FecIngreso,EM.TipoId,EM.Apellidos,EM.Nombres,N.IdEmpleado,EC.FecIngreso,EC.FecRetiro,EC.IdCot
	,EC.IdGrupo,Ap.CodISO,DEP.IdDep,INS.CodCiu,INS.DirInstala,EC.SalIntegral,TC.CodDIAN,EC.VrSalario,EC.IdMedPago,B.Banco,CL.ClaseCuenta,EM.NumCuenta
	,TNOM.CdCiaInt,TE.TipoId,TE.IdTercero,NA_Prefijo,NA_Numero,NA_CUNE,NA_FecEnvio,NE_Prefijo,NE_Numero,NE_CUNE,FechaCrea
END
BEGIN --AJUSTE 
	SELECT IdConcepto,Detalle,CASE WHEN ISNULL(IdConcNE,IdConcepto) = '' THEN IdConcepto ELSE ISNULL(IdConcNE,IdConcepto) END IdConcNE,Tarifa,
	ISNULL((CASE WHEN IdConcepto='VAC' THEN (case when V.vrliquida is null then VrTotDevg else V.vrliquida end) WHEN IdConcepto='VCO' THEN VrRemndo ELSE VrTotDevg END),0) VrTotDevg,N.VrTotDed,
	N.Cantidad,HoraInicial,HoraFinal,FecInicioNov,FecFinalNov,ClaseLiq,N.NContrato,V.FecIniPmd,V.FecFinPmd,ISNULL(CAST(V.DiasDom AS decimal(12,2)),0) DiasDom,ISNULL(CAST(V.DiasVac AS decimal(12,2)),0) DiasVac
	FROM (SELECT DISTINCT N.IdEmpleado,N.NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,MAX(D.Tarifa) Tarifa,SUM(VrTotDevg) VrTotDevg,SUM(D.VrTotDed) VrTotDed
	-- se modifica para hacer el calculo sin inferir en el calculo de syscom sino de la incapacidad
	,CASE 
    WHEN ISNULL(dbo.Func180(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado),0) >= 180 and D.IdConcepto = 'IGE' THEN
	CASE 
		WHEN NC.IdConcepto = 'IGE' THEN 
			-- Comprobar que el mes de inicio sea igual al mes y la fecha de fin
			CASE 
				WHEN MONTH(dbo.FuncNovFechasIni(Detalle)) = MONTH(dbo.FuncNovFechasFin(Detalle)) THEN 		
					CASE 
						WHEN DAY(dbo.FuncNovFechasFin(Detalle)) = 31 THEN 31- DAY(dbo.FuncNovFechasIni(Detalle))
						WHEN (DATEDIFF(day, dbo.FuncNovFechasIni(Detalle), dbo.FuncNovFechasFin(Detalle)) + 1) > 30 THEN
							30
						ELSE
							(DATEDIFF(day, dbo.FuncNovFechasIni(Detalle), dbo.FuncNovFechasFin(Detalle)) + 1)
					END
				-- Comprobar que la fecha de inicio esté en el período de búsqueda 
				WHEN MONTH(dbo.FuncNovFechasIni(Detalle)) = CONVERT(INT, RIGHT(@IdPeriodo, 2)) THEN
					CASE 
						WHEN (30-(DAY(dbo.FuncNovFechasIni(Detalle))) +1) > 30 THEN
							30
						ELSE
						   (30-(DAY(dbo.FuncNovFechasIni(Detalle))) +1) 
					END
				-- Comprobar que la fecha de fin esté en el período de búsqueda
				WHEN MONTH(dbo.FuncNovFechasFin(Detalle)) = CONVERT(INT, RIGHT(@IdPeriodo, 2)) THEN
					CASE 
						WHEN DAY(dbo.FuncNovFechasFin(Detalle)) > 30 THEN
							30
						ELSE
						   DAY(dbo.FuncNovFechasFin(Detalle))
					END
					-- si no cumple ninguna de las anteriores condiciones el mes completo esta en incapacidad 
				ELSE
					30
			END
		END
    ELSE 
        SUM(
            CASE 
                WHEN NC.IdConcNE = 'LicenciaNR' THEN CantDed 
                ELSE CantDevg 
            END
        )
END AS Cantidad	
	,null HoraInicial, null HoraFinal
	,CONVERT(date,dbo.FuncNovFechasIni(Detalle)) FecInicioNov, CONVERT(date,dbo.FuncNovFechasFin(Detalle)) FecFinalNov,ClaseLiq
	FROM Trn_NomAjustes N 
	INNER JOIN Trn_NomAjustesDet D ON N.TipNota=D.TipNota and N.NumNota=D.NumNota and N.IdCia=D.IdCia
	INNER JOIN NomConceptos AS NC on D.IdConcepto = NC.Idconcepto	
	WHERE N.TipNota = @TipNota AND N.NumNota = @NroNota AND N.IdCia = @IdCia AND ClaseLiq in ('NOMINA','NOVEDAD','LIQUDACION')
	--WHERE SUBSTRING(N.IdPeriodo,1,6) = @IdPeriodo AND N.IdEmpleado=@IdEmpleado AND ClaseLiq in ('NOMINA','NOVEDAD') AND N.NumNota=@Nota --and EsRetiro =0 
	GROUP BY N.IdEmpleado,N.NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,NC.IdConcepto,N.IdPeriodo
	,CONVERT(date,dbo.FuncNovFechasIni(Detalle)), CONVERT(date,dbo.FuncNovFechasFin(Detalle)),ClaseLiq) N
	LEFT JOIN Trn_NomVac AS V ON V.IdEmpleado=N.IdEmpleado AND V.NContrato=N.NContrato AND CONVERT(date,dbo.FuncNovFechasIni(Detalle))=V.FecInicial AND CONVERT(date,dbo.FuncNovFechasFin(Detalle))=V.FecFinal AND V.Anulado=0
END
BEGIN --VACACIONES
	SELECT 
	DV.IdConcepto,DV.Detalle,NC.IdConcNE,DV.VrDevgado AS VrTotDevg,
	CASE WHEN YEAR(V.FecInicial) = SUBSTRING(@IdPeriodo,1,4) AND RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2) = SUBSTRING(@IdPeriodo,5,2) THEN DV.VrDeducido ELSE 0 END AS VrTotDed,DV.Tarifa,
	V.FecIniciaL,V.FecFinal,CASE WHEN YEAR(V.FecInicial) = SUBSTRING(@IdPeriodo,1,4) AND RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2) = SUBSTRING(@IdPeriodo,5,2) THEN V.VrLiquida ELSE 0 END ValorVac,
	CASE WHEN @IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) THEN V.VrRemndo ELSE 0 END AS PagoCompensadas,
	CASE WHEN @IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) THEN V.CantRem ELSE 0 END AS CantVacCompensa
	FROM Trn_NomVac AS V
	LEFT JOIN Trn_NomVacDet DV ON V.IdEmpleado = DV.IdEmpleado AND V.Numero = DV.Numero AND 
	(@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) OR
	@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecFinal))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecFinal)))),2)))	
	INNER JOIN NomConceptos AS NC on DV.IdConcepto = NC.Idconcepto
	WHERE V.IdEmpleado = ISNULL(@IdEmpleado, V.IdEmpleado) AND 
	(@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecIniciaL))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecIniciaL)))),2)) OR	@IdPeriodo=(CONVERT(VARCHAR(4),YEAR(V.FecFinal))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(V.FecFinal)))),2)))
	AND V.Anulado=0 
END
BEGIN --VALIDACIONES
	SELECT 
	T.IdNom,t.TipoNomina,T.TipoLiquida,T.Asistencia,T.NomDiario,C.SalIntegral,C.IdCot,SUM(CASE WHEN ISNULL(l.Cerrado,0)= 0 THEN 0 ELSE 1 END) NomLiq,
	CAST(SUBSTRING(N.IdPeriodo,5,2) AS INT) mes,CAST((CASE WHEN ISNULL(dbo.Func180(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado),0) >= 180 THEN 1 ELSE 0 END) AS bit) D180,
	CASE WHEN(CASE WHEN T.TipoLiquida='M' AND  SUM(CASE WHEN ISNULL(l.Cerrado,0)= 0 THEN 0 ELSE 1 END) > 1 THEN 1 ELSE SUM(CASE WHEN ISNULL(l.Cerrado,0)= 0 THEN 0 ELSE 1 END) END)=dbo.FuncPeriodos(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado,C.NContrato) THEN CAST(1 as bit) ELSE CAST(1 as bit) END liquidar
	FROM Trn_Nomina N 
	INNER JOIN Emp_Contrato C ON C.IdEmpleado=N.IdEmpleado AND C.NContrato = N.NContrato --and N.EsRetiro=0
	INNER JOIN TiposNom T ON C.IdNom=T.IdNom
	LEFT JOIN Log_Nomina L  ON T.IdNom=L.IdNom AND L.IdPeriodo=N.IdPeriodo
	WHERE N.IdEmpleado=ISNULL(@IdEmpleado,N.IdEmpleado) AND ISNULL(SUBSTRING(N.IdPeriodo,1,6),@IdPeriodo) = @IdPeriodo
	GROUP BY N.IdEmpleado,SUBSTRING(N.IdPeriodo,1,6),T.IdNom,t.TipoNomina,T.TipoLiquida,T.Asistencia,T.NomDiario,C.SalIntegral,C.IdCot,CAST(SUBSTRING(N.IdPeriodo,5,2) AS INT),dbo.FuncPeriodos(SUBSTRING(N.IdPeriodo,1,6),N.IdEmpleado,C.NContrato)
END
BEGIN --CONSOLIDADO DE VACACIONES
	SELECT 
	VrLiquida FROM Trn_NomLiqDet 
	WHERE 
	TipoLiq= 'VAC' and 
	IdEmpleado=@IdEmpleado and 
	year(fecFinal)=SUBSTRING(@IdPeriodo,1,4) and
	Numero = (select max(Numero) from Trn_NomLiqDet where TipoLiq= 'VAC' and IdEmpleado=@IdEmpleado and year(fecFinal)=SUBSTRING(@IdPeriodo,1,4)) and
	MONTH(fecFinal)=12
END
BEGIN --PROVISIONES MENSUALES
	--Consulta para calcular fecha inicio y fin de un periodo de vacaciones si hay liquidación de vacaciones en el periodo consultado
	select MENSUAL.IdConcepto,MENSUAL.Detalle,MENSUAL.IdConcNE,MENSUAL.NContrato,MENSUAL.VrTotDevg,ISNULL(DIFERENCIAL.VrDebito,0) VrDebito,ISNULL(DIFERENCIAL.VrCredito,0) VrCredito
		FROM (
		SELECT  IdEmpleado,Periodo,NContrato,IdConcepto,Detalle,IdConcNE,SUM(VrTotDevg) VrTotDevg,SUM(Cantidad) Cantidad FROM (
			--consulta de liquidacion de provisiones de nomina
			SELECT N.IdEmpleado,SUBSTRING(N.IdPeriodo,1,6) Periodo,N.NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,SUM(D.VrTotDevg) VrTotDevg,SUM(CantDevg) Cantidad
			FROM Trn_NomAjustes N 
			INNER JOIN Trn_NomAjustesDet D ON  N.TipNota=D.TipNota and N.NumNota=D.NumNota and N.IdCia=D.IdCia AND ClaseLiq = 'PROVISION'
			INNER JOIN NomConceptos AS NC on D.IdConcepto = NC.Idconcepto	
			WHERE N.TipNota = @TipNota AND N.NumNota = @NroNota AND N.IdCia = @IdCia AND D.IdConcepto IN ('CES','INT','PRI','VAC')
			GROUP BY N.IdEmpleado,SUBSTRING(N.IdPeriodo,1,6),N.NContrato,D.IdConcepto,D.Detalle,NC.IdConcNE,D.ClaseLiq
		UNION 
			--consulta para incluir dotacion
			SELECT D.IdEmpleado,CAST(YEAR(Fecha) AS varchar(4))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(Fecha)))),2),D.NContrato,'DOT','DOTACION','Dotación',SUM((D.Cantidad*D.VrUnitario)),SUM(D.Cantidad) 
			FROM Trn_NomDotacion N
			INNER JOIN Trn_NomDotacionDet D ON N.IdCia=D.IdCia AND N.Numero=D.Numero
			WHERE D.IdEmpleado=@IdEmpleado AND ANULADO=0 AND
			YEAR(Fecha) = SUBSTRING(@IdPeriodo,1,4) AND 
			MONTH(Fecha) = CAST(SUBSTRING(@IdPeriodo,5,2) AS INT)
			GROUP BY D.IdEmpleado,CAST(YEAR(Fecha) AS varchar(4))+RIGHT('00' + Ltrim(Rtrim(CONVERT(varchar(2), MONTH(Fecha)))),2),D.NContrato
			) MENSUAL
			GROUP BY IdEmpleado,Periodo,NContrato,IdConcepto,Detalle,IdConcNE
		) MENSUAL
		LEFT JOIN 
		(SELECT DD.IdEmpleado,SUBSTRING(D.IdPeriodo,1,6) Periodo,DD.NContrato,IdConcepto,DD.VrDebito,dd.VrCredito from Trn_NomProvAju D 
		LEFT JOIN Trn_NomProvAjuDet DD on D.TipDoc=DD.TipDoc and D.NumAjuste=DD.NumAjuste and D.IdCia=DD.IdCia
		where DD.IdEmpleado=@IdEmpleado AND	SUBSTRING(D.IdPeriodo,1,6) = @IdPeriodo AND D.ANULADO=0
		) DIFERENCIAL ON 
		MENSUAL.IdEmpleado=DIFERENCIAL.IdEmpleado AND MENSUAL.Periodo=DIFERENCIAL.Periodo AND MENSUAL.NContrato=DIFERENCIAL.NContrato AND MENSUAL.IdConcepto=DIFERENCIAL.IdConcepto
END
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaGcon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaGcon]  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT N.IdPeriodo AS NumPdo,N.KeyRegistro AS KeyReg,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,ClaseLiq
 ,SUM(CantDevg) AS SCantDev,SUM(VrTotDevg) AS STotDev,SUM(CantDed) AS SCantDed,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS STotBase
,SUM(DiasCalc-DiasNov) AS TotalDias,SUM(VrBaseLiq) AS STotLiq
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE'  AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%')
 AND N.IdNom like ISNULL(@pmIdNom,'%')  AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY N.IdPeriodo,N.KeyRegistro,N.IdEmpleado,Apellidos,Nombres,D.IdConcepto,Concepto,ClaseCon,ClaseLiq
 ORDER BY N.IdPeriodo,N.KeyRegistro,N.IdEmpleado,D.IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaIng]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaIng] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null
AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContto,SUBSTRING(N.IdPeriodo,1,6) AS Nmes,N.IdDep AS CodDep,N.IdInstala AS CodInstala
,N.IdCCosto AS CodCcto,N.IdSubCos AS CodSubcc,N.IdNom AS CodNom,N.pVehiculo AS PlacaVeh,N.VrSalario AS Salbasico,NLiqRet,TipoLiq,IdArea,IdTipCon
,D.IdConcepto AS CodConcepto,Concepto,ClaseLiq,SUM(Cantidad) AS Scant,SUM(CantNoRem) AS SCanNoRem,SUM(VrBaseLiq) AS SbaseLiq
,SUM(CantDevg) AS SCanDev,SUM(CantDed) AS SCanDed,SUM(VrTotDevg) AS STotDev,SUM(VrTotDed) AS STotDed,SUM(VrOrigen) AS SValBase,MAX(D.Tarifa) AS Tarfa
,SUM(DiasCalc) AS SDiasCalc, SUM(DiasNov) AS SDiasNov,SUM(DiasCalc-DiasNov) AS DiasNeto
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin  AND ClaseLiq IN ('NOMINA','NOVEDAD','LIQUDACION')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')   AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 GROUP BY N.IdEmpleado,Apellidos,Nombres,N.NContrato,SUBSTRING(N.IdPeriodo,1,6),N.IdDep,N.IdInstala,N.IdCCosto,N.IdSubCos
,N.IdNom,N.pVehiculo,N.VrSalario,NLiqRet,TipoLiq,IdArea,IdTipCon,D.IdConcepto,Concepto,ClaseLiq
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaInt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaInt] @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4),@pmEsRetiro BIT=Null
 AS 
 SELECT N.IdPeriodo AS IdPdo,N.KeyRegistro AS IdKeyReg,N.IdEmpleado AS IdEmpldo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido,N.NContrato AS NCntto,N.IdDep,N.IdInstala,N.IdCCosto
,N.IdSubCos,N.IdNom,N.VrSalario,N.pVehiculo AS PlacaVeh,N.TipCom,N.Comprobante,N.IdCiaCom,EsRetiro,NLiqRet,TipoLiq,Apellidos,Nombres,EsCondtor,E.pVehiculo AS VehiculoDef
,DenyCes,DenyPri,DenyVac
--detalle de la nomina
,Item,D.IdConcepto AS IdConcep,Detalle,CantDevg,CantDed,VrUnitario,VrTotDevg,VrTotDed,ClaseLiq,VrOrigen,D.Tarifa AS Tarfa,DiasCalc,DiasNov,CodFondo,NPrestamo,NCuota,OrigCargue,VrBaseLiq,NitTercero
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D  ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN NomConceptos AS C ON D.IdConcepto=C.IdConcepto
 LEFT JOIN Emp_Contrato AS CN ON N.NContrato=CN.NContrato AND N.IdEmpleado=CN.IdEmpleado
 WHERE N.IdPeriodo=@pmIdPeriodo AND N.IdNom like ISNULL(@pmIdNom,'%')
 AND  (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY N.IdEmpleado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaNov] @pmMes VARCHAR(6),@pmIdPeriodo VARCHAR(8)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmEsRetiro BIT=Null,@pmIdConcepto VARCHAR(4)=Null
AS 
 SELECT N.IdEmpleado AS IdEmpldo,IdConcepto, SUM(CantDevg) AS SCantDev,SUM(CantDed) AS SCantDed
,SUM(VrTotDevg) AS SValDev,SUM(VrTotDed) AS SValDed,SUM(VrOrigen) AS SValBase,SUM(VrBaseLiq) AS SValLiquida
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND NLiqRet>=0 AND IdConcepto IN ('IGE','IRP','LIC') AND ClaseLiq='NOVEDAD'
 AND N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY N.IdEmpleado,IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaPag]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNominaPag]  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,Item,D.IdConcepto AS CodConcepto,Detalle,ClaseCon,CantDevg,D.Unidad AS Undad,VrUnitario,VrTotDevg,CantDed,VrTotDed,NPrestamo,NCuota
,VrOrigen,D.Tarifa AS TarifaBase,DiasCalc,DiasNov,DiasCalc-DiasNov AS TotalDias,CodFondo,FD.Fondo AS Det_Fondo,ClaseLiq,OrigCargue,Concepto,VrBaseLiq
,N.IdPeriodo AS IdPerdo,FecInicial,FecFinal,N.KeyRegistro AS KeyRegstro
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE' AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%')
 AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND N.IdNom like ISNULL(@pmIdNom,'%')  AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 ORDER BY Apellidos,Nombres,N.IdPeriodo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaRes] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumCntrato,KeyRegistro,IdPeriodo,FecInicial,FecFinal,Cantidad,CantNoRem,VrDevengado,VrDeducido
,N.IdNom AS CodNmna,TipoNomina,N.IdDep AS CodDep,Dependencia,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcos,SubCosto,N.IdInstala AS CodIstala,Instlacion
,N.VrSalario AS SalBasico,N.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS IdEstdo,ED.Estado AS Nom_Estado,EsRetiro,NLiqRet,TipoLiq,TimeSys
,N.FecUpdate AS Fec_Update,N.IdUsuario AS IdUsuari,Usuario
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,FC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS VlrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj,C.IdGrupo AS CodGrup
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN Dependencias AS D ON N.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala  INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom 
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY  N.IdEmpleado,IdPeriodo
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaRst]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaRst] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT N.IdEmpleado,Apellidos,Nombres,DATEDIFF(YEAR,E.FecNacmto,GETDATE()) AS Edad,E.Sexo,N.NContrato,N.IdNom,TipoNomina,ISNULL(D.HoraInicial,N.FecFinal) AS Fecha,N.IdPeriodo
,D.IdConcepto,CN.Concepto,ISNULL(D.HoraInicial,N.FecFinal) AS Hora_Inicial,ISNULL(D.HoraFinal,N.FecFinal) AS Fec_Final
,D.CantDevg AS CantHoras,D.VrUnitario,D.VrTotDevg AS VrLiquidado,D.VrOrigen AS BaseLiq,D.Tarifa,C.IdCargo,Cargo,D.Detalle,D.ClaseLiq,D.OrigCargue,CN.Unidad
,CN.Tarifa AS ConcTarifa,N.VrSalario,C.IdArea,Area,C.IdDep,Dependencia,C.IdInstala,Instlacion,C.IdCia,Compania,C.IdCCosto,CCosto,C.IdSubCos,SubCosto
FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro AND N.IdEmpleado=D.IdEmpleado
INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
INNER JOIN Instalaciones AS IST ON C.IdInstala=IST.IdInstala INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos 
WHERE (N.IdPeriodo=@pmIdPeriodo OR @pmIdPeriodo IS NULL) AND (N.IdEmpleado=@pmIdEmpleado OR @pmIdEmpleado IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaRtot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaRtot] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdPeriodo VARCHAR(8)=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto  VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
 AS 
 SELECT SUM(Cantidad) AS SCant,SUM(VrDevengado) AS TotalDev,SUM(VrDeducido) AS TotalDed,SUM(N.VrSalario) AS ToalSalBasico,SUM(VrAuxTrans) AS TotalAuxtrans
 FROM Trn_Nomina AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 WHERE FecInicial>=@pmFecIni  AND FecFinal<=@pmFecFin AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  AND  IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND (N.NContrato>=ISNULL(@pmNContrato,0)  AND N.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-2)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaTEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNominaTEmp]  @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmEsRetiro BIT=Null,@pmNLiqRet INT=Null
 AS 
 SELECT  Apellidos,Nombres,N.IdEmpleado AS IdEmpldo,N.NContrato AS NumContrato,sum(VrTotDevg) AS VrTotalDevg,sum(VrTotDed) AS VrTotalDed,sum(VrBaseLiq) AS VrTotOtros
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE ClaseLiq<>'PROVISION' AND ClaseLiq<>'APORTE' AND  N.IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%')  AND N.KeyRegistro LIKE ISNULL(@pmKeyRegistro,'%') 
 AND SUBSTRING(N.IdPeriodo,1,6)=@pmMes
 AND N.IdNom like ISNULL(@pmIdNom,'%') AND  N.IdDep LIKE ISNULL(@pmIdDep,'%') AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%') AND N.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND (NLiqRet>=ISNULL(@pmNLiqRet,-1)  AND NLiqRet<=ISNULL(@pmNLiqRet,2147483647))
 AND (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
 GROUP BY Apellidos,Nombres,N.IdEmpleado,N.NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaVeha]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaVeha] @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
 AS 
 SELECT N.pVehiculo AS PlacaVeh,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdCCosto AS CdCcosto,E.pVehiculo AS Emp_Veh,TipoLiq
,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 WHERE N.IdPeriodo=@pmIdPeriodo AND FPnomina='OTRO' AND EsCondtor<>0 AND ClaseLiq IN ('NOMINA','NOVEDAD')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 GROUP BY   N.pVehiculo,N.IdEmpleado,Apellidos,Nombres,N.NContrato,N.IdCCosto,E.pVehiculo,TipoLiq
 ORDER BY  N.pVehiculo,N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNominaVehc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNominaVehc] @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
 AS 
 SELECT N.pVehiculo AS PlacaVeh,N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.NContrato AS NumContrato,N.IdCCosto AS CdCcosto,E.pVehiculo AS Emp_Veh,TipoLiq
,ClaseLiq,SUM(VrTotDevg) AS STOTDEV,SUM(VrTotDed) AS STOTDED,SUM(VrOrigen) AS SVALBAS
 FROM Trn_Nomina AS N INNER JOIN Trn_NomDetalle AS D ON N.IdPeriodo=D.IdPeriodo AND N.KeyRegistro=D.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 WHERE N.IdPeriodo=@pmIdPeriodo AND TipoTrabj=3 AND EsCondtor<>0 AND ClaseLiq IN ('NOMINA','NOVEDAD','PROVISION','APORTE')
 AND N.IdNom LIKE ISNULL(@pmIdNom,'%') AND N.IdDep LIKE ISNULL(@pmIdDep,'%')
 GROUP BY   N.pVehiculo,N.IdEmpleado,Apellidos,Nombres,N.NContrato,N.IdCCosto,E.pVehiculo,TipoLiq,ClaseLiq
 ORDER BY  N.pVehiculo,N.IdEmpleado,ClaseLiq
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiqDet] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmItem INT
 AS 
 SELECT TipoLiq,Numero,Item,IdConcepto,Detalle,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd
,FecFinPmd,DiasBase,DiasNoRem,Tarifa,NPrestamo,NCuota,LogPmdio,IdEmpleado,NContrato,pVehiculo,IdDep
,IdCCosto,IdSubCos,IdNom,VrSalario,VrParcial,NitTercero
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDet_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiqDet_Cr]  @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNumero INT=Null
,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmSemstre INT=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT Q.TipoLiq AS Tip_Liqda,Q.Numero AS NumLiquida,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,Anulado,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--detalle de liquidaicion
,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.NContrato AS NumContrato,D.pVehiculo AS PlacaVeh,D.IdDep AS CodDep,Dependencia,D.IdCCosto AS CodCcto,CCosto,D.IdSubCos AS CodSubcen,SubCosto,D.IdNom AS CodNom,TipoNomina,D.VrSalario AS Liq_SalBasico
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,D.Tarifa AS Tarfa,NPrestamo,NCuota,LogPmdio,Unidad
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps
,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.IdJornada AS CodJnada,Jornada,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,TipoTrabj
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModPromdio,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,VrParcial
 FROM Trn_NomLiquida AS Q INNER JOIN Trn_NomLiqDet AS D ON Q.TipoLiq=D.TipoLiq AND Q.Numero=D.Numero
 INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN Dependencias AS DP ON D.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON D.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON D.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom 
 WHERE Q.TipoLiq=@pmTipoLiq  AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND D.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND Q.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Q.Numero>=ISNULL(@pmNumero,0)  AND Q.Numero<=ISNULL(@pmNumero,2147483647))
 AND (Semstre >=ISNULL(@pmSemstre ,0)  AND Semstre <=ISNULL(@pmSemstre,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (D.NContrato >=ISNULL(@pmNContrato ,0)  AND D.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY Q.Numero,Apellidos,Nombres,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDetEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiqDetEmp] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT IdEmpleado,NContrato,FecUltLiq,FecInicial,FecFinal, COUNT(Item) AS SITEM,SUM(VrLiquida) AS SValLiq,SUM(VrDeducido) AS SValDed
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 GROUP BY  IdEmpleado,NContrato,FecUltLiq,FecInicial,FecFinal
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDetTEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiqDetTEmp] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdEmpleado VARCHAR(16)
,@pmNContrato INT
 AS 
 SELECT SUM(VrBase) AS SBASE,SUM(Cantidad) AS SCANT,SUM(VrLiquida) AS STOTLIQ,SUM(VrDeducido) AS STOTDED
 FROM Trn_NomLiqDet
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND IdEmpleado=@pmIdEmpleado AND NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiqDetTnm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiqDetTnm]  @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdNom VARCHAR(4)=Null
AS
 SELECT D.IdNom AS CodNom,TipoNomina,TipoLiquida,COUNT(Item) AS SITEM
 FROM Trn_NomLiqDet  AS D INNER JOIN TiposNom AS T ON D.IdNom=T.IdNom
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 GROUP BY D.IdNom,TipoNomina,TipoLiquida
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquida]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomLiquida] @pmTipoLiq VARCHAR(3),@pmNumero INT
 AS 
 SELECT TipoLiq,Numero,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquida_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquida_Cr] @pmTipoLiq VARCHAR(3),@pmNumero INT=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdNom VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 SELECT Q.TipoLiq AS Tip_Liqda,Q.Numero AS NumLiquida,Fecha,Semstre,VrTotal,VrTotDed,VrAplicado,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,Anulado,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--detalle de liquidaicion
,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.NContrato AS NumContrato,D.pVehiculo AS PlacaVeh,D.IdDep AS CodDep,Dependencia,D.IdCCosto AS CodCcto,CCosto,D.IdSubCos AS CodSubcen,SubCosto,D.IdNom AS CodNom,TipoNomina,D.VrSalario AS Liq_SalBasico
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,FecUltLiq,FecInicial,FecFinal,VrBase,Cantidad,VrLiquida,VrDeducido,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,D.Tarifa AS Tarfa,NPrestamo,NCuota,LogPmdio,Unidad
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,FecUltCes,FecUltPri,FecUltVac,NumVeh,TipoAdmon,VehPropio,VrParcial
 FROM Trn_NomLiquida AS Q INNER JOIN Trn_NomLiqDet AS D ON Q.TipoLiq=D.TipoLiq AND Q.Numero=D.Numero
 INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN Dependencias AS DP ON D.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON D.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON D.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom LEFT JOIN NomVehiculos AS VH ON D.pVehiculo=VH.IdVehiculo
 WHERE Q.TipoLiq=@pmTipoLiq 
 AND (Q.Numero>=ISNULL(@pmNumero,0)  AND Q.Numero<=ISNULL(@pmNumero,2147483647))
 AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND D.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Q.Numero,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaBan] @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
AS
SELECT L.TipoLiq AS Tliq,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,e_mail,Telefono,D.NContrato AS NumContrato,IdConcepto
,E.Direccion AS EmpDireccion,TelMovil,Cargo 
,SUM(VrLiquida) AS STOTLIQ,SUM(VrDeducido) AS STOTDED,SUM(VrParcial) AS STOTPARC,SUM(VrLiquida-VrDeducido) AS SNETLIQ
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND ((L.TipoLiq='CES' AND Semstre=0) OR L.TipoLiq<>'CES') 
 AND L.Anulado=0 AND FPnomina='TRANS' 
 AND L.TipoLiq LIKE ISNULL(@pmTipoLiq,'%') AND D.IdNom LIKE ISNULL(@pmIdNom,'%') AND D.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') 
 GROUP BY L.TipoLiq,D.IdEmpleado,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase,ClaseCuenta,NumCuenta
 ,E.IdBanco,Banco,CodEntidad,CdLocCue,e_mail,Telefono,D.NContrato,IdConcepto,E.Direccion,TelMovil,Cargo
 ORDER BY D.IdEmpleado,L.TipoLiq
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaCes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaCes] @pmTipoLiq VARCHAR(3),@pmIdEmpleado VARCHAR(16),@pmFechLiq SMALLDATETIME
 AS 
 SELECT L.TipoLiq AS TipLiq,L.Numero AS NumLiq,Fecha,VrTotal,VrTotDed,VrAplicado,VrParcial,Anulado,IdEstado
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq  AND Semstre=0 AND Anulado=0 AND IdEmpleado=@pmIdEmpleado
 AND Fecha>=@pmFechLiq
 ORDER BY L.Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaCmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaCmp] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT  TipCom,Comprobante,IdCiaCom,COUNT(Numero) AS SCANT 
 FROM  Trn_NomLiquida
 WHERE TipoLiq='PRI'  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Comprobante>0
 GROUP BY TipCom,Comprobante,IdCiaCom
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaEmp] @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16),@pmNContrato INT=Null
 AS 
 SELECT L.TipoLiq AS TipLiq,L.Numero AS NumLiq,Fecha,IdEmpleado,NContrato,SUM(VrBase) AS STOTBASE,SUM(Cantidad) AS SDIAS,SUM(VrLiquida) AS SVLIQ
,SUM(VrDeducido) AS SVDED,SUM(DiasBase) AS SDiasBase,SUM(DiasNoRem) AS SDiasNoRem,SUM(VrParcial) AS SVRPAR
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 GROUP BY L.TipoLiq,L.Numero,Fecha,IdEmpleado,NContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaFec] @pmTipoLiq VARCHAR(3),@pmFecha SMALLDATETIME,@pmNumero INT
 AS 
 SELECT TipoLiq,Numero,Fecha,Semstre,IdEstado,TipCom,Comprobante,IdCiaCom
 FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq AND Anulado=0 AND Fecha>@pmFecha  AND Numero<>@pmNumero
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaId]  @pmTipoLiq VARCHAR(3)
AS
 SELECT MAX(Numero) AS MXNUM FROM Trn_NomLiquida
 WHERE TipoLiq=@pmTipoLiq
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaIng]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaIng] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT Q.TipoLiq AS Tip_Liqda,Q.Numero AS NumLiquida,Fecha,D.IdEmpleado AS IdEmpldo,Apellidos,Nombres,D.NContrato AS NumContrato,D.pVehiculo AS PlacaVeh,D.IdDep AS CodDep
,D.IdCCosto AS CodCcto,D.IdSubCos AS CodSubcen,D.IdNom AS CodNom,D.VrSalario AS Liq_SalBasico,Item,D.IdConcepto AS CodConcepto,Concepto,CN.Tarifa AS TrfaDft,Detalle,ClaseCon,FecUltLiq,FecInicial,FecFinal
,VrBase,Cantidad,VrLiquida,VrDeducido,DiasBase,DiasNoRem,D.Tarifa AS Tarfa,NPrestamo,IdTipCon,IdArea,IdInstala,C.Inactivo AS Con_inactivo,E.Inactivo AS Emp_Inactvo,IdFonCes,VrParcial
 FROM Trn_NomLiquida AS Q INNER JOIN Trn_NomLiqDet AS D ON Q.TipoLiq=D.TipoLiq AND Q.Numero=D.Numero
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON D.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON D.NContrato=C.NContrato
 WHERE Fecha BETWEEN @pmFecIni AND @pmFecFin AND ((Q.TipoLiq='CES' AND Semstre=0) OR Q.TipoLiq<>'CES')
 AND Q.Anulado=0 AND D.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND IdArea LIKE ISNULL(@pmIdArea,'%')  AND D.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND IdInstala LIKE ISNULL(@pmIdInstala,'%') AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%') AND D.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (D.NContrato >=ISNULL(@pmNContrato ,0)  AND D.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY D.IdEmpleado,Q.TipoLiq,Q.Numero,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaPar]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaPar] @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16),@pmNContrato INT=Null
 AS 
 SELECT IdConcepto,Detalle,SUM(VrBase) AS STOTBASE,SUM(Cantidad) AS SDIAS,SUM(VrLiquida) AS SVLIQ,SUM(VrDeducido) AS SVDED
,SUM(DiasBase) AS SDiasBase,SUM(DiasNoRem) AS SDiasNoRem,SUM(VrParcial) AS SVRPAR
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND VrTotal>VrAplicado
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 GROUP BY IdConcepto,Detalle
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaPtot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaPtot] @pmTipoLiq VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16),@pmNContrato INT=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT IdConcepto,SUM(VrBase) AS STOTBASE,SUM(Cantidad) AS SDIAS,SUM(VrLiquida) AS SVLIQ,SUM(VrDeducido) AS SVDED
,SUM(DiasBase) AS SDiasBase,SUM(DiasNoRem) AS SDiasNoRem,SUM(VrParcial) AS SVRPAR
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 GROUP BY IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaTip]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaTip]  @pmTipoLiq VARCHAR(3),@pmFecha SMALLDATETIME,@pmSemstre INT=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
AS
 SELECT L.TipoLiq AS TLiq,L.Numero AS NumLiq,Fecha
  FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
  WHERE L.TipoLiq=@pmTipoLiq AND Fecha=@pmFecha AND Anulado=0 AND  IdDep LIKE ISNULL(@pmIdDep,'%') 
  AND IdNom LIKE ISNULL(@pmIdNom,'%')   AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (Semstre>=ISNULL(@pmSemstre,0)  AND Semstre<=ISNULL(@pmSemstre,2147483647))
 ORDER BY L.Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLiquidaUcp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomLiquidaUcp] @pmTipoLiq VARCHAR(3),@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT L.TipoLiq AS TipLiq,L.Numero AS NumLiq,Fecha,VrTotal,VrTotDed,VrAplicado,Anulado,IdEstado,VrParcial
 FROM Trn_NomLiquida AS L INNER JOIN Trn_NomLiqDet AS D ON L.TipoLiq=D.TipoLiq AND L.Numero=D.Numero
 WHERE L.TipoLiq=@pmTipoLiq  AND Anulado=0 AND IdEmpleado=@pmIdEmpleado
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLogVeh]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomLogVeh] @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 SELECT IdEmpleado,NumReg,Fecha,pVehAnterior,NitPropAnt,NitCondAnt,pVehNew,NitPropNew,Observacion,TimeSys,IdUsuario
 FROM Trn_NomLogVeh
 WHERE IdEmpleado=@pmIdEmpleado
 AND (NumReg>=ISNULL(@pmNumReg,0)  AND NumReg<=ISNULL(@pmNumReg,2147483647))
 ORDER BY NumReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLogVehDso]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomLogVehDso] @pmIdEmpleado VARCHAR(16)=Null,@pmNumReg INT=Null,@pmFechaIni SMALLDATETIME=Null
,@pmFechaFin SMALLDATETIME=Null,@pmpVehNew VARCHAR(10)=Null
 AS 
 SELECT LV.IdEmpleado AS IdEmpldo,Apellidos,Nombres,NumReg,Fecha,pVehAnterior,NitPropAnt,NitCondAnt,pVehNew,NitPropNew,LV.Observacion AS Observ
,TimeSys,LV.IdUsuario AS IdUsuari,Usuario,NContrato
 FROM Trn_NomLogVeh AS LV INNER JOIN Empleados AS E ON LV.IdEmpleado=E.IdEmpleado INNER JOIN adm_Usuarios AS U ON LV.IdUsuario=U.IdUsuario
 WHERE LV.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND pVehNew LIKE ISNULL(@pmpVehNew,'%')
 AND (NumReg>=ISNULL(@pmNumReg,0)  AND NumReg<=ISNULL(@pmNumReg,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,NumReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomLogVehId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomLogVehId] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(NumReg) AS MXNUM
 FROM Trn_NomLogVeh
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNov]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNov] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT
 AS 
 SELECT Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrTotal,Tarifa,VrOrigen,IdPeriodo,IdEmpleado
,TimeSys,FecUpdate,IdUsuario,OrigCargue,NumDocRef,Num_Contrato,Nit_Tercero,HoraInicial,HoraFinal
 FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNov_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNov_Cr] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT IdPeriodo,N.IdEmpleado AS IdEmpledo,Apellidos,Nombres,E.NContrato AS NumContrato,Item,N.IdConcepto AS IdConcept,Concepto,Detalle,Cantidad,VrUnitario,VrTotal,N.Tarifa AS TrfaBase,VrOrigen,ClaseCon,Unidad,TimeSys
,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario,OrigCargue,Num_Contrato,Nit_Tercero,T.RazonSocial AS NomTercero,N.HoraInicial,N.HoraFinal
--Datos empleado
,E.Codigo,E.IdLugarCed,Localidad,E.Direccion AS Dirccion,E.Telefono,E.TelMovil,E.e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdCCosto AS CodCcto,CCosto
,C.IdSubCos AS CodSubcen,SubCosto,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
 FROM Trn_NomNov AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado  INNER JOIN  NomConceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 LEFT JOIN  Emp_Contrato AS C ON E.NContrato=C.NContrato  LEFT JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 LEFT JOIN Dependencias AS DP ON C.IdDep=DP.IdDep  LEFT JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 LEFT JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto  LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposNom AS TN ON C.IdNom=TN.IdNom LEFT JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado 
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo LEFT JOIN Areas AS AR ON C.IdArea=AR.IdArea
 LEFT JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase LEFT JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 LEFT JOIN Terceros AS T ON N.Nit_Tercero=T.IdTercero
 WHERE IdPeriodo=@pmIdPeriodo AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY  N.IdEmpleado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovCon] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16) 
,@pmIdConcepto VARCHAR(4),@pmOrigCargue VARCHAR(10)=Null
 AS 
 SELECT Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrTotal,Tarifa,VrOrigen,IdPeriodo,IdEmpleado
,TimeSys,FecUpdate,IdUsuario,OrigCargue,Num_Contrato,Nit_Tercero,HoraInicial,HoraFinal
 FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado
 AND IdConcepto=@pmIdConcepto
 AND OrigCargue LIKE ISNULL(@pmOrigCargue,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovConv] @pmId BIGINT
 AS 
 SELECT [Id],IdPeriodo,IdEmpleado,NContrato,FecInicial,FecFinal,IdConv,IdGrupo,CodEscfon,CodBase,CodZona,TipoNom,IdNom,Cantidad,VrDevengado,VrDeducido,VrSalario
 ,VrAuxTransp,VrSalBasDia,VrAuxTraDia,VrPriConDia,NumRegLog,OrigenReg,Anulado,FechaCrea,IdUsuario
 FROM Trn_NomNovConv
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovConvLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovConvLta] @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmNumNovIni INT=Null,@pmNumNovFin INT=Null
 AS 
 SELECT N.Id,N.IdPeriodo,N.IdEmpleado,E.Apellidos,E.Nombres,N.NContrato,N.FecInicial,N.FecFinal,N.IdConv,CV.Proyecto,N.IdGrupo,G.GrupoConv,N.CodEscfon,EC.Escalafon
,EC.IdCargo,CG.Cargo,N.CodBase,B.NombreBase,N.CodZona,Z.ZonaConv,N.IdNom,N.TipoNom,N.Cantidad AS CantTotal,N.VrDevengado,N.VrDeducido,N.VrSalario
,N.VrAuxTransp,N.VrSalBasDia,N.VrAuxTraDia,N.VrPriConDia
--items del detalle 
,D.Item,D.IdConcepto,CN.Concepto,D.Descripcion,D.Cantidad,D.VrUnitario,D.VrTotal,D.VrBaseLiq,D.Tarifa,D.Unidad,D.ClaseCon,D.NitTercero,T.RazonSocial
,D.Referencia,D.HoraInicial,D.HoraFinal,D.TipoReg,D.NumRegVf,D.CantDias,D.CantNov,CN.BaseTrfa
,N.OrigenReg,N.NumRegLog,N.Anulado,N.FechaCrea,N.IdUsuario,Usuario
 FROM Trn_NomNovConv AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado 
 INNER JOIN NomConvenciones AS CV ON N.IdConv=CV.Id INNER JOIN NomGruposConv AS G ON N.IdGrupo=G.IdGrupo
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 INNER JOIN Trn_NomNovConc AS D ON N.Id=D.IdNovedad INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero
 LEFT JOIN NomEscalafones AS EC ON N.CodEscfon=EC.IdEscfon LEFT JOIN Cargos AS CG ON EC.IdCargo=CG.IdCargo
 LEFT JOIN NomZonasConv AS Z ON N.CodZona=Z.IdZona LEFT JOIN NomBasesConv AS B ON N.CodBase=B.IdBase
 WHERE N.Id BETWEEN ISNULL(@pmNumNovIni,0) AND ISNULL(@pmNumNovFin,2147483647)
 AND ((N.FecInicial BETWEEN @pmFecInicio AND @pmFecFinal) OR (N.FecFinal BETWEEN @pmFecInicio AND @pmFecFinal)
 OR (N.FecInicial>=@pmFecInicio AND N.FecFinal<=@pmFecFinal))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedad]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovedad] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,Remnrado
,Observacion,CodInstla,CodClsRie,NumAutza,CodNewFon,CodOldFon,Inactivo,VrCotVolAfi,VrCotVolApo,VrNoRetenido
,TipoIncap,FechaDcto,VrDescuento,TipoBaseLiq,IncAlargado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadApo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadApo] @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdNov VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT FecInicio,FecFinal,SUM(CantDias) AS SCanDia,SUM(VrCotVolAfi) AS SVolAfi,SUM(VrCotVolApo) AS SVolApo,SUM(VrNoRetenido) AS SNoReten
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado AND Inactivo=0  AND FecFinal>=@pmFecIni  AND  FecInicio<=@pmFecFin
 AND IdNov LIKE ISNULL(@pmIdNov,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 GROUP BY FecInicio,FecFinal
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadCon] @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmRemnrado BIT=Null,@pmIdOpc INT=Null
 AS 
 SELECT IdEmpleado,Numero,N.IdConcepto AS CodConcept,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla,CodClsRie,NumAutza,CodNewFon
,CodOldFon,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,Remnrado,Observacion,IdUsuario,Inactivo,FechaDcto,VrDescuento,TipoBaseLiq
 FROM Trn_NomNovedad AS N INNER JOIN NomConOpciones AS O ON N.IdConcepto=O.IdConcepto
 WHERE IdEmpleado=@pmIdEmpleado  AND Inactivo=0 AND CantDias>0 AND FecFinal>=@pmFecIni AND FecInicio<=@pmFecFin
 AND Asignado<>0 AND  (IdOpc>=ISNULL(@pmIdOpc,0)  AND IdOpc<=ISNULL(@pmIdOpc,2147483647))
 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadEmp] @pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdNov VARCHAR(4)=Null,@pmRemnrado BIT=Null
 AS 
 SELECT IdEmpleado,Numero,N.IdConcepto AS CodConcepto,Concepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla
,CodClsRie,NumAutza,CodNewFon,CodOldFon,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,Remnrado,N.Inactivo AS Inactvo,FechaDcto,VrDescuento,TipoBaseLiq
 FROM Trn_NomNovedad AS N INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
 WHERE IdEmpleado=@pmIdEmpleado  AND N.Inactivo=0 AND CantDias>0 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND IdNov LIKE ISNULL(@pmIdNov,'%') 
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadFec] @pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmModalidad VARCHAR(10)=Null
,@pmRemnrado BIT=Null
 AS 
 SELECT IdEmpleado,Numero,IdConcepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,IdNov,CodInstla,CodClsRie,NumAutza,CodNewFon,CodOldFon,Remnrado
,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,Observacion,FechaDcto,VrDescuento,TipoBaseLiq,Inactivo,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomNovedad
 WHERE Inactivo=0 AND CantDias>0 AND IdConcepto<>'AVP' AND IdEmpleado=@pmIdEmpleado AND @pmFecha BETWEEN FecInicio AND FecFinal 
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')   AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadId] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNumero
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadLic]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadLic] @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
--total de incapacidad y licencias por descontar
 AS 
 SELECT Numero,IdConcepto,Modalidad,IdNov,VrDescuento,NumAutza,FechaDcto,TipoIncap
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado  AND Inactivo=0 AND FecInicio<=@pmFecFin AND CantDias>0
  AND  FechaDcto BETWEEN @pmFecIni AND @pmFecFin AND IdConcepto  IN ('IGE','IRP','LIC')
  AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 ORDER BY IdConcepto,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadLta] @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdEmpleado VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmModalidad VARCHAR(10)=Null,@pmNumero INT=Null,@pmIdNov VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmRemnrado BIT=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpledo,Apellidos,Nombres,Numero,N.IdConcepto AS CodConcepto,Concepto,FecInicio,FecFinal,CantDias,DiaInicio,Modalidad,N.IdNov AS CodNov,Novedad,Remnrado
,N.Observacion AS Observ,CodInstla,CodClsRie,CR.Tarifa AS NewTarfARP,NumAutza,CodOldFon,CodNewFon,Fondo,VrCotVolAfi,VrCotVolApo,VrNoRetenido,TipoIncap,TipoBaseLiq,N.IncAlargado
,N.Inactivo AS Inactvo,TimeSys,FecUpdate,N.IdUsuario AS IdUsuari,Usuario,FechaDcto,VrDescuento
 FROM Trn_NomNovedad AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN TiposNov AS TN ON N.IdNov=TN.IdNov INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 LEFT JOIN ClaseRie AS CR ON N.CodClsRie=CR.IdClase LEFT JOIN Fondos AS F ON N.CodNewFon=F.IdFondo
 WHERE FecInicio BETWEEN @pmFecInicio AND @pmFecFinal AND  N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')  AND N.IdNov LIKE ISNULL(@pmIdNov,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 AND (N.Inactivo=ISNULL(@pmInactivo,0) or N.Inactivo=ISNULL(@pmInactivo,1))
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY Apellidos,Nombres,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadPen] @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null,@pmRemnrado BIT=Null,@pmCantDias INT=0
 AS 
 SELECT N.IdEmpleado,N.Numero,N.IdConcepto,N.FecInicio,N.FecFinal,N.CantDias,N.DiaInicio,N.Modalidad,N.IdNov,N.CodInstla
,CodClsRie,N.NumAutza,CodOldFon,CodNewFon,N.VrCotVolAfi,N.VrCotVolApo,N.VrNoRetenido,N.TipoIncap
,Remnrado,FechaDcto,VrDescuento,N.TipoBaseLiq,N.IncAlargado,N.Observacion,N.IdUsuario,N.Inactivo
,C.Concepto,C.ClaseCon,C.Tarifa AS ConcTarif,C.BaseTrfa AS ConcBase,C.DiasEmp,C.TarifaEmp
 FROM Trn_NomNovedad AS N INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
 WHERE N.IdEmpleado=@pmIdEmpleado AND N.Inactivo=0 AND N.CantDias>@pmCantDias AND N.FecFinal>=@pmFecIni AND N.FecInicio<=@pmFecFin
 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND N.Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND (Remnrado=ISNULL(@pmRemnrado,0) or Remnrado=ISNULL(@pmRemnrado,1))
 ORDER BY N.Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovedadTra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomNovedadTra] @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT IdNov,CodOldFon,CodNewFon,SUM(CantDias) AS SCanDia
 FROM Trn_NomNovedad
 WHERE IdEmpleado=@pmIdEmpleado AND Inactivo=0 AND CantDias>0 AND  FecInicio BETWEEN @pmFecIni AND @pmFecFin
 AND IdNov IN ('TAE','TAP')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 GROUP BY IdNov,CodOldFon,CodNewFon
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovEst_Cp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovEst_Cp] @pmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmIdEmpleado VARCHAR(16)=Null
AS 
SELECT ET.IdNovedad,N.IdPeriodo,N.IdEmpleado,E.Apellidos,E.Nombres,N.NContrato,N.IdConv,CV.Proyecto,ET.IdEstado,EC.EstadoConv,EC.NColor,ET.FechaDia
FROM Trn_NomNovEst AS ET INNER JOIN  Trn_NomNovConv AS N ON ET.IdNovedad=N.Id
INNER JOIN NomEstadosConv AS EC ON ET.IdEstado=EC.IdEstado
INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado 
INNER JOIN NomConvenciones AS CV ON N.IdConv=CV.Id
WHERE  SUBSTRING(N.IdPeriodo,1,6)=@pmMes AND (N.IdPeriodo=@pmIdPeriodo OR @pmIdPeriodo IS NULL)
AND (N.IdEmpleado=@pmIdEmpleado OR @pmIdEmpleado IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovEstLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovEstLta] @pmNumNovIni INT=Null,@pmNumNovFin INT=Null
AS 
 SELECT NE.Id,NE.IdNovedad,NE.IdEstado,E.EstadoConv,E.NColor,NE.FechaDia
 FROM Trn_NomNovEst AS NE INNER JOIN NomEstadosConv AS E ON NE.IdEstado=E.IdEstado
 WHERE NE.IdNovedad BETWEEN ISNULL(@pmNumNovIni,0) AND ISNULL(@pmNumNovFin,2147483647)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovId] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Item) AS MXITEM
 FROM Trn_NomNov
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomNovTot]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomNovTot] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16)
,@pmDeveng BIT
 AS 
 IF @pmDeveng <>0 --devengados 
  SELECT Count(Item) AS SITEM,SUM(Cantidad) AS SCANT,SUM(VrTotal) AS STOTAL,SUM(VrOrigen) AS SVBASE
  FROM Trn_NomNov AS N  INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
  WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado AND ClaseCon<>'DEDUCIDO'
 ELSE
  SELECT Count(Item) AS SITEM,SUM(Cantidad) AS SCANT,SUM(VrTotal) AS STOTAL,SUM(VrOrigen) AS SVBASE
  FROM Trn_NomNov AS N  INNER JOIN NomConceptos AS C ON N.IdConcepto=C.IdConcepto
  WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado AND ClaseCon='DEDUCIDO'
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrendas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomPrendas] @pmIdPrend VARCHAR(4)
 AS 
 SELECT IdPrend,DescPrenda,TipoPrenda,VrCostoUnd,Inactivo
 FROM NomPrendas WHERE IdPrend=@pmIdPrend
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrest]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomPrest] @pmNPrestamo INT
 AS 
 SELECT NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal
,VrTmAbono,NumPerMes,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomPrest
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrest_Cra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrest_Cra] @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmSaldoIni DECIMAL(14,2),@pmSaldoFin DECIMAL(14,2),@pmIdEmpleado VARCHAR(16)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmFrecDcto VARCHAR(10)=Null,@pmAnulado BIT=Null,@pmNPrestamo INT=Null
 AS 
 SELECT P.NPrestamo AS NumPrest,Fecha,P.IdEmpleado AS IdEmpledo,Apellidos,Nombres,P.IdConcepto AS IdConcept,Concepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,TotPrestamo-TotAbonado AS VrSaldoAct,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,P.Observacion AS Observ,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal,TimeSys,P.FecUpdate AS FecUpd,P.IdUsuario AS IdUsuari,Usuario
,E.NContrato AS NumContrato,FecIngreso,FecRetiro,VrSalario,VrAuxTrans,CE.IdNom AS CodNom,TipoNomina,pVehiculo
,Item,FechaAbo,VrAbono,nCuotas,Dscto,IdPeriodo,Detalle,NLiquida,NumPerMes
 FROM Trn_NomPrest AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado INNER JOIN NomConceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario LEFT JOIN Trn_NomAbonos AS PA ON P.NPrestamo=PA.NPrestamo
 LEFT JOIN Emp_Contrato AS CE ON E.NContrato=CE.NContrato LEFT JOIN TiposNom AS TN ON CE.IdNom=TN.IdNom
 WHERE Fecha BETWEEN @pmFecInicio AND @pmFecFinal  AND VrSaldo BETWEEN @pmSaldoIni AND @pmSaldoFin AND P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND FrecDcto LIKE ISNULL(@pmFrecDcto,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (P.NPrestamo>=ISNULL(@pmNPrestamo,0)  AND P.NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 ORDER BY P.NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestAbo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrestAbo] @pmNPrestamo INT,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT NPrestamo,IdEmpleado,VrPrestamo,NumCuotas,VrCuota,TotPrestamo,TotAbonado,VrTmAbono
 FROM Trn_NomPrest
 WHERE IdEmpleado like ISNULL(@pmIdEmpleado,'%')
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestEmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrestEmp] @pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME,@pmDsctPri INT,@pmDsctVac INT
 AS 
 SELECT NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal
,VrTmAbono,NumPerMes,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomPrest
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND DsctNom>0  AND FecInicio<=@pmFecInicio AND DsctPri>=@pmDsctPri AND DsctVac>=@pmDsctVac
  AND (VrSaldo>=0.8 or (VrSaldo+VrTmAbono)>=0.8)
 ORDER BY FecInicio,NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrestId]
 AS 
 SELECT MAX(NPrestamo) AS MXPSTM
 FROM Trn_NomPrest
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrestLta] @pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmSaldoIni DECIMAL(14,2),@pmSaldoFin DECIMAL(14,2),@pmIdEmpleado VARCHAR(16)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmFrecDcto VARCHAR(10)=Null,@pmAnulado BIT=Null,@pmNPrestamo INT=Null
 AS 
 SELECT NPrestamo,Fecha,P.IdEmpleado AS IdEmpledo,Apellidos,Nombres,P.IdConcepto AS IdConcept,Concepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,TotPrestamo-TotAbonado AS VrSaldoAct,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,P.Observacion AS Observ,Cxpagar,DsctNom,DsctPri,DsctVac,DsctEspPer,DsctEspVal,TimeSys,P.FecUpdate AS FecUpd,P.IdUsuario AS IdUsuari,Usuario
,E.NContrato AS NumContrato,FecIngreso,FecRetiro,VrSalario,VrAuxTrans,CE.IdNom AS CodNom,TipoNomina,pVehiculo,NumPerMes
 FROM Trn_NomPrest AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado INNER JOIN NomConceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Emp_Contrato AS CE ON E.NContrato=CE.NContrato LEFT JOIN TiposNom AS TN ON CE.IdNom=TN.IdNom
 WHERE Fecha BETWEEN @pmFecInicio AND @pmFecFinal  AND VrSaldo BETWEEN @pmSaldoIni AND @pmSaldoFin AND P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND FrecDcto LIKE ISNULL(@pmFrecDcto,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
 ORDER BY NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomPrestPen] @pmIdEmpleado VARCHAR(16),@pmNPreExste INT
 AS 
 SELECT NPrestamo,Fecha,IdEmpleado,IdConcepto,VrPrestamo,NumCuotas,VrCuota,FecInicio,FrecDcto,Exceptuar,TotPrestamo
,TotAbonado,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Cxpagar,NumPerMes
 FROM Trn_NomPrest
 WHERE Anulado=0 AND VrSaldo>=0.8  AND  IdEmpleado=@pmIdEmpleado  AND NPrestamo<>@pmNPreExste
 ORDER BY NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestSal]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrestSal] @pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT NPrestamo,Fecha,TotPrestamo,TotAbonado,VrSaldo,VrPrestamo,NumCuotas,VrCuota,DsctNom,FecInicio,FrecDcto
,P.IdConcepto AS CodConcepto,Concepto,Exceptuar,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,P.Observacion AS Observ,Cxpagar
,DsctPri,DsctVac,DsctEspPer,DsctEspVal,P.IdEmpleado AS CedEmpleado,Apellidos,Nombres,NumPerMes
 FROM Trn_NomPrest AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado
 INNER JOIN NomConceptos AS N ON P.IdConcepto=N.IdConcepto
 WHERE P.IdEmpleado=@pmIdEmpleado AND Anulado=0 AND DsctNom>0  AND FecInicio<=@pmFecInicio AND VrSaldo>=0.8
 AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY FecInicio,NPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrestSdo]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrestSdo] @pmIdEmpleado VARCHAR(16),@pmFecInicio SMALLDATETIME
 AS 
 SELECT COUNT(NPrestamo) AS CANPRE,SUM(VrPrestamo) AS SVALPRE,SUM(NumCuotas) AS Scuotas,SUM(TotPrestamo) AS STOTPRE
,SUM(TotAbonado) AS STOTABO
 FROM Trn_NomPrest
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND DsctNom>0  AND FecInicio<=@pmFecInicio
  AND (VrSaldo>=0.8 or (VrSaldo+VrTmAbono)>=0.8)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomPrmSaludLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomPrmSaludLta] @pmIdEmpleado VARCHAR(16)=Null,@pmnAnno INT=Null
 AS 
 SELECT N.IdEmpleado AS CdEmpleado,Apellidos,Nombres,nAnno,VrBase,nMeses,VrPromedio
 FROM Trn_NomPrmSalud AS N INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado
 WHERE N.IdEmpleado like ISNULL(@pmIdEmpleado,'%')
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))
 ORDER BY Apellidos,Nombres,nAnno
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProrrogas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomProrrogas] @pmIdEmpleado VARCHAR(16),@pmNumReg INT
 AS 
 SELECT IdEmpleado,NumReg,NContrato,Fecha,FecAnterior,Indefinido,CdTipCon,CdCargo,CdDep,CdArea,CdCCosto,CdSubCos
,IdTipCon,IdCargo,IdArea,IdDep,IdCCosto,IdSubCos,Observacion,TimeSys,IdUsuario
 FROM Trn_NomProrrogas
 WHERE IdEmpleado=@pmIdEmpleado AND NumReg=@pmNumReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProrrogasId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomProrrogasId] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(NumReg)  AS MXITM
 FROM Trn_NomProrrogas
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProrrogasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomProrrogasLta] @pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmInactivo BIT=Null
,@pmEmp_Inactivo BIT=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT P.IdEmpleado AS IdEmplado,Apellidos,Nombres,NumReg,P.NContrato AS NumContrato,FecAnterior,Fecha,P.Indefinido AS Indefnido,CdTipCon,TCA.TipoContrato AS TipoConAnterior
,P.IdTipCon AS IdTcont,TC.TipoContrato AS TipoConNuevo,CdCargo,CGA.Cargo AS CargoAnterior,P.IdCargo AS IdCarg,CG.Cargo AS CargoNuevo,CdArea,ARA.Area AS AreaAnterior
,P.IdArea AS Id_Area,AR.Area AS AreaNueva,CdDep,DA.Dependencia AS DepeAnterior,P.IdDep AS IdDepe,D.Dependencia AS DepeNueva
,CdCCosto,COA.CCosto AS CentroAnterior,P.IdCCosto AS IdCenCost,CO.CCosto AS CentroNuevo,CdSubCos,SCA.SubCosto AS SubCenAnterior,P.IdSubCos AS IdSubCen,SC.SubCosto AS SubCenNuevo
,P.Observacion AS Observ,TimeSys,P.IdUsuario AS IdUsuari,Usuario
--inf. de contratos
,FecIngreso,C.Indefinido AS Con_Indefinido,C.IdJornada AS IdJrnada,Jornada,C.IdInstala AS IdInstla,Instlacion,C.IdCia AS CodCia,Compania
,C.IdClase AS CodClaRie,ClaseRiesgo,Tarifa,TipoTrabj,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipoLiq,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,C.Inactivo AS Inactvo
--empleados
--,E.Direccion AS Dirccion,E.IdLocal AS CodCiu,L.Localidad AS Ciudad,Telefono,TelMovil,e_mail,VvdaPropia,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,IdEstCivil,EstCivil,NHijos,TallaCam,TallaPan,TallaZap,UsaGafas,E.IdProf AS CodProf,Profesion
--,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,E.IdLugar AS CodLugar,LugarLic,CatLicencia,FecLicencia,VigLicencia,IdLugarCed,LC.Localidad AS LugarCed,Conyugue,ConyFecNac,ConyTrabaja
--,ConyEmpresa,ConyCargo,ConyFing,ConyTel,E.IdClase AS CodClase,ClaseCuenta,NumCuenta,E.IdBanco AS CodBco,Banco,IdFonPen,FP.Fondo AS FondPen,IdFonEps,FS.Fondo AS FondEps,IdFonArp,FR.Fondo AS FondArp,IdFonCes,FC.Fondo AS FondCes
--,IdCajaCom,CC.Fondo AS CajaComp,FecVincula,FecUltAum,FecUltCes,FecUltPri,FecUltVac,FecUltDot,FecUltExm,FecUltCap,NCAnterior,FecIngAnt,FecRetAnt,EsCondtor,pVehiculo
--,ET.Estado AS Emp_estado,E.Inactivo AS Emp_Inactivo,TipoId,Codigo,ET.NColor AS EmpEstcolor,E.FechaAdd AS EmpFecAdd,E.FechaUpdate AS EmpFecupd,E.IdUsuario AS Emp_IdUsuario,UE.Usuario AS Emp_Usuario

 FROM Trn_NomProrrogas AS P INNER JOIN Empleados AS E ON P.IdEmpleado=E.IdEmpleado
 INNER JOIN Emp_Contrato AS C  ON P.NContrato=C.NContrato
 INNER JOIN TiposCon AS TC ON P.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON P.IdCargo=CG.IdCargo 
 INNER JOIN Dependencias AS D ON P.IdDep=D.IdDep
 INNER JOIN Areas AS AR ON P.IdArea=AR.IdArea
 INNER JOIN CentroCosto AS CO ON P.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON P.IdSubCos=SC.IdSubCos
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 LEFT JOIN TiposCon AS TCA ON P.CdTipCon=TCA.IdTipCon
 LEFT JOIN Cargos AS CGA ON P.CdCargo=CGA.IdCargo 
 LEFT JOIN Dependencias AS DA ON P.CdDep=DA.IdDep
 LEFT JOIN Areas AS ARA ON P.CdArea=ARA.IdArea
 LEFT JOIN CentroCosto AS COA ON P.CdCCosto=COA.IdCCosto
 LEFT JOIN SubCentros AS SCA ON P.CdSubCos=SCA.IdSubCos

-- INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
-- INNER JOIN EstadoCiv AS ECV ON E.IdEstCivil=ECV.IdEstado INNER JOIN ExpLicencias AS LL ON E.IdLugar=LL.IdLugar
-- INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 --INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 --INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 --INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase  INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
--INNER JOIN EstadoTer AS ET ON E.IdEstado=ET.IdEstado INNER JOIN adm_Usuarios AS UE ON E.IdUsuario=UE.IdUsuario
 WHERE P.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  
 AND (P.NContrato>=ISNULL(@pmNContrato,0)  AND P.NContrato<=ISNULL(@pmNContrato,2147483647)) 
 AND P.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')  AND P.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY Apellidos,Nombres,NumReg
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProvAjuFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomProvAjuFmt] @pmTipDoc VARCHAR(3),@pmNumAjusteIni INT,@pmNumAjusteFin INT,@pmIdCia CHAR(2)
 AS 
SELECT A.TipDoc,A.NumAjuste,A.IdCia,Compania,A.Fecha,A.TipoLiquida,A.FecLiquida,A.LiqParcial,A.IdPeriodo,A.IdNom,TipoNomina,A.VrAjusteProv,A.VrAjusteLiq,A.TipCom,TipoCom,A.Comprobante,A.IdCiaCom
,A.Observacion,A.Anulado,A.FechaCrea,A.IdCiaCrea,A.IdUsuario,Usuario
--NE_Estado, NE_Prefijo, NE_Numero, NE_FecEnvio, NE_CUNE, NE_QR, 
,D.Item,D.IdConcepto,Concepto,D.Descripcion,D.VrDebito,D.VrCredito,D.IdEmpleado,E.Apellidos,E.Nombres,D.NContrato
,D.CdCuentaDb,P.NomCuenta AS NomCuentaDb,D.CdCuentaCr,PC.NomCuenta AS NomCuentaCr,D.IdCCosto,CCosto,D.IdSubCos,SubCosto,D.CdDepend,Dependencia
FROM Trn_NomProvAju AS A INNER JOIN Trn_NomProvAjuDet AS D ON A.TipDoc=D.TipDoc AND A.NumAjuste=D.NumAjuste AND A.IdCia=D.IdCia
INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN TiposNom AS TN ON A.IdNom=TN.IdNom INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
LEFT JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
LEFT JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto LEFT JOIN TiposCom AS TC ON A.TipCom=TC.IdCom
LEFT JOIN Puc AS P ON D.CdCuentaDb=P.IdCuenta LEFT JOIN Puc AS PC ON D.CdCuentaCr=PC.IdCuenta
LEFT JOIN Dependencias AS DP ON D.CdDepend=DP.IdDep
WHERE A.TipDoc=@pmTipDoc AND A.NumAjuste BETWEEN @pmNumAjusteIni AND @pmNumAjusteFin AND A.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNomProvAjuLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomProvAjuLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
SELECT A.TipDoc,A.NumAjuste,A.IdCia,Compania,A.Fecha,A.TipoLiquida,A.FecLiquida,A.LiqParcial,A.IdPeriodo,A.IdNom,TipoNomina,A.VrAjusteProv,A.VrAjusteLiq,A.TipCom,TipoCom,A.Comprobante,A.IdCiaCom
,A.Observacion,A.Anulado,A.FechaCrea,A.IdCiaCrea,A.IdUsuario,Usuario--NE_Estado, NE_Prefijo, NE_Numero, NE_FecEnvio, NE_CUNE, NE_QR, 
,D.Item,D.IdConcepto,Concepto,D.Descripcion,D.VrDebito,D.VrCredito,D.IdEmpleado,E.Apellidos,E.Nombres,D.NContrato
,D.CdCuentaDb,P.NomCuenta AS NomCuentaDb,D.CdCuentaCr,PC.NomCuenta AS NomCuentaCr,D.IdCCosto,CCosto,D.IdSubCos,SubCosto,D.CdDepend,Dependencia
FROM Trn_NomProvAju AS A INNER JOIN Trn_NomProvAjuDet AS D ON A.TipDoc=D.TipDoc AND A.NumAjuste=D.NumAjuste AND A.IdCia=D.IdCia
INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN TiposNom AS TN ON A.IdNom=TN.IdNom INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
INNER JOIN Empleados AS E ON D.IdEmpleado=E.IdEmpleado
LEFT JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
LEFT JOIN NomConceptos AS NC ON D.IdConcepto=NC.IdConcepto LEFT JOIN TiposCom AS TC ON A.TipCom=TC.IdCom
LEFT JOIN Puc AS P ON D.CdCuentaDb=P.IdCuenta LEFT JOIN Puc AS PC ON D.CdCuentaCr=PC.IdCuenta
LEFT JOIN Dependencias AS DP ON D.CdDepend=DP.IdDep
WHERE A.TipDoc=@pmTipDoc AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (A.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRangosFsu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRangosFsu] @pmIdRango INT
AS
 SELECT     IdRango, VrInicial, VrFinal, Tarifa 
 FROM  NomRangosFsu
 WHERE IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRangosFsuId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRangosFsuId] 
AS
 SELECT  MAX(IdRango) AS MXRANGO,MAX(VrFinal) AS MXFINAL
 FROM  NomRangosFsu
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRangosFsuLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRangosFsuLta] 
AS
 SELECT   IdRango, VrInicial, VrFinal, Tarifa 
 FROM  NomRangosFsu
 ORDER BY IdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomRet] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes
,VrBaseVac,IdPeriodo,KeyReg,NPerVac,VrSalario,IdDep,IdCCosto,IdSubCos,IdNom,TipoLiq,pVehiculo,TipCom,Comprobante,IdCiaCom,Observacion,Anulado,IdEstado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRet_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRet_Cr] @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdCausa VARCHAR(4)=Null
,@pmNumero INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdPeriodo VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null
 AS 
 SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,R.Numero AS NumLiquida,Fecha,R.NContrato AS Ncontrato,R.IdCausa AS IdCauRet,CausalRet,FecInicial,FecFinal,DiasTrab,R.DiasNoRem AS Dias_Norem,VrTotDev,VrTotDed,VrTotCes
,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,R.VrSalario AS Liq_Salbasico,R.IdDep AS CodDep,Dependencia,R.IdCCosto AS CodCcost,CCosto,R.IdSubCos AS CodSubcos,SubCosto
,R.IdNom AS CodNom,TipoNomina,TipoLiq,R.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,R.Observacion AS Observ,Anulado,R.IdEstado AS Liq_IdEstdo,ED.Estado AS Liq_Estado,TimeSys,R.FecUpdate AS FecUpd,R.IdUsuario AS IdUsuari,Usuario
,Item,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,Unidad,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,D.Tarifa  AS Tarfa,VrBase,DiasBase,D.DiasNoRem AS DiasNov,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd
,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,FD.Fondo AS Det_Fondo,VrBaseLiq
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar
,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,Duracion,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,ModPromdio,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio
 FROM Trn_NomRet AS R  INNER JOIN  Empleados AS E ON R.IdEmpleado=E.IdEmpleado  INNER JOIN NomCausalesRet AS CAR ON R.IdCausa=CAR.IdCausa
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON R.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON R.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo  INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON R.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN Trn_NomRetDet AS D ON R.IdEmpleado=D.IdEmpleado AND R.Numero=D.Numero
 LEFT JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom   LEFT JOIN NomVehiculos AS VH ON R.pVehiculo=VH.IdVehiculo
 WHERE R.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')   AND R.IdCausa LIKE ISNULL(@pmIdCausa,'%') AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (R.Numero>=ISNULL(@pmNumero,0)  AND  R.Numero<=ISNULL(@pmNumero,2147483647))
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
AND (R.NContrato>=ISNULL(@pmNContrato,0)  AND  R.NContrato<=ISNULL(@pmNContrato,2147483647))
ORDER BY R.IdEmpleado,R.Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRet_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRet_Crr] @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdEmpleado VARCHAR(16)=Null,@pmIdCausa VARCHAR(4)=Null
,@pmNumero INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdNom VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdPeriodo VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null
 AS 
 SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Numero,Fecha,R.NContrato AS Ncontrato,R.IdCausa AS IdCauRet,CausalRet,FecInicial,FecFinal,DiasTrab,DiasNoRem,VrTotDev,VrTotDed,VrTotCes
,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes,VrBaseVac,IdPeriodo,KeyReg,NPerVac,R.VrSalario AS Liq_Salbasico,R.IdDep AS CodDep,Dependencia,R.IdCCosto AS CodCcost,CCosto,R.IdSubCos AS CodSubcos,SubCosto
,R.IdNom AS CodNom,TipoNomina,TipoLiq,R.pVehiculo AS PlacaVeh,TipCom,TipoCom,Comprobante,IdCiaCom,R.Observacion AS Observ,Anulado,R.IdEstado AS Liq_IdEstdo,ED.Estado AS Liq_Estado,TimeSys,R.FecUpdate AS FecUpd,R.IdUsuario AS IdUsuari,Usuario
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar
,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,Duracion,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,ModPromdio,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio
 FROM Trn_NomRet AS R  INNER JOIN  Empleados AS E ON R.IdEmpleado=E.IdEmpleado  INNER JOIN NomCausalesRet AS CAR ON R.IdCausa=CAR.IdCausa
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON R.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON R.IdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo  INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON R.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom  LEFT JOIN NomVehiculos AS VH ON  R.pVehiculo=VH.IdVehiculo
 WHERE R.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')   AND R.IdCausa LIKE ISNULL(@pmIdCausa,'%') AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND  Numero<=ISNULL(@pmNumero,2147483647))
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
AND (R.NContrato>=ISNULL(@pmNContrato,0)  AND  R.NContrato<=ISNULL(@pmNContrato,2147483647))
ORDER BY R.IdEmpleado,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetAct]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRetAct] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,IdCausa,FecInicial,FecFinal,DiasTrab,DiasNoRem
 FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND Numero<>@pmNumero
 ORDER BY  Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryNomRetBan] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
AS
SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,E.Direccion AS EmpDireccion,TelMovil,e_mail,Telefono,R.NContrato AS NumContrato
,Cargo,VrTotDev,VrTotDed,VrTotCes,VrTotPri,VrTotVac,VrTotInt,VrTotInd,VrParCes,VrParInt,VrNeto,VrBaseCes,VrBaseVac
 FROM Trn_NomRet AS R INNER JOIN Empleados AS E ON R.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON R.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0  AND FPnomina='TRANS' 
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%') AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') 
 ORDER BY  Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetCmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomRetCmp] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT  TipCom,Comprobante,IdCiaCom,COUNT(Numero) AS SCANT 
 FROM Trn_NomRet
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Comprobante>0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 GROUP BY TipCom,Comprobante,IdCiaCom
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomRetDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 SELECT IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrUnitario,VrDevngado,VrDeducido,Tarifa,VrBase,DiasBase,DiasNoRem,FecUltLiq,FecDesde,FecHasta,FecIniPmd,FecFinPmd
,GrupoLiq,NPrestamo,NCuota,LogPmdio,ClaseLiq,CodFondo,VrBaseLiq
 FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetDetLiq]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRetDetLiq] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Item,IdConcepto,Detalle,FecUltLiq,FecDesde,FecHasta,ClaseLiq
 FROM Trn_NomRetDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero AND ClaseLiq='LIQUDACION'
 ORDER BY IdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRetId] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomRet
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomRetIng]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomRetIng] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
 AS 
 SELECT R.IdEmpleado AS IdEmpldo,Apellidos,Nombres,R.NContrato AS NumContto,MONTH(R.Fecha) AS Nmes,YEAR(R.Fecha) AS NumAnno,R.IdDep AS CodDep,C.IdInstala AS CodInstala
,R.IdCCosto AS CodCcto,R.IdSubCos AS CodSubcc,R.IdNom AS CodNom,R.pVehiculo AS PlacaVeh,R.VrSalario  AS Salbasico,TipoLiq,IdArea,IdTipCon
,D.IdConcepto AS CodConcepto,Concepto
,SUM(Cantidad) AS SCANT,SUM(VrDevngado) AS STotDev,SUM(VrDeducido) AS STotDed,SUM(VrBase) AS SValBase
,SUM(DiasBase) AS DIAS_BASE,SUM(D.DiasNoRem) AS SCanNoRem,SUM(DiasBase-D.DiasNoRem) AS DiasNeto
,SUM(VrBaseLiq) AS SbaseLiq
 FROM Trn_NomRet AS R INNER JOIN  Trn_NomRetDet AS  D ON R.IdEmpleado=D.IdEmpleado AND R.Numero=D.Numero
 INNER JOIN Empleados AS E ON R.IdEmpleado=E.IdEmpleado  INNER JOIN Emp_Contrato AS C ON R.NContrato=C.NContrato
 INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 WHERE Fecha BETWEEN @pmFecIni  AND @pmFecFin  AND ClaseLiq='LIQUDACION' AND R.Anulado=0
 AND R.IdNom LIKE ISNULL(@pmIdNom,'%')  AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 AND R.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')   AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND R.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')  
 AND (R.NContrato>=ISNULL(@pmNContrato,0)  AND R.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 GROUP BY  R.IdEmpleado,Apellidos,Nombres,R.NContrato,MONTH(R.Fecha),YEAR(R.Fecha),R.IdDep,C.IdInstala
,R.IdCCosto,R.IdSubCos,R.IdNom,R.pVehiculo,R.VrSalario,TipoLiq,IdArea,IdTipCon,D.IdConcepto,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryNomSueldos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomSueldos] @pmNumero INT,@pmIdEmpleado VARCHAR(16)
 AS 
 SELECT Numero,IdEmpleado,Fecha,NContrato,VrSueAnterior,VrSueNuevo,VrAtAnterior,VrAtNuevo,MetodoUp,Reemplzado
,FecUltAumto,CritSelect,Observacion,TipoActualiza,TimeSys,IdUsuario
 FROM Trn_NomSueldos
 WHERE Numero=@pmNumero AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomSueldos_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomSueldos_Cr]  @pmIdEmpleado VARCHAR(16)=Null,@pmNumero INT=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT Numero,Fecha,S.IdEmpleado AS IdEmpldo,Apellidos,Nombres,S.NContrato AS NumCtrato,VrSueAnterior,VrSueNuevo,VrAtAnterior,VrAtNuevo,MetodoUp,Reemplzado
,FecUltAumto,CritSelect,S.Observacion AS Observ,TipoActualiza,TimeSys,S.IdUsuario AS IdUsuari,Usuario
--datos del empleado
,E.IdProf AS CodProf,Profesion
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdNom AS CodNom,TipoNomina
,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,C.IdEstado AS Con_IdEstdo,Estado,C.Inactivo AS Con_inactivo
 FROM Trn_NomSueldos AS S INNER JOIN Empleados AS E ON S.IdEmpleado=E.IdEmpleado INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf 
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario 
 INNER JOIN  Emp_Contrato AS C ON S.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon 
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala 
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea 
 WHERE S.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND  Numero<=ISNULL(@pmNumero,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Numero,Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryNomSueldosId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomSueldosId] @pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomSueldos
 WHERE  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryNomTablaRet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomTablaRet] @pmnAnno INT,@pmnIntrvalo INT=Null
 AS 
 SELECT nAnno,nIntrvalo,VrInicial,VrFinal,Tarifa,VrRetncion,TarExcdnte,VrBaseExc,FechaAdd,FechaUpdate,IdUsuario
 FROM NomTablaRet
 WHERE nAnno=@pmnAnno  AND (nIntrvalo>=ISNULL(@pmnIntrvalo,0)  AND nIntrvalo<=ISNULL(@pmnIntrvalo,2147483647))
 ORDER BY nIntrvalo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomTablaRetInv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomTablaRetInv] @pmnAnno INT,@pmValbase MONEY
 AS 
 SELECT nAnno,nIntrvalo,VrInicial,VrFinal,Tarifa,VrRetncion,TarExcdnte,VrBaseExc
 FROM NomTablaRet
 WHERE nAnno=@pmnAnno AND @pmValbase>VrInicial AND @pmValbase<=VrFinal
 ORDER BY nIntrvalo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomTablaRetItm]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomTablaRetItm] @pmnAnno INT
 AS 
 SELECT MAX(nIntrvalo) AS MXITM,MAX(VrFinal) AS MXFINAL
 FROM NomTablaRet
 WHERE nAnno=@pmnAnno
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomVac] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem
,VrRemndo,VrTotDed,VrSalario,pVehiculo,DiasAjuste,TipCom,Comprobante,IdCiaCom,Observacion,LogPmdio,Anulado,IdEstado,LiqParcial,DiasDom,TimeSys,FecUpdate,IdUsuario
 FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVac_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVac_Cr] @pmIdEmpleado VARCHAR(16),@pmNumero INT
 AS 
 SELECT V.IdEmpleado AS IdEmpldo,Apellidos,Nombres,V.Numero AS NumReg,Fecha,V.NContrato AS NumContrato,FecInicial,FecFinal,V.Cantidad AS DiasCal,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac
,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,V.VrSalario AS Vac_VrBasico,V.pVehiculo AS PlacaVeh,DiasAjuste,TipCom,TipoCom,Comprobante,IdCiaCom,V.Observacion AS Observ,LogPmdio,LiqParcial,DiasDom,Anulado,V.IdEstado AS Vac_IdEstdo,ED.Estado AS Vac_Estado
,TimeSys,V.FecUpdate AS FecUpd,V.IdUsuario AS IdUsuari,Usuario
--datos del detalle de liquidacion
,Item,D.IdConcepto AS CodConcepto,Concepto,ClaseCon,Detalle,D.Cantidad AS Cant,Unidad,VrDevgado,VrDeducido,D.Tarifa AS Tarfa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo
--datos del empleado 
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdCCosto AS CodCcto,CCosto
,C.IdSubCos AS CodSubcen,SubCosto,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio,VrSalud
 FROM Trn_NomVac  AS V INNER JOIN  Empleados AS E ON V.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON V.IdEstado=ED.IdEstado
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom 
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 LEFT JOIN  Trn_NomVacDet  AS D ON V.IdEmpleado=D.IdEmpleado AND V.Numero=D.Numero  LEFT JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto
 LEFT JOIN TiposCom AS TM ON V.TipCom=TM.IdCom
 LEFT JOIN NomVehiculos AS VH ON V.pVehiculo=VH.IdVehiculo
 WHERE  V.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND (V.Numero>=ISNULL(@pmNumero,0)  AND V.Numero<=ISNULL(@pmNumero,2147483647))
ORDER BY   V.Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVac_Crr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVac_Crr] @pmIdEmpleado VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNumero INT=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null,@pmFecVacIni SMALLDATETIME=Null,@pmFecVacFin SMALLDATETIME=Null
 AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Numero,Fecha,Q.NContrato AS NumContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem
,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico,Q.pVehiculo AS PlacaVeh,DiasAjuste,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,LogPmdio,LiqParcial,DiasDom,Anulado
,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps
,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdJornada AS CodJnada,Jornada
,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,C.IdCCosto AS CodCcto,CCosto,C.IdSubCos AS CodSubcen,SubCosto,Asistencia,NoDevenga,TipoTrabj
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModPromdio,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo
 FROM Trn_NomVac AS Q INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  
 INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado  INNER JOIN  Empleados AS E ON Q.IdEmpleado=E.IdEmpleado  
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom 
 WHERE  Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND Q.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Q.NContrato >=ISNULL(@pmNContrato ,0)  AND Q.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (FecInicial>=ISNULL(@pmFecVacIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecVacFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacBan]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVacBan] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null
AS
SELECT V.IdEmpleado AS IdEmpldo,Apellidos,Nombres,TipoId,Codigo,IdLocal,E.IdClase AS CdClase,ClaseCuenta,NumCuenta
,E.IdBanco AS CdBanco,Banco,CodEntidad,CdLocCue,e_mail,Telefono,V.NContrato AS NumContrato
,E.Direccion AS EmpDireccion,TelMovil,Cargo
,Cantidad,VrLiquida,VrBase,VrRemndo,VrTotDed,(VrLiquida+VrRemndo)-VrTotDed  AS SNETVAC
 FROM Trn_NomVac AS V INNER JOIN Empleados AS E ON V.IdEmpleado=E.IdEmpleado  
 INNER JOIN  Emp_Contrato AS C ON V.NContrato=C.NContrato
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 WHERE  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0  AND FPnomina='TRANS' 
 AND C.IdNom LIKE ISNULL(@pmIdNom,'%') AND C.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') 
 ORDER BY  Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacCmp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomVacCmp] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT  TipCom,Comprobante,IdCiaCom,COUNT(Numero) AS SCANT 
 FROM  Trn_NomVac
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0 AND Comprobante>0
 AND  IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 GROUP BY TipCom,Comprobante,IdCiaCom
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVacDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT
 AS 
 SELECT IdEmpleado,Numero,Item,IdConcepto,Detalle,Cantidad,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension
,VrSalud,NPrestamo,NCuota,IdPeriodo,CodFondo
 FROM Trn_NomVacDet
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDet_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVacDet_Cr] @pmIdEmpleado VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmNumero INT=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null,@pmNContrato INT=Null,@pmFecVacIni SMALLDATETIME=Null
,@pmFecVacFin SMALLDATETIME=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Q.Numero AS NumLiquida,Fecha,Q.NContrato AS NumContrato,FecInicial,FecFinal,Q.Cantidad AS CantDias,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem
,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico,Q.pVehiculo AS PlacaVeh,DiasAjuste,TipCom,TipoCom,Comprobante,IdCiaCom,Q.Observacion AS Observ,LogPmdio,LiqParcial,DiasDom,Anulado
,Q.IdEstado AS IdEstdo,ED.Estado AS Liq_estado,TimeSys,Q.FecUpdate AS FecUpd,Q.IdUsuario AS IdUsuari,Usuario
--detalle de liq vac
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,D.Cantidad AS Cant,VrDevgado,VrDeducido,D.Tarifa AS Tarfa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,D.CodFondo,FD.Fondo AS DetFondo
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen,IdFonEps,FS.Fondo AS FondoEps
,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,E.pVehiculo AS Emp_Vehiculo,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,FecUltCes,FecUltPri,FecUltVac,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdJornada AS CodJnada,Jornada
,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,C.IdCCosto AS CodCcto,CCosto,C.IdSubCos AS CodSubcen,SubCosto,Asistencia,NoDevenga,TipoTrabj
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,C.VrSalario AS SalBasico,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ModPromdio,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,DenyCes,DenyPri,DenyVac,BasePrest
,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,VrSalud
 FROM Trn_NomVac AS Q INNER JOIN Trn_NomVacDet AS D ON Q.IdEmpleado=D.IdEmpleado AND Q.Numero=D.Numero
 INNER JOIN adm_Usuarios AS U ON Q.IdUsuario=U.IdUsuario  INNER JOIN EstadoDoc AS ED ON Q.IdEstado=ED.IdEstado
 INNER JOIN Empleados AS E ON Q.IdEmpleado=E.IdEmpleado  INNER JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
 LEFT JOIN TiposCom AS TM ON Q.TipCom=TM.IdCom LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE  Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') AND C.IdNom LIKE ISNULL(@pmIdNom,'%')
 AND C.IdDep LIKE ISNULL(@pmIdDep,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%') AND C.IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND C.IdInstala LIKE ISNULL(@pmIdInstala,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND Q.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Q.Numero>=ISNULL(@pmNumero,0)  AND Q.Numero<=ISNULL(@pmNumero,2147483647))
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (Q.NContrato >=ISNULL(@pmNContrato ,0)  AND Q.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (FecInicial>=ISNULL(@pmFecVacIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecVacFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Apellidos,Nombres,Q.Numero,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDetCon]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomVacDetCon] @pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmMes VARCHAR(6)
,@pmIdPeriodo VARCHAR(8)=Null,@pmNContrato INT=Null
 AS 
 --Obsoleto Nov 22/2016
 SELECT SUM(VD.Cantidad) AS SCANT,SUM(VrDevgado) AS SDEVNG,SUM(VrDeducido) AS STOTDED,SUM(VrBaseLiq) AS STOTBAS
,SUM(VrCertfcado) AS STOTCER,SUM(VrPension) AS STOTPEN,SUM(VrSalud) AS STOTSALUD
 FROM Trn_NomVacDet AS VD INNER JOIN Trn_NomVac AS V ON VD.IdEmpleado=V.IdEmpleado AND VD.Numero=V.Numero
 WHERE VD.IdEmpleado=@pmIdEmpleado AND  IdConcepto=@pmIdConcepto AND Anulado=0 AND SUBSTRING(IdPeriodo,1,6)=@pmMes
 AND  IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') 
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacDetRes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVacDetRes] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdEmpleado VARCHAR(16)=Null,@pmNContrato INT=Null,@pmIdArea VARCHAR(4)=Null,@pmIdDep VARCHAR(4)=Null
,@pmIdNom VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmInactivo BIT=Null
,@pmEmp_Inactivo BIT=Null,@pmFecVacIni SMALLDATETIME=Null,@pmFecVacFin SMALLDATETIME=Null
 AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Q.Numero AS NumLiquida,Q.NContrato AS NumContrato,Fecha,FecInicial,FecFinal,Q.Cantidad AS CantDias
,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem,DiasVac,NNovedad,NPeriodos,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico
,Q.pVehiculo AS PlacaVeh,DiasAjuste,LiqParcial,DiasDom,TipCom,Comprobante,IdCiaCom,Q.Observacion AS Observ
--detalle de liq vac
,Item,IdConcepto,Detalle,D.Cantidad AS Cant,VrDevgado,VrDeducido,Tarifa,VrBaseLiq,VrCertfcado,VrPension,NPrestamo,NCuota,IdPeriodo,VrSalud
,D.CodFondo,FD.Fondo AS DetFondo
--datos del contrato
,IdArea,IdDep,IdInstala,IdNom,TipoLiquida,IdCCosto,IdSubCos,C.VrSalario AS SalBasico,VrAuxTrans
 FROM Trn_NomVac AS Q INNER JOIN Empleados AS E ON Q.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato
 LEFT JOIN Trn_NomVacDet AS D ON Q.IdEmpleado=D.IdEmpleado AND Q.Numero=D.Numero
 LEFT JOIN Fondos AS FD ON D.CodFondo=FD.IdFondo
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND IdDep LIKE ISNULL(@pmIdDep,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdNom LIKE ISNULL(@pmIdNom,'%')
 AND IdInstala LIKE ISNULL(@pmIdInstala,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (Q.NContrato >=ISNULL(@pmNContrato ,0)  AND Q.NContrato <=ISNULL(@pmNContrato,2147483647))
 AND (FecInicial>=ISNULL(@pmFecVacIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecVacFin,CAST('20781230' AS SMALLDATETIME)))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY IdEmpldo,Q.Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacId]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVacId] @pmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacIng]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNomVacIng] @pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME,@pmIdNom VARCHAR(4)=Null,@pmIdArea VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmIdInstala VARCHAR(4)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdTipCon VARCHAR(4)=Null,@pmIdEmpleado VARCHAR(16)=Null
,@pmNContrato INT=Null,@pmInactivo BIT=Null,@pmEmp_Inactivo BIT=Null
AS 
 SELECT Q.IdEmpleado AS IdEmpldo,Apellidos,Nombres,Q.Numero AS NumLiquida,Fecha,Q.NContrato AS NumContrato,FecInicial,FecFinal,Q.Cantidad AS CantDias,VrLiquida,VrBase,FecIniPmd,FecFinPmd,DiasBase,DiasNoRem
,DiasVac,CantRem,VrRemndo,VrTotDed,Q.VrSalario AS Liq_SalBasico,Q.pVehiculo AS PlacaVeh,DiasAjuste
,Item,D.IdConcepto AS CodConcepto,Concepto,Detalle,ClaseCon,CN.Tarifa AS TarifDft,D.Cantidad AS Cant,VrDevgado,VrDeducido,D.Tarifa AS Tarfa,VrBaseLiq,VrCertfcado,VrPension,VrSalud,NPrestamo
,IdTipCon,IdArea,IdDep,IdInstala,IdNom,TipoLiquida,IdCCosto,IdSubCos,C.VrSalario AS SalBasico,VrAuxTrans,E.Inactivo AS Emp_Inactvo,C.Inactivo AS Con_inactivo,IdFonPen,IdFonEps
 FROM Trn_NomVac AS Q INNER JOIN Empleados AS E ON Q.IdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON Q.NContrato=C.NContrato
 LEFT JOIN  Trn_NomVacDet AS D ON Q.IdEmpleado=D.IdEmpleado AND Q.Numero=D.Numero
 LEFT JOIN NomConceptos AS CN ON D.IdConcepto=CN.IdConcepto  
 WHERE  FecInicial  BETWEEN  @pmFecIni AND @pmFecFin AND Q.Anulado=0
 AND IdNom LIKE ISNULL(@pmIdNom,'%')  AND IdArea LIKE ISNULL(@pmIdArea,'%')
 AND IdDep LIKE ISNULL(@pmIdDep,'%') AND IdInstala LIKE ISNULL(@pmIdInstala,'%')
 AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')   AND IdTipCon LIKE ISNULL(@pmIdTipCon,'%')
 AND Q.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND (Q.NContrato>=ISNULL(@pmNContrato,0)  AND Q.NContrato<=ISNULL(@pmNContrato,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (E.Inactivo=ISNULL(@pmEmp_Inactivo,0) or E.Inactivo=ISNULL(@pmEmp_Inactivo,1))
 ORDER BY Q.IdEmpleado,Q.Numero,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVacNom]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomVacNom] @pmIdEmpleado VARCHAR(16),@pmFecIni SMALLDATETIME,@pmFecFin SMALLDATETIME
,@pmNContrato INT=Null
 AS 
 SELECT IdEmpleado,Numero,Fecha,NContrato,FecInicial,FecFinal,Cantidad,VrLiquida,VrBase
 FROM Trn_NomVac
 WHERE IdEmpleado=@pmIdEmpleado AND Anulado=0 AND FecInicial<=@pmFecFin AND FecFinal>=@pmFecIni
 AND (NContrato>=ISNULL(@pmNContrato,0)  AND NContrato<=ISNULL(@pmNContrato,2147483647))
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryNomVehiculos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomVehiculos] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT IdVehiculo,NumVeh,ClaseVeh,TipoAdmon,GrupoProp,VehPropio,CedCond,Conductor
 FROM NomVehiculos
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryNomZonasConv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNomZonasConv] @pmIdZona VARCHAR(4)
 AS 
 IF @pmIdZona IS NULL
  BEGIN
   SELECT IdZona,ZonaConv,Inactivo
   FROM NomZonasConv
   WHERE Inactivo=0
  END
 ELSE
  BEGIN
   SELECT IdZona,ZonaConv,Inactivo
   FROM NomZonasConv
   WHERE IdZona=@pmIdZona
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotaProd] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden,IdCCosto,IdSubCos,Modalidad,TipoProd
,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_NotaProd
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProd_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotaProd_Cr] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc AS Tip_Doc,TipoDoc,NumNota,N.IdCia AS CdCia,Compania,N.Fecha AS FechaDoc,N.IdConcepto AS CdConcepto,Concepto
,N.IdTercero AS NitTercero,RazonSocial,VrSubTotal,VrCostos,CantEnt,CantSal,N.NumOrden AS Num_Orden,N.IdCCosto AS CdCcosto,CC.CCosto AS NomCentCosto
,N.IdSubCos AS CdSubCent,SC.SubCosto AS SubcCosto,Modalidad,TipoProd,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,N.TimeSys AS Fec_Add,N.FecUpdate AS Fec_Update,IdCiaCrea,N.IdUsuario AS CdUsuario,Usuario,Leyenda
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,VrReteEnt,VrReteSal,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,pVehiculo,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,K.NumOrden AS KarNumOrden,IdCiaOrd,Cotizacion,IdCiaCot
,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_NotaProd AS N  INNER JOIN Trn_Kardex AS K ON N.TipDoc=K.TipDoc AND N.NumNota=K.Documento AND N.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd  
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TC ON N.TipCom=TC.IdCom
 WHERE N.TipDoc=@pmTipDoc AND NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
 ORDER BY NumNota,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProdLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotaProdLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmNumNotaIni INT=Null,@pmNumNotaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT NumNota,IdCia,Fecha,N.IdConcepto AS CdConcepto,Concepto,N.IdTercero AS NitTercero,RazonSocial,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden,N.IdCCosto AS CdCcosto,CCosto,IdSubCos
,Modalidad,TipoProd,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario
 FROM Trn_NotaProd AS N INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON  N.IdCCosto=CC.IdCCosto
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND NumNota BETWEEN ISNULL(@pmNumNotaIni,0) AND ISNULL(@pmNumNotaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND N.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProdOrd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotaProdOrd]  @pmNumOrden INT,@pmIdCia CHAR(2),@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT NumNota,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,VrCostos,CantEnt,CantSal,NumOrden,TipoProd,Modalidad
 FROM Trn_NotaProd
 WHERE  NumOrden=@pmNumOrden  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotaProdRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotaProdRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,NumNota,N.IdCia AS CdCia,Compania,Fecha,N.IdConcepto AS CdConcepto,Concepto,N.IdTercero AS NitTercero,RazonSocial,VrSubTotal,VrCostos
,CantEnt,CantSal,NumOrden,N.IdCCosto AS CdCcosto,CCosto,N.IdSubCos AS CdSubCent,SubCosto,Modalidad,TipoProd,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,N.FecUpdate AS Fec_Update,IdCiaCrea,N.IdUsuario AS CdUsuario,Usuario
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
 FROM Trn_NotaProd AS N  INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND N.IdCia LIKE ISNULL(@pmIdCia,'%%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND N.IdTercero LIKE ISNULL(@pmIdTercero,'%')  AND N.IdCCosto LIKE ISNULL(@pmIdCCosto ,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY N.IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCosto,VrSancion,VrOtros,VrNeto
,VrAplicado,VrAnticipo,Cantidad,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos
,IdVend,TarifaCom,CodTarCom,CdCajero,IdLocal,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,FecDcm,CdProducto,CdForma,NumCheque,CdBanco
,MulPlazos,IdPlazo,PrestCaja,Modalidad,nRemesa,CdCiaRem,ItemRem,VrReteCREE,TarifaRtc,CodTarRtc,IdConcFE,TipoNotaFE,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado
,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Notas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNotas_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotas_Cr] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc AS Tip_Doc,TipoDoc,NumNota,N.IdCia AS CdCia,Compania,N.Fecha AS FechaDoc,N.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,N.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,CodAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,N.VrCosto AS VrTotCosto,VrSancion,VrOtros,VrNeto
,VrAplicado,VrAnticipo,Cantidad,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv
,N.IdCCosto AS CdCentCosto,CC.CCosto AS NotCenCosto,N.IdSubCos AS CdSubCentro,SC.SubCosto AS NotSubCentro,N.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom
,N.IdLocal AS NotCdCiudad,LN.Localidad AS NotCiudad,N.Referencia AS NotReferencia,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,TipDcm,N.Documento AS NumDocmento,IdCiaDcm,FecDcm,nRemesa,CdCiaRem,ItemRem,CdProducto,DescripProd
,CdForma,N.NumCheque AS NroCheque,CdBanco,BN.Banco AS NomBanco,MulPlazos,N.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,PrestCaja,Modalidad,VrReteCREE,TarifaRtc,CodTarRtc,IdConcFE,N.TipoNotaFE,OrigenAdd
,N.TipCom AS CodTipoComp,TipoCom,N.Comprobante AS NumComprob,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,N.TimeSys AS Fec_Add,N.FecUpdate AS Fec_Update
,N.IdCiaCrea AS CodCiaCrea,N.IdUsuario AS IdUsuari,Usuario,Leyenda
--detalle del comprobante
,Item,D.IdCuenta AS CdCuenta,NomCuenta,Detalle,VrDebito,VrCredito,D.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,IdVehiculo,D.IdCCosto AS DetCodCentCost,DC.CCosto AS DetCentCost
,D.IdSubCos AS DetCodSubCentro,DS.SubCosto  AS DetSubCentro,VrBase,TarifaBase,D.TipDoc AS DetTipoDoc,D.Documento AS DetNumDoc,IdCiaDoc,TipFac,Factura,IdCiaFac,ItemFac
,FecVence,D.NumCheque AS DetNumCheque,TipoAplica,NitOtros,Referncia
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_Notas AS N INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON N.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON N.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON N.IdAgencia=A.IdAgencia  INNER JOIN Localidades  AS LN ON N.IdLocal=LN.IdLocal
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON N.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN ProdMcias  AS PM ON N.CdProducto=PM.IdProducto  LEFT JOIN Bancos AS BN ON N.CdBanco=BN.IdBanco
 LEFT JOIN TiposCom AS TCM ON N.TipCom=TCM.IdCom  LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS TC ON N.CdConductor=TC.IdTercero
 LEFT JOIN  Trn_ComDetalle AS D ON N.TipCom=D.TipCom AND N.Comprobante=D.Comprobante AND N.IdCiaCom=D.IdCia
 LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta LEFT JOIN Terceros AS DT ON D.IdTercero=DT.IdTercero
 LEFT JOIN CentroCosto AS DC ON D.IdCCosto=DC.IdCCosto LEFT JOIN SubCentros AS DS ON D.IdSubCos=DS.IdSubCos
 LEFT JOIN Trn_Face AS FE ON N.TipDoc=FE.TipDoc AND N.NumNota=FE.Documento AND N.IdCia=FE.IdCia
 WHERE N.TipDoc=@pmTipDoc AND NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
 ORDER BY  NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotas_DocElectronicos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


Create PROCEDURE [dbo].[paQryNotas_DocElectronicos] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT 
f.TipDoc, f.NumNota, f.IdCia, f.Fecha, f.IdConcepto, f.IdCliente, f.IdAgencia, f.FechaVence, f.VrSubTotal, f.VrImpuesto, f.VrRetencion, f.VrReteICA, f.VrReteIVA, f.VrCosto, f.VrSancion, f.VrOtros, f.VrNeto
, f.VrAplicado, f.VrAnticipo, f.Cantidad, f.BaseImp, f.BaseRet, f.BaseIca, f.BaseRiv, f.TarifaIva, f.TarifaRet, f.TarifaIca, f.TarifaRiv, f.CodTarIva, f.CodTarRet, f.CodTarIca, f.CodTarRiv, f.IdCCosto, f.IdSubCos
, f.IdVend, f.TarifaCom, f.CodTarCom, f.CdCajero, f.IdLocal, f.Referencia, f.pVehiculo, f.CdConductor, f.TipDcm, f.Documento, f.IdCiaDcm, f.FecDcm, f.CdProducto, f.CdForma, f.NumCheque, f.CdBanco
, f.MulPlazos, f.IdPlazo, f.PrestCaja, f.Modalidad, f.nRemesa, f.CdCiaRem, f.ItemRem, f.VrReteCREE, f.TarifaRtc, f.CodTarRtc, f.IdConcFE, f.TipoNotaFE, f.OrigenAdd, f.TipCom, f.Comprobante, f.IdCiaCom, f.Observacion, f.IdEstado
, f.TimeSys, f.FecUpdate, f.IdCiaCrea, f.IdUsuario
, CASE 
        WHEN FD.TipRem = 'RMT' THEN 'SI' 
        ELSE 'NO' 
    END AS 'REM'
 FROM Trn_Notas F
 LEFT JOIN Trn_TraFacRemesas as FD on FD.TipDoc = f.TipDoc and FD.Factura = f.NumNota and FD.IdCia = f.IdCia
 WHERE 
 f.TipDoc=@pmTipDoc AND 
 f.NumNota=@pmNumNota AND 
 f.IdCia=@pmIdCia
 
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasAcu]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasAcu] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT IdCliente,IdAgencia,IdCia,SUM(VrNeto) AS STOTNET
 FROM Trn_Notas
 WHERE  TipDoc='NCR' AND YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY  IdCliente,IdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBuses]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBuses] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,FecVence,IdConcepto,IdCliente,IdAgencia,IdVehiculo,IdConductor,VehPropio,ValorTotal,ValorIva,ValorReteFte,ValorReteIca,ValorCosto,ValorSancion,ValorNeto,ValorAplicado,IdVendedor
,Comision,IdTarCom,MulPlazos,IdPlazo,PrestCaja,IntMora,NumCheque,IdBanco,IdCCosto,IdClase,IdCargo,Referencia,TipDcm,Documento,IdCiaDoc,BaseIva,BaseRet,TarifaIva,TarifaRet,IdTarIva,IdTarRet,TipCom,Comprobante
,IdCiaCom,Observacion,IdEstado,IdConcFE,TipoNotaFE,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_NotasBuses
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBuses_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBuses_Cr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCargo VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmPrestCaja BIT=Null,@pmIntMora BIT=Null,@pmNumNotaIni INT=Null,@pmNumNotaFin INT=Null,@pmIdGrupo VARCHAR(4)=Null
AS
 SELECT TipDoc,NumNota,N.IdCia AS CodCia,Compania, Fecha,MulPlazos, N.IdPlazo AS codPlazo,Plazo,DiasPago,NVmto, FecVence, N.IdConcepto AS IdConcept,C.Concepto AS ConceptDoc, IdCliente,NP.RazonSocial AS Propietario,N.IdVehiculo AS PlacaVeh, N.IdConductor AS CedConductor
, NC.RazonSocial AS Conductor,ValorTotal, ValorIva, ValorReteFte,ValorReteIca, ValorNeto, ValorAplicado,NumCheque, N.IdBanco AS CodBanco,Banco,N.IdClase AS IdClas,ClaseCuenta, N.IdCargo AS CodCargo,F.Concepto AS ConceptCargo, Referencia, TipDcm, Documento, IdCiaDoc
 ,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ, N.IdEstado AS IdEstad,ED.Estado AS EstadDoc,N.IdUsuario AS IdUsuari,Usuario,TipoDoc,TipoNotaFE,IdConcFE,TimeSys, FecUpdate, IdCiaCrea,PrestCaja, IntMora,N.IdCCosto AS IdCcost,CCosto,BaseIva, BaseRet, TarifaIva, TarifaRet, IdTarIva
,IdTarRet,N.VehPropio AS VhPropio
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_NotasBuses AS N INNER JOIN  Companias  AS CI ON N.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON N.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON  N.IdUsuario=U.IdUsuario 
 INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo   INNER JOIN Terceros AS NP ON N.IdCliente=NP.IdTercero
 INNER JOIN Terceros AS NC ON N.IdConductor=NC.IdTercero  INNER JOIN BusClaseCue AS CU ON N.IdClase=CU.IdClase
 INNER JOIN Bancos AS B ON N.IdBanco=B.IdBanco INNER JOIN Fijos AS F ON N.IdCargo=F.IdCargo
 INNER JOIN Plazos AS PZ ON N.IdPlazo=PZ.IdPlazo INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN Sys_TiposDoc  AS TD ON N.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON N.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar  LEFT JOIN TiposCom AS TM ON N.TipCom=TM.IdCom
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  NumNota BETWEEN ISNULL(@pmNumNotaIni,0)  AND ISNULL(@pmNumNotaFin,2147483647)
 AND N.IdCia LIKE ISNULL(@pmIdCia,'%%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND N.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND N.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND N.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND N.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND N.IdUsuario LIKE ISNULL(@pmIdUsuario,'%') 
 AND (PrestCaja=ISNULL(@pmPrestCaja,0) or PrestCaja=ISNULL(@pmPrestCaja,1))
 AND (IntMora=ISNULL(@pmIntMora,0) or IntMora=ISNULL(@pmIntMora,1))
 AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY TipDoc,N.IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesCaj] @pmTipDoc VARCHAR(3),@pmFecha SMALLDATETIME
, @pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
AS
 SELECT  TipDoc,IdCia,IdUsuario,SUM(ValorNeto) AS STotNet
 FROM   Trn_NotasBuses WHERE PrestCaja<>0 AND Fecha=@pmFecha AND  TipDoc like ISNULL(@pmTipDoc,'%')  AND  IdCia like ISNULL(@pmIdCia ,'%%')
 AND IdUsuario like ISNULL(@pmIdUsuario,'%')
 GROUP BY TipDoc,IdCia,IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesCR_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesCR_Cr] @pmTipDoc VARCHAR(3), @pmNumNotaIni INT,@pmNumNotaFin INT, @pmIdCia CHAR(2)
AS
 SELECT  N.TipDoc AS TipoNota,TipoDoc,NumNota, N.IdCia AS CodCia,Compania, N.Fecha AS FechaNota,N.IdConcepto AS IdConcept,C.Concepto AS Concept, N.IdCliente AS NitPropietario,NP.RazonSocial AS Propietario, N.IdAgencia,N.IdVehiculo AS PlacaVeh, N.IdConductor AS CedConductor,NC.RazonSocial AS Conductor
, N.VehPropio AS VehEspropio, ValorTotal, ValorIva, ValorReteFte, ValorReteIca, ValorCosto, ValorSancion, ValorNeto, ValorAplicado, N.IdVendedor, N.Comision, IdTarCom,PrestCaja, IntMora,NumCheque,N.IdBanco, N.IdCCosto AS IdCCost,CCosto,N.Referencia AS RefNota
,TipDcm, N.Documento AS NDocumnt, N.IdCiaDoc AS CiaDocumnt, BaseIva, BaseRet, TarifaIva, TarifaRet, IdTarIva, IdTarRet, N.TipCom AS IdTipCom,TM.TipoCom AS TipoComprobante, Comprobante, IdCiaCom,N.IdConcFE, N.Observacion AS Observ, N.IdEstado AS IdEstadDoc,ED.Estado AS EstadDoc, N.TimeSys, FecUpdate, IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario,Leyenda
,Item,RF.TipDoc AS TipoDocApl,RF.Documento AS NCausacionApl,RF.IdCiaDoc AS CiaDocApl,ItemDoc,RF.IdCargo AS CodCargo,F.Concepto AS Cargo,RF.IdClase AS CodClase,ClaseCuenta,ValorAbono,Detalle,FecPago
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM Trn_NotasBuses AS N INNER JOIN Trn_RecFactura AS RF ON N.TipDoc=RF.TipRec AND N.NumNota=RF.Recibo AND N.IdCia=RF.IdCia
 INNER JOIN Sys_TiposDoc  AS TD ON N.TipDoc=TD.IdDoc  INNER JOIN Companias  AS CI ON N.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON N.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NP ON N.IdCliente=NP.IdTercero   INNER JOIN Terceros AS NC ON N.IdConductor=NC.IdTercero
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto  INNER JOIN Fijos AS F ON RF.IdCargo=F.IdCargo
 INNER JOIN BusClaseCue AS CU ON  RF.IdClase=CU.IdClase
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON N.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN TiposCom AS TM ON N.TipCom=TM.IdCom
 WHERE N.TipDoc=@pmTipDoc AND NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin   AND N.IdCia=@pmIdCia
ORDER BY N.IdCia,NumNota,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesDb_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesDb_Cr] @pmTipDoc VARCHAR(3), @pmNumNotaIni INT,@pmNumNotaFin INT, @pmIdCia CHAR(2)
AS
 SELECT  N.TipDoc AS TipoNota,TipoDoc,NumNota, N.IdCia AS CodCia,Compania, Fecha, N.FecVence AS FecVenceNota,N.IdConcepto AS IdConcept,C.Concepto AS Concept, N.IdCliente AS NitPropietario,NP.RazonSocial AS Propietario, N.IdAgencia,N.IdVehiculo AS PlacaVeh, N.IdConductor AS CedConductor,NC.RazonSocial AS Conductor
, N.VehPropio AS VehEspropio, ValorTotal, ValorIva, ValorReteFte, ValorReteIca, ValorCosto, ValorSancion, ValorNeto, ValorAplicado, N.IdVendedor, N.Comision, IdTarCom, MulPlazos, N.IdPlazo AS IdPlzo,Plazo,DiasPago,NVmto, PrestCaja, IntMora,NumCheque, N.IdBanco AS CodBanco,Banco, N.IdCCosto AS IdCCost,CCosto,N.Referencia AS RefNota
,TipDcm, N.Documento AS NDocumnt, IdCiaDoc, BaseIva, BaseRet, TarifaIva, TarifaRet, IdTarIva, IdTarRet, N.TipCom AS IdTipCom,TM.TipoCom AS TipoComprobante, Comprobante, IdCiaCom, N.Observacion AS Observ, N.IdEstado AS IdEstadDoc,ED.Estado AS EstadDoc,N.IdConcFE, TimeSys, FecUpdate, IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario,Leyenda
,Item,VF.FecVence AS FecVenceFac,ValorFactura,ValorAbono,VF.IdCargo AS IdCarg,F.Concepto AS NomCargo,VF.IdClase AS CodClase,ClaseCuenta,FecUltPago,Factura,VF.Referencia AS RefVce
,Detalle,TipRec,Recibo,IdCiaRec,ValorAtcpo
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM Trn_NotasBuses  AS N  INNER JOIN Trn_CausacVence AS VF ON N.TipDoc = VF.TipDoc AND N.NumNota= VF.Documento AND N.IdCia =VF.IdCia
 INNER JOIN Sys_TiposDoc  AS TD ON N.TipDoc=TD.IdDoc  INNER JOIN Companias  AS CI ON N.IdCia=CI.IdCia
 INNER JOIN Conceptos AS C ON N.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario  INNER JOIN Plazos AS PZ ON N.IdPlazo=PZ.IdPlazo 
 INNER JOIN Vehiculos AS V ON N.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS NP ON N.IdCliente=NP.IdTercero 
 INNER JOIN Terceros AS NC ON N.IdConductor=NC.IdTercero INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN  Bancos AS B ON N.IdBanco=B.IdBanco  INNER JOIN Fijos AS F ON VF.IdCargo=F.IdCargo
 INNER JOIN BusClaseCue AS CU ON VF.IdClase=CU.IdClase
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON N.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN TiposCom AS TM ON N.TipCom=TM.IdCom
WHERE N.TipDoc=@pmTipDoc AND NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin   AND N.IdCia=@pmIdCia
ORDER BY N.IdCia,NumNota,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesLta] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCliente VARCHAR(16),@pmIdVehiculo VARCHAR(10)
AS
 SELECT NumNota,IdCia,Fecha,FecVence,N.IdConcepto AS IdConcept,Concepto,IdCliente,T.RazonSocial AS Cliente, IdAgencia, IdVehiculo, IdConductor,O.RazonSocial AS Conductor,VehPropio, ValorTotal, ValorIva, ValorReteFte
,ValorReteIca, ValorCosto, ValorSancion, ValorNeto, ValorAplicado, IdVendedor,V.RazonSocial AS Vendedor,N.Comision AS Comison, IdTarCom, MulPlazos, N.IdPlazo AS IdPlaz,DiasPago AS Dias, PrestCaja, IntMora
,NumCheque,N.IdBanco AS IdBanc,Banco, IdCCosto, N.IdClase AS IdClas,IdCargo,Referencia,N.IdConcFE,N.TipoNotaFE,TipDcm,Documento,IdCiaDoc,BaseIva, BaseRet, TarifaIva, TarifaRet, IdTarIva
,IdTarRet, TipCom, Comprobante, IdCiaCom, N.Observacion AS Observ, N.IdEstado AS IdEstad,Estado,TimeSys, FecUpdate, IdCiaCrea,N.IdUsuario AS IdUsuari
 FROM Trn_NotasBuses AS N INNER JOIN Conceptos AS C ON N.IdConcepto=C.IdConcepto
  INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero  INNER JOIN Terceros AS O ON N.IdConductor=O.IdTercero
  LEFT JOIN Terceros AS V ON N.IdVendedor=V.IdTercero  LEFT JOIN Plazos AS P ON N.IdPlazo=P.IdPlazo
  LEFT JOIN Bancos AS B ON N.IdBanco=B.IdBanco LEFT JOIN EstadoDoc AS E ON N.IdEstado=E.IdEstado
 WHERE TipDoc=@pmTipDoc AND  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesNMes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesNMes] @pmAnno INT,@pmMes INT=Null, @pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdClase VARCHAR(4)=Null, @pmTipDoc VARCHAR(3)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT IdCliente,IdVehiculo,IdCia,IdClase,Month(Fecha) AS NMes,SUM(ValorTotal) AS SvalTot,SUM(ValorNeto) AS SValNet
 FROM   Trn_NotasBuses 
 WHERE Year(Fecha)=@pmAnno AND Month(Fecha)=ISNULL(@pmMes,Month(Fecha))  AND  IdCia like ISNULL(@pmIdCia,'%%') 
 AND IdCliente like ISNULL(@pmIdCliente,'%') AND IdClase like ISNULL(@pmIdClase,'%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 GROUP BY  IdCliente,IdVehiculo,IdCia,IdClase,Month(Fecha)
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesTotCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesTotCaj]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmCdCajero VARCHAR(11)=Null
AS
 SELECT  TipDoc,SUM(ValorNeto) AS STotNet
 FROM   Trn_NotasBuses WHERE PrestCaja<>0 AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmCdCajero,'%')
 GROUP BY TipDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesVc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesVc] @pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
  SELECT  TipDoc, NumNota, IdCia, Fecha, FecVence, IdConcepto, IdCliente, IdAgencia, IdVehiculo, IdConductor, VehPropio, ValorTotal,ValorNeto, ValorAplicado
, IdVendedor, Comision,IdClase,IdCargo,Referencia,TipDcm, Documento, IdCiaDoc
 FROM Trn_NotasBuses 
 WHERE TipDoc='NC1' AND  IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasBusesVFec]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasBusesVFec] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdClase VARCHAR(4)=Null, @pmTipDoc VARCHAR(3)=Null
AS
 SELECT IdCliente,IdVehiculo,SUM(ValorTotal) AS SvalTot,SUM(ValorNeto) AS SValNet
 FROM   Trn_NotasBuses 
 WHERE Fecha  BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia like ISNULL(@pmIdCia,'%%') 
 AND IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdClase like ISNULL(@pmIdClase,'%') AND TipDoc like ISNULL(@pmTipDoc,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY IdCliente,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasCaj] @pmFecha SMALLDATETIME,@pmIdCia CHAR(2),@pmCdCajero VARCHAR(11)
 AS 
 SELECT TipDoc,IdCia,CdCajero,SUM(VrSubTotal) AS SSUBTOT,SUM(VrNeto) AS SNETO,SUM(VrOtros) AS STOTCAJ
 FROM Trn_Notas 
 WHERE PrestCaja<>0 AND Fecha=@pmFecha AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND CdCajero LIKE ISNULL(@pmCdCajero,'%')
 GROUP BY TipDoc,IdCia,CdCajero
 ORDER BY IdCia,CdCajero
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasDoc]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasDoc] @pmTipDoc VARCHAR(3),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2)
,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrNeto
,TipCom,Comprobante,IdCiaCom
 FROM Trn_Notas
 WHERE TipDoc=@pmTipDoc  AND TipDcm=@pmTipDcm AND Documento=@pmDocumento AND IdCiaDcm=@pmIdCiaDcm
AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasDocumentoSOP40_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Heiman Daza Tamayo
-- Create date(dd/MM/yyyy): 28/07/2022
-- Description:	procedimiento que busca un documento soporte para ser enviada a la DIAN en Syscom40 (Documentos Electronicos).
-- =============================================
CREATE PROCEDURE [dbo].[paQryNotasDocumentoSOP40_Cr]
	@pmTipDoc VARCHAR(3),--Tipo de documento que se desea buscar
	@pmDocumento INT, --Número de documento que se desea buscar
	@pmIdCia CHAR(2) --Compañía de documento que se desea buscar
AS
BEGIN
SELECT S.TipDoc,S.NumDoc,S.IdCia,S.FecDev Fecha,S.FecDev FechaVence,S.TimeSys,S.idTercero, T.RazonSocial NomTercero,S.ValorTotal,S.SubTotal,S.OtrosDctos,S.OtrosCargos,D.VrDcto,S.Observacion,MetPago,IdMedPago,OrigenAdd,
Item,D.IdProducto,ISNULL(P.CodFEDian,D.IdProducto) CodProductoDIAN,Descripcion,Cantidad,'94' CdUndMed,VrUnitario,VrDcto,TarifaDct,CASE WHEN D.TarifaRet = 0 THEN S.TarifaRet ELSE D.TarifaRet END TarifaRet,CASE WHEN D.TarifaIca = 0 THEN S.TarifaIca ELSE D.TarifaIca END TarifaIca,D.TarifaBom,D.TarifaAvta,CodTarDct,D.CodTarRet,
D.CodTarIca,D.CodTarifBom,D.CodTarifAvta,S.OrigenAdd,'COP' CdMoneda,
--Inforamción de factura electrónica
FE.EstadoFE,FE.Prefijo,CAST(FE.NumFace AS DECIMAL(16, 2)) NumDocSOP,FE.CUFE CUDS,FE.Resolucion,FE.RangoNum,FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion
FROM Trn_DocSoporte S
INNER JOIN Trn_DocSoporteDet D ON S.TipDoc=D.TipDoc AND S.NumDoc=D.NumDoc AND S.IdCia=D.IdCia
INNER JOIN Terceros AS T ON S.idTercero = T.IdTercero
LEFT JOIN ProdMcias AS P ON D.IdProducto = P.IdProducto
LEFT JOIN Trn_Face AS FE ON S.TipDoc=FE.TipDoc AND S.NumDoc=FE.Documento AND S.IdCia=FE.IdCia
WHERE S.Anulado = 1 AND S.TipDoc=@pmTipDoc AND S.NumDoc=@pmDocumento AND S.IdCia=@pmIdCia
END
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmNotaIni INT=Null,@pmNotaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT NumNota,IdCia,Fecha,N.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrCosto,VrSancion,VrOtros,VrNeto
,VrAplicado,VrAnticipo,Cantidad,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,N.IdCCosto AS CodCcosto,CCosto,IdSubCos,IdVend,V.RazonSocial AS Vendedor
,TarifaCom,CodTarCom,CdCajero,N.IdLocal AS CodCiudad,Localidad,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,FecDcm,nRemesa,CdCiaRem,ItemRem,CdProducto,Modalidad,PrestCaja
,CdForma,NumCheque,CdBanco,MulPlazos,IdPlazo,VrReteCREE,TarifaRtc,CodTarRtc,IdConcFE,TipoNotaFE,OrigenAdd,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_Notas AS N  INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON N.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON N.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario 
 INNER JOIN   CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON N.IdLocal=L.IdLocal
 WHERE TipDoc=@pmTipDoc   AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND NumNota BETWEEN ISNULL(@pmNotaIni,0) AND ISNULL(@pmNotaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdCCosto  VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,NumNota,N.IdCia AS CdCia,Compania,Fecha,N.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,N.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,CodAgencia,FechaVence,VrSubTotal,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,N.VrCosto AS ValCosto,VrSancion,VrOtros,VrNeto
,VrAplicado,VrAnticipo,Cantidad,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv
,N.IdCCosto AS CdCentCosto,CCosto,N.IdSubCos AS CdSubCentro,SubCosto,N.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom
,N.IdLocal AS NotCdCiudad,LN.Localidad AS NotCiudad,N.Referencia AS NotReferencia,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,TipDcm
,Documento,IdCiaDcm,FecDcm,nRemesa,CdCiaRem,ItemRem,CdProducto,DescripProd,CdForma,NumCheque,CdBanco,BN.Banco AS NomBanco,MulPlazos,N.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,PrestCaja,Modalidad,OrigenAdd
,TipCom,Comprobante,IdCiaCom,VrReteCREE,TarifaRtc,CodTarRtc,N.IdConcFE,N.TipoNotaFE,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,N.FecUpdate AS Fec_Update,IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,CdFntePago,FuentePago
 FROM Trn_Notas AS N INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON N.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON N.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON N.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON N.IdAgencia=A.IdAgencia  INNER JOIN Localidades  AS LN ON N.IdLocal=LN.IdLocal
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON N.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN ProdMcias  AS PM ON N.CdProducto=PM.IdProducto  LEFT JOIN Bancos AS BN ON N.CdBanco=BN.IdBanco
 LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos LEFT JOIN Terceros AS TC ON N.CdConductor=TC.IdTercero
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND N.IdCia LIKE ISNULL(@pmIdCia,'%%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND N.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND N.IdVend LIKE ISNULL(@pmIdVend,'%') 
 AND N.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY N.IdCia,NumNota
GO
/****** Object:  StoredProcedure [dbo].[paQryNotasTotCaj]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryNotasTotCaj] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmCdCajero VARCHAR(11)=Null
 AS 
 SELECT TipDoc,SUM(VrSubTotal) AS SSUBTOT,SUM(VrNeto) AS SNETO,SUM(VrOtros) AS STOTCAJ
 FROM Trn_Notas 
 WHERE PrestCaja<>0 AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND CdCajero LIKE ISNULL(@pmCdCajero,'%')
 GROUP BY TipDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryNovedadRep]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNovedadRep] @pmIdNov VARCHAR(4)
 AS 
 IF @pmIdNov IS NULL
  SELECT IdNov,Novedad
  FROM NovedadRep
  WHERE Inactivo=0
  ORDER BY IdNov
 ELSE
  SELECT IdNov,Novedad,Inactivo
  FROM NovedadRep
  WHERE IdNov=@pmIdNov
GO
/****** Object:  StoredProcedure [dbo].[paQryNovedadTra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryNovedadTra] @pmIdNovedad VARCHAR(4)
 AS 
 IF @pmIdNovedad IS NULL
  SELECT IdNovedad,Novedad
  FROM NovedadTra
  WHERE Inactivo=0
  ORDER BY IdNovedad
 ELSE
  SELECT IdNovedad,Novedad,Inactivo
  FROM NovedadTra
  WHERE IdNovedad=@pmIdNovedad
GO
/****** Object:  StoredProcedure [dbo].[paQryObjetosApp]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryObjetosApp] @pmIdObj VARCHAR(10)
 AS 
 SELECT IdObj,IdGrupo,SubModulo,IndObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo
 FROM Sys_ObjetosApp
 WHERE IdObj=@pmIdObj
GO
/****** Object:  StoredProcedure [dbo].[paQryObjetosAppLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryObjetosAppLta] @pmNivelMinimo INT,@pmIdGrupo VARCHAR(6)=Null
,@pmSubModulo VARCHAR(3)=Null,@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT O.IdGrupo AS IdGrup,GrupoObjeto,SubModulo,IndObj,IdObj,Nombre,Formulario,Permisos,NivelMinimo,NomArchivo
 FROM Sys_ObjetosApp AS O INNER JOIN Sys_GruposObj AS G ON O.IdGrupo=G.IdGrupo
 WHERE NivelMinimo<=@pmNivelMinimo AND O.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') 
 AND SubModulo LIKE ISNULL(@pmSubModulo,'%') AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY nModulo,O.IdGrupo,SubModulo,IndObj
GO
/****** Object:  StoredProcedure [dbo].[paQryObjetosAppSub]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryObjetosAppSub] @pmIdGrupo VARCHAR(6)=Null
 AS
 SELECT   SubModulo,Count(IndObj) AS CantInd
 FROM     Sys_ObjetosApp 
 WHERE IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 GROUP BY SubModulo
GO
/****** Object:  StoredProcedure [dbo].[paQryOComb]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOComb] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,OCargue,IdCia,Fecha,FechaDesp,FechaVence,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto
,VrSobretasa,VrImpGlobal,VrNeto,Cantidad,VrImpCarbono,VrIvaIngProd,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocal,LugarEnv,DiasEntraga,IdVehiculo,IdConductor,NitEmpTrans,EmpTrans
,CdRuta,Referncia,IdForma,DetallePago,MulPlazos,IdPlazo,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,Factura,IdCiaFac,FechaFact,AutzaMora,AutzaCupo,Aprobacion,FechaAprob
,DetalleAprob,CdUsuAprob,OrigenAdd,ZonaFrontera,TipoOrden,IdTerminal,Remolque,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_OComb
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOComb_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOComb_Cr] @pmTipDoc VARCHAR(3),@pmOCargueIni INT,@pmOCargueFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc AS Tip_Doc,TipoDoc,OCargue,O.IdCia AS CdCia,Compania,O.Fecha AS FechaDoc,FechaDesp,FechaVence
,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia
,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrImpCarbono,O.VrIvaIngProd,VrNeto
,Cantidad,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,DiasEntraga,O.IdVehiculo AS PlacaVeh,O.IdConductor AS CedConductor,TC.RazonSocial AS Conductor,LibMilitar,ClaseLib,FechaLib,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,NumTarjeta,VigTarjeta
,O.NitEmpTrans,EmpTrans,CdRuta,Ruta,Referncia,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos
,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact,AutzaMora,AutzaCupo
,Aprobacion,FechaAprob,DetalleAprob,CdUsuAprob,UA.Usuario AS UsuarioAprob,OrigenAdd,IdTerminal,ZonaFrontera,TipoOrden,Remolque,Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,Leyenda
,O.TimeSys AS Fec_Add,O.FecUpdate AS Fech_Update,IdCiaCrea
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,CLI.NumCuenta AS NumeroCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--vehiculo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarcaVeh,MV.Marca AS MarcaVeh,Modelo,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,CarrCapac,V.UndCapc AS UnidCapacidad,Comptmtos,CapComp
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,K.Descripcion AS KarDescripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,K.Remision AS KarRemision,K.IdCiaRem AS CdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev
,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,K.ListaPrec AS KarLtaPrec,VrBase,BaseIvp,TarifaIvp,IvaIngProd,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,M.Marca AS MarcaProd,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
,A.codsicom,DM.Comentarios
 FROM  Trn_OComb AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCargue=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN Terceros AS TC ON O.IdConductor=TC.IdTercero
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN adm_Usuarios AS UA ON O.CdUsuAprob=UA.IdUsuario
 LEFT JOIN TercCndtores AS TCD ON O.IdConductor=TCD.IdConductor
 LEFT JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo
 LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca
 LEFT JOIN Trn_DocMemo DM On O.TipDoc=DM.TipDoc AND O.Ocargue=DM.Documento AND O.idcia=DM.Idcia
  WHERE O.TipDoc=@pmTipDoc AND OCargue BETWEEN @pmOCargueIni AND @pmOCargueFin AND O.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY OCargue,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCombDet] @pmOCargue INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Item,K.IdProducto AS CdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Salidas,VrPrecio,Salidas*VrPrecio AS VrSubTotal,Comptmntos
,VrBruto,K.ListaPrec AS LtaPrec,VrBase,K.Referencia AS Referncia,Unidades,K.IdVend AS NitVend,V.RazonSocial AS Vendedor,Comision,K.CodTarCom AS CdTarifCom
,DescripProd,Servcios,Tanques,O.Fecha AS FecOCargue,FechaDesp,FechaVence,IdCliente,T.RazonSocial AS Cliente,IdAgencia,DirEnvio,LugarEnv
,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor,NitEmpTrans,EmpTrans,Referncia,Referencia2,Pedido,IdCiaPed,Guia,IdCiaGui,O.Factura AS NumFactura,IdCiaFac,FechaFact
,O.Observacion AS Observ
 FROM Trn_OComb AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCargue=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN Terceros AS V ON K.IdVend=V.IdTercero
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS CD ON O.IdConductor=CD.IdTercero
 WHERE OCargue=@pmOCargue AND O.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombFac]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCombFac]  @pmFactura INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT OCargue,IdCia,Fecha,T.RazonSocial AS NomCliente,IdCliente,IdAgencia,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor,FechaDesp,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrNeto
,Cantidad,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio,O.IdLocal AS CdCiudad,Localidad,LugarEnv,DiasEntraga,O.IdConcepto AS CdConcepto,Concepto,NitEmpTrans,EmpTrans,CdRuta,Referncia,IdForma,DetallePago,MulPlazos,IdPlazo
,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,Factura,IdCiaFac,FechaFact,AutzaMora,AutzaCupo,Aprobacion,FechaAprob,DetalleAprob,CdUsuAprob,OrigenAdd,Anulado,FecDev
,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.IdUsuario AS IdUsuari,Usuario,TimeSys,IdCiaCrea,FecUpdate,TipDoc
 FROM Trn_OComb AS O  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON O.IdVend=V.IdTercero
 INNER JOIN Terceros AS CD ON O.IdConductor=CD.IdTercero
 INNER JOIN  Conceptos AS CN ON O.IdConcepto=CN.IdConcepto
 INNER JOIN Localidades AS L ON O.IdLocal=L.IdLocal
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  Anulado=0 AND Factura<=@pmFactura
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')   AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 ORDER BY IdCia,OCargue
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombFact]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCombFact] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmOrdenIni INT=Null,@pmOrdenFin INT=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmIdProducto VARCHAR(16)=Null,@pmFechaFacIni SMALLDATETIME=Null,@pmFechaFacFin SMALLDATETIME=Null
 AS 
 SELECT  OCargue,O.IdCia AS CdCia,Compania,O.Fecha AS FechaOrd,FechaDesp,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantOrden,SUM(Unidades) AS Unidades
--datos de la factura
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas
,TotalUnidades,FacTarifSob,FacTarifSol,FacTarifIglobal
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor
,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,O.IdVehiculo AS PlacaVeh,Referncia,Aprobacion,FechaAprob,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui
,O.Observacion AS Observ,DetallePago,O.IdEstado AS CdEstado,Estado
,MAX(VrPrecio) AS OrdValorUnit,SUM(Salidas*VrPrecio) AS OrdValorTotal,MAX(Sobretasa) AS TarifSobtasa,MAX(Soldicom) AS TarifSoldicom,MAX(ImpGlobal) AS TarifIglobal
 FROM  Trn_OComb AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero  INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado 
 INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia 
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCargue=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT  TipOrd,NumOrden,IdCiaOrd,K.TipDoc AS TipoFact,K.Documento AS NumFactura,K.IdCia AS CdCiaFac,KC.Compania AS NomCiaFac
,K.Fecha AS FecFactura,Remision,IdCiaRem,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd
,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaEnt) AS IvaEntradas
,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoEnt) AS DctoEntradas,SUM(VrDctoSal) AS DctoSalidas,SUM(K.Unidades) AS TotalUnidades
,MAX(Sobretasa) AS FacTarifSob,MAX(Soldicom) AS FacTarifSol,MAX(ImpGlobal) AS FacTarifIglobal
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE NoVentas BETWEEN 1  AND 4  AND TipOrd='OCC'  AND  NumOrden>0 
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaFacIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFacFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY TipOrd,NumOrden,IdCiaOrd,K.TipDoc,K.Documento,K.IdCia,KC.Compania,K.Fecha,Remision,IdCiaRem,K.IdProducto,PM.DescripProd) AS FA 
 ON O.TipDoc=FA.TipOrd AND O.OCargue=FA.NumOrden AND O.IdCia=FA.IdCiaOrd AND K.IdProducto=FA.CdProducto
 WHERE  O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%') AND O.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND OCargue  BETWEEN ISNULL(@pmOrdenIni,0) AND ISNULL(@pmOrdenFin,2147483647)
 GROUP BY  OCargue,O.IdCia,Compania,O.Fecha,FechaDesp,FechaVence,K.IdProducto,DescripProd
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas
,TotalUnidades,FacTarifSob,FacTarifSol,FacTarifIglobal
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,O.IdVend,VN.RazonSocial
,O.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,LugarEnv,O.IdVehiculo,Referncia,Aprobacion,FechaAprob,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui
,O.Observacion,DetallePago,O.IdEstado,Estado
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombGui]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOCombGui]  @pmGuia INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT OCargue,IdCia,Fecha,T.RazonSocial AS NomCliente,IdCliente,IdAgencia,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor
,FechaDesp,FechaVence,O.IdConcepto AS CdConcepto,Concepto,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrNeto
,Cantidad,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio,O.IdLocal AS CdCiudad,Localidad,LugarEnv,DiasEntraga,NitEmpTrans,EmpTrans,CdRuta,Referncia,IdForma,DetallePago,MulPlazos,IdPlazo
,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,Factura,IdCiaFac,FechaFact,TipoOrden,AutzaMora,AutzaCupo,Aprobacion,FechaAprob,DetalleAprob,CdUsuAprob,OrigenAdd,Anulado,FecDev
,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.IdUsuario AS IdUsuari,Usuario,TimeSys,IdCiaCrea,FecUpdate,TipDoc
 FROM Trn_OComb AS O  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON O.IdVend=V.IdTercero
 INNER JOIN Terceros AS CD ON O.IdConductor=CD.IdTercero
 INNER JOIN  Conceptos AS CN ON O.IdConcepto=CN.IdConcepto
 INNER JOIN Localidades AS L ON O.IdLocal=L.IdLocal
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  Anulado=0 AND Factura<=0
 AND Guia<=@pmGuia
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')   AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 ORDER BY IdCia,OCargue
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCombGuia] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmOrdenIni INT=Null,@pmOrdenFin INT=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmIdProducto VARCHAR(16)=Null,@pmFechaGuiIni SMALLDATETIME=Null,@pmFechaGuiFin SMALLDATETIME=Null
,@pmFacturaIni INT=Null,@pmFacturaFin INT=Null
 AS 
 SELECT  OCargue,O.IdCia AS CdCia,Compania,O.Fecha AS FechaOrd,FechaDesp,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantOrden,SUM(Unidades) AS Unidades
--datos de la guía
,NumGuia,CdCiaGui,NomCiaGui,FecGuia,CantSalidas,TotalUnidades,FechaDesGui,GuiLugar,HorasVig,GuiTipFact,GuiFactura,GuiCiaFac,GuiFechaFac
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor
,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,O.IdVehiculo AS PlacaVeh,Referncia,Aprobacion,FechaAprob,TipPed,Pedido,IdCiaPed,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact
,O.Observacion AS Observ,DetallePago,O.IdEstado AS CdEstado,Estado
,MAX(VrPrecio) AS OrdValorUnit,SUM(Salidas*VrPrecio) AS OrdValorTotal,MAX(Sobretasa) AS TarifSobtasa,MAX(Soldicom) AS TarifSoldicom,MAX(ImpGlobal) AS TarifIglobal
 FROM  Trn_OComb AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero  INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado 
 INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia 
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCargue=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN  (SELECT  TipOrd,NumOrden,IdCiaOrd,K.Documento AS NumGuia,K.IdCia AS CdCiaGui,KC.Compania AS NomCiaGui,K.Fecha AS FecGuia,K.IdProducto AS CdProducto
,PM.DescripProd AS NombreProd,SUM(Salidas) AS CantSalidas,SUM(Unidades) AS TotalUnidades,G.FechaDesp AS FechaDesGui,G.LugarEnv AS GuiLugar,HorasVig
,G.TipFac AS GuiTipFact,G.Factura AS GuiFactura,G.IdCiaFac AS GuiCiaFac,G.FechaFact AS GuiFechaFac
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN Trn_Guia AS G ON K.TipDoc=G.TipDoc AND K.Documento=G.Guia AND K.IdCia=G.IdCia
 WHERE  K.TipDoc='GUI' AND TipOrd='OCC' AND NumOrden>0 AND  Anulado=0 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (G.Fecha>=ISNULL(@pmFechaGuiIni,CAST('19100101' AS SMALLDATETIME)) AND G.Fecha<=ISNULL(@pmFechaGuiFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY  TipOrd,NumOrden,IdCiaOrd,K.Documento,K.IdCia,KC.Compania,K.Fecha,K.IdProducto,PM.DescripProd,FechaDesp,G.LugarEnv,HorasVig
,G.TipFac,G.Factura,G.IdCiaFac,G.FechaFact) AS GU
  ON O.TipDoc=GU.TipOrd AND O.OCargue=GU.NumOrden AND O.IdCia=GU.IdCiaOrd AND K.IdProducto=GU.CdProducto
  WHERE  O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%') AND O.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND OCargue  BETWEEN ISNULL(@pmOrdenIni,0) AND ISNULL(@pmOrdenFin,2147483647)
 AND O.Factura BETWEEN ISNULL(@pmFacturaIni,-1) AND ISNULL(@pmFacturaFin,2147483647)
 GROUP BY  OCargue,O.IdCia,Compania,O.Fecha,FechaDesp,FechaVence,K.IdProducto,DescripProd
,NumGuia,CdCiaGui,NomCiaGui,FecGuia,CantSalidas,TotalUnidades,FechaDesGui,GuiLugar,HorasVig,GuiTipFact,GuiFactura,GuiCiaFac,GuiFechaFac
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,O.IdVend,VN.RazonSocial
,O.IdLocal,LE.Localidad,LE.IdDep,DE.Departamento,LugarEnv,O.IdVehiculo,Referncia,Aprobacion
,FechaAprob,TipPed,Pedido,IdCiaPed,TipFac,O.Factura,IdCiaFac,FechaFact
,O.Observacion,DetallePago,O.IdEstado,Estado
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOCombLta]  @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmOCargueIni INT=Null,@pmOCargueFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT OCargue,IdCia,Fecha,FechaDesp,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrImpCarbono,VrIvaIngProd,VrNeto
,Cantidad,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio,O.IdLocal AS CdCiudad,Localidad,LugarEnv,DiasEntraga,IdVehiculo,IdConductor,CD.RazonSocial AS Conductor,NitEmpTrans,EmpTrans,CdRuta,Referncia,IdForma,DetallePago,MulPlazos,IdPlazo
,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,Factura,IdCiaFac,FechaFact,AutzaMora,AutzaCupo,Aprobacion,FechaAprob,DetalleAprob,CdUsuAprob,OrigenAdd,Anulado,FecDev
,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,ZonaFrontera,IdTerminal,TipoOrden,Remolque,O.IdUsuario AS IdUsuari,Usuario,TimeSys,IdCiaCrea,FecUpdate,TipDoc
 FROM Trn_OComb AS O  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON O.IdVend=V.IdTercero
 INNER JOIN Terceros AS CD ON O.IdConductor=CD.IdTercero
 INNER JOIN  Conceptos AS CN ON O.IdConcepto=CN.IdConcepto
 INNER JOIN Localidades AS L ON O.IdLocal=L.IdLocal
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND OCargue BETWEEN ISNULL(@pmOCargueIni,0) AND ISNULL(@pmOCargueFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,OCargue
GO
/****** Object:  StoredProcedure [dbo].[paQryOCombRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOCombRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null
,@pmIdConductor VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,OCargue,O.IdCia AS CdCia,Compania,Fecha,FechaDesp,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrImpCarbono,VrNeto
,Cantidad,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,O.IdLocal AS CdCiudad,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,LugarEnv,DiasEntraga,O.IdVehiculo AS PlacaVeh,O.IdConductor AS CedConductor,TC.RazonSocial AS Conductor,LibMilitar,ClaseLib,FechaLib,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,NumTarjeta,VigTarjeta
,O.NitEmpTrans,EmpTrans,CdRuta,Ruta,Referncia,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos
,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,TipPed,Pedido,IdCiaPed,TipGui,Guia,IdCiaGui,TipFac,Factura,IdCiaFac,FechaFact,AutzaMora,AutzaCupo
,Aprobacion,FechaAprob,DetalleAprob,CdUsuAprob,UA.Usuario AS UsuarioAprob,OrigenAdd,ZonaFrontera,TipoOrden,Remolque,Anulado,FecDev,O.Observacion AS Observ,IdTerminal,O.IdEstado AS CdEstado,Estado,O.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
,TimeSys,O.FecUpdate AS Fech_Update,IdCiaCrea
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,CLI.NumCuenta AS NumeroCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--vehiculo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarcaVeh,MV.Marca AS MarcaVeh,Modelo,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,CarrCapac,V.UndCapc AS UnidCapacidad,Comptmtos,CapComp
 FROM  Trn_OComb AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN Terceros AS TC ON O.IdConductor=TC.IdTercero
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON O.IdLocal=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN adm_Usuarios AS UA ON O.CdUsuAprob=UA.IdUsuario
 LEFT JOIN TercCndtores AS TCD ON O.IdConductor=TCD.IdConductor
 LEFT JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo
 LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca
  WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,OCargue
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOCompra] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,OCompra,IdCia,Fecha,FechaVence,IdConcepto,IdProv,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobtasa,VrImpGlobal,VrNeto
,VrRetencion,VrReteICA,TarifaRet,TarifaIca,CodTarRet,CodTarIca,Cantidad,IdEmpresa,DirEntrega,IdLocEtga,DiasEntraga,NitContac,NomContac,TelContac,emlContac
,IdCCosto,IdSubCos,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans
,EmpTrans,LiqFletes,pVehiculo,CdConductor,TipEnt,Entrada,IdCiaEnt,NumAutoriza,Modalidad,Vigencia,OrigenAdd,Anulado,FecDev,Observacion,VrReteIVA,CodTarRiv,VrImpuBA,VrImpuCUP,NumDocSop,CdCiaSop
,NumAprob,FecAprob,CdUsuAprob,NivelAprob,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_OCompra
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompra_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryOCompra_Cr] @pmTipDoc VARCHAR(3),@pmOCompraIni INT,@pmOCompraFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc AS Tip_Doc,TipoDoc,OCompra,O.IdCia AS CdCia,Compania,O.Fecha AS FechaDoc,FechaVence,O.IdConcepto AS CdConcepto,Concepto
,O.IdProv AS NitProvee,T.RazonSocial AS NomProvee,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobtasa,VrImpGlobal,VrNeto,Cantidad
,VrRetencion,VrReteICA,VrReteIVA,CodTarRiv,O.TarifaRet AS OrdTarifRet,O.TarifaIca AS OrdTarifIca,O.CodTarRet AS OrdCodTarRef,O.CodTarIca AS OrdCodTarIca,O.VrImpuBA,O.VrImpuCUP,IdEmpresa,TE.RazonSocial AS NomEmpresa,DirEntrega
,IdLocEtga,LE.Localidad AS CiudadEntrega,LE.IdDep AS CdDepEntrega,DE.Departamento AS DptoEntrega,DiasEntraga,O.NitContac AS Nit_Contacto,O.NomContac AS NombContacto,O.TelContac AS Tel_Contacto,O.emlContac AS Eml_Contacto
,O.IdCCosto AS CdCentCosto,CC.CCosto AS CentCosto,O.IdSubCos AS CdSubcost,SC.SubCosto AS SubcCosto,O.IdForma AS CdForma,FormaPago,DetallePago
,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,O.CdMney AS CodMoney,NitEmpTrans,EmpTrans,O.LiqFletes AS Liq_Fletes,O.pVehiculo AS OrdPlacaVeh
,CdConductor,TCD.RazonSocial AS Conductor,TipEnt,Entrada,IdCiaEnt,NumAutoriza,Modalidad,Vigencia,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,OrigenAdd,Anulado,FecDev,O.Observacion AS Observ
,NumAprob,FecAprob,CdUsuAprob,UA.Usuario AS NomUsuAprob,NivelAprob,O.NumDocSop,O.CdCiaSop,O.IdEstado AS CdEstado,Estado,O.TimeSys AS Fec_Add,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS CdUsuario,U.Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,D.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,TP.NitContac AS ProvNitContact,TP.NomContac AS ProvNomContacto,TP.TelContac AS ProvTelContact,TP.emlContac AS ProvEmailContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
--detalles
,K.Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS PlacaVeh,K.Referencia AS KarReferencia,Descripcion,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,Remision,IdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_OCompra AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCompra=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdProv=T.IdTercero INNER JOIN Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN Terceros AS TE ON O.IdEmpresa=TE.IdTercero  INNER JOIN CentroCosto AS CC ON O.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN Localidades AS LE ON O.IdLocEtga=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TCD ON O.CdConductor=TCD.IdTercero
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON O.IdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON O.IdProv=TP.IdProv
 LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco LEFT JOIN adm_Usuarios AS UA ON O.CdUsuAprob=UA.IdUsuario
 WHERE O.TipDoc=@pmTipDoc AND OCompra BETWEEN @pmOCompraIni AND @pmOCompraFin  AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraDet]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCompraDet] @pmOCompra INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,K.IdProducto AS CdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,CdTanque,Entradas,VrPrecio AS CostoBruto,Entradas*VrPrecio AS TotalCosto,TarifaDct,VrDctoEnt
,VrUnitario AS CostoNeto,Entradas*VrUnitario AS TotalCostNeto,TarifaIva,VrIvaEnt,CdCCosto,CdSubCos,K.Referencia AS Referncia,Unidades
,CodTarDct,CodTarIva,ImpGlobal,Servcios,Tanques,DescripProd,O.Fecha AS FecOrden,DiasEntraga,FechaVence,O.IdProv AS NitProvee,T.RazonSocial AS Proveedor
,Modalidad,Vigencia,IdCCosto,IdSubCos,TipEnt,Entrada,IdCiaEnt,K.CodTarRet AS CdTarifRet,K.TarifaRet AS TarifRet,VrReteEnt,K.CodTarIca AS CdTarifIca,K.TarifaIca AS TarifIca,VrIcaEnt
,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup 
 FROM  Trn_OCompra AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCompra=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN Terceros AS T ON O.IdProv=T.IdTercero
 WHERE OCompra=@pmOCompra AND O.IdCia=@pmIdCia
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraEnt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryOCompraEnt]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmOCompraIni INT=Null,@pmOCompraFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null
,@pmIdEmpresa VARCHAR(16)=Null,@pmIdLocEtga VARCHAR(8)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaEntIni SMALLDATETIME=Null,@pmFechaEntFin SMALLDATETIME=Null
 AS 
 SELECT  OCompra,O.IdCia AS CdCia,Compania,O.Fecha AS FechaOrden,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Entradas) AS CantOrden,SUM(Unidades) AS Unidades
--datos de entradas y dev.
,TipDocEnt,E.Documento AS NumDocEnt,CdCiaEnt,NomCiaEnt,FechaEnt,CantEntradas,CantSalidas,CostoUnitEnt
,TotalCostoEnt,TotalCostoSal,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,Unidad,O.IdProv AS NitProvee,T.RazonSocial AS NomProvee,Modalidad,O.IdConcepto AS CdConcepto,Concepto,IdEmpresa,TE.RazonSocial AS NomEmpresa
,IdLocEtga,LE.Localidad AS CiudadEntrega,LE.IdDep AS CdDepEntrega,DE.Departamento AS DptoEntrega,Vigencia,NumAprob,O.IdEstado AS CdEstado,Estado,O.Observacion AS Observ
,MAX(VrUnitario) AS OrdCostoUnit,SUM(VrCostoEnt) AS OrdCostoEnt,SUM(VrCostoSal) AS OrdCostoSal,SUM(VrIvaEnt) AS OrdIva,SUM(VrDctoEnt) AS OrdDcto
,MAX(CASE K.TipOrd WHEN 'REQ' THEN K.NumOrden ELSE 0 END) AS Requisicion
 FROM  Trn_OCompra AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.OCompra=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Terceros AS T ON O.IdProv=T.IdTercero INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto  INNER JOIN Terceros AS TE ON O.IdEmpresa=TE.IdTercero
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN Localidades AS LE ON O.IdLocEtga=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT  TipOrd,NumOrden,IdCiaOrd,K.TipDoc AS TipDocEnt,Documento,K.IdCia AS CdCiaEnt,KC.Compania AS NomCiaEnt,K.Fecha AS FechaEnt,K.IdProducto AS CdProducto
,PM.DescripProd AS NombreProd,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrUnitario) AS CostoUnitEnt,SUM(VrCostoEnt) AS TotalCostoEnt,SUM(VrCostoSal) AS TotalCostoSal
,SUM(VrIvaEnt) AS IvaEntradas,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoEnt) AS DctoEntradas,SUM(VrDctoSal) AS DctoSalidas,SUM(Unidades) AS TotalUnidades
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE TipDoc IN ('ENT', 'DVE', 'COM', 'DEI') AND TipOrd='ODC' AND NumOrden >0 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaEntIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaEntFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY  TipOrd,NumOrden,IdCiaOrd,K.TipDoc,Documento,K.IdCia,Compania,K.Fecha,K.IdProducto,DescripProd) AS E 
  ON O.TipDoc=E.TipOrd AND O.OCompra=E.NumOrden AND O.IdCia=E.IdCiaOrd AND K.IdProducto=E.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND O.IdProv LIKE ISNULL(@pmIdProv,'%') AND IdEmpresa LIKE ISNULL(@pmIdEmpresa,'%')
 AND IdLocEtga LIKE ISNULL(@pmIdLocEtga,'%')  AND O.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND OCompra  BETWEEN ISNULL(@pmOCompraIni,0) AND ISNULL(@pmOCompraFin,2147483647)
 GROUP BY OCompra,O.IdCia,Compania,O.Fecha,FechaVence,K.IdProducto,DescripProd
,TipDocEnt,E.Documento,CdCiaEnt,NomCiaEnt,FechaEnt,CantEntradas,CantSalidas,CostoUnitEnt
,TotalCostoEnt,TotalCostoSal,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,Unidad,O.IdProv,T.RazonSocial,Modalidad,O.IdConcepto,Concepto,IdEmpresa,TE.RazonSocial
,IdLocEtga,LE.Localidad,LE.IdDep,DE.Departamento,Vigencia,NumAprob,O.IdEstado,Estado,O.Observacion
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCompraLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmOCompraIni INT=Null,@pmOCompraFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT OCompra,IdCia,Fecha,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdProv,T.RazonSocial AS Proveedor,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobtasa,VrImpGlobal,VrNeto
,VrRetencion,VrReteICA,TarifaRet,TarifaIca,CodTarRet,CodTarIca,CodTarRiv,VrReteIVA,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,O.Cantidad,O.VrImpuBA,O.VrImpuCUP,IdEmpresa,E.RazonSocial AS Empresa,DirEntrega,IdLocEtga,DiasEntraga,NitContac,NomContac,TelContac,emlContac
,IdCCosto,IdSubCos,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,LiqFletes,pVehiculo,CdConductor,TipEnt,Entrada,IdCiaEnt,NumAutoriza,NumDocSop,CdCiaSop,Modalidad,Vigencia,OrigenAdd,Anulado,FecDev,O.Observacion AS Observ,NumAprob,FecAprob,CdUsuAprob,NivelAprob
,O.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario
 FROM Trn_OCompra AS O INNER JOIN Terceros AS T ON O.IdProv=T.IdTercero
 INNER JOIN Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS E ON O.IdEmpresa=E.IdTercero
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND OCompra BETWEEN ISNULL(@pmOCompraIni,0) AND ISNULL(@pmOCompraFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,OCompra
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraPen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOCompraPen] @pmEntrada INT,@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT OCompra,O.IdCia AS CdCia,Compania,Fecha,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdProv,T.RazonSocial AS Proveedor,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobtasa,VrImpGlobal,VrNeto
,Cantidad,IdEmpresa,E.RazonSocial AS Empresa,DirEntrega,IdLocEtga,DiasEntraga,NitContac,NomContac,TelContac,emlContac,O.IdCCosto AS CdCenCto,O.IdSubCos AS CdSubCen,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans
,EmpTrans,LiqFletes,pVehiculo,CdConductor,TipEnt,Entrada,IdCiaEnt,NumAutoriza,Modalidad,Vigencia,OrigenAdd,O.Observacion AS Observ,NumAprob,FecAprob,CdUsuAprob,O.IdEstado AS CdEstado,Estado,O.IdUsuario AS IdUsuari,Usuario
 FROM Trn_OCompra AS O INNER JOIN Terceros AS T ON O.IdProv=T.IdTercero
 INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS E ON O.IdEmpresa=E.IdTercero
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Formaspago AS F ON O.IdForma=F.IdForma
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  Anulado=0
 AND (Modalidad='PERMANENTE' or Entrada<=@pmEntrada)
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProv LIKE ISNULL(@pmIdProv,'%')
 AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY O.IdCia,OCompra
GO
/****** Object:  StoredProcedure [dbo].[paQryOCompraRel]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryOCompraRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdEmpresa VARCHAR(16)=Null,@pmIdLocEtga VARCHAR(8)=Null,@pmIdCCosto VARCHAR(16)=Null
,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT TipDoc,OCompra,O.IdCia AS CdCia,Compania,Fecha,FechaVence,O.IdConcepto AS CdConcepto,Concepto
,O.IdProv AS NitProvee,T.RazonSocial AS NomProvee,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobtasa,VrImpGlobal,VrReteIVA,O.VrNeto,O.Cantidad,O.VrImpuBA,O.VrImpuCUP
,VrRetencion,VrReteICA,TarifaRet,TarifaIca,CodTarRet,CodTarIca,CodTarRiv,VrIvaMvc,VrReteCREE,TarifaRtc,CodTarRtc,IdEmpresa,TE.RazonSocial AS NomEmpresa,DirEntrega
,IdLocEtga,LE.Localidad AS CiudadEntrega,LE.IdDep AS CdDepEntrega,DE.Departamento AS DptoEntrega,DiasEntraga,O.NitContac AS Nit_Contacto,O.NomContac AS NombContacto,O.TelContac AS Tel_Contacto,O.emlContac AS Eml_Contacto
,O.IdCCosto AS CdCentCosto,CCosto,O.IdSubCos AS CdSubcost,SubCosto,O.IdForma AS CdForma,FormaPago,DetallePago
,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,O.CdMney AS OrdMoney,NitEmpTrans,EmpTrans,O.LiqFletes AS Liq_Fletes,pVehiculo
,CdConductor,TCD.RazonSocial AS Conductor,TipEnt,Entrada,IdCiaEnt,NumAutoriza,O.NumDocSop,O.CdCiaSop,Modalidad,Vigencia,OrigenAdd,Anulado,FecDev,O.Observacion AS Observ
,NumAprob,FecAprob,CdUsuAprob,NivelAprob,O.IdEstado AS CdEstado,Estado,TimeSys,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,D.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercEnte
--Información del proveedor
,TP.IdGrupo AS ProvGrupo,GrupoClie,TP.NitContac AS ProvNitContact,TP.NomContac AS ProvNomContacto,TP.TelContac AS ProvTelContact,TP.emlContac AS ProvEmailContac,CargContac,DirOrdComp,DiasEntga
,TP.IdClase AS CodClase,NumCuenta,TP.IdBanco AS CdBanco,Banco,Autoret
 FROM Trn_OCompra AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON O.IdProv=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN Terceros AS TE ON O.IdEmpresa=TE.IdTercero  INNER JOIN CentroCosto AS CC ON O.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LE ON O.IdLocEtga=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TCD ON O.CdConductor=TCD.IdTercero
 LEFT JOIN SubCentros AS SC ON O.IdSubCos=SC.IdSubCos
 LEFT JOIN TercProvee AS TP ON O.IdProv=TP.IdProv
 LEFT JOIN GruposCli AS GP ON TP.IdGrupo=GP.IdGrupo
 LEFT JOIN Bancos AS BP ON TP.IdBanco=BP.IdBanco
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND O.IdProv LIKE ISNULL(@pmIdProv,'%') AND IdEmpresa LIKE ISNULL(@pmIdEmpresa,'%')
 AND IdLocEtga LIKE ISNULL(@pmIdLocEtga,'%') AND O.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,OCompra
GO
/****** Object:  StoredProcedure [dbo].[paQryOcupaciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOcupaciones] @pmIdOcupac VARCHAR(4)
 AS 
 IF @pmIdOcupac IS NULL
  BEGIN
  SELECT IdOcupac,Ocupacion
  FROM Ocupaciones
  WHERE Inactivo=0
  END
 ELSE
  BEGIN
  SELECT IdOcupac,Ocupacion,Inactivo
  FROM Ocupaciones
  WHERE IdOcupac=@pmIdOcupac
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryOilAjustes]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilAjustes] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumProceso,IdCia,Fecha,FecProceso,TipOrden,NumOrden,IdCiaOrden,TipoProceso,IdConcepto,IdTercero,CantEntradas,CantSalidas,CostoEnt,CostoSal,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilAjustes
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilAjustesFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilAjustesFmt] @pmTipDoc VARCHAR(3),@pmNumProcesoIni INT,@pmNumProcesoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT A.TipDoc,TipoDoc,A.NumProceso,A.IdCia,Compania,A.Fecha,A.FecProceso,A.TipOrden,A.NumOrden,A.IdCiaOrden,A.TipoProceso,A.IdConcepto,Concepto,A.IdTercero,T.RazonSocial
,A.CantEntradas,A.CantSalidas,A.CostoEnt,A.CostoSal,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado,A.NumDev,A.FecDev,A.Observacion
,A.IdEstado,ED.Estado,A.FechaCrea,A.IdCiaCrea,A.OrigenAdd,A.IdUsuario,Usuario
,D.Item,D.IdProducto,D.Descripcion,D.IdTanque,D.Entradas,D.Salidas,D.UndMed,UM.Unidad,D.VrUnitario,D.TipoProd,P.DescripProd
 FROM Trn_OilAjustes AS A INNER JOIN Trn_OilAjustesProd AS D ON A.TipDoc=D.TipDoc AND A.NumProceso=D.NumProceso AND A.IdCia=D.IdCia
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON A.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS T ON A.IdTercero=T.IdTercero INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc
-- INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 WHERE A.TipDoc=@pmTipDoc AND A.NumProceso BETWEEN @pmNumProcesoIni AND @pmNumProcesoFin AND A.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCompra] @pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumCompra,IdCia,Fecha,IdConcepto,IdProveedor,NumFactura,FechaFac,FechaVence,MulPlazos,IdPlazo,CxPagar,SubTotal,Descuento,Impuesto,Retencion,ReteIca,ReteIva,IvaIngProd,OtrosCargos,OtrosDctos,Fletes,VrNeto,Cantidad,BaseImp,BaseRet,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CdCCosto,CdSubCos,Modalidad
,FechaInicio,FechaFinal,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,NumDev,Observacion,IdEstado,EstRegCosto,NumRegCosto,CiaRegCosto,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilCompra
 WHERE TipDoc=@pmTipDoc AND NumCompra=@pmNumCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCompraDespFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCompraDespFmt] @pmTipDoc VARCHAR(3),@pmNumCompraIni INT,@pmNumCompraFin INT,@pmIdCia CHAR(2)
 AS 
SELECT D.TipDoc,D.NumCompra,D.IdCia,D.Item,D.NumGuia,D.IdCiaGuia,G.FecDespacho,G.IdVehiculo,G.IdEstacion AS IdCampo,CM.EstServicio AS Campo,G.NumRemision
,D.TipEnt,D.NumEntrada,D.IdCiaEnt,D.ItemEnt,E.FecDescargue,E.IdProveedor,T.RazonSocial AS NomProveedor,E.TipoAju,E.NumAjuInv,E.IdCiaAju,E.CantAjuste,E.EstContable,E.TipCom,E.Comprobante,E.IdCiaCom
,D.IdProducto,P.DescripProd,D.CantBruto,D.CantNeto,D.UndMed,UM.Unidad,D.CantEntrada,D.UMCargue,UMC.Unidad AS Um_Cargue,D.VrUnitario,D.NumTasas,D.TasaBrent,D.TasaWti,D.TRMdolar,D.Puntos,D.PrecioUnd
,D.VrTotal,D.CdMoneda,D.UMprecio
FROM Trn_OilCompraDesp AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN Trn_OilGuia AS G ON D.NumGuia=G.NumGuia AND D.IdCiaGuia=G.IdCia
INNER JOIN Trn_OilEntrada AS E ON D.TipEnt=E.TipEnt AND D.NumEntrada=E.NumEntrada AND D.IdCiaEnt=E.IdCia
INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero
LEFT JOIN EdsServicio AS CM ON G.IdEstacion=CM.IdEstacion LEFT JOIN Sys_Um AS UMC ON D.UMCargue=UMC.UndMed 
WHERE D.TipDoc=@pmTipDoc AND D.NumCompra BETWEEN ISNULL(@pmNumCompraIni,0) AND ISNULL(@pmNumCompraFin,2147483647) 
AND (D.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCompraFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCompraFmt] @pmTipDoc VARCHAR(3),@pmNumCompraIni INT,@pmNumCompraFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc,TipoDoc,C.NumCompra,C.IdCia,Compania,C.Fecha,C.IdProveedor,T.RazonSocial,C.NumFactura,C.FechaFac,C.FechaVence,C.Modalidad,C.SubTotal,C.Descuento,C.Impuesto,C.Retencion,C.ReteIca
,C.ReteIva,C.IvaIngProd,C.OtrosCargos,C.OtrosDctos,C.Fletes,C.VrNeto,C.Cantidad AS CantTotal,C.BaseImp,C.BaseRet,C.BaseIvaIgp,C.TarifaIva,C.TarifaRet,C.TarifaIca,C.TarifaRiv
,C.MulPlazos,C.IdPlazo,Plazo,NVmto,DiasPago,C.CxPagar,C.IdConcepto,Concepto,C.CdCCosto,CC.CCosto AS CentCosto,C.CdSubCos,SC.SubCosto AS SubcCosto,C.FechaInicio,C.FechaFinal,C.EstRegCosto,C.NumRegCosto,C.CiaRegCosto,C.TipCom,C.Comprobante,C.IdCiaCom
,C.CodTarIva,C.CodTarRet,C.CodTarIca,C.CodTarRiv,C.Anulado,C.FecDev,C.NumDev,C.Observacion,C.IdEstado,ED.Estado,C.FechaCrea,C.IdCiaCrea,C.OrigenAdd,C.IdUsuario,Usuario
,D.Item,D.IdProducto,P.DescripProd,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.CostoUnit,D.VrTotal,D.VrDcto,D.VrIva,D.TarifaIva AS TarifIva,D.TarifaDct,D.CodTarIva AS CodTarifIva,D.CodTarDct,D.Descripcion,D.CdMoneda,Mneda
,D.CantBruto,D.CantNeto,D.CantEntrada,D.UMCargue,D.UMEntrada
,P.IdSubgrupo,P.TipoRef,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
,T.TipoId,T.Dv,T.Codigo AS CodTercero,T.NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,T.Telefono,Fax,T.e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte
 FROM Trn_OilCompra AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_OilCompraProd AS D ON C.TipDoc=D.TipDoc AND C.NumCompra=D.NumCompra AND C.IdCia=D.IdCia
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea LEFT JOIN adm_monedas AS MN ON D.CdMoneda=MN.IdMneda
 LEFT JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo LEFT JOIN TercProvee AS TP ON C.IdProveedor=TP.IdProv
 LEFT JOIN CentroCosto AS CC ON C.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON C.CdSubCos=SC.IdSubCos
 WHERE C.TipDoc=@pmTipDoc AND C.NumCompra BETWEEN @pmNumCompraIni AND @pmNumCompraFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCostos] @pmTipProc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipProc,NumProceso,IdCia,Fecha,FechaInicio,FechaFinal,IdConcepto,NitProveedor,CodCiaFac,Cantidad,SubTotal,VrTransporte,VrTraVacio,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,NumDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilCostos
 WHERE TipProc=@pmTipProc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCostosFmt] @pmTipProc VARCHAR(3),@pmNumProcesoIni INT,@pmNumProcesoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT PC.TipProc,TipoDoc,PC.NumProceso,PC.IdCia,CI.Compania,PC.Fecha,PC.FechaInicio,PC.FechaFinal,PC.IdConcepto,Concepto,PC.NitProveedor AS NitTercero,N.RazonSocial,PC.CodCiaFac,CC.Compania AS CiaCompras
,PC.Cantidad AS CantTotal,PC.SubTotal,PC.VrTransporte,PC.VrTraVacio,PC.TipCom,PC.Comprobante,PC.IdCiaCom,PC.Anulado,PC.FecDev,PC.NumDev,PC.Observacion,PC.FechaCrea,PC.IdCiaCrea,PC.OrigenAdd,PC.IdUsuario,Usuario
--detalles
,D.Item,D.TipCom AS DetTipCom,D.NumCompra,D.IdCiaCom AS CiaCom,D.ItemCom,D.IdProducto,P.DescripProd,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.VrTotal,D.CostoUnit,D.CantNeto,D.UMCargue,UMC.Unidad AS UM_Cargue
,C.Fecha AS FecCompra,C.IdProveedor,T.RazonSocial AS NomProveedor,C.NumFactura,C.FechaFac,C.FechaVence,C.Modalidad,C.FechaInicio AS FecIniPdo,C.FechaFinal AS FecFinPdo,C.Observacion AS ObservCompra
FROM Trn_OilCostos AS PC INNER JOIN Trn_OilCostosProd AS D ON PC.TipProc=D.TipProc AND PC.NumProceso=D.NumProceso AND PC.IdCia=D.IdCia
INNER JOIN Companias AS CI ON PC.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON PC.IdConcepto=CN.IdConcepto
INNER JOIN adm_Usuarios AS U ON PC.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON PC.TipProc=TD.IdDoc
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN Trn_OilCompra AS C ON D.TipCom=C.TipDoc AND D.NumCompra=C.NumCompra AND D.IdCiaCom=C.IdCia
INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero
LEFT JOIN Terceros AS N ON PC.NitProveedor=N.IdTercero LEFT JOIN Companias AS CC ON PC.CodCiaFac=CC.IdCia
LEFT JOIN Sys_Um AS UMC ON D.UMCargue=UMC.UndMed
WHERE PC.TipProc=@pmTipProc AND PC.NumProceso BETWEEN @pmNumProcesoIni AND @pmNumProcesoFin AND PC.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostosFmv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCostosFmv] @pmTipProc VARCHAR(3),@pmNumProcesoIni INT,@pmNumProcesoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT PC.TipProc,TipoDoc,PC.NumProceso,PC.IdCia,CI.Compania,PC.Fecha,PC.FechaInicio,PC.FechaFinal,PC.IdConcepto,Concepto,PC.NitProveedor AS NitTercero,N.RazonSocial,PC.CodCiaFac,CC.Compania AS CiaCompras
,PC.Cantidad AS CantTotal,PC.SubTotal,PC.VrTransporte,PC.VrTraVacio,PC.TipCom,PC.Comprobante,PC.IdCiaCom,PC.Anulado,PC.FecDev,PC.NumDev,PC.Observacion,PC.FechaCrea,PC.IdCiaCrea,PC.OrigenAdd,PC.IdUsuario,Usuario
--detalles
,D.Item,D.TipCom AS TipFact,D.NumCompra AS NumFactura,D.IdCiaCom AS CiaFact,D.ItemCom AS ItemFact,D.IdProducto,P.DescripProd,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.VrTotal
,F.Fecha AS FecFactura,F.IdCliente,T.RazonSocial AS NomCliente,F.FechaVence,F.Observacion AS ObservFactura
FROM Trn_OilCostos AS PC INNER JOIN Trn_OilCostosProd AS D ON PC.TipProc=D.TipProc AND PC.NumProceso=D.NumProceso AND PC.IdCia=D.IdCia
INNER JOIN Companias AS CI ON PC.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON PC.IdConcepto=CN.IdConcepto
INNER JOIN adm_Usuarios AS U ON PC.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON PC.TipProc=TD.IdDoc
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
LEFT JOIN Trn_Facturas AS F ON D.TipCom=F.TipDoc AND D.NumCompra=F.Factura AND D.IdCiaCom=F.IdCia
LEFT JOIN Terceros AS T ON F.IdCliente=T.IdTercero
LEFT JOIN Terceros AS N ON PC.NitProveedor=N.IdTercero LEFT JOIN Companias AS CC ON PC.CodCiaFac=CC.IdCia
WHERE PC.TipProc=@pmTipProc AND PC.NumProceso BETWEEN @pmNumProcesoIni AND @pmNumProcesoFin AND PC.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostoVen]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCostoVen] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,FechaInicio,FechaFinal,IdConcepto,Cantidad,ValorTotal,CantDev,VrDevFact,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilCostoVen
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilCostoVenFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilCostoVenFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc,TipoDoc,N.NumNota,N.IdCia,Compania,N.Fecha,N.FechaInicio,N.FechaFinal,N.IdConcepto,Concepto,N.Cantidad AS CantTotal,N.ValorTotal,N.CantDev,N.VrDevFact
,N.TipCom,N.Comprobante,N.IdCiaCom,N.Anulado,N.NumDev,N.FecDev,N.Observacion,N.IdEstado,ED.Estado,N.FechaCrea,N.IdCiaCrea,N.OrigenAdd,N.IdUsuario,Usuario
,D.Item,D.IdProducto,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TipFact,D.NumFactura,D.IdCiaFact,D.ItemFact,D.FechaFact
,D.TipGuia,D.NumGuia,D.IdCiaGuia,D.FechaGuia,D.IdCliente,T.RazonSocial,D.IdAgencia,D.IdVehiculo,D.CdCCosto,CCosto,D.CdSubCos,SubCosto,D.TipoProd,P.DescripProd,P.IdSubgrupo
 FROM Trn_OilCostoVen AS N INNER JOIN Trn_OilCostoVenProd AS D ON N.TipDoc=D.TipDoc AND N.NumNota=D.NumNota AND N.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON N.IdConcepto=CT.IdConcepto
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 INNER JOIN Terceros AS T ON D.IdCliente=T.IdTercero
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos
 WHERE N.TipDoc=@pmTipDoc AND N.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDespClie]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDespClie] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumGuia,IdCia,Fecha,FecCargue,FecDespacho,FecDescargue,HorasVig,IdCliente,IdAgencia,IdVehiculo,IdConductor,NitEmpTrans,NomEmpTrans,Remolque,IdEstacion,IdLocOrigen,IdLocDestino,LugarOrigen,DirDestino,NomContacto,TelContacto,emlContacto,Modalidad,Referencia,NumRemision,DetSellos,CodSicom,ZonaFrontera,Cantidad,SubTotal,VrIva,VrTransporte,TipOrden,NumOrden,IdCiaOrden,EstFactura,TipFac,Factura,IdCiaFac,FechaFact,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilDespClie
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDespClieFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDespClieFmt] @pmTipDoc VARCHAR(3),@pmNumGuiaIni INT,@pmNumGuiaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT G.TipDoc,G.NumGuia,G.IdCia,Compania,G.Fecha,G.FecCargue,G.FecDespacho,G.FecDescargue,G.HorasVig,G.IdCliente,T.RazonSocial AS NomCliente,G.IdAgencia,A.Agencia
,G.IdVehiculo,G.IdConductor,CD.RazonSocial AS NomConductor,G.NitEmpTrans,G.NomEmpTrans,G.Remolque,G.IdEstacion AS IdCampo,CM.EstServicio AS Campo
,G.IdLocOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CdDptoOrig,DT.Departamento AS DptoOrigen
,G.IdLocDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CdDptoDest,DD.Departamento AS DptoDestino
,G.LugarOrigen,G.DirDestino,G.NomContacto,G.TelContacto,G.emlContacto,G.Modalidad,G.Referencia,G.NumRemision,G.DetSellos,G.CodSicom,G.ZonaFrontera
,G.Cantidad AS CantTotal,G.SubTotal,G.VrIva AS TotalIVA,G.VrTransporte,G.TipOrden,G.NumOrden,G.IdCiaOrden,G.EstFactura,G.TipFac,G.Factura,G.IdCiaFac,G.FechaFact
,G.Anulado,G.FecDev,G.Observacion,G.IdEstado,ED.Estado,G.FechaCrea,G.IdCiaCrea,G.OrigenAdd,G.IdUsuario,Usuario,TD.TipoDoc
--detalles
,D.Item,D.IdTanque,D.TipoProd,D.IdProducto,D.Descripcion,D.CantBruto,D.Cantidad,D.UndMed,UM.Unidad,D.Temperatura,D.TempLab,D.UnidTemp,D.ValorAPI,D.API_Corregido,D.Densidad,D.ValorVCW
,D.FactorTemp,D.VrUnitario,D.FleteUnd,D.TarifaIva,D.VrIva,D.CodTarIva,D.CodSicomPro,P.DescripProd,TQ.CapTanq,TQ.NivAgua,TQ.CapNeta,TQ.Descripcion AS TanqDescrip,TQ.Altura
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
FROM Trn_OilDespClie AS G INNER JOIN Trn_OilDespClieProd AS D ON G.TipDoc=D.TipDoc AND G.NumGuia=D.NumGuia AND G.IdCia=D.IdCia
INNER JOIN Companias AS CN ON G.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON G.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON G.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero
INNER JOIN Terceros AS CD ON G.IdConductor=CD.IdTercero 
INNER JOIN Localidades AS LO ON G.IdLocOrigen=LO.IdLocal INNER JOIN Departamentos AS DT ON LO.IdDep=DT.IdDep 
INNER JOIN Localidades AS LD ON G.IdLocDestino=LD.IdLocal INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN Tanques AS TQ ON D.IdTanque=TQ.IdTanque
LEFT JOIN Agencias AS A ON G.IdAgencia=A.IdAgencia LEFT JOIN EdsServicio AS CM ON G.IdEstacion=CM.IdEstacion
WHERE G.TipDoc=@pmTipDoc AND G.NumGuia BETWEEN @pmNumGuiaIni AND @pmNumGuiaFin AND G.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCompra]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDevCompra] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumCompra,IdCiaDoc,FecDoc,IdProveedor,NumFactura,CxPagar,SubTotal,Descuento,Impuesto,Retencion,ReteIca,ReteIva,IvaIngProd,OtrosCargos,OtrosDctos,Fletes,VrNeto,Cantidad,BaseImp,BaseRet,BaseIvaIgp,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CdCCosto,CdSubCos,Modalidad,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilDevCompra
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCompraFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDevCompraFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
SELECT DV.TipDev,TipoDoc,DV.Devolucion,DV.IdCia,Compania,DV.Fecha,DV.IdConcepto,Concepto,DV.TipDoc,DV.NumCompra,DV.IdCiaDoc,DV.FecDoc,DV.IdProveedor,T.RazonSocial
,DV.NumFactura,C.FechaFac,C.FechaVence,DV.CxPagar,C.IdPlazo,Plazo,NVmto,DiasPago,DV.SubTotal,DV.Descuento,DV.Impuesto,DV.Retencion,DV.ReteIca,DV.ReteIva,DV.IvaIngProd,DV.OtrosCargos,DV.OtrosDctos,DV.Fletes,DV.VrNeto
,DV.Cantidad AS CantTotal,DV.BaseImp,DV.BaseRet,DV.BaseIvaIgp,DV.TarifaIva,DV.TarifaRet,DV.TarifaIca,DV.TarifaRiv,DV.CodTarIva,DV.CodTarRet,DV.CodTarIca,DV.CodTarRiv
,DV.CdCCosto,CC.CCosto,DV.CdSubCos,SC.SubCosto,DV.Modalidad,C.FechaInicio,C.FechaFinal,DV.TipCom,DV.Comprobante,DV.IdCiaCom,DV.ModdDev,DV.Observacion,DV.FechaCrea,DV.IdCiaCrea,DV.OrigenAdd,DV.IdUsuario,Usuario
,D.Item,D.IdProducto,P.DescripProd,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.CostoUnit,D.VrTotal,D.VrDcto,D.VrIva,D.TarifaIva AS TarifIva,D.TarifaDct,D.CodTarIva AS CodTarifIva,D.CodTarDct,D.Descripcion,D.CdMoneda,Mneda,D.CantBruto,D.CantNeto,D.CantEntrada,D.UMCargue,D.UMEntrada
,P.IdSubgrupo,P.TipoRef,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
,T.TipoId,T.Dv,T.Codigo AS CodTercero,T.NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,T.Telefono,Fax,T.e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte
FROM Trn_OilDevCompra AS DV INNER JOIN Trn_OilCompra AS C ON DV.TipDoc=C.TipDoc AND DV.NumCompra=C.NumCompra AND DV.IdCiaDoc=C.IdCia
INNER JOIN Trn_OilDevComProd AS D ON DV.TipDev=D.TipDev AND DV.Devolucion=D.Devolucion AND DV.IdCia=D.IdCia
INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto
INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc 
INNER JOIN Terceros AS T ON DV.IdProveedor=T.IdTercero 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
LEFT JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo LEFT JOIN TercProvee AS TP ON DV.IdProveedor=TP.IdProv
LEFT JOIN CentroCosto AS CC ON DV.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON DV.CdSubCos=SC.IdSubCos
LEFT JOIN adm_monedas AS MN ON D.CdMoneda=MN.IdMneda
WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCostos]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDevCostos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,NumProceso,IdCiaDoc,FecDoc,Cantidad,SubTotal,VrTransporte,VrTraVacio,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilDevCostos
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCostosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDevCostosFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT DV.TipDev,TipoDoc,DV.Devolucion,DV.IdCia,Compania,DV.Fecha,DV.IdConcepto,Concepto,DV.TipDoc,DV.NumProceso,DV.IdCiaDoc,DV.FecDoc,DV.Cantidad AS CantTotal,DV.SubTotal,DV.VrTransporte,DV.VrTraVacio
,DV.TipCom,TipoCom,DV.Comprobante,DV.IdCiaCom,DV.ModdDev,DV.Observacion,DV.FechaCrea,DV.IdCiaCrea,DV.OrigenAdd,DV.IdUsuario,Usuario
--detalles
,D.Item,D.IdProducto,P.DescripProd,P.TipoProdCo,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.VrTotal,D.CostoUnit
,DC.TipCom AS DetTipCom,DC.NumCompra,DC.IdCiaCom AS CiaCom,DC.ItemCom,DC.CantNeto,DC.UMCargue,UMC.Unidad AS UM_Cargue
,C.Fecha AS FecCompra,C.IdProveedor,T.RazonSocial AS NomProveedor,C.NumFactura,C.FechaFac,C.FechaVence,C.Modalidad,C.FechaInicio AS FecIniPdo,C.FechaFinal AS FecFinPdo,C.Observacion AS ObservCompra
FROM Trn_OilDevCostos AS DV INNER JOIN Trn_OilDevCostosProd AS D ON DV.TipDev=D.TipDev AND DV.Devolucion=D.Devolucion AND DV.IdCia=D.IdCia
INNER JOIN Trn_OilCostosProd AS DC ON DV.TipDoc=DC.TipProc AND DV.NumProceso=DC.NumProceso AND DV.IdCiaDoc=DC.IdCia AND D.Item=DC.Item
INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto
INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN Trn_OilCompra AS C ON DC.TipCom=C.TipDoc AND DC.NumCompra=C.NumCompra AND DC.IdCiaCom=C.IdCia
INNER JOIN Terceros AS T ON C.IdProveedor=T.IdTercero LEFT JOIN Sys_Um AS UMC ON DC.UMCargue=UMC.UndMed
LEFT JOIN TiposCom AS TC ON DV.TipCom=TC.IdCom
WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevCostosFmv]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDevCostosFmv] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT DV.TipDev,TipoDoc,DV.Devolucion,DV.IdCia,Compania,DV.Fecha,DV.IdConcepto,Concepto,DV.TipDoc,DV.NumProceso,DV.IdCiaDoc,DV.FecDoc,DV.Cantidad AS CantTotal,DV.SubTotal
,DV.TipCom,TipoCom,DV.Comprobante,DV.IdCiaCom,DV.ModdDev,DV.Observacion,DV.FechaCrea,DV.IdCiaCrea,DV.OrigenAdd,DV.IdUsuario,Usuario
--detalles
,D.Item,D.IdProducto,P.DescripProd,P.TipoProdCo,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.VrTotal,D.CostoUnit
,DC.TipCom AS TipoFact,DC.NumCompra AS NumFactura,DC.IdCiaCom AS CiaFact,DC.ItemCom AS ItemFact
,F.Fecha AS FecFact,F.IdCliente,T.RazonSocial AS NomCliente,F.FechaVence,F.Observacion AS ObservFactura
FROM Trn_OilDevCostos AS DV INNER JOIN Trn_OilDevCostosProd AS D ON DV.TipDev=D.TipDev AND DV.Devolucion=D.Devolucion AND DV.IdCia=D.IdCia
INNER JOIN Trn_OilCostosProd AS DC ON DV.TipDoc=DC.TipProc AND DV.NumProceso=DC.NumProceso AND DV.IdCiaDoc=DC.IdCia AND D.Item=DC.Item
INNER JOIN Companias AS CI ON DV.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON DV.IdConcepto=CN.IdConcepto
INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
LEFT JOIN Trn_Facturas AS F ON DC.TipCom=F.TipDoc AND DC.NumCompra=F.Factura AND DC.IdCiaCom=F.IdCia
LEFT JOIN Terceros AS T ON F.IdCliente=T.IdTercero
LEFT JOIN TiposCom AS TC ON DV.TipCom=TC.IdCom
WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilDevFcrLtd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilDevFcrLtd] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS  
SELECT DV.TipDev,DV.Devolucion,DV.IdCia,Compania,DV.Fecha,DV.TipDoc,DV.Factura,DV.IdCiaDoc,DV.FecDoc,DV.IdCliente,T.RazonSocial AS NomCliente
,D.Item,D.IdTanque,D.IdProducto,P.DescripProd,D.TipoProd,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TarifaDct,D.VrDcto,D.TarifaIva,D.VrIva
,D.TarifaRet AS DetTarifRet,D.VrRetFte AS DetVrRetFte,D.VrBaseRet,D.TarifaIca AS DetTarifIca,D.VrRetIca AS DetReteIca
,D.ItemDet,D.TipGuia,D.NumGuia,D.IdCiaGuia,D.ItemGuia,D.CantGuia,D.IndMezcla,D.ItemMezcla,D.FactorMezcla,D.CodSicomPro,D.CodBodega,Bodega
,DV.VrRetencion,DV.VrReteICA,DV.VrReteIVA,DV.VrFletes,DV.VrCargos,DV.VrOtrDcto,DV.VrReteCREE,DV.VrNeto,DV.BaseImp,DV.BaseRet
,DV.Modalidad,DV.IdConcepto,Concepto,DV.IdAgencia,A.Agencia AS NomAgencia,DV.IdVend AS NitVend,VN.RazonSocial AS Vendedor,DV.TarifaCom,DV.TarifaArf,DV.VrAutRetFte,DV.TarifaAri,DV.VrAutRetIca
,DV.Remision,DV.IdCiaRem,DV.ModdDev,DV.TipCom,TipoCom,DV.Comprobante,DV.IdCiaCom,DV.Observacion AS Observ,DV.TimeSys AS FechaCrea,DV.IdCiaCrea,DV.IdUsuario,Usuario,DV.OrigenAdd
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
,T.TipEnte,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen
FROM Trn_DevFcr AS DV INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON DV.IdConcepto=C.IdConcepto
INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario INNER JOIN Terceros AS VN ON DV.IdVend=VN.IdTercero
INNER JOIN Terceros AS T ON DV.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON DV.IdCliente=CLI.IdClie
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Trn_OilDevFacProd AS D ON DV.TipDev=D.TipDev AND DV.Devolucion=D.Devolucion AND DV.IdCia=D.IdCia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Sys_Um AS UMP ON P.UndMed=UMP.UndMed
LEFT JOIN Agencias AS A ON DV.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON DV.TipCom=TC.IdCom
LEFT JOIN Bodegas AS B ON D.CodBodega=B.IdBodega
WHERE DV.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (DV.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryOilEntrada]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipEnt,NumEntrada,IdCia,Fecha,NumGuia,IdCiaGuia,FecDespacho,FecDescargue,IdProveedor,IdVehiculo,IdConductor,NitEmpTrans,NomEmpTrans,Remolque,ValorTotal,CtaPagar,TipFactCxp,NumFactura,IdCiaCxp
,TipoAju,NumAjuInv,IdCiaAju,CantAjuste,NumFactTra,CdCiaFtr,EstContable,CdConcepto,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilEntrada
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilEntradaFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilEntradaFmt] @pmTipEnt VARCHAR(3),@pmNumEntradaIni INT,@pmNumEntradaFin INT,@pmIdCia CHAR(2)
AS 
 SELECT E.TipEnt,E.NumEntrada,E.IdCia,Compania,E.Fecha,E.NumGuia,E.IdCiaGuia,E.FecDespacho,E.FecDescargue,E.IdProveedor,T.RazonSocial AS NomProveedor,E.IdVehiculo,E.IdConductor,CD.RazonSocial AS NomConductor
,D.IdTanque,D.IdProducto,D.Cantidad,D.UndMed,D.Temperatura,D.UnidTemp,D.ValorAPI,D.ValorVCW,D.API_Corregido,D.Densidad
,D.CantCargue,D.UMCargue,D.TempCargue,D.API_Cargue,D.VCW_Cargue,D.PesoNeto,D.VrUnitario
,E.NitEmpTrans,E.NomEmpTrans,E.Remolque,E.ValorTotal,E.CtaPagar,E.TipFactCxp,E.NumFactura,E.IdCiaCxp,E.TipoAju,E.NumAjuInv,E.IdCiaAju,E.CantAjuste,E.NumFactTra,E.CdCiaFtr,E.EstContable,E.CdConcepto,Concepto
,E.TipCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.FecDev,E.Observacion,E.IdEstado,Estado,E.FechaCrea,E.IdCiaCrea,E.OrigenAdd,E.IdUsuario,Usuario,TipoDoc
--Datos del proveedor
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
 FROM Trn_OilEntrada AS E INNER JOIN Trn_OilEntradaProd AS D ON E.TipEnt=D.TipEnt AND E.NumEntrada=D.NumEntrada AND E.IdCia=D.IdCia
 INNER JOIN Sys_TiposDoc AS TD ON E.TipEnt=TD.IdDoc INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 INNER JOIN Terceros AS CD ON E.IdConductor=CD.IdTercero INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN Conceptos AS CT ON E.CdConcepto=CT.IdConcepto
 WHERE E.TipEnt=@pmTipEnt AND E.NumEntrada BETWEEN @pmNumEntradaIni AND @pmNumEntradaFin AND E.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilFacturasLtd]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilFacturasLtd] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS  
SELECT F.TipDoc,F.Factura,F.IdCia,Compania,FE.Prefijo,FE.NumFace,F.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,F.Fecha,F.IdPlazo,Plazo,F.FechaVence
,D.Item,D.TipGuia,D.NumGuia,D.IdCiaGuia,D.ItemGuia,D.IdTanque,D.IdProducto,D.Descripcion,P.DescripProd,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TarifaDct,D.VrDcto,D.TarifaIva,D.VrIva,D.VrBaseRet,D.TarifaRet AS DetTarifRet,D.VrRetFte AS DetVrRetFte
,D.TarifaIca AS DetTarifIca,D.VrRetIca AS DetVrReteIca,D.Temperatura,D.TempLab,D.UnidTemp,D.ValorAPI,D.API_Corregido,D.Densidad,D.CantGuia,D.IndMezcla,D.ItemMezcla,D.FactorMezcla,D.NumTasas,D.TasaBrent,D.TasaWti,D.TRMdolar,D.Puntos
,D.CodSicomPro,D.TipoProd,D.CodBodega,Bodega
,P.Referencia AS ProdReferencia,P.CodBarras AS Cod_Sicom,P.UndMed AS ProdUnd,UMP.Unidad AS ProdUnidad,P.IdSubgrupo,Subgrupo
,F.TarifaRet,F.VrRetencion,F.TarifaIca,F.VrReteICA,F.TarifaRiv,F.VrReteIVA,F.TarifaRtc,F.VrReteCREE,F.VrFletes,F.VrCargos,F.VrOtrDcto,F.VrNeto,F.VrAplicado,F.BaseImp,F.BaseRet,F.BaseIca,F.BaseRiv
,F.TarifaArf,F.VrAutRetFte,F.TarifaAri,F.VrAutRetIca,F.IdAgencia,A.Agencia AS NomAgencia,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.TarifaCom,F.IdLocEnv AS IdCiudad,LE.Localidad AS NomCiudad,LE.IdDep,DE.Departamento
,F.IdForma,FormaPago,F.DetallePago,F.MulPlazos,F.NitContac AS FacNitContac,F.NomContac AS FacNomContac,F.TelContac AS FacTelContac,F.emlContac AS FacEmailContac,F.CargoContac,F.pVehiculo,F.CdConductor,CD.RazonSocial AS Conductor,F.ZonaFrontera,F.TipRem,F.Remision,F.IdCiaRem
,F.IdConcepto AS CdConcepto,Concepto,F.Modalidad,F.IdCCosto,CCosto,F.IdSubCos,SubCosto,F.TipCom,TipoCom,F.Comprobante,F.IdCiaCom,F.Anulado,F.NumDev,F.FecDev,F.Observacion,F.IdEstado,ED.Estado,F.TimeSys AS FechaCrea,F.IdUsuario AS CdUsuario,Usuario,F.OrigenAdd
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
,T.TipEnte,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen
FROM Trn_Facturas AS F INNER JOIN Companias AS CN ON F.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto
INNER JOIN EstadoDoc AS ED ON F.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero
INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN Trn_OilFacturaProd AS D ON F.TipDoc=D.TipDoc AND F.Factura=D.Factura AND F.IdCia=D.IdCia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Sys_Um AS UMP ON P.UndMed=UMP.UndMed
LEFT JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos LEFT JOIN Terceros AS CD ON F.CdConductor=CD.IdTercero
LEFT JOIN Localidades AS LE ON F.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
LEFT JOIN Trn_Face AS FE ON F.TipDoc=FE.TipDoc AND F.Factura=FE.Documento AND F.IdCia=FE.IdCia
LEFT JOIN TiposCom AS TC ON F.TipCom=TC.IdCom LEFT JOIN Bodegas AS B ON D.CodBodega=B.IdBodega
WHERE F.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (F.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryOilGuia]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumGuia,IdCia,Fecha,FecDespacho,IdProveedor,IdVehiculo,IdConductor,IdEstacion,IdProducto,CantBruto,CantNeto,UndMed,Temperatura,UnidTemp,ValorAPI,ValorVCW,CantDescargue,APIDescargue,TempDescargue,FecDescargue,NitEmpTrans,NomEmpTrans,NumRemision,Remolque,TipoEnt,NumEntrada,IdCiaEnt
,Anulado,FecDev,Observacion,IdEstado,NumFactCom,CdCiaFco,NumFactTra,CdCiaFtr,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilGuia
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilGuiaFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilGuiaFmt] @pmTipDoc VARCHAR(3),@pmNumGuiaIni INT,@pmNumGuiaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT G.TipDoc,G.NumGuia,G.IdCia,Compania,G.Fecha,G.FecDespacho,G.IdProveedor,T.RazonSocial AS NomProveedor,G.IdVehiculo,G.IdConductor,CD.RazonSocial AS NomConductor,G.IdEstacion AS IdCampo,CM.EstServicio AS Campo
,G.IdProducto,DescripProd,G.CantBruto,G.CantNeto,G.UndMed,UM.Unidad,G.Temperatura,G.UnidTemp,G.ValorAPI,G.ValorVCW,G.CantDescargue,G.APIDescargue,G.TempDescargue,G.FecDescargue
,G.NitEmpTrans,G.NomEmpTrans,G.NumRemision,G.Remolque,G.TipoEnt,G.NumEntrada,G.IdCiaEnt,G.NumFactCom,G.CdCiaFco,G.NumFactTra,G.CdCiaFtr,G.Anulado,G.FecDev
,G.Observacion,G.IdEstado,Estado,G.FechaCrea,G.IdCiaCrea,G.OrigenAdd,G.IdUsuario,Usuario,TipoDoc
--datos proveedor
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,L.Localidad AS TercCiudad,L.IdDep AS TercIdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.TelMovil AS TercCelular,T.e_mail AS TercEmail
 FROM Trn_OilGuia AS G INNER JOIN Sys_TiposDoc AS TD ON G.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON G.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CN ON G.IdCia=CN.IdCia INNER JOIN Terceros AS T ON G.IdProveedor=T.IdTercero
 INNER JOIN ProdMcias AS P ON G.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON G.UndMed=UM.UndMed
 INNER JOIN Terceros AS CD ON G.IdConductor=CD.IdTercero INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN EdsServicio AS CM ON G.IdEstacion=CM.IdEstacion
 WHERE G.TipDoc=@pmTipDoc AND G.NumGuia BETWEEN @pmNumGuiaIni AND @pmNumGuiaFin AND G.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInvent]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilInvent] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipEnt,NumEntrada,IdCia,Fecha,IdConcepto,Modalidad,IdProveedor,NumFactura,FechaFac,FechaVence,Cantidad,ValorTotal,CtaPagar,EstContable,TipCom,Comprobante,IdCiaCom,Anulado,FecDev,NumDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilInvent
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInventDev]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilInventDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipEnt,NumEntrada,IdCiaDoc,FecDoc,IdProveedor,Cantidad,ValorTotal,CtaPagar,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilInventDev
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInventDevFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilInventDevFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT DV.TipDev,TipoDoc,DV.Devolucion,DV.IdCia,Compania,DV.Fecha,DV.IdConcepto,Concepto,DV.TipEnt,DV.NumEntrada,DV.IdCiaDoc,DV.FecDoc,DV.IdProveedor,T.RazonSocial AS NomProveedor
,DV.Cantidad AS TotalCant,DV.ValorTotal,E.NumFactura,E.FechaFac,E.FechaVence,DV.CtaPagar,DV.TipCom,DV.Comprobante,DV.IdCiaCom,DV.ModdDev,DV.Observacion
,D.Item,D.IdTanque,D.IdProducto,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TipoProd,D.IdEstacion AS CdCampo,EstServicio AS NomCampo,P.DescripProd
,DV.FechaCrea,DV.IdCiaCrea,DV.OrigenAdd,DV.IdUsuario,Usuario
FROM Trn_OilInventDev AS DV INNER JOIN Trn_OilInventDevp AS D ON DV.TipDev=D.TipDev AND DV.Devolucion=D.Devolucion AND DV.IdCia=D.IdCia
INNER JOIN Trn_OilInvent AS E ON DV.TipEnt=E.TipEnt AND DV.NumEntrada=E.NumEntrada AND DV.IdCiaDoc=E.IdCia
INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc  
INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia INNER JOIN Terceros AS T ON DV.IdProveedor=T.IdTercero
INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON DV.IdConcepto=CT.IdConcepto
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
LEFT JOIN EdsServicio AS CM ON D.IdEstacion=CM.IdEstacion
WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilInventFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilInventFmt] @pmTipEnt VARCHAR(3),@pmNumEntradaIni INT,@pmNumEntradaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT E.TipEnt,TipoDoc,E.NumEntrada,E.IdCia,Compania,E.Fecha,E.IdConcepto,Concepto,E.Modalidad,E.IdProveedor,T.RazonSocial AS NomProveedor,E.NumFactura,E.FechaFac,FechaVence
,E.Cantidad AS TotalCant,E.ValorTotal,E.CtaPagar,E.EstContable,E.TipCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.FecDev,E.NumDev,E.Observacion,E.IdEstado,ED.Estado
,D.Item,D.IdTanque,D.IdProducto,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TipoProd,D.IdEstacion AS CdCampo,EstServicio AS NomCampo,P.DescripProd
,E.FechaCrea,E.IdCiaCrea,E.OrigenAdd,E.IdUsuario,Usuario
 FROM Trn_OilInvent AS E INNER JOIN Sys_TiposDoc AS TD ON E.TipEnt=TD.IdDoc INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia INNER JOIN Terceros AS T ON E.IdProveedor=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON E.IdConcepto=CT.IdConcepto
 INNER JOIN Trn_OilInventProd AS D ON E.TipEnt=D.TipEnt AND E.NumEntrada=D.NumEntrada AND E.IdCia=D.IdCia
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 LEFT JOIN EdsServicio AS CM ON D.IdEstacion=CM.IdEstacion
 WHERE E.TipEnt=@pmTipEnt AND E.NumEntrada BETWEEN @pmNumEntradaIni AND @pmNumEntradaFin AND E.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilMediciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilMediciones] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumInvent,IdCia,Fecha,FecProceso,IdTurno,IdOperario,NomOperario,Modalidad,TipDocAju,AjuInvSob,AjuInvFal,NumNota,IdCiaAin,VolPT,VolMP,FecProcAnt,NumHoras
,NumSalida,NumNcp,IdCiaNcp,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilMediciones
 WHERE TipDoc=@pmTipDoc AND NumInvent=@pmNumInvent AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilMedicionesFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilMedicionesFmt] @pmTipDoc VARCHAR(3),@pmNumInventIni INT,@pmNumInventFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc,TipoDoc,M.NumInvent,M.IdCia,Compania,M.Fecha,M.FecProceso,M.IdTurno,Turno,M.IdOperario,M.NomOperario,M.Modalidad,M.TipDocAju,M.AjuInvSob,M.AjuInvFal,M.NumNota,M.IdCiaAin
 ,VolPT,VolMP,M.FecProcAnt,M.NumHoras,M.NumSalida,M.NumNcp,M.IdCiaNcp,M.Anulado,M.NumDev,M.FecDev,M.Observacion,M.IdEstado,ED.Estado,M.FechaCrea,M.IdCiaCrea,M.OrigenAdd,M.IdUsuario,Usuario
--Detalles
,D.Item,D.IdTanque,D.IdProducto,P.DescripProd,D.NivelVol,D.Cantidad,D.UndMed,UM.Unidad,D.TipoMed,D.AlturaTq,D.UndAforoC,D.UndAforoF,D.Temperatura,D.UnidTemp
,D.ValorAPI,D.API_Corregido,D.Densidad,D.CantSaldo,D.CantAjuste,D.VrUnitario,D.TempLab,D.VolMedido,D.VolNeto,D.Vol_Anterior,D.CantEntradas,D.CantSalidas,D.TipoProd AS DetTipoProd,D.Descripcion
,TQ.CapTanq,TQ.NivAgua,TQ.CapNeta,TQ.TipoProd,TQ.Descripcion AS TanqDescrip
FROM Trn_OilMediciones AS M INNER JOIN Trn_OilMedicionesTq AS D ON M.TipDoc=D.TipDoc AND M.NumInvent=D.NumInvent AND M.IdCia=D.IdCia
INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN Turnos AS TN ON M.IdTurno=TN.IdTurno
INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario 
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
INNER JOIN Tanques AS TQ ON D.IdTanque=TQ.IdTanque
WHERE M.TipDoc=@pmTipDoc AND M.NumInvent BETWEEN @pmNumInventIni AND @pmNumInventFin AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilNotas]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,IdConcepto,IdTercero,Cantidad,ValorTotal,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilNotas
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilNotasFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilNotasFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc,TipoDoc,N.NumNota,N.IdCia,Compania,N.Fecha,N.IdConcepto,Concepto,N.IdTercero,T.RazonSocial
,N.Cantidad AS CantTotal,N.ValorTotal,N.CdCCosto,CCosto,N.CdSubCos,SubCosto,N.TipCom,N.Comprobante,N.IdCiaCom,N.Anulado,N.NumDev,N.FecDev,N.Observacion,N.IdEstado,ED.Estado
,D.Item,D.IdTanque,D.IdProducto,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,TQ.TipoProd,P.DescripProd
,N.FechaCrea,N.IdCiaCrea,N.OrigenAdd,N.IdUsuario,Usuario
 FROM Trn_OilNotas AS N INNER JOIN Trn_OilNotasProd AS D ON N.TipDoc=D.TipDoc AND N.NumNota=D.NumNota AND N.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero
 INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON N.IdConcepto=CT.IdConcepto
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
 INNER JOIN Tanques AS TQ ON D.IdTanque=TQ.IdTanque 
 LEFT JOIN CentroCosto AS CC ON N.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON N.CdSubCos=SC.IdSubCos  
 WHERE N.TipDoc=@pmTipDoc AND N.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilTraslado]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilTraslado] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumNota,IdCia,Fecha,FechaInicio,FechaFinal,IdConcepto,IdTercero,CantMP,CantProducido,CantConsumo,CantCrudoCom,Total_MP,VU_MP,CantBrutoMP,CantNetoMP,CantFactMP,Total_TRA,VU_TRA,CantNetoTRA,CantFactTRA,Total_TVacio,VU_TVacio,CantNetoTv,CantFactTv,Total_Standby,VU_Standby,Cant_Standby,Total_MOD,Total_CIF,CdCCosto,CdSubCos,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,FechaCrea,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_OilTraslado
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilTrasladoFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilTrasladoFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc,TipoDoc,N.NumNota,N.IdCia,Compania,N.Fecha,N.FechaInicio,N.FechaFinal,N.IdTercero,T.RazonSocial,N.CantMP,N.CantProducido,N.CantConsumo,N.CantCrudoCom
,N.Total_MP,VU_MP,CantBrutoMP,CantNetoMP,CantFactMP,Total_TRA,VU_TRA,CantNetoTRA,CantFactTRA,Total_TVacio,VU_TVacio,CantNetoTv,CantFactTv,Total_Standby,VU_Standby,Cant_Standby,Total_MOD,Total_CIF
,N.IdConcepto,Concepto,N.CdCCosto,CCosto,N.CdSubCos,SubCosto,N.TipCom,N.Comprobante,N.IdCiaCom,N.Anulado,N.NumDev,N.FecDev,N.Observacion,N.IdEstado,ED.Estado,N.FechaCrea,N.IdCiaCrea,N.OrigenAdd,N.IdUsuario,Usuario
--Detalles
,D.Item,D.IdProducto,D.Descripcion,D.TipoProd,D.SaldoInicial,D.SaldoFinal,D.Entradas,D.Despachos,D.DespMezcla,D.Salidas,D.AjuSobrante,D.AjuFaltante,D.Cantidad,D.UndMed,UM.Unidad
,D.PorcRend,D.CostoAnt,D.VrUnitario,D.VrTotal,D.SaldoMPAnt,D.CantProdAnt,D.CostoMPAnt,D.CostoMPMes,D.CostoUndMP,D.CostoUndTra,D.CostoTotalTra,D.CostoTotalSB,D.CostoUndVco,D.CostoTotalVco
,D.CostoTotalMod,D.CostoTotalCif,P.DescripProd,P.IdSubgrupo,D.CodMezcla,D.CdoSubMezcla,D.Producido,D.CantVehTnsto,D.CantBrutoDesp,D.CantNetoDesp,D.CantTraDesp
FROM Trn_OilTraslado AS N INNER JOIN Trn_OilTrasladoProd AS D ON N.TipDoc=D.TipDoc AND N.NumNota=D.NumNota AND N.IdCia=D.IdCia
INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero
INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON N.IdConcepto=CT.IdConcepto
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed
LEFT JOIN CentroCosto AS CC ON N.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON N.CdSubCos=SC.IdSubCos
WHERE N.TipDoc=@pmTipDoc AND N.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND N.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOilTrasladoRubrosFmt]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOilTrasladoRubrosFmt] @pmTipDoc VARCHAR(3),@pmNumNotaIni INT,@pmNumNotaFin INT,@pmIdCia CHAR(2)
AS 
SELECT R.TipDoc,R.NumNota,R.IdCia,R.Item,R.IdProducto,P.DescripProd,R.TipoRubro,R.CantBruto,R.CantNeto,R.Cantidad,R.VrUnitario,R.VrTotal
,R.UndMed,U.Unidad,R.CodCueCP,P.IdSubgrupo
FROM Trn_OilTrasladoRubros AS R INNER JOIN ProdMcias AS P ON R.IdProducto=P.IdProducto INNER JOIN Sys_Um AS U ON R.UndMed=U.UndMed
WHERE R.TipDoc=@pmTipDoc AND R.NumNota BETWEEN @pmNumNotaIni AND @pmNumNotaFin AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOpciones]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpciones] @pmIdOpc VARCHAR(3),@pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo
 FROM adm_Opciones
 WHERE IdOpc LIKE ISNULL(@pmIdOpc,'%') AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY IdOpc
GO
/****** Object:  StoredProcedure [dbo].[paQryOpcionesLta]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpcionesLta] @pmnModulo VARCHAR(10)=Null
 AS 
 SELECT IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo
 FROM adm_Opciones
 WHERE nModulo='GENERAL' Or  nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY IdOpc
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedido]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Pedido,IdCia,Fecha,FechaVence,IdConcepto,IdCliente,IdAgencia,IdClieFact,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa
,VrImpGlobal,VrIvaIngProd,VrImpuBA,VrImpuCUP,VrNeto,Cantidad,BaseIvaIgp,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,LugarEnvio,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma
,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,AsignarVeh,pVehiculo,CdConductor,CdRuta,ListaPrec,RefPedido,Modalidad,Vigencia,NumAutoriza,NumAutCupo
,NumAutCheq,NumAprob,IdCiaApr,FecAprob,DetalleAprob,CdUsuAprob,TipFac,Factura,IdCiaFac,FechaFact,TipRem,Remision,IdCiaRem,FechaRem,NumCotizac,CdCiaCotizac,OrigenAdd,Anulado
,FecDev,ZonaFrontera,TipoTrans,TipoOrden,TipoModifica,NumAutSicom,VrImpCarbono,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Opedido
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedido_Cr]    Script Date: 10/12/2025 8:11:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedido_Cr] @pmTipDoc VARCHAR(3),@pmPedidoIni INT,@pmPedidoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc AS Tip_Doc,TipoDoc,Pedido,O.IdCia AS CdCia,Compania,O.Fecha AS FechaDoc,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,IdClieFact,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrImpCarbono,O.VrIvaIngProd,VrNeto,O.Cantidad,O.VrImpuBA,O.VrImpuCUP
,O.BaseIvaIgp,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,DiasEntraga,LugarEnvio
,O.NitContac AS NitContacto,O.NomContac AS NomContacto,O.TelContac AS TelContacto,O.emlContac AS EmailContacto,CargoContac,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago
,NitEmpTrans,EmpTrans,O.pVehiculo AS PlacaVeh,AsignarVeh,CdConductor,TC.RazonSocial AS Conductor,CdRuta,Ruta,RefPedido,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact
,TipRem,O.Remision AS NumRemision,O.IdCiaRem AS CdCiaRem,FechaRem,NumCotizac,CdCiaCotizac,NumAutoriza,NumAutCupo,NumAutCheq,Modalidad,Vigencia,NumAprob,IdCiaApr,FecAprob,DetalleAprob,CdUsuAprob,OrigenAdd,ZonaFrontera
,TipoTrans,TipoOrden,TipoModifica,NumAutSicom,Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS Fech_Add,O.FecUpdate AS Fech_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--Detalles
,K.Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,K.Remision AS KarRemision,K.IdCiaRem AS CdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev
,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,K.ListaPrec AS KarLtaPrec,VrBase,BaseIvp,TarifaIvp,IvaIngProd,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_Opedido AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Pedido=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON O.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 WHERE O.TipDoc=@pmTipDoc AND Pedido BETWEEN @pmPedidoIni AND @pmPedidoFin AND O.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY Pedido,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoAct]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoAct] @pmIdCliente VARCHAR(16),@pmIdCia CHAR(2),@pmModalidad VARCHAR(10)
 AS 
 SELECT TipDoc,Pedido,IdCia,Fecha,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos
,VrOtrDcto,VrSobretasa,VrImpGlobal,VrNeto,Factura,NumAprob
 FROM Trn_Opedido
 WHERE IdEstado='0001' AND IdCliente=@pmIdCliente AND Anulado=0 AND NumAprob>0 
 AND (Factura<=0 OR Vigencia='PERMANENTE')
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoDet] @pmPedido INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,K.IdProducto AS CdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega
,CASE WHEN O.Modalidad='PRODUCCION' THEN (CASE WHEN K.Unidades>0 THEN (K.Unidades-K.galsneto) ELSE (K.Salidas-K.galsneto) END) ELSE Salidas END AS Cantidad
,VrPrecio,Salidas*VrPrecio AS VrSubTotal,TarifaDct,VrDctoSal,TarifaIva,VrIvaSal,((Salidas*VrPrecio)-VrDctoSal)+VrIvaSal AS VrTotal,VrBruto,K.ListaPrec AS LtaPrec,VrBase,K.Referencia AS Referncia,Referencia2
,Salidas,Unidades,galsneto,CodTarDct,CodTarIva,K.IdVend AS NitVend,V.RazonSocial AS Vendedor,Comision,K.CodTarCom AS CdTarifCom,DescripProd,Servcios,Tanques,CdTanque,CdMoneda,VrTasaCamb
,O.Fecha AS FecPedido,FechaVence,DiasEntraga,IdCliente,T.RazonSocial AS Cliente,IdAgencia,Modalidad,Vigencia,O.Factura AS NumFactura,IdCiaFac,FechaFact
,O.Remision AS NumRemision,O.IdCiaRem AS CiaRem,FechaRem,CantObseq,VrIvaObseq,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBa,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
 FROM Trn_Opedido AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Pedido=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS  V ON K.IdVend=V.IdTercero
 WHERE Pedido=@pmPedido AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoDetFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedidoDetFac] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT O.TipDoc,O.Pedido,O.IdCia AS CdCia,Compania,O.Fecha,O.FechaVence,O.IdConcepto AS CdConcepto,Concepto,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,CodAgencia,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.TarifaCom
,O.VrFletes,O.VrOtros,O.VrCargos,O.VrOtrDcto,O.VrNeto,O.DirEnvio,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LugarEnvio,O.DiasEntraga,O.NitContac AS NitContacto,O.NomContac AS NomContacto,O.TelContac AS TelContacto,O.emlContac AS EmailContacto,O.CargoContac
,O.IdForma AS CdForma,FormaPago,O.DetallePago,O.MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,O.NitEmpTrans,O.EmpTrans,O.pVehiculo AS PlacaVeh,O.CdConductor,TC.RazonSocial AS Conductor,O.CdRuta,Ruta,RefPedido,O.TipFac,O.Factura,O.IdCiaFac,O.FechaFact,O.TipRem,O.Remision,O.IdCiaRem,O.FechaRem
,O.NumCotizac,CdCiaCotizac,O.NumAutoriza,O.Modalidad,O.Vigencia,O.NumAprob,O.IdCiaApr,FecAprob,CdUsuAprob,DetalleAprob,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.ZonaFrontera,TipoTrans,O.TipoOrden,TipoModifica,O.TimeSys AS FechaCrea,O.IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
--detalles
,D.Item,D.IdProducto AS CdProducto,DescripProd,PM.TipoRef,D.IdBodega AS CdBodega,Bodega,D.CdTanque,D.Salidas AS CantOrden,D.IdUnd AS CdUnd,UM.Unidad,D.VrUnitario AS CostoUnd,D.VrPrecio AS VlrUnitario,D.TarifaIva,D.VrIvaSal,D.TarifaDct,D.VrDctoSal
,D.TarifaRet,D.VrReteSal,D.TarifaIca,D.VrIcaSal,D.ListaPrec,D.VrBruto,D.VrBase,D.Unidades,D.Descripcion AS DetDescripcion,D.Referencia,D.Referencia2,D.Servcios,D.NoVentas,D.EsCombo,D.EsProdBase,D.CodTarBa,D.TarifaIba,D.VrImpuBa AS KarImpuBa,D.CodTarCup,D.TarifaCup,D.VrImpuCup AS KarImpuCup
,D.TipOrd AS DetTipoFac,D.NumOrden AS DetNumFac,D.IdCiaOrd AS DetIdCiaFac,D.galsneto AS CantTotFact,D.CantObseq,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
--datos de item facturado
,DF.TipDoc AS FacTipo,DF.Documento AS FacNumero,DF.IdCia AS FacIdCia,DF.FecFact,DF.Salidas AS FacCantidad,DF.VrUnitario AS FacCostoUnd,DF.VrPrecio AS FacVrUnitario,DF.TarifaIva AS FacTarifIva,DF.VrIvaSal AS FacVrIva
,DF.TarifaDct AS FacTarifDcto,DF.VrDctoSal AS FacVrDcto,DF.TarifaRet AS FacTarifRet,DF.TarifaIca AS FacTarifIca,DF.ListaPrec AS FacLista,DF.VrBruto AS FacVrBruto,DF.VrBase AS FacVrBase,D.Unidades AS FacUnidades,DF.Servcios AS FacServicio
,DF.EsCombo AS FacEsCombo,DF.EsProdBase AS FacProdBase,DF.galsbruto AS FacCantTotPed,DF.VrRetencion AS FacRetencion,DF.VrReteICA AS FacReteICA,DF.VrReteIVA AS FacReteIva,DF.VrFletes AS FacFletes,DF.VrOtros AS FacVrOtros,DF.VrCargos AS FacVrCargos,DF.VrOtrDcto AS FacOtrDcto
,DF.VrNeto AS FacVrNeto,DF.BaseRet,DF.VrReteCREE AS FacReteCREE
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono
,T.Fax AS TercFax,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,ExcIva,LiqFletes,Autoret,VrCupo,VrSaldo,CdDiaEnt,DiaEntrega,CLI.IdEstrato AS CdEstrato,Estrato
 FROM Trn_Opedido AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN Trn_Kardex AS D ON O.TipDoc=D.TipDoc AND O.Pedido=D.Documento AND O.IdCia=D.IdCia
 INNER JOIN ProdMcias AS PM ON D.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN Localidades AS LE ON O.IdLocEnv=LE.IdLocal LEFT JOIN Terceros AS TC ON O.CdConductor=TC.IdTercero
 LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta LEFT JOIN TiposEnt AS EG ON CLI.CdDiaEnt=EG.IdEnt LEFT JOIN Estratos AS ETT ON CLI.IdEstrato=ETT.IdEstrato
 --facturas>
 LEFT JOIN (SELECT D.TipDoc,D.Documento,D.IdCia,D.Item,D.Fecha,D.IdProducto,D.IdBodega,Salidas,VrUnitario,VrPrecio,D.TarifaIva,D.VrIvaSal,D.TarifaDct,D.VrDctoSal,D.TarifaRet,VrReteSal
,D.TarifaIca,D.VrIcaSal,ListaPrec,D.VrBruto,VrBase,D.Unidades,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.Remision,D.IdCiaRem,ItemCombo,Servcios,EsCombo,EsProdBase,galsbruto
,F.Fecha AS FecFact,F.IdConcepto AS CdConcFact,F.IdCliente,F.IdAgencia,F.VrRetencion,F.VrReteICA,F.VrReteIVA,VrFletes,F.VrOtros,VrCargos,VrOtrDcto,VrNeto,F.BaseRet,F.TarifaRet AS TarifRetFact,F.TarifaIca AS TarifIcaFact,F.TarifaRiv AS TarifRivFact
,F.TarifaRtc,F.VrReteCREE,F.Observacion FROM Trn_Kardex AS D INNER JOIN Trn_Facturas AS F ON D.TipDoc=F.TipDoc AND D.Documento=F.Factura AND D.IdCia=F.IdCia 
 WHERE D.TipDoc IN ('FCR','FC1','FC2','FC3','FC4','FC5') AND F.Anulado=0
 UNION ALL
 SELECT D.TipDoc,D.Documento,D.IdCia,D.Item,D.Fecha,D.IdProducto,D.IdBodega,Salidas,VrUnitario,VrPrecio,D.TarifaIva,D.VrIvaSal,D.TarifaDct,D.VrDctoSal,D.TarifaRet,VrReteSal
,D.TarifaIca,D.VrIcaSal,ListaPrec,D.VrBruto,VrBase,D.Unidades,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.Remision,D.IdCiaRem,ItemCombo,Servcios,EsCombo,EsProdBase,galsbruto
,F.Fecha AS FecFact,F.IdConcepto AS CdConcFact,F.NitCliente,F.CdAgencia,F.VrRetencion,F.VrReteICA,F.VrReteIVA,VrFletes,0,F.VrCargos,F.VrOtrDcto,F.VrNeto,F.BaseRet,F.TarifaRet,F.TarifaIca,F.TarifaRiv,F.TarifaRtc,F.VrReteCREE,F.Observacion
 FROM Trn_Kardex AS D INNER JOIN Trn_Factcon AS F ON D.TipDoc=F.TipDoc AND D.Documento=F.Factura AND D.IdCia=F.IdCia 
 WHERE D.TipDoc IN ('FCO','FO1','FO2','FO3','FO4','FO5') AND F.Anulado=0 AND D.TipOrd='PED' AND D.NumOrden>0) AS DF ON D.TipDoc=DF.TipOrd AND D.Documento=DF.NumOrden AND D.IdCia=DF.IdCiaOrd AND D.Item=DF.ItemCombo AND D.IdProducto=DF.IdProducto
--<Facturas
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND (@pmIdCia IS NULL OR O.IdCia=@pmIdCia) AND (@pmIdCliente IS NULL OR O.IdCliente=@pmIdCliente)
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoFac]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmPedidoIni INT=Null,@pmPedidoFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaFacIni SMALLDATETIME=Null,@pmFechaFacFin SMALLDATETIME=Null
,@pmTipoVentaIni INT=Null,@pmTipoVentaFin INT=Null
 AS 
 SELECT  Pedido,O.IdCia AS CdCia,Compania,O.Fecha AS FechaPed,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantPedido,SUM(Unidades) AS Unidades
--datos de factura
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,OrdCargue,CiaOrdCargue,FA.Remision AS FacRemision,FA.IdCiaRem AS FacCiaRem
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Modalidad,O.IdConcepto AS CdConcepto,Concepto
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,Vigencia,NumAprob,O.Remision AS PedRemision,O.IdCiaRem AS PedCiaRem,O.IdEstado AS CdEstado,Estado,O.Observacion AS Observ,DetallePago
,MAX(VrPrecio) AS OrdValorUnit,SUM(Salidas*VrPrecio) AS OrdValorTotal,SUM(VrIvaSal) AS OrdIva,SUM(VrDctoSal) AS OrdDcto
 FROM Trn_Opedido AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia   INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado  INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Pedido=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT  CASE TipOrd WHEN 'PED' THEN TipOrd ELSE 'PED' END AS TipoPed,CASE TipOrd WHEN 'PED' THEN NumOrden ELSE Cotizacion END AS NumPedido
,CASE TipOrd WHEN 'PED' THEN IdCiaOrd ELSE IdCiaCot END AS IdCiaPedido,K.TipDoc AS TipoFact,K.Documento AS NumFactura,K.IdCia AS CdCiaFac,KC.Compania AS NomCiaFac
,K.Fecha AS FecFactura,CASE TipOrd WHEN 'OCC' THEN  NumOrden ELSE 0 END AS OrdCargue,CASE TipOrd WHEN 'OCC' THEN  IdCiaOrd ELSE '00' END AS CiaOrdCargue
,Remision,IdCiaRem,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd
,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaEnt) AS IvaEntradas
,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoEnt) AS DctoEntradas,SUM(VrDctoSal) AS DctoSalidas,SUM(K.Unidades) AS TotalUnidades
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE NoVentas BETWEEN ISNULL(@pmTipoVentaIni,1) AND ISNULL(@pmTipoVentaFin,4)  AND TipOrd IN ('PED','OCC') 
 AND (CASE TipOrd WHEN 'PED' THEN NumOrden ELSE Cotizacion END)>0 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaFacIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFacFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY  CASE TipOrd WHEN 'PED' THEN TipOrd ELSE 'PED' END,CASE TipOrd WHEN 'PED' THEN NumOrden ELSE Cotizacion END
,CASE TipOrd WHEN 'PED' THEN IdCiaOrd ELSE IdCiaCot END,K.TipDoc,K.Documento,K.IdCia,KC.Compania,K.Fecha,CASE TipOrd WHEN 'OCC' THEN  NumOrden ELSE 0 END
,CASE TipOrd WHEN 'OCC' THEN  IdCiaOrd ELSE '00' END,Remision,IdCiaRem,K.IdProducto,PM.DescripProd) AS FA 
 ON O.TipDoc=FA.TipoPed AND O.Pedido=FA.NumPedido AND O.IdCia=FA.IdCiaPedido AND K.IdProducto=FA.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Pedido  BETWEEN ISNULL(@pmPedidoIni,0) AND ISNULL(@pmPedidoFin,2147483647)
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY  Pedido,O.IdCia,Compania,O.Fecha,FechaVence,K.IdProducto,DescripProd
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,OrdCargue,CiaOrdCargue,FA.Remision,FA.IdCiaRem
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,Modalidad,O.IdConcepto,Concepto
,O.IdVend,VN.RazonSocial,O.IdLocEnv,LE.Localidad,LE.IdDep,DE.Departamento
,Vigencia,NumAprob,O.Remision,O.IdCiaRem,O.IdEstado,Estado,O.Observacion,DetallePago
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedidoLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmPedidoIni INT=Null,@pmPedidoFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmVigencia VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS
 SELECT Pedido,IdCia,Fecha,FechaVence,P.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,IdClieFact,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,P.VrImpuBA,P.VrImpuCUP
,VrCargos,VrSobretasa,VrImpGlobal,VrImpCarbono,VrIvaIngProd,VrNeto,Cantidad,BaseIvaIgp,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,LugarEnvio,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac
,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,TipoTrans,NitEmpTrans,EmpTrans,pVehiculo,AsignarVeh,CdConductor,CdRuta,ListaPrec,RefPedido,TipFac,Factura,IdCiaFac,FechaFact,TipRem,Remision,IdCiaRem,FechaRem
,NumAutoriza,NumAutCupo,NumAutCheq,Modalidad,Vigencia,NumAprob,IdCiaApr,FecAprob,CdUsuAprob,DetalleAprob,TipoOrden,TipoModifica,NumCotizac,CdCiaCotizac,NumAutSicom,OrigenAdd,ZonaFrontera,Anulado,FecDev,P.Observacion AS Observ
,P.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Opedido AS P INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON P.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON P.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Pedido BETWEEN ISNULL(@pmPedidoIni,0) AND ISNULL(@pmPedidoFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND Vigencia LIKE ISNULL(@pmVigencia,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoOcc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoOcc]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmPedidoIni INT=Null,@pmPedidoFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaOrdIni SMALLDATETIME=Null,@pmFechaOrdFin SMALLDATETIME=Null
,@pmFacturaIni INT=Null,@pmFacturaFin INT=Null
 AS 
 SELECT  Pedido,O.IdCia AS CdCia,Compania,O.Fecha AS FechaPed,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantPedido,SUM(Unidades) AS Unidades
--datos de orden cargue
,OC.Documento AS OrdenCargue,CdCiaOcc,NomCiaOcc,FechaOcc,CantSalidas,VrPrecioUnit,IvaSalidas,DctoSalidas,TotalUnidades,TarifSobTasa,TarifSoldicom,TarifIglobal
,OccReferncia,Guia,IdCiaGui,OccNumFactura,OccCiaFact,OccFechaFact
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Modalidad,O.IdConcepto AS CdConcepto,Concepto
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,Vigencia,NumAprob,O.Remision AS NRemision,O.IdCiaRem AS CdCiaRem,FechaRem,O.Factura AS NumFactura,IdCiaFac,FechaFact,O.IdEstado AS CdEstado,Estado,O.Observacion AS Observ,DetallePago
,MAX(VrPrecio) AS OrdValorUnit,SUM(Salidas*VrPrecio) AS OrdValorTotal,SUM(VrIvaSal) AS OrdIva,SUM(VrDctoSal) AS OrdDcto
 FROM Trn_Opedido AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia   INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado  INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Pedido=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT  TipOrd,NumOrden,IdCiaOrd,Documento,K.IdCia AS CdCiaOcc,KC.Compania AS NomCiaOcc,K.Fecha AS FechaOcc,K.IdProducto AS CdProducto
,PM.DescripProd AS NombreProd,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoSal) AS DctoSalidas
,SUM(Unidades) AS TotalUnidades,MAX(Sobretasa) AS TarifSobTasa,MAX(Soldicom) AS TarifSoldicom,MAX(ImpGlobal) AS TarifIglobal
,O.Referncia AS OccReferncia,Guia,IdCiaGui,O.Factura AS OccNumFactura,O.IdCiaFac AS OccCiaFact,O.FechaFact AS OccFechaFact
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN Trn_OComb AS O ON K.TipDoc=O.TipDoc AND K.Documento=O.OCargue AND K.IdCia=O.IdCia
 WHERE  K.TipDoc='OCC' AND TipOrd='PED' AND NumOrden >0 AND Salidas>0 AND Anulado=0 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (O.Fecha>=ISNULL(@pmFechaOrdIni,CAST('19100101' AS SMALLDATETIME)) AND O.Fecha<=ISNULL(@pmFechaOrdFin,CAST('20781230' AS SMALLDATETIME)))
 AND O.Factura BETWEEN ISNULL(@pmFacturaIni,-1) AND ISNULL(@pmFacturaFin,2147483647)
 GROUP BY  TipOrd,NumOrden,IdCiaOrd,Documento,K.IdCia,KC.Compania,K.Fecha,K.IdProducto,PM.DescripProd,O.Referncia,Guia,IdCiaGui,O.Factura,O.IdCiaFac,O.FechaFact ) AS OC
  ON O.TipDoc=OC.TipOrd AND O.Pedido=OC.NumOrden AND O.IdCia=OC.IdCiaOrd AND K.IdProducto=OC.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Pedido  BETWEEN ISNULL(@pmPedidoIni,0) AND ISNULL(@pmPedidoFin,2147483647)
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY Pedido,O.IdCia,Compania,O.Fecha,FechaVence,K.IdProducto,DescripProd
,OC.Documento,CdCiaOcc,NomCiaOcc,FechaOcc,CantSalidas,VrPrecioUnit,IvaSalidas,DctoSalidas,TotalUnidades,TarifSobTasa,TarifSoldicom,TarifIglobal
,OccReferncia,Guia,IdCiaGui,OccNumFactura,OccCiaFact,OccFechaFact,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,Modalidad
,O.IdConcepto,Concepto,O.IdVend,VN.RazonSocial,O.IdLocEnv
,LE.Localidad,LE.IdDep,DE.Departamento,Vigencia,NumAprob,O.Remision,O.IdCiaRem,FechaRem,O.Factura,IdCiaFac,FechaFact
,O.IdEstado,Estado,O.Observacion,DetallePago
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoOpp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedidoOpp] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdInsumo VARCHAR(16)=Null,@pmIdTipProc VARCHAR(4)=Null,@pmProcFinal BIT=Null,@pmModalidad VARCHAR(10)=NuLL,@pmFecOrdenIni SMALLDATETIME=Null,@pmFecOrdenFin SMALLDATETIME=Null
,@pmNumOrdenIni INT=Null,@pmNumOrdenFin INT=Null
AS
--desde @pmIdInsumo: son parametros opcionales para comprobar en funciones IF EXISTS
SELECT O.TipDoc,O.Pedido,O.IdCia,Compania,O.Fecha,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia,Agencia,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.TarifaCom
,D.Item,D.IdProducto,DescripProd,D.IdBodega AS CdBodega,B.Bodega,D.Salidas,D.Unidades AS CantAprobado,D.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,D.VrUnitario,D.VrPrecio,D.TarifaIva
,D.VrIvaSal,D.TarifaDct,D.VrDctoSal,D.Descripcion,D.Comptmntos AS DescTallas,D.galsneto AS CantFact,D.TipOrd AS DetTipDoc,D.NumOrden AS DetNumDoc,D.IdCiaOrd AS DetCiaDoc,D.ItemCombo AS ItemDoc
,D.galsbruto AS CantRemision,D.EsProdBase,(CASE WHEN D.Unidades>0 THEN D.Unidades ELSE D.Salidas END) AS Cant_AprobPed
,C.NumCons,C.IdCia AS IdCiaCons,DC.Item AS ItemCons,DC.CantPedido AS CantPedidoCons,DC.CantAprob AS CantAprobCons,DC.CantTdo AS CantTdoCons,DC.CdBodTdo,BT.Bodega AS BodegaTdo
--resumen procesos
,OP.CantProcCons,OP.NumOrdenProc,OP.CiaOrdenProc,OP.Cant_OrdenProc,OP.Cant_Arreglos,OP.NumEntrega,OP.IdCiaEntrega,OP.Cant_Entrega,OP.Cant_Rechazo,OP.CantEntInvent,OP.NumEntInvent,OP.CiaEntInvent,OP.Costo_Entrega,OP.Costo_Arreglos
,IC.Cant_Salidas,IC.Costo_Insumos,OP.Ord_Terminados,OP.Ord_Pendientes
,O.DiasEntraga,O.NitContac AS NitContacto,O.NomContac AS NomContacto,O.TelContac AS TelContacto,O.emlContac AS EmailContacto,O.CargoContac,O.FechaVence
,O.MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,O.RefPedido,O.NumAutSicom AS NumOrdenCom,O.TipFac,O.Factura,O.IdCiaFac,O.FechaFact,O.NumAprob,O.IdCiaApr,O.FecAprob,O.DetalleAprob
,O.TipRem,D.Remision,D.IdCiaRem,O.Modalidad,O.Vigencia,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Anulado,O.TimeSys AS FechaCrea,O.IdUsuario AS CdUsuario,Usuario
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb
,P.Referencia AS Prod_Referencia,P.TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca,P.Tamano
,P.ExtciaMin,P.ExtciaMax,P.ExtciaAct,P.VrCostAnt,P.VrCosto,P.VrCostPmd,P.FecUltcom,P.FecUltVta,P.Seriales,P.Lotes,P.Combo,P.Tanques,P.Tallaje,P.DescripLong
,P.Precio1,P.Precio2,P.Precio3,P.Precio4,P.Precio5
FROM Trn_Opedido AS O INNER JOIN Trn_Kardex AS D ON O.TipDoc=D.TipDoc AND O.Pedido=D.Documento AND O.IdCia=D.IdCia
INNER JOIN Companias AS CI ON O.IdCia=CI.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie
INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
INNER JOIN Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero
INNER JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega
INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
LEFT JOIN Trn_ProdConsDet AS DC ON D.TipDoc=DC.TipPed AND D.Documento=DC.Pedido AND D.IdCia=DC.IdCiaPed AND D.Item=DC.ItemPed
LEFT JOIN Trn_ProdConsolida AS C ON DC.TipDoc=C.TipDoc AND DC.NumCons=C.NumCons AND DC.IdCia=C.IdCia
LEFT JOIN Bodegas AS BT ON DC.CdBodTdo=BT.IdBodega
--PROCESOS
LEFT JOIN (SELECT CP.TipDoc,CP.NumCons,CP.IdCia,CP.TipPed,CP.Pedido,CP.IdCiaPed,CP.ItemPed
,SUM(CASE WHEN CP.ProcFinal=1 THEN CP.Cantidad ELSE 0 END) AS CantProcCons
,MAX(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 THEN OD.NumOrden ELSE 0 END) AS NumOrdenProc
,MAX(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 THEN OD.IdCia ELSE Null END) AS CiaOrdenProc
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 THEN OD.Cantidad ELSE 0 END) AS Cant_OrdenProc
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 AND O.Modalidad='ARREGLO' THEN OD.Cantidad ELSE 0 END) AS Cant_Arreglos
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 THEN OD.CantEntrada ELSE 0 END) AS CantEntInvent
,MAX(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 THEN OD.NumEntrada ELSE 0 END) AS NumEntInvent
,MAX(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 THEN OD.CdCiaEnt ELSE 0 END) AS CiaEntInvent
,MAX(CASE WHEN ISNULL(E.Anulado,0)=0 AND CP.ProcFinal=1 THEN ED.NumEntrega ELSE 0 END) AS NumEntrega
,MAX(CASE WHEN ISNULL(E.Anulado,0)=0 AND CP.ProcFinal=1 THEN ED.IdCia ELSE Null END) AS IdCiaEntrega
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 AND ISNULL(E.Anulado,0)=0 THEN ED.Cantidad+ED.Defectuoso ELSE 0 END) AS Cant_Entrega
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND CP.ProcFinal=1 AND ISNULL(E.Anulado,0)=0 THEN ED.Rechazado ELSE 0 END) AS Cant_Rechazo
,SUM(CASE WHEN O.Modalidad<>'ARREGLO' AND ISNULL(O.Anulado,0)=0 AND ISNULL(E.Anulado,0)=0 THEN (((ED.Cantidad+ED.Defectuoso)-ED.Rechazado)*ED.CostoUnit)-ED.VrDcto ELSE 0 END) AS Costo_Entrega
,SUM(CASE WHEN O.Modalidad='ARREGLO' AND ISNULL(O.Anulado,0)=0 AND ISNULL(E.Anulado,0)=0 THEN (((ED.Cantidad+ED.Defectuoso)-ED.Rechazado)*ED.CostoUnit)-ED.VrDcto ELSE 0 END) AS Costo_Arreglos
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND ((ISNULL(OD.Terminado,0)+ISNULL(OD.Defectuoso,0))-ISNULL(OD.Rechazado,0))>=ISNULL(OD.Cantidad,0) THEN 1 ELSE 0 END) AS Ord_Terminados
,SUM(CASE WHEN ISNULL(O.Anulado,0)=0 AND ((ISNULL(OD.Terminado,0)+ISNULL(OD.Defectuoso,0))-ISNULL(OD.Rechazado,0))<ISNULL(OD.Cantidad,0) THEN 1 ELSE 0 END) AS Ord_Pendientes
FROM Trn_ProdConsProc AS CP LEFT JOIN Trn_ProdOrdenDet AS OD ON CP.TipDoc=OD.TipCons AND CP.NumCons=OD.NumCons AND CP.IdCia=OD.IdCiaCons AND CP.Item=OD.ItemCons
LEFT JOIN Trn_ProdOrden AS O ON OD.TipDoc=O.TipDoc AND OD.NumOrden=O.NumOrden AND OD.IdCia=O.IdCia 
LEFT JOIN Trn_ProdEntregaDet AS ED ON OD.TipDoc=ED.TipOrden AND OD.NumOrden=ED.NumOrden AND OD.IdCia=ED.IdCiaOrden AND OD.Item=ED.ItemOrden
LEFT JOIN Trn_ProdEntrega AS E ON ED.TipDoc=E.TipDoc AND ED.NumEntrega=E.NumEntrega AND ED.IdCia=E.IdCia
WHERE CP.TipDoc='CPP' GROUP BY CP.TipDoc,CP.NumCons,CP.IdCia,CP.TipPed,CP.Pedido,CP.IdCiaPed,CP.ItemPed)
AS OP ON D.TipDoc=OP.TipPed AND D.Documento=OP.Pedido AND D.IdCia=OP.IdCiaPed AND D.Item=OP.ItemPed AND DC.TipDoc=OP.TipDoc AND DC.NumCons=OP.NumCons AND DC.IdCia=OP.IdCia
--Costo de insumos
LEFT JOIN (SELECT IM.TipDoc,IM.NumCons,IM.IdCia,IM.TipPed,IM.Pedido,IM.IdCiaPed,IM.ItemPed,SUM(IM.Cantidad) AS Cant_Insumos
,SUM(IM.CantSalidas) AS Cant_Salidas,SUM(IM.CantSalidas*IM.CostoUntSai) AS Costo_Insumos
FROM Trn_ProdConsInsu AS IM WHERE IM.TipDoc='CPP' GROUP BY IM.TipDoc,IM.NumCons,IM.IdCia,IM.TipPed,IM.Pedido,IM.IdCiaPed,IM.ItemPed) AS IC ON D.TipDoc=IC.TipPed AND D.Documento=IC.Pedido AND D.IdCia=IC.IdCiaPed AND D.Item=IC.ItemPed AND DC.TipDoc=IC.TipDoc AND DC.NumCons=IC.NumCons AND DC.IdCia=IC.IdCia
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND ISNULL(C.Anulado,0)=0
AND dbo.FuncProdPedidoInsu(O.TipDoc,O.Pedido,O.IdCia,D.IdProducto,@pmIdInsumo)=1 
AND dbo.FuncProdConsProc(DC.TipDoc,DC.NumCons,DC.IdCia,O.TipDoc,O.Pedido,O.IdCia,D.Item,@pmIdTipProc)=1
AND dbo.FuncProdConsProcFinal(DC.TipDoc,DC.NumCons,DC.IdCia,O.TipDoc,O.Pedido,O.IdCia,D.Item,@pmProcFinal)=1
AND dbo.FuncProdOrdenTipo(DC.TipDoc,DC.NumCons,DC.IdCia,DC.Item,@pmModalidad)=1
AND dbo.FuncProdOrdenFecha(DC.TipDoc,DC.NumCons,DC.IdCia,DC.Item,@pmFecOrdenIni,@pmFecOrdenFin)=1
AND dbo.FuncProdOrdenNum(DC.TipDoc,DC.NumCons,DC.IdCia,DC.Item,@pmNumOrdenIni,@pmNumOrdenFin)=1
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoPen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoPen] @pmFactura INT,@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Pedido,P.IdCia AS CodCia,Compania,Fecha,DiasEntraga,FechaVence,P.IdConcepto AS CodConcepto,Concepto,IdCliente,T.RazonSocial AS Cliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto
,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,IdVend,V.RazonSocial AS Vendedor,DirEnvio,IdLocEnv,Localidad,NitContac,NomContac,TelContac,emlContac,CargoContac
,P.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,ListaPrec,TipFac,Factura,IdCiaFac,FechaFact
,TipRem,Remision,IdCiaRem,FechaRem,NumAutoriza,Modalidad,Vigencia,OrigenAdd,ZonaFrontera,TipoTrans,TipoOrden,Anulado,FecDev,P.Observacion AS Observ,P.IdEstado AS CodEstado,Estado,P.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Opedido AS P  INNER JOIN Terceros AS T ON  P.IdCliente=T.IdTercero
 INNER JOIN  Conceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS V ON P.IdVend=V.IdTercero
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia
 INNER JOIN Formaspago AS F ON P.IdForma=F.IdForma
 INNER JOIN Localidades AS L ON P.IdLocEnv=L.IdLocal
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  Anulado=0
 AND (Modalidad='PERMANENTE' or Factura<=@pmFactura)
 AND P.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY P.IdCia,Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedidoRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Pedido,O.IdCia AS CdCia,Compania,Fecha,FechaVence,O.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,IdClieFact,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrSobretasa,VrImpGlobal,VrImpCarbono,O.VrNeto,O.Cantidad,O.VrImpuBA,O.VrImpuCUP
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio,LugarEnvio,DiasEntraga
,O.NitContac AS NitContacto,O.NomContac AS NomContacto,O.TelContac AS TelContacto,O.emlContac AS EmailContacto,CargoContac,O.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago
,NitEmpTrans,EmpTrans,AsignarVeh,O.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor,O.CdRuta,Ruta,RefPedido,TipFac,Factura,IdCiaFac,FechaFact
,TipRem,Remision,IdCiaRem,FechaRem,NumCotizac,CdCiaCotizac,NumAutoriza,Modalidad,Vigencia,NumAprob,IdCiaApr,FecAprob,CdUsuAprob,DetalleAprob,OrigenAdd,Anulado,FecDev,O.Observacion AS Observ
,O.IdEstado AS CdEstado,Estado,ZonaFrontera,TipoTrans,TipoOrden,TipoModifica,CdBodega,DesBodega,TimeSys,O.FecUpdate AS Fech_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_Opedido AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON O.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 --subconsulta para filtrar por bodega
 LEFT JOIN (SELECT K.TipDoc AS CdTipDoc,K.Documento AS NumDoc,K.IdCia AS CodCia,K.IdBodega AS CdBodega,Bodega AS DesBodega,SUM(K.Salidas) AS SSAL
 FROM Trn_Kardex AS K INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega WHERE K.TipDoc='PED' AND Item=1 GROUP BY K.TipDoc,K.Documento,K.IdCia,K.IdBodega,Bodega) 
 AS KD ON O.TipDoc=KD.CdTipDoc AND O.Pedido=KD.NumDoc AND O.IdCia=KD.CodCia
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoRem] @pmRemision INT,@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Pedido,P.IdCia AS CodCia,T.RazonSocial AS Cliente,IdCliente,IdAgencia,pVehiculo,CdConductor,Fecha
,DiasEntraga,FechaVence,P.IdConcepto AS CodConcepto,Concepto,VrSubTotal,VrDescuento,VrImpuesto
,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,IdVend,V.RazonSocial AS Vendedor,DirEnvio,IdLocEnv,Localidad,NitContac,NomContac,TelContac,emlContac,CargoContac
,P.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,CdRuta,ListaPrec,Compania
,TipFac,Factura,IdCiaFac,FechaFact,NumAutoriza,Modalidad,Vigencia,OrigenAdd,Anulado,FecDev,P.Observacion AS Observ,P.IdEstado AS CodEstado,Estado,P.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Opedido AS P  INNER JOIN Terceros AS T ON  P.IdCliente=T.IdTercero
 INNER JOIN  Conceptos AS C ON P.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS V ON P.IdVend=V.IdTercero
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia
 INNER JOIN Formaspago AS F ON P.IdForma=F.IdForma
 INNER JOIN Localidades AS L ON P.IdLocEnv=L.IdLocal
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND  Anulado=0 AND Factura<=0
 AND (Modalidad='PERMANENTE' or Remision<=@pmRemision)
 AND P.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY P.IdCia,Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRms]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoRms]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmPedidoIni INT=Null,@pmPedidoFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaOrdIni SMALLDATETIME=Null,@pmFechaOrdFin SMALLDATETIME=Null
,@pmFacturaIni INT=Null,@pmFacturaFin INT=Null
 AS 
 SELECT  Pedido,O.IdCia AS CdCia,Compania,O.Fecha AS FechaPed,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantPedido,SUM(Unidades) AS Unidades
--datos de remision
,RM.Documento AS NRemision,CdCiaRem,NomCiaRem,FecRemision,CantSalidas,VrPrecioUnit,IvaSalidas,DctoSalidas
,TotalUnidades,FechaDesp,FecVceRem,RM.VrFletes AS VrFletesRem,RM.IdLocEnv AS CdCiudadRem,RM.Localidad AS CiudadRem,RM.NumAprob AS RemNumAprob,RemFactura,RM.IdCiaFac AS RemCiaFact,RM.FechaFact AS RemFechaFact
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Modalidad,O.IdConcepto AS CdConcepto,Concepto
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,Vigencia,O.NumAprob AS PedNumAprob,O.Factura AS PedNFactura,O.IdCiaFac AS PedCiaFact,O.FechaFact AS PedFechaFac,O.IdEstado AS CdEstado,Estado,O.Observacion AS Observ,DetallePago
,MAX(VrPrecio) AS OrdValorUnit,SUM(Salidas*VrPrecio) AS OrdValorTotal,SUM(VrIvaSal) AS OrdIva,SUM(VrDctoSal) AS OrdDcto
 FROM Trn_Opedido AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia   INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado  INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Pedido=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT  TipOrd,NumOrden,IdCiaOrd,Documento,K.IdCia AS CdCiaRem,KC.Compania AS NomCiaRem,K.Fecha AS FecRemision,K.IdProducto AS CdProducto
,PM.DescripProd AS NombreProd,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoSal) AS DctoSalidas
,SUM(K.Unidades) AS TotalUnidades,FechaDesp,R.FechaVence AS FecVceRem,VrFletes,IdLocEnv,Localidad,NumAprob,R.Factura AS RemFactura,IdCiaFac,FechaFact
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN Trn_Remision AS R ON K.TipDoc=R.TipDoc AND K.Documento=R.Remision AND K.IdCia=R.IdCia
 LEFT JOIN  Localidades AS LE ON R.IdLocEnv=LE.IdLocal 
 WHERE  K.TipDoc='REM' AND TipOrd='PED' AND NumOrden>0 AND  Anulado=0 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (R.Fecha>=ISNULL(@pmFechaOrdIni,CAST('19100101' AS SMALLDATETIME)) AND R.Fecha<=ISNULL(@pmFechaOrdFin,CAST('20781230' AS SMALLDATETIME)))
 AND R.Factura BETWEEN ISNULL(@pmFacturaIni,-1) AND ISNULL(@pmFacturaFin,2147483647)
 GROUP BY  TipOrd,NumOrden,IdCiaOrd,Documento,K.IdCia,KC.Compania,K.Fecha,K.IdProducto,PM.DescripProd
 ,FechaDesp,FechaVence,VrFletes,IdLocEnv,Localidad,NumAprob,R.Factura,IdCiaFac,FechaFact) AS RM
  ON O.TipDoc=RM.TipOrd AND O.Pedido=RM.NumOrden AND O.IdCia=RM.IdCiaOrd AND K.IdProducto=RM.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Pedido  BETWEEN ISNULL(@pmPedidoIni,0) AND ISNULL(@pmPedidoFin,2147483647)
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY Pedido,O.IdCia,Compania,O.Fecha,FechaVence,K.IdProducto,DescripProd,RM.Documento
,CdCiaRem,NomCiaRem,FecRemision,CantSalidas,VrPrecioUnit,IvaSalidas,DctoSalidas,TotalUnidades,FechaDesp
,FecVceRem,RM.VrFletes,RM.IdLocEnv,RM.Localidad,RM.NumAprob,RemFactura,RM.IdCiaFac,RM.FechaFact
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,Modalidad,O.IdConcepto,Concepto,O.IdVend,VN.RazonSocial,O.IdLocEnv
,LE.Localidad,LE.IdDep,DE.Departamento,Vigencia,O.NumAprob,O.Remision,O.IdCiaRem,FechaRem,O.Factura,O.IdCiaFac,O.FechaFact
,O.IdEstado,Estado,O.Observacion,DetallePago
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoRmsn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOpedidoRmsn] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
SELECT O.TipDoc,O.Pedido,O.IdCia,Compania,O.Fecha,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia,Agencia,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.TarifaCom
,D.Item,D.IdProducto,DescripProd,D.IdBodega AS CdBodega,B.Bodega,D.Salidas,D.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,D.VrUnitario,D.VrPrecio,D.TarifaIva
,D.VrIvaSal,D.TarifaDct,D.VrDctoSal,D.Descripcion,D.Comptmntos AS DescTallas,D.galsneto AS CantFact,D.TipOrd AS DetTipDoc,D.NumOrden AS DetNumDoc,D.IdCiaOrd AS DetCiaDoc,D.ItemCombo AS ItemDoc
,D.Remision,D.IdCiaRem,D.galsbruto AS CantTotalRem,D.Cotizacion,D.IdCiaCot,D.EsProdBase,(CASE WHEN D.Unidades>0 AND D.TipDocDev='PPD' THEN D.Unidades ELSE D.Salidas END) AS Cant_Aprob,D.Referencia,D.Referencia2
,D.CdOperario,OP.RazonSocial AS NomOperario,D.ComisnOper,D.TipDocDev,D.Servcios
,O.DiasEntraga,O.NitContac AS NitContacto,O.NomContac AS NomContacto,O.TelContac AS TelContacto,O.emlContac AS EmailContacto,O.CargoContac,O.FechaVence
,O.MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,O.RefPedido,O.NumAutSicom AS NumOrdenCom,O.TipFac,O.Factura,O.IdCiaFac,O.FechaFact,O.NumAprob,O.IdCiaApr,O.FecAprob,O.DetalleAprob
,O.Modalidad,O.Vigencia,O.IdConcepto,Concepto,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Anulado,O.TimeSys AS FechaCrea,O.IdUsuario AS CdUsuario,Usuario
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb
,P.Referencia AS Prod_Referencia,P.TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca,P.Tamano
,P.ExtciaMin,P.ExtciaMax,P.ExtciaAct,P.VrCostAnt,P.VrCosto,P.VrCostPmd,P.FecUltcom,P.FecUltVta,P.Seriales,P.Lotes,P.Combo,P.Tanques,P.Tallaje,P.DescripLong
,P.Precio1,P.Precio2,P.Precio3,P.Precio4,P.Precio5
--detalle de remisiones
,RM.NumRemison,RM.IdCia AS CiaRemision,RM.ItemRem,RM.Salidas AS CantRemision,RM.Referencia AS RefRemision,RM.Descripcion AS DescRemision,RM.DescTallas AS TallasRem
,RM.Fecha AS FecRemision,RM.FechaDesp,RM.FechaVence AS FecVenceRem,RM.DiasEntraga AS DiasEntregaRem,RM.Observacion AS ObservRemision
FROM Trn_Opedido AS O INNER JOIN Trn_Kardex AS D ON O.TipDoc=D.TipDoc AND O.Pedido=D.Documento AND O.IdCia=D.IdCia
INNER JOIN Companias AS CI ON O.IdCia=CI.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie
INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
INNER JOIN Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero
INNER JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia INNER JOIN Conceptos AS CN ON O.IdConcepto=CN.IdConcepto
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega
INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
LEFT JOIN Terceros AS OP ON D.CdOperario=OP.IdTercero
--remisiones
LEFT JOIN (SELECT K.Documento AS NumRemison,K.IdCia,K.Item AS ItemRem,K.IdProducto,K.IdBodega,K.Entradas,K.Salidas,K.Unidades,K.VrUnitario,K.VrPrecio,K.pVehiculo
,K.Referencia,K.Descripcion,K.Comptmntos AS DescTallas,K.TipOrd,K.NumOrden,K.IdCiaOrd,K.ItemCombo AS ItemOrden,K.Servcios
,R.Fecha,R.FechaDesp,R.FechaVence,R.DiasEntraga,R.IdLocEnv,R.DirEnvio,R.EmpTrans,R.NitEmpTrans,R.pVehiculo AS RemVehiculo,R.CdConductor,R.DetalleEnvio
,R.TipFac,R.Factura,R.IdCiaFac,R.Modalidad,R.Observacion
FROM Trn_Kardex AS K INNER JOIN Trn_Remision AS R ON K.TipDoc=R.TipDoc AND K.Documento=R.Remision AND K.IdCia=R.IdCia
WHERE K.TipDoc='REM' AND K.TipOrd='PED' AND K.NumOrden>0 AND R.Anulado=0) AS RM ON O.TipDoc=RM.TipOrd AND O.Pedido=RM.NumOrden AND O.IdCia=RM.IdCiaOrd AND D.Item=RM.ItemOrden
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryOpedidoSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryOpedidoSal] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmPedidoIni INT=Null,@pmPedidoFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaSalIni SMALLDATETIME=Null,@pmFechaSalFin SMALLDATETIME=Null
 AS 
 SELECT  Pedido,O.IdCia AS CdCia,Compania,O.Fecha AS FechaPed,FechaVence,K.IdProducto AS CodProducto,DescripProd,SUM(Salidas) AS CantPedido,SUM(Unidades) AS Unidades
--datos de salidas
,TipoSalida,NumSalida,CdCiaSal,NomCiaSal,FecSalida,CdProducto,NombreProd,CantEntradas,CantSalidas,ValorUnit,CostoEntradas,CostoSalidas,IvaEntradas,IvaSalidas,TotalUnidades
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Modalidad,O.IdConcepto AS CdConcepto,Concepto
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,Vigencia,NumAprob,O.Remision AS PedRemision,O.IdCiaRem AS PedCiaRem,O.IdEstado AS CdEstado,Estado,O.Observacion AS Observ,DetallePago
,MAX(VrPrecio) AS OrdValorUnit,SUM(Salidas*VrPrecio) AS OrdValorTotal,SUM(VrIvaSal) AS OrdIva,SUM(VrDctoSal) AS OrdDcto
 FROM Trn_Opedido AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia   INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado  INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Pedido=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal  LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT TipOrd,NumOrden,IdCiaOrd,K.TipDoc AS TipoSalida,K.Documento AS NumSalida,K.IdCia AS CdCiaSal,KC.Compania AS NomCiaSal
,K.Fecha AS FecSalida,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd
,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrUnitario) AS ValorUnit,SUM(VrCostoEnt) AS CostoEntradas,SUM(VrCostoSal) AS CostoSalidas
,SUM(VrIvaEnt) AS IvaEntradas,SUM(VrIvaSal) AS IvaSalidas,SUM(K.Unidades) AS TotalUnidades
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE TipDoc IN ('SAL','DVS') AND TipOrd='PED' AND NumOrden>0  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaSalIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaSalFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY  TipOrd,NumOrden,IdCiaOrd,K.TipDoc,K.Documento,K.IdCia,KC.Compania,K.Fecha,K.IdProducto,PM.DescripProd) AS SD 
 ON O.TipDoc=SD.TipOrd AND O.Pedido=SD.NumOrden AND O.IdCia=SD.IdCiaOrd AND K.IdProducto=SD.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Pedido  BETWEEN ISNULL(@pmPedidoIni,0) AND ISNULL(@pmPedidoFin,2147483647)
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY  Pedido,O.IdCia,Compania,O.Fecha,FechaVence,K.IdProducto,DescripProd
,TipoSalida,NumSalida,CdCiaSal,NomCiaSal,FecSalida,CdProducto,NombreProd,CantEntradas,CantSalidas,ValorUnit,CostoEntradas,CostoSalidas,IvaEntradas,IvaSalidas,TotalUnidades
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,Modalidad,O.IdConcepto,Concepto
,O.IdVend,VN.RazonSocial,O.IdLocEnv,LE.Localidad,LE.IdDep,DE.Departamento
,Vigencia,NumAprob,O.Remision,O.IdCiaRem,O.IdEstado,Estado,O.Observacion,DetallePago
GO
/****** Object:  StoredProcedure [dbo].[paQryOrgTransito]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOrgTransito] @pmIdOrgTra VARCHAR(8)
 AS 
 SELECT IdOrgTra,NomOrgTrans,IdLocal,Inactivo
 FROM OrgTransito
 WHERE IdOrgTra=@pmIdOrgTra
GO
/****** Object:  StoredProcedure [dbo].[paQryOrgTransitoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryOrgTransitoLta] 
 AS 
 SELECT IdOrgTra,NomOrgTrans,OG.IdLocal AS CdLocal,Localidad
 FROM OrgTransito AS OG INNER JOIN Localidades AS L ON OG.IdLocal=L.IdLocal
 WHERE OG.Inactivo=0
 ORDER BY NomOrgTrans
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma
,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta
,CdProducto,FE_Ticket,Cant_Gals,PrecioBase,PrecioUnit,ConsCP,CodCueCons,PrecioPub,RefVehiculo,RefNumVeh,IdUsuario
 FROM Trn_Pagos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_Bus]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagos_Bus] @pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdForma VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmEsCaja BIT=Null,@pmIdBanco VARCHAR(4)=Null
,@pmDocumentoIni INT=Null,@pmDocumentoFin INT=Null,@pmNitCliente VARCHAR(16)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT P.TipDoc AS CdTipDoc,TipoDoc,Documento,P.IdCia AS CodCia,Compania,P.Fecha AS FechaRec,Item,P.IdForma AS CdForma,FormaPago,Detalle
,VrPagado,VrCambio,EsCaja,P.IdBanco AS CodBanco,B.Banco AS NomBanco,NumForma,FecForma,CtaForma,Beneficiario
,NitCliente,T.RazonSocial AS NomCliente,CdAgencia,Referncia1,Referncia2,NumAutoriza,P.CdLocal AS CodCiudad,LF.Localidad AS CiudadPlaza,LF.IdDep AS CdDptoPlaza
,DF.Departamento AS DptoPlaza,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BC.Banco AS CtaBanco,VrDenom,Cantidad,TipDenom
,TipRef,DocRef,IdCiaRef,ItemDoc,P.ConsCP,P.CodCueCons,P.IdUsuario AS IdUsuari,Usuario
--datos de recibo de caja
,R.IdVehiculo AS PlacaVeh,NumVeh,R.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,Modalidad,TipCar,Cartulina,IdCiaCar,R.CentInicial AS CentenaIni,R.CentFinal AS CentenaFin
--Información del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDV,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,L.IdDep AS TercCdDep,D.Departamento AS TercDpto
 FROM  Trn_Pagos AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS B ON P.IdBanco=B.IdBanco
 LEFT JOIN Terceros AS T ON P.NitCliente=T.IdTercero 
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep 
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN CtasCorrientes AS CTA ON P.CdCta=CTA.IdCta LEFT JOIN  Bancos AS BC ON CTA.IdBanco=BC.IdBanco
 LEFT JOIN Trn_RecBuses AS R ON P.TipDoc=R.TipDoc AND P.Documento=R.Recibo AND P.IdCia=R.IdCia
 LEFT JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo LEFT JOIN Terceros AS NC ON R.IdConductor =NC.IdTercero
 WHERE  P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND P.TipDoc IN ('RC1','OD1','CNS','DVC','RCO','DRC') AND P.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdForma  LIKE ISNULL(@pmIdForma,'%') AND P.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND  (EsCaja=ISNULL(@pmEsCaja,0) or EsCaja=ISNULL(@pmEsCaja,1))
 AND Documento BETWEEN ISNULL(@pmDocumentoIni,0) AND ISNULL(@pmDocumentoFin,2147483647)
 AND  NitCliente LIKE ISNULL(@pmNitCliente,'%') AND P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 ORDER BY P.TipDoc,P.IdCia,Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagos_Cr] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,TipoDoc,Documento,P.IdCia AS CodCia,Compania,Fecha,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja
,P.IdBanco AS CodBanco,B.Banco AS NomBanco,NitCliente,RazonSocial,CdAgencia,Agencia,CodAgencia,A.Referencia AS RefeAgencia,NumForma
,FecForma,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,LF.Localidad AS CiudadPlaza,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,CdProducto,FE_Ticket
,Cant_Gals,PrecioBase,PrecioUnit,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BC.Banco AS CtaBanco,P.ConsCP,P.CodCueCons,P.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,TipoId,Dv,T.Codigo AS TerCodigo,NomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento,Telefono,e_mail
 FROM  Trn_Pagos AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS B ON P.IdBanco=B.IdBanco
 LEFT JOIN Terceros AS T ON P.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON P.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal 
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN CtasCorrientes AS CTA ON P.CdCta=CTA.IdCta LEFT JOIN  Bancos AS BC ON CTA.IdBanco=BC.IdBanco
 WHERE P.TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND P.IdCia=@pmIdCia
 ORDER BY Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_Lta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPagos_Lta] @pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdForma VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmEsCaja BIT=Null,@pmIdBanco VARCHAR(4)=Null
,@pmDocumentoIni INT=Null,@pmDocumentoFin INT=Null,@pmNitCliente VARCHAR(16)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT TipDoc,TipoDoc,Documento,P.IdCia AS CodCia,Compania,Fecha,Item,P.IdForma AS CdForma,FormaPago,Detalle
,VrPagado,VrCambio,EsCaja,P.IdBanco AS CodBanco,B.Banco AS NomBanco,NumForma,FecForma,CtaForma,Beneficiario
,NitCliente,RazonSocial,CdAgencia,Agencia,CodAgencia,A.Referencia AS RefeAgencia,Referncia1,Referncia2,NumAutoriza,CdLocal,LF.Localidad AS CiudadPlaza,LF.IdDep AS CdDptoPlaza
,DF.Departamento AS DptoPlaza,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BC.Banco AS CtaBanco,VrDenom,Cantidad,TipDenom
,TipRef,DocRef,IdCiaRef,ItemDoc,P.CdProducto,FE_Ticket,Cant_Gals,PrecioBase,PrecioUnit,P.ConsCP,P.CodCueCons,P.PrecioPub,P.RefVehiculo,P.RefNumVeh,P.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,TipoId,Dv,T.Codigo AS TerCodigo,NomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,L.IdDep AS TercCdDep,D.Departamento AS TercDpto,DocAnulado,NumDev,FecDev
 FROM  Trn_Pagos AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS B ON P.IdBanco=B.IdBanco
 LEFT JOIN Terceros AS T ON P.NitCliente=T.IdTercero  LEFT JOIN Agencias  AS A ON P.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal  LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep 
 LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN CtasCorrientes AS CTA ON P.CdCta=CTA.IdCta LEFT JOIN  Bancos AS BC ON CTA.IdBanco=BC.IdBanco
 LEFT JOIN (SELECT RC.TipDoc AS DocTipo,RC.Recibo AS DocNumero,RC.IdCia AS DocCia,RC.Anulado AS DocAnulado,NumDev,FecDev FROM Trn_Recibos AS RC 
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Factura,IdCia,Anulado,NumDev,FecDev FROM Trn_Factcon  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Consignacion,IdCia,Anulado,NumDev,FecDev FROM Trn_Consigna  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Recibo,IdCia,Anulado,NumDev,FecDev FROM Trn_CompCaja  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Planilla,IdCia,Anulado,NumDev,FecDev FROM Trn_EdsCortes  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  ) AS DOC ON P.TipDoc=DOC.DocTipo AND P.Documento=DOC.DocNumero  AND P.IdCia=DOC.DocCia
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND P.TipDoc LIKE ISNULL(@pmTipDoc,'%') AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdForma  LIKE ISNULL(@pmIdForma,'%') AND P.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND  (EsCaja=ISNULL(@pmEsCaja,0) or EsCaja=ISNULL(@pmEsCaja,1))
 AND Documento BETWEEN ISNULL(@pmDocumentoIni,0) AND ISNULL(@pmDocumentoFin,2147483647)
 AND  NitCliente LIKE ISNULL(@pmNitCliente,'%') AND P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 ORDER BY TipDoc,P.IdCia,Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPagos_LtaTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagos_LtaTot] @pmTipDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmIdForma VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmEsCaja BIT=Null,@pmIdBanco VARCHAR(4)=Null
,@pmDocumentoIni INT=Null,@pmDocumentoFin INT=Null,@pmNitCliente VARCHAR(16)=Null,@pmIdUsuario VARCHAR(11)=Null
,@pmAnulado BIT=Null
--******** NO SE ESTA UTILIZANDO
 AS 
 SELECT TipDoc,TipoDoc,COUNT(Documento) AS sCuenta,SUM(VrPagado) AS ValorTotal,SUM(VrCambio) AS TotalCambio,SUM(VrPagado-VrCambio) AS TotalPagado
,SUM(Cantidad) AS CantDenom,SUM(VrDenom*Cantidad) AS TotalDenom
 FROM  Trn_Pagos AS P INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc
 LEFT JOIN Terceros AS T ON P.NitCliente=T.IdTercero 
 LEFT JOIN (SELECT RC.TipDoc AS DocTipo,RC.Recibo AS DocNumero,RC.IdCia AS DocCia,RC.Anulado AS DocAnulado  FROM Trn_Recibos AS RC 
  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Factura,IdCia,Anulado FROM Trn_Factcon  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Consignacion,IdCia,Anulado FROM Trn_Consigna  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Recibo,IdCia,Anulado FROM Trn_CompCaja  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  UNION SELECT TipDoc,Planilla,IdCia,Anulado FROM Trn_EdsCortes  WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
  ) AS DOC ON P.TipDoc=DOC.DocTipo AND P.Documento=DOC.DocNumero  AND P.IdCia=DOC.DocCia
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND P.TipDoc LIKE ISNULL(@pmTipDoc,'%') AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdForma  LIKE ISNULL(@pmIdForma,'%') AND P.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND  (EsCaja=ISNULL(@pmEsCaja,0) or EsCaja=ISNULL(@pmEsCaja,1))
 AND Documento BETWEEN ISNULL(@pmDocumentoIni,0) AND ISNULL(@pmDocumentoFin,2147483647)
 AND  NitCliente LIKE ISNULL(@pmNitCliente,'%') AND P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND  (DocAnulado=ISNULL(@pmAnulado,0) or DocAnulado=ISNULL(@pmAnulado,1))
 GROUP BY TipDoc,TipoDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagosAcu] @pmFecha SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT TipDoc,IdCia,IdUsuario,SUM(VrPagado-VrCambio) AS STOTPAG
 FROM Trn_Pagos
 WHERE Fecha=@pmFecha AND EsCaja<>0  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 GROUP BY TipDoc,IdCia,IdUsuario
 ORDER BY IdCia,IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosChe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagosChe] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma
,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta,ConsCP,CodCueCons
 FROM Trn_Pagos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND (IdForma IN ('CHE','BON','CON','TRA') OR IdForma LIKE 'CH%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosCns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPagosCns] @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdCia CHAR(2)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmIdForma VARCHAR(4)=Null,@pmNitCliente VARCHAR(16)=Null,@pmCdAgencia VARCHAR(16)=Null
,@pmDocIni INT=Null,@pmDocFin INT=Null
 AS 
 SELECT TipDoc,Documento,IdCia,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,P.IdBanco AS CdBanco,Banco,NumForma,Fecha,FecForma,CtaForma
,Beneficiario,Referncia1,Referncia2,NumAutoriza,NitCliente,RazonSocial,CdAgencia,CdLocal,Localidad,CdCta
,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,EsCaja,ConsCP,CodCueCons,P.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Pagos AS P INNER JOIN Formaspago AS F ON P.IdForma=F.IdForma
 INNER JOIN  Bancos AS B ON P.IdBanco=B.IdBanco  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Localidades AS L ON P.CdLocal=L.IdLocal
 LEFT JOIN Terceros AS T ON P.NitCliente=T.IdTercero
 WHERE TipDoc IN ('REC','FCO','FO1','FO2','FO3','FO4','FO5','PLA','RCO','RC1','RC2' )
 AND ((TipRef='CNS' AND DocRef<=0) OR (TipRef='EGO' AND DocRef<=0) OR (TipRef<>'CNS' AND TipRef<>'EGO')  )
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND P.IdForma LIKE ISNULL(@pmIdForma,'%')
 AND NitCliente LIKE ISNULL(@pmNitCliente,'%') AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%')
 AND Documento BETWEEN ISNULL(@pmDocIni,0) AND ISNULL(@pmDocFin,2147483647)
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY IdCia,TipDoc,Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosDsd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagosDsd] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS CodBanco,Banco,NumForma,FecForma
,CtaForma,Beneficiario,Referncia1,Referncia2,NumAutoriza,NitCliente,CdAgencia,CdLocal,TipDenom,VrDenom,Cantidad
,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta,ConsCP,CodCueCons,P.IdUsuario AS IdUsuari,Usuario,TipDoc,Documento,IdCia,Fecha
 FROM Trn_Pagos AS P INNER JOIN Formaspago AS F ON P.IdForma=F.IdForma
 INNER JOIN  Bancos AS B ON P.IdBanco=B.IdBanco
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosFdvc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagosFdvc]  @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCiaDoc CHAR(2)
,@pmIdForma VARCHAR(4),@pmIdBanco VARCHAR(4),@pmNumForma VARCHAR(20)
 AS 
 SELECT  TipDev,Devolucion,D.IdCia AS CodCia,D.Fecha AS FechDev,Consignacion,IdCiaDoc,FecDoc
,Item,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma
,CtaForma,Beneficiario,Referncia1,P.Referncia2 AS Refncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta
 FROM  Trn_DevCns AS D INNER JOIN  Trn_Pagos AS P ON D.TipDev=P.TipDoc AND D.Devolucion=P.Documento AND D.IdCia=P.IdCia
 WHERE D.TipDoc=@pmTipDoc  AND Consignacion=@pmConsignacion AND IdCiaDoc=@pmIdCiaDoc
 AND IdForma=@pmIdForma AND IdBanco=@pmIdBanco AND NumForma=@pmNumForma
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagosFor] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdForma VARCHAR(4),@pmNumForma VARCHAR(20),@pmIdBanco VARCHAR(4)
 AS 
 SELECT Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma
,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,CdCta,CdProducto
,FE_Ticket,IdUsuario,ConsCP,CodCueCons
 FROM Trn_Pagos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND IdForma=@pmIdForma  AND NumForma=@pmNumForma AND IdBanco=@pmIdBanco
GO
/****** Object:  StoredProcedure [dbo].[paQryPagosTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPagosTot] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdUsuario VARCHAR(11)=Null
 AS 
 SELECT TipDoc,SUM(CASE EsCaja WHEN 1 THEN VrPagado-VrCambio ELSE 0 END)  AS  STOTCAJA
,SUM(CASE EsCaja WHEN 0 THEN VrPagado-VrCambio ELSE 0 END)  AS  STOTOTROS
 FROM Trn_Pagos
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 GROUP BY TipDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryPaises]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPaises] @pmIdPais VARCHAR(8)
 AS 
 SELECT IdPais,CodISO,NombrePais,IdMneda
 FROM adm_Paises
 WHERE IdPais=@pmIdPais
GO
/****** Object:  StoredProcedure [dbo].[paQryPaisesIso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPaisesIso] @pmCodISO VARCHAR(3)
 AS 
 SELECT IdPais,CodISO,NombrePais,IdMneda
 FROM adm_Paises
 WHERE CodISO=@pmCodISO
GO
/****** Object:  StoredProcedure [dbo].[paQryPaisesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPaisesLta] @pmIdPais VARCHAR(8)=Null
 AS 
 SELECT IdPais,CodISO,NombrePais,P.IdMneda AS CodMneda,Mneda,Simbolo,MneLocal,VrCambio
 FROM adm_Paises AS P INNER JOIN adm_monedas AS M ON P.IdMneda=M.IdMneda
 WHERE IdPais LIKE ISNULL(@pmIdPais,'%')
 ORDER BY NombrePais
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesCat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPeajesCat] @pmIdCat VARCHAR(4)
 AS 
 IF @pmIdCat IS NULL
  SELECT IdCat,Catpeaje
  FROM PeajesCat
 WHERE Inactivo=0
 ORDER BY  IdCat
 ELSE
  SELECT IdCat,Catpeaje,Inactivo
  FROM PeajesCat
  WHERE IdCat=@pmIdCat
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesCatDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPeajesCatDso]
 AS 
 SELECT IdCat,Catpeaje,IdCat+' '+Catpeaje AS DsCat
 FROM PeajesCat
 WHERE Inactivo=0
 ORDER BY  IdCat
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesClase]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPeajesClase] @pmIdClase VARCHAR(4)
 AS 
 IF @pmIdClase IS NULL
 SELECT IdClase,ClasePeaje,NitConsec
 FROM PeajesClase
 WHERE Inactivo=0
 ORDER BY IdClase
 ELSE
 SELECT IdClase,ClasePeaje,NitConsec,Inactivo
 FROM PeajesClase
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesTarf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPeajesTarf] @pmIdCat VARCHAR(4),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdCat,IdClase,VrTarifa
 FROM PeajesTarf
 WHERE IdCat=@pmIdCat AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryPeajesTarfLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPeajesTarfLta] @pmIdCat VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null
 AS 
 SELECT T.IdCat AS CdCat,Catpeaje,T.IdClase AS CdClase,ClasePeaje,VrTarifa
 FROM PeajesTarf AS T INNER JOIN PeajesCat AS C ON T.IdCat=C.IdCat
 INNER JOIN PeajesClase AS PC ON T.IdClase=PC.IdClase
 WHERE T.IdCat LIKE ISNULL(@pmIdCat,'%') AND T.IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY T.IdCat,T.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPermisos] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null
 AS 
 SELECT IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename
 FROM adm_Permisos
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%')
 ORDER BY IdObj
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPermisos_Cr] @pmNivUsu INT,@pmIdUsuario VARCHAR(11)=Null,@pmIdGrupo VARCHAR(6)=Null
,@pmSubModulo VARCHAR(3)=Null,@pmnModulo VARCHAR(10)=Null
AS
 SELECT P.IdUsuario AS IdUsuari,Usuario,U.IdGrupo AS NivelUsu,IdEstacion,U.IdCargo AS CodCargo,Cargo,FechaAcc,U.Inactivo AS Inactvo
 ,P.IdObj AS IdObjto,Nombre,IndObj,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename,O.IdGrupo AS IdGrup,GrupoObjeto
,nModulo,SubModulo,Formulario,Permisos,NivelMinimo,Consecutivo
 FROM adm_Permisos AS P  INNER JOIN Sys_ObjetosApp AS O ON P.IdObj =O.IdObj
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Sys_GruposObj AS G ON O.IdGrupo=G.IdGrupo
 INNER JOIN Cargos AS C ON U.IdCargo=C.IdCargo
 WHERE U.Inactivo=0 AND U.IdGrupo<=@pmNivUsu AND P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')  AND O.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') 
 AND SubModulo LIKE ISNULL(@pmSubmodulo,'%')  AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY Usuario,nModulo,O.IdGrupo,SubModulo,IndObj
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPermisosLta] @pmIdUsuario VARCHAR(11),@pmIdGrupo VARCHAR(6)=Null,@pmSubModulo VARCHAR(3)=Null
,@pmnModulo VARCHAR(10)=Null
AS
 SELECT P.IdUsuario AS IdUsuari,Usuario,P.IdObj AS IdObjto,Nombre,IndObj,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename,O.IdGrupo AS IdGrup,GrupoObjeto
,SubModulo,Formulario,Permisos,NivelMinimo,Consecutivo,U.IdGrupo AS NivelUsu
 FROM adm_Permisos AS P  INNER JOIN Sys_ObjetosApp AS O ON P.IdObj =O.IdObj
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Sys_GruposObj AS G ON O.IdGrupo=G.IdGrupo
 WHERE  P.IdUsuario=@pmIdUsuario  AND O.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  AND SubModulo LIKE ISNULL(@pmSubmodulo,'%')
 AND nModulo LIKE ISNULL(@pmnModulo,'%')
 ORDER BY nModulo,O.IdGrupo,SubModulo,IndObj
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisosRoles]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPermisosRoles] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10)=Null,@pmIdRole VARCHAR(3)=Null
 AS 
 SELECT IdUsuario,IdObj,IdRole,Asignado
 FROM adm_PermisosRoles
 WHERE IdUsuario=@pmIdUsuario AND IdObj LIKE ISNULL(@pmIdObj,'%') AND IdRole LIKE ISNULL(@pmIdRole,'%')
 ORDER BY IdObj,IdRole
GO
/****** Object:  StoredProcedure [dbo].[paQryPermisosRoles_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPermisosRoles_Cr] @pmIdUsuario VARCHAR(11)=Null,@pmIdObj VARCHAR(10)=Null
 AS 
 SELECT P.IdUsuario AS IdUsuari,Usuario,P.IdObj AS CodObj,Nombre,O.IdGrupo AS IdGrup,SubModulo,P.IdRole AS IdFuncion,Funcion,Asignado
 FROM adm_PermisosRoles AS P INNER JOIN Sys_ObjetosApp AS O ON P.IdObj=O.IdObj
 INNER JOIN Sys_Roles AS R ON  P.IdObj=R.IdObj AND P.IdRole=R.IdRole
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE P.IdUsuario LIKE ISNULL(@pmIdUsuario,'%') AND P.IdObj LIKE ISNULL(@pmIdObj,'%') 
 ORDER BY Usuario,IndObj,P.IdRole
GO
/****** Object:  StoredProcedure [dbo].[paQryPicoPlaca]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPicoPlaca] @pmFecha SMALLDATETIME
 AS 
 IF @pmFecha IS NULL
  SELECT Fecha,UltimoDig
  FROM PicoPlaca
 ELSE
  SELECT Fecha,UltimoDig
  FROM PicoPlaca
  WHERE Fecha=@pmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQryPlantillasConcLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPlantillasConcLta] @pmIdPlantilla VARCHAR(4)=Null
AS
 SELECT  P.IdPlantilla AS CdPlantilla,DescPlantilla,CdTipCom,TipoCom,P.Inactivo AS Inactvo
 ,Item,Concepto,C.IdCuenta AS CdCuenta,NomCuenta,TipoMov,Tarifa, Requerido
 FROM Plantillas AS P LEFT JOIN  PlantillasConc AS C ON P.IdPlantilla=C.IdPlantilla
 LEFT JOIN TiposCom AS TC ON P.CdTipCom=TC.IdCom
 LEFT JOIN Puc AS PC ON C.IdCuenta=PC.IdCuenta
 WHERE P.IdPlantilla LIKE ISNULL(@pmIdPlantilla,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryPlazos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPlazos] @pmIdPlazo VARCHAR(4)
 AS 
 IF @pmIdPlazo IS NULL
  SELECT IdPlazo,Plazo,NVmto,DiasPago,CdDctoPp
  FROM Plazos
  WHERE Inactivo=0
  ORDER BY IdPlazo
 ELSE
  SELECT IdPlazo,Plazo,NVmto,DiasPago,CdDctoPp,Inactivo
  FROM Plazos
  WHERE IdPlazo=@pmIdPlazo
GO
/****** Object:  StoredProcedure [dbo].[paQryPlazosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPlazosDso]
 AS 
 SELECT IdPlazo,Plazo,DiasPago,IdPlazo+' '+Plazo+' ('+DiasPago+')' AS DsPla
 FROM Plazos
 WHERE Inactivo=0
 ORDER BY IdPlazo
GO
/****** Object:  StoredProcedure [dbo].[paQryPolizas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPolizas] @pmNumPoliza VARCHAR(30)
 AS 
 SELECT NumPoliza,Fecha,Vigencia,NitCompania,Compania,NitTomador,Tomador,NitAseg,Asegurado
,NitBenef,Beneficiario,Inactivo,CodEmpresa,Tipo_Poliza,FechaAdd,FechaUpdate,IdUsuario,DescFirma
 FROM Polizas
 WHERE NumPoliza=@pmNumPoliza
GO
/****** Object:  StoredProcedure [dbo].[paQryPolizasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPolizasLta]
 AS 
 SELECT NumPoliza,Fecha,Vigencia,NitCompania,Compania,NitTomador,Tomador,NitAseg,Asegurado
,NitBenef,Beneficiario,DescFirma,CodEmpresa,Tipo_Poliza,P.IdUsuario AS IdUsuari,Usuario,FechaAdd,FechaUpdate
 FROM Polizas AS P INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE P.Inactivo=0
 ORDER BY NumPoliza
GO
/****** Object:  StoredProcedure [dbo].[paQryPos40_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[paQryPos40_Cr]
	--@pmTipFact VARCHAR(20),--Tipo de documento que se desea buscar módulo
	@pmTipDoc VARCHAR(3),--Tipo de documento que se desea buscar
	@pmNroFactura INT, --Número de documento que se desea buscar
	@pmIdCia CHAR(2), --Compañía de documento que se desea buscar
	@pmIdCliente VARCHAR(16)= NULL, --Id de Cliente de documento que se desea buscar
	@Modalidad VARCHAR(16)= NULL,
	@Origen VARCHAR(16)= NULL
AS
BEGIN
		SELECT F.TipDoc AS Tip_Doc, TD.TipoDoc, F.Factura AS NumFactura,  F.IdCia AS CdCia, C.Compania,  F.Fecha AS FechaDoc, F.IdConcepto AS CdConceptoP,  
		F.nClieCon IdCliente,  T.RazonSocial AS NomCliente,  F.CdAgencia AS IdAgencia,AG.Agencia AS NomAgencia,AG.DirAgncia,AG.TelAgncia,AG.IdLocal IdLocalAgncia,LA.Localidad LocalidadAgncia, AG.emlCont AS AgEmails,  F.Fecha AS FechaVence,   F.VrSubTotal, F.VrDescuento,  F.VrImpuesto,  F.VrImpCons, 
		F.VrRetencion, F.VrReteICA,  VrReteIVA, CAST('0' AS DECIMAL(18,4)) AS VrOtros,CASE WHEN F.TipCom ='GTC' THEN 0 ELSE VrCargos END VrCargos,  VrOtrDcto,  CAST('0' AS DECIMAL(18,4)) AS VrSobretasa,
		CAST('0' AS DECIMAL(18,4)) AS VrImpGlobal, CAST('0' AS DECIMAL(18,4)) AS VrAnticipos,  CAST('0' AS DECIMAL(18,4)) AS VrImpCarbono,  
		VrNeto,  CAST('0' AS DECIMAL(18,4)) AS VrAplicado, Cantidad, BaseImp, CAST('0' AS DECIMAL(18,4)) AS BaseICO,  BaseRet,  BaseIca,  BaseRiv, F.TarifaIva, 
		F.TarifaRet,  F.TarifaIca, F.TarifaRiv, CAST('0' AS DECIMAL(18,4)) AS ETarifaIco, F.TarifaAri, F.VrAutRetIca AS VrAutRetIcaNoTTE,  F.TarifaArf, F.VrAutRetFte,
		---nuevos campos para gestion de PDF
		F.VrFletes,F.VrReteCREE,F.TarifaRtc,F.TimeSys AS Fec_Add,F.Remision AS NumRemision,f.IdCiaRem,'' TipCot,0 AS NumCotizacion,'' AS CiaCotiza,F.TipPed,F.Pedido,F.IdCiaPed,'' AS CdPlazo,'' Plazo,CAST(0 as BIT) MulPlazos,F.IdUsuario AS CdUsuario,Usuario,
		F.TipCom,F.Comprobante,F.IdCiaCom,F.Anulado AS FacAnulado,F.NumDev,F.FecDev,F.DetallePago,T.IdRegimen AS CdRegimen,Regimen,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,'' PlacaVeh,
		--Detalles
		CASE WHEN F.TipCom ='GTC' THEN 1 ELSE K.Item END Item, CASE WHEN F.TipCom ='GTC' THEN '999' ELSE K.IdProducto END  AS CodProducto,CASE WHEN F.TipCom ='GTC' THEN '999' ELSE ISNULL(P.CodFEDian, K.IdProducto) END AS CodProductoDIAN,CASE WHEN F.TipCom ='GTC' THEN ('GUIA TRANSPORTE: '+F.TipRem+' '+CAST(F.Remision AS varchar)+' '+F.IdCiaRem)  ELSE DescripProd END  AS DescripProd,
		'' AS DescripProd1, CASE WHEN F.TipCom ='GTC' THEN CAST(1 AS decimal(12,2)) ELSE Salidas END Cant, CASE WHEN F.TipCom ='GTC' THEN '94' ELSE ISNULL(UM.CodUMFE, P.UndMed) END  AS CdUndMed, 
		CASE WHEN F.TipCom ='GTC' THEN VrNeto ELSE  
		(CASE WHEN (SELECT Modalidad FROM Trn_Facturas WHERE TipDoc = @pmTipDoc AND Factura = @pmNroFactura AND IdCia = @pmIdCia) = 'INVENTARIO' AND K.ItemCombo > 0 AND K.EsCombo = 0 AND K.EsProdBase > 0  THEN CAST((K.IngBaseCom / K.Salidas) AS DECIMAL(18,4)) ELSE K.VrPrecio END) END AS VrUnitario, 
		ISNULL(K.VrDctoSal,0) VrDctoSal,  ISNULL(K.TarifaDct,CAST('0' AS DECIMAL(18,4))) TarifaDct, 0 AS TipoReg, ISNULL(K.CantObseq,CAST('0' AS DECIMAL(18,4))) CantObseq,ISNULL(K.CdMoneda,'COP') CdMoneda, ISNULL(K.VrTasaCamb,0) VrTasaCamb,  ISNULL(K.TarifaIco,CAST('0' AS DECIMAL(18,4))) TarifaIco, ISNULL(K.VrImpCon,CAST('0' AS DECIMAL(18,4))) VrImpCon, 
		(CASE WHEN VrImpCon > 0 THEN ((K.Salidas * K.VrPrecio) - K.VrDctoSal)  ELSE 0 END) AS BaseIcoDet, ISNULL(K.TarifaIva,CAST('0' AS DECIMAL(18,4)))  AS TarifaIvaDet,  ISNULL(K.VrIvaSal,CAST('0' AS DECIMAL(18,4))) AS VrIvaDet,
		ISNULL(CAST(((K.Salidas * K.VrPrecio) - K.VrDctoSal) AS DECIMAL(18,4)),CAST('0' AS DECIMAL(18,4))) AS BaseIvaDet, ISNULL(K.TarifaRet,CAST('0' AS DECIMAL(18,4))) AS TarifaRetDet,ISNULL(K.VrReteSal,CAST('0' AS DECIMAL(18,4))) AS VrRetDet, 
		ISNULL(K.TarifaIca,CAST('0' AS DECIMAL(18,4))) AS TarifaIcaDet, ISNULL(K.VrIcaSal,CAST('0' AS DECIMAL(18,4)))  AS VrIcaDet,
		--Versiónn 10
		CAST('0' AS DECIMAL(18,4))  AS VrAutRetIca, CAST('0' AS DECIMAL(18,4))  AS BaseAutoIcaDet, 
		ISNULL(P.ExcluidoImp,0) ExcluidoImp, CAST('0' AS DECIMAL(18,4)) AS ImpCarbono,  CAST('0' AS DECIMAL(18,4)) AS ImpGlobal, CAST('0' AS DECIMAL(18,4)) AS Sobretasa, CAST('0' AS DECIMAL(18,4)) AS Soldicom,  
		CAST('0' AS DECIMAL(18,4)) AS TarifaIvp, CAST('0' AS DECIMAL(18,4)) AS BaseIvp, CAST('0' AS DECIMAL(18,4)) AS IvaIngProd,ISNULL(CAST(K.EsCombo AS bit), 0) EsCombo, 
		--Arreglo Colanta
		--K.ItemCombo, 
		(CASE WHEN K.EsCombo = 0 AND k.EsProdBase = 1 THEN 1 ELSE 0 END) AS ItemCombo, ISNULL(K.Entradas,CAST('0' AS DECIMAL(18,4))) Entradas,ISNULL(P.IvaDetCombo,0) IvaDetCombo,CAST('0' AS DECIMAL(14, 4)) VrOtrDctoDet,
		(CASE WHEN P.TipoZonaFront = 'IT' THEN  K.CdOperario ELSE '' END) AS Mandatario, TM.Dv  AS MandatarioDV, TM.TipoId AS MandatarioTipDoc, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3,
		--Inforamción de factura electrónica
		FE.EstadoFE, FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion, FE.RangoNum, FE.FecVigencia,FE.CUFE_QR AS QR,FE.FechaValidacion,
		--Otros
		F.Observacion AS Observ, 1 AS FormaPago, F.CdForma, F.Modalidad,F.Origenadd,CAST('0' AS DECIMAL(18,4)) AS VrSeguroRem, CAST('0' AS DECIMAL(14, 4)) Volumen,CASE WHEN TP.Simbolo='$' AND TP.IdClase ='ICO' THEN 'Nominal' ELSE 'Porcentual' END TipoICO, 
		 isnull(k.TarifaIba, 0) as TarifaIba, k.VrImpuBa, ISNULL(k.TarifaCup, 0) AS TarifaCup, k.VrImpuCup, p.MedVolm,
		 --PARAMETROS PARA LA CONSULTA DE CAJERO PARA XML POS
		 cj.CdCajero 'PlacaCaja', bo.Bodega 'UbicacionCaja', cj.CdCajero 'Cajero', 'POS' 'TipoCaja', F.Factura 'CodigoVenta', f.nClieCon 'Codigo', CI.Nombre 'NombreApellido'
		FROM Trn_Factcon AS F
		LEFT JOIN Trn_Kardex AS K ON F.TipDoc = K.TipDoc AND F.Factura = K.Documento AND F.IdCia = K.IdCia
		LEFT JOIN ProdMcias AS P ON K.IdProducto = P.IdProducto
		LEFT JOIN ProdCombo AS PC ON P.Idproducto = PC.IdProducto
		LEFT JOIN Sys_Um AS UM ON P.UndMed = UM.UndMed
		INNER JOIN Companias AS C ON F.IdCia = C.IdCia
		INNER JOIN Sys_TiposDoc AS TD ON F.TipDoc = TD.IdDoc
		LEFT JOIN Terceros AS T ON F.nClieCon = T.IdTercero
		LEFT JOIN  Terceros AS VN ON F.IdVend=VN.IdTercero
		LEFT JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
		LEFT JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
		LEFT JOIN Terceros AS TM ON K.CdOperario = TM.IdTercero
		LEFT JOIN Trn_Face AS FE ON F.TipDoc = FE.TipDoc AND F.Factura = FE.Documento AND F.IdCia = FE.IdCia
		LEFT JOIN Agencias AS AG ON F.CdAgencia = AG.IdAgencia AND F.NitCliente = AG.IdClie
		LEFT JOIN Localidades AS LA ON AG.IdLocal=LA.IdLocal
		LEFT JOIN Tablapor AS TP ON K.CodTarIco=TP.IdTarifa
		LEFT JOIN adm_Usucaja AS CJ ON CJ.IdUsuario = F.IdUsuario 
		left join Bodegas AS BO on  CJ.cdbodega = BO.idbodega
		LEFT JOIN ClieContado AS CI ON F.nClieCon =  CI.IdCliente
		WHERE F.TipDoc = @pmTipDoc AND F.Factura = @pmNroFactura AND F.IdCia = @pmIdCia AND F.nClieCon LIKE ISNULL(@pmIdCliente,'%')	
END
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPreCausacion] @pmCausacionID INT,@pmIdCia CHAR(2)
 AS 
 SELECT CausacionID,IdCia,Fecha,Modalidad,TotalCapital,TotalInteres,TotalCuota,IdVehiculo,IdPropietario,TipDoc,PrestamoID,IdCiaDoc,NumCuota,Anulado,FecDev,TipCom,Comprobante,IdCiaCom,Observacion,TimeSys,IdUsuario
 FROM Trn_PreCausacion
 WHERE CausacionID=@pmCausacionID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacion_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPreCausacion_Cr] @pmCausacionID INT=Null,@pmIdCia CHAR(2)=Null
AS
 SELECT C.CausacionID AS NumCausacion, C.IdCia AS CodCia,C.Fecha AS FechaCausa, Modalidad,CU.TipDoc AS TipPre, CU.PrestamoID AS PrstamoID, CU.IdCia AS CiaPrest, CU.NumCuota AS NroCuota
,FecCausa, FecVence, ValorCapital, ValorInteres,ValorCuota,FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres,P.IdConcepto AS IdConcept,Concepto,CxPagar
,Referencia,TotalCausado, P.TotalInteres AS TtalIntereses, UltimaCuota, Cancelado,P.Anulado AS PrestAnulado,P.IdEstado AS IdEstad,Estado,TotalCapital, C.TotalInteres AS TtalIntCausado, TotalCuota, C.TipCom AS IdTipCom
,TipoCom,C.Comprobante AS NumComp,C.IdCiaCom AS IdCiaCmp, C.Anulado AS Cau_anulado, C.FecDev AS Cau_FecAnulado,C.Observacion AS Observ,P.IdVehiculo AS PlacaVeh,NumVeh,P.IdPropietario AS IdPropietari,T.RazonSocial AS Propietario
,V.IdPropietario AS Veh_IdPropietario,NP.RazonSocial AS Veh_NomPropietario,C.TimeSys AS FecHoraCrea, C.IdUsuario AS IdUsuari,Usuario,Compania
 FROM Trn_PreCausacion AS C INNER JOIN Trn_PreCuotas AS CU ON C.CausacionID=CU.CausacionID
 INNER JOIN Trn_Prestamos AS P ON CU.TipDoc=P.TipDoc AND CU.PrestamoID=P.PrestamoID AND CU.IdCia=P.IdCia
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Companias  AS CI ON P.IdCia=CI.IdCia
 INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero
 INNER JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero
 INNER JOIN Conceptos AS CO ON P.IdConcepto=CO.IdConcepto INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 LEFT JOIN TiposCom AS TM ON C.TipCom=TM.IdCom
 WHERE  (C.CausacionID>=ISNULL(@pmCausacionID,0)  AND C.CausacionID<=ISNULL(@pmCausacionID,2147483647))
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY C.IdCia,C.CausacionID
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacion_Crr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPreCausacion_Crr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmAnulado BIT=Null,@pmPrestamoID INT=Null,@pmNumCuota INT=Null,@pmTipoPlazo VARCHAR(10)=Null
,@pmTipoCuota VARCHAR(10)=Null,@pmCausacionID INT=Null
AS
SELECT C.CausacionID AS NumCausacion, C.IdCia AS CodCia,C.Fecha AS FechaCausa,Modalidad,TotalCapital,C.TotalInteres AS TInteresCausado,TotalCuota,CU.PrestamoID AS NumPrestamo,CU.IdCia AS CodCiaPre,CP.Compania AS NomCiaPrest
,CU.NumCuota AS NroCuota,FecCausa, CU.FecVence AS FechVence, ValorCapital, ValorInteres,ValorCuota,ValorAbono,FecUltPago, FecPrestamo, TipoPlazo, NumCuotas,TipoCuota,DiasCausa, DiasVence, ValorPrestamo, TasaInteres,TotalCausado, P.TotalInteres AS AcuIntereses, UltimaCuota
,Cancelado, P.IdConcepto AS IdConcept,Concepto,P.IdVehiculo AS PlacaVeh,NumVeh,P.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,P.VehPropio AS VhEsPropio,CxPagar,P.Referencia AS NFactura, P.Anulado AS Pre_Anulado, P.NumDev AS Pre_NumDev
,P.FecDev AS Pre_FecDev,P.TipCom AS Pre_TipCom,P.Comprobante AS Pre_NumCmp,P.IdCiaCom AS Pre_CiaCom,P.Observacion AS Pre_Observ,P.IdEstado AS IdEstad,Estado,C.Anulado AS CauAnulado, C.FecDev AS CauFecDev, C.TipCom AS CauTipCom
,TipoCom,C.Comprobante AS CauNumCmp,C.IdCiaCom AS CauCiaComp, C.Observacion AS CauObserv,CU.IdUsuario,Usuario,CI.Compania AS NomCiaCausa,C.TimeSys AS TmeSys
,V.IdPropietario,NP.RazonSocial AS Veh_propietario,V.IdConductor AS CedConductor,NC.RazonSocial AS Veh_Conductor
 FROM Trn_PreCausacion AS C INNER JOIN Trn_PreCuotas AS CU ON C.CausacionID=CU.CausacionID
 INNER JOIN Trn_Prestamos AS P ON CU.TipDoc=P.TipDoc AND CU.PrestamoID=P.PrestamoID AND CU.IdCia=P.IdCia
 INNER JOIN Trn_CausacVence AS VC ON CU.TipDoc=VC.TipDoc AND CU.PrestamoID=VC.Documento AND CU.IdCia=VC.IdCia AND CU.NumCuota=VC.Item
 INNER JOIN adm_Usuarios AS U ON CU.IdUsuario=U.IdUsuario INNER JOIN Companias  AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Companias  AS CP ON CU.IdCia=CP.IdCia  INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo 
 INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero  INNER JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero
 INNER JOIN Terceros AS NC ON V.IdConductor=NC.IdTercero
 INNER JOIN Conceptos AS CO ON P.IdConcepto=CO.IdConcepto INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 LEFT JOIN TiposCom AS TM ON C.TipCom=TM.IdCom
 WHERE C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia like ISNULL(@pmIdCia,'%%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND V.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') 
 AND (CU.PrestamoID>=ISNULL(@pmPrestamoID,0)  AND CU.PrestamoID<=ISNULL(@pmPrestamoID,2147483647))
 AND (C.Anulado=ISNULL(@pmAnulado,0) or C.Anulado=ISNULL(@pmAnulado,1))
 AND (CU.NumCuota>=ISNULL(@pmNumCuota,0)  AND CU.NumCuota<=ISNULL(@pmNumCuota,2147483647))
 AND TipoPlazo LIKE ISNULL(@pmTipoPlazo,'%')
 AND TipoCuota LIKE ISNULL(@pmTipoCuota,'%')
 AND (C.CausacionID>=ISNULL(@pmCausacionID,0)  AND C.CausacionID<=ISNULL(@pmCausacionID,2147483647))
 ORDER BY C.IdCia,C.CausacionID,CU.IdCia,CU.PrestamoID,CU.NumCuota
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionAcp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPreCausacionAcp] @pmCausacionID INT,@pmIdCia CHAR(2)
--aplicacion de anticipos
AS
  SELECT  RF.TipRec AS TRec, RF.Recibo AS Nrecibo, RF.IdCia AS CodCia,RF.IdVehiculo AS Placaveh,ValorAnticipo,R.ValorAbono AS AbonoAnt,SUM(RF.ValorAbono) AS TotalAbono
  FROM   Trn_PreCausacion AS C INNER JOIN Trn_PreCuotas AS CU ON C.CausacionID=CU.CausacionID
  INNER JOIN Trn_CausacVence AS VC ON CU.TipDoc=VC.TipDoc AND CU.PrestamoID=VC.Documento AND CU.IdCia=VC.IdCia AND CU.NumCuota=VC.Item
  INNER JOIN  Trn_RecFactura AS RF ON VC.TipDoc=RF.TipDoc AND VC.Documento=RF.Documento AND VC.IdCia=RF.IdCiaDoc AND VC.Item=RF.ItemDoc
  INNER JOIN Trn_RecBuses AS R ON RF.TipRec=R.TipDoc AND RF.Recibo=R.Recibo AND RF.IdCia=R.IdCia
  WHERE RF.TipDoc='PRE' AND C.CausacionID=@pmCausacionID  AND C.IdCia=@pmIdCia AND AplAntcpo<>0
  GROUP BY  RF.TipRec, RF.Recibo, RF.IdCia,RF.IdVehiculo,ValorAnticipo,R.ValorAbono
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionCuo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPreCausacionCuo] @pmCausacionID INT,@pmIdCia CHAR(2)
AS
SELECT  CU.PrestamoID AS NumPrest,CU.IdCia AS CodCia,SUM(ValorCapital) AS tValorCapital,SUM(ValorInteres) AS tValorInteres ,SUM(ValorCuota) AS tValorCuota
FROM Trn_PreCuotas AS CU INNER JOIN  Trn_PreCausacion AS C ON CU.CausacionID=C.CausacionID
WHERE C.CausacionID=@pmCausacionID AND C.IdCia=@pmIdCia
GROUP BY CU.PrestamoID,CU.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPreCausacionLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmAnulado BIT=Null
,@pmModalidad VARCHAR(10)=Null
AS
SELECT CausacionID, IdCia, Fecha, Modalidad, TotalCapital, TotalInteres, TotalCuota, C.IdVehiculo AS PlacaVeh,NumVeh,C.IdPropietario AS IdPropietari,RazonSocial
, TipDoc, PrestamoID, IdCiaDoc, NumCuota, Anulado, FecDev, TipCom, Comprobante, IdCiaCom, C.Observacion AS Observ, TimeSys, C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_PreCausacion AS C INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS T ON C.IdPropietario=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE  Fecha BETWEEN  @pmFechaIni AND @pmFechaFin  AND IdCia like ISNULL(@pmIdCia,'%%')
 AND Modalidad like ISNULL(@pmModalidad,'%')
 AND   (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,CausacionID
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionVce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPreCausacionVce] @pmCausacionID INT,@pmIdCia CHAR(2)
AS
 SELECT C.CausacionID AS NumCausacion, C.IdCia AS CodCia,Fecha,Modalidad,VC.TipDoc AS TDoc,Documento,VC.IdCia AS CodCiaVce,Item,FecEmision
,VC.FecVence AS FecVce,ValorFactura,IdCliente,VC.IdVehiculo AS PlacaVeh,CU.PrestamoID AS PrstamoID, CU.IdCia AS CiaPrest,CU.NumCuota AS NroCuota
,ValorCapital, ValorInteres,ValorCuota
 FROM Trn_PreCausacion AS C INNER JOIN Trn_PreCuotas AS CU ON C.CausacionID=CU.CausacionID
 INNER JOIN Trn_CausacVence AS VC ON CU.TipDoc=VC.TipDoc AND CU.PrestamoID=VC.Documento AND CU.IdCia=VC.IdCia AND CU.NumCuota=VC.Item
 WHERE VC.TipDoc='PRE' AND C.CausacionID=@pmCausacionID  AND C.IdCia=@pmIdCia
 ORDER BY VC.IdCia,Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCausacionVct]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPreCausacionVct] @pmCausacionID INT,@pmIdCia CHAR(2)
AS
 SELECT VC.IdCliente AS NitCliente,VC.IdVehiculo AS PlacaVeh,VC.IdCia AS CodCia,SUM(ValorFactura) AS SValFac,SUM(ValorAbono) AS SValAbo
 FROM Trn_PreCausacion AS C INNER JOIN Trn_PreCuotas AS CU ON C.CausacionID=CU.CausacionID
 INNER JOIN Trn_CausacVence AS VC ON CU.TipDoc=VC.TipDoc AND CU.PrestamoID=VC.Documento AND CU.IdCia=VC.IdCia AND CU.NumCuota=VC.Item
 WHERE VC.TipDoc='PRE' AND C.CausacionID=@pmCausacionID  AND C.IdCia=@pmIdCia
 GROUP BY VC.IdCliente, VC.IdVehiculo,VC.IdCia
 ORDER BY VC.IdCliente, VC.IdVehiculo,VC.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCuotas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPreCuotas] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmNumCuota INT
 AS 
 SELECT TipDoc,PrestamoID,IdCia,NumCuota,FecCausa,FecVence,ValorCapital,ValorInteres,ValorCuota,CausacionID,IdUsuario
 FROM Trn_PreCuotas
 WHERE TipDoc=@pmTipDoc AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia 
 AND (NumCuota>=ISNULL(@pmNumCuota,-1)  AND NumCuota<=ISNULL(@pmNumCuota,2147483647))
 ORDER BY NumCuota
GO
/****** Object:  StoredProcedure [dbo].[paQryPreCuotasTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPreCuotasTot] @pmTipDoc VARCHAR(3), @pmPrestamoID INT=Null, @pmIdCia CHAR(2)=Null
 AS
 SELECT C.TipDoc AS Tdoc,C.PrestamoID AS PrestID,C.IdCia AS CodCia,NumCuotas,IdEstado,ValorPrestamo,COUNT(NumCuota) AS SCanCuo,MAX(NumCuota) AS MxCuota,SUM(ValorCapital) AS STotCap
,SUM(ValorInteres) AS STotInt,SUM(ValorCuota) AS STotCuo
 FROM  Trn_PreCuotas AS C INNER JOIN Trn_Prestamos AS P ON C.TipDoc=P.TipDoc AND C.PrestamoID=P.PrestamoID AND C.IdCia=P.IdCia
 WHERE C.TipDoc=@pmTipDoc  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')  
 AND (C.PrestamoID>=ISNULL(@pmPrestamoID,0)  AND C.PrestamoID<=ISNULL(@pmPrestamoID,2147483647))
 GROUP BY C.TipDoc,C.PrestamoID,C.IdCia,NumCuotas,IdEstado,ValorPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamos] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2)
AS
 SELECT   TipDoc, PrestamoID, IdCia, Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, IdConcepto, IdVehiculo, IdPropietario, IdConductor, VehPropio, CxPagar,Referencia, Anulado, NumDev
,FecDev, TipCom, Comprobante, IdCiaCom, Observacion, IdEstado, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
 FROM  Trn_Prestamos
 WHERE  TipDoc=@pmTipDoc AND PrestamoID=@pmPrestamoID AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamos_Cr] @pmTipDoc VARCHAR(3),@pmPrestamoIDIni INT=Null,@pmPrestamoIDFin INT=Null
,@pmIdCia CHAR(2)=Null
AS
 SELECT   TipDoc,TipoDoc, PrestamoID, P.IdCia AS CodCia,Compania, Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, P.IdConcepto AS IdConcept,Concepto, P.IdVehiculo AS PlacaVeh, P.IdPropietario AS IdPropietari,NP.RazonSocial AS Propietario,P.IdConductor AS CedConductor
,NC.RazonSocial AS Conductor,P.VehPropio AS VhPropio, CxPagar,Referencia, Anulado, NumDev,FecDev, TipCom,TipoCom, Comprobante, IdCiaCom, P.Observacion AS Observ, P.IdEstado AS IdEstad,ED.Estado AS EstadDoc, TimeSys, FecUpdate, IdCiaCrea, P.IdUsuario AS IdUsuari,Usuario
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_Prestamos  AS P  INNER JOIN Sys_TiposDoc  AS TD ON P.TipDoc=TD.IdDoc   INNER JOIN Companias  AS CI ON P.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON P.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON P.IdConductor=NC.IdTercero
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON P.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN TiposCom AS TM ON P.TipCom=TM.IdCom
  WHERE   P.TipDoc=@pmTipDoc  AND PrestamoID BETWEEN @pmPrestamoIDIni AND @pmPrestamoIDFin
 AND  P.IdCia like ISNULL(@pmIdCia,'%%')
 ORDER BY P.IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamos_Crr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamos_Crr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmTipoPlazo VARCHAR(10)=Null,@pmTipoCuota VARCHAR(10)=Null,@pmDiasCausa VARCHAR(5)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
,@pmAnulado BIT=Null,@pmCancelado BIT=Null,@pmIdEstado VARCHAR(4)=Null
AS
 SELECT  PrestamoID,P.IdCia AS CodCia,Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, P.IdConcepto AS IdConcept,Concepto, P.IdVehiculo AS PlacaVeh, NumVeh,P.IdPropietario AS IdPropietari,NP.RazonSocial AS Propietario,P.IdConductor AS CedConductor
,NC.RazonSocial AS Conductor,P.VehPropio AS VhPropio, CxPagar,Referencia, Anulado, NumDev,FecDev, TipCom,TipoCom, Comprobante, IdCiaCom, P.Observacion AS Observ, P.IdEstado AS IdEstad,ED.Estado AS EstadDoc,P.IdUsuario AS IdUsuari,Usuario
,TipDoc,TipoDoc,Compania,IdCiaCrea,TimeSys, FecUpdate
,Marca,Modelo,TipoVehiculo,CV.Descripcion AS ClaseVeh,NomColor,EV.Estado AS EstadVeh,NumMotor,SerieChasis,V.IdGrupo AS IdGrup,GrupoProp,NumSoat,VigSoat,KmActual, ObligaTProd,V.FecIngreso AS FechaIngreso, V.FecRetiro AS FechaRetiro,NContrato
,V.IdAdmon AS CodAdmon,TA.TipoAdmon AS TipAdmonVeh,NP.TipoId AS TipoIdProp,NP.Dv AS DvProp,NP.Direccion AS DireccionProp,NP.Telefono AS TeleProp,NP.Fax AS Tele2Prop,NP.TelMovil AS CelularProp,NP.EsConductor AS EsConductr,NP.IdLocal AS CodCiuProp,LP.Localidad AS CiudadProp
,NC.IdLugarCed AS LugarCedulaCond,NC.Direccion AS DireccionCond,NC.Telefono AS TeleCond,NC.Fax AS Tele2Cond,NC.TelMovil AS CelularCond,NC.EsPropietario AS EsPropietar,NC.IdLocal AS CodCiuCond,LC.Localidad AS CiudadCond
 FROM  Trn_Prestamos  AS P  INNER JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc   INNER JOIN Companias AS CI ON P.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON P.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON P.IdConductor=NC.IdTercero
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal  
  INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca   INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh  
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor  
  INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo  
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon   LEFT JOIN TiposCom AS TM ON P.TipCom=TM.IdCom
  LEFT JOIN TarifBuses AS CV ON V.CdTarifa=CV.IdTarifa
  WHERE  FecPrestamo BETWEEN @pmFechaIni AND @pmFechaFin AND  P.IdCia like ISNULL(@pmIdCia,'%%')  AND P.IdConcepto like ISNULL(@pmIdConcepto,'%')
  AND TipoPlazo like ISNULL(@pmTipoPlazo,'%') AND TipoCuota LIKE ISNULL(@pmTipoCuota,'%') AND DiasCausa LIKE ISNULL(@pmDiasCausa,'%')
 AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND P.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND  (Cancelado=ISNULL(@pmCancelado,0) or Cancelado=ISNULL(@pmCancelado,1))
 ORDER BY P.IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosCau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamosCau] @pmFechaDia SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT   TipDoc, PrestamoID, IdCia, Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, IdConcepto, P.IdVehiculo AS PlacaVeh,NumVeh,TipoAfil,P.IdPropietario AS NitPropietario
,T.RazonSocial AS Propietario, P.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,P.VehPropio AS VhPropioPre, CxPagar,Referencia, Anulado, NumDev
,FecDev, TipCom, Comprobante, IdCiaCom, P.Observacion AS Observ, P.IdEstado AS IdEstad, TimeSys, FecUpdate, IdCiaCrea, P.IdUsuario AS IdUsuari
,V.IdPropietario AS IdPropVeh,V.IdConductor AS CedCondVeh
 FROM  Trn_Prestamos AS P INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero INNER JOIN Terceros AS NC ON P.IdConductor=NC.IdTercero
 WHERE  Anulado=0 AND Cancelado=0  AND P.IdEstado<>'0077' AND FecPrestamo<=@pmFechaDia AND FecInicio<=@pmFechaDia
 AND  IdCia like ISNULL(@pmIdCia,'%%') AND P.IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdConcepto like ISNULL(@pmIdConcepto,'%')
 ORDER BY P.IdVehiculo,IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosDft]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamosDft] @pmIdVehiculo VARCHAR(10),@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT TipDoc, PrestamoID, IdCia, Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, IdConcepto, IdVehiculo, IdPropietario, IdConductor, VehPropio, CxPagar,Referencia, Anulado, NumDev
,FecDev, TipCom, Comprobante, IdCiaCom, Observacion, IdEstado, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
 FROM  Trn_Prestamos 
 WHERE  Anulado=0 AND Cancelado=0  AND IdEstado<>'0077'  AND IdVehiculo=@pmIdVehiculo
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamosLta] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmAnulado BIT=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
 SELECT PrestamoID, IdCia, Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, P.IdConcepto AS IdConcep,Concepto,P.IdVehiculo AS IdVehic,NumVeh,P.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,P.IdConductor AS CedConductor
,NC.RazonSocial AS Conductor,P.VehPropio AS VhPropio,CxPagar, Referencia,Anulado, NumDev,FecDev, TipCom, Comprobante, IdCiaCom, P.Observacion AS Observ, P.IdEstado AS IdEstad,Estado, TimeSys, FecUpdate, IdCiaCrea, P.IdUsuario AS IdUsuari,Usuario 
 FROM  Trn_Prestamos AS P  INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto 
 INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero INNER JOIN Terceros AS NC ON P.IdConductor=NC.IdTercero
 INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
 INNER JOIN  EstadoDoc AS E ON P.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE  TipDoc=@pmTipDoc  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND P.IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosPen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamosPen] @pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null,@pmIdConcepto VARCHAR(4)=Null
 AS
 SELECT  PrestamoID,P.IdCia AS CodCia,Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, P.IdConcepto AS IdConcept,Concepto, P.IdVehiculo AS PlacaVeh, P.IdPropietario AS IdPropietari,NP.RazonSocial AS Propietario,P.IdConductor AS CedConductor
,NC.RazonSocial AS Conductor,P.VehPropio AS VhPropio, CxPagar,Referencia,TipCom,TipoCom, Comprobante, IdCiaCom, P.Observacion AS Observ, P.IdEstado AS IdEstad,ED.Estado AS EstadDoc,P.IdUsuario AS IdUsuari,Usuario
,TipDoc,TipoDoc,Compania,IdCiaCrea,TimeSys, FecUpdate
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_Prestamos  AS P  INNER JOIN Sys_TiposDoc  AS TD ON P.TipDoc=TD.IdDoc   INNER JOIN Companias  AS CI ON P.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
  INNER JOIN Terceros AS NP ON P.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON P.IdConductor=NC.IdTercero
  INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
   INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa   LEFT JOIN TercCndtores AS CT ON  P.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN TiposCom AS TM ON P.TipCom=TM.IdCom
  WHERE  Anulado=0 AND Cancelado=0  AND P.IdEstado<>'0077'  AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND P.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') 
  AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
  ORDER BY P.IdPropietario,P.IdVehiculo,P.IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamosTot] @pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmCancelado BIT=Null
AS
 SELECT COUNT(PrestamoID) AS Cuenta,SUM(ValorPrestamo) AS tValorPrestamo,SUM(TotalCausado) AS tTotalCausado
 ,SUM(TotalInteres) AS tTotalInteres
 FROM  Trn_Prestamos
 WHERE IdVehiculo=@pmIdVehiculo AND Anulado=0 AND   IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND (Cancelado=ISNULL(@pmCancelado,0) or Cancelado=ISNULL(@pmCancelado,1))
GO
/****** Object:  StoredProcedure [dbo].[paQryPrestamosVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryPrestamosVeh] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
AS
 SELECT PrestamoID, IdCia, Fecha, FecPrestamo, FecInicio, TipoPlazo, NumCuotas, DiasCausa, DiasVence, TipoCuota, ValorPrestamo, TasaInteres
,TotalCausado, TotalInteres, UltimaCuota, Cancelado, P.IdConcepto AS IdConcep,Concepto,P.IdVehiculo AS IdVehic,NumVeh,P.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,P.IdConductor AS CedConductor
,NC.RazonSocial AS Conductor,P.VehPropio AS VhPropio,CxPagar, Referencia,TipCom, Comprobante, IdCiaCom, P.Observacion AS Observ, P.IdEstado AS IdEstad,Estado, TimeSys, FecUpdate, IdCiaCrea, P.IdUsuario AS IdUsuari,Usuario 
 FROM  Trn_Prestamos AS P  INNER JOIN Conceptos AS C ON P.IdConcepto=C.IdConcepto 
 INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero INNER JOIN Terceros AS NC ON P.IdConductor=NC.IdTercero
 INNER JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo
 INNER JOIN  EstadoDoc AS E ON P.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE  Anulado=0 AND Cancelado=0  AND P.IdEstado<>'0077'  AND P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND P.IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND P.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY IdCia,PrestamoID
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuesto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPresupuesto] @pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT Numero,IdCia,nAnno,nMes,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 ,TipoPsto,DetCentros
 FROM Trn_Presupuesto
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuesto_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPresupuesto_Cr] @pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT P.Numero AS NumPsto,P.IdCia AS CdCia,Compania,nAnno,nMes,Observacion,Item,D.IdCuenta AS CdCuenta,PC.NomCuenta,D.IdCCosto AS CdCentro,CCosto
,D.IdSubCos AS CdSubcentro,SubCosto,VrPresupuesto,SaldoAnterior,TotalDebitos,TotalCreditos,PC.Movimiento,PC.CentroCosto,PC.SubCentro,PC.Naturaleza
,D.TipoNiif,D.CodCueNiif,D.VrPrespNiif,D.SAnteriorNiif,D.DebitosNiif,D.CreditosNiif,D.FecUpdate AS FecModifica,CdUsuario,UM.Usuario AS UsuarioModifica
,P.IdEstado AS CdEstado,Estado,TimeSys,P.FecUpdate AS Fec_Update,IdCiaCrea,P.IdUsuario AS Id_Usuario,U.Usuario AS UsuarioCrea
,TipoPsto,DetCentros,PN.NomCuenta AS NiifNomCuenta
 FROM Trn_Presupuesto AS P INNER JOIN Trn_PresDetalle AS D ON P.Numero=D.Numero AND P.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Puc AS PC ON D.IdCuenta=PC.IdCuenta LEFT JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos LEFT JOIN adm_Usuarios AS UM ON D.CdUsuario=UM.IdUsuario
 LEFT JOIN PucNiif AS PN ON D.CodCueNiif=PN.IdCuenta
 WHERE P.Numero=@pmNumero AND P.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuestoMes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPresupuestoMes] @pmIdCia CHAR(2),@pmnAnno INT,@pmnMes INT
 AS 
 SELECT Numero,IdCia,nAnno,nMes,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
,TipoPsto,DetCentros
 FROM Trn_Presupuesto
 WHERE  IdCia=@pmIdCia AND nAnno=@pmnAnno AND  nMes=@pmnMes
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryPresupuestoPer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPresupuestoPer]  @pmnAnno INT,@pmnMesIni INT,@pmnMesFin INT,@pmIdCia CHAR(2)=Null
 AS 
 SELECT P.Numero AS NumPsto,P.IdCia AS CdCia,Compania,nAnno,nMes,Observacion,Item,D.IdCuenta AS CdCuenta,NomCuenta,D.IdCCosto AS CdCentro,CCosto
,D.IdSubCos AS CdSubcentro,SubCosto,VrPresupuesto,SaldoAnterior,TotalDebitos,TotalCreditos,Movimiento,CentroCosto,SubCentro,Naturaleza
,D.TipoNiif,D.CodCueNiif,D.VrPrespNiif,D.SAnteriorNiif,D.DebitosNiif,D.CreditosNiif,D.FecUpdate AS FecModifica,CdUsuario,UM.Usuario AS UsuarioModifica
,P.IdEstado AS CdEstado,Estado,TimeSys,P.FecUpdate AS Fec_Update,IdCiaCrea,P.IdUsuario AS Id_Usuario,U.Usuario AS UsuarioCrea
,TipoPsto,DetCentros
 FROM Trn_Presupuesto AS P INNER JOIN Trn_PresDetalle AS D ON P.Numero=D.Numero AND P.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Puc AS PC ON D.IdCuenta=PC.IdCuenta LEFT JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos LEFT JOIN adm_Usuarios AS UM ON D.CdUsuario=UM.IdUsuario
 WHERE nAnno=@pmnAnno AND nMes BETWEEN @pmnMesIni AND @pmnMesFin
 AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY nMes
GO
/****** Object:  StoredProcedure [dbo].[paQryProdAditivos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdAditivos] @pmIdProducto VARCHAR(16),@pmIdAditivo VARCHAR(16)
 AS 
 SELECT IdProducto,IdAditivo,Cant,Unidad,CdBodega,CdTanq
 FROM ProdAditivos
 WHERE IdProducto=@pmIdProducto AND IdAditivo LIKE ISNULL(@pmIdAditivo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryProdAditivosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdAditivosLta] @pmIdProducto VARCHAR(16)=Null,@pmIdAditivo VARCHAR(16)=Null
 AS 
 SELECT A.IdProducto AS CdProducto,P.DescripProd AS NombreProd,IdAditivo,PM.DescripProd AS ProdAditivo,Cant,Unidad,CdBodega,Bodega,CdTanq
 FROM ProdAditivos AS A INNER JOIN ProdMcias AS P ON A.IdProducto=P.IdProducto
 INNER JOIN ProdMcias AS PM ON A.IdAditivo=PM.IdProducto
 LEFT JOIN  Bodegas AS B ON A.CdBodega=B.IdBodega
 WHERE A.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdAditivo LIKE ISNULL(@pmIdAditivo,'%')
 ORDER BY P.DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCodigos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdCodigos]  @pmCodigo VARCHAR(20)
 AS 
 SELECT Codigo,IdProducto
 FROM ProdCodigos
 WHERE Codigo=@pmCodigo
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCombo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdCombo] @pmIdProducto VARCHAR(16),@pmItem INT
 AS 
 SELECT IdProducto,Item,IdProdBas,Cant,FacMezcla,CdBodega,CdTanq,ExentoSob
 FROM ProdCombo
 WHERE IdProducto=@pmIdProducto
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdComboFac] @pmIdProducto VARCHAR(16),@pmItem INT
 AS 
 SELECT SUM(Cant) AS SCANT
 FROM ProdCombo
 WHERE IdProducto=@pmIdProducto AND  Item<>@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdComboItm] @pmIdProducto VARCHAR(16)
 AS 
 SELECT Max(Item) AS MXITM
 FROM ProdCombo
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdComboLta] @pmIdProducto VARCHAR(16)=Null,@pmIdProdBas VARCHAR(16)=Null
 AS 
 SELECT PC.IdProducto AS CdProd,P.DescripProd AS Prodcto,Item,IdProdBas,PB.DescripProd AS ProdBase
,Cant,FacMezcla,CdBodega,Bodega,CdTanq,P.Tanques AS ProdTanques,PB.Tanques AS ProBasTanq,ExentoSob
 FROM ProdCombo AS PC INNER JOIN ProdMcias AS P ON PC.IdProducto=P.IdProducto
 INNER JOIN ProdMcias AS PB ON PC.IdProdBas=PB.IdProducto
 LEFT JOIN  Bodegas AS B ON PC.CdBodega=B.IdBodega
 WHERE PC.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND IdProdBas LIKE ISNULL(@pmIdProdBas,'%')
 ORDER BY P.DescripProd,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdComboPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdComboPro] @pmIdProducto VARCHAR(16)
 AS 
 SELECT C.IdProducto AS CdProducto,Item,IdProdBas,Cant,FacMezcla,CdBodega,CdTanq
,DescripProd,TipoRef,IdSubgrupo,IdUnd,IdBodega,IdUbic
,VrCostPmd,Seriales,Lotes,Combo,Tanques,Precio1,Precio2,Precio3,Precio4,Precio5,ExentoSob
 FROM ProdCombo AS C INNER JOIN ProdMcias AS P ON C.IdProdBas=P.IdProducto
 WHERE C.IdProducto=@pmIdProducto
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsInsuFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsInsuFmt] @pmTipDoc VARCHAR(3),@pmNumConsIni INT,@pmNumConsFin INT,@pmIdCia CHAR(2)
AS 
SELECT D.TipDoc,D.NumCons,D.IdCia,D.Item,D.TipPed,D.Pedido,D.IdCiaPed,D.ItemPed,D.IdProducto AS CodProducto,P.DescripProd
,D.IdInsumo,IM.DescripProd AS Insumo,D.IdTipProc,TP.TipoProceso,TP.IndOrden,D.IdBodega,B.Bodega,CdBodTdo,BD.Bodega AS BodegaTdo
,D.Cantidad,D.CantPed,D.Existencias,D.CantSaldo,D.CantTdo,D.CantOrden,D.CantSalidas,D.CostoUntSai
--datos del insumo
,IM.Referencia,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,IM.IdSubgrupo AS CdSubgpo,Subgrupo
,IM.IdMarca,Marca,IM.IdUnd,UM.Unidad AS UndadMed,IM.Color,IM.Tamano,IM.DescripLong AS InsDescripcion
FROM Trn_ProdConsInsu AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega INNER JOIN TiposProceso AS TP ON D.IdTipProc=TP.IdTipProc
INNER JOIN ProdMcias AS IM ON D.IdInsumo=IM.IdProducto INNER JOIN SubGrupos AS S ON IM.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON IM.IdMarca=M.IdMarca INNER JOIN UndMed AS UM ON IM.IdUnd=UM.IdUnd
LEFT JOIN Bodegas AS BD ON D.CdBodTdo=BD.IdBodega
WHERE D.TipDoc=@pmTipDoc AND D.NumCons BETWEEN @pmNumConsIni AND @pmNumConsFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsInsuLpt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsInsuLpt] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
SELECT O.TipDoc,O.Pedido,O.IdCia,O.IdCliente,O.IdAgencia,O.IdVend,D.Item,D.IdProducto,P.DescripProd,D.Salidas,D.Unidades
,DM.NumCons,DM.IdCia AS CdCiaCons,DM.Item AS ItemInsu,DM.ItemPed,DM.IdInsumo,IM.DescripProd AS Insumo,DM.IdTipProc,TP.TipoProceso,TP.IndOrden
,DM.IdBodega,B.Bodega,CdBodTdo,BD.Bodega AS BodegaTdo,DM.Cantidad,DM.CantPed,DM.Existencias,DM.CantSaldo,DM.CantTdo,DM.CantOrden,DM.CantSalidas,DM.CostoUntSai
--datos del insumo
,IM.Referencia,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,IM.IdSubgrupo AS CdSubgpo,Subgrupo
,IM.IdMarca,Marca,IM.IdUnd,UM.Unidad AS UndadMed,IM.Color,IM.Tamano,IM.DescripLong AS InsDescripcion
FROM Trn_Opedido AS O INNER JOIN Trn_Kardex AS D ON O.TipDoc=D.TipDoc AND O.Pedido=D.Documento AND O.IdCia=D.IdCia
INNER JOIN Trn_ProdConsInsu AS DM ON D.TipDoc=DM.TipPed AND D.Documento=DM.Pedido AND D.IdCia=DM.IdCiaPed AND D.Item=DM.ItemPed
INNER JOIN Trn_ProdConsolida AS C ON DM.TipDoc=C.TipDoc AND DM.NumCons=C.NumCons AND DM.IdCia=C.IdCia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON DM.IdBodega=B.IdBodega INNER JOIN TiposProceso AS TP ON DM.IdTipProc=TP.IdTipProc
INNER JOIN ProdMcias AS IM ON DM.IdInsumo=IM.IdProducto INNER JOIN SubGrupos AS S ON IM.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON IM.IdMarca=M.IdMarca INNER JOIN UndMed AS UM ON IM.IdUnd=UM.IdUnd
LEFT JOIN Bodegas AS BD ON DM.CdBodTdo=BD.IdBodega
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND C.Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsolida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsolida] @pmTipDoc VARCHAR(3),@pmNumCons INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumCons,IdCia,Fecha,IdBodega,CdBodDest,IdBodIns,CdBodInsDest,OrigenAdd,Anulado,FecDev,CritPedidos,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_ProdConsolida
 WHERE TipDoc=@pmTipDoc AND NumCons=@pmNumCons AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsolida_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsolida_Cr] @pmTipDoc VARCHAR(3),@pmNumConsIni INT,@pmNumConsFin INT,@pmIdCia CHAR(2)
AS 
 SELECT C.TipDoc,TipoDoc,C.NumCons,C.IdCia,Compania,C.Fecha,C.IdBodega,B.Bodega,C.CdBodDest,BD.Bodega AS BodDestino,C.IdBodIns,BU.Bodega AS BodInsumo,C.CdBodInsDest,BDI.Bodega AS BodDestInsumo
,C.Anulado,C.FecDev,C.CritPedidos,PT.NumTdoProd,PT.NumTdoInsu,C.Observacion,C.IdEstado,Estado,C.TimeSys AS FecCrea,C.FecUpdate AS FecActualiza,C.OrigenAdd,C.IdCiaCrea,C.IdUsuario,Usuario
--Detalles
,D.Item,D.TipPed,D.Pedido,D.IdCiaPed,D.ItemPed,D.IdProducto AS CodProducto,P.DescripProd,D.IdBodega AS CodBodega,BG.Bodega AS DetBodega,D.CdUbic,D.CantPedido,D.CantAprob,D.Existencias
,D.CantSaldo,D.CantTdo,D.CdBodTdo,BT.Bodega AS DetBodegaDest,D.Tallas,D.IdUnd,UD.Unidad
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.Color,P.Tamano,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong
FROM Trn_ProdConsolida AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
INNER JOIN Bodegas AS B ON C.IdBodega=B.IdBodega
INNER JOIN Trn_ProdConsDet AS D ON C.TipDoc=D.TipDoc AND C.NumCons=D.NumCons AND C.IdCia=D.IdCia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca INNER JOIN Bodegas AS BG ON D.IdBodega=BG.IdBodega
INNER JOIN UndMed AS UD ON D.IdUnd=UD.IdUnd 
LEFT JOIN Bodegas AS BD ON C.CdBodDest=BD.IdBodega
LEFT JOIN Bodegas AS BU ON C.IdBodIns=BU.IdBodega LEFT JOIN Bodegas AS BDI ON C.CdBodInsDest=BDI.IdBodega
LEFT JOIN Bodegas AS BT ON D.CdBodTdo=BT.IdBodega
LEFT JOIN (SELECT TipDoc,NumCons,IdCia,MAX(Traslado) AS NumTdoProd,MAX(NumTdoIns) AS NumTdoInsu FROM Trn_ProdConsPed GROUP BY TipDoc,NumCons,IdCia)
AS PT ON C.TipDoc=PT.TipDoc AND C.NumCons=PT.NumCons AND C.IdCia=PT.IdCia
WHERE C.TipDoc=@pmTipDoc AND C.NumCons BETWEEN @pmNumConsIni AND @pmNumConsFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsPedFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsPedFmt] @pmTipDoc VARCHAR(3),@pmNumConsIni INT,@pmNumConsFin INT,@pmIdCia CHAR(2)
AS 
SELECT PD.TipDoc,PD.NumCons,PD.IdCia,PD.Item,PD.TipPed,PD.Pedido,PD.IdCiaPed,Compania,PD.TipTdo,PD.Traslado,PD.IdCiaTdo,PD.NumTdoIns,PD.CdCiaIns
,O.Fecha,FechaVence,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia,Agencia,VrSubTotal,VrDescuento,VrImpuesto,VrNeto,O.IdVend,VN.RazonSocial AS Vendedor
,O.IdLocEnv,LE.Localidad AS CiudadEnvio,DirEnvio,DiasEntraga,O.NomContac,O.TelContac,O.emlContac,O.RefPedido,O.Modalidad,O.Vigencia,NumAprob,IdCiaApr,FecAprob,DetalleAprob
,O.TipFac,O.Factura,O.IdCiaFac,TipRem,Remision,IdCiaRem,O.NumAutSicom AS NumOrdenComp,O.IdEstado,Estado,O.Anulado,O.Observacion
FROM Trn_ProdConsPed AS PD INNER JOIN dbo.Trn_Opedido AS O ON PD.TipPed=O.TipDoc AND PD.Pedido=O.Pedido AND PD.IdCiaPed=O.IdCia
INNER JOIN Companias AS CN ON PD.IdCiaPed=CN.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
INNER JOIN Terceros AS VN ON O.IdVend=VN.IdTercero 
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal
WHERE PD.TipDoc=@pmTipDoc AND PD.NumCons BETWEEN @pmNumConsIni AND @pmNumConsFin AND PD.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsProcFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsProcFmt] @pmTipDoc VARCHAR(3),@pmNumConsIni INT,@pmNumConsFin INT,@pmIdCia CHAR(2)
AS 
SELECT D.TipDoc,D.NumCons,D.IdCia,D.Item,D.TipPed,D.Pedido,D.IdCiaPed,D.ItemPed,D.IdProducto AS CodProducto,P.DescripProd,D.IdBodega,B.Bodega
,D.CdUbic,D.CantAprob,D.Existencias,D.CantSaldo,D.CantTdo,D.IdTipProc,TP.TipoProceso,TP.IndOrden,D.ProcFinal,D.Cantidad,D.Tallas
,D.VrCostoEst,D.EdoOrden,D.TipOrden,D.NumOrden,D.CdCiaOrden,D.CantOrden
--datos del producto
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.Color,P.Tamano,P.IdUnd,UM.Unidad,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong AS ProComentarios
FROM Trn_ProdConsProc AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega INNER JOIN TiposProceso AS TP ON D.IdTipProc=TP.IdTipProc
INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
WHERE D.TipDoc=@pmTipDoc AND D.NumCons BETWEEN @pmNumConsIni AND @pmNumConsFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdConsTallasFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdConsTallasFmt] @pmTipDoc VARCHAR(3),@pmNumConsIni INT,@pmNumConsFin INT,@pmIdCia CHAR(2)
,@pmTipoReg VARCHAR(3)=Null
AS 
SELECT D.TipDoc,D.NumCons,D.IdCia,D.Item,D.TipoReg,D.ItemDet,D.NumTalla,D.Cantidad,D.CantPed AS CantAprob
FROM Trn_ProdConsTallas AS D
WHERE D.TipDoc=@pmTipDoc AND D.NumCons BETWEEN @pmNumConsIni AND @pmNumConsFin AND D.IdCia=@pmIdCia
AND (D.TipoReg=@pmTipoReg OR @pmTipoReg IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCostos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdCostos] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,IdCia,CostoAnt,CostoUlt,CostoPmd,FecUltPmd
 FROM ProdCostos
 WHERE IdProducto=@pmIdProducto AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdCostosCia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdCostosCia] @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null
,@pmIdSubgrupo VARCHAR(8)=Null,@pmTanques BIT=Null,@pmInactivo BIT=Null
 AS 
 SELECT P.IdProducto AS CdProducto,IdCia,CostoAnt,CostoUlt,CostoPmd
 FROM ProdCostos AS P INNER JOIN ProdMcias  AS PM ON P.IdProducto=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
  INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
  WHERE P.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND TipoRef LIKE ISNULL(@pmTipoRef,'%')  AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
  AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND PM.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo ,'%')
  AND (Tanques=ISNULL(@pmTanques,0) or Tanques=ISNULL(@pmTanques,1))
  AND (PM.Inactivo=ISNULL(@pmInactivo,0) or PM.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY P.IdProducto,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntrega]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntrega] @pmTipDoc VARCHAR(3),@pmNumEntrega INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumEntrega,IdCia,Fecha,TipOrden,NumOrden,IdCiaOrden,FecEntrega,CostoTotal,Descuento,CantTotal,TipoEntrega,NitTercero,NomContacto,TelContacto,EdoOrden,Anulado,FecDev,Observacion,IdEstado
,CodConcepto,TipCom,Comprobante,IdCiaCom,NumDev,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_ProdEntrega
 WHERE TipDoc=@pmTipDoc AND NumEntrega=@pmNumEntrega AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntrega_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntrega_Cr] @pmTipDoc VARCHAR(3),@pmNumEntregaIni INT,@pmNumEntregaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT E.TipDoc,TipoDoc,E.NumEntrega,E.IdCia,Compania,E.Fecha,E.FecEntrega,E.TipOrden,E.NumOrden,E.IdCiaOrden,E.CostoTotal,E.Descuento,E.CantTotal
,E.TipoEntrega,E.NitTercero,RazonSocial,E.NomContacto,E.TelContacto,E.EdoOrden AS EdoEntrega
,O.Fecha AS FecOrden,O.TipCons,O.NumCons,O.IdCiaCons,O.Modalidad,O.IdTipProc,TP.TipoProceso,TP.IndOrden,O.IdTaller,TL.NomTaller,TL.Direccion,TL.IdLocal,LC.Localidad,TL.Telefono,TL.TelCelular,TL.TipoTaller 
,O.ConPago,O.ProcFinal,O.Observacion AS ObservOrden,O.EdoOrden
,E.Anulado,E.FecDev,E.NumDev,E.Observacion,E.CodConcepto,E.TipCom,E.Comprobante,E.IdCiaCom,E.IdEstado,Estado,E.OrigenAdd,E.TimeSys AS FecCrea,E.FecUpdate AS FecActualiza,E.IdCiaCrea,E.IdUsuario,Usuario
--detalles
,D.Item,D.ItemOrden,D.CantOrden,D.Cantidad,D.Defectuoso,D.Rechazado,D.CostoUnit,D.VrDcto,D.TipPed,D.Pedido,D.IdCiaPed,D.ItemPed,D.IdProducto,P.DescripProd,D.Descripcion
,D.CdTipProc AS DetCdProc,PS.TipoProceso AS DetProceso,D.Tallas,D.ProcFinal AS DetProcFinal,D.Observacion AS MotivoRechz
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.IdUnd,UD.Unidad,P.Color,P.Tamano,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong
FROM Trn_ProdEntrega AS E INNER JOIN Trn_ProdEntregaDet AS D ON E.TipDoc=D.TipDoc AND E.NumEntrega=D.NumEntrega AND E.IdCia=D.IdCia
INNER JOIN Companias AS CN ON E.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON E.TipDoc=TD.IdDoc
INNER JOIN Trn_ProdOrden AS O ON E.TipOrden=O.TipDoc AND E.NumOrden=O.NumOrden AND E.IdCiaOrden=O.IdCia
INNER JOIN TiposProceso AS TP ON O.IdTipProc=TP.IdTipProc
INNER JOIN Talleres AS TL ON O.IdTaller=TL.IdTaller INNER JOIN Localidades AS LC ON TL.IdLocal=LC.IdLocal
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca INNER JOIN UndMed AS UD ON P.IdUnd=UD.IdUnd
LEFT JOIN TiposProceso AS PS ON D.CdTipProc=PS.IdTipProc 
LEFT JOIN Terceros AS T ON E.NitTercero=T.IdTercero
WHERE E.TipDoc=@pmTipDoc AND E.NumEntrega BETWEEN @pmNumEntregaIni AND @pmNumEntregaFin AND E.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaDev_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntregaDev_Cr] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT DV.TipDev,TipoDoc,DV.Devolucion,DV.IdCia,Compania,DV.Fecha,DV.TipDocEnt,DV.NumEntrega,DV.IdCiaEnt,E.FecEntrega,DV.CostoTotal,DV.Descuento
,DV.CantTotal,E.TipoEntrega,E.TipOrden,E.NumOrden,E.IdCiaOrden,E.EdoOrden AS EdoEntrega,DV.NitTercero,RazonSocial,E.NomContacto,E.TelContacto
,O.Fecha AS FecOrden,O.TipCons,O.NumCons,O.IdCiaCons,O.Modalidad,O.IdTipProc,TP.TipoProceso,TP.IndOrden,O.IdTaller,TL.NomTaller,TL.Telefono,TL.TelCelular,TL.TipoTaller 
,O.ConPago,O.ProcFinal,E.Observacion AS EntObservacion,O.Observacion AS ObservOrden
,DV.Observacion,DV.TipCom,DV.Comprobante,DV.IdCiaCom,DV.TimeSys AS FechaCrea,DV.IdCiaCrea,DV.OrigenAdd,DV.IdUsuario,Usuario
--detalles
,D.Item,D.ItemEnt,D.Cantidad AS CantDev,D.CostoUnit,D.VrDcto,D.Tallas,D.Observacion AS DetObservacion
,DE.Cantidad AS CantEntrega,DE.Defectuoso,DE.Rechazado AS CantTotDev,DE.ItemOrden,DE.CantOrden,DE.TipPed,DE.Pedido,DE.IdCiaPed,DE.ItemPed
,DE.IdProducto,P.DescripProd,DE.Descripcion,DE.CdTipProc AS DetCdProc,PS.TipoProceso AS DetProceso,DE.ProcFinal AS DetProcFinal
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.IdUnd,UD.Unidad,P.Color,P.Tamano,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong
FROM Trn_ProdEntregaDev AS DV INNER JOIN Trn_ProdEntregaDei AS D ON DV.TipDev=D.TipDev AND DV.Devolucion=D.Devolucion AND DV.IdCia=D.IdCia
INNER JOIN Trn_ProdEntrega AS E ON DV.TipDocEnt=E.TipDoc AND DV.NumEntrega=E.NumEntrega AND DV.IdCiaEnt=E.IdCia
INNER JOIN Trn_ProdEntregaDet AS DE ON DV.TipDocEnt=DE.TipDoc AND DV.NumEntrega=DE.NumEntrega AND DV.IdCiaEnt=DE.IdCia AND D.ItemEnt=DE.Item
INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario
INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
INNER JOIN Trn_ProdOrden AS O ON E.TipOrden=O.TipDoc AND E.NumOrden=O.NumOrden AND E.IdCiaOrden=O.IdCia
INNER JOIN TiposProceso AS TP ON O.IdTipProc=TP.IdTipProc
INNER JOIN Talleres AS TL ON O.IdTaller=TL.IdTaller
INNER JOIN ProdMcias AS P ON DE.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca INNER JOIN UndMed AS UD ON P.IdUnd=UD.IdUnd
LEFT JOIN TiposProceso AS PS ON DE.CdTipProc=PS.IdTipProc 
LEFT JOIN Terceros AS T ON DV.NitTercero=T.IdTercero
WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaDtlFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntregaDtlFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
AS
SELECT TipDev,Devolucion,IdCia,Item,ItemDet,NumTalla,Cantidad
FROM Trn_ProdEntregaDtl
WHERE TipDev=@pmTipDev AND Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin
AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaInsuFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntregaInsuFmt] @pmTipDoc VARCHAR(3),@pmNumEntregaIni INT,@pmNumEntregaFin INT,@pmIdCia CHAR(2)
AS 
SELECT D.TipDoc,D.NumEntrega,D.IdCia,D.Item,D.ItemCons,D.IdInsumo,IM.DescripProd AS Insumo,D.CantTraslado,D.CantSobrante
,D.CdBodOrig,B.Bodega,D.CdBodTdo,BD.Bodega AS BodegaDtno,D.TipTdo,D.Traslado,D.IdCiaTdo,D.CdTipProc,TP.TipoProceso
FROM Trn_ProdEntregaInsu AS D INNER JOIN ProdMcias AS IM ON D.IdInsumo=IM.IdProducto
INNER JOIN Bodegas AS B ON D.CdBodOrig=B.IdBodega
LEFT JOIN TiposProceso AS TP ON D.CdTipProc=TP.IdTipProc
LEFT JOIN Bodegas AS BD ON D.CdBodTdo=BD.IdBodega
WHERE D.TipDoc=@pmTipDoc AND D.NumEntrega BETWEEN @pmNumEntregaIni AND @pmNumEntregaFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntregaLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
SELECT E.TipDoc,TipoDoc,E.NumEntrega,E.IdCia,CI.Compania,E.Fecha,E.FecEntrega,E.TipOrden,E.NumOrden,E.IdCiaOrden,CO.Compania AS CiaOrden
,D.ItemOrden,D.Item,D.IdProducto AS CdProducto,D.Descripcion,D.CantOrden,D.Cantidad,D.Defectuoso,D.Rechazado,D.CostoUnit,D.VrDcto
,D.TipPed,D.Pedido,D.IdCiaPed,D.ItemPed,D.CdTipProc,TipoProceso,D.Tallas,D.ProcFinal,D.Observacion AS Detalle
,E.TipoEntrega,E.CodConcepto,Concepto,E.NitTercero,T.RazonSocial,E.NomContacto,E.TelContacto,E.CostoTotal,E.Descuento,E.CantTotal
,E.EdoOrden,E.IdEstado,ED.Estado,E.Observacion,E.TipCom,E.Comprobante,E.IdCiaCom,E.Anulado,E.NumDev,E.FecDev,E.TimeSys AS FechaCrea,E.IdUsuario,U.Usuario
--Inf. producto
,P.DescripProd,P.TipoRef,P.Referencia,P.CodBarras,G.IdLinea,Linea,SG.IdGrupo,Grupo,P.IdSubgrupo,Subgrupo,P.IdMarca,Marca,P.Tamano,P.Color
,P.UndMed,UM.Unidad AS DescUndMed,P.IdUnd,UM.Unidad,P.Tallaje,P.Inactivo
FROM Trn_ProdEntrega AS E INNER JOIN Trn_ProdEntregaDet AS D ON E.TipDoc=D.TipDoc AND E.NumEntrega=D.NumEntrega AND E.IdCia=D.IdCia
INNER JOIN adm_Usuarios AS U ON E.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON E.IdEstado=ED.IdEstado
INNER JOIN Sys_TiposDoc AS TD ON E.TipDoc=TD.IdDoc INNER JOIN Companias AS CI ON E.IdCia=CI.IdCia
INNER JOIN Companias AS CO ON E.IdCiaOrden=CO.IdCia  
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
LEFT JOIN Conceptos AS CN ON E.CodConcepto=CN.IdConcepto LEFT JOIN TiposProceso AS TP ON D.CdTipProc=TP.IdTipProc
LEFT JOIN Terceros AS T ON E.NitTercero=T.IdTercero
WHERE E.TipDoc=@pmTipDoc AND E.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
AND (E.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryProdEntregaTallasFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdEntregaTallasFmt] @pmTipDoc VARCHAR(3),@pmNumEntregaIni INT,@pmNumEntregaFin INT,@pmIdCia CHAR(2)
AS
SELECT TipDoc,NumEntrega,IdCia,Item,ItemDet,NumTalla,Cantidad,Defectuoso,Rechazado
FROM Trn_ProdEntregaTallas
WHERE TipDoc=@pmTipDoc AND NumEntrega BETWEEN @pmNumEntregaIni AND @pmNumEntregaFin
AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImpFron]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdImpFron] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT
 AS 
 SELECT IdProducto,IdClase,Item,IdLocal,CdDpto,Tarifa,SimbTfa,CdTarifa,TarifZfe,RngFecha,FecInicial,FecFinal,LtaPre,Inactivo,FecUpdate
 FROM ProdImpFron
 WHERE IdProducto=@pmIdProducto AND IdClase=@pmIdClase AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImpFronLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdImpFronLta] @pmIdProducto VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null
 AS 
 SELECT PIM.IdProducto AS CdProducto,DescripProd,PIM.IdClase AS CdClase,NomClase,Item,PIM.IdLocal AS CdLocal,Localidad
,CdDpto,Departamento,Tarifa,TarifZfe,SimbTfa,CdTarifa,RngFecha,FecInicial,FecFinal,LtaPre,PIM.Inactivo AS Inactvo,FecUpdate
 FROM ProdImpFron AS PIM  INNER JOIN ProdMcias AS P ON PIM.IdProducto=P.IdProducto
 INNER JOIN ClaseTar AS CT ON PIM.IdClase=CT.IdClase
 INNER JOIN Localidades AS L ON PIM.IdLocal=L.IdLocal LEFT JOIN Departamentos AS DP ON PIM.CdDpto=DP.IdDep
 WHERE PIM.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND PIM.IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY  DescripProd,PIM.IdClase,PIM.IdLocal,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImpFronUlt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdImpFronUlt] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4)
,@pmIdLocal VARCHAR(8)
 AS 
 SELECT IdProducto,IdClase,Item,IdLocal,CdDpto,Tarifa,SimbTfa,CdTarifa,TarifZfe,RngFecha,FecInicial,FecFinal,LtaPre
 FROM ProdImpFron
 WHERE IdProducto=@pmIdProducto AND IdClase=@pmIdClase  AND IdLocal=@pmIdLocal
 AND Inactivo=0
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdImptos] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT
 AS 
 SELECT IdProducto,IdClase,Item,Tarifa,SimbTfa,CdTarifa,RngFecha,FecInicial,FecFinal,LtaPre,Inactivo,FecUpdate,TarifZfe
 FROM ProdImptos
 WHERE IdProducto=@pmIdProducto AND IdClase=@pmIdClase AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdImptosFec] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4)
,@pmFecha SMALLDATETIME
 AS 
 SELECT IdProducto,IdClase,Tarifa,SimbTfa,CdTarifa,RngFecha,FecInicial,FecFinal,TarifZfe
 FROM ProdImptos
 WHERE  Inactivo=0 AND IdProducto=@pmIdProducto AND IdClase=@pmIdClase
 AND (RngFecha=0 OR (RngFecha<>0 AND @pmFecha BETWEEN FecInicial AND FecFinal))
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdImptosItm] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM ProdImptos
 WHERE IdProducto=@pmIdProducto AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdImptosLta] @pmIdProducto VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null
,@pmInactivo BIT=Null
 AS 
 SELECT PIM.IdProducto AS CodProd,DescripProd,PIM.IdClase AS CdClase,NomClase,Item,Tarifa,TarifZfe,SimbTfa,CdTarifa,RngFecha
,FecInicial,FecFinal,LtaPre,PIM.Inactivo AS Inactiv,FecUpdate
 FROM ProdImptos AS PIM  INNER JOIN ProdMcias AS P ON PIM.IdProducto=P.IdProducto
 INNER JOIN ClaseTar AS CT ON PIM.IdClase=CT.IdClase
 WHERE PIM.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND PIM.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND (PIM.Inactivo=ISNULL(@pmInactivo,0) or PIM.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY  DescripProd,PIM.IdClase,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdImptosUlt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdImptosUlt] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdProducto,IdClase,Item,Tarifa,SimbTfa,CdTarifa,RngFecha,FecInicial,FecFinal,LtaPre,TarifZfe
 FROM ProdImptos
 WHERE  Inactivo=0 AND IdProducto=@pmIdProducto AND IdClase LIKE ISNULL(@pmIdClase ,'%')
 ORDER BY IdClase,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryProdInsumosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdInsumosLta] 
AS
SELECT PN.IdProducto AS CodProducto,P.DescripProd,PN.Item,PN.IdInsumo AS CodInsumo,IM.DescripProd AS DescInsumo
,PN.IdTipProc,TipoProceso,PC.Descripcion AS DescProceso,PC.IndOrden,PN.Cantidad,PN.Inactivo,PN.Id
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.Color,P.Tamano,P.IdUnd,UM.Unidad AS UndadMed,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong
--inf. insumos
,IM.IdUnd AS InsIdUnd,UMI.Unidad AS InsUndad
FROM ProdInsumos AS PN INNER JOIN TiposProceso AS PC ON PN.IdTipProc=PC.IdTipProc
INNER JOIN ProdMcias AS P ON PN.IdProducto=P.IdProducto INNER JOIN ProdMcias AS IM ON PN.IdInsumo=IM.IdProducto
INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd INNER JOIN UndMed AS UMI ON IM.IdUnd=UMI.IdUnd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMcias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdMcias] @pmIdProducto VARCHAR(16)
 AS 
 SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,IdSubgrupo,IdMarca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,UndMed,IdUnd,IdUndP,CdUndS,CdUndE,CdUndEb
,IdEmp,IdNat,IdMnjo,IdTmcia,IdBodega,IdUbic,DesUbic,IdProv,GarProv,GarClie,CdDctCom,VrCostAnt,VrCosto,VrCostPmd,IdTarIva,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5,CdMon1,CdMon2,CdMon3
,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,CdTarIca,CdTarRet,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes
,Combo,NoAjustes,Tanques,ValesComb,Tallaje,FecUltcom,FecUltVta,CodMcia,DescripLong,Cmntarios,PathFoto,CantTpv,IdEstado,Inactivo,TipoZonaFront,ExcluidoImp,Electrocomb,IvaDetCombo,LtaBaseIva,CodFEDian,TipoProdCo
,TipoIBAICU,Procedencia,CantAzucar,FechaAdd,FechaUpdate,IdUsuario
 FROM ProdMcias
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMcias_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMcias_Cr] @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmSeriales BIT=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null,@pmIdCiaCos CHAR(2)=Null,@pmIdCiaSal CHAR(2)=Null
 AS 
 SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo,P.IdMarca AS CdMarc,Marca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,P.UndMed AS UndVolm,SM.Unidad
,P.IdUnd AS CdUnd,UM.Unidad AS UndadMed,IdUndP,UP.Unidad AS EmpPrim,CdUndS,CdUndE,CdUndEb,P.IdEmp AS CdEmp,Empaque,P.IdNat AS CdNat,Natlzaprod,P.IdMnjo AS CdMnjo,ManejoMcia,P.IdTmcia AS CdTmcia,TipoMcia,P.IdBodega AS CdBodga,Bodega,Descrip,LtaPre AS LtaPreBod
,IdUbic,DesUbic,P.IdProv AS IdProvee,RazonSocial,GarProv,GarClie,CdDctCom,DCC.Tarifa AS TarifDctComp,VrCostAnt,CiaCostoAnt,VrCosto,CiaCostoUlt,VrCostPmd,CiaCostoPmd,IdTarIva,TI.Tarifa AS TarifIva,TI.Simbolo AS SimbTarfIva,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5,BaseMgn,CdMgn1,MG1.Tarifa AS TarifMarg1
,CdMgn2,MG2.Tarifa AS TarifMarg2,CdMgn3,MG3.Tarifa AS TarifMarg3,CdMgn4,MG4.Tarifa AS TarifMarg4,CdMgn5,MG5.Tarifa AS TarifMarg5,CdDct1,DC1.Tarifa AS TarifDct1,CdDct2,DC2.Tarifa AS TarifDct2,CdDct3,DC3.Tarifa AS TarifDct3,CdDct4,DC4.Tarifa AS TarifDct4,CdDct5,DC5.Tarifa AS TarifDct5
,P.CdTarIca AS CdTarfIca,TIC.Tarifa AS TarifIca,P.CdTarRet AS CdTarfRet,TRF.Tarifa AS TarifRet,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,ExtciaMin,ExtciaMax,ExtciaAct,CiaExistencia,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,NoAjustes
,Tanques,ValesComb,Tallaje,TipoProdCo,TipoIBAICU,Procedencia,CantAzucar,TipoZonaFront,ExcluidoImp,Electrocomb,IvaDetCombo,LtaBaseIva,FecUltcom,FecUltVta,CodMcia,DescripLong,CodFEDian,P.Cmntarios AS Prod_Observ,P.PathFoto AS ArchivoFoto,CantTpv,P.IdEstado AS CdEstdo,Estado,NColor,P.Inactivo AS Inactvo
--información del proveedor
,TipoId,Dv,NomCial,Direccion,TP.IdLocal AS CdCiudad,Localidad,Departamento,Telefono,Fax,e_mail,TP.IdSector AS CdSector,SectorEco,TP.IdRegimen AS CdRegimen,Regimen,TipEnte
,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,PV.IdGrupo AS IdGrupoClie,GrupoClie
,P.IdUsuario AS IdUsuari,Usuario,P.FechaAdd AS FecAdd,P.FechaUpdate AS FecUpd
 FROM ProdMcias AS P INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd  INNER JOIN UndMed AS UP ON P.IdUndP=UP.IdUnd
 INNER JOIN Empaques AS E ON P.IdEmp=E.IdEmp INNER JOIN TiposNat AS N ON P.IdNat=N.IdNat
 INNER JOIN TiposMnjo AS MM ON P.IdMnjo=MM.IdMnjo INNER JOIN TiposMcia AS TM ON P.IdTmcia=TM.IdTmcia
 INNER JOIN Bodegas AS B ON P.IdBodega=B.IdBodega INNER JOIN Terceros AS TP ON P.IdProv=TP.IdTercero
 INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa INNER JOIN EstadoPro AS EP ON P.IdEstado=EP.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario 
 INNER JOIN SectoresEco AS SE ON TP.IdSector=SE.IdSector INNER JOIN RegimenDian AS RG ON TP.IdRegimen=RG.IdRegimen
 INNER JOIN Localidades AS LP ON TP.IdLocal=LP.IdLocal  INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 LEFT JOIN TercProvee AS PV ON P.IdProv=PV.IdProv  LEFT JOIN GruposCli AS GP ON PV.IdGrupo=GP.IdGrupo
 LEFT JOIN  Tablapor AS MG1 ON P.CdMgn1=MG1.IdTarifa  LEFT JOIN  Tablapor AS MG2 ON P.CdMgn2=MG2.IdTarifa
 LEFT JOIN  Tablapor AS MG3 ON P.CdMgn3=MG3.IdTarifa  LEFT JOIN  Tablapor AS MG4 ON P.CdMgn4=MG4.IdTarifa
 LEFT JOIN  Tablapor AS MG5 ON P.CdMgn5=MG5.IdTarifa LEFT JOIN  Tablapor AS DCC ON P.CdDctCom=DCC.IdTarifa
 LEFT JOIN  Tablapor AS DC1 ON P.CdDct1=DC1.IdTarifa LEFT JOIN  Tablapor AS DC2 ON P.CdDct2=DC2.IdTarifa
 LEFT JOIN  Tablapor AS DC3 ON P.CdDct3=DC3.IdTarifa LEFT JOIN  Tablapor AS DC4 ON P.CdDct4=DC4.IdTarifa
 LEFT JOIN  Tablapor AS DC5 ON P.CdDct5=DC5.IdTarifa 
 LEFT JOIN  Tablapor AS TIC ON P.CdTarIca=TIC.IdTarifa LEFT JOIN  Tablapor AS TRF ON P.CdTarRet=TRF.IdTarifa
 LEFT JOIN Sys_Um AS SM ON P.UndMed=SM.UndMed
 --consulta de costos
 LEFT JOIN (SELECT IdProducto AS CiaProducto,CostoAnt AS CiaCostoAnt,CostoUlt AS CiaCostoUlt,CostoPmd  AS CiaCostoPmd
 FROM ProdCostos WHERE IdCia=@pmIdCiaCos)  AS CP ON P.IdProducto=CP.CiaProducto
--consulta de saldos
 LEFT JOIN (SELECT  IdProducto AS SalProducto,SUM(SaldoActual) AS CiaExistencia FROM ProdSaldos
 WHERE IdCia=@pmIdCiaSal AND IdBodega LIKE ISNULL(@pmIdBodega,'%') GROUP BY IdProducto)  AS SC ON P.IdProducto=SC.SalProducto
 WHERE  TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND P.IdMarca LIKE ISNULL(@pmIdMarca,'%') AND P.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND P.IdProv LIKE ISNULL(@pmIdProv,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Seriales=ISNULL(@pmSeriales,0) or  Seriales=ISNULL(@pmSeriales,1))
 AND (Tanques=ISNULL(@pmTanques,0) or  Tanques=ISNULL(@pmTanques,1))
 AND (P.Inactivo=ISNULL(@pmInactivo,0) or  P.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasCat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMciasCat] @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null
,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null,@pmIdProducto VARCHAR(16)=Null,@pmTanques BIT=Null
,@pmInactivo BIT=Null
 AS 
 SELECT G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,IdProducto,DescripProd,DescripAbrv,P.Inactivo AS Inactvo,Tanques,TipoRef,P.IdMarca AS CdMarc,Marca,P.IdEstado AS CdEstdo,Estado
,ExtciaAct
 FROM ProdMcias AS P INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN EstadoPro AS EP ON P.IdEstado=EP.IdEstado
 WHERE  TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND P.IdMarca LIKE ISNULL(@pmIdMarca,'%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Tanques=ISNULL(@pmTanques,0) or  Tanques=ISNULL(@pmTanques,1))
 AND (P.Inactivo=ISNULL(@pmInactivo,0) or  P.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Linea,Grupo,Subgrupo,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasCod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMciasCod] @pmIdProducto VARCHAR(20),@pmCodBarras VARCHAR(20)
,@pmReferencia VARCHAR(20),@pmInactivo BIT=Null
 AS 
 SELECT ProdMcias.*
 FROM ProdMcias
 WHERE (IdProducto=@pmIdProducto OR CodBarras=@pmCodBarras OR Referencia=@pmReferencia)
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasCol]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMciasCol]
 AS 
 SELECT Color,COUNT(IdProducto)  AS CantProd
 FROM ProdMcias
 GROUP BY Color
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasDes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMciasDes] @pmIdProducto VARCHAR(16)
 AS 
 SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,Linea,Grupo,Subgrupo,Marca,Color,Tamano,P.UndMed AS UndVolm
,UM.Unidad AS UndadMed,UP.Unidad AS EmpPrim,Empaque,Bodega,DescripLong,Estado,RazonSocial,Tarifa,Simbolo
,S.IdGrupo AS CdGrupo,G.IdLinea AS CdLinea
 FROM ProdMcias AS P INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd  INNER JOIN UndMed AS UP ON P.IdUndP=UP.IdUnd
 INNER JOIN Empaques AS E ON P.IdEmp=E.IdEmp  INNER JOIN Bodegas AS B ON P.IdBodega=B.IdBodega
 INNER JOIN Terceros AS TP ON P.IdProv=TP.IdTercero
 INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa INNER JOIN EstadoPro AS EP ON P.IdEstado=EP.IdEstado
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasLkar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMciasLkar]  @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2),@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null
,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null,@pmIdMarca VARCHAR(4)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmSeriales BIT=Null,@pmTanques BIT=Null
,@pmLotes BIT=Null,@pmInactivo BIT=Null,@pmCiaPre CHAR(2)=Null
 AS 
 SELECT K.IdProducto AS CdProducto,DescripProd,TipoRef,P.IdBodega AS CdBodega,IdTarIva,Tarifa,IvaInc,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,BaseMgn
,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,ExtciaAct,ExtciaAct,ExtciaMin,ExtciaMax,VrCostPmd,VrCosto,Precio1,Precio2,Precio3,Precio4,Precio5,S.CdTarifIco
--precios cia
,CiaCodProd,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,CiaIvaInc,CiaIdTarifIva,CiaTarifIva,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5
 ,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5
,SUM(Entradas) AS TotalEnt,SUM(Salidas) AS TotalSal,SUM(VrCostoEnt) AS TotalCostoEnt,SUM(VrCostoSal) AS TotalCostoSal
 FROM Trn_Kardex AS K INNER JOIN  ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa
 INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 LEFT JOIN (SELECT IdProducto AS CiaCodProd,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,IvaInc AS CiaIvaInc,CdTarIva AS CiaIdTarifIva,Tarifa AS CiaTarifIva
,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5
 FROM ProdPrecios AS PP LEFT JOIN Tablapor AS CI ON PP.CdTarIva=CI.IdTarifa WHERE IdCia=@pmCiaPre) AS PC ON K.IdProducto=PC.CiaCodProd
 WHERE TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND IdCia=@pmIdCia
 AND  TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND IdMarca LIKE ISNULL(@pmIdMarca,'%') AND P.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND IdProv LIKE ISNULL(@pmIdProv,'%') AND IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Seriales=ISNULL(@pmSeriales,0) or  Seriales=ISNULL(@pmSeriales,1))
 AND (Tanques=ISNULL(@pmTanques,0) or  Tanques=ISNULL(@pmTanques,1))
 AND (Lotes=ISNULL(@pmLotes,0) or  Lotes=ISNULL(@pmLotes,1))
 AND (P.Inactivo=ISNULL(@pmInactivo,0) or P.Inactivo=ISNULL(@pmInactivo,1))
 GROUP BY  K.IdProducto,DescripProd,TipoRef,P.IdBodega,IdTarIva,Tarifa,IvaInc,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,BaseMgn
,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,ExtciaAct,ExtciaAct,ExtciaMin,ExtciaMax,VrCostPmd,VrCosto,Precio1,Precio2,Precio3,Precio4,Precio5,S.CdTarifIco
,CiaCodProd,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,CiaIvaInc,CiaIdTarifIva,CiaTarifIva,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5
 ,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5
 ORDER BY DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasLpre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdMciasLpre] @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmSeriales BIT=Null,@pmTanques BIT=Null
,@pmLotes BIT=Null,@pmInactivo BIT=Null,@pmCiaPre CHAR(2)=Null
 AS 
 SELECT IdProducto AS CdProducto,DescripProd,TipoRef,IdBodega,IdTarIva,Tarifa,IvaInc,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,BaseMgn
,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,ExtciaAct,ExtciaAct,ExtciaMin,ExtciaMax,VrCostPmd,VrCosto,Precio1,Precio2,Precio3,Precio4,Precio5,S.CdTarifIco
--precios cia
,CiaCodProd,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,CiaIvaInc,CiaIdTarifIva,CiaTarifIva,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5
 ,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5
 FROM ProdMcias AS P  INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa
 INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 LEFT JOIN (SELECT IdProducto AS CiaCodProd,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,IvaInc AS CiaIvaInc,CdTarIva AS CiaIdTarifIva,Tarifa AS CiaTarifIva
,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5
 FROM ProdPrecios AS PP LEFT JOIN Tablapor AS CI ON PP.CdTarIva=CI.IdTarifa WHERE IdCia=@pmCiaPre) AS PC ON P.IdProducto=PC.CiaCodProd
  WHERE TipoRef<>'INSUMO'  AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND IdMarca LIKE ISNULL(@pmIdMarca,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND IdProv LIKE ISNULL(@pmIdProv,'%') AND IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Seriales=ISNULL(@pmSeriales,0) or  Seriales=ISNULL(@pmSeriales,1))
 AND (Tanques=ISNULL(@pmTanques,0) or  Tanques=ISNULL(@pmTanques,1))
 AND (Lotes=ISNULL(@pmLotes,0) or  Lotes=ISNULL(@pmLotes,1))
 AND (P.Inactivo=ISNULL(@pmInactivo,0) or P.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdMciasLta] @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmSeriales BIT=Null,@pmTanques BIT=Null
 AS 
 SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo,P.IdMarca AS CdMarc,Marca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,P.UndMed AS UndVolm
,P.IdUnd AS CdUnd,UM.Unidad AS UndadMed,IdUndP,UP.Unidad AS EmpPrim,CdUndS,CdUndE,CdUndEb,P.IdEmp AS CdEmp,Empaque,P.IdNat AS CdNat,Natlzaprod,P.IdMnjo AS CdMnjo,ManejoMcia,P.IdTmcia AS CdTmcia,TipoMcia,P.IdBodega AS CdBodga,Bodega,IdUbic,DesUbic,IdProv,RazonSocial
,GarProv,GarClie,CdDctCom,VrCostAnt,VrCosto,VrCostPmd,IdTarIva,Tarifa,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5,P.CdTarIca AS CdTarfIca,P.CdTarRet AS CdTarfRet
,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,IvaDetCombo,LtaBaseIva,NoAjustes,Tanques,ValesComb,FecUltcom,FecUltVta,CodMcia,DescripLong,Cmntarios,PathFoto,CantTpv,P.IdEstado AS CdEstdo,Estado,P.Inactivo AS Inactvo,TipoZonaFront,ExcluidoImp,Electrocomb,CodFEDian,Tallaje,TipoProdCo,TipoIBAICU,Procedencia,CantAzucar
,P.IdUsuario AS IdUsuari,Usuario,P.FechaAdd AS FecAdd,P.FechaUpdate AS FecUpd
 FROM ProdMcias AS P INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd  INNER JOIN UndMed AS UP ON P.IdUndP=UP.IdUnd
 INNER JOIN Empaques AS E ON P.IdEmp=E.IdEmp INNER JOIN TiposNat AS N ON P.IdNat=N.IdNat
 INNER JOIN TiposMnjo AS MM ON P.IdMnjo=MM.IdMnjo INNER JOIN TiposMcia AS TM ON P.IdTmcia=TM.IdTmcia
 INNER JOIN Bodegas AS B ON P.IdBodega=B.IdBodega INNER JOIN Terceros AS TP ON P.IdProv=TP.IdTercero
 INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa INNER JOIN EstadoPro AS EP ON P.IdEstado=EP.IdEstado
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario 
 WHERE P.TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND P.IdMarca LIKE ISNULL(@pmIdMarca,'%') AND P.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND IdProv LIKE ISNULL(@pmIdProv,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Seriales=ISNULL(@pmSeriales,0) or  Seriales=ISNULL(@pmSeriales,1))
 AND (Tanques=ISNULL(@pmTanques,0) or  Tanques=ISNULL(@pmTanques,1))
 ORDER BY DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdMciasPre] @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null
 AS 
 SELECT IdProducto,DescripProd,DescripAbrv,TipoRef,VrCosto,VrCostPmd,IdTarIva,Tarifa,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,BaseMgn,CdMgn1,CdMgn2,CdMgn3,CdMgn4,CdMgn5,CdDct1,CdDct2,CdDct3,CdDct4,CdDct5
,IdUnd,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo,IdMarca,IdBodega,IdProv,ExtciaMin,ExtciaMax,ExtciaAct
,IdEstado,P.Inactivo AS Inactiv,CdDctCom
 FROM ProdMcias AS P INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea  INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa 
 WHERE P.Inactivo=0  AND TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND IdMarca LIKE ISNULL(@pmIdMarca,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND IdProv LIKE ISNULL(@pmIdProv,'%') 
 ORDER BY DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasRef]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdMciasRef]  @pmCodigo VARCHAR(20),@pmEsRef BIT,@pmTipoRef VARCHAR(10)=Null
 AS 
 IF @pmEsRef=1
   SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef
   FROM  ProdMcias
   WHERE Referencia=@pmCodigo AND  Inactivo=0 AND TipoRef LIKE ISNULL(@pmTipoRef,'%')
   ORDER BY IdProducto
 ELSE
   SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef
   FROM  ProdMcias
   WHERE CodBarras=@pmCodigo AND Inactivo=0 AND TipoRef LIKE ISNULL(@pmTipoRef,'%')
   ORDER BY IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasShr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdMciasShr] @pmIdProducto VARCHAR(16)
 AS 
 SELECT IdProducto,DescripProd,DescripAbrv,CodBarras,Referencia,TipoRef,DescripLong
,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,Inactivo
 FROM ProdMcias
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdMciasVal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdMciasVal] 
 AS 
 SELECT IdProducto,DescripProd,TipoRef
 FROM ProdMcias
 WHERE  TipoRef='SERVICIO' AND ValesComb<>0  AND Inactivo=0
 ORDER BY  IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrden]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,TipCons,NumCons,IdCiaCons,Modalidad,IdTipProc,IdTaller,CostoTotal,ConPago,EdoOrden,Num_Entrega,CdCiaEnt,FecEntrega
,NitTercero,NomContacto,TelContacto,ProcFinal,Anulado,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_ProdOrden
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrden_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrden_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
AS 
SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia,Compania,O.Fecha,D.TipCons,D.NumCons,D.IdCiaCons,C.Fecha AS FecCons,O.Modalidad,O.IdTipProc,TP.TipoProceso,TP.IndOrden
,O.IdTaller,TL.NomTaller,TL.Direccion,TL.IdLocal,LC.Localidad,TL.Telefono,TL.TelCelular,TL.TipoTaller,O.NitTercero,RazonSocial,O.NomContacto,O.TelContacto
,O.CostoTotal,O.ConPago,O.EdoOrden,O.Num_Entrega,O.CdCiaEnt,O.FecEntrega,O.ProcFinal,O.Anulado,O.FecDev,O.Observacion
,O.IdEstado,Estado,O.OrigenAdd,O.TimeSys AS FecCrea,O.FecUpdate AS FecActualiza,O.IdCiaCrea,O.IdUsuario,Usuario
--datos detalle
,D.Item,DT.TipPed,DT.Pedido,DT.IdCiaPed,DT.ItemPed,D.ItemCons,D.IdProducto,P.DescripProd,D.Descripcion,D.Cantidad,D.CostoEst,D.Terminado,D.Defectuoso,D.Rechazado
,DT.IdBodega AS CodBodega,B.Bodega,DT.CantAprob,DT.Existencias,DT.CantSaldo,DT.CantTdo,DT.Cantidad AS CantProceso,DT.Tallas
,DT.IdTipProc AS DetCdTipProc,PS.TipoProceso AS DetTipoProceso,DT.ProcFinal AS DetProcFinal,D.MotivoDev,D.ItemEnt
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.IdUnd,UD.Unidad,P.Color,P.Tamano,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong
FROM Trn_ProdOrden AS O INNER JOIN TiposProceso AS TP ON O.IdTipProc=TP.IdTipProc
INNER JOIN Talleres AS TL ON O.IdTaller=TL.IdTaller INNER JOIN Localidades AS LC ON TL.IdLocal=LC.IdLocal
INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
INNER JOIN Trn_ProdOrdenDet AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
INNER JOIN Trn_ProdConsolida AS C ON D.TipCons=C.TipDoc AND D.NumCons=C.NumCons AND D.IdCiaCons=C.IdCia
INNER JOIN Trn_ProdConsProc AS DT ON D.TipCons=DT.TipDoc AND D.NumCons=DT.NumCons AND D.IdCiaCons=DT.IdCia AND D.ItemCons=DT.Item
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca INNER JOIN UndMed AS UD ON P.IdUnd=UD.IdUnd
INNER JOIN Bodegas AS B ON DT.IdBodega=B.IdBodega
LEFT JOIN TiposProceso AS PS ON DT.IdTipProc=PS.IdTipProc
LEFT JOIN Terceros AS T ON O.NitTercero=T.IdTercero
WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenEntFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrdenEntFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
AS 
SELECT O.TipDoc,O.NumEntrega,O.IdCia,Compania,O.Fecha,O.FecEntrega,O.TipoEntrega,O.NitTercero,RazonSocial,O.NomContacto,O.TelContacto
,O.TipOrden,O.NumOrden,O.IdCiaOrden,O.EdoOrden,O.Anulado,O.FecDev,O.Observacion,O.TimeSys AS FechaCrea,O.IdUsuario,Usuario
,D.Item,D.ItemOrden,D.CantOrden,D.Cantidad,D.Defectuoso,D.Rechazado,D.CostoUnit,D.VrDcto,D.TipPed,D.Pedido,D.IdCiaPed,D.ItemPed
,D.IdProducto,P.DescripProd,D.Descripcion,D.CdTipProc,TipoProceso,D.Tallas,D.ProcFinal,D.Observacion AS MotivoRchzo,P.Tallaje
FROM Trn_ProdEntrega AS O INNER JOIN Trn_ProdEntregaDet AS D ON O.TipDoc=D.TipDoc AND O.NumEntrega=D.NumEntrega AND O.IdCia=D.IdCia
INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
LEFT JOIN TiposProceso AS TP ON D.CdTipProc=TP.IdTipProc LEFT JOIN Terceros AS T ON O.NitTercero=T.IdTercero
WHERE O.TipOrden=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin  AND O.IdCia=@pmIdCia
AND O.Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrdenLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdInsumo VARCHAR(16)=Null
 AS 
SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia,Compania,O.Fecha,O.IdTipProc,TipoProceso
,D.Item,D.IdProducto AS CdProducto,D.Descripcion,D.Cantidad,D.CostoEst,D.Terminado,D.Defectuoso,D.Rechazado
,D.MotivoDev,D.TipCons,D.NumCons,D.IdCiaCons,D.ItemCons,CD.TipPed,CD.Pedido,CD.IdCiaPed,CD.ItemPed,CD.CantAprob
,CD.Cantidad AS CantConsolida,CD.CantTdo,CD.Tallas,CD.EdoOrden AS EdoConsolida,D.TipEntInv,D.NumEntrada,D.CdCiaEnt,D.ItemKdxEnt,D.CantEntrada
,O.Modalidad,O.ConPago,O.IdTaller AS CdTaller,TL.NomTaller,TL.TelCelular,TL.TipoTaller,O.NitTercero,T.RazonSocial,O.NomContacto,O.TelContacto
,O.EdoOrden,O.ProcFinal,TP.IndOrden AS ProcOrden,O.FecEntrega,O.Num_Entrega AS NumEntArreglo,O.CdCiaEnt AS CiaEntArreglo,EG.FechaUltEnt,EG.MaxNumEntrega AS UltNumEntrega,EG.MaxIdCia AS Cd_CiaEnt
,O.Observacion,O.Anulado,O.FecDev,O.IdEstado,ED.Estado,O.TimeSys AS FechaCrea,O.IdUsuario,U.Usuario
--datos del producto
,P.DescripProd,P.TipoRef,P.Referencia,P.CodBarras,G.IdLinea,Linea,SG.IdGrupo,Grupo,P.IdSubgrupo,Subgrupo,P.IdMarca,Marca,P.Tamano,P.Color
,P.UndMed,UM.Unidad AS DescUndMed,P.IdUnd,UM.Unidad,P.Tallaje,P.Inactivo
--datos del pedidO
,OP.Fecha AS FecPedido,OP.FechaVence,OP.IdCliente,TC.RazonSocial AS NomCliente,OP.IdAgencia,OP.IdVend,VN.RazonSocial AS NomVendedor,OP.DiasEntraga,OP.RefPedido
,OP.TipFac,OP.Factura,OP.IdCiaFac,OP.FechaFact,OP.NumAutSicom as NumOrdenCom
FROM Trn_ProdOrden AS O INNER JOIN Trn_ProdOrdenDet AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
INNER JOIN TiposProceso AS TP ON O.IdTipProc=TP.IdTipProc INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
INNER JOIN Companias AS CI ON O.IdCia=CI.IdCia INNER JOIN EstadoDoc  AS ED ON O.IdEstado=ED.IdEstado INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
INNER JOIN Talleres AS TL ON O.IdTaller=TL.IdTaller 
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
LEFT JOIN Terceros AS T ON O.NitTercero=T.IdTercero
LEFT JOIN Trn_ProdConsProc AS CD ON D.TipCons=CD.TipDoc AND D.NumCons=CD.NumCons AND D.IdCiaCons=CD.IdCia AND D.ItemCons=CD.Item
LEFT JOIN Trn_Opedido AS OP ON CD.TipPed=OP.TipDoc AND CD.Pedido=OP.Pedido AND CD.IdCiaPed=OP.IdCia
LEFT JOIN Terceros AS TC ON OP.IdCliente=TC.IdTercero LEFT JOIN Terceros AS VN ON OP.IdVend=VN.IdTercero
--datos ultima entrega
LEFT JOIN (SELECT TipOrden,NumOrden,IdCiaOrden,MAX(FecEntrega) AS FechaUltEnt,MAX(NumEntrega) AS MaxNumEntrega,MAX(IdCia) AS MaxIdCia
FROM Trn_ProdEntrega WHERE TipDoc='OEP' AND Anulado=0 GROUP BY TipOrden,NumOrden,IdCiaOrden) AS EG ON O.TipDoc=EG.TipOrden AND O.NumOrden=EG.NumOrden AND O.IdCia=EG.IdCiaOrden
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL)
AND dbo.FuncProdConsInsu(D.TipCons,D.NumCons,D.IdCiaCons,D.IdProducto,@pmIdInsumo)=1
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenLtp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrdenLtp] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
SELECT O.TipDoc,O.Pedido,O.IdCia,O.IdCliente,O.IdAgencia,O.IdVend,D.Item,D.IdProducto,D.Salidas,D.Unidades
,C.Fecha AS FechaCons,CP.NumCons,CP.IdCia AS CdCiaCons,CP.Item AS ItemCons,CP.IdTipProc,TipoProceso,CP.ProcFinal,CP.Cantidad,CP.CantOrden AS CantTotOrden
,OD.NumOrden,OD.IdCia AS CiaOrden,OD.Item AS ItemOrden,OD.Cantidad AS Cant_Orden,CASE WHEN OP.Modalidad='ARREGLO' THEN OD.Cantidad ELSE 0 END AS Cant_Arreglos
,OD.CostoEst,OD.Descripcion,OD.Terminado+OD.Defectuoso AS CantTotEntrega,OD.Rechazado AS CantTotDev,OD.MotivoDev,OD.NumEntrada,OD.CdCiaEnt,OD.ItemKdxEnt,OD.CantEntrada
,OP.Fecha AS FecOrden,OP.Modalidad,OP.IdTaller,NomTaller,OP.ConPago,OP.EdoOrden,OP.FecEntrega AS FecEstEntrega,OP.NitTercero,T.RazonSocial,OP.NomContacto,OP.TelContacto,OP.Observacion
--detalle de entregas
,ED.NumEntrega,ED.IdCia AS CdCiaEnt,ED.Item AS ItemEnt,ED.Cantidad+ED.Defectuoso AS CantEntregas,ED.Rechazado AS CantDevEntregas,ED.CostoUnit,ED.VrDcto,ED.Observacion AS EntObservacion
,E.FecEntrega,E.TipoEntrega,E.EdoOrden AS EdoEntrega,E.TipCom,E.Comprobante,E.IdCiaCom
FROM Trn_Opedido AS O INNER JOIN Trn_Kardex AS D ON O.TipDoc=D.TipDoc AND O.Pedido=D.Documento AND O.IdCia=D.IdCia
INNER JOIN Trn_ProdConsProc AS CP ON D.TipDoc=CP.TipPed AND D.Documento=CP.Pedido AND D.IdCia=CP.IdCiaPed AND D.Item=CP.ItemPed
INNER JOIN Trn_ProdConsolida AS C ON CP.TipDoc=C.TipDoc AND CP.NumCons=C.NumCons AND CP.IdCia=C.IdCia
INNER JOIN Trn_ProdOrdenDet AS OD ON CP.TipDoc=OD.TipCons AND CP.NumCons=OD.NumCons AND CP.IdCia=OD.IdCiaCons AND CP.Item=OD.ItemCons
INNER JOIN Trn_ProdOrden AS OP ON OD.TipDoc=OP.TipDoc AND OD.NumOrden=OP.NumOrden AND OD.IdCia=OP.IdCia 
INNER JOIN Talleres AS TL ON OP.IdTaller=TL.IdTaller INNER JOIN TiposProceso AS TP ON CP.IdTipProc=TP.IdTipProc
LEFT JOIN Trn_ProdEntregaDet AS ED ON OD.TipDoc=ED.TipOrden AND OD.NumOrden=ED.NumOrden AND OD.IdCia=ED.IdCiaOrden AND OD.Item=ED.ItemOrden
LEFT JOIN Trn_ProdEntrega AS E ON ED.TipDoc=E.TipDoc AND ED.NumEntrega=E.NumEntrega AND ED.IdCia=E.IdCia
LEFT JOIN Terceros AS T ON OP.NitTercero=T.IdTercero
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (O.IdCia=@pmIdCia OR @pmIdCia IS NULL) AND O.Anulado=0 AND C.Anulado=0 AND OP.Anulado=0 AND ISNULL(E.Anulado,0)=0
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenSalFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrdenSalFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
AS
SELECT PS.TipDoc,PS.NumOrden,PS.IdCia,Compania,PS.Item,PS.TipSal,PS.NumSalida,PS.IdCiaSal,D.Item AS DetItem,D.IdProducto,D.Descripcion,D.Entradas,D.Salidas,D.VrUnitario
,D.IdBodega,Bodega,D.Referencia AS SalReferencia,SA.Fecha,SA.TipOrd,SA.NumOrden AS Num_OrdenSA,SA.IdCiaOrd,SA.Modalidad,SA.Anulado,SA.Observacion,SA.TipCom,SA.Comprobante,SA.IdCiaCom
,P.DescripProd,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.IdUnd,UD.Unidad,P.Color,P.Tamano,P.Inactivo AS ProdInactivo,P.DescripLong
FROM Trn_ProdOrdenSal AS PS INNER JOIN Trn_Kardex AS D ON PS.TipSal=D.TipDoc AND PS.NumSalida=D.Documento AND PS.IdCiaSal=D.IdCia
INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo
INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca INNER JOIN UndMed AS UD ON P.IdUnd=UD.IdUnd
INNER JOIN Bodegas AS B ON D.IdBodega=B.IdBodega INNER JOIN Companias AS CN ON PS.IdCiaSal=CN.IdCia
LEFT JOIN (SELECT TipDoc,Salida,IdCia,Fecha,TipOrd,NumOrden,IdCiaOrd,Modalidad,TipCom,Comprobante,IdCiaCom,Anulado,Observacion,IdEstado FROM Trn_Salidas WHERE TipDoc='SAI'
UNION ALL SELECT TipDev,Devolucion,IdCia,Fecha,TipOrd,NumOrden,IdCiaOrd,Modalidad,TipCom,Comprobante,IdCiaCom,1,Observacion,IdEstado
FROM Trn_DevSal WHERE TipDev='DSI') AS SA ON PS.TipSal=SA.TipDoc AND PS.NumSalida=SA.Salida AND PS.IdCiaSal=SA.IdCia
WHERE PS.TipDoc=@pmTipDoc AND PS.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND PS.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenTallasFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrdenTallasFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
AS
SELECT TipDoc,NumOrden,IdCia,Item,ItemOrden,NumTalla,Cantidad,Terminado,Defectuoso,Rechazado,CantEntrada
FROM Trn_ProdOrdenTallas
WHERE TipDoc=@pmTipDoc AND NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin
AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdOrdenTallasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdOrdenTallasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
SELECT TL.TipDoc,TL.NumOrden,TL.IdCia,O.Fecha,TL.Item,TL.ItemOrden,TL.NumTalla,TL.Cantidad,TL.Terminado,TL.Defectuoso,TL.Rechazado,TL.CantEntrada
FROM Trn_ProdOrdenTallas AS TL INNER JOIN Trn_ProdOrden AS O ON TL.TipDoc=O.TipDoc AND TL.NumOrden=O.NumOrden AND TL.IdCia=O.IdCia
WHERE TL.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (TL.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPedidoInsuFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdPedidoInsuFmt] @pmTipDoc VARCHAR(3),@pmPedidoIni INT,@pmPedidoFin INT,@pmIdCia CHAR(2)
AS
SELECT D.TipDoc,D.Pedido,D.IdCia,D.Item,D.ItemDet,D.IdProducto,P.DescripProd,D.IdInsumo,IM.DescripProd AS DescInsumo
,D.IdTipProc,TP.TipoProceso,TP.IndOrden,D.Cantidad,D.CantPed,D.CantAprob,IM.IdSubgrupo AS CdSubgpo,Subgrupo
FROM Trn_ProdPedidoInsu AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
INNER JOIN ProdMcias AS IM ON D.IdInsumo=IM.IdProducto INNER JOIN SubGrupos AS S ON IM.IdSubgrupo=S.IdSubgrupo
INNER JOIN TiposProceso AS TP ON D.IdTipProc=TP.IdTipProc
WHERE D.TipDoc=@pmTipDoc AND D.Pedido BETWEEN @pmPedidoIni AND @pmPedidoFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdPrecCom] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmNumero INT
 AS 
 SELECT IdProducto,IdCia,Numero,TipoTarif,nMes,nAnno,Tarifa,NitProv,Inactivo
 FROM ProdPrecCom
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecComLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdPrecComLta] @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT T.IdProducto AS CdProducto,DescripProd,T.IdCia AS CdCia,Compania,Numero,TipoTarif,nMes,nAnno
,Tarifa,NitProv,RazonSocial,T.Inactivo AS Inactvo
 FROM ProdPrecCom AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto INNER JOIN Companias AS CI ON T.IdCia=CI.IdCia
 LEFT JOIN Terceros AS PV ON T.NitProv=PV.IdTercero
 WHERE T.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND T.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecCrudoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdPrecCrudoLta] @pmTipoTarif VARCHAR(3)
AS 
SELECT T.TipoTarif,T.Numero,T.IdCia,Compania,T.IdProducto,P.DescripProd,T.IdTercero,N.RazonSocial,T.CodCiudad,Localidad
,T.Duracion,T.FecInicio,T.FecFinal,T.Tarifa,T.IdMoneda,M.Mneda AS Moneda,T.UndMed,UM.Unidad,T.Inactivo
FROM ProdPrecCrudo AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
INNER JOIN adm_monedas AS M ON T.IdMoneda=M.IdMneda INNER JOIN Companias AS C ON T.IdCia=C.IdCia
INNER JOIN Terceros AS N ON T.IdTercero=N.IdTercero LEFT JOIN Sys_Um AS UM ON T.UndMed=UM.UndMed
LEFT JOIN Localidades AS L ON T.CodCiudad=L.IdLocal
WHERE TipoTarif=@pmTipoTarif
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdPrecios] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,IdCia,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,IvaInc,CdTarIva,CdMoney1
,CdMoney2,CdMoney3,CdMoney4,CdMoney5,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5
,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5,IdUnd,IdBodega
 FROM ProdPrecios
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPrecios_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdPrecios_Cr]   @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmTanques BIT=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT PP.IdProducto AS CdProducto,DescripProd,DescripAbrv,PP.IdCia AS CdCia,Compania,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5
,PP.CdTarIva AS CodTarifIva,TI.Tarifa AS TarifIva,TI.Simbolo AS SimbTarfIva,PP.IvaInc AS IvaIncluido,BaseMargen
,CdMargen1,MG1.Tarifa AS TarifMarg1,CdMargen2,MG2.Tarifa AS TarifMarg2,CdMargen3,MG3.Tarifa AS TarifMarg3
,CdMargen4,MG4.Tarifa AS TarifMarg4,CdMargen5,MG5.Tarifa AS TarifMarg5
,CdDcto1,DC1.Tarifa AS TarifDcto1,CdDcto2,DC2.Tarifa AS TarifDcto2,CdDcto3,DC3.Tarifa AS TarifDcto3
,CdDcto4,DC4.Tarifa AS TarifDcto4,CdDcto5,DC5.Tarifa AS TarifDcto5
,P.CdTarIca AS CdTarfIca,TIC.Tarifa AS TarifIca,P.CdTarRet AS CdTarfRet,TRF.Tarifa AS TarifRet
,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5,CostoAnt AS CiaCostoAnt,CostoUlt AS CiaCostoUlt,CostoPmd AS CiaCostoPmd
,VrCostAnt,VrCosto,VrCostPmd,ExtciaMin,ExtciaMax,ExtciaAct,CiaExistencia
,PP.IdUnd AS CdUnidad,Unidad,PP.IdBodega AS CdBodega,Bodega,Factor1,Factor2,Factor3,Factor4,Factor5
,CodBarras,Referencia,TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo,P.IdMarca AS CdMarc,Marca,Color,Tamano
,MedAlto,MedAncho,MedLargo,MedVolm,P.UndMed AS UndVolm,P.IdProv AS IdProvee,RazonSocial,CdDctCom,DCC.Tarifa AS TarifDctComp
,LtPreDef,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,FecUltcom,FecUltVta,DescripLong,P.Cmntarios AS Prod_Observ,P.FechaAdd AS FecAdd
 FROM ProdPrecios  AS PP INNER JOIN  ProdMcias AS P ON PP.IdProducto=P.IdProducto
 INNER JOIN Companias AS C ON PP.IdCia=C.IdCia  INNER JOIN UndMed AS UM ON PP.IdUnd=UM.IdUnd
 INNER JOIN Bodegas AS B ON PP.IdBodega=B.IdBodega
 INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN Terceros AS TP ON P.IdProv=TP.IdTercero
 LEFT JOIN Tablapor AS TI ON PP.CdTarIva=TI.IdTarifa
 LEFT JOIN  Tablapor AS MG1 ON PP.CdMargen1=MG1.IdTarifa  LEFT JOIN  Tablapor AS MG2 ON PP.CdMargen2=MG2.IdTarifa
 LEFT JOIN  Tablapor AS MG3 ON PP.CdMargen3=MG3.IdTarifa  LEFT JOIN  Tablapor AS MG4 ON PP.CdMargen4=MG4.IdTarifa
 LEFT JOIN  Tablapor AS MG5 ON PP.CdMargen5=MG5.IdTarifa LEFT JOIN  Tablapor AS DCC ON P.CdDctCom=DCC.IdTarifa
 LEFT JOIN  Tablapor AS DC1 ON PP.CdDcto1=DC1.IdTarifa LEFT JOIN  Tablapor AS DC2 ON PP.CdDcto2=DC2.IdTarifa
 LEFT JOIN  Tablapor AS DC3 ON PP.CdDcto3=DC3.IdTarifa LEFT JOIN  Tablapor AS DC4 ON PP.CdDcto4=DC4.IdTarifa
 LEFT JOIN  Tablapor AS DC5 ON PP.CdDcto5=DC5.IdTarifa 
 LEFT JOIN  Tablapor AS TIC ON P.CdTarIca=TIC.IdTarifa LEFT JOIN  Tablapor AS TRF ON P.CdTarRet=TRF.IdTarifa
 LEFT JOIN ProdCostos AS CP ON  PP.IdProducto=CP.IdProducto AND PP.IdCia=CP.IdCia
 LEFT JOIN (SELECT  IdProducto AS SalProducto,IdCia AS SalCdCia,SUM(SaldoActual) AS CiaExistencia FROM ProdSaldos
 WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')  GROUP BY IdProducto,IdCia)  AS SC ON PP.IdProducto=SC.SalProducto AND PP.IdCia=SC.SalCdCia
 WHERE P.Inactivo=0 AND  TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND P.IdMarca LIKE ISNULL(@pmIdMarca,'%') 
 AND (Tanques=ISNULL(@pmTanques,0) or  Tanques=ISNULL(@pmTanques,1))
 AND PP.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY DescripProd,PP.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPreciosCia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdPreciosCia] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)=Null
 AS 
 SELECT IdProducto,IdCia,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5,IvaInc,CdTarIva,CdMoney1
,CdMoney2,CdMoney3,CdMoney4,CdMoney5,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5
,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5,IdUnd,IdBodega,Tarifa
 FROM ProdPrecios AS PP  LEFT JOIN Tablapor AS TI ON PP.CdTarIva=TI.IdTarifa
 WHERE IdProducto=@pmIdProducto AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdPreciosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdPreciosLta] @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT PP.IdProducto AS CdProducto,DescripProd,PP.IdCia AS CdCia,Compania,VrPrecio1,VrPrecio2,VrPrecio3,VrPrecio4,VrPrecio5
,PP.IvaInc AS IvaIncluido,CdTarIva,Tarifa,PP.IdUnd AS CdUnidad,Unidad,PP.IdBodega AS CdBodega,Bodega,CdMoney1,CdMoney2,CdMoney3,CdMoney4,CdMoney5
,CdMargen1,CdMargen2,CdMargen3,CdMargen4,CdMargen5,BaseMargen,CdDcto1,CdDcto2,CdDcto3,CdDcto4,CdDcto5
 FROM ProdPrecios  AS PP INNER JOIN  ProdMcias AS P ON PP.IdProducto=P.IdProducto
 INNER JOIN Companias AS C ON PP.IdCia=C.IdCia  INNER JOIN UndMed AS UM ON PP.IdUnd=UM.IdUnd
 INNER JOIN Bodegas AS B ON PP.IdBodega=B.IdBodega
 LEFT JOIN Tablapor AS TI ON PP.CdTarIva=TI.IdTarifa
 WHERE PP.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND PP.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY DescripProd,PP.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProcesosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdProcesosLta] 
AS
SELECT PS.IdProducto AS CodProducto,P.DescripProd,PS.Item,PS.IdTipProc,TipoProceso,PC.Descripcion AS DescProceso,PC.IndOrden
,PS.CostoEst,PS.UltCosto,PS.ProcFinal,PS.CostoMP,PS.CDI_Adic,PS.CodTarifCDI,TF.Tarifa,PS.Id,PC.Inactivo AS ProcInactivo
,P.CodBarras,P.Referencia,P.TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca,Marca,P.Color,P.Tamano,P.IdUnd,UM.Unidad AS UndadMed,P.Tallaje,P.Seriales,P.Lotes,P.Combo,P.Inactivo AS ProdInactivo,P.DescripLong
FROM ProdProcesos AS PS INNER JOIN TiposProceso AS PC ON PS.IdTipProc=PC.IdTipProc
INNER JOIN ProdMcias AS P ON PS.IdProducto=P.IdProducto
INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd LEFT JOIN Tablapor AS TF ON PS.CodTarifCDI=TF.IdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProvee]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdProvee] @pmIdProducto VARCHAR(16),@pmIdProv VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,IdProv,IdCia,Fecha,DiasGar,CdDct,VrCostCom,VrCostPmd,RefProv,Dcmento
 FROM ProdProvee
 WHERE IdProducto=@pmIdProducto AND IdProv=@pmIdProv AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProvee_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdProvee_Cr]  @pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmIdGrupoPrv VARCHAR(4)=Null,@pmInactivoPrv BIT=Null
AS
 SELECT PV.IdProducto AS CodProducto,DescripProd,PV.IdProv AS IdProvee,RazonSocial,PV.IdCia AS CdCia,Compania,Fecha,DiasGar
,PV.CdDct AS CodDct,TD.Tarifa AS TarifDcto,VrCostCom,PV.VrCostPmd AS VrCostoProm,RefProv,Dcmento
--datos del producto
,DescripAbrv,Referencia,TipoRef,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo,P.IdMarca AS CdMarc,Marca,Color,Tamano,P.IdUnd AS CdUnd,UM.Unidad AS UndadMed
,IdTarIva,TI.Tarifa AS TarifaIva,IvaInc,LtPreDef,Precio1,Precio2,Precio3,Precio4,Precio5,ExtciaMin,ExtciaMax,ExtciaAct,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,FecUltcom,FecUltVta
,DescripLong,P.IdEstado AS CdEstdo,Estado,P.Inactivo AS Inactvo
--datos del proveedor
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,Telefono,Fax,TP.IdGrupo AS CdGruClie,GrupoClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,TP.Inactivo AS Prov_Inactivo
 FROM ProdProvee AS PV INNER JOIN ProdMcias AS P ON PV.IdProducto=P.IdProducto
 INNER JOIN Terceros AS T ON PV.IdProv=T.IdTercero
 INNER JOIN Companias AS C ON PV.IdCia=C.IdCia
 INNER JOIN TercProvee AS TP ON PV.IdProv=TP.IdProv
 INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal
 INNER JOIN GruposCli AS GC ON TP.IdGrupo=GC.IdGrupo
 INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo 
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa INNER JOIN EstadoPro AS EP ON P.IdEstado=EP.IdEstado
 LEFT JOIN Tablapor AS TD ON PV.CdDct=TD.IdTarifa
 WHERE TipoRef LIKE ISNULL(@pmTipoRef,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%') AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND P.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')  AND P.IdMarca LIKE ISNULL(@pmIdMarca,'%')
 AND PV.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND PV.IdProv LIKE ISNULL(@pmIdProv,'%')
 AND PV.IdCia LIKE ISNULL(@pmIdCia,'%%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (P.Inactivo=ISNULL(@pmInactivo,0) or  P.Inactivo=ISNULL(@pmInactivo,1))
 AND TP.IdGrupo LIKE ISNULL(@pmIdGrupoPrv,'%')
 AND (TP.Inactivo=ISNULL(@pmInactivoPrv,0) or  TP.Inactivo=ISNULL(@pmInactivoPrv,1))
 ORDER BY DescripProd,RazonSocial,PV.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdProveeLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdProveeLta] @pmIdProducto VARCHAR(16)=Null,@pmIdProv VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT PV.IdProducto AS CodProd,DescripProd,PV.IdProv AS IdProvee,RazonSocial,PV.IdCia AS CdCia,Compania,Fecha,DiasGar
,CdDct,VrCostCom,PV.VrCostPmd AS VrCostoProm,RefProv,Dcmento
 FROM ProdProvee AS PV INNER JOIN ProdMcias AS P ON PV.IdProducto=P.IdProducto
 INNER JOIN Terceros AS T ON PV.IdProv=T.IdTercero
 INNER JOIN Companias AS C ON PV.IdCia=C.IdCia
 WHERE P.Inactivo=0 AND PV.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND PV.IdProv LIKE ISNULL(@pmIdProv,'%')
  AND PV.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY DescripProd,RazonSocial,PV.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldos] @pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,IdBodega,IdCia,SaldoActual
 FROM ProdSaldos
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 ORDER BY IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldos_Cr] @pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdCia CHAR(2)=Null,@pmTipoRef VARCHAR(10)=Null
 AS 
 SELECT S.IdProducto AS CdProducto,DescripProd,S.IdBodega AS CdBodega,Bodega,S.IdCia AS CdCia,Compania,SaldoActual
,DescripAbrv,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
,P.IdUnd AS CdUnid,Unidad,ExtciaMin,ExtciaMax,CostoUlt,CostoPmd,Tanques,P.Inactivo AS ProInactivo
 FROM ProdSaldos  AS S INNER JOIN ProdMcias  AS P ON S.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON S.IdBodega=B.IdBodega  INNER JOIN Companias AS CI ON S.IdCia=CI.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 LEFT JOIN ProdCostos AS PC ON S.IdProducto=PC.IdProducto AND S.IdCia=PC.IdCia
 WHERE S.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND S.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND S.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND TipoRef LIKE ISNULL(@pmTipoRef,'%')
 ORDER BY DescripProd,S.IdBodega,S.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosInv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldosInv] @pmIdCia CHAR(2)=Null
 AS 
 SELECT S.IdProducto AS CdProducto,DescripProd,S.IdBodega AS CdBodega,IdCia,SaldoActual
 FROM ProdSaldos AS S INNER JOIN ProdMcias AS P ON S.IdProducto=P.IdProducto
 WHERE SaldoActual<>0 AND TipoRef<>'SERVICIO' AND Tanques=0 
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY S.IdProducto,S.IdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldosLta] @pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdCia CHAR(2)=Null,@pmTipoRef VARCHAR(10)=Null,@pmIdLinea VARCHAR(8)=Null,@pmIdGrupo VARCHAR(8)=Null,@pmIdSubgrupo VARCHAR(8)=Null
,@pmIdMarca VARCHAR(4)=Null,@pmTanques BIT=Null
 AS 
 SELECT S.IdProducto AS CdProducto,DescripProd,S.IdBodega AS CdBodega,Bodega,S.IdCia AS CdCia,Compania,SaldoActual
,DescripAbrv,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
,P.IdUnd AS CdUnid,Unidad,ExtciaMin,ExtciaMax,CostoUlt,CostoPmd,Tanques,P.Inactivo AS ProInactivo
 FROM ProdSaldos  AS S INNER JOIN ProdMcias  AS P ON S.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON S.IdBodega=B.IdBodega  INNER JOIN Companias AS CI ON S.IdCia=CI.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 LEFT JOIN ProdCostos AS PC ON S.IdProducto=PC.IdProducto AND S.IdCia=PC.IdCia
 WHERE S.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND S.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND S.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND TipoRef LIKE ISNULL(@pmTipoRef,'%')
 ORDER BY DescripProd,S.IdBodega,S.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosP]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldosP] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 IF @pmIdCia  IS NULL
  SELECT  SUM(SaldoActual) AS SSALDO  FROM ProdSaldos  WHERE IdProducto=@pmIdProducto
 ELSE
  SELECT  SUM(SaldoActual) AS SSALDO  FROM ProdSaldos 
  WHERE IdProducto=@pmIdProducto  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldosTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldosTot] @pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto, SUM(SaldoActual) AS SSALDO
 FROM ProdSaldos
 WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldoUbc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldoUbc] @pmIdProducto VARCHAR(16),@pmIdUbic VARCHAR(10),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,IdUbic,IdCia,SaldoActual
 FROM ProdSaldoUbc
 WHERE IdProducto=@pmIdProducto AND IdUbic=@pmIdUbic AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryProdSaldoUbcTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdSaldoUbcTot] @pmIdProducto VARCHAR(16),@pmIdUbic VARCHAR(10),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,SUM(SaldoActual) AS SSALDO
 FROM ProdSaldoUbc
 WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdUbic LIKE ISNULL(@pmIdUbic,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY IdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdTarf] @pmTipo VARCHAR(3),@pmNumero INT
 AS 
 SELECT Tipo,Numero,FecInicial,FecFinal,CdCia,CdLinea,CdGrupo,CdSubgrupo,CdMarca,CdProducto,Tarifa,SimbTfa,LtaPre,CdTarifa,CdClie,CdAgencia
,CdVend,CdCiudad,CdZona,CdSzona,CdGruCli,OtrosCrit,Anulado,CodBod,TimeSys,FecUpdate,IdUsuario
 FROM Trn_ProdTarf
 WHERE Tipo=@pmTipo AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarfFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryProdTarfFec] @pmTipo VARCHAR(3),@pmFecha SMALLDATETIME,@pmCdProducto VARCHAR(16)
,@pmCdSubgrupo VARCHAR(8)=Null,@pmCdCia CHAR(2)=Null,@pmCdClie  VARCHAR(16)=Null,@pmCdVend VARCHAR(16)=Null
,@pmLtaPre CHAR(1)
 AS 
 SELECT Tipo,Numero,FecInicial,FecFinal,CdCia,CdLinea,CdGrupo,CdSubgrupo,CdMarca,CdProducto,Tarifa,SimbTfa,LtaPre,CdTarifa,CdClie
,CdAgencia,CdVend,CdCiudad,CdZona,CdSzona,CdGruCli,OtrosCrit,ISNULL(CodBod,'') AS CodBodega,Anulado,TimeSys,FecUpdate,IdUsuario
 FROM Trn_ProdTarf
 WHERE Tipo=@pmTipo  AND Anulado=0 AND Tarifa>0 AND @pmFecha BETWEEN FecInicial AND FecFinal
 AND CdProducto IN (@pmCdProducto,'0') AND CdSubgrupo IN (@pmCdSubgrupo,'0')
 AND CdCia IN (@pmCdCia,'00') AND CdClie IN (@pmCdClie,'0') AND CdVend IN (@pmCdVend,'0')
 AND LtaPre IN (@pmLtaPre,'0')
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarfItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdTarfItm] @pmTipo VARCHAR(3)
 AS 
 SELECT MAX(Numero) AS MXNUM
 FROM Trn_ProdTarf
 WHERE Tipo=@pmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQryProdTarfLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProdTarfLta] @pmTipo VARCHAR(3)=Null,@pmCdSubgrupo VARCHAR(8)=Null,@pmCdProducto VARCHAR(16)=Null
,@pmCdClie VARCHAR(16)=Null,@pmFecIni SMALLDATETIME=Null,@pmFecFin SMALLDATETIME=Null
 AS 
 SELECT Tipo,Numero,FecInicial,FecFinal,Tarifa,SimbTfa,CdTarifa,CdSubgrupo,Subgrupo,CdProducto,DescripProd,CdClie,T.RazonSocial AS NombreClie,CdAgencia,Agencia
,TR.LtaPre,CdCia,Compania,CdLinea,Linea,CdGrupo,Grupo,CdMarca,Marca,CdVend,V.RazonSocial AS NombreVend,CdCiudad,Localidad,CdZona,Zona,CdSzona,Subzona
,CdGruCli,GrupoClie,OtrosCrit,CodBod,Bodega,TimeSys,FecUpdate,TR.IdUsuario AS IdUsuari,Usuario
 FROM Trn_ProdTarf AS TR INNER JOIN adm_Usuarios AS U ON TR.IdUsuario=U.IdUsuario
 LEFT JOIN SubGrupos AS S ON TR.CdSubgrupo=S.IdSubgrupo
 LEFT JOIN ProdMcias AS P ON TR.CdProducto=P.IdProducto
 LEFT JOIN Terceros AS T ON TR.CdClie=T.IdTercero
 LEFT JOIN Terceros AS V ON TR.CdVend=V.IdTercero
 LEFT JOIN Companias AS C ON TR.CdCia=C.IdCia
 LEFT JOIN Lineas AS L ON TR.CdLinea=L.IdLinea
 LEFT JOIN Grupos AS G ON TR.CdGrupo=G.IdGrupo
 LEFT JOIN Marcas AS M ON TR.CdMarca=M.IdMarca
 LEFT JOIN  Agencias AS A ON TR.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LC ON TR.CdCiudad=LC.IdLocal
 LEFT JOIN Zonas AS Z ON TR.CdZona=Z.IdZona
 LEFT JOIN Subzonas AS SZ ON TR.CdSzona=SZ.IdSzona
 LEFT JOIN GruposCli AS GC ON TR.CdGruCli=GC.IdGrupo
 LEFT JOIN Bodegas AS B ON TR.CodBod=B.IdBodega
 WHERE Anulado=0 AND Tipo LIKE ISNULL(@pmTipo,'%') AND CdSubgrupo LIKE ISNULL(@pmCdSubgrupo,'%')
 AND CdProducto LIKE ISNULL(@pmCdProducto,'%') AND CdClie LIKE ISNULL(@pmCdClie,'%')
 AND (FecInicial>=ISNULL(@pmFecIni,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY Tipo,FecInicial,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryProfesiones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryProfesiones] @pmIdProf VARCHAR(4)
 AS 
 IF @pmIdProf IS NULL
  SELECT IdProf,Profesion
  FROM Profesiones
  WHERE Inactivo=0
  ORDER  BY Profesion
 ELSE
  SELECT IdProf,Profesion,Inactivo
  FROM Profesiones
  WHERE IdProf=@pmIdProf
GO
/****** Object:  StoredProcedure [dbo].[paQryPuc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuc] @pmIdCuenta VARCHAR(16)
 AS 
 IF @pmIdCuenta IS NULL
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,FechaAdd,FechaUpdate,IdUsuario
,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor,IdCueNiif
  FROM Puc ORDER BY IdCuenta
 ELSE
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,FechaAdd,FechaUpdate,IdUsuario
,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor,IdCueNiif
  FROM Puc
  WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQryPucAju]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPucAju] @pmIdCuenta VARCHAR(16)=Null,@pmCueIni VARCHAR(16)=Null
,@pmCueFin VARCHAR(16)=Null
AS
 IF @pmCueIni IS NULL --NO RANGOS
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
 ,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,Afijos,IdCueNiif
  FROM  Puc
  WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta like ISNULL(@pmIdCuenta,'%')
  ORDER BY IdCuenta
 ELSE
  BEGIN
  IF @pmCueIni='LIKE'
   SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
   ,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,Afijos,IdCueNiif
   FROM  Puc
   WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta LIKE @pmIdCuenta
   ORDER BY IdCuenta
  ELSE
   SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,Porcntaje,Naturaleza
   ,Ajustable,CuentaAjuDeb,CuentaAjuCre,FmtDian,ConDian,RenDec,Cheques,Referncias,CdTipDoc,Afijos,IdCueNiif
   FROM  Puc
   WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta BETWEEN @pmCueIni AND @pmCueFin
   ORDER BY IdCuenta
 END
GO
/****** Object:  StoredProcedure [dbo].[paQryPucLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPucLta] 
 AS 
 SELECT P.IdCuenta,P.NomCuenta,P.Mayor,P.Movimiento,P.Tercero,P.Vehiculo,P.Agencia,P.CentroCosto,P.SubCentro,P.Vencimiento,P.BaseGravable,P.Porcntaje
,P.Naturaleza,P.Ajustable,P.CuentaAjuDeb,P.CuentaAjuCre,P.FmtDian,P.ConDian,P.RenDec,P.Cheques,P.Referncias,P.CdTipDoc,P.FechaAdd,P.FechaUpdate,P.IdUsuario
,P.Inactivo,P.Afijos,P.ListarConc,P.ReqAutorizac,P.AntProveedor,P.IdCueNiif,PN.NomCuenta AS NiifNombre,U.Usuario
 FROM Puc AS P LEFT JOIN PucNiif AS PN ON P.IdCueNiif=PN.IdCuenta
 LEFT JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryPucNiif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPucNiif] @pmIdCuenta VARCHAR(16)
 AS 
 SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred,Naturaleza,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referencias,CdTipDoc,FechaCrea,FechaAct,IdUsuario,Inactivo,Afijos,ListarConc,ReqAutorizac,AntProveedor
 FROM PucNiif
 WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQryPucNiifAju]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPucNiifAju] @pmIdCuenta VARCHAR(16)=Null,@pmCueIni VARCHAR(16)=Null
,@pmCueFin VARCHAR(16)=Null
AS
 IF @pmCueIni IS NULL --NO RANGOS
  SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred AS Porcntaje,Naturaleza
 ,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referencias AS Referncias,CdTipDoc,Afijos
  FROM  PucNiif
  WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta like ISNULL(@pmIdCuenta,'%')
  ORDER BY IdCuenta
 ELSE
  BEGIN
  IF @pmCueIni='LIKE'
   SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred AS Porcntaje,Naturaleza
   ,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referencias AS Referncias,CdTipDoc,Afijos
   FROM PucNiif
   WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta LIKE @pmIdCuenta
   ORDER BY IdCuenta
  ELSE
   SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,Vehiculo,Agencia,CentroCosto,SubCentro,Vencimiento,BaseGravable,TarifaPred AS Porcntaje,Naturaleza
   ,Ajustable,CuentaAjuDeb,CuentaAjuCre,Cheques,Referencias AS Referncias,CdTipDoc,Afijos
   FROM PucNiif
   WHERE Movimiento<>0 AND Ajustable<>0 AND  IdCuenta BETWEEN @pmCueIni AND @pmCueFin
   ORDER BY IdCuenta
 END
GO
/****** Object:  StoredProcedure [dbo].[paQryPucSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
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
/****** Object:  StoredProcedure [dbo].[paQryPuestos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPuestos] @pmIdPto VARCHAR(4)
 AS 
 SELECT IdPto,PtoControl,TagPuesto,IdLocal,Ubicacion,Contacto,Telefono,TelMovil,Referencia,Inactivo
 FROM Puestos
 WHERE IdPto=@pmIdPto
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuestosDso] @pmIdLocal VARCHAR(8)=Null
 AS 
 SELECT IdPto,PtoControl+' '+IdPto+' ('+Localidad+' '+Departamento+')' AS DsPto
 FROM Puestos AS P INNER JOIN Localidades AS L ON P.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE P.Inactivo=0 AND P.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 ORDER BY  PtoControl
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPuestosLta] @pmIdLocal VARCHAR(8)=Null
 AS 
 SELECT IdPto,PtoControl,P.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDpto,Departamento,Ubicacion
,Contacto,Telefono,TelMovil,Referencia,TagPuesto
 FROM Puestos AS P INNER JOIN Localidades AS L ON P.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE P.Inactivo=0 AND P.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 ORDER BY  PtoControl
GO
/****** Object:  StoredProcedure [dbo].[paQryPuestosTag]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPuestosTag] @pmTagPuesto VARCHAR(50)
 AS 
 SELECT IdPto,PtoControl,TagPuesto,IdLocal,Ubicacion,Contacto,Telefono,TelMovil,Referencia,Inactivo
 FROM Puestos
 WHERE TagPuesto=@pmTagPuesto
 ORDER BY IdPto
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntBases]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntBases] @pmIdProgrma INT,@pmCdSubgrupo VARCHAR(8),@pmCdProducto VARCHAR(16)
 AS 
 SELECT IdProgrma,CdSubgrupo,CdProducto,Puntos,Monto
 FROM PuntBases
 WHERE IdProgrma=@pmIdProgrma AND CdSubgrupo=@pmCdSubgrupo AND CdProducto=@pmCdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntBasesDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntBasesDet] @pmIdProgrma INT
 AS 
 SELECT IdProgrma,CdSubgrupo,CdProducto,Puntos,Monto
 FROM PuntBases
 WHERE IdProgrma=@pmIdProgrma AND (CdSubgrupo<>'0'  OR  CdProducto<>'0')
 ORDER BY CdSubgrupo,CdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntBasesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntBasesLta] @pmIdProgrma INT,@pmCdSubgrupo VARCHAR(8)=Null
 AS 
 SELECT CdSubgrupo,Subgrupo,CdProducto,DescripProd,Puntos,Monto,IdProgrma
 FROM PuntBases AS B LEFT JOIN SubGrupos AS S ON B.CdProducto=S.IdSubgrupo
 LEFT JOIN ProdMcias AS P ON B.CdProducto=P.IdProducto
 WHERE  (IdProgrma>=ISNULL(@pmIdProgrma,0)  AND IdProgrma<=ISNULL(@pmIdProgrma,2147483647))
 AND CdSubgrupo LIKE ISNULL(@pmCdSubgrupo,'%')
 ORDER BY IdProgrma,CdSubgrupo,CdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntFormas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntFormas] @pmIdProgrma INT,@pmIdForma VARCHAR(4)
 AS 
 SELECT IdProgrma,IdForma,Puntos
 FROM PuntFormas
 WHERE IdProgrma=@pmIdProgrma AND IdForma LIKE ISNULL(@pmIdForma,'%')
 ORDER BY IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntFormasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntFormasLta] @pmIdProgrma INT
 AS 
 SELECT P.IdForma AS CdForma,FormaPago,Puntos,IdProgrma
 FROM PuntFormas AS P INNER JOIN Formaspago AS F ON P.IdForma=F.IdForma
 WHERE (IdProgrma>=ISNULL(@pmIdProgrma,0)  AND IdProgrma<=ISNULL(@pmIdProgrma,2147483647))
 ORDER BY IdProgrma,P.IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPuntos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Fecha,IdCliente,IdAgencia,VrBase,PuntFactura,PuntExtra,PuntRedim,IdProgrma,NumTarjeta,Detalles,Referncia
 FROM Trn_Puntos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntos_Cr]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdProgrma INT=Null
 AS 
 SELECT  M.IdProgrma AS NumPrograma,M.NumTarjeta  AS NTarjeta,M.IdCliente AS NitCliente,CL.RazonSocial AS NomCliente,M.IdAgencia AS CdAgencia,Agencia
,TipDoc,TipoDoc,Documento,M.IdCia AS CdCia,Compania,Item,M.Fecha AS FechaMov,VrBase,PuntFactura,PuntExtra,M.PuntRedim AS Punt_Redim,Detalles,Referncia
--datos de tarjeta
,T.IdClie AS TarjNit,CLT.RazonSocial AS TarjNomCliente,T.Fecha AS TarjFecha,TotalPuntos,T.PuntRedim AS TotalRedim,FecUltCompra,T.Inactivo AS TarjInactivo
--datos de programa
,FecInicial,FecFinal,MesesInact,MesesVcmto,P.Observacion AS Observ,P.Anulado AS ProgAnulado,P.TimeSys AS FecCreacion,P.IdUsuario AS CdUsuari,Usuario
--datos del cliente
,CL.TipoId AS CliTipoId,CL.Dv AS CliDV,CL.NomCial AS CliNomCial,CL.SiglaRaz CliSigalRaz,CL.Direccion AS CliDireccion,CL.Telefono AS CliTelefono
,CL.IdLocal AS CliCodLocal,Localidad,L.IdDep AS CdDep,Departamento,CL.Inactivo AS TercInactivo,CLI.IdEstado AS CliCdEstado,CLI.Inactivo AS CliInactivo
 FROM Trn_Puntos AS M INNER JOIN  Terceros AS CL ON M.IdCliente=CL.IdTercero  INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia
 INNER JOIN Localidades AS L ON CL.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Agencias AS  A ON M.IdAgencia=A.IdAgencia LEFT JOIN TercCliente AS CLI ON M.IdCliente=CLI.IdClie
 LEFT JOIN PuntTarjetas AS T ON M.NumTarjeta=T.NumTarjeta LEFT JOIN Terceros AS CLT ON T.IdClie=CLT.IdTercero
 LEFT JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc
 LEFT JOIN  PuntProg AS P ON M.IdProgrma=P.IdProgrma LEFT JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE M.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND ( M.IdProgrma>=ISNULL(@pmIdProgrma,0)  AND  M.IdProgrma<=ISNULL(@pmIdProgrma,2147483647))
 ORDER BY M.IdCliente,M.Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntosPrg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntosPrg]  @pmIdProgrma INT
 AS 
 SELECT Fecha,IdCliente,IdAgencia,NumTarjeta
 FROM Trn_Puntos
 WHERE IdProgrma=@pmIdProgrma
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntPremios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntPremios] @pmIdProgrma INT,@pmItem INT
 AS 
 SELECT IdProgrma,Item,Descripcion,IdProducto,Puntos,VrBono
 FROM PuntPremios
 WHERE IdProgrma=@pmIdProgrma
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntPremiosItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntPremiosItm] @pmIdProgrma INT
 AS 
 SELECT MAX(Item) AS MXITM
 FROM PuntPremios
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntPremiosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntPremiosLta] @pmIdProgrma INT
 AS 
 SELECT Item,Descripcion,P.IdProducto AS IdProdcto,DescripProd,Puntos,VrBono,IdProgrma
 FROM PuntPremios AS P INNER JOIN ProdMcias AS PD ON P.IdProducto=PD.IdProducto
 WHERE (IdProgrma>=ISNULL(@pmIdProgrma,0)  AND IdProgrma<=ISNULL(@pmIdProgrma,2147483647))
 ORDER BY IdProgrma,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntProg] @pmIdProgrma INT
 AS 
 SELECT IdProgrma,FecInicial,FecFinal,MesesInact,MesesVcmto,Observacion,Anulado,TimeSys,FecUpdate,IdUsuario
 FROM PuntProg
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProg_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntProg_Cr] @pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmAnulado BIT=Null
,@pmIdProgrmaIni INT=Null,@pmIdProgrmaFin INT=Null
 AS 
 SELECT P.IdProgrma AS Id_Programa,FecInicial,FecFinal,MesesInact,MesesVcmto,Observacion,Anulado,TimeSys,FecUpdate,P.IdUsuario AS IdUsuari,Usuario
,CdSubgrupo,Subgrupo,CdProducto,DescripProd,Puntos,Monto
 FROM PuntProg AS P INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN PuntBases AS PB ON P.IdProgrma=PB.IdProgrma
 LEFT JOIN SubGrupos AS S ON PB.CdProducto=S.IdSubgrupo
 LEFT JOIN ProdMcias AS PR ON PB.CdProducto=PR.IdProducto
  WHERE (FecInicial>=ISNULL(@pmFecInicial,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecFinal,CAST('20781230' AS SMALLDATETIME)))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND P.IdProgrma BETWEEN ISNULL(@pmIdProgrmaIni,0) AND ISNULL(@pmIdProgrmaFin,2147483647)
 ORDER BY P.IdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProgFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntProgFec] @pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME
,@pmIdProgrma INT
 AS 
 SELECT IdProgrma,FecInicial,FecFinal,MesesInact,MesesVcmto,Observacion,TimeSys,FecUpdate,IdUsuario
 FROM PuntProg
 WHERE Anulado=0 AND  FecInicial<@pmFecFinal  AND FecFinal>@pmFecInicial
 AND IdProgrma<>@pmIdProgrma
 ORDER BY IdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProgItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntProgItm] 
 AS 
 SELECT MAX(IdProgrma) AS MXITM  FROM PuntProg
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntProgLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntProgLta] @pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmAnulado BIT=Null
 AS 
 SELECT IdProgrma,FecInicial,FecFinal,MesesInact,MesesVcmto,Observacion,Anulado,TimeSys,FecUpdate,P.IdUsuario AS IdUsuari,Usuario
 FROM PuntProg AS P INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE (FecInicial>=ISNULL(@pmFecInicial,CAST('19100101' AS SMALLDATETIME)) AND FecInicial<=ISNULL(@pmFecFinal,CAST('20781230' AS SMALLDATETIME)))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntTarjetas] @pmNumTarjeta VARCHAR(20)
 AS 
 SELECT NumTarjeta,IdClie,Fecha,TotalPuntos,PuntRedim,FecUltCompra,Inactivo,FechaUpdate,IdUsuario
 FROM PuntTarjetas
 WHERE NumTarjeta=@pmNumTarjeta
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetasCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntTarjetasCli] @pmIdClie VARCHAR(16)
 AS 
 SELECT NumTarjeta,IdClie,Fecha,TotalPuntos,PuntRedim,FecUltCompra
,Inactivo,FechaUpdate,IdUsuario
 FROM PuntTarjetas 
 WHERE IdClie=@pmIdClie AND  Inactivo=0 
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntTarjetasLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdClie VARCHAR(16)=Null,@pmInactivo BIT=Null
 AS 
 SELECT NumTarjeta,IdClie,RazonSocial,Fecha,TotalPuntos,PuntRedim,FecUltCompra,P.Inactivo AS Inactiv
,P.FechaUpdate AS FecUpdate,P.IdUsuario AS IdUsuari,Usuario
,TipoId,Dv,NomCial,SiglaRaz,Direccion,Telefono,T.IdLocal AS CdLocal,Localidad
 FROM PuntTarjetas AS P INNER JOIN Terceros AS T ON P.IdClie=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 WHERE (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND IdClie LIKE ISNULL(@pmIdClie,'%')
 AND (P.Inactivo=ISNULL(@pmInactivo,0) or P.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY NumTarjeta
GO
/****** Object:  StoredProcedure [dbo].[paQryPuntTarjetasNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPuntTarjetasNit] @pmIdClie VARCHAR(16),@pmNumTarjeta VARCHAR(20)
 AS 
 SELECT NumTarjeta,IdClie,Fecha,TotalPuntos,PuntRedim,FecUltCompra,Inactivo
 FROM PuntTarjetas 
 WHERE IdClie=@pmIdClie AND  Inactivo=0  AND NumTarjeta<>@pmNumTarjeta
 ORDER BY Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQryRadicaVales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRadicaVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,nRadica,IdCia,Fecha,FechaVence,IdConcepto,IdTercero,TotalPagos,TotalCobros,Referencia,CxPagar,VrDescuento
,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_RadicaVales
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRadicaVales_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRadicaVales_Cr] @pmTipDoc VARCHAR(3),@pmnRadicaIni INT,@pmnRadicaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS CdTipDoc,TipoDoc,R.nRadica AS NumRadica,R.IdCia AS CdCia,Compania,R.Fecha AS FechaDoc,FechaVence,R.IdConcepto AS CdConcepto ,Concepto,R.IdTercero AS NitTercero
,T.RazonSocial AS NomTercero,TotalPagos,TotalCobros,R.Referencia AS DocReferncia,CxPagar,VrDescuento,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,R.Anulado AS DocAnulado,R.NumDev AS DocNumDev,R.FecDev  AS DocFecDev
,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario,Leyenda
--detalles
,Item,TipoRango,IdRango,NumSerie,NumForma,V.Fecha AS FechaServ,HoraServ,IdCliente,CL.RazonSocial AS NomCliente,V.IdAgencia AS ValAgencia,Agencia,IdCuenta,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera
,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,PlacaVeh,CdConductor,NomConductor,CantPasaj,Usuarios,TipFac,NumFactura,IdCiaFac,FechaFac,V.Anulado AS ValAnulado,V.NumDev AS ValNumAnul,V.FecDev AS ValFechaDev
,V.Observacion AS ValObserv,FechaUp,CdUsuario
--datos del cliente
,CL.TipoId AS CliTipoId,CL.Dv AS CliDv,CL.Codigo AS CliCodigo,CL.NomCial AS CliNomCial,CL.Direccion AS CliDireccion,CL.IdLocal AS CliCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,CL.Telefono AS CliTelefono,CL.Fax AS CliFax,CL.e_mail AS CliEmail,CL.IdSector AS CdSector,SectorEco,CL.IdRegimen AS CdRegimen,Regimen,CL.TipEnte AS CliTipoEnte
 FROM Trn_RadicaVales AS R INNER JOIN Trn_Vales AS V ON R.TipDoc=V.TipDoc AND R.nRadica=V.nRadica AND R.IdCia=V.IdCia
 INNER JOIN  Terceros AS T ON R.IdTercero=T.IdTercero  INNER JOIN  Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN  Terceros AS CL ON V.IdCliente=CL.IdTercero
 INNER JOIN Localidades AS L ON CL.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON CL.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON CL.IdSector=SE.IdSector
 LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON R.TipCom=TC.IdCom
  WHERE R.TipDoc=@pmTipDoc AND R.nRadica BETWEEN @pmnRadicaIni  AND @pmnRadicaFin AND R.IdCia=@pmIdCia
 ORDER BY R.nRadica
GO
/****** Object:  StoredProcedure [dbo].[paQryRadicaValesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRadicaValesLta]  @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmnRadicaIni INT=Null,@pmnRadicaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT nRadica,IdCia,Fecha,FechaVence,R.IdConcepto AS CdConcepto ,Concepto,R.IdTercero AS NitTercero,RazonSocial,TotalPagos,TotalCobros,Referencia,CxPagar
,VrDescuento,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea
,R.IdUsuario AS IdUsuari,Usuario
 FROM Trn_RadicaVales AS R INNER JOIN Terceros AS T ON R.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND nRadica BETWEEN ISNULL(@pmnRadicaIni,0) AND ISNULL(@pmnRadicaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND R.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
ORDER BY IdCia,nRadica
GO
/****** Object:  StoredProcedure [dbo].[paQryRangosPeso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRangosPeso] @pmIdRango VARCHAR(4)
 AS 
 IF @pmIdRango IS NULL
 SELECT IdRango,DescripRango,ValorInicial,ValorFinal
 FROM RangosPeso
 WHERE  Inactivo=0
 ORDER BY IdRango
 ELSE
 SELECT IdRango,DescripRango,ValorInicial,ValorFinal,Inactivo
 FROM RangosPeso
 WHERE IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paQryRecAfavor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecAfavor] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,VrAFavor,VrOtrosDb,VrAbono,IdCliente,IdAgencia,IdVend
 FROM Trn_RecAfavor
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRecAfavorSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecAfavorSal] @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,VrAFavor,VrOtrosDb,VrAbono,IdCliente,IdAgencia,IdVend
 FROM Trn_RecAfavor
 WHERE  IdCliente=@pmIdCliente AND (VrAFavor-VrOtrosDb)>VrAbono AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 ORDER BY Fecha,IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecAfavorTNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecAfavorTNit] @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)=Null
 AS 
 SELECT SUM(VrAFavor) AS STOTAL,SUM(VrOtrosDb) AS STOTODB,SUM(VrAbono) AS STOTABO
 FROM Trn_RecAfavor
 WHERE IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBuses] @pmTipDoc VARCHAR(3), @pmRecibo INT, @pmIdCia CHAR(2)

AS
 SELECT  TipDoc, Recibo, IdCia, Fecha, IdConcepto, IdCliente, IdAgencia, Modalidad, TipCar, Cartulina, IdCiaCar,IdRuta,IdRelevador, IdVehiculo, IdConductor, VehPropio, CentInicial, 
                      CentFinal, NPasajeros, Recorridos,ValorRecibido, ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorOtrosDct, ValorPagMas, ValorNeto,
ValorAplicado, ValorAnticipo, ValorAbono, TotalProducido, TotalGastos, TotalAhorro, TotalOtros, TotalVales, TotalAbono, ValorPasaje, IdVendedor, Comision, 
                      IdTarCom, IdCCosto, IdCta, EnEfectivo, NumCheque, IdBanco, Referencia, BaseIva, BaseRet, BaseOtr, TarifaIva, TarifaRet, TarifaOtr, IdTarIva, 
                      IdTarRet, IdTarOtr,IdClase, TipCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev, Observacion, IdEstado, TimeSys, FecUpdate, IdCiaCrea,IdUsuario
 FROM  Trn_RecBuses
 WHERE TipDoc=@pmTipDoc AND  Recibo=@pmRecibo AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBuses_Cr] @pmTipDoc VARCHAR(3), @pmReciboIni INT,@pmReciboFin INT, @pmIdCia CHAR(2)
AS
 SELECT  R.TipDoc AS IdTipRec,TipoDoc, Recibo,R.IdCia AS CodCia,Compania, R.Fecha AS FechaRec, R.IdConcepto AS IdConcept,Concepto, R.IdCliente AS NitPropietario,NP.RazonSocial AS Propietario, R.IdAgencia, R.Modalidad AS RecModalidad, TipCar, Cartulina, IdCiaCar,R.IdRuta,Ruta,IdRelevador
, R.IdVehiculo AS PlacaVeh, R.IdConductor AS CedConductor,NC.RazonSocial AS Conductor, R.VehPropio AS VehcPropio, R.CentInicial AS CenInicial, R.CentFinal AS CenFinal, NPasajeros, Recorridos,ValorRecibido, ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros
, ValorOtrosDct, ValorPagMas, ValorNeto,ValorAplicado, ValorAnticipo, ValorAbono, TotalProducido, TotalGastos, TotalAhorro, TotalOtros, TotalVales, TotalAbono, ValorPasaje, IdVendedor,R.Comision,IdTarCom, R.IdCCosto AS IdCCost,CCosto,EnEfectivo,R.Referencia AS RefeRecibo, BaseIva
, BaseRet, BaseOtr, TarifaIva, TarifaRet, TarifaOtr, IdTarIva,IdTarRet, IdTarOtr,R.IdClase AS CodClase, ClaseCuenta,R.TipCom AS IdTipoCom,TM.TipoCom AS TipoComprobante, Comprobante, IdCiaCom, Anulado, NumDev, FecDev, R.Observacion AS Observ, R.IdEstado AS IdEstad,ED.Estado AS EstadDoc, R.TimeSys, FecUpdate, IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario,Leyenda
,Item,F.IdForma AS IdForm,FormaPago,VrPagado,VrCambio,EsCaja,FP.NumForma AS NumeroCheque, FP.IdBanco AS IdBanc,Banco,CtaForma,Beneficiario,NitCliente,FecForma,CdCta,NumeroCta,FP.CdLocal AS CodPlaza,PZA.Localidad AS Plaza
, FP.Referncia1 AS RefCheque,Referncia2,VrDenom,Cantidad,TipDenom,FP.Detalle AS DetallePago,TipRef,DocRef,IdCiaRef
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,V.CentInicial AS VehCentInicio,V.CentFinal AS CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  Trn_RecBuses AS R INNER JOIN Sys_TiposDoc  AS TD ON R.TipDoc=TD.IdDoc
 INNER JOIN Trn_Pagos AS FP ON R.TipDoc=FP.TipDoc AND R.Recibo=FP.Documento AND R.IdCia=FP.IdCia
 INNER JOIN Companias  AS CI ON R.IdCia=CI.IdCia  INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado  INNER JOIN adm_Usuarios AS U ON  R.IdUsuario=U.IdUsuario
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS NP ON R.IdCliente=NP.IdTercero
 INNER JOIN Terceros AS NC ON R.IdConductor=NC.IdTercero  INNER JOIN BusClaseCue AS CU ON R.IdClase=CU.IdClase
 INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto  INNER JOIN Bancos AS B ON FP.IdBanco=B.IdBanco
 INNER JOIN Formaspago AS F ON FP.IdForma=F.IdForma 
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON  R.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN CtasCorrientes AS CTA ON FP.CdCta=CTA.IdCta  LEFT JOIN Localidades AS PZA ON FP.CdLocal=PZA.IdLocal
 LEFT JOIN Rutas AS RT ON  R.IdRuta=RT.IdRuta LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom
 WHERE R.TipDoc=@pmTipDoc AND  Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND   R.IdCia=@pmIdCia
 ORDER BY R.IdCia,Recibo,item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses_Crl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBuses_Crl] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME , @pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null, @pmEnEfectivo BIT=Null,@pmAnulado BIT=Null
,@pmIdEstado VARCHAR(4)=Null,@pmIdUsuario VARCHAR(11)=Null,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT Recibo, R.IdCia AS CodCia, R.Fecha AS FecRecibo,TipCar, R.Cartulina AS NumCartulina, IdCiaCar,CL.Fecha AS FecCartulina,NumOrden,FechaRec,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,R.IdRuta AS CodRuta,Ruta
,R.CentInicial AS CentenaIni,R.CentFinal AS CentenaFin,R.NPasajeros AS NPasajers,R.Recorridos AS Recorrdos,R.ValorPasaje AS ValorPasje,TotalProducido,TotalGastos ,TotalVales,TotalGastos+TotalVales AS TtGastos,TotalAhorro,TotalOtros,TotalAbono,ValorTotal,R.ValorOtros AS ValorOtrs
,ValorOtrosDct,ValorPagMas,ValorNeto,ValorAplicado,ValorAnticipo,ValorRecibido,EnEfectivo,NumCheque, R.IdBanco AS CodBanco,Banco,Referencia,TipCom,TipoCom, Comprobante, IdCiaCom, R.Anulado AS Anlado, R.NumDev As Ndevolucion, R.FecDev AS FechDev,R.Observacion AS Observ
,R.IdEstado AS IdEstad, ED.Estado AS EstadDoc,R.TimeSys AS Time_sys, R.FecUpdate AS FechUpdate, R.IdCiaCrea AS CodCiaCrea,R.IdUsuario,Usuario,Compania,R.IdRelevador AS IdRelevadr,NR.RazonSocial AS Relevador,R.IdConcepto AS IdConcep,Concepto,R.IdClase AS IdClaCue,ClaseCuenta,R.VehPropio AS VPropio
,IdCliente,NP.RazonSocial AS Propietario,NumAutoriza
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TA.TipoAdmon AS VehTipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,V.CentInicial AS VehCentInicio,V.CentFinal AS VehCentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
  FROM Trn_RecBuses AS R INNER JOIN Trn_Despachos AS CL ON R.TipCar=CL.TipDoc AND R.Cartulina=CL.Cartulina AND R.IdCiaCar=CL.IdCia
  INNER JOIN Companias  AS CI ON R.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON  R.IdUsuario=U.IdUsuario 
  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo   INNER JOIN Terceros AS NP ON R.IdCliente=NP.IdTercero
  INNER JOIN Terceros AS NC ON R.IdConductor=NC.IdTercero  INNER JOIN BusClaseCue AS CU ON R.IdClase=CU.IdClase
  INNER JOIN Bancos AS B ON R.IdBanco=B.IdBanco  INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
    INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa   LEFT JOIN TercCndtores AS CT ON R.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN Rutas AS RT ON  R.IdRuta=RT.IdRuta LEFT JOIN Terceros AS NR ON R.IdRelevador=NR.IdTercero
  LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom
 WHERE R.TipDoc=@pmTipDoc  AND  R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND  R.Modalidad like ISNULL(@pmModalidad,'%') 
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND R.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 AND  (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  (R.Anulado=ISNULL(@pmAnulado,0) or R.Anulado=ISNULL(@pmAnulado,1))
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND R.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND R.IdConductor LIKE ISNULL(@pmIdConductor,'%')  AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY R.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBuses_Crr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBuses_Crr] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME , @pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null, @pmEnEfectivo BIT=Null,@pmAnulado BIT=Null
,@pmIdEstado VARCHAR(4)=Null,@pmIdUsuario VARCHAR(11)=Null,@pmIdAdmon VARCHAR(4)=Null
AS
 SELECT  Recibo, R.IdCia AS CodCia, Fecha, R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,IdCliente,NP.RazonSocial AS Propietario,ValorRecibido, ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorOtrosDct
, ValorPagMas, TotalAhorro, TotalOtros, ValorNeto,ValorAplicado,ValorAnticipo,R.IdCta AS CodCta,NumeroCta,EnEfectivo, NumCheque, R.IdBanco AS IdBanc,Banco,Referencia,R.IdClase AS IdClasCue,ClaseCuenta,R.Modalidad AS RecModalidad,R.IdConcepto AS IdConcep,Concepto
,TipCom,TipoCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev, R.Observacion AS Observ, R.IdEstado AS IdEstad,ED.Estado AS EstadDoc, TimeSys, FecUpdate, IdCiaCrea,R.IdUsuario,Usuario,Compania,BaseIva, BaseRet, BaseOtr
,TarifaIva, TarifaRet, TarifaOtr, IdTarIva,IdTarRet, IdTarOtr,TipCar, Cartulina, IdCiaCar,R.IdRuta AS CodRuta,Ruta,IdRelevador,NR.RazonSocial AS Relevador,R.CentInicial AS CentenaIni, R.CentFinal AS CentenaFin, NPasajeros, Recorridos,ValorPasaje,TotalProducido
,TotalGastos ,TotalVales,TotalGastos+TotalVales AS TtGastos,TotalAbono,R.VehPropio AS VhPropio
--inf. vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,V.CentInicial AS VehCentInicio,V.CentFinal AS VehCentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
  FROM Trn_RecBuses AS R  INNER JOIN Companias  AS CI ON R.IdCia=CI.IdCia
  INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
  INNER JOIN adm_Usuarios AS U ON  R.IdUsuario=U.IdUsuario
  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo   INNER JOIN Terceros AS NP ON R.IdCliente=NP.IdTercero
  INNER JOIN Terceros AS NC ON R.IdConductor=NC.IdTercero  INNER JOIN BusClaseCue AS CU ON R.IdClase=CU.IdClase
  INNER JOIN Bancos AS B ON R.IdBanco=B.IdBanco   INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON R.IdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN Rutas AS RT ON  R.IdRuta=RT.IdRuta LEFT JOIN CtasCorrientes AS CTA ON R.IdCta=CTA.IdCta LEFT JOIN Terceros AS NR ON R.IdRelevador=NR.IdTercero
  LEFT JOIN TiposCom AS TM ON R.TipCom=TM.IdCom
  WHERE TipDoc=@pmTipDoc AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND R.Modalidad like ISNULL(@pmModalidad,'%') 
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND R.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 AND  (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND  (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND R.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND R.IdConductor LIKE ISNULL(@pmIdConductor,'%')  AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY R.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesAnt] @pmIdVehiculo VARCHAR(10)
AS
 SELECT  TipDoc, Recibo, IdCia, Fecha, IdConcepto, IdCliente, IdAgencia, Modalidad,IdVehiculo, IdConductor, VehPropio,ValorTotal, ValorNeto,ValorAnticipo, ValorAbono
, ValorAnticipo-ValorAbono AS ValorSaldoAnt, IdVendedor, Comision , NumCheque, IdBanco, Referencia,IdClase
 FROM  Trn_RecBuses
 WHERE Anulado=0 AND ValorAnticipo>0 AND ValorAnticipo>ValorAbono AND IdVehiculo=@pmIdVehiculo
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesAntVce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesAntVce] @pmSaldo DECIMAL(14,2),@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
  SELECT IdCliente,R.IdVehiculo AS PlacaVeh,R.IdClase AS CodClase,IdCia,R.IdConductor AS CedConductor,R.VehPropio AS VhPropio,SUM(ValorAnticipo-ValorAbono) AS SaldoAFavor
  FROM Trn_RecBuses AS R  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
  WHERE Anulado=0 AND ValorAnticipo>0 AND (ValorAnticipo-ValorAbono)>@pmSaldo 
  AND  Fecha BETWEEN ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME))
  AND IdCia like ISNULL(@pmIdCia,'%%')
  AND  R.IdVehiculo like ISNULL(@pmIdVehiculo,'%')  AND IdCliente like ISNULL(@pmIdCliente,'%') AND R.IdClase like ISNULL(@pmIdClase,'%') AND IdGrupo like ISNULL(@pmIdGrupo,'%')
  GROUP BY IdCliente,R.IdVehiculo,R.IdClase,IdCia,R.IdConductor,R.VehPropio
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesCli] @pmIdCliente VARCHAR(16)
AS
 SELECT IdCliente,SUM(ValorAnticipo) AS StotAnt,SUM(ValorAbono) AS STotAbo
 FROM  Trn_RecBuses
 WHERE ValorAnticipo>0  AND  IdCliente like ISNULL(@pmIdCliente,'%')
 GROUP BY  IdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesIca]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesIca] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT IdCia,V.IdPropietario AS IdCliente,R.IdVehiculo AS PlacaVeh,NumVeh,V.IdConductor AS CedConductor,SUM(ValorNeto) AS Total_Neto
 FROM  Trn_RecBuses AS R INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  VehPropio=0 AND ValorNeto>0--TipoAfil<>'PROPIO' 
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 GROUP BY  IdCia,V.IdPropietario,R.IdVehiculo,NumVeh,V.IdConductor
 UNION 
 SELECT IdCia,V.IdPropietario AS IdCliente,D.IdVehiculo AS PlacaVeh,NumVeh,V.IdConductor AS CedConductor,SUM(ValorNeto*-1) AS Total_Neto
 FROM     Trn_DevRecBuses AS D  INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  VehPropio=0 AND ValorNeto>0 --TipoAfil<>'PROPIO' 
 AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 GROUP BY  IdCia,V.IdPropietario,D.IdVehiculo,NumVeh,V.IdConductor
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesLiq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesLiq]  @pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmModalidad VARCHAR(10),@pmIdCliente VARCHAR(16)
,@pmIdVehiculo VARCHAR(10)
AS
 SELECT  TipDoc, Recibo, IdCia, Fecha,R.IdConcepto AS IdConcept, Concepto,IdCliente,T.RazonSocial AS Cliente, IdAgencia, Modalidad, TipCar, Cartulina, IdCiaCar,IdRuta,IdRelevador, IdVehiculo, IdConductor,O.RazonSocial AS Conductor,VehPropio, CentInicial, 
                      CentFinal, NPasajeros, Recorridos,ValorRecibido,ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorOtrosDct, ValorPagMas, ValorNeto,
                      ValorAplicado, ValorAnticipo, ValorAbono, TotalProducido, TotalGastos, TotalAhorro, TotalOtros, TotalVales, TotalAbono, ValorPasaje, IdVendedor,V.RazonSocial AS Vendedor, R.Comision AS Comison, 
                      IdTarCom, IdCCosto, IdCta, EnEfectivo, NumCheque,R.IdBanco AS IdBanc,Banco, Referencia, BaseIva, BaseRet, BaseOtr, TarifaIva, TarifaRet, TarifaOtr, IdTarIva, 
                      IdTarRet, IdTarOtr,R.IdClase AS IdClas, TipCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev, R.Observacion AS Observ,R.IdEstado AS IdEstad,Estado,TimeSys, FecUpdate, IdCiaCrea,R.IdUsuario AS IdUsuari
 FROM  Trn_RecBuses AS R INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
  INNER JOIN Terceros AS O ON R.IdConductor=O.IdTercero  INNER JOIN Terceros AS V ON R.IdVendedor=V.IdTercero
  INNER JOIN Bancos AS B ON R.IdBanco=B.IdBanco  INNER JOIN EstadoDoc AS E ON R.IdEstado=E.IdEstado
 WHERE Modalidad=@pmModalidad  AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 ORDER BY  TipDoc, Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesLta]  @pmIdCia CHAR(2),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdVehiculo VARCHAR(10)
AS
 SELECT  TipDoc, Recibo, IdCia, Fecha,R.IdConcepto AS IdConcept, Concepto,IdCliente,T.RazonSocial AS Cliente, IdAgencia, Modalidad, IdVehiculo, IdConductor,O.RazonSocial AS Conductor,VehPropio, CentInicial AS CartInicial
,CentFinal AS CartFinal, ValorRecibido,ValorTotal, ValorDcto, ValorReteFte, ValorReteIva, ValorReteIca, ValorOtros, ValorOtrosDct, ValorPagMas,TotalOtros,TotalAhorro, ValorNeto,ValorAplicado, ValorAnticipo, ValorAbono, IdVendedor,V.RazonSocial AS Vendedor, R.Comision AS Comison
, IdTarCom, IdCCosto, IdCta, EnEfectivo, NumCheque,R.IdBanco AS IdBanc,Banco, Referencia, BaseIva, BaseRet, BaseOtr, TarifaIva, TarifaRet, TarifaOtr, IdTarIva,IdTarRet, IdTarOtr,R.IdClase AS IdClas, TipCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev
, R.Observacion AS Observ,R.IdEstado AS IdEstad,Estado,TimeSys, FecUpdate, IdCiaCrea,R.IdUsuario AS IdUsuari,TotalVales
 FROM   Trn_RecBuses AS R INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Terceros AS O ON R.IdConductor=O.IdTercero  INNER  JOIN Terceros AS V ON R.IdVendedor=V.IdTercero
 INNER  JOIN Bancos AS B ON R.IdBanco=B.IdBanco  INNER JOIN EstadoDoc AS E ON R.IdEstado=E.IdEstado
 WHERE Modalidad IN ('VC','OTROS')  AND  IdCia LIKE ISNULL(@pmIdCia,'%%') AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 ORDER BY  TipDoc, Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesNetIca]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesNetIca] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS
 SELECT TipoDoc,R.IdCia AS CdCia,Compania,IdCliente,T.RazonSocial AS NomCliente,R.IdVehiculo AS PlacaVeh,NumVeh,R.IdConductor AS CedConductor,CD.RazonSocial AS NomConductor
,SUM(ValorNeto) AS Total_Neto
 FROM  Trn_RecBuses AS R INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN Terceros AS CD ON R.IdConductor=CD.IdTercero
 INNER JOIN Companias AS C ON R.IdCia=C.IdCia INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  VehPropio=0 AND ValorNeto>0--TipoAfil<>'PROPIO' 
 AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 GROUP BY  TipoDoc,R.IdCia,Compania,IdCliente,T.RazonSocial,R.IdVehiculo,NumVeh,R.IdConductor,CD.RazonSocial
 UNION 
 SELECT TipoDoc,R.IdCia AS CdCia,Compania,IdCliente,T.RazonSocial AS NomCliente,R.IdVehiculo AS PlacaVeh,NumVeh,R.IdConductor AS CedConductor,CD.RazonSocial AS NomConductor
,SUM(ValorNeto*-1) AS Total_Neto
 FROM  Trn_DevRecBuses AS R INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN Terceros AS CD ON R.IdConductor=CD.IdTercero
 INNER JOIN Companias AS C ON R.IdCia=C.IdCia INNER JOIN Sys_TiposDoc AS TD ON R.TipDev=TD.IdDoc
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  VehPropio=0 AND ValorNeto>0--TipoAfil<>'PROPIO' 
 AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%') 
 GROUP BY  TipoDoc,R.IdCia,Compania,IdCliente,T.RazonSocial,R.IdVehiculo,NumVeh,R.IdConductor,CD.RazonSocial
 ORDER BY R.IdCia,R.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesNMes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesNMes] @pmAnno INT,@pmMes INT=Null, @pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdClase VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT IdCliente,IdVehiculo,IdCia,IdClase,Month(Fecha) AS NMes,SUM(ValorTotal) AS SvalTot,SUM(ValorNeto) AS SValNet
 FROM  Trn_RecBuses
 WHERE Year(Fecha)=@pmAnno AND Month(Fecha)=ISNULL(@pmMes,Month(Fecha))  AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 GROUP BY  IdCliente,IdVehiculo,IdCia,IdClase,Month(Fecha)
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesUlt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesUlt]  @pmTipDoc VARCHAR(3), @pmIdCia CHAR(2),@pmModalidad VARCHAR(10),@pmIdVehiculo VARCHAR(10)

AS
 SELECT  TipDoc, Recibo, IdCia, Fecha, IdConcepto, IdCliente, IdAgencia, Modalidad, TipCar, Cartulina, IdCiaCar, IdVehiculo, CentInicial, CentFinal,ValorNeto, Anulado, NumDev, FecDev, IdCiaCrea
 FROM  Trn_RecBuses
 WHERE  TipDoc=@pmTipDoc AND  IdCia=@pmIdCia AND Modalidad=@pmModalidad AND IdVehiculo=@pmIdVehiculo AND Anulado=0
 ORDER BY Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesVc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesVc] @pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmAnulado BIT=null,@pmValorNeto MONEY=0
AS
 SELECT  TipDoc, Recibo, IdCia, Fecha, IdConcepto, IdCliente, IdAgencia, Modalidad, TipCar, Cartulina, IdCiaCar,IdRuta,IdRelevador, IdVehiculo, IdConductor, VehPropio
,ValorNeto,ValorAplicado,ValorAnticipo,IdVendedor, Comision,Referencia,IdClase,Anulado, Observacion
 FROM  Trn_RecBuses
 WHERE  Anulado=@pmAnulado AND ValorNeto>@pmValorNeto  AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesVeh] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
 IF @pmIdVehiculo IS NULL
  SELECT R.IdVehiculo AS IdVehic,R.IdClase AS IdClas, IdCia,SUM(ValorAnticipo) AS StotAnt,SUM(ValorAbono) AS STotAbo 
  FROM  Trn_RecBuses  AS R  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
  WHERE ValorAnticipo>0 AND  IdPropietario LIKE ISNULL(@pmIdPropietario,'%') 
  GROUP BY  R.IdVehiculo,R.IdClase, IdCia
 ELSE
  SELECT R.IdVehiculo AS IdVehic,R.IdClase AS IdClas, IdCia,SUM(ValorAnticipo) AS StotAnt,SUM(ValorAbono) AS STotAbo 
  FROM  Trn_RecBuses  AS R  --INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
  WHERE ValorAnticipo>0 AND  R.IdVehiculo=@pmIdVehiculo
 GROUP BY  R.IdVehiculo,R.IdClase, IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRecBusesVFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecBusesVFec] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdClase VARCHAR(4)=Null
AS
 SELECT IdCliente,IdVehiculo,SUM(ValorTotal) AS SvalTot,SUM(ValorNeto) AS SValNet
 FROM  Trn_RecBuses
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdClase LIKE ISNULL(@pmIdClase,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY IdCliente,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecCheques]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecCheques] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,IdCliente,IdAgencia,VrTotal,PlacaVehic,Cantidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_RecCheques
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRecCheques_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecCheques_Cr] @pmTipDoc VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS Tip_Doc,TipoDoc,C.Recibo AS NumRecibo,C.IdCia AS CdCia,Compania,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS Cd_Agencia
,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrTotal,Cantidad,OrigenAdd,PlacaVehic,C.Anulado AS EstaAnulado,NumDev,C.FecDev AS FechDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,TimeSys,FecUpdate,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,Leyenda
--INFORMACION DEL CHEQUE
,TipForma,Numero,H.IdBanco AS CodBanco,B.Banco AS NomBanco,H.Fecha AS FechaCheq,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle
,NitCliente,HC.RazonSocial AS CheNombCliente,H.CdAgencia AS CheIdAgencia,HA.Agencia AS CheAgencia,HA.CodAgencia AS CheCodAgenc,HA.Referencia AS AgeReferencia
,CdVend,V.RazonSocial AS NomVendedor,H.IdLocal AS CodCiudad,LP.Localidad AS CiudadPlaza,H.TipDoc AS TipDocAplica,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig
,IdCiaCon,FecConsig,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco,H.Anulado AS CheAnulado,H.FecDev AS CheFecAnulado,H.IdEstado AS CheCodEstado,HE.Estado AS CheEstado
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_RecCheques AS C  INNER JOIN Trn_Cheques AS H ON C.TipDoc=H.TipRec  AND C.Recibo=H.Recibo AND C.IdCia=H.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero INNER JOIN Agencias  AS A ON C.IdAgencia=A.IdAgencia
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Bancos AS B ON H.IdBanco=B.IdBanco INNER JOIN Localidades AS LP ON H.IdLocal=LP.IdLocal
 INNER JOIN TercCliente AS CLI ON C.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS HC ON H.NitCliente=HC.IdTercero  LEFT JOIN Agencias  AS HA ON H.CdAgencia=HA.IdAgencia
 LEFT JOIN Terceros AS V ON H.CdVend=V.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON H.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON  CTA.IdBanco=BCT.IdBanco
 LEFT JOIN EstadoDoc AS HE ON H.IdEstado=HE.IdEstado
 WHERE C.TipDoc=@pmTipDoc AND C.Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND C.IdCia=@pmIdCia
 ORDER BY C.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesBus]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecChequesBus] @pmTipDoc VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS Tip_Doc,TipoDoc,C.Recibo AS NumRecibo,C.IdCia AS CdCia,Compania,C.IdCliente AS NitPropietario,T.RazonSocial AS Propietario
,PlacaVehic,NumVeh,VrTotal,Cantidad,OrigenAdd,C.Anulado AS EstaAnulado,NumDev,C.FecDev AS FechDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,TimeSys,FecUpdate,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,Leyenda
--INFORMACION DEL CHEQUE
,TipForma,Numero,H.IdBanco AS CodBanco,B.Banco AS NomBanco,H.Fecha AS FechaCheq,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle
,NitCliente,HC.RazonSocial AS CheNombCliente,H.CdAgencia AS CheIdAgencia,CdVend,V.RazonSocial AS NomVendedor,H.IdLocal AS CodCiudad,LP.Localidad AS CiudadPlaza
,H.TipDoc AS TipDocAplica,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco
,H.Anulado AS CheAnulado,H.FecDev AS CheFecAnulado,H.IdEstado AS CheCodEstado,HE.Estado AS CheEstado
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
--datos del vehículo
,VH.IdTipoVeh AS CdTipoVeh,TipoVehiculo,VH.IdMarca AS CdMarca,Marca,Modelo,TipoAfil,FecIngreso,VH.Inactivo AS VehInactivo
 FROM Trn_RecCheques AS C  INNER JOIN Trn_Cheques AS H ON C.TipDoc=H.TipRec  AND C.Recibo=H.Recibo AND C.IdCia=H.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Bancos AS B ON H.IdBanco=B.IdBanco INNER JOIN Localidades AS LP ON H.IdLocal=LP.IdLocal
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 LEFT JOIN  Vehiculos AS VH ON C.PlacaVehic=VH.IdVehiculo 
 LEFT JOIN TiposVeh AS TV ON VH.IdTipoVeh=TV.IdTipoVeh LEFT JOIN Marcas AS M ON VH.IdMarca=M.IdMarca
  LEFT JOIN Terceros AS HC ON H.NitCliente=HC.IdTercero  LEFT JOIN Terceros AS V ON H.CdVend=V.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON H.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON  CTA.IdBanco=BCT.IdBanco
 LEFT JOIN EstadoDoc AS HE ON H.IdEstado=HE.IdEstado
 WHERE C.TipDoc=@pmTipDoc AND C.Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND C.IdCia=@pmIdCia
 ORDER BY C.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecChequesLta]  @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmReciboIni INT=Null,@pmReciboFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Recibo,IdCia,Fecha,IdCliente,RazonSocial,IdAgencia,PlacaVehic,VrTotal,Cantidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_RecCheques AS C INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecChequesPre] @pmTipDoc VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS Tip_Doc,TipoDoc,C.Recibo AS NumRecibo,C.IdCia AS CdCia,Compania,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS Cd_Agencia
,NomAgencia,VrTotal,Cantidad,OrigenAdd,PlacaVehic,C.Anulado AS EstaAnulado,NumDev,C.FecDev AS FechDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,TimeSys,FecUpdate,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS IdUsuari,Usuario,Leyenda
--INFORMACION DEL CHEQUE
,TipForma,Numero,H.IdBanco AS CodBanco,B.Banco AS NomBanco,H.Fecha AS FechaCheq,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle
,NitCliente,HC.RazonSocial AS CheNombCliente,H.CdAgencia AS CheIdAgencia,CdVend,V.RazonSocial AS NomVendedor,H.IdLocal AS CodCiudad,LP.Localidad AS CiudadPlaza
,H.TipDoc AS TipDocAplica,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig,IdCiaCon,FecConsig,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco
,BCT.Banco AS CtaBanco,H.Anulado AS CheAnulado,H.FecDev AS CheFecAnulado,H.IdEstado AS CheCodEstado,HE.Estado AS CheEstado
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,EsExento,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero
, DirAgencia,IdLocalAge,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto
 FROM Trn_RecCheques AS C  INNER JOIN Trn_Cheques AS H ON C.TipDoc=H.TipRec  AND C.Recibo=H.Recibo AND C.IdCia=H.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero 
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Bancos AS B ON H.IdBanco=B.IdBanco INNER JOIN Localidades AS LP ON H.IdLocal=LP.IdLocal
 INNER JOIN  TercCliePrestamo AS CLI ON C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo  INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LA ON CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Terceros AS HC ON H.NitCliente=HC.IdTercero LEFT JOIN Terceros AS V ON H.CdVend=V.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON H.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON  CTA.IdBanco=BCT.IdBanco
 LEFT JOIN EstadoDoc AS HE ON H.IdEstado=HE.IdEstado LEFT JOIN TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 WHERE C.TipDoc=@pmTipDoc AND C.Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND C.IdCia=@pmIdCia
 ORDER BY C.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecChequesRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecChequesRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT C.TipDoc AS Tip_Doc,C.Recibo AS NumRecibo,C.IdCia AS CdCia,Compania,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS Cd_Agencia
,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,PlacaVehic,VrTotal,Cantidad,OrigenAdd,C.Anulado AS EstaAnulado,NumDev,C.FecDev AS FechDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,ED.Estado AS EstadoDoc,TimeSys,FecUpdate,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS IdUsuari,Usuario
--INFORMACION DEL CHEQUE
,TipForma,Numero,H.IdBanco AS CodBanco,B.Banco AS NomBanco,H.Fecha AS FechaCheq,FecPago,VrForma,CtaForma,Beneficiario,Referncia1,Referncia2,Detalle
,NitCliente,HC.RazonSocial AS CheNombCliente,H.CdAgencia AS CheIdAgencia,HA.Agencia AS CheAgencia,HA.CodAgencia AS CheCodAgenc,HA.Referencia AS AgeReferencia
,CdVend,V.RazonSocial AS NomVendedor,H.IdLocal AS CodCiudad,LP.Localidad AS CiudadPlaza,H.TipDoc AS TipDocAplica,Documento,IdCiaDoc,FecDoc,TipCon,NumConsig
,IdCiaCon,FecConsig,CdCta,NumeroCta,CTA.IdBanco AS CtaIdBanco,BCT.Banco AS CtaBanco,H.Anulado AS CheAnulado,H.FecDev AS CheFecAnulado,H.IdEstado AS CheCodEstado,HE.Estado AS CheEstado
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_RecCheques AS C  INNER JOIN Trn_Cheques AS H ON C.TipDoc=H.TipRec  AND C.Recibo=H.Recibo AND C.IdCia=H.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero INNER JOIN Agencias  AS A ON C.IdAgencia=A.IdAgencia
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia  
 INNER JOIN Bancos AS B ON H.IdBanco=B.IdBanco INNER JOIN Localidades AS LP ON H.IdLocal=LP.IdLocal
 INNER JOIN TercCliente AS CLI ON C.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS HC ON H.NitCliente=HC.IdTercero  LEFT JOIN Agencias  AS HA ON H.CdAgencia=HA.IdAgencia
 LEFT JOIN Terceros AS V ON H.CdVend=V.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON H.CdCta=CTA.IdCta LEFT JOIN Bancos AS BCT ON  CTA.IdBanco=BCT.IdBanco
 LEFT JOIN EstadoDoc AS HE ON H.IdEstado=HE.IdEstado
 WHERE C.TipDoc=@pmTipDoc  AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND C.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')   AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (C.Anulado=ISNULL(@pmAnulado,0) or C.Anulado=ISNULL(@pmAnulado,1))
 ORDER BY C.IdCia,C.Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecFactura] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipRec,Recibo,IdCia,Item,TipDoc,Documento,IdCiaDoc,ItemDoc,Fecha,IdCargo,IdClase,ValorAbono,Devolucion,Descuento,IdCliente,IdAgencia,IdVehiculo,VehPropio,IdVendedor,Comision,Detalle,FecPago,AplAntcpo,TimeSys,IdUsuario
 FROM Trn_RecFactura
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura_Ant]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFactura_Ant]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
AS
  SELECT  TipRec, RF.Recibo AS Nrecibo, RF.IdCia AS CodCia,RF.IdVehiculo AS Placaveh,ValorAnticipo,R.ValorAbono AS AbonoAnt,SUM(RF.ValorAbono) AS TotalAbono
  FROM  Trn_RecFactura AS RF INNER JOIN Trn_RecBuses AS R ON RF.TipRec=R.TipDoc AND RF.Recibo=R.Recibo AND RF.IdCia=R.IdCia
 WHERE RF.TipDoc=@pmTipDoc AND Documento=@pmDocumento  AND IdCiaDoc=@pmIdCiaDoc  AND AplAntcpo<>0
 GROUP BY  TipRec, RF.Recibo, RF.IdCia,RF.IdVehiculo,ValorAnticipo,R.ValorAbono
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFactura_Cr]  @pmTipRec VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
AS
  SELECT  TipRec,TR.TipoDoc AS TipoRecibo, Recibo, RF.IdCia AS CodCia,CR.Compania AS CompaniaRec, Item, TipDoc,TD.TipoDoc AS TipoDocumeto, Documento, IdCiaDoc,CD.Compania AS CompaniaDoc, ItemDoc, Fecha
, RF.IdCargo AS CodCargo,Concepto,RF.IdClase AS CodClase,ClaseCuenta,ValorAbono, Devolucion, Descuento, IdCliente,NP.RazonSocial AS Propietario, IdAgencia,RF.IdVehiculo AS PlacaVeh,NumVeh,RF.VehPropio, IdVendedor,NC.RazonSocial AS Conductor
, Comision, Detalle,FecPago,AplAntcpo,TimeSys, RF.IdUsuario AS Idusuari
  FROM  Trn_RecFactura AS RF INNER JOIN Sys_TiposDoc  AS TR ON RF.TipRec=TR.IdDoc  INNER JOIN Sys_TiposDoc  AS TD ON RF.TipDoc=TD.IdDoc
 INNER JOIN Companias  AS CR ON RF.IdCia=CR.IdCia INNER JOIN Companias  AS CD ON RF.IdCiaDoc=CD.IdCia
 INNER JOIN BusClaseCue AS CU ON RF.IdClase=CU.IdClase INNER JOIN Fijos AS F ON RF.IdCargo=F.IdCargo
 INNER JOIN Vehiculos AS V ON RF.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS NP ON RF.IdCliente=NP.IdTercero 
 INNER JOIN Terceros AS NC ON RF.IdVendedor=NC.IdTercero
 WHERE  TipRec=@pmTipRec  AND Recibo between @pmReciboIni  AND @pmReciboFin AND  RF.IdCia=@pmIdCia
ORDER BY TipRec,RF.IdCia, Recibo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFactura_Cra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFactura_Cra] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmTipRec VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdCargo VARCHAR(4)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdAdmon VARCHAR(4)=Null,@pmIdVendedor VARCHAR(16)=Null,@pmIdUsuario VARCHAR(11)=Null,@pmRecibo INT=Null,@pmDocumento INT=Null
AS
 --cancelaciones vs facturas
  SELECT  RF.TipRec AS IdTipRec,TR.TipoDoc AS TipoRecibo, RF.Recibo AS NumRecibo, RF.IdCia AS CodCia,CR.Compania AS CompaniaRec, RF.Item AS ItemRec,Fecha,RF.TipDoc AS IdTipDoc,TD.TipoDoc AS TipoDocumeto
, RF.Documento AS NumFactura, IdCiaDoc,CD.Compania AS CompaniaDoc, ItemDoc,RF.ValorAbono AS ValrAbono, Devolucion,RF.IdCliente AS NitPropietario,NP.RazonSocial AS Propietario,RF.IdVehiculo AS PlacaVeh
,RF.VehPropio, RF.IdVendedor AS CedConductor,NC.RazonSocial AS Conductor,RF.Detalle AS DetalleRec,VC.IdCargo AS CodCargo,F.Concepto AS ConceptoCargo,VC.IdClase AS CodClase,ClaseCuenta
,AplAntcpo,FecEmision, FecVence, ValorFactura,Factura,Referencia,VC.Detalle AS DetalleDoc,VC.IdConcepto AS IdConcep,C.Concepto AS ConceptoDoc,FecUltPago,NotaInt,FecUltLiquida,RF.IdUsuario AS Idusuari,Usuario,FecPago,Descuento,TimeSys
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
 FROM  Trn_RecFactura AS RF INNER JOIN Trn_CausacVence AS VC ON RF.TipDoc=VC.TipDoc AND RF.Documento=VC.Documento AND RF.IdCiaDoc=VC.IdCia AND RF.ItemDoc=VC.Item
 INNER JOIN Sys_TiposDoc  AS TR ON RF.TipRec=TR.IdDoc  INNER JOIN Sys_TiposDoc  AS TD ON RF.TipDoc=TD.IdDoc
 INNER JOIN Companias  AS CR ON RF.IdCia=CR.IdCia  INNER JOIN Companias  AS CD ON RF.IdCiaDoc=CD.IdCia
 INNER JOIN Terceros AS NP ON RF.IdCliente=NP.IdTercero   INNER JOIN Terceros AS NC ON RF.IdVendedor=NC.IdTercero
 INNER JOIN adm_Usuarios AS U ON RF.IdUsuario=U.IdUsuario  INNER JOIN Vehiculos AS V ON RF.IdVehiculo=V.IdVehiculo
 INNER JOIN BusClaseCue  AS CU ON VC.IdClase=CU.IdClase  INNER JOIN Fijos AS F ON VC.IdCargo=F.IdCargo
 INNER JOIN Conceptos AS C ON VC.IdConcepto=C.IdConcepto   INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND RF.TipRec LIKE ISNULL(@pmTipRec,'%') AND RF.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND RF.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND VC.IdCargo LIKE ISNULL(@pmIdCargo,'%') AND VC.IdClase LIKE ISNULL(@pmIdClase,'%') AND RF.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND RF.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND VC.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%') AND RF.IdVendedor LIKE ISNULL(@pmIdVendedor,'%')
 AND RF.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 AND ( RF.Recibo>=ISNULL(@pmRecibo,0)  AND  RF.Recibo<=ISNULL(@pmRecibo,2147483647))
 AND ( RF.Documento>=ISNULL(@pmDocumento,0)  AND  RF.Documento<=ISNULL(@pmDocumento,2147483647))
ORDER BY RF.TipRec,RF.IdCia, RF.Recibo,RF.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaApl]  @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
AS
  SELECT  TipDoc, Documento, IdCiaDoc, ItemDoc, SUM(ValorAbono) AS STOTABO,SUM(Devolucion) AS STOTDEV
  FROM     Trn_RecFactura
  WHERE  TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
 GROUP BY TipDoc, Documento, IdCiaDoc, ItemDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaCla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaCla] @pmIdVehiculo VARCHAR(10),@pmIdCliente VARCHAR(16)=Null,@pmTipDoc VARCHAR(3)=Null
,@pmIdCiaDoc CHAR(2)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdConcepto VARCHAR(4)=Null
AS
  SELECT SUM(R.ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
  FROM  Trn_RecFactura AS R INNER JOIN Trn_CausacVence AS VC ON R.TipDoc=VC.TipDoc AND R.Documento=VC.Documento AND R.IdCiaDoc=VC.IdCia AND R.ItemDoc=VC.Item
  WHERE R.IdVehiculo=@pmIdVehiculo AND  R.IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND R.TipDoc LIKE ISNULL(@pmTipDoc,'%')
  AND IdCiaDoc LIKE ISNULL(@pmIdCiaDoc,'%%') AND VC.IdClase LIKE ISNULL(@pmIdClase,'%') AND IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaCli] @pmIdCliente VARCHAR(16)=Null,@pmAplAntcpo BIT=Null
AS
 IF @pmAplAntcpo IS NULL
  SELECT IdCliente,SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
  FROM     Trn_RecFactura
  WHERE  IdCliente LIKE ISNULL(@pmIdCliente,'%')
  GROUP BY  IdCliente
ELSE
  SELECT IdCliente,SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
  FROM   Trn_RecFactura
  WHERE AplAntcpo=@pmAplAntcpo AND  IdCliente LIKE ISNULL(@pmIdCliente,'%')
  GROUP BY  IdCliente
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaDoc]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmItemDoc INT
AS
 SELECT  TipRec, Recibo, IdCia, Item, TipDoc, Documento, IdCiaDoc, ItemDoc, Fecha, IdCargo, IdClase, ValorAbono, Devolucion, Descuento, IdCliente, IdAgencia, 
                       IdVehiculo, VehPropio, IdVendedor, Comision, Detalle,FecPago,AplAntcpo, TimeSys, IdUsuario
 FROM     Trn_RecFactura
  WHERE  TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
  AND (ItemDoc>=ISNULL(@pmItemDoc,0)  AND ItemDoc<=ISNULL(@pmItemDoc,2147483647))
 ORDER BY TipRec, Recibo, IdCia, Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaDocA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaDocA]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmItemDoc INT=Null
AS
 SELECT  TipRec, Recibo, IdCia, Item, TipDoc, Documento, IdCiaDoc, ItemDoc, Fecha, IdCargo, IdClase, ValorAbono, Devolucion, Descuento
, IdCliente, IdAgencia,IdVehiculo, VehPropio, IdVendedor, Comision, Detalle,FecPago,AplAntcpo, TimeSys, IdUsuario
 FROM     Trn_RecFactura
 WHERE  TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc AND AplAntcpo=0 
 AND (ItemDoc>=ISNULL(@pmItemDoc,0)  AND ItemDoc<=ISNULL(@pmItemDoc,2147483647))
 ORDER BY TipRec, Recibo, IdCia, Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaLta]  @pmTipRec VARCHAR(3),@pmIdCia CHAR(2),@pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdClase VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdVehiculo VARCHAR(10)

AS
  SELECT  TipRec, Recibo, IdCia, Item, Fecha, TipDoc, Documento, IdCiaDoc, ItemDoc, ValorAbono, Devolucion, Descuento, IdCliente,T.RazonSocial AS NomCliente, IdAgencia, 
                      IdVehiculo, VehPropio, IdVendedor,C.RazonSocial AS Conductor,Comision, Detalle,R.IdClase AS ClaCue,IdCargo,FecPago,AplAntcpo,TimeSys,R.IdUsuario AS IdUsuari
  FROM   Trn_RecFactura AS R INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero LEFT JOIN Terceros AS C ON R.IdVendedor=C.IdTercero
  WHERE  IdCia=@pmIdCia AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipRec like ISNULL(@pmTipRec,'%')  AND TipDoc like ISNULL(@pmTipDoc,'%')
 AND R.IdClase like ISNULL(@pmIdClase,'%') AND IdCliente like ISNULL(@pmIdCliente,'%') AND IdVehiculo like ISNULL(@pmIdVehiculo,'%')
 ORDER BY TipRec,Recibo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaRec]  @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
AS
  SELECT  Item,Fecha,TipDoc, Documento, IdCiaDoc, ItemDoc,R.IdCargo AS IdCarg,Concepto,R.IdClase AS IdClas, ValorAbono, Devolucion, Descuento, IdCliente,T.RazonSocial AS Cliente,IdAgencia, 
                      IdVehiculo, VehPropio, IdVendedor,V.RazonSocial AS Vendedor, Comision, Detalle,FecPago,AplAntcpo, TimeSys, R.IdUsuario AS IdUsuari,TipRec, Recibo, IdCia
  FROM  Trn_RecFactura  AS R INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
    LEFT JOIN Terceros AS V ON R.IdVendedor=V.IdTercero
   LEFT JOIN Fijos AS F ON R.IdCargo=F.IdCargo
  WHERE  TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaTot]  @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
AS
  SELECT  IdCliente,IdVehiculo, SUM(ValorAbono) AS STOTABO,SUM(Devolucion) AS STOTDEV
  FROM   Trn_RecFactura
  WHERE  TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
  GROUP BY IdCliente,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaTpa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaTpa] @pmIdVehiculo VARCHAR(10),@pmAplAntcpo BIT=Null
AS
 IF @pmAplAntcpo IS NULL 
  SELECT  SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev, SUM(Descuento) AS STotDct
  FROM     Trn_RecFactura
  WHERE  IdVehiculo=@pmIdVehiculo
 ELSE
  SELECT  SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev, SUM(Descuento) AS STotDct
  FROM     Trn_RecFactura
  WHERE  IdVehiculo=@pmIdVehiculo  AND AplAntcpo=@pmAplAntcpo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecFacturaVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecFacturaVeh] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmAplAntcpo BIT=Null
AS
 IF @pmAplAntcpo IS NULL
 BEGIN 
  IF @pmIdVehiculo IS NULL
    SELECT R.IdVehiculo AS IdVehic,R.IdClase AS IdClas,IdCia,SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
   FROM   Trn_RecFactura AS R  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
   WHERE  IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
  GROUP BY R.IdVehiculo,R.IdClase,IdCia
 ELSE
    SELECT R.IdVehiculo AS IdVehic,R.IdClase AS IdClas,IdCia,SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
   FROM   Trn_RecFactura AS R -- INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
   WHERE  R.IdVehiculo=@pmIdVehiculo
  GROUP BY R.IdVehiculo,R.IdClase,IdCia
 END
ELSE
 BEGIN
  IF @pmIdVehiculo IS NULL
    SELECT R.IdVehiculo AS IdVehic,R.IdClase AS IdClas,IdCia,SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
   FROM   Trn_RecFactura AS R  INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
   WHERE AplAntcpo=@pmAplAntcpo AND  IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
  GROUP BY R.IdVehiculo,R.IdClase,IdCia
 ELSE
    SELECT R.IdVehiculo AS IdVehic,R.IdClase AS IdClas,IdCia,SUM(ValorAbono) AS STotAbo,SUM(Devolucion) AS STotDev
   FROM   Trn_RecFactura AS R -- INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
   WHERE  R.IdVehiculo=@pmIdVehiculo AND AplAntcpo=@pmAplAntcpo
  GROUP BY R.IdVehiculo,R.IdClase,IdCia
 END
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto
,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,IdCCosto
,IdSubCos,IdCajero,IdVend,TarifaCom,CodTarCom,IdLocal,EnEfectivo,CdForma,NumForma,DetallePago,CdBanco,CdCta,Referencia,pVehiculo,CdConductor
,TipDcm,Documento,IdCiaDcm,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,VrReteCREE,TarifaRtc,CodTarRtc,VrDevFact
,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Recibos
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecibos_Cr] @pmTipDoc VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS Tip_Doc,TipoDoc,Recibo,R.IdCia AS CodCia,Compania,R.Fecha AS FechaRec,FecPago,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,R.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA
,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta
,R.IdCCosto AS IdCenCost,CC.CCosto AS CentCosto,R.IdSubCos AS IdSubCent,SC.SubCosto AS SubcCosto,IdCajero,UC.Usuario AS NomCajero
,R.IdVend AS NitVend,V.RazonSocial AS Vendedor,TarifaCom,R.IdLocal AS CdCiudad,LR.Localidad AS CiudadRecibo,EnEfectivo,CdForma,R.NumForma AS RecNumForma,DetallePago
,CdBanco,BR.Banco AS RecBanco,R.CdCta AS RecCodCta,R.Referencia AS RecReferencia,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,TipDcm,R.Documento AS NumDocmto,IdCiaDcm
,Modalidad,VrReteCREE,TarifaRtc,CodTarRtc,VrDevFact,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado
,TimeSys,R.FecUpdate AS Fec_Update,IdCiaCrea,R.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario,Leyenda
--detalle de pagos
,Item,P.IdForma AS CdForma,FormaPago,Detalle,VrPagado,VrCambio,EsCaja,P.IdBanco AS PagCdBanco,BF.Banco AS PagBanco,NitCliente,PC.RazonSocial AS NomCliente
,CdAgencia,PA.Agencia AS PagNomAgencia,PA.CodAgencia AS PagCodAgencia,PA.Referencia AS PagRefeAgencia,P.NumForma AS PagNumForma,FecForma,CtaForma,Beneficiario,Referncia1
,P.Referncia2 AS PagReferencia2,CdLocal,LF.Localidad AS CiudadPlaza,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_Recibos AS R  INNER JOIN Trn_Pagos AS P ON R.TipDoc=P.TipDoc AND R.Recibo=P.Documento AND R.IdCia=P.IdCia
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero  INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN Agencias  AS A ON R.IdAgencia=A.IdAgencia
 INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia  INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN adm_Usuarios AS UC ON R.IdCajero=UC.IdUsuario 
 INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto 
 INNER JOIN Formaspago AS FP ON P.IdForma=FP.IdForma INNER JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Localidades AS LR ON R.IdLocal=LR.IdLocal LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TCM ON R.TipCom=TCM.IdCom
 LEFT JOIN Bancos AS BR ON R.CdBanco=BR.IdBanco LEFT JOIN Terceros AS TC ON R.CdConductor=TC.IdTercero
 LEFT JOIN Terceros AS PC ON P.NitCliente=PC.IdTercero  LEFT JOIN Agencias  AS PA ON P.CdAgencia=PA.IdAgencia
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal 
 WHERE R.TipDoc=@pmTipDoc AND Recibo BETWEEN @pmReciboIni AND @pmReciboFin AND R.IdCia=@pmIdCia
 ORDER BY Recibo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecibosAcu] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT IdCliente,IdAgencia,IdCia,SUM(VrNeto) AS STOTNET
 FROM Trn_Recibos
 WHERE YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY  IdCliente,IdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecibosDoc]  @pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmTipDcm VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Recibo,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal
,IdEstado,TipDcm,Documento,IdCiaDcm,Anulado
 FROM Trn_Recibos
 WHERE Documento=@pmDocumento AND IdCiaDcm=@pmIdCiaDcm AND TipDcm LIKE ISNULL(@pmTipDcm,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRecibosLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmReciboIni INT=Null,@pmReciboFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdLocal VARCHAR(8)=Null,@pmEnEfectivo BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS 
 SELECT Recibo,IdCia,Fecha,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,FecPago,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto
,VrAplicado,VrAnticipo,VrEfectivo,VrBomberil,TarifaBom,ImpAviTab,TarifaAvta,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,CodTarRet,CodTarIca,CodTarRiv,CodTarifBom,CodTarifAvta,IdCCosto,IdSubCos,IdCajero,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,R.IdLocal AS CdCiudad
,EnEfectivo,CdForma,NumForma,DetallePago,CdBanco,CdCta,Referencia,pVehiculo,CdConductor,TipDcm,Documento,IdCiaDcm,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,VrReteCREE,TarifaRtc,CodTarRtc,VrDevFact,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Recibos AS R INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Recibo BETWEEN ISNULL(@pmReciboIni,0) AND ISNULL(@pmReciboFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')  AND R.IdLocal LIKE ISNULL(@pmIdLocal,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 ORDER BY IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecibosRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecibosRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdCajero VARCHAR(11)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocal VARCHAR(8)=Null,@pmEnEfectivo BIT=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Recibo,R.IdCia AS CodCia,Compania,Fecha,FecPago,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente
,R.IdAgencia AS IdAgenc,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,VrRecibido,VrSubTotal,VrDescuento,VrRetencion,VrReteICA,VrReteIVA
,VrOtros,VrOtrDcto,VrAhorro,VrPagosMas,VrNeto,VrAplicado,VrAnticipo,VrEfectivo,BaseRet,BaseIca,BaseRiv,TarifaRet,TarifaIca,TarifaRiv,VrBomberil,TarifaBom,CodTarifBom,ImpAviTab,TarifaAvta,CodTarifAvta
,R.IdCCosto AS IdCenCost,CCosto,R.IdSubCos AS IdSubCent,SubCosto,IdCajero,UC.Usuario AS NomCajero
,R.IdVend AS NitVend,V.RazonSocial AS Vendedor,TarifaCom,R.IdLocal AS CdCiudad,LR.Localidad AS CiudadRecibo,EnEfectivo,CdForma,NumForma,DetallePago
,CdBanco,BR.Banco AS RecBanco,CdCta,R.Referencia AS Referncia,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,TipDcm,Documento,IdCiaDcm
,Modalidad,VrReteCREE,TarifaRtc,CodTarRtc,VrDevFact,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado
,TimeSys,R.FecUpdate AS Fec_Update,IdCiaCrea,R.IdUsuario AS IdUsuari,U.Usuario AS NombreUsuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CliCodBanco,BC.Banco AS CliBanco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,CdFntePago,FuentePago
 FROM Trn_Recibos AS R  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero  INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN Agencias  AS A ON R.IdAgencia=A.IdAgencia INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia  INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario  INNER JOIN adm_Usuarios AS UC ON R.IdCajero=UC.IdUsuario 
 INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto 
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Localidades AS LR ON R.IdLocal=LR.IdLocal LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos
 LEFT JOIN Bancos AS BR ON R.CdBanco=BR.IdBanco LEFT JOIN Terceros AS TC ON R.CdConductor=TC.IdTercero
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 WHERE  TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%') AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND R.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND R.IdVend LIKE ISNULL(@pmIdVend,'%') AND IdCajero LIKE ISNULL(@pmIdCajero,'%')
 AND R.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (EnEfectivo=ISNULL(@pmEnEfectivo,0) or EnEfectivo=ISNULL(@pmEnEfectivo,1))
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY R.IdCia,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryRecTanqueos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRecTanqueos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Recibo,IdCia,Item,Fecha,Documento,IdTipoCom,TipoComb,Cantidad,ValorUnitario,R.IdEstacion AS CdEstacion,EstServicio
 FROM Trn_RecTanqueos AS R LEFT JOIN EdsServicio AS ED ON R.IdEstacion=ED.IdEstacion
 LEFT JOIN TiposFuel AS TF ON R.IdTipoCom=TF.IdCom
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRecTanqueos_Crr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryRecTanqueos_Crr] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdTipoCom VARCHAR(4)=Null
,@pmIdEstacion VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmAnulado BIT=Null
,@pmIdUsuario VARCHAR(11)=Null,@pmIdEstado VARCHAR(4)=Null
AS
 SELECT RT.Recibo AS NumRecibo, RT.IdCia AS CodCia, Item, RT.Fecha AS FechaRec, Documento, RT.IdTipoCom AS CodTipoCom,TipoComb, Cantidad, ValorUnitario,Cantidad*ValorUnitario AS ValorTotal
,RT.IdEstacion AS CodEstacion,EstServicio,Modalidad,TipCar,Cartulina,IdCiaCar,R.IdVehiculo AS PlacaVeh,NumVeh,IdCliente AS NitPropietario,T.RazonSocial AS Propietario,R.IdConductor AS CedConductor
,NC.RazonSocial AS Conductor,R.VehPropio AS VhPropio,R.CentInicial AS CentenaIni,R.CentFinal AS CentenaFin,Recorridos,TotalProducido,TotalGastos,TotalVales,TotalGastos*TotalVales AS SumaGastos
,Anulado,NumDev,FecDev,R.Observacion AS Observ,R.IdUsuario AS IdUsuari,Usuario,Compania,RT.TipDoc AS TipDocm,TimeSys
 FROM  Trn_RecTanqueos AS RT  INNER JOIN Trn_RecBuses AS R ON RT.TipDoc=R.TipDoc AND RT.Recibo=R.Recibo AND RT.IdCia=R.IdCia
 INNER JOIN  Companias AS CI ON RT.IdCia=CI.IdCia  INNER JOIN EdsServicio AS E ON RT.IdEstacion=E.IdEstacion
 INNER JOIN TiposFuel AS TC ON RT.IdTipoCom=TC.IdCom INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Terceros AS NC ON R.IdConductor=NC.IdTercero INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 WHERE RT.Fecha BETWEEN @pmFechaIni  AND @pmFechaFin AND RT.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND RT.IdTipoCom LIKE ISNULL(@pmIdTipoCom,'%') AND RT.IdEstacion LIKE ISNULL(@pmIdEstacion,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND R.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND R.IdUsuario LIKE ISNULL(@pmIdUsuario,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 ORDER BY RT.IdCia,RT.Recibo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRegimenDian]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRegimenDian] @pmIdRegimen VARCHAR(4)
 AS 
 IF @pmIdRegimen IS NULL
  SELECT IdRegimen,Regimen,CodFiscal
  FROM RegimenDian
  WHERE Inactivo=0
 ORDER BY Regimen
 ELSE
  SELECT IdRegimen,Regimen,CodFiscal,Inactivo
  FROM RegimenDian
  WHERE IdRegimen=@pmIdRegimen
GO
/****** Object:  StoredProcedure [dbo].[paQryRegistro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRegistro] @pmIdCia CHAR(2)=Null
 AS 
 SELECT IdCia,IdEmpresa,NitEmpresa,DvNit,RazonSocial,Descripcion,Direccion,Telefono,Fax,R.IdLocal AS CodCiu
,R.IdPais AS IdPai,e_mail,ArchivoLogo,NumeroSerial,Regimen,Licencia,VigenciaLic,Personeria,Leyenda,FechaRegistro,FechaVence,CurrtyDate
,CodISO,NombrePais,P.IdMneda AS CodMnda,Mneda,Simbolo,MneLocal,VrCambio,Localidad,TipoId,NitRepLegal
,RepLegal,TipoPersna,CIIUDane,CurDate1,FechaPrest
 FROM adm_Registro AS R INNER JOIN adm_Paises AS P ON R.IdPais=P.IdPais 
 INNER JOIN adm_monedas AS M ON P.IdMneda=M.IdMneda
 INNER JOIN Localidades AS  L ON R.IdLocal=L.IdLocal
 WHERE IdCia  LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRelaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRelaciones] @pmIdTabla VARCHAR(20)=Null,@pmTablaForanea VARCHAR(20)=Null,@pmCampoForaneo VARCHAR(20)=Null
 AS 
 SELECT IdTabla,TablaForanea,CampoForaneo,BasedeDatos,NoValidar
 FROM Sys_Relaciones
 WHERE IdTabla LIKE ISNULL(@pmIdTabla, '%') AND TablaForanea LIKE ISNULL(@pmTablaForanea,'%') 
 AND CampoForaneo LIKE ISNULL(@pmCampoForaneo,'%')
 ORDER BY IdTabla,TablaForanea,CampoForaneo
GO
/****** Object:  StoredProcedure [dbo].[paQryRelacionesEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRelacionesEnt] @pmIdTabla VARCHAR(20), @pmNoValidar BIT=Null
AS
 SELECT R.IdTabla AS TablaPmry,TablaForanea,CampoForaneo,BasedeDatos,NoValidar
,NivelRel,CamposPK,FngKey,Sp_Qry,Sp_Qpmt,Sp_Ins, Sp_Upd, Sp_Del
 FROM Sys_Relaciones AS R INNER JOIN Sys_Entidades AS E ON  R.IdTabla=E.IdTabla
 WHERE  R.IdTabla=@pmIdTabla  
 AND (NoValidar=ISNULL(@pmNoValidar,0) or NoValidar=ISNULL(@pmNoValidar,1))
 ORDER BY TablaForanea,CampoForaneo
GO
/****** Object:  StoredProcedure [dbo].[paQryRelacionesFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRelacionesFor] @pmIdTabla VARCHAR(20)
 AS 
 SELECT R.IdTabla AS NomTabla,TablaForanea,CampoForaneo,BasedeDatos,NoValidar,NivelRel
 FROM Sys_Relaciones AS R LEFT JOIN Sys_Entidades AS E ON R.TablaForanea=E.IdTabla
 WHERE R.IdTabla=@pmIdTabla
 ORDER BY  NivelRel
GO
/****** Object:  StoredProcedure [dbo].[paQryRemision]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemision] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Remision,IdCia,Fecha,FechaDesp,FechaVence,IdConcepto,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto
,Cantidad,Unidades,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,NitEmpTrans,EmpTrans
,pVehiculo,CdConductor,DetalleEnvio,IdForma,DetallePago,MulPlazos, IdPlazo, CdRuta, FechaPed,TipFac,Factura,IdCiaFac,FechaFact,TipPed,Pedido,IdCiaPed,NumAutoriza,Modalidad,OrigenAdd,Anulado
,FecDev,Observacion,IdEstado,NumAprob,FecAprob,CdUsuAprob,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Remision
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRemision_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemision_Cr] @pmTipDoc VARCHAR(3),@pmRemisionIni INT,@pmRemisionFin INT,@pmIdCia CHAR(2)
 AS
 SELECT O.TipDoc AS Tip_Doc,TipoDoc,O.Remision AS NumRemision,O.IdCia AS CdCia,Compania,O.Fecha AS FechaDoc,FechaDesp,FechaVence,O.IdConcepto AS CdConcepto,Concepto
,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,O.Unidades AS NumUnidades
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,O.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DiasEntraga,O.NitContac AS RemNitContac,O.NomContac AS RemNomContac,O.TelContac AS RemTelContac,O.emlContac AS RemEmailContac,CargoContac,O.IdForma AS CdForma,FormaPago
,DetallePago,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CdRuta,Ruta,NitEmpTrans,EmpTrans,O.pVehiculo AS PlacaVeh,CdConductor,TC.RazonSocial AS Conductor,DetalleEnvio,TipFac,O.Factura AS NumFactura,IdCiaFac,FechaFact
,TipPed,Pedido,IdCiaPed,FechaPed,NumAutoriza,NumAprob,FecAprob,CdUsuAprob,Modalidad,OrigenAdd,Anulado,FecDev
,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS Fec_Add,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
--Detalles
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,CdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,IdCiaCot,K.Factura AS KarFactura,TipDocDev,NumDocDev
,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,K.Unidades AS KarUnidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,K.ListaPrec AS KarLtaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM Trn_Remision AS O INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Remision=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON O.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 WHERE O.TipDoc=@pmTipDoc AND O.Remision BETWEEN @pmRemisionIni AND @pmRemisionFin AND O.IdCia=@pmIdCia
 ORDER BY O.Remision,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemisionDet]  @pmRemision INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,K.IdProducto AS CdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega,Salidas,VrPrecio,Salidas*VrPrecio AS VrSubTotal
,TarifaDct,VrDctoSal,TarifaIva,VrIvaSal,((Salidas*VrPrecio)-VrDctoSal)+VrIvaSal AS VrTotal,VrBruto,K.ListaPrec AS LtaPrec,VrBase,K.Referencia AS Referncia,Referencia2,K.Unidades AS Undades
,CodTarDct,CodTarIva,K.IdVend AS NitVend,V.RazonSocial AS Vendedor,Comision,K.CodTarCom AS CdTarifCom,DescripProd,Servcios,Tanques,CdTanque,CdMoneda,VrTasaCamb
,R.Fecha AS FecRemision,FechaDesp,DiasEntraga,FechaVence,IdCliente,T.RazonSocial AS Cliente,IdAgencia,Modalidad,Cantidad,R.Unidades AS TotalUnd
,DirEnvio,IdLocEnv,Localidad,NitContac,NomContac,TelContac,emlContac,CargoContac,NitEmpTrans,EmpTrans
,R.pVehiculo AS PlacaVeh,DetalleEnvio,TipPed,Pedido,IdCiaPed,FechaPed,CantObseq,VrIvaObseq
 FROM  Trn_Remision AS R INNER JOIN Trn_Kardex AS K ON R.TipDoc=K.TipDoc AND R.Remision=K.Documento AND R.IdCia=K.IdCia
 INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Terceros AS  V ON K.IdVend=V.IdTercero
 INNER JOIN Localidades AS L ON R.IdLocEnv=L.IdLocal
 WHERE R.Remision=@pmRemision AND R.IdCia=@pmIdCia
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemisionFac] @pmFactura INT,@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null
,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
 AS
 SELECT Remision,IdCia,Fecha,FechaDesp,FechaVence,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,Cantidad,Unidades
,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago
,MulPlazos,IdPlazo,CdRuta,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,DetalleEnvio,TipPed,Pedido,IdCiaPed,FechaPed,Modalidad
,R.Observacion AS Observ,TimeSys,IdCiaCrea
 FROM Trn_Remision AS R INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0  AND Factura<=@pmFactura
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 ORDER BY IdCia,Remision
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionFact]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemisionFact] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmRemisionIni INT=Null,@pmRemisionFin INT=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null
,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdProducto VARCHAR(16)=Null,@pmFechaFacIni SMALLDATETIME=Null,@pmFechaFacFin SMALLDATETIME=Null
,@pmTipoVentaIni INT=Null,@pmTipoVentaFin INT=Null
 AS
 SELECT O.Remision AS NumRemision,O.IdCia AS CdCia,Compania,O.Fecha AS FechaRem,FechaDesp,FechaVence,K.IdProducto AS CodProducto,DescripProd
,SUM(Salidas) AS CantPedido,SUM(K.Unidades) AS Unidades,SUM(K.NumFinal) AS RemCantFact
,MAX(CASE WHEN (K.TipOrd LIKE 'FC%' OR K.TipOrd LIKE 'FO%') THEN K.NumOrden ELSE 0 END) AS RemNumFac
,MAX(CASE WHEN (K.TipOrd LIKE 'FC%' OR K.TipOrd LIKE 'FO%') THEN K.IdCiaOrd ELSE 0 END) AS RemCiaFac
,TipoFact,ISNULL(NumFactura,0) AS NumFactura,ISNULL(CdCiaFac,'') AS CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,Unidad,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,Modalidad,O.IdConcepto AS CdConcepto,Concepto
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,O.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,NumAprob,TipPed,Pedido,IdCiaPed,FechaPed,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
 FROM Trn_Remision AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado  INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia 
 INNER JOIN Trn_Kardex AS K ON O.TipDoc=K.TipDoc AND O.Remision=K.Documento AND O.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd 
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN (SELECT  Remision,IdCiaRem,K.TipDoc AS TipoFact,K.Documento AS NumFactura,K.IdCia AS CdCiaFac,KC.Compania AS NomCiaFac
  ,TipOrd,NumOrden,IdCiaOrd,K.Fecha AS FecFactura,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd
,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrPrecio) AS VrPrecioUnit,SUM(VrIvaEnt) AS IvaEntradas
,SUM(VrIvaSal) AS IvaSalidas,SUM(VrDctoEnt) AS DctoEntradas,SUM(VrDctoSal) AS DctoSalidas,SUM(K.Unidades) AS TotalUnidades
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 WHERE NoVentas BETWEEN ISNULL(@pmTipoVentaIni,1) AND ISNULL(@pmTipoVentaFin,4) AND Remision>0
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (Fecha>=ISNULL(@pmFechaFacIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFacFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY  Remision,IdCiaRem,K.TipDoc,K.Documento,K.IdCia,KC.Compania,TipOrd,NumOrden,IdCiaOrd,K.Fecha,K.IdProducto,PM.DescripProd) AS FA 
 ON  O.Remision=FA.Remision AND O.IdCia=FA.IdCiaRem AND K.IdProducto=FA.CdProducto
 WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Anulado=0
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')  AND  O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND O.Remision  BETWEEN ISNULL(@pmRemisionIni,0) AND ISNULL(@pmRemisionFin,2147483647)
 AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 GROUP BY O.Remision,O.IdCia,Compania,O.Fecha,FechaDesp,FechaVence,K.IdProducto,DescripProd
,TipoFact,NumFactura,CdCiaFac,NomCiaFac,FecFactura,CantEntradas,CantSalidas,VrPrecioUnit,IvaEntradas,IvaSalidas,DctoEntradas,DctoSalidas,TotalUnidades
,Unidad,IdCliente,T.RazonSocial,O.IdAgencia,Agencia,CodAgencia,Modalidad,O.IdConcepto,Concepto
,O.IdVend,VN.RazonSocial,O.IdLocEnv,LE.Localidad,LE.IdDep,DE.Departamento
,NumAprob,TipPed,Pedido,IdCiaPed,FechaPed,O.Observacion,O.IdEstado,Estado
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemisionLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmRemisionIni INT=Null,@pmRemisionFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS
 SELECT Remision,IdCia,Fecha,FechaDesp,FechaVence,R.IdConcepto AS CdConcepto,Concepto,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto
,Cantidad,Unidades,IdVend,V.RazonSocial AS Vendedor,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdRuta,NitEmpTrans,EmpTrans
,pVehiculo,CdConductor,DetalleEnvio,TipFac,Factura,IdCiaFac,FechaFact,TipPed,Pedido,IdCiaPed,FechaPed,NumAutoriza,NumAprob,FecAprob,CdUsuAprob,Modalidad,OrigenAdd,Anulado,FecDev
,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Remision AS R INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON R.IdVend=V.IdTercero
 INNER JOIN  Conceptos AS CN ON R.IdConcepto=CN.IdConcepto
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Remision BETWEEN ISNULL(@pmRemisionIni,0) AND ISNULL(@pmRemisionFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Remision
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionPed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRemisionPed] @pmPedido INT,@pmIdCiaPed CHAR(2),@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT R.Remision AS NumRemision,R.IdCia AS CodCia,R.Fecha AS FechaRem,FechaVence,IdCliente,RazonSocial,IdAgencia,Item,IdProducto,Descripcion,K.IdBodega AS CdBodega,Bodega
,CdTanque,Salidas,VrPrecio,VrPrecio*Salidas AS SubTotal,TarifaIva,VrIvaSal,TarifaDct,VrDctoSal,((VrPrecio*Salidas)-TarifaDct)+TarifaIva AS SValTotal,VrUnitario
,VrCostoSal,TarifaRet,VrReteSal,TarifaIca,VrIcaSal,VrBruto,ListaPrec,VrBase,CdMoneda,VrTasaCamb,K.IdVend AS CedVend,Comision,Referencia,K.Unidades AS Unddes,R.Factura AS NumFactura,IdCiaFac,FechaFact
 FROM Trn_Remision AS R INNER JOIN Trn_Kardex AS  K ON R.Remision=K.Documento AND R.IdCia=K.IdCia
 AND R.TipDoc=K.TipDoc  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 WHERE TipPed='PED' AND Pedido=@pmPedido AND IdCiaPed=@pmIdCiaPed  AND Anulado=0
AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
ORDER BY R.IdCia,R.Remision,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRemisionRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRemisionRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdLocEnv VARCHAR(8)=Null
,@pmModalidad VARCHAR(10)=Null,@pmCdRuta VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
 AS
 SELECT TipDoc,Remision,O.IdCia AS CdCia,Compania,Fecha,FechaDesp,FechaVence,O.IdConcepto AS CdConcepto,Concepto
,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS IdAgenc,Agencia,CodAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,Unidades
,O.IdVend AS NitVendedor,VN.RazonSocial AS Vendedor,TarifaCom,DirEnvio,O.IdLocEnv AS CodCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DiasEntraga,O.NitContac AS RemNitContac,O.NomContac AS RemNomContac,O.TelContac AS RemTelContac,O.emlContac AS RemEmailContac,CargoContac,O.IdForma AS CdForma,FormaPago
,DetallePago,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,CdRuta,Ruta,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,TC.RazonSocial AS Conductor,DetalleEnvio,TipFac,Factura,IdCiaFac,FechaFact
,TipPed,Pedido,IdCiaPed,FechaPed,NumAutoriza,NumAprob,FecAprob,CdUsuAprob,Modalidad,CdBodega,DesBodega,OrigenAdd,Anulado,FecDev
,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,TimeSys,O.FecUpdate AS Fec_Update,IdCiaCrea,O.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,DirAgncia,TelAgncia,FaxAgncia,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
 FROM Trn_Remision AS O  INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN  Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN  Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo INNER JOIN  Terceros AS VN ON O.IdVend=VN.IdTercero
 INNER JOIN Agencias  AS A ON O.IdAgencia=A.IdAgencia  INNER JOIN Formaspago AS FP ON O.IdForma=FP.IdForma
 INNER JOIN TercCliente AS CLI ON O.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Localidades AS LE ON O.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep 
 LEFT JOIN Terceros AS TC ON O.CdConductor=TC.IdTercero LEFT JOIN Rutas AS R ON O.CdRuta=R.IdRuta
 --subconsulta para filtrar por bodega
 LEFT JOIN (SELECT K.TipDoc AS CdTipDoc,K.Documento AS NumDoc,K.IdCia AS CodCia,K.IdBodega AS CdBodega,Bodega AS DesBodega,SUM(K.Salidas) AS SSAL
 FROM Trn_Kardex AS K INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega WHERE K.TipDoc='REM' AND Item=1 GROUP BY K.TipDoc,K.Documento,K.IdCia,K.IdBodega,Bodega) 
 AS KD ON O.TipDoc=KD.CdTipDoc AND O.Remision=KD.NumDoc AND O.IdCia=KD.CodCia
 WHERE O.TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND O.IdCia LIKE ISNULL(@pmIdCia,'%%') AND O.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND O.IdAgencia LIKE ISNULL(@pmIdAgencia ,'%')
 AND O.IdVend LIKE ISNULL(@pmIdVend,'%') AND O.IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND CdRuta LIKE ISNULL(@pmCdRuta,'%')
 AND  O.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY O.IdCia,Remision
GO
/****** Object:  StoredProcedure [dbo].[paQryReport]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryReport] @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2)
 AS 
 SELECT TipoRep,NomRep,IdRep,Descripcion,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
 FROM Sys_Report
 WHERE TipoRep like ISNULL(@pmTipoRep,'%')  AND IdRep like ISNULL(@pmIdRep,'%%')
 ORDER BY TipoRep, IdRep
GO
/****** Object:  StoredProcedure [dbo].[paQryReportDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportDso] @pmTipoRep VARCHAR(3)
AS
 SELECT  TipoRep, IdRep,Descripcion,IdRep+ '  '+Descripcion AS DsRep,Formato
 FROM   Sys_Report
 WHERE TipoRep=@pmTipoRep
 ORDER BY IdRep
GO
/****** Object:  StoredProcedure [dbo].[paQryReportFmto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportFmto] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
 AS 
 SELECT TipoRep,Formato,TipoOrigen,CrVersion,sp_Nombre,Ind_Location
 FROM Sys_ReportFmto
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryReportFmtoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportFmtoLta] @pmTipoRep VARCHAR(10)=Null
 AS 
 SELECT TipoRep,Formato,TipoOrigen,CrVersion,sp_Nombre,Ind_Location
 FROM Sys_ReportFmto
 WHERE TipoRep LIKE ISNULL(@pmTipoRep,'%')
 ORDER BY Formato
GO
/****** Object:  StoredProcedure [dbo].[paQryReportGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportGru]
AS
 SELECT TipoRep,NomRep,count(IdRep) AS Cuenta
 FROM   Sys_Report
 GROUP BY  TipoRep,NomRep
GO
/****** Object:  StoredProcedure [dbo].[paQryReportSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportSub] @pmTipoRep VARCHAR(10)
,@pmFormato VARCHAR(20),@pmNombreSub VARCHAR(20)
 AS 
 SELECT TipoRep,Formato,NombreSub,TipoOrigen,sp_Nombre,Ind_Location
 FROM Sys_ReportSub
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato AND NombreSub=@pmNombreSub
GO
/****** Object:  StoredProcedure [dbo].[paQryReportSubLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportSubLta] @pmTipoRep VARCHAR(10)=Null,@pmFormato VARCHAR(20)=Null
 AS 
 SELECT TipoRep,Formato,NombreSub,TipoOrigen,sp_Nombre,Ind_Location
 FROM Sys_ReportSub
 WHERE TipoRep like ISNULL(@pmTipoRep,'%') AND Formato LIKE ISNULL(@pmFormato,'%')
 ORDER BY Formato,NombreSub
GO
/****** Object:  StoredProcedure [dbo].[paQryReportSubPmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReportSubPmt] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmNombreSub VARCHAR(20),@pmIndParam INT
 AS 
 SELECT TipoRep,Formato,NombreSub,IndParam,NomParam,TipoDato,ValorPred
 FROM Sys_ReportSubPmt
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato  AND NombreSub LIKE ISNULL(@pmNombreSub,'%')
 AND (IndParam>=ISNULL(@pmIndParam,0)  AND IndParam<=ISNULL(@pmIndParam,2147483647))
 ORDER BY IndParam
GO
/****** Object:  StoredProcedure [dbo].[paQryReqDetalle]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryReqDetalle] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,CdProducto,Descripcion,Cantidad,IdUnd,IdSubgrupo,VrUnitario
,TipOrd,NumOrden,IdCiaOrd,Cant_Orden,TipSal,NSalida,IdCiaSal,FechaSal,CdBodega,Referencia
,CantSalida,CantDevSal,CodCCtoDet,CodSCtoDet,PlacaVehDet
 FROM Trn_ReqDetalle
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicion] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Requisicion,IdCia,Fecha,FechaVence,IdConcepto,IdRespons,IdCCosto,IdSubCos,IdDep,VrSubTotal,Cantidad
,NContrato,IdCiaCont,NitCliente,CdAgencia,Modalidad,DirEntrega,IdLocEnt,TipSal,NumSalida,IdCiaSal,FechaSal
,NumAprob,FecAprob,CdUsuAprob,NivelAprob,NomContacto,TelsContacto,EmailContacto,Num_Vehic,Num_Trailer,TipoVigencia
,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Requisicion
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicion_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicion_Cr] @pmTipDoc VARCHAR(3),@pmRequisicionIni INT,@pmRequisicionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS CdTipo,TipoDoc,R.Requisicion AS NumRequis,R.IdCia AS CdCia,Compania,Fecha,FechaVence,R.IdConcepto AS CdConcepto,Concepto,IdRespons,T.RazonSocial AS NomResponsable
,R.IdCCosto AS CdCentCosto,CC.CCosto,R.IdSubCos AS CdSubCent,SC.SubCosto,R.IdDep AS CdDep,Dependencia,VrSubTotal,R.Cantidad AS CantTotal,R.NContrato AS NumContrato,IdCiaCont
,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,Agencia,CodAgencia,Modalidad,DirEntrega,IdLocEnt,Localidad,Departamento,R.TipSal AS Tip_Sal,NumSalida,R.IdCiaSal AS CdCiaSal
,R.FechaSal AS Fec_Salida,NumAprob,FecAprob,CdUsuAprob,NivelAprob,OrigenAdd,Anulado,NomContacto,TelsContacto,EmailContacto,Num_Vehic,Num_Trailer,TipoVigencia,FecDev,R.Observacion AS Observ
,R.IdEstado AS CdEstado,Estado,R.TimeSys,R.FecUpdate,R.IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario
,D.Item,CdProducto,Descripcion,D.Cantidad AS CantArt,D.IdUnd AS CdUnid,Unidad,D.IdSubgrupo AS CdSubgrupo,Subgrupo,VrUnitario,TipOrd,NumOrden,IdCiaOrd,D.TipSal AS DetTipoSal,NSalida,D.IdCiaSal AS DetCiaSal
,D.FechaSal AS DetFecSalida,CdBodega,Bodega,D.Referencia,D.CantSalida,D.CantDevSal,D.Cant_Orden,CodCCtoDet,CCD.CCosto AS DetCentro,CodSCtoDet,SCD.SubCosto AS DetSubCosto,D.PlacaVehDet
 FROM Trn_Requisicion AS R INNER JOIN Trn_ReqDetalle AS D ON R.TipDoc=D.TipDoc AND R.Requisicion=D.Requisicion AND R.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero
 INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto
 INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON D.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Localidades AS L ON R.IdLocEnt=L.IdLocal
 INNER JOIN Departamentos AS DT ON L.IdDep=DT.IdDep
 LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero
 LEFT JOIN Bodegas AS BG ON D.CdBodega =BG.IdBodega
 LEFT JOIN Agencias AS A ON R.CdAgencia=A.IdAgencia
 LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos
 LEFT JOIN CentroCosto AS CCD ON D.CodCCtoDet=CCD.IdCCosto
 LEFT JOIN SubCentros AS SCD ON D.CodSCtoDet=SCD.IdSubCos
 WHERE R.TipDoc=@pmTipDoc AND R.Requisicion BETWEEN  @pmRequisicionIni AND @pmRequisicionFin 
 AND R.IdCia=@pmIdCia 
 ORDER BY  R.Requisicion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionDet] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
 AS 
 SELECT Fecha,IdRespons,IdCCosto,IdSubCos,IdDep,NContrato,IdCiaCont,NitCliente,CdAgencia,Modalidad
,DirEntrega,IdLocEnt,NumAprob,FecAprob,CdUsuAprob,OrigenAdd,Anulado,FecDev,Observacion,IdEstado
,Item,CdProducto,Descripcion,IdSubgrupo,CdBodega,D.Cantidad AS CantArt,IdUnd,VrUnitario,D.Referencia
,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.Cant_Orden,D.CantSalida,D.CantDevSal,D.CodCCtoDet,D.CodSCtoDet,D.PlacaVehDet
,D.TipSal,D.NSalida,D.IdCiaSal,D.FechaSal
 FROM Trn_Requisicion AS R INNER JOIN Trn_ReqDetalle AS D ON R.TipDoc=D.TipDoc AND R.Requisicion=D.Requisicion
 AND R.IdCia=D.IdCia
 WHERE R.TipDoc=@pmTipDoc AND R.Requisicion=@pmRequisicion AND R.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionLta] @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmRequisicionIni INT=Null
,@pmRequisicionFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdRespons VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmAnulado BIT=Null
,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT Requisicion,IdCia,Fecha,FechaVence,R.IdConcepto AS CdConcepto,Concepto,IdRespons,T.RazonSocial AS NomResponsable
,R.IdCCosto AS CdCentCosto,CCosto,R.IdSubCos AS CdSubCent,R.IdDep AS CdDep,Dependencia,VrSubTotal,Cantidad,NContrato,IdCiaCont
,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,Modalidad,DirEntrega,IdLocEnt,TipSal,NumSalida,IdCiaSal,FechaSal,NumAprob,FecAprob,CdUsuAprob,NivelAprob
,NomContacto,TelsContacto,EmailContacto,Num_Vehic,Num_Trailer,TipoVigencia,OrigenAdd,Anulado,FecDev,R.Observacion AS Observ
,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_Requisicion AS R INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero
 INNER JOIN  CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto
 INNER JOIN  Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN Dependencias AS D ON R.IdDep=D.IdDep
 LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero
 WHERE TipDoc='REQ' AND Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND IdRespons LIKE ISNULL(@pmIdRespons,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND NitCliente LIKE ISNULL(@pmNitCliente,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 AND  Requisicion BETWEEN ISNULL(@pmRequisicionIni,0) AND ISNULL(@pmRequisicionFin,2147483647)
 ORDER BY IdCia,Requisicion
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionLtm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionLtm] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdCia CHAR(2)=Null,@pmModalidad VARCHAR(10)=Null
AS 
 SELECT R.Requisicion,R.IdCia AS CdCia,Compania,R.Fecha,FechaVence,R.NContrato AS NumOrden,R.IdCiaCont AS IdCiaOdt,R.Modalidad
,R.IdRespons AS CdOperario,T.RazonSocial AS Operario,Num_Vehic,Num_Trailer,R.NitCliente AS NitCentro,CL.RazonSocial AS NomCentroServ
,DirEntrega,IdLocEnt,Localidad,R.IdDep AS CdDep,Dependencia,VrSubTotal,Cantidad,NumAprob,FecAprob,CdUsuAprob
,TipSal,NumSalida,IdCiaSal,FechaSal,R.IdConcepto AS CdConcepto,Concepto,R.IdCCosto AS CdCCosto,CCosto,R.IdSubCos AS CdSubCos
,NomContacto,TelsContacto,EmailContacto,TipoVigencia,R.Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado
,OrigenAdd,R.TimeSys,R.FecUpdate,R.IdCiaCrea,R.IdUsuario AS CdUsuario,Usuario
 FROM Trn_Requisicion AS R INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto
 INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario INNER JOIN Dependencias AS D ON R.IdDep=D.IdDep
 LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero LEFT JOIN Localidades AS L ON R.IdLocEnt=L.IdLocal
 WHERE R.TipDoc=@pmTipDoc AND R.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.Modalidad LIKE ISNULL(@pmModalidad,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionMtto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionMtto] @pmTipDoc VARCHAR(3),@pmRequisicionIni INT,@pmRequisicionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS CdTipo,TipoDoc,R.Requisicion,R.IdCia AS CdCia,Compania,Fecha,FechaVence,R.IdConcepto AS CdConcepto,Concepto,R.IdRespons AS CdOperario,T.RazonSocial AS NomOperario
,R.IdCCosto AS CdCCosto,CCosto,R.IdSubCos AS CdSubCos,R.IdDep AS CdDep,Dependencia,VrSubTotal,R.Cantidad AS CantTotal,R.NContrato AS NumOrden,R.IdCiaCont AS CdCiaOrden,R.Num_Vehic,R.Num_Trailer
,R.NitCliente AS NitCentServ,CL.RazonSocial AS NomCentServ,R.Modalidad,DirEntrega,R.IdLocEnt,Localidad,Departamento,NumAprob,FecAprob,CdUsuAprob,OrigenAdd,R.Anulado
,NomContacto,TelsContacto,EmailContacto,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,R.TimeSys AS FecCrea,R.FecUpdate,R.IdCiaCrea,R.IdUsuario AS CdUsuario,U.Usuario
,Item,TipoItem,D.IdProducto AS CdProducto,D.Descripcion,DescripProd,D.Cantidad,D.IdUnd AS CdUnd,Unidad,D.VrUnitario,D.CdBodega,Bodega,TipoRef,D.TipOdt,D.NumOrden AS Num_Orden,D.IdCiaOdt,EstadoReq
,D.TipSal,D.NumSalida,D.IdCiaSal,D.CantSalida,D.IdOperario AS DetIdOperario,NP.RazonSocial AS DetOperario,D.CdCenServ,CentroServ,D.NitTercero,NC.RazonSocial
,D.NumVehic,D.NumParte,D.VrPrecioUnd,D.Observacion AS DetObserv,D.FechaCrea AS DetFecCrea,D.IdUsuario AS DetCdUsuario,DU.Usuario AS DetUsuario
,T.TipoId,T.Codigo,T.Dv,T.Telefono,T.TelMovil,T.e_mail
 FROM Trn_Requisicion AS R INNER JOIN Trn_MttoOrdenReq AS D ON R.TipDoc=D.TipReq AND R.Requisicion=D.Requisicion AND R.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario 
 INNER JOIN CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep
 INNER JOIN Localidades AS L ON R.IdLocEnt=L.IdLocal INNER JOIN Departamentos AS DT ON L.IdDep=DT.IdDep
 INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd
 LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero LEFT JOIN Terceros AS NP ON D.IdOperario=NP.IdTercero
 LEFT JOIN Terceros AS NC ON D.NitTercero=NC.IdTercero LEFT JOIN Bodegas AS BG ON D.CdBodega=BG.IdBodega
 LEFT JOIN CentrosServ AS CS ON D.CdCenServ=CS.IdCenSer LEFT JOIN adm_Usuarios AS DU ON D.IdUsuario=DU.IdUsuario 
 WHERE R.TipDoc=@pmTipDoc AND R.Requisicion BETWEEN  @pmRequisicionIni AND @pmRequisicionFin AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionOrd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionOrd] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRespons VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null
 AS 
 SELECT R.Requisicion AS NumRequision,R.IdCia AS CdCia,Compania,Fecha,FechaVence,R.IdConcepto AS CdConcepto,Concepto,IdRespons,T.RazonSocial AS Responsable
,R.IdCCosto AS CdCentCosto,CCosto,R.IdSubCos AS CdSubCent,SubCosto,R.IdDep AS CdDep,Dependencia,R.NContrato AS NumContrato,IdCiaCont,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,Modalidad
,VrSubTotal,R.Cantidad AS CantTotal,DirEntrega,IdLocEnt,Localidad,NumAprob,FecAprob,R.Num_Vehic,R.Num_Trailer,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado
--detalles
,Item,CdProducto,D.Descripcion AS DescProd,D.IdSubgrupo AS CdSubgrupo,Subgrupo,CdBodega,Bodega,D.Cantidad AS CantArtic,D.IdUnd AS CdUnidad,Unidad,VrUnitario,TipOrd,NumOrden,IdCiaOrd
,D.TipSal AS TipoSal,D.NSalida AS NumSalida,D.IdCiaSal AS CdCiaSal,D.FechaSal AS FecSalida,D.Referencia
--datos del cliente
,CL.TipoId AS TercTipo,CL.Dv AS TercDv,CL.Codigo AS TercCodigo,CL.NomCial AS TercNomCial,CL.SiglaRaz AS TercSigal,CL.Direccion AS TercDireccion
 FROM Trn_Requisicion AS R INNER JOIN Trn_ReqDetalle AS D ON R.TipDoc=D.TipDoc AND R.Requisicion=D.Requisicion AND R.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero  INNER JOIN  CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto
 INNER JOIN Conceptos AS C ON R.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep
 INNER JOIN SubGrupos AS SG ON D.IdSubgrupo=SG.IdSubgrupo  INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd 
 LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero LEFT JOIN TercCliente AS CLI ON R.NitCliente=CLI.IdClie
 LEFT JOIN SubCentros AS SC ON R.IdSubCos=SC.IdSubCos LEFT JOIN Localidades AS LC ON R.IdLocEnt=LC.IdLocal
 LEFT JOIN Bodegas AS B ON D.CdBodega=B.IdBodega
 WHERE R.TipDoc=@pmTipDoc AND R.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdRespons LIKE ISNULL(@pmIdRespons,'%') AND NitCliente LIKE ISNULL(@pmNitCliente,'%')
 ORDER BY  R.IdCia,R.Requisicion
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionPen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionPen] @pmRequisicionIni INT=Null,@pmRequisicionFin INT=Null,@pmIdCia CHAR(2)=Null
,@pmIdRespons VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT  R.Requisicion AS NumRequis,R.IdCia AS CdCia,Fecha,FechaVence,IdRespons,T.RazonSocial AS NomResponsable
,Item,CdProducto,Descripcion,D.Cantidad AS CantArt,D.IdUnd AS CdUnid,Unidad,VrUnitario,D.Cantidad*VrUnitario AS ValorTotal
,R.IdConcepto AS CdConcepto,Concepto,R.IdCCosto AS CdCentCosto,CCosto,R.IdSubCos AS CdSubCent,R.IdDep AS CdDep,Dependencia
,NContrato,IdCiaCont,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,R.Num_Vehic,R.Num_Trailer,Modalidad,DirEntrega,NumAprob,FecAprob,CdUsuAprob
,R.Observacion AS Observ,TipOrd,NumOrden,IdCiaOrd,NomContacto,TelsContacto,EmailContacto,D.Referencia
 FROM Trn_Requisicion AS R INNER JOIN Trn_ReqDetalle AS D ON R.TipDoc=D.TipDoc AND R.Requisicion=D.Requisicion AND R.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero
 INNER JOIN  CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto
 INNER JOIN  Conceptos AS C ON R.IdConcepto=C.IdConcepto
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd
 LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero
 WHERE R.TipDoc='REQ' AND R.Anulado=0 AND R.IdEstado='0001' AND NumAprob>0
 AND  R.Requisicion BETWEEN ISNULL(@pmRequisicionIni,0) AND ISNULL(@pmRequisicionFin,2147483647)
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdRespons LIKE ISNULL(@pmIdRespons,'%')
 AND NitCliente LIKE ISNULL(@pmNitCliente,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY R.IdCia,R.Requisicion,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryRequisicionSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRequisicionSal] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME
,@pmRequisicionIni INT=Null,@pmRequisicionFin INT=Null,@pmIdCia CHAR(2)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdRespons VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null,@pmNitCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdDep VARCHAR(4)=Null,@pmFechaSalIni SMALLDATETIME=Null,@pmFechaSalFin SMALLDATETIME=Null
 AS 
 SELECT R.Requisicion AS NumRequision,R.IdCia AS CdCia,Compania,Fecha,FechaVence,D.IdSubgrupo AS CodSubgrupo,Subgrupo,SUM(D.Cantidad) AS CantReq
,D.IdUnd AS CdUnidad,Unidad
,TipoSalida,SD.NumSalida AS NroSalida,CdCiaSal,NomCiaSal,FecSalida,NumEntrada,CiaEntrada,SD.CdProducto AS CodProducto,NombreProd,CantEntradas,CantSalidas
,ValorUnit,CostoEntradas,CostoSalidas,TotalUnidades
,D.NumOrden AS NumOCompra,D.IdCiaOrd AS CdCiaOcompra,R.IdConcepto AS CdConcepto,Concepto,IdRespons,T.RazonSocial AS NomResponsable
,R.IdCCosto AS CdCentCosto,CCosto,R.IdSubCos AS CdSubCent,R.IdDep AS CdDep,Dependencia,NContrato,IdCiaCont,Num_Vehic,Num_Trailer
,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,Modalidad,NumAprob,FecAprob,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado
 FROM Trn_Requisicion AS R  INNER JOIN  Trn_ReqDetalle AS D ON R.TipDoc=D.TipDoc AND R.Requisicion=D.Requisicion AND R.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON R.IdRespons=T.IdTercero  INNER JOIN  CentroCosto AS CC ON R.IdCCosto=CC.IdCCosto
 INNER JOIN  Conceptos AS C ON R.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN  SubGrupos AS SG ON D.IdSubgrupo=SG.IdSubgrupo
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd 
 INNER JOIN Dependencias AS DP ON R.IdDep=DP.IdDep  LEFT JOIN Terceros AS CL ON R.NitCliente =CL.IdTercero
 LEFT JOIN (SELECT TipOrd,NumOrden,IdCiaOrd,K.TipDoc AS TipoSalida,K.Documento AS NumSalida,K.IdCia AS CdCiaSal,KC.Compania AS NomCiaSal
,K.Fecha AS FecSalida,K.Remision AS NumEntrada,K.IdCiaRem AS CiaEntrada,K.IdProducto AS CdProducto,PM.DescripProd AS NombreProd
,PM.IdSubgrupo AS CdSubgrupo,SG.Subgrupo AS NomSubgrupo,SUM(Entradas) AS CantEntradas,SUM(Salidas) AS CantSalidas,MAX(VrUnitario) AS ValorUnit,SUM(VrCostoEnt) AS CostoEntradas,SUM(VrCostoSal) AS CostoSalidas
,SUM(K.Unidades) AS TotalUnidades
 FROM Trn_Kardex AS K INNER JOIN Companias AS KC ON K.IdCia=KC.IdCia  INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo  WHERE TipDoc IN ('SAI','DSI','SAL','DVS') AND TipOrd=@pmTipDoc AND NumOrden>0 
 AND (Fecha>=ISNULL(@pmFechaSalIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaSalFin,CAST('20781230' AS SMALLDATETIME)))
 GROUP BY TipOrd,NumOrden,IdCiaOrd,K.TipDoc,K.Documento,K.IdCia,KC.Compania,K.Fecha,K.Remision ,K.IdCiaRem,K.IdProducto,PM.DescripProd
,PM.IdSubgrupo,SG.Subgrupo) AS SD ON R.TipDoc=SD.TipOrd AND R.Requisicion=SD.NumOrden AND R.IdCia=SD.IdCiaOrd AND D.IdSubgrupo=SD.CdSubgrupo
 WHERE R.TipDoc=@pmTipDoc AND R.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND Anulado=0 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND IdRespons LIKE ISNULL(@pmIdRespons,'%')
 AND R.IdCCosto LIKE ISNULL(@pmIdCCosto,'%') AND NitCliente LIKE ISNULL(@pmNitCliente,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND R.IdDep LIKE ISNULL(@pmIdDep,'%')
 AND  R.Requisicion BETWEEN ISNULL(@pmRequisicionIni,0) AND ISNULL(@pmRequisicionFin,2147483647)
 GROUP BY  R.Requisicion,R.IdCia,Compania,Fecha,FechaVence,D.IdSubgrupo,Subgrupo,D.IdUnd,Unidad
,TipoSalida,SD.NumSalida,CdCiaSal,NomCiaSal,FecSalida,NumEntrada,CiaEntrada,SD.CdProducto,NombreProd,CantEntradas,CantSalidas
,ValorUnit,CostoEntradas,CostoSalidas,TotalUnidades
,D.NumOrden,D.IdCiaOrd,R.IdConcepto,Concepto,IdRespons,T.RazonSocial,R.IdCCosto,CCosto,R.IdSubCos
,R.IdDep,Dependencia,NContrato,IdCiaCont,Num_Vehic,Num_Trailer,NitCliente,CL.RazonSocial,CdAgencia,Modalidad,NumAprob,FecAprob
,R.Observacion,R.IdEstado,Estado
GO
/****** Object:  StoredProcedure [dbo].[paQryResiduosPeligrosos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryResiduosPeligrosos] @pmCodigoUN VARCHAR(30)
 AS 
 SELECT CodigoUN,Designacion,Clase,PeligroSec,GrupoEmb,IdCoRes,IdCRdes,Inactivo
 FROM ResiduosPeligrosos
 WHERE CodigoUN=@pmCodigoUN
GO
/****** Object:  StoredProcedure [dbo].[paQryResiduosPeligrososLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryResiduosPeligrososLta] @pmInactivo BIT=Null
 AS 
 SELECT R.CodigoUN,R.Designacion,R.Clase,R.PeligroSec,R.GrupoEmb
,R.IdCoRes,C.CodigoCR,C.GrupoRP,C.CorrResiduo,R.IdCRdes,D.CodigoDR,D.Desagregacion,R.Inactivo
 FROM ResiduosPeligrosos AS R LEFT JOIN CorrResiduos AS C ON R.IdCoRes=C.IdCorr
 LEFT JOIN Desagregaciones AS D ON R.IdCRdes=D.IdDrp
 WHERE (R.Inactivo=@pmInactivo OR @pmInactivo IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryRoles]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRoles] @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3)=Null
 AS 
 SELECT IdObj,IdRole,Funcion
 FROM Sys_Roles
 WHERE IdObj=@pmIdObj AND IdRole LIKE ISNULL(@pmIdRole,'%')
 ORDER BY IdRole
GO
/****** Object:  StoredProcedure [dbo].[paQryRutas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRutas] @pmIdRuta VARCHAR(4)
 AS 
 SELECT IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,CdCiaTurno,PuntosRut,Inactivo
 FROM Rutas
 WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasBus]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasBus] @pmEsLocal BIT=Null
 AS 
 SELECT IdRuta,Ruta,IdRuta+' '+Ruta  AS DsRut
 FROM Rutas
 WHERE  Inactivo=0  AND (EsLocal=ISNULL(@pmEsLocal,0) or EsLocal=ISNULL(@pmEsLocal,1))
 ORDER BY IdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasCiu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasCiu] @pmIdLocOri VARCHAR(8),@pmIdLocDes VARCHAR(8),@pmInactivo BIT=Null
 AS 
 SELECT IdRuta,Ruta,IdLocOri,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDptoOrig,D.Departamento AS DptoOrigen
,IdLocDes,LD.Localidad AS CiuDestino,LD.IdDep AS CdDptoDest,DD.Departamento AS DptoDestino
,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,PuntosRut,R.Inactivo AS Inactvo
 FROM Rutas AS R INNER JOIN Localidades AS LO ON R.IdLocOri=LO.IdLocal INNER JOIN Departamentos AS D ON LO.IdDep=D.IdDep
 INNER JOIN Localidades AS LD ON R.IdLocDes=LD.IdLocal INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 WHERE  IdLocOri=@pmIdLocOri AND  IdLocDes=@pmIdLocDes AND EsLocal=0
 AND (R.Inactivo=ISNULL(@pmInactivo,0) or  R.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasDso]  @pmIdLocOri VARCHAR(8)=Null,@pmIdLocDes VARCHAR(8)=Null,@pmEsLocal BIT=Null
 AS 
 SELECT IdRuta,Ruta,Ruta+' '+IdRuta+' ('+LO.Localidad+' - '+LD.Localidad+')' AS DsRut
 FROM Rutas AS R INNER JOIN Localidades AS LO ON R.IdLocOri=LO.IdLocal
 INNER JOIN Departamentos AS D ON LO.IdDep=D.IdDep
 INNER JOIN Localidades AS LD ON R.IdLocDes=LD.IdLocal
 INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 WHERE R.Inactivo=0 AND  IdLocOri like ISNULL(@pmIdLocOri,'%') AND IdLocDes LIKE ISNULL(@pmIdLocDes,'%')
 AND (EsLocal=ISNULL(@pmEsLocal,0) or EsLocal=ISNULL(@pmEsLocal,1))
 ORDER BY Ruta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRutasLta]  @pmIdLocOri VARCHAR(8)=Null,@pmIdLocDes VARCHAR(8)=Null,@pmEsLocal BIT=Null
 AS 
 SELECT IdRuta,Ruta,IdLocOri,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDptoOrig,D.Departamento AS DptoOrigen,IdLocDes
,LD.Localidad AS CiuDestino,LD.IdDep AS CdDptoDest,DD.Departamento AS DptoDestino,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,CdCiaTurno,PuntosRut,R.Inactivo AS Inactvo
 FROM Rutas AS R INNER JOIN Localidades AS LO ON R.IdLocOri=LO.IdLocal
 INNER JOIN Departamentos AS D ON LO.IdDep=D.IdDep
 INNER JOIN Localidades AS LD ON R.IdLocDes=LD.IdLocal
 INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 WHERE IdLocOri like ISNULL(@pmIdLocOri,'%') AND IdLocDes LIKE ISNULL(@pmIdLocDes,'%')
 AND (EsLocal=ISNULL(@pmEsLocal,0) OR EsLocal=ISNULL(@pmEsLocal,1))
 ORDER BY IdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasPlan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasPlan] @pmIdRuta VARCHAR(4),@pmIdPunto INT
 AS 
 SELECT  IdRuta,IdPunto,Descripcion,Distancia,Tiempo,ClasePto,CdPto,IdLocal,PosLat,PosLon,Inactivo
 FROM RutasPlan
 WHERE IdRuta=@pmIdRuta 
 AND (IdPunto>=ISNULL(@pmIdPunto,0)  AND IdPunto<=ISNULL(@pmIdPunto,2147483647))
 ORDER BY IdPunto
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasPlanItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasPlanItm] @pmIdRuta VARCHAR(4)
 AS 
 SELECT MAX(IdPunto) AS MXPUNTO
 FROM RutasPlan
 WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasPlanLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasPlanLta] @pmIdRuta VARCHAR(4)=Null,@pmIdLocOri VARCHAR(8)=Null,@pmIdLocDes VARCHAR(8)=Null
 AS 
 SELECT RP.IdRuta AS CdRuta,Ruta,IdLocOri,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDptoOrig,D.Departamento AS DptoOrigen,IdLocDes,LD.Localidad AS CiuDestino
,LD.IdDep AS CdDptoDest,DD.Departamento AS DptoDestino,IdPunto,Descripcion,Distancia,Tiempo,ClasePto,CdPto,PtoControl,Referencia
,Telefono,RP.IdLocal AS CdCiuPto,LP.Localidad AS CiudadPto,LP.IdDep AS CdDptoPto,DP.Departamento AS DptoPto,EsLocal,Distkmt,TmHoras,PosLat,PosLon
 FROM RutasPlan AS RP INNER JOIN Rutas AS R ON RP.IdRuta=R.IdRuta
 INNER JOIN Localidades AS LO ON R.IdLocOri=LO.IdLocal
 INNER JOIN Departamentos AS D ON LO.IdDep=D.IdDep
 INNER JOIN Localidades AS LD ON R.IdLocDes=LD.IdLocal
 INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 INNER JOIN Localidades AS LP ON RP.IdLocal=LP.IdLocal
 INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 LEFT JOIN Puestos AS P ON RP.CdPto=P.IdPto
 WHERE R.Inactivo=0 AND RP.Inactivo=0 AND RP.IdRuta LIKE ISNULL(@pmIdRuta,'%')
 AND IdLocOri like ISNULL(@pmIdLocOri,'%') AND IdLocDes LIKE ISNULL(@pmIdLocDes,'%') 
 ORDER BY Ruta,IdPunto
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasTra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasTra]  @pmEsLocal BIT=Null
 AS 
 SELECT IdRuta,Ruta,Ruta+' '+IdRuta AS DsRut,CodigoMt
 FROM Rutas 
 WHERE  Inactivo=0  
 AND (EsLocal=ISNULL(@pmEsLocal,0) or EsLocal=ISNULL(@pmEsLocal,1))
 ORDER BY Ruta
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasTramos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryRutasTramos] @pmIdRuta VARCHAR(4),@pmNumTramo INT
 AS 
 SELECT IdRuta,NumTramo,IdLocal,kmstramo,kmstotal
 FROM RutasTramos
 WHERE IdRuta=@pmIdRuta AND NumTramo=@pmNumTramo
GO
/****** Object:  StoredProcedure [dbo].[paQryRutasTramosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryRutasTramosLta] @pmIdRuta VARCHAR(4)=Null
 AS 
 SELECT  RT.IdRuta AS CdRuta,Ruta,NumTramo,RT.IdLocal AS CdLocal,LT.Localidad AS Ciudad,DT.Departamento AS Depto,kmstramo,kmstotal
,IdLocOri,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDptoOrig,D.Departamento AS DptoOrigen,IdLocDes,LD.Localidad AS CiuDestino,CodigoMt
,LD.IdDep AS CdDptoDest,DD.Departamento AS DptoDestino
 FROM RutasTramos AS RT INNER JOIN Rutas AS R ON RT.IdRuta=R.IdRuta
 INNER JOIN Localidades AS LT ON RT.IdLocal=LT.IdLocal  INNER JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 INNER JOIN Localidades AS LO ON R.IdLocOri=LO.IdLocal  INNER JOIN Departamentos AS D ON LO.IdDep=D.IdDep
 INNER JOIN Localidades AS LD ON R.IdLocDes=LD.IdLocal  INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 WHERE R.Inactivo=0 AND RT.IdRuta LIKE ISNULL(@pmIdRuta,'%')
 ORDER BY Ruta,NumTramo
GO
/****** Object:  StoredProcedure [dbo].[paQrySaiArticulos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySaiArticulos] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Salida,IdCia,Item,TipEnt,Entrada,IdCiaEnt,ItemEnt,IdProducto,IdBodega,Cantidad,VrUnitario
 FROM Trn_SaiArticulos
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCia=@pmIdCia 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidas] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Salida,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,VrImpuBA,VrImpuCUP
,TarifaIva,CodTarIva,TipOrd,NumOrden,IdCiaOrd,IdCCosto,IdSubCos,pVehiculo,Modalidad
,CdConductor,CdDep,NContrato,IdCiaCont ,NitCliente,CdAgencia,ModRequis,DirEntrega,IdLocEnt,GuiaComb,CdCiaGuia
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,NumDotac,DiaVigDot,FecVigDot,EdoDocEnt,NumDocEnt,CiaDocEnt
,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,OrigenAdd,IdUsuario
 FROM Trn_Salidas
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidas_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidas_Cr] @pmTipDoc VARCHAR(3),@pmSalidaIni INT,@pmSalidaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT S.TipDoc AS Tipo_Doc,TipoDoc,Salida,S.IdCia AS CdCia,Compania,S.Fecha AS FechaDoc,S.IdConcepto AS CdConcepto
,Concepto,S.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,S.TarifaIva AS TarifIva,S.VrImpuBA,S.VrImpuCUP
,S.TipOrd AS TipoOrden,S.NumOrden AS Num_Orden,S.IdCiaOrd AS CdCiaOrden,S.IdCCosto AS CdCentCosto,CC.CCosto AS CentCosto,S.IdSubCos AS CdSubCenCost,SC.SubCosto AS SubcCosto
,S.pVehiculo AS PlacaVeh,CdConductor,CDT.RazonSocial AS NomConductor,S.NContrato AS NumContrato,IdCiaCont
,NitCliente,CLI.RazonSocial AS NomCliente,S.CdAgencia AS IdAgncia,Agencia,CdDep,ModRequis,DirEntrega,IdLocEnt,LE.Localidad AS CiuEntrega,GuiaComb,CdCiaGuia,NumDotac,DiaVigDot,FecVigDot
,EdoDocEnt,NumDocEnt,CiaDocEnt,Modalidad,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,S.Observacion AS Observ,S.IdEstado AS CdEstado,Estado
,S.TimeSys AS Fec_Add,S.FecUpdate AS Fec_Update,IdCiaCrea,S.IdUsuario AS CdUsuario,Usuario,Leyenda
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--Detalle
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,VrPrecio,VrCostProm,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal
,VrCostoEnt,VrCostoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,K.IdTercero AS KarNitTercero,KT.RazonSocial AS KarNomTercero,K.CdAgencia AS KarIdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto
,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,CdLocal,KL.Localidad AS KarCiudad,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Comptmntos,CdProdEquiv,K.TipOrd AS KarTipOrden,K.NumOrden AS KarNumOrden,K.IdCiaOrd AS KarCiaOrden,Cotizacion,IdCiaCot
,Remision,IdCiaRem,K.Factura AS KarFactura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,K.CodTarBa,K.TarifaIba,K.VrImpuBa AS KarImpuBA,K.CodTarCup,K.TarifaCup,K.VrImpuCup AS KarImpuCup
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_Salidas AS S INNER JOIN Trn_Kardex AS K ON S.TipDoc=K.TipDoc AND S.Salida=K.Documento AND S.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON S.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON S.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON S.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON S.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON S.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON S.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd INNER JOIN Terceros AS KT ON K.IdTercero=KT.IdTercero
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN Localidades AS KL ON K.CdLocal=KL.IdLocal
 LEFT JOIN SubCentros AS SC ON S.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TC ON S.TipCom=TC.IdCom
 LEFT JOIN Terceros AS CLI ON S.NitCliente=CLI.IdTercero
 LEFT JOIN Terceros AS CDT ON S.CdConductor=CDT.IdTercero
 LEFT JOIN Agencias AS A ON S.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 WHERE S.TipDoc=@pmTipDoc AND Salida BETWEEN @pmSalidaIni AND  @pmSalidaFin AND S.IdCia=@pmIdCia
 AND EsProdBase=0
 ORDER BY Salida,Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasAdi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasAdi] @pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmModalidad VARCHAR(10)
 AS 
 SELECT COUNT(Salida) AS SCANSAL
 FROM Trn_Salidas 
 WHERE  IdCia=@pmIdCia AND Fecha=@pmFecha AND Modalidad=@pmModalidad AND Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmSalidaIni INT=Null,@pmSalidaFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmAnulado BIT=Null
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Salida,IdCia,Fecha,S.IdConcepto AS CdConcepto,Concepto,S.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,TarifaIva,CodTarIva
,TipOrd,NumOrden,IdCiaOrd,GuiaComb,CdCiaGuia,S.IdCCosto AS CdCcosto,CCosto,IdSubCos,pVehiculo,CdConductor,CdDep,NContrato,IdCiaCont ,NitCliente,CL.RazonSocial AS NomCliente,CdAgencia,ModRequis,DirEntrega,IdLocEnt
,Modalidad,NumDotac,DiaVigDot,FecVigDot,EdoDocEnt,NumDocEnt,CiaDocEnt,VrImpuBA,VrImpuCUP,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,S.Observacion AS Observ,S.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,OrigenAdd
,IdCiaCrea,S.IdUsuario AS IdUsuari,Usuario,TipDoc
 FROM Trn_Salidas AS S INNER JOIN Terceros AS T ON S.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON S.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON S.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON  S.IdCCosto=CC.IdCCosto
 LEFT JOIN Terceros AS CL ON S.NitCliente=CL.IdTercero
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Salida BETWEEN ISNULL(@pmSalidaIni,0) AND ISNULL(@pmSalidaFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND S.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND S.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND S.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY IdCia,Salida
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasNet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasNet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdLocEnt VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Salida,S.IdCia AS CdCia,Compania,Fecha,S.IdConcepto AS CdConcepto,Concepto,S.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrSubTotal
,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,TarifaIva,S.VrImpuBA,S.VrImpuCUP,TipOrd,NumOrden,IdCiaOrd,S.IdCCosto AS CdCentCosto,CCosto,S.IdSubCos AS CdSubCenCost,SubCosto
,pVehiculo,CdConductor,CDT.RazonSocial AS NomConductor,S.NContrato AS NumContrato,IdCiaCont,NitCliente,CLI.RazonSocial AS NomCliente
,S.CdAgencia AS IdAgncia,Agencia,CdDep,ModRequis,DirEntrega,IdLocEnt,LE.Localidad AS CiuEntrega
,Modalidad,GuiaComb,CdCiaGuia,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,S.Observacion AS Observ,S.IdEstado AS CdEstado,Estado
,TimeSys,S.FecUpdate AS Fec_Update,IdCiaCrea,S.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_Salidas AS S INNER JOIN Companias AS CN ON S.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON S.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON S.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON S.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON S.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN SubCentros AS SC ON S.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS CLI ON S.NitCliente=CLI.IdTercero
 LEFT JOIN Terceros AS CDT ON S.CdConductor=CDT.IdTercero
 LEFT JOIN Agencias AS A ON S.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND S.IdCia LIKE ISNULL(@pmIdCia,'%%') AND S.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND S.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND S.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')  AND IdLocEnt LIKE ISNULL(@pmIdLocEnt,'%')
 UNION 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,D.VrSubTotal AS SubTotal
,D.VrImpuesto AS Impuesto,D.VrCostos AS Costos,D.VrNeto AS TotalNeto,D.Cantidad AS CantDev,D.BaseImp AS VrBaseImp,TarifaIva,D.VrImpuBA,D.VrImpuCUP,D.TipOrd AS TipoOrd,D.NumOrden AS NOrden,D.IdCiaOrd AS CodCiaOrden
,D.IdCCosto AS IdCenCosto,CCosto,D.IdSubCos AS IdSubCosto,SubCosto,D.pVehiculo AS PlacaVeh,CdConductor,CDT.RazonSocial AS NomConductor,D.NContrato AS NumContrato,D.IdCiaCont AS CodCiaContrato
,D.NitCliente AS Nit_Cliente,CLI.RazonSocial AS NomCliente,D.CdAgencia AS Id_Agencia,Agencia,CdDep,D.ModRequis AS ModdReq,DirEntrega,IdLocEnt,LE.Localidad AS CiuEntrega,D.Modalidad AS ModSalida
,GuiaComb,CdCiaGuia,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CodCiaComp,0,D.Salida AS NumSalida,FecDoc
,D.Observacion AS Observ,D.IdEstado AS CdEstado,Estado,D.TimeSys AS Fec_Add,D.FecUpdate AS Fec_Update,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS IdUsuari,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_DevSal AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON D.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_Salidas AS S ON D.TipDoc=S.TipDoc AND D.Salida=S.Salida AND D.IdCiaDoc=S.IdCia
 LEFT JOIN Terceros AS CLI ON D.NitCliente=CLI.IdTercero
 LEFT JOIN Terceros AS CDT ON S.CdConductor=CDT.IdTercero
 LEFT JOIN Agencias AS A ON D.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 LEFT JOIN SubCentros AS SC ON D.IdSubCos=SC.IdSubCos
 WHERE D.TipDoc=@pmTipDoc  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND S.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND D.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND D.Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND D.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')  AND IdLocEnt LIKE ISNULL(@pmIdLocEnt,'%')
 ORDER BY S.IdCia,Salida
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasNetDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasNetDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
 SELECT S.TipDoc,S.Salida,S.IdCia AS CdCia,Compania,S.Fecha,S.IdConcepto AS CdConcepto,Concepto,S.IdTercero AS NitTercero,T.RazonSocial AS NomTercero
,S.VrSubTotal,S.VrImpuesto,S.VrCostos,S.VrNeto,S.BaseImp,S.TarifaIva,S.VrImpuBA,S.VrImpuCUP,S.TipOrd,S.NumOrden,S.IdCiaOrd
,S.pVehiculo,S.CdConductor,CDT.RazonSocial AS NomConductor,S.NContrato AS NumContrato,S.IdCiaCont,S.NitCliente,CLI.RazonSocial AS NomCliente
,S.CdAgencia AS IdAgncia,Agencia,S.CdDep AS CdDepend,S.ModRequis,S.DirEntrega,S.IdLocEnt,LE.Localidad AS CiuEntrega,S.Modalidad,S.GuiaComb,S.CdCiaGuia
--Detalles
,K.Item,K.IdProducto AS CdProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,K.Entradas,K.Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,K.VrUnitario
,VrCostoEnt,VrCostoSal,K.TarifaIva AS DetTarifIva,VrIvaEnt,VrIvaSal,K.VrCostProm,K.Unidades,K.Descripcion,K.Referencia,Referencia2
,K.TipOrd as DetTipOrd,K.NumOrden AS DetNumOrden,K.IdCiaOrd AS DetIdCiaOrd,K.TipDocDev,K.NumDocDev,K.VrBruto,K.VrBase,K.Servcios,K.EsCombo,K.EsProdBase,K.NumLote,K.FechLote,K.CdTanque,K.CdCCosto AS CdCentCosto,CCosto,K.CdSubCos AS CdSubCenCost,SubCosto
,S.TipCom,S.Comprobante,S.IdCiaCom,S.Anulado,S.NumDev,S.FecDev,S.Observacion AS Observ,S.IdEstado AS CdEstado,Estado,S.TimeSys,S.FecUpdate AS Fec_Update,S.IdCiaCrea,S.IdUsuario AS CdUsuario,Usuario
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_Salidas AS S INNER JOIN Trn_Kardex AS K ON S.TipDoc=K.TipDoc AND S.Salida=K.Documento AND S.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON S.IdCia=CN.IdCia INNER JOIN Terceros AS T ON S.IdTercero=T.IdTercero 
 INNER JOIN Conceptos AS C ON S.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON S.IdEstado=ED.IdEstado 
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS CLI ON S.NitCliente=CLI.IdTercero
 LEFT JOIN Terceros AS CDT ON S.CdConductor=CDT.IdTercero
 LEFT JOIN Agencias AS A ON S.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 WHERE S.TipDoc=@pmTipDoc  AND S.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND S.IdCia LIKE ISNULL(@pmIdCia,'%%')
 UNION ALL
 SELECT D.TipDev,D.Devolucion,D.IdCia,Compania,D.Fecha,D.IdConcepto,Concepto,D.IdTercero,T.RazonSocial,D.VrSubTotal
,D.VrImpuesto,D.VrCostos,D.VrNeto,D.BaseImp,S.TarifaIva,D.VrImpuBA,D.VrImpuCUP,D.TipOrd,D.NumOrden,D.IdCiaOrd
,D.pVehiculo,S.CdConductor,CDT.RazonSocial,D.NContrato,D.IdCiaCont
,D.NitCliente,CLI.RazonSocial,D.CdAgencia,Agencia,CdDep,D.ModRequis,DirEntrega,IdLocEnt,LE.Localidad,D.Modalidad,GuiaComb,CdCiaGuia
,K.Item,K.IdProducto,DescripProd,K.IdBodega,Bodega,K.Entradas,K.Salidas,K.IdUnd,UM.Unidad,K.VrUnitario
,VrCostoEnt,VrCostoSal,K.TarifaIva,VrIvaEnt,VrIvaSal,K.VrCostProm,K.Unidades,K.Descripcion,K.Referencia,Referencia2
,K.TipOrd,K.NumOrden,K.IdCiaOrd,TipDocDev,K.NumDocDev,K.VrBruto,K.VrBase,K.Servcios,K.EsCombo,K.EsProdBase,K.NumLote,K.FechLote,K.CdTanque,K.CdCCosto,CCosto,K.CdSubCos,SubCosto
,D.TipCom,D.Comprobante,D.IdCiaCom,0,D.Salida,D.FecDoc,D.Observacion,D.IdEstado,Estado,D.TimeSys,D.FecUpdate,D.IdCiaCrea,D.IdUsuario,Usuario
,T.TipoId,T.Dv,T.Codigo,T.NomCial,T.Direccion,T.IdLocal,L.Localidad,L.IdDep,Departamento
,T.Telefono,T.Fax,T.e_mail,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
 FROM Trn_DevSal AS D INNER JOIN Trn_Salidas AS S ON D.TipDoc=S.TipDoc AND D.Salida=S.Salida AND D.IdCiaDoc=S.IdCia
 INNER JOIN Trn_Kardex AS K ON D.TipDev=K.TipDoc AND D.Devolucion=K.Documento AND D.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 LEFT JOIN Terceros AS CLI ON D.NitCliente=CLI.IdTercero LEFT JOIN Terceros AS CDT ON S.CdConductor=CDT.IdTercero
 LEFT JOIN Agencias AS A ON D.CdAgencia=A.IdAgencia LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos
 WHERE D.TipDoc=@pmTipDoc  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasOrd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasOrd]  @pmNumOrden INT,@pmTipOrd VARCHAR(3)
,@pmIdCiaOrd CHAR(2),@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Salida,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,VrImpuesto,VrCostos,VrNeto,Modalidad
,TipOrd,NumOrden,IdCiaOrd
 FROM Trn_Salidas
 WHERE NumOrden=@pmNumOrden AND Anulado=0 AND TipOrd LIKE ISNULL(@pmTipOrd,'%')
 AND IdCiaOrd LIKE ISNULL(@pmIdCiaOrd,'%%') AND  Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,Salida
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdLocEnt VARCHAR(8)=Null,@pmModalidad VARCHAR(10)=Null
,@pmAnulado BIT=Null
 AS 
 SELECT TipDoc,Salida,S.IdCia AS CdCia,Compania,Fecha,S.IdConcepto AS CdConcepto,Concepto,S.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,VrSubTotal
,VrImpuesto,VrCostos,VrNeto,Cantidad,BaseImp,TarifaIva,TipOrd,NumOrden,IdCiaOrd,GuiaComb,CdCiaGuia,S.IdCCosto AS CdCentCosto,CCosto,S.IdSubCos AS CdSubCenCost,SubCosto
,pVehiculo,CdConductor,CDT.RazonSocial AS NomConductor,S.NContrato AS NumContrato,IdCiaCont,NitCliente,CLI.RazonSocial AS NomCliente
,S.CdAgencia AS IdAgncia,Agencia,CdDep,ModRequis,DirEntrega,IdLocEnt,LE.Localidad AS CiuEntrega,NumDotac,DiaVigDot,FecVigDot
,EdoDocEnt,NumDocEnt,CiaDocEnt,VrImpuBA,VrImpuCUP,Modalidad,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,S.Observacion AS Observ,S.IdEstado AS CdEstado,Estado
,TimeSys,S.FecUpdate AS Fec_Update,IdCiaCrea,OrigenAdd,S.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 FROM Trn_Salidas AS S INNER JOIN Companias AS CN ON S.IdCia=CN.IdCia 
 INNER JOIN Terceros AS T ON S.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON S.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON S.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON S.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN SubCentros AS SC ON S.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS CLI ON S.NitCliente=CLI.IdTercero
 LEFT JOIN Terceros AS CDT ON S.CdConductor=CDT.IdTercero
 LEFT JOIN Agencias AS A ON S.CdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 WHERE TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND S.IdCia LIKE ISNULL(@pmIdCia,'%%') AND S.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND S.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND S.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')  AND IdLocEnt LIKE ISNULL(@pmIdLocEnt,'%')
 AND (Anulado=ISNULL(@pmAnulado,0) or Anulado=ISNULL(@pmAnulado,1))
 ORDER BY S.IdCia,Salida
GO
/****** Object:  StoredProcedure [dbo].[paQrySalidasReq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySalidasReq]  @pmTipOrd  VARCHAR(3),@pmNumOrden  INT,@pmIdCiaOrd CHAR(2)
 AS 
 SELECT  Documento,K.IdCia AS CdCia,Compania,S.Fecha AS FechaDoc,Item,K.IdProducto AS CodProducto,DescripProd
,K.IdBodega AS CdBodega,Bodega,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario,Salidas*VrUnitario AS CostoTotal
,K.CdAgencia AS KarIdAgencia,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro
,CdLocal,KL.Localidad AS KarCiudad,K.pVehiculo AS KarPlacaVeh,K.Referencia AS KarReferencia,Descripcion,Remision,IdCiaRem,Unidades
,S.IdConcepto AS CdConcepto,Concepto,S.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,DirEntrega,IdLocEnt,LE.Localidad AS CiuEntrega
,S.Observacion AS Observ,TipCom,Comprobante,IdCiaCom
 FROM Trn_Salidas AS S INNER JOIN Trn_Kardex AS K ON S.TipDoc=K.TipDoc AND S.Salida=K.Documento AND S.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON K.IdCia=CN.IdCia
 INNER JOIN Terceros AS T ON S.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON S.IdConcepto=C.IdConcepto
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN Localidades AS KL ON K.CdLocal=KL.IdLocal
 LEFT JOIN Localidades AS LE ON S.IdLocEnt=LE.IdLocal
 WHERE S.TipDoc='SAI'  AND Anulado=0 AND K.TipOrd=@pmTipOrd  AND K.NumOrden=@pmNumOrden  AND K.IdCiaOrd=@pmIdCiaOrd
 ORDER BY Documento,Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySAutoriza]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySAutoriza] @pmIdConcepto VARCHAR(4)
 AS 
 IF @pmIdConcepto IS NULL
  SELECT IdConcepto,ConceptoAut,Inactivo
  FROM Sys_Autoriza
  ORDER BY IdConcepto
 ELSE
  SELECT IdConcepto,ConceptoAut,Inactivo
  FROM Sys_Autoriza
  WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQrySAutorizaDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySAutorizaDso]
 AS 
  SELECT IdConcepto,ConceptoAut,ConceptoAut+' '+IdConcepto AS DsCon
  FROM Sys_Autoriza
  WHERE Inactivo=0
  ORDER BY ConceptoAut
GO
/****** Object:  StoredProcedure [dbo].[paQrySectoresEco]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySectoresEco] @pmIdSector VARCHAR(8)
 AS 
 IF @pmIdSector IS NULL
  SELECT IdSector,SectorEco,CdTarifRtc
  FROM SectoresEco
  WHERE Inactivo=0
 ORDER BY SectorEco
 ELSE
  SELECT IdSector,SectorEco,CdTarifRtc,Inactivo
  FROM SectoresEco
  WHERE IdSector=@pmIdSector
GO
/****** Object:  StoredProcedure [dbo].[paQrySectoresEcoDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySectoresEcoDso] 
 AS 
  SELECT IdSector,SectorEco,IdSector+' '+SectorEco AS DsSector
  FROM SectoresEco
  WHERE Inactivo=0
  ORDER BY IdSector
GO
/****** Object:  StoredProcedure [dbo].[paQrySecurity]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySecurity] @pmIdLla INT
 AS 
 SELECT IdLla,Descripcion,Pwd
 FROM Sys_Security
 WHERE IdLla=ISNULL(@pmIdLla,IdLla)
GO
/****** Object:  StoredProcedure [dbo].[paQrySeriales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySeriales] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,NumSerial,IdCia,IdBodega,CdUbic,FecEntrada,FecSalida,NitProv,IdEstado,Inactivo,Observacion,Referncia1,Referncia2,FecRef1,FecRef2,Ubicacion,IdUsuario
 FROM Trn_Seriales
 WHERE IdProducto=@pmIdProducto AND NumSerial LIKE ISNULL(@pmNumSerial,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia,NumSerial
GO
/****** Object:  StoredProcedure [dbo].[paQrySeriales_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySeriales_Cr] @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmFechaIni SMALLDATETIME=Null
,@pmFechaFin SMALLDATETIME=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmProdInac BIT=Null
 AS 
 SELECT S.IdProducto AS CdProd,DescripProd,NumSerial,S.IdCia AS CdCia,Compania,S.IdBodega AS CdBodega,Bodega,Descrip,CdUbic,FecEntrada,FecSalida
,NitProv,RazonSocial,S.IdEstado AS CdEstado,Estado,S.Inactivo AS Inactiv,S.Observacion AS Observ
,Referncia1,Referncia2,FecRef1,FecRef2,Ubicacion,S.IdUsuario AS IdUsuari,Usuario
--información del producto
,P.Referencia AS Prod_Referencia,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca,Tamano,P.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,P.IdUnd AS CdUndPre,UM.Unidad AS UnidadPre,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong,NColor
 FROM Trn_Seriales AS S INNER JOIN ProdMcias AS P  ON S.IdProducto=P.IdProducto
 INNER JOIN EstadoSer AS E ON S.IdEstado=E.IdEstado
 INNER JOIN Bodegas AS B ON S.IdBodega=B.IdBodega
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CN ON S.IdCia=CN.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd 
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON P.UndMed=SU.UndMed 
 LEFT JOIN Terceros AS T ON S.NitProv=T.IdTercero
 WHERE S.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND S.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  S.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND S.IdEstado LIKE ISNULL(@pmIdEstado,'%')
AND (FecEntrada>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecEntrada<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (S.Inactivo=ISNULL(@pmInactivo,0) or S.Inactivo=ISNULL(@pmInactivo,1))
 AND (P.Inactivo=ISNULL(@pmProdInac,0) or P.Inactivo=ISNULL(@pmProdInac,1))
 ORDER BY DescripProd,S.IdCia,FecEntrada,NumSerial
GO
/****** Object:  StoredProcedure [dbo].[paQrySerialesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerialesLta] @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmFechaIni SMALLDATETIME=Null
,@pmFechaFin SMALLDATETIME=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmProdInac BIT=Null
 AS 
 SELECT S.IdProducto AS CdProd,DescripProd,NumSerial,IdCia,S.IdBodega AS CdBodega,Bodega,CdUbic,FecEntrada,FecSalida,NitProv,RazonSocial,S.IdEstado AS CdEstado
,Estado,S.Inactivo AS Inactiv,S.Observacion AS Observ,Referncia1,Referncia2,FecRef1,FecRef2,Ubicacion,S.IdUsuario AS IdUsuari,Usuario,NColor
 FROM Trn_Seriales AS S INNER JOIN ProdMcias AS P  ON S.IdProducto=P.IdProducto
 INNER JOIN EstadoSer AS E ON S.IdEstado=E.IdEstado
 INNER JOIN Bodegas AS B ON S.IdBodega=B.IdBodega
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS T ON S.NitProv=T.IdTercero
 WHERE S.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  S.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND S.IdEstado LIKE ISNULL(@pmIdEstado,'%')
AND (FecEntrada>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND FecEntrada<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (S.Inactivo=ISNULL(@pmInactivo,0) or S.Inactivo=ISNULL(@pmInactivo,1))
 AND (P.Inactivo=ISNULL(@pmProdInac,0) or P.Inactivo=ISNULL(@pmProdInac,1))
 ORDER BY DescripProd,IdCia,FecEntrada,NumSerial
GO
/****** Object:  StoredProcedure [dbo].[paQrySerialesPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerialesPro] @pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT S.IdProducto AS CdProd,DescripProd,NumSerial,IdCia,S.IdBodega AS CdBodega,CdUbic,FecEntrada,FecSalida,NitProv,S.IdEstado AS CdEstado
,S.Inactivo AS Inactiv,S.Observacion AS Observ,Referncia1,Referncia2,FecRef1,FecRef2,Ubicacion,S.IdUsuario AS IdUsuari
 FROM Trn_Seriales AS S INNER JOIN ProdMcias AS P  ON S.IdProducto=P.IdProducto
 WHERE S.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND S.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND S.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (S.Inactivo=ISNULL(@pmInactivo,0) or S.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY DescripProd,IdCia,FecEntrada,NumSerial
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySerMov] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,IdProducto,NumSerial,IdBodega,CdUbic,Linea,Movimiento,Fecha,Observacion,Referencia
 FROM Trn_SerMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMov_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerMov_Cr] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT TipDoc,Documento,M.IdCia AS CdCia,Item,M.IdProducto AS CdProducto,DescripProd,M.NumSerial AS Num_Serial,M.IdBodega AS CdBodega,Bodega
,M.CdUbic AS CodUbic,Linea,Movimiento,Fecha,M.Observacion AS Observ,M.Referencia AS MovReferencia
--campos del serial
,FecEntrada,FecSalida,NitProv,RazonSocial,S.IdEstado AS CdEstado,Estado,S.Inactivo AS Inactiv
,S.Observacion AS SerObserv,Referncia1,Referncia2,FecRef1,FecRef2,Ubicacion
 FROM Trn_SerMov AS M INNER JOIN Trn_Seriales AS S ON M.NumSerial=S.NumSerial
 AND M.IdCia=S.IdCia AND M.IdProducto=S.IdProducto
 INNER JOIN ProdMcias  AS P ON M.IdProducto=P.IdProducto INNER JOIN Bodegas AS B ON M.IdBodega=B.IdBodega
 INNER JOIN EstadoSer AS E ON S.IdEstado=E.IdEstado
 LEFT JOIN Terceros AS T ON S.NitProv=T.IdTercero
 WHERE TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND M.IdCia=@pmIdCia 
 AND  M.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovDel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerMovDel] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT IdProducto,NumSerial,IdCia,Movimiento,COUNT(Documento) AS SCAN
 FROM Trn_SerMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 GROUP BY IdProducto,NumSerial,IdCia,Movimiento
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerMovDoc] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT
,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Documento,IdCia,IdProducto,NumSerial,IdBodega
 FROM Trn_SerMov
 WHERE TipDoc=@pmTipDoc AND Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin
 AND IdCia=@pmIdCia 
 ORDER BY Documento,IdProducto,NumSerial
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerMovLta] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmLinea INT=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmMovimiento VARCHAR(3)=Null
 AS 
 SELECT NumSerial,M.IdProducto AS CdProducto,DescripProd,M.IdBodega AS CdBodega,Bodega,CdUbic,Linea,Item
,Movimiento,Observacion,M.Referencia AS Referncia
 FROM Trn_SerMov AS M INNER JOIN ProdMcias AS P ON M.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON M.IdBodega=B.IdBodega
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND M.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND M.IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND Movimiento LIKE ISNULL(@pmMovimiento,'%')
 AND (Linea>=ISNULL(@pmLinea,0)  AND Linea<=ISNULL(@pmLinea,2147483647))
 ORDER BY Linea,NumSerial
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySerMovPro] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmLinea INT=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null
,@pmNumSerial VARCHAR(30)=Null,@pmMovimiento VARCHAR(3)=Null
 AS 
 SELECT TipDoc,Documento,IdCia,Item,IdProducto,NumSerial,IdBodega,CdUbic,Linea,Movimiento,Fecha,Observacion,Referencia
 FROM Trn_SerMov
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 AND IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
 AND NumSerial LIKE ISNULL(@pmNumSerial,'%')  AND Movimiento LIKE ISNULL(@pmMovimiento,'%')
 AND (Linea>=ISNULL(@pmLinea,0)  AND Linea<=ISNULL(@pmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrySerMovRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySerMovRel] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmIdProducto VARCHAR(16)=Null,@pmIdBodega VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
,@pmInactivo BIT=Null,@pmProdInac BIT=Null,@pmNumSerial VARCHAR(30)=Null
 AS 
 SELECT  M.IdProducto AS CdProducto,DescripProd,M.NumSerial AS Num_Serial,Fecha,TipDoc,Documento,M.IdCia AS CdCia,Compania,Item
,Movimiento,TipoDoc,M.IdBodega AS CdBodega,B.Bodega AS NomBodega,M.CdUbic AS MovCdUbic,M.Observacion AS MovObserv,M.Referencia AS MovReferencia
,M.Linea AS NroLinea
--datos del serial
,S.IdBodega AS SerIdBodega,BS.Bodega AS SerNomBodega,FecEntrada,FecSalida,S.IdEstado AS CdEstado,Estado,S.Inactivo AS SerInactivo,S.Observacion AS SerObserv
,Referncia1,FecRef1,Referncia2,FecRef2,NitProv,RazonSocial,Ubicacion,S.CdUbic AS SerCdUbic,S.IdUsuario AS CdUsusari,Usuario
--Datos del producto
,P.Referencia AS Prod_Referencia,CodBarras,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,LN.Linea AS NomLinea,P.IdMarca AS CdMarca,Marca
,Tamano,P.UndMed AS CdUndMed,SU.Unidad AS ProdUnidad,P.IdUnd AS CdUndPre,UM.Unidad AS UnidadPre,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd
,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Lotes,Combo,Tanques,DescripLong,DescripAbrv
 FROM Trn_SerMov AS M INNER JOIN Trn_Seriales AS S ON M.NumSerial=S.NumSerial
 AND M.IdProducto=S.IdProducto AND M.IdCia=S.IdCia
 INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc INNER JOIN ProdMcias AS P  ON M.IdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON M.IdBodega=B.IdBodega INNER JOIN Bodegas AS BS ON S.IdBodega=BS.IdBodega
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia  INNER JOIN EstadoSer AS E ON S.IdEstado=E.IdEstado
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd 
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS MC ON P.IdMarca=MC.IdMarca
 INNER JOIN Sys_Um AS SU ON P.UndMed=SU.UndMed 
 LEFT JOIN Terceros AS T ON S.NitProv=T.IdTercero
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND M.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND  M.IdBodega LIKE ISNULL(@pmIdBodega,'%') AND S.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND M.NumSerial LIKE ISNULL(@pmNumSerial,'%')
 AND (S.Inactivo=ISNULL(@pmInactivo,0) or S.Inactivo=ISNULL(@pmInactivo,1))
 AND (P.Inactivo=ISNULL(@pmProdInac,0) or P.Inactivo=ISNULL(@pmProdInac,1))
 ORDER BY DescripProd,M.NumSerial,Fecha
GO
/****** Object:  StoredProcedure [dbo].[paQrySobDetalle]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySobDetalle] @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmItem INT
 AS 
 SELECT IdDec,NumDeclara,Item,Concepto,Cantidad,VrUnitario,VrBase,Tarifa,VrLiquida,VrPrecio,ClaseProd,TarifGalon,PorcBase,PorcAch
 FROM Trn_SobDetalle
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidades]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySobEntidades] @pmIdEnterr VARCHAR(8)
 AS 
 SELECT IdEnterr,TipoEnterr,NitEntidad,TipoId,Dv,DirOficina,Telefono,Fax,SitioWeb,e_mail,CedRepLegal,RepLegal
,CargoRep,FormaPago,IdClase,NumCuenta,NomTitular,IdBanco,CdLocCue,NomEntidad,Inactivo,CodCtaPag
 FROM SobEntidades
 WHERE IdEnterr=@pmIdEnterr
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidadesDep]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobEntidadesDep] @pmTipoEnterr VARCHAR(10) 
 AS 
 SELECT IdEnterr,NomEntidad,Departamento+' '+IdEnterr AS DsEnt
 FROM SobEntidades AS S  INNER JOIN Departamentos AS D ON  S.IdEnterr=D.IdDep
 WHERE TipoEnterr=@pmTipoEnterr AND S.Inactivo=0
 ORDER BY  Departamento
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidadesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySobEntidadesLta] @pmTipoEnterr VARCHAR(10)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmInactivo BIT=Null
 AS 
 SELECT IdEnterr,NitEntidad,RazonSocial,E.TipoId AS Tipo_Id,E.Dv AS DvNit,TipoEnterr,NomEntidad,LE.Localidad AS NomMunicipio
,LE.IdDep AS CdDpto,Departamento,DirOficina,E.Telefono AS NumTelefono,E.Fax AS NumFax,E.SitioWeb AS Sitio_Web,E.e_mail AS Email,CedRepLegal,RepLegal
,CargoRep,FormaPago,E.IdClase AS CdClase,ClaseCuenta,NumCuenta,E.IdBanco AS CdBanco,Banco,CodEntidad,NomTitular
,CdLocCue,L.Localidad AS LugarCuenta,CodCtaPag,E.Inactivo AS Inactiv
 FROM SobEntidades AS E INNER JOIN ClaseCta AS C ON E.IdClase=C.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco
 LEFT JOIN Terceros AS T ON E.NitEntidad=T.IdTercero
 LEFT JOIN  Localidades AS LE ON E.IdEnterr=LE.IdLocal LEFT JOIN Departamentos AS DP ON LE.IdDep=DP.IdDep
 LEFT JOIN  Localidades AS L ON E.CdLocCue=L.IdLocal
 WHERE TipoEnterr LIKE ISNULL(@pmTipoEnterr,'%')
 AND E.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND  (E.Inactivo=ISNULL(@pmInactivo,0) or E.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdEnterr
GO
/****** Object:  StoredProcedure [dbo].[paQrySobEntidadesMun]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobEntidadesMun] @pmTipoEnterr VARCHAR(10) 
 AS 
 SELECT IdEnterr,NomEntidad,Localidad+' ('+Departamento+') '+IdEnterr AS DsEnt
 FROM SobEntidades AS S INNER JOIN Localidades AS L ON S.IdEnterr=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 WHERE TipoEnterr LIKE ISNULL(@pmTipoEnterr,'%') AND S.Inactivo=0
 ORDER BY  Localidad
GO
/****** Object:  StoredProcedure [dbo].[paQrySobGasOxigenLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobGasOxigenLta] @pmIdDec VARCHAR(4),@pmNumDeclaraIni INT,@pmNumDeclaraFin INT
AS 
SELECT D.IdDec,D.NumDeclara,D.Item,D.ItemDet,D.ClaseProd,D.IdProducto,P.DescripProd,D.Cantidad,D.Tarifa,D.PorcBase
,D.PorcAch,D.BaseGrav,D.VrSobretasa,D.PrecioRef
FROM Trn_SobGasOxigen AS D INNER JOIN ProdMcias AS P ON D.IdProducto=P.IdProducto
WHERE D.IdDec=@pmIdDec AND D.NumDeclara BETWEEN ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobProductos] @pmIdClase INT
 AS 
 SELECT IdClase,IdProducto,ClaseProd
 FROM SobProductos
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductosExi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobProductosExi] @pmIdProducto VARCHAR(16),@pmIdClase INT
 AS 
 SELECT IdClase,IdProducto,ClaseProd
 FROM SobProductos
 WHERE IdProducto=@pmIdProducto AND IdClase<>@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductosId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobProductosId]
 AS 
 SELECT MAX(IdClase) AS MXITM
 FROM SobProductos
GO
/****** Object:  StoredProcedure [dbo].[paQrySobProductosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobProductosLta] 
 AS 
 SELECT S.IdClase,S.IdProducto AS CdProducto,P.DescripProd,S.ClaseProd AS CodClase,C.ClaseProd
 FROM SobProductos AS S INNER JOIN ProdMcias AS P ON S.IdProducto=P.IdProducto
 INNER JOIN ClasesProd AS C ON S.ClaseProd=C.IdClaseProd
 ORDER BY S.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySobretasas] @pmIdDec VARCHAR(4),@pmNumDeclara INT
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,IdEnterr,TipoEntidad,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar
,VrFondoSubs,VrRecaudoDep,NitDeclara,DvDeclara,CedDeclara,Declarante,DirEntidad,EmailEnt,NomRepres,CargoRepres
,TipoFirma,NitRevisor,NomRevisor,TpRevisor,NumCheque,CodBanco,IdClase,NumCuenta,IdBanco,CdLocCue,TitularCuenta
,VrEfectivo,VrOtros,VrTransf,VrPagado,Estado,Adhesivo,FechaPago,EsCorr,NumCorr,FecCorr,Observacion,TimeSys,FecUpdate,IdUsuario,CodCta
,TipEgreso,NumEgreso,CiaEgreso
 FROM Trn_Sobretasas
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasas_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobretasas_Cr]  @pmIdDec VARCHAR(4),@pmNumDeclaraIni INT,@pmNumDeclaraFin INT
,@pmnAnnoIni INT=Null,@pmnAnnoFin INT=Null,@pmnMesIni INT=Null,@pmnMesFin INT=Null
,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null,@pmIdBanco VARCHAR(4)=Null,@pmEstado INT=Null
 AS 
 SELECT S.IdDec AS CdDec,Declaracion,S.NumDeclara AS NumeroDec,Fecha,nAnno,nMes,NitDeclara,DvDeclara,CedDeclara,Declarante
,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrFondoSubs,VrRecaudoDep,VrEfectivo,VrOtros,VrTransf,VrPagado,TipEgreso,NumEgreso,CiaEgreso
--detalles
,Item,Concepto,Cantidad,VrUnitario,VrBase,Tarifa,VrLiquida,VrPrecio,ClaseProd,TarifGalon,PorcBase,PorcAch
--entidad
,TipoEntidad,S.IdEnterr AS CdEnterr,NomEntidad,E.TipoId AS EntTipoID,NitEntidad,E.Dv AS EntDv,RazonSocial,DirEntidad,E.Telefono AS EntTelefono,E.Fax AS EntFax
,E.SitioWeb AS EntSitioWeb,EmailEnt,E.CedRepLegal AS CedRepres,NomRepres,CargoRepres,FormaPago
,S.IdClase AS CdClase,ClaseCuenta,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco,CodEntidad
,S.CdLocCue AS IdLocCue,L.Localidad AS LugarCuenta,L.IdDep AS CdDepLugar,DP.Departamento AS DptoLugarCuenta,TitularCuenta,NumCheque,CodBanco,CodCta,NumeroCta
,S.TipoFirma AS TipFirma,S.NitRevisor AS IdRevisor,S.NomRevisor AS NombRevisor,S.TpRevisor AS TarjProf,Estado,Adhesivo,FechaPago
,EsCorr,NumCorr,FecCorr,S.Observacion AS Observ,S.IdUsuario AS IdUsuari,Usuario,TimeSys
--información del tipo de declaracion
,TipoDec,TipoIdDec,TD.Direccion AS DirDeclarante,TD.IdLocal AS CdCiuDec,LT.Localidad AS CiuDeclarante
,LT.IdDep AS CdDepDec,DT.Departamento AS DptoDeclarante,TD.Telefono AS TelefDeclara,TD.CedRepLegal AS CedRepDeclara,TD.RepLegal AS RepLegalDeclara
 FROM Trn_Sobretasas AS S INNER JOIN Trn_SobDetalle AS D ON S.IdDec=D.IdDec AND S.NumDeclara=D.NumDeclara
 INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr INNER JOIN SobTiposDec AS TD ON S.IdDec=TD.IdDec
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco
 INNER JOIN  ClaseCta AS CT ON S.IdClase=CT.IdClase
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LT ON TD.IdLocal=LT.IdLocal INNER JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 LEFT JOIN Localidades AS L ON S.CdLocCue=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Terceros AS T ON E.NitEntidad=T.IdTercero LEFT JOIN CtasCorrientes AS CTA ON S.CodCta=CTA.IdCta
 WHERE S.IdDec LIKE ISNULL(@pmIdDec ,'%')
 AND S.NumDeclara BETWEEN  ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
 AND nMes BETWEEN ISNULL(@pmnMesIni,0)  AND ISNULL(@pmnMesFin,20)
 AND nAnno BETWEEN ISNULL(@pmnAnnoIni,0) AND ISNULL(@pmnAnnoFin,2147483647)
 AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%') AND TipoEntidad  LIKE ISNULL(@pmTipoEntidad ,'%')
 AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647)) 
 ORDER BY S.NumDeclara,Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasas_Crr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobretasas_Crr]  @pmnAnno INT,@pmnMesIni INT=Null,@pmnMesFin INT=Null,@pmIdDec VARCHAR(4)=Null
,@pmNumDeclaraIni INT=Null,@pmNumDeclaraFin INT=Null,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null
,@pmIdBanco VARCHAR(4)=Null
 AS 
 SELECT  IdDec,NumDeclara,nAnno,nMes,TipoEntidad,S.IdEnterr AS CdEnterr,E.TipoId AS EntTipoID
,NitEntidad,E.Dv AS EntDv,NomEntidad,S.IdClase AS CdClase,ClaseCuenta,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco,CodEntidad,TitularCuenta
--valores
,tmAcpmCant,tmAcpmBase,tmAcpmValor,tmAcpmTarif,tmAcpmPrecio,tmAcpiCant,tmAcpiBase,tmAcpiValor,tmAcpiTarif,tmAcpiPrecio,tmGcorCant,tmGcorBase
,tmGcorValor,tmGcorTarif,tmGcorPrecio,tmGextCant,tmGextBase,tmGextValor,tmGextTarif,tmGextPrecio,tmGimpCant,tmGimpBase,tmGimpValor,tmGimpTarif
,tmGimpPrecio,tmGcoxCant,tmGcoxBase,tmGcoxValor,tmGcoxTarif,tmGcoxPrecio,tmGeoxCant,tmGeoxBase,tmGeoxValor,tmGeoxTarif,tmGeoxPrecio
,tmAczfCant,tmAczfBase,tmAczfValor,tmAczfTarif,tmAczfPrecio,tmGnzfCant,tmGnzfBase,tmGnzfValor,tmGnzfTarif,tmGnzfPrecio,tmGOzfCant,tmGOzfBase,tmGOzfValor,tmGOzfTarif,tmGOzfPrecio
,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrFondoSubs,VrRecaudoDep,VrEfectivo,VrOtros,VrTransf,VrPagado,TipEgreso,NumEgreso,CiaEgreso
,FormaPago,S.CdLocCue AS IdLocCue,L.Localidad AS LugarCuenta,L.IdDep AS CdDepLugar,DP.Departamento AS DptoLugarCuenta,NumCheque,CodBanco
,CodCta,NumeroCta,DirEntidad,E.Telefono AS EntTelefono,E.Fax AS EntFax,E.SitioWeb AS EntSitioWeb,EmailEnt,E.CedRepLegal AS CedRepres,NomRepres,CargoRepres
,RazonSocial,LT.Localidad AS NomCiudad,LT.IdDep AS CdDep,DT.Departamento AS NomDpto
,Estado,Fecha,NitDeclara,DvDeclara,CedDeclara,Declarante
 FROM Trn_Sobretasas AS S  INNER JOIN tm_Sobtasas AS T ON S.IdDec=T.tmIdDec AND S.NumDeclara=T.tmNumDeclara
 INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco
 INNER JOIN ClaseCta AS CT ON S.IdClase=CT.IdClase
 LEFT JOIN Localidades AS L ON S.CdLocCue=L.IdLocal LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN Localidades AS LT ON S.IdEnterr=LT.IdLocal LEFT JOIN Departamentos AS DT ON LT.IdDep=DT.IdDep
 LEFT JOIN Terceros AS TE ON E.NitEntidad=TE.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON S.CodCta=CTA.IdCta
 WHERE nAnno=@pmnAnno AND Estado<=1 AND IdDec LIKE ISNULL(@pmIdDec ,'%')
 AND nMes BETWEEN ISNULL(@pmnMesIni,0)  AND ISNULL(@pmnMesFin,20)
 AND NumDeclara BETWEEN  ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
 AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%') AND TipoEntidad  LIKE ISNULL(@pmTipoEntidad ,'%')
 AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 ORDER BY IdDec,NomEntidad,NumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobretasasDet] @pmnAnno INT,@pmnMesIni INT=Null,@pmnMesFin INT=Null
,@pmIdDec VARCHAR(4)=Null,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmNumDeclaraIni INT=Null,@pmNumDeclaraFin INT=Null
 AS 
 SELECT S.IdDec AS CdDec,S.NumDeclara AS NroDeclara,nAnno,nMes,S.IdEnterr AS CdEnterr,FormaPago,NomEntidad,Localidad,IdDep
,TipoEntidad,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar
,VrEfectivo,VrOtros,VrTransf,VrPagado,Estado,CodBanco,CodCta
,Item,Concepto,Cantidad,VrUnitario,VrBase,Tarifa,VrLiquida,VrPrecio,ClaseProd,TarifGalon,PorcBase,PorcAch
 FROM  Trn_Sobretasas AS S INNER JOIN  Trn_SobDetalle AS D ON S.IdDec=D.IdDec AND S.NumDeclara=D.NumDeclara
 INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr
 LEFT JOIN Localidades AS L ON E.IdEnterr=L.IdLocal
 WHERE nAnno=@pmnAnno AND Estado<=1 --2 Y 3 no se incluyen
 AND (nMes>=ISNULL(@pmnMesIni,0)  AND nMes<=ISNULL(@pmnMesFin,2147483647))
 AND S.IdDec LIKE ISNULL(@pmIdDec,'%') AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%')
 AND TipoEntidad LIKE ISNULL(@pmTipoEntidad,'%') AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (S.NumDeclara>=ISNULL(@pmNumDeclaraIni,0)  AND S.NumDeclara<=ISNULL(@pmNumDeclaraFin,2147483647))
 ORDER BY S.IdDec,S.NumDeclara,Item
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasEgr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobretasasEgr]  @pmnAnno INT,@pmnMes INT,@pmIdBanco VARCHAR(4)=Null
,@pmIdDec VARCHAR(4)=Null,@pmFormaPago VARCHAR(10)=Null
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,NitDeclara,DvDeclara,CedDeclara,Declarante
,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar,VrEfectivo,VrOtros,VrTransf,VrPagado
,TipoEntidad,S.IdEnterr AS CdEnterr,E.TipoId AS EntTipoID,NitEntidad,E.Dv AS EntDv,RazonSocial
,NomRepres,FormaPago,S.IdClase AS CdClase,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco,CodEntidad
,S.CdLocCue AS IdLocCue,TitularCuenta,NumCheque,CodBanco,Estado,EsCorr,CodCta
 FROM Trn_Sobretasas AS S INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco  LEFT JOIN Terceros AS T ON E.NitEntidad=T.IdTercero
 WHERE  nAnno=@pmnAnno AND nMes=@pmnMes AND Estado<=1 AND VrTotalPagar>0
 AND  IdDec LIKE ISNULL(@pmIdDec ,'%') AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND FormaPago LIKE ISNULL(@pmFormaPago,'%')
 ORDER BY IdDec,NumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobretasasEnt] @pmIdDec VARCHAR(4),@pmnAnno INT,@pmnMes INT
,@pmIdEnterr VARCHAR(8),@pmTipoEntidad VARCHAR(10)
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,IdEnterr,TipoEntidad,Estado
 FROM Trn_Sobretasas
 WHERE IdDec=@pmIdDec AND  nAnno=@pmnAnno AND nMes=@pmnMes
 AND IdEnterr=@pmIdEnterr AND TipoEntidad=@pmTipoEntidad
 ORDER BY NumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobretasasLta] @pmIdDec VARCHAR(4),@pmnAnno INT,@pmnMesIni INT=Null,@pmnMesFin INT=Null
,@pmNumDeclaraIni INT=Null,@pmNumDeclaraFin INT=Null,@pmIdEnterr VARCHAR(8)=Null,@pmTipoEntidad VARCHAR(10)=Null
,@pmIdBanco VARCHAR(4)=Null,@pmEstado INT=Null
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,TipoEntidad,S.IdEnterr AS CdEnterr,TipoId,NitEntidad,Dv,DirEntidad,SitioWeb,EmailEnt
,NomRepres,CargoRepres,VrSobretasa,VrSanciones,VrCompensa,VrIntMora,VrTotalPagar
,VrFondoSubs,VrRecaudoDep,NitDeclara,DvDeclara,CedDeclara,Declarante,TipoFirma,NitRevisor,NomRevisor
,TpRevisor,FormaPago,NumCheque,CodBanco,CodCta,NumeroCta,S.IdClase AS CdClase,ClaseCuenta,S.NumCuenta AS NroCuenta,S.IdBanco AS IdBanc,Banco
,S.CdLocCue AS IdLocCue,Localidad,TitularCuenta,VrEfectivo,VrOtros,VrTransf,VrPagado,TipEgreso,NumEgreso,CiaEgreso,Estado,Adhesivo,FechaPago,EsCorr
,NumCorr,FecCorr,Observacion,TimeSys,FecUpdate,S.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Sobretasas AS S INNER JOIN SobEntidades AS E ON S.IdEnterr=E.IdEnterr
 INNER JOIN Bancos AS B ON S.IdBanco=B.IdBanco
 INNER JOIN  ClaseCta AS CT ON S.IdClase=CT.IdClase
 INNER JOIN adm_Usuarios AS U ON S.IdUsuario=U.IdUsuario
 LEFT JOIN Localidades AS L ON S.CdLocCue=L.IdLocal
 LEFT JOIN CtasCorrientes AS CTA ON S.CodCta=CTA.IdCta
 WHERE IdDec=@pmIdDec AND nAnno=@pmnAnno AND nMes BETWEEN ISNULL(@pmnMesIni,0)  AND ISNULL(@pmnMesFin,20)
 AND NumDeclara BETWEEN  ISNULL(@pmNumDeclaraIni,0) AND ISNULL(@pmNumDeclaraFin,2147483647)
 AND S.IdEnterr LIKE ISNULL(@pmIdEnterr,'%') AND TipoEntidad  LIKE ISNULL(@pmTipoEntidad ,'%')
 AND S.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (Estado>=ISNULL(@pmEstado,-1)  AND Estado<=ISNULL(@pmEstado,2147483647)) 
 ORDER BY NumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paQrySobretasasMes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySobretasasMes] @pmIdDec VARCHAR(4),@pmnAnno INT,@pmnMes INT
,@pmIdEnterr VARCHAR(8),@pmTipoEntidad VARCHAR(10)
 AS 
 SELECT IdDec,NumDeclara,Fecha,nAnno,nMes,IdEnterr,TipoEntidad,Adhesivo,FechaPago,EsCorr,NumCorr,FecCorr,Estado
 FROM Trn_Sobretasas
 WHERE IdDec=@pmIdDec AND  nAnno=@pmnAnno AND nMes=@pmnMes
 AND IdEnterr=@pmIdEnterr AND TipoEntidad=@pmTipoEntidad AND Estado<2 --2anulado,3-Corregido
 ORDER BY NumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySobTiposDec] @pmIdDec VARCHAR(4)
 AS 
 SELECT IdDec,Declaracion,TipoDec,NitDec,TipoIdDec,NombreDec,DvDec,Direccion,IdLocal,Telefono
,CedRepLegal,RepLegal,TipoFirma,NitRevisor,NomRevisor,TpRevisor,TarifSubsidio,Consecutivo
 FROM SobTiposDec
 WHERE IdDec=@pmIdDec
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDecDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobTiposDecDso] 
 AS 
 SELECT IdDec,Declaracion,Declaracion+' '+IdDec AS DsDec
 FROM SobTiposDec
 ORDER BY Declaracion
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDecGas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobTiposDecGas] 
 AS 
 SELECT IdDec,Declaracion,Declaracion+' '+IdDec AS DsDec
 FROM SobTiposDec
 WHERE IdDec<>'0010'
 ORDER BY Declaracion
GO
/****** Object:  StoredProcedure [dbo].[paQrySobTiposDecLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySobTiposDecLta] 
 AS 
 SELECT IdDec,Declaracion,TipoDec,TipoIdDec,NitDec,NombreDec,DvDec,Direccion,T.IdLocal AS CdLocal,Localidad
,L.IdDep AS CdDepto,Departamento,Telefono,CedRepLegal,RepLegal,TipoFirma,NitRevisor,NomRevisor,TpRevisor,TarifSubsidio,Consecutivo
 FROM SobTiposDec AS T INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 ORDER BY IdDec
GO
/****** Object:  StoredProcedure [dbo].[paQrySubCentros]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySubCentros] @pmIdSubCos VARCHAR(16)
 AS 
 SELECT IdSubCos,SubCosto,IdCCosto,FecAdd,FecUpdate,Inactivo
 FROM SubCentros
 WHERE IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paQrySubCentrosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubCentrosDso] @pmIdCCosto VARCHAR(16)=Null,@pmInactivo BIT=Null
 AS 
 IF @pmIdCCosto IS NULL
  BEGIN
   SELECT IdSubCos,SubCosto,SubCosto+' '+IdSubCos AS DsSub,IdCCosto
   FROM SubCentros
   WHERE  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
   ORDER BY IdCCosto,SubCosto
  END
 ELSE
  BEGIN
   SELECT IdSubCos,SubCosto,SubCosto+' '+IdSubCos AS DsSub,IdCCosto
   FROM SubCentros
   WHERE (IdSubCos='0'  OR IdCCosto='0' OR   IdCCosto=@pmIdCCosto)
   AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
   ORDER BY IdCCosto,SubCosto
  END
GO
/****** Object:  StoredProcedure [dbo].[paQrySubCentrosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubCentrosLta] @pmIdCCosto VARCHAR(16)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdSubCos,SubCosto,S.IdCCosto AS CodCcosto,CCosto,FecAdd,FecUpdate,S.Inactivo AS Inactvo
 FROM SubCentros AS S INNER JOIN CentroCosto AS C ON S.IdCCosto=C.IdCCosto
 WHERE S.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND (S.Inactivo=ISNULL(@pmInactivo,0) or S.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY CCosto,SubCosto
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGrupos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySubGrupos] @pmIdSubgrupo VARCHAR(8)
 AS 
 SELECT IdSubgrupo,Subgrupo,IdGrupo,CdTarIva,CdTarAut,CdTarRet,CdTarIca
,TipoInvent,CdTarifImv,CdTarifIco,CdTarIvp,CdTarifIcu,Inactivo
 FROM SubGrupos
 WHERE IdSubgrupo=@pmIdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySubGruposAgenc] @pmIdSubAgenc VARCHAR(4)
 AS 
 SELECT IdSubAgenc,SubGrupoAgenc,IdGrupo,Inactivo
 FROM SubGruposAgenc
 WHERE IdSubAgenc=@pmIdSubAgenc
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposAgencLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubGruposAgencLta] @pmIdGrupo VARCHAR(4)
 AS 
 SELECT IdSubAgenc,SubGrupoAgenc,S.IdGrupo AS CdGrupo,GrupoAgenc
 FROM SubGruposAgenc AS S INNER JOIN GruposAgenc AS G  ON S.IdGrupo=G.IdGrupo
 WHERE S.Inactivo=0 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 ORDER BY SubGrupoAgenc
GO
/****** Object:  StoredProcedure [dbo].[paQrySubgruposCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubgruposCue] @pmIdSubgrupo VARCHAR(8),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdSubgrupo,IdClase,IdCuenta,CdCueDev,CdCueCom,CdCueCdv,FecAdd,FecUpdate
 FROM SubgruposCue
 WHERE IdSubgrupo=@pmIdSubgrupo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrySubgruposCueLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubgruposCueLta] @pmIdSubgrupo VARCHAR(8)=Null
 AS 
 SELECT SC.IdSubgrupo AS CdSubg,Subgrupo,SC.IdClase AS CdClase,NomClase,SC.IdCuenta AS CdCueVen
,P.NomCuenta AS CueVentas,CdCueDev,CdCueCom,CP.NomCuenta AS CueCompras,CdCueCdv,FecAdd,FecUpdate
 FROM SubgruposCue AS SC INNER JOIN  SubGrupos AS S ON SC.IdSubgrupo=S.IdSubgrupo
 INNER JOIN ClaseSub AS C ON SC.IdClase=C.IdClase
 INNER JOIN Puc AS P ON SC.IdCuenta=P.IdCuenta
 LEFT JOIN Puc AS CP ON SC.CdCueCom=CP.IdCuenta
 WHERE S.Inactivo=0 AND SC.IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%') 
 ORDER BY Subgrupo,SC.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrySubgruposCuePuc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubgruposCuePuc] @pmIdSubgrupo VARCHAR(8)
 AS 
 SELECT IdSubgrupo,IdClase,SC.IdCuenta AS CdCuenta,P.NomCuenta AS NomCue,P.Movimiento AS MovCue
,P.CentroCosto AS CCcue,P.SubCentro AS SubCCue,CdCueCom,PC.NomCuenta AS NomCueCom
,PC.Movimiento AS MovCueCom,PC.CentroCosto AS CCCueCom,PC.SubCentro AS SubCCueCom
,CdCueDev,CdCueCdv,P.Tercero,P.Vehiculo,PC.Tercero AS CComTerc,PC.Vehiculo AS CComVehic
 FROM SubgruposCue AS SC INNER JOIN Puc AS P ON SC.IdCuenta=P.IdCuenta
 LEFT JOIN Puc AS PC ON SC.CdCueCom=PC.IdCuenta
 WHERE IdSubgrupo=@pmIdSubgrupo
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubGruposDso] @pmIdGrupo VARCHAR(8)=Null,@pmTipoInvent VARCHAR(10)=Null
 AS 
 SELECT IdSubgrupo,Subgrupo,Subgrupo+' '+IdSubgrupo +' ('+Grupo+')' AS DsSub
 FROM SubGrupos AS S INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 WHERE S.Inactivo=0 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND  S.TipoInvent LIKE ISNULL(@pmTipoInvent,'%')
 ORDER BY Grupo,Subgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposLin]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubGruposLin] @pmIdSubgrupo VARCHAR(8)=Null
 AS 
 SELECT IdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
,S.TipoInvent AS TipoInv
 FROM SubGrupos AS S INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 WHERE  IdSubgrupo LIKE ISNULL(@pmIdSubgrupo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySubGruposLta] @pmIdGrupo VARCHAR(8)=Null,@pmIdLinea VARCHAR(8)=Null
,@pmTipoInvent VARCHAR(10)=Null
 AS 
 SELECT IdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,CdTarIva
,TP.Tarifa,TP.Simbolo,TP.Descripcion AS DescIva
,CdTarAut,TA.Tarifa AS TarifaAut,TA.Simbolo AS SimbAut,TA.Descripcion AS DescAut
,CdTarRet,TR.Tarifa AS TarifaRet,TR.Simbolo AS SimbRet,TR.Descripcion AS DescRet
,CdTarIca,TI.Tarifa AS TarifaIca,TI.Simbolo AS SimbIca,TI.Descripcion AS DescIca
,CdTarifImv,TM.Tarifa AS TarifaImv,TM.Simbolo AS SimbImv,TM.Descripcion AS DescImv
,CdTarifIco,TC.Tarifa AS TarifaIco,TC.Simbolo AS SimbIco,TC.Descripcion AS DescIco
,S.CdTarIvp,TPR.Tarifa AS TarifaIvp,TPR.Simbolo AS SimbIvp
,S.CdTarifIcu,TUP.Tarifa AS TarifaIcu,TUP.Simbolo AS SimbIcu
,S.TipoInvent AS TipoInventario
 FROM SubGrupos AS S INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea
 LEFT JOIN Tablapor AS TP ON S.CdTarIva=TP.IdTarifa
 LEFT JOIN Tablapor AS TR ON S.CdTarRet=TR.IdTarifa
 LEFT JOIN Tablapor AS TI ON S.CdTarIca=TI.IdTarifa
 LEFT JOIN Tablapor AS TA ON S.CdTarAut=TA.IdTarifa
 LEFT JOIN Tablapor AS TM ON S.CdTarifImv=TM.IdTarifa
 LEFT JOIN Tablapor AS TC ON S.CdTarifIco=TC.IdTarifa
 LEFT JOIN Tablapor AS TPR ON S.CdTarIvp=TPR.IdTarifa
 LEFT JOIN Tablapor AS TUP ON S.CdTarifIcu=TUP.IdTarifa
 WHERE S.Inactivo=0 AND S.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND G.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND S.TipoInvent LIKE ISNULL(@pmTipoInvent,'%')
 ORDER BY Linea,Grupo,Subgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQrySubGruposTas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrySubGruposTas] @pmIdSubgrupo VARCHAR(8)
 AS 
 SELECT IdSubgrupo,Subgrupo,CdTarIva,TI.Tarifa AS TarfIva,TI.Simbolo AS SimbIva
,CdTarRet,TR.Tarifa AS TarfRet,TR.Simbolo AS SimbRet
,CdTarIca,TC.Tarifa AS TarfIca,TC.Simbolo AS SimbIca
,CdTarAut,TA.Tarifa AS TarfAut,TA.Simbolo AS SimbAut
,CdTarifImv,TM.Tarifa AS TarfImv,TM.Simbolo AS SimbImv
,CdTarifIco,TIC.Tarifa AS TarfIco,TIC.Simbolo AS SimbIco
 FROM SubGrupos AS S LEFT JOIN Tablapor AS TI ON S.CdTarIva=TI.IdTarifa
 LEFT JOIN Tablapor AS TR ON S.CdTarRet=TR.IdTarifa
 LEFT JOIN Tablapor AS TC ON S.CdTarIca=TC.IdTarifa
 LEFT JOIN Tablapor AS TA ON S.CdTarAut=TA.IdTarifa
 LEFT JOIN Tablapor AS TM ON S.CdTarifImv=TM.IdTarifa
 LEFT JOIN Tablapor AS TIC ON S.CdTarifIco=TIC.IdTarifa
 WHERE IdSubgrupo=@pmIdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQrySubzonas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

CREATE PROCEDURE [dbo].[paQrySubzonas] @pmIdSzona VARCHAR(4)
 AS 
 SELECT IdSzona,Subzona,IdZona,Cd_Rut,Inactivo
 FROM Subzonas
 WHERE IdSzona=@pmIdSzona
GO
/****** Object:  StoredProcedure [dbo].[paQrySubzonasDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrySubzonasDso] @pmIdZona VARCHAR(4)=Null
 AS 
  SELECT IdSzona,Subzona,Subzona+' '+IdSzona+'('+Zona+')' AS DsSub
  FROM Subzonas AS S INNER JOIN Zonas AS Z ON S.IdZona=Z.IdZona
  WHERE S.Inactivo=0 AND S.IdZona LIKE ISNULL(@pmIdZona,'%')
  ORDER BY Subzona
GO
/****** Object:  StoredProcedure [dbo].[paQrySubzonasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

CREATE PROCEDURE [dbo].[paQrySubzonasLta] @pmIdZona VARCHAR(4)=Null
 AS 
  SELECT IdSzona,Subzona,S.IdZona AS CdZona,Zona,Cd_Rut,Ruta
  FROM Subzonas AS S INNER JOIN Zonas AS Z ON S.IdZona=Z.IdZona
  LEFT JOIN Rutas AS R ON S.Cd_Rut=R.IdRuta
  WHERE S.Inactivo=0 AND S.IdZona LIKE ISNULL(@pmIdZona,'%')
  ORDER BY Zona,Subzona
GO
/****** Object:  StoredProcedure [dbo].[paQryTablapor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTablapor] @pmIdTarifa VARCHAR(4)
 AS 
 SELECT IdTarifa,Descripcion,IdClase,Tarifa,Simbolo,CdLocdad,Minimo,Maximo,Inactivo
 FROM Tablapor
 WHERE IdTarifa=@pmIdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporCiu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTablaporCiu] @pmIdClase  VARCHAR(4),@pmCdLocdad VARCHAR(8)
 AS 
 SELECT IdTarifa,Descripcion,IdClase,Tarifa,Simbolo,CdLocdad,Minimo,Maximo,Inactivo
 FROM Tablapor
 WHERE IdClase=@pmIdClase AND CdLocdad=@pmCdLocdad AND Inactivo=0
 ORDER BY IdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTablaporDso] @pmIdClase VARCHAR(4)=Null,@pmPrecsn INT,@pmDecm INT
 AS 
 --ICA  @pmPrecsn=8,@pmDecm=4
--IVA  @pmPrecsn=5,@pmDecm=2
--OTROS  @pmPrecsn=6,@pmDecm=2
 SELECT IdTarifa,Tarifa,IdTarifa+' '+STR(Tarifa,@pmPrecsn,@pmDecm)+Simbolo+' '+ISNULL(Descripcion,'') AS DsTar
 FROM Tablapor
 WHERE Inactivo=0 AND  IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY IdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTablaporLta] @pmIdClase VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT T.IdClase AS CodClase,NomClase,IdTarifa,Tarifa,Simbolo,Descripcion,Minimo,Maximo,CdLocdad,T.Inactivo AS Inactvo
 FROM Tablapor AS T INNER JOIN ClaseTar AS CT ON T.IdClase=CT.IdClase
 WHERE  T.IdClase LIKE ISNULL(@pmIdClase,'%')
 AND  (T.Inactivo=ISNULL(@pmInactivo,0) or T.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY T.IdClase,IdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryTablaporTar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTablaporTar] @pmIdClase VARCHAR(4),@pmTarifa DECIMAL(16,6)
,@pmIdTarifa VARCHAR(4)
 AS 
 SELECT IdTarifa,Descripcion,IdClase,Tarifa
 FROM  Tablapor
 WHERE IdClase=@pmIdClase AND Tarifa=@pmTarifa  AND  IdTarifa<>@pmIdTarifa
 ORDER BY IdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQryTallajesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTallajesLta]
 AS  
SELECT T.IdProducto,DescripProd,T.IdCia,Compania,T.IdBodega,Bodega,T.IdUbic,T.NumTalla,T.Cantidad,T.Pedidos,S.SaldoActual 
,P.TipoRef,P.Referencia,P.CodBarras,G.IdLinea,Linea,SG.IdGrupo,Grupo,P.IdSubgrupo,Subgrupo,P.IdMarca,Marca,P.Tamano,P.Color
,P.UndMed,UM.Unidad AS DescUndMed,P.IdUnd,U.Unidad,P.Tallaje,P.Inactivo
FROM Trn_Tallajes AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON T.IdBodega=B.IdBodega INNER JOIN Companias AS CI ON T.IdCia=CI.IdCia
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
INNER JOIN UndMed AS U ON P.IdUnd=U.IdUnd 
LEFT JOIN Sys_Um AS UM ON P.UndMed=UM.UndMed
LEFT JOIN ProdSaldos AS S ON T.IdProducto=S.IdProducto AND T.IdBodega=S.IdBodega AND T.IdCia=S.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTallajesMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTallajesMov] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmAnnoAnt INT,@pmMesAnt INT
 AS  
SELECT T.IdProducto,DescripProd,T.IdCia,CI.Compania,T.IdBodega,Bodega,T.IdUbic,T.NumTalla,T.Cantidad,T.Pedidos,S.SaldoActual
,D.Fecha,D.TipDoc,TD.TipoDoc,D.Documento,D.IdCia AS DetIdCia,CM.Compania AS DetCompania,D.Item,D.Entradas,D.Salidas,D.CantPedido,D.CantRem,D.CantFactura
,dbo.FuncAcuInvTallasSan(@pmAnnoAnt,@pmMesAnt,D.IdCia,D.IdProducto,D.IdBodega,D.IdUbic,D.NumTalla) AS SaldoAnt,D.ItemKdx,D.IdUbic AS DetUbic
--datos del producto 
,P.TipoRef,P.Referencia,P.CodBarras,G.IdLinea,Linea,SG.IdGrupo,Grupo,P.IdSubgrupo,Subgrupo,P.IdMarca,Marca,P.Tamano,P.Color
,P.UndMed,UM.Unidad AS DescUndMed,P.IdUnd,U.Unidad,P.Tallaje,P.Inactivo
FROM Trn_Tallajes AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON T.IdBodega=B.IdBodega INNER JOIN Companias AS CI ON T.IdCia=CI.IdCia
INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo
INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
INNER JOIN UndMed AS U ON P.IdUnd=U.IdUnd 
LEFT JOIN Trn_TallasMov AS D ON T.IdProducto=D.IdProducto AND T.NumTalla=D.NumTalla AND T.IdCia=D.IdCia AND T.IdBodega=D.IdBodega
LEFT JOIN Sys_TiposDoc AS TD ON D.TipDoc=TD.IdDoc LEFT JOIN Companias AS CM ON D.IdCia=CM.IdCia
LEFT JOIN Sys_Um AS UM ON P.UndMed=UM.UndMed
LEFT JOIN ProdSaldos AS S ON T.IdProducto=S.IdProducto AND T.IdBodega=S.IdBodega AND T.IdCia=S.IdCia
WHERE ((D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin) OR D.Fecha IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryTallasMovDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTallasMovDoc] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
AS 
SELECT TM.TipDoc,TM.Documento,TM.IdCia,Compania,TM.Item,TM.Fecha,TM.ItemKdx,TM.IdProducto AS CdProducto,DescripProd
,TM.IdBodega AS CdBodega,Bodega,TM.IdUbic,TM.NumTalla,TM.Entradas,TM.Salidas,TM.CantRem,TM.CantFactura
,TL.Cantidad AS CantSaldo,TL.Pedidos AS CantPed
FROM Trn_TallasMov AS TM INNER JOIN ProdMcias AS P ON TM.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON TM.IdBodega=B.IdBodega INNER JOIN Companias AS CN ON TM.IdCia=CN.IdCia
LEFT JOIN Trn_Tallajes AS TL ON TM.IdProducto=TL.IdProducto AND TM.IdCia=TL.IdCia AND TM.IdBodega=TL.IdBodega
AND TM.NumTalla=TL.NumTalla
WHERE TM.TipDoc=@pmTipDoc AND TM.Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND TM.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTallasMovPed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTallasMovPed] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
SELECT TM.TipDoc,TM.Documento,TM.IdCia,Compania,TM.Item,TM.Fecha,TM.ItemKdx,TM.IdProducto AS CdProducto,DescripProd
,TM.IdBodega AS CdBodega,Bodega,TM.IdUbic,TM.NumTalla,TM.Entradas,TM.Salidas,TM.CantPedido,TM.CantRem,TM.CantFactura
,TL.Cantidad AS CantSaldo,TL.Pedidos AS CantPed,O.Fecha,O.IdCliente
FROM Trn_TallasMov AS TM INNER JOIN ProdMcias AS P ON TM.IdProducto=P.IdProducto
INNER JOIN Bodegas AS B ON TM.IdBodega=B.IdBodega INNER JOIN Companias AS CN ON TM.IdCia=CN.IdCia
INNER JOIN Trn_Opedido AS O ON TM.TipDoc=O.TipDoc AND TM.Documento=O.Pedido AND TM.IdCia=O.IdCia
LEFT JOIN Trn_Tallajes AS TL ON TM.IdProducto=TL.IdProducto AND TM.IdCia=TL.IdCia AND TM.IdBodega=TL.IdBodega
AND TM.NumTalla=TL.NumTalla
WHERE TM.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (TM.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryTalleres]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTalleres] @pmIdTaller VARCHAR(4)
 AS 
 SELECT IdTaller,NomTaller,Direccion,IdLocal,Telefono,TelCelular,NitTercero,TipoTaller,Inactivo
 FROM Talleres WHERE IdTaller=@pmIdTaller
GO
/****** Object:  StoredProcedure [dbo].[paQryTalleresLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTalleresLta] 
 AS 
 SELECT IdTaller,NomTaller,T.Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,T.Telefono,T.TelCelular
,T.NitTercero,RazonSocial AS NomTercero,TipoTaller,T.Inactivo
 FROM Talleres AS T INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 LEFT JOIN Terceros AS N ON T.NitTercero=N.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanqAforo] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4)
 AS 
 SELECT IdTanque,UndAforo,Cantidad
 FROM TanqAforo
 WHERE IdTanque=@pmIdTanque AND UndAforo=@pmUndAforo
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoFrac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanqAforoFrac] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4)
 AS 
 SELECT IdTanque,UndAforo,Fraccion,Milimetros
 FROM TanqAforoFrac
 WHERE IdTanque=@pmIdTanque AND UndAforo=@pmUndAforo
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoFracLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanqAforoFracLta] @pmIdTanque VARCHAR(4)=Null
 AS 
 SELECT A.IdTanque AS NumTanque,UndAforo,Fraccion,Milimetros,T.IdProducto AS CdProd,DescripProd,CapTanq,NivAgua,CapNeta
,SaldoActual,Descripcion,TnqGas,TnqUnido,TnqVirtual
 FROM TanqAforoFrac AS A INNER JOIN Tanques AS T ON A.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE T.Inactivo=0 AND A.IdTanque LIKE ISNULL(@pmIdTanque,'%')
 ORDER BY A.IdTanque,UndAforo
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoLmi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqAforoLmi] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4)
 AS 
 SELECT IdTanque,UndAforo,Cantidad
 FROM TanqAforo
 WHERE IdTanque=@pmIdTanque AND UndAforo<@pmUndAforo
 ORDER BY UndAforo
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoLms]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqAforoLms] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4)
 AS 
 SELECT IdTanque,UndAforo,Cantidad
 FROM TanqAforo
 WHERE IdTanque=@pmIdTanque AND UndAforo>@pmUndAforo
 ORDER BY UndAforo
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqAforoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqAforoLta] @pmIdTanque VARCHAR(4)=Null
 AS 
 SELECT A.IdTanque AS NumTanque,UndAforo,Cantidad,T.IdProducto AS CdProd,DescripProd,CapTanq,NivAgua,CapNeta
,SaldoActual,Descripcion,TnqGas,TnqUnido,TnqVirtual
 FROM TanqAforo AS A INNER JOIN Tanques AS T ON A.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE T.Inactivo=0 AND A.IdTanque LIKE ISNULL(@pmIdTanque,'%')
 ORDER BY A.IdTanque,UndAforo
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispens]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqDispens] @pmIdMngra VARCHAR(10)
 AS 
 SELECT IdMngra,NumDisp,NumPos,NumMngra,IdTanque,Descripcion,LecGalAnt,LecGalUlt,LecPesAnt,LecPesUlt
,LtaPrec,LecGalMax,FechaAdd,FechaUpdate,Inactivo
 FROM TanqDispens
 WHERE IdMngra=@pmIdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqDispensDso] @pmIdTanque VARCHAR(4)=Null,@pmIdCiaDef CHAR(2)=Null
 AS 
 SELECT IdMngra,D.IdTanque AS CdTanq,D.Descripcion AS Descript
,IdMngra+' T'+D.IdTanque+' ('+DescripProd+' '+T.IdProducto+')' AS DsMan
 FROM TanqDispens AS D INNER JOIN Tanques AS T ON D.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE  D.Inactivo=0 AND T.Inactivo=0 AND TnqUnido=0 AND D.IdTanque LIKE ISNULL(@pmIdTanque,'%')
 AND  (IdCiaDef LIKE ISNULL(@pmIdCiaDef,'%%')  OR IdCiaDef='00')
 ORDER BY IdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqDispensLta] @pmIdTanque  VARCHAR(4)=Null,@pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT IdMngra,NumDisp,NumPos,NumMngra,D.IdTanque AS NumTanq,D.Descripcion AS DescripDisp,LecGalAnt,LecGalUlt,LecPesAnt,LecPesUlt,LtaPrec
,T.IdProducto AS CodProd,DescripProd,T.Descripcion AS DescripTanq,CapTanq,NivAgua,CapNeta,SaldoActual,TnqGas,TnqUnido,TnqVirtual,NColor
,D.FechaAdd AS Fec_Add,D.FechaUpdate AS Fec_Upd,LecGalMax
 FROM TanqDispens AS D INNER JOIN Tanques AS T ON D.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE D.Inactivo=0 AND D.IdTanque LIKE ISNULL(@pmIdTanque,'%') 
AND T.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY D.IdTanque,IdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensMan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqDispensMan] @pmNumDisp VARCHAR(4),@pmNumPos VARCHAR(4),@pmNumMngra VARCHAR(4)
 AS 
 SELECT IdMngra,NumDisp,NumPos,NumMngra,D.IdTanque AS CdTanque,D.Descripcion AS DescripDisp,LecGalAnt,LecGalUlt
,LecPesAnt,LecPesUlt,LtaPrec,D.Inactivo AS Disp_inactivo,LecGalMax
--tanques
,T.IdProducto AS CdProd,T.Descripcion AS Tan_Descrip,CapTanq,NivAgua,CapNeta,SaldoActual
 ,TnqGas,TnqUnido,TnqVirtual,T.Inactivo AS Tan_inactivo
--productos
,DescripProd,Referencia,TipoRef,IdBodega,IdUnd,Tanques,ExtciaAct,Precio1
,Precio2,Precio3,Precio4,Precio5,P.Inactivo AS Pro_Inactivo
 FROM TanqDispens  AS D INNER JOIN Tanques AS T ON D.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE NumDisp=@pmNumDisp AND NumPos=@pmNumPos AND NumMngra=@pmNumMngra
 ORDER BY IdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqDispensPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqDispensPro] @pmIdMngra VARCHAR(10)
 AS 
 SELECT IdMngra,NumDisp,NumPos,NumMngra,D.IdTanque AS CdTanque,D.Descripcion AS DescripDisp,LecGalAnt,LecGalUlt
,LecPesAnt,LecPesUlt,LtaPrec,D.Inactivo AS Disp_inactivo,LecGalMax
--tanques
,T.IdProducto AS CdProd,T.Descripcion AS Tan_Descrip,CapTanq,NivAgua,CapNeta,SaldoActual
 ,TnqGas,TnqUnido,TnqVirtual,T.Inactivo AS Tan_inactivo
--productos
,DescripProd,Referencia,TipoRef,IdBodega,IdUnd,Tanques,ExtciaAct,Precio1
,Precio2,Precio3,Precio4,Precio5,P.Inactivo AS Pro_Inactivo
 FROM TanqDispens  AS D INNER JOIN Tanques AS T ON D.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE IdMngra=@pmIdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanqSaldos] @pmIdTanque VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 SELECT IdTanque,IdCia,SaldoActual
 FROM TanqSaldos
 WHERE IdTanque=@pmIdTanque AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqSaldos_Cr] @pmIdProducto VARCHAR(16)=Null,@pmIdTanque VARCHAR(4)=Null
,@pmIdCia CHAR(2)=Null
 AS 
 SELECT T.IdProducto AS CdProducto,DescripProd,S.IdTanque AS CdTanque,Descripcion,S.IdCia AS CdCia,Compania,S.SaldoActual AS SaldoTanque
,CapTanq,NivAgua,CapNeta,T.SaldoActual AS SaldoTotal,TnqGas,TnqUnido,TnqVirtual,NColor,T.Inactivo AS TanInactivo
,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea
,P.IdMarca AS CdMarca,Marca,P.IdUnd AS CdUnid,Unidad,ExtciaMin,ExtciaMax,CostoUlt,CostoPmd,P.Inactivo AS ProInactivo
 FROM TanqSaldos AS S INNER JOIN Tanques AS T ON S.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto INNER JOIN Companias AS CI ON S.IdCia=CI.IdCia
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS SG ON P.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 LEFT JOIN ProdCostos AS PC ON T.IdProducto=PC.IdProducto AND S.IdCia=PC.IdCia
 WHERE Tanques<>0  AND  T.IdProducto LIKE ISNULL(@pmIdProducto,'%')  AND S.IdTanque LIKE ISNULL(@pmIdTanque,'%')
 AND S.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY DescripProd,S.IdTanque,S.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldosSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqSaldosSal] @pmIdCia CHAR(2)=Null
 AS 
 SELECT S.IdTanque AS CdTanque,IdCia,S.SaldoActual AS VrSaldo,T.IdProducto AS CodProducto
,DescripProd,TipoRef,IdBodega
 FROM TanqSaldos AS S INNER JOIN Tanques AS T ON S.IdTanque=T.IdTanque
 INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE S.SaldoActual<>0  AND Tanques<>0  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY S.IdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldosTan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanqSaldosTan] @pmIdCia CHAR(2)=Null
 AS 
 SELECT IdTanque,SUM(SaldoActual)  AS STOTSAL
 FROM TanqSaldos
 WHERE  IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY IdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryTanqSaldosTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanqSaldosTot] @pmIdTanque VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT sum(SaldoActual) AS SSALDO
 FROM TanqSaldos
 WHERE IdTanque LIKE ISNULL(@pmIdTanque,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTanques]    Script Date: 10/12/2025 8:11:25 ******/
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
/****** Object:  StoredProcedure [dbo].[paQryTanquesDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTanquesDso] @pmIdProducto VARCHAR(16)=Null,@pmTnqUnido BIT=Null
,@pmTnqGas BIT=Null,@pmIdCiaDef CHAR(2)=Null
 AS 
 SELECT IdTanque,Descripcion,T.IdProducto AS CdProd,DescripProd
,IdTanque+' '+Descripcion+' ('+DescripProd+' '+T.IdProducto+')' AS DsTan
,IdTanque AS IdBodega,IdTanque+' '+Descripcion+' '+T.IdProducto AS DsBod
 FROM Tanques AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE T.Inactivo=0 AND  T.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND (TnqUnido=ISNULL(@pmTnqUnido,0) or TnqUnido=ISNULL(@pmTnqUnido,1))
 AND (TnqGas=ISNULL(@pmTnqGas,0) or TnqGas=ISNULL(@pmTnqGas,1))
 AND (IdCiaDef LIKE ISNULL(@pmIdCiaDef,'%%')  OR IdCiaDef='00')
 ORDER BY IdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQryTanquesLta]    Script Date: 10/12/2025 8:11:25 ******/
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
/****** Object:  StoredProcedure [dbo].[paQryTarifAnticipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifAnticipos] @pmNumero INT
 AS 
 SELECT Numero,CuotaMax,TipoCuota,TipoAplica,CdOrigen,CdDestino,CdRuta,NitCliente
,CdTipoVeh,TipoAfilVeh,Inactivo,NitPropietario,Tipo_Egreso,FechaCrea,IdUsuario
 FROM TarifAnticipos
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifAnticiposLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTarifAnticiposLta] @pmTipoCuota VARCHAR(10)=Null,@pmTipoAplica VARCHAR(10)=Null,@pmInactivo BIT=Null
 AS 
 SELECT Numero,TipoAplica,CuotaMax,TipoCuota,CdRuta,CdOrigen,O.Localidad AS CiuOrigen,CdDestino,D.Localidad AS CiuDestino
,NitCliente,RazonSocial,CdTipoVeh,TipoVehiculo,TipoAfilVeh,A.Inactivo AS Inactvo,FechaCrea,A.IdUsuario AS CdUsuario,Usuario
,O.IdDep AS CdDep,DPO.Departamento AS DptoOrigen,D.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,NitPropietario,Tipo_Egreso
 FROM TarifAnticipos AS A INNER JOIN  adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 LEFT JOIN Localidades AS O ON A.CdOrigen=O.IdLocal LEFT JOIN Localidades AS D ON  A.CdDestino=D.IdLocal
 LEFT JOIN Departamentos AS DPO ON O.IdDep=DPO.IdDep LEFT JOIN Departamentos AS DPD ON D.IdDep=DPD.IdDep
 LEFT JOIN Terceros AS TC ON A.NitCliente=TC.IdTercero LEFT JOIN TiposVeh AS TV ON A.CdTipoVeh=TV.IdTipoVeh
 WHERE  TipoCuota LIKE ISNULL(@pmTipoCuota,'%') AND  TipoAplica LIKE ISNULL(@pmTipoAplica,'%')
 AND  (A.Inactivo=ISNULL(@pmInactivo,0) or A.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFleMay]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasFleMay] @pmIdAgencia VARCHAR(16),@pmTipoTarifa VARCHAR(10),@pmNumero INT
 AS 
 SELECT IdAgencia,TipoTarifa,Numero,TipoVehic,NitEmpresa,CapacMin,CapacMax,VrTarifa,TipoLiquida,DescTipoVeh,Inactivo,FechaCrea,IdUsuario
 FROM TarifasFleMay
 WHERE IdAgencia=@pmIdAgencia AND TipoTarifa=@pmTipoTarifa AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFleMayLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasFleMayLta] @pmIdAgencia VARCHAR(16)
 AS 
 SELECT A.IdClie AS NitClie,T.RazonSocial AS NomCliente,F.IdAgencia AS CdAgencia,Agencia,TipoTarifa,Numero
,F.TipoVehic AS CdTipoVeh,TV.TipoVehic AS TipoVeh,F.CapacMax AS CapMaxima,VrTarifa,TipoLiquida,F.Inactivo AS Inactvo
,NitEmpresa,E.RazonSocial AS NomEmpresa,TV.CapacMin AS Cap_Minimo,TV.CapacMax AS Cap_Maximo,FechaCrea,F.IdUsuario AS CdUsuario,Usuario
FROM TarifasFleMay AS F INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia
INNER JOIN Terceros AS T ON A.IdClie=T.IdTercero LEFT JOIN TiposVehFletes AS TV ON F.TipoVehic=TV.Item 
LEFT JOIN Terceros AS E ON F.NitEmpresa=E.IdTercero
WHERE F.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFletes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasFletes] @pmNumero INT
 AS 
 SELECT Numero,IdOrigen,IdDestino,CdRuta,TipoTarifa,TarifClie,TarifPago,TarifTabla,IdMneda,UndMed
,NitCliente,CdNat,CdTipoVeh,CdRango,UndTarifClie,UndTarifPago
,Inactivo,CdMercancia,TipoAfiVehic,TarifAfiliado,TarifTercero,TarifPropio,TipoOper,CdGrupo,MargenMin,CdAgencia,FechaCrea,IdUsuario
 FROM TarifasFletes
 WHERE  Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasFletesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasFletesLta] @pmTipoTarifa VARCHAR(10)=Null,@pmIdOrigen VARCHAR(8)=Null,@pmIdDestino VARCHAR(8)=Null
,@pmNitCliente VARCHAR(16)=Null,@pmInactivo BIT=Null,@pmCdRuta VARCHAR(4)=Null
 AS 
 SELECT Numero,IdOrigen,O.Localidad AS CiuOrigen,IdDestino,D.Localidad AS CiuDestino,CdRuta,TarifClie,TarifPago,TarifTabla,IdMneda,T.UndMed AS Und_Med,Unidad
,NitCliente,RazonSocial,CdNat,Natlzaprod,CdTipoVeh,TipoVehiculo,CdRango,DescripRango,T.Inactivo AS Inactvo,UndTarifClie,UndTarifPago,CdMercancia,TipoAfiVehic
,TarifAfiliado,TarifTercero,TarifPropio,TipoOper,CdGrupo,GrupoProp,MargenMin,CdAgencia,FechaCrea,T.IdUsuario AS CdUsuario,Usuario
,O.IdDep AS CdDep,DPO.Departamento AS DptoOrigen,D.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,TipoTarifa
 FROM TarifasFletes AS T INNER JOIN Localidades AS O ON T.IdOrigen=O.IdLocal INNER JOIN Localidades AS D ON T.IdDestino=D.IdLocal
 INNER JOIN Departamentos AS DPO ON O.IdDep=DPO.IdDep INNER JOIN Departamentos AS DPD ON D.IdDep=DPD.IdDep
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS TC ON T.NitCliente=TC.IdTercero LEFT JOIN Sys_Um AS UM ON T.UndMed=UM.UndMed 
 LEFT JOIN TiposNat AS N ON T.CdNat=N.IdNat LEFT JOIN TiposVeh AS TV ON T.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN RangosPeso AS R ON T.CdRango=R.IdRango LEFT JOIN GruposPro AS G ON T.CdGrupo=G.IdGrupo
 WHERE TipoTarifa LIKE ISNULL(@pmTipoTarifa,'%') AND  IdOrigen LIKE ISNULL(@pmIdOrigen,'%')
 AND IdDestino LIKE ISNULL(@pmIdDestino,'%') AND NitCliente LIKE ISNULL(@pmNitCliente,'%')
 AND CdRuta LIKE ISNULL(@pmCdRuta,'%')
 AND  (T.Inactivo=ISNULL(@pmInactivo,0) or T.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY O.Localidad,D.Localidad,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasMasivoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasMasivoLta] @pmIdOrigen VARCHAR(8)=Null,@pmIdDestino VARCHAR(8)=Null
AS
 SELECT IdOrigen,O.Localidad AS CiuOrigen,O.IdDep AS CdDepOrig,DOR.Departamento AS DptoOrigen
,IdDestino,D.Localidad AS CiuDestino,D.IdDep AS CdDepDtno,DDT.Departamento AS DptoDtno
,T.IdTipoVeh AS CdTipoVeh,TipoVehiculo,TarifaUnd,VrFletes
 FROM TarifasMasivo AS T INNER JOIN Localidades AS O ON T.IdOrigen=O.IdLocal INNER JOIN Departamentos AS DOR ON O.IdDep=DOR.IdDep
 INNER JOIN Localidades AS D ON T.IdDestino=D.IdLocal INNER JOIN Departamentos AS DDT ON D.IdDep=DDT.IdDep
 INNER JOIN TiposVeh AS TV ON T.IdTipoVeh=TV.IdTipoVeh
 WHERE T.IdOrigen LIKE ISNULL(@pmIdOrigen,'%') AND T.IdDestino LIKE ISNULL(@pmIdDestino,'%')
 AND T.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasPaqLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasPaqLta] @pmIdOrigen VARCHAR(8)=Null,@pmIdDestino VARCHAR(8)=Null
AS
 SELECT IdOrigen,O.Localidad AS CiuOrigen,O.IdDep AS CdDepOrig,DOR.Departamento AS DptoOrigen
,IdDestino,D.Localidad AS CiuDestino,D.IdDep AS CdDepDtno,DDT.Departamento AS DptoDtno
,TarifaUnd,TiempoEnt,TarifaMin,FormaPago
 FROM TarifasPaq AS T INNER JOIN Localidades AS O ON T.IdOrigen=O.IdLocal INNER JOIN Departamentos AS DOR ON O.IdDep=DOR.IdDep
 INNER JOIN Localidades AS D ON T.IdDestino=D.IdLocal INNER JOIN Departamentos AS DDT ON D.IdDep=DDT.IdDep
 WHERE T.IdOrigen LIKE ISNULL(@pmIdOrigen,'%') AND T.IdDestino LIKE ISNULL(@pmIdDestino,'%')
 AND T.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasServ]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasServ] @pmNumero INT
 AS 
 SELECT Numero,TipoServ,IdCliente,IdMercancia,IdEstacion,UndMed,TipoAfiVehic
,CdTipoVeh,TarifaClie,TarifaPago,Inactivo,MargenMin,CdRuta,CdCiuOrigen,CdCiuDestino,FechaCrea,IdUsuario
 FROM TarifasServ
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifasServLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTarifasServLta] 
 AS 
SELECT Numero,TipoServ,IdCliente,RazonSocial,T.IdMercancia AS CodMcia,DescripMcia,T.IdEstacion AS IdCampo,E.EstServicio AS DescCampo
,T.UndMed,Unidad,TipoAfiVehic,CdTipoVeh,TarifaClie,TarifaPago,MargenMin,T.Inactivo
,CdRuta,CdCiuOrigen,O.Localidad AS CiuOrigen,CdCiuDestino,D.Localidad AS CiuDestino,T.FechaCrea,T.IdUsuario AS CdUsuario,Usuario
FROM TarifasServ AS T INNER JOIN Terceros AS C ON T.IdCliente=C.IdTercero INNER JOIN EdsServicio AS E ON T.IdEstacion=E.IdEstacion 
INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario INNER JOIN Sys_Um AS UM ON T.UndMed=UM.UndMed
LEFT JOIN Mercancias AS M ON T.IdMercancia=M.IdMercancia LEFT JOIN Localidades AS O ON T.CdCiuOrigen=O.IdLocal
LEFT JOIN Localidades AS D ON T.CdCiuDestino=D.IdLocal
GO
/****** Object:  StoredProcedure [dbo].[paQryTarifBuses]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTarifBuses] @pmIdTarifa VARCHAR(4)
 AS 
 IF @pmIdTarifa IS NULL
 SELECT IdTarifa,Descripcion,VrNormal,VrFestivo
 FROM TarifBuses
 WHERE Inactivo=0
 ORDER BY Descripcion
 ELSE
 SELECT IdTarifa,Descripcion,VrNormal,VrFestivo,Inactivo
 FROM TarifBuses
 WHERE IdTarifa=@pmIdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paQrytasas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytasas] @pmIdMneda VARCHAR(5),@pmIdMnedaD VARCHAR(5),@pmFecha SMALLDATETIME
 AS 
 SELECT IdMneda,IdMnedaD,Fecha,TasaDia
 FROM Trn_tasas
 WHERE IdMneda=@pmIdMneda AND IdMnedaD=@pmIdMnedaD AND Fecha=@pmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQrytasasDiv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytasasDiv] @pmIdMneda VARCHAR(5),@pmIdMnedaD VARCHAR(5),@pmFecha SMALLDATETIME
 AS 
 SELECT T.IdMneda AS IdMnyO,MO.Mneda AS MnyOrig,MO.Simbolo AS SimbOrig
,IdMnedaD,MD.Mneda AS MnyDtn,MD.Simbolo AS SimbDtn,Fecha,TasaDia
 FROM Trn_tasas AS T INNER JOIN adm_monedas AS MO ON T.IdMneda=MO.IdMneda
 INNER JOIN adm_monedas AS MD ON T.IdMnedaD=MD.IdMneda
 WHERE T.IdMneda=@pmIdMneda AND IdMnedaD=@pmIdMnedaD AND Fecha=@pmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQryTasasInteres]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTasasInteres] @pmIdTasa VARCHAR(4)
 AS 
 SELECT IdTasa,DescTasa,TipoInteres,TipoPeriodo,CausaInteres,TipoDTF,DTF_EA,Spread_TA,TasaEfectiva,OpcCompra,Inactivo
 FROM TasasInteres
 WHERE IdTasa=@pmIdTasa
GO
/****** Object:  StoredProcedure [dbo].[paQryTasasInteresDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTasasInteresDso] 
 AS 
 SELECT IdTasa,DescTasa,IdTasa+' '+DescTasa+' ( '+TipoInteres+'  '+TipoPeriodo
 + ' '+CASE CausaInteres WHEN 1 THEN 'ANTICIPADA' ELSE 'VENCIDA' END +'  DTF '+TipoDTF+')' AS DsTasa 
 FROM TasasInteres
 WHERE Inactivo=0 
 ORDER BY IdTasa
GO
/****** Object:  StoredProcedure [dbo].[paQryTasasIntmoraDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTasasIntmoraDso] 
 AS 
 SELECT IdMora,DescMora,IdMora+' '+DescMora+' ( '+TipoInteres+'  '+STR(TasaEM,7,4)+ ')' AS DsTasa 
 FROM TasasIntmora
 WHERE Inactivo=0 
 ORDER BY IdMora
GO
/****** Object:  StoredProcedure [dbo].[paQrytasasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytasasLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
,@pmIdMneda VARCHAR(5)=Null,@pmIdMnedaD VARCHAR(5)=Null,@pmInactivo BIT=Null
 AS 
 SELECT Fecha,'1 '+MO.Mneda+' '+MO.Simbolo AS MnyOrigen,TasaDia,MD.Mneda+' '+MD.Simbolo AS MnyDestino
,T.IdMneda AS IdMonO,IdMnedaD
 FROM Trn_tasas AS T INNER JOIN adm_monedas AS MO ON T.IdMneda=MO.IdMneda
 INNER JOIN adm_monedas AS MD ON T.IdMnedaD=MD.IdMneda
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND  T.IdMneda LIKE ISNULL(@pmIdMneda,'%')
 AND IdMnedaD LIKE ISNULL(@pmIdMnedaD,'%')
 AND (MO.Inactivo=ISNULL(@pmInactivo,0) or MO.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Fecha,MO.Mneda,MD.Mneda
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxRutas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTaxRutas] @pmIdRuta VARCHAR(4)
 AS 
 SELECT IdRuta,NomRuta,TipoRuta,TarifPago,TarifCobro,Origen,Destino,CodRuta,Inactivo
 FROM TaxRutas
 WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxRutasDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTaxRutasDso] 
 AS 
 SELECT   IdRuta,NomRuta,IdRuta+' '+NomRuta AS DSRUT
 FROM TaxRutas
 WHERE  Inactivo=0
 ORDER BY IdRuta
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxTarifas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTaxTarifas] @pmTipoTarif VARCHAR(10),@pmItem INT
 AS 
 SELECT TipoTarif,Item,TipoHora,NumInicial,NumFinal,TarifPago,TarifCobro
 FROM TaxTarifas
 WHERE TipoTarif=@pmTipoTarif AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryTaxTarifClie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTaxTarifClie] @pmTipoTarif VARCHAR(10),@pmItem INT
 AS 
 SELECT TipoTarif,Item,IdClie,TipoHora,IdRuta,NumInicial,NumFinal,TarifPago,TarifCobro
 FROM TaxTarifClie
 WHERE TipoTarif=@pmTipoTarif AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieCia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieCia] @pmIdClie VARCHAR(16),@pmIdCia CHAR(2)
 AS 
 SELECT IdClie,IdCia
 FROM TercClieCia
 WHERE IdClie=@pmIdClie AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieCuposLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieCuposLta] 
 AS 
 SELECT C.IdClie,RazonSocial,C.IdAgencia AS CdAgencia,Agencia,C.nAnno,C.nMes,C.CupoGals,C.CupoZFE,C.CupoAdic
 FROM TercClieCupos AS C INNER JOIN Terceros AS T ON C.IdClie=T.IdTercero 
 LEFT JOIN Agencias AS A ON C.IdAgencia=A.IdAgencia
 WHERE T.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieGarant]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieGarant] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4),@pmItem INT
 AS 
 SELECT IdClie,IdAgencia,IdLinea,Item,TipoGarant,CdInmueble,CdTipoVeh,VrGarant,VrAvaluo,Propietario,DirInmueble,CdCiudad,Matricula,Escritura
,NumNotaria,MarcaVeh,Modelo,CdBanco,FecCheque,NumCheque,OtroTipoVehic,OtroInmueble,CedFmnte1,NomFmnte1,CedFmnte2,NomFmnte2
,CedFmnte3,NomFmnte3,CedFmnte4,NomFmnte4,CedFmnte5,NomFmnte5,CedFmnte6,NomFmnte6
 FROM TercClieGarant
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia AND IdLinea=@pmIdLinea AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieGarantLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieGarantLta] @pmIdClie VARCHAR(16),@pmIdLinea VARCHAR(4)
 AS 
 SELECT CG.IdClie AS NitClie,RazonSocial,CG.IdAgencia AS CdAgencia,NomAgencia,CG.IdLinea AS CdLinea,LinCredito,Item,TipoGarant,CdInmueble,TipoInmueble
,CdTipoVeh,TipoVehiculo,VrGarant,VrAvaluo,Propietario,DirInmueble,CdCiudad,Localidad,Matricula,Escritura
,NumNotaria,MarcaVeh,Modelo,CdBanco,Banco,FecCheque,NumCheque,OtroTipoVehic,OtroInmueble,CedFmnte1,NomFmnte1,CedFmnte2,NomFmnte2
,CedFmnte3,NomFmnte3,CedFmnte4,NomFmnte4,CedFmnte5,NomFmnte5,CedFmnte6,NomFmnte6
,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero
 FROM TercClieGarant AS CG INNER JOIN TercCliePrestamo AS CLI ON CG.IdClie=CLI.IdClie AND CG.IdAgencia=CLI.IdAgencia
 INNER JOIN Terceros AS T ON CG.IdClie=T.IdTercero INNER JOIN LineasCred AS L ON CG.IdLinea=L.IdLinea
 INNER JOIN TiposTerc AS TC ON CLI.IdTipoTerc=TC.IdTipoTerc
 LEFT JOIN TiposInm AS IM ON CG.CdInmueble=IM.IdTipoInm LEFT JOIN TiposVeh AS TV ON CG.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Bancos AS B ON CG.CdBanco=B.IdBanco LEFT JOIN Localidades AS LC ON CG.CdCiudad=LC.IdLocal
 WHERE CG.IdClie LIKE ISNULL(@pmIdClie,'%') AND CG.IdLinea LIKE ISNULL(@pmIdLinea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieLineas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieLineas] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4)
 AS 
 SELECT IdClie,IdAgencia,IdLinea,IdTasa,nPlazo,TipoPlazo,CupoCredito,SaldoCapital,SaldoInteres,MaxCupoSmlv,TipoCausac,DiasVence,LiqSeguro,FecPreAprob
,PlazoAprob,EtdoAprob,TipoAprob,DescAprob,Garantias,TipoGarantia,DescGarantia,VrGarantia,ReqCheques,FecActCupo
,CdTasaConv,NitConvenio,CuotasConv,CdTarifSeguro,EstadoAct,TasaIntLinea,FechaCrea,FechaAct,IdUsuario
 FROM TercClieLineas
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia AND IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieLineasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieLineasLta] @pmIdClie VARCHAR(16)=Null,@pmIdLinea VARCHAR(4)=Null,@pmIdTipoTerc  VARCHAR(4)=Null
 AS 
 SELECT LC.IdClie AS NitCliente,RazonSocial,LC.IdAgencia AS CdAgencia,NomAgencia,LC.IdLinea AS CdLinea,LinCredito,LC.IdTasa AS CdTasa,DescTasa,TasaEfectiva,nPlazo,TipoPlazo,CupoCredito
,SL.SaldoCapital,SL.SaldoInteres,MaxCupoSmlv,TipoCausac,DiasVence,FecPreAprob,PlazoAprob,EtdoAprob,TipoAprob,DescAprob,Garantias,TipoGarantia,DescGarantia,VrGarantia
,ReqCheques,FecActCupo,EstadoAct,LiqSeguro,CdTarifSeguro,CdTasaConv,NitConvenio,CuotasConv,TasaIntLinea,LC.FechaCrea AS FecCrea,LC.FechaAct AS FecActualiza,LC.IdUsuario AS CdUsuario,Usuario
--datos del cliente
,TipoId,Dv,C.IdTipoTerc AS CdTipoTerc,TipoTercero,C.IdEstado AS CdEstado,Estado,FecIngreso,VrSalBasico,MaxDcto,Comentarios
 FROM TercClieLineas AS LC INNER JOIN LineasCred AS L ON LC.IdLinea=L.IdLinea
 INNER JOIN TercCliePrestamo AS C ON LC.IdClie=C.IdClie AND LC.IdAgencia=C.IdAgencia  INNER JOIN Terceros AS T ON LC.IdClie=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON LC.IdUsuario=U.IdUsuario
 INNER JOIN TiposTerc AS TC ON C.IdTipoTerc=TC.IdTipoTerc  INNER JOIN EstadoTer AS EC ON C.IdEstado=EC.IdEstado
 LEFT JOIN TasasInteres AS TI ON LC.IdTasa=TI.IdTasa
 LEFT JOIN (SELECT IdClie,CdAgencia,IdLinea,SUM(VrSaldoCap) AS SaldoCapital,SUM(VrSaldoInt) AS SaldoInteres FROM FinClieSaldosLin
 GROUP BY IdClie,CdAgencia,IdLinea) AS SL ON LC.IdClie=SL.IdClie AND LC.IdAgencia=SL.CdAgencia AND LC.IdLinea=SL.IdLinea
 WHERE C.Inactivo=0 AND LC.IdClie LIKE ISNULL(@pmIdClie,'%') AND LC.IdLinea LIKE ISNULL(@pmIdLinea,'%')
 AND  C.IdTipoTerc  LIKE ISNULL(@pmIdTipoTerc ,'%')
 ORDER BY RazonSocial,LC.IdLinea
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCliente]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCliente] @pmIdClie VARCHAR(16)
 AS 
 SELECT IdClie,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirEnv,IdLocEnv,DiasEntga
,IdSzona,IdGrupo,IdPlazo,CdPlazoComb,IdForma,IdEstrato,IdVend,NitFact,IdRuta,IdClase,NumCuenta,IdBanco,CdMney,CdDct,CdRet,CdRiv
,CdCms,PlazosImp,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,PwdClie
,FecIngreso,FecVigencia,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,Cmntario1,Cmntario2,CdBandera,CodClieSicom,Contrato,NContrato,CiaContMay,Cmntario3,PrendGarant,FecUpCupo
,TipoCliente,CupoGalones,Restric_Cia,FecPlazoDoc,EdoRadicaDoc,CdTipBloq,DescEdoDoc,ComIndustrial,NumLista,IdEstado,Inactivo,Termicas,CodRetCom,CodCCosto,CodSubCosto,CdDiaEnt
,AutoIca,ExcImpBACU,TipoFMR,FechaAdd,FechaUpdate,IdUsuario
 FROM TercCliente
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClienteLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClienteLta] @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdRegimen VARCHAR(4)=Null,@pmTipoId CHAR(1)=Null
,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLocEnv VARCHAR(8)=Null,@pmIdForma VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null,@pmIdZona VARCHAR(4)=Null
,@pmIdSzona VARCHAR(4)=Null,@pmIdPlazo VARCHAR(4)=Null,@pmIdEstrato VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdRuta VARCHAR(4)=Null
,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmInactivoTer BIT=Null
 AS 
 SELECT IdClie,T.RazonSocial AS RaznSocial,T.TipoId AS TipId,T.Dv AS DvNit,T.NomCial AS NombreCmcial,T.SiglaRaz AS SiglaRazSocial
,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,T.Direccion AS Dirccion,T.IdLocal AS CdCiudad,L.Localidad AS Ciudad,L.IdDep AS CdDpto
,D.Departamento AS Dpto,T.Telefono AS Tlefono,T.Fax AS NumFax,T.TelMovil AS TelCeluar,T.SitioWeb AS WebSite,T.e_mail AS Email,DirEnv,IdLocEnv,LE.Localidad AS CiuEnvio
,DE.Departamento AS Dptoenvio,DiasEntga,C.IdGrupo AS CdGrupo,GrupoClie,C.IdEstrato AS CdEstrato,Estrato,SZ.IdZona AS CdZona,Zona,C.IdSzona AS CdSubzona,Subzona
,C.IdRuta AS CdRuta,Ruta,C.IdPlazo AS CdPlazo,Plazo,NVmto,PlazosImp,CdPlazoComb,C.IdForma AS CdFrma,FormaPago,T.IdSector AS CdSector,SectorEco,T.IdProf AS CdProf,Profesion,T.IdRegimen AS CdRgmen
,Regimen,T.TipEnte AS TipoEnte,IdVend,TV.RazonSocial AS NomVendedor,NitFact,C.IdClase AS CdClase,ClaseCuenta,NumCuenta,C.IdBanco AS CdBanco,Banco,B.Direccion AS Dirbanco
,CdMney,CdDct,CdRet,CdRiv,CdCms,ExcIva,TrfIntMora,DiasGracia,LiqFletes,FactSold,Autoret,AutoIca,IncRet,IncRiv,IncIca,FactTipo,VrCupo,VrSaldo,UidClie,Contrato,NContrato,CiaContMay,FecIngreso,FecVigencia
,FecRetiro,MatMerc,FecMat,PathFoto,PathFirma,T.Observacion AS Observ,Cmntario1,Cmntario2,Cmntario3,CdBandera,TipoBandera,PrendGarant,FecUpCupo,TipoCliente,CodClieSicom,ExcImpBACU,C.TipoFMR,CdDiaEnt,C.IdEstado AS CdEst_clie,EC.Estado AS EstadoClie,C.Inactivo AS Clie_inactivo
,T.IdEstado AS CdEst_terc,ET.Estado AS Estad_terc,T.Inactivo AS Terc_inactivo,T.Codigo AS CodTerc,T.IdLugarCed AS IdLugCed,LC.Localidad AS LugarCed,T.FecExpCed AS FecExpCedula
,T.EsVendedor AS EsVend,T.EsConductor AS EsCond,T.EsPropietario AS EsProp,T.EsProveedor AS EsProvee,T.EsEmpleado AS EsEmpldo,T.EsOperario AS EsOper,T.EsAccnista AS EsAcc
,T.EsCiaAseg AS EsAseg,T.RecPublicos,T.CargoPublico,T.FecInicioCP,T.FecFinalCp,T.PersonaPub,T.CargoPersPub,T.FecInicioPP,T.FecFinalPP,T.VrIngresos,T.VrOtroIng,T.VrGastos,T.VrActivos,T.VrPasivos,T.VrPatrimonio,T.ConcOtrosIng
,T.OperActVirtual,T.TipoOperVirtual,T.LavadoActivos,T.RL_Nombre,T.RL_Identificacion,T.RL_Direccion,T.RL_CodCiudad,T.RL_Telefono,T.RL_Email,CdTipBloq,C.FechaAdd AS FecAdd,C.FechaUpdate AS FecUpd,C.IdUsuario AS IdUsuari,Usuario,T.IniStgNom AS PosNomb,Restric_Cia,CupoGalones,FecPlazoDoc,EdoRadicaDoc
,DescEdoDoc,ComIndustrial,NumLista,Termicas,CodRetCom,CodCCosto,CodSubCosto,T.FechaNac,T.ImagenDoc1,T.ImagenDoc2,T.ImagenDoc3,T.PN_RUT
 FROM TercCliente AS C INNER JOIN Terceros AS T ON C.IdClie=T.IdTercero  INNER JOIN Terceros AS TV ON C.IdVend=TV.IdTercero
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN Estratos AS ETC ON C.IdEstrato=ETC.IdEstrato
 INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona  INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN Plazos AS PZ ON C.IdPlazo=PZ.IdPlazo INNER JOIN Rutas AS R ON C.IdRuta=R.IdRuta
 INNER JOIN Formaspago AS F ON C.IdForma=F.IdForma
 INNER JOIN ClaseCta AS CTA ON  C.IdClase=CTA.IdClase
 INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco INNER JOIN EstadoTer AS EC ON C.IdEstado=EC.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario   INNER JOIN Localidades AS LE ON C.IdLocEnv=LE.IdLocal
 INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf LEFT JOIN TiposBan TB ON C.CdBandera=TB.IdBandera
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%')  AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND T.TipoId LIKE ISNULL(@pmTipoId,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%') AND C.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdLocEnv LIKE ISNULL(@pmIdLocEnv,'%') AND C.IdForma LIKE ISNULL(@pmIdForma,'%') AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND SZ.IdZona LIKE ISNULL(@pmIdZona,'%') AND C.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND C.IdPlazo LIKE ISNULL(@pmIdPlazo,'%') AND C.IdEstrato LIKE ISNULL(@pmIdEstrato,'%')
 AND IdVend LIKE ISNULL(@pmIdVend,'%') AND C.IdRuta LIKE ISNULL(@pmIdRuta,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCliePrestamo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCliePrestamo] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16)
 AS 
 SELECT IdClie,IdAgencia,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,NomAgencia,DirAgencia,IdLocalAge,IdSzona,IdGrupo,IdTipoTerc,IdVend,IdClase,NumCuenta,IdBanco
,EsExento,CalcIntMora,DiasGracia,FecIngreso,FecVigencia,FecRetiro,VrSalBasico,MaxDcto,TipoSalario,MatMerc,FecMat,Comentarios,IdEstado,Inactivo,NumTarj,PwdTarj,FecVenceTc,IncRetFte
,FechaCrea,FechaAct,FechaImp,CodCCosto,CodSubCosto,FecNacmto,Nacionalidad,Sexo,CdEstCivil,NumPerCargo,NivelEduc,TipoVivienda,EstratoSocial,IdOcupac,VrPension,VrOtrosDev,VrPasivo,VrPatrimonio
,EmpresaLab,FecIngLab,TelEmpresa,DirEmpresa,EmailEmpresa,BaseAportes,CdTarifApo,VrAportes,FecInicioApo,FecFinalApo,DiaCausacApo,FecRetiroApo,CausalRetiro,SinDctoNom,SinLiqAporte,CabFamilia,DebitoAuto,VrActivos,IdUsuario
 FROM TercCliePrestamo
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCliePrestamoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCliePrestamoLta]  @pmIdGrupo VARCHAR(4)=Null,@pmIdVend VARCHAR(16)=Null,@pmIdSzona VARCHAR(4)=Null
,@pmIdTipoTerc  VARCHAR(4)=Null,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT IdClie,T.RazonSocial AS Razon_Social,T.TipoId AS TipId,T.Dv AS DvNit,T.NomCial AS NombreCmcial,T.SiglaRaz AS SiglaRazSocial
,IdAgencia,NomAgencia,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,T.Direccion AS TercDireccion,T.IdLocal AS CdCiudad,L.Localidad AS Ciudad,L.IdDep AS CdDpto
,D.Departamento AS Dpto,T.Telefono AS Tlefono,T.Fax AS NumFax,T.TelMovil AS TelCeluar,T.SitioWeb AS WebSite,T.e_mail AS Email
,DirAgencia,IdLocalAge,LE.Localidad AS CiuAgencia,DE.Departamento AS DptoAgencia,C.IdTipoTerc AS CdTipoTerc,TipoTercero
,SZ.IdZona AS CdZona,Zona,C.IdSzona AS CdSubzona,Subzona,C.IdGrupo AS CdGrupo,GrupoClie,T.IdSector AS CdSector,SectorEco,T.IdProf AS CdProf,Profesion,T.IdRegimen AS CdRgmen,Regimen
,T.TipEnte AS TipoEnte,IdVend,TV.RazonSocial AS NomVendedor,C.IdClase AS CdClase,ClaseCuenta,NumCuenta,C.IdBanco AS CdBanco,Banco
,EsExento,CalcIntMora,DiasGracia,FecIngreso,FecVigencia,FecRetiro,VrSalBasico,TipoSalario,MaxDcto,MatMerc,FecMat,IncRetFte,NumTarj,FecVenceTc,FechaImp,CodCCosto,CodSubCosto
,C.FecNacmto,C.Nacionalidad,C.Sexo,C.CdEstCivil,EstCivil,C.NumPerCargo,C.NivelEduc,C.TipoVivienda,C.EstratoSocial,C.IdOcupac,Ocupacion,C.VrPension,C.VrOtrosDev,C.VrActivos,C.VrPasivo,C.VrPatrimonio
,C.EmpresaLab,C.FecIngLab,C.TelEmpresa,C.DirEmpresa,C.EmailEmpresa,C.BaseAportes,C.CdTarifApo,TA.Tarifa AS TarifApo,C.VrAportes,C.FecInicioApo,C.FecFinalApo,C.DiaCausacApo,C.FecRetiroApo,C.CausalRetiro,C.SinDctoNom,C.SinLiqAporte,C.CabFamilia,C.DebitoAuto
,Comentarios,C.IdEstado AS CdEstado,EC.Estado AS EstadoClie,C.Inactivo AS ClieInactivo,FechaCrea,FechaAct,C.IdUsuario AS CdUsuario,Usuario
,T.IniStgNom AS PosNomb,T.IdLugarCed AS IdLugCed,LC.Localidad AS LugarCed,T.FecExpCed AS FecExpCedula,T.PN_RUT,T.Inactivo AS TercInactivo,T.Codigo AS TercCodigo
 FROM TercCliePrestamo AS C INNER JOIN Terceros AS T ON C.IdClie=T.IdTercero  INNER JOIN Terceros AS TV ON C.IdVend=TV.IdTercero
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN TiposTerc AS TC ON C.IdTipoTerc=TC.IdTipoTerc
 INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona  INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN EstadoTer AS EC ON C.IdEstado=EC.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LE ON C.IdLocalAge=LE.IdLocal INNER JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
 LEFT JOIN ClaseCta AS CTA ON C.IdClase=CTA.IdClase LEFT JOIN Bancos AS B ON C.IdBanco=B.IdBanco 
 LEFT JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal  LEFT JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN Tablapor AS TA ON C.CdTarifApo=TA.IdTarifa LEFT JOIN Ocupaciones AS OC ON C.IdOcupac=OC.IdOcupac
 LEFT JOIN EstadoCiv AS EV ON C.CdEstCivil=EV.IdEstado
 WHERE C.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND  C.IdSzona LIKE ISNULL(@pmIdSzona,'%')  AND  C.IdTipoTerc  LIKE ISNULL(@pmIdTipoTerc ,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRef]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieRef] @pmIdClie VARCHAR(16),@pmItem INT
 AS 
 SELECT IdClie,Item,TipoRef,Referencia,NitRefncia,DirRefncia,TelRefncia,emlRefncia,CargRefncia,NumCuenta,Observcion
 FROM TercClieRef
 WHERE IdClie=@pmIdClie
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRef_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieRef_Cr] @pmIdClie VARCHAR(16)=Null
 AS 
 SELECT IdClie,Item,TipoRef,Referencia,NitRefncia,DirRefncia,TelRefncia,emlRefncia,CargRefncia,NumCuenta,Observcion
 FROM TercClieRef
 WHERE IdClie LIKE ISNULL(@pmIdClie,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRefItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieRefItm] @pmIdClie VARCHAR(16)
 AS 
 SELECT MAX(Item) AS MXNUM 
 FROM TercClieRef
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieRefLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieRefLta] @pmIdClie VARCHAR(16)=Null
 AS 
 SELECT IdClie,RazonSocial,Item,TipoRef,Referencia,NitRefncia,DirRefncia,TelRefncia,emlRefncia,CargRefncia,NumCuenta,Observcion
 FROM TercClieRef AS TR INNER JOIN Terceros AS T ON TR.IdClie=T.IdTercero
 WHERE IdClie LIKE ISNULL(@pmIdClie,'%')
 ORDER BY RazonSocial,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieSaldos] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16)
,@pmIdCia CHAR(2)
 AS 
 SELECT IdClie,CdAgencia,IdCia,VrSaldo
 FROM TercClieSaldos
 WHERE IdClie=@pmIdClie AND CdAgencia=@pmCdAgencia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieSaldos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieSaldos_Cr] @pmIdClie VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmCdAgencia VARCHAR(16)=Null
AS 
 SELECT S.IdClie AS NitCliente,RazonSocial,CdAgencia,Agencia,S.IdCia AS CdCia,Compania,S.VrSaldo AS SaldoCia
--datos del cliente
,TipoId,Dv,NomCial,SiglaRaz,VrCupo,C.VrSaldo AS  ClieSaldo
,C.IdGrupo AS CdGrupo,GrupoClie,SZ.IdZona AS CdZona,Z.Zona AS ClieZona,C.IdSzona AS CdSubzona,SZ.Subzona AS ClieSubZona
,C.IdEstado AS ClieIdEstado,Estado,C.Inactivo AS ClieInactivo
--datos de Agencia
,VrCupoCre,VrSaldoAct,CodAgencia,Referencia,A.IdEstado AS Age_Estado,A.Inactivo AS Age_inactivo
 FROM TercClieSaldos AS S INNER JOIN  Terceros AS T ON S.IdClie=T.IdTercero
 INNER JOIN TercCliente AS C ON S.IdClie=C.IdClie INNER JOIN Companias AS CI ON S.IdCia=CI.IdCia
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN Subzonas AS SZ ON C.IdSzona=SZ.IdSzona
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona   INNER JOIN EstadoTer AS E ON C.IdEstado=E.IdEstado
 LEFT JOIN Agencias AS A ON S.IdClie=A.IdClie AND S.CdAgencia=A.IdAgencia
 WHERE S.IdClie LIKE ISNULL(@pmIdClie,'%') AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%')
 AND S.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY RazonSocial,S.IdCia,CdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieSaldosSum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercClieSaldosSum] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT SUM(VrSaldo) AS STotSal
 FROM TercClieSaldos
 WHERE IdClie=@pmIdClie AND CdAgencia LIKE ISNULL(@pmCdAgencia,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieVeh] @pmIdClie VARCHAR(16),@pmpVehiculo VARCHAR(10)
 AS 
 SELECT IdClie,pVehiculo,CdConductor,NumVehiculo,Descripcion
 FROM TercClieVeh
 WHERE IdClie=@pmIdClie AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
 ORDER BY pVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieVehLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieVehLta] @pmIdClie VARCHAR(16)=Null
 AS 
 SELECT IdClie,T.RazonSocial AS NomCliente,pVehiculo,NumVehiculo,Descripcion,CdConductor,C.RazonSocial AS Conductor
 FROM TercClieVeh AS V INNER JOIN Terceros AS T ON V.IdClie=T.IdTercero
 LEFT JOIN  Terceros AS C ON V.CdConductor=C.IdTercero
 WHERE T.Inactivo=0 AND  IdClie LIKE ISNULL(@pmIdClie,'%')
 ORDER BY T.RazonSocial,pVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryTercClieVehPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercClieVehPla] @pmpVehiculo VARCHAR(10)
 AS 
 SELECT IdClie,pVehiculo,CdConductor,NumVehiculo,Descripcion
 FROM TercClieVeh
 WHERE pVehiculo=@pmpVehiculo
 ORDER BY IdClie
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndCapacLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndCapacLta] 
 AS 
 SELECT IdConductor,RazonSocial,Item,C.IdClase AS CdClase,NomClase,C.Fecha,C.FecVence,Habilitado
 FROM TercCndCapac AS C INNER JOIN ClaseCapac AS CL ON C.IdClase=CL.IdClase
 INNER JOIN Terceros AS T ON C.IdConductor=T.IdTercero
 WHERE CL.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndContrato]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndContrato] @pmNumContrato INT
 AS 
 SELECT NumContrato,IdConductor,IdTipCon,IdModd,FecIngreso,FecRetiro,FecVigencia,Observaciones,FecUpdate,IdUsuario
 FROM TercCndContrato
 WHERE NumContrato=@pmNumContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndContrato_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercCndContrato_Cr] @pmIdConductor VARCHAR(16),@pmIdContrato VARCHAR(4),@pmIdModalidad VARCHAR(4),@pmNumContrato INT

AS
 SELECT  TC.NumContrato AS NContrato,TC.IdConductor AS IdConductr,RazonSocial,Direccion,Telefono,TelMovil,Fax,L.Localidad As NomCiudad,T.IdLocal AS CodCiu,IdLugarCed,LEC.Localidad AS LugarCedula,Licencia, LugarLic,CatLicencia,VigLicencia,Sexo,FecNacmto,TipoSangre,FactorRh
,LibMilitar,T.IdProf AS Idprofesion,Profesion,C.IdEstado AS IdEstad,Estado,pVehiculo,TC.IdTipCon AS IdContrat,TipoContrato, TC.IdModd AS IdModaldad,Modalidad, TC.FecIngreso AS FechaIngreso,TC.FecVigencia AS FechaVigencia, TC.FecRetiro AS FechaRetiro
, Observaciones, FecUpdate, TC.IdUsuario AS IdUsuari
 FROM  TercCndContrato AS TC  INNER JOIN Terceros AS T ON TC.IdConductor=T.IdTercero
  INNER JOIN TercCndtores AS C ON TC.IdConductor=C.IdConductor  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
  INNER JOIN Profesiones AS P ON T.IdProf=P.IdProf    INNER JOIN EstadoTer AS E ON C.IdEstado=E.IdEstado
  INNER JOIN TiposCon AS TN ON TC.IdTipCon=TN.IdTipCon  INNER JOIN TiposMod AS TM ON TC.IdModd=TM.IdModd
 LEFT JOIN   Localidades AS LEC ON T.IdLugarCed=LEC.IdLocal LEFT JOIN ExpLicencias AS LLC ON C.IdLugar=LLC.IdLugar
 WHERE TC.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND TC.IdTipCon LIKE ISNULL(@pmIdContrato,'%')
 AND TC.IdModd LIKE ISNULL(@pmIdModalidad,'%')  
 AND (TC.NumContrato>=ISNULL(@pmNumContrato,0)  AND TC.NumContrato<=ISNULL(@pmNumContrato,2147483647))
 ORDER BY TC.NumContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndDocLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndDocLta] 
 AS 
 SELECT IdConductor,RazonSocial,Item,D.IdDoc AS CdDoc,Documento,Vigencia,D.Fecha,D.FecVence,Radicado,D.Descripcion
 FROM TercCndDoc AS D INNER JOIN ClaseDocCond AS C ON D.IdDoc=C.IdDoc
 INNER JOIN Terceros AS T ON D.IdConductor=T.IdTercero
 WHERE C.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndReferencias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndReferencias] @pmIdConductor VARCHAR(16),@pmItem INT
 AS 
 SELECT Item,TipoRef,EmpresaRef,NitRef,DireccionRef,TelefonoRef,ContactoRef,EmailRef,CargoRef
,CuentaBanco,FechaInicial,FechaFinal,Verificado,ObservRef,IdConductor
 FROM TercCndReferencias
 WHERE IdConductor=@pmIdConductor 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndReferenciasVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndReferenciasVeh] 
 AS 
 SELECT V.IdVehiculo,V.IdConductor,C.RazonSocial AS NomConductor,R.Item,TipoRef,EmpresaRef,NitRef,DireccionRef,TelefonoRef
,ContactoRef,EmailRef,CargoRef,CuentaBanco,FechaInicial,FechaFinal,Verificado,ObservRef
,C.Telefono,C.TelMovil,C.e_mail
 FROM Vehiculos AS V INNER JOIN TercCndReferencias AS R ON V.IdConductor=R.IdConductor
 INNER JOIN Terceros AS C ON V.IdConductor=C.IdTercero
 WHERE V.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndTarjetas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndTarjetas] @pmIdConductor VARCHAR(16),@pmItem INT
 AS 
 SELECT IdConductor,Item,NumeroTarj,Secuencia,Fecha,FecVence
 FROM TercCndTarjetas
 WHERE IdConductor=@pmIdConductor 
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndTarjetasItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndTarjetasItm] @pmIdConductor VARCHAR(16)
 AS 
 SELECT MAX(Item) AS MXITM
 FROM TercCndTarjetas
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndTarjetasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercCndTarjetasLta] @pmIdConductor VARCHAR(16)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT IdConductor,RazonSocial,Item,NumeroTarj,Secuencia,Fecha,FecVence
 FROM TercCndTarjetas AS TJ INNER JOIN Terceros AS T ON TJ.IdConductor=T.IdTercero
 WHERE IdConductor LIKE ISNULL(@pmIdConductor ,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY RazonSocial,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndtores]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndtores] @pmIdConductor VARCHAR(16)
 AS 
 SELECT IdConductor,IdGrupo,IdModd,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,IdEstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial
,FecJudicial,VigJudicial,Pasporte,VigPaspte,Licencia,IdLugar,CatLicencia,FecLicencia,VigLicencia,IdClase,NumCuenta,IdBanco,CdLocCue,CdFonPen,CdFonEps
,CdFonArp,pVehiculo,PathFoto,PathFirma,PathLic,Cmntarios,IdEstado,Inactivo,NumTarjeta,EdicTarjeta,FecTarjeta,VigTarjeta,PasSeguridad,FecPasSeg,VigPasSeg,NitEmpTrans
,FechaAdd,FechaUpdate,IdUsuario,Num_Contrato,Contrato_Activo,CdTipCon,Fec_Ingreso,Fec_Retiro,Fec_Vigencia,Fec_IngresoAnt,Fec_UltimoAcc,PasadoJudicial,Restriccion
,FecPagoPen,FecPagoEps,FecPagoArp,CdTipoOper
 FROM TercCndtores
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndtoresLic]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercCndtoresLic] @pmLicencia VARCHAR(25)
 AS 
 SELECT TercCndtores.*
 FROM TercCndtores
 WHERE Licencia=@pmLicencia
 ORDER BY IdConductor
GO
/****** Object:  StoredProcedure [dbo].[paQryTercCndtoresLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercCndtoresLta] @pmIdLocal VARCHAR(8)=Null,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdBanco VARCHAR(4)=Null,@pmIdLugar VARCHAR(8)=Null,@pmCatLicencia INT=Null,@pmIdModd VARCHAR(4)=Null,@pmEsEmpleado BIT=Null
,@pmEsPropietario BIT=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmInactivoTer BIT=Null
 AS 
 SELECT IdConductor,RazonSocial,T.Codigo AS CodCondtor,TipoId,Dv,FecExpCed,IdLugarCed,LC.Localidad AS LugarCedula,T.Direccion AS Dirccion,T.IdLocal AS CodCiudad
,L.Localidad AS Ciudad,L.IdDep AS CodDpto,Departamento,Telefono,Fax,TelMovil,e_mail,T.IdProf AS CdProf,Profesion,C.IdGrupo AS CodGrupo,GrupoClie,C.IdModd AS CdModd,Modalidad,TipoSangre,FactorRh
,FecNacmto,LugarNacmto,Sexo,IdEstCivil,EstCivil,NHijos,LibMilitar,ClaseLib,FechaLib,DistMil,CertJudicial,FecJudicial,VigJudicial,Licencia,C.IdLugar AS CodLugarLic,LugarLic,CatLicencia,FecLicencia,VigLicencia,C.IdClase AS CdClaseCta
,Pasporte,VigPaspte,ClaseCuenta,NumCuenta,C.IdBanco AS CodBanco,Banco,CdLocCue,LCT.Localidad AS LugarCuenta,CdFonPen,FP.Fondo AS FondoPen,CdFonEps,FS.Fondo AS Eps,CdFonArp
,FR.Fondo AS FondoRiesgo,pVehiculo,PathFoto,PathFirma,PathLic,Observacion,Cmntarios,EsCliente,EsVendedor,EsPropietario,EsEmpleado,EsOperario,IniStgNom
,C.IdEstado AS CdEstado,EC.Estado AS EstadoCond,C.Inactivo AS Inactiv,T.IdEstado AS IdEstdTerc,ET.Estado AS EstadoTerc,T.Inactivo AS Ter_Inactivo
,NumTarjeta,EdicTarjeta,FecTarjeta,VigTarjeta,PasSeguridad,FecPasSeg,VigPasSeg,NitEmpTrans,C.IdUsuario AS IdUsuari,Usuario,EC.NColor AS EstdNColor,C.FechaAdd AS Fec_Add,C.FechaUpdate AS Fec_Upd
,Num_Contrato,Contrato_Activo,CdTipCon,Fec_Ingreso,Fec_Retiro,Fec_Vigencia,Fec_IngresoAnt,Fec_UltimoAcc,PasadoJudicial,Restriccion,FecPagoPen,FecPagoEps,FecPagoArp,CdTipoOper,TipoOperacion,T.ImagenDoc1,T.ImagenDoc2,T.ImagenDoc3,T.PN_RUT
 FROM TercCndtores AS C INNER JOIN Terceros AS T ON C.IdConductor=T.IdTercero
 INNER JOIN GruposCli AS G ON C.IdGrupo=G.IdGrupo INNER JOIN ExpLicencias AS LL ON C.IdLugar=LL.IdLugar
 INNER JOIN ClaseCta AS CTA ON  C.IdClase=CTA.IdClase  INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco
 INNER JOIN EstadoTer AS EC ON C.IdEstado=EC.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN TiposMod AS M ON C.IdModd=M.IdModd INNER JOIN EstadoCiv AS ECV ON C.IdEstCivil=ECV.IdEstado
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf  INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado
 INNER JOIN  Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 LEFT JOIN  Localidades AS LCT ON  C.CdLocCue=LCT.IdLocal 
 LEFT JOIN Fondos AS FP ON C.CdFonPen=FP.IdFondo LEFT JOIN Fondos AS FS ON C.CdFonEps=FS.IdFondo
 LEFT JOIN Fondos AS FR ON C.CdFonArp=FR.IdFondo LEFT JOIN TiposOperac AS TP ON C.CdTipoOper=TP.IdTipoOper
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%')  AND T.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND C.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')   AND C.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND C.IdLugar LIKE ISNULL(@pmIdLugar,'%') AND C.IdModd LIKE ISNULL(@pmIdModd,'%')
 AND C.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (CatLicencia>=ISNULL(@pmCatLicencia,0)  AND CatLicencia<=ISNULL(@pmCatLicencia,2147483647))
 AND (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (EsEmpleado=ISNULL(@pmEsEmpleado,0) or EsEmpleado=ISNULL(@pmEsEmpleado,1))
 AND (EsPropietario=ISNULL(@pmEsPropietario,0) or EsPropietario=ISNULL(@pmEsPropietario,1))
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTerceros]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTerceros] @pmIdTercero VARCHAR(16)
 AS 
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor
,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdProf,IdRegimen,TipEnte,IdLugarCed,FecExpCed
,Observacion,IniStgNom,IdEstado,Inactivo,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,CdGrupoTerc,RegimenFE,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos
,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado,FechaAdd,FechaUpdate,IdUsuario
 FROM Terceros
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosBus]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercerosBus] @pmCodigo VARCHAR(16)=Null,@pmTelefono VARCHAR(20)=Null
 AS 
--consultar por codigo o por telefono
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor
,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdProf,IdSector,IdRegimen,IdLugarCed,TipEnte,FecExpCed
,Observacion,IniStgNom,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,CdGrupoTerc,RegimenFE,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos
,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM Terceros
 WHERE Codigo  LIKE ISNULL(@pmCodigo,'%') AND Telefono LIKE ISNULL(@pmTelefono,'%')
 ORDER BY RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosCod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercerosCod] @pmIdTercero VARCHAR(16),@pmCodigo VARCHAR(16)
 AS 
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor
,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdRegimen,IdLugarCed,FecExpCed,TipEnte,IdProf
,Observacion,IniStgNom,IdEstado,Inactivo,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,CdGrupoTerc,RegimenFE,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos
,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado,FechaAdd,FechaUpdate,IdUsuario
 FROM Terceros
 WHERE IdTercero=@pmIdTercero OR Codigo=@pmCodigo
 ORDER BY  IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosCta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercerosCta] @pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT T.IdTercero,Dv,TipoId,RazonSocial,T.Codigo AS Codtercero,NomCial,SiglaRaz,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto
,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,TipEnte
,T.IdSector AS CodSector,SectorEco,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed
,Observacion,T.IdEstado AS IdEstdo,Estado,T.Inactivo AS Inactvo,PN_RUT,T.FechaAdd,T.FechaUpdate,T.IdUsuario AS IdUsario,Usuario,IniStgNom,NColor,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac
,Item,TC.IdClase AS CdClase,ClaseCuenta,NumCuenta,TC.IdBanco AS CdBanco,Banco,CdLugarCue,CC.Localidad AS LugarCuenta
 FROM Terceros AS T INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector 
 INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN TercCuentas AS TC ON T.IdTercero=TC.IdTercero
 LEFT JOIN ClaseCta AS CL ON TC.IdClase=CL.IdClase LEFT JOIN Bancos AS B ON TC.IdBanco=B.IdBanco
 LEFT JOIN Localidades AS CC ON TC.CdLugarCue=CC.IdLocal
 WHERE (@pmIdEstado IS NULL OR T.IdEstado=@pmIdEstado)
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercerosDso] @pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT IdTercero,Dv,TipoId,RazonSocial,T.Codigo AS Codtercero,NomCial,SiglaRaz,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto
,Telefono,Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,TipEnte,RegimenFE
,T.IdSector AS CodSector,SectorEco,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed
,Observacion,T.IdEstado AS IdEstdo,ET.Estado,T.Inactivo AS Inactvo,FechaAdd,FechaUpdate,T.IdUsuario AS IdUsario,Usuario,IniStgNom,ET.NColor,ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac
,T.IdEstOper AS CdEstOper,EO.Estado AS EstOper,IdLocUbic,DescUbicac,CdGrupoTerc,PN_RUT
,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos
,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,Asociado
 FROM Terceros AS T INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector 
 INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf LEFT JOIN EstadoOper AS EO ON T.IdEstOper=EO.IdEstado
 WHERE (@pmIdEstado IS NULL OR T.IdEstado=@pmIdEstado)
ORDER BY RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosDsoT]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercerosDsoT] @pmIdEstado VARCHAR(4)=Null
 AS 
 SELECT T.IdTercero,T.RazonSocial,T.TipoId,CASE WHEN T.TipoId <> 'N' AND IniStgNom>1 THEN SUBSTRING(T.RazonSocial,1,IniStgNom-1) ELSE '' END AS Apellidos
 ,CASE WHEN T.TipoId <> 'N' AND IniStgNom>0 THEN SUBSTRING(T.RazonSocial,IniStgNom,(LEN(T.RazonSocial)-IniStgNom)+1) ELSE '' END Nombres
,T.FechaNac,T.Direccion,T.e_mail,T.Telefono,T.TelMovil,T.RecPublicos,T.CargoPublico,T.PersonaPub,T.FecInicioPP,T.FecFinalPP,T.IdSector,S.SectorEco
,T.RL_Nombre,T.IdLocal,L.Localidad,D.Departamento,P.NombrePais,T.VrIngresos,T.VrOtroIng,T.VrGastos,T.VrActivos,T.VrPasivos,T.OperActVirtual,T.TipoOperVirtual
,T.LavadoActivos,T.Inactivo AS Inactvo
,CASE WHEN T.EsCliente = 1 THEN TC.Referencia WHEN T.EsProveedor = 1 THEN TP.NomContac ELSE '' END AS NombreContacto
,CASE WHEN T.EsCliente = 1 THEN TC.TelRefncia WHEN T.EsProveedor = 1 THEN TP.TelContac ELSE '' END AS TelefonoContacto
,CASE WHEN T.EsCliente = 1 THEN TC.CargRefncia WHEN T.EsProveedor = 1 THEN TP.CargContac ELSE '' END AS CargoContacto
 FROM Terceros AS T INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep INNER JOIN adm_Paises AS P ON D.IdPais=P.IdPais
 LEFT JOIN TercProvee AS TP ON T.IdTercero=TP.IdProv LEFT JOIN TercClieRef AS TC ON T.IdTercero=TC.IdClie 
 WHERE (T.IdEstado=@pmIdEstado OR @pmIdEstado IS NULL)  
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosReg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercerosReg] @pmIdTercero VARCHAR(16)
 AS 
 SELECT IdTercero,RazonSocial,Codigo,TipoId,Dv,Direccion,IdLocal,Telefono,IdEstado,Inactivo
 FROM Terceros
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryTercerosUbi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercerosUbi] @pmIdEst CHAR(2),@pmTipoRep INT,@pmFecInicio SMALLDATETIME,@pmIdEstOper VARCHAR(4)=Null
 AS 
 SELECT T.IdTercero,T.Dv,T.TipoId,T.RazonSocial,T.Codigo,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto
,T.Telefono,T.Fax,T.TelMovil,T.SitioWeb,T.e_mail,T.EsVendedor,T.EsConductor,T.EsEmpleado,T.EsOperario,T.IdSector AS CodSector,SectorEco
,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,T.IdLugarCed,LC.Localidad AS LugarCedula,T.FecExpCed
,T.Observacion,T.IdEstOper AS CdEstOper,ET.Estado,ET.NColor,T.FechaAdd AS FechaCrea,T.FechaUpdate,T.FechaNac,T.IdLocUbic,LU.Localidad AS CiudadUbic,T.DescUbicac
,TM.TipoOrd,TM.NumOrden,TM.IdCiaOrd,TM.Remesa,TM.IdCiaRem,R.Fecha AS FecOrden,R.IdCliente,C.RazonSocial AS NomCliente,IdLocOrigen,CO.Localidad AS CiuOrigen,IdLocDestino,CD.Localidad AS CiuDestino
,TM.IdVehiculo,TM.nRemolque,R.IdConductor AS CedConductor,NC.RazonSocial AS Conductor
 FROM Terceros AS T INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen
 INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN EstadoOper AS ET ON T.IdEstOper=ET.IdEstado LEFT JOIN Localidades AS LU ON T.IdLocUbic=LU.IdLocal
 LEFT JOIN (SELECT IdOperario,IdVehiculo,nRemolque,TipoOrd,NumOrden,IdCiaOrd,Remesa,IdCiaRem FROM tm_TraInfOper WHERE IdEst=@pmIdEst AND TipoRep=@pmTipoRep) AS TM ON T.IdTercero=TM.IdOperario
 LEFT JOIN (SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdCliente,IdAgencia,IdLocOrigen,IdLocDestino,IdVehiculo,IdConductor,nRemolque
 FROM Trn_TraRemesa WHERE TipDoc='OCT' AND Fecha>=@pmFecInicio
 UNION ALL SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdCliente,IdAgencia,IdDestino,IdDestino AS CiuDstno,IdVehiculo,IdConductor,nRemolque
 FROM Trn_TraOrdenServ WHERE TipDoc='OSA' AND Fecha>=@pmFecInicio) AS R ON TM.TipoOrd=R.TipDoc AND TM.NumOrden=R.NumOrden AND TM.IdCiaOrd=R.IdCia
 LEFT JOIN Terceros AS C ON R.IdCliente=C.IdTercero LEFT JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal LEFT JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal
 LEFT JOIN Terceros AS NC ON R.IdConductor=NC.IdTercero
WHERE T.Inactivo=0 AND (@pmIdEstOper IS NULL OR T.IdEstOper=@pmIdEstOper)
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercPropietario] @pmIdPropietario VARCHAR(16)
 AS 
 SELECT IdPropietario,IdGrupo,CupoCredito,SaldoActual,Avala,IdAdmon,IdTipCon,ContratoActivo,FecIngreso,FecRetiro,FecVigencia,Observacion,IdEstado,FechaAdd,FechaUpdate,IdUsuario
 FROM TercPropietario
 WHERE IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietario_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercPropietario_Cr]  @pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null,@pmIdContrato VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdProf VARCHAR(4)=Null
,@pmContratoActivo BIT=Null,@pmFecIngreso SMALLDATETIME=Null,@pmIdSector VARCHAR(4)=Null,@pmEsConductor BIT=Null,@pmEsProveedor BIT=Null, @pmIdRegimen VARCHAR(4)=Null
AS
 SELECT  IdPropietario,RazonSocial,TipoId,Dv,Codigo,T.Direccion AS Direcion,Telefono,Fax,TelMovil,e_mail,Localidad,T.IdLocal AS CodCiu, P.IdGrupo AS IdGrup,GrupoProp, CupoCredito, SaldoActual, Avala, T.IdProf AS IdProfesion,Profesion
, P.IdAdmon AS IdAdmn,TipoAdmon ,P.IdTipCon AS CodContrato,TipoContrato, ContratoActivo, FecIngreso,FecVigencia, FecRetiro ,P.Observacion AS Observ,P.IdEstado AS IdEstad,Estado,P.FechaAdd AS FecAdd,P.FechaUpdate AS FecUpdate, P.IdUsuario AS IdUsuari
,Usuario,T.IdSector AS IdSectr,SectorEco,T.IdRegimen AS IdRegmn,Regimen,TipEnte,EsConductor,EsProveedor,SitioWeb
 FROM  TercPropietario AS P INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal   INNER JOIN GruposPro AS G ON P.IdGrupo=G.IdGrupo
 INNER JOIN Profesiones AS F ON T.IdProf=F.IdProf   INNER JOIN TiposAdm AS A ON P.IdAdmon=A.IdAdmon
 INNER JOIN TiposCon AS CO ON P.IdTipCon=CO.IdTipCon  INNER JOIN EstadoTer AS E ON P.IdEstado=E.IdEstado
 INNER JOIN SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 WHERE P.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND P.IdAdmon LIKE ISNULL(@pmIdAdmon,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND P.IdTipCon LIKE ISNULL(@pmIdContrato,'%') AND P.IdEstado LIKE ISNULL(@pmIdEstado,'%') 
 AND T.IdSector LIKE ISNULL(@pmIdSector,'%') 
 AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND (ContratoActivo=ISNULL(@pmContratoActivo,0) or ContratoActivo=ISNULL(@pmContratoActivo,1))
 AND (EsConductor=ISNULL(@pmEsConductor,0) or EsConductor=ISNULL(@pmEsConductor,1))
 AND (EsProveedor=ISNULL(@pmEsProveedor,0) or EsProveedor=ISNULL(@pmEsProveedor,1))
AND (FecIngreso>=ISNULL(@pmFecIngreso,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngreso,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY  RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietarioLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercPropietarioLta] 
 AS 
 SELECT IdPropietario,RazonSocial,P.IdGrupo AS CdGrupo,GrupoProp,CupoCredito,SaldoActual,Avala,P.IdAdmon AS CdAdmon,TipoAdmon,P.IdTipCon AS CdTipCon,TipoContrato
,ContratoActivo,FecIngreso,FecRetiro,FecVigencia,P.Observacion AS Observ,P.IdEstado AS CdEstado,P.FechaAdd AS Fec_Add,P.FechaUpdate AS Fec_Update,P.IdUsuario  AS CdUsuario
 FROM TercPropietario AS P INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero
 INNER JOIN GruposPro AS G ON P.IdGrupo=G.IdGrupo INNER JOIN TiposAdm AS TA ON P.IdAdmon=TA.IdAdmon
 INNER JOIN TiposCon AS TC ON P.IdTipCon=TC.IdTipCon
 ORDER BY RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercPropietarioReg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercPropietarioReg] @pmIdPropietario VARCHAR(16)
 AS 
 SELECT IdPropietario,RazonSocial,P.IdGrupo AS CdGrupo,GrupoProp,CupoCredito,SaldoActual,Avala,P.IdAdmon AS CdAdmon,TipoAdmon,P.IdTipCon AS CdTipCon,TipoContrato
,ContratoActivo,FecIngreso,FecRetiro,FecVigencia,P.Observacion AS Observ,P.IdEstado AS CdEstado,P.FechaAdd AS Fec_Add,P.FechaUpdate AS Fec_Update,P.IdUsuario  AS CdUsuario
,Direccion,Localidad,Telefono,T.IdLocal AS CdLocal,Estado,NColor
 FROM TercPropietario AS P INNER JOIN Terceros AS T ON P.IdPropietario=T.IdTercero
 INNER JOIN GruposPro AS G ON P.IdGrupo=G.IdGrupo INNER JOIN TiposAdm AS TA ON P.IdAdmon=TA.IdAdmon
 INNER JOIN TiposCon AS TC ON P.IdTipCon=TC.IdTipCon
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN EstadoTer AS ET  ON T.IdEstado=ET.IdEstado
 WHERE IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paQryTercProvee]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercProvee] @pmIdProv VARCHAR(16)
 AS 
 SELECT IdProv,IdGrupo,NitRepLeg,NomRepLeg,NitContac,NomContac,TelContac,emlContac,CargContac,DirOrdComp,IdLocOrd,DiasEntga,IdPlazo
,IdForma,CdMney,CdDct,IdClase,NumCuenta,IdBanco,Autoret,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv,GartProd,FecIngreso,PathFoto,PathFirma
,Contrato,NContrato,FecVigencia,FecRetiro,ObsFinanc,ObsJuridica,Cmntarios,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario,CodRetCom,CupoElectcom,AutoIca,CodRetIca
 FROM TercProvee
 WHERE IdProv=@pmIdProv
GO
/****** Object:  StoredProcedure [dbo].[paQryTercProveeLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercProveeLta]  @pmIdLocal VARCHAR(8)=Null,@pmIdSector VARCHAR(8)=Null,@pmIdRegimen VARCHAR(4)=Null,@pmTipoId CHAR(1)=Null
,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null,@pmIdLocOrd VARCHAR(8)=Null,@pmIdForma VARCHAR(4)=Null,@pmIdBanco VARCHAR(4)=Null
,@pmFecIngIni SMALLDATETIME=Null,@pmFecIngFin SMALLDATETIME=Null,@pmIdEstado VARCHAR(4)=Null,@pmIdEstadoTer VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmInactivoTer BIT=Null
 AS 
 SELECT IdProv,Dv,TipoId,RazonSocial,T.Codigo AS Codtercero,NomCial,SiglaRaz,NitRepLeg,NomRepLeg,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto,Telefono,Fax,TelMovil
,DirOrdComp,IdLocOrd,LP.Localidad AS CiudadOrd,DP.Departamento AS DeptoOrd,SitioWeb,e_mail,TipEnte,T.IdSector AS CodSector,SectorEco,T.IdProf AS CodProf,Profesion,T.IdRegimen AS IdRegmen,Regimen,PV.IdGrupo AS CdGrupo,GrupoClie
,NitContac,NomContac,TelContac,emlContac,CargContac,DiasEntga,PV.IdPlazo AS CdPlazo,Plazo,PV.IdForma AS CdForma,FormaPago,PV.IdClase AS CdClase,ClaseCuenta,NumCuenta,PV.IdBanco AS CdBanco,Banco
,B.Direccion AS DirBanco,Contacto,CdMney,CdDct,Tarifa,Simbolo,Autoret,AutoIca,IncRet,IncRiv,IncIca,LiqFletes,CdRet,CdRiv,CodRetIca,GartProd,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed
,Observacion,Cmntarios,ObsFinanc,ObsJuridica,PathFoto,PathFirma,T.IdEstado AS IdEstTerc,ET.Estado AS EstadTerc,T.Inactivo AS Ter_Inactvo,PV.IdEstado AS IdEstProv,EP.Estado AS EstadProv,PV.Inactivo AS Prv_Inactvo,CodRetCom
,Contrato,NContrato,FecIngreso,FecVigencia,FecRetiro,EsCliente,EsProveedor,EsPropietario,EsAccnista,EsCiaAseg,PV.FechaAdd AS Fec_Add,PV.FechaUpdate AS Fec_Upd,PV.IdUsuario AS IdUsario,Usuario,IniStgNom,EP.NColor AS ClrEstado
,T.FechaNac,T.ImagenDoc1,T.ImagenDoc2,T.ImagenDoc3,CupoElectcom,T.PN_RUT
,T.RecPublicos,T.CargoPublico,T.FecInicioCP,T.FecFinalCp,T.PersonaPub,T.CargoPersPub,T.FecInicioPP,T.FecFinalPP,T.VrIngresos,T.VrOtroIng,T.VrGastos,T.VrActivos,T.VrPasivos,T.VrPatrimonio,T.ConcOtrosIng
,T.OperActVirtual,T.TipoOperVirtual,T.LavadoActivos,T.RL_Nombre,T.RL_Identificacion,T.RL_Direccion,T.RL_CodCiudad,T.RL_Telefono,T.RL_Email
 FROM TercProvee AS PV INNER JOIN Terceros AS T ON PV.IdProv=T.IdTercero
 INNER JOIN GruposCli AS G ON PV.IdGrupo=G.IdGrupo INNER JOIN Plazos AS PZ ON PV.IdPlazo=PZ.IdPlazo
 INNER JOIN Formaspago AS F ON PV.IdForma=F.IdForma INNER JOIN ClaseCta AS CTA ON  PV.IdClase=CTA.IdClase
 INNER JOIN Bancos AS B ON PV.IdBanco=B.IdBanco INNER JOIN EstadoTer AS EP ON PV.IdEstado=EP.IdEstado
 INNER JOIN adm_Usuarios AS U ON PV.IdUsuario=U.IdUsuario   INNER JOIN Localidades AS LP ON PV.IdLocOrd=LP.IdLocal
 INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN  SectoresEco AS S ON T.IdSector=S.IdSector  INNER JOIN RegimenDian AS R ON T.IdRegimen=R.IdRegimen
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal 
 INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep  INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN Tablapor AS TD ON PV.CdDct=TD.IdTarifa
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND T.IdSector LIKE ISNULL(@pmIdSector,'%')  AND T.IdRegimen LIKE ISNULL(@pmIdRegimen,'%')
 AND TipoId LIKE ISNULL(@pmTipoId,'%') AND T.IdProf LIKE ISNULL(@pmIdProf,'%') AND PV.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND IdLocOrd LIKE ISNULL(@pmIdLocOrd,'%') AND PV.IdForma LIKE ISNULL(@pmIdForma,'%') AND PV.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND PV.IdEstado LIKE ISNULL(@pmIdEstado,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstadoTer,'%')
 AND (PV.Inactivo=ISNULL(@pmInactivo,0) or PV.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
 AND (FecIngreso>=ISNULL(@pmFecIngIni,CAST('19100101' AS SMALLDATETIME)) AND FecIngreso<=ISNULL(@pmFecIngFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercSedesDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercSedesDso] @pmIdTercero VARCHAR(16)
 AS 
 SELECT IdSede,NomSede,IdLocSede,Localidad
,NomSede+' '+IdSede+' ('+ISNULL(Localidad,'')+')' AS DsSede
 FROM TercSedes AS S LEFT JOIN Localidades AS L ON S.IdLocSede=L.IdLocal
 WHERE IdTercero=@pmIdTercero
 ORDER BY NomSede
GO
/****** Object:  StoredProcedure [dbo].[paQryTercVendedor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTercVendedor] @pmIdVend VARCHAR(16)
 AS 
 SELECT IdVend,IdTarCms,IdTarCm2,CdJorn,IdSzona,IdGrupo,PathFoto,PathFirma,IdClase,NumCuenta,IdBanco
,Comntarios,Inactivo,FecAdd,FecUpdate,IdUsuario
 FROM TercVendedor
 WHERE IdVend=@pmIdVend
GO
/****** Object:  StoredProcedure [dbo].[paQryTercVendedorLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercVendedorLta] @pmIdLocal VARCHAR(8)=Null,@pmIdProf VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdSzona VARCHAR(4)=Null,@pmIdTarCms VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmInactivoTer BIT=Null,@pmIdEstado VARCHAR(4)=Null
,@pmIdBanco VARCHAR(4)=Null
 AS 
 SELECT IdVend,Dv,TipoId,RazonSocial,T.Codigo AS CodVend,T.Direccion AS Dreccion,T.IdLocal AS CodCiud,L.Localidad AS Ciudad,D.Departamento AS Departmto,Telefono
,Fax,TelMovil,e_mail,T.IdProf AS CodProf,Profesion,V.IdGrupo AS CdGrupo,GrupoClie,CdJorn,Jornada,IdTarCms,CM.Tarifa AS TarfCms,IdTarCm2,TCM.Tarifa AS TarfCms2,V.IdSzona AS CdSubzona,Subzona
,IdLugarCed,LC.Localidad AS LugarCedula,DC.Departamento AS DptoLugcedula,FecExpCed,NomCial
,V.IdClase AS CdClase,ClaseCuenta,NumCuenta,V.IdBanco AS CdBanco,Banco,B.Direccion AS DirBanco
,EsCliente,EsProveedor,EsPropietario,EsVendedor,EsConductor,EsEmpleado,EsOperario
,Observacion,Comntarios,PathFoto,PathFirma,T.PN_RUT,T.IdEstado AS IdEstTerc,Estado,V.Inactivo AS Vend_inactivo,T.Inactivo AS Ter_Inactvo
,FecAdd,FecUpdate,V.IdUsuario AS IdUsuari,Usuario,IniStgNom,NColor
 FROM TercVendedor AS V INNER JOIN Terceros AS T ON V.IdVend=T.IdTercero  INNER JOIN GruposCli AS G ON V.IdGrupo=G.IdGrupo
 INNER JOIN Tablapor AS CM ON V.IdTarCms=CM.IdTarifa INNER JOIN Tablapor AS TCM ON V.IdTarCm2=TCM.IdTarifa
 INNER JOIN Subzonas AS SZ ON V.IdSzona=SZ.IdSzona  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 INNER JOIN ClaseCta AS CTA ON  V.IdClase=CTA.IdClase  INNER JOIN Bancos AS B ON V.IdBanco=B.IdBanco
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN EstadoTer AS ET ON T.IdEstado=ET.IdEstado INNER JOIN Localidades AS LC ON T.IdLugarCed=LC.IdLocal
 INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep  INNER JOIN Profesiones AS PF ON T.IdProf=PF.IdProf 
 LEFT JOIN Jornadas AS J ON V.CdJorn=J.IdJornada 
 WHERE T.IdLocal LIKE ISNULL(@pmIdLocal,'%') AND  T.IdProf LIKE ISNULL(@pmIdProf,'%')
 AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')  AND V.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND IdTarCms LIKE ISNULL(@pmIdTarCms,'%') AND T.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND V.IdBanco LIKE ISNULL(@pmIdBanco,'%')
 AND (V.Inactivo=ISNULL(@pmInactivo,0) or V.Inactivo=ISNULL(@pmInactivo,1))
 AND (T.Inactivo=ISNULL(@pmInactivoTer,0) or T.Inactivo=ISNULL(@pmInactivoTer,1))
ORDER BY RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTercVendedorReg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTercVendedorReg] @pmIdVend VARCHAR(16)
 AS 
 SELECT IdVend,TipoId,RazonSocial,Dv,IdTarCms,Tarifa,Simbolo,IdTarCm2,CdJorn,V.IdSzona AS CdSubzona,Subzona
,SZ.IdZona AS CdZona,Zona,V.IdGrupo AS CdGrupo,GrupoClie,V.IdClase AS CdClase,ClaseCuenta,NumCuenta,V.IdBanco AS CdBco,Banco
,Comntarios,V.Inactivo AS Inactvo
 FROM TercVendedor AS V INNER JOIN Terceros AS T ON V.IdVend=T.IdTercero  INNER JOIN GruposCli AS G ON V.IdGrupo=G.IdGrupo
 INNER JOIN Tablapor AS CM ON V.IdTarCms=CM.IdTarifa INNER JOIN Subzonas AS SZ ON V.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN ClaseCta AS CTA ON  V.IdClase=CTA.IdClase  INNER JOIN Bancos AS B ON V.IdBanco=B.IdBanco
 WHERE IdVend=@pmIdVend
GO
/****** Object:  StoredProcedure [dbo].[paQryTerminales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTerminales] @pmIdTerminal VARCHAR(4)
 AS 
 SELECT IdTerminal,Terminal,IdCia,Inactivo
 FROM Terminales
 WHERE IdTerminal=@pmIdTerminal
GO
/****** Object:  StoredProcedure [dbo].[paQryTFmtos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTFmtos] @pmnFormato VARCHAR(10)
 AS 
 IF @pmnFormato IS NULL
  SELECT nFormato,FmtoFactura,TipFac
  FROM Sys_TFmtos
 ORDER BY nFormato
 ELSE
  SELECT nFormato,FmtoFactura,TipFac
  FROM Sys_TFmtos
  WHERE nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryTFmtosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTFmtosDso] @pmTipFac VARCHAR(3)=Null
 AS 
  SELECT nFormato,FmtoFactura,nFormato+' '+FmtoFactura AS DsFmt
  FROM Sys_TFmtos
  WHERE TipFac LIKE ISNULL(@pmTipFac,'%')
  ORDER BY nFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposAdm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposAdm] @pmIdAdmon VARCHAR(4)
 AS 
 IF @pmIdAdmon IS NULL
 SELECT IdAdmon,TipoAdmon
 FROM TiposAdm
 WHERE Inactivo=0
 ORDER BY TipoAdmon
ELSE
 SELECT IdAdmon,TipoAdmon,Inactivo
 FROM TiposAdm
 WHERE IdAdmon=@pmIdAdmon
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposAgenc] @pmIdTipAgenc VARCHAR(4)
 AS 
 IF @pmIdTipAgenc IS NULL
 SELECT IdTipAgenc,TipoAgencia
 FROM TiposAgenc
 WHERE Inactivo=0
 ORDER BY IdTipAgenc
 ELSE
 SELECT IdTipAgenc,TipoAgencia,Inactivo
 FROM TiposAgenc
 WHERE IdTipAgenc=@pmIdTipAgenc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposBan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposBan] @pmIdBandera VARCHAR(4)
 AS 
 IF @pmIdBandera IS NULL 
  SELECT IdBandera,TipoBandera
  FROM TiposBan
  WHERE Inactivo=0
  ORDER BY IdBandera
ELSE
  SELECT IdBandera,TipoBandera,Inactivo
  FROM TiposBan
  WHERE IdBandera=@pmIdBandera
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposBloq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposBloq] @pmIdTipBloq VARCHAR(4)
 AS 
 IF @pmIdTipBloq IS NULL
  SELECT IdTipBloq,TipoBloqueo
  FROM TiposBloq
  WHERE Inactivo=0
 ORDER BY IdTipBloq
 ELSE
  SELECT IdTipBloq,TipoBloqueo,Inactivo
  FROM TiposBloq
  WHERE IdTipBloq=@pmIdTipBloq
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposCar] @pmIdCrceria VARCHAR(4)
 AS 
 IF @pmIdCrceria IS NULL
 SELECT IdCrceria,TipoCar
 FROM TiposCar
 WHERE Inactivo=0 
 ORDER BY TipoCar
 ELSE
 SELECT IdCrceria,TipoCar,Inactivo
 FROM TiposCar
 WHERE IdCrceria=@pmIdCrceria
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCarga]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposCarga] @pmIdTipCarga VARCHAR(4)
 AS 
 IF @pmIdTipCarga IS NULL
  SELECT IdTipCarga,TipoCarga
  FROM TiposCarga
  WHERE Inactivo=0
 ORDER BY IdTipCarga
 ELSE
  SELECT IdTipCarga,TipoCarga,Inactivo
  FROM TiposCarga
  WHERE IdTipCarga=@pmIdTipCarga
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCnd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposCnd] @pmIdTipoCon VARCHAR(4)
 AS 
 BEGIN
 IF @pmIdTipoCon IS NULL
  SELECT IdTipoCon,TipoContndor
  FROM TiposCnd
  WHERE Inactivo=0
  ORDER BY IdTipoCon
 ELSE
  SELECT IdTipoCon,TipoContndor,Inactivo
  FROM TiposCnd
  WHERE IdTipoCon=@pmIdTipoCon
 END
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCol]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposCol] @pmIdColor VARCHAR(4)
 AS 
 IF @pmIdColor IS NULL
 SELECT IdColor,NomColor,NColor,CodigoMT
 FROM TiposCol
 WHERE Inactivo=0
 ORDER BY NomColor
 ELSE
 SELECT IdColor,NomColor,NColor,CodigoMT,Inactivo
 FROM TiposCol
 WHERE IdColor=@pmIdColor
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposCom] @pmIdCom VARCHAR(3)
 AS 
 SELECT IdCom,TipoCom,IdDiario,EsEgreso,ConsUnico,Inactivo,FechaAdd,FechaUpdate,ClaseNiif,Doc_Soporte
 FROM TiposCom
 WHERE IdCom=@pmIdCom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposComAgenc] @pmIdSubAgenc VARCHAR(4)
 AS 
 SELECT IdSubAgenc,SubTipoAgenc,IdTipAgenc,Inactivo
 FROM TiposComAgenc
 WHERE IdSubAgenc=@pmIdSubAgenc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComAgencLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposComAgencLta] @pmIdTipAgenc VARCHAR(4)
 AS 
 SELECT IdSubAgenc,SubTipoAgenc,S.IdTipAgenc AS CdTipoAgenc,TipoAgencia
 FROM TiposComAgenc AS S INNER JOIN TiposAgenc AS A ON S.IdTipAgenc=A.IdTipAgenc
 WHERE S.Inactivo=0 AND S.IdTipAgenc LIKE ISNULL(@pmIdTipAgenc,'%')
 ORDER BY SubTipoAgenc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComCons]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposComCons] @pmIdCom VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT IdCom,IdCia,LDesde,LHasta,Numero,NumManual,Formato,ConfigFecha,TipoPapel
,Orientacion,VistaPrevia,VerSetup,NumCopias,CodResol,FechaAdd,FechaUpdate
 FROM TiposComCons
 WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComConsLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposComConsLta] @pmIdCom VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT N.IdCom AS CdTipo,TipoCom,N.IdCia AS CdCia,Compania,LDesde,LHasta,Numero,NumManual,Formato
,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,ConfigFecha,EsEgreso,ConsUnico
,T.IdDiario AS CdDiario,Diario,ClaseNiif,T.Doc_Soporte,CodResol,N.FechaAdd AS Fec_Add,N.FechaUpdate AS Fec_Update
 FROM TiposComCons AS N INNER JOIN TiposCom AS T ON N.IdCom=T.IdCom
 INNER JOIN Diarios AS D ON T.IdDiario=D.IdDiario INNER JOIN Companias AS C ON N.IdCia=C.IdCia
 WHERE T.Inactivo=0  AND N.IdCom LIKE ISNULL(@pmIdCom,'%') AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY N.IdCom,N.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComDsa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposComDsa] @pmEsEgreso BIT
 AS
 SELECT   IdCom,TipoCom +'  ' + IdCom  AS DsTip  FROM  TiposCom 
 WHERE  Inactivo=0 AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 AND (ISNULL(ClaseNiif,'')='CONTAB' OR LEN(ISNULL(ClaseNiif,''))=0)
 UNION
 SELECT   IdDoc AS IdCom,TipoDoc+ ' '+ IdDoc AS DsTip   FROM   Sys_TiposDoc
 WHERE  IdDoc IN ('DVE','DEI','DOP','DEC','DVO','DRV','DRR') AND Inactivo=0
 ORDER BY IdCom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposComDso] @pmEsEgreso BIT
AS
 SELECT IdCom,TipoCom,IdCom +'  ' + TipoCom  AS DsTip
 FROM TiposCom 
 WHERE Inactivo=0 AND (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 AND (ISNULL(ClaseNiif,'')='CONTAB' OR LEN(ISNULL(ClaseNiif,''))=0) 
 ORDER BY IdCom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposComFmt] @pmIdCom VARCHAR(3),@pmIdForma CHAR(2)
 AS 
 SELECT IdCom,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
 FROM TiposComFmt
 WHERE IdCom=@pmIdCom AND IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComFmtDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposComFmtDso] @pmIdCom VARCHAR(3)
 AS
  SELECT IdCom,IdForma,Descripcion,Formato,IdForma + ' '+Descripcion AS DsFor
  FROM TiposComFmt
  WHERE IdCom=@pmIdCom
 ORDER BY IdForma
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposComLta] @pmEsEgreso BIT=Null,@pmInactivo BIT=Null
 AS 
 SELECT TC.IdCom AS CdCom,TipoCom,TC.IdDiario AS CodDiario,Diario,EsEgreso,ConsUnico
,N.IdCia AS CdCia,Compania,LDesde,LHasta,Numero,NumManual,Formato
,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,ConfigFecha
,TC.Inactivo AS Inactvo,ClaseNiif,Doc_Soporte,TC.FechaAdd AS Fec_Add,TC.FechaUpdate AS Fec_Update
 FROM TiposCom AS TC INNER JOIN Diarios AS  D ON TC.IdDiario=D.IdDiario
 LEFT JOIN  TiposComCons  AS N ON TC.IdCom=N.IdCom
 LEFT JOIN Companias AS C ON N.IdCia=C.IdCia 
 WHERE (EsEgreso=ISNULL(@pmEsEgreso,0) or EsEgreso=ISNULL(@pmEsEgreso,1))
 AND  (TC.Inactivo=ISNULL(@pmInactivo,0) or TC.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY TipoCom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComNiif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposComNiif] 
AS
 SELECT IdCom,TipoCom,IdCom + ' '+TipoCom+' ('+ISNULL(ClaseNiif,'')+')' AS DsTip
 FROM TiposCom 
 WHERE ISNULL(ClaseNiif,'') IN ('NIIF','FISCAL') AND Inactivo=0
 ORDER BY IdCom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposComRes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposComRes] @pmIdRes VARCHAR(4)
 AS 
 SELECT IdRes,Resolucion,Prefijo,NumInicial,NumFinal,FechaExpRes,FechaVigencia,Establecimiento
 FROM TiposComRes
 WHERE IdRes=@pmIdRes
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposCon] @pmIdTipCon VARCHAR(4)
 AS 
 IF @pmIdTipCon IS NULL
  SELECT IdTipCon,TipoContrato,Duracion,VincLabUgpp,CodDIAN
  FROM TiposCon
  WHERE Inactivo=0
  ORDER BY IdTipCon
 ELSE
  SELECT IdTipCon,TipoContrato,Duracion,VincLabUgpp,CodDIAN,Inactivo
  FROM TiposCon
  WHERE IdTipCon=@pmIdTipCon
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposCot] @pmIdCot VARCHAR(4)
 AS 
 IF @pmIdCot IS NULL
  SELECT IdCot,Cotizante 
  FROM TiposCot
  WHERE Inactivo=0
  ORDER BY IdCot
 ELSE
 SELECT IdCot,Cotizante,Inactivo
 FROM TiposCot
 WHERE IdCot=@pmIdCot
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposCotDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposCotDso]
 AS 
  SELECT IdCot,Cotizante,IdCot+ ' '+Cotizante AS DsCot
  FROM TiposCot
  WHERE Inactivo=0
  ORDER BY IdCot
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDoc] @pmIdDoc VARCHAR(3)
 AS 
 IF @pmIdDoc IS NULL
  SELECT IdDoc,TipoDoc,ConsUnico,Leyenda,IntegraCias
  FROM Sys_TiposDoc
  WHERE Inactivo=0 
  ORDER BY IdDoc
 ELSE
  SELECT IdDoc,TipoDoc,ConsUnico,Leyenda,IntegraCias,Inactivo
  FROM Sys_TiposDoc
  WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocAbo]
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('DFC','DF1','DF2', 'DF3', 'DF4', 'DF5','NCR','REC','ODB' )  AND Inactivo=0
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocAut]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposDocAut]
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('FCR','DFO','ODB','OD2','PR1','NTS','MUC','OSA','OCT','OSM')
 --todas las fac.credito con este codigo FCR
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocCli]
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('FCR','FC1','FC2', 'FC3', 'FC4', 'FC5','NDB','CHE','ODB' )  AND Inactivo=0
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryTiposDocCmp] 
 AS
 SELECT   IdDoc AS IdTipo, TipoDoc AS NomTipo,TipoDoc+ ' '+ IdDoc AS DsTip 
 FROM    Sys_TiposDoc
 WHERE Inactivo=0 
 UNION
 SELECT  IdCom AS IdTipo, TipoCom AS NomTipo,TipoCom+ ' '+IdCom AS DsTip
 FROM     TiposCom
 WHERE Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCons]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocCons] @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2)
 AS 
 SELECT IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero
,NumManual,IntLotes,ConfigFecha,Formato,TipoPapel,Orientacion,VistaPrevia
,VerSetup,NumCopias,FechaVigRes,ClaveTecDian,CodResol,FechaAdd,FechaUpdate
 FROM TiposDocCons
 WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocConsLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocConsLta] @pmIdDoc VARCHAR(3)=Null,@pmIdCia CHAR(2)=Null
 AS 
 SELECT N.IdDoc AS CdDoc,TipoDoc,N.IdCia AS CdCia,Compania,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero
,NumManual,IntLotes,ConfigFecha,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias
,ConsUnico,Leyenda,FechaVigRes,ClaveTecDian,N.CodResol,N.FechaAdd AS Fec_Add,N.FechaUpdate AS Fec_Update
 FROM TiposDocCons AS N INNER JOIN Sys_TiposDoc AS T ON N.IdDoc=T.IdDoc
 INNER JOIN Companias AS C ON N.IdCia=C.IdCia
 WHERE T.Inactivo=0 AND N.IdDoc LIKE ISNULL(@pmIdDoc,'%')  AND N.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY N.IdDoc,N.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposDocCue] @pmIdDoc VARCHAR(3),@pmIdClase INT
 AS 
 SELECT IdDoc,IdClase,ClaseCuenta,TipoMov
 FROM Sys_TiposDocCue
 WHERE IdDoc=@pmIdDoc AND (IdClase>=ISNULL(@pmIdClase,0)  AND IdClase<=ISNULL(@pmIdClase,2147483647))
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocCueDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposDocCueDso] @pmIdDoc VARCHAR(3)=Null
 AS 
 SELECT TC.IdDoc AS CdTipo,TipoDoc,IdClase,ClaseCuenta,TipoMov
 FROM Sys_TiposDocCue AS TC  INNER JOIN Sys_TiposDoc AS T ON TC.IdDoc=T.IdDoc
 WHERE TC.IdDoc LIKE ISNULL(@pmIdDoc,'%')  OR IdClase=98 OR IdClase=99
 ORDER BY TipoDoc,IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocDso] @pmInactivo BIT=Null
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip   FROM  Sys_TiposDoc 
 WHERE (Inactivo=ISNULL(@pmInactivo,0) or  Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocEnt]
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('ENT','COM','SAL','SAI') 
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposDocFac] 
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('FCR','FC1','FC2', 'FC3', 'FC4', 'FC5', 'FCO', 'FO1', 'FO2', 'FO3', 'FO4', 'FO5')
 AND Inactivo=0
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocFor]
--tipos de documento de formas de pago
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('REC','FCO','FO1','FO2','FO3','FO4','FO5','PLA','RCO' ,'RC1','RC2','ODP')
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocInv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposDocInv]
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc  NOT IN ('ODC','PED','REM','COT','GUI','ODS','OCC','FIS','VCC') AND Inactivo=0
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocKar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocKar] @pmInactivo BIT=Null
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip 
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('AJF','AJS','COM','COT','DEI','DF1','DF2','DF3','DF4','DF5','DFC','DFO','DFV','DNP','DO1','DO2','DO3','DO4','DO5','DSI','DVE','DVN','DVP','DVS','ENT'
,'FC1','FC2','FC3','FC4','FC5','FCO','FCR','FIS','FO1','FO2','FO3','FO4','FO5','FVC','GUI','NPR','NTS','OCC','ODC','PAS','PED','PLA','REM','REQ','SAI','SAL')
 AND (Inactivo=ISNULL(@pmInactivo,0) or  Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocLta] @pmInactivo BIT=Null
 AS 
 SELECT T.IdDoc AS CdDoc,TipoDoc,ConsUnico,Leyenda,N.IdCia AS CdCia,Compania
,LDesde,LHasta,Resolucion,RangoNum,FechaRes,Prefijo,Numero
,NumManual,IntLotes,ConfigFecha,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias
,N.FechaAdd AS Fec_Add,N.FechaUpdate AS Fec_Update,T.Inactivo AS Inactiv
 FROM Sys_TiposDoc AS T LEFT JOIN TiposDocCons AS N ON T.IdDoc=N.IdDoc
 LEFT JOIN Companias AS C ON N.IdCia=C.IdCia 
 WHERE  (T.Inactivo=ISNULL(@pmInactivo,0) or T.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY T.IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposDocPag]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposDocPag]
 AS 
 SELECT  IdDoc,TipoDoc,IdDoc+'  '+ TipoDoc AS DsTip
 FROM  Sys_TiposDoc 
 WHERE IdDoc IN ('REC','FCO','FO1','FO2','FO3','FO4','FO5','PLA','RCO'
,'PAS','EGO','CNS','DNP','DVP','DVC','ODB','DEC','DRC','DFO','DO1','DO2','DO3','DO4','DO5','OD1','RC1','RC2','OD2','ODP','DOP')
 ORDER BY IdDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposEnt] @pmIdEnt VARCHAR(4)
 AS 
 IF @pmIdEnt IS NULL
  SELECT IdEnt,DiaEntrega
  FROM TiposEnt
  WHERE Inactivo=0
 ELSE
  SELECT IdEnt,DiaEntrega,Inactivo
  FROM TiposEnt WHERE IdEnt=@pmIdEnt
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposEsc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposEsc] @pmIdTipoEsc VARCHAR(4)
 AS 
 IF @pmIdTipoEsc IS NULL
  SELECT IdTipoEsc,TipoEscolta
  FROM TiposEsc
  WHERE Inactivo=0
  ORDER BY TipoEscolta
 ELSE
  SELECT IdTipoEsc,TipoEscolta,Inactivo
  FROM TiposEsc
  WHERE IdTipoEsc=@pmIdTipoEsc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposFil]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposFil] @pmIdFiltro VARCHAR(4)
 AS 
 IF @pmIdFiltro IS NULL 
  SELECT IdFiltro,TipoFiltro
  FROM TiposFil
  WHERE Inactivo=0
  ORDER BY  IdFiltro
 ELSE
  SELECT IdFiltro,TipoFiltro,Inactivo
  FROM TiposFil
  WHERE IdFiltro=@pmIdFiltro
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposFuel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposFuel] @pmIdCom VARCHAR(4)
 AS 
 IF @pmIdCom IS NULL
 SELECT IdCom,TipoComb
 FROM TiposFuel
 WHERE Inactivo=0
 ORDER BY TipoComb
 ELSE
 SELECT IdCom,TipoComb,Inactivo
 FROM TiposFuel
 WHERE IdCom=@pmIdCom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposInm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposInm] @pmIdTipoInm VARCHAR(4)
 AS 
IF @pmIdTipoInm IS NULL
 SELECT IdTipoInm,TipoInmueble FROM TiposInm WHERE Inactivo=0 ORDER BY IdTipoInm
ELSE  
 SELECT IdTipoInm,TipoInmueble,Inactivo FROM TiposInm WHERE IdTipoInm=@pmIdTipoInm
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposLla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposLla] @pmIdTlla VARCHAR(4)
 AS 
 IF @pmIdTlla IS NULL
 SELECT IdTlla,TipoLlanta
 FROM TiposLla
 WHERE Inactivo=0
 ORDER BY TipoLlanta
 ELSE
 SELECT IdTlla,TipoLlanta,Inactivo
 FROM TiposLla
 WHERE IdTlla=@pmIdTlla
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposLub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposLub] @pmIdLub VARCHAR(4)
 AS 
 IF @pmIdLub IS NULL
 SELECT IdLub,TipoLub
 FROM TiposLub
 WHERE Inactivo=0
 ORDER BY TipoLub
 ELSE
 SELECT IdLub,TipoLub,Inactivo
 FROM TiposLub
 WHERE IdLub=@pmIdLub
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposMat] @pmIdMat VARCHAR(4)
 AS 
 IF @pmIdMat IS NULL
 SELECT IdMat,Material
 FROM TiposMat
 WHERE Inactivo=0
 ORDER BY IdMat
 ELSE
 SELECT IdMat,Material,Inactivo
 FROM TiposMat
 WHERE IdMat=@pmIdMat
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMcia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposMcia] @pmIdTmcia VARCHAR(4)
 AS 
 IF @pmIdTmcia IS NULL
  SELECT IdTmcia,TipoMcia,CodPeligrosidad
  FROM TiposMcia
  WHERE  Inactivo=0
  ORDER BY IdTmcia
 ELSE
  SELECT IdTmcia,TipoMcia,CodPeligrosidad,Inactivo 
  FROM TiposMcia
  WHERE IdTmcia=@pmIdTmcia
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMnjo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposMnjo] @pmIdMnjo VARCHAR(4)
 AS 
 IF @pmIdMnjo IS NULL
  SELECT IdMnjo,ManejoMcia
  FROM TiposMnjo
  WHERE  Inactivo=0
  ORDER BY IdMnjo
 ELSE
  SELECT IdMnjo,ManejoMcia,Inactivo
  FROM TiposMnjo
  WHERE IdMnjo=@pmIdMnjo
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposMod] @pmIdModd VARCHAR(4)
 AS 
 IF @pmIdModd IS NULL
 SELECT IdModd,Modalidad
 FROM TiposMod
 WHERE Inactivo=0
 ORDER BY IdModd
 ELSE
 SELECT IdModd,Modalidad,Inactivo
 FROM TiposMod
 WHERE IdModd=@pmIdModd
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposMot] @pmIdTipoMot VARCHAR(4)
 AS 
 IF @pmIdTipoMot IS NULL
 SELECT IdTipoMot,TipoMotor
 FROM TiposMot
 WHERE Inactivo=0
 ORDER BY TipoMotor
 ELSE
 SELECT IdTipoMot,TipoMotor,Inactivo
 FROM TiposMot
 WHERE IdTipoMot=@pmIdTipoMot
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMotdev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposMotdev] @pmIdMotDev VARCHAR(4)
 AS 
 IF @pmIdMotDev IS NULL
  BEGIN
   SELECT M.IdMotDev,M.MotivoDev,M.TipoFact,M.EstadoPed,M.CodEstadoPed,ED.Estado,M.BodegaDev,M.CodBodegaDev,B.Bodega,M.CodCias,M.Inactivo
   FROM TiposMotdev AS M LEFT JOIN EstadoDoc AS ED ON M.CodEstadoPed=ED.IdEstado LEFT JOIN Bodegas AS B ON M.CodBodegaDev=B.IdBodega
  END
 ELSE
  BEGIN
   SELECT IdMotDev,MotivoDev,TipoFact,EstadoPed,CodEstadoPed,BodegaDev,CodBodegaDev,CodCias,Inactivo
   FROM TiposMotdev
   WHERE IdMotDev=@pmIdMotDev
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposMotdevDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposMotdevDso] @pmTipoFact VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null
 AS 
 --@pmTipoFact NO APLICA AUN
 SELECT IdMotDev,MotivoDev,TipoFact 
 FROM TiposMotdev
 WHERE Inactivo=0 AND (LEN(ISNULL(CodCias,''))=0 OR (ISNULL(CodCias,'') LIKE '%'+@pmIdCia+'%') OR @pmIdCia IS NULL)
 ORDER BY MotivoDev
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposNat] @pmIdNat VARCHAR(4)
 AS 
 IF @pmIdNat IS NULL
  SELECT IdNat,Natlzaprod
  FROM TiposNat
  WHERE  Inactivo=0
  ORDER BY IdNat
 ELSE
  SELECT IdNat,Natlzaprod,Inactivo
  FROM TiposNat
  WHERE IdNat=@pmIdNat
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNivs]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposNivs] @pmIdNiv VARCHAR(4)
 AS 
 IF @pmIdNiv IS NULL
 SELECT IdNiv,NivelServicio
 FROM TiposNivs
 WHERE Inactivo=0
 ORDER BY NivelServicio
 ELSE
 SELECT IdNiv,NivelServicio,Inactivo
 FROM TiposNivs
 WHERE IdNiv=@pmIdNiv
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposNom] @pmIdNom VARCHAR(4)
 AS 
 IF @pmIdNom IS NULL
  SELECT IdNom,TipoNomina,Asistencia,NoDevenga,TipoLiquida,FechaActual,CdCiaInt,LiqEspSalud,DctoSalud,PagoSalud,NomDiario
  FROM TiposNom WHERE Inactivo=0
  ORDER BY IdNom
ELSE
  SELECT IdNom,TipoNomina,Asistencia,NoDevenga,TipoLiquida,FechaActual,CdCiaInt,LiqEspSalud,DctoSalud,PagoSalud,NomDiario,Inactivo
  FROM TiposNom
  WHERE IdNom=@pmIdNom
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposNov] @pmIdNov VARCHAR(4)
 AS 
 IF @pmIdNov IS NULL
  SELECT IdNov,Novedad,Admon
  FROM TiposNov
  WHERE Inactivo =0
  ORDER BY IdNov
 ELSE
  SELECT IdNov,Novedad,Admon,Inactivo 
  FROM TiposNov
  WHERE IdNov=@pmIdNov
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposNovTra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposNovTra] 
 AS 
  SELECT IdNov,Novedad,Admon  FROM TiposNov
  WHERE  IdNov IN ('TAE','TAP')
  ORDER BY IdNov
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposOperac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposOperac] @pmIdTipoOper VARCHAR(4)
 AS 
 IF @pmIdTipoOper IS NULL
  BEGIN
   SELECT IdTipoOper,TipoOperacion,TipoIngreso,TarifaIng 
   FROM TiposOperac WHERE Inactivo=0
   ORDER BY TipoOperacion
  END
 ELSE
  BEGIN
   SELECT IdTipoOper,TipoOperacion,TipoIngreso,TarifaIng,Inactivo
   FROM TiposOperac WHERE IdTipoOper=@pmIdTipoOper
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposOperarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposOperarios] @pmIdOper VARCHAR(4)
 AS 
 IF @pmIdOper IS NULL
  BEGIN
  SELECT IdOper,TipoOperario,TarifaCom,GrupoOper FROM TiposOperarios
  WHERE Inactivo=0 ORDER BY TipoOperario
  END
 ELSE
  BEGIN
   SELECT IdOper,TipoOperario,TarifaCom,GrupoOper,Inactivo FROM TiposOperarios
   WHERE IdOper=@pmIdOper
  END
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposPcnto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposPcnto] @pmIdTipoPre VARCHAR(4)
 AS 
 IF @pmIdTipoPre IS NULL
 SELECT IdTipoPre,Precinto
 FROM TiposPcnto
 WHERE Inactivo=0
 ORDER BY Precinto
 ELSE
 SELECT IdTipoPre,Precinto,Inactivo
 FROM TiposPcnto
 WHERE IdTipoPre=@pmIdTipoPre
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposPpt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTiposPpt] @pmIdPpd VARCHAR(4)
 AS 
 IF @pmIdPpd IS NULL
  SELECT IdPpd,TipoProp,VehPropio
  FROM TiposPpt
 WHERE Inactivo=0
 ORDER BY  TipoProp
 ELSE
  SELECT IdPpd,TipoProp,VehPropio,Inactivo
  FROM TiposPpt
  WHERE IdPpd=@pmIdPpd
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposPrend]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposPrend] @pmIdPrend VARCHAR(4)
 AS 
 IF @pmIdPrend IS NULL
  SELECT IdPrend,TipoPrenda
  FROM TiposPrend
  WHERE Inactivo=0
 ORDER BY TipoPrenda
 ELSE
  SELECT IdPrend,TipoPrenda,Inactivo
  FROM TiposPrend
  WHERE IdPrend=@pmIdPrend
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposProceso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposProceso] @pmIdTipProc VARCHAR(4)
 AS 
 SELECT IdTipProc,TipoProceso,Descripcion,IndOrden,Inactivo
 FROM TiposProceso WHERE IdTipProc=@pmIdTipProc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposRespFis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposRespFis] @pmIdResFis VARCHAR(10)
 AS 
 IF @pmIdResFis IS NULL
  SELECT IdResFis,NomResFiscal
  FROM TiposRespFis
  WHERE Inactivo=0
 ELSE
  SELECT IdResFis,NomResFiscal,Inactivo
  FROM TiposRespFis
  WHERE IdResFis=@pmIdResFis
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposSustento]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposSustento] @pmIdSustento VARCHAR(4)
 AS 
IF @pmIdSustento IS NULL 
 SELECT IdSustento,Sustento FROM TiposSustento WHERE Inactivo=0 ORDER BY Sustento
ELSE
 SELECT IdSustento,Sustento,Inactivo FROM TiposSustento WHERE IdSustento=@pmIdSustento
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposSustentoDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposSustentoDso] 
AS 
SELECT IdSustento,Sustento,IdSustento+' '+Sustento AS DsSus FROM TiposSustento 
WHERE Inactivo=0
ORDER BY IdSustento
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposTasas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposTasas] @pmIdTasa VARCHAR(4)
 AS 
 SELECT IdTasa,TipoTasa,Simbolo,Unidad,Inactivo
 FROM TiposTasas
 WHERE IdTasa=@pmIdTasa
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposTerc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposTerc] @pmIdTipoTerc VARCHAR(4)
 AS 
 IF @pmIdTipoTerc IS NULL 
  SELECT IdTipoTerc,TipoTercero
  FROM TiposTerc
  WHERE Inactivo=0
 ORDER BY IdTipoTerc
 ELSE
  SELECT IdTipoTerc,TipoTercero,Inactivo
  FROM TiposTerc
  WHERE IdTipoTerc=@pmIdTipoTerc
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposVeh] @pmIdTipoVeh VARCHAR(4)
 AS 
 SELECT IdTipoVeh,TipoVehiculo,Configuracion,Ejes,Llantas,CapacPeso,UndCapac,CapacVol
,UndCapVol,CubAlto,CubLargo,CubAncho,PesoBruto,Inactivo
 FROM TiposVeh
 WHERE IdTipoVeh=@pmIdTipoVeh
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposVehDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposVehDso] 
 AS 
 SELECT IdTipoVeh,TipoVehiculo,Configuracion,Ejes,Llantas,PesoBruto,CapacPeso,UndCapac
 ,CubAlto,CubLargo,CubAncho,CapacVol,UndCapVol
 FROM TiposVeh
 WHERE Inactivo=0
 ORDER BY TipoVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryTiposZona]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTiposZona] @pmIdTipZona VARCHAR(4)
 AS  
 IF @pmIdTipZona IS NULL
  SELECT IdTipZona,TipoZona
  FROM TiposZona
  WHERE Inactivo=0
  ORDER BY TipoZona
 ELSE
  SELECT IdTipZona,TipoZona,Inactivo
  FROM TiposZona
  WHERE IdTipZona=@pmIdTipZona
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfAmtLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfAmtLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdDiferido,NomDiferido,tmTipoContab,tmCostoIni,tmAdiciones,tmDisminucion,tmAcuAjustes,(tmCostoIni+tmAdiciones-tmDisminucion+tmAcuAjustes) AS CostoAjustado
,tmTarifa,tmAjustesInf,tmAmortizaMes,tmAmortizaAcum,tmAjuAmtzaAcum,tmAmortizaAcum+tmAjuAmtzaAcum AS TotalAmortizaAcum,tmAjustesAmtza
,tmAmtzaHisAcum,tmAmortizaHis,tmCorrMonAcum,tmBaseCorrMon,tmCorrMonDif,tmEstadoReg,tmObservacion,tmFechaIni,tmNumPeriodos
,tmIdCia,Compania,tmCdCCosto,CCosto,tmCdSubCos,SubCosto,tmCdDep,Dependencia,tmNitRespons,RazonSocial,D.IdEstado AS CdEstado,Estado,FecRetiro
,Ajustable,Contable,G.IdLinea AS CdLinea,Linea,D.IdGrupo AS CdGrupo,Grupo,tmCuota,tmGalones,IdProv,tmInversion,tmCdGrupo
 FROM tm_AfAmt AS T INNER JOIN Diferidos AS D ON T.tmIdDiferido=D.IdDiferido
 INNER JOIN  AfGrupos AS G ON D.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN AfEstados AS ED ON D.IdEstado=ED.IdEstado
 LEFT JOIN CentroCosto AS CC ON T.tmCdCCosto=CC.IdCCosto
 LEFT JOIN Dependencias AS DP ON T.tmCdDep=DP.IdDep LEFT JOIN Terceros AS TR ON T.tmNitRespons=TR.IdTercero
 LEFT JOIN Companias AS CI ON T.tmIdCia=CI.IdCia LEFT JOIN SubCentros AS SC ON  T.tmCdSubCos=SC.IdSubCos
 WHERE tmNumero=@pmtmNumero
 ORDER BY NomDiferido
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfDep]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfDep] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdActivo,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepreciaHis,tmDepreciaMes,tmAjustesInf,tmAjustesDep
,tmDepreciaAcum,tmAjuDepAcum,tmTarifa,tmIdCia,tmCdCCosto,tmCdSubCos,tmCdInstala,tmCdDep,tmNitRespons,tmVidaUtil,tmMetodo
,tmFechaIni,tmEstadoReg,tmObservacion,tmCdGrupo,tmSalvamento,tmTipoContab,tmPartes,tmUnidades,tmCantidad
 FROM tm_AfDep
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfDepLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfDepLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo,NomActivo,tmPartes,(tmCostoIni+tmMejoras+tmAcuAjustes)-tmDisminucion AS TotalBase,tmSalvamento,tmMetodo,tmVidaUtil
,(tmVidaUtil/12) AS VUA,tmUnidades,tmCantidad,tmDepreciaMes,tmDepreciaHis,tmCostoIni,tmMejoras,tmDisminucion,tmDepreciaAcum
,tmAcuAjustes,tmTarifa,tmAjustesInf,tmAjuDepAcum,tmDepreciaAcum+tmAjuDepAcum AS BaseAjuDepAcum,tmAjustesDep,tmEstadoReg,tmObservacion,tmTipoContab
,tmFechaIni,FecFinDep,tmIdCia,Compania,tmCdCCosto,CCosto,tmCdSubCos,SubCosto,tmCdInstala,Instlacion,tmCdDep,Dependencia,tmNitRespons,RazonSocial
,A.IdEstado AS CdEstado,Estado,FecRetiro,Ajustable,Contable,NumPlaca,NumSerie,G.IdLinea AS CdLinea,Linea,A.IdGrupo AS CdGrupo,Grupo,tmCdGrupo
 FROM tm_AfDep AS T INNER JOIN Activos AS A ON T.tmIdActivo=A.IdActivo
 INNER JOIN  AfGrupos AS G ON A.IdGrupo=G.IdGrupo INNER JOIN AfLineas AS L ON G.IdLinea=L.IdLinea
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 LEFT JOIN CentroCosto AS CC ON T.tmCdCCosto=CC.IdCCosto LEFT JOIN Instalaciones AS I ON T.tmCdInstala=I.IdInstala
 LEFT JOIN Dependencias AS DP ON T.tmCdDep=DP.IdDep LEFT JOIN Terceros AS TR ON T.tmNitRespons=TR.IdTercero
 LEFT JOIN Companias AS CI ON T.tmIdCia=CI.IdCia LEFT JOIN SubCentros AS SC ON  T.tmCdSubCos=SC.IdSubCos
 WHERE tmNumero=@pmtmNumero 
 ORDER BY  NomActivo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfDepPartesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfDepPartesLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo,NomActivo,tmIdParte,DescParte,NumParte,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes,tmDepreciaHis
,tmDepreciaMes,tmAjustesInf,tmAjustesDep,tmDepreciaAcum,tmAjuDepAcum,tmTarifa
,tmVidaUtil,tmMetodo,tmFechaIni,tmEstadoReg,tmObservacion,tmSalvamento,tmUnidades,tmCantidad
,P.IdEstado AS CdEstado,Estado,Fec_Retiro
 FROM tm_AfDepPartes AS T INNER JOIN Activos AS A ON T.tmIdActivo=A.IdActivo
 INNER JOIN Activos_Partes AS P ON T.tmIdActivo=P.IdActivo AND T.tmIdParte=P.Item
 INNER JOIN AfEstados AS ED ON A.IdEstado=ED.IdEstado
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfIngreso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AfIngreso] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdActivo,tmFecha,tmVrMejoras,tmVrDisminucion,tmVrAjuInfAcum,tmVrDepAcuHis
,tmVrDepAcuAju,tmVrAjuInfDep,tmNumMeses,tmVidaUtil,tmBaseDep,tmMetodo,tmFecUltDep,tmConcepto,tmUnidades
,tmSalvamento,tmDepPartes,tmNumParte,tmCantidad
 FROM tm_AfIngreso
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfIngresoDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfIngresoDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo,tmNumParte,NomActivo,tmFecha,tmBaseDep,tmVrMejoras,tmVrDisminucion,tmBaseDep+tmVrMejoras-tmVrDisminucion AS TotalBaseDep
,tmVrAjuInfAcum,tmVrDepAcuHis,tmVrDepAcuAju,tmVrAjuInfDep,tmNumMeses,tmFecUltDep,tmSalvamento,tmMetodo,tmVidaUtil,tmUnidades,tmCantidad
,tmDepPartes,tmConcepto,IdEstado,IdCCosto,IdSubCos,IdInstala,IdDep,IdRespons,IdGrupo
 FROM tm_AfIngreso AS T INNER JOIN Activos AS A ON T.tmIdActivo=A.IdActivo
 WHERE tmNumero=@pmtmNumero
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfRetiro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AfRetiro] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdActivo,tmIdCausal,tmNitTercero,tmNomTercero,tmCostoIni,tmMejoras
,tmDisminucion,tmAcuAjustes,tmDepAcum,tmAjuDepAcum,tmVrIngreso,tmFechaRet,tmIdCueDeb,tmIdCueIng
,tmConcepto,tmIdCia,tmCdCCosto,tmCdSubCos,tmNitRespons,tmNumParte
 FROM tm_AfRetiro
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfRetiroDif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfRetiroDif] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo AS IdDiferido,NomDiferido,tmFechaRet,tmCostoIni,tmMejoras AS VrAdiciones,tmDisminucion,tmAcuAjustes
,tmCostoIni+tmMejoras+tmAcuAjustes-tmDisminucion AS CostoAjustado,tmDepAcum AS AmortizaAcum,tmAjuDepAcum AS AjuAmtzaAcum
,(tmCostoIni+tmMejoras+tmAcuAjustes-tmDisminucion)-(tmDepAcum+tmAjuDepAcum) AS SaldoActual
,tmIdCausal,Causal,tmConcepto,tmIdCia,tmCdCCosto,tmCdSubCos
 FROM tm_AfRetiro  AS T INNER JOIN Diferidos AS D ON T.tmIdActivo=D.IdDiferido
 INNER JOIN AfCausales AS C ON T.tmIdCausal=C.IdCausal
 WHERE tmNumero=@pmtmNumero 
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfRetiroDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfRetiroDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo,NomActivo,DepPartes,tmNumParte,tmFechaRet,tmCostoIni,tmMejoras,tmDisminucion,tmAcuAjustes
,tmCostoIni+tmMejoras+tmAcuAjustes-tmDisminucion AS CostoAjustado,tmDepAcum,tmAjuDepAcum
,(tmCostoIni+tmMejoras+tmAcuAjustes-tmDisminucion)-(tmDepAcum+tmAjuDepAcum) AS ValorReal
,tmVrIngreso,tmVrIngreso-((tmCostoIni+tmMejoras+tmAcuAjustes-tmDisminucion)-(tmDepAcum+tmAjuDepAcum)) AS Utilidad
,tmIdCausal,Causal,tmIdCueDeb,tmIdCueIng,tmNitTercero,tmNomTercero,tmConcepto,tmIdCia,tmCdCCosto,tmCdSubCos
 FROM tm_AfRetiro  AS T INNER JOIN Activos AS A ON T.tmIdActivo=A.IdActivo
 INNER JOIN AfCausales AS C ON T.tmIdCausal=C.IdCausal
 WHERE tmNumero=@pmtmNumero 
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfTraslado]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AfTraslado] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdActivo,tmIdCia,tmIdGrupo,tmIdCCosto,tmIdSubCos,tmIdInstala,tmIdDep,tmIdRespons
,tmCdCiaDest,tmCdGrupoDest,tmCdCCostoDest,tmCdSubCosDest,tmCdInstalaDest,tmCdDepDest,tmCdResponsDest
,tmConcepto,tmUbicacion,tmUbicacionDest
 FROM tm_AfTraslado
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfTrasladoDif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfTrasladoDif] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo AS CodDiferido,NomDiferido,tmIdGrupo,G.Grupo AS GrupoOrig,tmCdGrupoDest,GD.Grupo AS GrupoDest,tmIdCCosto,CC.CCosto AS CentroOrigen
,tmCdCCostoDest,CCD.CCosto AS CentroDest,tmIdSubCos,SC.SubCosto AS SubcentroOrig,tmCdSubCosDest,SCD.SubCosto AS SubCentroDest
,tmIdCia,CI.Compania AS CiaOrigen,tmCdCiaDest,CID.Compania AS CiaDestino,tmIdDep,DP.Dependencia AS DependOrig,tmCdDepDest,DPD.Dependencia AS DependDest
,tmIdRespons,TR.RazonSocial AS Responsable,tmCdResponsDest,TRD.RazonSocial AS ResponsDest,tmUbicacion,tmUbicacionDest,tmConcepto
 FROM tm_AfTraslado AS T INNER JOIN Diferidos AS A ON T.tmIdActivo=A.IdDiferido
 INNER JOIN AfGrupos AS G ON T.tmIdGrupo=G.IdGrupo INNER JOIN CentroCosto AS CC ON T.tmIdCCosto=CC.IdCCosto 
 INNER JOIN Dependencias AS DP ON T.tmIdDep=DP.IdDep INNER JOIN Terceros AS TR ON T.tmIdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON T.tmIdCia=CI.IdCia  LEFT JOIN SubCentros AS SC ON T.tmIdSubCos=SC.IdSubCos
 LEFT JOIN AfGrupos AS GD ON T.tmCdGrupoDest=GD.IdGrupo LEFT JOIN CentroCosto AS CCD ON T.tmCdCCostoDest=CCD.IdCCosto 
 LEFT JOIN Dependencias AS DPD ON T.tmCdDepDest=DPD.IdDep LEFT JOIN Terceros AS TRD ON T.tmCdResponsDest=TRD.IdTercero
 LEFT JOIN Companias AS CID ON T.tmCdCiaDest=CID.IdCia  LEFT JOIN SubCentros AS SCD ON T.tmCdSubCosDest=SCD.IdSubCos
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AfTrasladoDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AfTrasladoDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdActivo,NomActivo,tmIdGrupo,G.Grupo AS GrupoOrig,tmCdGrupoDest,GD.Grupo AS GrupoDest,tmIdCCosto,CC.CCosto AS CentroOrigen
,tmCdCCostoDest,CCD.CCosto AS CentroDest,tmIdSubCos,SC.SubCosto AS SubcentroOrig,tmCdSubCosDest,SCD.SubCosto AS SubCentroDest
,tmIdCia,CI.Compania AS CiaOrigen,tmCdCiaDest,CID.Compania AS CiaDestino,tmIdDep,DP.Dependencia AS DependOrig,tmCdDepDest,DPD.Dependencia AS DependDest
,tmIdRespons,TR.RazonSocial AS Responsable,tmCdResponsDest,TRD.RazonSocial AS ResponsDest,tmIdInstala,I.Instlacion AS UbicOrigen,tmUbicacion
,tmCdInstalaDest,UDE.Instlacion AS UbicDestino,tmUbicacionDest,tmConcepto
 FROM tm_AfTraslado AS T INNER JOIN Activos AS A ON T.tmIdActivo=A.IdActivo
 INNER JOIN AfGrupos AS G ON T.tmIdGrupo=G.IdGrupo
 INNER JOIN CentroCosto AS CC ON T.tmIdCCosto=CC.IdCCosto INNER JOIN Instalaciones AS I ON T.tmIdInstala=I.IdInstala
 INNER JOIN Dependencias AS DP ON T.tmIdDep=DP.IdDep INNER JOIN Terceros AS TR ON T.tmIdRespons=TR.IdTercero
 INNER JOIN Companias AS CI ON T.tmIdCia=CI.IdCia  LEFT JOIN SubCentros AS SC ON T.tmIdSubCos=SC.IdSubCos
 LEFT JOIN AfGrupos AS GD ON T.tmCdGrupoDest=GD.IdGrupo
 LEFT JOIN CentroCosto AS CCD ON T.tmCdCCostoDest=CCD.IdCCosto LEFT JOIN Instalaciones AS UDE ON T.tmCdInstalaDest=UDE.IdInstala
 LEFT JOIN Dependencias AS DPD ON T.tmCdDepDest=DPD.IdDep LEFT JOIN Terceros AS TRD ON T.tmCdResponsDest=TRD.IdTercero
 LEFT JOIN Companias AS CID ON T.tmCdCiaDest=CID.IdCia  LEFT JOIN SubCentros AS SCD ON T.tmCdSubCosDest=SCD.IdSubCos
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Aportes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Aportes] @pmtmEst VARCHAR(5),@pmtmIdInstala VARCHAR(4)=Null,@pmtmIdDep VARCHAR(4)=Null,@pmtmIdNom VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContto,tmDiasPen,tmBasePen,tmTarfaPen,tmValorPen,tmTarfaFsp,tmValorFsp,tmTarfaFsu,tmValorFsu,tmDiasSal
,tmBaseSal,tmTarfaSal,tmValorSal,tmDiasRie,tmBaseRie,tmTarfaRie,tmValorRie,tmDiasCom,tmBaseCom,tmTarfaCom,tmValorCom,tmTarfaIcb,tmValorIcbf,tmTarfaSen,tmValorSena
,tmTarfaMin,tmValorMin,tmTarfaEsa,tmValorESAP,tmDiasNov,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmNAutInc,tmVrIncap,tmNAutLic,tmVrLicencia,tmNAutIrp,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp
,tmIdFonPen,FP.Fondo AS FondoPen,tmIdFonSal,FS.Fondo AS FondoEps,tmIdFonRie,FR.Fondo AS FondoArp,tmIdFonCaj,CC.Fondo AS CajaComp,tmIdInstala,Instlacion,tmIdDep,Dependencia,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmVehiculo,tmVrBasico
,tmCodNewEps,tmCodNewPen,tmCodNewRie,tmCodNewIns,tmCodNewTar,CRN.ClaseRiesgo AS NewClaseRie,CRN.Tarifa AS NewTarifa,tmCodNewGru,TarfaEmp,TarfaTrab,tmEst,tmItem,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmBaseRef,tmDiasSan,tmDiasDnrPen,tmDiasDnrSal
,tmNovDsr,tmFecNovIng,tmFecNovRet,tmFecNovVsp,tmFecIniSln,tmFecFinSln,tmFecIniIge,tmFecFinIge,tmFecIniLma,tmFecFinLma,tmFecIniVac,tmFecFinVac,tmFecIniVct,tmFecFinVct,tmFecIniIrl,tmFecFinIrl,tmVrIBCparaf,tmCantHoras,tmTipSalario,tmIdActEco
--Datos empleado
,Codigo,TipoId,Dv,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,EsCondtor,FecNacmto,LugarNacmto,TipoSangre,FactorRh,Sexo,Licencia,CatLicencia,VigLicencia
,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,IdEstCivil,EstCivil,NHijos,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,CR.ClaseRiesgo AS ClasRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,C.TipoLiquida AS TipLiq,FecAfiSeg
,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj,tmCdFonAvp,CdFonAvp
 FROM tm_Aportes AS A INNER JOIN Empleados AS E ON A.tmIdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON A.tmNContto=C.NContrato
 INNER JOIN Dependencias AS DP ON A.tmIdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON A.tmIdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON A.tmIdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON A.tmIdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON A.tmIdNom=TN.IdNom INNER JOIN Fondos AS FP ON A.tmIdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON A.tmIdFonSal=FS.IdFondo  INNER JOIN Fondos AS FR ON A.tmIdFonRie=FR.IdFondo
 INNER JOIN Fondos AS CC ON A.tmIdFonCaj=CC.IdFondo INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN EstadoCiv AS EC ON E.IdEstCivil=EC.IdEstado
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado  LEFT JOIN ClaseRie AS CRN ON A.tmCodNewTar=CRN.IdClase
 LEFT JOIN GruposAR AS GAR ON A.tmCodNewGru=GAR.IdGrupo
 WHERE tmEst=@pmtmEst AND tmIdInstala LIKE ISNULL(@pmtmIdInstala,'%') AND tmIdDep LIKE ISNULL(@pmtmIdDep,'%')
 AND tmIdNom LIKE ISNULL(@pmtmIdNom,'%') AND C.IdArea LIKE ISNULL(@pmIdArea,'%')
 ORDER BY Apellidos,Nombres,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesAdm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesAdm] @pmtmEst VARCHAR(5),@pmAdmon VARCHAR(3)
 AS 
 IF @pmAdmon='PEN'
  SELECT tmIdFonPen,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasPen>0 OR tmValorPen>0)
  GROUP BY  tmIdFonPen
 IF @pmAdmon='SAL'
  SELECT tmIdFonSal,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasSal>0 OR tmValorSal>0)
  GROUP BY tmIdFonSal
 IF @pmAdmon='RIE'
  SELECT tmIdFonRie,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst  AND (tmDiasRie>0 OR tmValorRie>0)
 GROUP BY  tmIdFonRie
 IF @pmAdmon='COM'
  SELECT tmIdFonCaj,COUNT(tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasCom>0 OR tmValorCom>0)
  GROUP BY tmIdFonCaj
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesAfi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesAfi] @pmtmEst VARCHAR(5),@pmAdmon VARCHAR(3)
 AS 
 IF @pmAdmon='PEN'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasPen>0 OR tmValorPen>0)
 IF @pmAdmon='SAL'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasSal>0 OR tmValorSal>0)
 IF @pmAdmon='RIE'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasRie>0 OR tmValorRie>0)
 IF @pmAdmon='COM'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND (tmDiasCom>0 OR tmValorCom>0)
 IF @pmAdmon='SEN'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorSena>0
 IF @pmAdmon='ICB'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorIcbf>0
 IF @pmAdmon='ESA'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorESAP>0
 IF @pmAdmon='MIN'
  SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad   FROM tm_Aportes
  WHERE tmEst=@pmtmEst AND tmValorMin>0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesAtz]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesAtz] @pmtmEst VARCHAR(5),@pmtmIdFonSal VARCHAR(8)=Null,@pmtmIdFonRie VARCHAR(8)=Null
 AS 
 SELECT tmIdEmpleado,tmNAutInc,tmNAutLic,tmNAutIrp,tmVrIncIrp,tmVrIncap,tmVrLicencia
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst AND tmIdFonSal LIKE ISNULL(@pmtmIdFonSal,'%') AND tmIdFonRie LIKE ISNULL(@pmtmIdFonRie,'%')
 AND (tmVrIncIrp>0 OR tmVrIncap>0 OR tmVrLicencia>0)
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesCed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesCed] @pmtmEst VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 SELECT tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst AND tmIdEmpleado=@pmtmIdEmpleado  AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesCom] @pmtmEst VARCHAR(5)
 AS 
 SELECT SUM(tmBaseCom) AS SValBase
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst  AND (tmValorCom>0 OR tmValorSena>0 OR tmValorIcbf>0)
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesDet] @pmtmEst VARCHAR(5),@pmtmItem INT=Null
 AS 
 SELECT tmEst,tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNContto,tmDiasPen,tmDiasSal,tmDiasRie,tmDiasCom,tmBasePen,tmBaseSal,tmBaseRie,tmBaseCom,tmBaseRef,tmValorPen,tmValorSal,tmValorRie,tmValorCom,tmValorSena
,tmValorIcbf,tmValorFsp,tmValorFsu,tmValorESAP,tmValorMin,tmTarfaPen,tmTarfaSal,tmTarfaRie,tmTarfaFsp,tmTarfaFsu,tmTarfaEsa,tmTarfaMin,tmTarfaCom,tmTarfaIcb,tmTarfaSen,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte
,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovAvp,tmNovIrp,tmNovVct,tmCodNewEps,tmCodNewPen,tmCodNewRie,tmCodNewIns,tmCodNewTar,tmCodNewGru,tmVrIncap,tmVrLicencia,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmVrUpc,tmVrIncIrp,tmNAutLic,tmNAutInc,tmNAutIrp
,tmIdFonPen,tmIdFonSal,tmIdFonRie,tmIdFonCaj,tmIdInstala,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVehiculo,tmVrBasico,tmDiasNov,tmCdFonAvp,tmDiasSan,tmDiasDnrPen,tmDiasDnrSal
,tmNovDsr,tmFecNovIng,tmFecNovRet,tmFecNovVsp,tmFecIniSln,tmFecFinSln,tmFecIniIge,tmFecFinIge,tmFecIniLma,tmFecFinLma,tmFecIniVac,tmFecFinVac,tmFecIniVct,tmFecFinVct,tmFecIniIrl,tmFecFinIrl,tmVrIBCparaf,tmCantHoras,tmTipSalario,tmIdActEco
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesDsn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesDsn] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmNovIng,tmNovRet,tmNovTda,tmNovTaa,tmNovTdp,tmNovTap,tmNovVsp,tmNovVte
,tmNovVst,tmNovSln,tmNovIge,tmNovLma,tmNovVac,tmNovDsr,tmNovAvp,tmNovIrp,tmNovVct,tmCodNewEps,FS.Fondo AS NuevaEps,tmCodNewPen,FP.Fondo AS NuevoFdoPen,tmCodNewIns,Instlacion
,tmCodNewTar,tmCodNewGru,tmDiasNov,tmDiasSan,tmDiasDnrPen,tmDiasDnrSal,tmFecNovIng,tmFecNovRet,tmFecNovVsp,tmFecIniSln,tmFecFinSln,tmFecIniIge,tmFecFinIge,tmFecIniLma,tmFecFinLma
,tmFecIniVac,tmFecFinVac,tmFecIniVct,tmFecFinVct,tmFecIniIrl,tmFecFinIrl
 FROM tm_Aportes AS A LEFT JOIN Instalaciones AS I ON A.tmCodNewIns=I.IdInstala
 LEFT JOIN Fondos AS FP ON A.tmCodNewPen=FP.IdFondo LEFT JOIN Fondos AS FS ON A.tmCodNewEps=FS.IdFondo
 WHERE tmEst=@pmtmEst AND tmDiasNov>0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesDso] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmItem,tmIdEmpleado,tmApellido1,tmApellido2,tmNombre1,tmNombre2,tmVrBasico,tmDiasPen,tmBasePen,tmTarfaPen,tmValorPen,tmVrVolAfi,tmVrVolApo,tmVrNoReten,tmValorFsp,tmValorFsu
,tmDiasSal,tmBaseSal,tmTarfaSal,tmValorSal,tmVrUpc,tmNAutInc,tmVrIncap,tmNAutLic,tmVrLicencia,tmDiasRie,tmBaseRie,tmTarfaRie,tmValorRie,tmVrIncIrp,tmNAutIrp
,tmDiasCom,tmBaseCom,tmTarfaCom,tmValorCom,tmTarfaIcb,tmValorIcbf,tmTarfaSen,tmValorSena,tmBaseRef,tmTarfaEsa,tmValorESAP,tmTarfaMin,tmValorMin
,tmTarfaFsp,tmTarfaFsu,tmIdFonPen,FP.Fondo AS FondoPen,tmIdFonSal,FS.Fondo AS FondoEps,tmIdFonRie,FR.Fondo AS FondoArp,tmIdFonCaj,CC.Fondo AS CajaComp
,tmIdInstala,Instlacion,tmNContto,tmIdNom,tmCdFonAvp,tmDiasSan,tmDiasDnrPen,tmDiasDnrSal,tmVrIBCparaf,tmCantHoras,tmTipSalario,tmIdActEco,AC.IdSector,AC.CodAdicional,AC.DescActividad
 FROM tm_Aportes AS A INNER JOIN Instalaciones AS I ON A.tmIdInstala=I.IdInstala
 INNER JOIN Fondos AS FP ON A.tmIdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON A.tmIdFonSal=FS.IdFondo
 INNER JOIN Fondos AS FR ON A.tmIdFonRie=FR.IdFondo INNER JOIN Fondos AS CC ON A.tmIdFonCaj=CC.IdFondo
 LEFT JOIN NomActividades AS AC ON A.tmIdActEco=AC.IdActEco
 WHERE tmEst=@pmtmEst
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesEmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesEmp] @pmtmEst VARCHAR(5)
 AS 
 SELECT COUNT(DISTINCT tmIdEmpleado) AS Cantidad
 FROM tm_Aportes
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesItm] @pmtmEst VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM,COUNT(tmItem) AS SCANITM
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesTCom] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonCaj,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBaseCom) AS TotalIBC,SUM(tmValorCom) AS TotalCajas
,SUM(tmValorSena) AS TotalSena,SUM(tmValorIcbf) AS TotalIcb,SUM(tmValorESAP) AS TotalESAP,SUM(tmValorMin) AS TotalMinEdu
,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst AND (tmDiasCom>0 OR tmValorCom>0 OR tmValorSena>0 OR tmValorIcbf>0 OR tmValorESAP>0 OR tmValorMin>0)
 GROUP BY  tmIdFonCaj
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesTot] @pmtmEst VARCHAR(5),@pmtmIdInstala VARCHAR(4)=Null,@pmtmIdDep VARCHAR(4)=Null,@pmtmIdNom VARCHAR(4)=Null
,@pmIdArea VARCHAR(4)=Null
 AS 
 SELECT COUNT(tmIdEmpleado) AS Cantidad,SUM(tmValorPen) AS TotalPension,SUM(tmValorFsp) AS TotalFsp,SUM(tmValorFsu) AS TotalFsu,SUM(tmValorSal) AS TotalSalud
 ,SUM(tmValorRie) AS TotalRiesgos,SUM(tmValorCom) AS TotalCajas,SUM(tmValorIcbf) AS TotalICBF,SUM(tmValorSena) AS TotalSena,SUM(tmVrIncap) AS TotalIncap,SUM(tmVrLicencia) AS TotalLicencias
,SUM(tmVrVolAfi) AS TotalAfiVol,SUM(tmVrVolApo) AS TotalApoVol,SUM(tmVrNoReten) AS TotalNoRetnido,SUM(tmVrUpc) AS TotalUpc,SUM(tmVrIncIrp) AS TotalIncIrp,SUM(tmVrBasico) AS TotalSalarios
,SUM(tmValorESAP) AS TotalESAP,SUM(tmValorMin) AS TotalMinEdu
 FROM tm_Aportes AS A INNER JOIN  Emp_Contrato AS C ON A.tmNContto=C.NContrato
 WHERE tmEst=@pmtmEst AND tmIdInstala LIKE ISNULL(@pmtmIdInstala,'%') AND tmIdDep LIKE ISNULL(@pmtmIdDep,'%')
 AND tmIdNom LIKE ISNULL(@pmtmIdNom,'%') AND IdArea LIKE ISNULL(@pmIdArea,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTpen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesTpen] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonPen,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBasePen) AS TotalIBC,SUM(tmValorPen) AS TotalPension,SUM(tmValorFsp) AS TotalFsp,SUM(tmValorFsu) AS TotalFsu
,SUM(tmVrVolAfi) AS TotalAfiVol,SUM(tmVrVolApo) AS TotalApoVol,SUM(tmVrNoReten) AS TotalNoRetnido,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst AND (tmDiasPen>0 OR tmValorPen>0 OR tmVrVolAfi>0 OR tmVrVolApo>0 OR tmValorFsp>0)
 GROUP BY  tmIdFonPen
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTrie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesTrie] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonRie,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBaseRie) AS TotalIBC, SUM(tmValorRie) AS TotalRiesgos,SUM(tmVrIncIrp) AS TotalIncIrp,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst  AND (tmDiasRie>0 OR tmValorRie>0 OR tmVrIncIrp>0)
 GROUP BY  tmIdFonRie
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AportesTSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AportesTSal] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmIdFonSal,COUNT(DISTINCT tmIdEmpleado) AS Cantidad,SUM(tmBaseSal) AS TotalIBC,SUM(tmValorSal) AS TotalSalud,SUM(tmVrIncap) AS TotalIncap
,SUM(tmVrLicencia) AS TotalLicencias,SUM(tmVrUpc) AS TotalUpc,SUM(tmVrBasico) AS TotalSalarios
 FROM tm_Aportes 
 WHERE tmEst=@pmtmEst AND (tmDiasSal>0 OR tmValorSal>0 OR tmVrIncap>0 OR tmVrLicencia>0 OR tmVrUpc>0)
 GROUP BY  tmIdFonSal
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_AutTot] @pmtmEst VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc
,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AutTotDso] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmItem,tmTipAdm,tmIdFondo,Fondo,tmCodTipoApo,tmTotalCot,tmTotalFsp,tmTotalFsu,tmTotalAva,tmTotalAve,tmTotalUpc,tmTotalLic,tmTotalInc
,tmTotalOtr,tmDiasMora,tmTarifMora,tmIntMora,tmIMoraOtr,tmTotalSAF,tmSAFUpc,tmTotalPagar,tmTotalFon,tmTotalAfi,tmNumAutLic,tmNumAutInc,tmNumPlaSAF
 FROM tm_AutTot AS A LEFT JOIN Fondos AS F ON A.tmIdFondo=F.IdFondo
 WHERE tmEst=@pmtmEst 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotFon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AutTotFon] @pmtmEst VARCHAR(5),@pmtmTipAdm VARCHAR(3),@pmtmIdFondo VARCHAR(8)
,@pmtmItem INT
 AS 
 SELECT tmEst,tmItem,tmTipAdm,tmIdFondo,tmCodTipoApo
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst AND tmTipAdm=@pmtmTipAdm AND tmIdFondo=@pmtmIdFondo
 AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AutTotItm] @pmtmEst VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM,COUNT(tmItem) AS ScanItm
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AutTotPag]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AutTotPag] @pmtmEst VARCHAR(5)
 AS 
 SELECT tmTipAdm,COUNT(tmItem) AS Cantidad,SUM(tmTotalPagar)  AS StotPag,SUM(tmTotalAfi) AS TotalAfi
 FROM tm_AutTot
 WHERE tmEst=@pmtmEst 
 GROUP BY tmTipAdm
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AuxInv] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdBodega,Bodega,tmNumLote,tmSaldoAnt,tmCostoAnt
,tmEntradas,tmCostoEnt,tmSalidas,tmCostoSal
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmSaldoAnt+tmEntradas-tmSalidas ELSE tmSalidas-tmEntradas  END AS NuevoSaldo
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoAnt+tmCostoEnt-tmCostoSal ELSE 0  END AS CostoTotal
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoProm ELSE 0  END AS CostoPromActual
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoProm*(tmSaldoAnt+tmEntradas-tmSalidas) ELSE 0  END AS  CostoTotalPromedio,tmProdCia
,TipoRef,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,tmCdTanque,PM.IdUnd AS CdUnid,UM.Unidad AS UnidadPres,PM.UndMed AS CdUndMed,SU.Unidad AS UnidadMed
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,Tamano,Color,Referencia,VrCosto AS ProdUltCosto,VrCostPmd AS ProdCostoProm,IdTarIva,Tarifa,Simbolo,IvaInc
,tmPrecioVta1 AS Precio1,tmPrecioVta2 AS Precio2,tmPrecioVta3 AS Precio3,tmPrecioVta4 AS Precio4,tmPrecioVta5 AS Precio5,IdProv,PV.RazonSocial AS NomProveedor,DescripLong,DescripAbrv
,dbo.FuncAuxInvNivelMin(tmIdProducto,tmIdCia) AS ExtciaMin,dbo.FuncAuxInvNivelMax(tmIdProducto,tmIdCia) AS ExtciaMax
,dbo.FuncAuxInvSaldoAct(tmIdProducto,tmIdCia,tmIdBodega) AS ExtciaAct
,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo AS ProdInactivo 
 FROM tm_AuxInv AS A INNER JOIN ProdMcias AS PM ON A.tmIdProducto=PM.IdProducto 
 INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed INNER JOIN Terceros AS PV ON PM.IdProv=PV.IdTercero
 LEFT JOIN Companias AS CN ON A.tmIdCia=CN.IdCia LEFT JOIN Bodegas AS B ON A.tmIdBodega=B.IdBodega
 LEFT JOIN Tablapor AS TI ON PM.IdTarIva=TI.IdTarifa
 WHERE tmEst=@pmtmEst
 ORDER BY DescripProd,tmIdCia,tmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvCpm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AuxInvCpm] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,tmIdCia,SUM(tmEntradas) AS STOTCAN
 FROM tm_AuxInv
 WHERE tmEst=@pmtmEst AND  tmCostoProm=0 AND (tmSaldoAnt<>0 OR tmEntradas<>0 OR tmSalidas<>0)
 GROUP BY tmIdProducto,tmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AuxInvPro] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4)=Null
,@pmtmIdCia CHAR(2)=Null,@pmtmNumLote VARCHAR(30)=Null
 AS 
 SELECT tmEst,tmIdProducto,tmIdBodega,tmIdCia,tmNumLote,tmSaldoAnt,tmEntradas,tmSalidas
,tmCostoAnt,tmCostoEnt,tmCostoSal,tmCostoProm,tmCdTanque
 FROM tm_AuxInv
 WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%') AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 AND tmNumLote LIKE ISNULL(@pmtmNumLote,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvUbic]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AuxInvUbic] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdBodega,Bodega,tmIdUbic,Ubicacion
,tmSaldoAnt,tmCostoAnt,tmEntradas,tmCostoEnt,tmSalidas,tmCostoSal
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmSaldoAnt+tmEntradas-tmSalidas ELSE tmSalidas-tmEntradas  END AS NuevoSaldo
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoAnt+tmCostoEnt-tmCostoSal ELSE 0  END AS CostoTotal
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoProm ELSE 0  END AS CostoPromActual
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoProm*(tmSaldoAnt+tmEntradas-tmSalidas) ELSE 0  END AS  CostoTotalPromedio
,TipoRef,PM.IdUnd AS CdUnid,UM.Unidad AS UnidadPres,PM.UndMed AS CdUndMed,SU.Unidad AS UnidadMed
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,Tamano,Color,Referencia,VrCosto AS ProdUltCosto,VrCostPmd AS ProdCostoProm,IdTarIva,Tarifa,Simbolo,IvaInc
,Precio1,Precio2,Precio3,Precio4,Precio5,IdProv,PV.RazonSocial AS NomProveedor,DescripLong,DescripAbrv
,dbo.FuncAuxInvNivelMin(tmIdProducto,tmIdCia) AS ExtciaMin,dbo.FuncAuxInvNivelMax(tmIdProducto,tmIdCia) AS ExtciaMax
,dbo.FuncAuxInvSaldoAct(tmIdProducto,tmIdCia,tmIdBodega) AS ExtciaAct --,ExtciaMin,ExtciaMax,ExtciaAct
,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo AS ProdInactivo,Pasillo,Nivel,Profdad,Notas
 FROM tm_AuxInvUbic AS A INNER JOIN ProdMcias AS PM ON A.tmIdProducto=PM.IdProducto
 INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed
 INNER JOIN Terceros AS PV ON PM.IdProv=PV.IdTercero
 LEFT JOIN Companias AS CN ON A.tmIdCia=CN.IdCia LEFT JOIN Bodegas AS B ON A.tmIdBodega=B.IdBodega
 LEFT JOIN Tablapor AS TI ON PM.IdTarIva=TI.IdTarifa LEFT JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN BodUbic AS U ON A.tmIdUbic=U.IdUbic
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_AuxInvVen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_AuxInvVen] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdBodega,Bodega,tmNumLote,tmSaldoAnt,tmCostoAnt
,tmEntradas,tmCostoEnt,tmSalidas,tmCostoSal
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmSaldoAnt+tmEntradas-tmSalidas ELSE tmSalidas-tmEntradas  END AS NuevoSaldo
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoAnt+tmCostoEnt-tmCostoSal ELSE 0  END AS CostoTotal
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoProm ELSE 0  END AS CostoPromActual
,CASE  WHEN TipoRef IN ('PRODUCTO','INSUMO') THEN tmCostoProm*(tmSaldoAnt+tmEntradas-tmSalidas) ELSE 0  END AS  CostoTotalPromedio,tmProdCia
--información de ventas
,tmVtaCant,tmVtaCantDev,tmVtaCant-tmVtaCantDev AS VtaCantNeto,tmVtaTotal,tmVtaTotalDev,(tmVtaTotal-tmVtaTotalDev)+(tmVtaGlobal-tmVtaGlobalDev) AS VtaNeto
,tmVtaCosto,tmVtaCostoDev,tmVtaCosto-tmVtaCostoDev AS VtaCostoNeto,tmVtaDcto,tmVtaDctoDev,tmVtaDcto-tmVtaDctoDev AS VtaDctoNeto
,((tmVtaTotal-tmVtaTotalDev)+(tmVtaGlobal-tmVtaGlobalDev))-(tmVtaCosto-tmVtaCostoDev)  AS VtaUtilidad,tmVtaIva,tmVtaIvaDev,tmVtaRet,tmVtaRetDev
,tmVtaIca,tmVtaIcaDev,tmVtaTasa,tmVtaTasaDev,tmVtaGlobal,tmVtaGlobalDev,tmVtaSol,tmVtaSolDev
,TipoRef,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,tmCdTanque,PM.IdUnd AS CdUnid,UM.Unidad AS UnidadPres,PM.UndMed AS CdUndMed,SU.Unidad AS UnidadMed
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,Tamano,Color,Referencia,VrCosto AS ProdUltCosto,VrCostPmd AS ProdCostoProm,IdTarIva,Tarifa,Simbolo,IvaInc
,tmPrecioVta1 AS Precio1,tmPrecioVta2 AS Precio2,tmPrecioVta3 AS Precio3,tmPrecioVta4 AS Precio4,tmPrecioVta5 AS Precio5
,IdProv,PV.RazonSocial AS NomProveedor,DescripLong,DescripAbrv
,dbo.FuncAuxInvNivelMin(tmIdProducto,tmIdCia) AS ExtciaMin,dbo.FuncAuxInvNivelMax(tmIdProducto,tmIdCia) AS ExtciaMax
,dbo.FuncAuxInvSaldoAct(tmIdProducto,tmIdCia,tmIdBodega) AS ExtciaAct --,ExtciaMin,ExtciaMax,ExtciaAct
,Factor1,Factor2,Factor3,Factor4,Factor5,PM.Inactivo AS ProdInactivo
 FROM tm_AuxInv  AS A INNER JOIN ProdMcias  AS PM ON A.tmIdProducto=PM.IdProducto 
 INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed   INNER JOIN Terceros AS PV ON PM.IdProv=PV.IdTercero
 LEFT JOIN Companias AS CN ON A.tmIdCia=CN.IdCia  LEFT JOIN Bodegas AS B ON A.tmIdBodega=B.IdBodega
 LEFT JOIN Tablapor AS TI ON PM.IdTarIva=TI.IdTarifa
 WHERE tmEst=@pmtmEst 
 ORDER BY DescripProd,tmIdCia,tmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalAcum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalAcum] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmCodAgncia VARCHAR(16)=Null
 AS 
 SELECT BC.tmIdCuenta AS IdCuent,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo
,tmIdCia,Compania,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
--información del tercero
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
--información de agencia y vehículos
,CodAgencia,Referencia--,NumVeh
,tmItem,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_BalAcum  AS  BC INNER JOIN Puc AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON BC.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN  Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CI ON BC.tmIdCia=CI.IdCia
-- LEFT JOIN Vehiculos AS V ON BC.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst AND BC.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmCodAgncia LIKE ISNULL(@pmtmCodAgncia,'%')
 ORDER BY BC.tmIdCuenta,tmIdCia,RazonSocial,tmCodAgncia,tmIdCCosto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalAcumGCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalAcumGCue] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCuenta,COUNT(tmItem) AS SCANT
 FROM tm_BalAcum
 WHERE tmEst=@pmtmEst
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalCom] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmCodAgncia VARCHAR(16)=Null
 AS 
 SELECT BC.tmIdCuenta AS IdCuent,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
,tmVrPresupto,tmVrCompras
--información del tercero
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono,EsAccnista,EsCliente,EsPropietario 
--información de agencia y vehículos
,CodAgencia,Referencia--,NumVeh
,tmItem,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,Tercero,CentroCosto
 FROM tm_BalCom  AS  BC INNER JOIN Puc AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON BC.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN  Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
-- LEFT JOIN Vehiculos AS V ON BC.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst AND BC.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmCodAgncia LIKE ISNULL(@pmtmCodAgncia,'%')
 ORDER BY BC.tmIdCuenta,RazonSocial,tmCodAgncia,tmIdCCosto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComAux]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComAux] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmTipo VARCHAR(4),@pmtmIdTercero VARCHAR(16),@pmtmIdVehiculo VARCHAR(10)
,@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmCodAgncia VARCHAR(16)
 AS 
 SELECT tmEst,tmIdCuenta,tmItem,tmTipo,tmSaldoAnterior
 FROM tm_BalCom
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmTipo=@pmtmTipo
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
 AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%') AND tmIdSubCos LIKE ISNULL(@pmtmIdSubCos,'%')
 AND tmCodAgncia LIKE ISNULL(@pmtmCodAgncia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComBases]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComBases] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmCodAgncia VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmIdCia CHAR(2)=Null
 AS 
 SELECT BC.tmIdCuenta AS IdCuent,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo,tmVrPresupto,tmVrCompras
--bases acumuladas del año
,CASE P.BaseGravable WHEN 1 THEN ISNULL(CASE tmTipo WHEN 'N' THEN dbo.FuncComDetalleBasesNit(BC.tmIdCuenta,tmIdTercero,@pmFechaIni,@pmFechaFin,@pmIdCia)
WHEN 'NC' THEN dbo.FuncComDetalleBasesNitCc(BC.tmIdCuenta,tmIdTercero,tmIdCCosto,@pmFechaIni,@pmFechaFin,@pmIdCia)
WHEN 'NCS' THEN dbo.FuncComDetalleBasesNitCcSub(BC.tmIdCuenta,tmIdTercero,tmIdCCosto,tmIdSubCos,@pmFechaIni,@pmFechaFin,@pmIdCia)
WHEN 'CS' THEN dbo.FuncComDetalleBasesCcSub(BC.tmIdCuenta,tmIdCCosto,tmIdSubCos,@pmFechaIni,@pmFechaFin,@pmIdCia)
WHEN 'C' THEN dbo.FuncComDetalleBasesCc(BC.tmIdCuenta,tmIdCCosto,@pmFechaIni,@pmFechaFin,@pmIdCia)
ELSE 
 dbo.FuncComDetalleBasesCue (BC.tmIdCuenta,@pmFechaIni,@pmFechaFin,@pmIdCia)
END,0) ELSE 0 END AS TotalBase,Porcntaje
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
--información del tercero
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono,EsAccnista,EsCliente,EsPropietario 
--información de agencia y vehículos
,CodAgencia,Referencia--,NumVeh
,tmItem,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,Tercero,CentroCosto
 FROM tm_BalCom  AS  BC INNER JOIN Puc AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON BC.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN  Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
-- LEFT JOIN Vehiculos AS V ON BC.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst AND BC.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmCodAgncia LIKE ISNULL(@pmtmCodAgncia,'%')
 ORDER BY BC.tmIdCuenta,RazonSocial,tmCodAgncia,tmIdCCosto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComCue] @pmtmEst CHAR(2)
 AS
 SELECT  tmIdCuenta,COUNT(tmItem) AS StotItm
 FROM tm_BalCom
 WHERE tmEst=@pmtmEst
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComNiif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComNiif] @pmtmEst CHAR(2)
 AS 
 SELECT BC.tmIdCuenta AS CdCuenta,P.NomCuenta,tmIdCueNiif,PN.NomCuenta AS NomCueNiif,tmIdCia,Compania,tmTipo
,tmSaldoAnt1,tmDebitos1,tmCreditos1,tmSaldoAnt1+tmDebitos1-tmCreditos1 AS NuevoSaldo1
,tmSaldoAnt2,tmDebitos2,tmCreditos2,tmSaldoAnt2+tmDebitos2-tmCreditos2 AS NuevoSaldo2
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
,NC.tmNivel1,NC.tmNivel2,NC.tmNivel4,NC.tmNivel6,NC.tmNivel9,NC.tmNivel12
,NCN.tmNivel1 AS NiifNivel1,NCN.tmNivel2 AS NiifNivel2,NCN.tmNivel4 AS NiifNivel4,NCN.tmNivel6 AS NiifNivel6
,NCN.tmNivel9 AS NiifNivel9,NCN.tmNivel12 AS NiifNivel12,tmId,tmEst
 FROM tm_BalComNiif AS BC INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN Puc AS P ON BC.tmIdCuenta=P.IdCuenta LEFT JOIN PucNiif AS PN ON BC.tmIdCueNiif=PN.IdCuenta
 LEFT JOIN tm_NivCue AS NC ON BC.tmIdCuenta=NC.tmIdCuenta LEFT JOIN tm_NivCueNiif AS NCN ON BC.tmIdCueNiif=NCN.tmIdCuenta
 LEFT JOIN Companias AS CI ON BC.tmIdCia=CI.IdCia LEFT JOIN Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalCompara]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalCompara] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT BC.tmIdCuenta AS CdCuenta,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmSalAnt3,tmDebitos3,tmCreditos3,tmSaldo3,tmIdCia,Compania
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
--información de agencia y vehículos
,CodAgencia,Referencia--,NumVeh
,tmItem,tmEst,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_BalCompara AS BC INNER JOIN Puc AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON BC.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN  Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CI ON BC.tmIdCia=CI.IdCia
-- LEFT JOIN Vehiculos AS V ON BC.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst AND BC.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 ORDER BY BC.tmIdCuenta,tmIdCia,RazonSocial,tmCodAgncia,tmIdCCosto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComparaCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComparaCue] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdCia CHAR(2)=Null,@pmtmTipo VARCHAR(4)=Null
 AS 
 SELECT tmEst,tmIdCuenta,tmItem,tmIdCia,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmSalAnt3,tmDebitos3,tmCreditos3,tmSaldo3
 FROM tm_BalCompara
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 AND tmTipo LIKE ISNULL(@pmtmTipo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComparaGCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComparaGCue] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCuenta,COUNT(tmItem) AS SCANT
 FROM tm_BalCompara
 WHERE tmEst=@pmtmEst
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComparaTer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComparaTer] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmTipo VARCHAR(4)
,@pmtmIdCia CHAR(2)=Null,@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdVehiculo VARCHAR(10)=Null
,@pmtmIdCCosto VARCHAR(16)=Null,@pmtmIdSubCos VARCHAR(16)=Null,@pmtmCodAgncia VARCHAR(16)=Null
 AS 
 SELECT tmEst,tmIdCuenta,tmItem,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmSalAnt3,tmDebitos3,tmCreditos3,tmSaldo3
 FROM tm_BalCompara
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta  AND tmTipo=@pmtmTipo
 AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%') AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%')
 AND tmIdSubCos LIKE ISNULL(@pmtmIdSubCos,'%') AND tmCodAgncia LIKE ISNULL(@pmtmCodAgncia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComSan] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmTipo VARCHAR(4)
 AS 
 SELECT tmEst,tmIdCuenta,tmItem,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
 FROM tm_BalCom
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmTipo=@pmtmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalComVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalComVeh] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null, @pmtmIdTercero VARCHAR(16)=Null, @pmtmIdVehiculo VARCHAR(10)=Null
,@pmIdGrupo VARCHAR(4)=Null,@pmIdAdmon VARCHAR(4)=Null
 AS
 SELECT tmIdCuenta,NomCuenta,tmIdVehiculo,tmSaldoAnterior,tmTotalDebitos, tmTotalCreditos,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo
,tmIdTercero,T.RazonSocial AS NombreTercero
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,Dv,TipoId,T.Direccion AS Dirccion,Telefono,Localidad
,tmItem,tmEst,tmTipo
 FROM tm_BalCom AS BC INNER JOIN Puc AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Vehiculos AS V ON BC.tmIdVehiculo=V.IdVehiculo
   INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
   INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo   LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa  LEFT JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 WHERE tmEst=@pmtmEst  AND tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%') AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')  AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
 ORDER BY tmIdCuenta,T.RazonSocial,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalGen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalGen] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT BG.tmIdCuenta AS CdCuenta,NomCuenta,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmIdCia,Compania,tmEst,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_BalGen AS  BG INNER JOIN Puc AS P ON BG.tmIdCuenta=P.IdCuenta
 LEFT JOIN Companias AS CI ON BG.tmIdCia=CI.IdCia
 LEFT JOIN tm_NivCue AS NV ON BG.tmIdCuenta=NV.tmIdCuenta
 WHERE tmEst=@pmtmEst AND BG.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 ORDER BY  BG.tmIdCuenta,tmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalGenCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalGenCue] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2)=Null
 AS 
 SELECT tmEst,tmIdCuenta,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2
 FROM tm_BalGen
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalGenGcue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalGenGcue] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCuenta,count(tmIdCuenta) AS SCANT
 FROM tm_BalGen
 WHERE tmEst=@pmtmEst
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalPspto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalPspto] @pmtmEst CHAR(2)
 AS 
 SELECT T.IdCuenta AS CdCuenta,NomCuenta,T.IdCCosto AS CdCcosto,CCosto,T.IdSubCos AS CdSubCentro,SubCosto,T.IdCia AS CdCia,Compania,VrPstoEne,VrSanEne,VrDebEne,VrCreEne,VrPstoFeb,VrSanFeb,VrDebFeb,VrCreFeb,VrPstoMar,VrSanMar,VrDebMar,VrCreMar
,VrPstoAbr,VrSanAbr,VrDebAbr,VrCreAbr,VrPstoMay,VrSanMay,VrDebMay,VrCreMay,VrPstoJun,VrSanJun,VrDebJun,VrCreJun,VrPstoJul,VrSanJul,VrDebJul,VrCreJul,VrPstoAgo,VrSanAgo,VrDebAgo,VrCreAgo,VrPstoSep,VrSanSep,VrDebSep,VrCreSep
,VrPstoOct,VrSanOct,VrDebOct,VrCreOct,VrPstoNov,VrSanNov,VrDebNov,VrCreNov,VrPstoDic,VrSanDic,VrDebDic,VrCreDic,VrPstoAnual
,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,Naturaleza,CentroCosto,SubCentro
 FROM tm_BalPspto AS T INNER JOIN Puc AS P ON T.IdCuenta=P.IdCuenta
 LEFT JOIN CentroCosto AS CC ON T.IdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON T.IdSubCos=SC.IdSubCos
 LEFT JOIN Companias AS C ON T.IdCia=C.IdCia
 LEFT JOIN tm_NivCue AS NV ON T.IdCuenta=NV.tmIdCuenta
 WHERE T.tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_BalPsptoCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_BalPsptoCue] @pmtmEst CHAR(2)
 AS
 SELECT IdCuenta AS  tmIdCuenta,COUNT(IdCia) AS StotItm
 FROM tm_BalPspto
 WHERE tmEst=@pmtmEst
 GROUP BY IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CajaDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CajaDoc] @pmtmEst CHAR(2),@pmtmItem INT=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 SELECT TipDoc,TipoDoc,Numero,C.IdCia AS CdCia,Compania,Fecha,C.IdTercero AS NitTercero,T.RazonSocial AS NomCliente,C.IdAgencia AS Id_Agencia,Agencia,CodAgencia,nClieCon,Nombre
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros
,EnEfectivo,CdForma,NumForma,CdBanco,Banco,DetallePagos,CdCta,NumeroCta,FecCheque,C.Referencia AS Referencia1,Referencia2
,C.IdConcepto AS CdConcepto,Concepto,Modalidad,C.IdVend AS NitVendedor,V.RazonSocial AS Vendedor,TarifaCom,IdCajero,Usuario,UC.IdEstacion AS CdEstacion,Estacion
,C.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDpto,Departamento,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,pVehiculo,Cantidad,CantPuntos,PuntosAcum,C.Observacion AS Observ,TimeSys,tmItem
 FROM tm_Caja AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON  C.IdTercero=T.IdTercero
 INNER JOIN Terceros AS V ON  C.IdVend=V.IdTercero INNER JOIN  Agencias  AS A ON C.IdAgencia=A.IdAgencia
 INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto 
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario  INNER JOIN Sys_Estaciones AS ET ON UC.IdEstacion =ET.IdEstacion
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN ClieContado AS CC ON C.nClieCon=CC.IdCliente  LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTA ON C.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON C.CdBanco=B.IdBanco
 WHERE tmEst=@pmtmEst  AND TipDoc LIKE ISNULL(@pmTipDoc ,'%') 
  AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem,TipDoc,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CajaFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CajaFor] @pmtmEst CHAR(2),@pmtmItem INT=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 SELECT C.TipDoc AS IdTipDoc,TipoDoc,Numero,C.IdCia AS CdCia,Compania,C.Fecha AS FechaDoc,P.IdForma AS CdForma,Detalle
 ,CASE  WHEN C.TipDoc IN ('NDB','NCR','DEG') OR P.IdForma IS NULL THEN VrEfectivo ELSE VrPagado  END AS ValPagado,VrCambio
,CASE  WHEN C.TipDoc IN ('NDB','NCR','DEG') OR P.IdForma IS NULL THEN EnEfectivo ELSE  EsCaja END AS EsCaja,FormaPago
,P.NumForma AS NumeroForma,FecForma,P.IdBanco AS CodBanco,BF.Banco AS NomBanco,C.IdTercero AS NitTercero,T.RazonSocial AS NomCliente
,C.IdAgencia AS Id_Agencia,A.Agencia AS NomAgencia,A.CodAgencia AS CodAgenc,nClieCon,Nombre
,C.IdVend AS NitVendedor,V.RazonSocial AS Vendedor,TarifaCom,IdCajero,Usuario,UC.IdEstacion AS CdEstacion,Estacion
,CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,LF.Localidad AS CiudadPlaza,NumAutoriza,VrDenom,P.Cantidad AS CantDenom,TipDenom
,P.TipRef AS PagTipRef,P.DocRef AS PagDocRef,P.IdCiaRef AS PagIdCiaRef,P.NitCliente AS PagNitCliente,TP.RazonSocial AS PagNomCliente
,CdAgencia,AP.Agencia AS PagAgencia,AP.CodAgencia AS PagCodAgenc,EnEfectivo,CdForma,C.NumForma AS NumCheque,CdBanco,B.Banco AS DocBanco
,DetallePagos,C.CdCta AS DocCodCta,NumeroCta,FecCheque,C.Referencia AS Referencia1,Referencia2,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion
,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrNeto,VrEfectivo,VrPagosOtr,VrCreditos,VrGastComb,VrGastOtros
,C.IdConcepto AS CdConcepto,Concepto,Modalidad,C.IdLocal AS CdLocal,L.Localidad AS DocNomCiudad,L.IdDep AS DocCdDpto,Departamento
,C.TipRef AS DocTipRef,C.DocRef AS DocNumDocRef,C.IdCiaRef AS DocIdCiaRef
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,pVehiculo,C.Cantidad AS DocCantidad,CantPuntos,PuntosAcum,C.Observacion AS Observ,TimeSys,tmItem
 FROM tm_Caja AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON  C.IdTercero=T.IdTercero
 INNER JOIN Terceros AS V ON  C.IdVend=V.IdTercero INNER JOIN  Agencias  AS A ON C.IdAgencia=A.IdAgencia
 INNER JOIN  Conceptos AS CN ON C.IdConcepto=CN.IdConcepto 
 INNER JOIN adm_Usuarios AS UC ON C.IdCajero=UC.IdUsuario  INNER JOIN Sys_Estaciones AS ET ON UC.IdEstacion =ET.IdEstacion
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 LEFT JOIN ClieContado AS CC ON C.nClieCon=CC.IdCliente  LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTA ON C.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON C.CdBanco=B.IdBanco
 LEFT JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND C.Numero=P.Documento AND C.IdCia=P.IdCia
 LEFT JOIN Formaspago AS FP ON P.IdForma=FP.IdForma  LEFT JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 LEFT JOIN Terceros AS TP ON P.NitCliente=TP.IdTercero  LEFT JOIN Agencias  AS AP ON P.CdAgencia=AP.IdAgencia
 LEFT JOIN Localidades AS LF ON P.CdLocal=LF.IdLocal 
 WHERE tmEst=@pmtmEst  AND C.TipDoc LIKE ISNULL(@pmTipDoc ,'%') 
  AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem,C.TipDoc,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CajaTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CajaTot] @pmtmEst CHAR(2)
 AS 
 SELECT tmConcepto,tmValorTotal,tmValorOtros,tmTipo,tmItem
 FROM tm_CajaTot
 WHERE tmEst=@pmtmEst 
 ORDER BY tmTipo,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cargos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Cargos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdCliente,tmIdCargo,tmConcepto,tmReferencia
,tmFactura,tmValor,tmDetalle,tmFecVence,tmTipDoc,tmDocumento,tmIdCiaDoc,tmConductor,tmAbonado,tmTipDocAnt,tmDocAnticipo
,tmCiaDocAnt,tmPrestamoID,tmIdCiaPre,tmNumCuota,tmFecCausa,tmValorCapital,tmValorInteres,tmIdCuenta,tmCombCant,tmCombValor
,tmBaseImpu,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrRetIca,tmCodTarifIva,tmCodTarifRet,tmCodTarifIca
 FROM tm_Cargos
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cargos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Cargos_Cr] @pmtmNumero VARCHAR(5)
 AS
  SELECT  tmItem, tmIdCargo, tmConcepto, tmValor,tmDetalle,tmFactura,tmReferencia, tmIdVehiculo,tmVehPropio,tmIdConductor,C.RazonSocial AS Conductor
, tmIdCliente,T.RazonSocial AS Propietario,tmNumero, tmFecVence, tmTipDoc, tmDocumento, tmIdCiaDoc, tmConductor,tmAbonado,tmTipDocAnt,tmDocAnticipo,tmCiaDocAnt
 ,tmPrestamoID, tmIdCiaPre, tmNumCuota, tmFecCausa, tmValorCapital, tmValorInteres,tmIdCuenta,tmCombCant,tmCombValor
,tmBaseImpu,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrRetIca,tmCodTarifIva,tmCodTarifRet,tmCodTarifIca
 FROM tm_Cargos INNER JOIN Terceros AS T ON tm_Cargos.tmIdCliente=T.IdTercero INNER JOIN Terceros AS C ON tm_Cargos.tmIdConductor=C.IdTercero
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CargosCmp] @pmtmNumero VARCHAR(5)
 AS
   SELECT tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor, tmIdCuenta
,SUM(tmValor) AS SValFac,SUM(tmCombValor) AS TotalBase
  FROM    tm_Cargos  WHERE tmNumero=@pmtmNumero  
 GROUP BY tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosCmpp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CargosCmpp] @pmtmNumero VARCHAR(5)
 AS
 SELECT tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdCuenta,SUM(tmValor) AS SValFac,SUM(tmValorCapital) AS SValCap
,SUM(tmValorInteres) AS SValInt,SUM(tmValorCapital+tmValorInteres) AS STotCuo
 FROM    tm_Cargos  WHERE tmNumero=@pmtmNumero  
 GROUP BY tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CargosGru] @pmtmNumero VARCHAR(5)
 AS
   SELECT tmIdCliente,tmIdVehiculo,SUM( tmValor ) AS STotFac
   FROM    tm_Cargos  WHERE tmNumero=@pmtmNumero  
  GROUP BY tmIdCliente,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CargosPre] @pmtmNumero VARCHAR(5)
AS
 SELECT  tmItem,tmValor,tmDetalle,tmFactura,tmReferencia, tmIdVehiculo,tmVehPropio,tmIdConductor, tmIdCliente,tmNumero
, tmFecVence,tmPrestamoID, tmIdCiaPre, tmNumCuota, tmFecCausa, tmValorCapital, tmValorInteres
 FROM tm_Cargos  WHERE tmNumero=@pmtmNumero 
 ORDER BY tmIdCiaPre,tmPrestamoID,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosVce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CargosVce] @pmtmNumero VARCHAR(5)
AS
   SELECT  tmItem,tmFecVence, tmValor,tmIdVehiculo,tmDetalle,tmIdCuenta,tmFactura,tmReferencia
,tmVehPropio,tmIdConductor,tmConductor,tmIdCliente
  FROM    tm_Cargos 
  WHERE tmNumero=@pmtmNumero
  ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CargosVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CargosVeh] @pmtmNumero VARCHAR(5),@pmtmIdVehiculo VARCHAR(10)
AS
  SELECT  tmItem, tmIdCargo, tmConcepto, tmValor,tmDetalle,tmFactura,tmReferencia, tmIdVehiculo,tmVehPropio,tmIdConductor, tmIdCliente,tmNumero
  ,  tmFecVence, tmTipDoc, tmDocumento, tmIdCiaDoc, tmConductor,tmAbonado,tmTipDocAnt,tmDocAnticipo,tmCiaDocAnt
,tmPrestamoID, tmIdCiaPre, tmNumCuota, tmFecCausa, tmValorCapital, tmValorInteres
   FROM  tm_Cargos  WHERE tmNumero=@pmtmNumero  AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
   ORDER BY tmIdVehiculo,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cartera]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Cartera] @pmtmEst CHAR(2),@pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME
 AS 
 SELECT  IdCliente,T.RazonSocial AS NomCliente,V.IdAgencia AS CdAgencia,Agencia,TipDoc,TipoDoc,Factura,V.IdCia AS CdCia,Compania,Item
,VrFactura,VrAbonado,CASE TipDoc WHEN 'SAF' THEN V.VrSaldo*-1  ELSE  V.VrSaldo END AS ValorSaldo,Fecha,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
,V.IdConcepto AS CdConcepto,Concepto,V.Referencia AS FacReferencia,Detalle,V.IdVend AS CdVend,VN.RazonSocial AS Vendedor,V.Comision AS TarifComs
,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,CLI.VrSaldo AS SaldoClie,Contrato,CLI.NContrato AS CliNumContrato
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont,CLI.IdVend AS VendedorPre,VNC.RazonSocial AS NomVendedorPre
,PZ.DiasPago AS DiasPlazoAge,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco
-- PZC.DiasPago AS DiasPlazoAgeCom
 FROM tm_Cartera AS V INNER JOIN  Companias AS CI ON V.IdCia=CI.IdCia
 INNER JOIN  Terceros AS T ON V.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliente AS CLI ON V.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia  
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Plazos AS PZ ON A.IdPlazo=PZ.IdPlazo   INNER JOIN Terceros AS VNC ON CLI.IdVend=VNC.IdTercero
 LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto  LEFT JOIN Sys_TiposDoc AS TD ON V.TipDoc=TD.IdDoc
 -- LEFT JOIN Plazos AS PZC ON A.CdPlazoComb=PZC.IdPlazo
 WHERE tmEst=@pmtmEst AND V.VrSaldo>@pmSaldo
 ORDER BY T.RazonSocial,FechaVence
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ccCupones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ccCupones] @pmtmEst CHAR(2) 
 AS 
 SELECT tmItem,tmTipoReg,tmTipDoc,tmDocumento,tmIdCia,Compania,tmItemDoc,tmFecEmision,tmFecVence,tmValorFactura,tmValorAbono
,tmIdPropietario,T.RazonSocial AS Propietario,tmIdVehiculo,NumVeh,tmIdConductor,CD.RazonSocial AS Conductor,tmIdCargo,Concepto,NCuotas,TipoDcto,DctoPpago
,tmIdClase,ClaseCuenta,tmFactura,tmReferencia,tmDetalle,tmDescuento,tmNCuota
--datos del tercero
,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercIdCiu,Localidad,T.Telefono AS TercTel,T.Fax AS TercFax,T.TelMovil AS TercMovil,T.e_mail AS TercEmail
 FROM tm_ccCupones AS C INNER JOIN  Companias  AS CI ON C.tmIdCia=CI.IdCia
 INNER JOIN  Terceros AS T ON C.tmIdPropietario=T.IdTercero 
 INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal
 INNER JOIN Vehiculos AS V ON C.tmIdVehiculo=V.IdVehiculo
 INNER JOIN   Terceros AS CD  ON C.tmIdConductor=CD.IdTercero
 LEFT JOIN   Fijos AS  F ON C.tmIdCargo=F.IdCargo  LEFT JOIN  BusClaseCue AS B ON C.tmIdClase=B.IdClase
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_cheq] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmTipForma,tmNumForma,tmIdBanco,tmFecha,tmFecPago,tmVrForma,tmCtaForma,tmBeneficiario,tmReferncia1,tmReferncia2
,tmDetalle,tmNitCliente,tmCdAgencia,tmCdVend,tmIdLocal,tmCdCta
 FROM tm_cheq
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_cheqDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmTipForma,tmNumForma,tmIdBanco,Banco,tmVrForma,tmDetalle,tmFecha,tmFecPago,tmCtaForma
,tmBeneficiario,tmReferncia1,tmReferncia2,tmIdLocal,Localidad,tmCdCta
,tmNitCliente,tmCdAgencia,tmCdVend,tmNumero
 FROM tm_cheq AS C INNER JOIN Bancos AS B ON C.tmIdBanco=B.IdBanco
 LEFT JOIN Localidades AS L ON C.tmIdLocal=L.IdLocal
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_cheqItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_cheq
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_cheqNum] @pmtmNumero VARCHAR(5),@pmtmTipForma VARCHAR(3),@pmtmNumForma VARCHAR(20)
,@pmtmIdBanco VARCHAR(4),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmTipForma,tmNumForma,tmIdBanco,tmVrForma
 FROM tm_cheq
 WHERE tmNumero=@pmtmNumero AND tmTipForma=@pmtmTipForma AND tmNumForma=@pmtmNumForma
 AND tmIdBanco=@pmtmIdBanco AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_cheqTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_cheqTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS STOTCAN,SUM(tmVrForma) AS STOTCHE
 FROM tm_cheq
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Combo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Combo] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdProdBase,tmCantidad,tmVrUnitario,tmIdBodega,tmCdTanque
,tmIdUnd,tmFactor,tmUndFac,tmServcios,tmLinea
 FROM tm_Combo
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ComboItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT  MAX(tmItem) AS  MXITM
 FROM tm_Combo
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboLin]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ComboLin] @pmtmNumero VARCHAR(5),@pmtmLinea INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdProdBase,tmCantidad,tmVrUnitario,tmIdBodega,tmCdTanque
,tmIdUnd,tmFactor,tmUndFac,tmServcios,tmLinea
,DescripProd,TipoRef,IdSubgrupo,IdUnd,IdBodega,IdUbic,VrCostPmd,Seriales,Lotes,Combo,Tanques
,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM  tm_Combo AS C INNER JOIN ProdMcias AS P ON C.tmIdProdBase=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmLinea=@pmtmLinea
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ComboPla] @pmtmNumero VARCHAR(5),@pmtmReferencia2 VARCHAR(50)
 AS 
 SELECT COUNT(C.tmItem) AS SCANT,SUM(C.tmCantidad) AS STOTCAN,SUM(C.tmVrUnitario*C.tmCantidad) AS STOTCOS
 FROM tm_Combo AS C  INNER JOIN tm_Kdex AS  K ON C.tmNumero=K.tmNumero AND C.tmLinea=K.tmItem
 WHERE C.tmNumero=@pmtmNumero AND tmEsCombo<>0 AND tmReferencia2=@pmtmReferencia2
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComboTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ComboTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(C.tmItem) AS SCANT,SUM(C.tmCantidad) AS STOTCAN,SUM(C.tmVrUnitario*C.tmCantidad) AS STOTCOS
 FROM tm_Combo AS C  INNER JOIN tm_Kdex AS  K ON C.tmNumero=K.tmNumero AND C.tmLinea=K.tmItem
 WHERE C.tmNumero=@pmtmNumero AND tmEsCombo<>0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Comisiones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Comisiones] @pmtmEst CHAR(2)
 AS 
 SELECT  TipDoc,TipoDoc,Numero,C.IdCia AS CdCia,Compania,Item,Fecha,FecVence,C.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,C.IdTercero AS NitCliente,T.RazonSocial AS NomCliente
,C.IdAgencia AS CdAgencia,Agencia,CodAgencia,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,C.IdConcepto AS CdConcepto,Concepto,Cantidad,nClieCon,Nombre
,IdCajero,Usuario,C.IdLocal AS CdLocalidad,Localidad,L.IdDep AS CodDep,Departamento
,CdSzona,Subzona,SZ.IdZona AS CdZona,Zona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,C.Observacion AS Observ,Detalles,C.Referencia AS Referncia
--datos del vendedor
,VN.Codigo AS VendCodigo,VN.TipoId AS VendTipoId,VN.Dv AS VendDv,VN.IdProf AS VendIdProf,Profesion,CdJorn,TV.IdGrupo AS VendIdGrupo,GV.GrupoClie AS GrupoVend
--datos del cliente
,T.Codigo AS CliCodigo,T.TipoId AS CliTipoId,T.Dv AS CliDV,T.IdSector AS CdSector,SectorEco,CLI.IdGrupo AS CdGrupoCli,GC.GrupoClie AS Grupo_Clie
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera
 FROM tm_Comisiones  AS C INNER JOIN  Companias AS CI ON  C.IdCia=CI.IdCia  INNER JOIN Terceros AS VN ON C.IdVend=VN.IdTercero 
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero  INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  adm_Usuarios AS U ON C.IdCajero=U.IdUsuario INNER JOIN Profesiones AS PF ON VN.IdProf=PF.IdProf
 LEFT JOIN  Agencias  AS A ON C.IdAgencia=A.IdAgencia
 LEFT JOIN TercVendedor AS TV ON C.IdVend=TV.IdVend LEFT JOIN GruposCli AS GV ON TV.IdGrupo=GV.IdGrupo
 LEFT JOIN Jornadas AS J ON TV.CdJorn=J.IdJornada
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc  LEFT JOIN  Conceptos AS CO ON C.IdConcepto=CO.IdConcepto
 LEFT JOIN TercCliente AS CLI ON C.IdTercero=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Subzonas AS SZ ON C.CdSzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Localidades AS L ON C.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera  LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera
 LEFT JOIN ClieContado AS CC ON C.nClieCon=CC.IdCliente 
 WHERE tmEst=@pmtmEst 
 ORDER BY VN.RazonSocial,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ComisionesDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ComisionesDet] @pmtmEst CHAR(2)
 AS 
 SELECT  TipDoc,TipoDoc,Numero,C.IdCia AS CdCia,Compania,Item,Fecha,FecVence,C.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,C.IdTercero AS NitCliente,T.RazonSocial AS NomCliente
,C.IdAgencia AS CdAgencia,Agencia,CodAgencia,CdProducto,DescripProd,Cantidad,CdOperario,VO.RazonSocial AS NomOperario,ComisnOper
,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrOtros,VCargos,VrOtrosDctos,C.IdConcepto AS CdConcepto,Concepto,nClieCon,Nombre
,IdCajero,Usuario,C.IdLocal AS CdLocalidad,Localidad,L.IdDep AS CodDep,Departamento
,CdSzona,Subzona,SZ.IdZona AS CdZona,Zona,Modalidad,TipRef,DocRef,IdCiaRef,Anulado,C.Observacion AS Observ,Detalles,C.Referencia AS Referncia
--datos del vendedor
,VN.Codigo AS VendCodigo,VN.TipoId AS VendTipoId,VN.Dv AS VendDv,VN.IdProf AS VendIdProf,Profesion,CdJorn,TV.IdGrupo AS VendIdGrupo,GV.GrupoClie AS GrupoVend
--datos del cliente
,T.Codigo AS CliCodigo,T.TipoId AS CliTipoId,T.Dv AS CliDV,T.IdSector AS CdSector,SectorEco,CLI.IdGrupo AS CdGrupoCli,GC.GrupoClie AS Grupo_Clie
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera
--datos del producto
,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca
,PM.Referencia AS Prod_Referencia,PM.IdUnd AS CdUnid,UM.Unidad AS UnidMed,Tanques,DescripLong,DescripAbrv,Precio1,Precio2,Precio3,Precio4,Precio5
 FROM tm_Comisiones  AS C INNER JOIN  Companias AS CI ON  C.IdCia=CI.IdCia  INNER JOIN Terceros AS VN ON C.IdVend=VN.IdTercero 
 INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero  INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN  adm_Usuarios AS U ON C.IdCajero=U.IdUsuario INNER JOIN Profesiones AS PF ON VN.IdProf=PF.IdProf
 LEFT JOIN  Agencias  AS A ON C.IdAgencia=A.IdAgencia
 LEFT JOIN TercVendedor AS TV ON C.IdVend=TV.IdVend LEFT JOIN GruposCli AS GV ON TV.IdGrupo=GV.IdGrupo
 LEFT JOIN Jornadas AS J ON TV.CdJorn=J.IdJornada
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc  LEFT JOIN  Conceptos AS CO ON C.IdConcepto=CO.IdConcepto
 LEFT JOIN TercCliente AS CLI ON C.IdTercero=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Subzonas AS SZ ON C.CdSzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Localidades AS L ON C.IdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera  LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera
 LEFT JOIN ClieContado AS CC ON C.nClieCon=CC.IdCliente 
 LEFT JOIN Terceros AS VO ON C.CdOperario=VO.IdTercero
 LEFT JOIN ProdMcias  AS PM ON C.CdProducto=PM.IdProducto LEFT JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 LEFT JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo  LEFT JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 LEFT JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea  LEFT JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 WHERE tmEst=@pmtmEst 
 ORDER BY VN.RazonSocial,TipDoc,Numero,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Comp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Comp] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura
,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante
,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Compau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Compau] @pmtmNumero VARCHAR(5),@pmtmTipCom VARCHAR(3),@pmtmComprobante INT,@pmtmIdCia CHAR(2)
 AS 
 SELECT tmNumero,tmTipCom,tmComprobante,tmIdCia,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos
,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque
,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmNombre,tmCcosto
,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut
 FROM tm_Compau
 WHERE tmNumero=@pmtmNumero AND tmTipCom=@pmtmTipCom AND tmComprobante=@pmtmComprobante AND tmIdCia=@pmtmIdCia
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompCue] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdCuenta,SUM(tmVrDebito) AS STOTDEB,SUM(tmVrCredito) AS STOTCRE
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompDsc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompDsc] @pmtmNumero VARCHAR(5) 
 AS  
 SELECT tmItem,tmCodCargo,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmTercero,tmCodAgncia,tmVrBase,tmTarifaBase
,tmIdCCosto,tmCcosto,tmIdSubCos,tmSubcc,tmIdVehiculo,tmTipoAplica,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
,tmCodCta,tmNumCheque,tmReferncia,tmConsolida,tmTipDocRef,tmDocRef,tmIdCiaRef,tmConcTrib,tmTarifTrib
,tmNombre,tmNitOtros,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompDso] @pmtmNumero VARCHAR(5) 
 AS 
 SELECT tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmTercero,tmCodAgncia,tmVrBase,tmTarifaBase
,tmIdCCosto,tmCcosto,tmIdSubCos,tmSubcc,tmIdVehiculo,tmTipoAplica,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmNitDoc,tmCodCta,tmNumCheque,tmReferncia,tmTipDocRef,tmDocRef,tmIdCiaRef
,tmNombre,tmNitOtros,tmVehPropio,tmCodSubgpo,tmCiuOrigen,tmConcTrib,tmTarifTrib,tmEstablec,tmPtoEmision,tmAutoriza,tmFechAut,tmCuentaNiif
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompFac] @pmtmNumero VARCHAR(5), @pmtmIdTercero VARCHAR(16),@pmtmTipFac VARCHAR(3)
,@pmtmFactura  VARCHAR(15),@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmItem INT
AS
 SELECT tmNumero,tmItem,tmIdCuenta,tmIdTercero,tmVrDebito,tmVrCredito,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
,tmTipoAplica
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero AND tmTipoAplica IN ('C','A')  AND  tmIdTercero=@pmtmIdTercero AND tmTipFac=@pmtmTipFac 
 AND tmFactura=@pmtmFactura AND tmIdCiaFac=@pmtmIdCiaFac AND tmItemFac=@pmtmItemFac
 AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompID] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITEM
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CompItm] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT COUNT(tmItem) AS SCANT
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CompLta] @pmtmNumero VARCHAR(5) 
 AS 
 SELECT tmItem,tmIdCuenta,NomCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmTercero,tmVrBase,tmTarifaBase
,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdVehiculo,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmReferncia,tmNitOtros,RazonSocial,tmCuentaNiif
 FROM tm_Comp AS D LEFT JOIN Puc AS P ON D.tmIdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS T ON D.tmNitOtros=T.IdTercero
 LEFT JOIN CentroCosto AS O ON D.tmIdCCosto=O.IdCCosto LEFT JOIN SubCentros AS SC ON D.tmIdSubCos=SC.IdSubCos
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompTot] @pmtmNumero VARCHAR(5)
 AS
    SELECT SUM(tmVrDebito) AS STotDeb, SUM(tmVrCredito) AS STotCre,SUM(tmVrBase) AS STotBas  
    FROM  tm_Comp 
    WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompVce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompVce] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdCuenta,tmIdTercero,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmTipoAplica
,SUM(tmVrDebito) AS STotDeb,SUM(tmVrCredito) AS STotCre 
 FROM tm_Comp
 WHERE tmNumero=@pmtmNumero  AND tmTipoAplica  IN ('C','A')
 GROUP BY  tmIdCuenta,tmIdTercero,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmTipoAplica
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CompVen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CompVen] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdCuenta,tmDetalle,tmVrDebito,tmVrCredito,tmIdTercero,tmIdVehiculo,tmIdCCosto,tmIdSubCos,tmVrBase,tmTarifaBase,tmTipDoc,tmDocumento,tmIdCiaDoc,tmCodConce,tmTipFac,tmFactura
,tmIdCiaFac,tmItemFac,tmFecVence,tmCodCta,tmNumCheque,tmIntegrado,tmTipoAplica,tmConsolida,tmCodCargo,tmNitOtros,tmCodSubgpo,tmCiuOrigen,tmCodAgncia,tmVehPropio,tmReferncia,tmTipCom,tmComprobante
,tmIdCia,tmNombre,tmCcosto,tmSubcc,tmTercero,tmTipDocRef,tmDocRef,tmIdCiaRef,tmNitDoc
 FROM  tm_Comp AS T INNER JOIN puc AS C ON T.tmIdCuenta=C.IdCuenta
 WHERE tmNumero=@pmtmNumero   AND tmTipoAplica IN ('A','C')  AND Vencimiento<>0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Contratos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Contratos] @pmtmEst CHAR(2)
 AS 
 SELECT tmContrato,tmIdCia,Compania,IdCliente,T.RazonSocial AS NomCliente,C.IdAgencia AS CdAgencia,Agencia,tmPeriodo,tmTipoProd
,tmCdProducto,DescripProd,tmPresptoAnno,tmPresptoMes,tmCantNeto,tmValorNeto
,Fecha,C.IdTipo AS CdTipo,TipContrato,C.IdBonif AS CdBonif,TipoBonif,ConvBonif,ModPlazo,Plazo,FechaVence,VrCuota,C.IdBandera AS CdBandera,TipoBandera
,C.IdVend AS CdVend,V.RazonSocial AS Vendedor
--datos del cliente
,T.IdLocal AS TercCodCiudad,L.Localidad AS NomCiudad,L.IdDep AS CodDpto,D.Departamento AS TercDpto,T.IdSector AS CdSector,SectorEco
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM tm_Contratos AS TC  INNER JOIN Trn_MayContratos AS C ON TC.tmContrato=C.NContrato AND TC.tmIdCia=C.IdCia
 INNER JOIN Companias AS CN ON TC.tmIdCia=CN.IdCia
 INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero INNER JOIN MayTipos AS TCO ON C.IdTipo=TCO.IdTipo
 INNER JOIN MayTiposBonif AS B ON C.IdBonif=B.IdBonif INNER JOIN  TiposBan AS TB ON C.IdBandera=TB.IdBandera
 INNER JOIN Terceros AS V ON C.IdVend=V.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN TercCliente AS CLI ON C.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Agencias   AS A ON C.IdAgencia=A.IdAgencia LEFT JOIN ProdMcias AS PM ON TC.tmCdProducto=PM.IdProducto
 WHERE tmEst=@pmtmEst
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Cuotas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Cuotas] @pmtmEst CHAR(2),@pmtmPrestamoID INT=Null,@pmtmIdCia CHAR(2)=Null,@pmtmNumCuota INT=Null
AS
 SELECT tmNumCuota,tmFecCausa,tmFecVence,tmSaldo,tmValorInteres,tmValorCapital,tmValorCuota,tmValorCausado,tmValorAbonado
,tmValorCausado-tmValorAbonado AS SaldoAPagar,tmFecPago,tmTipRec,tmRecibo, tmIdCiaRec,tmPrestamoID,tmIdCia
 FROM    tm_Cuotas
 WHERE tmEst=@pmtmEst
 AND (tmPrestamoID>=ISNULL(@pmtmPrestamoID,0)  AND tmPrestamoID<=ISNULL(@pmtmPrestamoID,2147483647))
 AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 AND (tmNumCuota>=ISNULL(@pmtmNumCuota,0)  AND tmNumCuota<=ISNULL(@pmtmNumCuota,2147483647))
 ORDER BY tmNumCuota
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CuotasCr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CuotasCr] @pmtmEst CHAR(2)
AS
 SELECT tmPrestamoID,tmIdCia,tmNumCuota,tmFecCausa,tmFecVence,tmValorCapital,tmValorInteres,tmValorCuota,tmSaldo
,tmValorCausado AS VrPrestamo,tmFecPago,tmRecibo AS NPlazos
 FROM    tm_Cuotas
 WHERE tmEst=@pmtmEst
 ORDER BY tmPrestamoID,tmNumCuota
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmVrDescto,tmVrBaseCms,tmIdCliente
,tmIdAgencia,tmIdVend,tmComision,tmDetalle,tmTipoAplica,tmCodTarDct,tmCodTarCom,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonosDoc] @pmtmNumero VARCHAR(5),@pmtmTipDoc VARCHAR(3),@pmtmFactura INT
,@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT
 AS 
 SELECT tmNumero,tmItem,tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero AND tmTipDoc=@pmtmTipDoc  AND tmFactura=@pmtmFactura
 AND tmIdCiaFac=@pmtmIdCiaFac AND tmItemFac=@pmtmItemFac
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonosDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmVrDescto,tmDetalle
,tmIdVend,tmComision,tmTipoAplica,tmVrBaseCms,tmCodTarDct,tmCodTarCom
,tmIdCliente,tmIdAgencia,tmNumero
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosG]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonosG] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac,SUM(tmVrAbono) AS STotAbo,SUM(tmVrDescto) AS STotDct
,SUM(tmVrBaseCms) AS STotBase
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero 
 GROUP BY  tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonosItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosTip]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonosTip] @pmtmNumero VARCHAR(5),@pmtmTipoAplica VARCHAR(10)
 AS 
 SELECT tmNumero,tmItem,tmTipDoc,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmVrDescto,tmVrBaseCms,tmIdCliente
,tmIdAgencia,tmIdVend,tmComision,tmDetalle,tmTipoAplica,tmCodTarDct,tmCodTarCom
,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero  AND tmTipoAplica LIKE ISNULL(@pmtmTipoAplica,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxcAbonosTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxcAbonosTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCAN,SUM(tmVrAbono) AS STotAbo,SUM(tmVrDescto) AS STotDct,SUM(tmVrBaseCms) AS STotCom
 FROM tm_CxcAbonos
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxCobrar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxCobrar] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmItem,tmFecVence,tmVrFactura,tmDetalle,tmReferencia,tmTarifDcto,tmTipoDcto
,tmTipoBase,tmFecLmtDcto,tmTipRef,tmDocRef,tmIdCiaRef,tmNumero,tmTotAbono,tmFecPlazo
 FROM tm_CxCobrar
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxCobrarId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxCobrarId] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_CxCobrar
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxCobrarTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxCobrarTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrFactura) AS SVALTOT,SUM(tmTotAbono) AS STotAbono
 FROM tm_CxCobrar
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxPagar] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProveedor,tmFecVence,tmIdCuenta,tmTipDoc,tmDocumento,tmIdCiaDoc,tmVrFactura,tmItemCom,tmReferencia
,tmDetalle,tmpVehiculo,tmVehPropio,tmTipRef,tmDocRef,tmIdCiaRef,tmProveedor
 FROM tm_CxPagar
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxPagarDso] @pmtmNumero VARCHAR(5),@pmtmIdProveedor VARCHAR(16)=Null
 AS 
 SELECT tmItem,tmFecVence,tmVrFactura,tmDetalle,tmReferencia,tmIdCuenta,tmTipDoc,tmDocumento,tmIdCiaDoc
,tmIdProveedor,tmProveedor,tmpVehiculo,tmTipRef,tmDocRef,tmIdCiaRef,tmItemCom,tmNumero
 FROM tm_CxPagar
 WHERE tmNumero=@pmtmNumero  AND tmIdProveedor LIKE ISNULL(@pmtmIdProveedor,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpagarGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxpagarGru] @pmtmNumero VARCHAR(5),@pmGruVeh BIT
AS
 IF @pmGruVeh<>0  --AGRUPADO POR VEHICULO
  SELECT  tmNumero,tmIdProveedor, tmFecVence,tmpVehiculo,tmVehPropio,SUM(tmVrFactura) AS STotVal 
  FROM     tm_Cxpagar WHERE tmNumero=@pmtmNumero
 GROUP BY    tmNumero,tmIdProveedor, tmFecVence,tmpVehiculo,tmVehPropio 
ELSE
  SELECT  tmNumero,tmIdProveedor,tmFecVence,SUM(tmVrFactura) AS STotVal 
  FROM     tm_Cxpagar WHERE tmNumero=@pmtmNumero
 GROUP BY    tmNumero,tmIdProveedor, tmFecVence
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxPagarID] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem)  AS MXITM
 FROM tm_CxPagar
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxPagarNit] @pmtmNumero VARCHAR(5),@pmtmIdProveedor VARCHAR(16)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdProveedor,tmFecVence,tmIdCuenta,tmTipDoc,tmDocumento,tmIdCiaDoc,tmVrFactura,tmItemCom,tmReferencia
,tmDetalle,tmpVehiculo,tmVehPropio,tmTipRef,tmDocRef,tmIdCiaRef,tmProveedor
 FROM tm_CxPagar
 WHERE tmNumero=@pmtmNumero AND tmIdProveedor LIKE ISNULL(@pmtmIdProveedor,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxPagarTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxPagarTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT Count(tmItem) AS SCANT,SUM(tmVrFactura) AS SVALTOT
 FROM tm_CxPagar
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplica]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxpAplica] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmItem,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmDetAbono,tmIdProveedor,tmProveedor,tmIdCuenta
,tmTipDev,tmNumDev,tmpVehiculo,tmVehPropio,tmNumero
 FROM tm_CxpAplica
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxpAplicaFac] @pmtmNumero VARCHAR(5),@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15)
,@pmtmIdCiaFac CHAR(2),@pmtmItemFac INT,@pmtmIdProveedor VARCHAR(16)
 AS 
 SELECT tmNumero,tmItem,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmVrAbono,tmIdProveedor
 FROM tm_CxpAplica
 WHERE tmNumero=@pmtmNumero AND tmTipFac=@pmtmTipFac  AND tmFactura=@pmtmFactura
 AND tmIdCiaFac=@pmtmIdCiaFac  AND tmItemFac=@pmtmItemFac  AND  tmIdProveedor=@pmtmIdProveedor
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaG]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_CxpAplicaG] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmIdProveedor,SUM(tmVrAbono) AS STOTABO
 FROM tm_CxpAplica
 WHERE tmNumero=@pmtmNumero
 GROUP BY tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxpAplicaID] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_CxpAplica
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_CxpAplicaTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_CxpAplicaTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrAbono) AS STOTABO
 FROM tm_CxpAplica
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_DetCue] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmConcepto VARCHAR(10)=Null
 AS 
 SELECT tmNumero,tmItem,tmConcepto,tmIdCuenta,tmValor,tmDetalle,tmIdTercero,tmCodAgncia,tmCdCCosto,tmCdSubCos
,tmpVehiculo,tmVrBase,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCheque,tmCiuOrigen,tmReferencia
,tmTarifa,tmTipoTarif,tmCodConc,tmCodTarif
 FROM tm_DetCue
 WHERE tmNumero=@pmtmNumero AND tmConcepto LIKE ISNULL(@pmtmConcepto,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_DetCueDso] @pmtmNumero VARCHAR(5),@pmtmConcepto VARCHAR(10)=Null
 AS 
 SELECT tmConcepto,tmItem,tmIdCuenta,tmValor,tmDetalle,tmVrBase,tmIdTercero,RazonSocial,tmCodAgncia
,tmCdCCosto,CCosto,tmCdSubCos,tmpVehiculo,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCheque
,tmReferencia,tmCodConc,tmCiuOrigen,Localidad,tmCodTarif
 FROM tm_DetCue AS D LEFT JOIN Terceros AS T ON D.tmIdTercero=T.IdTercero
 LEFT JOIN CentroCosto AS CC ON D.tmCdCCosto=CC.IdCCosto
 LEFT JOIN Localidades AS L ON D.tmCiuOrigen=L.IdLocal
 WHERE tmNumero=@pmtmNumero AND tmConcepto LIKE ISNULL(@pmtmConcepto,'%')
 ORDER BY tmConcepto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_DetCueFac] @pmtmNumero VARCHAR(5),@pmtmConcepto VARCHAR(10)
,@pmtmIdTercero VARCHAR(16),@pmtmTipFac VARCHAR(3),@pmtmFactura VARCHAR(15),@pmtmIdCiaFac CHAR(2)
,@pmtmItemFac INT,@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmConcepto,tmIdCuenta,tmValor,tmDetalle,tmIdTercero
,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
 FROM tm_DetCue AS D INNER JOIN Puc AS P ON D.tmIdCuenta=P.IdCuenta
 WHERE tmNumero=@pmtmNumero AND Vencimiento<>0 AND tmIdTercero=@pmtmIdTercero
 AND tmTipFac=@pmtmTipFac AND tmFactura=@pmtmFactura AND tmIdCiaFac=@pmtmIdCiaFac
 AND tmItemFac=@pmtmItemFac AND tmItem<>@pmtmItem
 AND  tmConcepto LIKE ISNULL(@pmtmConcepto,'%')
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_DetCueItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM FROM tm_DetCue
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_DetCueTot] @pmtmNumero VARCHAR(5),@pmtmConcepto VARCHAR(10)=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmValor) AS SVALTOT,SUM(tmVrBase) AS SBASE
 FROM tm_DetCue
 WHERE tmNumero=@pmtmNumero AND tmConcepto LIKE ISNULL(@pmtmConcepto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DetCueVce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_DetCueVce] @pmtmNumero VARCHAR(5),@pmtmConcepto VARCHAR(10)=Null
 AS 
 SELECT tmNumero,tmItem,tmConcepto,tmIdCuenta,tmValor,tmIdTercero,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence
,Naturaleza,Vencimiento
 FROM tm_DetCue AS D INNER JOIN Puc AS P ON D.tmIdCuenta=P.IdCuenta
 WHERE tmNumero=@pmtmNumero AND Vencimiento<>0 AND tmConcepto LIKE ISNULL(@pmtmConcepto,'%')
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Diario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Diario] @pmtmEst CHAR(2)
 AS 
 SELECT TipDoc,TipoDoc,Numero,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,D.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,D.IdAgencia AS Id_Agencia,Agencia
,VrSubTotal,VrDescuento,VrImpuesto,VrSobretasa,VrRetencion,VrReteIca,VrReteIva,VrOtros,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrImpConsumo,VrNeto
,VrEfectivo,VrPagosOtr,VrCreditos,VrValesGastos,CantPuntos,CdProducto,DescripProd,Cantidad,EnEfectivo
,CdForma,FormaPago,NumForma,CdBanco,Banco,DetallePagos,CdCta,NumeroCta,FecCheque,D.IdVend AS CdVend,V.RazonSocial AS Vendedor
,TarifaCom,nClieCon,Nombre,IdCajero,Usuario,D.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDpto,Departamento,D.Referencia AS DetReferencia,Referencia2,Beneficiario
,Modalidad,pVehiculo,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,D.Observacion AS Observ,TimeSys,tmId,tmEst
--datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen
,A.Referencia AS AgeReferencia
--datos del producto
,P.Referencia AS Prod_Referencia,TipoRef,P.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,P.IdMarca AS CdMarca,Marca
 FROM tm_Diario AS D INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Terceros AS T ON  D.IdTercero=T.IdTercero 
 LEFT JOIN Terceros AS V ON  D.IdVend=V.IdTercero INNER JOIN  Conceptos AS CN ON D.IdConcepto=CN.IdConcepto 
 INNER JOIN adm_Usuarios AS UC ON D.IdCajero=UC.IdUsuario 
 INNER JOIN Localidades AS L ON D.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN ClieContado AS CC ON D.nClieCon=CC.IdCliente  LEFT JOIN Sys_TiposDoc AS TD ON D.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTA ON D.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON D.CdBanco=B.IdBanco
 LEFT JOIN  Agencias  AS A ON D.IdAgencia=A.IdAgencia LEFT JOIN Formaspago AS FP ON D.CdForma=FP.IdForma
 LEFT JOIN ProdMcias AS P ON D.CdProducto=P.IdProducto 
 LEFT JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo LEFT JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 LEFT JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea LEFT JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 WHERE  tmEst=@pmtmEst
 ORDER BY TipDoc,tmId
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DifIngreso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_DifIngreso] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdDiferido,tmFecha,tmPeriodos,tmVrBase,tmMejoras,tmDisminucion,tmAjustes,tmAmortiza
,tmAmortizaAju,tmAjuInfAmtza,tmMesesAcum,tmCorrMonDif,tmMesesCorr,tmFecUltAmtza,tmConcepto
 FROM tm_DifIngreso
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_DifIngresoDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_DifIngresoDso] @pmtmNumero VARCHAR(5) 
 AS 
 SELECT tmItem,tmIdDiferido,NomDiferido,tmFecha,tmVrBase,tmMejoras,tmDisminucion,tmVrBase+tmMejoras-tmDisminucion AS TotalBase
,tmAjustes,tmAmortiza,tmAmortizaAju,tmAjuInfAmtza,tmPeriodos,tmCorrMonDif,tmMesesCorr,tmFecUltAmtza,tmMesesAcum,tmConcepto
,IdEstado,IdCCosto,IdSubCos,IdDep,IdRespons,IdCia,IdGrupo
 FROM tm_DifIngreso AS T INNER JOIN Diferidos AS D ON T.tmIdDiferido=D.IdDiferido
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Dotacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Dotacion] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmTipo,tmFecha,tmDiasPlazo,tmFecVence,tmIdCia,CI.Compania,tmNumReg,tmDetalle
,FecIngreso,Indefinido,C.IdNom AS CdNom,TipoNomina,C.IdTipCon AS CdTipCon,TipoContrato,C.IdArea AS CdArea,Area,C.IdDep AS CdDep,Dependencia,C.IdInstala AS IdInstla,Instlacion
,C.IdCargo AS CodCargo,Cargo,C.IdCia AS ConCdCia,CN.Compania AS ConCompania,C.TipoLiquida AS TipoLiq,DchDotacion,VrSalario,VrAuxTrans,SalMinimo,SalIntegral
,E.Codigo,e_mail,E.Sexo,E.IdProf AS CodProf,Profesion,FecUltDot,TallaCam,TallaPan,TallaZap
FROM tm_Dotacion AS T INNER JOIN Empleados AS E ON T.tmIdEmpleado=E.IdEmpleado INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
INNER JOIN Emp_Contrato AS C ON T.tmNContrato=C.NContrato INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep
INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom
LEFT JOIN Companias AS CI ON T.tmIdCia=CI.IdCia
WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormas] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma
,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo
,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza
,tmVrDenom,tmCantDenm,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrBase,tmVrPresp
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero 
  AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasChe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasChe] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma
,tmCtaForma,tmBeneficiario,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdVend,tmReferencia,tmReferncia2
,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero  AND tmCredito=0
 AND (tmIdForma IN ('CHE','BON','CON','TRA') OR tmIdForma LIKE 'CH%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasCmp] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdForma,FormaPago,tmObservacion,tmNForma,tmFecForma,tmCtaForma,tmReferencia,tmReferncia2
,tmCdCta,tmNumAutoriza,tmIdCliente,tmIdAgencia,tmpVehiculo,tmnVehiculo,tmCdCCosto,tmCdSubCos
,SUM(tmVrTotal) AS STOTPAG
 FROM tm_EdsFormas AS P INNER JOIN Formaspago AS F ON P.tmIdForma=F.IdForma
 WHERE tmNumero=@pmtmNumero AND tmCredito=0
 GROUP BY tmIdForma,FormaPago,tmObservacion,tmNForma,tmFecForma,tmCtaForma,tmReferencia,tmReferncia2
,tmCdCta,tmNumAutoriza,tmIdCliente,tmIdAgencia,tmpVehiculo,tmnVehiculo,tmCdCCosto,tmCdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCpla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasCpla] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrTotal) AS STOTAL,SUM(tmCantPuntos) AS STOTPUN
,SUM(tmCantidad) AS STOTCAN
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero AND tmCredito<>0 AND tmEsCaja=0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasCre] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipoRango,COUNT(tmItem) AS SCANT,SUM(tmVrTotal) AS STOTAL,SUM(tmCantPuntos) AS STOTPUN
,SUM(tmCantidad) AS STOTCAN,SUM(tmVrDenom*tmCantDenm) AS STOTDEN,SUM(tmCantDenm) AS SCANDEN
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero AND tmCredito<>0
 GROUP BY tmTipoRango
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasCue] @pmtmNumero VARCHAR(5),@pmIdConcepto VARCHAR(4)
AS 
 SELECT tmIdForma,IdConcepto,IdCuenta
FROM tm_EdsFormas AS EF LEFT JOIN FormasCue AS F ON EF.tmIdForma=F.IdForma
WHERE tmNumero=@pmtmNumero AND tmCredito=0
AND (ISNULL(IdConcepto,'')=@pmIdConcepto OR tmTipoRango='TKT')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasDsc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasDsc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmTipoRango,tmIdRango,tmNumSerie,tmNumForma,tmVrTotal,tmIdCuenta,tmIdCliente,T.RazonSocial AS NomCliente
,tmIdAgencia,tmpVehiculo,tmnVehiculo,tmCdProducto,DescripProd,tmCantidad,tmReferencia,tmReferncia2,tmObservacion,tmIdForma,FormaPago
,tmIdUsuario,tmIdVend,V.RazonSocial AS Vendedor,tmCantPuntos,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmTipAplica,tmVrBase,tmVrPresp
 FROM tm_EdsFormas  AS P INNER JOIN Formaspago AS F ON P.tmIdForma=F.IdForma
 INNER JOIN Terceros AS T ON P.tmIdCliente=T.IdTercero
 LEFT JOIN Terceros AS V ON P.tmIdVend=V.IdTercero
 LEFT JOIN ProdMcias AS PD ON P.tmCdProducto=PD.IdProducto
 WHERE tmNumero=@pmtmNumero  AND tmCredito<>0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmCredito,tmIdForma,FormaPago,tmTipoRango,tmIdRango,tmNumSerie,tmNumForma,tmNForma,tmVrTotal
,tmIdBanco,Banco,tmObservacion,tmIdCuenta,tmIdCliente,ISNULL(T.RazonSocial,tmBeneficiario) AS NomCliente,tmIdAgencia,tmpVehiculo,tmnVehiculo
,tmIdVend,V.RazonSocial AS Vendedor,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmFecForma,tmCtaForma,tmBeneficiario
,tmIdUsuario,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantDenm,tmTipDenom,tmCdCta,tmEsCaja,tmCantPuntos
,tmTipAplica,tmNumero,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrPrecio*tmCantidad AS VrPublico
,CASE WHEN tmVrPrecio<>0 THEN tmVrTotal-(tmVrPrecio*tmCantidad) ELSE 0 END AS Excedente
,tmVrBase,tmVrPresp
 FROM tm_EdsFormas AS P INNER JOIN Formaspago AS F ON P.tmIdForma=F.IdForma
 INNER JOIN Bancos AS B ON P.tmIdBanco=B.IdBanco
 LEFT JOIN Terceros AS T ON P.tmIdCliente=T.IdTercero
 LEFT JOIN Terceros AS V ON P.tmIdVend=V.IdTercero
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasEfe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasEfe] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrTotal) AS STOTAL,SUM(tmCantPuntos) AS STOTPUN
,SUM(tmCantidad) AS STOTCAN,SUM(tmVrDenom*tmCantDenm) AS STOTDEN,SUM(tmCantDenm) AS SCANDEN
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero AND tmCredito=0 AND tmTipoRango<>'TKT' AND tmIdForma='EFE'
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasFac] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmTipoRango,tmIdRango,tmNumSerie,tmNumForma,tmEsCaja,tmVrTotal,tmIdCliente
,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo,tmIdVend,tmCdProducto,tmCantidad,tmReferencia
,TipDcm,Documento,IdCiaDcm,FechaDcm,AgencDcm,Anulado,Planilla,IdCia,IdCliente,IdAgencia
,tmCdCCosto,tmCdSubCos
 FROM tm_EdsFormas AS F INNER JOIN Trn_EdsFormas AS EF ON F.tmTipoRango=EF.TipoRango
 AND F.tmIdRango=EF.IdRango AND F.tmNumSerie=EF.NumSerie AND F.tmNumForma=EF.NumForma
 WHERE tmNumero=@pmtmNumero AND tmCredito<>0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasFma]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasFma] @pmtmNumero VARCHAR(5),@pmtmIdForma VARCHAR(4)
,@pmtmIdBanco VARCHAR(4),@pmtmNForma VARCHAR(20),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdForma,tmIdBanco,tmNForma,tmFecForma,tmCtaForma
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero  AND tmCredito=0 AND tmIdForma=@pmtmIdForma
  AND tmIdBanco=@pmtmIdBanco  AND tmNForma=@pmtmNForma AND tmItem<>@pmtmItem
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasPro] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipoRango,tmIdRango,tmIdForma,tmNumSerie,tmNumForma,tmVrTotal
,tmObservacion,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo
,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdCCosto,tmCdSubCos
--VARIABLES DE ITEM
,Item,IdProducto,IdBodega,Cantidad,VrPrecio,TarifaIva,VrIva,TarifaDct,VrDcto,Servicios,Descripcion,ListaPrec,CantDev
,CdOperario,Comision,I.TarifaIba,I.VrImpuBa,I.CodTarBa,I.TarifaCup,I.VrImpuCup,I.CodTarCup
 FROM tm_EdsFormas AS F INNER JOIN Trn_EdsForItems AS I ON F.tmTipoRango=I.TipoRango
 AND F.tmIdRango=I.IdRango AND F.tmNumSerie=I.NumSerie AND F.tmNumForma=I.NumForma
 WHERE tmNumero=@pmtmNumero AND tmCredito<>0 AND tmEsCaja<>0 AND (I.Cantidad-I.CantDev)>0
 ORDER BY tmItem,Item
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasRan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasRan] @pmtmNumero VARCHAR(5),@pmtmTipoRango VARCHAR(3),@pmtmIdRango INT
,@pmtmNumSerie VARCHAR(5),@pmtmNumForma INT,@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmVrTotal,tmNumSerie,tmNumForma,tmIdCliente,tmIdAgencia,tmIdCuenta
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero AND tmCredito<>0  AND tmTipoRango=@pmtmTipoRango AND tmIdRango=@pmtmIdRango
 AND tmNumSerie=@pmtmNumSerie AND tmNumForma=@pmtmNumForma
 AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasTip]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasTip] @pmtmNumero VARCHAR(5),@pmtmCredito BIT
 AS 
 SELECT tmNumero,tmItem,tmCredito,tmTipoRango,tmIdRango,tmIdForma,tmObservacion,tmEsCaja,tmIdBanco,tmNForma,tmFecForma
,tmCtaForma,tmBeneficiario,tmNumSerie,tmNumForma,tmVrTotal,tmIdCliente,tmIdAgencia,tmIdCuenta,tmpVehiculo,tmnVehiculo
,tmIdVend,tmCdProducto,tmCantidad,tmReferencia,tmReferncia2,tmCantPuntos,tmCdLocal,tmNumAutoriza
,tmVrDenom,tmCantDenm,tmTipDenom,tmCdCta,tmTipAplica,tmIdUsuario,tmCdCCosto,tmCdSubCos,tmVrPrecio,tmVrBase,tmVrPresp
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero AND tmCredito=@pmtmCredito
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EdsFormasTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EdsFormasTot] @pmtmNumero VARCHAR(5),@pmtmCredito BIT=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrTotal) AS STOTAL,SUM(tmCantPuntos) AS STOTPUN
,SUM(tmCantidad) AS STOTCAN,SUM(tmVrDenom*tmCantDenm) AS STOTDEN,SUM(tmCantDenm) AS SCANDEN
,SUM(CASE WHEN tmVrPrecio>0 AND tmCantidad>0 AND tmVrTotal>(tmCantidad*tmVrPrecio) THEN tmVrTotal-(tmCantidad*tmVrPrecio) ELSE 0 END) AS STOTEXCD
,SUM(CASE WHEN tmVrPrecio>0 AND tmCantidad>0 AND (tmCantidad*tmVrPrecio)>tmVrTotal THEN (tmCantidad*tmVrPrecio)-tmVrTotal ELSE 0 END) AS STOTDCT
 FROM tm_EdsFormas
 WHERE tmNumero=@pmtmNumero 
 AND (tmCredito=ISNULL(@pmtmCredito,0) or tmCredito=ISNULL(@pmtmCredito,1))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGyp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EstadoGyp] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT GP.tmIdCuenta AS CdCuenta,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmIdCia,Compania
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmTipoAfi,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
--información de agencia y vehículos
,CodAgencia,Referencia--,NumVeh
,tmItem,tmEst,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_EstadoGyp AS GP INNER JOIN Puc AS P ON GP.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON GP.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON GP.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON GP.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON GP.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN  Agencias AS A ON GP.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CI ON GP.tmIdCia=CI.IdCia
-- LEFT JOIN Vehiculos AS V ON GP.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst AND GP.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 ORDER BY GP.tmIdCuenta,tmIdCia,RazonSocial,tmCodAgncia,tmIdCCosto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EstadoGypCue] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdCia CHAR(2)=Null,@pmtmTipo VARCHAR(4)=Null
 AS 
 SELECT tmEst,tmIdCuenta,tmItem,tmIdCia,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmTipoAfi
 FROM tm_EstadoGyp
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 AND tmTipo LIKE ISNULL(@pmtmTipo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypGcue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EstadoGypGcue] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCuenta,COUNT(tmItem) AS SCANT
 FROM tm_EstadoGyp
 WHERE tmEst=@pmtmEst 
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypTC]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EstadoGypTC] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT GP.tmIdCuenta AS CdCuenta,NomCuenta,tmTipo,p.Vehiculo,tmIdVehiculo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmIdCia,Compania
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmTipoAfi,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
,CodAgencia,Referencia,NumVeh,IdPpd,TipoAfil
,tmItem,GP.tmEst,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
,VehiculoTC,CCostoTC
 FROM tm_EstadoGyp AS GP INNER JOIN Puc AS P ON GP.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON GP.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON GP.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON GP.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON GP.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN  Agencias AS A ON GP.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CI ON GP.tmIdCia=CI.IdCia
 LEFT JOIN Vehiculos AS V ON GP.tmIdVehiculo=V.IdVehiculo
 LEFT JOIN (SELECT tmEst AS tmEstTC, tmIdCuenta AS tmIdCuentaTC, MAX(CASE WHEN tmTipo IN ('VC', 'NV') THEN 1 ELSE 0 END) AS VehiculoTC, MAX(CASE WHEN tmTipo IN ('C') THEN 1 ELSE 0 END) AS CCostoTC
 FROM dbo.tm_EstadoGyp GROUP BY tmEst, tmIdCuenta) AS TC ON GP.tmEst=TC.tmEstTC AND GP.tmIdCuenta=TC.tmIdCuentaTC
 WHERE tmEst=@pmtmEst AND GP.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 ORDER BY GP.tmIdCuenta,tmIdCia,RazonSocial,tmCodAgncia,tmIdCCosto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstadoGypTer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_EstadoGypTer] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmTipo VARCHAR(4)
,@pmtmIdCia CHAR(2)=Null,@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdVehiculo VARCHAR(10)=Null
,@pmtmIdCCosto VARCHAR(16)=Null,@pmtmIdSubCos VARCHAR(16)=Null,@pmtmCodAgncia VARCHAR(16)=Null,@pmtmTipoAfi INT=Null
 AS 
 SELECT tmEst,tmIdCuenta,tmItem,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2
 FROM tm_EstadoGyp
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta  AND tmTipo=@pmtmTipo
 AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%') AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%')
 AND tmIdSubCos LIKE ISNULL(@pmtmIdSubCos,'%') AND tmCodAgncia LIKE ISNULL(@pmtmCodAgncia,'%')
 AND (tmTipoAfi>=ISNULL(@pmtmTipoAfi,-1) AND tmTipoAfi<=ISNULL(@pmtmTipoAfi,9))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstClientes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EstClientes] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCliente,T.RazonSocial AS NomCliente,tmIdAgencia,Agencia,tmIdCia,Compania
 ,tmFecUltFcr,tmPPlazoFcr,tmMayorFcr,tmMenorFcr,tmFecUltFco,tmPPlazoFco,tmMayorFco,tmMenorFco,tmVentaBruto
,tmVrDevolucion,tmVrDescuentos,tmCostoBruto,tmCostoDev,tmVrIva,tmFecUltPago,tmPromPago,tmSaldoMora,tmFecIniMora,tmDiasEnMora
,tmChequesDev,tmSaldoActual,tmSaldoAnterior,tmVrFacturas,tmVrDevFacturas,tmVrRecibos,tmVrDevRecibos,tmVrNotasDeb,tmVrNotasCre,tmVrCheques
--Datos del cliente
,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigla,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,CLI.IdForma AS CdForma,ExcIva,TrfIntMora,CLI.DiasGracia AS CliDiasGracia,LiqFletes,Autoret
,CLI.Inactivo AS ClieInactivo,CLI.CdBandera AS CliCdbandera,TipoBandera,CLI.IdPlazo AS CdPlazo,Plazo,DiasPago,CLI.NContrato AS CliNumContrato
,CLI.IdVend AS CdVend,VN.RazonSocial AS Vendedor
 FROM tm_EstClientes AS TC INNER JOIN Terceros AS T ON TC.tmIdCliente=T.IdTercero  INNER JOIN TercCliente AS CLI ON TC.tmIdCliente=CLI.IdClie
 INNER JOIN Terceros AS VN ON CLI.IdVend=VN.IdTercero   INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona   INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Companias AS CI ON TC.tmIdCia=CI.IdCia   LEFT JOIN Agencias AS A ON TC.tmIdAgencia=A.IdAgencia
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 WHERE tmEst=@pmtmEst
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstClientesMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EstClientesMov] @pmtmEst CHAR(2)
 AS 
 SELECT TC.tmIdCliente AS NitCliente,T.RazonSocial AS NomCliente,TC.tmIdAgencia AS CdAgencia,A.Agencia AS NomAgencia,TC.tmIdCia AS CdCia,CI.Compania AS NomCia
 ,tmFecUltFcr,tmPPlazoFcr,tmMayorFcr,tmMenorFcr,tmFecUltFco,tmPPlazoFco,tmMayorFco,tmMenorFco,tmVentaBruto
,tmVrDevolucion,tmVrDescuentos,tmCostoBruto,tmCostoDev,tmVrIva,tmFecUltPago,tmPromPago,tmSaldoMora,tmFecIniMora,tmDiasEnMora
,tmChequesDev,tmSaldoActual,tmSaldoAnterior,tmVrFacturas,tmVrDevFacturas,tmVrRecibos,tmVrDevRecibos,tmVrNotasDeb,tmVrNotasCre,tmVrCheques
--Datos del cliente
,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigla,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,CLI.IdForma AS CdForma,ExcIva,TrfIntMora,CLI.DiasGracia AS CliDiasGracia,LiqFletes,Autoret
,CLI.Inactivo AS ClieInactivo,CLI.CdBandera AS CliCdbandera,TipoBandera,CLI.IdPlazo AS CdPlazo,Plazo,DiasPago,CLI.NContrato AS CliNumContrato
,CLI.IdVend AS CdVend,VN.RazonSocial AS Vendedor
--datos de movimientos
,M.tmIdAgencia AS MovAgencia,AM.Agencia AS MovNomAgencia,M.tmIdCia AS MovCodCia,CM.Compania AS MovNomCia,tmTipDoc,tmNumero,M.tmItem AS MovItem,tmFecha,tmCargos,tmAbonos,tmDetalle
,tmReferencia,tmNumForma,tmModalidad,tmTipRef,tmDocRef,tmIdCiaRef,tmCdConcepto
,tmTotalAbono,tmVrAfavor,tmTimeSys,tmFecVence,tmCdForma,tmEnEfectivo,tmCdBanco,tmBeneficiario,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario
 FROM tm_EstClientes AS TC INNER JOIN Terceros AS T ON TC.tmIdCliente=T.IdTercero  INNER JOIN TercCliente AS CLI ON TC.tmIdCliente=CLI.IdClie
 INNER JOIN Terceros AS VN ON CLI.IdVend=VN.IdTercero   INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona   INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN  Companias AS CI ON TC.tmIdCia=CI.IdCia   LEFT JOIN Agencias AS A ON TC.tmIdAgencia=A.IdAgencia
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 LEFT JOIN tm_MovClientes AS M ON TC.tmEst=M.tmEst AND TC.tmIdCliente=M.tmIdCliente
 AND TC.tmIdAgencia=M.tmIdAgencia AND TC.tmIdCia=M.tmIdCiaCom
 LEFT JOIN Agencias AS AM ON M.tmIdAgencia=AM.IdAgencia   LEFT JOIN  Companias AS CM ON M.tmIdCia=CM.IdCia
 WHERE TC.tmEst=@pmtmEst
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCte]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EstCueCte] @pmtmEst CHAR(2)
AS
SELECT  tmIdCliente AS NitPropietario,T.RazonSocial AS Propietario,tmIdVehiculo,NumVeh,tmTipDoc,TipoDoc, tmDocumento, tmIdCia, tmItem, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmIdCargo,F.Concepto AS Cargo,tmIdClase,ClaseCuenta
,tmIdConcepto,CO.Concepto AS ConceptoDoc, tmFecUltPago, tmReferencia, tmDetalle, tmFactura, tmIdVendedor AS CedConductor,NC.RazonSocial AS Conductor,tmTipCar, tmCartulina, tmIdCiaCar, tmModalidad, tmCentInicial,tmCentFinal, tmNPasajeros, tmIdBanco,Banco
, tmNumCheque, tmAnulado, tmNumDev, tmFecDev, tmTipDcm, tmDocDev, tmIdCiaDcm, tmFecDcm, tmIdEstado,Estado,tmIdUsuario,Usuario,Compania,tmTimeSys
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,Modelo,FecRep,V.IdAdmon AS CdAdmon,TipoAdmon,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa
 FROM   tm_EstCueCte AS C INNER JOIN Companias  AS CI ON C.tmIdCia=CI.IdCia
 INNER JOIN  Terceros AS T ON C.tmIdCliente=T.IdTercero  INNER JOIN  Vehiculos AS V ON C.tmIdVehiculo=V.IdVehiculo
 INNER JOIN  Fijos AS F ON C.tmIdCargo=F.IdCargo INNER JOIN  BusClaseCue  AS CU ON C.tmIdClase=CU.IdClase
 INNER JOIN  Bancos AS B ON C.tmIdBanco=B.IdBanco INNER JOIN  adm_Usuarios AS U ON C.tmIdUsuario=U.IdUsuario
 INNER JOIN  EstadoDoc AS ED ON C.tmIdEstado=ED.IdEstado  INNER JOIN  Terceros AS NC ON C.tmIdVendedor=NC.IdTercero
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo   LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
 LEFT JOIN  Conceptos AS CO ON C.tmIdConcepto=CO.IdConcepto  LEFT JOIN Sys_TiposDoc  AS TD ON C.tmTipDoc=TD.IdDoc
 WHERE tmEst=@pmtmEst 
 ORDER BY T.RazonSocial,tmIdVehiculo,tmFecha,tmIndTip,tmIdCia,tmDocumento,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCte_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EstCueCte_Cr] @pmtmEst CHAR(2)
AS
SELECT  tmIdCliente AS NitPropietario,T.RazonSocial AS Propietario,tmIdVehiculo,tmTipDoc,TipoDoc, tmDocumento, tmIdCia, tmItem, tmFecha, tmFecVence, tmValorDebito, tmValorCredito, tmIdCargo,F.Concepto AS Cargo,tmIdClase,ClaseCuenta
,tmIdConcepto,COC.Concepto AS ConceptoDoc, tmFecUltPago, tmReferencia, tmDetalle, tmFactura, tmIdVendedor AS CedConductor,NC.RazonSocial AS Conductor,tmTipCar, tmCartulina, tmIdCiaCar, tmModalidad, tmCentInicial,tmCentFinal, tmNPasajeros, tmIdBanco,Banco
, tmNumCheque, tmAnulado, tmNumDev, tmFecDev, tmTipDcm, tmDocDev, tmIdCiaDcm, tmFecDcm, tmIdEstado,ED.Estado AS EstadoDoc,tmIdUsuario,Usuario,Compania,tmTimeSys
,tmIndTip,tmValorAbono,tmVehPropio, tmRecorridos, tmValorRecibido, tmTotalGastos,tmTotalVales, tmTotalAhorro, tmTotalOtros, tmTotalAbono,tmIntMora,tmCxPagar,tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia, tmSaldoAntDia,tmNuevoSaldo,tmSalAntPro,tmSalAntProCla,tmSalAntProCia
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
 FROM   tm_EstCueCte AS C INNER JOIN Companias  AS CI ON C.tmIdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.tmIdCliente=T.IdTercero  INNER JOIN Vehiculos AS V ON C.tmIdVehiculo=V.IdVehiculo
 INNER JOIN  Fijos AS F ON C.tmIdCargo=F.IdCargo INNER JOIN  BusClaseCue  AS CU ON C.tmIdClase=CU.IdClase
 INNER JOIN  Bancos AS B ON C.tmIdBanco=B.IdBanco INNER JOIN  adm_Usuarios AS U ON C.tmIdUsuario=U.IdUsuario
 INNER JOIN  EstadoDoc AS ED ON C.tmIdEstado=ED.IdEstado  INNER JOIN  Terceros AS NC ON C.tmIdVendedor=NC.IdTercero
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
 LEFT JOIN  Conceptos AS COC ON C.tmIdConcepto=COC.IdConcepto  LEFT JOIN Sys_TiposDoc  AS TD ON C.tmTipDoc=TD.IdDoc
 WHERE tmEst=@pmtmEst 
 ORDER BY T.RazonSocial,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCtePro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQrytm_EstCueCtePro] @pmtmEst CHAR(2),@pmtmIdCliente VARCHAR(16),@pmtmIdClase VARCHAR(4)=Null,@pmtmIdCia CHAR(2)=Null
,@pmtmIdVehiculo VARCHAR(10)=Null
AS
 SELECT tmEst,tmIdCia,tmIdCliente,tmIdVehiculo,tmIdClase,tmSalAntPro,tmSalAntProCla,tmSalAntProCia
 FROM  tm_EstCueCte
 WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente AND tmIdClase LIKE ISNULL(@pmtmIdClase,'%')
  AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
 ORDER BY tmIdCliente,tmIdVehiculo,tmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EstCueCteVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQrytm_EstCueCteVeh] @pmtmEst CHAR(2),@pmtmIdVehiculo VARCHAR(10),@pmtmIdClase VARCHAR(4)=Null,@pmtmIdCia CHAR(2)=Null
AS
 SELECT tmEst,tmIdCia,tmIdVehiculo,tmIdClase,tmSaldoAnt, tmSaldoAntCla, tmSaldoAntCia
 FROM  tm_EstCueCte
 WHERE tmEst=@pmtmEst AND tmIdVehiculo=@pmtmIdVehiculo AND tmIdClase LIKE ISNULL(@pmtmIdClase,'%')
  AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 ORDER BY tmIdVehiculo,tmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVcau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EVcau] @pmtmEst CHAR(2),@pmtmTipo VARCHAR(3)=Null,@pmtmIdCia CHAR(2)=Null,@pmtmIdCliente VARCHAR(16)=Null,@pmtmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT tmTipo,TipoDoc,tmDocmnto,tmIdCia,compania,tmItem,tmFecha,tmGrupo,tmIdCargo,F.Concepto AS CargoFijo,tmIdConcepto,COC.Concepto AS NomConcepto,tmValor,tmValorDev,tmIdCliente,T.RazonSocial AS NomPropietario,tmIdVehiculo
,tmVehPropio,tmIdConductor,NC.RazonSocial AS NomConductor,tmModalidad,tmValorTotal,tmGalones,tmVrComb,tmDetalle,tmNumCheque,tmReferencia,tmIdClase,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev
,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmVrGastos,tmIdUsuario,Usuario,tmTimeSys,tmEst
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM tm_EVcau AS EC INNER JOIN Terceros AS T ON EC.tmIdCliente=T.IdTercero INNER JOIN Vehiculos AS V ON EC.tmIdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NC ON EC.tmIdConductor=NC.IdTercero INNER JOIN Sys_TiposDoc  AS TD ON EC.tmTipo=TD.IdDoc
 INNER JOIN Fijos AS F ON EC.tmIdCargo=F.IdCargo INNER JOIN Conceptos AS COC ON EC.tmIdConcepto=COC.IdConcepto
 INNER JOIN adm_Usuarios AS U ON EC.tmIdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa     LEFT JOIN TercCndtores AS CT ON  EC.tmIdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
  LEFT JOIN Companias  AS CI ON EC.tmIdCia=CI.IdCia
 WHERE tmEst=@pmtmEst AND tmTipo LIKE ISNULL(@pmtmTipo,'%')  AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') 
 AND tmIdCliente LIKE ISNULL(@pmtmIdCliente,'%') AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
 ORDER BY tmIdCliente,tmIdVehiculo,tmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVcauVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EVcauVeh] @pmtmEst CHAR(2)
 AS 
 SELECT tmEst,tmIdCliente,tmIdVehiculo,tmIdConductor,tmVehPropio,SUM(tmValor) AS SValor,SUM(tmValorDev) AS SValDev
,SUM(tmGalones) AS Sgalones,SUM(tmVrComb) AS SVrComb,SUM(tmVrGastos) AS StGastos
 FROM tm_EVcau
 WHERE tmEst=@pmtmEst
 GROUP BY tmEst,tmIdCliente,tmIdVehiculo,tmIdConductor,tmVehPropio
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVrec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EVrec] @pmtmEst CHAR(2),@pmtmTipo VARCHAR(3)=Null,@pmtmIdCia CHAR(2)=Null,@pmtmIdCliente VARCHAR(16)=Null,@pmtmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT tmTipo,TipoDoc,tmDocmnto,tmIdCia,compania,tmItem,tmFecha,tmGrupo,tmValor,tmValorDev,tmIdCliente,T.RazonSocial AS NomPropietario,tmIdVehiculo,tmVehPropio,tmIdConductor,NC.RazonSocial AS NomConductor,tmModalidad,tmTipCar,tmCartulina,tmIdCiaCar,tmFechaRec
,tmCentInicial,tmCentFinal,tmNPasajeros,tmRecorridos,tmValorTotal,tmValorOtros,tmTotalProducido,tmTotalGastos,tmTotalAhorro,tmTotalOtros,tmTotalVales,tmTotalAbono,tmValorPasaje,tmDetalle,tmNumCheque,tmReferencia,tmIdConcepto,Concepto
,tmIdBanco,Banco,tmIdClase,tmIdRuta,Ruta,tmAnulado,tmNumDev,tmFecDev,tmTipDcm,tmDocDev,tmIdCiaDcm,tmFecDcm,tmIdEstado,tmIdUsuario,Usuario,tmTimeSys,tmEst
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM tm_EVrec  AS EC INNER JOIN Terceros AS T ON EC.tmIdCliente=T.IdTercero INNER JOIN Vehiculos AS V ON EC.tmIdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NC ON EC.tmIdConductor=NC.IdTercero INNER JOIN Sys_TiposDoc AS TD ON EC.tmTipo=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON EC.tmIdUsuario=U.IdUsuario INNER JOIN Bancos AS B ON EC.tmIdBanco=B.IdBanco
 INNER JOIN Rutas AS R ON EC.tmIdRuta=R.IdRuta INNER JOIN Conceptos AS COC ON EC.tmIdConcepto=COC.IdConcepto
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  LEFT JOIN TercCndtores AS CT ON  EC.tmIdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar  LEFT JOIN Companias  AS CI ON EC.tmIdCia=CI.IdCia
 WHERE tmEst=@pmtmEst AND tmTipo like ISNULL(@pmtmTipo,'%')  AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') 
 AND tmIdCliente LIKE ISNULL(@pmtmIdCliente,'%') AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
 ORDER BY tmIdCliente,tmIdVehiculo,tmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_EVrecEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_EVrecEst] @pmtmEst CHAR(2),@pmtmGrupo VARCHAR(3)=Null,@pmtmModalidad VARCHAR(10)=Null
 AS 
 SELECT tmIdCliente,tmIdVehiculo,tmTipo,COUNT(tmDocmnto) AS SCANT,SUM(tmValor) AS SValor,SUM(tmValorDev) AS SValDev,SUM(tmNPasajeros) AS SNpasj,SUM(tmRecorridos) AS SRecorr
,SUM(tmTotalProducido) AS STotProd,MAX(tmTotalProducido) AS MXTotProd,MIN(tmTotalProducido) AS MinTotProd
 FROM tm_EVrec
 WHERE tmEst=@pmtmEst AND tmTipo IN ('RC1','OD1') AND tmGrupo LIKE ISNULL(@pmtmGrupo,'%')
 AND tmModalidad LIKE ISNULL(@pmtmModalidad,'%')
 GROUP BY tmIdCliente,tmIdVehiculo,tmTipo
 ORDER BY tmIdCliente,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ExtVeh] @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16),@pmtmIdVehiculo VARCHAR(10)
 AS 
 SELECT tmEst,tmIdPropietario,tmIdVehiculo,tmIdConductor,tmVehPropio,tmTotaDebito,tmTotaCredito,tmSaldoAnt,tmSaldoAntCla,tmSalAntPro
,tmSalAntProCla,tmTotalProducido,tmMaxProducido,tmMinProducido,tmTotalRecrridos,tmTotalPasaj,tmTotalDias,tmTotalCausac,tmGalones,tmValorComb
 FROM  tm_ExtVeh
 WHERE  tmEst=@pmtmEst AND tmIdPropietario=@pmtmIdPropietario AND tmIdVehiculo=@pmtmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVehCr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ExtVehCr] @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16)=Null,@pmtmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT tmIdPropietario,NP.RazonSocial AS Propietario,tmIdVehiculo,tmIdConductor,NC.RazonSocial AS Conductor,tmVehPropio,tmTotaDebito,tmTotaCredito,tmSaldoAnt,tmSaldoAntCla,tmSalAntPro
,tmSalAntProCla,EV.tmTotalProducido AS TotalProducido,EV.tmMaxProducido AS MaxProducido,EV.tmMinProducido AS MinProducido,EV.tmTotalRecrridos AS TotalRecrridos,EV.tmTotalPasaj AS TotalPasaj
,EV.tmTotalDias AS TotalDias,EV.tmTotalCausac AS TotalCausac,EV.tmGalones AS tmGalones,EV.tmValorComb AS ValorComb,EV.tmEst AS Id_Est
,ESV.tmTotalProducido AS EvTotalProducido,ESV.tmMaxProducido AS EvMaxProducido ,ESV.tmMinProducido AS EvMinProducido,ESV.tmTotalRecrridos AS EvTotalRecrridos,ESV.tmTotalPasaj AS EvTotalPasaj
,ESV.tmTotalDias AS EvTotalDias,ESV.tmTotalCausac AS EvTotalCausac,ESV.tmGalones AS EvGalones,ESV.tmValorComb AS EvValorComb,tmCantVeh
--Datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,VrNormal,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EVH.Estado AS VehEstado,V.Inactivo AS VehInactivo
--datos del propietario
,NP.Codigo AS PropCodigo,NP.TipoId AS PropTipoId,NP.Dv AS PropDv,NP.Direccion AS PropDireccion,NP.IdLocal AS PropCdCiudad,LP.Localidad AS PropCiudad,LP.IdDep AS PropCdDep
,DP.Departamento AS PropDpato,NP.Telefono AS PropTelefono,NP.Fax AS PropFax,NP.TelMovil AS PropTelMovil
--datos de conductor
,NC.Codigo AS CondCodigo,NC.Direccion AS CondDireccion,NC.IdLocal AS CondCdCiudad,LC.Localidad AS CondCiudad,LC.IdDep AS CondCdDpto,DC.Departamento AS CondDpto
,NC.Telefono AS CondTelefono,NC.Fax AS CondFax,NC.TelMovil AS CondTelMovil,NC.e_mail AS CondEmail,NC.EsPropietario AS CondEspropietario,NC.IdLugarCed AS CondCdLugarCed,LCE.Localidad AS CondLugarCed,NC.FecExpCed AS CondFechaExpCedula
,CT.IdModd AS CondCdMod,MCD.Modalidad AS ModConductor,TipoSangre,FactorRh,FecNacmto,LugarNacmto,Sexo,CertJudicial,VigJudicial,Licencia,CatLicencia,VigLicencia,CT.IdLugar AS CdLugarLic,LugarLic
 FROM  tm_ExtVeh AS EV INNER JOIN Terceros AS NP ON EV.tmIdPropietario=NP.IdTercero  INNER JOIN Vehiculos AS V ON EV.tmIdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NC ON EV.tmIdConductor=NC.IdTercero
 INNER JOIN Localidades AS LP ON NP.IdLocal=LP.IdLocal INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 INNER JOIN Localidades AS LC ON NC.IdLocal=LC.IdLocal INNER JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EVH ON V.IdEstado=EVH.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa    LEFT JOIN TercCndtores AS CT ON EV.tmIdConductor=CT.IdConductor
  LEFT JOIN  Localidades AS LCE ON NC.IdLugarCed=LCE.IdLocal LEFT JOIN TiposMod AS MCD ON CT.IdModd=MCD.IdModd
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar
 LEFT JOIN  tm_EVEst AS ESV ON EV.tmEst=ESV.tmEst AND V.CdTarifa=ESV.tmIdTipo
 WHERE  EV.tmEst=@pmtmEst AND tmIdPropietario LIKE ISNULL(@pmtmIdPropietario,'%') AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
 ORDER BY NP.RazonSocial,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVehSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ExtVehSan] @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16)=Null
 AS 
 SELECT tmEst,tmIdPropietario,tmIdVehiculo,tmSaldoAnt,tmSaldoAntCla,tmSalAntPro,tmSalAntProCla
 FROM  tm_ExtVeh
 WHERE  tmEst=@pmtmEst AND tmIdPropietario LIKE ISNULL(@pmtmIdPropietario,'%')
 ORDER BY tmIdPropietario,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ExtVehVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ExtVehVeh]  @pmtmEst CHAR(2),@pmtmIdVehiculo VARCHAR(10),@pmtmIdPropietario VARCHAR(16)
AS
 SELECT   tmEst,tmIdPropietario,tmIdVehiculo,tmIdConductor
 FROM tm_ExtVeh
 WHERE tmEst=@pmtmEst AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
  AND tmIdPropietario LIKE ISNULL(@pmtmIdPropietario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_FactNeto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_FactNeto] @pmtmEst CHAR(2)
 AS 
 SELECT tmTipFac,tmFactura,tmIdCia,Compania,F.Fecha,F.FechaVence,T.TipoId,F.IdCliente,T.Dv,T.RazonSocial AS NomCliente,F.IdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,tmEntradas,tmSalidas,tmSubTotal,tmDescuento,tmImpuesto,tmRetencion,tmReteICA,tmReteIVA,tmReteCREE,tmSobretasa,tmImpGlobal,tmOtros,tmCargos,tmOtrDcto,tmFletes,tmCostos,tmTarifaIba,tmVrImpuBa,tmTarifaCup,tmVrImpuCup
,tmFaltantes,tmAnticipos,tmImpCons,tmNeto AS VrNeto,F.BaseImp,F.BaseRet,F.TarifaIva,F.TarifaRet,F.TarifaIca,F.TarifaRiv,F.TarifaRtc,F.TipPed,F.Pedido,F.IdCiaPed
,F.TipRem,F.Remision,F.IdCiaRem,F.TipCot,F.Cotizacion,F.IdCiaCot,F.FecPedido,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,TarifaCom,F.pVehiculo AS PlacaVeh
,F.CdConductor,TC.RazonSocial AS Conductor,NitEmpTrans,EmpTrans,DirEnvio,F.IdLocEnv AS IdCiuEnvio,LE.Localidad AS CiudadEnvio,LE.IdDep AS CdDepEnvio,DE.Departamento AS DptoEnvio
,DiasEntraga,F.IdForma AS CdForma,FormaPago,DetallePago,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago
,F.IdCCosto AS IdCenCost,CCosto,F.IdSubCos AS IdSubCent,SubCosto,Modalidad,F.IdConcepto AS CdConcepto,Concepto,F.TipCom,F.Comprobante,F.IdCiaCom
,F.Observacion,F.NumDev,F.FecDev,F.TimeSys AS FechaCrea,F.FecUpdate AS FechaAct,F.IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.TelMovil AS TercCelular,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.TipoCliente,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo
,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.CdFntePago AS CdFuente,FuentePago,TipoZona,A.CodSicom
,V.Observacion AS VehObservacion,V.Descripcion AS VehDescripcion
FROM tm_FactNeto AS TF INNER JOIN Trn_Facturas AS F ON TF.tmTipFac=F.TipDoc AND TF.tmFactura=F.Factura AND TF.tmIdCia=F.IdCia
INNER JOIN Companias AS CN ON TF.tmIdCia=CN.IdCia INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
INNER JOIN CentroCosto AS CC ON F.IdCCosto=CC.IdCCosto 
INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
LEFT JOIN Localidades AS LE ON F.IdLocEnv=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Vehiculos AS V ON F.pVehiculo=V.IdVehiculo 
LEFT JOIN SubCentros AS SC ON F.IdSubCos=SC.IdSubCos LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
WHERE tmEst=@pmtmEst
--Detalles tmItem,tmTasaNac,tmTasaDep,tmTasaMun,tmRec_Costo,tmMgenCont,tmIvaInf
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_FactNetoDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_FactNetoDet] @pmtmEst CHAR(2)
 AS 
 SELECT tmTipFac,tmFactura,tmIdCia,Compania,F.Fecha,F.FechaVence,T.TipoId,F.IdCliente,T.Dv,T.RazonSocial AS NomCliente,F.IdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,tmItem,K.IdProducto AS CdProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,CdTanque,tmEntradas,tmSalidas,tmSubTotal,tmDescuento,tmImpuesto,tmRetencion,tmReteICA,tmReteIVA,tmReteCREE,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun
,tmImpGlobal,tmOtros,tmRec_Costo,tmMgenCont,tmIvaInf,tmCargos,tmOtrDcto,tmFletes,tmCostos,tmFaltantes,tmAnticipos,tmImpCons,tmTarifaIba,tmVrImpuBa,tmTarifaCup,tmVrImpuCup,tmNeto AS VrNeto
,K.IdUnd AS CdUnid,UM.Unidad AS UnidMed,K.VrPrecio,K.Unidades,K.Referencia,K.Referencia2,K.CdLocal AS KarCdLocal,LE.Localidad AS KarLocalidad,LE.IdDep AS KarCodDep,DE.Departamento AS KarDpto
,K.CdCCosto,CCosto,K.CdSubCos,SubCosto,ListaPrec,K.VrBruto,K.VrBase,K.Servcios,K.NoVentas,K.EsCombo,K.EsProdBase,K.ItemCombo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo
,G.IdLinea AS CdLinea,Linea,PM.CodBarras,DescripLong,DescripAbrv
,F.BaseImp,F.BaseRet,F.TarifaIva,F.TarifaRet,F.TarifaIca,F.TarifaRiv,F.TarifaRtc,F.TipPed,F.Pedido,F.IdCiaPed,F.TipRem,F.Remision,F.IdCiaRem,F.TipCot,F.Cotizacion,F.IdCiaCot,F.FecPedido
,F.IdVend AS NitVend,VN.RazonSocial AS Vendedor,F.TarifaCom,F.pVehiculo AS PlacaVeh,F.CdConductor,TC.RazonSocial AS Conductor,NitEmpTrans,EmpTrans,DirEnvio,DiasEntraga,F.IdForma AS CdForma,FormaPago,DetallePago
,MulPlazos,F.IdPlazo AS CdPlazo,Plazo,NVmto,DiasPago,Modalidad,F.IdConcepto AS CdConcepto,Concepto,F.TipCom,F.Comprobante,F.IdCiaCom
,F.Observacion,F.NumDev,F.FecDev,F.TimeSys AS FechaCrea,F.FecUpdate AS FechaAct,F.IdCiaCrea,F.IdUsuario AS CdUsuario,Usuario
--Información del tercero
,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto
,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.TelMovil AS TercCelular,T.e_mail AS TercEmail,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.TipoCliente,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo
,Contrato,CLI.NContrato AS CliNumContrato
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia
,A.CdFntePago AS CdFuente,FuentePago,TipoZona,A.CodSicom
,V.Observacion AS VehObservacion,V.Descripcion AS VehDescripcion
FROM tm_FactNeto AS TF INNER JOIN Trn_Facturas AS F ON TF.tmTipFac=F.TipDoc AND TF.tmFactura=F.Factura AND TF.tmIdCia=F.IdCia
INNER JOIN Trn_Kardex AS K ON TF.tmTipFac=K.TipDoc AND TF.tmFactura=K.Documento AND TF.tmIdCia=K.IdCia AND TF.tmItem=K.Item
INNER JOIN Companias AS CN ON TF.tmIdCia=CN.IdCia INNER JOIN Terceros AS T ON F.IdCliente=T.IdTercero
INNER JOIN Agencias AS A ON F.IdAgencia=A.IdAgencia INNER JOIN adm_Usuarios AS U ON F.IdUsuario=U.IdUsuario
INNER JOIN Conceptos AS C ON F.IdConcepto=C.IdConcepto INNER JOIN Plazos AS PZ ON F.IdPlazo=PZ.IdPlazo
INNER JOIN Terceros AS VN ON F.IdVend=VN.IdTercero INNER JOIN Formaspago AS FP ON F.IdForma=FP.IdForma
INNER JOIN TercCliente AS CLI ON F.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
INNER JOIN ProdMcias AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea 
LEFT JOIN Terceros AS TC ON F.CdConductor=TC.IdTercero LEFT JOIN Vehiculos AS V ON F.pVehiculo=V.IdVehiculo 
LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
LEFT JOIN CentroCosto AS CC ON K.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON K.CdSubCos=SC.IdSubCos 
LEFT JOIN Localidades AS LE ON K.CdLocal=LE.IdLocal LEFT JOIN Departamentos AS DE ON LE.IdDep=DE.IdDep
WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItems]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ForItems] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCantidad,tmVrPrecio,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto
,tmVrBruto,tmDescripcion,tmServcios,tmListaPrec,tmCantDev,tmCantFact,tmCdOperario,tmComsOper,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM tm_ForItems
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItemsDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ForItemsDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,tmDescripcion,tmIdBodega,Bodega,tmCantidad,tmVrPrecio,tmListaPrec
,tmTarifaDct,tmVrDcto,tmTarifaIva,tmVrIva,((tmCantidad*tmVrPrecio)-tmVrDcto)+tmVrIva AS ValorTotal
,tmCdOperario,tmComsOper,tmServcios,tmCantDev,tmCantFact,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM tm_ForItems AS F INNER JOIN Bodegas AS B ON F.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItemsItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ForItemsItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM 
 FROM tm_ForItems
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ForItemsTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ForItemsTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCOUNT,SUM(tmCantidad) AS SCANT,SUM(tmCantidad*tmVrPrecio) AS SSUBTOT
,SUM(tmVrIva) AS SVALIVA,SUM(tmVrDcto) AS SVALDCT,SUM(tmVrBruto) AS SVALBRU
,SUM(tmCantDev) AS SCANTDEV,SUM(tmCantFact) AS SCANTFACT
,SUM(tmVrImpuBa*tmCantidad) AS STOTIMPBA,SUM(tmVrImpCup*tmCantidad) AS STOTIMPCUP
 FROM tm_ForItems
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_GypVentas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_GypVentas] @pmtmEst CHAR(2)
 AS 
SELECT   tmItem, tmIdCia,Compania, tmTipo, tmConcepto, tmEnero, tmFebrero, tmMarzo, tmAbril, tmMayo, tmJunio
, tmJulio, tmAgosto, tmSeptiembre, tmOctubre,tmNoviembre, tmDiciembre
 FROM  tm_GypVentas AS GT  LEFT  JOIN Companias AS CN ON  GT.tmIdCia=CN.IdCia
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_InfDiarioDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_InfDiarioDet] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3)=Null
 AS 
 SELECT C.TipDoc AS CdTipDoc,TipoDoc,Numero,C.IdCia AS  CdCia,Compania,C.Fecha AS FechaDoc,C.IdTercero AS NitCliente,T.RazonSocial AS NomCliente
,C.IdAgencia AS Id_Agencia,Agencia,CodAgencia,nClieCon,Nombre,VrSubTotal,VrDescuento,VrImpuesto,C.VrImpCon,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VCargos,VrOtrosDctos,VrImpGlobal,VrSoldicom,VrCostos,VrNeto
,VrEfectivo,VrPagosOtr,VrCreditos,EnEfectivo,CdForma,NumForma,CdBanco,DetallePagos,C.IdConcepto AS CdConcepto,Concepto,Modalidad
,C.IdVend AS NitVend,V.RazonSocial AS Vendedor,TarifaCom,IdCajero,Usuario,U.IdEstacion AS CdEstacion,Estacion,C.IdLocal AS CdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CodDpto,DP.Departamento AS NomDpto
,C.Referencia AS Refrncia1,C.Referencia2 AS Refrncia2,TipRef,DocRef,IdCiaRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.TimeSys AS Fec_Add,tmItem
--DETALLES
,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,Unidades
,VrPrecio,K.TarifaIva AS KarTarifIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,K.TarifaRet AS KarTarifRet,VrReteEnt,VrReteSal,K.TarifaIca AS KarTarifIca,VrIcaEnt,VrIcaSal
,K.VrImpCon AS KarImpConsumo,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal,OtroImpto,VrUnitario,VrCostoEnt,VrCostoSal,VrCostProm,Descripcion,K.Referencia AS KarReferencia,Servcios,NoVentas,ListaPrec,VrBase,VrBruto,CdTanque
--productos
,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,FecUltcom,FecUltVta,Tanques
--Datos del cliente de contado
,CC.TipoId AS CliTipoId,CC.Dv AS CliDv,CC.IdLocal AS CliIdCiudad,LC.Localidad AS CliCiudad,LC.IdDep AS CliCodDpto,DC.Departamento AS CliDpto,CC.Telefono AS Clitelefono,email
 FROM tm_InfDiario AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON  C.IdTercero=T.IdTercero
 INNER JOIN Terceros AS V ON  C.IdVend=V.IdTercero INNER JOIN  Agencias  AS A ON C.IdAgencia=A.IdAgencia
 INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto 
 INNER JOIN adm_Usuarios AS U ON C.IdCajero=U.IdUsuario  INNER JOIN Sys_Estaciones AS ET ON U.IdEstacion =ET.IdEstacion
 INNER JOIN Localidades AS L ON C.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN Trn_Kardex AS K ON C.TipDoc=K.TipDoc AND C.Numero=K.Documento AND C.IdCia=K.IdCia
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN ClieContado AS CC ON C.nClieCon=CC.IdCliente  LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN Localidades AS LC ON CC.IdLocal=LC.IdLocal LEFT JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 WHERE tmEst=@pmtmEst  AND C.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 ORDER BY tmItem,C.TipDoc,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_InfDiarioFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_InfDiarioFor] @pmtmEst CHAR(2),@pmTipDoc VARCHAR(3)=Null
 AS 
 SELECT C.TipDoc AS CdTipDoc,TipoDoc,Numero,C.IdCia AS  CdCia,Compania,C.Fecha AS FechaDoc
,C.IdTercero AS NitCliente,RazonSocial,IdCajero,Usuario,U.IdEstacion AS CdEstacion,Estacion
,P.IdForma AS CodForma,FormaPago,P.IdBanco AS CdBanco,Banco,SUM(VrPagado) AS ValPagado,SUM(VrCambio) AS ValCambio
 FROM tm_InfDiario AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Terceros AS T ON  C.IdTercero=T.IdTercero
 INNER JOIN adm_Usuarios AS U ON C.IdCajero=U.IdUsuario  INNER JOIN Sys_Estaciones AS ET ON U.IdEstacion =ET.IdEstacion
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN Trn_Pagos AS P ON C.TipDoc=P.TipDoc AND C.Numero=P.Documento AND C.IdCia=P.IdCia
 LEFT JOIN Formaspago AS FP ON P.IdForma=FP.IdForma  LEFT JOIN Bancos AS BF ON P.IdBanco=BF.IdBanco
 WHERE tmEst=@pmtmEst  AND C.TipDoc LIKE ISNULL(@pmTipDoc,'%')
 GROUP BY  C.TipDoc,TipoDoc,Numero,C.IdCia,Compania,C.Fecha,C.IdTercero,RazonSocial,IdCajero,Usuario,U.IdEstacion,Estacion
,P.IdForma,FormaPago,P.IdBanco,Banco
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Ingresos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Ingresos] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmNMes,tmIdConcepto,tmDetalle,tmCantDevg,tmVrDevngado,tmCantDed,tmVrDeducido,tmVrBase,tmTarifa,tmBaseRet,tmClaseLiq
,tmOrigenLiq,tmFecInicial,tmFecFinal,tmDiasBase,tmDiasNoRem,tmIdNom,TipoNomina,tmIdDep,Dependencia,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdInstala,Instlacion,tmVrSalario,tmpVehiculo
,Concepto,ClaseCon,CN.Tarifa AS TrfaDft,tmCodFondo,tmEsRetiro,tmNPrestamo,tmItem
--datos del empleado
,E.Codigo,E.TipoId,E.IdLugarCed,LC.Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,VvdaPropia,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,IdFonCes,FC.Fondo AS FondoCes,Sexo,FecNacmto,IdEstCivil,EstCivil,NHijos,Conyugue,TipoSangre,FactorRh,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
,EsCondtor,pVehiculo,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,FecUltCes,FecUltPri,FecUltVac,E.IdLocal AS EmpIdLocal,L.Localidad AS NomCiudad,L.IdDep AS CodDpto,DT.Departamento AS NombreDpto,DT.IdPais,PA.NombrePais
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecVigencia,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.TipoLiquida AS TipLiq,C.IdJornada AS CodJnada,Jornada,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie
,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,TipoTrabj,IdCot,ModPromdio,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,ModoRet,FecAfiSeg,DenyCes,DenyPri,DenyVac,BasePrest,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdUsuario AS Con_IdUsuari,Usuario
 FROM tm_Ingresos AS TI INNER JOIN Empleados AS E ON TI.tmIdEmpleado=E.IdEmpleado  INNER JOIN NomConceptos AS CN ON TI.tmIdConcepto=CN.IdConcepto
 INNER JOIN Emp_Contrato AS C ON TI.tmNContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON TI.tmIdDep=DP.IdDep INNER JOIN Instalaciones AS I ON TI.tmIdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON TI.tmIdCCosto=CO.IdCCosto INNER JOIN SubCentros AS SC ON TI.tmIdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON TI.tmIdNom=TN.IdNom
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN Fondos AS FC ON E.IdFonCes=FC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar INNER JOIN Localidades AS LC ON E.IdLugarCed=LC.IdLocal
 INNER JOIN EstadoCiv AS EV ON E.IdEstCivil=EV.IdEstado INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 INNER JOIN Localidades AS L ON E.IdLocal=L.IdLocal INNER JOIN Departamentos AS DT ON L.IdDep=DT.IdDep
 INNER JOIN adm_Paises AS PA ON DT.IdPais=PA.IdPais
 WHERE tmEst=@pmtmEst
 ORDER BY Apellidos,Nombres,tmNMes,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntAhorro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_IntAhorro] @pmtmEst CHAR(2),@pmtmIdVehiculo VARCHAR(10)=Null,@pmtmIdTercero VARCHAR(16)=Null,@pmtmNmes INT=Null
 AS
 SELECT  tmEst, tmItem, tmIdVehiculo, tmIdTercero, tmSaldoBase, tmTasa, tmValor, tmNmes, tmVehPropio, tmIdConductor
, tmIdPropietario, tmConductor,tmTercero,tmRetencion,tmVrAbono
 FROM   tm_IntAhorro
 WHERE tmEst=@pmtmEst AND tmIdVehiculo LIKE ISNULL(@pmtmIdVehiculo,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND (tmNmes>=ISNULL(@pmtmNmes,0)  AND tmNmes<=ISNULL(@pmtmNmes,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntAhorroLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_IntAhorroLta] @pmtmEst CHAR(2)
 AS
 SELECT  tmItem, tmIdVehiculo,NumVeh,tmIdTercero,tmTercero,tmSaldoBase,tmVrAbono, tmTasa, tmValor
, tmNmes,tmVehPropio, tmIdConductor,tmConductor, tmIdPropietario
 FROM   tm_IntAhorro AS T INNER JOIN  Vehiculos AS V ON T.tmIdVehiculo=V.IdVehiculo
 WHERE tmEst=@pmtmEst 
 ORDER BY tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntAhorroVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_IntAhorroVeh] @pmtmEst CHAR(2)
 AS
 SELECT tmIdVehiculo,tmNmes,tmSaldoBase,tmTasa, tmValor,tmIdTercero,tmTercero,tmIdPropietario
,tmIdConductor,tmConductor,tmVehPropio,tmItem,tmRetencion,tmVrAbono
 FROM   tm_IntAhorro
 WHERE tmEst=@pmtmEst
 ORDER BY tmIdVehiculo,tmNmes,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntNomina]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_IntNomina] @pmtmEst CHAR(2),@pmtmIdVehiculo VARCHAR(10),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmEst,tmItem,tmIdVehiculo,tmIdEmpleado,tmIdConductor,tmIdPropietario,tmVehPropio,tmConductor,tmTercero,tmCcosto,tmValorAbono
 FROM tm_IntNomina
 WHERE tmEst=@pmtmEst AND tmIdVehiculo=@pmtmIdVehiculo AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_IntNominaVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_IntNominaVeh] @pmtmEst CHAR(2)
 AS 
 SELECT tmEst,tmItem,tmIdVehiculo,tmIdEmpleado,tmIdConductor,tmIdPropietario,tmVehPropio,tmConductor,tmTercero,tmCcosto,tmValorAbono
 FROM tm_IntNomina
 WHERE tmEst=@pmtmEst 
 ORDER BY tmIdVehiculo,tmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KarUbi] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmLinea INT=Null
,@pmtmIdProducto VARCHAR(16)=Null,@pmtmIdBodega VARCHAR(4)=Null,@pmtmIdUbic VARCHAR(10)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmIdUbic,tmEntradas,tmSalidas,tmLinea,tmCdNueBod,tmCdNueUbic
 FROM tm_KarUbi
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND tmIdUbic LIKE ISNULL(@pmtmIdUbic,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647)) 
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KarUbiID] @pmtmNumero VARCHAR(5)
 AS 
 SELECT  MAX(tmItem) AS MXITM
 FROM tm_KarUbi
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KarUbiPro] @pmtmNumero VARCHAR(5),@pmtmLinea INT=Null
,@pmtmIdProducto VARCHAR(16)=Null,@pmtmIdBodega VARCHAR(4)=Null,@pmtmIdUbic VARCHAR(10)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmIdUbic,tmEntradas,tmSalidas,tmLinea,tmCdNueBod,tmCdNueUbic
,DescripProd,Seriales,Lotes,Combo,Tanques,TipoRef
 FROM tm_KarUbi AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND TipoRef<>'SERVICIO' AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')  AND tmIdUbic LIKE ISNULL(@pmtmIdUbic,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
 ORDER BY tmIdProducto,tmIdBodega,tmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KarUbiSal] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdUbic,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_KarUbi AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND TipoRef<>'SERVICIO'  AND Tanques=0
 GROUP BY  tmIdProducto,DescripProd,tmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KarUbiTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KarUbiTot] @pmtmNumero VARCHAR(5),@pmtmLinea INT=Null
,@pmtmIdProducto VARCHAR(16)=Null,@pmtmIdBodega VARCHAR(4)=Null,@pmtmIdUbic VARCHAR(10)=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_KarUbi
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND tmIdUbic LIKE ISNULL(@pmtmIdUbic,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Kdex]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Kdex] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb
,tmTipDoc,tmDocumento,tmIdCia,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad
,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo
,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup
,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexAju]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexAju] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmEntradas+tmSalidas AS Cant,tmVrUnitario
,(tmEntradas+tmSalidas)*tmVrUnitario AS VrTotal,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion
,tmCdCCosto,tmCdSubCos,tmVrBruto,tmVrBase,tmNumLote,tmFecVceLote,Tanques
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexBga]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexBga] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)
,@pmtmIdBodega VARCHAR(4),@pmtmComptmntos VARCHAR(50),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmVrUnitario,tmVrPrecio
,tmItemCbo,tmComptmntos,tmCdProdEquiv
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmSalidas>0 AND tmIdProducto=@pmtmIdProducto
 AND tmIdBodega=@pmtmIdBodega AND tmComptmntos=@pmtmComptmntos
 AND tmItem<>@pmtmItem
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexCc] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCodTarIca,tmCodTarRet,tmCodTarIat,tmCodTarBom
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexCom] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrBruto,tmVrDcto,tmReferencia,tmCdProdEquiv,tmUnidades,tmServcios,tmEsCombo,tmEsProdBase,tmItemCbo,tmCdSubgrupo
,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend
,tmComision,tmCdOperario,tmComisnOper,tmCodTarCom,tmCodTarCmc,tmCantObseq
--variables de ProMcias
,DescripProd,TipoRef,IdSubgrupo,IdBodega,IdUbic,VrCostAnt,VrCosto,VrCostPmd,ExtciaMin,ExtciaMax,ExtciaAct
,Seriales,Lotes,Combo,Tanques,IvaDetCombo,LtaBaseIva
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND Combo<>0 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDcom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDcom] @pmtmNumero VARCHAR(5),@pmtmRemision INT,@pmtmIdCiaRem CHAR(2)
,@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4)
 AS 
 SELECT  SUM(tmEntradas) AS SCANENT,SUM(tmSalidas) AS SCANSAL
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmRemision=@pmtmRemision AND tmIdCiaRem=@pmtmIdCiaRem
 AND tmIdProducto=@pmtmIdProducto AND tmIdBodega=@pmtmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDet] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp
,tmDensidad,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq
,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom
--variables de productos
,DescripProd,TipoRef,IdSubgrupo,Seriales,Lotes,Combo,Tanques
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 WHERE  tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDetC]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDetC] @pmtmNumero VARCHAR(5)
 AS 
--traslado de productos combos
 SELECT tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmRec_Costo,tmMgenCont,tmCotizacion,tmCiaCotiza,tmVrImvCosto
,tmTarifaIco,tmVrImpCon,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmIngCombo,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup
,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom,tmgalsbruto,tmTemperatura,tmUmTemp,tmDensidad
--variables de productos
,DescripProd,TipoRef,IdSubgrupo,Seriales,Lotes,Combo,Tanques
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 WHERE  tmNumero=@pmtmNumero AND tmEsCombo<>0 AND Combo<>0 AND TipoRef<>'SERVICIO'
 AND  tmEsProdBase=0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDfo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDfo] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmEntradas,tmVrPrecio,tmTarifaDct,tmVrDcto
,(tmVrPrecio*tmEntradas)-tmVrDcto AS SubTotal,tmTarifaIva,tmVrIva,((tmVrPrecio*tmEntradas)-tmVrDcto)+tmVrIva AS ValorTotal
,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmTarifaIco,tmVrImpCon,tmVrUnitario,tmVrUnitario*tmEntradas AS CostoTotal,tmVrBruto,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion
,tmIdVend,tmComision,tmCdCCosto,tmCdSubCos,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet
,tmCodTarCom,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmServcios,Tanques,tmCdTanque,tmEsCombo,tmEsProdBase,tmItemCbo,tmCantObseq,tmIvaObseq
,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDve]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDve] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,tmCdTanque,tmSalidas,tmVrPrecio,tmTarifaDct,tmVrDcto,tmVrUnitario
,(tmSalidas*tmVrPrecio)-tmVrDcto AS VrTotal,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmImpGlobal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom
,tmUnidades,Bodega,tmReferencia,tmDescripcion,tmCdCCosto,tmCdSubCos,tmNumLote,tmFecVceLote,tmCodTarDct,tmCodTarRet,tmCodTarIca
,tmServcios,Tanques,tmTipDoc,tmDocumento,tmIdCia,tmNumInicial,tmVrImvCosto,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb
,tmTarifaIco,tmVrImpCon,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDvf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDvf] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmEntradas,tmVrPrecio,tmTarifaDct,tmVrDcto
,(tmVrPrecio*tmEntradas)-tmVrDcto AS SubTotal,tmTarifaIva,tmVrIva,((tmVrPrecio*tmEntradas)-tmVrDcto)+tmVrIva AS ValorTotal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmTarifaIat,tmVrAviTab,tmTarifaBom,tmVrSobBom
,tmTarifaIco,tmVrImpCon,tmVrUnitario,tmVrUnitario*tmEntradas AS CostoTotal,tmVrBruto,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion
,tmIdVend,tmComision,tmCdCCosto,tmCdSubCos,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarIat,tmCodTarBom,tmCodTarRet,tmCodTarCom,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb
,tmServcios,Tanques,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmCdAgencia,tmCantObseq,tmIvaObseq,tmBaseIvp,tmTarifaIvp,tmIvaIngProd
,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexDvs]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexDvs] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmEntradas,tmVrUnitario,tmEntradas*tmVrUnitario AS CostoTotal
,tmVrPrecio,tmEntradas*tmVrPrecio AS ValorTotal,tmUnidades,tmReferencia,tmDescripcion,tmCdCCosto,tmCdSubCos,tmpVehiculo
,tmNumLote,tmFecVceLote,tmEsCombo,tmServcios,Tanques,tmTipDoc,tmDocumento,tmIdCia,tmVrImvCosto,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero  AND  tmEsProdBase=0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexEnt] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmEntradas,tmVrPrecio,tmTarifaDct,tmVrDcto,tmVrUnitario
,(tmEntradas*tmVrPrecio)-tmVrDcto AS VrTotal,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmImpGlobal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmUnidades,tmReferencia,tmDescripcion,tmCdCCosto,tmCdSubCos,tmNumLote,tmFecVceLote,tmCodTarDct,tmCodTarRet,tmCodTarIca
,tmTipDoc,tmDocumento,tmIdCia,tmServcios,Tanques,tmNumInicial,tmVrImvCosto,tmCantObseq,tmIvaObseq,tmIvaComb,tmImpCarb,tmTarifaIco,tmVrImpCon
,tmTarifaStc,tmSobtasaCons,tmCodTarIco,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmItemCbo,tmMgenCont,tmRec_Costo,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexFco]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexFco] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmSalidas,tmVrPrecio,tmListaPrec,tmTarifaDct,tmVrDcto,tmTarifaIva,tmTarifaIco
,((tmVrPrecio*tmSalidas)-tmVrDcto)+tmVrIva+tmVrImpCon AS ValorTotal,((tmVrPrecio*tmSalidas)-tmVrDcto)+tmVrIva AS ValorNeto
,tmVrIva,tmVrImpCon,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmTarifaIat,tmVrAviTab,tmTarifaBom,tmVrSobBom
,tmUnidades,tmIdUnd,Unidad,tmIdBodega,Bodega,tmReferencia,tmDescripcion,tmVrBruto,tmVrUnitario,tmVrUnitario*tmSalidas AS CostoTotal
,tmIdVend,tmComision,tmCodTarDct,tmCodTarIva,tmCodTarRet,tmCodTarIca,tmCodTarIat,tmCodTarBom,tmCodTarCom,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmServcios,Tanques,tmCdTanque
,tmEsCombo,tmEsProdBase,tmItemCbo,tmTipDoc,tmDocumento,tmIdCia,tmCdOperario,tmComisnOper,tmCodTarCmc,tmpVehiculo,tmRec_Costo,tmCantObseq,tmIvaObseq
,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexFcr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexFcr] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmSalidas,tmVrPrecio,tmTarifaDct,tmVrDcto
,(tmVrPrecio*tmSalidas)-tmVrDcto AS SubTotal,tmTarifaIva,tmVrIva,tmTarifaIco,tmVrImpCon
,((tmVrPrecio*tmSalidas)-tmVrDcto)+tmVrIva AS ValorTotal,((tmVrPrecio*tmSalidas)-tmVrDcto)+tmVrIva+tmVrImpCon AS ValorNeto
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmTarifaIat,tmVrAviTab,tmTarifaBom,tmVrSobBom
,tmVrUnitario,tmVrUnitario*tmSalidas AS CostoTotal,tmVrBruto,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion
,tmIdVend,tmComision,tmCdOperario,tmComisnOper,tmNumLote,tmFechLote,tmFecVceLote,tmCdCCosto,tmCdSubCos,tmComptmntos
,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarIat,tmCodTarBom,tmCodTarRet,tmCodTarCom,tmCodTarCmc,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb
,tmServcios,Tanques,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo,tmTipDoc,tmDocumento,tmIdCia
,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden,tmCdAgencia,tmRec_Costo,tmMgenCont,tmIvaComb,tmImpCarb
,tmCantObseq,tmIvaObseq,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGBod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexGBod] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdProducto,DescripProd,ExtciaAct,tmIdBodega,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
--entradas con flete al costo
,SUM(tmEntradas*(tmVrUnitario+tmNumInicial)) AS SCOSENTFLE
,SUM(tmSalidas*(tmVrUnitario+tmNumInicial)) AS SCOSSALFLE
,SUM(tmCantObseq) AS CANTOBSEQ
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND TipoRef<>'SERVICIO'
 GROUP BY  tmIdProducto,DescripProd,ExtciaAct,tmIdBodega 
 ORDER BY tmIdProducto,tmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGord]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexGord] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipDoc,tmDocumento,tmIdCia,tmIdProducto,DescripProd
,SUM(tmEntradas) AS STOTENT,SUM(tmSalidas) AS STOTSAL
 FROM tm_Kdex AS T INNER JOIN ProdMcias AS P ON  T.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND TipoRef<>'SERVICIO' AND tmDocumento>0
 GROUP BY  tmTipDoc,tmDocumento,tmIdCia,tmIdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGpro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexGpro] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdProducto,DescripProd,SUM(tmEntradas) AS STOTENT,SUM(tmSalidas) AS STOTSAL
 FROM tm_Kdex AS T INNER JOIN ProdMcias AS P ON  T.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND TipoRef<>'SERVICIO'
 GROUP BY  tmIdProducto,DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGtan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexGtan] @pmtmNumero VARCHAR(5)
 AS 
 SELECT  tmCdTanque,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND Tanques<>0 AND tmServcios=0 AND tmEsCombo=0
 GROUP BY tmCdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexGui]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexGui] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmCdTanque,tmSalidas,tmVrPrecio,tmSalidas*tmVrPrecio AS VrSubTotal
,tmIvaComb*tmSalidas AS BaseIva,tmTarifaIva,tmVrIva,tmBaseIvp*tmSalidas AS BaseIngProd,tmTarifaIvp,tmIvaIngProd
,((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva+tmIvaIngProd AS VrTotal,tmComptmntos,tmSobretasa,tmImpGlobal,tmSoldicom
,tmTasaNac,tmTasaDep,tmTasaMun,tmImpCarb,tmRec_Costo,tmMgenCont,tmgalsbruto,tmgalsneto,tmTemperatura,tmUmTemp,tmDensidad
,tmUnidades,tmDescripcion,tmReferencia,tmReferencia2,tmListaPrec,tmVrBruto,tmVrUnitario,tmVrBase,tmServcios,Tanques,tmEsCombo
,tmCdMoneda,tmVrTasaCamb,tmCdLocal,tmIdVend,tmComision,tmCodTarCom,tmpVehiculo,tmIdBodega,tmIvaComb,tmBaseIvp
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
-- INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexID] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexIen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexIen] @pmtmNumero VARCHAR(5),@pmtmItemCbo INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas
,tmVrUnitario,tmVrPrecio,tmComptmntos,tmCdProdEquiv
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmEntradas>0 AND tmItemCbo=@pmtmItemCbo
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexIns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexIns] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmRemision,tmIdCiaRem,tmIdProducto,DescripProd,tmIdBodega
,SUM(tmSalidas) AS STOTSAL,MAX(tmVrUnitario) AS SVALUNIT
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmTipRem='COM' AND tmRemision>0
 GROUP BY tmRemision,tmIdCiaRem,tmIdProducto,DescripProd,tmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexItm] @pmtmNumero VARCHAR(5),@pmtmItem INT
,@pmtmIdProducto VARCHAR(16)=Null,@pmtmEsProdBase INT=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 AND (tmEsProdBase>=ISNULL(@pmtmEsProdBase,0)  AND tmEsProdBase<=ISNULL(@pmtmEsProdBase,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexItn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexItn] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
--items notas de traslado
 AS 
 SELECT COUNT(tmItem) AS SCANT
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmSalidas>0
 AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexLot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexLot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmDescripcion,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmUnidades,tmCdProdEquiv,DescripProd,tmCantObseq
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero  AND Lotes<>0
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,Unidad
,tmVrUnitario,tmVrPrecio,tmVrCostProm,tmVrProm,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
,tmCdOperario,tmComisnOper,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal
,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmImpCarb,tmOtroImpto,tmIvaComb,tmUnidades,tmServcios,tmNoVentas
,tmEsCombo,tmEsProdBase,tmItemCbo,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
,tmCdSubgrupo,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTarifaIba,tmVrImpuBa,tmCodTarBa,tmTarifaCup,tmVrImpCup,tmCodTarCup
,tmTarifaIat,tmVrAviTab,tmCodTarIat,tmTarifaBom,tmVrSobBom,tmCodTarBom,tmTipDoc,tmDocumento,tmIdCia,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden
,TipoRef,Seriales,Lotes,Combo,Tanques
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE tmNumero=@pmtmNumero 
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexMng]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexMng] @pmtmNumero VARCHAR(5),@pmtmCdMngra VARCHAR(10),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmCdMngra
,tmNumInicial,tmNumFinal,tmVrUnitario,tmVrPrecio
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmCdMngra=@pmtmCdMngra
 AND tmItem<>@pmtmItem
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNpr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexNpr] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmEntradas,tmSalidas,tmVrUnitario
,(tmEntradas+tmSalidas)*tmVrUnitario AS CostoTotal,tmVrPrecio,(tmEntradas+tmSalidas)*tmVrPrecio AS ValorTotal
,tmIdUnd,Unidad,tmUnidades,tmReferencia,tmDescripcion,tmCdCCosto,tmCdSubCos,tmNumLote,tmFecVceLote
,tmCdUbic,tmVrBruto,tmServcios,Tanques,tmCdTanque
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNts]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexNts] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmComptmntos,tmSalidas,tmVrUnitario
,tmSalidas*tmVrUnitario AS VrTotal,tmCdProdEquiv,tmUnidades,tmIdUnd,Unidad
,tmReferencia,tmDescripcion,tmCdCCosto,tmCdSubCos,tmNumLote,tmFecVceLote,Tanques,tmTipDoc,tmDocumento,tmIdCia,tmItemCbo
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmSalidas>0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNtsal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexNtsal] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmIdUnd,tmVrUnitario,tmVrPrecio,tmVrCostProm
,tmVrProm,tmTarifaIva,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos
,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmCdOperario,tmReferencia,tmDescripcion,tmComptmntos,tmCdProdEquiv
,tmUnidades,tmServcios,tmNoVentas,tmEsProdBase,tmItemCbo,tmCdSubgrupo
,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia
,DescripProd,TipoRef,IdSubgrupo,IdBodega,IdUbic,VrCostAnt,VrCosto,VrCostPmd,ExtciaMin,ExtciaMax,ExtciaAct
,Seriales,Lotes,Combo,Tanques,Tallaje
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmSalidas>0
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexNum] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmCdTanque,tmCdMngra,tmNumInicial,tmNumFinal,tmSalidas,tmEntradas,tmServcios
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND Tanques<>0
 ORDER BY  tmCdMngra
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexOcc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexOcc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmCdTanque,tmSalidas,tmVrPrecio,(tmSalidas*tmVrPrecio)-tmVrDcto AS VrSubTotal
,tmIvaComb*tmSalidas AS BaseIva,tmTarifaIva,tmVrIva,tmBaseIvp*tmSalidas AS BaseIngProd,tmTarifaIvp,tmIvaIngProd
,((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva+tmIvaIngProd AS VrTotal,tmComptmntos,tmSobretasa,tmImpGlobal,tmSoldicom
,tmTasaNac,tmTasaDep,tmTasaMun,tmImpCarb,tmRec_Costo,tmMgenCont,tmUnidades,tmReferencia,tmDescripcion,tmListaPrec,tmVrBruto,tmVrUnitario,tmVrBase
,tmServcios,Tanques,tmEsCombo,tmCdMoneda,tmVrTasaCamb,tmCdLocal,tmIdVend,tmComision,tmCodTarCom,tmpVehiculo
,tmReferencia2,tmIdBodega,tmIvaComb,tmBaseIvp
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 --INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexOdc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexOdc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,tmCdTanque,tmEntradas,tmVrPrecio,tmTarifaDct,tmVrDcto,tmVrUnitario
,(tmEntradas*tmVrPrecio)-tmVrDcto AS VrTotal,tmTarifaIva,tmVrIva,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca,tmUnidades,Bodega,tmReferencia,tmDescripcion,tmImpGlobal,tmSobretasa
,tmCdCCosto,tmCdSubCos,tmpVehiculo,tmCodTarDct,tmCodTarRet,tmCodTarIca,tmServcios,Tanques,tmTipDoc,tmDocumento,tmIdCia,tmItemCbo AS ItemReq,tmVrImvCosto
,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexOrd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexOrd] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipDoc,tmDocumento,tmIdCia,tmTipRem,tmRemision,tmIdCiaRem,count(tmItem) AS CantItm
,SUM(CASE tmNoVentas WHEN -1 THEN 1 ELSE 0 END) AS SODCCIE
,SUM(CASE WHEN tmNoVentas>=0 AND tmServcios=0 THEN 1 ELSE 0 END) AS SODCNOCIE
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND (tmDocumento>0 OR tmRemision>0)
 GROUP BY  tmTipDoc,tmDocumento,tmIdCia,tmTipRem,tmRemision,tmIdCiaRem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexParc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexParc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmVrUnitario
,tmVrPrecio,tmVrCostProm,tmVrProm,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmDescripcion,tmReferencia
,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo
,tmCdSubgrupo,tmComptmntos
,DescripProd,TipoRef,IdSubgrupo,IdBodega,IdUbic,VrCostAnt,VrCosto,VrCostPmd,ExtciaMin,ExtciaMax,ExtciaAct
,Seriales,Lotes,Combo,Tanques
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY tmIdProducto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPas] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmCdMngra,tmCdTanque,tmIdProducto,DescripProd,tmEntradas,tmVrPrecio,tmVrPrecio*tmEntradas AS SubTotal
,tmSobretasa,tmEntradas*tmSobretasa AS TotSobTasa,tmSoldicom,tmEntradas*tmSoldicom AS TotSoldicom,tmImpGlobal,tmEntradas*tmImpGlobal AS TotIGlobal
,(tmVrPrecio*tmEntradas)+(tmEntradas*tmSobretasa)+(tmEntradas*tmSoldicom)+(tmEntradas*tmImpGlobal) AS ValorTotal,tmVrUnitario,tmVrUnitario*tmEntradas AS CostoTotal
,tmVrBruto,tmVrPrecio+tmSobretasa+tmSoldicom+tmImpGlobal+tmVrIva AS PrecioPub,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion,tmIdBodega,Bodega,tmTarifaDct,tmVrDcto,tmTarifaIva,tmVrIva
,tmTasaNac,tmTasaDep,tmTasaMun,tmIdVend,tmComision,tmCodTarDct,tmCodTarIva,tmCodTarCom,tmListaPrec,tmVrBase,tmServcios,Tanques,tmNumInicial,tmNumFinal
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPdc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPdc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmCdTanque,tmSalidas,tmVrPrecio,tmTarifaDct,tmVrDcto,(tmSalidas*tmVrPrecio)-tmVrDcto AS VrSubTotal
,tmIvaComb*tmSalidas AS BaseIva,tmTarifaIva,tmVrIva,tmBaseIvp*tmSalidas AS BaseIngProd,tmTarifaIvp,tmIvaIngProd,((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva+tmIvaIngProd AS VrTotal
,tmComptmntos,tmSobretasa,tmImpGlobal,tmSoldicom,tmTasaNac,tmTasaDep,tmTasaMun,tmImpCarb,tmRec_Costo,tmMgenCont,tmVrBruto,tmListaPrec
,tmUnidades,tmReferencia,tmDescripcion,tmCodTarDct,tmIdVend,tmComision,tmCodTarCom,tmCdOperario,tmComisnOper,tmCodTarCmc,tmServcios,Tanques,tmVrUnitario,tmVrBase
,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia,tmIdBodega,tmpVehiculo,tmIvaComb,tmBaseIvp,tmCantObseq,tmIvaObseq
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 --INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPed] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmSalidas,tmVrPrecio,tmTarifaDct,tmVrDcto,(tmSalidas*tmVrPrecio)-tmVrDcto AS VrSubTotal
,tmTarifaIva,tmVrIva,((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva AS VrTotal,tmComptmntos,tmSobretasa,tmImpGlobal,tmSoldicom,tmTasaNac,tmTasaDep,tmTasaMun
,tmVrBruto,tmListaPrec,tmUnidades,tmReferencia,tmDescripcion,tmCodTarDct
,tmIdVend,tmComision,tmCodTarCom,tmServcios,Tanques,tmVrUnitario,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia,tmRec_Costo,tmMgenCont
,tmIvaComb,tmImpCarb,tmCdOperario,tmComisnOper,tmCodTarCmc,tmpVehiculo,tmBaseIvp,tmTarifaIvp,tmIvaIngProd,tmItemCbo,tmCantObseq,tmIvaObseq
,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 WHERE  tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPla] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmCdMngra,tmCdTanque,tmIdProducto,DescripProd,tmNumInicial,tmNumFinal,tmSalidas,tmVrPrecio,(tmVrPrecio*tmSalidas)-tmVrDcto AS SubTotal
,tmSobretasa,tmSalidas*tmSobretasa AS TotSobTasa,tmSoldicom,tmSalidas*tmSoldicom AS TotSoldicom,tmImpGlobal,tmSalidas*tmImpGlobal AS TotIGlobal
,((tmVrPrecio*tmSalidas)-tmVrDcto)+tmVrIva+(tmSalidas*tmSobretasa)+(tmSalidas*tmSoldicom)+(tmSalidas*tmImpGlobal) AS ValorTotal,tmVrUnitario,tmVrUnitario*tmSalidas AS CostoTotal
,tmVrBruto,tmVrPrecio+tmSobretasa+tmSoldicom+tmImpGlobal+tmVrIva AS PrecioPub,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion,tmIdBodega,Bodega,tmTarifaDct,tmVrDcto,tmTarifaIva,tmVrIva
,tmTasaNac,tmTasaDep,tmTasaMun,tmIdVend,tmComision,tmCodTarDct,tmCodTarIva,tmCodTarCom,tmListaPrec,tmVrBase,tmServcios,Tanques
FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPnp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPnp] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)
,@pmtmItem INT,@pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='ENT'
  SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
  FROM tm_Kdex 
  WHERE tmNumero=@pmtmNumero AND tmIdProducto=@pmtmIdProducto  AND tmEntradas>0
  AND tmItem<>@pmtmItem
 ELSE
  SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
  FROM tm_Kdex 
  WHERE tmNumero=@pmtmNumero AND tmIdProducto=@pmtmIdProducto  AND tmSalidas>0
  AND tmItem<>@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPro] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmVrUnitario
,tmVrPrecio,tmVrCostProm,tmVrProm,tmVrBruto,tmCdUbic,tmNumLote,tmFechLote,tmFecVceLote,tmDescripcion,tmReferencia
,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo
,tmCdSubgrupo,tmComptmntos,tmCantObseq,tmIvaObseq,tmOtroImpto AS AjuCostoDve,tmVrImpuBa,tmVrImpCup
--variables de ProMcias
,DescripProd,TipoRef,IdSubgrupo,IdBodega,IdUbic,VrCostAnt,VrCosto,VrCostPmd,ExtciaMin,ExtciaMax,ExtciaAct
,Seriales,Lotes,Combo,Tanques,Tallaje
--,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDcto,tmTarifaRet,tmVrRete,tmTarifaIca,tmVrIca
--,tmIdTercero,tmCdAgencia,tmCdCCosto,tmCdSubCos,tmCdLocal,tmCdSzona,tmpVehiculo,tmIdVend,tmComision
--,tmCdOperario,tmComisnOper,
--,tmSobretasa,tmTasaNac,tmTasaDep,tmTasaMun,tmSoldicom,tmImpGlobal,tmOtroImpto,tmUnidades
--,tmCodTarDct,tmCodTarIva,tmCodTarIca,tmCodTarRet,tmCodTarCom,tmCodTarCmc
--,tmListaPrec,tmVrBase,tmCdMoneda,tmVrTasaCamb,tmTipDoc,tmDocumento,tmIdCia
--,tmTipRem,tmRemision,tmIdCiaRem,tmReferencia2,tmFecOrden
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 ORDER BY tmIdProducto,tmIdBodega,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexPrv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexPrv] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdProducto,tmVrUnitario,tmVrPrecio,tmVrProm,tmTarifaDct,tmCodTarDct,tmReferencia
,SUM(tmEntradas) AS Sent
 FROM   tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmServcios=0
 GROUP BY  tmIdProducto,tmVrUnitario,tmVrPrecio,tmVrProm,tmTarifaDct,tmCodTarDct,tmReferencia
 ORDER BY  tmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSai]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexSai] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmSalidas,tmVrUnitario,tmSalidas*tmVrUnitario AS CostoTotal
,tmRemision,tmIdCiaRem,tmTipDoc,tmDocumento,tmIdCia,tmIdUnd,Unidad,tmUnidades,tmReferencia,tmDescripcion
,tmCdCCosto,tmCdSubCos,tmIdTercero,tmIdVend,tmpVehiculo,tmVrPrecio,tmSalidas*tmVrPrecio AS VrTotal,tmTarifaIva,tmVrIva
,tmVrBruto,tmNumLote,tmFecVceLote,Tanques,tmServcios,tmEsCombo,tmCdTanque,tmVrImvCosto,tmItemCbo,tmgalsbruto,tmReferencia2
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexSal] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdTanque,tmSalidas,tmVrUnitario
,tmSalidas*tmVrUnitario AS CostoTotal,tmVrPrecio,tmSalidas*tmVrPrecio AS VrTotal,tmTarifaIva,tmVrIva
,tmUnidades,tmIdUnd,Unidad,tmReferencia,tmDescripcion,tmCdCCosto,tmCdSubCos,tmIdTercero,tmpVehiculo
,tmVrBruto,tmNumLote,tmFecVceLote,Tanques,tmServcios,tmEsCombo,tmTipDoc,tmDocumento,tmIdCia,tmRemision,tmIdCiaRem
,tmCotizacion AS ItemReq,tmVrImvCosto,tmCodTarBa,tmTarifaIba,tmVrImpuBa,tmCodTarCup,tmTarifaCup,tmVrImpCup
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto 
 INNER JOIN Bodegas AS B ON K.tmIdBodega=B.IdBodega
 LEFT JOIN UndMed AS U ON K.tmIdUnd=U.IdUnd
 WHERE  tmNumero=@pmtmNumero AND tmEsProdBase=0
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexSer] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmCdUbic,tmNumLote,tmFechLote
,tmFecVceLote,tmDescripcion,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmUnidades,tmCdProdEquiv,DescripProd,tmCantObseq
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero  AND Seriales<>0
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexSub] @pmtmNumero VARCHAR(5)
 AS 
 SELECT IdSubgrupo,tmIdProducto,DescripProd,TipoRef,Combo,tmEsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo
,COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmEntradas*tmImpGlobal) AS SGLOENT,SUM(tmSalidas*tmImpGlobal) AS SGLOSAL
,SUM(tmSobretasa*tmEntradas) AS SSOBENT,SUM(tmSobretasa*tmSalidas) AS SSOBSAL
,SUM(tmTasaNac*tmEntradas) AS SNACENT,SUM(tmTasaNac*tmSalidas) AS SNACSAL
,SUM(tmTasaDep*tmEntradas) AS SDEPENT,SUM(tmTasaDep*tmSalidas) AS SDEPSAL
,SUM(tmTasaMun*tmEntradas) AS SMUNENT,SUM(tmTasaMun*tmSalidas) AS SMUNSAL
,SUM(tmSoldicom*tmEntradas) AS SSOLENT,SUM(tmSoldicom*tmSalidas) AS SSOLSAL
,SUM(tmOtroImpto*tmEntradas) AS SOTRENT,SUM(tmOtroImpto*tmSalidas) AS SOTRSAL
--Para los ajustes con cantidad en cero (0)
,SUM(tmVrUnitario) AS SCOSAJU,SUM(tmOtroImpto) AS SDVEAJU
,SUM(tmRec_Costo*tmEntradas) AS SRCOSENT,SUM(tmRec_Costo*tmSalidas) AS SRCOSSAL
,SUM(tmMgenCont*tmEntradas) AS SMGENENT,SUM(tmMgenCont*tmSalidas) AS SMGENSAL
,SUM(tmVrImvCosto) AS SIMVCOS,SUM(tmVrImpCon) AS SVICO
,SUM(CASE WHEN tmCantObseq>0 THEN tmIvaObseq ELSE 0 END) AS SIVAOBSQ
,SUM(tmCantObseq*tmVrUnitario) AS SBASCOSOBSQ,SUM(tmCantObseq*tmVrPrecio) AS SBASEOBSQ
,SUM(tmIvaComb*tmEntradas) AS BASEIVAENT,SUM(tmIvaComb*tmSalidas) AS BASEIVASAL 
,SUM(tmImpCarb*tmEntradas) AS IMPCARBENT,SUM(tmImpCarb*tmSalidas) AS IMPCARBSAL 
,SUM(CASE WHEN (tmTarifaIva>0 AND P.TipoZonaFront='F') THEN ((tmEntradas*tmIvaComb)*tmTarifaIva)/100 ELSE 0 END) AS SIVAZFENT
,SUM(CASE WHEN (tmTarifaIva>0 AND P.TipoZonaFront='F') THEN ((tmSalidas*tmIvaComb)*tmTarifaIva)/100 ELSE 0 END) AS SIVAZFSAL
,SUM(CASE WHEN Combo=0 AND tmEsProdBase=1 THEN tmIvaComb ELSE 0 END) AS BASEIVACOM
,SUM(CASE WHEN Combo=1 AND IvaDetCombo=1 THEN tmIngCombo ELSE 0 END) AS INGBASECOM
,SUM(CASE WHEN Combo=0 AND tmEsProdBase=1 THEN tmIngCombo ELSE 0 END) AS SBASEING
,SUM(tmSobtasaCons) AS SOBTCON
,SUM(tmBaseIvp*tmEntradas) AS BASEIVPENT,SUM(tmBaseIvp*tmSalidas) AS BASEIVAING,SUM(tmIvaIngProd) AS SIVAINGP,MAX(tmTarifaIvp) AS TARIVAING
,SUM(tmVrImpuBa*(tmEntradas+tmSalidas+tmCantObseq)) AS SIMPUBA,SUM(tmVrImpCup*(tmEntradas+tmSalidas+tmCantObseq)) AS SIMPUCUP
,SUM(tmVrAviTab) AS SIAT,SUM(tmVrSobBom) AS SBOM,SUM(tmCantObseq) AS CANTOBSQ
FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero
 GROUP BY IdSubgrupo,tmIdProducto,DescripProd,TipoRef,Combo,tmEsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo
 ORDER BY IdSubgrupo,tmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSubc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexSubc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT IdSubgrupo,tmIdProducto,DescripProd
,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmEsCombo<>0 AND Combo<>0 AND TipoRef<>'SERVICIO'
 AND  tmEsProdBase=0
 GROUP BY IdSubgrupo,tmIdProducto,DescripProd
 ORDER BY IdSubgrupo,tmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexSubOpe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexSubOpe] @pmtmNumero VARCHAR(5)
 AS 
 SELECT IdSubgrupo,tmIdProducto,DescripProd,TipoRef,Combo,tmEsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo,tmCdOperario
,COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmEntradas*tmImpGlobal) AS SGLOENT,SUM(tmSalidas*tmImpGlobal) AS SGLOSAL
,SUM(tmSobretasa*tmEntradas) AS SSOBENT,SUM(tmSobretasa*tmSalidas) AS SSOBSAL
,SUM(tmTasaNac*tmEntradas) AS SNACENT,SUM(tmTasaNac*tmSalidas) AS SNACSAL
,SUM(tmTasaDep*tmEntradas) AS SDEPENT,SUM(tmTasaDep*tmSalidas) AS SDEPSAL
,SUM(tmTasaMun*tmEntradas) AS SMUNENT,SUM(tmTasaMun*tmSalidas) AS SMUNSAL
,SUM(tmSoldicom*tmEntradas) AS SSOLENT,SUM(tmSoldicom*tmSalidas) AS SSOLSAL
,SUM(tmOtroImpto*tmEntradas) AS SOTRENT,SUM(tmOtroImpto*tmSalidas) AS SOTRSAL
--Para los ajustes con cantidad en cero (0)
,SUM(tmVrUnitario) AS SCOSAJU,SUM(tmOtroImpto) AS SDVEAJU
,SUM(tmRec_Costo*tmEntradas) AS SRCOSENT,SUM(tmRec_Costo*tmSalidas) AS SRCOSSAL
,SUM(tmMgenCont*tmEntradas) AS SMGENENT,SUM(tmMgenCont*tmSalidas) AS SMGENSAL
,SUM(tmVrImvCosto) AS SIMVCOS,SUM(tmVrImpCon) AS SVICO
,SUM(CASE WHEN tmCantObseq>0 THEN tmIvaObseq ELSE 0 END) AS SIVAOBSQ
,SUM(tmCantObseq*tmVrUnitario) AS SBASCOSOBSQ,SUM(tmCantObseq*tmVrPrecio) AS SBASEOBSQ
,SUM(tmIvaComb*tmEntradas) AS BASEIVAENT,SUM(tmIvaComb*tmSalidas) AS BASEIVASAL 
,SUM(tmImpCarb*tmEntradas) AS IMPCARBENT,SUM(tmImpCarb*tmSalidas) AS IMPCARBSAL 
,SUM(CASE WHEN (tmTarifaIva>0 AND P.TipoZonaFront='F') THEN ((tmEntradas*tmIvaComb)*tmTarifaIva)/100 ELSE 0 END) AS SIVAZFENT
,SUM(CASE WHEN (tmTarifaIva>0 AND P.TipoZonaFront='F') THEN ((tmSalidas*tmIvaComb)*tmTarifaIva)/100 ELSE 0 END) AS SIVAZFSAL
,SUM(CASE WHEN Combo=0 AND tmEsProdBase=1 THEN tmIvaComb ELSE 0 END) AS BASEIVACOM
,SUM(CASE WHEN Combo=1 AND IvaDetCombo=1 THEN tmIngCombo ELSE 0 END) AS INGBASECOM
,SUM(CASE WHEN Combo=0 AND tmEsProdBase=1 THEN tmIngCombo ELSE 0 END) AS SBASEING
,SUM(tmSobtasaCons) AS SOBTCON,SUM(tmBaseIvp*tmEntradas) AS BASEIVPENT,SUM(tmBaseIvp*tmSalidas) AS BASEIVAING,SUM(tmIvaIngProd) AS SIVAINGP,MAX(tmTarifaIvp) AS TARIVAING
,SUM(tmVrImpuBa*(tmEntradas+tmSalidas+tmCantObseq)) AS SIMPUBA,SUM(tmVrImpCup*(tmEntradas+tmSalidas+tmCantObseq)) AS SIMPUCUP
,SUM(tmVrAviTab) AS SIAT,SUM(tmVrSobBom) AS SBOM,SUM(tmCantObseq) AS CANTOBSQ
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero
 GROUP BY IdSubgrupo,tmIdProducto,DescripProd,TipoRef,Combo,tmEsProdBase,IdProv,ExcluidoImp,Electrocomb,IvaDetCombo,tmCdOperario
 ORDER BY IdSubgrupo,tmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTAju]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTAju] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrUnitario) AS SCOSAJU
 FROM  tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmEntradas<=0 AND tmSalidas<=0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTan] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmVrUnitario
,tmVrPrecio,tmVrCostProm,tmVrProm,tmVrBruto,tmDescripcion,tmReferencia
,tmCdProdEquiv,tmCdMngra,tmNumInicial,tmNumFinal,tmServcios,tmNoVentas,tmEsCombo,tmEsProdBase,tmItemCbo
,tmCdSubgrupo,tmComptmntos
--variables de ProMcias
,DescripProd,TipoRef,IdSubgrupo,IdBodega,IdUbic,VrCostAnt,VrCosto,VrCostPmd,ExtciaMin,ExtciaMax,ExtciaAct
,Seriales,Lotes,Combo,Tanques
 FROM tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND Tanques<>0
 ORDER BY tmIdProducto,tmCdTanque,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTanq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTanq] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)
,@pmtmCdTanque VARCHAR(4),@pmtmComptmntos VARCHAR(50),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmIdBodega,tmCdTanque,tmEntradas,tmSalidas,tmVrUnitario,tmVrPrecio
,tmItemCbo,tmComptmntos,tmCdProdEquiv
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmSalidas>0 AND tmIdProducto=@pmtmIdProducto
 AND tmCdTanque=@pmtmCdTanque AND tmComptmntos=@pmtmComptmntos
 AND tmItem<>@pmtmItem
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTar] @pmtmNumero VARCHAR(5),@pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='IVA' 
  SELECT tmNumero,tmItem,tmIdProducto,tmCodTarIva,tmTarifaIva,tmVrIva
  FROM tm_Kdex
  WHERE tmNumero=@pmtmNumero  AND tmVrIva>0
 ELSE
  BEGIN
   IF @pmTipo='ICA' 
    SELECT tmNumero,tmItem,tmIdProducto,tmCodTarIca,tmTarifaIca,tmVrIca
    FROM tm_Kdex
    WHERE tmNumero=@pmtmNumero  AND tmVrIca>0
   ELSE
    SELECT tmNumero,tmItem,tmIdProducto,tmCodTarRet,tmTarifaRet,tmVrRete
    FROM tm_Kdex
    WHERE tmNumero=@pmtmNumero  AND tmVrRete>0
  END
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTBas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTBas] @pmtmNumero VARCHAR(5),@pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='IVA'
 BEGIN
  SELECT SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
 ,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
 ,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT
 ,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
 ,SUM(tmVrImvCosto) AS SIVAMVC,SUM(tmVrImpCon) AS SIMPCON,SUM(tmSobtasaCons) AS SSOBCON
  FROM  tm_Kdex
  WHERE tmNumero=@pmtmNumero AND tmVrIva>0
 END
 ELSE
   BEGIN
   IF @pmTipo='RET'
    BEGIN
     SELECT SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
     ,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
    ,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
    ,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
    ,SUM(tmVrImvCosto) AS SIVAMVC,SUM(tmVrImpCon) AS SIMPCON,SUM(tmSobtasaCons) AS SSOBCON
    FROM  tm_Kdex
    WHERE tmNumero=@pmtmNumero AND tmVrRete>0
   END
  ELSE
   BEGIN --ICA
     SELECT SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
     ,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
    ,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
    ,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
    ,SUM(tmVrImvCosto) AS SIVAMVC,SUM(tmVrImpCon) AS SIMPCON,SUM(tmSobtasaCons) AS SSOBCON
    FROM  tm_Kdex
    WHERE tmNumero=@pmtmNumero AND  tmVrIca>0
   END
 END
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTBod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTBod] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4)
,@pmtmItem INT
 AS 
 SELECT SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmIdProducto=@pmtmIdProducto
 AND tmItem<>@pmtmItem AND tmServcios=0
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmVrImvCosto) AS SIVAMVC,SUM(tmIvaObseq) AS SIVAOBSEQ
,SUM(tmVrImpCon) AS SIMPCON,SUM(tmSobtasaCons) AS SSOBCON
,SUM(tmVrImpuBa*(tmEntradas+tmSalidas+ISNULL(tmCantObseq,0))) AS SIMPUBA,SUM(tmVrImpCup*(tmEntradas+tmSalidas+ISNULL(tmCantObseq,0))) AS SIMPUCUP
 FROM  tm_Kdex
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotFac] @pmtmNumero VARCHAR(5)
 AS 
--totaliza el valor de ventas de la factura o salida, de los productos no combos
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmVrImpCon) AS SIMPCON,SUM(tmIvaObseq) AS SIVAOBSEQ,SUM(tmVrImvCosto) AS SIVAMVC
,SUM(tmVrImpuBa*(tmEntradas+tmSalidas+ISNULL(tmCantObseq,0)))AS SIMPUBA,SUM(tmVrImpCup*(tmEntradas+tmSalidas+ISNULL(tmCantObseq,0))) AS SIMPUCUP
,SUM(tmVrAviTab) AS STOTIAT,SUM(tmVrSobBom) AS STOTBOM
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0 AND tmEsCombo=0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotPla] @pmtmNumero VARCHAR(5)
 AS 
--totaliza el valor de ventas de planilla solamente combustible
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmEntradas*tmImpGlobal) AS SGLOENT,SUM(tmSalidas*tmImpGlobal) AS SGLOSAL
,SUM(tmSobretasa*tmEntradas) AS SSOBENT,SUM(tmSobretasa*tmSalidas) AS SSOBSAL
,SUM(tmTasaNac*tmEntradas) AS SNACENT,SUM(tmTasaNac*tmSalidas) AS SNACSAL
,SUM(tmTasaDep*tmEntradas) AS SDEPENT,SUM(tmTasaDep*tmSalidas) AS SDEPSAL
,SUM(tmTasaMun*tmEntradas) AS SMUNENT,SUM(tmTasaMun*tmSalidas) AS SMUNSAL
,SUM(tmSoldicom*tmEntradas) AS SSOLENT,SUM(tmSoldicom*tmSalidas) AS SSOLSAL
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero  AND Tanques<>0 AND tmEsProdBase=0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPlaC]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotPlaC] @pmtmNumero VARCHAR(5),@pmtmReferencia2 VARCHAR(50)
 AS 
--totaliza el valor de ventas de los productos COMBOS
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
 FROM  tm_Kdex  AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0 AND tmEsCombo<>0 AND Tanques=0
 AND tmReferencia2=@pmtmReferencia2
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPlaV]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotPlaV] @pmtmNumero VARCHAR(5),@pmtmReferencia2 VARCHAR(50)
 AS 
--totaliza el valor de ventas de los productos no combos
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
 FROM  tm_Kdex  AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0 AND tmEsCombo=0 AND Tanques=0
 AND tmReferencia2=@pmtmReferencia2
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotPun]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotPun] @pmtmNumero VARCHAR(5)
 AS 
--totaliza el valor de ventas de la factura o salida, de los productos no combos
 SELECT tmIdProducto,tmCdSubgrupo,COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
 FROM  tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0 AND tmEsCombo=0
 GROUP BY tmIdProducto,tmCdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotSal] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
,SUM(tmEntradas*tmVrUnitario) AS SCOSENT,SUM(tmSalidas*tmVrUnitario) AS SCOSSAL
,SUM(tmVrPrecio*tmEntradas) AS SVALENT,SUM(tmVrPrecio*tmSalidas) AS SVALSAL
,SUM(tmVrIva) AS SIVA,SUM(tmVrDcto) AS SDCT,SUM(tmVrRete) AS SRET,SUM(tmVrIca) AS SICA
,SUM(tmVrBruto*tmEntradas) AS SBRUENT,SUM(tmVrBruto*tmSalidas) AS SBRUSAL
,SUM(tmVrImpCon) AS SIMPCON,SUM(tmIvaObseq) AS SIVAOBSEQ
,SUM(tmVrImpuBa*(tmEntradas+tmSalidas+ISNULL(tmCantObseq,0)))AS SIMPUBA,SUM(tmVrImpCup*(tmEntradas+tmSalidas+ISNULL(tmCantObseq,0))) AS SIMPUCUP
,SUM(tmVrAviTab) AS STOTIAT,SUM(tmVrSobBom) AS STOTBOM
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmEsProdBase=0 AND tmEsCombo<>0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTotSob]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTotSob] @pmtmNumero VARCHAR(5)
 AS 
--totales de sobretasas e imp. global
 SELECT  SUM(tmEntradas*tmImpGlobal) AS SGLOENT,SUM(tmSalidas*tmImpGlobal) AS SGLOSAL
,SUM(tmSobretasa*tmEntradas) AS SSOBENT,SUM(tmSobretasa*tmSalidas) AS SSOBSAL
,SUM(tmTasaNac*tmEntradas) AS SNACENT,SUM(tmTasaNac*tmSalidas) AS SNACSAL
,SUM(tmTasaDep*tmEntradas) AS SDEPENT,SUM(tmTasaDep*tmSalidas) AS SDEPSAL
,SUM(tmTasaMun*tmEntradas) AS SMUNENT,SUM(tmTasaMun*tmSalidas) AS SMUNSAL
,SUM(tmSoldicom*tmEntradas) AS SSOLENT,SUM(tmSoldicom*tmSalidas) AS SSOLSAL
,SUM(tmImpCarb*tmEntradas) AS SICARENT,SUM(tmImpCarb*tmSalidas) AS SICARSAL
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero  AND Tanques<>0 AND tmEsProdBase=0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTpro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTpro] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)
,@pmtmItem INT
 AS 
 SELECT COUNT(tmItem) AS SCANT
 FROM tm_Kdex 
 WHERE tmNumero=@pmtmNumero AND tmIdProducto=@pmtmIdProducto AND tmItem<>@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTTan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTTan] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16),@pmtmCdTanque VARCHAR(4)
,@pmtmItem INT
 AS 
 SELECT SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmIdProducto=@pmtmIdProducto
 AND tmCdTanque=@pmtmCdTanque
 AND tmItem<>@pmtmItem AND tmServcios=0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTUbi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTUbi] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16),@pmtmCdUbic VARCHAR(10)
,@pmtmItem INT
 AS 
 SELECT SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero  AND tmIdProducto=@pmtmIdProducto
 AND tmItem<>@pmtmItem AND tmServcios=0
 AND tmCdUbic=@pmtmCdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexTVcc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexTVcc] @pmtmNumero VARCHAR(5)
 AS 
--total de vales crédito combustible
 SELECT  SUM(((tmSalidas*tmVrPrecio)-tmVrDcto)+tmVrIva) AS STOTBRU
 FROM  tm_Kdex AS K INNER JOIN ProdMcias AS P ON K.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero  AND TipoRef='SERVICIO' AND ValesComb<>0
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_KdexVcr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_KdexVcr] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmTipRem,tmRemision,tmReferencia2,tmUnidades,SUM(tmSalidas) AS STOTSAL
 FROM tm_Kdex
 WHERE tmNumero=@pmtmNumero AND tmIdCiaRem='VC'
 GROUP BY tmTipRem,tmRemision,tmReferencia2,tmUnidades
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LibOf] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT O.tmIdCuenta AS CdCuenta,NomCuenta,tmTipCom,TipoCom,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo,tmIdTercero,RazonSocial
,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmSanNit,tmSanNitcc,tmSanNitCcSub
,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,tmItem,Compania,TC.IdDiario AS CdDiario,Diario
--información del tercero
,TipoId,Dv,NomCial,SiglaRaz,Direccion,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep
,Departamento,Telefono,TipEnte
 FROM tm_LibOf AS O  INNER JOIN  TiposCom AS TC ON O.tmTipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Puc AS P ON O.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON O.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN CentroCosto AS CC ON O.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON O.tmIdSubCos=SC.IdSubCos
 LEFT JOIN Companias AS CI ON O.tmIdCia=CI.IdCia
 LEFT JOIN tm_NivCue AS NV ON O.tmIdCuenta=NV.tmIdCuenta
 WHERE tmEst=@pmtmEst AND O.tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%') AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%')
 ORDER BY O.tmIdCuenta,RazonSocial,tmTipCom
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfcue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LibOfcue] @pmtmEst CHAR(2),@pmtmTipCom VARCHAR(3)
,@pmtmIdCuenta VARCHAR(16),@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdCCosto VARCHAR(16)=Null
,@pmtmIdSubCos VARCHAR(16)=Null,@pmtmIdCia CHAR(2)=Null
 AS 
 SELECT tmEst,tmTipCom,tmItem,tmTotalDebitos,tmTotalCreditos,tmSaldoAnterior
 FROM tm_LibOf
 WHERE tmEst=@pmtmEst AND tmTipCom=@pmtmTipCom AND tmIdCuenta=@pmtmIdCuenta
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%') AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%')
 AND tmIdSubCos LIKE ISNULL(@pmtmIdSubCos,'%') AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfDia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LibOfDia] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)=Null
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT tmIdCuenta,NomCuenta,tmTipCom,TipoCom,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo,tmIdTercero,RazonSocial
,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmSanNit,tmSanNitcc,tmSanNitCcSub
,Compania,TC.IdDiario AS CdDiario,Diario,tmItem
--información del tercero
,TipoId,Dv,NomCial,SiglaRaz,Direccion,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep
,Departamento,Telefono,TipEnte
 FROM tm_LibOf AS O  INNER JOIN  TiposCom AS TC ON O.tmTipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN Puc AS P ON O.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON O.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN CentroCosto AS CC ON O.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON O.tmIdSubCos=SC.IdSubCos
 LEFT JOIN Companias AS CI ON O.tmIdCia=CI.IdCia
 WHERE tmEst=@pmtmEst AND tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%') AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%')
 ORDER BY O.tmIdCuenta,tmTipCom
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfGcue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LibOfGcue] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCuenta,COUNT(tmItem) AS SCANT
 FROM tm_LibOf
 WHERE tmEst=@pmtmEst 
 GROUP BY tmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LibOfSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LibOfSan] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdCCosto VARCHAR(16)=Null
,@pmtmIdSubCos VARCHAR(16)=Null,@pmtmIdCia CHAR(2)=Null
 AS 
 SELECT tmEst,tmTipCom,tmItem,tmTotalDebitos,tmTotalCreditos,tmSaldoAnterior
 FROM tm_LibOf
 WHERE tmEst=@pmtmEst AND  tmIdCuenta=@pmtmIdCuenta
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%') AND tmIdCCosto LIKE ISNULL(@pmtmIdCCosto,'%')
 AND tmIdSubCos LIKE ISNULL(@pmtmIdSubCos,'%') AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Liquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Liquida] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd
,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,tmVrParcial,tmNitTercero
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Liquida_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Liquida_Cr] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null,@pmtmIdDep VARCHAR(4)=Null,@pmtmIdNom VARCHAR(4)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,Apellidos,Nombres,tmIdConcepto,Concepto,tmDetalle,ClaseCon,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida
,tmVrDeducido,tmFecIniPmd,tmFecFinPmd,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,Dependencia,tmIdCCosto,CCosto
,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmVrSalario
--datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdInstala AS CodInst,Instlacion,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga
,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada
,NumVeh,TipoAdmon,VehPropio,tmVrParcial
 FROM tm_Liquida AS T INNER JOIN NomConceptos AS CN ON T.tmIdConcepto=CN.IdConcepto  INNER JOIN  Empleados AS E ON T.tmIdEmpleado=E.IdEmpleado
 INNER JOIN Dependencias AS DP ON T.tmIdDep=DP.IdDep INNER JOIN CentroCosto AS CO ON T.tmIdCCosto=CO.IdCCosto
 INNER JOIN SubCentros AS SC ON T.tmIdSubCos=SC.IdSubCos INNER JOIN TiposNom AS TN ON T.tmIdNom=TN.IdNom 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal  INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf  
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN  Emp_Contrato AS C ON T.tmNContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  
 INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado 
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea  
 INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada 
 LEFT JOIN NomVehiculos AS VH ON  T.tmpVehiculo=VH.IdVehiculo
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND tmIdDep LIKE ISNULL(@pmtmIdDep,'%') AND tmIdNom LIKE ISNULL(@pmtmIdNom,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaCon] @pmtmNumero VARCHAR(5),@pmtmIdConcepto VARCHAR(4),@pmtmIdEmpleado VARCHAR(16)
,@pmtmItem INT
 AS 
 SELECT Count(tmItem) AS SITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero  AND tmIdConcepto=@pmtmIdConcepto AND tmIdEmpleado=@pmtmIdEmpleado
 AND tmItem<>@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaDed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaDed] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,EsCondtor,pVehiculo
,tmIdConcepto,Concepto,SUM(tmVrBase) AS tVrBase,SUM(tmCantidad) AS tCant,SUM(tmVrDeducido) AS tVrDeducido
,SUM(tmVrLiquida) AS tVrLiquida,MAX(tmTarifa) AS tTarifa
 FROM tm_Liquida AS L INNER JOIN NomConceptos AS C ON L.tmIdConcepto=C.IdConcepto
 INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero AND tmIdConcepto NOT IN ('CES','PRI','INT') AND tmVrDeducido>0
 GROUP BY tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,EsCondtor,pVehiculo
,tmIdConcepto,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaDso] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmItem,tmIdConcepto,tmDetalle,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido
,tmFecUltLiq,tmFecInicial,tmFecFinal,tmFecIniPmd,tmFecFinPmd,tmDiasBase,tmDiasNoRem,tmNPrestamo,tmNCuota,tmTarifa
,tmLogPmdio,tmNContrato,tmVrSalario,tmVrParcial --tmNumero,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom
 FROM tm_Liquida AS L INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaEmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaEmp] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,SUM(tmVrLiquida) AS tVrLiquida,SUM(tmVrDeducido) AS tVrDeducido,sum(tmVrParcial) AS tVrParcial
 FROM tm_Liquida AS L INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 GROUP BY tmIdEmpleado,Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaId] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaItm] @pmtmNumero VARCHAR(5),@pmtmItem INT, @pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT Count(tmItem) AS SITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero  AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaLpre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaLpre] @pmtmNumero VARCHAR(5),@pmtmIdConcepto VARCHAR(4)=Null,@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmCantidad,tmVrDeducido,tmNPrestamo,tmNCuota
,TotPrestamo,TotAbonado,VrPrestamo,NumCuotas
 FROM tm_Liquida AS  L  INNER JOIN Trn_NomPrest AS P ON L.tmNPrestamo=P.NPrestamo
 WHERE tmNumero=@pmtmNumero AND  tmNPrestamo>0 AND tmVrDeducido>0 AND  tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
  AND tmIdConcepto LIKE ISNULL(@pmtmIdConcepto,'%')
 ORDER BY tmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,Apellidos,Nombres,tmIdConcepto,tmDetalle,tmFecUltLiq,tmFecInicial,tmFecFinal,tmVrBase,tmCantidad,tmVrLiquida,tmVrDeducido,tmFecIniPmd,tmFecFinPmd
,tmDiasBase,tmDiasNoRem,tmTarifa,tmNPrestamo,tmNCuota,tmLogPmdio,tmNContrato,tmpVehiculo,tmIdDep,tmIdCCosto,tmIdSubCos,tmIdNom,tmVrSalario,EsCondtor,pVehiculo,tmVrParcial,tmNitTercero
 FROM  tm_Liquida AS L INNER JOIN Empleados AS E ON L.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmIdEmpleado,tmIdConcepto,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaPar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaPar] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmNumero,tmItem,tmIdEmpleado,tmIdConcepto,tmDetalle,tmCantidad,tmVrDeducido
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero AND tmVrDeducido>0  AND  tmIdConcepto IN ('CES','INT')
 AND  tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaPre] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmNPrestamo INT
 AS 
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero AND tmNPrestamo=@pmtmNPrestamo AND  tmItem<>@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LiquidaTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LiquidaTot] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT COUNT(tmItem) AS CANITM,SUM(tmVrBase) AS SBASE,SUM(tmCantidad) AS SCANTIDAD,SUM(tmVrLiquida) AS SVALLIQ
,SUM(tmVrDeducido) AS SDEDUCIDO,SUM(tmDiasBase) AS SDIASBASE,SUM(tmDiasNoRem) AS DIASNOREM,SUM(tmVrParcial) AS STOTPAR
 FROM tm_Liquida
 WHERE tmNumero=@pmtmNumero  AND tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ListaPrec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ListaPrec] @pmtmEst CHAR(2)
 AS 
 SELECT LT.IdProducto AS CdProducto,DescripProd,TipoRef,CiaPrecio1 AS Precio1,CiaPrecio2 AS Precio2,CiaPrecio3 AS Precio3,CiaPrecio4 AS Precio4
,CiaPrecio5 AS Precio5,IdTarIva,TI.Tarifa,TI.Simbolo,CiaIvaInc AS IvaInc,Margen1,Margen2,Margen3,Margen4,Margen5,BaseMgn,TarifDcto1,TarifDcto2,TarifDcto3,TarifDcto4,TarifDcto5
,TrmDia1,TrmDia2,TrmDia3,TrmDia4,TrmDia5
,ExtciaMin,ExtciaMax,ExtciaAct,ExistenciaCia,ISNULL(FecUltcom,CAST('19900101' AS SMALLDATETIME)) AS FecUltCompra,ISNULL(FecUltVta,CAST('19900101' AS SMALLDATETIME)) AS FecUltVenta
,LT.IdCia AS CdCia,Compania,CostoAnt,CostoUlt,CostoPmd,VrCostAnt,VrCosto,VrCostPmd
,Factor1,Factor2,Factor3,Factor4,Factor5,Seriales,Lotes,Combo,NoAjustes,Tanques,ValesComb,P.IdBodega AS CdBodga,Bodega,Descrip
,CodBarras,Referencia,DescripAbrv,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,P.IdSubgrupo AS CdSubgpo,Subgrupo
,P.IdMarca AS CdMarc,Marca,Color,Tamano,MedAlto,MedAncho,MedLargo,MedVolm,P.UndMed AS UndVolm,P.IdUnd AS CdUnd,UM.Unidad AS UndadMed
,IdUndP,UP.Unidad AS EmpPrim,IdUbic,DesUbic,P.IdProv AS IdProvee,RazonSocial,GarProv,GarClie,LtPreDef
,CdMon1,CdMon2,CdMon3,CdMon4,CdMon5,CodMcia,DescripLong,P.Cmntarios AS Prod_Observ,P.IdEstado AS CdEstdo,Estado,NColor,P.Inactivo AS Inactvo
,P.FechaAdd AS FecAdd,P.FechaUpdate AS FecUpd,P.IdUsuario AS IdUsuari,KarTipDoc,KarEntradas,KarSalidas,KarCostoEnt,KarCostoSal
,CdTarifIco,TIC.Tarifa AS TarifIco,TIC.Simbolo AS SimbIco,PrecioVenta1,PrecioVenta2,PrecioVenta3,PrecioVenta4,PrecioVenta5
,ISNULL(NV.NivelMin,ExtciaMin) AS NivelMinCia,ISNULL(NV.NivelMax,ExtciaMax) AS NivelMaxCia
--información del proveedor
,TipoId,Dv,NomCial,Direccion,TP.IdLocal AS CdCiudad,Localidad,Departamento,Telefono,Fax,e_mail
,CiaTarifIva
 FROM tm_ListaPrec AS LT INNER JOIN ProdMcias AS P ON LT.IdProducto=P.IdProducto
 INNER JOIN SubGrupos AS S ON P.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS L ON G.IdLinea=L.IdLinea INNER JOIN Marcas AS M ON P.IdMarca=M.IdMarca
 INNER JOIN UndMed AS UM ON P.IdUnd=UM.IdUnd  INNER JOIN UndMed AS UP ON P.IdUndP=UP.IdUnd
 INNER JOIN Bodegas AS B ON P.IdBodega=B.IdBodega INNER JOIN Terceros AS TP ON P.IdProv=TP.IdTercero
 INNER JOIN Tablapor AS TI ON P.IdTarIva=TI.IdTarifa INNER JOIN EstadoPro AS EP ON P.IdEstado=EP.IdEstado
 INNER JOIN Localidades AS LP ON TP.IdLocal=LP.IdLocal  INNER JOIN Departamentos AS DP ON LP.IdDep=DP.IdDep
 LEFT JOIN Companias AS CI ON LT.IdCia=CI.IdCia LEFT JOIN Tablapor AS TIC ON S.CdTarifIco=TIC.IdTarifa
 LEFT JOIN ProdNiveles AS NV ON LT.IdProducto=NV.IdProducto AND LT.IdCia=NV.IdCia
 WHERE tmEst=@pmtmEst  
 ORDER BY DescripProd
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Lot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Lot] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 SELECT tmItem,tmNumLote,tmIdProducto,DescripProd,tmIdBodega,Bodega,tmCdUbic,tmEntradas,tmSalidas
,tmFecha,tmFecVence,tmLinea,tmNumero,Lotes,tmCdNueUbic
 FROM tm_Lot AS L INNER JOIN ProdMcias AS P ON L.tmIdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON L.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LotGru] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 SELECT tmNumLote,tmIdProducto,DescripProd,tmIdBodega,tmCdUbic,tmFecVence
,sum(tmEntradas) AS SEnt,SUM(tmSalidas) AS SSal
 FROM tm_Lot AS L INNER JOIN ProdMcias AS P ON L.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND Lotes<>0  AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
 GROUP BY  tmNumLote,tmIdProducto,DescripProd,tmIdBodega,tmCdUbic,tmFecVence
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LotID] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_Lot 
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotIng]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LotIng] @pmtmNumero VARCHAR(5),@pmtmLinea INT,@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmNumLote VARCHAR(30)=Null
 AS 
 SELECT SUM(tmEntradas) AS SENT,SUM(tmSalidas) AS SSAL
 FROM tm_Lot
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%') AND tmNumLote LIKE ISNULL(@pmtmNumLote,'%')
 AND  tmLinea<>@pmtmLinea
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LotLta] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 SELECT tmItem,tmNumLote,tmFecVence,tmEntradas+tmSalidas AS Cantidad,tmIdProducto,DescripProd
,tmIdBodega,Bodega,tmCdUbic,tmLinea,tmFecha
 FROM tm_Lot AS L INNER JOIN ProdMcias AS P ON L.tmIdProducto=P.IdProducto
 INNER JOIN Bodegas AS B ON L.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Lotr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Lotr] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmNumLote,tmIdProducto,DescripProd,tmIdBodega,tmCdUbic,tmEntradas,tmSalidas
,tmFecha,tmFecVence,tmLinea,tmCdNueUbic
 FROM tm_Lot AS L INNER JOIN ProdMcias AS P ON L.tmIdProducto=P.IdProducto
 WHERE tmNumero=@pmtmNumero AND Lotes<>0 
 ORDER BY tmNumLote,tmIdProducto,tmIdBodega,tmCdUbic
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_LotTot] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SEntradas,SUM(tmSalidas) AS SSalidas
 FROM tm_Lot 
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_LotTotU]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_LotTotU] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null,@pmtmCdUbic VARCHAR(10)=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmEntradas) AS SEntradas,SUM(tmSalidas) AS SSalidas
 FROM tm_Lot 
 WHERE tmNumero=@pmtmNumero AND tmCdUbic=@pmtmCdUbic 
 AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')  AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovClientes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovClientes] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCliente,T.RazonSocial AS NomCliente,tmIdAgencia,Agencia,tmIdCia,Compania,tmTipDoc,TipoDoc,tmNumero,tmItem,tmFecha
,tmCargos,tmAbonos,tmDetalle,tmReferencia,tmNumForma,tmModalidad,tmTipRef,tmDocRef,tmIdCiaRef,tmCdConcepto,Concepto
,tmIdVend,VN.RazonSocial AS Vendedor,tmSanAgeCia,tmSanAge,tmSanClieCia,tmSanClie,tmTotalAbono,tmVrAfavor,tmTimeSys,tmFecVence
,tmCdForma,tmEnEfectivo,tmCdBanco,Banco,tmBeneficiario,tmCdLocal,LD.Localidad AS DocCiudad,tmTipCom,tmComprobante,tmIdCiaCom
,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,Usuario
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato,CLI.IdPlazo AS CdPlazo,Plazo,NVmto,CLI.CdBandera AS CodBandera,TipoBandera
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM tm_MovClientes AS M  INNER JOIN Terceros AS T ON M.tmIdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON M.tmIdAgencia=A.IdAgencia   INNER JOIN  Companias AS CI ON M.tmIdCia=CI.IdCia
 INNER JOIN Terceros AS VN ON M.tmIdVend=VN.IdTercero  INNER JOIN TercCliente AS CLI ON  M.tmIdCliente=CLI.IdClie
 INNER JOIN adm_Usuarios AS U ON M.tmIdUsuario=U.IdUsuario
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Conceptos AS C ON M.tmCdConcepto=C.IdConcepto  LEFT JOIN Sys_TiposDoc AS TD ON M.tmTipDoc=TD.IdDoc
 LEFT JOIN Bancos AS B ON M.tmCdBanco =B.IdBanco LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera
 LEFT JOIN Localidades AS LD ON M.tmCdLocal=LD.IdLocal
 WHERE tmEst=@pmtmEst 
 ORDER BY T.RazonSocial,tmIdAgencia,tmTimeSys
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovClientesCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovClientesCli] @pmtmEst CHAR(2),@pmtmIdCliente VARCHAR(16)=Null,@pmtmIdAgencia VARCHAR(16)=Null
,@pmtmIdCia CHAR(2)=Null
 AS 
 SELECT tmEst,tmTipDoc,tmNumero,tmIdCia,tmItem,tmIdCliente,tmIdAgencia,tmSanClie,tmSanClieCia,tmSanAge,tmSanAgeCia
 FROM tm_MovClientes
 WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') AND tmIdAgencia LIKE ISNULL(@pmtmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovCue] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT C.IdCuenta AS CdCuenta,NomCuenta,TipCom,TipoCom,Comprobante,C.IdCia AS CdCia,Compania,Item,Fecha,Detalle,VrDebito,VrCredito,C.IdTercero AS NitTercero,T.RazonSocial AS RaznSocial
,IdVehiculo,C.IdCCosto AS CdCenCosto,CCosto,C.IdSubCos AS CdSubcentro,SubCosto,VrBase,TarifaBase,TipDoc,TipoDoc,Documento,IdCiaDoc,CodConce,Concepto
,NitDoc,ND.RazonSocial AS NomNitDoc,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumeroCta,CTE.IdBanco AS CodBanco,Banco
,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,NIO.RazonSocial AS NomNitOtros,CodSubgpo,Subgrupo,CiuOrigen,LD.Localidad AS NomCiudad
,CodAgncia,A.Agencia AS NomAgencia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,VrSanCue,VrSanCueCia,VrSanNit,VrSanNitCia,VrSanVeh,VrSanVehCia
,VrSanCc,VrSanCcCia,VrSanCcSub,VrSanCcSubCia,VrSanNitCc,VrSanNitCcCia,VrSanNitCcSub,VrSanNitCcSubCia,VrSanNitAge,VrSanNitAgeCia
,VrSanNitAgeCc,VrSanNitAgeCcCia,VrSanNitAgeCcSub,VrSanNitAgeCcSubCia,VrSanNitVeh
,VrSanNitVehCia,VrSanNitVehCc,VrSanNitVehCcCia,VrSanVehCc,VrSanVehCcCia,VrSanVehCcSub,VrSanVehCcSubCia,tmEst
,TC.IdDiario AS CdDiario,Diario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono,T.TipEnte AS TercTipEnte
,CodAgencia,DirAgncia,Referencia
 FROM tm_MovCue AS C INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 INNER JOIN CentroCosto AS O ON C.IdCCosto=O.IdCCosto
 LEFT JOIN TiposCom AS TC ON C.TipCom=TC.IdCom LEFT JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 LEFT JOIN Companias AS CI ON C.IdCia=CI.IdCia
 LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NIO ON C.NitOtros=NIO.IdTercero
 LEFT JOIN Terceros AS ND ON C.NitDoc=ND.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN Localidades AS LD ON C.CiuOrigen=LD.IdLocal
 LEFT JOIN SubGrupos AS SG ON C.CodSubgpo=SG.IdSubgrupo
 LEFT JOIN Agencias AS A ON C.CodAgncia=A.IdAgencia
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTE ON C.CodCta=CTE.IdCta LEFT JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 WHERE tmEst=@pmtmEst
-- AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
-- AND C.IdTercero LIKE ISNULL(@pmIdTercero ,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 --ORDER BY C.IdCuenta,Fecha,C.IdCia,TipCom
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCueCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_MovCueCue] @pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16),@pmIdCia CHAR(2)=Null
,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmIdSubCos VARCHAR(16)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmCodAgncia VARCHAR(16)=Null
 AS 
 SELECT tmEst,IdCuenta,IdTercero,IdVehiculo,IdCCosto,IdSubCos,CodAgncia
 FROM tm_MovCue
 WHERE tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta  AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 AND IdSubCos LIKE ISNULL(@pmIdSubCos,'%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 AND CodAgncia LIKE ISNULL(@pmCodAgncia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCueDia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovCueDia] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT C.IdCuenta AS CdCuenta,NomCuenta,TipCom,TipoCom,Comprobante,C.IdCia AS CdCia,Compania,Item,Fecha,Detalle,VrDebito,VrCredito,C.IdTercero AS NitTercero,T.RazonSocial AS RaznSocial
,IdVehiculo,C.IdCCosto AS CdCenCosto,CCosto,C.IdSubCos AS CdSubcentro,SubCosto,VrBase,TarifaBase,TipDoc,TipoDoc,Documento,IdCiaDoc,CodConce,Concepto
,NitDoc,ND.RazonSocial AS NomNitDoc,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumeroCta,CTE.IdBanco AS CodBanco,Banco
,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,NIO.RazonSocial AS NomNitOtros,CodSubgpo,Subgrupo,CiuOrigen,LD.Localidad AS NomCiudad
,CodAgncia,A.Agencia AS NomAgencia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,VrSanCue,VrSanCueCia,VrSanNit,VrSanNitCia
,VrSanNitCc,VrSanNitCcCia,VrSanNitCcSub,VrSanNitCcSubCia
,TC.IdDiario AS CdDiario,Diario,tmEst,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
--no disponible
--,VrSanVeh,VrSanVehCia,VrSanCc,VrSanCcCia,VrSanCcSub,VrSanCcSubCia,,VrSanNitAge,VrSanNitAgeCia
--,VrSanNitAgeCc,VrSanNitAgeCcCia,VrSanNitAgeCcSub,VrSanNitAgeCcSubCia,VrSanNitVeh
--,VrSanNitVehCia,VrSanNitVehCc,VrSanNitVehCcCia,VrSanVehCc,VrSanVehCcCia,VrSanVehCcSub,VrSanVehCcSubCia,
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono,T.TipEnte AS TercTipEnte
,CodAgencia,DirAgncia,Referencia
 FROM tm_MovCue AS C  INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 INNER JOIN CentroCosto AS O ON C.IdCCosto=O.IdCCosto
 LEFT JOIN  TiposCom AS TC ON C.TipCom=TC.IdCom LEFT JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 LEFT JOIN Companias AS CI ON C.IdCia=CI.IdCia
 LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NIO ON C.NitOtros=NIO.IdTercero
 LEFT JOIN Terceros AS ND ON C.NitDoc=ND.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN Localidades AS LD ON C.CiuOrigen=LD.IdLocal
 LEFT JOIN SubGrupos AS SG ON  C.CodSubgpo=SG.IdSubgrupo
 LEFT JOIN Agencias AS A ON C.CodAgncia=A.IdAgencia
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTE ON C.CodCta=CTE.IdCta LEFT JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 LEFT JOIN tm_NivCue AS NV ON C.IdCuenta=NV.tmIdCuenta
 WHERE tmEst=@pmtmEst AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND C.IdTercero LIKE ISNULL(@pmIdTercero ,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
 ORDER BY C.IdCuenta,Fecha,C.IdCia,TipCom
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovCueGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovCueGru] @pmtmEst CHAR(2)
 AS 
 SELECT IdCuenta AS tmIdCuenta,count(Item) AS SCANT
 FROM tm_MovCue 
 WHERE tmEst=@pmtmEst
 GROUP BY IdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovInvent]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovInvent] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdCliente,T.RazonSocial AS NomCliente,tmCdAgencia,Agencia,CodAgencia,tmIdVend,VN.RazonSocial AS Vendedor
,tmIdBodega,Bodega,tmTipDoc,TipoDoc,tmIdConcepto,Concepto,tmCdLocal,Localidad,L.IdDep AS CodDep,Departamento
,tmCdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,tmFecha
,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal,tmValorEnt,tmValorSal,tmDctosEnt,tmDctosSal,tmIvaEnt,tmIvaSal,tmOtrosImpEnt,tmOtrosImpSal,tmUnidVolumen
,tmEntradas2,tmSalidas2,tmCostoEnt2,tmCostoSal2,tmValorEnt2,tmValorSal2,tmDctosEnt2,tmDctosSal2,tmIvaEnt2,tmIvaSal2,tmOtrosImpEnt2,tmOtrosImpSal2,tmUnidVolumen2
,tmEst,tmItem
--Datos del producto
,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,TipoRef,PM.IdMarca AS CdMarca,Marca
,PM.IdUnd AS CdUnid,Unidad,FecUltcom,FecUltVta,Tanques
--datos del tercero
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera
,U.Unidades
 FROM tm_MovInvent AS V INNER JOIN ProdMcias  AS PM ON V.tmIdProducto=PM.IdProducto  INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero LEFT JOIN Agencias  AS A ON V.tmCdAgencia=A.IdAgencia
 LEFT JOIN TercCliente AS CLI ON V.tmIdCliente=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Subzonas AS SZ ON V.tmCdSubzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Terceros AS VN ON V.tmIdVend=VN.IdTercero   LEFT JOIN Bodegas AS B ON V.tmIdBodega=B.IdBodega 
 LEFT  JOIN Companias AS CN ON  V.tmIdCia=CN.IdCia  LEFT JOIN Sys_TiposDoc AS TD ON V.tmTipDoc=TD.IdDoc
 LEFT JOIN  Conceptos AS C ON V.tmIdConcepto=C.IdConcepto
 LEFT JOIN Localidades AS L ON V.tmCdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera  LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera
 LEFT JOIN (SELECT tmIdProducto AS IdProducto,SUM(tmSalidas-tmEntradas) AS Unidades FROM tm_MovInvent
 WHERE tmEst=@pmtmEst GROUP BY tmIdProducto) AS U ON V.tmIdProducto=U.IdProducto
 WHERE tmEst=@pmtmEst
 ORDER BY DescripProd,tmIdCia,tmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesDia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovTanquesDia] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16)=Null
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdTanque,tmFecha,tmSaldoAntDia,tmEntradas,tmDevEnt
,tmPlanillas,tmDevPlanillas,tmNotasCalib,tmFacturas,tmDevFact,tmSalidas,tmDevSalidas,tmAjusteSob,tmAjusteFal
,tmTraslados,tmOtros,tmNuevoSaldo,tmCantFisico,tmDiferencia,tmCantFisico-tmNuevoSaldo AS Sob_Fal,tmCantAgua
--datos del producto
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,DescripAbrv
,PM.IdUnd AS CdUnid,Unidad,Precio1,Precio2,Precio3,Precio4,Precio5,VrCosto,VrCostPmd,ExtciaAct,ExtciaMin,ExtciaMax,FecUltcom,FecUltVta
,Descripcion,CapTanq,NivAgua,CapNeta,SaldoActual,TnqGas,TnqUnido,TnqVirtual,NColor
--costos
,tmCostoAntDia,tmCostoEnt,tmCostoDve,tmCostoPla,tmCostoDvp,tmCostoNot,tmCostoFac,tmCostoDfc
,tmCostoSal,tmCostoDvs,tmCostoAjs,tmCostoAjf,tmCostoTra,tmCostoOtr,tmCostoNsal
,tmSaldoAnt,tmCostoAnt,tmSaldoAntCia,tmCostoSanCia,tmSaldoAntTan,tmCostoSanTan,tmSaldoAntPro,tmCostoSanPro
,tmUndsEnt,tmUndsDve,tmUndsFac,tmUndsDfc,tmUndsSal,tmUndsDvs,tmUndsOtr,tmUndsDot
 FROM tm_MovTanques AS M INNER JOIN ProdMcias AS PM ON M.tmIdProducto=PM.IdProducto
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea   INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 LEFT JOIN Companias AS CN ON M.tmIdCia=CN.IdCia  LEFT JOIN Tanques AS TQ ON M.tmIdTanque=TQ.IdTanque
 WHERE tmEst=@pmtmEst AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 ORDER BY DescripProd,tmIdCia,tmIdTanque,tmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesFis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovTanquesFis] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16)=Null
 AS 
 SELECT tmEst,tmIdProducto,DescripProd,tmIdTanque,tmItem,tmIdCia,tmFecha,tmSaldoAnt,tmCostoAnt
,tmEntradas+tmDevSalidas+tmDevFact+tmAjusteSob+tmDevPlanillas+tmNotasCalib+tmTraslados AS TotalEntradas
,tmCostoEnt+tmCostoDvs+tmCostoDfc+tmCostoAjs+tmCostoDvp+tmCostoNot+tmCostoTra AS CostoEntradas
,tmDevEnt+tmSalidas+tmFacturas+tmAjusteFal+tmPlanillas+tmOtros AS TotalSalidas
,tmCostoDve+tmCostoSal+tmCostoFac+tmCostoAjf+tmCostoPla+tmCostoOtr AS CostoSalidas
,tmNuevoSaldo,tmCostoNsal,tmCantFisico,tmCantAgua,tmDiferencia
 FROM tm_MovTanques AS M INNER JOIN ProdMcias AS PM ON M.tmIdProducto=PM.IdProducto
 WHERE tmEst=@pmtmEst AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 ORDER BY tmIdProducto,tmIdCia,tmIdTanque,tmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovTanquesPro] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16)
,@pmtmIdTanque VARCHAR(4)=Null,@pmtmIdCia CHAR(2)=Null
 AS 
 SELECT tmEst,tmIdProducto,tmIdTanque,tmItem,tmIdCia,tmFecha,tmSaldoAnt,tmCostoAnt
 FROM tm_MovTanques
 WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto
  AND tmIdTanque LIKE ISNULL(@pmtmIdTanque,'%') AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovTanquesRes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovTanquesRes] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16)=Null
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdTanque,tmSaldoAnt,tmEntradas,tmSalidas,tmSaldoAnt+tmEntradas-tmSalidas AS NuevoSaldo
,tmCostoAnt,tmCostoEnt,tmCostoSal,tmCostoAnt+tmCostoEnt-tmCostoSal AS CostoTotal
,tmSaldoAntCia,tmCostoSanCia,tmSaldoAntTan,tmCostoSanTan,tmSaldoAntPro,tmCostoSanPro,tmUndsEnt AS UnidadesEnt,tmUndsDve AS UnidadesSal
--datos del producto
,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,S.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,DescripAbrv
,PM.IdUnd AS CdUnid,Unidad,Precio1,Precio2,Precio3,Precio4,Precio5,VrCosto,VrCostPmd,ExtciaAct,ExtciaMin,ExtciaMax,FecUltcom,FecUltVta
,Descripcion,CapTanq,NivAgua,CapNeta,SaldoActual,TnqGas,TnqUnido,TnqVirtual,NColor
 FROM tm_MovTanques AS M INNER JOIN ProdMcias AS PM ON M.tmIdProducto=PM.IdProducto
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea   INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 LEFT JOIN Companias AS CN ON M.tmIdCia=CN.IdCia  LEFT JOIN Tanques AS TQ ON M.tmIdTanque=TQ.IdTanque
 WHERE tmEst=@pmtmEst AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 ORDER BY DescripProd,tmIdCia,tmIdTanque
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovVentas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovVentas] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdCliente,T.RazonSocial AS NomCliente,tmCdAgencia,Agencia,CodAgencia,tmIdVend,VN.RazonSocial AS Vendedor
,tmIdBodega,Bodega,tmTipDoc,TipoDoc,tmIdConcepto,Concepto,tmCdLocal,Localidad,L.IdDep AS CodDep,Departamento
,tmCdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,tmFecha
,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal,tmValorEnt,tmValorSal,tmDctosEnt,tmDctosSal,tmIvaEnt,tmIvaSal,tmImpGlobalEnt,tmImpGlobalSal,tmOtrosEnt,tmOtrosSal
,tmUnidVolumen,tmImpConEnt,tmImpConSal,tmImpuBaEnt,tmImpuBaSal,tmImpuCupEnt,tmImpuCupSal,tmEntradas2,tmSalidas2,tmCostoEnt2,tmCostoSal2,tmValorEnt2,tmValorSal2,tmDctosEnt2,tmDctosSal2,tmIvaEnt2,tmIvaSal2
,tmImpGlobalEnt2,tmImpGlobalSal2,tmOtrosEnt2,tmOtrosSal2,tmUnidVolumen2,tmImpConEnt2,tmImpConSal2,tmImpuBaEnt2,tmImpuBaSal2,tmImpuCupEnt2,tmImpuCupSal2,tmItem
--Datos del producto
,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,TipoRef,PM.IdMarca AS CdMarca,Marca
,PM.IdUnd AS CdUnid,Unidad,FecUltcom,FecUltVta,Tanques,Factor1,Factor2
--datos del tercero
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera
 FROM tm_MovVentas AS V LEFT JOIN ProdMcias  AS PM ON V.tmIdProducto=PM.IdProducto  LEFT JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 LEFT JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo LEFT JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 LEFT JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea LEFT JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero LEFT JOIN Agencias  AS A ON V.tmCdAgencia=A.IdAgencia
 LEFT JOIN TercCliente AS CLI ON V.tmIdCliente=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Subzonas AS SZ ON V.tmCdSubzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Terceros AS VN ON V.tmIdVend=VN.IdTercero   LEFT JOIN Bodegas AS B ON V.tmIdBodega=B.IdBodega 
 LEFT  JOIN Companias AS CN ON  V.tmIdCia=CN.IdCia  LEFT JOIN Sys_TiposDoc AS TD ON V.tmTipDoc=TD.IdDoc
 LEFT JOIN  Conceptos AS C ON V.tmIdConcepto=C.IdConcepto
 LEFT JOIN Localidades AS L ON V.tmCdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera  LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera
 WHERE tmEst=@pmtmEst
 ORDER BY DescripProd,tmIdCia,tmFecha
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_MovVentasAes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_MovVentasAes] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdCliente,T.RazonSocial AS NomCliente,tmCdAgencia,Agencia,CodAgencia,tmIdVend,VN.RazonSocial AS Vendedor
,tmCdLocal,Localidad,L.IdDep AS CodDep,Departamento,tmCdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,tmEntradas,tmSalidas,tmCostoEnt,tmCostoSal,tmValorEnt,tmValorSal,tmDctosEnt,tmDctosSal,tmIvaEnt,tmIvaSal,tmImpConEnt,tmImpConSal,tmImpGlobalEnt,tmImpGlobalSal,tmOtrosEnt,tmOtrosSal
,tmImpuBaEnt,tmImpuBaSal,tmImpuCupEnt,tmImpuCupSal,tmUnidVolumen,tmEntradas2,tmSalidas2,tmCostoEnt2,tmCostoSal2,tmValorEnt2,tmValorSal2,tmDctosEnt2,tmDctosSal2,tmIvaEnt2,tmIvaSal2,tmImpConEnt2,tmImpConSal2,tmImpGlobalEnt2,tmImpGlobalSal2
,tmOtrosEnt2,tmOtrosSal2,tmUnidVolumen2,tmImpuBaEnt2,tmImpuBaSal2,tmImpuCupEnt2,tmImpuCupSal2,tmItem
--datos del tercero
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera
,CLI.IdVend AS IdVendDef,VD.RazonSocial AS VendedorDef,CLI.NContrato AS CliNumContrato,CiaContMay,A.NContrato AS AgeNContrato,CiaCont
 FROM tm_MovVentas AS V  INNER JOIN ProdMcias  AS PM ON V.tmIdProducto=PM.IdProducto 
 INNER JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Agencias  AS A ON V.tmCdAgencia=A.IdAgencia  LEFT JOIN TercCliente AS CLI ON V.tmIdCliente=CLI.IdClie 
 LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN Subzonas AS SZ ON V.tmCdSubzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Terceros AS VN ON V.tmIdVend=VN.IdTercero   LEFT  JOIN Companias AS CN ON  V.tmIdCia=CN.IdCia
 LEFT JOIN Localidades AS L ON V.tmCdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera  LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera
 LEFT JOIN Terceros AS VD ON CLI.IdVend=VD.IdTercero
 WHERE tmEst=@pmtmEst
 ORDER BY T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifCom] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCia,Compania,BC.tmIdCuenta AS IdCuenta,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo,tmSaldoAnterior2,tmTotalDebitos2,tmTotalCreditos2
,tmSaldoAnterior2+tmTotalDebitos2-tmTotalCreditos2 AS NuevoSaldo2,tmVrPresupto
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
--información del tercero
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono
,EsAccnista,EsCliente,EsPropietario,CodAgencia,Referencia 
,tmItem,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,P.Tercero,P.CentroCosto
 FROM tm_NiifCom AS BC INNER JOIN PucNiif AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON BC.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CN ON BC.tmIdCia=CN.IdCia
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifComIB]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifComIB] @pmtmEst CHAR(2)
 AS 
 SELECT BC.tmIdCuenta AS IdCuent,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo
,tmIdCia,Compania,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
--información del tercero
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
--información de agencia y vehículos
,CodAgencia,Referencia
,tmItem,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_NiifCom AS BC INNER JOIN PucNiif AS P ON BC.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON BC.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON BC.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON BC.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON BC.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN Agencias AS A ON BC.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CI ON BC.tmIdCia=CI.IdCia
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifGen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifGen] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCia,Compania,BG.tmIdCuenta AS CdCuenta,NomCuenta,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,tmEst
 FROM tm_NiifGen AS BG INNER JOIN PucNiif AS P ON BG.tmIdCuenta=P.IdCuenta
 LEFT JOIN Companias AS CI ON BG.tmIdCia=CI.IdCia
 LEFT JOIN tm_NivCue AS NV ON BG.tmIdCuenta=NV.tmIdCuenta
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifGyp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifGyp] @pmtmEst CHAR(2) 
 AS 
 SELECT GP.tmIdCuenta AS CdCuenta,NomCuenta,tmTipo,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos,tmNuevoSaldo
,tmSalAnt2,tmDebitos2,tmCreditos2,tmSaldo2,tmIdCia,Compania
,tmIdTercero,RazonSocial,tmCodAgncia,A.Agencia AS NomAgencia,tmIdVehiculo,tmTipoAfi,tmIdCCosto,CCosto,tmIdSubCos,SubCosto
,TipoId,Dv,Direccion,T.IdLocal AS CdCiudad,Localidad,L.IdDep AS CdDepto,Departamento,Telefono 
,CodAgencia,Referencia
,tmItem,tmEst,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_NiifGyp AS GP INNER JOIN PucNiif AS P ON GP.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON GP.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep
 INNER JOIN CentroCosto AS CC ON GP.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON GP.tmIdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON GP.tmIdCuenta=NV.tmIdCuenta
 LEFT JOIN Agencias AS A ON GP.tmCodAgncia=A.IdAgencia
 LEFT JOIN Companias AS CI ON GP.tmIdCia=CI.IdCia
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifLibDia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifLibDia] @pmtmEst CHAR(2)
AS 
 SELECT tmIdCuenta,NomCuenta,tmTipCom,TipoCom,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo,tmIdTercero,RazonSocial
,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmSanNit,tmSanNitcc,tmSanNitCcSub
,Compania,TC.IdDiario AS CdDiario,Diario,tmItem
--información del tercero
,TipoId,Dv,NomCial,SiglaRaz,Direccion,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep
,Departamento,Telefono,TipEnte
 FROM tm_NiifLib AS O INNER JOIN TiposCom AS TC ON O.tmTipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN PucNiif AS P ON O.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON O.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN CentroCosto AS CC ON O.tmIdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON O.tmIdSubCos=SC.IdSubCos
 LEFT JOIN Companias AS CI ON O.tmIdCia=CI.IdCia
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifLibOfi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifLibOfi] @pmtmEst CHAR(2)
 AS 
 SELECT O.tmIdCuenta AS CdCuenta,NomCuenta,tmTipCom,TipoCom,tmIdCia,tmSaldoAnterior,tmTotalDebitos,tmTotalCreditos
,tmSaldoAnterior+tmTotalDebitos-tmTotalCreditos AS NuevoSaldo,tmIdTercero,RazonSocial
,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmSanNit,tmSanNitcc,tmSanNitCcSub
,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12,tmItem,Compania,TC.IdDiario AS CdDiario,Diario
,TipoId,Dv,NomCial,SiglaRaz,Direccion,T.IdLocal AS TercCdCiudad,Localidad,L.IdDep AS CdDep
,Departamento,Telefono,TipEnte
 FROM tm_NiifLib AS O INNER JOIN TiposCom AS TC ON O.tmTipCom=TC.IdCom
 INNER JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 INNER JOIN PucNiif AS P ON O.tmIdCuenta=P.IdCuenta
 INNER JOIN Terceros AS T ON O.tmIdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN CentroCosto AS CC ON O.tmIdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON O.tmIdSubCos=SC.IdSubCos
 LEFT JOIN Companias AS CI ON O.tmIdCia=CI.IdCia LEFT JOIN tm_NivCue AS NV ON O.tmIdCuenta=NV.tmIdCuenta
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NiifMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NiifMov] @pmtmEst CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmIdTercero VARCHAR(16)=Null
,@pmIdCCosto VARCHAR(16)=Null
 AS 
 SELECT C.IdCuenta AS CdCuenta,NomCuenta,TipCom,TipoCom,Comprobante,C.IdCia AS CdCia,Compania,Item,Fecha,Detalle,VrDebito,VrCredito,C.IdTercero AS NitTercero,T.RazonSocial AS RaznSocial
,IdVehiculo,C.IdCCosto AS CdCenCosto,CCosto,C.IdSubCos AS CdSubcentro,SubCosto,VrBase,TarifaBase,TipDoc,TipoDoc,Documento,IdCiaDoc,CodConce,Concepto
,NitDoc,ND.RazonSocial AS NomNitDoc,TipFac,Factura,IdCiaFac,ItemFac,FecVence,CodCta,NumeroCta,CTE.IdBanco AS CodBanco,Banco
,NumCheque,Integrado,TipoAplica,Consolida,CodCargo,NitOtros,NIO.RazonSocial AS NomNitOtros,CodSubgpo,Subgrupo,CiuOrigen,LD.Localidad AS NomCiudad
,CodAgncia,A.Agencia AS NomAgencia,VehPropio,Referncia,TipDocRef,DocRef,IdCiaRef,CodCuentaCG,VrSanCue,VrSanCueCia,VrSanNit,VrSanNitCia,VrSanVeh,VrSanVehCia
,VrSanCc,VrSanCcCia,VrSanCcSub,VrSanCcSubCia,VrSanNitCc,VrSanNitCcCia,VrSanNitCcSub,VrSanNitCcSubCia,VrSanNitAge,VrSanNitAgeCia
,VrSanNitAgeCc,VrSanNitAgeCcCia,VrSanNitAgeCcSub,VrSanNitAgeCcSubCia,VrSanNitVeh
,VrSanNitVehCia,VrSanNitVehCc,VrSanNitVehCcCia,VrSanVehCc,VrSanVehCcCia,VrSanVehCcSub,VrSanVehCcSubCia,tmEst
,TC.IdDiario AS CdDiario,Diario
--Información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS TercCiudad,L.IdDep AS CdDep,Departamento,T.Telefono AS TercTelefono,T.TipEnte AS TercTipEnte
,CodAgencia,DirAgncia,Referencia
 FROM tm_NiifMov AS C INNER JOIN Terceros AS T ON C.IdTercero=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN PucNiif AS P ON C.IdCuenta=P.IdCuenta
 INNER JOIN CentroCosto AS O ON C.IdCCosto=O.IdCCosto
 LEFT JOIN TiposCom AS TC ON C.TipCom=TC.IdCom LEFT JOIN Diarios AS DR ON TC.IdDiario=DR.IdDiario
 LEFT JOIN Companias AS CI ON C.IdCia=CI.IdCia
 LEFT JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 LEFT JOIN Terceros AS NIO ON C.NitOtros=NIO.IdTercero
 LEFT JOIN Terceros AS ND ON C.NitDoc=ND.IdTercero
 LEFT JOIN Conceptos AS CN ON C.CodConce=CN.IdConcepto
 LEFT JOIN Localidades AS LD ON C.CiuOrigen=LD.IdLocal
 LEFT JOIN SubGrupos AS SG ON  C.CodSubgpo=SG.IdSubgrupo
 LEFT JOIN Agencias AS A ON C.CodAgncia=A.IdAgencia
 LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN CtasCorrientes AS CTE ON C.CodCta=CTE.IdCta LEFT JOIN Bancos AS B ON CTE.IdBanco=B.IdBanco
 WHERE tmEst=@pmtmEst
--AND C.IdCia LIKE ISNULL(@pmIdCia,'%%') AND C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 --AND C.IdTercero LIKE ISNULL(@pmIdTercero ,'%') AND C.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')
-- ORDER BY C.IdCuenta,Fecha,C.IdCia,TipCom
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NomHoras]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NomHoras] 
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmHorDiurno,tmHorNocturno,tmHorExtraDia,tmHorExtraNoc,tmHorRecNoc,tmHorDomDia,tmHorDomNoc,tmHorExtDom,tmHorExtDomNoc
,tmVrHoras1,tmVrHoras2,tmVrHoras3,tmVrHoras4,tmVrSalario,tmVrATrans
,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmTipoLiquida,tmpVehiculo
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,E.Inactivo AS Emp_Inactvo
 FROM tm_NomHoras AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN  Emp_Contrato AS C ON N.tmNContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.tmIdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.tmIdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.tmIdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.tmIdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.tmIdNom=TN.IdNom  INNER JOIN Areas AS AR ON N.tmIdArea=AR.IdArea 
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 ORDER BY Apellidos,Nombres
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Nomina]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Nomina] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 SELECT tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad,tmClaseLiq
,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo
,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmVrPension,tmVrSalud,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
ORDER BY tmIdEmpleado,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Nomina_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Nomina_Cr] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmItem,tmIdConcepto,tmDetalle,Concepto,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias,tmCodFondo,FD.Fondo AS tm_Fondo,tmVrBaseLiq,tmFecIni,tmFecFin,tmIdPeriodo
,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmClaseLiq,tmOrigCargue,tmBasExceso,tmNitTercero,tmHoraInicial,tmHoraFinal,tmTipoInc,tmVrIngNoSal
--Datos empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,FecNacmto,EsCondtor,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
--datos del contrato
,E.NContrato AS NumContrato,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdDep AS CodDep,Dependencia,C.IdInstala AS CodInst,Instlacion,C.IdCCosto AS CodCcto,CCosto
,C.IdSubCos AS CodSubcen,SubCosto,C.IdNom AS CodNom,TipoNomina,C.TipoLiquida AS TipLiq,Asistencia,NoDevenga,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie,VrSalario,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes
,SegFinMes,DchDotacion,DchCafeteria,ModoRet,C.IdEstado AS IdEstdo,Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,C.IdUsuario AS Con_IdUsuari,Usuario
,pVehiculo,NumVeh,TipoAdmon,VehPropio
 FROM tm_Nomina AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN NomConceptos AS CN ON N.tmIdConcepto=CN.IdConcepto
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN  Emp_Contrato AS C ON E.NContrato=C.NContrato  INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon
 INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo  INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea
 INNER JOIN Dependencias AS DP ON C.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON C.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON C.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON C.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON C.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON C.IdEstado=EN.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario  INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase 
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada  LEFT JOIN Fondos AS FD ON N.tmCodFondo=FD.IdFondo
 LEFT JOIN NomVehiculos AS VH ON E.pVehiculo=VH.IdVehiculo
 WHERE tmNumero=@pmtmNumero  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaBas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaBas] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmTipBas VARCHAR(3)
,@pmtmClaseLiq VARCHAR(10)
 AS 
 IF @pmTipBas ='SD' --SALARIO BASICO+EXTRAS
  SELECT tmIdConcepto,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDed) AS STOTDED,SUM(tmVrBaseLiq) AS SBASLIQ
  ,SUM(tmBasExceso) AS STOTBEXC,SUM(CASE WHEN tmIdConcepto='IGE' AND tmBasExceso>0 THEN tmBasExceso ELSE tmVrBaseLiq END) AS SBASEIGE 
  FROM tm_Nomina 
  WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado 
  AND (tmIdConcepto NOT IN ('BAS','HHD','HHN','LIC','IGE','IRP','DSR','VAC','DCP','DCS','FSP','FSU','RET') OR (tmIdConcepto IN ('BAS','HHD','HHN') AND tmOrigCargue='CONVENCION'))
  AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
  GROUP BY tmIdConcepto
 ELSE --TOTAL DEVENGADO
  SELECT tmIdConcepto,SUM(tmCantDevg) AS SCANDEV ,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDed) AS STOTDED,SUM(tmVrBaseLiq) AS SBASLIQ
  ,SUM(tmBasExceso) AS STOTBEXC,SUM(CASE WHEN tmIdConcepto='IGE' AND tmBasExceso>0 THEN tmBasExceso ELSE tmVrBaseLiq END) AS SBASEIGE 
  FROM tm_Nomina 
  WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmClaseLiq IN ('NOMINA','NOVEDAD')
  AND tmIdConcepto NOT IN ('DCP','DCS','FSP','FSU','RET')
  GROUP BY tmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaCau] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContto,tmFecIni,tmFecFin,Count(tmItem) AS SCANT,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV
,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDed) AS STOTDED,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET,SUM(tmVrBaseLiq) AS SVALLIQ
,SUM(CASE WHEN tmIdConcepto='IGE' AND tmDiasCalc>0 AND tmBasExceso>0 THEN tmBasExceso ELSE 0 END) AS BASEIGECON
 FROM tm_Nomina AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero  AND tmItem>=@pmtmItem AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 GROUP BY  tmIdEmpleado,Apellidos,Nombres,tmNContto,tmFecIni,tmFecFin
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCip]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaCip] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmVrBaseLiq,tmIdEmpleado
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
ORDER BY tmIdEmpleado,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaCon] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4),@pmtmItem INT,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT Count(tmItem) AS SITEM
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto=@pmtmIdConcepto
 AND tmItem<>@pmtmItem  AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaCpre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaCpre] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT Count(tmItem) AS SITEM
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmNPrestamo>0
 AND  tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaDia] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmTipo CHAR(1),@pmtmIdConcepto VARCHAR(4),@pmtmItem INT
AS 
 IF @pmTipo='B'
  SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV,SUM(tmVrTotDed) AS SVALDED
,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
  FROM tm_Nomina
  WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
  AND tmIdConcepto IN ('BAS','LIC','IGE','IRP','VAC','DSR')
 ELSE
 BEGIN
  IF  @pmTipo='H'
   SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV  ,SUM(tmVrTotDed) AS SVALDED
 ,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
   FROM tm_Nomina
   WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
   AND tmIdConcepto IN ('HHD','HHN')--,'HFD','HFN')
  ELSE
   BEGIN
    IF  @pmTipo='E'
     SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV  ,SUM(tmVrTotDed) AS SVALDED
   ,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
     FROM tm_Nomina
     WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
     AND tmIdConcepto IN ('HED','HEN','HXD','HXN')
    ELSE
     SELECT SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDevg) AS SVALDEV  ,SUM(tmVrTotDed) AS SVALDED
   ,SUM(tmDiasCalc) AS SCANDIA,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET
     FROM tm_Nomina
     WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND  tmClaseLiq IN ('NOMINA','NOVEDAD') AND tmItem<>@pmtmItem
     AND tmIdConcepto=@pmtmIdConcepto
   END
END
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDsa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaDsa] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias,tmCodFondo,tmVrBaseLiq,tmHoraInicial,tmHoraFinal,tmTipoInc
 FROM tm_Nomina AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 WHERE tmNumero=@pmtmNumero  AND tmItem>=@pmtmItem
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')  --AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 ORDER BY Apellidos,Nombres,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDsl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaDsl] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmFecUltLiq,tmFecIni,tmFecFin,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias
,tmLogPmdio,tmClaseLiq,tmFecIniPmd,tmFecFinPmd,tmIdEmpleado
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq NOT IN ('PROVISION','APORTE') AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaDso] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDevg,tmUnidad,tmVrUnitario,tmVrTotDevg,tmCantDed,tmVrUnitario AS VrUndDed
,tmVrTotDed,tmNPrestamo,tmNCuota,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmDiasCalc-tmDiasNov AS Dias,tmIdEmpleado
,tmHoraInicial,tmHoraFinal,tmTipoInc
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
ORDER BY tmIdEmpleado,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaEdv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaEdv] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmClaseLiq VARCHAR(10)
,@pmtmItem INT
--valida si existe el primer concepto devengado
AS 
  SELECT Count(tmItem) AS SITEM
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado
  AND tmIdConcepto IN ('BAS','LIC','IGE','IRP','HHD','HHN','HFD','HFN','DSR','VAC')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')  AND tmItem<>@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaEitm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaEitm] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmItem INT,@pmtmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaGCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaGCon] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4)=Null,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT tmIdConcepto,tmClaseLiq,Count(tmItem) AS SITEM,SUM(tmVrBaseLiq) AS STOTBAS,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmVrTotDed) AS STOTDED
,SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED,SUM(tmVrOrigen) AS SBASORIG
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto LIKE ISNULL(@pmtmIdConcepto,'%')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%') 
 GROUP BY tmIdConcepto,tmClaseLiq
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaId] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT MAX(tmItem) AS MXITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaItm] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT
 AS 
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 AND  tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaLInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaLInt] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmClaseLiq VARCHAR(10)=Null
 AS 
 SELECT tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmClaseCon,tmDetalle,tmCantDevg,tmCantDed,tmVrUnitario,tmVrTotDevg,tmVrTotDed,tmUnidad,tmClaseLiq
,tmVrOrigen,tmTarifa,tmDiasCalc,tmDiasNov,tmCodFondo,tmNPrestamo,tmNCuota,tmOrigCargue,tmVrBaseLiq,tmNContto,tmFecIni,tmFecFin,tmIdPeriodo
,tmFecUltLiq,tmFecIniPmd,tmFecFinPmd,tmLogPmdio,tmNitTercero
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero AND tmClaseLiq IN ('NOMINA','PROVISION','APORTE','NOVEDAD',@pmClaseLiq)
 AND  tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaLpre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaLpre] @pmtmNumero VARCHAR(5),@pmtmIdConcepto VARCHAR(4)=Null,@pmtmIdEmpleado VARCHAR(16)=Null
,@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT tmNumero,tmIdEmpleado,tmItem,tmIdConcepto,tmCantDed,tmVrUnitario,tmVrTotDed,tmNPrestamo,tmNCuota,TotPrestamo,TotAbonado,VrPrestamo,NumCuotas
  FROM tm_Nomina AS N  INNER JOIN Trn_NomPrest AS P ON N.tmNPrestamo=P.NPrestamo
 WHERE  tmNumero=@pmtmNumero AND  tmNPrestamo>0 AND  tmIdEmpleado LIKE ISNULL(@pmtmIdEmpleado,'%')
 AND  tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')  AND tmIdConcepto LIKE ISNULL(@pmtmIdConcepto,'%')
ORDER BY tmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaNov] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmNContto INT
 AS 
 SELECT Count(tmItem) AS SCANT,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV
,SUM(tmCantDed) AS SCANDED,SUM(tmVrTotDed) AS STOTDED
,SUM(tmDiasCalc-tmDiasNov) AS SDIASNET,SUM(tmVrBaseLiq) AS SVALLIQ
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmItem>=0 AND tmClaseLiq='NOVEDAD' AND tmIdEmpleado=@pmtmIdEmpleado
 AND tmNContto=@pmtmNContto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaPre] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmItem INT,@pmtmNPrestamo INT
 AS 
 --VALIDA SI EXISTE EL PRESTAMO EN EL TEMPORAL
 SELECT COUNT(tmItem) AS SITEM
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq='NOMINA'  AND tmIdEmpleado=@pmtmIdEmpleado
 AND tmNPrestamo=@pmtmNPrestamo AND tmItem<>@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaRet] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT COUNT(tmItem) AS SITEM,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq='NOMINA' AND tmIdConcepto='RET'
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaSBas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaSBas] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmClaseLiq VARCHAR(10)
 AS 
 SELECT tmIdConcepto,SUM(tmCantDevg) AS SCANDEV,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmCantDed) AS SCANDED
,SUM(tmVrTotDed) AS STOTDED,SUM(tmVrBaseLiq) AS SBASLIQ
 FROM tm_Nomina 
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado 
 AND tmIdConcepto IN ('BAS','AXT','LIC','IGE','IRP','HHD','HHN','DSR','VAC')
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
 GROUP BY tmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaTCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaTCon] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
,@pmtmIdConcepto VARCHAR(4),@pmtmClaseLiq VARCHAR(10)=Null
AS 
  SELECT Count(tmItem) AS SITEM,SUM(tmVrBaseLiq) AS STOTBAS,SUM(tmVrTotDevg) AS STOTDEV,SUM(tmVrTotDed) AS STOTDED
,SUM(tmCantDevg) AS SCANDEV,SUM(tmCantDed) AS SCANDED
  FROM tm_Nomina
 WHERE  tmNumero=@pmtmNumero AND  tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto=@pmtmIdConcepto
 AND tmClaseLiq LIKE ISNULL(@pmtmClaseLiq,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaTot] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT COUNT(tmItem) AS SITEM,SUM(tmCantDevg) AS tCantDevg,SUM(tmVrTotDevg) AS tVrTotDevg
 ,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed,SUM(tmVrBaseLiq) AS tVrBaseLiq
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN  ('NOMINA','NOVEDAD')
  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaTPen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaTPen] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmIdPeriodo VARCHAR(8)=Null
 AS 
 SELECT COUNT(tmItem) AS SITEM,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN  ('NOMINA','NOVEDAD') AND tmIdConcepto IN ('DCP','FSP','FSU')
  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')  AND  tmIdPeriodo LIKE ISNULL(@pmtmIdPeriodo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaVac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaVac] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmItem,tmIdConcepto,tmDetalle,tmClaseCon,tmCantDed,tmUnidad,tmVrUnitario,tmVrTotDed,tmVrOrigen,tmTarifa
,tmNPrestamo,tmNCuota,tmDiasCalc,tmVrPension AS VrApoPension,tmVrBaseLiq AS VrCertf,tmIdEmpleado,tmIdPeriodo
,tmVrSalud,tmCodFondo
 FROM tm_Nomina
 WHERE tmNumero=@pmtmNumero  AND tmClaseLiq IN ('NOMINA','NOVEDAD')
 AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
ORDER BY tmIdEmpleado,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NominaVint]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NominaVint] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16)
 AS 
 SELECT tmIdConcepto,Concepto,SUM(tmCantDed) AS tCantDed,SUM(tmVrTotDed) AS tVrTotDed,SUM(tmCantDevg) AS tCantDevg,SUM(tmVrTotDevg) AS tVrTotDevg
 ,SUM(tmVrBaseLiq) AS tVrBaseLiq,SUM(tmVrOrigen) AS tVrOrigen
 FROM  tm_Nomina AS N INNER JOIN NomConceptos AS C ON N.tmIdConcepto=C.IdConcepto
 WHERE  tmNumero=@pmtmNumero  AND tmClaseLiq IN  ('NOMINA','NOVEDAD')
  AND tmIdEmpleado like ISNULL(@pmtmIdEmpleado,'%')
 GROUP BY tmIdConcepto,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NomRes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NomRes] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmItem,tmIdConcepto,tmDetalle,tmFecInicial,tmFecFinal,tmIdPeriodo
,tmCantDevg,tmVrTotDevg,tmCantDed,tmVrTotDed,tmUnidad,tmVrOrigen,Concepto,tmClaseLiq,ClaseCon,tmTarifa,tmDiasCalc,tmDiasNov
,tmCodFondo,FCO.Fondo AS NomFondo,tmNPrestamo,tmNCuota,tmVrBaseLiq,tmVrUnitario
,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina,tmTipoLiq,tmEsRetiro
,tmNLiqRet,tmVrSalario,tmVrATrans,tmpVehiculo,tmTipCom,tmComprobante,tmIdCiaCom,tmObservacion
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,FC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,E.Inactivo AS Emp_Inactvo
 FROM tm_NomRes AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN Areas AS AR ON N.tmIdArea=AR.IdArea INNER JOIN Dependencias AS DP ON N.tmIdDep=DP.IdDep
 INNER JOIN TiposNom AS TN ON N.tmIdNom=TN.IdNom 
 INNER JOIN CentroCosto AS CC ON N.tmIdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.tmIdSubCos=SC.IdSubCos
 INNER JOIN Instalaciones AS I ON N.tmIdInstala=I.IdInstala
 INNER JOIN NomConceptos AS NC ON N.tmIdConcepto=NC.IdConcepto
 INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo 
 INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo INNER JOIN Fondos AS FC ON E.IdCajaCom=FC.IdFondo 
 INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 LEFT JOIN Fondos AS FCO ON N.tmCodFondo=FCO.IdFondo
 WHERE tmNumero=@pmtmNumero
 ORDER BY Apellidos,Nombres,tmFecInicial,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_NomResCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_NomResCon] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmIdConcepto,Concepto,ClaseCon,tmDetalle
,SUM(tmCantDevg) AS CantDev,SUM(tmCantDed) AS CantDed,SUM(tmVrTotDevg) AS TotalDeveng
,SUM(tmVrTotDed) AS TotalDed,SUM(tmVrOrigen) AS VrOrigen,SUM(tmDiasCalc) AS CantDias,SUM(tmDiasNov) AS DiasNov
,SUM(tmVrBaseLiq) AS TotalBaseLiq
,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina
,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco
 FROM tm_NomRes AS N INNER JOIN Empleados AS E ON N.tmIdEmpleado=E.IdEmpleado
 INNER JOIN Areas AS AR ON N.tmIdArea=AR.IdArea INNER JOIN Dependencias AS DP ON N.tmIdDep=DP.IdDep
 INNER JOIN TiposNom AS TN ON N.tmIdNom=TN.IdNom 
 INNER JOIN CentroCosto AS CC ON N.tmIdCCosto=CC.IdCCosto INNER JOIN SubCentros AS SC ON N.tmIdSubCos=SC.IdSubCos
 INNER JOIN Instalaciones AS I ON N.tmIdInstala=I.IdInstala
 INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco 
 INNER JOIN NomConceptos AS NC ON N.tmIdConcepto=NC.IdConcepto
 WHERE tmNumero=@pmtmNumero
 GROUP BY  tmIdEmpleado,Apellidos,Nombres,tmNContrato,tmIdConcepto,Concepto,ClaseCon,tmDetalle
 ,tmIdArea,Area,tmIdDep,Dependencia,tmIdInstala,Instlacion,tmIdCCosto,CCosto,tmIdSubCos,SubCosto,tmIdNom,TipoNomina
,E.IdClase,ClaseCuenta,NumCuenta,E.IdBanco,Banco
 ORDER BY Apellidos,Nombres,Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_OccComp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_OccComp] @pmtmTipDoc VARCHAR(3),@pmtmOCargueIni INT
,@pmtmOCargueFin INT,@pmtmIdCia CHAR(2)
 AS 
 SELECT tmNumComp,tmIdProducto,DescripProd,DescripAbrv,Referencia,tmCantidad
,tmTipDoc,tmOCargue,tmIdCia
 FROM tm_OccComp AS C INNER JOIN ProdMcias AS P ON C.tmIdProducto=P.IdProducto
 WHERE tmTipDoc=@pmtmTipDoc AND tmOCargue BETWEEN @pmtmOCargueIni AND @pmtmOCargueFin AND tmIdCia=@pmtmIdCia
 ORDER BY tmNumComp
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_OccCompExi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_OccCompExi] @pmtmTipDoc VARCHAR(3),@pmtmOCargue INT,@pmtmIdCia CHAR(2)
 AS 
 SELECT COUNT(*) AS Scant
 FROM tm_OccComp
 WHERE tmTipDoc=@pmtmTipDoc AND tmOCargue=@pmtmOCargue AND tmIdCia=@pmtmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Pagos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Pagos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdForma,tmDetalle,tmVrPagado,tmVrCambio,tmEsCaja,tmIdBanco,tmNitCliente,tmCdAgencia,tmNumForma
,tmFecForma,tmCtaForma,tmBeneficiario,tmReferncia1,tmReferncia2,tmCdLocal,tmNumAutoriza,tmVrDenom,tmCantidad,tmTipDenom
,tmTipRef,tmDocRef,tmIdCiaRef,tmItemDoc,tmCdCta,tmCliente,tmTipDoc,tmDocumento,tmIdCia,tmTipAplica,tmConsCP,tmCodCueCons
 FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosChe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosChe] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdForma,tmDetalle,tmVrPagado,tmVrCambio,tmEsCaja,tmIdBanco,tmNitCliente,tmCdAgencia,tmNumForma
,tmFecForma,tmCtaForma,tmBeneficiario,tmReferncia1,tmReferncia2,tmCdLocal,tmNumAutoriza,tmTipAplica,tmIdCia,tmConsCP,tmCodCueCons
 FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero AND (tmIdForma IN ('CHE','BON','CON','TRA') OR tmIdForma LIKE 'CH%')
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosCmp] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmIdForma,FormaPago,tmDetalle,tmNumForma,tmFecForma,tmCtaForma,tmReferncia1
,tmReferncia2,tmCdCta,tmNumAutoriza,tmNitCliente,tmCdAgencia,tmConsCP,tmCodCueCons
,SUM(tmVrPagado) AS STOTPAG,SUM(tmVrCambio) AS STOTCAM
 FROM tm_Pagos AS P INNER JOIN Formaspago AS F ON P.tmIdForma=F.IdForma
 WHERE tmNumero=@pmtmNumero
 GROUP BY tmIdForma,FormaPago,tmDetalle,tmNumForma,tmFecForma,tmCtaForma,tmReferncia1
,tmReferncia2,tmCdCta,tmNumAutoriza,tmNitCliente,tmCdAgencia,tmConsCP,tmCodCueCons
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosCue] @pmtmNumero VARCHAR(5),@pmIdConcepto VARCHAR(4)
 AS 
 SELECT tmIdForma,IdConcepto,IdCuenta
 FROM tm_Pagos AS P INNER JOIN FormasCue AS F ON P.tmIdForma=F.IdForma
 WHERE tmNumero=@pmtmNumero AND IdConcepto=@pmIdConcepto
 ORDER BY  tmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdForma,FormaPago,tmVrPagado,tmNumForma,tmIdBanco,Banco,tmCtaForma,tmBeneficiario,tmFecForma
,tmCdLocal,tmDetalle,tmReferncia1,tmReferncia2,tmNumAutoriza,tmCdCta,tmVrDenom,tmCantidad
,tmVrDenom*tmCantidad AS TotalDenm,tmTipDenom,tmEsCaja,tmIdCia,tmTipRef,tmDocRef,tmIdCiaRef,tmItemDoc,tmConsCP,tmCodCueCons,tmNumero
 FROM tm_Pagos AS P INNER JOIN Formaspago AS F ON P.tmIdForma=F.IdForma
 LEFT JOIN Bancos AS B ON P.tmIdBanco=B.IdBanco
 WHERE tmNumero=@pmtmNumero
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosFor] @pmtmNumero VARCHAR(5),@pmtmIdForma VARCHAR(4),@pmtmIdBanco VARCHAR(4)
,@pmtmNumForma VARCHAR(20),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdForma,tmVrPagado,tmVrCambio,tmIdBanco,tmNumForma
 FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero AND tmIdForma=@pmtmIdForma AND tmIdBanco=@pmtmIdBanco
 AND tmNumForma=@pmtmNumForma AND tmItem<>@pmtmItem
 ORDER BY  tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosTEfe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosTEfe] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrPagado) AS STOTPAG,SUM(tmVrCambio) AS SCAMB
,SUM(tmVrDenom*tmCantidad) AS STOTDEN
 FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero AND tmIdForma='EFE'
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PagosTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_PagosTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCANT,SUM(tmVrPagado) AS STOTPAG,SUM(tmVrCambio) AS SCAMB
,SUM(tmVrDenom*tmCantidad) AS STOTDEN
 FROM tm_Pagos
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Plasueldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Plasueldos] @pmtmIdPeriodo VARCHAR(8),@pmMes VARCHAR(6),@pmtmKeyRegistro VARCHAR(30)=Null,@pmIdEmpleado VARCHAR(16)=Null
 AS 
 SELECT N.IdEmpleado AS IdEmpldo,Apellidos,Nombres,N.VrSalario AS VrSalBasico,tmDias,tmVrBasico,tmVrAuxtrans,tmVrHextras,tmVrRecargos,tmVrComision,tmVrIncapac,tmVrLicencia
,tmVrVacLiquida,tmVrOtrosDev,VrDevengado+tmVrVacLiquida AS Devengado,tmVrDctoPen,tmVrDctoSal,tmVrDctoFsp,tmVrRetencion,tmVrPrestmos,tmVrSanciones,tmVrOtrosDed,tmVrVacPen,tmVrVacSal,tmVrVacFsp,tmVrVacOtr
,VrDeducido+tmVrVacPen+tmVrVacSal+tmVrVacFsp+tmVrVacOtr AS Deducido
,(VrDevengado+tmVrVacLiquida) -(VrDeducido+tmVrVacPen+tmVrVacSal+tmVrVacFsp+tmVrVacOtr) AS VrNetoPagar,tmVrVacacnes,tmObserv,tmIdPeriodo,FecInicial,FecFinal,tmKeyRegistro
--datos nomina
,N.IdDep AS CodDep,Dependencia,N.IdInstala AS CodInst,Instlacion,N.IdCCosto AS CodCcto,CCosto,N.IdSubCos AS CodSubcen,SubCosto,N.IdNom AS CodNom,TipoNomina,Asistencia,NoDevenga
,TipoLiq,N.pVehiculo AS PlacaVeh,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS Nom_IdEstdo,EN.Estado AS Nom_Estado,EsRetiro,NLiqRet,Cantidad,CantNoRem
,TimeSys,N.FecUpdate AS FecUpd,N.IdUsuario AS IdUsuari,Usuario
--datos del contrato
,N.NContrato AS NumContrato,C.IdTipCon AS CodTipCon,TipoContrato,FecIngreso,FecRetiro,Indefinido,C.IdCargo AS CodCargo,Cargo,C.IdArea AS CodArea,Area,C.IdClase AS CodClaRie,ClaseRiesgo,CR.Tarifa AS TarifaRie
,VrAuxTrans,SalMinimo,SalIntegral,FPnomina,ATFinMes,SegFinMes,DchDotacion,DchCafeteria,C.IdEstado AS Con_IdEstdo,ECO.Estado AS Con_Estado,C.Inactivo AS Con_inactivo,C.IdJornada AS CodJnada,Jornada,TipoTrabj
--datos del empleado
,Codigo,IdLugarCed,Localidad,E.Direccion AS Dirccion,Telefono,TelMovil,e_mail,E.IdProf AS CodProf,Profesion,E.IdClase AS CodClaCta,ClaseCuenta,NumCuenta,E.IdBanco AS CodBanco,Banco,IdFonPen,FP.Fondo AS FondoPen
,IdFonEps,FS.Fondo AS FondoEps,IdFonArp,FR.Fondo AS FondoArp,IdCajaCom,CC.Fondo AS CajaComp,EsCondtor,FecNacmto,Licencia,CatLicencia,VigLicencia,E.IdLugar AS CodLugar,LugarLic,TallaCam,TallaPan,TallaZap,E.Inactivo AS Emp_Inactvo
,NumVeh,TipoAdmon,VehPropio
 FROM tm_Plasueldos AS PS INNER JOIN Trn_Nomina AS N ON PS.tmIdPeriodo=N.IdPeriodo AND PS.tmKeyRegistro=N.KeyRegistro
 INNER JOIN Empleados AS E ON N.IdEmpleado=E.IdEmpleado INNER JOIN  Emp_Contrato AS C ON N.NContrato=C.NContrato
 INNER JOIN Dependencias AS DP ON N.IdDep=DP.IdDep  INNER JOIN Instalaciones AS I ON N.IdInstala=I.IdInstala
 INNER JOIN CentroCosto AS CO ON N.IdCCosto=CO.IdCCosto  INNER JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 INNER JOIN TiposNom AS TN ON N.IdNom=TN.IdNom INNER JOIN EstadoDoc AS EN ON N.IdEstado=EN.IdEstado 
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario INNER JOIN Localidades AS L ON E.IdLugarCed=L.IdLocal
 INNER JOIN Profesiones AS P ON E.IdProf=P.IdProf   INNER JOIN ClaseCta AS CT ON E.IdClase=CT.IdClase
 INNER JOIN Bancos AS B ON E.IdBanco=B.IdBanco  INNER JOIN Fondos AS FP ON E.IdFonPen=FP.IdFondo
 INNER JOIN Fondos AS FS ON E.IdFonEps=FS.IdFondo  INNER JOIN Fondos AS FR ON E.IdFonArp=FR.IdFondo
 INNER JOIN Fondos AS CC ON E.IdCajaCom=CC.IdFondo INNER JOIN ExpLicencias AS EL ON E.IdLugar=EL.IdLugar
 INNER JOIN TiposCon AS TC ON C.IdTipCon=TC.IdTipCon  INNER JOIN Cargos AS CG ON C.IdCargo=CG.IdCargo
 INNER JOIN Areas AS AR ON C.IdArea=AR.IdArea INNER JOIN ClaseRie AS CR ON C.IdClase=CR.IdClase
 INNER JOIN Jornadas AS J ON C.IdJornada=J.IdJornada  INNER JOIN EstadoDoc AS ECO ON C.IdEstado=ECO.IdEstado
 LEFT JOIN NomVehiculos AS VH ON N.pVehiculo=VH.IdVehiculo
 WHERE SUBSTRING(tmIdPeriodo,1,6)=@pmMes AND tmIdPeriodo LIKE ISNULL(@pmtmIdPeriodo,'%') 
 AND tmKeyRegistro LIKE ISNULL(@pmtmKeyRegistro,'%')  AND N.IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 ORDER BY Apellidos,Nombres,N.IdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PlasueldosKey]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PlasueldosKey] @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30)
 AS 
 SELECT tmIdPeriodo,tmKeyRegistro,tmDias
 FROM tm_Plasueldos 
 WHERE tmKeyRegistro=@pmtmKeyRegistro AND SUBSTRING(tmIdPeriodo,1,6)=@pmtmIdPeriodo
 ORDER BY tmIdPeriodo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreAbonos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PreAbonos] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmTipDoc,tmIdPrestamo,tmIdCiaPre,tmItemPre,tmVrAbono,tmVrBaseCms,tmIdCliente,tmIdAgencia,tmIdVend,tmComision,tmDetalle,tmGalones
,tmTipoAplica,tmCodTarCom,tmTipRec,tmRecibo,tmCiaRec,tmItemRec,tmFecPago
 FROM tm_PreAbonos
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreCartera]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PreCartera] @pmtmEst CHAR(2),@pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME
 AS 
 SELECT T.RazonSocial AS NomCliente,C.IdCliente AS NitCliente,NomAgencia AS Agencia,C.IdAgencia AS CdAgencia,C.TipDoc AS CdTipoDoc,TipoDoc,IdPrestamo,C.IdCia AS CdCia,Compania,Item
,VrTotal,VrAbonado,CASE C.TipDoc WHEN 'SAF' THEN C.VrSaldo*-1  ELSE  C.VrSaldo END AS ValorSaldo,Fecha,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
,C.Concepto AS ConceptoCuota,NumCuota,Detalle,C.IdConcepto AS CdConcepto,CO.Concepto AS NomConcepto,C.IdVend AS CdVend,VN.RazonSocial AS Vendedor,TipoTasa,DTF_EA,TasaNom,Spread_TA,TasaEfe,TipoCuota
,NumCausacion,IdCiaCau,FecUltPago,FecLiqMora,C.FechaCrea,CtaForma,Beneficiario,RefCheque,NumCheque,CdBanco
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdVend AS CdVendClie,VNC.RazonSocial AS NomVendClie
,DirAgencia,CLI.IdLocalAge  AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,Comentarios
 FROM tm_PreCartera  AS C INNER JOIN Terceros AS T ON C.IdCliente=T.IdTercero  INNER JOIN  Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS VN ON C.IdVend=VN.IdTercero
 INNER JOIN TercCliePrestamo AS CLI ON C.IdCliente=CLI.IdClie AND C.IdAgencia=CLI.IdAgencia
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona   INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo INNER JOIN Terceros AS VNC ON CLI.IdVend=VNC.IdTercero
 INNER JOIN  TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Conceptos AS CO ON C.IdConcepto=CO.IdConcepto  LEFT JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE tmEst=@pmtmEst AND C.VrSaldo>@pmSaldo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreCuotasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paQrytm_PreCuotasLta] @pmtmNumero VARCHAR(5)
AS
SELECT  tmItem, tmTipDoc, tmPrestamo, tmIdCiaPre, tmItemPre, tmCuota, tmConcepto, tmFecCausa, tmFecVence, tmVrTotal
,tmTipoTasa, tmDTF_EA,tmTasaNom, tmSpread, tmTasaEfe, tmIdCliente,T.RazonSocial AS NomCliente,tmIdAgencia,NomAgencia AS Agencia
,tmIdVend,V.RazonSocial AS NomVendedor,tmEstado, tmDetalle,tmLinCred,tmFactura,tmDiasLiq,tmVrIntCorr, tmTotAbono,tmVrSaldo
,tmUltCausac,tmVrAcumCap,tmNitConv,tmVrSeguro,tmVrProrroga,tmVrCustodia,tmTasaCustod,tmTarifIva,tmVrIva,tmTarifRet,tmVrRet
,tmPMInicio,tmPMFinal,tmPMDias,tmPMValorInt
--datos del prestamo
,FecPrestamo,VrPrestamo,NPlazos,Causacion,P.NContrato AS NumContrato,CdCiaCon,NumCuotaIni,P.IdEstado AS CdEstado
 FROM   tm_PreCuotas AS PC  INNER JOIN Terceros AS T ON PC.tmIdCliente=T.IdTercero
 INNER JOIN Terceros AS V ON PC.tmIdVend=V.IdTercero
 INNER JOIN Trn_FinPrestamo AS P ON PC.tmTipDoc=P.TipDoc AND PC.tmPrestamo=P.IdPrestamo AND PC.tmIdCiaPre=P.IdCia
 LEFT JOIN TercCliePrestamo AS A ON  PC.tmIdCliente=A.IdClie AND PC.tmIdAgencia=A.IdAgencia
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreCuotasSim]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paQrytm_PreCuotasSim] @pmtmNumero VARCHAR(5)
AS
SELECT tmItem,tmItemPre,tmCuota,tmConcepto,tmFecCausa,tmFecVence,tmVrTotal,tmTipoTasa,tmDTF_EA,tmTasaNom,tmSpread,tmTasaEfe,tmDiasLiq
,tmDetalle,tmLinCred,L.LinCredito,L.PuntosTI,tmIdCliente,N.RazonSocial AS NomCliente,tmIdAgencia,NomAgencia AS Agencia,tmIdVend,V.RazonSocial AS NomVendedor
,tmVrIntCorr,tmTotAbono,tmVrSaldo,tmVrAcumCap,tmVrSeguro,tmVrProrroga,tmVrCustodia,tmTasaCustod,tmNitConv,tmTarifIva,tmVrIva,tmTarifRet,tmVrRet
,tmPMInicio,tmPMFinal,tmPMDias,tmPMValorInt
 FROM tm_PreCuotas AS T LEFT JOIN Terceros AS N ON T.tmIdCliente=N.IdTercero
 LEFT JOIN Terceros AS V ON T.tmIdVend=V.IdTercero
 LEFT JOIN TercCliePrestamo AS A ON T.tmIdCliente=A.IdClie AND T.tmIdAgencia=A.IdAgencia
 LEFT JOIN LineasCred AS L ON T.tmLinCred=L.IdLinea
 WHERE tmNumero=@pmtmNumero
 
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreExtoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_PreExtoLta] @pmtmEst CHAR(2),@pmFecInicio SMALLDATETIME,@pmFecCorte SMALLDATETIME,@pmtmTipoRep INT
AS 
SELECT tmIdCliente,T.RazonSocial AS NomCliente,tmIdAgencia,NomAgencia AS Agencia,tmFecha,tmFecVence,tmTipDoc,TipoDoc,tmNumero,tmIdCia,Compania,tmItem,tmCargos,tmAbonos
,tmIdLinea,LinCredito,CupoCredito,tmConcepto,tmDetalle,tmReferencia,tmCredito,tmVrPrestamo,tmVrCuota,tmTotAbonos,tmTipoAbono,tmNCuota,tmIdVend,VN.RazonSocial AS NomVendedor
,tmTipRef,tmDocRef,tmIdCiaRef,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmDTF_EA,tmTasaNom,tmTasaEfe
,tmSanClie,tmSanCia,tmSanAgenc,tmSanAgeCia,tmSanLinea,tmSanLineaCia,tmSanConc,tmSanConcCia,IdReg,tmTimeSys
,NumCredito,NPlazos,Causacion,FecPrestamo,TipoCredito,P.Observacion AS Observ,ISNULL(SaldoMora,0) AS VrSaldoMora
--Total pagos a capital
,ISNULL(CASE tmTipDoc WHEN 'PR1' THEN (SELECT SUM(Trn_FinAbonos.TotalAbono) FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc
 AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
 WHERE Trn_FinAbonos.TipDoc=EX.tmTipDoc AND Trn_FinAbonos.IdPrestamo=EX.tmNumero AND Trn_FinAbonos.IdCiaPre=EX.tmIdCia
 AND Trn_FinAbonos.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='CAPITAL') ELSE 0 END,0) AS VrPagosCapital
,ISNULL(CASE tmTipDoc WHEN 'PR1' THEN (SELECT COUNT(NumCuota) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=EX.tmTipDoc AND Trn_FinCuotas.IdPrestamo=EX.tmNumero AND Trn_FinCuotas.IdCia=EX.tmIdCia
 AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='CAPITAL') ELSE 0 END,0) AS CuotasCausadas
,ISNULL(CASE tmTipDoc WHEN 'PR1' THEN (SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=EX.tmTipDoc AND Trn_FinCuotas.IdPrestamo=EX.tmNumero AND Trn_FinCuotas.IdCia=EX.tmIdCia
 AND Trn_FinCuotas.Fecha<=@pmFecCorte AND Trn_FinCuotas.Concepto='CAPITAL') ELSE 0 END,0) AS TotalCausac
--datos del cliente
,T.TipoId AS ClieTipoId,T.Dv AS ClieDv,T.Direccion AS ClieDireccion,T.IdLocal AS ClieCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS ClieDpto
,T.Telefono AS ClieTelefono,T.Fax AS ClieFax,T.e_mail AS ClieEmail,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento
FROM tm_PreExto AS EX INNER JOIN Terceros AS T ON EX.tmIdCliente=T.IdTercero INNER JOIN  Companias AS CI ON EX.tmIdCia=CI.IdCia
INNER JOIN LineasCred AS LC ON EX.tmIdLinea=LC.IdLinea
INNER JOIN  TercCliePrestamo AS CLI ON EX.tmIdCliente=CLI.IdClie AND EX.tmIdAgencia=CLI.IdAgencia
INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo  INNER JOIN  TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
LEFT JOIN Terceros AS VN ON EX.tmIdVend=VN.IdTercero
LEFT JOIN TercClieLineas AS CL ON EX.tmIdCliente=CL.IdClie AND EX.tmIdAgencia=CL.IdAgencia AND EX.tmIdLinea=CL.IdLinea
LEFT JOIN Sys_TiposDoc AS TD ON EX.tmTipDoc=TD.IdDoc 
LEFT JOIN Trn_FinPrestamo AS P ON EX.tmTipDoc=P.TipDoc AND EX.tmNumero=P.IdPrestamo AND EX.tmIdCia=P.IdCia
LEFT JOIN (SELECT IdCliente,IdAgencia,CodLinCred,SUM(VrTotal-VrAbonado) AS SaldoMora FROM Trn_FinCuotas WHERE Fecha<@pmFecCorte AND VrTotal>VrAbonado GROUP BY IdCliente,IdAgencia,CodLinCred)
AS SM ON EX.tmIdCliente=SM.IdCliente AND EX.tmIdAgencia=SM.IdAgencia AND EX.tmIdLinea=SM.CodLinCred
WHERE tmEst=@pmtmEst AND tmTipoRep=@pmtmTipoRep
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreIntMoraLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paQrytm_PreIntMoraLta] @pmtmNumero VARCHAR(5)
AS
 SELECT tmItem,tmTipDoc,tmPrestamo,tmIdCia,tmItemPre,tmNCuota,tmIdCliente,T.RazonSocial AS NomCliente,tmIdAgencia,NomAgencia AS Agencia
,tmIdVend,V.RazonSocial AS NomVendedor,tmFecVence,tmVrTotal,tmVrAbonado,tmFecUltLiq,tmFecIniLiq,tmFecFinLiq,tmDiasLiq,tmDiasGracia,tmBaseLiq
,tmTasaEA,tmTasaEM,tmTasaDia,tmVrLiquida,tmTarifaIva,tmVrIva,tmEstado,tmDetalle,tmLinCred,tmTarifaRet,tmVrRetFte
FROM  tm_PreIntMora AS IM INNER JOIN Terceros AS T ON IM.tmIdCliente=T.IdTercero
INNER JOIN Terceros AS V ON IM.tmIdVend=V.IdTercero
LEFT JOIN TercCliePrestamo AS A ON  IM.tmIdCliente=A.IdClie AND IM.tmIdAgencia=A.IdAgencia
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_PreMovi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_PreMovi] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCliente,T.RazonSocial AS NomCliente,tmIdAgencia,NomAgencia AS Agencia,tmIdCia,Compania,tmTipDoc,TipoDoc,tmNumero,tmItem,tmFecha,tmCargos,tmAbonos,tmConcepto,tmDetalle,tmReferencia
 ,tmNumCuota,tmNumForma,tmTipRef,tmDocRef,tmIdCiaRef,tmCdConcepto,Concepto,tmIdVend,VN.RazonSocial AS Vendedor,tmSanAge,tmSanAgeCia,tmSanClie,tmSanClieCia
,tmTimeSys,tmFecVence,tmTipoTasa,tmDTF_EA,tmTasaNom,tmPuntos,tmTasaEfe,tmCdBanco,Banco,tmBeneficiario,tmCdForma
,tmEnEfectivo,tmTotalAbono,tmVrAfavor,tmTipCom,tmComprobante,tmIdCiaCom,tmAnulado,tmNumDev,tmFecDev,tmIdUsuario,Usuario
--Datos del cliente
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,DP.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
--agencias
,DirAgencia,CLI.IdLocalAge  AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep,DA.Departamento AS AgeDpto,CLI.IdTipoTerc AS CdTipoTerc,TipoTercero,EsExento,Comentarios
 FROM tm_PreMovi  AS  M  INNER JOIN Terceros AS T ON M.tmIdCliente=T.IdTercero  INNER JOIN  Companias AS CI ON M.tmIdCia=CI.IdCia
 INNER JOIN Terceros AS VN ON M.tmIdVend=VN.IdTercero INNER JOIN  TercCliePrestamo AS CLI ON M.tmIdCliente=CLI.IdClie AND M.tmIdAgencia=CLI.IdAgencia
 INNER JOIN adm_Usuarios AS U ON M.tmIdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona   INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo  INNER JOIN  TiposTerc AS TTC ON CLI.IdTipoTerc=TTC.IdTipoTerc
 LEFT JOIN Conceptos AS C ON M.tmCdConcepto=C.IdConcepto  LEFT JOIN Sys_TiposDoc AS TD ON M.tmTipDoc=TD.IdDoc
 LEFT JOIN Bancos AS B ON M.tmCdBanco =B.IdBanco 
 LEFT JOIN Localidades AS LA ON  CLI.IdLocalAge=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 WHERE tmEst=@pmtmEst
 ORDER BY T.RazonSocial,tmIdAgencia,tmTimeSys
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplica]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplica] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmTipoDoc,tmDocumento,tmIdCiaDoc,tmItemDoc,tmIdClase,tmIdCargo,tmValor,tmIdVehiculo,tmVehPropio,tmIdConductor
,tmIdCliente,tmIdAgencia,tmReferencia,tmFactura,tmDetalle,tmComision,tmDescuento,tmConductor,tmTipRec,tmRecibo,tmCiaRec,tmFecRec,tmItemRec,tmAplAnt
 FROM tm_RecAplica
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaCmp] @pmtmNumero VARCHAR(5),@pmtmAplAnt BIT=Null
AS
 SELECT  tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor,sum(tmValor) AS SValAbo
 FROM    tm_RecAplica  
 WHERE tmNumero=@pmtmNumero
 AND (tmAplAnt=ISNULL(@pmtmAplAnt,0) or tmAplAnt=ISNULL(@pmtmAplAnt,1))
 GROUP BY  tmIdCliente,tmIdVehiculo,tmVehPropio,tmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaCr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaCr] @pmtmNumero VARCHAR(5),@pmtmAplAnt BIT=Null
AS
 SELECT     tmNumero, tmItem, tmTipoDoc, tmDocumento, tmIdCiaDoc, tmItemDoc, tmIdClase, tmIdCargo, tmValor, tmIdVehiculo, tmVehPropio, tmIdConductor, 
                      tmIdCliente, tmIdAgencia, tmReferencia, tmFactura, tmDetalle, tmComision, tmDescuento, tmConductor,tmTipRec,tmRecibo, tmCiaRec, tmFecRec, tmItemRec,tmAplAnt
 FROM    tm_RecAplica  
 WHERE tmNumero=@pmtmNumero 
 AND (tmAplAnt=ISNULL(@pmtmAplAnt,0) or tmAplAnt=ISNULL(@pmtmAplAnt,1))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaDoc] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipoDoc VARCHAR(3),@pmtmDocumento INT
,@pmtmIdCiaDoc CHAR(2),@pmtmItemDoc INT
AS
 IF @pmtmItem IS NULL
  SELECT  tmNumero, tmItem, tmTipoDoc, tmDocumento, tmIdCiaDoc, tmItemDoc, tmValor  FROM    tm_RecAplica  
  WHERE tmNumero=@pmtmNumero AND tmTipoDoc=@pmtmTipoDoc AND tmDocumento=@pmtmDocumento AND tmIdCiaDoc=@pmtmIdCiaDoc
  AND tmItemDoc=@pmtmItemDoc 
 ORDER BY tmItem
 ELSE
  SELECT  tmNumero, tmItem, tmTipoDoc, tmDocumento, tmIdCiaDoc, tmItemDoc, tmValor  FROM    tm_RecAplica  
  WHERE tmNumero=@pmtmNumero AND tmTipoDoc=@pmtmTipoDoc AND tmDocumento=@pmtmDocumento AND tmIdCiaDoc=@pmtmIdCiaDoc
  AND tmItemDoc=@pmtmItemDoc  AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaDso] @pmtmNumero VARCHAR(5)
AS
 SELECT   tmItem, tmTipoDoc, tmDocumento, tmIdCiaDoc, tmItemDoc,tmValor,tmDescuento,tmDetalle,tmIdCliente,tmIdVehiculo,tmVehPropio
,tmIdConductor,tmConductor,tmReferencia,tmFactura
 FROM    tm_RecAplica  
 WHERE  tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaGap]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaGap] @pmtmNumero VARCHAR(5),@pmtmAplAnt BIT=Null
AS
 SELECT tmIdCliente,tmIdVehiculo,SUM( tmValor) AS STotApl, SUM(tmDescuento) AS STotDct
 FROM    tm_RecAplica  
 WHERE tmNumero=@pmtmNumero
 AND (tmAplAnt=ISNULL(@pmtmAplAnt,0) or tmAplAnt=ISNULL(@pmtmAplAnt,1))
 GROUP BY  tmIdCliente,tmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaGru] @pmtmNumero VARCHAR(5)
AS
 SELECT   tmTipoDoc, tmDocumento, tmIdCiaDoc, tmItemDoc,SUM( tmValor) AS STotApl, SUM(tmDescuento) AS STotDct
 FROM    tm_RecAplica  
 WHERE tmNumero=@pmtmNumero
 GROUP BY tmTipoDoc, tmDocumento, tmIdCiaDoc, tmItemDoc
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_RecAplicaRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_RecAplicaRec] @pmtmNumero VARCHAR(5)
AS
 SELECT tmTipRec,tmRecibo, tmCiaRec,SUM(tmValor) AS StotVal
 FROM    tm_RecAplica  
 WHERE tmNumero=@pmtmNumero
 GROUP BY tmTipRec,tmRecibo, tmCiaRec
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalle]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ReqDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmItem,tmCdProducto,tmDescripcion,tmIdSubgrupo,tmCdBodega,tmCantidad,tmIdUnd,tmVrUnitario
,tmTipOrd,tmNumOrden,tmIdCiaOrd,tmTipSal,tmNSalida,tmIdCiaSal,tmFechaSal
,tmCantSalida,tmIdOperario,tmCdCenServ,tmNitTercero,tmNumVehic,tmNumParte,tmEstado,tmObservacion
,tmCodConc,tmVrPrecio,tmCodCenCto,tmCodSubCto,tmCantOrden,tmNumero
 FROM tm_ReqDetalle
 WHERE tmNumero=@pmtmNumero
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalleDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ReqDetalleDso] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmCdProducto,tmDescripcion,tmCantidad,tmIdUnd,Unidad,tmVrUnitario,tmCantidad*tmVrUnitario AS ValorTotal
,tmTipOrd,tmNumOrden,tmIdCiaOrd,tmCantOrden,tmTipSal,tmNSalida,tmIdCiaSal,tmFechaSal,tmCantSalida,tmIdSubgrupo,tmCdBodega,tmObservacion
,tmVrPrecio,tmCodCenCto,tmCodSubCto,tmNumVehic,tmNumero
 FROM tm_ReqDetalle AS D INNER JOIN UndMed AS U ON D.tmIdUnd=U.IdUnd
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalleItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ReqDetalleItm] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM
 FROM tm_ReqDetalle
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ReqDetalleTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_ReqDetalleTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT COUNT(tmItem) AS SCOUNT,SUM(tmCantidad) AS SCANT,SUM(tmCantidad*tmVrUnitario) AS SVALTOTAL
 FROM tm_ReqDetalle
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ResMensualCli] @pmtmEst CHAR(2),@pmtmTipo INT
 AS 
 SELECT tmIdTercero,tmCodigo,T.RazonSocial AS NomCliente,tmIdCia,Compania,tmCdAgencia,Agencia
,tmEneSaldoAnt,tmEneDebitos,tmEneCreditos,tmFebSaldoAnt,tmFebDebitos,tmFebCreditos,tmMarSaldoAnt,tmMarDebitos,tmMarCreditos,tmAbrSaldoAnt,tmAbrDebitos,tmAbrCreditos
,tmMaySaldoAnt,tmMayDebitos,tmMayCreditos,tmJunSaldoAnt,tmJunDebitos,tmJunCreditos,tmJulSaldoAnt,tmJulDebitos,tmJulCreditos,tmAgoSaldoAnt,tmAgoDebitos,tmAgoCreditos
,tmSepSaldoAnt,tmSepDebitos,tmSepCreditos,tmOctSaldoAnt,tmOctDebitos,tmOctCreditos,tmNovSaldoAnt,tmNovDebitos,tmNovCreditos,tmDicSaldoAnt,tmDicDebitos,tmDicCreditos
--DATOS DEL CLIENTE
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdVend AS NitVend,VN.RazonSocial AS NomVendedor
,CLI.CdBandera AS CodBandera,TipoBandera
,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.IdSector AS CdSector,SectorEco
 FROM tm_ResMensual  AS TR INNER JOIN Terceros AS T ON  TR.tmCodigo=T.IdTercero INNER JOIN TercCliente AS CLI ON TR.tmCodigo=CLI.IdClie
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo  LEFT JOIN  Terceros AS VN ON CLI.IdVend=VN.IdTercero 
 LEFT  JOIN Companias AS CN ON  TR.tmIdCia=CN.IdCia LEFT JOIN Agencias  AS A ON TR.tmCdAgencia=A.IdAgencia
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera
 WHERE tmEst=@pmtmEst AND  tmTipo=@pmtmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ResMensualCue] @pmtmEst CHAR(2),@pmtmTipo INT
 AS 
 SELECT  tmCodigo,ISNULL(P.NomCuenta,PN.NomCuenta) AS NomCuenta,tmIdCia,Compania,tmIdTercero,RazonSocial,tmCdAgencia,A.Agencia AS NomAgencia
,tmCdCCosto,CCosto,tmCdSubCos,SubCosto,tmpVehiculo,tmTipoAfi
,tmEneSaldoAnt,tmEneDebitos,tmEneCreditos,tmFebSaldoAnt,tmFebDebitos,tmFebCreditos,tmMarSaldoAnt,tmMarDebitos,tmMarCreditos,tmAbrSaldoAnt,tmAbrDebitos,tmAbrCreditos
,tmMaySaldoAnt,tmMayDebitos,tmMayCreditos,tmJunSaldoAnt,tmJunDebitos,tmJunCreditos,tmJulSaldoAnt,tmJulDebitos,tmJulCreditos,tmAgoSaldoAnt,tmAgoDebitos,tmAgoCreditos
,tmSepSaldoAnt,tmSepDebitos,tmSepCreditos,tmOctSaldoAnt,tmOctDebitos,tmOctCreditos,tmNovSaldoAnt,tmNovDebitos,tmNovCreditos,tmDicSaldoAnt,tmDicDebitos,tmDicCreditos
,tmM13SaldoAnt,tmM13Debitos,tmM13Creditos
 FROM tm_ResMensual AS TR LEFT JOIN Puc AS P ON TR.tmCodigo=P.IdCuenta LEFT JOIN PucNiif AS PN ON TR.tmCodigo=PN.IdCuenta
 LEFT JOIN Companias AS CN ON  TR.tmIdCia=CN.IdCia  LEFT JOIN Terceros AS T ON TR.tmIdTercero=T.IdTercero
 LEFT JOIN Agencias  AS A ON TR.tmCdAgencia=A.IdAgencia
 LEFT JOIN CentroCosto AS CC ON TR.tmCdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON TR.tmCdSubCos=SC.IdSubCos
 WHERE tmEst=@pmtmEst AND  tmTipo=@pmtmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualCueN]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ResMensualCueN] @pmtmEst CHAR(2),@pmtmTipo INT
 AS 
 SELECT  tmCodigo,ISNULL(P.NomCuenta,PN.NomCuenta) AS NomCuenta,tmIdCia,Compania,tmIdTercero,RazonSocial,tmCdAgencia,A.Agencia AS NomAgencia
,tmCdCCosto,CCosto,tmCdSubCos,SubCosto,tmpVehiculo,tmTipoAfi
,tmEneSaldoAnt,tmEneDebitos,tmEneCreditos,tmFebSaldoAnt,tmFebDebitos,tmFebCreditos,tmMarSaldoAnt,tmMarDebitos,tmMarCreditos,tmAbrSaldoAnt,tmAbrDebitos,tmAbrCreditos
,tmMaySaldoAnt,tmMayDebitos,tmMayCreditos,tmJunSaldoAnt,tmJunDebitos,tmJunCreditos,tmJulSaldoAnt,tmJulDebitos,tmJulCreditos,tmAgoSaldoAnt,tmAgoDebitos,tmAgoCreditos
,tmSepSaldoAnt,tmSepDebitos,tmSepCreditos,tmOctSaldoAnt,tmOctDebitos,tmOctCreditos,tmNovSaldoAnt,tmNovDebitos,tmNovCreditos,tmDicSaldoAnt,tmDicDebitos,tmDicCreditos
,tmM13SaldoAnt,tmM13Debitos,tmM13Creditos
,tmNivel1,tmNivel2,tmNivel4,tmNivel6,tmNivel9,tmNivel12
 FROM tm_ResMensual AS TR LEFT JOIN Puc AS P ON TR.tmCodigo=P.IdCuenta LEFT JOIN PucNiif AS PN ON TR.tmCodigo=PN.IdCuenta
 LEFT JOIN Companias AS CN ON  TR.tmIdCia=CN.IdCia LEFT JOIN Terceros AS T ON TR.tmIdTercero=T.IdTercero
 LEFT JOIN Agencias AS A ON TR.tmCdAgencia=A.IdAgencia
 LEFT JOIN CentroCosto AS CC ON TR.tmCdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON TR.tmCdSubCos=SC.IdSubCos
 LEFT JOIN tm_NivCue AS NV ON TR.tmCodigo=NV.tmIdCuenta
 WHERE tmEst=@pmtmEst AND  tmTipo=@pmtmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ResMensualInv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ResMensualInv] @pmtmEst CHAR(2),@pmtmTipo INT
 AS 
 SELECT tmCodigo,DescripProd,tmIdCia,Compania,tmCdBodega,Bodega,tmCdTanque,T.tmEneSaldoAnt AS CostoAntEne,tmEneDebitos,tmEneCreditos,T.tmFebSaldoAnt AS CostoAntFeb,tmFebDebitos,tmFebCreditos,T.tmMarSaldoAnt AS CostoAntMar,tmMarDebitos,tmMarCreditos
,T.tmAbrSaldoAnt AS CostoAntAbr,tmAbrDebitos,tmAbrCreditos,T.tmMaySaldoAnt AS CostoAntMay,tmMayDebitos,tmMayCreditos,T.tmJunSaldoAnt AS CostoAntJun,tmJunDebitos,tmJunCreditos,T.tmJulSaldoAnt AS CostoAntJul,tmJulDebitos,tmJulCreditos
,T.tmAgoSaldoAnt AS CostoAntAgo,tmAgoDebitos,tmAgoCreditos,T.tmSepSaldoAnt AS CostoAntSep,tmSepDebitos,tmSepCreditos,T.tmOctSaldoAnt AS CostoAntOct,tmOctDebitos,tmOctCreditos,T.tmNovSaldoAnt AS CostoAntNov,tmNovDebitos,tmNovCreditos
,T.tmDicSaldoAnt AS CostoAntDic,tmDicDebitos,tmDicCreditos
--datos de unidades
,U.tmEneSaldoAnt AS SaldoAntEne,tmEneEntradas,tmEneSalidas,U.tmFebSaldoAnt AS SaldoAntFeb,tmFebEntradas,tmFebSalidas,U.tmMarSaldoAnt AS SaldoAntMar,tmMarEntradas,tmMarSalidas,U.tmAbrSaldoAnt AS SaldoAntAbr
,tmAbrEntradas,tmAbrSalidas,U.tmMaySaldoAnt AS SaldoAntMay,tmMayEntradas,tmMaySalidas,U.tmJunSaldoAnt AS SaldoAntJun,tmJunEntradas,tmJunSalidas,U.tmJulSaldoAnt AS SaldoAntJul,tmJulEntradas
,tmJulSalidas,U.tmAgoSaldoAnt AS SaldoAntAgo,tmAgoEntradas,tmAgoSalidas,U.tmSepSaldoAnt AS SaldoAntSep,tmSepEntradas,tmSepSalidas,U.tmOctSaldoAnt AS SaldoAntOct,tmOctEntradas,tmOctSalidas,U.tmNovSaldoAnt AS SaldoAntNov,tmNovEntradas,tmNovSalidas,U.tmDicSaldoAnt AS SaldoAntDic,tmDicEntradas,tmDicSalidas
--datos de productos
,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,TipoRef,PM.IdMarca AS CdMarca,Marca,FecUltcom,FecUltVta,Tanques
,IdProv,RazonSocial
 FROM tm_ResMensual  AS T INNER JOIN tm_ResInvent AS U ON T.tmEst=U.tmEst AND T.tmTipo=U.tmTipo AND T.tmItem=U.tmItem
 INNER JOIN ProdMcias  AS PM ON T.tmCodigo=PM.IdProducto  INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo
 INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo  INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Terceros AS TP ON  PM.IdProv=TP.IdTercero
 LEFT  JOIN Companias AS CN ON  T.tmIdCia=CN.IdCia  LEFT JOIN Bodegas AS B ON T.tmCdBodega=B.IdBodega 
 WHERE T.tmEst=@pmtmEst AND T.tmTipo=@pmtmTipo
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Saldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Saldos] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdCuenta,NomCuenta,tmIdTercero,RazonSocial,tmCdSubgrupo,Subgrupo,tmIdCia,Compania
,tmSanCue,tmDebitos,tmCreditos,tmCostoAnt,tmCostoEnt,tmCostoSal,tmSaldoAnt,tmEntradas,tmSalidas
--datos del subgrupo y cuenta
,G.IdLinea AS CdLinea,Linea,SG.IdGrupo AS CdGrupo,Grupo,Tercero,Agencia,Vencimiento
--datos del tercero
,Codigo,TipoId,Dv,SiglaRaz,NomCial
 FROM tm_Saldos AS S LEFT JOIN Puc AS P ON S.tmIdCuenta=P.IdCuenta
 LEFT  JOIN Companias AS CN ON  S.tmIdCia=CN.IdCia  LEFT JOIN Terceros AS T ON S.tmIdTercero=T.IdTercero
 LEFT JOIN SubGrupos AS SG ON S.tmCdSubgrupo=SG.IdSubgrupo  LEFT JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 LEFT JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea
 WHERE tmEst=@pmtmEst 
 ORDER BY tmIdCuenta,RazonSocial,tmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SaldosCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_SaldosCue] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2)=Null
,@pmtmIdTercero VARCHAR(16)=Null
 AS 
 SELECT tmEst,tmIdCia,tmIdCuenta,tmIdTercero,tmCdSubgrupo,tmCostoEnt,tmCostoSal
 FROM tm_Saldos
 WHERE tmEst=@pmtmEst  AND tmIdCuenta=@pmtmIdCuenta
  AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')   AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SaldosTer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_SaldosTer] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2)=Null
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmCdSubgrupo VARCHAR(8)=Null
 AS 
 SELECT tmEst,tmIdCia,tmIdCuenta,tmIdTercero,tmCdSubgrupo,tmCostoEnt,tmCostoSal,tmSaldoAnt,tmCostoAnt
 FROM tm_Saldos
 WHERE tmEst=@pmtmEst  AND tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')   AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%')
 AND tmCdSubgrupo LIKE ISNULL(@pmtmCdSubgrupo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Ser]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_Ser] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 SELECT tmItem,tmIdProducto,DescripProd,tmNumSerial,tmIdCia,tmIdBodega,Bodega,tmCdUbic,tmIdEstado,Estado,tmLinea
,tmDetalle,tmReferencia,tmRef2,tmFecRef1,tmFecRef2,tmUbicacion,tmIdBodNue,tmUbicNue,tmNueEstado,tmInactivo
,tmTipMovi,tmNumero,Seriales
 FROM tm_Ser  AS S INNER JOIN ProdMcias AS P ON S.tmIdProducto=P.IdProducto
 INNER JOIN EstadoSer AS E ON S.tmIdEstado=E.IdEstado
 INNER JOIN Bodegas AS B ON S.tmIdBodega=B.IdBodega
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_SerId] @pmtmNumero VARCHAR(5)
 AS 
 SELECT MAX(tmItem) AS MXITM  FROM tm_Ser 
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_SerPro] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdProducto VARCHAR(16)
,@pmtmNumSerial VARCHAR(30)
 AS 
 SELECT tmNumero,tmItem,tmIdProducto,tmNumSerial,tmIdCia,tmIdBodega,tmCdUbic,tmLinea,tmTipMovi
 FROM tm_Ser
 WHERE tmNumero=@pmtmNumero AND tmIdProducto=@pmtmIdProducto
 AND tmNumSerial=@pmtmNumSerial AND tmItem<>@pmtmItem
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_SerTot] @pmtmNumero VARCHAR(5),@pmtmIdProducto VARCHAR(16)=Null
,@pmtmIdBodega VARCHAR(4)=Null,@pmtmLinea INT=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT FROM tm_Ser
 WHERE tmNumero=@pmtmNumero AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND tmIdBodega LIKE ISNULL(@pmtmIdBodega,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_SerTotU]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_SerTotU] @pmtmNumero VARCHAR(5),@pmtmCdUbic VARCHAR(10)
,@pmtmIdProducto VARCHAR(16)=Null,@pmtmLinea INT=Null
 AS 
 SELECT COUNT(tmItem) AS SCANT FROM tm_Ser
 WHERE tmNumero=@pmtmNumero AND tmCdUbic=@pmtmCdUbic
 AND tmIdProducto LIKE ISNULL(@pmtmIdProducto,'%')
 AND (tmLinea>=ISNULL(@pmtmLinea,0)  AND tmLinea<=ISNULL(@pmtmLinea,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_Tanqueos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_Tanqueos] @pmtmNumero VARCHAR(5),@pmtmItem INT
AS 
 SELECT  tmItem, tmDocumento,tmFecha, tmIdTipoCom,tmTipoCom, tmCantidad, tmValorUnitario
, tmCantidad * tmValorUnitario AS ValorTotal ,tmIdEstacion,tmEstacion ,tmNumero
 FROM     tm_Tanqueos
 WHERE tmNumero=@pmtmNumero 
 AND (tmItem>=ISNULL(@pmtmItem,0)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalle]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetalle] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmdmsAlto,tmdmsAncho,tmdmsLargo,tmVolumen,tmUndVol
,tmIdUnd,tmIdEmp,tmIdNat,tmIdMnjo,tmIdTmcia,tmCdRango,tmCases,tmCajas,tmPalets,tmRemision,tmNumOrden
,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCdAgencia,tmTipoVehic
,tmTarifClie,tmTarifPago,tmTarifTabla,tmVrDeclarado,tmVrSeguro,tmTarifSeguro,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmContenedor1,tmContenedor2,tmUndTarifa
,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmNumMintrans,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado,tmTieCargue,tmTieDesc,tmFecIniCargue,tmFecFinCargue,tmFecInidesc
,tmFecFindesc,tmCdTipoVeh,tmTipoServicio,tmSedeRem,tmSedeDest,tmFecLlegaCargue,tmFecLlegaDesc,tmMinCargue,tmMinDescargue,tmTarifOtros,tmCod_UN,tmCod_Corr,tmCod_Desg,tmDescripRP,tmTray_Vacio1,tmTray_Vacio2
 FROM tm_TraDetalle
 WHERE tmNumero=@pmtmNumero 
  AND (tmItem>=ISNULL(@pmtmItem,-1)  AND tmItem<=ISNULL(@pmtmItem,2147483647))
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetalleLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmCases,tmCajas,tmPalets,tmPesoNeto,tmUndMed,tmTarifClie,tmUndTarifa,tmTarifTabla,tmTarifPago,tmUndTarPago
,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmIdOrigen,LO.Localidad AS LugarOrigen,tmIdDestino,LD.Localidad AS LugarDestino,tmDirOrigen,tmDirDestino,tmNitRemite,tmRemitente,tmSedeRem
,tmNitDestntario,tmDestinatario,tmSedeDest,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmdmsLargo,tmdmsAncho,tmdmsAlto,tmVolumen,tmUndVol,tmIdUnd,U.Unidad AS UndPresenta,tmIdEmp,Empaque 
,tmIdNat,Natlzaprod,tmIdMnjo,ManejoMcia,tmIdTmcia,TipoMcia,tmCdRango,DescripRango,tmContenedor1,tmContenedor2,tmPesoCont,tmCodBodega,tmTipoTraslado,tmCdTipoVeh,tmTipoServicio,tmTarifOtros
,tmCod_UN,tmCod_Corr,tmCod_Desg,tmDescripRP,tmTray_Vacio1,tmTray_Vacio2
 FROM tm_TraDetalle AS T INNER JOIN Localidades AS LO ON T.tmIdOrigen=LO.IdLocal
 INNER JOIN Localidades AS LD ON T.tmIdDestino=LD.IdLocal
 INNER JOIN UndMed AS U ON T.tmIdUnd=U.IdUnd  LEFT JOIN Empaques AS E ON T.tmIdEmp=E.IdEmp
 LEFT JOIN TiposNat AS TN ON T.tmIdNat=TN.IdNat LEFT JOIN TiposMnjo AS MJ ON T.tmIdMnjo=MJ.IdMnjo
 LEFT JOIN TiposMcia AS TM ON T.tmIdTmcia=TM.IdTmcia 
 LEFT JOIN RangosPeso AS RP ON T.tmCdRango=RP.IdRango
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleMuc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetalleMuc] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed
,tmIdEmp,Empaque,tmIdNat,Natlzaprod,tmReferencia1,tmReferencia2,tmTarifTabla,tmTarifPago,tmIdOrigen,LO.Localidad AS LugarOrigen
,tmIdDestino,LD.Localidad AS LugarDestino,tmNitRemite,tmRemitente,tmSedeRem,tmDirOrigen,tmNitDestntario,tmDestinatario,tmSedeDest,tmDirDestino
,tmdmsLargo,tmdmsAncho,tmdmsAlto,tmVolumen,tmCases,tmCajas,tmPalets,tmRemision,tmReferencia3,tmDocCliente,tmPesoCont,tmUndTarPago,tmCodBodega,tmTipoTraslado
,tmTieCargue,tmMinCargue,tmFecLlegaCargue,tmFecIniCargue,tmFecFinCargue,tmTieDesc,tmMinDescargue,tmFecLlegaDesc,tmFecInidesc,tmFecFindesc,tmTray_Vacio1,tmTray_Vacio2
--datos pendientes
--,tmTarifClie,tmUndTarifa,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmUndVol,tmIdUnd,U.Unidad AS UndPresenta
--,tmIdMnjo,ManejoMcia,tmIdTmcia,TipoMcia,tmCdRango,DescripRango,tmContenedor1,tmContenedor2, 
 FROM tm_TraDetalle AS T INNER JOIN Localidades AS LO ON T.tmIdOrigen=LO.IdLocal
 INNER JOIN Localidades AS LD ON T.tmIdDestino=LD.IdLocal
 INNER JOIN UndMed AS U ON T.tmIdUnd=U.IdUnd  LEFT JOIN Empaques AS E ON T.tmIdEmp=E.IdEmp
 LEFT JOIN TiposNat AS TN ON T.tmIdNat=TN.IdNat 
 --LEFT JOIN TiposMnjo AS MJ ON T.tmIdMnjo=MJ.IdMnjo
-- LEFT JOIN TiposMcia AS TM ON T.tmIdTmcia=TM.IdTmcia 
-- LEFT JOIN RangosPeso AS RP ON T.tmCdRango=RP.IdRango
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleOct]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetalleOct] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmIdEmp,Empaque,tmIdNat,Natlzaprod
,tmIdOrigen,LO.Localidad AS LugarOrigen,tmIdDestino,LD.Localidad AS LugarDestino,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3
,tmDirOrigen,tmDirDestino,tmNitRemite,tmRemitente,tmSedeRem,tmNitDestntario,tmDestinatario,tmSedeDest,tmCases,tmCajas,tmPalets
,tmdmsLargo,tmdmsAncho,tmdmsAlto,tmVolumen,tmUndVol,tmIdUnd,U.Unidad AS UndPresenta,tmIdMnjo,ManejoMcia,tmIdTmcia,TipoMcia,tmCdRango
,DescripRango,tmContenedor1,tmContenedor2,tmPesoCont,tmCod_UN,tmDescripRP,tmCod_Corr,tmCod_Desg
--,tmTarifClie,tmTarifTabla,tmTarifPago,tmUndTarifa,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmUndTarPago
 FROM tm_TraDetalle AS T INNER JOIN Localidades AS LO ON T.tmIdOrigen=LO.IdLocal
 INNER JOIN Localidades AS LD ON T.tmIdDestino=LD.IdLocal
 INNER JOIN UndMed AS U ON T.tmIdUnd=U.IdUnd  LEFT JOIN Empaques AS E ON T.tmIdEmp=E.IdEmp
 LEFT JOIN TiposNat AS TN ON T.tmIdNat=TN.IdNat LEFT JOIN TiposMnjo AS MJ ON T.tmIdMnjo=MJ.IdMnjo
 LEFT JOIN TiposMcia AS TM ON T.tmIdTmcia=TM.IdTmcia 
 LEFT JOIN RangosPeso AS RP ON T.tmCdRango=RP.IdRango
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleRmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetalleRmt] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmIdMercancia,tmDescripMcias,tmCantidad,tmPesoNeto,tmUndMed,tmIdEmp,Empaque,tmIdNat,Natlzaprod
,tmIdOrigen,LO.Localidad AS LugarOrigen,tmIdDestino,LD.Localidad AS LugarDestino,tmTarifClie,tmUndTarifa,tmTarifTabla,tmTarifPago,tmUndTarPago
,tmTarifOtros,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3
,tmDirOrigen,tmDirDestino,tmNitRemite,tmRemitente,tmSedeRem,tmNitDestntario,tmDestinatario,tmSedeDest
,tmdmsLargo,tmdmsAncho,tmdmsAlto,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmIdUnd,U.Unidad AS UndPresenta
,tmIdMnjo,ManejoMcia,tmIdTmcia,TipoMcia,tmCdRango,DescripRango,tmContenedor1,tmContenedor2,tmPesoCont,tmCod_UN,tmDescripRP,tmCod_Corr,tmCod_Desg
 FROM tm_TraDetalle AS T INNER JOIN Localidades AS LO ON T.tmIdOrigen=LO.IdLocal
 INNER JOIN Localidades AS LD ON T.tmIdDestino=LD.IdLocal
 INNER JOIN UndMed AS U ON T.tmIdUnd=U.IdUnd  LEFT JOIN Empaques AS E ON T.tmIdEmp=E.IdEmp
 LEFT JOIN TiposNat AS TN ON T.tmIdNat=TN.IdNat LEFT JOIN TiposMnjo AS MJ ON T.tmIdMnjo=MJ.IdMnjo
 LEFT JOIN TiposMcia AS TM ON T.tmIdTmcia=TM.IdTmcia 
 LEFT JOIN RangosPeso AS RP ON T.tmCdRango=RP.IdRango
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetalleTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetalleTot] @pmtmNumero VARCHAR(5)
 AS 
 SELECT SUM(tmCantidad) AS SCANT,SUM(tmPesoNeto) AS SPESO,SUM(tmVolumen) AS SVOLUMEN,SUM(tmVrDeclarado) AS TDECLARA,SUM(tmVrSeguro) AS TSEGURO
,SUM(CASE tmUndTarifa WHEN 'PESO' THEN tmTarifClie*tmPesoNeto WHEN 'UNIDADES' THEN tmTarifClie*tmCantidad  WHEN 'VOLUMEN' THEN  tmTarifClie*tmVolumen 
 WHEN 'CAJAS' THEN tmTarifClie*tmCajas WHEN 'PALETS' THEN  tmTarifClie*tmPalets ELSE tmTarifClie*tmPesoNeto END) AS TCLIENTE
,SUM(CASE  tmUndTarPago  WHEN 'PESO' THEN tmTarifPago*tmPesoNeto WHEN 'UNIDADES' THEN tmTarifPago*tmCantidad  WHEN 'VOLUMEN' THEN  tmTarifPago*tmVolumen 
 WHEN 'CAJAS' THEN tmTarifPago*tmCajas WHEN 'PALETS' THEN  tmTarifPago*tmPalets ELSE tmTarifPago*tmPesoNeto END) AS TPAGO
,SUM(CASE tmUndTarPago WHEN 'PESO' THEN tmTarifTabla*tmPesoNeto WHEN 'UNIDADES' THEN tmTarifTabla*tmCantidad  WHEN 'VOLUMEN' THEN  tmTarifTabla*tmVolumen 
 WHEN 'CAJAS' THEN tmTarifTabla*tmCajas WHEN 'PALETS' THEN  tmTarifTabla*tmPalets ELSE tmTarifTabla*tmPesoNeto END) AS TFLETE
,SUM(tmTarifOtros*tmPesoNeto) AS TOTOTROSPAG,SUM(tmTray_Vacio1) AS STrayVacio1,SUM(tmTray_Vacio2) AS STrayVacio2
 FROM tm_TraDetalle
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetConc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetConc] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,tmNitTercero,tmCdCCosto,tmCdSubCos
,tmpVehiculo,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia,tmTipDocRef,tmDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmCodAgncia,tmCantComb
,tmDocSop,tmTipoImp,tmCodTarImp,tmItemBase,tmTipoDs,tmNumDs,tmIdCiaDs,tmTipoNov,tmCiaDocRef,tmItemDocRef
 FROM tm_TraDetConc
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraDetConcLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraDetConcLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmIdConcepto,tmDescripcion,tmTipoConc,tmVrDebito,tmVrCredito,tmCdCuenta,NomCuenta,tmNitTercero,RazonSocial
,tmCdCCosto,CCosto,tmCdSubCos,SubCosto,tmpVehiculo,tmTipoAfiVehic,tmVrBase,tmTarifBase,tmReferencia
,tmTipDocRef,tmDocRef,tmCiaDocRef,tmItemDocRef,tmTipFac,tmFactura,tmIdCiaFac,tmItemFac,tmFecVence,tmTipoNov,tmCodAgncia,tmCantComb
 FROM tm_TraDetConc AS T LEFT JOIN CentroCosto AS CC ON T.tmCdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON T.tmCdSubCos=SC.IdSubCos
 LEFT JOIN Terceros  AS N ON T.tmNitTercero=N.IdTercero LEFT JOIN Puc AS P ON T.tmCdCuenta=P.IdCuenta
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraMovAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_TraMovAnt] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdEst CHAR(2)
 AS 
 SELECT MA.TipDoc,TipoDoc,MA.Numero AS Anticipo,MA.IdCia AS CdCia,Compania,MA.Fecha,T.TipoId AS NitTipId,MA.IdPoseedor AS NitPoseedor,T.Dv AS NitDv,T.RazonSocial AS Poseedor,MA.IdVehiculo AS PlacaVeh,NumVeh
,MA.SaldoAnt,MA.VrAnticipo,MA.VrPagos AS VrAbonos,A.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,MA.TipMuc,MA.Manifiesto,MA.IdCiaMuc,A.Modalidad,A.TipoPago,A.NumCheque,A.FecCheque,A.Beneficiario,A.Anulado,A.Observacion AS Detalle,A.IdConcepto AS CdConcepto,Concepto,A.TipCom,A.Comprobante,A.IdCiaCom
,A.TipoAplica,A.VrPago,A.TimeSys
FROM tm_TraMovAnt AS MA INNER JOIN Companias AS CN ON MA.IdCia=CN.IdCia INNER JOIN Terceros AS T ON MA.IdPoseedor=T.IdTercero
INNER JOIN Vehiculos AS V ON MA.IdVehiculo=V.IdVehiculo
LEFT JOIN (SELECT TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,IdPoseedor,IdConductor,VrAnticipo,VrAbonado,Modalidad,TipoPago,NumCheque,FecCheque,IdCta,IdCuenta,Beneficiario
,CedBenef,FechaVence,NumPresAnt,PreAnticipo,NumCargue,CiaCargue,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,IdUsuario,'' AS TipoAplica,0 AS VrPago 
FROM Trn_TraAnticipos WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
UNION ALL
SELECT P.TipDoc,P.Documento,P.IdCia,P.Fecha,A.IdConcepto,A.TipMuc,A.Manifiesto,A.IdCiaMuc,A.IdVehiculo,A.IdPoseedor,A.IdConductor,A.VrAnticipo,A.VrAbonado,A.Modalidad,A.TipoPago,A.NumCheque,A.FecCheque,A.IdCta,P.CdCuentaAnt,A.Beneficiario
,A.CedBenef,A.FechaVence,A.NumPresAnt,A.PreAnticipo,A.NumCargue,A.CiaCargue,P.TipAnt,P.Anticipo,P.IdCiaAnt,A.Anulado,A.NumDev,A.FecDev,P.Detalle,A.TimeSys,A.IdUsuario,P.TipoAplica,P.VrAbono
FROM Trn_TraAntAbonos AS P INNER JOIN Trn_TraAnticipos AS A ON P.TipAnt=A.TipDoc AND P.Anticipo=A.Anticipo AND P.IdCiaAnt=A.IdCia
WHERE P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
UNION ALL
SELECT A.TipDoc,A.Anticipo,A.IdCia,A.Fecha,A.IdConcepto,A.TipOds,A.NumOrden,A.IdCiaOds,O.IdVehiculo,O.IdPoseedor,O.IdConductor,A.VrAnticipo,A.VrAbonado,A.TipoAncpo,A.TipoPago,A.NumCheque,A.FecCheque,A.IdCta,A.IdCuenta,A.Beneficiario
,A.CedBenef,A.FechaVence,A.NumPresAnt,0,0,'',A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado,A.NumDev,A.FecDev,A.Observacion,A.TimeSys,A.IdUsuario,'',0
FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
WHERE A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
UNION ALL
SELECT P.TipDoc,P.Documento,P.IdCia,P.Fecha,A.IdConcepto,A.TipOds,A.NumOrden,A.IdCiaOds,O.IdVehiculo,O.IdPoseedor,O.IdConductor,A.VrAnticipo,A.VrAbonado,A.TipoAncpo,A.TipoPago,A.NumCheque,A.FecCheque,A.IdCta,P.CodCuenta,A.Beneficiario
,A.CedBenef,A.FechaVence,A.NumPresAnt,0,0,'',P.TipAnt,P.Anticipo,P.IdCiaAnt,A.Anulado,A.NumDev,A.FecDev,P.Observacion,A.TimeSys,A.IdUsuario,P.TipoAplica,P.VrAbono
FROM Trn_TraOrdenAbo AS P INNER JOIN Trn_TraOrdenAnt AS A ON P.TipAnt=A.TipDoc AND P.Anticipo=A.Anticipo AND P.IdCiaAnt=A.IdCia
INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
WHERE P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
--Transporte especial
--UNION ALL 
--SELECT TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipRes,Reserva,IdCiaRes,IdVehiculo,IdPoseedor,IdConductor,VrAnticipo,VrAbonado,Modalidad,TipoPago,NumCheque,FecCheque,IdCta,IdCuenta,Beneficiario
--,CedBenef,FechaVence,NumPresAnt,PreAnticipo,0,'',TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,TimeSys,IdUsuario,'' AS TipoAplica,0 AS VrPago 
--FROM Trn_TraEspAnticipos
--WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
--UNION ALL 
--SELECT P.TipDoc,P.Documento,P.IdCia,P.Fecha,A.IdConcepto,A.TipRes,A.Reserva,A.IdCiaRes,A.IdVehiculo,A.IdPoseedor,A.IdConductor,A.VrAnticipo,A.VrAbonado,A.Modalidad,A.TipoPago,A.NumCheque,A.FecCheque,A.IdCta,P.CdCuentaAnt,A.Beneficiario
--,A.CedBenef,A.FechaVence,A.NumPresAnt,A.PreAnticipo,0,'',P.TipAnt,P.Anticipo,P.IdCiaAnt,A.Anulado,A.NumDev,A.FecDev,P.Detalle,A.TimeSys,A.IdUsuario,P.TipoAplica,P.VrAbono
--FROM Trn_TraEspAntAbonos AS P INNER JOIN Trn_TraEspAnticipos AS A ON P.TipAnt=A.TipDoc AND P.Anticipo=A.Anticipo AND P.IdCiaAnt=A.IdCia
--WHERE P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
) AS A ON MA.TipDoc=A.TipDoc AND MA.Numero=A.Anticipo AND MA.IdCia=A.IdCia
LEFT JOIN Sys_TiposDoc AS TD ON MA.TipDoc=TD.IdDoc
LEFT JOIN Terceros AS CDT ON A.IdConductor=CDT.IdTercero LEFT JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto
WHERE MA.IdEst=@pmIdEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraMovLiquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraMovLiquida] @pmtmEst CHAR(2)
 AS 
 SELECT tmTipo,TipoDoc,tmNumero,tmIdCia,Compania,tmItem,tmFecha,tmFecVence,tmIdPoseedor,RazonSocial,tmIdVehiculo
,tmIdConcepto,tmDescripcion,tmVrDebito,tmVrCredito,tmVrAbonado,tmTipoVehic,tmVrBase
,tmTarifa,tmReferencia,tmTipDocRef,tmDocRef,tmEstado,tmTipoLiq,tmLiquida,tmCiaLiq
,tmSaldoAnt,tmSaldoCia,tmSaldoAntVeh,tmSaldoVehCia
 FROM tm_TraMovLiquida AS M INNER JOIN Terceros AS T ON M.tmIdPoseedor=T.IdTercero
 INNER JOIN Companias  AS CN ON M.tmIdCia=CN.IdCia
 LEFT JOIN Sys_TiposDoc AS TD ON M.tmTipo=TD.IdDoc
 WHERE tmEst=@pmtmEst
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraRemFact]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraRemFact] @pmtmNumero VARCHAR(5),@pmtmItem INT
 AS 
 SELECT tmNumero,tmItem,tmTipoReg,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmDescripcion,tmCantidad,tmVrUnitario,tmVrCosto,tmUndTarifa,tmUndCosto,tmUnidades,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDscto
,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrReteIca,tmVrFaltante,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmCdMercancia,tmCdConc,tmCdCCosto,tmCdSubCos,tmNitTercero,tmCdAgencia,tmpVehiculo,tmTipoVehic,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen
,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCantFalt,tmUnidadFalt,tmCdTarRet,tmCdTarIca,tmCdTarDct,tmPedRem,tmCiaPed,tmEtdoFact,tmFecRemesa,tmIntCumplido,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmNitAsegurad,tmCostoCump,tmTipoOrd,tmNumOrden,tmIdCiaOrd
,tmCantPago,tmVrAutoIca,tmRemTransb,tmCostoAdic,tmNitMucTbdo,tmTipoNov,tmItemOrd,tmTarifIat,tmVrAviTab,tmCdTarifIat,tmTarifBom,tmVrSobBom,tmCdTarifBom,tmVrAutoIat,tmVrAutoBom
,tmEstado,tmObserv,tmTotFletes,tmTotOtros,tmTotCargos,tmTotDctos,tmTotCostoAfi,tmTotCostoRem,tmReteCree,tmTarifaCree,tmCdTarCree,tmReteIva,tmTarifaRiv,tmCdTarRiv,tmTarifaAri,tmCdTarAri,tmBaseIva,tmBaseRet,tmBaseIca,tmBaseRiv,tmVrNeto,tmTray_Vacio1,tmTray_Vacio2
 FROM tm_TraRemFact
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraRemFactLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraRemFactLta] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmNumero,tmItem,tmTipoReg,tmTipRem,tmRemesa,tmIdCiaRem,tmItemRem,tmDescripcion,tmCantidad,tmVrUnitario,tmVrCosto,tmUndTarifa,tmUndCosto,tmUnidades,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDscto
,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrReteIca,tmTarifIat,tmVrAviTab,tmTarifBom,tmVrSobBom,tmVrFaltante,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmCdMercancia,tmCdConc,tmCdCCosto,tmCdSubCos,tmNitTercero,tmCdAgencia,tmpVehiculo,tmTipoVehic,tmNitRemite,tmRemitente,tmDirOrigen,tmIdOrigen
,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,tmCantFalt,tmUnidadFalt,tmCantPago,tmCdTarRet,tmCdTarIca,tmCdTarifIat,tmCdTarifBom,tmCdTarDct,tmPedRem,tmCiaPed,tmEtdoFact,tmFecRemesa,tmIntCumplido,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmVrAutoIca,tmVrAutoIat,tmVrAutoBom,tmNitAsegurad,tmCostoCump,tmTipoNov
,tmTipoOrd,tmNumOrden,tmIdCiaOrd,tmItemOrd,tmRemTransb,tmCostoAdic,tmNitMucTbdo,tmTray_Vacio1,tmTray_Vacio2
 FROM tm_TraRemFact
 WHERE tmNumero=@pmtmNumero
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_TraRemFactMvo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_TraRemFactMvo] @pmtmNumero VARCHAR(5)
 AS 
 SELECT tmItem,tmTipoReg,tmTipRem,tmRemesa,tmIdCiaRem,Compania,tmItemRem,tmDescripcion,tmCantidad,tmVrUnitario,tmVrCosto,tmUndTarifa,tmUndCosto,tmUnidades,tmPesoNeto,tmUndMed,tmVolumen,tmUndVol,tmCases,tmCajas,tmPalets,tmTarifaIva,tmVrIva,tmTarifaDct,tmVrDscto
,tmTarifaRet,tmVrRetFte,tmTarifaIca,tmVrReteIca,tmVrFaltante,tmRemision,tmDocCliente,tmReferencia1,tmReferencia2,tmReferencia3,tmCdMercancia,tmCdConc,tmCdCCosto,CT.CCosto,tmCdSubCos,SC.SubCosto,tmNitTercero,tmCdAgencia,tmpVehiculo,tmTipoVehic,tmNitRemite,tmRemitente,tmDirOrigen
,tmIdOrigen,CO.Localidad AS CiudadOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,tmNitDestntario,tmDestinatario,tmDirDestino,tmIdDestino,CD.Localidad AS CiudadDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,tmCantFalt,tmUnidadFalt
,tmCdTarRet,tmCdTarIca,tmCdTarDct,tmPedRem,tmCiaPed,tmEtdoFact,tmFecRemesa,tmIntCumplido,tmVrDeclarado,tmTarifSeguro,tmVrSeguro,tmNitAsegurad,tmCostoCump,tmTipoOrd,tmNumOrden,tmIdCiaOrd
,tmCantPago,tmVrAutoIca,tmRemTransb,tmCostoAdic,tmNitMucTbdo,tmTipoNov,tmItemOrd,tmTarifIat,tmVrAviTab,tmCdTarifIat,tmTarifBom,tmVrSobBom,tmCdTarifBom,tmVrAutoIat,tmVrAutoBom
,tmEstado,tmObserv,tmTotFletes,tmTotOtros,tmTotCargos,tmTotDctos,tmTotCostoAfi,tmTotCostoRem,tmReteCree,tmTarifaCree,tmCdTarCree,tmReteIva,tmTarifaRiv,tmCdTarRiv,tmTarifaAri,tmCdTarAri,tmBaseIva,tmBaseRet,tmBaseIca,tmBaseRiv,tmVrNeto,tmTray_Vacio1,tmTray_Vacio2
,R.Fecha,R.FecDespacho,R.IdCliente,TC.RazonSocial,R.IdAgencia,A.Agencia AS NomAgencia,R.nRemolque,R.Modalidad,R.NumPedido,R.IdCiaPed,R.FechaPed,R.TipDcm,R.NumDocmto,R.IdCiaDcm,R.NumManif,R.IdCiaManif,R.EstCumplido,R.EstFactura,R.Observacion AS Observ
,R.CdRutaTarif,RT.Ruta AS DescRuta,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
 FROM tm_TraRemFact AS T INNER JOIN Companias AS CN ON T.tmIdCiaRem=CN.IdCia
 INNER JOIN Localidades AS CO ON T.tmIdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON T.tmIdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Trn_TraRemesa AS R ON T.tmTipRem=R.TipDoc AND T.tmRemesa=R.NumOrden AND T.tmIdCiaRem=R.IdCia
 INNER JOIN Terceros AS TC ON R.IdCliente=TC.IdTercero INNER JOIN Terceros AS CDT ON R.IdConductor=CDT.IdTercero   
 LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Rutas AS RT ON R.CdRutaTarif=RT.IdRuta
 LEFT JOIN CentroCosto AS CT ON T.tmCdCCosto=CT.IdCCosto LEFT JOIN SubCentros AS SC ON T.tmCdSubCos=SC.IdSubCos
 WHERE tmNumero=@pmtmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_ValesCred]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_ValesCred] @pmtmNumero VARCHAR(5) 
 AS 
 SELECT tmItem,tmTipo,tmRango,tmNumSerie,tmNumVale,tmFecha,tmHoraServ,tmNumMovil,tmCentCosto,tmUnidades,tmHoraRec,tmHoraEspera
,tmVrPago,tmFactUnid,tmFactRutas,tmFactHoras,tmCantidad,tmIdCliente,RazonSocial,tmIdAgencia,Agencia,tmUsuarios,tmObservacion,tmIdCuenta,tmRutas,tmVrCobro
 FROM tm_ValesCred AS V INNER JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero LEFT JOIN Agencias AS A ON V.tmIdAgencia=A.IdAgencia
 WHERE tmNumero=@pmtmNumero 
 ORDER BY tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytm_vce] @pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmItem INT
 AS 
 SELECT tmTipDoc,tmDocumento,tmIdCia,tmItem,tmValorFactura,tmValorAbono,tmIdVehiculo,tmFecUltPago
 FROM tm_vce
 WHERE tmTipDoc=@pmtmTipDoc AND tmDocumento=@pmtmDocumento AND tmIdCia=@pmtmIdCia AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vceLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_vceLta]
 AS 
 SELECT tmTipDoc,tmDocumento,tmIdCia,tmItem,tmValorFactura,tmValorAbono,tmIdVehiculo,tmFecUltPago
 FROM tm_vce
 ORDER BY tmTipDoc,tmIdCia,tmDocumento,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vence]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_vence] @pmtmEst CHAR(2),@pmFechaAct SMALLDATETIME
AS
 SELECT  tmIdPropietario,T.RazonSocial AS Propietario, tmIdVehiculo, tmIdCia,tmTipDoc,tmDocumento,tmItem,tmFecEmision,tmFecVence,DATEDIFF(day,tmFecVence,@pmFechaAct) AS DiasMora
 ,tmValorFactura, tmValorAbono,tmValorFactura-tmValorAbono AS TotalSaldo,tmVencido,tmVence1, tmVence2, tmVence3, tmVence4,tmPorVencer,tmIdCargo,F.Concepto AS ConceptoCargo,tmIdClase,ClaseCuenta,tmFecUltPago,tmFactura,tmReferencia
,tmDetalle,tmObservacion,tmIdConcepto,COC.Concepto AS ConceptoDoc,tmIdConductor,NC.RazonSocial AS Conductor,tmModalidad, tmTipCom, tmComprobante, tmIdCiaCom,tmTipDcm,tmDocmto,tmIdCiaDcm
,tmIdEstado,ED.Estado AS EstadoDoc,tmIdUsuario,Usuario,tmVehPropio,tmNotaInt,tmFecUltLiquida,Compania,TipoDoc,tmTimeSys
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor
,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro,NumSoat,FecSoat,VigSoat
,VrLmtCred,VrSaldoAct,V.IdEstado AS VehCdEstado,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
 FROM  tm_vence  AS C INNER JOIN Companias  AS CI ON C.tmIdCia=CI.IdCia
 INNER JOIN  Terceros AS T ON C.tmIdPropietario=T.IdTercero  INNER JOIN Vehiculos AS V ON C.tmIdVehiculo=V.IdVehiculo
 INNER JOIN  Fijos AS F ON C.tmIdCargo=F.IdCargo INNER JOIN BusClaseCue  AS CU ON C.tmIdClase=CU.IdClase
 INNER JOIN  adm_Usuarios AS U ON C.tmIdUsuario=U.IdUsuario INNER JOIN  EstadoDoc AS ED ON C.tmIdEstado=ED.IdEstado  
 INNER JOIN  Terceros AS NC ON C.tmIdConductor=NC.IdTercero
 INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
 INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
 LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
 LEFT JOIN  Conceptos AS COC ON C.tmIdConcepto=COC.IdConcepto  LEFT JOIN Sys_TiposDoc  AS TD ON C.tmTipDoc=TD.IdDoc
 WHERE tmEst=@pmtmEst 
 ORDER BY T.RazonSocial,tmIdVehiculo,tmFecVence
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_vence_Ed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQrytm_vence_Ed] @pmtmEst CHAR(2)
 --Cartera edades
 AS
 SELECT  tmEst, tmTipDoc, tmDocumento, tmIdCia, tmItem, tmFecEmision, tmFecVence, tmValorFactura, tmValorAbono
, tmVencido, tmPorVencer, tmVence1,tmVence2, tmVence3, tmVence4, tmIdPropietario, tmIdVehiculo, tmIdClase
 FROM   tm_vence
 WHERE tmEst=@pmtmEst AND tmTipDoc IN ('ADM','OTR','ND1','PRE','FVC')
 ORDER BY tmTipDoc,tmIdCia,tmDocumento,tmItem
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_VentasCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_VentasCom] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdCliente,T.RazonSocial AS NomCliente,tmCdAgencia,Agencia,CodAgencia,tmIdVend,VN.RazonSocial AS Vendedor
,tmIdBodega,Bodega,tmTipDoc,TipoDoc,tmIdConcepto,Concepto,tmCdLocal,Localidad,L.IdDep AS CodDep,Departamento
,tmCdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,tmPeriodo
,tmUnidades,tmVentaNeto,tmCostoNeto,tmImpuestos,tmImpConsumo,tmImpuBa,tmImpuCup,tmImpGlobal,tmSoldicom,tmVolumen,tmUnidades2,tmVentaNeto2,tmCostoNeto2,tmImpuestos2,tmImpConsumo2
,tmImpuBa2,tmImpuCup2,tmImpGlobal2,tmSoldicom2,tmVolumen2
--Datos del producto
,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,TipoRef,PM.IdMarca AS CdMarca,Marca
,PM.IdUnd AS CdUnid,Unidad,FecUltcom,FecUltVta,Tanques
--datos del tercero
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.NContrato AS ClieNumContrato,CiaContMay
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera,A.NContrato AS AgeNContrato,A.CiaCont AS AgeCiaCont,NumInterno
,CdFntePago,FuentePago
 FROM tm_Ventas AS V INNER JOIN tm_VentasCom AS D ON V.tmEst=D.tmEst AND V.tmItem=D.tmItem
 INNER JOIN ProdMcias  AS PM ON V.tmIdProducto=PM.IdProducto  INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero LEFT JOIN Agencias  AS A ON V.tmCdAgencia=A.IdAgencia
 LEFT JOIN TercCliente AS CLI ON V.tmIdCliente=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Subzonas AS SZ ON V.tmCdSubzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Terceros AS VN ON V.tmIdVend=VN.IdTercero   LEFT JOIN Bodegas AS B ON V.tmIdBodega=B.IdBodega 
 LEFT  JOIN Companias AS CN ON  V.tmIdCia=CN.IdCia  LEFT JOIN Sys_TiposDoc AS TD ON V.tmTipDoc=TD.IdDoc
 LEFT JOIN  Conceptos AS C ON V.tmIdConcepto=C.IdConcepto
 LEFT JOIN Localidades AS L ON V.tmCdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera 
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Trn_MayContratos AS MC ON A.NContrato=MC.NContrato AND A.CiaCont=MC.IdCia
 WHERE V.tmEst=@pmtmEst
 ORDER BY DescripProd,tmIdCia,T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_VentasDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_VentasDet] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdCliente,T.RazonSocial AS NomCliente,tmCdAgencia,Agencia,CodAgencia,tmIdVend,VN.RazonSocial AS Vendedor
,tmIdBodega,Bodega,tmTipDoc,TipoDoc,tmIdConcepto,Concepto,tmCdLocal,Localidad,L.IdDep AS CodDep,Departamento
,tmCdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,tmPeriodo
,tmSalidas,tmEntradas,tmVtaBrutoSal,tmVtaBrutoEnt,tmDctosSal,tmDctosEnt,tmIvaSal,tmIvaEnt,tmCostoSal,tmCostoEnt
,tmReteFteSal,tmReteFteEnt,tmReteIcaSal,tmReteIcaEnt,tmSobtasaSal,tmSobtasaEnt,tmImpGlobalSal,tmImpGlobalEnt
,tmSoldicomSal,tmSoldicomEnt,tmImpConEnt,tmImpConSal,tmImpuBaEnt,tmImpuBaSal,tmImpuCupEnt,tmImpuCupSal,tmUnidVolumen,tmComision
--Datos del producto
,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,TipoRef,PM.IdMarca AS CdMarca,Marca
,PM.IdUnd AS CdUnid,Unidad,FecUltcom,FecUltVta,Tanques
--datos del tercero
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.NContrato AS ClieNumContrato,CiaContMay
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera
,VrCupo,DiasPago,A.NContrato AS AgeNContrato,A.CiaCont AS AgeCiaCont,NumInterno,CdFntePago,FuentePago
 FROM tm_Ventas AS V INNER JOIN tm_VentasDet AS D ON V.tmEst=D.tmEst AND V.tmItem=D.tmItem
 INNER JOIN ProdMcias  AS PM ON V.tmIdProducto=PM.IdProducto  INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero LEFT JOIN Agencias  AS A ON V.tmCdAgencia=A.IdAgencia
 LEFT JOIN TercCliente AS CLI ON V.tmIdCliente=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Subzonas AS SZ ON V.tmCdSubzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Terceros AS VN ON V.tmIdVend=VN.IdTercero   LEFT JOIN Bodegas AS B ON V.tmIdBodega=B.IdBodega 
 LEFT  JOIN Companias AS CN ON  V.tmIdCia=CN.IdCia  LEFT JOIN Sys_TiposDoc AS TD ON V.tmTipDoc=TD.IdDoc
 LEFT JOIN  Conceptos AS C ON V.tmIdConcepto=C.IdConcepto
 LEFT JOIN Localidades AS L ON V.tmCdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera 
 LEFT JOIN Plazos AS PZ ON CLI.IdPlazo=PZ.IdPlazo LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Trn_MayContratos AS MC ON A.NContrato=MC.NContrato AND A.CiaCont=MC.IdCia
 WHERE V.tmEst=@pmtmEst
 ORDER BY DescripProd,tmIdCia,T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQrytm_VentasRes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQrytm_VentasRes] @pmtmEst CHAR(2)
 AS 
 SELECT tmIdProducto,DescripProd,tmIdCia,Compania,tmIdCliente,T.RazonSocial AS NomCliente,tmCdAgencia,Agencia,CodAgencia,tmIdVend,VN.RazonSocial AS Vendedor
,tmIdBodega,Bodega,tmTipDoc,TipoDoc,tmIdConcepto,Concepto,tmCdLocal,L.Localidad AS NomCiudad,L.IdDep AS CodDep,DP.Departamento AS NomDpto
,tmCdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,tmEnero,tmFebrero,tmMarzo,tmAbril,tmMayo,tmJunio,tmJulio,tmAgosto,tmSeptiembre,tmOctubre,tmNoviembre,tmDiciembre
--Datos del producto
,G.IdLinea AS CdLinea,Linea,S.IdGrupo AS CdGrupo,Grupo,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,TipoRef,PM.IdMarca AS CdMarca,Marca
,PM.IdUnd AS CdUnid,Unidad,FecUltcom,FecUltVta,Tanques
--datos del tercero
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.NContrato AS ClieNumContrato,CiaContMay
,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera,A.CdBandera AS AgeCdBandera,TBA.TipoBandera AS AgeBandera,A.IdLocal AS AgeCdCiu,LA.Localidad AS AgeNomCiudad
,A.NContrato AS AgeNContrato,A.CiaCont AS AgeCiaCont,NumInterno,CdFntePago,FuentePago
 FROM tm_Ventas AS V INNER JOIN tm_VentasRes AS D ON V.tmEst=D.tmEst AND V.tmItem=D.tmItem
 INNER JOIN ProdMcias  AS PM ON V.tmIdProducto=PM.IdProducto  INNER JOIN UndMed AS UM ON PM.IdUnd=UM.IdUnd
 INNER JOIN SubGrupos AS S ON PM.IdSubgrupo=S.IdSubgrupo INNER JOIN Grupos AS G ON S.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 LEFT JOIN Terceros AS T ON V.tmIdCliente=T.IdTercero LEFT JOIN Agencias  AS A ON V.tmCdAgencia=A.IdAgencia
 LEFT JOIN TercCliente AS CLI ON V.tmIdCliente=CLI.IdClie LEFT JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 LEFT JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen LEFT JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Subzonas AS SZ ON V.tmCdSubzona=SZ.IdSzona  LEFT JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  
 LEFT JOIN Terceros AS VN ON V.tmIdVend=VN.IdTercero   LEFT JOIN Bodegas AS B ON V.tmIdBodega=B.IdBodega 
 LEFT  JOIN Companias AS CN ON  V.tmIdCia=CN.IdCia  LEFT JOIN Sys_TiposDoc AS TD ON V.tmTipDoc=TD.IdDoc
 LEFT JOIN  Conceptos AS C ON V.tmIdConcepto=C.IdConcepto
 LEFT JOIN Localidades AS L ON V.tmCdLocal=L.IdLocal  LEFT JOIN Departamentos AS DP ON L.IdDep=DP.IdDep 
 LEFT JOIN TiposBan AS TB ON CLI.CdBandera=TB.IdBandera LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera 
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN FuentesPago AS FPG ON A.CdFntePago=FPG.IdFuente
 LEFT JOIN Trn_MayContratos AS MC ON A.NContrato=MC.NContrato AND A.CiaCont=MC.IdCia
 WHERE V.tmEst=@pmtmEst
 ORDER BY DescripProd,tmIdCia,T.RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[paQryTpapers]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTpapers]
AS
 SELECT Idpapel,Nombre,STR(Idpapel,3,0)+'  '+Nombre AS DsPap FROM Sys_Tpapers ORDER BY IdPapel
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAntAbonos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraAntAbonos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Fecha,TipAnt,Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
 FROM Trn_TraAntAbonos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAntAbonosFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAntAbonosFmt] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Documento,AP.IdCia AS CdCia,Item,AP.Fecha AS FechaDoc,TipAnt,AP.Anticipo AS NumAntcpo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt,A.Fecha AS FechaAnt,TipMuc,A.Manifiesto AS NumManif,IdCiaMuc,A.IdVehiculo AS PlacaVeh
 ,A.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,A.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,A.VrAnticipo AS ValAnticipo,VrAbonado,Modalidad,TipoPago,NumCheque,FecCheque
,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,NomCuenta,Beneficiario,A.Cantidad AS CantGals,FechaVence,NumPresAnt,TipCom,Comprobante,IdCiaCom
,A.Anulado AS Anuldo,NumDev,A.FecDev AS FechaDev,A.Observacion AS Observ,AP.TipDoc AS Tip_Doc
 FROM Trn_TraAntAbonos AS AP  INNER JOIN  Trn_TraAnticipos AS A ON AP.TipAnt=A.TipDoc  AND AP.Anticipo=A.Anticipo  AND AP.IdCiaAnt=A.IdCia
 INNER JOIN Terceros AS  CDT ON A.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE AP.TipDoc=@pmTipDoc AND AP.Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND AP.IdCia=@pmIdCia
 ORDER BY  AP.Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAnticipos] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,IdPoseedor,IdConductor,VrAnticipo,VrAbonado,Modalidad,TipoPago
,NumCheque,FecCheque,IdCta,IdCuenta,CedBenef,Beneficiario,Cantidad,FechaVence,NumPresAnt,PreAnticipo,NumCargue,CiaCargue,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,Observacion,IdEstado,VrDeduccion,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraAnticipos
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAnticiposFmt] @pmTipDoc VARCHAR(3),@pmAnticipoIni INT,@pmAnticipoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT A.TipDoc AS TipoAnt,TipoDoc,Anticipo,A.IdCia AS CdCia,Compania,A.Fecha AS FechaAnt,A.IdConcepto AS CdConcepto,Concepto,TipMuc,A.Manifiesto AS NumManif,IdCiaMuc,A.IdVehiculo AS PlacaVeh
,A.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,A.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,A.VrAnticipo AS ValAnticipo,VrAbonado,VrDeduccion,Modalidad,TipoPago,A.NumCheque AS NroCheque,FecCheque
,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,P.NomCuenta AS DescCuenta,CedBenef,Beneficiario,A.Cantidad AS CantGals,FechaVence,NumPresAnt,PreAnticipo,NumCargue,CiaCargue,A.TipCom AS CdTipCom,TipoCom,A.Comprobante AS NumComp,A.IdCiaCom AS CdCiaComp
,A.Anulado AS Anuldo,NumDev,A.FecDev AS FechaDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaAct,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario,Leyenda
--datos de manifiesto
,FecDespacho,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,VrFletes,TarifaFlete,PesoTotal
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
--comprobante
,Item,DC.IdCuenta AS CodCuenta,PC.NomCuenta AS Nom_Cuenta,Detalle,VrDebito,VrCredito,DC.IdTercero AS NitTercero,DT.RazonSocial AS NomTercero,DC.IdCCosto AS DetCodCentCost,DCC.CCosto AS DetCentCost
,DC.IdSubCos AS DetCodSubCentro,DS.SubCosto  AS DetSubCentro,VrBase,TarifaBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,DC.NumCheque AS DetNumCheque,TipoAplica,NitOtros,Referncia
 FROM Trn_TraAnticipos AS A  INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON A.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Trn_TraManifiesto AS M ON A.TipMuc=M.TipDoc AND  A.Manifiesto=M.Manifiesto AND  A.IdCiaMuc=M.IdCia
 LEFT JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON M.IdRuta=R.IdRuta 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON A.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON A.IdCuenta=P.IdCuenta LEFT JOIN TiposCom AS TCM ON A.TipCom=TCM.IdCom 
 LEFT JOIN  Trn_ComDetalle AS DC ON A.TipCom=DC.TipCom AND A.Comprobante=DC.Comprobante AND A.IdCiaCom=DC.IdCia
 LEFT JOIN Puc AS PC ON DC.IdCuenta=PC.IdCuenta LEFT JOIN Terceros AS DT ON DC.IdTercero=DT.IdTercero
 LEFT JOIN CentroCosto AS DCC ON DC.IdCCosto=DCC.IdCCosto  LEFT JOIN SubCentros AS DS ON DC.IdSubCos=DS.IdSubCos
 WHERE A.TipDoc=@pmTipDoc AND A.Anticipo BETWEEN @pmAnticipoIni AND @pmAnticipoFin AND A.IdCia=@pmIdCia
 ORDER BY A.Anticipo
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAnticiposLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdCta VARCHAR(4)=Null
 AS 
 SELECT  Anticipo,A.IdCia AS CdCia,Compania,Fecha,TipMuc,Manifiesto,IdCiaMuc,A.IdVehiculo AS PlacaVeh,IdPoseedor,T.RazonSocial AS Poseedor,IdConductor,CDT.RazonSocial AS Conductor,VrAnticipo,VrAbonado,Modalidad
,A.IdConcepto AS CdConcepto,Concepto,TipoPago,NumCheque,FecCheque,A.IdCta AS CdCta,NumeroCta,CT.IdBanco,Banco,A.IdCuenta AS CdCuenta,CedBenef,Beneficiario,VrDeduccion,Cantidad,FechaVence,NumPresAnt,PreAnticipo,NumCargue,CiaCargue
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,A.IdUsuario AS Cdusuario,Usuario
 FROM Trn_TraAnticipos AS A INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON A.IdConductor=CDT.IdTercero
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON A.IdCia=CI.IdCia
 LEFT JOIN CtasCorrientes AS CT ON A.IdCta=CT.IdCta LEFT JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 WHERE   Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND A.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')   AND A.Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND A.IdCta LIKE ISNULL( @pmIdCta,'%') 
 ORDER BY A.IdCia,Anticipo
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraAnticiposMov] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT TipDoc,TipoDoc,Anticipo,A.IdCia AS CdCia,Compania,Fecha,T.TipoId AS NitTipId,A.IdPoseedor AS NitPoseedor,T.Dv AS NitDv,T.RazonSocial AS Poseedor,A.IdVehiculo AS PlacaVeh,NumVeh,VrAnticipo,(VrAbonado*0) AS VrAbonos,A.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
 ,TipMuc,Manifiesto,IdCiaMuc,Modalidad,TipoPago,NumCheque,FecCheque,Beneficiario,Anulado,A.Observacion AS Detalle,A.IdConcepto AS CdConcepto,Concepto,TipCom,Comprobante,IdCiaCom,TimeSys  
 FROM Trn_TraAnticipos AS A INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero  
 INNER JOIN Terceros AS CDT ON A.IdConductor=CDT.IdTercero INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo
 WHERE  A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND A.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
UNION ALL
SELECT P.TipDoc,ISNULL(TipoDoc,'COMPROBANTE'),Documento,P.IdCia,Compania,P.Fecha,T.TipoId,A.IdPoseedor,T.Dv,T.RazonSocial,A.IdVehiculo,NumVeh,0,P.VrAbono,A.IdConductor,CDT.RazonSocial
,A.TipMuc,A.Manifiesto,A.IdCiaMuc,Modalidad,TipoAplica,NumCheque,FecCheque,Beneficiario,0,Detalle,A.IdConcepto,Concepto,TipAnt,P.Anticipo,IdCiaAnt,P.Fecha
FROM Trn_TraAntAbonos AS P INNER JOIN Trn_TraAnticipos AS A ON P.TipAnt=A.TipDoc AND P.Anticipo=A.Anticipo AND P.IdCiaAnt=A.IdCia
INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto
INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero  INNER JOIN Terceros AS CDT ON A.IdConductor=CDT.IdTercero
INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo LEFT JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc 
 WHERE  P.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND A.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
--saldos anteriores
UNION ALL
SELECT 'SAN','SALDO ANTERIOR',0,A.IdCia,Compania,@pmFechaIni,T.TipoId,A.IdPoseedor,T.Dv,T.RazonSocial,A.IdVehiculo,NumVeh,(SaldoAnt+VrAnticipos-VrPagos),0,'0',''
,'',0,'','','','',Null,'',0,'saldo anterior','SAN','Anticipos','',0,'',@pmFechaIni
FROM AcuAnticipos AS A INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia
INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero  INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo
 WHERE  A.nAnno=YEAR(DATEADD (Month ,-1,@pmFechaIni))  AND A.nMes=MONTH(DATEADD (Month ,-1, @pmFechaIni))
  AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND A.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND A.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAnticiposRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
,@pmtmEst CHAR(2)=Null
 AS 
 SELECT A.TipDoc AS TipoAnt,A.Anticipo AS NumAnticipo,A.IdCia AS CdCia,Compania,A.Fecha AS FechaAnt,A.IdConcepto AS CdConcepto,Concepto,TipMuc,A.Manifiesto AS NumManif,IdCiaMuc,A.IdVehiculo AS PlacaVeh
,A.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,A.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,A.VrAnticipo AS ValAnticipo,VrAbonado,A.VrAnticipo-VrAbonado AS VrSaldo,Modalidad,TipoPago,NumCheque,FecCheque
,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,NomCuenta,CedBenef,Beneficiario,A.Cantidad AS CantGals,FechaVence,NumPresAnt,PreAnticipo,NumCargue,CiaCargue,A.VrDeduccion,A.TipCom,TipoCom,A.Comprobante,A.IdCiaCom
,A.Anulado AS Anuldo,NumDev,A.FecDev AS FechaDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaAct,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario
--datos de manifiesto
,FecDespacho,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,VrFletes,TarifaFlete,PesoTotal,EstCumplido,Cumplido,IdCiaCump,FechaCump
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
--,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
--Apr 10/2018 Deducciones de anticipos ,tmConcepto1,tmValor1,tmConcepto2,tmValor2,tmConcepto3,tmValor3,tmConcepto4,tmValor4,tmConcepto5,tmValor5
 FROM Trn_TraAnticipos AS A  INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON A.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Trn_TraManifiesto AS M ON A.TipMuc=M.TipDoc AND A.Manifiesto=M.Manifiesto AND  A.IdCiaMuc=M.IdCia
 LEFT JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON M.IdRuta=R.IdRuta 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON A.IdCuenta=P.IdCuenta LEFT JOIN TiposCom AS TCM ON A.TipCom=TCM.IdCom 
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
-- LEFT JOIN TercCndtores AS CT ON A.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
--Apr 10/2018 Deducciones de anticipos LEFT JOIN tm_TraDedAnt AS DA ON A.TipDoc=DA.tmTipAnt AND A.Anticipo=DA.tmAnticipo AND A.IdCia=DA.tmIdCia 
 WHERE A.TipDoc=@pmTipDoc AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND A.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND A.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND A.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND A.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY A.IdCia,A.Anticipo
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposRelAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAnticiposRelAbo] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT A.TipDoc AS TipoAnt,A.Anticipo AS NumAnticipo,A.IdCia AS CdCia,Compania,A.Fecha AS FechaAnt,A.IdConcepto AS CdConcepto,Concepto,TipMuc,A.Manifiesto AS NumManif,IdCiaMuc,A.IdVehiculo AS PlacaVeh
,A.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,A.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,A.VrAnticipo AS ValAnticipo,VrAbonado,A.VrAnticipo-VrAbonado AS VrSaldo
,AP.TipDoc AS TipDocAbo,AP.Documento AS NumDocAbo,AP.IdCia AS CdCiaAbo,Item,AP.Fecha AS FechaAbo,VrAbono,TipoAplica,Detalle
,Modalidad,TipoPago,NumCheque,FecCheque,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,NomCuenta,CedBenef,Beneficiario,A.Cantidad AS CantGals,FechaVence,NumPresAnt,PreAnticipo,A.TipCom,TipoCom,A.Comprobante,A.IdCiaCom
,A.Anulado AS Anuldo,NumDev,A.FecDev AS FechaDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaAct,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario
--datos de manifiesto
,FecDespacho,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,VrFletes,TarifaFlete,PesoTotal,EstCumplido,Cumplido,IdCiaCump,FechaCump
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
 FROM Trn_TraAnticipos AS A  INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario 
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON A.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON A.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON A.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Trn_TraManifiesto AS M ON A.TipMuc=M.TipDoc AND  A.Manifiesto=M.Manifiesto AND  A.IdCiaMuc=M.IdCia
 LEFT JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON M.IdRuta=R.IdRuta 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON A.IdCuenta=P.IdCuenta LEFT JOIN TiposCom AS TCM ON A.TipCom=TCM.IdCom 
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Trn_TraAntAbonos AS AP ON A.TipDoc=AP.TipAnt AND A.Anticipo=AP.Anticipo AND A.IdCia=AP.IdCiaAnt
 WHERE A.TipDoc=@pmTipDoc AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND A.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND A.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND A.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND A.IdConductor LIKE ISNULL(@pmIdConductor,'%') AND A.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY A.IdCia,A.Anticipo
GO
/****** Object:  StoredProcedure [dbo].[paQryTraAnticiposTotCaj]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraAnticiposTotCaj]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
AS
SELECT TipDoc,SUM(VrAnticipo) AS TotalAnt
FROM Trn_TraAnticipos 
WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipoPago='EFECTIVO'
AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GROUP BY TipDoc
UNION ALL
SELECT D.TipDev,SUM(VrDevolucion)
FROM Trn_TraDevAnt AS D INNER JOIN Trn_TraAnticipos AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipoPago='EFECTIVO'
AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GROUP BY D.TipDev
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCausacion] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Causacion,IdCia,Fecha,IdConcepto,IdProv,Factura,VrTotal,VrOtros,VrNeto,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraCausacion
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacionFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraCausacionFmt] @pmTipDoc VARCHAR(3),@pmCausacionIni INT,@pmCausacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc AS TipCau,TipoDoc,C.Causacion AS NumCausac,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CdConcepto,CO.Concepto AS DescConcepto
,IdProv,T.RazonSocial AS Proveedor,C.Factura AS NumFactura,VrTotal,VrOtros,VrNeto,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado
,TimeSys,C.FecUpdate AS FechaAct,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,Leyenda
,D.IdConcepto AS CdConcCausac,CCA.Concepto AS ConcCausac,D.Descripcion AS DetDescripcion,D.TipoConc AS TipConcept,VrDebito,VrCredito,CdCuenta,NomCuenta,pVehiculo,NitTercero,NP.RazonSocial AS Razon_Social
,CdCCosto,CCosto,CdSubCos,SubCosto,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,TipFac,D.Factura AS DetFactura,IdCiaFac,ItemFac,FecVence,NumLiquida,CiaLiquida,VrAbonado
--datos del proveedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDpto,DP.Departamento AS DescDpto
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraCausacion AS C   INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
 INNER JOIN Conceptos AS CO ON C.IdConcepto=CO.IdConcepto
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS T ON C.IdProv=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN Trn_TraCauDetalle AS D ON C.TipDoc=D.TipDoc AND C.Causacion=D.Causacion AND C.IdCia=D.IdCia
 INNER JOIN TraConcCausac AS CCA ON D.IdConcepto=CCA.IdConcepto 
 LEFT JOIN  Vehiculos AS V ON D.pVehiculo=V.IdVehiculo   LEFT JOIN  TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd 
 LEFT JOIN Terceros AS NP ON D.NitTercero=NP.IdTercero  LEFT JOIN Puc AS P ON D.CdCuenta=P.IdCuenta 
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN TiposCom AS TCM ON C.TipCom=TCM.IdCom 
  WHERE C.TipDoc=@pmTipDoc AND C.Causacion  BETWEEN @pmCausacionIni AND @pmCausacionFin AND C.IdCia=@pmIdCia
 ORDER BY C.Causacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacionLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraCausacionLta] @pmTipDoc VARCHAR(3), @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdProv VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT Causacion,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CdConcepto,Concepto,IdProv,RazonSocial,Factura,VrTotal,VrOtros,VrNeto
,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraCausacion AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON C.IdProv=T.IdTercero  INNER JOIN Conceptos AS CO ON C.IdConcepto=CO.IdConcepto
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdProv LIKE ISNULL(@pmIdProv,'%') AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY C.IdCia,C.Causacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCausacionRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraCausacionRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null
 AS 
 SELECT C.TipDoc AS TipCau,C.Causacion AS NumCausac,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CdConcepto,CO.Concepto AS DescConcepto
,IdProv,T.RazonSocial AS Proveedor,C.Factura AS NumFactura,VrTotal,VrOtros,VrNeto,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado
,TimeSys,C.FecUpdate AS FechaAct,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
,D.IdConcepto AS CdConcCausac,CCA.Concepto AS ConcCausac,D.Descripcion AS DetDescripcion,D.TipoConc AS TipConcept,VrDebito,VrCredito,CdCuenta,NomCuenta,pVehiculo,NitTercero,NP.RazonSocial AS Razon_Social
,CdCCosto,CCosto,CdSubCos,SubCosto,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,TipFac,D.Factura AS DetFactura,IdCiaFac,ItemFac,FecVence,EstadoReg,NumLiquida,CiaLiquida,VrAbonado
--datos del proveedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDpto,DP.Departamento AS DescDpto
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraCausacion AS C   INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia 
 INNER JOIN Conceptos AS CO ON C.IdConcepto=CO.IdConcepto
 INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS T ON C.IdProv=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN Trn_TraCauDetalle AS D ON C.TipDoc=D.TipDoc AND C.Causacion=D.Causacion AND C.IdCia=D.IdCia
 INNER JOIN TraConcCausac AS CCA ON D.IdConcepto=CCA.IdConcepto 
 LEFT JOIN  Vehiculos AS V ON D.pVehiculo=V.IdVehiculo   LEFT JOIN  TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd 
 LEFT JOIN Terceros AS NP ON D.NitTercero=NP.IdTercero  LEFT JOIN Puc AS P ON D.CdCuenta=P.IdCuenta 
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN TiposCom AS TCM ON C.TipCom=TCM.IdCom 
  WHERE C.TipDoc=@pmTipDoc AND C.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND C.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND C.IdProv LIKE ISNULL(@pmIdProv,'%')
 ORDER BY C.IdCia,C.Causacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConcCausac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraConcCausac] @pmIdConcepto VARCHAR(4)
 AS 
 SELECT IdConcepto,Concepto,IdCuenta,TipoConc,Inactivo
 FROM TraConcCausac
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConcCausacDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraConcCausacDso] 
 AS 
 SELECT IdConcepto,Concepto,Concepto+' '+IdConcepto AS DsCon
 FROM TraConcCausac
 WHERE Inactivo=0 
 ORDER BY Concepto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraConceptos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Descripcion,Tarifa,TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva
,IdConcepto,CdCuenta,NitTercero,CdTipoEsc,FechaNov,VrBase,TipoTarif,RefConc,Fijos,IncBaseRet,Referencia2,Referencia3
,Est_Factura,Est_Liquida,TipFact,NumFactura,CiaFact,VrTotalFact,TipLiq,NumLiquida,CiaLiq,VrTotalLiq
 FROM Trn_TraConceptos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraConceptosFac] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT RF.Factura,RF.IdCia AS CdCiaFac,C.TipDoc AS TipRem,C.Documento AS NumRemesa,C.IdCia AS CdCia,C.Item,C.Descripcion,Tarifa,TipoConc
,RubroConcep,C.Cantidad,C.VrUnitario,C.TarifIva,C.IdConcepto AS CdConcepto,Concepto,C.CdCuenta,NomCuenta
,C.NitTercero,RazonSocial,CdTipoEsc,TipoEscolta,FechaNov,VrBase,TipoTarif,RefConc,C.Referencia2,C.Referencia3
,C.Est_Factura,C.Est_Liquida,C.TipFact,C.NumFactura,C.CiaFact,C.VrTotalFact,C.TipLiq,C.NumLiquida,C.CiaLiq,C.VrTotalLiq
 FROM Trn_TraFacRemesas AS RF INNER JOIN Trn_TraConceptos AS C ON RF.TipRem=C.TipDoc AND RF.Remesa=C.Documento AND RF.IdCiaRem=C.IdCia
 INNER JOIN ConcDiversos AS CD ON C.IdConcepto=CD.IdConcepto
 LEFT JOIN TiposEsc AS TE ON C.CdTipoEsc=TE.IdTipoEsc LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero
 LEFT JOIN Puc AS P ON C.CdCuenta=P.IdCuenta
 WHERE RF.TipDoc=@pmTipDoc AND RF.Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND RF.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraConceptosFmt] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Descripcion,Tarifa,TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva
,C.IdConcepto AS CdConcepto,Concepto,CdCuenta,NomCuenta,NitTercero,RazonSocial,CdTipoEsc,TipoEscolta
,FechaNov,VrBase,TipoTarif,RefConc,Referencia2,Referencia3
,Est_Factura,Est_Liquida,TipFact,NumFactura,CiaFact,VrTotalFact,TipLiq,NumLiquida,CiaLiq,VrTotalLiq
 FROM Trn_TraConceptos AS C INNER JOIN ConcDiversos AS CD ON C.IdConcepto=CD.IdConcepto
 LEFT JOIN TiposEsc AS TE ON C.CdTipoEsc=TE.IdTipoEsc LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero
 LEFT JOIN Puc AS P ON C.CdCuenta=P.IdCuenta
 WHERE TipDoc=@pmTipDoc AND C.Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND C.IdCia=@pmIdCia 
 ORDER BY C.Documento
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosItem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraConceptosItem] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmItem INT
 AS 
 SELECT TipDoc,Documento,IdCia,Item,Descripcion,Tarifa,TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva,IdConcepto
,CdCuenta,NitTercero,CdTipoEsc,FechaNov,VrBase,TipoTarif,RefConc,Fijos,IncBaseRet,Referencia2,Referencia3
,Est_Factura,Est_Liquida,TipFact,NumFactura,CiaFact,VrTotalFact,TipLiq,NumLiquida,CiaLiq,VrTotalLiq
 FROM Trn_TraConceptos
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia   AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryTraConceptosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraConceptosLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT C.TipDoc,C.Documento,C.IdCia,Compania,C.Item,C.FechaNov,C.IdConcepto AS CdConcepto,Concepto,C.Descripcion,C.VrBase,C.TipoTarif,C.Tarifa,C.TipoConc,C.RubroConcep,C.Cantidad,C.VrUnitario,C.TarifIva
,C.CdCuenta,P.NomCuenta,C.NitTercero,T.RazonSocial,C.CdTipoEsc,TipoEscolta,C.RefConc AS Referencia1,C.Referencia2,C.Referencia3,C.Est_Factura,C.Est_Liquida,C.TipFact,C.NumFactura,C.CiaFact,C.VrTotalFact,C.TipLiq,C.NumLiquida,C.CiaLiq,C.VrTotalLiq
,O.Fecha AS FecOrden,O.FecDespacho,O.IdVehiculo,O.IdConductor,NC.RazonSocial AS Conductor,O.TipoAfiVehic,O.IdPoseedor,NP.RazonSocial AS Poseedor,O.IdPropietario AS IdCliente,CL.RazonSocial AS NomCliente
,O.IdOrigen,LO.Localidad AS CiuOrigen,O.IdDestino,LD.Localidad AS CiuDestino,O.Cumplido,O.IdCiaCump,O.EstCumplido,O.EstOrden,O.TipOdp,O.OrdPago,O.IdCiaOdp,O.EstFactura,O.TipFact AS OrdTipFact,O.NumFactura AS OrdNumFactura,O.CdCiaFact,O.Anulado,O.Observacion
 FROM Trn_TraConceptos AS C INNER JOIN ConcDiversos AS CD ON C.IdConcepto=CD.IdConcepto  INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia
 INNER JOIN (SELECT TipDoc,Manifiesto,IdCia,Fecha,FecDespacho,IdVehiculo,IdConductor,TipoAfiVehic,IdPoseedor,IdPropietario,IdOrigen,IdDestino,Cumplido,IdCiaCump,EstCumplido
 ,EstOrden,TipOdp,OrdPago,IdCiaOdp,Remesa AS EstFactura,'0' AS TipFact,Remesa AS NumFactura,IdCiaRem AS CdCiaFact,Anulado,Observacion FROM Trn_TraManifiesto
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (IdCia=@pmIdCia OR @pmIdCia IS NULL)
 UNION ALL
 SELECT R.TipDoc,R.NumOrden,R.IdCia,R.Fecha,R.FecDespacho,R.IdVehiculo,R.IdConductor,R.TipoAfiVehic,V.IdPoseedor,R.IdCliente,R.IdLocOrigen,R.IdLocDestino,0,'',R.EstCumplido
 ,R.NumManif,'',R.NumManif,R.IdCiaManif,R.EstFactura,R.TipDcm,R.NumDocmto,R.IdCiaDcm,R.Anulado,R.Observacion FROM Trn_TraRemesa AS R LEFT JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo
 WHERE R.TipDoc='RMT' AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (R.IdCia=@pmIdCia OR @pmIdCia IS NULL)
 UNION ALL
 SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdVehiculo,IdConductor,TipoAfiVehic,IdPoseedor,IdCliente,IdOrigen,IdDestino,NumCump,CdCiaCum,EstCumplido
 ,EstOrden,TipLiq,NumLiquida,CdCiaLiq,EstFactura,TipFact,NumFactura,CdCiaFact,Anulado,Observacion FROM Trn_TraOrdenServ 
 WHERE TipDoc='OSA' AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (IdCia=@pmIdCia OR @pmIdCia IS NULL)) AS O ON C.TipDoc=O.TipDoc AND C.Documento=O.Manifiesto AND C.IdCia=O.IdCia
 LEFT JOIN TiposEsc AS TE ON C.CdTipoEsc=TE.IdTipoEsc LEFT JOIN Terceros AS T ON C.NitTercero=T.IdTercero
 LEFT JOIN Puc AS P ON C.CdCuenta=P.IdCuenta
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Terceros AS NC ON O.IdConductor=NC.IdTercero LEFT JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero LEFT JOIN Terceros AS CL ON O.IdPropietario=CL.IdTercero
 WHERE (C.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumplido] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Cumplido,IdCia,Fecha,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,Modalidad,DiasPlazo,FecPago
,TipoMargen,MargenFalt,UndCalcFalt,TarifFaltPago,TarifFaltCobro,Anulado,FecDev,Observacion,IdEstado
,NRadicaDoc,IdCiaRadic,CdCiaOfic,FecRadic,CdRuta,CdOrigen,CdDestino,TipoComp,NumComp,CodConcepto
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,TipoCumpMT,MotivoSusp,ConsecSusp,VrAdicCargue
,VrAdicDescargue,VrAdicFlete,MotivoVrAdic,VrDctoFlete,MotivoVrDcto,VrAdicAnticipo,FecEntregaDoc,NumRadicaMT
,MvoAnulaCump,ObservAnulado,NumViajesCum,PesoLiqPago,PesoLiqFact,CdPlazoPago,NumDevCum,MvoRechazo,MunOrigVacio1,MunDestVacio1,MunOrigVacio2,MunDestVacio2,VrTrayVacio1,VrTrayVacio2
 FROM Trn_TraCumplido
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumplidoFmt] @pmTipDoc VARCHAR(3),@pmCumplidoIni INT,@pmCumplidoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT CU.TipDoc AS TipCum,TipoDoc,CU.Cumplido AS NumCumplido,CU.IdCia AS CdCia,Compania,CU.Fecha AS FechaCum,TipMuc,CU.Manifiesto AS NumManif,IdCiaMuc,CU.IdVehiculo AS PlacaVeh,Modalidad,DiasPlazo,FecPago
,TipoMargen,MargenFalt,UndCalcFalt,TarifFaltPago,TarifFaltCobro,CU.Observacion AS Observ
,CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,CdRuta,R.Ruta AS DescRuta
,NRadicaDoc,IdCiaRadic,CdCiaOfic,FecRadic,CU.IdEstado AS CdEstado,Estado,CU.Anulado AS Anuldo,CU.FecDev AS FechaDev,CU.NumDevCum
,CU.TimeSys AS FechaCrea,CU.FecUpdate AS FechaAct,CU.IdCiaCrea AS CdCiaCrea,CU.IdUsuario AS CdUsuario,Usuario,Leyenda
,M.Fecha AS FecManif,FecDespacho,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,M.Cantidad AS CantTotal,PesoTotal
,IdLocFletes,CF.Localidad AS LugarFletes,FechaPago,PagoCargue,PagoDescargue,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,M.Observacion AS Observ,TipoComp AS CdTipComp,NumComp AS Comprobante
,TipoCumpMT,MotivoSusp,ConsecSusp,VrAdicCargue,VrAdicDescargue,VrAdicFlete,MotivoVrAdic,VrDctoFlete,MotivoVrDcto,VrAdicAnticipo,FecEntregaDoc,NumRadicaMT,MvoAnulaCump,ObservAnulado,NumViajesCum,PesoLiqPago,PesoLiqFact,MvoRechazo
,CU.MunOrigVacio1,CU.MunDestVacio1,CU.MunOrigVacio2,CU.MunDestVacio2,CU.VrTrayVacio1,CU.VrTrayVacio2
--detalle de cumplidos
,D.Item AS DetItem,TipRem,D.Remesa AS NumRemesa,D.IdCiaRem AS CdCiaRem,ItemRem,D.Cantidad AS Cant,D.PesoNeto AS PesoCump,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Volumen AS VolCump,D.UndVol AS Und_Vol
,D.Cases AS CasesCump,D.Cajas AS CajasCump,D.Palets AS PaletsCump,D.TarifClie AS Tarif_Clie,D.TarifPago AS Tarif_Pago,TarifFlete,UndTarifClie,D.UndTarifPago AS UndTarifPag,D.VrTray_Vacio1 AS RemTrayVacio1,D.VrTray_Vacio2 AS RemTrayVacio2,CantCargue,PesoCargue,VolCargue,CasesCargue,CajasCargue,PaletsCargue
,EstadoCump,D.Remision AS NumRemision,D.DocCliente AS CumDocClie,D.Referencia1 AS CumRef1,D.Referencia2 AS CumRef2,D.Referencia3 AS CumRef3,D.Detalle AS CumDetalle
,IdMercancia,DescripMcias,RM.Cantidad AS RemCant,RM.PesoNeto AS RemPeso,NitRemite,Remitente,NitDestntario,Destinatario,TipoCumRemesa,MotivoSuspRem,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue
,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue
--Datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,CU.CdPlazoPago,PZ.Plazo,PZ.NVmto,PZ.DiasPago
 FROM Trn_TraCumplido AS CU INNER JOIN Companias AS CN ON CU.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON CU.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON CU.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON CU.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraCumRemesas AS D ON CU.TipDoc=D.TipDoc  AND CU.Cumplido=D.Cumplido AND CU.IdCia=D.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON CU.TipMuc=M.TipDoc AND CU.Manifiesto=M.Manifiesto AND CU.IdCiaMuc=M.IdCia
 INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON CU.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Localidades AS CO ON CU.CdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON CU.CdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON CU.CdRuta=R.IdRuta 
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 LEFT JOIN Trn_TraRemMcias AS RM ON D.TipRem=RM.TipDoc  AND D.Remesa=RM.NumOrden AND D.IdCiaRem=RM.IdCia  AND D.ItemRem=RM.Item
 LEFT JOIN Plazos AS PZ ON CU.CdPlazoPago=PZ.IdPlazo
 WHERE CU.TipDoc=@pmTipDoc AND CU.Cumplido BETWEEN @pmCumplidoIni AND @pmCumplidoFin AND CU.IdCia=@pmIdCia
 ORDER BY CU.Cumplido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumplidoLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT C.Cumplido AS NumCumplido,C.IdCia AS CdCia,Compania,C.Fecha AS FecCumplido,C.Manifiesto AS NumManif,IdCiaMuc,M.Fecha AS FecManif,C.IdVehiculo AS PlacaVeh,Modalidad
,M.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,NP.RazonSocial AS Poseedor
,M.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,DiasPlazo,FecPago,TipoMargen,MargenFalt,UndCalcFalt,TarifFaltPago,TarifFaltCobro,NRadicaDoc,IdCiaRadic,CdCiaOfic,FecRadic
,C.Anulado AS CumAnulado,C.FecDev AS FechAnulado,C.NumDevCum,TipoComp,NumComp,CodConcepto,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado
,CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,CdRuta,R.Ruta AS DescRuta
,IdLocFletes,LP.Localidad AS LugarPago,C.TimeSys AS FechaCrea,C.FecUpdate AS FechaAct,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
,TipoCumpMT,MotivoSusp,ConsecSusp,VrAdicCargue,VrAdicDescargue,VrAdicFlete,MotivoVrAdic,VrDctoFlete,MotivoVrDcto,VrAdicAnticipo,FecEntregaDoc,NumRadicaMT
,MA.TipoRuta,MvoAnulaCump,ObservAnulado,C.MvoRechazo,NumViajesCum,PesoLiqPago,PesoLiqFact,MA.MucMintrans AS TipoViaje,C.CdPlazoPago,C.MunOrigVacio1,C.MunDestVacio1,C.VrTrayVacio1,C.MunOrigVacio2,C.MunDestVacio2,C.VrTrayVacio2
 FROM Trn_TraCumplido AS C INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto AS M ON C.TipMuc=M.TipDoc AND C.Manifiesto=M.Manifiesto AND C.IdCiaMuc=M.IdCia
 INNER JOIN Trn_TraManifAnexo AS MA ON C.TipMuc=MA.TipDoc AND C.Manifiesto=MA.Manifiesto AND C.IdCiaMuc=MA.IdCia
 INNER JOIN Terceros AS NC ON M.IdConductor=NC.IdTercero INNER JOIN Terceros AS T ON M.IdPropietario=T.IdTercero
 INNER JOIN Terceros AS NP ON M.IdPoseedor=NP.IdTercero 
 LEFT JOIN Localidades AS CO ON C.CdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON C.CdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON C.CdRuta=R.IdRuta LEFT JOIN Localidades AS LP ON M.IdLocFletes=LP.IdLocal 
 WHERE C.TipDoc=@pmTipDoc  AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY C.IdCia,C.Cumplido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumplidoRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME, @pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT CU.TipDoc AS TipCum,CU.Cumplido AS NumCumplido,CU.IdCia AS CdCia,Compania,CU.Fecha AS FechaCum,TipMuc,CU.Manifiesto AS NumManif,IdCiaMuc,CU.IdVehiculo AS PlacaVeh,Modalidad,DiasPlazo,FecPago
,TipoMargen,MargenFalt,UndCalcFalt,TarifFaltPago,TarifFaltCobro,NRadicaDoc,IdCiaRadic,CdCiaOfic,FecRadic,CU.Anulado AS Anuldo,CU.FecDev AS FechaDev,CU.NumDevCum,TipoComp,NumComp,NumRadicaMT,CU.Observacion AS Observ,CU.IdEstado AS CdEstado,Estado
,CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,CdRuta,R.Ruta AS DescRuta
,CU.TimeSys AS FechaCrea,CU.FecUpdate AS FechaAct,CU.IdCiaCrea AS CdCiaCrea,CU.IdUsuario AS CdUsuario,Usuario
,M.Fecha AS FecManif,FecDespacho,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,M.Cantidad AS CantTotal,PesoTotal
,IdLocFletes,CF.Localidad AS LugarFletes,FechaPago,PagoCargue,PagoDescargue,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,M.Observacion AS MucObserv
,MA.TipoRuta,MA.kmsTotal,MA.NomRemite,MA.NomDestino,MA.LugarFletes,MA.NumAnticipo AS NumAnticipo,MA.NumCheque AS Num_Cheque,MA.TipoMintrans,MA.WsSeguro,MA.NumRadSeguro,CU.TipoCumpMT,CU.MotivoSusp,CU.ConsecSusp,CU.MvoRechazo
,CU.MunOrigVacio1,CU.MunDestVacio1,CU.MunOrigVacio2,CU.MunDestVacio2,CU.VrTrayVacio1,CU.VrTrayVacio2,dbo.FuncTraCumplidoCobro(CU.TipDoc,CU.Cumplido,CU.IdCia) AS VrTotalClie,dbo.FuncTraCumplidoPago(CU.TipDoc,CU.Cumplido,CU.IdCia) AS VrTotalPago
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupoPro,GrupoProp
,M.Remesa,M.IdCiaRem,RMT.Fecha AS Fecremesa,RMT.Comprobante AS Cmpremesa,RMT.TipCom AS TipComRmt
 FROM Trn_TraCumplido AS CU INNER JOIN Companias AS CN ON CU.IdCia=CN.IdCia
 INNER JOIN EstadoDoc AS ED ON CU.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON CU.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto AS M ON CU.TipMuc=M.TipDoc AND CU.Manifiesto=M.Manifiesto AND CU.IdCiaMuc=M.IdCia
 INNER JOIN Trn_TraManifAnexo AS MA ON CU.TipMuc=MA.TipDoc AND CU.Manifiesto=MA.Manifiesto AND CU.IdCiaMuc=MA.IdCia
 INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON CU.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Localidades AS CO ON CU.CdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON CU.CdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON CU.CdRuta=R.IdRuta
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN (SELECT NumOrden,IdCia,Fecha,TipCom,Comprobante,IdCiaCom FROM Trn_TraRemesa WHERE TipDoc='RMT') AS RMT ON M.Remesa=RMT.NumOrden AND M.IdCiaRem=RMT.IdCia 
 WHERE CU.TipDoc=@pmTipDoc AND CU.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND  CU.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  CU.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%') AND M.IdConductor LIKE ISNULL(@pmIdConductor,'%')
  ORDER BY CU.IdCia,CU.Cumplido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumplidoRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumplidoRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME, @pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT CU.TipDoc AS TipCum,CU.Cumplido AS NumCumplido,CU.IdCia AS CdCia,Compania,CU.Fecha AS FechaCum,TipMuc,CU.Manifiesto AS NumManif,IdCiaMuc,CU.IdVehiculo AS PlacaVeh,Modalidad,DiasPlazo,FecPago
,TipoMargen,MargenFalt,UndCalcFalt,TarifFaltPago,TarifFaltCobro,NRadicaDoc,IdCiaRadic,CdCiaOfic,FecRadic,CU.Anulado AS Anuldo,CU.FecDev AS FechaDev,CU.NumDevCum,TipoComp,NumComp,NumRadicaMT,CU.Observacion AS Observ,CU.IdEstado AS CdEstado,Estado
,CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,CdRuta,R.Ruta AS DescRuta
,CU.TimeSys AS FechaCrea,CU.FecUpdate AS FechaAct,CU.IdCiaCrea AS CdCiaCrea,CU.IdUsuario AS CdUsuario,Usuario
,M.Fecha AS FecManif,FecDespacho,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,M.Cantidad AS CantTotal,PesoTotal
,IdLocFletes,CF.Localidad AS LugarFletes,FechaPago,PagoCargue,PagoDescargue,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,M.Observacion AS MucObserv
,MA.TipoRuta,MA.kmsTotal,MA.NomRemite,MA.NomDestino,MA.LugarFletes,MA.NumAnticipo AS NumAnticipo,MA.NumCheque AS Num_Cheque,MA.TipoMintrans,MA.WsSeguro,MA.NumRadSeguro,CU.TipoCumpMT,CU.MotivoSusp,CU.ConsecSusp,CU.MvoRechazo
,CU.MunOrigVacio1,CU.MunDestVacio1,CU.MunOrigVacio2,CU.MunDestVacio2,CU.VrTrayVacio1,CU.VrTrayVacio2
--detalle de cumplidos
,D.Item AS DetItem,TipRem,D.Remesa AS NumRemesa,D.IdCiaRem AS CdCiaRem,ItemRem,D.Cantidad AS Cant,D.PesoNeto AS PesoCump,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Volumen AS VolCump,D.UndVol AS Und_Vol
,D.Cases AS CasesCump,D.Cajas AS CajasCump,D.Palets AS PaletsCump,D.TarifClie AS Tarif_Clie,D.TarifPago AS Tarif_Pago,TarifFlete,UndTarifClie,D.UndTarifPago AS UndTarifPag,D.VrTray_Vacio1 AS RemTrayVacio1,D.VrTray_Vacio2 AS RemTrayVacio2,CantCargue,PesoCargue,VolCargue,CasesCargue,CajasCargue,PaletsCargue
,EstadoCump,D.Remision AS NumRemision,D.DocCliente AS CumDocClie,D.Referencia1 AS CumRef1,D.Referencia2 AS CumRef2,D.Referencia3 AS CumRef3,D.Detalle AS CumDetalle
,IdMercancia,DescripMcias,RM.Cantidad AS RemCant,RM.PesoNeto AS RemPeso,NitRemite,Remitente,NitDestntario,Destinatario,D.HoraLlegaCargue,D.HoraEntraCargue,D.HoraSaleCargue,D.HoraLlegaDescargue,D.HoraEntraDescargue,D.HoraSaleDescargue
,D.CodCCosto,CCosto,D.CodSubCos,SubCosto
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupoPro,GrupoProp
 FROM Trn_TraCumplido AS CU INNER JOIN Companias AS CN ON CU.IdCia=CN.IdCia
 INNER JOIN EstadoDoc AS ED ON CU.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON CU.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto AS M ON CU.TipMuc=M.TipDoc AND CU.Manifiesto=M.Manifiesto AND CU.IdCiaMuc=M.IdCia
 INNER JOIN Trn_TraManifAnexo AS MA ON CU.TipMuc=MA.TipDoc AND CU.Manifiesto=MA.Manifiesto AND CU.IdCiaMuc=MA.IdCia
 INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON CU.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraCumRemesas AS D ON CU.TipDoc=D.TipDoc  AND CU.Cumplido=D.Cumplido AND CU.IdCia=D.IdCia
 LEFT JOIN Localidades AS CO ON CU.CdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON CU.CdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON CU.CdRuta=R.IdRuta LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 LEFT JOIN Trn_TraRemMcias AS RM ON D.TipRem=RM.TipDoc  AND D.Remesa=RM.NumOrden AND D.IdCiaRem=RM.IdCia  AND D.ItemRem=RM.Item
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN CentroCosto AS CC ON D.CodCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CodSubCos=SC.IdSubCos
 WHERE CU.TipDoc=@pmTipDoc AND CU.Fecha BETWEEN  @pmFechaIni AND @pmFechaFin AND  CU.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  CU.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%') AND M.IdConductor LIKE ISNULL(@pmIdConductor,'%')
  ORDER BY CU.IdCia,CU.Cumplido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumRadica]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumRadica] @pmNumRadica INT,@pmIdCia CHAR(2)
 AS 
 SELECT NumRadica,IdCia,Fecha,TipMuc,Manifiesto,IdCiaMuc,CdCiaRad,DocAnexos,CantDoc,FormaEnvio
,NomRadica,CedRadica,Funcionario,Observacion,NumeroCum,IdCiaCum,FechaCum,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_TraCumRadica
 WHERE NumRadica=@pmNumRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumRadicaFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumRadicaFmt] @pmNumRadicaIni INT,@pmNumRadicaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT NumRadica,R.IdCia AS CdCia,CN.Compania AS NombreCia,R.Fecha AS FecRadica,R.TipMuc AS TipManif,R.Manifiesto AS NumManif,R.IdCiaMuc AS CdCiaManif,CU.IdVehiculo AS PlacaVeh
,CdCiaRad,CR.Compania AS CiaRadica,DocAnexos,CantDoc,FormaEnvio,NomRadica,CedRadica,Funcionario,R.Observacion AS Observ,NumeroCum,IdCiaCum,CU.Fecha AS FecCump,CU.Observacion AS ObservCump
--datos del manifiesto
,M.Fecha AS FecManif,FecDespacho,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,RT.Ruta AS DescRuta
,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,R.TimeSys AS FechaCrea,R.IdUsuario AS CdUsuario,Usuario
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.Descripcion AS VehDescripcion
 FROM Trn_TraCumRadica AS R  INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia INNER JOIN Companias AS CR ON R.CdCiaRad=CR.IdCia
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto AS M ON R.TipMuc=M.TipDoc AND R.Manifiesto=M.Manifiesto AND R.IdCiaMuc=M.IdCia
 INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS RT ON M.IdRuta=RT.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 LEFT JOIN Trn_TraCumplido AS CU ON R.NumeroCum=CU.Cumplido AND R.IdCiaCum=CU.IdCia
 LEFT JOIN Vehiculos AS V ON CU.IdVehiculo=V.IdVehiculo  LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 WHERE NumRadica BETWEEN @pmNumRadicaIni AND @pmNumRadicaFin AND R.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraCumRadicaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraCumRadicaLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmCdCiaRad CHAR(2)=Null
 AS 
 SELECT NumRadica,R.IdCia AS CdCia,CN.Compania AS NombreCia,R.Fecha AS FecRadica,R.TipMuc AS TipManif,R.Manifiesto AS NumManif,R.IdCiaMuc AS CdCiaManif
,CdCiaRad,CR.Compania AS CiaRadica,DocAnexos,CantDoc,FormaEnvio,NomRadica,CedRadica,Funcionario,R.Observacion AS Observ,NumeroCum,IdCiaCum,CU.Fecha AS FecCump,CU.Observacion AS ObservCump
--datos del manifiesto
,M.Fecha AS FecManif,FecDespacho,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,RT.Ruta AS DescRuta
,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,M.IdVehiculo AS PlacaVeh,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,R.TimeSys AS FechaCrea,R.IdUsuario AS CdUsuario,Usuario
,M.FechaPago AS ManFechaPago,M.Remesa AS NumRemesa,M.IdCiaRem AS CiaRemesa,RM.Fecha AS FecRemesa,RM.IdCliente AS NitCliente,TC.RazonSocial AS NomCliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.Descripcion AS VehDescripcion
 FROM Trn_TraCumRadica AS R INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia INNER JOIN Companias AS CR ON R.CdCiaRad=CR.IdCia
 INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto AS M ON R.TipMuc=M.TipDoc AND R.Manifiesto=M.Manifiesto AND R.IdCiaMuc=M.IdCia
 INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS RT ON M.IdRuta=RT.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 LEFT JOIN Trn_TraCumplido AS CU ON R.NumeroCum=CU.Cumplido AND R.IdCiaCum=CU.IdCia
 LEFT JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN (SELECT NumOrden,IdCia,Fecha,IdCliente,IdRemitente FROM Trn_TraRemesa  WHERE TipDoc ='RMT') AS RM ON M.Remesa=RM.NumOrden AND M.IdCiaRem=RM.IdCia 
 LEFT JOIN Terceros AS TC ON RM.IdCliente=TC.IdTercero
 WHERE R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.CdCiaRad LIKE ISNULL(@pmCdCiaRad,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduana]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDecAduana] @pmTipDoc VARCHAR(3),@pmNumDeclara INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumDeclara,IdCia,Fecha,FecEmision,IdOrigen,IdAduCarga,IdDestino,IdAduOrigen,IdAduDestino,IdAduFrontera,IdDeclarante,Declarante,DirDeclara,CdLocalDec,IdRemitente,Remitente,DirOrigen,CdLocalRem,IdDestinatario,Destinatario,DirDestino,CdLocalDest,IdConsig,Consignatario,DirConsig,CdLocalConsig,IdMoneda,ValorTotal,PesoTotal
,DocAnexos,Vehiculos,Remolques,Manifiestos,Contenedores,Precintos,OrigenAdd,Anulado,FecDev,Observacion,Negociacion,CondicPago,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDecAduana
 WHERE TipDoc=@pmTipDoc AND NumDeclara=@pmNumDeclara AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduana_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDecAduana_Cr] @pmTipDoc VARCHAR(3),@pmNumDeclaraIni INT,@pmNumDeclaraFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumDeclara,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino
,O.IdAduCarga,AC.NomAduana AS AduanaCargo,PAC.NombrePais AS PaisAduCargo,O.IdAduOrigen,AP.NomAduana AS AduanaOrigen,PAP.NombrePais AS PaisAduOrigen,O.IdAduDestino,AD.NomAduana AS AduanaDestino,PAD.NombrePais AS PaisAduDestino
,O.IdAduFrontera,AF.NomAduana AS AduanaFrontera,PAF.NombrePais AS PaisAduFront,O.IdDeclarante,Declarante,DirDeclara,DC.Telefono AS TelDecla,DC.TelMovil AS MovDecla,CdLocalDec,LDC.Localidad AS CiudadDec,O.IdRemitente,O.Remitente,RM.Telefono AS TelRemi,RM.TelMovil AS MovRemi
,DirOrigen,CdLocalRem,LRM.Localidad AS CiudadRemite,O.IdDestinatario,Destinatario,DT.Telefono AS TelDest,DT.TelMovil AS MovDest,DirDestino,CdLocalDest,LDT.Localidad AS CiudadDest,O.IdConsig,Consignatario,DirConsig,CS.Telefono AS TelCons,CS.TelMovil AS MovCons,CdLocalConsig,LCN.Localidad AS CiudadConsig
,O.IdMoneda AS CdMoneda,M.Simbolo,M.Mneda AS Moneda,O.ValorTotal,O.PesoTotal,O.DocAnexos,O.Vehiculos,O.Remolques,O.Manifiestos,O.Contenedores,O.Precintos,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Negociacion,O.CondicPago
,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
--detalles
,D.Item,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MN.Mneda AS DetMoneda,MN.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad
,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.DescripUnid
 FROM Trn_TraDecAduana AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario 
 INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN Trn_TraDecMcia AS D ON O.TipDoc=D.TipDoc AND O.NumDeclara=D.NumDeclara AND O.IdCia=D.IdCia
 INNER JOIN Aduanas AS AC ON O.IdAduCarga=AC.IdAduana INNER JOIN adm_Paises AS PAC ON AC.IdPais=PAC.IdPais
 INNER JOIN Aduanas AS AP ON O.IdAduOrigen=AP.IdAduana INNER JOIN adm_Paises AS PAP ON AP.IdPais=PAP.IdPais
 INNER JOIN Aduanas AS AD ON O.IdAduDestino=AD.IdAduana INNER JOIN adm_Paises AS PAD ON AD.IdPais=PAD.IdPais
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MN ON D.IdMoneda=MN.IdMneda  
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat
 INNER JOIN Terceros AS DC ON O.IdDeclarante=DC.IdTercero INNER JOIN Terceros AS RM ON O.IdRemitente=RM.IdTercero
 INNER JOIN Terceros AS DT ON O.IdDestinatario=DT.IdTercero INNER JOIN Terceros AS CS ON O.IdConsig=CS.IdTercero
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda
 LEFT JOIN Aduanas AS AF ON O.IdAduFrontera=AF.IdAduana LEFT JOIN adm_Paises AS PAF ON AF.IdPais=PAF.IdPais
 LEFT JOIN Localidades AS LDC ON O.CdLocalDec=LDC.IdLocal LEFT JOIN Localidades AS LRM ON O.CdLocalRem=LRM.IdLocal
 LEFT JOIN Localidades AS LDT ON O.CdLocalDest=LDT.IdLocal LEFT JOIN Localidades AS LCN ON O.CdLocalConsig=LCN.IdLocal
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed
 LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 WHERE O.TipDoc=@pmTipDoc AND O.NumDeclara BETWEEN @pmNumDeclaraIni AND @pmNumDeclaraFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduanaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDecAduanaLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumDeclara,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino
,O.IdAduCarga,AC.NomAduana AS AduanaCargo,PAC.NombrePais AS PaisAduCargo,O.IdAduOrigen,AP.NomAduana AS AduanaOrigen,PAP.NombrePais AS PaisAduOrigen,O.IdAduDestino,AD.NomAduana AS AduanaDestino,PAD.NombrePais AS PaisAduDestino
,O.IdAduFrontera,AF.NomAduana AS AduanaFrontera,PAF.NombrePais AS PaisAduFront,O.IdDeclarante,Declarante,DirDeclara,CdLocalDec,LDC.Localidad AS CiudadDec,O.IdRemitente,O.Remitente,DirOrigen,CdLocalRem,LRM.Localidad AS CiudadRemite
,O.IdDestinatario,Destinatario,DirDestino,CdLocalDest,LDT.Localidad AS CiudadDest,O.IdConsig,Consignatario,DirConsig,CdLocalConsig,LCN.Localidad AS CiudadConsig,O.IdMoneda AS CdMoneda,M.Simbolo,M.Mneda AS Moneda
,O.ValorTotal,O.PesoTotal,O.DocAnexos,O.Vehiculos,O.Remolques,O.Manifiestos,O.Contenedores,O.Precintos,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Negociacion,O.CondicPago
,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDecAduana AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 INNER JOIN Aduanas AS AC ON O.IdAduCarga=AC.IdAduana INNER JOIN adm_Paises AS PAC ON AC.IdPais=PAC.IdPais
 INNER JOIN Aduanas AS AP ON O.IdAduOrigen=AP.IdAduana INNER JOIN adm_Paises AS PAP ON AP.IdPais=PAP.IdPais
 INNER JOIN Aduanas AS AD ON O.IdAduDestino=AD.IdAduana INNER JOIN adm_Paises AS PAD ON AD.IdPais=PAD.IdPais
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda
 LEFT JOIN Aduanas AS AF ON O.IdAduFrontera=AF.IdAduana LEFT JOIN adm_Paises AS PAF ON AF.IdPais=PAF.IdPais
 LEFT JOIN Localidades AS LDC ON O.CdLocalDec=LDC.IdLocal LEFT JOIN Localidades AS LRM ON O.CdLocalRem=LRM.IdLocal
 LEFT JOIN Localidades AS LDT ON O.CdLocalDest=LDT.IdLocal LEFT JOIN Localidades AS LCN ON O.CdLocalConsig=LCN.IdLocal
 WHERE O.TipDoc=@pmTipDoc AND O.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDecAduanaLtd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDecAduanaLtd] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumDeclara,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino
,O.IdAduCarga,AC.NomAduana AS AduanaCargo,PAC.NombrePais AS PaisAduCargo,O.IdAduOrigen,AP.NomAduana AS AduanaOrigen,PAP.NombrePais AS PaisAduOrigen,O.IdAduDestino,AD.NomAduana AS AduanaDestino,PAD.NombrePais AS PaisAduDestino
,O.IdAduFrontera,AF.NomAduana AS AduanaFrontera,PAF.NombrePais AS PaisAduFront,O.IdDeclarante,Declarante,DirDeclara,CdLocalDec,LDC.Localidad AS CiudadDec,O.IdRemitente,O.Remitente,DirOrigen,CdLocalRem,LRM.Localidad AS CiudadRemite
,O.IdDestinatario,Destinatario,DirDestino,CdLocalDest,LDT.Localidad AS CiudadDest,O.IdConsig,Consignatario,DirConsig,CdLocalConsig,LCN.Localidad AS CiudadConsig,O.IdMoneda AS CdMoneda,M.Simbolo,M.Mneda AS Moneda
,O.ValorTotal,O.PesoTotal,O.DocAnexos,O.Vehiculos,O.Remolques,O.Manifiestos,O.Contenedores,O.Precintos,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Negociacion,O.CondicPago
,O.OrigenAdd,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
,D.Item,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MN.Mneda AS DetMoneda,MN.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad
,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.DescripUnid
 FROM Trn_TraDecAduana AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 INNER JOIN Aduanas AS AC ON O.IdAduCarga=AC.IdAduana INNER JOIN adm_Paises AS PAC ON AC.IdPais=PAC.IdPais
 INNER JOIN Aduanas AS AP ON O.IdAduOrigen=AP.IdAduana INNER JOIN adm_Paises AS PAP ON AP.IdPais=PAP.IdPais
 INNER JOIN Aduanas AS AD ON O.IdAduDestino=AD.IdAduana INNER JOIN adm_Paises AS PAD ON AD.IdPais=PAD.IdPais
 INNER JOIN Trn_TraDecMcia AS D ON O.TipDoc=D.TipDoc AND O.NumDeclara=D.NumDeclara AND O.IdCia=D.IdCia
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MN ON D.IdMoneda=MN.IdMneda  
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda
 LEFT JOIN Aduanas AS AF ON O.IdAduFrontera=AF.IdAduana LEFT JOIN adm_Paises AS PAF ON AF.IdPais=PAF.IdPais
 LEFT JOIN Localidades AS LDC ON O.CdLocalDec=LDC.IdLocal LEFT JOIN Localidades AS LRM ON O.CdLocalRem=LRM.IdLocal
 LEFT JOIN Localidades AS LDT ON O.CdLocalDest=LDT.IdLocal LEFT JOIN Localidades AS LCN ON O.CdLocalConsig=LCN.IdLocal
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed
 LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 WHERE O.TipDoc=@pmTipDoc AND O.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDespachos] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Manifiesto,IdCia,Fecha,FecCargue,FecDespacho,IdOrigen,IdDestino,IdRuta,IdVehiculo,IdConductor,IdPoseedor,NitRemite,Remitente,NitDestntario
,Destinatario,DescMcia,PesoTotal,NumOrden,IdCiaOrd,Remesa,IdCiaRem,Estado,Anulado,FecDev,Observacion,TimeSys,FecUpdate,IdUsuario
 FROM Trn_TraDespachos
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachosFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDespachosFmt] @pmTipDoc VARCHAR(3),@pmManifiestoIni INT,@pmManifiestoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDoc AS CdTipMuc,D.Manifiesto AS NumManif,D.IdCia AS CdCia,Compania,D.Fecha AS FecMuc,FecCargue,FecDespacho,IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.IdRuta AS CdRuta,R.Ruta AS DescRuta,D.IdVehiculo AS PlacaVeh,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,T.TipoId AS PosTipoId,D.IdPoseedor AS NitPoseedor,T.Dv AS PosDv,T.RazonSocial AS NomPoseedor,NitRemite,Remitente,NitDestntario,Destinatario,DescMcia,PesoTotal,NumOrden,IdCiaOrd,Remesa,IdCiaRem
,D.Estado AS EdoDespacho,D.Anulado AS DesAnulado,FecDev,D.Observacion AS Observ,TimeSys,FecUpdate,D.IdUsuario AS CdUsuario,Usuario
--detalles reportes-program.
,PgmItem,PgmIdPunto,HoraProg,TipoProg,ObservProg,RepItem,RepIdPunto,FecReporte,TipoRep,EstadoRep,CdNovedad,Novedad,ObservRep,TipoPunto,CdPuesto,PtoControl,TagPuesto,PC.Ubicacion AS UbicacPto,RepConductor
--datos del vehíclo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDespachos AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON  D.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON D.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON D.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN (SELECT  ISNULL(PG.TipDoc,RP.TipDoc) AS PgmTipDoc,ISNULL(PG.Manifiesto,RP.Manifiesto) AS PgmManif,ISNULL(PG.IdCia,RP.IdCia) AS PgmCdCia
 ,PG.Item AS PgmItem,PG.IdPunto AS PgmIdPunto,HoraProg,TipoProg,ObservProg,RP.Item AS RepItem,RP.IdPunto AS RepIdPunto,FecReporte,TipoRep,EstadoRep
,CdNovedad,ObservRep,TipoPunto,RP.CdPuesto AS RepCodPuesto,RP.NomConductor AS RepConductor,RT.Descripcion AS PuntDescrip,RT.ClasePto AS PuntClase,RT.CdPto AS CdPuesto
 FROM Trn_TraDespProgram AS PG  FULL JOIN Trn_TraReportes AS RP  ON PG.TipDoc=RP.TipDoc AND  PG.Manifiesto=RP.Manifiesto AND PG.IdCia=RP.IdCia  
 AND PG.CdRuta=RP.CdRuta AND PG.IdPunto=RP.IdPunto LEFT JOIN RutasPlan AS RT ON PG.CdRuta=RT.IdRuta AND PG.IdPunto=RT.IdPunto) AS PGM 
 ON D.TipDoc=PGM.PgmTipDoc AND  D.Manifiesto=PGM.PgmManif AND D.IdCia=PGM.PgmCdCia
 LEFT JOIN NovedadRep AS NV ON PGM.CdNovedad=NV.IdNov  LEFT JOIN Puestos AS PC ON PGM.CdPuesto=PC.IdPto
 WHERE D.TipDoc=@pmTipDoc AND D.Manifiesto BETWEEN @pmManifiestoIni AND  @pmManifiestoFin  AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDespachosLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT D.TipDoc AS CdTipDoc,D.Manifiesto AS NumManif,D.IdCia AS CdCia,Compania,D.Fecha AS FecMuc,FecCargue,D.FecDespacho,D.IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,D.IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.IdRuta AS CdRuta,R.Ruta AS DescRuta,D.IdVehiculo AS PlacaVeh,M.nRemolque AS MucRemolque,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,T.TipoId AS PosTipoId,D.IdPoseedor AS NitPoseedor,T.Dv AS PosDv,T.RazonSocial AS NomPoseedor,NitRemite,Remitente,NitDestntario,Destinatario,DescMcia,D.PesoTotal,NumOrden,IdCiaOrd,D.Remesa,D.IdCiaRem
,D.Estado AS EdoDespacho,D.Anulado AS DesAnulado,D.FecDev,D.Observacion AS Observ,D.TimeSys,D.FecUpdate,D.IdUsuario AS CdUsuario,Usuario
--datos del vehíclo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
--datos del MAnifiesto
,M.VrFletes AS ManVrFletes , M.VrRetencion AS ManVrRetencion, M.VrReteIca As ManVrRteIca, M.VrAnticipo AS ManVrAnticipo
,M.VrAntAdic AS ManVrAntAdic, M.VrNeto AS ManVrNeto,M.VrPagos AS ManVrPagos, M.VrCargos AS ManVrCargos
,MA.NumCheque AS ManNumChe,MA.NumAnticipo As ManNumAnt
 FROM Trn_TraDespachos AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto M ON D.TipDoc =M.TipDoc AND D.Manifiesto =M.Manifiesto AND D.IdCia =M.IdCia
 INNER JOIN Trn_TraManifAnexo MA ON D.TipDoc =MA.TipDoc AND D.Manifiesto =MA.Manifiesto AND D.IdCia =MA.IdCia 
 INNER JOIN Localidades AS CO ON  D.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON D.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON D.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN ( SELECT EO.TipOdp,EO.OrdPago,EO.IdCia ,SUM(EO.VrAbonado) AS ABONO,
 MAX(EO.NumEgreso)AS NumEgreso,MAX(EO.IdCia)AS IdCiaEgr,MAX(EO.TipCom ) AS TiPoegr,MAX(CEO.Fecha) AS FecEgr, max(CEO.FecCheque ) AS FecCheEgr
 FROM  Trn_TraEgrOrden EO  INNER JOIN Trn_Comprobantes CEO ON EO.TipCom =CEO.TipCom AND EO.NumEgreso =CEO.Comprobante AND EO.IdCia =CEO.IdCia
 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCia) AS InFEgr ON M.TipOdp =InFEgr.TipOdp AND M.OrdPago=InFEgr.OrdPago AND M.IdCiaOdp=InFEgr.IdCia 
 WHERE D.TipDoc=@pmTipDoc AND  D.FecDespacho BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDespachosLtap]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDespachosLtap] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
--despachos-detalles de programacion
 SELECT D.TipDoc AS CdTipDoc,D.Manifiesto AS NumManif,D.IdCia AS CdCia,Compania,D.Fecha AS FecMuc,FecCargue,FecDespacho,IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,D.IdRuta AS CdRuta,R.Ruta AS DescRuta,D.IdVehiculo AS PlacaVeh,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,T.TipoId AS PosTipoId,D.IdPoseedor AS NitPoseedor,T.Dv AS PosDv,T.RazonSocial AS NomPoseedor,NitRemite,Remitente,NitDestntario,Destinatario,DescMcia,PesoTotal,NumOrden,IdCiaOrd,Remesa,IdCiaRem
,D.Estado AS EdoDespacho,D.Anulado AS DesAnulado,FecDev,D.Observacion AS Observ,TimeSys,FecUpdate,D.IdUsuario AS CdUsuario,Usuario
--datos del vehíclo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
,PgmItem,PgmIdPunto,HoraProg,TipoProg,ObservProg,RepItem,RepIdPunto,FecReporte,TipoRep,EstadoRep,CdNovedad,Novedad,ObservRep,TipoPunto,CdPuesto,PtoControl,TagPuesto,PC.Ubicacion AS UbicacPto,RepConductor
 FROM Trn_TraDespachos AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON  D.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON D.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON D.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN TercCndtores AS CT ON D.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN (SELECT  ISNULL(PG.TipDoc,RP.TipDoc) AS PgmTipDoc,ISNULL(PG.Manifiesto,RP.Manifiesto) AS PgmManif,ISNULL(PG.IdCia,RP.IdCia) AS PgmCdCia
 ,PG.Item AS PgmItem,PG.IdPunto AS PgmIdPunto,HoraProg,TipoProg,ObservProg,RP.Item AS RepItem,RP.IdPunto AS RepIdPunto,FecReporte,TipoRep,EstadoRep
,CdNovedad,ObservRep,TipoPunto,CdPuesto,RP.NomConductor AS RepConductor
 FROM Trn_TraDespProgram AS PG  FULL JOIN Trn_TraReportes AS RP  ON PG.TipDoc=RP.TipDoc AND  PG.Manifiesto=RP.Manifiesto AND PG.IdCia=RP.IdCia  
 AND PG.CdRuta=RP.CdRuta AND PG.IdPunto=RP.IdPunto) AS PGM ON D.TipDoc=PGM.PgmTipDoc AND  D.Manifiesto=PGM.PgmManif AND D.IdCia=PGM.PgmCdCia
 LEFT JOIN NovedadRep AS NV ON PGM.CdNovedad=NV.IdNov  LEFT JOIN Puestos AS PC ON PGM.CdPuesto=PC.IdPto
 WHERE D.TipDoc=@pmTipDoc AND  D.FecDespacho BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevAnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,VrDevolucion,CdCta,CdCuenta
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevAnt
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevAntDoc] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,ModdDev
 FROM Trn_TraDevAnt
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevAntFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Anticipo,IdCiaDoc,FecDoc
,D.IdVehiculo AS PlacaVeh,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,VrDevolucion
,CdCta,NumeroCta,CTA.IdBanco,Banco,CdCuenta,NomCuenta,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom,D.Observacion AS Observ
,TimeSys,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
--Datos poseedor y vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevAnt AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN CtasCorrientes AS CTA ON D.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON D.CdCuenta=P.IdCuenta LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
  ORDER BY D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevAntLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
,@pmIdCta VARCHAR(4)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipoAnt,D.Anticipo AS NumAnticipo,IdCiaDoc,FecDoc,TipMuc,Manifiesto,IdCiaMuc, D.IdVehiculo AS PlacaVeh
,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.IdConductor AS CedConductor,CDT.RazonSocial AS Conductor,VrDevolucion,CdCta,NumeroCta,CT.IdBanco,Banco,CdCuenta
,TipoPago,NumCheque,FecCheque,Beneficiario,Modalidad,VrAnticipo,VrAbonado,VrAnticipo-VrAbonado AS SaldoActual
,ModdDev,D.OrigenAdd AS Origen_Add,D.TipCom AS TipoComp,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp,D.Observacion AS Observ,D.IdEstado AS CdEstado,D.TimeSys AS Time_Sys,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevAnt AS D INNER JOIN  Terceros AS T ON D.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON D.IdConductor=CDT.IdTercero
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Trn_TraAnticipos AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 LEFT JOIN CtasCorrientes AS CT ON D.CdCta=CT.IdCta LEFT JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 WHERE  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')   AND A.Modalidad LIKE ISNULL(@pmModalidad,'%') 
 AND D.CdCta LIKE ISNULL( @pmIdCta,'%') 
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAntRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevAntRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,VrDevolucion,D.TipDoc AS TipoAnt,D.Anticipo AS NumAnticipo,IdCiaDoc,D.FecDoc AS FechaAnt
,D.IdVehiculo AS PlacaVeh,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,CdCta,NumeroCta,CTA.IdBanco,Banco,CdCuenta,NomCuenta,A.VrDeduccion,ModdDev,D.TipCom AS TipComp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp,D.Observacion AS Observ
,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
,TipMuc,A.Manifiesto AS NumManif,IdCiaMuc,Modalidad,TipoPago,NumCheque,FecCheque,Beneficiario,A.Cantidad AS CantGals,PreAnticipo
--datos del vehículo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
 FROM Trn_TraDevAnt AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraAnticipos AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 LEFT JOIN CtasCorrientes AS CTA ON D.CdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON D.CdCuenta=P.IdCuenta LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 WHERE D.TipDev=@pmTipDev AND  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%') 
 ORDER BY D.IdCia,D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevAos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,VrDevolucion,CdCta,CdCuenta,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevAos
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevAosDoc] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,VrDevolucion,ModdDev
 FROM Trn_TraDevAos
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevAosFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
AS 
 SELECT D.TipDev AS IdTipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Anticipo AS NumAnticipo,IdCiaDoc,FecDoc
,VrDevolucion,A.VrAnticipo,A.VrAbonado,A.VrAnticipo-A.VrAbonado AS SaldoActual,TipoPago,NumCheque,FecCheque,CdCta,NumeroCta,CT.IdBanco,Banco,CdCuenta,NomCuenta,A.Cantidad AS CantGalones
,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden,O.IdVehiculo AS PlacaVeh,nRemolque,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,O.VrTotal,O.VrCosto,O.Cantidad
,CedBenef,Beneficiario,FechaVence,D.ModdDev,D.OrigenAdd,D.TipCom,D.Comprobante AS NumComp,D.IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaModif,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
--datos orden
,O.Modalidad,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,IdDestino,LD.Localidad AS NomDestino
,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstFactura,TipFact,NumFactura,CdCiaFact,EstOrden,TipLiq,NumLiquida,CdCiaLiq,O.Observacion AS OdsObserv
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevAos AS D INNER JOIN Trn_TraOrdenAnt AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN CtasCorrientes AS CT ON D.CdCta=CT.IdCta LEFT JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 LEFT JOIN Puc AS PU ON D.CdCuenta=PU.IdCuenta LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevAosLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Anticipo AS NumAnticipo,IdCiaDoc,FecDoc
,VrDevolucion,A.VrAnticipo,A.VrAbonado,A.VrAnticipo-A.VrAbonado AS SaldoActual,TipoPago,NumCheque,FecCheque,CdCta,NumeroCta,CT.IdBanco,Banco,CdCuenta,A.Cantidad AS CantGalones
,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden,O.IdVehiculo AS PlacaVeh,nRemolque,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,O.VrTotal,O.Cantidad
,CedBenef,Beneficiario,FechaVence,D.ModdDev,D.OrigenAdd,D.TipCom,D.Comprobante AS NumComp,D.IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaModif,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevAos AS D INNER JOIN Trn_TraOrdenAnt AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
 LEFT JOIN CtasCorrientes AS CT ON D.CdCta=CT.IdCta LEFT JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 WHERE D.TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevAosRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevAosRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
 SELECT D.TipDev AS IdTipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Anticipo AS NumAnticipo,IdCiaDoc,FecDoc
,VrDevolucion,A.VrAnticipo,A.VrAbonado,A.VrAnticipo-A.VrAbonado AS SaldoActual,TipoPago,NumCheque,FecCheque,CdCta,NumeroCta,CT.IdBanco,Banco,CdCuenta,NomCuenta,A.Cantidad AS CantGalones
,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden,O.IdVehiculo AS PlacaVeh,nRemolque,O.TipoAfiVehic,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,O.VrTotal,O.VrCosto,O.Cantidad
,CedBenef,Beneficiario,FechaVence,D.ModdDev,D.OrigenAdd,D.TipCom,D.Comprobante AS NumComp,D.IdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaModif,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
--datos orden
,O.Modalidad,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,O.CdRuta,Ruta,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino,LD.Localidad AS NomDestino
,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstFactura,TipFact,NumFactura,CdCiaFact,EstOrden,TipLiq,NumLiquida,CdCiaLiq,O.Observacion AS OdsObserv
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevAos AS D INNER JOIN Trn_TraOrdenAnt AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado
 INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN CtasCorrientes AS CT ON D.CdCta=CT.IdCta LEFT JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 LEFT JOIN Puc AS PU ON D.CdCuenta=PU.IdCuenta LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
 WHERE D.TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCau] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdProv,Factura,VrTotal,VrOtros,VrNeto
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevCau
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevCauDoc] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,FecDoc,IdProv,ModdDev
 FROM Trn_TraDevCau
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevCauFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,CO.Concepto AS DescConcepto,DV.TipDoc AS TipoCau,DV.Causacion AS NumCausac,IdCiaDoc,FecDoc
,IdProv,T.RazonSocial AS Proveedor,DV.Factura AS NumFactura,VrTotal,VrOtros,VrNeto,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom
,DV.Observacion AS Observ,TimeSys,IdCiaCrea,DV.IdUsuario AS CdUsuario,Usuario,Leyenda
,D.IdConcepto AS CdConcCausac,CCA.Concepto AS ConcCausac,D.Descripcion AS DetDescripcion,D.TipoConc AS TipConcept,VrDebito,VrCredito,CdCuenta,NomCuenta,pVehiculo,NitTercero,NP.RazonSocial AS Razon_Social
,CdCCosto,CCosto,CdSubCos,SubCosto,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,TipFac,D.Factura AS DetFactura,IdCiaFac,ItemFac,FecVence,NumLiquida,CiaLiquida,VrAbonado
--datos del proveedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDpto,DP.Departamento AS DescDpto
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevCau AS DV  INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
 INNER JOIN Conceptos AS CO ON DV.IdConcepto=CO.IdConcepto INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS T ON DV.IdProv=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN Trn_TraCauDetalle AS D ON DV.TipDoc=D.TipDoc AND DV.Causacion=D.Causacion AND DV.IdCiaDoc=D.IdCia
 INNER JOIN TraConcCausac AS CCA ON D.IdConcepto=CCA.IdConcepto 
 LEFT JOIN  Vehiculos AS V ON D.pVehiculo=V.IdVehiculo   LEFT JOIN  TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd 
 LEFT JOIN Terceros AS NP ON D.NitTercero=NP.IdTercero  LEFT JOIN Puc AS P ON D.CdCuenta=P.IdCuenta 
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN TiposCom AS TCM ON DV.TipCom=TCM.IdCom 
 WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND DV.IdCia=@pmIdCia
 ORDER BY  DV.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevCauLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdProv VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdProv,RazonSocial,Factura,VrTotal,VrOtros,VrNeto
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevCau AS D  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 INNER JOIN Terceros AS T ON D.IdProv=T.IdTercero  INNER JOIN Conceptos AS CO ON D.IdConcepto=CO.IdConcepto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE TipDev=@pmTipDev  AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdProv LIKE ISNULL(@pmIdProv,'%') AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 ORDER BY D.IdCia,D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCauRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevCauRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdProv VARCHAR(16)=Null
 AS 
 SELECT TipDev,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,CO.Concepto AS DescConcepto,DV.TipDoc AS TipoCau,DV.Causacion AS NumCausac,IdCiaDoc,FecDoc
,IdProv,T.RazonSocial AS Proveedor,DV.Factura AS NumFactura,VrTotal,VrOtros,VrNeto,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom
,DV.Observacion AS Observ,TimeSys,IdCiaCrea,DV.IdUsuario AS CdUsuario,Usuario
,D.IdConcepto AS CdConcCausac,CCA.Concepto AS ConcCausac,D.Descripcion AS DetDescripcion,D.TipoConc AS TipConcept,VrDebito,VrCredito,CdCuenta,NomCuenta,pVehiculo,NitTercero,NP.RazonSocial AS Razon_Social
,CdCCosto,CCosto,CdSubCos,SubCosto,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,TipFac,D.Factura AS DetFactura,IdCiaFac,ItemFac,FecVence,NumLiquida,CiaLiquida,VrAbonado
--datos del proveedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDpto,DP.Departamento AS DescDpto
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevCau AS DV  INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia 
 INNER JOIN Conceptos AS CO ON DV.IdConcepto=CO.IdConcepto INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario 
 INNER JOIN Terceros AS T ON DV.IdProv=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS DP ON L.IdDep=DP.IdDep
 INNER JOIN Trn_TraCauDetalle AS D ON DV.TipDoc=D.TipDoc AND DV.Causacion=D.Causacion AND DV.IdCiaDoc=D.IdCia
 INNER JOIN TraConcCausac AS CCA ON D.IdConcepto=CCA.IdConcepto 
 LEFT JOIN  Vehiculos AS V ON D.pVehiculo=V.IdVehiculo   LEFT JOIN  TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  LEFT JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 LEFT JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd 
 LEFT JOIN Terceros AS NP ON D.NitTercero=NP.IdTercero  LEFT JOIN Puc AS P ON D.CdCuenta=P.IdCuenta 
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN TiposCom AS TCM ON DV.TipCom=TCM.IdCom 
 WHERE DV.TipDev=@pmTipDev AND DV.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND DV.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND DV.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND DV.IdProv LIKE ISNULL(@pmIdProv,'%')
 ORDER BY DV.IdCia,DV.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_TraDevCos
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCosDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCosDoc] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev
 FROM Trn_TraDevCos
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCosFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCosFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDev AS IdTipDev,TipoDoc,D.Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Cumplido AS NumCump,D.IdCiaDoc,D.FecDoc
,TipOds,C.NumOrden AS Num_Orden,IdCiaOds,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,O.Modalidad,O.TipoOrden,O.VrAnticipo AS Vr_Anticipo,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,C.TipoAfiVehic,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,DescServicio,C.Cantidad AS CumCantidad,C.VrTotal AS CumValor,C.VrCosto AS CumValTercero,C.RemCliente
,Funcionario,O.NumRemesa,O.CdCiaRem,O.kmtInicial,O.kmtFinal,IdDestino,LD.Localidad,D.ModdDev,D.TipCom,D.Comprobante AS NumComp,D.IdCiaCom,D.Observacion AS Observ
,D.OrigenAdd,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
--detalles
,Item,DC.IdMercancia,DC.Descripcion,DC.Cantidad,DC.UndMed AS Und_Med,Unidad,DC.VrUnitario,DC.TarifaPago,DC.DocCliente
--Datos del Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
FROM Trn_TraDevCos AS D INNER JOIN Trn_TraOrdenCum AS C ON D.TipDoc=C.TipDoc AND D.Cumplido=C.Cumplido AND D.IdCiaDoc=C.IdCia
INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
INNER JOIN Conceptos AS CT ON D.IdConcepto=CT.IdConcepto INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden  AND C.IdCiaOds=O.IdCia
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
INNER JOIN Trn_TraOrdenCumDet AS DC ON C.TipDoc=DC.TipDoc AND C.Cumplido=DC.Cumplido AND C.IdCia=DC.IdCia
INNER JOIN Sys_Um AS UM ON DC.UndMed=UM.UndMed INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCosRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCosRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT D.TipDev AS IdTipDev,TipoDoc,D.Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Cumplido AS NumCump,D.IdCiaDoc,D.FecDoc
,TipOds,C.NumOrden AS Num_Orden,IdCiaOds,O.Fecha AS FecOrden,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,O.Modalidad,O.TipoOrden,O.VrAnticipo AS Vr_Anticipo,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,C.TipoAfiVehic,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,DescServicio,C.Cantidad AS CumCantidad,C.VrTotal AS CumValor,C.VrCosto AS CumValTercero,C.RemCliente
,Funcionario,O.NumRemesa,O.CdCiaRem,O.kmtInicial,O.kmtFinal,O.IdDestino,LD.Localidad,D.ModdDev,D.TipCom,D.Comprobante AS NumComp,D.IdCiaCom,D.Observacion AS Observ
,D.OrigenAdd,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
--detalles
,Item,DC.IdMercancia,DC.Descripcion,DC.Cantidad,DC.UndMed AS Und_Med,Unidad,DC.VrUnitario,DC.TarifaPago,DC.DocCliente
--Datos del Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
FROM Trn_TraDevCos AS D INNER JOIN Trn_TraOrdenCum AS C ON D.TipDoc=C.TipDoc AND D.Cumplido=C.Cumplido AND D.IdCiaDoc=C.IdCia
INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
INNER JOIN Conceptos AS CT ON D.IdConcepto=CT.IdConcepto INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden  AND C.IdCiaOds=O.IdCia
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
INNER JOIN Trn_TraOrdenCumDet AS DC ON C.TipDoc=DC.TipDoc AND C.Cumplido=DC.Cumplido AND C.IdCia=DC.IdCia
INNER JOIN Sys_Um AS UM ON DC.UndMed=UM.UndMed INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
WHERE D.TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCum] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,TipoAnulacion,MvoAnulacion
,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_TraDevCum
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevCumFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevCumFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDev,D.Devolucion,D.IdCia AS CdCia,Compania,D.Fecha,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Cumplido,D.IdCiaDoc,D.FecDoc
,C.TipMuc,C.Manifiesto,C.IdCiaMuc,C.IdVehiculo AS PlacaVeh,C.Modalidad,C.DiasPlazo,C.FecPago,C.Observacion AS CumObserv
,C.TipoCumpMT,C.MotivoSusp,C.ConsecSusp,C.VrAdicCargue,C.VrAdicDescargue,C.VrAdicFlete,C.MotivoVrAdic
,C.VrDctoFlete,C.MotivoVrDcto,C.VrAdicAnticipo,C.FecEntregaDoc,C.NumRadicaMT,C.MvoAnulaCump,C.ObservAnulado,C.NumViajesCum,C.PesoLiqPago,C.PesoLiqFact
,C.CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,C.CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,C.CdRuta,R.Ruta AS DescRuta
,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,M.nRemolque,M.TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,M.VrFletes,M.VrRetencion,M.VrReteIca,M.VrDescuento,M.VrAnticipo,M.VrAntAdic,M.VrNeto,M.VrPagos,M.VrCargos,M.VrDctos,M.TarifaFlete,M.Cantidad AS CantTotal,M.PesoTotal
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,M.FechaOdp,M.EstOrden,D.TipoAnulacion,D.MvoAnulacion
,D.ModdDev,D.OrigenAdd,D.TipCom,D.Comprobante,D.IdCiaCom,D.Observacion AS Observ,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevCum AS D INNER JOIN Trn_TraCumplido AS C ON D.TipDoc=C.TipDoc AND D.Cumplido=C.Cumplido AND D.IdCiaDoc=C.IdCia
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraManifiesto AS M ON C.TipMuc=M.TipDoc AND C.Manifiesto=M.Manifiesto AND C.IdCiaMuc=M.IdCia
 INNER JOIN Terceros AS CDT ON M.IdConductor=CDT.IdTercero INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero
 INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo
 INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 LEFT JOIN Localidades AS CO ON C.CdOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS CD ON C.CdDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON C.CdRuta=R.IdRuta  
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLeg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevLeg] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,Modalidad,TipMuc,Manifiesto,IdCiaMuc
,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,NitEmpresa,VrAnticipos,VrGastos,VrCombustible,VrDiferencia,VrOtrosCred,galsComb,PesoTotal,Cantidad,Volumen
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevLeg
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLegDoc] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,FecDoc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,ModdDev
 FROM Trn_TraDevLeg
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLegFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,DV.TipDoc AS TipoLiq,DV.Liquidacion AS NumLiquida,IdCiaDoc,FecDoc,Modalidad,TipMuc,Manifiesto,IdCiaMuc
,DV.IdVehiculo AS PlacaVeh,DV.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,DV.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,DV.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,DV.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,VrAnticipos,DV.VrGastos,VrCombustible,VrDiferencia,VrOtrosCred,galsComb,PesoTotal,Cantidad,Volumen
,ModdDev,TipCom,TipoCom,Comprobante,IdCiaCom,DV.Observacion AS Observ,TimeSys,IdCiaCrea,DV.IdUsuario AS CdUsuario,Usuario,Leyenda
,Item,D.IdConcepto AS DetCodConc,CG.Concepto AS DetNomConc,DescConcepto,D.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito,D.IdTercero AS NitTercero,N.RazonSocial AS NomTercero
,CdCCosto,CCosto,CdSubCos,SubCosto,D.RubroConc,VrBase,TarifBase,CantComb,TipFac,Factura,IdCiaFac,ItemFac,FecVence,RefConcep
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevLeg AS DV  INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS C ON DV.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON DV.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS NP ON DV.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS T ON DV.IdPoseedor=T.IdTercero   INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON DV.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS ETR ON DV.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON DV.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN Trn_TraLiqDetalle AS D ON DV.TipDoc=D.TipDoc AND DV.Liquidacion=D.Liquidacion AND DV.IdCiaDoc=D.IdCia
 LEFT JOIN ConcDiversos AS CG ON D.IdConcepto=CG.IdConcepto LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS N ON  D.IdTercero=N.IdTercero
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin  AND DV.IdCia=@pmIdCia
 ORDER BY  DV.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLegLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,Modalidad,TipMuc,Manifiesto,IdCiaMuc
,IdVehiculo,IdConductor,CDT.RazonSocial AS Conductor,IdPropietario,TP.RazonSocial AS Propietario,IdPoseedor,T.RazonSocial AS Poseedor
,NitEmpresa,NE.RazonSocial AS NomEmpresa,VrAnticipos,D.VrGastos,VrCombustible,VrDiferencia,VrOtrosCred,galsComb,PesoTotal,Cantidad,Volumen
,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,D.Observacion AS Observ,D.IdEstado AS CdEstado,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevLeg AS D INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON D.IdConductor=CDT.IdTercero
 INNER JOIN Terceros AS TP ON D.IdPropietario=TP.IdTercero 
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia LEFT JOIN Terceros AS NE ON D.NitEmpresa=NE.IdTercero 
 WHERE TipDev=@pmTipDev AND  D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND D.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLegRel] @pmTipDev VARCHAR(3),@pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipLiq,D.Liquidacion AS NumLiquida,IdCiaDoc,FecDoc,D.Modalidad AS Modaldad
,D.TipMuc AS TipManif,D.Manifiesto AS NumManif,D.IdCiaMuc AS CdCiaManif,D.IdVehiculo AS PlacaVeh,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,D.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,D.VrAnticipos AS TotalAntcpos,D.VrGastos AS TotalGastos,D.VrCombustible AS TotalComb,D.VrDiferencia AS ValorDif
,D.VrOtrosCred AS TotalOtrosDed,D.galsComb AS CantGals,D.PesoTotal AS Peso_Total,D.Cantidad AS CantTotal,D.Volumen AS VolTotal,ModdDev,D.OrigenAdd AS OrigenCrea,D.TipCom AS CdTipComp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp
,D.Observacion AS Observ,D.IdEstado AS CdEstado,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
,LQ.IdRuta AS CdRuta,Ruta,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
--datos del vehículo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
 FROM Trn_TraDevLeg AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero   INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero   
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraLiqViajes AS LQ ON  D.TipDoc=LQ.TipDoc AND D.Liquidacion=LQ.Liquidacion AND D.IdCiaDoc=LQ.IdCia
 INNER JOIN Localidades AS CO ON  LQ.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON LQ.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON LQ.IdRuta=R.IdRuta  
 LEFT JOIN Terceros AS ETR ON D.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 WHERE D.TipDev=@pmTipDev  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY D.IdCia,D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLegRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLegRelDet] @pmTipDev VARCHAR(3),@pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT TipDev,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,D.TipDoc AS TipLiq,D.Liquidacion AS NumLiquida,IdCiaDoc,FecDoc,D.Modalidad AS Modaldad
,D.TipMuc AS TipManif,D.Manifiesto AS NumManif,D.IdCiaMuc AS CdCiaManif,D.IdVehiculo AS PlacaVeh,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,D.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,D.VrAnticipos AS TotalAntcpos,D.VrGastos AS TotalGastos,D.VrCombustible AS TotalComb,D.VrDiferencia AS ValorDif
,D.VrOtrosCred AS TotalOtrosDed,D.galsComb AS CantGals,D.PesoTotal AS Peso_Total,D.Cantidad AS CantTotal,D.Volumen AS VolTotal,ModdDev,D.OrigenAdd AS OrigenCrea,D.TipCom AS CdTipComp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp
,D.Observacion AS Observ,D.IdEstado AS CdEstado,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
,LQ.IdRuta AS CdRuta,Ruta,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
--detales
,Item,DT.IdConcepto AS DetCodConc,CG.Concepto AS DetNomConc,DescConcepto,DT.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito,DT.IdTercero AS NitTercero,N.RazonSocial AS NomTercero
,CdCCosto,CCosto,CdSubCos,SubCosto,DT.RubroConc,VrBase,TarifBase,CantComb,TipFac,Factura,IdCiaFac,ItemFac,FecVence,RefConcep
--datos del vehículo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
 FROM Trn_TraDevLeg AS D  INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero   INNER JOIN Terceros AS NP ON D.IdPropietario=NP.IdTercero   
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraLiqViajes AS LQ ON  D.TipDoc=LQ.TipDoc AND D.Liquidacion=LQ.Liquidacion AND D.IdCiaDoc=LQ.IdCia
 INNER JOIN Localidades AS CO ON  LQ.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON LQ.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON LQ.IdRuta=R.IdRuta  
 LEFT JOIN Terceros AS ETR ON D.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN Trn_TraLiqDetalle AS DT ON D.TipDoc=DT.TipDoc AND D.Liquidacion=DT.Liquidacion AND  D.IdCiaDoc=DT.IdCia
 LEFT JOIN ConcDiversos AS CG ON DT.IdConcepto=CG.IdConcepto LEFT JOIN Puc AS P ON DT.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS N ON  DT.IdTercero=N.IdTercero LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN CentroCosto AS CC ON DT.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON DT.CdSubCos=SC.IdSubCos 
 WHERE D.TipDev=@pmTipDev  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY D.IdCia,D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevLgo] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,VrTotal,VrCosto,VrAnticipo,VrGastos,VrIva,VrRetencion,VrReteIca,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrNeto,Cantidad,CxPagar,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdEstado,VrImpAvTa,VrBomberil
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevLgo
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLgoDoc] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,ModdDev
 FROM Trn_TraDevLgo
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevLgoFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDev AS IdTipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Liquidacion AS NumLiquida,D.IdCiaDoc,FecDoc
,TipOds,L.NumOrden,IdCiaOds,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdDestino,LD.Localidad AS NomDestino,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,TipoResiduo,O.RemCliente,O.NumRemesa,O.CdCiaRem
,D.VrTotal,D.VrCosto,D.VrAnticipo,D.VrGastos,D.VrIva,D.VrRetencion,D.VrReteIca,D.VrReteCREE,D.VrReteIva,D.VrOtros,D.VrDescuento,L.VrConcCargos,L.VrConcDed,D.VrImpAvTa,D.VrBomberil,D.VrNeto,D.Cantidad
,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,L.TarifaAvta,L.TarifaBom,L.Referencia,CdPlazo,Plazo,DiasPago,FechaVence,L.UndMed,Unidad
,D.CxPagar,D.TipCom,D.Comprobante,D.IdCiaCom,D.ModdDev,D.Observacion AS Observ,D.IdEstado AS CdEstado,D.OrigenAdd,D.TimeSys AS FechaCrea
,D.FecUpdate AS FechaModif,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
--vehiuculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LT.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevLgo AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON D.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Trn_TraOrdenLiq AS L ON D.TipDoc=L.TipDoc AND D.Liquidacion=L.Liquidacion AND D.IdCiaDoc=L.IdCia
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion 
 INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal
 INNER JOIN Vehiculos AS V ON L.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Plazos AS PZ ON L.CdPlazo=PZ.IdPlazo  LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Sys_Um AS UM ON L.UndMed=UM.UndMed
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevLgoLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Liquidacion AS NumLiquida,D.IdCiaDoc,FecDoc
,TipOds,L.NumOrden,IdCiaOds,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,D.VrTotal,D.VrCosto,D.VrAnticipo,D.VrGastos,D.VrIva,D.VrRetencion,D.VrReteIca,D.VrReteCREE,D.VrReteIva,D.VrOtros,D.VrDescuento,L.VrConcCargos,L.VrConcDed,D.VrImpAvTa,D.VrBomberil,D.VrNeto,D.Cantidad
,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,L.TarifaAvta,L.TarifaBom,L.Referencia,CdPlazo,FechaVence,UndMed
,D.CxPagar,D.TipCom,D.Comprobante,D.IdCiaCom,D.ModdDev,D.Observacion AS Observ,D.IdEstado AS CdEstado,D.OrigenAdd,D.TimeSys AS FechaCrea
,D.FecUpdate AS FechaModif,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevLgo AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON D.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraOrdenLiq AS L ON D.TipDoc=L.TipDoc AND D.Liquidacion=L.Liquidacion AND D.IdCiaDoc=L.IdCia
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 WHERE D.TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLgoRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevLgoRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT D.TipDev AS IdTipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc,D.Liquidacion AS NumLiquida,D.IdCiaDoc,FecDoc
,TipOds,L.NumOrden,IdCiaOds,O.Fecha AS FecOrden,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdDestino,LD.Localidad AS NomDestino,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,TipoResiduo,O.RemCliente,O.NumRemesa,O.CdCiaRem
,D.VrTotal,D.VrCosto,D.VrAnticipo,D.VrGastos,D.VrIva,D.VrRetencion,D.VrReteIca,D.VrReteCREE,D.VrReteIva,D.VrOtros,D.VrDescuento,L.VrConcCargos,L.VrConcDed,D.VrImpAvTa,D.VrBomberil,D.VrNeto,D.Cantidad
,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,L.TarifaAvta,L.TarifaBom,L.Referencia,CdPlazo,Plazo,DiasPago,FechaVence,L.UndMed,Unidad
,D.CxPagar,D.TipCom,D.Comprobante,D.IdCiaCom,D.ModdDev,D.Observacion AS Observ,D.IdEstado AS CdEstado,D.OrigenAdd,D.TimeSys AS FechaCrea
,D.FecUpdate AS FechaModif,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
--vehiuculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LT.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevLgo AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON D.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Trn_TraOrdenLiq AS L ON D.TipDoc=L.TipDoc AND D.Liquidacion=L.Liquidacion AND D.IdCiaDoc=L.IdCia
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion 
 INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal
 INNER JOIN Vehiculos AS V ON L.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Plazos AS PZ ON L.CdPlazo=PZ.IdPlazo  LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Sys_Um AS UM ON L.UndMed=UM.UndMed
 WHERE D.TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevLiq] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,VrTotal,ModdDev,OrigenAdd
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevLiq
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLiqDoc] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,FecDoc,IdVehiculo,IdPoseedor,IdConductor,ModdDev
 FROM Trn_TraDevLiq
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLiqFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,Concepto,DV.TipDoc AS TipoLiq,DV.Liquidacion AS NumLiquida,IdCiaDoc,FecDoc
,DV.IdVehiculo AS PlacaVeh,DV.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,DV.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,VrTotal,ModdDev
,TipCom,TipoCom,Comprobante,IdCiaCom,DV.Observacion AS Observ,TimeSys,IdCiaCrea,DV.IdUsuario AS CdUsuario,Usuario,Leyenda
,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,D.IdConcepto AS CdConcCausac,D.Descripcion AS DetDescripcion,VrAbono,NitPoseedor,N.RazonSocial AS NomPoseedor,pVehiculo,EsVence
,TipOdp,OrdenPago,IdCiaOdp,TipMuc,Manifiesto,IdCiaMuc,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CCosto,CdSubCos,SubCosto
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevLiq AS DV   INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON DV.TipDev=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario   INNER JOIN Conceptos AS C ON DV.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON DV.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON DV.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON DV.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraLiquidaDed AS D ON DV.TipDoc=D.TipDoc  AND DV.Liquidacion=D.Liquidacion AND DV.IdCiaDoc=D.IdCia
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN Terceros AS N ON  D.NitPoseedor=N.IdTercero  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero 
 LEFT JOIN TiposCom AS TCM ON DV.TipCom=TCM.IdCom 
 WHERE DV.TipDev=@pmTipDev AND DV.Devolucion BETWEEN @pmDevolucionIni AND  @pmDevolucionFin AND DV.IdCia=@pmIdCia
 ORDER BY  DV.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLiqLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,T.RazonSocial AS Poseedor,IdConductor,CDT.RazonSocial AS Conductor
,VrTotal,TipCom,Comprobante,IdCiaCom,ModdDev,D.Observacion AS Observ,D.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS Cdusuario,Usuario
 FROM Trn_TraDevLiq AS D  INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON  D.IdConductor=CDT.IdTercero
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia
 WHERE  D.TipDev=@pmTipDev  AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY D.IdCia,Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevLiqRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevLiqRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
AS
 SELECT TipDev,Devolucion,DV.IdCia AS CdCia,Compania,Fecha,DV.IdConcepto AS CdConcepto,Concepto,DV.TipDoc AS TipoLiq,DV.Liquidacion AS NumLiquida,IdCiaDoc,FecDoc
,DV.IdVehiculo AS PlacaVeh,DV.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,DV.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,VrTotal,ModdDev
,TipCom,TipoCom,Comprobante,IdCiaCom,DV.Observacion AS Observ,TimeSys,IdCiaCrea,DV.IdUsuario AS CdUsuario,Usuario
,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,D.IdConcepto AS CdConcCausac,D.Descripcion AS DetDescripcion,VrAbono,NitPoseedor,N.RazonSocial AS NomPoseedor,pVehiculo,EsVence
,TipOdp,OrdenPago,IdCiaOdp,TipMuc,Manifiesto,IdCiaMuc,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CCosto,CdSubCos,SubCosto
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevLiq AS DV   INNER JOIN Companias AS CN ON DV.IdCia=CN.IdCia 
 INNER JOIN adm_Usuarios AS U ON DV.IdUsuario=U.IdUsuario   INNER JOIN Conceptos AS C ON DV.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON DV.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON DV.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON DV.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraLiquidaDed AS D ON DV.TipDoc=D.TipDoc  AND DV.Liquidacion=D.Liquidacion AND DV.IdCiaDoc=D.IdCia
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN Terceros AS N ON  D.NitPoseedor=N.IdTercero  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero 
 LEFT JOIN TiposCom AS TCM ON DV.TipCom=TCM.IdCom 
 WHERE DV.TipDev=@pmTipDev  AND DV.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND DV.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND DV.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND DV.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND DV.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND DV.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 ORDER BY DV.IdCia,DV.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevOdp] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,OrdPago,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,CxPagar,ModdDev
,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevOdp
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevOdpDoc] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,FecDoc,IdPoseedor,IdConductor,ModdDev
 FROM Trn_TraDevOdp
 WHERE  TipDoc=@pmTipDoc  AND OrdPago=@pmOrdPago AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevOdpFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipoOdp,D.OrdPago AS NumOdp,IdCiaDoc,FecDoc
,D.IdVehiculo AS PlacaVeh,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,CxPagar,ModdDev
,D.TipCom AS CdTipComp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp,D.Observacion AS Observ,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,Leyenda
,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif,VrTotalFletes,O.VrDescuento AS Vr_Dcto,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrAnticipos
,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,VrImpAvTa,O.VrNeto AS Vr_Neto
,TarifaTabla,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino
,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp,TarifaAvta,TipoLiq,TipEgr,Egreso,IdCiaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos
,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,VrRemesas,VrRecCaja,CdForma,EdoLiqCausac
,M.Fecha AS FecManif,FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,nRemolque,TipoAfiVehic
,IdLocFletes,CF.Localidad AS LugarFletes,M.Observacion AS MucObserv
--Datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevOdp AS D INNER JOIN Trn_TraOrdenManif AS O ON D.TipDoc=O.TipDoc AND D.OrdPago=O.OrdPago AND D.IdCiaDoc=O.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero
 INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta    INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero  LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 WHERE D.TipDev=@pmTipDev AND D.Devolucion  BETWEEN @pmDevolucionIni AND @pmDevolucionFin  AND D.IdCia=@pmIdCia

 ORDER BY D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevOdpLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipOdp,D.OrdPago AS NumOrden,IdCiaDoc,FecDoc,TipMuc,Manifiesto,IdCiaMuc,D.IdVehiculo AS PlacaVeh,NumVeh
,D.IdPoseedor AS NitPoseedor,NP.RazonSocial AS Poseedor,D.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,D.CxPagar AS EsCxpagar,FechaVence,LiqRemesas,TipoLiq,VrTotalFletes,VrDescuento
,VrRetencion,VrReteIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,M.VrImpAvTa,VrNeto,TarifaTabla,TarifaFlete
,UnidTarifa,PesoTotal,Unidades,Volumen,VrRemesas,VrSeguroRc,VrRecCaja,CdForma,NumCheque,Referencia,ModdDev,D.TipCom AS Tip_Comp,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaCom,D.Observacion AS Observ
,D.IdEstado AS CdEstado,Estado,D.TimeSys AS FechaCrea,D.FecUpdate AS FechaAct,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevOdp AS D INNER JOIN  Trn_TraOrdenPago AS O ON D.TipDoc=O.TipDoc  AND D.OrdPago=O.OrdPago AND D.IdCiaDoc=O.IdCia
 INNER JOIN Trn_TraOrdenManif AS M ON O.TipDoc=M.TipDoc AND O.OrdPago=M.OrdPago AND O.IdCia=M.IdCia
 INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN Terceros AS NP ON D.IdPoseedor=NP.IdTercero 
 INNER JOIN Terceros AS NC ON D.IdConductor=NC.IdTercero
 INNER JOIN EstadoDoc AS ED ON D.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE TipDev=@pmTipDev AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY  D.IdCia,D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevOdpRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevOdpRel] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
,@pmDevolucionIni INT=Null,@pmDevolucionFin INT=Null
 AS 
 SELECT D.TipDev,D.Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS TipoOdp,D.OrdPago AS NumOdp,IdCiaDoc,FecDoc
,D.IdVehiculo AS PlacaVeh,D.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,D.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,CxPagar,ModdDev
,D.TipCom AS CdTipComp,TipoCom,D.Comprobante AS NumComp,D.IdCiaCom AS CdCiaComp,D.Observacion AS Observ,D.TimeSys AS FechaCrea,D.IdCiaCrea AS CdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif,VrTotalFletes,O.VrDescuento AS Vr_Dcto,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrAnticipos
,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto AS Vr_Neto
,TarifaTabla,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino
,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp,TipoLiq,TipEgr,Egreso,IdCiaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos
,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,VrRemesas,VrRecCaja,CdForma,EdoLiqCausac
,M.Fecha AS FecManif,FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,nRemolque,TipoAfiVehic
,IdLocFletes,CF.Localidad AS LugarFletes,M.Observacion AS MucObserv
--Datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraDevOdp  AS D INNER JOIN Trn_TraOrdenManif AS O ON D.TipDoc=O.TipDoc AND D.OrdPago=O.OrdPago AND D.IdCiaDoc=O.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero
 INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta    INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero  LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN ISNULL(@pmDevolucionIni,0) AND ISNULL(@pmDevolucionFin,2147483647)
 AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
-- AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
-- AND D.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND D.IdConductor LIKE ISNULL(@pmIdConductor,'%')
-- AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReex]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraDevReex] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdEmpTrans,NumFactura,FecFactura,VrTotal,VrImpuesto,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto
,PesoTotal,CxPagar,TipCom,Comprobante,IdCiaCom,ModdDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraDevReex
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReexDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevReexDoc] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCiaDoc CHAR(2)
 AS 
 SELECT TipDev,Devolucion,IdCia,Fecha,IdConcepto,IdEmpTrans,ModdDev
 FROM Trn_TraDevReex
 WHERE  TipDoc=@pmTipDoc  AND Causacion=@pmCausacion AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReexFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevReexFmt] @pmTipDev VARCHAR(3),@pmDevolucionIni INT,@pmDevolucionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Devolucion,D.IdCia AS CdCia,Compania,D.Fecha AS FechaDev,D.IdConcepto AS CdConcepto,Concepto,D.TipDoc AS CdTipDoc,D.Causacion AS NumCausac,IdCiaDoc,FecDoc,IdEmpTrans,T.RazonSocial AS NomEmpresa
,NumFactura,FecFactura,VrTotal,VrImpuesto,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto,PesoTotal,CxPagar,TipCom,TipoCom,Comprobante,IdCiaCom,ModdDev,D.Observacion AS Observ,D.IdEstado AS CdEstado
--detalles
,Item,TipRem,Remesa,IdCiaRem,FecRemesa,Descripcion,Unidades,PesoNeto,R.UndMed AS CdUmed,UMP.Unidad AS UmPeso,Volumen,UndVol,UndTarifa,VrUnitario,ValorTotal
,pVehiculo,CedConductor,CDT.RazonSocial AS NomConductor
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario,TipDev,TipoDoc,Leyenda
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM Trn_TraDevReex  AS D   INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN Terceros AS T ON D.IdEmpTrans=T.IdTercero INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_TraReexpedidoRem AS R  ON D.TipDoc=R.TipDoc AND D.Causacion=R.Causacion  AND D.IdCiaDoc=R.IdCia
 LEFT JOIN Sys_Um AS UMP ON R.UndMed=UMP.UndMed  LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom
 LEFT JOIN Terceros AS  CDT ON R.CedConductor=CDT.IdTercero 
 WHERE D.TipDev=@pmTipDev AND D.Devolucion BETWEEN @pmDevolucionIni AND @pmDevolucionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraDevReexLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraDevReexLta] @pmTipDev VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdEmpTrans VARCHAR(16)=Null
 AS 
 SELECT  Devolucion,D.IdCia AS CdCia,Compania,Fecha,D.IdConcepto AS CdConcepto,Concepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdEmpTrans,RazonSocial,NumFactura,FecFactura
,VrTotal,VrImpuesto,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto,PesoTotal,CxPagar,TipCom,Comprobante,IdCiaCom,ModdDev
,D.Observacion AS Observ,D.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,D.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraDevReex AS D  INNER JOIN Companias AS CI ON D.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON D.IdConcepto=CN.IdConcepto
 INNER JOIN Terceros AS T ON D.IdEmpTrans=T.IdTercero INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario
 WHERE D.TipDev=@pmTipDev   AND D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  D.IdEmpTrans LIKE ISNULL(@pmIdEmpTrans,'%')
 ORDER BY D.IdCia,D.Devolucion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraFacRemesasItem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraFacRemesasItem] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,TipRem,Remesa,IdCiaRem,ItemRem,FecRemesa,Descripcion,Cantidad,VrUnitario,VrCosto,UndTarifa,UndCosto,Unidades,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets
,TarifaIva,VrImpuesto,TarifaDct,VrDescuento,TarifaRet,VrRetencion,TarifaIca,VrReteIca,VrFaltante,Remision,DocCliente,Referencia1,Referencia2,Referencia3,CdMercancia,CdConcepto,CdCCosto,CdSubCos,NitTercero
,CdAgencia,pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipoNovFact,TipDocRef,NumDocRef,IdCiaRef,ItemDocRef,FecDocRef,CantidadFalt,UnidadFalt,CodTarRet,CodTarIca,CodTarDct,NumPedRem,CiaPedRem,VrDeclMcia,TarifaSeg,VrSeguroRem
,NitAsegurad,CantPago,VrAutRetIca,RemTransb,CostoAdicTbdo,NitMucTbdo,TarifaIat,VrAviTab,CodTarIat,TarifaBom,VrSobBom,CodTarBom,VrAutoIat,VrAutoBom,VrTray_Vacio1,VrTray_Vacio2
 FROM Trn_TraFacRemesas
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryTraFijos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraFijos] @pmNumero INT
 AS 
 SELECT Numero,IdConcepto,DescConc,TipoConc,Tarifa,TipoTarif,TipoAfilVeh,CdTipoVeh,TipoTerc,Anulado
,CdCiuOrigen,CdCiuDestino,pVehiculo,CedConductor,CdRuta,TipoVigencia,FechaInicial,FechaFinal,NitCliente,CdMercancia,IdentProp
 FROM TraFijos
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paQryTraFijosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraFijosLta] @pmTipoConc VARCHAR(10)=Null
 AS 
 SELECT Numero,IdConcepto,DescConc,TipoConc,Tarifa,TipoTarif,TipoAfilVeh,CdTipoVeh,TipoVehiculo,TipoTerc
,CdCiuOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CdDepOri,DPO.Departamento AS DptoOrigen
,CdCiuDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino
,pVehiculo,CedConductor,CDT.RazonSocial AS NomConductor,CdRuta,R.Ruta,NitCliente,T.RazonSocial AS NomCliente,CdMercancia,M.DescripMcia
,TipoVigencia,FechaInicial,FechaFinal,F.IdentProp,NP.RazonSocial AS NomPropietario,F.Anulado
 FROM TraFijos AS F LEFT JOIN TiposVeh AS TV ON F.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Localidades AS LO ON F.CdCiuOrigen=LO.IdLocal LEFT JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS LD ON F.CdCiuDestino=LD.IdLocal LEFT JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN Rutas AS R ON F.CdRuta=R.IdRuta LEFT JOIN Terceros AS CDT ON F.CedConductor=CDT.IdTercero
 LEFT JOIN Terceros AS T ON F.NitCliente=T.IdTercero LEFT JOIN Mercancias AS M ON F.CdMercancia=M.IdMercancia
 LEFT JOIN Terceros AS NP ON F.IdentProp=NP.IdTercero
 WHERE TipoConc LIKE ISNULL(@pmTipoConc,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraGuias] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumGuia,IdCia,Fecha,FecDespacho,FecVigencia,Modalidad,IdCliente,IdAgencia,IdRemitente,NomRemitente,IdDestinatario,NomDestinatario,DirOrigen,IdLocOrigen,DirDestino,IdLocDestino,NomContacto,TelContacto,emlContacto,TelRemitente,emlRemitente,TelDestinatario,emlDestinatario
,IdResponsable,NomResponsable,VrTotal,VrDeclarado,VrSeguro,VrCargos,Cantidad,PesoTotal,TipRem,NumRemesa,IdCiaRem,EstFactura,TipFac,NumFactura,IdCiaFac,FechaFac,EstLiquida,TipLiq,NumLiquida,IdCiaLiq,CdConcepto,CdForma,TipCom,Comprobante,IdCiaCom,NumRemision
,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,FechaCrea,FechaModif,IdCiaCrea,IdUsuario
 FROM Trn_TraGuias
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuiasFco]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraGuiasFco] @pmTipDoc VARCHAR(3),@pmNumGuiaIni INT,@pmNumGuiaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT G.TipDoc,TipoDoc,G.NumGuia,G.IdCia,Compania,G.Fecha,G.FecDespacho,G.FecVigencia,G.Modalidad,G.IdCliente,T.RazonSocial AS Nom_Cliente,G.IdAgencia,A.Agencia AS NomAgencia
,G.IdRemitente,G.NomRemitente,G.DirOrigen,G.TelRemitente,G.emlRemitente,G.IdDestinatario,G.NomDestinatario,G.DirDestino,G.TelDestinatario,G.emlDestinatario
,G.IdLocOrigen,LO.Localidad AS CiudadOrigen,DP.Departamento AS DptoOrigen,G.IdLocDestino,LD.Localidad AS CiudadDestino,DD.Departamento AS DptoDestino,G.NomContacto,G.TelContacto,G.emlContacto
,G.IdResponsable,G.NomResponsable,G.VrTotal,G.VrDeclarado AS VrTotDeclarado,G.VrSeguro AS VrTotSeguro,G.VrCargos,G.Cantidad AS Cant_Total,G.PesoTotal,G.TipRem,G.NumRemesa,G.IdCiaRem,G.EstFactura,G.TipFac,G.NumFactura,G.IdCiaFac,G.FechaFac
,G.EstLiquida,G.TipLiq,G.NumLiquida,G.IdCiaLiq,G.CdConcepto,C.Concepto,G.CdForma,FormaPago,G.TipCom,TipoCom,G.Comprobante,G.IdCiaCom,G.Anulado,G.FecDev,G.Observacion,G.IdEstado,ED.Estado
,G.FechaCrea,G.FechaModif,G.IdCiaCrea,G.IdUsuario,Usuario,G.OrigenAdd
--Detalle
,D.Item,D.IdMercancia,D.DescripcionMcia,D.Cantidad,D.PesoNeto,D.UndMed,UMP.Unidad AS UmPeso,D.dmsAlto,D.dmsAncho,D.dmsLargo,D.Volumen,D.UndVol,D.IdUnd,UM.Unidad AS UndMedida,D.IdEmp,EP.Empaque
,D.VrUnitario,D.VrDeclarado,D.VrSeguro,D.TarifSeguro,D.UndTarifa,D.Remision,D.DocCliente,D.Referencia1,D.Referencia2,D.Referencia3,D.CantFactura,D.VrFactura,D.CdConcepto AS CdConcFactura,DC.Concepto AS ConcFactura
--datos del tercero
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,A.DirAgncia AS AgeDireccion,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
--enc fact cont
,FE.EstadoFE,FE.Prefijo,FE.NumFace,FE.CUFE,FE.Resolucion,FE.RangoNum,FE.FecVigencia AS FecVigNum,FE.CUFE_QR AS QR,FE.FechaValidacion
 FROM Trn_TraGuias AS G INNER JOIN Companias AS CN ON G.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON G.TipDoc=TD.IdDoc
 INNER JOIN EstadoGuia AS ED ON G.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraGuiaMcia AS D ON G.TipDoc=D.TipDoc AND G.NumGuia=D.NumGuia AND G.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS LO ON G.IdLocOrigen=LO.IdLocal INNER JOIN Departamentos AS DP ON LO.IdDep=DP.IdDep
 INNER JOIN Localidades AS LD ON G.IdLocDestino=LD.IdLocal INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 LEFT JOIN Conceptos AS C ON G.CdConcepto=C.IdConcepto LEFT JOIN TiposCom AS TC ON G.TipCom=TC.IdCom
 LEFT JOIN Agencias AS A ON G.IdAgencia=A.IdAgencia LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal
 LEFT JOIN Formaspago AS F ON G.CdForma=F.IdForma LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 LEFT JOIN ConcDiversos AS DC ON D.CdConcepto=DC.IdConcepto 
 LEFT JOIN Trn_Face AS FE ON G.TipFac=FE.TipDoc AND G.NumFactura=FE.Documento AND G.IdCiaFac=FE.IdCia
 WHERE G.TipDoc=@pmTipDoc AND G.NumGuia BETWEEN @pmNumGuiaIni AND @pmNumGuiaFin AND G.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuiasFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraGuiasFmt] @pmTipDoc VARCHAR(3),@pmNumGuiaIni INT,@pmNumGuiaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT G.TipDoc,TipoDoc,G.NumGuia,G.IdCia,Compania,G.Fecha,G.FecDespacho,G.FecVigencia,G.Modalidad,G.IdCliente,T.RazonSocial AS Nom_Cliente,G.IdAgencia,A.Agencia AS NomAgencia
,G.IdRemitente,G.NomRemitente,G.DirOrigen,G.TelRemitente,G.emlRemitente,G.IdDestinatario,G.NomDestinatario,G.DirDestino,G.TelDestinatario,G.emlDestinatario
,G.IdLocOrigen,LO.Localidad AS CiudadOrigen,DP.Departamento AS DptoOrigen,G.IdLocDestino,LD.Localidad AS CiudadDestino,DD.Departamento AS DptoDestino,G.NomContacto,G.TelContacto,G.emlContacto
,G.IdResponsable,G.NomResponsable,G.VrTotal,G.VrDeclarado AS VrTotDeclarado,G.VrSeguro AS VrTotSeguro,G.VrCargos,G.Cantidad AS Cant_Total,G.PesoTotal,G.TipRem,G.NumRemesa,G.IdCiaRem,G.EstFactura,G.TipFac,G.NumFactura,G.IdCiaFac,G.FechaFac
,G.EstLiquida,G.TipLiq,G.NumLiquida,G.IdCiaLiq,G.NumRemision,G.CdConcepto,C.Concepto,G.CdForma,FormaPago,G.TipCom,TipoCom,G.Comprobante,G.IdCiaCom,G.Anulado,G.FecDev,G.Observacion,G.IdEstado,ED.Estado
,G.FechaCrea,G.FechaModif,G.IdCiaCrea,G.IdUsuario,Usuario,G.OrigenAdd
--Detalle
,D.Item,D.IdMercancia,D.DescripcionMcia,D.Cantidad,D.PesoNeto,D.UndMed,UMP.Unidad AS UmPeso,D.dmsAlto,D.dmsAncho,D.dmsLargo,D.Volumen,D.UndVol,D.IdUnd,UM.Unidad AS UndMedida,D.IdEmp,EP.Empaque--,D.IdNat,D.IdTmcia,D.IdMnjo
,D.VrUnitario,D.VrDeclarado,D.VrSeguro,D.TarifSeguro,D.UndTarifa,D.Remision,D.DocCliente,D.Referencia1,D.Referencia2,D.Referencia3,D.CantFactura,D.VrFactura,D.CdConcepto AS CdConcFactura,DC.Concepto AS ConcFactura
--datos del tercero
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,A.DirAgncia AS AgeDireccion,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
 FROM Trn_TraGuias AS G INNER JOIN Companias AS CN ON G.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON G.TipDoc=TD.IdDoc
 INNER JOIN EstadoGuia AS ED ON G.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraGuiaMcia AS D ON G.TipDoc=D.TipDoc AND G.NumGuia=D.NumGuia AND G.IdCia=D.IdCia
 INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS LO ON G.IdLocOrigen=LO.IdLocal INNER JOIN Departamentos AS DP ON LO.IdDep=DP.IdDep
 INNER JOIN Localidades AS LD ON G.IdLocDestino=LD.IdLocal INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 LEFT JOIN Conceptos AS C ON G.CdConcepto=C.IdConcepto LEFT JOIN TiposCom AS TC ON G.TipCom=TC.IdCom
 LEFT JOIN Agencias AS A ON G.IdAgencia=A.IdAgencia LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal
 LEFT JOIN Formaspago AS F ON G.CdForma=F.IdForma LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 LEFT JOIN ConcDiversos AS DC ON D.CdConcepto=DC.IdConcepto 
 WHERE G.TipDoc=@pmTipDoc AND G.NumGuia BETWEEN @pmNumGuiaIni AND @pmNumGuiaFin AND G.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraGuiasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraGuiasLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
SELECT G.TipDoc,G.NumGuia,G.IdCia,Compania,G.Fecha,G.FecDespacho,G.FecVigencia,G.Modalidad,T.TipoId,G.IdCliente,T.Dv,T.RazonSocial AS Nom_Cliente,G.IdAgencia,A.Agencia AS NomAgencia
,G.IdRemitente,G.NomRemitente,G.DirOrigen,G.TelRemitente,G.emlRemitente,G.IdDestinatario,G.NomDestinatario,G.DirDestino,G.TelDestinatario,G.emlDestinatario
,G.IdLocOrigen,LO.Localidad AS CiudadOrigen,DP.Departamento AS DptoOrigen,G.IdLocDestino,LD.Localidad AS CiudadDestino,DD.Departamento AS DptoDestino,G.NomContacto,G.TelContacto,G.emlContacto
,G.IdResponsable,G.NomResponsable,G.VrTotal,G.VrDeclarado AS VrTotDeclarado,G.VrSeguro AS VrTotSeguro,G.VrCargos,G.Cantidad AS Cant_Total,G.PesoTotal,G.TipRem,G.NumRemesa,G.IdCiaRem,G.EstFactura,G.TipFac,G.NumFactura,G.IdCiaFac,G.FechaFac
,G.EstLiquida,G.TipLiq,G.NumLiquida,G.IdCiaLiq,G.NumRemision,G.CdConcepto,C.Concepto,G.CdForma,FormaPago,G.TipCom,TC.TipoCom,G.Comprobante,G.IdCiaCom,G.Anulado,G.FecDev,G.Observacion,G.IdEstado,ED.Estado,G.FechaCrea,G.IdUsuario,Usuario
--datos de factura
,GF.FacCantidad,GF.FacValorTotal,GF.FacVrSeguro,GF.FacVrCargos,GF.FacUnidades,GF.FacPesoNeto,GF.FacVolumen
,GM.NumManif,GM.CiaManif,MC.IdVehiculo,MC.TipoAfiVehic,MC.IdConductor,NC.RazonSocial AS NomConductor,MC.IdPoseedor,NP.RazonSocial AS NomPoseedor,MC.EstOrden,MC.TipOdp,MC.OrdPago,MC.IdCiaOdp
,LG.LiqVrGuias,LG.LiqVrSeguro,LG.LiqVrCargos,LG.LiqCantidad,LG.LiqPesoTotal
 FROM Trn_TraGuias AS G INNER JOIN Companias AS CN ON G.IdCia=CN.IdCia INNER JOIN EstadoGuia AS ED ON G.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON G.IdUsuario=U.IdUsuario INNER JOIN Terceros AS T ON G.IdCliente=T.IdTercero
 INNER JOIN Localidades AS LO ON G.IdLocOrigen=LO.IdLocal INNER JOIN Departamentos AS DP ON LO.IdDep=DP.IdDep
 INNER JOIN Localidades AS LD ON G.IdLocDestino=LD.IdLocal INNER JOIN Departamentos AS DD ON LD.IdDep=DD.IdDep
 LEFT JOIN Conceptos AS C ON G.CdConcepto=C.IdConcepto LEFT JOIN Formaspago AS F ON G.CdForma=F.IdForma
 LEFT JOIN Agencias AS A ON G.IdAgencia=A.IdAgencia LEFT JOIN TiposCom AS TC ON G.TipCom=TC.IdCom
--subconsulta facturacion
 LEFT JOIN (SELECT TipRem,Remesa,IdCiaRem,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cantidad*-1 ELSE Cantidad END) AS FacCantidad
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Unidades*-1 ELSE Unidades END) AS FacUnidades
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN PesoNeto*-1 ELSE PesoNeto END) AS FacPesoNeto
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Volumen*-1 ELSE Volumen END) AS FacVolumen
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE Cantidad*VrUnitario END) AS FacValorTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN VrSeguroRem*-1 ELSE VrSeguroRem END) AS FacVrSeguro
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN CostoAdicTbdo*-1 ELSE CostoAdicTbdo END) AS FacVrCargos
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE Factura END) AS NumFactura
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Factura ELSE 0 END) AS NumDevFact
FROM Trn_TraFacRemesas WHERE TipRem='GTC' GROUP BY TipRem,Remesa,IdCiaRem) AS GF ON G.TipDoc=GF.TipRem AND G.NumGuia=GF.Remesa AND G.IdCia=GF.IdCiaRem
--subconsulta No. manifiesto
LEFT JOIN (SELECT RG.TipDoc,RG.NumGuia,RG.IdCiaGuia,MAX(MR.Manifiesto) AS NumManif,MAX(MR.IdCia) AS CiaManif
 FROM Trn_TraRemGuias AS RG INNER JOIN Trn_TraManifRem AS MR ON RG.TipRem=MR.TipRem AND RG.Remesa=MR.Remesa AND RG.IdCia=MR.IdCiaRem
 INNER JOIN Trn_TraManifiesto AS M ON MR.TipDoc=M.TipDoc AND MR.Manifiesto=M.Manifiesto AND MR.IdCia=M.IdCia WHERE M.Anulado=0 GROUP BY RG.TipDoc,RG.NumGuia,RG.IdCiaGuia) AS GM ON G.TipDoc=GM.TipDoc AND G.NumGuia=GM.NumGuia AND G.IdCia=GM.IdCiaGuia
--subconsulta manifiestos
LEFT JOIN (SELECT M.TipDoc,M.Manifiesto,M.IdCia,M.Fecha,M.IdOrigen,M.IdDestino,M.IdVehiculo,M.TipoAfiVehic,M.IdConductor,M.IdPropietario,M.IdPoseedor,M.EstCumplido,M.Cumplido,M.IdCiaCump,M.EstOrden,M.TipOdp,M.OrdPago,M.IdCiaOdp,M.Observacion
,O.Fecha AS FecOPago,O.TipCom,O.Comprobante,O.IdCiaCom,O.Anulado AS OdpAnulado,OM.VrTotalFletes,OM.VrRetencion,OM.VrReteIca,OM.VrAnticipos,OM.VrFaltantes,OM.VrSeguros,OM.VrFondos,OM.VrAportes,OM.VrOtrosDctos,OM.VrImpuestos,OM.VrOtrosPagos
,OM.VrNeto,OM.TarifaTabla,OM.TarifaFlete,OM.VrRemesas,OM.VrRecCaja,OM.VrSeguroRc
FROM Trn_TraManifiesto AS M LEFT JOIN Trn_TraOrdenPago AS O ON M.TipOdp=O.TipDoc AND M.OrdPago=O.OrdPago AND M.IdCiaOdp=O.IdCia
LEFT JOIN Trn_TraOrdenManif AS OM ON M.TipOdp=OM.TipDoc AND M.OrdPago=OM.OrdPago AND M.IdCiaOdp=OM.IdCia WHERE M.Anulado=0) AS MC ON GM.NumManif=MC.Manifiesto AND GM.CiaManif=MC.IdCia
--subconsulta Liq. contraentrega
LEFT JOIN (SELECT TipGui,NumGuia,IdCiaGuia,SUM(CASE WHEN (TipDoc='ODP' OR TipDoc='LGA') THEN VrLiquidado WHEN (TipDoc='DOP' OR TipDoc='DLG') THEN VrLiquidado*-1 ELSE 0 END) AS LiqVrGuias
,SUM(CASE WHEN (TipDoc='ODP' OR TipDoc='LGA') THEN VrSeguro WHEN (TipDoc='DOP' OR TipDoc='DLG') THEN VrSeguro*-1 ELSE 0 END) AS LiqVrSeguro
,SUM(CASE WHEN (TipDoc='ODP' OR TipDoc='LGA') THEN VrCargos WHEN (TipDoc='DOP' OR TipDoc='DLG') THEN VrCargos*-1 ELSE 0 END) AS LiqVrCargos
,SUM(CASE WHEN (TipDoc='ODP' OR TipDoc='LGA') THEN Cantidad WHEN (TipDoc='DOP' OR TipDoc='DLG') THEN Cantidad*-1 ELSE 0 END) AS LiqCantidad
,SUM(CASE WHEN (TipDoc='ODP' OR TipDoc='LGA') THEN PesoTotal WHEN (TipDoc='DOP' OR TipDoc='DLG') THEN PesoTotal*-1 ELSE 0 END) AS LiqPesoTotal
FROM Trn_TraOrdenGuias GROUP BY TipGui,NumGuia,IdCiaGuia) AS LG ON G.TipDoc=LG.TipGui AND G.NumGuia=LG.NumGuia AND G.IdCia=LG.IdCiaGuia
LEFT JOIN Terceros AS NP ON MC.IdPoseedor=NP.IdTercero LEFT JOIN Terceros AS NC ON MC.IdConductor=NC.IdTercero
WHERE G.TipDoc=@pmTipDoc AND G.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
AND (G.IdCia=@pmIdCia OR @pmIdCia IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryTraInfViajes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraInfViajes] @pmTipDoc VARCHAR(3),@pmNumViaje INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumViaje,IdCia,Fecha,IdOrigen,IdDestino,IdRuta,IdVehiculo,IdPoseedor,IdConductor,nRemolque,TipoAfiVehic,VrFletes,PesoTotal,NumManif,IdCiaManif,NumMintrans,MvoAnulacion,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraInfViajes
 WHERE TipDoc=@pmTipDoc AND NumViaje=@pmNumViaje AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraInfViajesFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraInfViajesFmt] @pmTipDoc VARCHAR(3),@pmNumViajeIni INT,@pmNumViajeFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc AS CdTipDoc,TipoDoc,M.NumViaje AS Num_Viaje,M.IdCia AS CdCia,Compania,M.Fecha AS FecViaje,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,Ruta
,M.IdVehiculo AS PlacaVeh,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,M.nRemolque AS NumRemolque,M.TipoAfiVehic AS TipoAfiVeh,M.VrFletes AS VrTotFlete,M.PesoTotal AS Peso_Total,M.NumManif AS Num_Manif,M.IdCiaManif AS CdCiaManif,NumMintrans,MvoAnulacion,M.Anulado AS Anuldo,M.FecDev AS FecAnulado
,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.TimeSys,M.FecUpdate,M.IdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
--detalles
,MR.Item AS ItemDet,TipOrden,MR.NumOrden AS Num_Orden,MR.IdCiaOrd AS CdCiaOrd,ItemOrd,D.IdMercancia AS CdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,Volumen,UndVol
,NitRemite,Remitente,DirOrigen,D.IdOrigen AS OrdCodOrigen,LO.Localidad AS OrdCiudadOrigen,LO.IdDep AS OrdCdepOrigen,DOR.Departamento AS OrdDptoOrigen,NitDestntario,Destinatario,DirDestino
,D.IdDestino AS OrdCodDestino,LD.Localidad AS OrdCiudadDestino,LD.IdDep AS OrdCdepDestino,DDN.Departamento AS OrdDptoDestino,TarifClie,TarifTabla,TarifPago,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro
,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,PesoCont,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod
,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango,IdCliente,CL.RazonSocial AS OrdNomCliente
--Datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraInfViajes AS M INNER JOIN Trn_TraInfViajesOrd AS MR ON M.TipDoc=MR.TipDoc AND M.NumViaje=MR.NumViaje AND M.IdCia=MR.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON MR.TipOrden=D.TipDoc AND MR.NumOrden=D.NumOrden AND MR.IdCiaOrd=D.IdCia AND MR.ItemOrd=D.Item
 INNER JOIN Trn_TraRemesa AS R ON MR.TipOrden=R.TipDoc AND MR.NumOrden=R.NumOrden AND MR.IdCiaOrd=R.IdCia 
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS RT ON M.IdRuta=RT.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DOR ON LO.IdDep=DOR.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DDN ON LD.IdDep=DDN.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia 
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS COL ON V.IdColor=COL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Terceros AS CL ON R.IdCliente=CL.IdTercero 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango
 WHERE M.TipDoc=@pmTipDoc AND M.NumViaje BETWEEN @pmNumViajeIni AND @pmNumViajeFin AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqDetalleFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiqDetalleFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
AS 
 SELECT TipDoc,Liquidacion,D.IdCia,Compania,D.Item,D.IdConcepto AS CdConcepto,DescConcepto,D.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito
,D.IdTercero AS NitTercero,RazonSocial,D.CodAgncia,CdCCosto,CCosto,CdSubCos,SubCosto,pVehiculo
,D.RubroConc,D.VrBase,D.TarifBase,D.TipFac,D.Factura,D.IdCiaFac,ItemFac,D.FecVence,RefConcep,Concepto,D.TipSop,D.NumSoporte,D.IdCiaSop
,D.DocSop,D.TipoImp,D.CodTarImp,D.ItemBase,D.TipoNov,D.TipDocNov,D.NumDocNov,D.CiaDocNov,D.ItemNov
 FROM Trn_TraLiqDetalle AS D INNER JOIN ConcDiversos AS C ON D.IdConcepto=C.IdConcepto 
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia
 INNER JOIN Puc AS P ON D.IdCuenta=P.IdCuenta LEFT JOIN Terceros AS T ON D.IdTercero=T.IdTercero
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 WHERE D.TipDoc=@pmTipDoc AND D.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqManifFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiqManifFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
SELECT L.TipDoc,L.Liquidacion,L.IdCia AS CdCia,L.Item,L.TipMuc,L.Manifiesto,L.IdCiaMuc,M.Fecha AS FechaMuc,M.FecDespacho
,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,M.IdRuta AS CdRuta,RT.Ruta AS DescRuta,M.IdVehiculo AS PlacaVeh,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,M.nRemolque,M.TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,M.VrFletes,VrAnticipo,VrAntAdic,VrNeto,TarifaFlete,M.Cantidad AS CantTotal,M.PesoTotal,M.FechaPago,NumMintrans,EdoMintrans,M.EstCumplido,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,M.VrFleteNeto,M.Anulado,M.FecDev,M.Observacion AS Observ
,MA.VrFleteTon,MA.TipoRuta AS MucTipoRuta,MA.NomRemite AS NomRmtente,MA.NomDestino AS NomDestnatario,NumAnticipo,NumCheque,MA.TipoMintrans AS TipoMucMintrans,MucMintrans,VolumenCarga
 FROM Trn_TraLiqManif AS L INNER JOIN Trn_TraManifiesto AS M ON L.TipMuc=M.TipDoc AND L.Manifiesto=M.Manifiesto AND L.IdCiaMuc=M.IdCia
 INNER JOIN Trn_TraManifAnexo AS MA ON L.TipMuc=MA.TipDoc AND L.Manifiesto=MA.Manifiesto AND L.IdCiaMuc=MA.IdCia
 INNER JOIN Localidades AS CO ON M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS RT ON M.IdRuta=RT.IdRuta INNER JOIN Terceros AS CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  
 WHERE L.TipDoc=@pmTipDoc AND L.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND L.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquida] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,IdVehiculo,IdPoseedor,IdConductor,VrTotal,CxPagar,TipCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,Observacion,IdEstado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,ModLiquida,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraLiquida
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaDedFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquidaDedFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDoc AS TipoLiq,Liquidacion,D.IdCia AS CdCia,Compania,D.Item AS nItem,TipCau,D.Causacion AS NumCausac,IdCiaCau,ItemCau,FechaCau
,D.IdConcepto AS CdConcCausac,D.Descripcion AS DetDescripcion,VrAbono,NitPoseedor,N.RazonSocial AS NomPoseedor,D.pVehiculo AS PlacaVeh,EsVence
,TipOdp,OrdenPago,IdCiaOdp,TipMuc,Manifiesto,IdCiaMuc,VrSaldoOrden,D.CdCuenta AS CodCuenta,CdCuePagar,NumFactura,D.CdCCosto AS CodCentro,CCosto,D.CdSubCos AS CodSubCosto,SubCosto
--Datos del detalle
,DC.Descripcion AS CauDescripcion,DC.VrDebito AS VrTotalDed,EstadoReg,DC.VrAbonado AS VrTotAbonado
--datos del poseedor
,N.TipoId AS TercTipId,N.Dv AS TercDv,N.Codigo AS TercCodigo,N.Direccion AS TercDireccion,N.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,N.Telefono AS TercTelefono,N.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdColor AS CdColor,NomColor,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,TipoAfil,V.Descripcion AS VehDescripcion
 FROM Trn_TraLiquidaDed AS D INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia 
 LEFT JOIN Terceros AS N ON D.NitPoseedor=N.IdTercero LEFT JOIN Localidades AS L ON N.IdLocal=L.IdLocal 
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN Vehiculos AS V ON D.pVehiculo=V.IdVehiculo  LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca  LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero 
 LEFT JOIN Trn_TraCauDetalle AS DC ON D.TipCau=DC.TipDoc AND D.Causacion=DC.Causacion AND D.IdCiaCau=DC.IdCia AND D.ItemCau=DC.Item
 WHERE D.TipDoc=@pmTipDoc AND D.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquidaFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT LQ.TipDoc AS TipLiq,TipoDoc,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,CN.Compania AS NomCompania,LQ.Fecha AS FechaLiq,LQ.IdConcepto AS CdConcepto,Concepto
,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,VrTotal,LQ.CxPagar AS CPagar,LQ.TipCom AS CdTipCom,TipoCom,LQ.Comprobante AS NumComp,LQ.IdCiaCom AS CdCiaComp
,LQ.Anulado AS Anuldo,LQ.NumDev AS NDevolucion,LQ.FecDev AS FechDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,Estado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,ModLiquida
,LQ.TimeSys AS FechaAdd,LQ.FecUpdate AS FechaAct,LQ.IdCiaCrea AS CdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario,Leyenda
--datos de ordenes de pago
,LP.TipOdp AS TipOrden,LP.OrdPago AS NumOrden,LP.IdCiaOdp AS CdCiaOdp,COP.Compania AS NomCiaOrden,OP.Fecha AS FechaOdp,OP.TipMuc AS TipManif,OP.Manifiesto AS NumManif,OP.IdCiaMuc AS CdCiaManif
,OP.IdVehiculo AS PlacaVeh,OP.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,OP.VrTotalFletes,OP.VrDescuento AS Vr_Dcto,OP.VrRetencion AS Vr_RetFte,OP.VrReteIca AS Vr_RetIca,OP.VrAnticipos,OP.VrFaltantes,OP.VrSeguros
,OP.VrFondos,OP.VrAportes,OP.VrOtrosDctos,OP.VrImpuestos,OP.VrEstampilla,OP.VrOtrosPagos,OP.VrNeto AS Vr_Neto,VrAbonado,TotAbonado,OP.TarifaTabla,OP.TarifaFlete AS Tarifa_Flete,OP.UnidTarifa,OP.PesoTotal AS Peso_Total
,OP.Unidades,OP.Volumen AS VolmTotal,OP.PesoOrigen,OP.UnidOrigen,OP.VolOrigen,OP.PesoDestino,OP.UnidDestino,OP.VolDestino,OP.BaseRet,OP.BaseIca,OP.BaseSeg,OP.BaseImp,OP.TarifaRet,OP.TarifaIca,OP.TarifaSeg,OP.TarifaImp,OP.NumCheque,OP.Referencia AS Referncia,OP.EdoLiqCausac
,OP.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,OP.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,OP.IdRuta AS CdRuta,R.Ruta AS DescRuta,OP.nRemolque
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,OP.FecManif,VrApos,VrFam,VrFsc,VrFgi,VrTarApos ,VrTarFam ,VrTarFGi,VrTarFsc,VrBaseApos ,VrBaseFam,VrBaseFgi,VrBaseFsc,TPV.NumCuenta AS NumCtaProveedor,CTA.ClaseCuenta
,TPV.NitContac,TPV.NomContac,BA.Banco 
 FROM Trn_TraLiquida AS LQ INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON LQ.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON LQ.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario 
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Trn_TraLiquidaOdp AS LP ON LQ.TipDoc=LP.TipDoc AND LQ.Liquidacion=LP.Liquidacion AND LQ.IdCia=LP.IdCia
--* SubConsulta: Ordenes de pago/ Liquidaciones
 INNER JOIN (SELECT OP.TipDoc,OP.OrdPago,OP.IdCia,OP.Fecha,OP.IdConcepto,OP.Modalidad,OP.Anulado,OP.Observacion,O.TipMuc,O.Manifiesto,O.IdCiaMuc
,O.IdVehiculo,O.IdConductor,O.IdPropietario,O.IdPoseedor,O.VrTotalFletes,O.VrDescuento,O.VrRetencion,O.VrReteIca,O.VrAnticipos,O.VrFaltantes,O.VrSeguros,O.VrFondos,O.VrAportes,O.VrReteCREE
,O.VrOtrosDctos,O.VrImpuestos,O.VrEstampilla,O.VrOtrosPagos,O.VrNeto,O.TarifaTabla,O.TarifaFlete,O.UnidTarifa,O.PesoTotal,O.Unidades,O.Volumen,O.PesoOrigen,O.UnidOrigen,O.VolOrigen,O.PesoDestino,O.UnidDestino,O.VolDestino
,O.BaseRet,O.BaseIca,O.BaseSeg,O.BaseImp,O.TarifaRet,O.TarifaIca,O.TarifaSeg,O.TarifaImp,O.VrConcPagos,O.VrConcDctos,O.VrConcFondo,O.VrConcSeguro,O.VrConcAporte,O.VrConcImpuesto,O.VrImpAvTa
,O.TipoLiq,O.TipEgr,O.Egreso,O.IdCiaEgr,O.FechaEgr,O.NumCheque,O.Referencia,O.CdCenCosto,O.CdSubCenCos,O.EdoLiqCausac
,M.Fecha AS FecManif,M.FecDespacho,M.IdOrigen,M.IdDestino,M.IdRuta,M.nRemolque,M.TipoAfiVehic,M.Remesa,M.IdCiaRem,M.Cumplido,M.IdCiaCump,M.FechaCump,M.EstCumplido
 FROM Trn_TraOrdenPago AS OP INNER JOIN Trn_TraOrdenManif AS O ON OP.TipDoc=O.TipDoc AND OP.OrdPago=O.OrdPago AND OP.IdCia=O.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 --Datos de Liq. ordenes de servico
 UNION ALL SELECT L.TipDoc,L.Liquidacion,L.IdCia,L.Fecha,L.IdConcepto,O.Modalidad,L.Anulado,L.Observacion,L.TipOds,L.NumOrden,L.IdCiaOds
,L.IdVehiculo,L.IdConductor,L.IdPoseedor,L.IdPoseedor,L.VrTotal,0,L.VrRetencion,L.VrReteIca,L.VrAnticipo,0,0,0,0,L.VrReteCREE,L.VrDescuento,L.VrIva,0,L.VrOtros,L.VrNeto,L.TarifaPago,L.TarifaPago,'UNIDAD',0,L.Cantidad,0,0,0,0,0,0,0,L.BaseRet,L.BaseIca,0,L.BaseImp
,L.TarifaRet,L.TarifaIca,0,L.TarifaImp,L.VrConcCargos,L.VrConcDed,0,0,0,0,0,0,L.TipEgr,L.Egreso,L.IdCiaEgr,Null,L.NumCheque,L.Referencia,L.CdCCosto,L.CdSubCos,0,O.Fecha,O.FecDespacho,O.IdOrigen,O.IdDestino,O.CdRuta,O.nRemolque,O.TipoAfiVehic,O.NumRemesa
,O.CdCiaRem,O.NumCump,O.CdCiaCum,Null,O.EstCumplido
 FROM Trn_TraOrdenLiq AS L INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia WHERE L.TipDoc='OPT') AS OP ON LP.TipOdp=OP.TipDoc AND LP.OrdPago=OP.OrdPago AND LP.IdCiaOdp=OP.IdCia
--* Fin consulta liquidaciones
 INNER JOIN Vehiculos AS V ON OP.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Terceros AS CDT ON OP.IdConductor=CDT.IdTercero
 INNER JOIN Companias AS COP ON LP.IdCiaOdp=COP.IdCia
 INNER JOIN Localidades AS CO ON OP.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON OP.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON OP.IdRuta=R.IdRuta
 LEFT JOIN Terceros AS NE ON V.NitEmpresa=NE.IdTercero LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 LEFT JOIN (SELECT TipDoc,Documento,IdCiaDoc,SUM(VrAbonado) AS TotAbonado FROM Trn_ComFactura WHERE (TipFac='ODP' OR TipFac='OPT') AND (TipDoc='ODP' OR TipDoc='OPT') GROUP BY TipDoc,Documento,IdCiaDoc)
 AS ABO ON LP.TipOdp=ABO.TipDoc AND LP.OrdPago=ABO.Documento AND LP.IdCiaOdp=ABO.IdCiaDoc
 --fondos-conceptos
 LEFT JOIN (SELECT TipDoc,Documento,IdCia,SUM(CASE WHEN Concepto='FLE' AND Factura='FGI' THEN Valor ELSE 0 END ) AS VrFgi,MAX(CASE WHEN Concepto='FLE' AND Factura='FGI' THEN Vrtarifa ELSE 0 END ) as VrTarFGi,MAX(CASE WHEN Concepto='FLE' AND Factura='FGI' THEN VrBase ELSE 0 END ) as VrBaseFgi
 ,SUM(CASE WHEN Concepto='FLE' AND Factura='FAM' THEN Valor ELSE 0 END ) AS VrFam,MAX(CASE WHEN Concepto='FLE' AND Factura='FAM' THEN Vrtarifa ELSE 0 END ) as VrTarFam,MAX(CASE WHEN Concepto='FLE' AND Factura='FAM' THEN VrBase ELSE 0 END ) as VrBaseFam,
 SUM(CASE WHEN Concepto='FLE' AND Factura='FSC' THEN Valor ELSE 0 END ) AS VrFsc, MAX(CASE WHEN Concepto='FLE' AND Factura='FSC' THEN Vrtarifa ELSE 0 END ) as VrTarFsc,MAX(CASE WHEN Concepto='FLE' AND Factura='FSC' THEN VrBase ELSE 0 END ) as VrBaseFsc
,SUM(CASE WHEN Concepto='OTR' AND Factura='APOS' THEN Valor ELSE 0 END) AS VrApos,MAX(CASE WHEN Concepto='OTR' AND Factura='APOS' THEN Vrtarifa ELSE 0 END ) as VrTarApos,MAX(CASE WHEN Concepto='OTR' AND Factura='APOS' THEN VrBase ELSE 0 END ) as VrBaseApos
 FROM Trn_DetCuentas WHERE (TipDoc='ODP' OR TipDoc='OPT') GROUP BY TipDoc,Documento,IdCia) AS FCN ON LP.TipOdp=FCN.TipDoc AND LP.OrdPago=FCN.Documento AND LP.IdCiaOdp=FCN.IdCia
 LEFT JOIN TercProvee TPV ON LQ.IdPoseedor=TPV.IdProv  LEFT JOIN ClaseCta CTA ON TPV.IdClase=CTA.IdClase 
 LEFT JOIN Bancos BA ON TPV.IdBanco=BA.IdBanco 
 WHERE LQ.TipDoc=@pmTipDoc AND LQ.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND LQ.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquidaLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT  Liquidacion,L.IdCia AS CdCia,Compania,Fecha,L.IdConcepto AS CdConcepto,Concepto,IdVehiculo,IdPoseedor,T.RazonSocial AS Poseedor,IdConductor,CDT.RazonSocial AS Conductor
,VrTotal,CxPagar,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,L.Observacion AS Observ,L.IdEstado AS CdEstado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,ModLiquida
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,L.IdUsuario AS Cdusuario,Usuario
 FROM Trn_TraLiquida AS L  INNER JOIN Terceros AS T ON L.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON  L.IdConductor=CDT.IdTercero
 INNER JOIN Conceptos AS C ON L.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON L.IdCia=CI.IdCia
 WHERE TipDoc=@pmTipDoc  AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND L.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND L.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY L.IdCia,Liquidacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaOtrFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquidaOtrFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc AS TipoLiq,O.Liquidacion,O.IdCia AS CdCia,Compania,O.Item AS nItem,TipCau,O.Causacion AS NumCausac,IdCiaCau,ItemCau
,D.TipFac,O.Factura,O.ItemFac,O.IdProveedor AS NitPropietario,RazonSocial,O.pVehiculo,D.IdConcepto AS CdConcepto,D.Descripcion
,D.VrDebito,D.VrCredito,O.VrAbono,D.CdCuenta,D.Referencia,D.TipDocRef,D.DocRef,D.FecVence,D.VrBase,D.TarifBase,D.EstadoReg
,F.FecEmision,F.FecVence AS FacFecVence,F.VrFactura,F.VrAbonado AS TotalAbonado,F.Referencia AS FacReferencia,F.Detalle
 FROM Trn_TraLiquidaOtr AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Terceros AS T ON O.IdProveedor=T.IdTercero
 LEFT JOIN Trn_TraCauDetalle AS D ON O.TipCau=D.TipDoc AND O.Causacion=D.Causacion AND O.IdCiaCau=D.IdCia AND O.ItemCau=D.Item
 LEFT JOIN Trn_ComFactura AS F ON O.TipCau=F.TipFac AND O.Factura=F.Factura AND O.IdCiaCau=F.IdCia AND O.ItemFac=F.Item AND O.IdProveedor=F.IdProveedor
 WHERE O.TipDoc=@pmTipDoc AND O.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquidaRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT LQ.TipDoc AS TipLiq,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,Compania,Fecha,LQ.IdConcepto AS CdConcepto,Concepto,LQ.IdVehiculo AS PlacaVeh
,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,LQ.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,VrTotal,CxPagar,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,Estado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,ModLiquida,TimeSys,LQ.FecUpdate AS FechaAct,IdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario
,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,D.IdConcepto AS CdConcCausac,D.Descripcion AS DetDescripcion,VrAbono,NitPoseedor,N.RazonSocial AS NomPoseedor,pVehiculo,EsVence
,TipOdp,OrdenPago,IdCiaOdp,TipMuc,Manifiesto,IdCiaMuc,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CCosto,CdSubCos,SubCosto
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraLiquida AS LQ INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia 
 INNER JOIN EstadoDoc AS ED ON LQ.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario 
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON LQ.IdConductor=CDT.IdTercero  INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON LQ.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraLiquidaDed AS D ON LQ.TipDoc=D.TipDoc  AND LQ.Liquidacion=D.Liquidacion AND LQ.IdCia=D.IdCia
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 LEFT JOIN Terceros AS N ON  D.NitPoseedor=N.IdTercero  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero 
 LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 WHERE LQ.TipDoc=@pmTipDoc AND  LQ.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND LQ.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND LQ.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND LQ.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND LQ.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND LQ.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 ORDER BY LQ.IdCia,LQ.Liquidacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiquidaRelo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiquidaRelo] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
AS 
 SELECT LQ.TipDoc AS TipLiq,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,CN.Compania AS NomCompania,LQ.Fecha AS FechaLiq,LQ.IdConcepto AS CdConcepto,Concepto,LQ.IdVehiculo AS PlacaVeh
,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,LQ.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,VrTotal,LQ.CxPagar AS CuePagar,LQ.TipCom AS CdTipCom,TipoCom,LQ.Comprobante AS NumComprob,LQ.IdCiaCom AS CdCiaCom
,LQ.Anulado AS Anuldo,LQ.NumDev AS NumDevoluc,LQ.FecDev AS FechaDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,Estado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,ModLiquida,LQ.TimeSys AS FechaCrea,LQ.FecUpdate AS FechaAct,LQ.IdCiaCrea AS CdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario
--datos de la orden
,LP.TipOdp AS TipOrden,LP.OrdPago AS NumOrden,LP.IdCiaOdp AS CdCiaOdp,COP.Compania AS NomCiaOrden,OP.Fecha AS FechaOdp,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif,VrTotalFletes,O.VrDescuento AS Vr_Dcto
,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto AS Vr_Neto,VrAbonado,TotAbonado,TarifaTabla
,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp
,NumCheque,O.Referencia AS Referncia,EdoLiqCausac,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,nRemolque
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraLiquida AS LQ INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia 
 INNER JOIN EstadoDoc AS ED ON LQ.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario 
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto
 INNER JOIN Terceros AS  CDT ON LQ.IdConductor=CDT.IdTercero INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON LQ.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraLiquidaOdp AS LP ON LQ.TipDoc=LP.TipDoc AND LQ.Liquidacion=LP.Liquidacion AND LQ.IdCia=LP.IdCia
 INNER JOIN Trn_TraOrdenPago AS OP ON LP.TipOdp=OP.TipDoc AND LP.OrdPago=OP.OrdPago AND LP.IdCiaOdp=OP.IdCia
 INNER JOIN Trn_TraOrdenManif AS O ON LP.TipOdp=O.TipDoc AND LP.OrdPago=O.OrdPago AND LP.IdCiaOdp=O.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Companias AS COP ON LP.IdCiaOdp=COP.IdCia
 INNER JOIN Localidades AS CO ON M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 LEFT JOIN (SELECT TipDoc,Documento,IdCiaDoc,SUM(VrAbonado) AS TotAbonado FROM Trn_ComFactura WHERE TipFac='ODP' AND TipDoc='ODP' GROUP BY TipDoc,Documento,IdCiaDoc)
 AS ABO ON LP.TipOdp=ABO.TipDoc AND LP.OrdPago=ABO.Documento AND LP.IdCiaOdp=ABO.IdCiaDoc
 WHERE LQ.TipDoc=@pmTipDoc AND LQ.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND LQ.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND LQ.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND LQ.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND LQ.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND LQ.IdConductor LIKE ISNULL(@pmIdConductor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor
,NitEmpresa,VrAnticipos,VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen,IdRuta,IdLocOrigen,IdLocDestino,Referencia,DescMcias,kmtInicial,kmtFinal
,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,LiqMixto,Num_Ppto,VrGuiasCe,VrGuiasSeg,VrGuiasOtr
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraLiqViajes
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajesFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT LQ.TipDoc AS TipoLiq,TipoDoc,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,Compania,Fecha,LQ.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc
,LQ.IdVehiculo AS PlacaVeh,LQ.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,LQ.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,LQ.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,VrAnticipos,LQ.VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen
,LQ.IdRuta AS CdRuta,Ruta,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,Referencia,DescMcias,LiqMixto,Num_Ppto,kmtInicial,kmtFinal,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,VrGuiasCe,VrGuiasSeg,VrGuiasOtr,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,Estado,TimeSys,LQ.FecUpdate AS FechaAct,IdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario,Leyenda
,Item,D.IdConcepto AS DetCodConc,CG.Concepto AS DetNomConc,DescConcepto,D.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito,D.IdTercero AS NitTercero,N.RazonSocial AS NomTercero
,CdCCosto,CCosto,CdSubCos,SubCosto,D.RubroConc,VrBase,TarifBase,CantComb,TipFac,Factura,IdCiaFac,ItemFac,FecVence,RefConcep,D.TipSop,D.NumSoporte,D.IdCiaSop
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraLiqViajes AS LQ INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON LQ.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON LQ.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto
 INNER JOIN Localidades AS CO ON  LQ.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON LQ.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON LQ.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON LQ.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON LQ.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON LQ.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS ETR ON LQ.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN Trn_TraLiqDetalle AS D ON LQ.TipDoc=D.TipDoc AND LQ.Liquidacion=D.Liquidacion AND LQ.IdCia=D.IdCia
 LEFT JOIN ConcDiversos AS CG ON D.IdConcepto=CG.IdConcepto LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS N ON  D.IdTercero=N.IdTercero
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 WHERE LQ.TipDoc=@pmTipDoc AND LQ.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND LQ.IdCia=@pmIdCia
 ORDER BY LQ.Liquidacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajesLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT  Liquidacion,L.IdCia AS CdCia,Compania,Fecha,L.IdConcepto AS CdConcepto,Concepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc,IdVehiculo,IdConductor,CDT.RazonSocial AS Conductor
,IdPropietario,TP.RazonSocial AS Propietario,IdPoseedor,T.RazonSocial AS Poseedor,NitEmpresa,NE.RazonSocial AS NomEmpresa,VrAnticipos,L.VrGastos,VrCombustible,VrOtrosCred,VrDiferencia
,galsComb,PesoTotal,Cantidad,Volumen,IdRuta,IdLocOrigen,LO.Localidad AS CiudadOrigen,IdLocDestino,LD.Localidad AS CiudadDestino,Referencia,DescMcias,LiqMixto,kmtInicial,kmtFinal
,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,Num_Ppto,VrGuiasCe,VrGuiasSeg,VrGuiasOtr,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,L.Observacion AS Observ,L.IdEstado AS CdEstado
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,L.IdUsuario AS Cdusuario,Usuario
 FROM Trn_TraLiqViajes AS L INNER JOIN Terceros AS T ON L.IdPoseedor=T.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Terceros AS TP ON L.IdPropietario=TP.IdTercero 
 INNER JOIN Conceptos AS C ON L.IdConcepto=C.IdConcepto  INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS CI ON L.IdCia=CI.IdCia LEFT JOIN Terceros AS NE ON L.NitEmpresa=NE.IdTercero 
 LEFT JOIN Localidades AS LO ON L.IdLocOrigen=LO.IdLocal LEFT JOIN Localidades AS LD ON L.IdLocDestino=LD.IdLocal
 WHERE TipDoc=@pmTipDoc   AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND L.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND L.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
  AND L.IdConductor LIKE ISNULL(@pmIdConductor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajesRel] @pmTipDoc VARCHAR(3),@pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT LQ.TipDoc AS TipoLiq,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,Compania,Fecha,LQ.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc
,LQ.IdVehiculo AS PlacaVeh,LQ.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,LQ.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,LQ.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,VrAnticipos,LQ.VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen
,LQ.IdRuta AS CdRuta,Ruta,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,Referencia,DescMcias,LiqMixto,kmtInicial,kmtFinal,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,Num_Ppto,VrGuiasCe,VrGuiasSeg,VrGuiasOtr,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,TimeSys,LQ.FecUpdate AS FechaAct,IdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
 FROM Trn_TraLiqViajes AS LQ INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto
 INNER JOIN Localidades AS CO ON  LQ.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON LQ.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON LQ.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON LQ.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON LQ.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON LQ.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS ETR ON LQ.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 WHERE LQ.TipDoc=@pmTipDoc  AND LQ.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND LQ.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND LQ.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND LQ.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND LQ.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND LQ.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY LQ.IdCia,LQ.Liquidacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraLiqViajesRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraLiqViajesRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni  SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT LQ.TipDoc AS TipoLiq,LQ.Liquidacion AS NumLiquida,LQ.IdCia AS CdCia,Compania,Fecha,LQ.IdConcepto AS CdConcepto,C.Concepto AS DescConcepto,Modalidad,TipMuc,Manifiesto,IdCiaMuc,FechaMuc
,LQ.IdVehiculo AS PlacaVeh,LQ.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,LQ.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,LQ.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,LQ.NitEmpresa AS Nit_Empresa,ETR.RazonSocial AS NomEmpresa,VrAnticipos,LQ.VrGastos,VrCombustible,VrOtrosCred,VrDiferencia,galsComb,PesoTotal,Cantidad,Volumen
,LQ.IdRuta AS CdRuta,Ruta,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,Referencia,DescMcias,LiqMixto,kmtInicial,kmtFinal,EstFactura,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,Num_Ppto,VrGuiasCe,VrGuiasSeg,VrGuiasOtr,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,NumDev,FecDev,LQ.Observacion AS Observ,LQ.IdEstado AS CdEstado,TimeSys,LQ.FecUpdate AS FechaAct,IdCiaCrea,LQ.IdUsuario AS CdUsuario,Usuario
--detalles
,Item,D.IdConcepto AS DetCodConc,CG.Concepto AS DetNomConc,DescConcepto,D.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito,D.IdTercero AS NitTercero,N.RazonSocial AS NomTercero
,CdCCosto,CCosto,CdSubCos,SubCosto,D.RubroConc,VrBase,TarifBase,CantComb,TipFac,Factura,IdCiaFac,ItemFac,FecVence,RefConcep
--datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,V.NitEmpresa AS VehNitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupo,GrupoProp
 FROM Trn_TraLiqViajes AS LQ INNER JOIN Companias AS CN ON LQ.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON LQ.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON LQ.IdConcepto=C.IdConcepto
 INNER JOIN Localidades AS CO ON  LQ.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON LQ.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON LQ.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON LQ.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON LQ.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON LQ.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON LQ.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS ETR ON LQ.NitEmpresa=ETR.IdTercero LEFT JOIN TiposCom AS TCM ON LQ.TipCom=TCM.IdCom 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN Trn_TraLiqDetalle AS D ON LQ.TipDoc=D.TipDoc AND LQ.Liquidacion=D.Liquidacion AND LQ.IdCia=D.IdCia
 LEFT JOIN ConcDiversos AS CG ON D.IdConcepto=CG.IdConcepto LEFT JOIN Puc AS P ON D.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS N ON  D.IdTercero=N.IdTercero LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN CentroCosto AS CC ON D.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON D.CdSubCos=SC.IdSubCos 
 WHERE LQ.TipDoc=@pmTipDoc  AND LQ.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND LQ.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND LQ.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND LQ.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND LQ.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND LQ.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifAnexo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifAnexo] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Manifiesto,IdCia,kmsTotal,VrFleteTon,TipoRuta,CdLocTrao,CdLocTrad,KmsTraOri,KmsTraDes,IdMneda,VrTasa
,NomRemite,NomDestino,LugarFletes,NumAnticipo,NumCheque,TipoMintrans,MucMintrans,ContIntegral,VolumenCarga
,NumPoliza,CdBodDtno,TipoTrslado,MvoAnulacion,MvoSuspension,WsSeguro,NumRadSeguro,PuntosRuta,CantViajes,Transbordo,NumMucAnu,CiaMucAnu,AceptaFirma,TipoValPacto
,MunOrigVacio1,MunDestVacio1,MunOrigVacio2,MunDestVacio2
 FROM Trn_TraManifAnexo
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiesto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifiesto] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Manifiesto,IdCia,Fecha,FecDespacho,FecEntrega,IdOrigen,IdDestino,IdRuta,IdRutaFle,IdVehiculo,IdConductor,nRemolque,TipoAfiVehic,IdPropietario,IdPoseedor
,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,Cantidad,PesoTotal,BaseRet,TarifaRet,TarifaIca,CodTarRet
,CodTarIca,IdLocFletes,FechaPago,PagoCargue,PagoDescargue,NumMintrans,EdoMintrans,Remesa,IdCiaRem,Cumplido,IdCiaCump,FechaCump,EstCumplido
,TipOdp,OrdPago,IdCiaOdp,FechaOdp,EstOrden,VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,VrTrayVacio1,VrTrayVacio2,OrigenAdd,Anulado,FecDev,CdCondRelev
,Observacion,IdEstado,TipCom,Comprobante,IdCiaCom,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraManifiesto
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoDet] @pmTipDoc VARCHAR(3),@pmManifiestoIni INT,@pmManifiestoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc AS CdTipMuc,M.Manifiesto AS NumManif,M.IdCia AS CdCia,M.Fecha AS FechaMuc,M.FecDespacho,M.IdRuta AS CdRuta,RT.Ruta AS DescRuta
,M.IdVehiculo AS PlacaVeh,M.nRemolque,M.TipoAfiVehic,M.EstCumplido,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,M.Anulado,M.FecDev,M.Observacion AS Observ
,M.VrFletes,VrRetencion,VrReteIca,VrAnticipo,VrAntAdic,VrNeto,TarifaFlete
,MR.Item AS ItemMuc,TipRem,MR.Remesa AS NumRemesa,MR.IdCiaRem AS CdCiaRem,ItemRem,D.IdMercancia AS CdMercancia,DescripMcias,CodigoMcia,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol
,Cases,Cajas,Palets,NitRemite,Remitente,DirOrigen,D.IdOrigen AS RemCodOrigen,LO.Localidad AS RemCiudadOrigen,LO.IdDep AS RemCdepOrigen,DOR.Departamento AS RemDptoOrigen,NitDestntario,Destinatario,DirDestino
,D.IdDestino AS RemCodDestino,LD.Localidad AS RemCiudadDestino,LD.IdDep AS RemCdepDestino,DDN.Departamento AS RemDptoDestino,TarifClie,MR.TarifTabla AS TarifaTabla,MR.TarifPago AS TarifaPago,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro
,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,D.CdAgencia AS DetCdAgencia,DA.Agencia AS DetAgencia
,D.Cumplido AS RemCumplido,D.IdCiaCump AS RemCiaCump,D.FechaCump AS RemFechaCum,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,D.TipOdp AS RemTipoOdp,D.NumeroOdp AS RemNumOdp,D.IdCiaOdp AS RemCiaOdp,TarifOdp,PesoCont,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida
,IdCliente,CL.RazonSocial AS RemNomCliente,R.IdClieFact AS RemIdPropMcia,PM.RazonSocial AS RemPropMcia
 FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND M.Manifiesto=MA.Manifiesto AND M.IdCia=MA.IdCia
 INNER JOIN Trn_TraManifRem AS MR ON M.TipDoc=MR.TipDoc AND M.Manifiesto=MR.Manifiesto AND M.IdCia=MR.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON MR.TipRem=D.TipDoc  AND MR.Remesa=D.NumOrden AND MR.IdCiaRem=D.IdCia AND MR.ItemRem=D.Item
 INNER JOIN Trn_TraRemesa AS R ON MR.TipRem=R.TipDoc AND MR.Remesa=R.NumOrden AND MR.IdCiaRem=R.IdCia
 INNER JOIN Rutas AS RT ON M.IdRuta=RT.IdRuta 
 INNER JOIN Mercancias AS MCA ON D.IdMercancia=MCA.IdMercancia
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DOR ON LO.IdDep=DOR.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DDN ON LD.IdDep=DDN.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo 
 INNER JOIN Terceros AS CL ON R.IdCliente=CL.IdTercero LEFT JOIN Terceros AS PM ON R.IdClieFact=PM.IdTercero
 LEFT JOIN Agencias AS DA ON D.CdAgencia=DA.IdAgencia LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 WHERE M.TipDoc=@pmTipDoc AND M.Manifiesto BETWEEN @pmManifiestoIni AND @pmManifiestoFin AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoFmt] @pmTipDoc VARCHAR(3),@pmManifiestoIni INT,@pmManifiestoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc AS CdTipDoc,TipoDoc,M.Manifiesto AS NumManif,M.IdCia AS CdCia,CN.Compania AS NomCompania,M.Fecha AS FechaMuc,M.FecDespacho,M.FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,RT.Ruta AS DescRuta,IdRutaFle,RF.Ruta AS RutaFletes
,M.IdVehiculo AS PlacaVeh,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,M.nRemolque,M.TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,M.VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,M.VrPagos,M.VrCargos,M.VrDctos,TarifaFlete,M.Cantidad AS CantTotal,M.PesoTotal,BaseRet,TarifaRet,TarifaIca
,M.IdLocFletes,CF.Localidad AS CiuLugarFletes,FechaPago,PagoCargue,PagoDescargue,NumMintrans,EdoMintrans,M.FechaRegMT,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido,M.EstCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,M.OrigenAdd,M.Anulado,M.FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.TipCom,M.Comprobante,M.IdCiaCom
,M.TimeSys,M.FecUpdate,M.IdCiaCrea,M.IdUsuario AS CdUsuario,Usuario,Leyenda,kmsTotal,VrFleteTon,MA.TipoRuta AS MucTipoRuta,MA.CdLocTrao,CMI.Localidad AS MunIntermedio,MA.CdLocTrad,KmsTraOri,KmsTraDes,MA.IdMneda,MA.VrTasa,MA.NomRemite AS NomRmtente,MA.NomDestino AS NomDestnatario
,MA.LugarFletes AS Lugar_Fletes,NumAnticipo,NumCheque,MA.TipoMintrans AS TipoMucMintrans,MucMintrans,ContIntegral,VolumenCarga,MA.NumPoliza AS NumPolizaMuc,DescFirma,CodEmpresa,TomadorPoliza,PolizaSeguro,NitCiaPoliza,NomCiaPoliza,FecVencePol,MA.MvoAnulacion,MvoSuspension
,PuntosRuta,MA.CantViajes,Transbordo,NumMucAnu,CiaMucAnu,MA.AceptaFirma,MA.TipoValPacto,M.VrTrayVacio1,M.VrTrayVacio2,MA.MunOrigVacio1,MA.MunDestVacio1,MA.MunOrigVacio2,MA.MunDestVacio2
--detalles
,MR.Item AS ItemMuc,TipRem,MR.Remesa AS NumRemesa,MR.IdCiaRem AS CdCiaRem,ItemRem,D.IdMercancia AS CdMercancia,DescripMcias,CodigoMcia,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol
,Cases,Cajas,Palets,NitRemite,Remitente,DirOrigen,D.IdOrigen AS RemCodOrigen,LO.Localidad AS RemCiudadOrigen,LO.IdDep AS RemCdepOrigen,DOR.Departamento AS RemDptoOrigen,NitDestntario,Destinatario,DirDestino
,D.IdDestino AS RemCodDestino,LD.Localidad AS RemCiudadDestino,LD.IdDep AS RemCdepDestino,DDN.Departamento AS RemDptoDestino,TarifClie,MR.TarifTabla AS TarifaTabla,MR.TarifPago AS TarifaPago,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro
,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,D.CdAgencia AS DetCdAgencia,DA.Agencia AS DetAgencia
,D.Cumplido AS RemCumplido,D.IdCiaCump AS RemCiaCump,D.FechaCump AS RemFechaCum,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,D.TipOdp AS RemTipoOdp,D.NumeroOdp AS RemNumOdp,D.IdCiaOdp AS RemCiaOdp,TarifOdp,PesoCont,MR.RemMintrans AS RemMucMintrans,EdoRemMin
,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango,CodBodDtno,TipTraslado,CodigoUN
,HorasCargue,HorasDesc,FecInicioCargue,FecFinCargue,FecIniciodesc,FecFindesc,TiempoCargue,TiempoDesc,FecLlegCargue,FecSalidaCargue,FecLlegdesc,FecSalidadesc
,IdCliente,CL.RazonSocial AS RemNomCliente,R.IdClieFact AS RemIdPropMcia,PM.RazonSocial AS RemPropMcia
--Datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,V.Modelo,V.Config
,V.PesoVacio,V.PesoMax,V.NumMotor,V.SerieChasis,V.NumSerie,V.CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,RQ.PesoKg AS PesoVacioRq
,CT.CertJudicial,CT.FecJudicial,CT.VigJudicial,CT.Licencia,CT.CatLicencia,CT.IdLugar AS CdLugar,EL.LugarLic,CT.FecLicencia,CT.VigLicencia,CDT.Direccion AS CdtDireccion,CDT.Telefono AS CdtTelefono,CDT.TelMovil AS CdtMovil,CDT.e_mail AS CdtEmail
,LC.Localidad AS CdtCiudad,DC.Departamento AS CdtDpto
,CdCondRelev,CRV.RazonSocial AS SegConductor,CTR.CertJudicial  AS CertJudicialRelev,CTR.FecJudicial AS FecJudicialRelev,CTR.VigJudicial AS VigJudicialRelev,CTR.Licencia AS LicenciaRelev,CTR.CatLicencia AS CatLicenciaRelev
,CTR.IdLugar AS CdLugarRelev,ELR.LugarLic AS LugarLicRelev,CTR.FecLicencia AS FecLicenciaRelev,CTR.VigLicencia AS VigLicenciaRelev,CRV.Direccion AS CdtDireccionRelev,CRV.Telefono AS CdtTelefonoRelev,CRV.e_mail AS CdtEmailRelev
,CRV.TelMovil AS CdtMovilRelev,LCR.Localidad AS CdtCiudadRelev, DCR.Departamento AS CdtDptoRelev
 FROM Trn_TraManifiesto AS M INNER JOIN  Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND M.Manifiesto=MA.Manifiesto AND  M.IdCia=MA.IdCia
 INNER JOIN Trn_TraManifRem AS MR ON M.TipDoc=MR.TipDoc AND  M.Manifiesto=MR.Manifiesto AND  M.IdCia=MR.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON MR.TipRem=D.TipDoc  AND MR.Remesa=D.NumOrden AND MR.IdCiaRem=D.IdCia AND MR.ItemRem=D.Item
 INNER JOIN Trn_TraRemesa AS R ON MR.TipRem=R.TipDoc AND MR.Remesa=R.NumOrden AND MR.IdCiaRem=R.IdCia 
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS RT ON M.IdRuta=RT.IdRuta  INNER JOIN Terceros AS CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Mercancias AS MCA ON D.IdMercancia=MCA.IdMercancia
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DOR ON LO.IdDep=DOR.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DDN ON LD.IdDep=DDN.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia 
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS COL ON V.IdColor=COL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Terceros AS CL ON R.IdCliente=CL.IdTercero LEFT JOIN Terceros AS PM ON R.IdClieFact=PM.IdTercero
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON M.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS DA ON D.CdAgencia=DA.IdAgencia  LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango    LEFT JOIN Rutas AS  RF ON M.IdRutaFle=RF.IdRuta
 LEFT JOIN Polizas AS PS ON MA.NumPoliza=PS.NumPoliza
 LEFT JOIN Trn_TraRemAnexo AS RA ON MR.TipRem=RA.TipDoc AND MR.Remesa=RA.NumOrden AND MR.IdCiaRem=RA.IdCia
 LEFT JOIN VehRemolq AS RQ ON M.nRemolque=RQ.IdRemque
 LEFT JOIN Terceros AS CRV ON M.CdCondRelev=CRV.IdTercero
 LEFT JOIN Localidades AS LCR ON CRV.IdLocal=LCR.IdLocal LEFT JOIN Departamentos AS DCR ON LCR.IdDep=DCR.IdDep
 LEFT JOIN TercCndtores AS CTR ON M.CdCondRelev=CTR.IdConductor LEFT JOIN ExpLicencias AS ELR ON CTR.IdLugar=ELR.IdLugar
 LEFT JOIN Localidades AS LC ON CDT.IdLocal=LC.IdLocal LEFT JOIN Departamentos AS DC ON LC.IdDep=DC.IdDep
 LEFT JOIN Localidades AS CMI ON MA.CdLocTrao=CMI.IdLocal 
 WHERE M.TipDoc=@pmTipDoc AND M.Manifiesto BETWEEN @pmManifiestoIni AND @pmManifiestoFin AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRuta VARCHAR(4)=Null,@pmIdOrigen VARCHAR(8)=Null,@pmIdDestino VARCHAR(8)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT M.Manifiesto AS NumManif,M.IdCia AS CdCia,Compania,Fecha,FecDespacho,FecEntrega,IdOrigen,LO.Localidad AS CiudadOrigen,IdDestino,LD.Localidad AS CiudadDestino,IdRuta,IdRutaFle,M.IdVehiculo AS PlacaVeh,NumVeh
,M.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,NP.RazonSocial AS Poseedor
,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,Cantidad,PesoTotal,VolumenCarga,BaseRet,TarifaRet,TarifaIca,CodTarRet
,CodTarIca,IdLocFletes,LugarFletes,FechaPago,PagoCargue,PagoDescargue,NomRemite,NomDestino,NumMintrans,EdoMintrans,Remesa,IdCiaRem,Cumplido,IdCiaCump,FechaCump,EstCumplido
,TipOdp,OrdPago,IdCiaOdp,FechaOdp,EstOrden,VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,NumAnticipo,NumCheque,TipoMintrans,TipoRuta,MucMintrans,PuntosRuta,AceptaFirma,A.TipoValPacto,CdCondRelev,A.CantViajes,M.VrTrayVacio1,M.VrTrayVacio2
,OrigenAdd,Anulado,FecDev,Transbordo,NumMucAnu,CiaMucAnu,TipCom,Comprobante,IdCiaCom,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS A ON M.TipDoc=A.TipDoc AND M.Manifiesto=A.Manifiesto AND M.IdCia=A.IdCia
 INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo INNER JOIN Companias AS CI ON M.IdCia=CI.IdCia
 INNER JOIN Terceros AS NC ON M.IdConductor=NC.IdTercero  INNER JOIN Terceros AS T ON M.IdPropietario=T.IdTercero
 INNER JOIN Terceros AS NP ON M.IdPoseedor=NP.IdTercero 
 INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 WHERE M.TipDoc=@pmTipDoc AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdRuta LIKE ISNULL(@pmIdRuta,'%')  AND IdOrigen LIKE ISNULL(@pmIdOrigen,'%') AND IdDestino LIKE ISNULL(@pmIdDestino,'%')
 AND M.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY M.IdCia,M.Manifiesto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoNov]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
, @pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
SELECT M.TipDoc AS CdTipDoc,M.Manifiesto AS NumManif,M.IdCia AS CdCia,Compania,Fecha,FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta
,M.IdVehiculo AS PlacaVeh,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos,TarifaFlete,M.Cantidad AS CantTotal,PesoTotal,BaseRet,TarifaRet,TarifaIca
,FechaPago,PagoCargue,PagoDescargue,NumMintrans,EdoMintrans,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido,EstCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,Anulado,FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado
,NomRemite,NomDestino,LugarFletes,NumAnticipo,NumCheque,TipoMintrans,MucMintrans,ContIntegral,VolumenCarga
--Datos de novedades
,C.Item,C.Descripcion AS Descrpcion,Tarifa,TipoConc,RubroConcep,C.Cantidad AS CantConc,VrUnitario,TarifIva,C.IdConcepto AS CdConcepto,Concepto,CdCuenta,NomCuenta
,NitTercero,TC.RazonSocial AS NomTercero,CdTipoEsc,TipoEscolta,C.FechaNov,C.VrBase,C.TipoTarif,C.RefConc,C.Referencia2,C.Referencia3,C.Est_Factura,C.TipFact,C.NumFactura,C.CiaFact,C.VrTotalFact,C.Est_Liquida,C.TipLiq,C.NumLiquida,C.CiaLiq,C.VrTotalLiq
--datos del propietario
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,Modelo,Config,V.Descripcion AS VehDescripcion
 FROM Trn_TraManifiesto AS M INNER JOIN  Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND  M.Manifiesto=MA.Manifiesto AND  M.IdCia=MA.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia  INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca
 INNER JOIN  Trn_TraConceptos AS C ON M.TipDoc=C.TipDoc AND M.Manifiesto=C.Documento AND M.IdCia=C.IdCia
 LEFT JOIN ConcDiversos AS CDV ON C.IdConcepto=CDV.IdConcepto
 LEFT JOIN TiposEsc AS TE ON C.CdTipoEsc=TE.IdTipoEsc LEFT JOIN Terceros AS TC ON C.NitTercero=TC.IdTercero
 LEFT JOIN Puc AS P ON C.CdCuenta=P.IdCuenta
 WHERE M.TipDoc='MUC'  AND  M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoOpe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoOpe] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT RM.TipDoc AS TipMuc,RM.Manifiesto AS NumManif,RM.IdCia AS CdCia,Compania,M.Fecha AS MucFecha,M.FecDespacho AS MucFecDespacho
,M.IdVehiculo AS PlacaVeh,M.TipoAfiVehic AS TipoAfiVeh,M.IdConductor AS CedCondutor,CDT.RazonSocial AS NomConductor,M.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,M.nRemolque AS NumRemolque
,RM.TipRem AS TipRem,RM.Remesa AS NumRemesa,RM.IdCiaRem AS CdCiaRem,R.Fecha AS FechaRem,IdMercancia,DescripMcias,D.Cantidad AS Cant,D.PesoNeto AS PesoNetoRem
,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Volumen AS VolumenRem,UndVol,Cases,Cajas,Palets,D.TarifClie AS TarifaClie,UndTarifa,RM.TarifPago AS TarifaPago,RM.TarifTabla AS TarifaTabla,UndTarifPago
,Remision,DocCliente,Referencia1,Referencia2,Referencia3,D.IdEmp AS CdEmp,Empaque,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida
,D.IdOrigen AS CdCiuOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,D.IdDestino AS CdCiuDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,M.IdRuta AS CdRuta,T.TipoId AS ClieTipId,IdCliente,T.Dv AS ClieDv,T.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,Agencia,R.Modalidad AS TipoRemesa,NitRemite,Remitente,NitDestntario,Destinatario
,M.VrFletes AS MucVrFletes,dbo.FuncMucListaAntcipos(RM.Manifiesto,RM.IdCia) AS Anticipos,M.VrAnticipo+VrAntAdic AS VrAnticipos,M.VrRetencion AS MucVrRetencion,M.VrReteIca AS MucVrReteIca,M.Observacion AS MucObserv,M.Anulado AS MucAnulado,EstOrden
,M.EstCumplido,D.Cumplido,D.IdCiaCump,D.FechaCump,D.CantidadCump,D.PesoCump,D.TarifCump,D.PagoCump
--datos ordenes de pago
,M.TipOdp AS CdTipOdp,M.OrdPago AS NumOrden,M.IdCiaOdp AS MucCiaOdp,M.FechaOdp AS FecOrden,OP.PesoTotal AS OdpPesoNeto,OP.Unidades AS OdpCantidad,OP.Volumen AS OdpVolumen
,OP.TarifaTabla AS OdpTarifTabla,OP.TarifaFlete AS OdpTarifFlete,OP.UnidTarifa AS OdpUndTarifa,OP.VrTotalFletes AS OdpTotalFletes,OP.VrDescuento AS OdpVrDcto,OP.VrRetencion AS OdpVrRetFte
,OP.VrReteIca AS OdpReteIca,OP.VrAnticipos AS OdpAnticipos,OP.VrFaltantes AS OdpFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,OP.VrNeto AS OdpVrNetoPagar,ODP.Observacion AS OdpObserv
--egresos
,OP.TipEgr,Egreso,IdCiaEgr,EG.Fecha AS FecEgreso,EG.NumCheque,TotalEgresos
--datos remesas
,R.NumPedido AS nPedido,IdCiaPed,FechaPed,R.TipDcm AS TipOdc,R.NumDocmto AS nOCargue,R.IdCiaDcm AS CdCiaOdc,R.FechaDcm AS FecOCargue,R.Observacion AS RemObserv
--Datos del vehic/ poseedor
,NP.TipoId AS TercTipId,NP.Dv AS TercDv,NP.NomCial AS TercNomCial,NP.Direccion AS TercDireccion,NP.IdLocal AS TercCodCiudad,L.Localidad AS NomCiudad,NP.Telefono AS TercTelefono,NP.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TPR.VehPropio AS VehEsPropio,TipoAfil,NumSoat,FecSoat,VigSoat
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia,CDT.Direccion AS CdtDireccion,CDT.Telefono AS CdtTelefono,CDT.e_mail AS CdtEmail,CDT.TelMovil AS CdtCelular
 FROM Trn_TraManifRem AS RM INNER JOIN Trn_TraManifiesto AS M ON RM.TipDoc=M.TipDoc AND RM.Manifiesto=M.Manifiesto AND RM.IdCia=M.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON RM.TipRem=D.TipDoc AND RM.Remesa=D.NumOrden AND RM.IdCiaRem=D.IdCia AND RM.ItemRem=D.Item
 INNER JOIN Trn_TraRemesa AS R ON RM.TipRem=R.TipDoc AND RM.Remesa=R.NumOrden AND RM.IdCiaRem=R.IdCia
 INNER JOIN Companias AS CN ON RM.IdCia=CN.IdCia 
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Terceros AS CDT ON M.IdConductor=CDT.IdTercero INNER JOIN Terceros AS NP ON M.IdPoseedor=NP.IdTercero 
 INNER JOIN Localidades AS L ON NP.IdLocal=L.IdLocal 
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor
 INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 LEFT JOIN Trn_TraOrdenPago AS ODP ON M.TipOdp=ODP.TipDoc AND M.OrdPago=ODP.OrdPago AND M.IdCiaOdp=ODP.IdCia
 LEFT JOIN Trn_TraOrdenManif AS OP ON M.TipOdp=OP.TipDoc AND M.OrdPago=OP.OrdPago AND M.IdCiaOdp=OP.IdCia
 LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 LEFT JOIN Empaques AS EQ ON D.IdEmp=EQ.IdEmp
 LEFT JOIN TercCndtores AS CT ON M.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Trn_Comprobantes AS EG ON OP.TipEgr=EG.TipCom AND OP.Egreso=EG.Comprobante AND OP.IdCiaEgr=EG.IdCia
 --total de egresos
 LEFT JOIN (SELECT EO.TipOdp AS TipOrden,EO.OrdPago AS NumOPago,EO.IdCiaOdp AS CdCiaOpago,SUM(VrAbonado) AS TotalEgresos
 FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
 WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EGT ON M.TipOdp=EGT.TipOrden AND M.OrdPago=EGT.NumOPago AND M.IdCiaOdp=EGT.CdCiaOpago
WHERE RM.TipDoc='MUC' AND M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
AND  M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT M.TipDoc AS CdTipDoc,M.Manifiesto AS NumManif,M.IdCia AS CdCia,Compania,M.Fecha,M.FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,IdRutaFle,RF.Ruta AS RutaFletes
,M.IdVehiculo AS PlacaVeh,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,M.VrFletes,M.VrRetencion,M.VrReteIca,M.VrDescuento,M.VrAnticipo,M.VrAntAdic,M.VrNeto,M.VrPagos,M.VrCargos,M.VrDctos,M.TarifaFlete,M.Cantidad AS CantTotal,M.PesoTotal,M.BaseRet,M.TarifaRet,M.TarifaIca
,M.IdLocFletes,CF.Localidad AS LugarFletes,M.FechaPago,M.PagoCargue,M.PagoDescargue,NumMintrans,EdoMintrans,M.Remesa AS NumRemesa,M.IdCiaRem,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido,EstCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,OP.TipEgr,OP.Egreso,OP.IdCiaEgr,OP.NumCheque AS EgrNumCheque,ISNULL(TotalEgresos,0) AS TotalEgresos,M.VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,M.VrTrayVacio1,M.VrTrayVacio2,M.Anulado,M.FecDev
,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.TipCom,M.Comprobante,M.IdCiaCom,TimeSys,FecUpdate,IdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
,kmsTotal,VrFleteTon,TipoRuta,CdLocTrao,CdLocTrad,KmsTraOri,KmsTraDes,IdMneda,VrTasa,NomRemite,NomDestino,LugarFletes,NumAnticipo,MA.NumCheque,TipoMintrans,MucMintrans,ContIntegral,PuntosRuta,MA.CantViajes,VolumenCarga,ISNULL(Num_Radica,0) AS NumRadicac,MA.TipoValPacto
,Transbordo,NumMucAnu,CiaMucAnu
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia,V.IdGrupo AS CdGrupoPro,GrupoProp,CdCondRelev,CRV.RazonSocial AS SegConductor
 FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND  M.Manifiesto=MA.Manifiesto AND M.IdCia=MA.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia  INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON M.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Rutas AS  RF ON M.IdRutaFle=RF.IdRuta LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Terceros AS CRV ON M.CdCondRelev=CRV.IdTercero
 LEFT JOIN Trn_TraOrdenManif AS OP ON M.TipOdp=OP.TipDoc AND M.OrdPago=OP.OrdPago AND M.IdCiaOdp=OP.IdCia
 LEFT JOIN (SELECT EO.TipOdp AS TipOrden,EO.OrdPago AS NumOPago,EO.IdCiaOdp AS CdCiaOpago,SUM(VrAbonado) AS TotalEgresos
 FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
 WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EG ON M.TipOdp=EG.TipOrden AND M.OrdPago=EG.NumOPago AND M.IdCiaOdp=EG.CdCiaOpago
 --radicacion de cumplidos
 LEFT JOIN (SELECT TipMuc,Manifiesto,IdCiaMuc,MAX(NumRadica) AS Num_Radica FROM Trn_TraCumRadica GROUP BY TipMuc,Manifiesto,IdCiaMuc) AS RC ON M.TipDoc=RC.TipMuc AND M.Manifiesto=RC.Manifiesto AND M.IdCia=RC.IdCiaMuc
--Condiciones consulta general
 WHERE M.TipDoc=@pmTipDoc AND  M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT M.TipDoc AS CdTipDoc,M.Manifiesto AS NumManif,M.IdCia AS CdCia,Compania,M.Fecha,M.FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,IdRutaFle,RF.Ruta AS RutaFletes
,M.IdVehiculo AS PlacaVeh,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,M.VrFletes,M.VrRetencion,M.VrReteIca,M.VrDescuento,M.VrAnticipo,M.VrAntAdic,M.VrNeto,M.VrPagos,M.VrCargos,M.VrDctos,M.TarifaFlete,M.Cantidad AS CantTotal,M.PesoTotal,M.BaseRet,M.TarifaRet,M.TarifaIca
,M.IdLocFletes,CF.Localidad AS LugarFletes,M.FechaPago,M.PagoCargue,M.PagoDescargue,NumMintrans,EdoMintrans,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido,EstCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,M.FechaOdp,M.EstOrden,OP.TipEgr,OP.Egreso,OP.IdCiaEgr,OP.NumCheque AS EgrNumCheque,ISNULL(TotalEgresos,0) AS TotalEgresos
,M.VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,M.VrTrayVacio1,M.VrTrayVacio2,M.Anulado,M.FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.TipCom,M.Comprobante,M.IdCiaCom,M.TimeSys,M.FecUpdate,M.IdCiaCrea
,M.IdUsuario AS CdUsuario,Usuario,kmsTotal,VrFleteTon,TipoRuta,CdLocTrao,CdLocTrad,KmsTraOri,KmsTraDes,IdMneda,VrTasa,NomRemite,NomDestino,LugarFletes,NumAnticipo,MA.NumCheque,TipoMintrans,MucMintrans,ContIntegral,PuntosRuta,VolumenCarga
,CdCondRelev,CRV.RazonSocial AS SegConductor,ISNULL(Num_Radica,0) AS NumRadicac,MA.TipoValPacto,Transbordo,NumMucAnu,CiaMucAnu
--detalles
,MR.Item AS ItemMuc,TipRem,MR.Remesa AS NumRemesa,MR.IdCiaRem AS CdCiaRem,ItemRem,D.IdMercancia AS CdMercancia,DescripMcias,CodigoMcia,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,dmsAlto,dmsAncho,dmsLargo,D.Volumen,UndVol
,D.Cases,D.Cajas,D.Palets,D.NitRemite,Remitente,DirOrigen,D.IdOrigen AS CodCiuOrigen,LO.Localidad AS CiudadOrigen,NitDestntario,Destinatario,DirDestino,D.IdDestino AS CodCiuDestino,LD.Localidad AS CiudadDestino,TarifClie,MR.TarifTabla AS TarifaTabla,MR.TarifPago AS TarifaPago
,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Contenedor1,Contenedor2,D.CdAgencia AS DetCdAgencia,D.Cumplido AS NumCumplidoRem,D.IdCiaCump AS CdCiaCumpRem
,D.FechaCump AS FecCumRem,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,D.TipOdp AS DetTipOdp,D.NumeroOdp AS NumOdp,D.IdCiaOdp AS CdCiaOdp,TarifOdp,PesoCont,RemMintrans,EdoRemMin
,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia,V.IdGrupo AS CdGrupoPro,GrupoProp
 FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND  M.Manifiesto=MA.Manifiesto AND  M.IdCia=MA.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia  INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraManifRem AS MR ON M.TipDoc=MR.TipDoc AND  M.Manifiesto=MR.Manifiesto AND  M.IdCia=MR.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON MR.TipRem=D.TipDoc  AND MR.Remesa=D.NumOrden AND MR.IdCiaRem=D.IdCia AND MR.ItemRem=D.Item
 INNER JOIN Mercancias AS MCA ON D.IdMercancia=MCA.IdMercancia
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal   INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON M.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Rutas AS  RF ON M.IdRutaFle=RF.IdRuta  LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango  LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Trn_TraOrdenManif AS OP ON M.TipOdp=OP.TipDoc AND M.OrdPago=OP.OrdPago AND M.IdCiaOdp=OP.IdCia
 LEFT JOIN Terceros AS CRV ON M.CdCondRelev=CRV.IdTercero
 LEFT JOIN (SELECT EO.TipOdp AS TipOrden,EO.OrdPago AS NumOPago,EO.IdCiaOdp AS CdCiaOpago,SUM(VrAbonado) AS TotalEgresos
 FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
 WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EG ON M.TipOdp=EG.TipOrden AND M.OrdPago=EG.NumOPago AND M.IdCiaOdp=EG.CdCiaOpago
 --radicacion de cumplidos
 LEFT JOIN (SELECT TipMuc,Manifiesto,IdCiaMuc,MAX(NumRadica) AS Num_Radica FROM Trn_TraCumRadica GROUP BY TipMuc,Manifiesto,IdCiaMuc) AS RC ON M.TipDoc=RC.TipMuc AND M.Manifiesto=RC.Manifiesto AND M.IdCia=RC.IdCiaMuc
--Condiciones consulta general
 WHERE M.TipDoc=@pmTipDoc AND  M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 ORDER BY M.IdCia,M.Manifiesto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRelPrec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoRelPrec] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdRuta VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 SELECT M.TipDoc AS CdTipDoc,M.Manifiesto AS NumManif,M.IdCia AS CdCia,Compania,M.Fecha,M.FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,IdRutaFle,RF.Ruta AS RutaFletes
,M.IdVehiculo AS PlacaVeh,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,M.VrFletes,M.VrRetencion,M.VrReteIca,M.VrDescuento,M.VrAnticipo,M.VrAntAdic,M.VrNeto,M.VrPagos,M.VrCargos,M.VrDctos,M.TarifaFlete,M.Cantidad AS CantTotal,M.PesoTotal,M.BaseRet,M.TarifaRet,M.TarifaIca
,M.IdLocFletes,CF.Localidad AS LugarFletes,M.FechaPago,M.PagoCargue,M.PagoDescargue,NumMintrans,EdoMintrans,M.Remesa AS NumRemesa,M.IdCiaRem,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump,M.FechaCump AS FecCumplido,EstCumplido
,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,OP.TipEgr,OP.Egreso,OP.IdCiaEgr,OP.NumCheque AS EgrNumCheque,ISNULL(TotalEgresos,0) AS TotalEgresos,M.VrFleteNeto,TipInfVia,NumViaje,CiaInfViaje,CdCatPeaje,M.Anulado,M.FecDev
,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.TipCom,M.Comprobante,M.IdCiaCom,TimeSys,FecUpdate,IdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
,kmsTotal,VrFleteTon,TipoRuta,CdLocTrao,CdLocTrad,KmsTraOri,KmsTraDes,IdMneda,VrTasa,NomRemite,NomDestino,LugarFletes,NumAnticipo,MA.NumCheque,TipoMintrans,MucMintrans,ContIntegral,PuntosRuta,MA.CantViajes,VolumenCarga,ISNULL(Num_Radica,0) AS NumRadicac
,Transbordo,NumMucAnu,CiaMucAnu
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia,V.IdGrupo AS CdGrupoPro,GrupoProp,CdCondRelev,CRV.RazonSocial AS SegConductor
-- PRECINTOS
,MP.NumPrecinto, MP.IdTipoPre,MP.ColorPrecinto,MP.Sellos, TP.Precinto
 FROM Trn_TraManifiesto AS M INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND  M.Manifiesto=MA.Manifiesto AND M.IdCia=MA.IdCia
 INNER JOIN Companias AS CN ON M.IdCia=CN.IdCia  INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta  INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero   INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON M.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Rutas AS  RF ON M.IdRutaFle=RF.IdRuta LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Terceros AS CRV ON M.CdCondRelev=CRV.IdTercero
 LEFT JOIN Trn_TraOrdenManif AS OP ON M.TipOdp=OP.TipDoc AND M.OrdPago=OP.OrdPago AND M.IdCiaOdp=OP.IdCia
 LEFT JOIN Trn_TraManifPrec AS MP ON M.TipDoc=MP.TipDoc AND M.Manifiesto=MP.Manifiesto AND M.IdCia=MP.IdCia
 LEFT JOIN TiposPcnto AS TP ON MP.IdTipoPre=TP.IdTipoPre
 LEFT JOIN (SELECT EO.TipOdp AS TipOrden,EO.OrdPago AS NumOPago,EO.IdCiaOdp AS CdCiaOpago,SUM(VrAbonado) AS TotalEgresos
 FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
 WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EG ON M.TipOdp=EG.TipOrden AND M.OrdPago=EG.NumOPago AND M.IdCiaOdp=EG.CdCiaOpago
 --radicacion de cumplidos
 LEFT JOIN (SELECT TipMuc,Manifiesto,IdCiaMuc,MAX(NumRadica) AS Num_Radica FROM Trn_TraCumRadica GROUP BY TipMuc,Manifiesto,IdCiaMuc) AS RC ON M.TipDoc=RC.TipMuc AND M.Manifiesto=RC.Manifiesto AND M.IdCia=RC.IdCiaMuc
--Condiciones consulta general
 WHERE M.TipDoc=@pmTipDoc AND  M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  M.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdRuta LIKE ISNULL(@pmIdRuta,'%') AND M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifiestoRen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifiestoRen]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmNovEstLiq INT=Null,@pmNovEstFact INT=Null
 AS 
SELECT RM.TipDoc AS TipMuc,RM.Manifiesto AS NumManif,RM.IdCia AS CdCia,Compania,M.Fecha AS MucFecha,M.FecDespacho AS MucFecDespacho,RM.TipRem AS TipRem,RM.Remesa AS NumRemesa,RM.IdCiaRem AS CdCiaRem
,RM.ItemRem AS ItemRemsa,R.Fecha AS RemFecha,R.FecDespacho AS RemFecDespacho,IdMercancia,DescripMcias,D.Cantidad AS RemCantidad,D.PesoNeto AS RemPesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Volumen AS RemVolumen,UndVol,Cases,Cajas,Palets
,D.TarifClie AS RemTarifClie,UndTarifa,D.VrDeclarado AS RemVrDeclara,D.VrSeguro AS RemVrSeguro,D.TarifSeguro AS RemTarifSeguro,RM.TarifPago AS MucTarifPago,RM.TarifTabla AS MucTarifTabla,UndTarifPago,D.Cumplido AS NumCumplido,D.IdCiaCump AS CdCiaCump
,D.FechaCump AS FecCumplido,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,UndTarCump,PagoCump,UndTarPagoCump,DetalleCump,D.TarifClieFac AS RemTarifFact,D.TarifOdp AS RemTarifOdp,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,Remision,DocCliente,Referencia1,Referencia2,Referencia3
,NitRemite,Remitente,NitDestntario,Destinatario,D.IdOrigen AS CdCiuOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,D.IdDestino AS CdCiuDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,IdCliente,T.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,Agencia,R.Modalidad AS TipoRemesa,M.IdVehiculo AS PlacaVeh,M.TipoAfiVehic AS TipoAfiVeh,M.IdConductor AS CedCondutor,CDT.RazonSocial AS NomConductor,M.nRemolque AS NumRemolque
,M.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,M.VrFletes AS MucVrFletes,M.VrRetencion AS MucVrRetencion,M.VrReteIca AS MucVrReteIca,M.VrAnticipo+VrAntAdic AS MucAnticipos,M.TarifaRet AS MucTarifRet,M.TarifaIca AS MucTarifIca,M.IdRuta AS CdRuta
,M.TipOdp AS CdTipOdp,M.OrdPago AS MucNumOdp,M.IdCiaOdp AS MucCiaOdp,M.FechaOdp AS FecOrdenPago,EstOrden,M.Observacion AS MucObserv
--datos de orden pago
,OP.PesoTotal AS OdpPesoNeto,OP.Unidades AS OdpCantidad,OP.Volumen AS OdpVolumen,OP.TarifaTabla AS OdpTarifTabla,OP.TarifaFlete AS OdpTarifFlete,OP.UnidTarifa AS OdpUndTarifa,OP.VrTotalFletes AS OdpTotalFletes,OP.VrDescuento AS OdpVrDcto
,OP.VrRetencion AS OdpVrRetFte,OP.VrReteIca AS OdpReteIca,OP.VrAnticipos AS OdpAnticipos,OP.VrFaltantes AS OdpFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla
,VrOtrosPagos,OP.VrNeto AS OdpVrNetoPagar,VrRemesas,VrRecCaja,OP.TarifaRet AS OdpTarifRet,OP.TarifaIca AS OdpTarifIca
,OP.IdPoseedor AS OdpNitPoseedor,ODP.Anulado AS OdpAnulado,ODP.Observacion AS OdpObserv,TipEgr,Egreso,IdCiaEgr,NumCheque,OP.Referencia AS OdpReferencia
,R.NumPedido AS nPedido,IdCiaPed,FechaPed,R.TipDcm AS TipOdc,R.NumDocmto AS nOCargue,R.IdCiaDcm AS CdCiaOdc,R.FechaDcm AS FecOCargue
,R.EstCumplido AS RemEdoCumplido,R.EstFactura AS RemEdoFactura,SerieGuia,NumGuia,R.Observacion AS RemObserv
--columnas de detalles ocultas,TipFac,Factura,IdCiaFac,FechaFac,TipOdp,NumeroOdp,IdCiaOdp,PesoCont
--datos de factura
,D.TipFac AS CdTipFact,Factura,NumFactura,D.IdCiaFac AS CdCiaFact,FechaFac,FacCantidad,FacUnidades,FacPesoNeto,FacVolumen,FacValorTotal,FacCostoTotal,FacFaltantes
,NumDevFactura,DfaCantidad,DfaUnidades,DfaPesoNeto,DfaVolumen,DfaValorTotal,DfaCostoTotal,DfaFaltantes
,NumNotaDb,NumNotaCr,NotCantidad,NotPesoNeto,NotVolumen,NotValorTotal,NotCostoTotal,EGR.FecEgr
,ISNULL(NM.Cargos,0) AS MucNovCargos,ISNULL(NM.Deducciones,0) AS MucNovDeducc,ISNULL(NR.Cargos,0) AS RemNovCargos,ISNULL(NR.Deducciones,0) AS RemNovDeducc
 FROM Trn_TraManifRem AS RM INNER JOIN Trn_TraManifiesto AS M ON RM.TipDoc=M.TipDoc AND RM.Manifiesto=M.Manifiesto AND RM.IdCia=M.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON RM.TipRem=D.TipDoc AND RM.Remesa=D.NumOrden AND RM.IdCiaRem=D.IdCia AND RM.ItemRem=D.Item
 INNER JOIN Trn_TraRemesa AS R ON RM.TipRem=R.TipDoc AND RM.Remesa=R.NumOrden AND RM.IdCiaRem=R.IdCia
 INNER JOIN Companias AS CN ON RM.IdCia=CN.IdCia 
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPoseedor=NP.IdTercero 
 LEFT JOIN Trn_TraOrdenPago AS ODP ON M.TipOdp=ODP.TipDoc AND M.OrdPago=ODP.OrdPago AND M.IdCiaOdp=ODP.IdCia
 LEFT JOIN Trn_TraOrdenManif AS OP ON M.TipOdp=OP.TipDoc AND M.OrdPago=OP.OrdPago AND M.IdCiaOdp=OP.IdCia
 LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
--subconsulta de facturas 
LEFT JOIN (SELECT TipRem,Remesa,IdCiaRem,ItemRem,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Cantidad ELSE 0 END) AS FacCantidad
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Cantidad*VrUnitario ELSE 0 END) AS FacValorTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN CantPago*VrCosto ELSE 0 END) AS FacCostoTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN VrFaltante ELSE 0 END) AS FacFaltantes
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Unidades ELSE 0 END) AS FacUnidades
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN PesoNeto ELSE 0 END) AS FacPesoNeto
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Volumen ELSE 0 END) AS FacVolumen
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Cases ELSE 0 END) AS FacCases
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Cajas ELSE 0 END) AS FacCajas
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Palets ELSE 0 END) AS FacPalets
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cantidad ELSE 0 END) AS DfaCantidad
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cantidad*VrUnitario ELSE 0 END) AS DfaValorTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN CantPago*VrCosto ELSE 0 END) AS DfaCostoTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN VrFaltante ELSE 0 END) AS DfaFaltantes
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Unidades ELSE 0 END) AS DfaUnidades
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN PesoNeto ELSE 0 END) AS DfaPesoNeto
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Volumen ELSE 0 END) AS DfaVolumen
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cases ELSE 0 END) AS DfaCases
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cajas ELSE 0 END) AS DfaCajas
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Palets ELSE 0 END) AS DfaPalets
,SUM(CASE TipDoc WHEN 'NDB' THEN Cantidad WHEN 'NCR' THEN Cantidad*-1 ELSE 0 END) AS NotCantidad
,SUM(CASE TipDoc WHEN 'NDB' THEN Cantidad*VrUnitario WHEN 'NCR' THEN (Cantidad*VrUnitario)*-1 ELSE 0 END) AS NotValorTotal
,SUM(CASE TipDoc WHEN 'NDB' THEN Cantidad*VrCosto WHEN 'NCR' THEN (Cantidad*VrCosto)*-1 ELSE 0 END) AS NotCostoTotal
,SUM(CASE TipDoc WHEN 'NDB' THEN PesoNeto WHEN 'NCR' THEN PesoNeto*-1 ELSE 0 END) AS NotPesoNeto
,SUM(CASE TipDoc WHEN 'NDB' THEN Volumen WHEN 'NCR' THEN Volumen*-1 ELSE 0 END) AS NotVolumen
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='FC' THEN Factura ELSE 0 END) AS NumFactura
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Factura ELSE 0 END) AS NumDevFactura
,MAX(CASE TipDoc WHEN 'NDB' THEN Factura ELSE 0 END) AS NumNotaDb
,MAX(CASE TipDoc WHEN 'NCR' THEN Factura ELSE 0 END) AS NumNotaCr
 FROM Trn_TraFacRemesas GROUP BY TipRem,Remesa,IdCiaRem,ItemRem) AS RF ON RM.TipRem=RF.TipRem AND RM.Remesa=RF.Remesa AND RM.IdCiaRem=RF.IdCiaRem AND RM.ItemRem=RF.ItemRem
LEFT JOIN(select OE.TipOdp ,OE.OrdPago,OE.IdCiaOdp,MAX(E.Fecha)AS FecEgr from Trn_TraEgrOrden  OE inner join Trn_Comprobantes E
ON OE.TipCom =E.TipCom AND OE.NumEgreso =E.Comprobante  AND OE.IdCia=E.IdCia 
group by OE.TipOdp ,OE.OrdPago,OE.IdCiaOdp) AS EGR ON ODP.TipDoc =EGR.TipOdp AND ODP.OrdPago=EGR.OrdPago AND ODP.IdCia =EGR.IdCiaOdp 
--Novedades
LEFT JOIN (SELECT TipDoc,Documento,IdCia,SUM(CASE WHEN (TipoConc='PAGO' OR TipoConc='GASTO') THEN (CASE TipoTarif WHEN '%' THEN (VrBase*Tarifa)/100 ELSE Tarifa END) ELSE 0 END) AS Cargos
,SUM(CASE TipoConc WHEN 'DEDUCCION' THEN (CASE TipoTarif WHEN '%' THEN (VrBase*Tarifa)/100 ELSE Tarifa END) ELSE  0 END) AS Deducciones
FROM Trn_TraConceptos WHERE TipDoc='MUC' AND Est_Liquida>=ISNULL(@pmNovEstLiq,0) GROUP BY TipDoc,Documento,IdCia) AS NM ON M.TipDoc=NM.TipDoc AND M.Manifiesto=NM.Documento AND M.IdCia=NM.IdCia
LEFT JOIN (SELECT TipDoc,Documento,IdCia,SUM(CASE TipoConc WHEN 'CARGO' THEN (CASE TipoTarif WHEN '%' THEN (VrBase*Tarifa)/100 ELSE Tarifa END) ELSE 0 END) AS Cargos
,SUM(CASE TipoConc WHEN 'DEDUCCION' THEN (CASE TipoTarif WHEN '%' THEN (VrBase*Tarifa)/100 ELSE Tarifa END) ELSE  0 END) AS Deducciones
FROM Trn_TraConceptos WHERE TipDoc='RMT' AND Est_Factura>=ISNULL(@pmNovEstFact,0) GROUP BY TipDoc,Documento,IdCia) AS NR ON RM.TipRem=NR.TipDoc AND RM.Remesa=NR.Documento AND RM.IdCiaRem=NR.IdCia
--main query condition
WHERE  RM.TipDoc='MUC' AND M.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND M.Anulado=0 AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
AND  M.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifInt] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Manifiesto,IdCia,Fecha,FecEmision,IdOrigen,IdDestino,IdVehiculo,nRemolque,IdConductor,IdCondRelev,NatCarga,CdAduana,CdAduanaDest,IdMoneda,ValorTotal,PesoTotal,NumMuc,CdCiaMuc,OrigenAdd,Anulado,FecDev,Observacion
,Negociacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraManifInt
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifInt_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifInt_Cr] @pmTipDoc VARCHAR(3),@pmManifiestoIni INT,@pmManifiestoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT M.TipDoc,TipoDoc,M.Manifiesto,M.IdCia AS CdCia,Compania,M.Fecha,M.FecEmision,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,M.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,M.IdDestino,LD.Localidad AS DescDestino
,M.IdVehiculo AS PlacaVeh,M.nRemolque,M.IdConductor AS CdConductor,NC.RazonSocial AS CondTitula,NC.Telefono AS TelCondTitu,NC.TelMovil AS MovCondTitu,M.IdCondRelev,NCA.RazonSocial AS CondAuxiliar,NCA.Telefono AS TelCondAuxiliar,NCA.TelMovil AS MovCondAuxiliar,NatCarga
,M.CdAduana,AF.NomAduana AS AduanaFront,AF.IdPais AS CdPaisAdu,PAF.NombrePais AS PaisAduFront,M.CdAduanaDest,AD.NomAduana AS AduanaDest,AD.IdPais AS CdPaisAduDest,PAD.NombrePais AS PaisAduDestino,M.IdMoneda AS CdMoneda,MN.Simbolo,MN.Mneda AS Moneda
,M.ValorTotal,M.PesoTotal,M.NumMuc,M.CdCiaMuc,M.Anulado,M.FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.Negociacion,M.OrigenAdd,M.TimeSys AS FechaCrea,M.FecUpdate,M.IdCiaCrea AS CdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
--detalles
,D.Item,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MD.Mneda AS DetMoneda,MD.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad
,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,CP.DocRemitente,D.DescripUnid
--datos del vehículo
,V.IdMarca AS CdMarca,MV.Marca,V.Modelo,V.SerieChasis,V.NumSerie,V.IdPoseedor AS CdPoseedor,T.RazonSocial AS Poseedor
,V.NumSoat,VigSoat,TarjProp,VigTProp,RevTecMec,VigTecMec,V.TarjOper,VigTarjOper,V.Ulttramite,V.Descripcion AS VehDescripcion,V.CertMovilizacion,VigCertMovil
,V.CdLugTp,LTP.Localidad AS VehLugarTp,DTP.IdPais AS CdPaisTP,PTP.NombrePais AS PaisLugarTP
,RQ.IdMarca AS CdMarcaRmq,MR.Marca AS MarcaRmq,RQ.Modelo AS ModeloRmq,RQ.NumSerial AS NumSerieRmq,RQ.TarjetaProp,RQ.FecTarjProp,RQ.VigTarjProp
,RQ.CdLocTarj,LPR.Localidad AS RemLugarTp,DPR.IdPais AS RemCdPaisTp,PRP.NombrePais AS RemPaisTP
,NC.IdLugarCed AS CondIdLugar,LC.Localidad AS CondLugarCed,DLC.IdPais AS CdPaisLugar,PLC.NombrePais AS CondPaisLugar
,CDT.TipoSangre,CDT.FactorRh,CDT.Pasporte,CDT.VigPaspte,CDT.Licencia AS NumLicencia,CDT.CatLicencia,CDT.VigLicencia,CDT.NumTarjeta,CDT.VigTarjeta,CDT.PasSeguridad,CDT.VigPasSeg
,NCA.IdLugarCed AS AuxIdLugar,LCA.Localidad AS AuxLugarCed,DLA.IdPais AS AuxCdPais,PLA.NombrePais AS AuxPaisLugar
,CDA.TipoSangre AS AuxTipoSangre,CDA.FactorRh AS AuxFactorRh,CDA.Pasporte AS AuxPasaporte,CDA.VigPaspte AS AuxVigPaspte,CDA.Licencia AS AuxNumLicencia
,CDA.CatLicencia AS AuxCategLic,CDA.VigLicencia AS AuxVigLicencia,CDA.NumTarjeta AS AuxNumTarjeta,CDA.VigTarjeta AS AuxVigTarjeta,CDA.PasSeguridad AS AuxPasSeguridad,CDA.VigPasSeg AS AuxVigPasSeg
 FROM Trn_TraManifInt AS M INNER JOIN Companias AS C ON M.IdCia=C.IdCia INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo
 INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON M.IdEstado=E.IdEstado INNER JOIN Sys_TiposDoc AS TD ON M.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS NC ON M.IdConductor=NC.IdTercero INNER JOIN TercCndtores AS CDT ON M.IdConductor=CDT.IdConductor 
 INNER JOIN Terceros AS T ON V.IdPoseedor=T.IdTercero  INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca
 INNER JOIN Trn_TraManifIntMcia AS D ON M.TipDoc=D.TipDoc AND M.Manifiesto=D.Manifiesto AND M.IdCia=D.IdCia
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MD ON D.IdMoneda=MD.IdMneda
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat 
 LEFT JOIN Trn_TraPorteInt AS CP ON D.TipOrd=CP.TipDoc AND D.NumOrden=CP.NumOrden AND D.IdCiaOrd=CP.IdCia
 LEFT JOIN VehRemolq AS RQ ON M.nRemolque=RQ.IdRemque LEFT JOIN Marcas AS MR ON RQ.IdMarca=MR.IdMarca
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 LEFT JOIN Terceros AS NCA ON M.IdCondRelev=NCA.IdTercero LEFT JOIN TercCndtores AS CDA ON M.IdCondRelev=CDA.IdConductor
 LEFT JOIN Aduanas AS AF ON M.CdAduana=AF.IdAduana LEFT JOIN Aduanas AS AD ON M.CdAduanaDest=AD.IdAduana
 LEFT JOIN adm_Paises AS PAF ON AF.IdPais=PAF.IdPais LEFT JOIN adm_Paises AS PAD ON AD.IdPais=PAD.IdPais
 LEFT JOIN adm_monedas AS MN ON M.IdMoneda=MN.IdMneda 
 LEFT JOIN Localidades AS LC ON NC.IdLugarCed=LC.IdLocal LEFT JOIN Departamentos AS DLC ON LC.IdDep=DLC.IdDep LEFT JOIN adm_Paises AS PLC ON DLC.IdPais=PLC.IdPais
 LEFT JOIN Localidades AS LCA ON NCA.IdLugarCed=LCA.IdLocal LEFT JOIN Departamentos AS DLA ON LCA.IdDep=DLA.IdDep LEFT JOIN adm_Paises AS PLA ON DLA.IdPais=PLA.IdPais
 LEFT JOIN Localidades AS LTP ON V.CdLugTp=LTP.IdLocal LEFT JOIN Departamentos AS DTP ON LTP.IdDep=DTP.IdDep LEFT JOIN adm_Paises AS PTP ON DTP.IdPais=PTP.IdPais
 LEFT JOIN Localidades AS LPR ON RQ.CdLocTarj=LPR.IdLocal LEFT JOIN Departamentos AS DPR ON LPR.IdDep=DPR.IdDep LEFT JOIN adm_Paises AS PRP ON DPR.IdPais=PRP.IdPais
 WHERE M.TipDoc=@pmTipDoc AND M.Manifiesto BETWEEN @pmManifiestoIni AND @pmManifiestoFin AND M.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifIntCon_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifIntCon_Cr] @pmTipDoc VARCHAR(3),@pmManifiestoIni INT,@pmManifiestoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.TipDoc,C.Manifiesto,C.IdCia AS CdCia,C.Item,C.IdTipoCon,TipoContndor,C.NumCont,C.PesoCont
,C.IdTipoPre,Precinto,C.NumPrecinto,C.ColorPrecinto
FROM Trn_TraManifIntCon AS C INNER JOIN TiposCnd AS TC ON C.IdTipoCon=TC.IdTipoCon
LEFT JOIN TiposPcnto AS P ON C.IdTipoPre=P.IdTipoPre 
WHERE C.TipDoc=@pmTipDoc AND C.Manifiesto BETWEEN @pmManifiestoIni AND @pmManifiestoFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifIntLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifIntLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT M.Manifiesto,M.IdCia AS CdCia,Compania,M.Fecha,M.FecEmision,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,M.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,M.IdDestino,LD.Localidad AS DescDestino
,M.IdVehiculo AS PlacaVeh,M.nRemolque,M.IdConductor AS CdConductor,NC.RazonSocial AS CondTitula,M.IdCondRelev,NCA.RazonSocial AS CondAuxiliar,NatCarga,M.CdAduana,AF.NomAduana AS AduanaFront,M.CdAduanaDest,AD.NomAduana AS AduanaDest
,M.IdMoneda AS CdMoneda,MN.Simbolo,MN.Mneda AS Moneda,M.ValorTotal,M.PesoTotal,M.NumMuc,M.CdCiaMuc,M.Anulado,M.FecDev
,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.Negociacion,M.OrigenAdd,M.TimeSys AS FechaCrea,M.FecUpdate,M.IdCiaCrea AS CdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraManifInt AS M INNER JOIN Companias AS C ON M.IdCia=C.IdCia INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo
 INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN Terceros AS NC ON M.IdConductor=NC.IdTercero
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON M.IdEstado=E.IdEstado
 LEFT JOIN Terceros AS NCA ON M.IdCondRelev=NCA.IdTercero LEFT JOIN Aduanas AS AF ON M.CdAduana=AF.IdAduana LEFT JOIN Aduanas AS AD ON M.CdAduanaDest=AD.IdAduana
 LEFT JOIN adm_monedas AS MN ON M.IdMoneda=MN.IdMneda 
 WHERE M.TipDoc=@pmTipDoc AND M.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifIntLtd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifIntLtd] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT M.Manifiesto,M.IdCia AS CdCia,Compania,M.Fecha,M.FecEmision,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,M.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,M.IdDestino,LD.Localidad AS DescDestino
,M.IdVehiculo AS PlacaVeh,M.nRemolque,M.IdConductor AS CdConductor,NC.RazonSocial AS CondTitula,M.IdCondRelev,NCA.RazonSocial AS CondAuxiliar,NatCarga,M.CdAduana,AF.NomAduana AS AduanaFront,M.CdAduanaDest,AD.NomAduana AS AduanaDest
,M.IdMoneda AS CdMoneda,MN.Simbolo,MN.Mneda AS Moneda,M.ValorTotal,M.PesoTotal,M.NumMuc,M.CdCiaMuc,M.Anulado,M.FecDev
,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado,M.Negociacion,M.OrigenAdd,M.TimeSys AS FechaCrea,M.FecUpdate,M.IdCiaCrea AS CdCiaCrea,M.IdUsuario AS CdUsuario,Usuario
,D.Item,D.TipOrd,D.NumOrden,D.IdCiaOrd,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MD.Mneda AS DetMoneda,MD.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad
,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.DescripUnid,CP.DocRemitente
 FROM Trn_TraManifInt AS M INNER JOIN Companias AS C ON M.IdCia=C.IdCia INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo
 INNER JOIN Localidades AS LO ON M.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON M.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN Terceros AS NC ON M.IdConductor=NC.IdTercero
 INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON M.IdEstado=E.IdEstado
 INNER JOIN Trn_TraManifIntMcia AS D ON M.TipDoc=D.TipDoc AND M.Manifiesto=D.Manifiesto AND M.IdCia=D.IdCia
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MD ON D.IdMoneda=MD.IdMneda
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat 
 LEFT JOIN Terceros AS NCA ON M.IdCondRelev=NCA.IdTercero LEFT JOIN Aduanas AS AF ON M.CdAduana=AF.IdAduana LEFT JOIN Aduanas AS AD ON M.CdAduanaDest=AD.IdAduana
 LEFT JOIN adm_monedas AS MN ON M.IdMoneda=MN.IdMneda 
 LEFT JOIN Trn_TraPorteInt AS CP ON D.TipOrd=CP.TipDoc AND D.NumOrden=CP.NumOrden AND D.IdCiaOrd=CP.IdCia
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 WHERE M.TipDoc=@pmTipDoc AND M.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND M.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifModLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraManifModLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT MV.Manifiesto AS NumManif,MV.IdCia AS CdCia,Compania,M.Fecha AS FecManif,FecDespacho,FecEntrega,M.IdVehiculo AS PlacaVeh
,MV.Fecha AS FechaMod,Item,MV.VrFleteTotal AS FleteTotal,MV.VrRetencion AS Retencion,MV.VrReteIca AS ReteIca,MV.VrAnticipo AS Anticipo,MV.PesoTotal AS Peso_Total
,MV.NumCump AS MmcCumplido,MV.CdCiaCump AS MmcCiaCump,IdLugarPago,LP.Localidad AS LugarPago,MV.FechaPago AS FecPagoSaldo,MV.TimeSys AS FechaCrea,MV.IdUsuario AS MmcIdUsuario,UM.Usuario AS MmcUsuario
,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,IdRutaFle,RF.Ruta AS RutaFletes,M.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,M.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,M.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,M.VrFletes AS MucFleteTotal,M.VrRetencion AS MucRetencion,M.VrReteIca AS MucReteIca,VrDescuento,M.VrAnticipo AS MucAnticipo,VrAntAdic,VrNeto,VrPagos,VrCargos,VrDctos
,TarifaFlete,M.Cantidad AS MucCantidad,M.PesoTotal AS MucPesoTotal,BaseRet,TarifaRet,TarifaIca,M.IdLocFletes AS MucIdLugar,CF.Localidad AS MucLugarPago,M.FechaPago AS MucFecPago,PagoCargue,PagoDescargue,NumMintrans,EdoMintrans,M.Cumplido AS NumCumplido,M.IdCiaCump AS CdCiaCump
,M.FechaCump AS FecCumplido,EstCumplido,M.TipOdp AS TipoOdp,M.OrdPago AS NumOrdPago,M.IdCiaOdp AS CdCiaOdp,FechaOdp,EstOrden,Anulado,FecDev,M.Observacion AS Observ,M.IdEstado AS CdEstado,Estado
,TipCom,Comprobante,IdCiaCom,M.TimeSys AS FechaCrea,FecUpdate,IdCiaCrea,M.IdUsuario AS CdUsuario,U.Usuario AS MucUsuario,M.TipDoc AS CdTipDoc
,kmsTotal,VrFleteTon,TipoRuta,CdLocTrao,CdLocTrad,KmsTraOri,KmsTraDes,IdMneda,VrTasa,NomRemite,NomDestino,LugarFletes,NumAnticipo,NumCheque,TipoMintrans,MucMintrans,ContIntegral,VolumenCarga
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MC.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_TraManifMod AS MV INNER JOIN Trn_TraManifiesto AS M ON MV.TipDoc=M.TipDoc AND MV.Manifiesto=M.Manifiesto AND MV.IdCia=M.IdCia
 INNER JOIN Trn_TraManifAnexo AS MA ON M.TipDoc=MA.TipDoc AND  M.Manifiesto=MA.Manifiesto AND  M.IdCia=MA.IdCia
 INNER JOIN Companias AS CN ON MV.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON M.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON M.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS CO ON M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta INNER JOIN Terceros AS  CDT ON M.IdConductor=CDT.IdTercero 
 INNER JOIN Terceros AS NP ON M.IdPropietario=NP.IdTercero INNER JOIN Terceros AS T ON M.IdPoseedor=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MC ON V.IdMarca=MC.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd INNER JOIN adm_Usuarios AS UM ON MV.IdUsuario=UM.IdUsuario
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON M.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Rutas AS RF ON M.IdRutaFle=RF.IdRuta  LEFT JOIN Localidades AS LP ON MV.IdLugarPago=LP.IdLocal 
 WHERE MV.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND MV.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifPrecFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifPrecFmt] @pmTipDoc VARCHAR(3),@pmManifiestoIni INT,@pmManifiestoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT P.TipDoc,P.Manifiesto,P.IdCia,P.Item,P.IdTipoPre,Precinto,NumPrecinto,ColorPrecinto,Sellos
 FROM Trn_TraManifPrec AS P INNER JOIN TiposPcnto AS TP ON P.IdTipoPre=TP.IdTipoPre
 WHERE P.TipDoc=@pmTipDoc AND P.Manifiesto BETWEEN @pmManifiestoIni AND @pmManifiestoFin AND P.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraManifRem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraManifRem] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Manifiesto,IdCia,Item,TipRem,Remesa,IdCiaRem,ItemRem,TarifTabla,TarifPago,RemMintrans,EdoRemMin,CodBodDtno,TipTraslado
 ,HorasCargue,HorasDesc,FecInicioCargue,FecFinCargue,FecIniciodesc,FecFindesc,TiempoCargue,TiempoDesc,FecLlegCargue,FecSalidaCargue,FecLlegdesc,FecSalidadesc,RemTrayVacio1,RemTrayVacio2
 FROM Trn_TraManifRem
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAboFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAboFmt] @pmTipDoc VARCHAR(3),@pmDocumentoIni INT,@pmDocumentoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT Documento,AP.IdCia AS CdCia,Item,AP.Fecha AS FechaDoc,TipAnt,AP.Anticipo AS NumAntcpo,IdCiaAnt,VrAbono,TipoAplica,AP.Observacion,CodCuenta,A.Fecha AS FechaAnt
,A.TipOds,A.NumOrden,IdCiaOds,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,A.VrAnticipo,A.VrAbonado,TipoPago,NumCheque,FecCheque,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,NomCuenta
,Beneficiario,FechaVence,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado,A.NumDev,A.FecDev,A.Observacion AS AntObserv,AP.TipDoc AS Tip_Doc
 FROM Trn_TraOrdenAbo AS AP  INNER JOIN  Trn_TraOrdenAnt AS A ON AP.TipAnt=A.TipDoc  AND AP.Anticipo=A.Anticipo  AND AP.IdCiaAnt=A.IdCia
 INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS T ON O.IdPoseedor=T.IdTercero
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS P ON A.IdCuenta=P.IdCuenta
 WHERE AP.TipDoc=@pmTipDoc AND AP.Documento BETWEEN @pmDocumentoIni AND @pmDocumentoFin AND AP.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAnt] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipOds,NumOrden,IdCiaOds,VrAnticipo,VrAbonado,TipoPago,NumCheque,FecCheque,IdCta,IdCuenta,Beneficiario,CedBenef,FechaVence,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion
,IdEstado,TipoAncpo,NumPresAnt,Cantidad,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraOrdenAnt
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAntAbo] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=NULL
 AS 
 SELECT A.TipDoc AS TipoAnt,TD.TipoDoc,A.Anticipo,A.IdCia AS CdCia,CN.Compania,A.Fecha AS FecAnt,A.IdConcepto AS CdConcepto,Concepto,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,O.IdVehiculo AS PlacaVeh,nRemolque,O.TipoAfiVehic,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,AG.Agencia,A.VrAnticipo,A.VrAbonado,TipoPago,A.NumCheque,FecCheque
,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,PU.NomCuenta,CedBenef,Beneficiario,FechaVence,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado AS Anuldo,A.NumDev
,A.FecDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado,A.OrigenAdd,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaModif,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario
--datos de la orden
,O.Modalidad,O.TipoOrden,O.VrTotal,O.VrCosto,O.Cantidad,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,IdDestino,LD.Localidad AS NomDestino
,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstFactura,TipFact,NumFactura,CdCiaFact,EstOrden,TipLiq,NumLiquida,CdCiaLiq,O.Observacion AS OdsObserv
,AP.TipDoc AS CdTipoAbo,TDA.TipoDoc AS TipDocAbo,Documento,AP.IdCia AS CdCiaAbo,CA.Compania AS CompaniaAbo,Item,AP.Fecha AS FechaAbo,VrAbono,TipoAplica,AP.Observacion AS ObservAbono,CodCuenta
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS AG ON O.IdAgencia=AG.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS PU ON A.IdCuenta=PU.IdCuenta
 LEFT JOIN Trn_TraOrdenAbo AS AP ON A.TipDoc=AP.TipAnt AND A.Anticipo=AP.Anticipo AND A.IdCia=AP.IdCiaAnt
 LEFT JOIN Companias AS CA ON AP.IdCia=CA.IdCia LEFT JOIN Sys_TiposDoc AS TDA ON AP.TipDoc=TDA.IdDoc
 WHERE A.TipDoc=@pmTipDoc AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAntFmt] @pmTipDoc VARCHAR(3),@pmAnticipoIni INT,@pmAnticipoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT A.TipDoc AS TipoAnt,TipoDoc,Anticipo,A.IdCia AS CdCia,Compania,A.Fecha AS FecAnt,A.IdConcepto AS CdConcepto,Concepto,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,O.IdVehiculo AS PlacaVeh,nRemolque,O.TipoAfiVehic,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,AG.Agencia,A.VrAnticipo,A.VrAbonado,TipoPago,A.NumCheque,FecCheque
,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,PU.NomCuenta,CedBenef,Beneficiario,FechaVence,A.TipoAncpo,A.NumPresAnt,A.Cantidad AS CantGalones,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado AS Anuldo,A.NumDev
,A.FecDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado,A.OrigenAdd,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaModif,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario,Leyenda
--datos de la orden
,O.Modalidad,O.TipoOrden,O.VrTotal,O.VrCosto,O.Cantidad,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,IdDestino,LD.Localidad AS NomDestino
,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstFactura,TipFact,NumFactura,CdCiaFact,EstOrden,TipLiq,NumLiquida,CdCiaLiq,O.Observacion AS OdsObserv
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
--detalles
,Item,DC.IdCuenta AS Cd_Cuenta,PC.NomCuenta AS Nom_Cuenta,Detalle,VrDebito,VrCredito,DC.IdCCosto AS DetCodCentCost,DCC.CCosto AS DetCentCost
,DC.IdSubCos AS DetCodSubCentro,DS.SubCosto AS DetSubCentro,VrBase,TarifaBase,Referncia
 FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS AG ON O.IdAgencia=AG.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS PU ON A.IdCuenta=PU.IdCuenta
 LEFT JOIN Trn_ComDetalle AS DC ON A.TipCom=DC.TipCom AND A.Comprobante=DC.Comprobante AND A.IdCiaCom=DC.IdCia
 LEFT JOIN Puc AS PC ON DC.IdCuenta=PC.IdCuenta LEFT JOIN CentroCosto AS DCC ON DC.IdCCosto=DCC.IdCCosto
 LEFT JOIN SubCentros AS DS ON DC.IdSubCos=DS.IdSubCos
 WHERE A.TipDoc=@pmTipDoc AND A.Anticipo BETWEEN @pmAnticipoIni AND @pmAnticipoFin AND A.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAntLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT Anticipo,A.IdCia AS CdCia,Compania,A.Fecha AS FecAnt,A.IdConcepto AS CdConcepto,Concepto,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden,O.IdVehiculo AS PlacaVeh,nRemolque
,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS CdAgencia,Agencia,A.VrAnticipo,VrAbonado,VrTotal,O.Cantidad,TipoPago,NumCheque,FecCheque,A.IdCta AS CdCta,NumeroCta,CT.IdBanco,Banco
,A.IdCuenta AS CdCuenta,CedBenef,Beneficiario,FechaVence,TipoAncpo,NumPresAnt,A.Cantidad AS CantGalones,TipCom,Comprobante,IdCiaCom,A.Anulado AS Anuldo,A.NumDev,A.FecDev,A.Observacion AS Observ
,A.IdEstado AS CdEstado,Estado,A.OrigenAdd,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaModif,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
 LEFT JOIN CtasCorrientes AS CT ON A.IdCta=CT.IdCta LEFT JOIN Bancos AS B ON CT.IdBanco=B.IdBanco
 LEFT JOIN Agencias AS AG ON O.IdAgencia=AG.IdAgencia 
 WHERE A.TipDoc=@pmTipDoc AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAntRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=NULL
 AS 
 SELECT A.TipDoc AS TipoAnt,TipoDoc,Anticipo,A.IdCia AS CdCia,Compania,A.Fecha AS FecAnt,A.IdConcepto AS CdConcepto,Concepto,TipOds,A.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,O.IdVehiculo AS PlacaVeh,nRemolque,O.TipoAfiVehic,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,O.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,AG.Agencia,A.VrAnticipo,A.VrAbonado,A.VrAnticipo-A.VrAbonado AS VrSaldo,TipoPago,A.NumCheque,FecCheque
,A.IdCta AS CdCta,NumeroCta,CTA.IdBanco,Banco,A.IdCuenta AS CdCuenta,PU.NomCuenta,CedBenef,Beneficiario,FechaVence,TipoAncpo,NumPresAnt,A.Cantidad AS CantGalones,A.TipCom,A.Comprobante,A.IdCiaCom,A.Anulado AS Anuldo,A.NumDev
,A.FecDev,A.Observacion AS Observ,A.IdEstado AS CdEstado,Estado,A.OrigenAdd,A.TimeSys AS FechaCrea,A.FecUpdate AS FechaModif,A.IdCiaCrea AS CdCiaCrea,A.IdUsuario AS CdUsuario,Usuario
--datos de la orden
,O.Modalidad,O.TipoOrden,O.VrTotal,O.VrCosto,O.Cantidad,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido
,O.CdRuta,Ruta,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino,LD.Localidad AS NomDestino,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstCumplido
,EstFactura,TipFact,NumFactura,CdCiaFact,EstOrden,TipLiq,NumLiquida,CdCiaLiq,O.Observacion AS OdsObserv
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TPR.TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_TraOrdenAnt AS A INNER JOIN Trn_TraOrdenServ AS O ON A.TipOds=O.TipDoc AND A.NumOrden=O.NumOrden AND A.IdCiaOds=O.IdCia
 INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia INNER JOIN adm_Usuarios AS U ON A.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON A.IdConcepto=C.IdConcepto INNER JOIN EstadoDoc AS ED ON A.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN Sys_TiposDoc AS TD ON A.TipDoc=TD.IdDoc
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS AG ON O.IdAgencia=AG.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
 LEFT JOIN CtasCorrientes AS CTA ON A.IdCta=CTA.IdCta LEFT JOIN Bancos AS B ON CTA.IdBanco=B.IdBanco
 LEFT JOIN Puc AS PU ON A.IdCuenta=PU.IdCuenta
 WHERE A.TipDoc=@pmTipDoc AND A.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenAntTotCaj]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenAntTotCaj]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdUsuario VARCHAR(11)=Null
AS
SELECT TipDoc,SUM(VrAnticipo) AS TotalAnt
FROM Trn_TraOrdenAnt 
WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND TipoPago='EFECTIVO'
AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GROUP BY TipDoc
UNION ALL
SELECT D.TipDev,SUM(D.VrDevolucion)
FROM Trn_TraDevAos AS D INNER JOIN Trn_TraOrdenAnt AS A ON D.TipDoc=A.TipDoc AND D.Anticipo=A.Anticipo AND D.IdCiaDoc=A.IdCia
WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND A.TipoPago='EFECTIVO'
AND D.IdCia LIKE ISNULL(@pmIdCia,'%%') AND D.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
GROUP BY D.TipDev
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenCum] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Cumplido,IdCia,Fecha,IdConcepto,TipOds,NumOrden,IdCiaOds,TipoAfiVehic,FecDespacho,FecRecibo,FecIngCertif,FecCertificado,DescServicio,Cantidad,VrTotal,VrCosto,RemCliente,Funcionario,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado
,NumReferencia,NumAprobCO,CiaAprobCO,FecAprobCO,ObservAprobCO,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraOrdenCum
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCumFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenCumFmt] @pmTipDoc VARCHAR(3),@pmCumplidoIni INT,@pmCumplidoFin INT,@pmIdCia CHAR(2)
AS 
 SELECT C.TipDoc AS IdTipDoc,TipoDoc,C.Cumplido AS NumCumplido,C.IdCia AS CdCia,Compania,C.Fecha AS FechaCump,C.IdConcepto AS CdConcepto,Concepto,TipOds,C.NumOrden AS Num_Orden,IdCiaOds
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,O.Modalidad,O.TipoOrden,O.VrAnticipo AS Vr_Anticipo,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,C.TipoAfiVehic,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,DescServicio,C.Cantidad AS CumCantidad,C.VrTotal AS CumValor,C.VrCosto AS CumValTercero,C.RemCliente
,Funcionario,O.NumRemesa,O.CdCiaRem,O.kmtInicial,O.kmtFinal,IdDestino,LD.Localidad,C.TipCom,C.Comprobante AS NumComp,C.IdCiaCom,C.Anulado AS CumAnulado,C.NumDev,C.FecDev,C.Observacion AS Observ
,C.NumReferencia,NumAprobCO,CiaAprobCO,FecAprobCO,ObservAprobCO,C.IdEstado AS CdEstado,Estado,C.OrigenAdd,C.TimeSys AS FechaCrea,C.FecUpdate AS FechaModif,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,Leyenda
--detalles
,Item,D.IdMercancia,D.Descripcion,D.Cantidad,D.UndMed AS Und_Med,Unidad,D.VrUnitario,D.TarifaPago,D.DocCliente
--Datos del Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
FROM Trn_TraOrdenCum AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON C.IdConcepto=CT.IdConcepto
INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden  AND C.IdCiaOds=O.IdCia
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
INNER JOIN Trn_TraOrdenCumDet AS D ON C.TipDoc=D.TipDoc AND C.Cumplido=D.Cumplido AND C.IdCia=D.IdCia
INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
WHERE C.TipDoc=@pmTipDoc AND C.Cumplido BETWEEN @pmCumplidoIni AND @pmCumplidoFin AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCumLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenCumLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT Cumplido,C.IdCia AS CdCia,Compania,C.Fecha AS FechaCump,C.IdConcepto AS CdConcepto,Concepto,TipOds,C.NumOrden AS Num_Orden,IdCiaOds
,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,O.Modalidad,TipoOrden,O.VrAnticipo AS Vr_Anticipo,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,C.TipoAfiVehic,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,DescServicio,C.Cantidad AS CumCantidad,C.VrTotal AS CumValor,C.VrCosto AS CumValTercero,C.RemCliente
,Funcionario,O.NumRemesa,O.CdCiaRem,O.kmtInicial,O.kmtFinal,C.TipCom,C.Comprobante AS NumComp,C.IdCiaCom,C.Anulado AS CumAnulado,C.NumDev,C.FecDev,C.Observacion AS Observ
,C.NumReferencia,NumAprobCO,CiaAprobCO,FecAprobCO,ObservAprobCO,C.IdEstado AS CdEstado,Estado,C.OrigenAdd,C.TimeSys AS FechaCrea,C.FecUpdate AS FechaModif,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
FROM Trn_TraOrdenCum AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON C.IdConcepto=CT.IdConcepto
INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden  AND C.IdCiaOds=O.IdCia
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia
WHERE C.TipDoc=@pmTipDoc AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenCumRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenCumRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
 SELECT C.TipDoc AS IdTipDoc,TipoDoc,C.Cumplido AS NumCumplido,C.IdCia AS CdCia,Compania,C.Fecha AS FechaCump,C.IdConcepto AS CdConcepto,Concepto,TipOds,C.NumOrden AS Num_Orden,IdCiaOds
,O.Fecha AS FecOrden,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,O.Modalidad,O.TipoOrden,O.VrAnticipo AS Vr_Anticipo,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,C.TipoAfiVehic,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,DescServicio,C.Cantidad AS CumCantidad,C.VrTotal AS CumValor,C.VrCosto AS CumValTercero,C.RemCliente
,Funcionario,O.NumRemesa,O.CdCiaRem,O.kmtInicial,O.kmtFinal,O.IdDestino,LD.Localidad,C.TipCom,C.Comprobante AS NumComp,C.IdCiaCom,C.Anulado AS CumAnulado,C.NumDev,C.FecDev
,C.NumReferencia,NumAprobCO,CiaAprobCO,FecAprobCO,ObservAprobCO,C.Observacion AS Observ,C.IdEstado AS CdEstado,Estado,C.OrigenAdd,C.TimeSys AS FechaCrea,C.FecUpdate AS FechaModif
,C.IdCiaCrea AS CdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
--detalles
,Item,D.IdMercancia,D.Descripcion,D.Cantidad,D.UndMed AS Und_Med,Unidad,D.VrUnitario,D.TarifaPago,D.DocCliente
--Datos del Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
FROM Trn_TraOrdenCum AS C INNER JOIN Companias AS CN ON C.IdCia=CN.IdCia INNER JOIN EstadoDoc AS ED ON C.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario INNER JOIN Conceptos AS CT ON C.IdConcepto=CT.IdConcepto
INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc
INNER JOIN Trn_TraOrdenServ AS O ON C.TipOds=O.TipDoc AND C.NumOrden=O.NumOrden  AND C.IdCiaOds=O.IdCia
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion  INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
INNER JOIN Trn_TraOrdenCumDet AS D ON C.TipDoc=D.TipDoc AND C.Cumplido=D.Cumplido AND C.IdCia=D.IdCia
INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
WHERE C.TipDoc=@pmTipDoc AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenLiq] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,TipOds,NumOrden,IdCiaOds,IdVehiculo,IdPoseedor,IdConductor,TipoAfiVehic,VrTotal,VrCosto,VrAnticipo,VrGastos,VrIva,VrRetencion,VrReteIca,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrNeto,Cantidad,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc
,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarRtc,Referencia,CxPagar,CdPlazo,FechaVence,UndMed,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TipEgr,Egreso,IdCiaEgr,NumCheque,VrConcCargos,VrConcDed,CdCCosto,CdSubCos,NumDocSop,CiaDocSop,Referencia2,CdTarAvta,TarifaAvta,VrImpAvTa,CdTarBom,TarifaBom,VrBomberil
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraOrdenLiq
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenLiqDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT L.TipDoc AS IdTipDoc,TipoDoc,L.Liquidacion,L.IdCia AS CdCia,Compania,L.Fecha AS FechaLiq,L.IdConcepto AS CdConcepto,CT.Concepto,TipOds,L.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,A.Agencia,O.IdDestino,LD.Localidad AS NomDestino,O.Modalidad,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,TipoResiduo,O.Cantidad AS CantOrden,O.RemCliente,O.NumRemesa,O.CdCiaRem,L.VrTotal,L.VrCosto,L.VrAnticipo,L.VrGastos,VrIva,VrRetencion,VrReteIca
,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrNeto,L.Cantidad,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarRtc
,L.Referencia,L.Referencia2,L.CxPagar,CdPlazo,Plazo,DiasPago,FechaVence,L.UndMed,Unidad,L.TipCom,L.Comprobante,L.IdCiaCom,L.Anulado,L.NumDev,L.FecDev,L.Observacion AS Observ
,L.IdEstado AS CdEstado,Estado,L.OrigenAdd,L.TimeSys AS FechaCrea,L.FecUpdate AS FechaModif,L.IdCiaCrea AS CdCiaCrea,L.IdUsuario AS CdUsuario,Usuario
,DC.Item,DC.IdConcepto AS DetCodConc,DescConcepto,DC.IdCuenta AS CdCuenta,NomCuenta,VrDebito,VrCredito
,DC.IdTercero AS NitTercero,TDT.RazonSocial AS NomTercero,DC.CodAgncia,DC.CdCCosto,CCosto,DC.CdSubCos,SubCosto,pVehiculo
,DC.RubroConc,DC.VrBase,DC.TarifBase,DC.TipFac,DC.Factura,DC.IdCiaFac,ItemFac,DC.FecVence,RefConcep,CD.Concepto AS DetConcep
--vehiuculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LT.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
 FROM Trn_TraOrdenLiq AS L INNER JOIN Companias AS CN ON L.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON L.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON L.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion 
 INNER JOIN Sys_TiposDoc AS TD ON L.TipDoc=TD.IdDoc INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal
 INNER JOIN Vehiculos AS V ON L.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN Trn_TraLiqDetalle AS DC ON L.TipDoc=DC.TipDoc AND L.Liquidacion=DC.Liquidacion AND L.IdCia=DC.IdCia
 INNER JOIN ConcDiversos AS CD ON DC.IdConcepto=CD.IdConcepto 
 LEFT JOIN Puc AS PC ON DC.IdCuenta=PC.IdCuenta LEFT JOIN Terceros AS TDT ON DC.IdTercero=TDT.IdTercero
 LEFT JOIN CentroCosto AS CC ON DC.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON DC.CdSubCos=SC.IdSubCos 
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Sys_Um AS UM ON L.UndMed=UM.UndMed
 LEFT JOIN Plazos AS PZ ON L.CdPlazo=PZ.IdPlazo
 WHERE L.TipDoc=@pmTipDoc AND L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenLiqFmt] @pmTipDoc VARCHAR(3),@pmLiquidacionIni INT,@pmLiquidacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT L.TipDoc AS IdTipDoc,TipoDoc,L.Liquidacion,L.IdCia AS CdCia,Compania,L.Fecha AS FechaLiq,L.IdConcepto AS CdConcepto,Concepto,TipOds,L.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdDestino,LD.Localidad AS NomDestino,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,TipoResiduo,O.RemCliente,O.NumRemesa,O.CdCiaRem,L.NumDocSop,L.CiaDocSop,L.VrTotal,L.VrCosto,L.VrAnticipo,L.VrGastos,VrIva,VrRetencion,VrReteIca
,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrNeto,L.Cantidad,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarRtc
,L.CdTarAvta,L.TarifaAvta,L.VrImpAvTa,L.CdTarBom,L.TarifaBom,L.VrBomberil,L.Referencia,L.Referencia2,L.CxPagar,CdPlazo,Plazo,DiasPago,FechaVence,L.UndMed,Unidad,L.TipCom,L.Comprobante,L.IdCiaCom,L.Anulado,L.NumDev,L.FecDev,L.Observacion AS Observ
,L.IdEstado AS CdEstado,Estado,TipEgr,Egreso,IdCiaEgr,NumCheque,VrConcCargos,VrConcDed,L.OrigenAdd,L.TimeSys AS FechaCrea,L.FecUpdate AS FechaModif,L.IdCiaCrea AS CdCiaCrea,L.IdUsuario AS CdUsuario,Usuario,Leyenda
--vehiuculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LT.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,L.CdCCosto,CCosto,L.CdSubCos,SubCosto
 FROM Trn_TraOrdenLiq AS L INNER JOIN Companias AS CN ON L.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON L.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON L.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion 
 INNER JOIN Sys_TiposDoc AS TD ON L.TipDoc=TD.IdDoc INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal
 INNER JOIN Vehiculos AS V ON L.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Sys_Um AS UM ON L.UndMed=UM.UndMed
 LEFT JOIN Plazos AS PZ ON L.CdPlazo=PZ.IdPlazo LEFT JOIN CentroCosto AS CC ON L.CdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON L.CdSubCos=SC.IdSubCos
 WHERE L.TipDoc=@pmTipDoc AND L.Liquidacion BETWEEN @pmLiquidacionIni AND @pmLiquidacionFin AND L.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenLiqLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT Liquidacion,L.IdCia AS CdCia,Compania,L.Fecha AS FechaLiq,L.IdConcepto AS CdConcepto,Concepto,TipOds,L.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdDestino,Localidad,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,TipoResiduo,O.RemCliente,O.NumRemesa,O.CdCiaRem,L.NumDocSop,L.CiaDocSop
,L.VrTotal,L.VrCosto,L.VrAnticipo,L.VrGastos,VrIva,VrRetencion,VrReteIca,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrConcCargos,VrConcDed,VrNeto,L.Cantidad
,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarRtc,L.CdTarAvta,L.TarifaAvta,L.VrImpAvTa,L.CdTarBom,L.TarifaBom,L.VrBomberil
,Referencia,L.Referencia2,CxPagar,CdPlazo,FechaVence,UndMed,L.TipCom,L.Comprobante,L.IdCiaCom,L.Anulado,L.NumDev,L.FecDev,L.Observacion AS Observ
,L.IdEstado AS CdEstado,Estado,TipEgr,Egreso,IdCiaEgr,NumCheque,L.CdCCosto,L.CdSubCos
,L.OrigenAdd,L.TimeSys AS FechaCrea,L.FecUpdate AS FechaModif,L.IdCiaCrea AS CdCiaCrea,L.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraOrdenLiq AS L INNER JOIN Companias AS CN ON L.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON L.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON L.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion 
 LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 WHERE L.TipDoc=@pmTipDoc AND L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenLiqRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenLiqRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT L.TipDoc AS IdTipDoc,TipoDoc,L.Liquidacion,L.IdCia AS CdCia,Compania,L.Fecha AS FechaLiq,L.IdConcepto AS CdConcepto,Concepto,TipOds,L.NumOrden,IdCiaOds,O.Fecha AS FecOrden
,L.IdVehiculo AS PlacaVeh,L.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,L.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,L.TipoAfiVehic
,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdDestino,LD.Localidad AS NomDestino,O.Modalidad,O.TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,TipoResiduo,O.Cantidad AS CantOrden,O.RemCliente,O.NumRemesa,O.CdCiaRem,L.VrTotal,L.VrCosto,L.VrAnticipo,L.VrGastos,VrIva,VrRetencion,VrReteIca
,VrReteCREE,VrReteIva,VrOtros,VrDescuento,VrConcCargos,VrConcDed,VrNeto,L.Cantidad,TarifaPago,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,TarifaRiv,TarifaRtc,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,CodTarRtc
,L.CdTarAvta,L.TarifaAvta,L.VrImpAvTa,L.CdTarBom,L.TarifaBom,L.VrBomberil,L.Referencia,L.Referencia2,L.CxPagar,CdPlazo,Plazo,DiasPago,FechaVence,L.UndMed,Unidad,L.TipCom,L.Comprobante,L.IdCiaCom,L.Anulado,L.NumDev,L.FecDev,L.Observacion AS Observ,L.IdEstado AS CdEstado,Estado
,L.TipEgr,L.Egreso,L.IdCiaEgr,L.NumCheque,ISNULL(VC.VrTotalAbo,0) AS CxpAbonado,ISNULL(VC.VrSaldo,0) AS CxpSaldo
,L.OrigenAdd,L.TimeSys AS FechaCrea,L.FecUpdate AS FechaModif,L.IdCiaCrea AS CdCiaCrea,L.IdUsuario AS CdUsuario,Usuario
--vehiuculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LT.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,L.CdCCosto,CCosto,L.CdSubCos,SubCosto
 FROM Trn_TraOrdenLiq AS L INNER JOIN Companias AS CN ON L.IdCia=CN.IdCia INNER JOIN Conceptos AS CT ON L.IdConcepto=CT.IdConcepto
 INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS ED ON L.IdEstado=ED.IdEstado
 INNER JOIN Terceros AS NP ON L.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON L.IdConductor=CDT.IdTercero
 INNER JOIN Trn_TraOrdenServ AS O ON L.TipOds=O.TipDoc AND L.NumOrden=O.NumOrden AND L.IdCiaOds=O.IdCia
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion 
 INNER JOIN Sys_TiposDoc AS TD ON L.TipDoc=TD.IdDoc INNER JOIN Localidades AS LT ON T.IdLocal=LT.IdLocal
 INNER JOIN Vehiculos AS V ON L.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Sys_Um AS UM ON L.UndMed=UM.UndMed
 LEFT JOIN Plazos AS PZ ON L.CdPlazo=PZ.IdPlazo
 LEFT JOIN CentroCosto AS CC ON L.CdCCosto=CC.IdCCosto LEFT JOIN SubCentros AS SC ON L.CdSubCos=SC.IdSubCos
 --Subconsulta egresos-pagos
 LEFT JOIN (SELECT TipFac,Factura,IdCia,IdProveedor,Documento,SUM(VrFactura) AS VrTotalFac,SUM(VrAbonado) AS VrTotalAbo,SUM(VrFactura-VrAbonado) AS VrSaldo FROM Trn_ComFactura
 WHERE TipFac=@pmTipDoc AND TipDoc=@pmTipDoc AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY TipFac,Factura,IdCia,IdProveedor,Documento) AS VC ON L.TipDoc=VC.TipFac AND L.Liquidacion=VC.Documento AND L.IdCia=VC.IdCia
 -- FIN Subconsulta
 WHERE L.TipDoc=@pmTipDoc AND L.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND L.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenManif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenManif] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,OrdPago,IdCia,Item,TipMuc,Manifiesto,IdCiaMuc,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,VrTotalFletes,VrDescuento,VrRetencion
,VrReteIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,VrNeto,TarifaTabla,TarifaFlete,UnidTarifa,PesoTotal,Unidades
,Volumen,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,BaseRet,BaseIca,BaseSeg,BaseImp,TarifaRet,TarifaIca,TarifaSeg,TarifaImp,CodTarRet,CodTarIca
,TipoLiq,TipEgr,Egreso,IdCiaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos,VrConcDctos
,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,EdoLiqCausac,VrRemesas,VrRecCaja,CdForma,FechaEgr,VrSeguroRc,VrReteCREE,TarifaRtc,CodTarRtc,CdCenCosto,CdSubCenCos
,CodTarifAvta,TarifaAvta,VrImpAvTa,VrDctoPago,CodTarifDcpp,VrTrayVacio1,VrTrayVacio2
 FROM Trn_TraOrdenManif
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPago]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenPago] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,OrdPago,IdCia,Fecha,IdConcepto,Modalidad,LiqRemesas,CxPagar,MulPlazos,IdPlazo,FechaVence,TipCom,Comprobante
,IdCiaCom,NumDocSop,CiaDocSop,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraOrdenPago
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenPagoFmt] @pmTipDoc VARCHAR(3),@pmOrdPagoIni INT,@pmOrdPagoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT OP.TipDoc AS TipoOdp,TipoDoc,OP.OrdPago AS NumOdp,OP.IdCia AS CdCia,Compania,OP.Fecha AS FechaOdp,OP.IdConcepto AS CdConcepto,Concepto,Modalidad,LiqRemesas,CxPagar,MulPlazos,OP.IdPlazo AS CdPlazo,Plazo,DiasPago,FechaVence
,OP.TipCom AS TipComp,TipoCom,OP.Comprobante AS NumComp,OP.IdCiaCom AS CdCiaComp,OP.Anulado AS Anuldo,NumDev,OP.FecDev AS FechaDev,OP.NumDocSop,OP.CiaDocSop,OP.Observacion AS Observ,OP.IdEstado AS CdEstado,Estado,OP.TimeSys AS FechaCrea,OP.FecUpdate AS FechaAct,OP.IdCiaCrea AS CdCiaCrea,OP.IdUsuario AS CdUsuario,Usuario,Leyenda
,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif,O.IdVehiculo AS PlacaVeh,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,O.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrTotalFletes,O.VrDescuento AS Vr_Dcto,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto AS Vr_Neto
,TarifaTabla,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp
,TipoLiq,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,O.VrTrayVacio1,O.VrTrayVacio2,EdoLiqCausac,VrRemesas,VrSeguroRc,VrRecCaja,VrReteCREE,TarifaRtc,CodTarRtc,CdForma
,M.Fecha AS FecManif,FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,nRemolque,TipoAfiVehic
,IdLocFletes,CF.Localidad AS LugarFletes,M.Observacion AS MucObserv,CdCenCosto,CdSubCenCos,CodTarifAvta,TarifaAvta,VrImpAvTa,O.VrDctoPago,O.CodTarifDcpp
,TipRem,ORM.Remesa AS NumRemesa,ORM.IdCiaRem AS CdCiaRem,ItemRem,ORM.Cantidad AS Cant,PesoNeto,ORM.UndMed AS CdUMed,UMP.Unidad AS UmPeso,ORM.Volumen AS Volmen,UndVol,Cases,Cajas,Palets,TarifPago,TarifTabla,UndTarifa,Detalle
--Datos del poseedor
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,NumLiquida
 FROM Trn_TraOrdenPago AS OP INNER JOIN Trn_TraOrdenManif AS O ON OP.TipDoc=O.TipDoc AND OP.OrdPago=O.OrdPago AND OP.IdCia=O.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Companias AS CN ON OP.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON OP.TipDoc=TD.IdDoc
 INNER JOIN EstadoDoc AS ED ON OP.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON OP.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON OP.IdConcepto=C.IdConcepto INNER JOIN Plazos AS PZ ON OP.IdPlazo=PZ.IdPlazo
 INNER JOIN Terceros AS  CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS T ON O.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS NP ON O.IdPropietario=NP.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta    INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Trn_TraOrdenRemesas AS ORM ON O.TipDoc=ORM.TipDoc AND   O.OrdPago=ORM.OrdPago AND  O.IdCia=ORM.IdCia 
 AND  O.TipMuc=ORM.TipMuc AND  O.Manifiesto=ORM.Manifiesto AND  O.IdCiaMuc=ORM.IdCiaMuc
 LEFT JOIN Sys_Um AS UMP ON ORM.UndMed=UMP.UndMed  LEFT JOIN TiposCom AS TCM ON OP.TipCom=TCM.IdCom 
 LEFT JOIN (SELECT TipOdp,OrdPago,IdCiaOdp,MAX(Liquidacion) AS NumLiquida,SUM(VrAbonado) AS TotalAbonos FROM Trn_TraLiquidaOdp GROUP BY TipOdp,OrdPago,IdCiaOdp)
 AS LQ ON OP.TipDoc=LQ.TipOdp AND OP.OrdPago=LQ.OrdPago AND OP.IdCia=LQ.IdCiaOdp
 WHERE OP.TipDoc=@pmTipDoc AND OP.OrdPago BETWEEN @pmOrdPagoIni AND @pmOrdPagoFin AND OP.IdCia=@pmIdCia
 ORDER BY OP.OrdPago
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenPagoLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT O.OrdPago AS NumOrden,O.IdCia AS CdCia,Compania,Fecha,TipMuc,Manifiesto,IdCiaMuc,M.IdVehiculo AS PlacaVeh,NumVeh,M.IdPropietario AS NitPropietario,T.RazonSocial AS Propietario,M.IdPoseedor AS NitPoseedor,NP.RazonSocial AS Poseedor
,M.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,LiqRemesas,TipoLiq,VrTotalFletes,VrDescuento,VrRetencion,VrReteIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos
,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,VrNeto,TarifaTabla,TarifaFlete,UnidTarifa,PesoTotal,Unidades,Volumen,PesoOrigen,UnidOrigen,VolOrigen
,PesoDestino,UnidDestino,VolDestino,BaseRet,BaseIca,BaseSeg,BaseImp,TarifaRet,TarifaIca,TarifaSeg,TarifaImp,CxPagar,MulPlazos,O.IdPlazo AS CdPlazo,Plazo,NVmto,FechaVence
,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,VrRemesas,VrSeguroRc,VrRecCaja,VrReteCREE,TarifaRtc,CodTarRtc,CodTarifAvta,TarifaAvta,VrImpAvTa,VrDctoPago,M.VrTrayVacio1,M.VrTrayVacio2,CodTarifDcpp,CdForma,CdCenCosto,CdSubCenCos
,O.IdConcepto AS CdConcepto,Concepto,Modalidad,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,Referencia,NumDocSop,CiaDocSop,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraOrdenPago AS O INNER JOIN Trn_TraOrdenManif AS M ON O.TipDoc=M.TipDoc AND O.OrdPago=M.OrdPago AND O.IdCia=M.IdCia
 INNER JOIN Companias AS CI ON O.IdCia=CI.IdCia INNER JOIN Conceptos AS C ON O.IdConcepto=C.IdConcepto
 INNER JOIN Vehiculos AS V ON M.IdVehiculo=V.IdVehiculo   INNER JOIN Terceros AS T ON M.IdPropietario=T.IdTercero
 INNER JOIN Terceros AS NC ON M.IdConductor=NC.IdTercero  INNER JOIN Terceros AS NP ON M.IdPoseedor=NP.IdTercero 
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 LEFT JOIN Plazos AS PZ ON O.IdPlazo=PZ.IdPlazo
 WHERE O.TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND M.IdVehiculo  LIKE ISNULL(@pmIdVehiculo ,'%') AND M.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND  M.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 ORDER BY O.IdCia,O.OrdPago
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoNet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenPagoNet] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
SELECT OP.TipDoc AS CdTipoDoc,TipoDoc,OP.OrdPago AS NumOrden,OP.IdCia AS CdCia,Compania,OP.Fecha AS FecOrden,OP.IdConcepto AS CdConcepto,Concepto,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif
,O.IdVehiculo AS PlacaVeh,NumVeh,O.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,O.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,VrTotalFletes,O.VrDescuento AS Vr_Dcto,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrReteCREE,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto AS Vr_Neto
,TarifaTabla,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp,TarifaRtc
,CxPagar,MulPlazos,OP.IdPlazo AS CdPlazo,Plazo,DiasPago,FechaVence,OP.TipCom AS TipComp,TipoCom,OP.Comprobante AS NumComp,OP.IdCiaCom AS CdCiaCom,OP.Anulado AS Anuldo,NumDev,OP.FecDev AS FechaDev,OP.Observacion AS Observ,OP.IdCiaCrea AS CdCiaCrea,OP.IdUsuario AS CdUsuario,Usuario
,TipoLiq,TipEgr,Egreso,IdCiaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,EdoLiqCausac,VrRemesas,VrSeguroRc,VrRecCaja,TarifaAvta,VrImpAvTa,O.VrTrayVacio1,O.VrTrayVacio2
,M.Fecha AS FecManif,FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,nRemolque,TipoAfiVehic,IdLocFletes,CF.Localidad AS LugarFletes,M.Observacion AS MucObserv
,ISNULL(EGR.Vrabono,0) AS VrEgreso,ISNULL(FechaEgr,EGR.EGRFEC) AS FechaEgr,ISNULL(VC.VrTotalAbo,0) AS CxpAbonado,ISNULL(VC.VrSaldo,0) AS CxpSaldo
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Direccion AS DirPoseedor,T.Telefono AS TelPoseedor,T.TelMovil AS TelMovilPosee,T.e_mail AS emailPoseedor
,TIC.CdLocdad AS IdIcaOdp,LIC.Localidad AS CiudadICaOdp,CDTR.IdLugar AS IdLugarLic,LLC.Localidad AS LugarLicencia
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,Modelo,Config,TipoAfil,V.Descripcion AS VehDescripcion
 FROM Trn_TraOrdenPago AS OP INNER JOIN Trn_TraOrdenManif AS O ON OP.TipDoc=O.TipDoc AND OP.OrdPago=O.OrdPago AND OP.IdCia=O.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Companias AS CN ON OP.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON OP.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON OP.IdConcepto=C.IdConcepto INNER JOIN Sys_TiposDoc AS TD ON OP.TipDoc=TD.IdDoc
 INNER JOIN Plazos AS PZ ON OP.IdPlazo=PZ.IdPlazo
 INNER JOIN Terceros AS  CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS T ON O.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS NP ON O.IdPropietario=NP.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca  LEFT JOIN TiposCom AS TCM ON OP.TipCom=TCM.IdCom 
 LEFT JOIN TercCndtores AS CDTR ON O.IdConductor =CDTR.IdConductor LEFT JOIN Localidades AS LLC ON CDTR.IdLugar=LLC.IdLocal 
 LEFT JOIN Tablapor AS TIC ON O.CodTarIca=TIC.IdTarifa  LEFT JOIN Localidades LIC ON TIC.CdLocdad=LIC.IdLocal 
 LEFT JOIN ( SELECT TipOdp,OrdPago,IdCiaOdp,SUM(VrAbonado) AS Vrabono,MAX(Trn_Comprobantes.Fecha) AS EGRFEC FROM Trn_TraEgrOrden 
 LEFT JOIN Trn_Comprobantes ON Trn_TraEgrOrden.TipCom =Trn_Comprobantes.TipCom AND Trn_TraEgrOrden.NumEgreso =Trn_Comprobantes.Comprobante
 AND Trn_TraEgrOrden.IdCia =Trn_Comprobantes.IdCia  GROUP BY TipOdp,OrdPago,IdCiaOdp) AS EGR
 ON OP.TipDoc =EGR.TipOdp AND OP.OrdPago =EGR.OrdPago AND OP.IdCia =EGR.IdCiaOdp 
 --subconsulta abonos cuentas por pagar
 LEFT JOIN (SELECT TipFac,Factura,IdCia,IdProveedor,Documento,SUM(VrFactura) AS VrTotalFac,SUM(VrAbonado) AS VrTotalAbo,SUM(VrFactura-VrAbonado) AS VrSaldo FROM Trn_ComFactura
 WHERE TipFac='ODP' AND TipDoc='ODP' AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProveedor LIKE ISNULL(@pmIdPoseedor,'%')
 GROUP BY TipFac,Factura,IdCia,IdProveedor,Documento) AS VC ON OP.TipDoc=VC.TipFac AND OP.OrdPago=VC.Documento AND OP.IdCia=VC.IdCia
 WHERE OP.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND OP.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND O.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
UNION ALL
 SELECT TipDev,TipoDoc,Devolucion,D.IdCia,Compania,D.Fecha,D.IdConcepto,Concepto,O.TipMuc,O.Manifiesto,O.IdCiaMuc,D.IdVehiculo,NumVeh
,O.IdPropietario,NP.RazonSocial,D.IdPoseedor,T.RazonSocial,D.IdConductor,CDT.RazonSocial,VrTotalFletes,O.VrDescuento,O.VrRetencion,O.VrReteIca,VrReteCREE,VrAnticipos
,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto
,TarifaTabla,O.TarifaFlete,UnidTarifa,O.PesoTotal,Unidades,O.Volumen,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,O.BaseRet,O.BaseIca,BaseSeg,BaseImp
,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp,TarifaRtc,D.CxPagar,0,'','','',FecDoc,D.TipCom,TipoCom,D.Comprobante,D.IdCiaCom,CAST(0 AS BIT),0,Null,D.Observacion,D.IdCiaCrea,D.IdUsuario,Usuario
,TipoLiq,D.TipDoc,D.OrdPago,D.IdCiaDoc,'',Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,EdoLiqCausac,VrRemesas,VrSeguroRc,VrRecCaja,TarifaAvta,VrImpAvTa,O.VrTrayVacio1,O.VrTrayVacio2
,M.Fecha,FecDespacho,FecEntrega,M.IdOrigen,CO.Localidad,CO.IdDep,DPO.Departamento,M.IdDestino,CD.Localidad,CD.IdDep,DPD.Departamento,M.IdRuta,R.Ruta,nRemolque,TipoAfiVehic,IdLocFletes
,CF.Localidad,M.Observacion,ISNULL(EGR.Vrabono,0),ISNULL(FechaEgr,EGR.EGRFEC),O.VrNeto,0
--Datos del vehiculo
,T.TipoId,T.Dv,T.IdLocal,L.Localidad,T.Direccion,T.Telefono,T.TelMovil,T.e_mail,TIC.CdLocdad,LIC.Localidad,CDTR.IdLugar,LLC.Localidad
,V.IdTipoVeh,TipoVehiculo,V.IdMarca,MV.Marca,Modelo,Config,TipoAfil,V.Descripcion
 FROM Trn_TraDevOdp AS D INNER JOIN Trn_TraOrdenManif AS O ON D.TipDoc=O.TipDoc AND D.OrdPago=O.OrdPago AND D.IdCiaDoc=O.IdCia
 INNER JOIN Companias AS CN ON D.IdCia=CN.IdCia  INNER JOIN Conceptos AS C ON D.IdConcepto=C.IdConcepto
 INNER JOIN Sys_TiposDoc AS TD ON D.TipDev=TD.IdDoc
 INNER JOIN adm_Usuarios AS U ON D.IdUsuario=U.IdUsuario INNER JOIN Terceros AS  CDT ON D.IdConductor=CDT.IdTercero
 INNER JOIN Terceros AS T ON D.IdPoseedor=T.IdTercero INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Terceros AS NP ON O.IdPropietario=NP.IdTercero
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Localidades AS CO ON M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON D.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca  LEFT JOIN TiposCom AS TCM ON D.TipCom=TCM.IdCom 
 LEFT JOIN TercCndtores AS CDTR ON D.IdConductor=CDTR.IdConductor LEFT JOIN Localidades AS LLC ON CDTR.IdLugar=LLC.IdLocal 
 LEFT JOIN Tablapor AS TIC ON O.CodTarIca=TIC.IdTarifa  LEFT JOIN Localidades LIC ON TIC.CdLocdad=LIC.IdLocal 
 LEFT JOIN ( SELECT TipOdp,OrdPago,IdCiaOdp,SUM(VrAbonado) AS Vrabono,MAX(Trn_Comprobantes.Fecha) AS EGRFEC FROM Trn_TraEgrOrden 
 LEFT JOIN Trn_Comprobantes ON Trn_TraEgrOrden.TipCom =Trn_Comprobantes.TipCom AND Trn_TraEgrOrden.NumEgreso =Trn_Comprobantes.Comprobante
 AND Trn_TraEgrOrden.IdCia=Trn_Comprobantes.IdCia GROUP BY TipOdp,OrdPago,IdCiaOdp) AS EGR
 ON D.TipDoc=EGR.TipOdp AND D.OrdPago=EGR.OrdPago AND D.IdCiaDoc=EGR.IdCiaOdp 
 WHERE D.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND D.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenPagoRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
,@pmOrdPagoIni INT=Null,@pmOrdPagoFin INT=Null
 AS 
 SELECT OP.TipDoc AS TipoOdp,OP.OrdPago AS NumOdp,OP.IdCia AS CdCia,Compania,OP.Fecha AS FechaOdp,OP.IdConcepto AS CdConcepto,Concepto,Modalidad,LiqRemesas,CxPagar,MulPlazos,OP.IdPlazo AS CdPlazo,Plazo,DiasPago,FechaVence
,OP.TipCom AS TipComp,TipoCom,OP.Comprobante AS NumComp,OP.IdCiaCom AS CdCiaComp,OP.Anulado AS Anuldo,NumDev,OP.FecDev AS FechaDev,OP.Observacion AS Observ,OP.IdEstado AS CdEstado,OP.TimeSys AS FechaCrea,OP.FecUpdate AS FechaAct,OP.IdCiaCrea AS CdCiaCrea,OP.IdUsuario AS CdUsuario,Usuario
,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif,O.IdVehiculo AS PlacaVeh,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,O.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrTotalFletes,O.VrDescuento AS Vr_Dcto,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto AS Vr_Neto
,TarifaTabla,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp
,TipoLiq,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,VrRemesas,VrSeguroRc,VrRecCaja,VrReteCREE,TarifaRtc,CodTarRtc,VrImpAvTa,CodTarifAvta,TarifaAvta,O.VrTrayVacio1,O.VrTrayVacio2
,CdForma,EdoLiqCausac,M.Fecha AS FecManif,FecDespacho,FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,nRemolque,TipoAfiVehic
,IdLocFletes,CF.Localidad AS LugarFletes,M.Observacion AS MucObserv
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupoPro,GrupoProp
,ISNULL(VC.VrTotalAbo,0) AS CxpAbonado,ISNULL(VC.VrSaldo,0) AS CxpSaldo
 FROM Trn_TraOrdenPago AS OP INNER JOIN Trn_TraOrdenManif AS O ON OP.TipDoc=O.TipDoc AND OP.OrdPago=O.OrdPago AND OP.IdCia=O.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Companias AS CN ON OP.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON OP.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON OP.IdConcepto=C.IdConcepto INNER JOIN Plazos AS PZ ON OP.IdPlazo=PZ.IdPlazo
 INNER JOIN Terceros AS  CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS T ON O.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS NP ON O.IdPropietario=NP.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta    INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TiposCom AS TCM ON OP.TipCom=TCM.IdCom  LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 --subconsulta abonos cuentas por pagar
 LEFT JOIN (SELECT TipFac,Factura,IdCia,IdProveedor,Documento,SUM(VrFactura) AS VrTotalFac,SUM(VrAbonado) AS VrTotalAbo,SUM(VrFactura-VrAbonado) AS VrSaldo FROM Trn_ComFactura
 WHERE TipFac=@pmTipDoc AND TipDoc=@pmTipDoc AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProveedor LIKE ISNULL(@pmIdPoseedor,'%')
 GROUP BY TipFac,Factura,IdCia,IdProveedor,Documento) AS VC ON O.TipDoc=VC.TipFac AND O.OrdPago=VC.Documento AND O.IdCia=VC.IdCia AND O.IdPoseedor=VC.IdProveedor
 WHERE OP.TipDoc=@pmTipDoc AND OP.OrdPago BETWEEN ISNULL(@pmOrdPagoIni,0) AND ISNULL(@pmOrdPagoFin,2147483647)
 AND OP.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 --Mayo 10/2018 Parametros Obsoletos
 --AND OP.IdCia LIKE ISNULL(@pmIdCia,'%%')
 --AND OP.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 --AND O.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 --2147483647
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenPagoRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenPagoRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
,@pmOrdPagoIni INT=Null,@pmOrdPagoFin INT=Null
 AS 
 SELECT OP.TipDoc AS TipoOdp,OP.OrdPago AS NumOdp,OP.IdCia AS CdCia,Compania,OP.Fecha AS FechaOdp,OP.IdConcepto AS CdConcepto,Concepto,OP.Modalidad,LiqRemesas,CxPagar,MulPlazos,OP.IdPlazo AS CdPlazo,Plazo,DiasPago,FechaVence
,OP.TipCom AS TipComp,TipoCom,OP.Comprobante AS NumComp,OP.IdCiaCom AS CdCiaComp,OP.Anulado AS Anuldo,NumDev,OP.FecDev AS FechaDev,OP.Observacion AS Observ,OP.IdEstado AS CdEstado,OP.TimeSys AS FechaCrea,OP.FecUpdate AS FechaAct,OP.IdCiaCrea AS CdCiaCrea,OP.IdUsuario AS CdUsuario,Usuario
,O.TipMuc AS TipManif,O.Manifiesto AS NumManif,O.IdCiaMuc AS CdCiaManif,O.IdVehiculo AS PlacaVeh,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,O.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,O.IdPoseedor AS NitPoseedor,T.RazonSocial AS Poseedor
,VrTotalFletes,O.VrDescuento AS Vr_Dcto,O.VrRetencion AS Vr_RetFte,O.VrReteIca AS Vr_RetIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,O.VrNeto AS Vr_Neto
,TarifaTabla,O.TarifaFlete AS Tarifa_Flete,UnidTarifa,O.PesoTotal AS Peso_Total,Unidades,O.Volumen AS VolmTotal,PesoOrigen,UnidOrigen,VolOrigen,PesoDestino,UnidDestino,VolDestino,O.BaseRet,O.BaseIca,BaseSeg,BaseImp,O.TarifaRet,O.TarifaIca,TarifaSeg,TarifaImp
,TipoLiq,TipEgr,Egreso,IdCiaEgr,FechaEgr,O.NumCheque,O.Referencia,CantFaltante,UnidadFalt,TolFaltNeto,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,VrRemesas,VrSeguroRc,VrRecCaja,VrReteCREE,TarifaRtc,CodTarRtc,VrImpAvTa,CodTarifAvta,TarifaAvta,EdoLiqCausac,O.VrTrayVacio1,O.VrTrayVacio2
,M.Fecha AS FecManif,M.FecDespacho,M.FecEntrega,M.IdOrigen AS CdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,M.IdDestino AS CdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,M.IdRuta AS CdRuta,R.Ruta AS DescRuta,M.nRemolque,M.TipoAfiVehic
,M.IdLocFletes,CF.Localidad AS LugarFletes,M.Observacion AS MucObserv
--detalles
,ORM.TipRem,ORM.Remesa AS NumRemesa,ORM.IdCiaRem AS CdCiaRem,ORM.ItemRem,ORM.Cantidad AS Cant,ORM.PesoNeto,ORM.UndMed AS CdUMed,UMP.Unidad AS UmPeso,ORM.Volumen AS Volmen,ORM.UndVol,ORM.Cases,ORM.Cajas,ORM.Palets,ORM.TarifPago,ORM.TarifTabla,ORM.UndTarifa,ORM.Detalle,RD.Referencia1,RD.Referencia2,RD.Referencia3
,RM.IdCliente AS CdCliente,NC.RazonSocial AS NomCliente,RM.IdAgencia AS CdAgencia,A.Agencia
--Datos del vehiculo
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion,V.IdGrupo AS CdGrupoPro,GrupoProp
,ISNULL(VC.VrTotalAbo,0) AS CxpAbonado,ISNULL(VC.VrSaldo,0) AS CxpSaldo
 FROM Trn_TraOrdenPago AS OP INNER JOIN Trn_TraOrdenManif AS O ON OP.TipDoc=O.TipDoc AND OP.OrdPago=O.OrdPago AND OP.IdCia=O.IdCia
 INNER JOIN Trn_TraManifiesto AS M ON O.TipMuc=M.TipDoc AND O.Manifiesto=M.Manifiesto AND O.IdCiaMuc=M.IdCia
 INNER JOIN Companias AS CN ON OP.IdCia=CN.IdCia  INNER JOIN adm_Usuarios AS U ON OP.IdUsuario=U.IdUsuario
 INNER JOIN Conceptos AS C ON OP.IdConcepto=C.IdConcepto INNER JOIN Plazos AS PZ ON OP.IdPlazo=PZ.IdPlazo
 INNER JOIN Terceros AS  CDT ON O.IdConductor=CDT.IdTercero INNER JOIN Terceros AS T ON O.IdPoseedor=T.IdTercero
 INNER JOIN Terceros AS NP ON O.IdPropietario=NP.IdTercero  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Localidades AS CO ON  M.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON M.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Rutas AS R ON M.IdRuta=R.IdRuta    INNER JOIN Localidades AS CF ON M.IdLocFletes=CF.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TiposCom AS TCM ON OP.TipCom=TCM.IdCom 
 LEFT JOIN Trn_TraOrdenRemesas AS ORM ON O.TipDoc=ORM.TipDoc AND O.OrdPago=ORM.OrdPago AND O.IdCia=ORM.IdCia 
 AND O.TipMuc=ORM.TipMuc AND O.Manifiesto=ORM.Manifiesto AND O.IdCiaMuc=ORM.IdCiaMuc
 LEFT JOIN Sys_Um AS UMP ON ORM.UndMed=UMP.UndMed LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Trn_TraRemesa AS RM ON ORM.TipRem=RM.TipDoc AND ORM.Remesa=RM.NumOrden AND ORM.IdCiaRem=RM.IdCia
 LEFT JOIN Trn_TraRemMcias AS RD ON ORM.TipRem=RD.TipDoc AND ORM.Remesa=RD.NumOrden AND ORM.IdCiaRem=RD.IdCia AND ORM.ItemRem=RD.Item
 LEFT JOIN Terceros AS NC ON RM.IdCliente=NC.IdTercero LEFT JOIN Agencias AS A ON RM.IdAgencia=A.IdAgencia
  --subconsulta abonos cuentas por pagar
 LEFT JOIN (SELECT TipFac,Factura,IdCia,IdProveedor,Documento,SUM(VrFactura) AS VrTotalFac,SUM(VrAbonado) AS VrTotalAbo,SUM(VrFactura-VrAbonado) AS VrSaldo FROM Trn_ComFactura
 WHERE TipFac=@pmTipDoc AND TipDoc=@pmTipDoc AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdProveedor LIKE ISNULL(@pmIdPoseedor,'%')
 GROUP BY TipFac,Factura,IdCia,IdProveedor,Documento) AS VC ON O.TipDoc=VC.TipFac AND O.OrdPago=VC.Documento AND O.IdCia=VC.IdCia AND O.IdPoseedor=VC.IdProveedor
 WHERE OP.TipDoc=@pmTipDoc AND OP.OrdPago BETWEEN ISNULL(@pmOrdPagoIni,0) AND ISNULL(@pmOrdPagoFin,2147483647)
 AND OP.Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 --Mayo 10/2018 Parametros Obsoletos
 --AND OP.IdCia LIKE ISNULL(@pmIdCia,'%%')
 --AND OP.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND O.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND O.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 --AND O.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServ]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,FecRecibo,IdCliente,IdAgencia,IdVehiculo,IdPoseedor,IdConductor,nRemolque,TipoAfiVehic,Modalidad,VrTotal,VrCosto,Cantidad,VrAnticipo,IdDestino,TipoOrden,IdEstacion,NomEstacion,TipoResiduo,RemCliente,NomRecibido
,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstCumplido,EstFactura,TipFact,NumFactura,CdCiaFact,kmtInicial,kmtFinal,EstOrden,TipLiq,NumLiquida,CdCiaLiq,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob
,CdRuta,IdOrigen,Cantkms,NumCump,CdCiaCum,CdTarIva,CdTarRiv,CdTarRet,CdTarIca,CdTarRtc,NumReferencia,CdTarAvta,CdTarBom,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraOrdenServ
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServFac] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=NULL
AS
SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden AS Num_Orden,O.IdCia AS CdCia,Compania,O.Fecha,T.TipoId AS ClieTipoId,O.IdCliente,T.Dv AS ClieDv,T.RazonSocial AS NomCliente
,O.IdVehiculo AS PlacaVeh,NumVeh,O.TipoAfiVehic,O.Modalidad,TipoOrden,O.VrTotal AS ValorTotal,O.VrCosto AS TotalTercero,O.Cantidad AS CantTotal,O.VrAnticipo
,D.Item,D.IdMercancia AS CdMercancia,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TarifaPago,D.DocCliente
,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,O.CdRuta,Ruta,O.IdOrigen AS CdOrigen,LO.Localidad AS NomOrigen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino,O.IdAgencia AS CdAgencia,Agencia
,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,NomEstacion,TipoResiduo,O.RemCliente,NomRecibido,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,O.NumRemesa,O.CdCiaRem,kmtInicial,kmtFinal,Cantkms,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,O.NumReferencia
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,ED.Estado,O.TimeSys AS FechaCrea,O.FecUpdate AS FechaModif,O.IdCiaCrea AS CdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
--cumplido
,EstCumplido,CM.Cumplido AS NumCumplido,CM.IdCia AS CiaCump,CM.Fecha AS FechaCump,CM.DescServicio AS CumpServicio,CM.Observacion AS ObservCump
,CM.IdMercancia AS CdMercanciaCump,CM.Descripcion AS DescripCump,CM.Cantidad AS CantCump,CM.UndMed AS UndMedCump,UMC.Unidad AS UnidadCump,CM.VrUnitario AS TarifCump
,CM.TarifaPago AS TarifPagoCump
--liquidacion
,O.EstOrden,O.TipLiq,O.NumLiquida,O.CdCiaLiq,L.Fecha AS FecLiquida,L.VrTotal AS LiqTotal,L.VrAnticipo AS LiqAnticipo,L.VrIva AS LiqIva,L.VrRetencion AS LiqRetencion
,L.VrReteIca,L.VrReteCREE,L.VrReteIva,L.VrOtros,L.VrDescuento,L.VrNeto,L.Cantidad AS LiqCantidad,L.TarifaPago AS LiqTarifaPago,L.TarifaImp,L.TarifaRet,L.TarifaIca,L.TarifaRiv
,L.Referencia,L.VrGastos
--Factura
,O.EstFactura,O.TipFact,O.NumFactura,O.CdCiaFact,FactFecha,FactCant,FactTarifClie,FactTotal,FactIva,FactTarifIVA,FactCosto,FactIdCli,TCF.RazonSocial AS FactNomCliente
--Inf vehiculo
,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LC.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.TelMovil AS TelCelular,T.e_mail AS TercEmail
--Vehiculo
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdColor AS CdColor,NomColor,Modelo,NumMotor,SerieChasis,NumSerie,NitEmpresa,NE.RazonSocial AS VehNomEmpresa
,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion
FROM Trn_TraOrdenServ AS O INNER JOIN Trn_TraOrdenDet AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal
INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia
LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
LEFT JOIN Trn_TraOrdenLiq AS L ON O.TipLiq=L.TipDoc AND O.NumLiquida=L.Liquidacion AND O.CdCiaLiq=L.IdCia
LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
--Subconsulta cumplido
LEFT JOIN (SELECT C.Cumplido,C.IdCia,C.Fecha,C.TipOds,C.NumOrden,C.IdCiaOds,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,C.DescServicio
,C.RemCliente,C.Funcionario,C.Observacion,D.IdMercancia,D.Descripcion,D.Item,D.Cantidad,D.UndMed,D.VrUnitario,D.TarifaPago,D.DocCliente
FROM Trn_TraOrdenCum AS C INNER JOIN Trn_TraOrdenCumDet AS D ON C.TipDoc=D.TipDoc AND C.Cumplido=D.Cumplido AND C.IdCia=D.IdCia
WHERE C.Anulado=0) AS CM ON O.TipDoc=CM.TipOds AND O.NumOrden=CM.NumOrden AND O.IdCia=CM.IdCiaOds AND D.Item=CM.Item
LEFT JOIN Sys_Um AS UMC ON CM.UndMed=UMC.UndMed
--Subconsulta factura
LEFT JOIN (SELECT F.TipDoc,F.Factura,F.IdCia,D.TipRem,D.Remesa,D.IdCiaRem,F.IdCliente AS FactIdCli,F.Fecha AS FactFecha,SUM(D.Cantidad) AS FactCant,SUM(D.VrUnitario*D.Cantidad) AS FactTotal
,SUM(D.VrCosto*D.Cantidad) AS FactCosto,SUM(D.VrImpuesto) AS FactIva,MAX(D.TarifaIva) AS FactTarifIVA,MAX(D.VrUnitario) AS FactTarifClie,MAX(D.VrCosto) AS FactTarifTerc
FROM Trn_Facturas AS F INNER JOIN Trn_TraFacRemesas AS D ON F.TipDoc=D.TipDoc AND F.Factura=D.Factura AND F.IdCia=D.IdCia
WHERE F.Anulado=0 GROUP BY F.TipDoc,F.Factura,F.IdCia,D.TipRem,D.Remesa,D.IdCiaRem,F.IdCliente,F.Fecha) AS FS ON O.TipFact=FS.TipDoc AND O.NumFactura=FS.Factura AND O.CdCiaFact=FS.IdCia
AND O.TipDoc=FS.TipRem AND O.NumOrden=FS.Remesa AND O.IdCia=FS.IdCiaRem
LEFT JOIN Terceros AS TCF ON FS.FactIdCli=TCF.IdTercero
WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.TipDoc LIKE ISNULL(@pmTipDoc,'%') AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,FecDespacho,FecRecibo,O.IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,NumVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,O.TipoAfiVehic,O.Modalidad,O.VrTotal,O.VrCosto,O.Cantidad AS Cant_Total,VrAnticipo,O.CdRuta,Ruta,O.IdOrigen AS CdOrigen,LO.Localidad AS NomOrigen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino
,TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstCumplido,NumCump,CdCiaCum,EstFactura,TipFact,NumFactura,CdCiaFact
,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,O.NumReferencia,kmtInicial,kmtFinal,Cantkms,EstOrden,TipLiq,NumLiquida,CdCiaLiq,O.CdTarAvta,O.CdTarBom
,O.Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS FechaCrea,O.FecUpdate AS FechaModif,O.IdCiaCrea AS CdCiaCrea,OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
--Detalles
,Item,D.IdMercancia AS CdMercancia,DescripMcia,D.Descripcion,D.Cantidad,D.UndMed,Unidad,D.VrUnitario,D.TarifaPago
,CantCump,TarifaCump,PagoCump,DocCliente
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
--Vehiculo
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_TraOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Trn_TraOrdenDet AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed  INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Mercancias AS MC ON D.IdMercancia=MC.IdMercancia
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
 WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT NumOrden,O.IdCia AS CdCia,Compania,Fecha,FecDespacho,FecRecibo,IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia
,O.IdVehiculo AS PlacaVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,O.TipoAfiVehic,O.Modalidad,VrTotal,VrCosto,Cantidad,VrAnticipo,O.CdRuta,Ruta,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino,LD.Localidad AS Destino
,TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,FecIngCertif,FecCertificado,O.NumReferencia,O.CdTarAvta,O.CdTarBom,NumRemesa,CdCiaRem,EstCumplido,NumCump,CdCiaCum
,EstFactura,TipFact,NumFactura,CdCiaFact,EstOrden,TipLiq,NumLiquida,CdCiaLiq,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,OrigenAdd,O.Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,O.TimeSys AS FechaCrea,O.FecUpdate AS FechaModif,kmtInicial,kmtFinal,Cantkms,O.IdCiaCrea AS CdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
FROM Trn_TraOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado
INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServNov] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=NULL
 AS 
 SELECT O.TipDoc AS IdTipDoc,O.NumOrden AS Num_Orden,O.IdCia AS CdCia,Compania,O.Fecha,FecDespacho,FecRecibo,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,A.Agencia
,O.IdVehiculo AS PlacaVeh,NumVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,O.TipoAfiVehic,O.Modalidad,O.VrTotal,O.VrCosto,O.Cantidad AS Cant_Total,VrAnticipo,O.CdRuta,Ruta,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino
,TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,NomEstacion,TipoResiduo,RemCliente,NomRecibido,FecIngCertif,FecCertificado,NumRemesa,CdCiaRem,EstCumplido,NumCump,CdCiaCum,O.EstFactura,O.TipFact AS OrdTipFac,O.NumFactura AS OrdFactura,O.CdCiaFact
,kmtInicial,kmtFinal,Cantkms,EstOrden,O.TipLiq AS OrdTipLiq,O.NumLiquida AS OrdNumLiquida,O.CdCiaLiq,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,O.NumReferencia,O.Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS FechaCrea
--novedades
,C.Item,C.Descripcion AS Descrpcion,Tarifa,TipoConc,RubroConcep,C.Cantidad AS CantConc,VrUnitario,TarifIva,C.IdConcepto AS CdConcepto,Concepto,CdCuenta,NomCuenta
,NitTercero,TCN.RazonSocial AS NomTercero,C.FechaNov,C.VrBase,C.TipoTarif,C.RefConc,C.Referencia2,C.Referencia3,C.Fijos,C.IncBaseRet,C.Est_Factura,C.TipFact,C.NumFactura,C.CiaFact,C.VrTotalFact,C.Est_Liquida,C.TipLiq,C.NumLiquida,C.CiaLiq,C.VrTotalLiq
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.TelMovil AS TelCelular,T.e_mail AS TercEmail
--Vehiculo
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_TraOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero
 INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraConceptos AS C ON O.TipDoc=C.TipDoc AND O.NumOrden=C.Documento AND O.IdCia=C.IdCia
 LEFT JOIN ConcDiversos AS CDV ON C.IdConcepto=CDV.IdConcepto LEFT JOIN Terceros AS TCN ON C.NitTercero=TCN.IdTercero
 LEFT JOIN Puc AS P ON C.CdCuenta=P.IdCuenta
 LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServOpe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServOpe] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=NULL
AS
SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden AS Num_Orden,O.IdCia AS CdCia,Compania,O.Fecha,T.TipoId AS ClieTipoId,O.IdCliente,T.Dv AS ClieDv,T.RazonSocial AS NomCliente
,O.IdVehiculo AS PlacaVeh,NumVeh,O.TipoAfiVehic,O.Modalidad,TipoOrden,O.VrTotal AS ValorTotal,O.VrCosto AS TotalTercero,O.Cantidad AS CantTotal,O.VrAnticipo
,D.Item,D.IdMercancia AS CdMercancia,D.Descripcion,D.Cantidad,D.UndMed,UM.Unidad,D.VrUnitario,D.TarifaPago,D.DocCliente
,O.IdEstacion AS CdCampo,EstServicio AS NomCampo,O.CdRuta,Ruta,O.IdOrigen AS CdOrigen,LO.Localidad AS NomOrigen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino,O.IdAgencia AS CdAgencia,Agencia
,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,NomEstacion,TipoResiduo,O.RemCliente,NomRecibido,O.NumReferencia,O.FecDespacho,O.FecRecibo,O.FecIngCertif,O.FecCertificado,O.NumRemesa,O.CdCiaRem,kmtInicial,kmtFinal,Cantkms,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,ED.Estado,O.TimeSys AS FechaCrea,O.FecUpdate AS FechaModif,O.IdCiaCrea AS CdCiaCrea,O.IdUsuario AS CdUsuario,Usuario
--cumplido
,EstCumplido,CM.Cumplido AS NumCumplido,CM.IdCia AS CiaCump,CM.Fecha AS FechaCump,CM.DescServicio AS CumpServicio,CM.Observacion AS ObservCump
,CM.IdMercancia AS CdMercanciaCump,CM.Descripcion AS DescripCump,CM.Cantidad AS CantCump,CM.UndMed AS UndMedCump,UMC.Unidad AS UnidadCump,CM.VrUnitario AS TarifCump
,CM.TarifaPago AS TarifPagoCump
--liquidacion
,O.EstOrden,O.TipLiq,O.NumLiquida,O.CdCiaLiq,L.Fecha AS FecLiquida,L.VrTotal AS LiqTotal,L.VrAnticipo AS LiqAnticipo,L.VrIva AS LiqIva,L.VrRetencion AS LiqRetencion
,L.VrReteIca,L.VrReteCREE,L.VrReteIva,L.VrOtros,L.VrDescuento,L.VrNeto,L.Cantidad AS LiqCantidad,L.TarifaPago AS LiqTarifaPago,L.TarifaImp,L.TarifaRet,L.TarifaIca,L.TarifaRiv
,L.Referencia,L.VrGastos,dbo.FuncOsaListaAntcipos(O.NumOrden,O.IdCia) AS Anticipos,L.TipEgr,L.Egreso,L.IdCiaEgr,EG.Fecha AS FecEgreso,EG.NumCheque,EGT.TotalEgresos
--Factura
,O.EstFactura,O.TipFact,O.NumFactura,O.CdCiaFact,FactFecha,FactCant,FactTarifClie,FactTotal,FactIva,FactTarifIVA,FactCosto,FactIdCli,TCF.RazonSocial AS FactNomCliente
--Inf vehiculo
,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,LC.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.TelMovil AS TelCelular,T.e_mail AS TercEmail
--Vehiculo
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdColor AS CdColor,NomColor,Modelo,NumMotor,SerieChasis,NumSerie,NitEmpresa,NE.RazonSocial AS VehNomEmpresa
,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion
FROM Trn_TraOrdenServ AS O INNER JOIN Trn_TraOrdenDet AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed INNER JOIN Localidades AS LC ON T.IdLocal=LC.IdLocal
INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia
LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
LEFT JOIN Trn_TraOrdenLiq AS L ON O.TipLiq=L.TipDoc AND O.NumLiquida=L.Liquidacion AND O.CdCiaLiq=L.IdCia
LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
--Subconsulta cumplido
LEFT JOIN (SELECT C.Cumplido,C.IdCia,C.Fecha,C.TipOds,C.NumOrden,C.IdCiaOds,C.FecDespacho,C.FecRecibo,C.FecIngCertif,C.FecCertificado,C.DescServicio
,C.RemCliente,C.Funcionario,C.Observacion,D.IdMercancia,D.Descripcion,D.Item,D.Cantidad,D.UndMed,D.VrUnitario,D.TarifaPago,D.DocCliente
FROM Trn_TraOrdenCum AS C INNER JOIN Trn_TraOrdenCumDet AS D ON C.TipDoc=D.TipDoc AND C.Cumplido=D.Cumplido AND C.IdCia=D.IdCia
WHERE C.Anulado=0) AS CM ON O.TipDoc=CM.TipOds AND O.NumOrden=CM.NumOrden AND O.IdCia=CM.IdCiaOds AND D.Item=CM.Item
LEFT JOIN Sys_Um AS UMC ON CM.UndMed=UMC.UndMed
--Subconsulta factura
LEFT JOIN (SELECT F.TipDoc,F.Factura,F.IdCia,D.TipRem,D.Remesa,D.IdCiaRem,F.IdCliente AS FactIdCli,F.Fecha AS FactFecha,SUM(D.Cantidad) AS FactCant,SUM(D.VrUnitario*D.Cantidad) AS FactTotal
,SUM(D.VrCosto*D.Cantidad) AS FactCosto,SUM(D.VrImpuesto) AS FactIva,MAX(D.TarifaIva) AS FactTarifIVA,MAX(D.VrUnitario) AS FactTarifClie,MAX(D.VrCosto) AS FactTarifTerc
FROM Trn_Facturas AS F INNER JOIN Trn_TraFacRemesas AS D ON F.TipDoc=D.TipDoc AND F.Factura=D.Factura AND F.IdCia=D.IdCia
WHERE F.Anulado=0 GROUP BY F.TipDoc,F.Factura,F.IdCia,D.TipRem,D.Remesa,D.IdCiaRem,F.IdCliente,F.Fecha) AS FS ON O.TipFact=FS.TipDoc AND O.NumFactura=FS.Factura AND O.CdCiaFact=FS.IdCia
AND O.TipDoc=FS.TipRem AND O.NumOrden=FS.Remesa AND O.IdCia=FS.IdCiaRem
LEFT JOIN Terceros AS TCF ON FS.FactIdCli=TCF.IdTercero
LEFT JOIN Trn_Comprobantes AS EG ON L.TipEgr=EG.TipCom AND L.Egreso=EG.Comprobante AND L.IdCiaEgr=EG.IdCia
LEFT JOIN (SELECT EO.TipOdp AS TipOrden,EO.OrdPago AS NumOPago,EO.IdCiaOdp AS CdCiaOpago,SUM(VrAbonado) AS TotalEgresos
FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EGT ON O.TipLiq=EGT.TipOrden AND O.NumLiquida=EGT.NumOPago AND O.CdCiaLiq=EGT.CdCiaOpago
WHERE O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=NULL
 AS 
 SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden AS Num_Orden,O.IdCia AS CdCia,Compania,O.Fecha,FecDespacho,FecRecibo,O.IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,NumVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,O.TipoAfiVehic,O.Modalidad,O.VrTotal,O.VrCosto,O.Cantidad AS Cant_Total,VrAnticipo,O.CdRuta,Ruta,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino,TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,NomEstacion,TipoResiduo,RemCliente,NomRecibido,FecIngCertif,FecCertificado,O.NumReferencia,NumRemesa,CdCiaRem,EstCumplido,NumCump,CdCiaCum,EstFactura,TipFact,NumFactura,CdCiaFact
,kmtInicial,kmtFinal,Cantkms,EstOrden,TipLiq,NumLiquida,CdCiaLiq,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,O.Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,O.TimeSys AS FechaCrea,O.FecUpdate AS FechaModif,O.IdCiaCrea AS CdCiaCrea,OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.TelMovil AS TelCelular,T.e_mail AS TercEmail
--Vehiculo
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
 FROM Trn_TraOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraOrdenServRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraOrdenServRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=NULL
 AS 
 SELECT O.TipDoc AS IdTipDoc,TipoDoc,O.NumOrden AS Num_Orden,O.IdCia AS CdCia,Compania,O.Fecha,FecDespacho,FecRecibo,O.IdCliente,T.RazonSocial AS NomCliente
,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,NumVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,O.TipoAfiVehic,O.Modalidad,O.VrTotal,O.VrCosto,O.Cantidad AS Cant_Total,VrAnticipo,O.CdRuta,Ruta,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino,TipoOrden,O.IdEstacion AS CdCampo,EstServicio AS NomCampo
,NomEstacion,TipoResiduo,RemCliente,NomRecibido,FecIngCertif,FecCertificado,O.NumReferencia,NumRemesa,CdCiaRem,EstCumplido,NumCump,CdCiaCum,EstFactura,TipFact,NumFactura,CdCiaFact
,kmtInicial,kmtFinal,Cantkms,EstOrden,TipLiq,NumLiquida,CdCiaLiq,NumAprob,IdCiaApr,FecAprob,UsuAprob,ObservAprob,O.Anulado,FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado
,O.TimeSys AS FechaCrea,O.FecUpdate AS FechaModif,O.IdCiaCrea AS CdCiaCrea,OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
--Cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad
,T.Telefono AS TercTelefono,T.TelMovil AS TelCelular,T.e_mail AS TercEmail
--Vehiculo
,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
--detalles
,Item,D.IdMercancia AS CdMercancia,DescripMcia,D.Descripcion,D.Cantidad,D.UndMed,Unidad,D.VrUnitario,D.TarifaPago
,CantCump,TarifaCump,PagoCump,DocCliente
 FROM Trn_TraOrdenServ AS O INNER JOIN Companias AS CN ON O.IdCia=CN.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero
 INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero INNER JOIN EdsServicio AS E ON O.IdEstacion=E.IdEstacion
 INNER JOIN EstadoDoc AS ED ON O.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 INNER JOIN Trn_TraOrdenDet AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN Sys_Um AS UM ON D.UndMed=UM.UndMed 
 LEFT JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN TercCndtores AS CT ON O.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia  LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal
 LEFT JOIN Mercancias AS MC ON D.IdMercancia=MC.IdMercancia
 LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Rutas AS RT ON O.CdRuta=RT.IdRuta
 WHERE O.TipDoc=@pmTipDoc AND O.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND O.IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedAnexo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPedAnexo] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Pedido,IdCia,NomCliente,NomRemite,NomDestino,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,PolizaEsp,NumPolizaEsp
,NitCiaPoliza,NomCiaPoliza,FecVencePol,VrLimiteDesp,Seguros,Cargue,Descargue,CdTipoEsc,NitSIA,NombreSIA,ContactoSIA,TelContacSIA,IdLocCont,PatioCont,CdTipoVeh,TipoMargen,MargenFalt,EmbAdicional
,TipoRuta,TipoTrans,Embarque,CdTipCarga,DevContenedor,UndCalcFalt,TarifFaltPago,TarifFaltCobro,CdRutaTarif,TipoServicio,CodTipoOper
 FROM Trn_TraPedAnexo
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Pedido,IdCia,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,IdAgencia,IdClieFact,IdRemitente,IdDestinatario,IdLocOrigen,IdLocDestino,IdVend,IdTarifCom,Modalidad,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor
,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,VrDeclarado,VrSeguro,Cantidad,CantDesp,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac,OrigenAdd,Anulado
,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraPedido
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPedidoFmt] @pmTipDoc VARCHAR(3),@pmPedidoIni INT,@pmPedidoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT P.TipDoc AS CdTipDoc,TipoDoc,P.Pedido AS NumPedido,P.IdCia AS CdCia,Compania,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli,P.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,IdLocDestino,CD.Localidad AS CiuDestino
,LugarCargue,LugarDescargue,P.IdVend AS CdVend,VN.RazonSocial AS Vendedor,Modalidad,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos
,P.VrDeclarado AS ValDeclarado,P.VrSeguro AS ValSeguro,P.Cantidad AS CantTotal,CantDesp,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac
,Anulado,FecDev,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS CdUsuario,Usuario,Leyenda
--datos de anexo
,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,PolizaEsp,NumPolizaEsp,NitCiaPoliza,NomCiaPoliza,FecVencePol,VrLimiteDesp,Seguros,Cargue,Descargue,CdTipoEsc,NitSIA,NombreSIA,ContactoSIA,TelContacSIA
,IdLocCont,LC.Localidad AS CiudadCont,PatioCont,CdTipoVeh,TipoVehiculo,TipoMargen,MargenFalt,EmbAdicional,TipoRuta,TipoTrans,Embarque,CdTipCarga,TipoCarga,DevContenedor,UndCalcFalt,TarifFaltPago,TarifFaltCobro,CdRutaTarif,TipoServicio
--datos de mcias
,Item,D.IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUm,UMP.Unidad AS UmPeso,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,Cases,Cajas,Palets,Remitente,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,TarifClie,TarifPago,TarifTabla,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,TarifSeguro,Referencia1,Referencia2,Contenedor1,Contenedor2
,NitRemite,NitDestntario,UndTarifa,UndTarifPago,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango,CodigoUN
--Datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
 FROM  Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc  AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
 INNER JOIN Trn_TraPedMcias AS D ON P.TipDoc=D.TipDoc AND P.Pedido=D.Pedido AND P.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero 
 INNER JOIN TercCliente AS CLI ON P.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  INNER JOIN Sys_TiposDoc AS TD ON P.TipDoc=TD.IdDoc
 INNER JOIN Localidades AS CO ON P.IdLocOrigen=CO.IdLocal INNER JOIN Localidades AS CD ON P.IdLocDestino=CD.IdLocal
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN Mercancias AS MC ON D.IdMercancia=MC.IdMercancia
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia  
 LEFT JOIN Agencias AS A ON P.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LC ON PA.IdLocCont=LC.IdLocal LEFT JOIN TiposVeh AS TV ON PA.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN TiposCarga AS TCG ON PA.CdTipCarga=TCG.IdTipCarga
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango
 WHERE P.TipDoc=@pmTipDoc AND P.Pedido BETWEEN @pmPedidoIni AND @pmPedidoFin AND P.IdCia=@pmIdCia
 ORDER BY P.Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPedidoLta]  @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT P.Pedido AS NumPedido,P.IdCia AS CdCia,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,NomCliente,P.IdAgencia AS Id_Agencia,Agencia,IdClieFact,CF.RazonSocial AS ClienteFact,IdRemitente,NomRemite,IdLocOrigen,LO.Localidad AS CiudadOrigen,LugarCargue
,NomContacto,TelContacto,emlContacto,IdDestinatario,NomDestino,IdLocDestino,LD.Localidad AS CiudadDestino,LugarDescargue,ContacDestino,TelContacDest,emlContacDest,P.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,IdTarifCom,Modalidad
,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,VrDeclarado,VrSeguro,Cantidad,CantDesp,Cantidad-CantDesp AS CantPendiente
,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac,OrigenAdd,Anulado
,FecDev,CdRutaTarif,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS CdUsuario,Usuario
--anexo
 FROM Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc  AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  INNER JOIN Agencias AS A ON P.IdAgencia=A.IdAgencia
 INNER JOIN Localidades AS LO ON P.IdLocOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON P.IdLocDestino=LD.IdLocal
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS CF ON P.IdClieFact=CF.IdTercero
 WHERE P.TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY P.IdCia,P.Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPedidoRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT P.TipDoc AS CdTipDoc,P.Pedido AS NumPedido,P.IdCia AS CdCia,Compania,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli,P.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,LugarCargue,LugarDescargue,P.IdVend AS CdVend,VN.RazonSocial AS Vendedor,Modalidad,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos
,P.VrDeclarado AS ValDeclarado,P.VrSeguro AS ValSeguro,P.Cantidad AS CantTotal,CantDesp,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac
,Anulado,FecDev,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS CdUsuario,Usuario
--datos de anexo
,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,PolizaEsp,NumPolizaEsp,NitCiaPoliza,NomCiaPoliza,FecVencePol,VrLimiteDesp,Seguros,Cargue,Descargue,CdTipoEsc,NitSIA,NombreSIA,ContactoSIA,TelContacSIA
,IdLocCont,LC.Localidad AS CiudadCont,PatioCont,CdTipoVeh,TipoVehiculo,TipoMargen,MargenFalt,EmbAdicional,TipoRuta,TipoTrans,TipoServicio,Embarque,CdTipCarga,TipoCarga,DevContenedor,UndCalcFalt,TarifFaltPago,TarifFaltCobro,CdRutaTarif
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
 FROM  Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc  AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero 
 INNER JOIN TercCliente AS CLI ON P.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  
 INNER JOIN Localidades AS CO ON P.IdLocOrigen=CO.IdLocal  INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdLocDestino=CD.IdLocal  INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Agencias AS A ON P.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LC ON PA.IdLocCont=LC.IdLocal LEFT JOIN TiposVeh AS TV ON PA.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN TiposCarga AS TCG ON PA.CdTipCarga=TCG.IdTipCarga
 WHERE P.TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND  @pmFechaFin AND   P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdCliente  LIKE ISNULL(@pmIdCliente,'%') AND P.IdVend LIKE ISNULL(@pmIdVend,'%') AND P.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY P.IdCia,P.Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRelCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPedidoRelCon] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT P.TipDoc AS CdTipDoc,P.Pedido AS NumPedido,P.IdCia AS CdCia,Compania,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli,P.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,LugarCargue,LugarDescargue,P.IdVend AS CdVend,VN.RazonSocial AS Vendedor,Modalidad,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos
,P.VrDeclarado AS ValDeclarado,P.VrSeguro AS ValSeguro,P.Cantidad AS CantTotal,CantDesp,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac
,Anulado,FecDev,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS CdUsuario,Usuario
--datos de anexo
,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,PolizaEsp,NumPolizaEsp,NitCiaPoliza,NomCiaPoliza,FecVencePol,VrLimiteDesp,Seguros,Cargue,Descargue,NitSIA,NombreSIA,ContactoSIA,TelContacSIA
,IdLocCont,LC.Localidad AS CiudadCont,PatioCont,CdTipoVeh,TipoVehiculo,TipoMargen,MargenFalt,EmbAdicional,TipoRuta,TipoTrans,Embarque,CdTipCarga,TipoCarga,TipoServicio,DevContenedor,UndCalcFalt,TarifFaltPago,TarifFaltCobro,CdRutaTarif
--conceptos
,Item,Descripcion,Tarifa,TipoConc,RubroConcep,CT.Cantidad AS Cant,VrUnitario,TarifIva,CT.IdConcepto AS CdConcTrans,Concepto,CdCuenta,NomCuenta,NitTercero,NTE.RazonSocial AS NomTercero,CT.CdTipoEsc AS CodTipoEsc,TipoEscolta,FechaNov,VrBase,TipoTarif,RefConc
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
 FROM  Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc  AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero 
 INNER JOIN TercCliente AS CLI ON P.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  
 INNER JOIN Localidades AS CO ON P.IdLocOrigen=CO.IdLocal  INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdLocDestino=CD.IdLocal  INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Agencias AS A ON P.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LC ON PA.IdLocCont=LC.IdLocal LEFT JOIN TiposVeh AS TV ON PA.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN TiposCarga AS TCG ON PA.CdTipCarga=TCG.IdTipCarga
 LEFT JOIN  Trn_TraConceptos AS CT ON P.TipDoc=CT.TipDoc AND P.Pedido=CT.Documento AND P.IdCia=CT.IdCia
 LEFT JOIN ConcDiversos AS CV ON CT.IdConcepto=CV.IdConcepto LEFT JOIN Puc AS PU ON CT.CdCuenta=PU.IdCuenta
 LEFT JOIN TiposEsc AS TE ON CT.CdTipoEsc=TE.IdTipoEsc LEFT JOIN Terceros AS NTE ON CT.NitTercero=NTE.IdTercero
 WHERE P.TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND  @pmFechaFin AND   P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdCliente  LIKE ISNULL(@pmIdCliente,'%') AND P.IdVend LIKE ISNULL(@pmIdVend,'%') AND P.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY P.IdCia,P.Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPedidoRelDet]  @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT P.TipDoc AS CdTipDoc,P.Pedido AS NumPedido,P.IdCia AS CdCia,Compania,Fecha,FechaVence,FecDespacho,FecEntrega,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli,P.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,LugarCargue,LugarDescargue,P.IdVend AS CdVend,VN.RazonSocial AS Vendedor,Modalidad,Vigencia,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos
,P.VrDeclarado AS ValDeclarado,P.VrSeguro AS ValSeguro,P.Cantidad AS CantTotal,CantDesp,IdMneda,VrTasa,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,TipOdc,OCargue,IdCiaOdc,FechaOdc,TipRem,Remesa,IdCiaRem,FechaRem,TipFac,Factura,IdCiaFac,FechaFac
,Anulado,FecDev,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,P.IdUsuario AS CdUsuario,Usuario
--detalles
,Item,IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUm,UMP.Unidad AS UmPeso,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,Cases,Cajas,Palets,Remitente,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen
,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,TarifClie,TarifPago,TarifTabla,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,TarifSeguro,Referencia1,Referencia2,Contenedor1,Contenedor2
,NitRemite,NitDestntario,UndTarifa,UndTarifPago,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango
,D.Tipo_Servicio AS TipoServicio,D.CdTipoVehic AS CdTipoVeh,TipoVehiculo
--datos de anexo
,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,PolizaEsp,NumPolizaEsp,NitCiaPoliza,NomCiaPoliza,FecVencePol,VrLimiteDesp,Seguros,Cargue,Descargue,CdTipoEsc,NitSIA,NombreSIA,ContactoSIA,TelContacSIA
,IdLocCont,LC.Localidad AS CiudadCont,PatioCont,TipoMargen,MargenFalt,EmbAdicional,TipoRuta,TipoTrans,Embarque,CdTipCarga,TipoCarga,DevContenedor,UndCalcFalt,TarifFaltPago,TarifFaltCobro,CdRutaTarif
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
 FROM  Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc  AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
 INNER JOIN Trn_TraPedMcias AS D ON P.TipDoc=D.TipDoc AND P.Pedido=D.Pedido AND P.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero 
 INNER JOIN TercCliente AS CLI ON P.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  
 INNER JOIN Localidades AS CO ON P.IdLocOrigen=CO.IdLocal  INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdLocDestino=CD.IdLocal  INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal  INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal 
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia 
 LEFT JOIN Agencias AS A ON P.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LC ON PA.IdLocCont=LC.IdLocal LEFT JOIN TiposVeh AS TV ON D.CdTipoVehic=TV.IdTipoVeh
 LEFT JOIN TiposCarga AS TCG ON PA.CdTipCarga=TCG.IdTipCarga
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango
 WHERE P.TipDoc=@pmTipDoc  AND Fecha BETWEEN @pmFechaIni AND  @pmFechaFin AND   P.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND P.IdCliente  LIKE ISNULL(@pmIdCliente,'%') AND P.IdVend LIKE ISNULL(@pmIdVend,'%') AND P.Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY P.IdCia,P.Pedido
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedidoRem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPedidoRem] @pmTipRem VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT P.TipDoc AS CdTipPed,P.Pedido AS NumPedido,P.IdCia AS CdCia,Compania,Fecha,FechaVence,FecDespacho,FecEntrega,T.TipoId AS TercTipId,IdCliente,T.Dv AS TercDv,T.RazonSocial AS NomCliente
,P.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,P.IdVend AS CdVend,VN.RazonSocial AS Vendedor,Modalidad,Vigencia
,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos
,P.VrDeclarado AS ValDeclarado,P.VrSeguro AS ValSeguro,P.Cantidad AS CantTotal,CantDesp,NumAprob,IdCiaApr,FecAprob
,P.Observacion AS Observ,P.IdEstado AS CdEstado,Estado,P.Anulado AS PedAnulado,TimeSys,P.IdUsuario AS CdUsuario,Usuario
,PolizaEsp,NumPolizaEsp,PA.NitCiaPoliza AS NitCiaPlza,PA.NomCiaPoliza AS NomCiaPlza,PA.FecVencePol AS FecVcePlza,VrLimiteDesp,Seguros,Cargue,Descargue
,IdLocCont,LC.Localidad AS CiudadCont,PatioCont,CdTipoVeh,TV.TipoVehiculo AS TipoVehic,TipoMargen,MargenFalt,EmbAdicional,PA.TipoRuta AS TipRutaPed
,TipoTrans,Embarque,CdTipCarga,TipoCarga,DevContenedor,UndCalcFalt,TarifFaltPago,TarifFaltCobro
,Item,IdMercancia,DescripMcias,D.Cantidad AS CantPed,PesoNeto,D.UndMed AS CdUm,UMP.Unidad AS UmPeso,TarifClie,D.UndTarifa AS UndTarifClie,TarifPago,D.UndTarifPago AS UndTarif_Pago
,TarifTabla,NitRemite,Remitente,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,NitDestntario,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,Referencia1,Referencia2,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,Cases,Cajas,Palets,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,TarifSeguro
,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango
--remesas
,CdTipRem,NumRemesa,CdCiaRem,NomCiaRem,FecRemesa,FecDespRem,FecEntgaRem,PlacaVeh,NumVeh,CdTipVeh,RM.TipoVehiculo AS TipoVehicRem,CedConductor,NomConductor
,nRemolque,TipoAfiVehic,TipoRemesa,NumManif,IdCiaManif,EstCumplido,EstFactura,ManifMintrans,RemMintrans,RM.TipoRuta AS TipoRutaRem,TipoMintrans
,CantRemesa,PesoNetoRem,CdUmPeso,UmPeso,CasesRem,CajasRem,PaletsRem,TarifClieRem,UndTarifRem,TarifPagoRem,TarifTablaRem,UndTarifPagoRem
,NitRemteRem,NomRemteRem,DirOrigenRem,CdCiuOrigRem,CiudadOrigen,CodDepOrigen,DptoOrigen
,NitDtnatario,NomDestnatario,DirDestinoRem,CdDestinoRem,CiudadDestino,CodDepDestino,DptoDestino
,Remision,DocClie,Refencia1,Refencia2,Refencia3,VlmenRem,CdUndVol,DetVrDeclarado,DetVrSeguro,TarifSegRem
,Cumplido,IdCiaCump,FechaCump,RM.TipFac AS TipFact,RM.Factura AS NumFact,RM.IdCiaFac AS CdCiaFact,RM.FechaFac AS FecFact,TarifClieFac,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp
 FROM  Trn_TraPedido AS P INNER JOIN Trn_TraPedAnexo AS PA ON P.TipDoc=PA.TipDoc  AND P.Pedido=PA.Pedido AND P.IdCia=PA.IdCia
 INNER JOIN Trn_TraPedMcias AS D ON P.TipDoc=D.TipDoc AND P.Pedido=D.Pedido AND P.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON P.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON P.IdCliente=T.IdTercero 
 INNER JOIN TercCliente AS CLI ON P.IdCliente=CLI.IdClie  INNER JOIN Terceros AS VN ON P.IdVend=VN.IdTercero  
 INNER JOIN EstadoDoc AS ED ON P.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia 
 LEFT JOIN Agencias AS A ON P.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LC ON PA.IdLocCont=LC.IdLocal LEFT JOIN TiposVeh AS TV ON PA.CdTipoVeh=TV.IdTipoVeh
 LEFT JOIN TiposCarga AS TCG ON PA.CdTipCarga=TCG.IdTipCarga
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango
--consultas de remesas -detalles
 LEFT JOIN (SELECT R.TipDoc AS CdTipRem,R.NumOrden AS NumRemesa,R.IdCia AS CdCiaRem,CN.Compania AS NomCiaRem,R.Fecha AS FecRemesa,R.FecDespacho AS FecDespRem,R.FecEntrega AS FecEntgaRem
 ,R.IdCliente AS NitClieRem,NomCliente,R.IdAgencia AS CdAgeRem,A.Agencia AS NomAgenRem,R.IdVehiculo AS PlacaVeh,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo
 ,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,R.Modalidad AS TipoRemesa,NumPedido,IdCiaPed,NumManif,IdCiaManif,EstCumplido,EstFactura
,TomadorPoliza,PolizaSeguro,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans,TipoRuta,TipoMintrans
 ,D.IdMercancia AS CdMcia,D.DescripMcias AS DescMcia,D.Cantidad AS CantRemesa,D.PesoNeto AS PesoNetoRem,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Cases AS CasesRem,D.Cajas AS CajasRem,D.Palets AS PaletsRem
 ,D.TarifClie AS TarifClieRem,D.UndTarifa AS UndTarifRem,D.TarifPago AS TarifPagoRem,D.TarifTabla AS TarifTablaRem,D.UndTarifPago AS UndTarifPagoRem
 ,D.NitRemite AS NitRemteRem,D.Remitente AS NomRemteRem,D.DirOrigen AS DirOrigenRem,D.IdOrigen AS CdCiuOrigRem,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
 ,D.NitDestntario AS NitDtnatario,D.Destinatario AS NomDestnatario,D.DirDestino AS DirDestinoRem,D.IdDestino AS CdDestinoRem,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
 ,Remision,D.DocCliente AS DocClie,D.Referencia1 AS Refencia1,D.Referencia2 AS Refencia2,D.Referencia3 AS Refencia3,D.Volumen AS VlmenRem,D.UndVol AS CdUndVol,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,D.TarifSeguro AS TarifSegRem
 ,Cumplido,IdCiaCump,FechaCump,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp
 FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON R.TipDoc=D.TipDoc  AND R.NumOrden=D.NumOrden AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia INNER JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed 
 WHERE R.TipDoc=@pmTipRem AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') ) AS RM ON P.Pedido=RM.NumPedido AND P.IdCia=RM.IdCiaPed AND D.IdMercancia=RM.CdMcia
WHERE P.TipDoc='PDT' AND P.Anulado=0  AND P.IdCia  LIKE ISNULL(@pmIdCia ,'%%') AND P.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND P.Modalidad LIKE ISNULL(@pmModalidad,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedMcias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPedMcias] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Pedido,IdCia,Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat,IdMnjo,IdTmcia,CdRango,Cases,Cajas,Palets
,Remitente,DirOrigen,IdOrigen,Destinatario,DirDestino,IdDestino,TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,Referencia1,Referencia2,Contenedor1,Contenedor2
,NitRemite,NitDestntario,UndTarifa,UndTarifPago,DocCliente,Referencia3,CdTipoVehic,Tipo_Servicio,SedeRem,SedeDest,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP
 FROM Trn_TraPedMcias
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPedMciasDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPedMciasDoc] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,D.UndMed AS UndPeso,Cases,Cajas,Palets,TarifClie,UndTarifa,TarifTabla,TarifPago,UndTarifPago,VrDeclarado,VrSeguro,TarifSeguro
,D.IdUnd AS CdUnid,Unidad,Referencia1,Referencia2,Referencia3,DocCliente,NitRemite,Remitente,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen
,NitDestntario,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino
,dmsLargo,dmsAncho,dmsAlto,Volumen,UndVol,Contenedor1,Contenedor2,CdRango,D.IdEmp AS CdEmpaque,Empaque
,IdNat,IdMnjo,IdTmcia,CdTipoVehic,Tipo_Servicio,SedeRem,SedeDest,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP
 FROM Trn_TraPedMcias AS D INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal
 INNER JOIN UndMed AS U ON D.IdUnd=U.IdUnd INNER JOIN Empaques AS E ON D.IdEmp=E.IdEmp
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,FecEmision,FecCargue,FecEntrega,IdOrigen,IdDestino,IdNotificado,Notificado,IdRemitente,Remitente,DirOrigen,IdDestinatario,Destinatario,DirDestino,IdConsig,Consignatario,DirConsig,InsTransporte,DocRemitente
,IdMoneda,ValorTotal,PesoTotal,Manifiesto,CdCiaManif,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,Negociacion,Condic_Pago,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraPorteInt
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteInt_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteInt_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT O.TipDoc,TipoDoc,O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,O.FecCargue,O.FecEntrega,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino,O.IdNotificado,O.Notificado,NF.Telefono AS TelNoti,NF.TelMovil AS MovNoti,O.IdRemitente,O.Remitente,RM.Telefono AS TelRemi,RM.TelMovil AS MovRemi,O.DirOrigen
,O.IdDestinatario,O.Destinatario,DT.Telefono AS TelDest,DT.TelMovil AS MovDest,O.DirDestino,O.IdConsig,O.Consignatario,CS.Telefono AS TelCons,CS.TelMovil AS MovCons,O.DirConsig,O.InsTransporte,O.DocRemitente,O.ValorTotal,M.Simbolo,O.IdMoneda AS CdMoneda,M.Mneda AS Moneda,O.PesoTotal,O.Manifiesto,O.CdCiaManif
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario,O.Negociacion,O.Condic_Pago
,D.Item,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MN.Mneda AS DetMoneda,MN.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad,D.IdEmp AS CdEmp,Empaque
,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.Observacion AS DetObservacion,D.DescripUnid
 FROM Trn_TraPorteInt AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia INNER JOIN Sys_TiposDoc AS TD ON O.TipDoc=TD.IdDoc
 INNER JOIN Trn_TraPorteIntMcia AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MN ON D.IdMoneda=MN.IdMneda  
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat
 INNER JOIN Terceros AS RM ON O.IdRemitente=RM.IdTercero INNER JOIN Terceros AS DT ON O.IdDestinatario=DT.IdTercero
 INNER JOIN Terceros AS NF ON O.IdNotificado=NF.IdTercero INNER JOIN Terceros AS CS ON O.IdConsig=CS.IdTercero
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp
 WHERE O.TipDoc=@pmTipDoc AND O.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND O.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteIntGas_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteIntGas_Cr] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT D.TipDoc,D.NumOrden,D.IdCia AS CdCia,D.Item,D.IdConcepto AS CdConcepto,Concepto,D.MontoRem,D.IdMonRem AS CdMonRem,MR.Mneda AS MonedaRem,MR.Simbolo AS MonSimbRem
,D.MontoDest,D.IdMonDest AS CdMonDest,MD.Mneda AS MonedaDest,MD.Simbolo AS MonSimbDest
 FROM Trn_TraPorteIntGas AS D INNER JOIN ConcDiversos AS C ON D.IdConcepto=C.IdConcepto
 LEFT JOIN adm_monedas AS MR ON D.IdMonRem=MR.IdMneda LEFT JOIN adm_monedas AS MD ON D.IdMonDest=MD.IdMneda
 WHERE D.TipDoc=@pmTipDoc AND D.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND D.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteIntLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteIntLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,O.FecCargue,O.FecEntrega,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino,O.IdNotificado,O.Notificado,O.IdRemitente,O.Remitente,O.DirOrigen
,O.IdDestinatario,O.Destinatario,O.DirDestino,O.IdConsig,O.Consignatario,O.DirConsig,O.InsTransporte,O.DocRemitente,O.ValorTotal,M.Simbolo,O.IdMoneda AS CdMoneda,M.Mneda AS Moneda,O.PesoTotal,O.Manifiesto,O.CdCiaManif
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.Negociacion,O.Condic_Pago,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraPorteInt AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda 
 WHERE O.TipDoc=@pmTipDoc AND O.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPorteIntLtd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPorteIntLtd] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT O.NumOrden,O.IdCia AS CdCia,Compania,O.Fecha,O.FecEmision,O.FecCargue,O.FecEntrega,DPO.IdPais AS CdPaisOrig,POR.NombrePais AS PaisOrig,LO.IdDep AS CdDepOrig,DPO.Departamento AS DptoOrigen,O.IdOrigen,LO.Localidad AS DescOrigen
,DPD.IdPais AS CdPaisDest,PDE.NombrePais AS PaisDestino,LD.IdDep AS CdDepDest,DPD.Departamento AS DptoDestino,O.IdDestino,LD.Localidad AS DescDestino,O.IdNotificado,O.Notificado,O.IdRemitente,O.Remitente,O.DirOrigen
,O.IdDestinatario,O.Destinatario,O.DirDestino,O.IdConsig,O.Consignatario,O.DirConsig,O.InsTransporte,O.DocRemitente,O.ValorTotal,M.Simbolo,O.IdMoneda AS CdMoneda,M.Mneda AS Moneda,O.PesoTotal,O.Manifiesto,O.CdCiaManif
,O.Anulado,O.FecDev,O.Observacion AS Observ,O.IdEstado AS CdEstado,Estado,O.TimeSys AS FechaCrea,O.FecUpdate,O.IdCiaCrea,O.OrigenAdd,O.IdUsuario AS CdUsuario,Usuario,O.Negociacion,O.Condic_Pago
--detalles
,D.Item,D.CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.PesoBruto,D.Volumen,D.ValorMcia,D.IdMoneda AS DetIdMoneda,MN.Mneda AS DetMoneda,MN.Simbolo AS DetMonSimb,D.IdUnd AS CdUnd,UM.Unidad,D.IdEmp AS CdEmp,Empaque
,D.IdNat AS CdNat,Natlzaprod,D.UndMed,UP.Unidad AS DesUndPeso,D.UndVol,UV.Unidad AS DesUndVol,D.Bultos,D.Observacion AS DetObservacion,D.DescripUnid
 FROM Trn_TraPorteInt AS O INNER JOIN Companias AS C ON O.IdCia=C.IdCia
 INNER JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep INNER JOIN adm_Paises AS POR ON DPO.IdPais=POR.IdPais
 INNER JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep INNER JOIN adm_Paises AS PDE ON DPD.IdPais=PDE.IdPais
 INNER JOIN adm_Usuarios AS U ON O.IdUsuario=U.IdUsuario INNER JOIN EstadoDoc AS E ON O.IdEstado=E.IdEstado
 INNER JOIN Trn_TraPorteIntMcia AS D ON O.TipDoc=D.TipDoc AND O.NumOrden=D.NumOrden AND O.IdCia=D.IdCia
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN adm_monedas AS MN ON D.IdMoneda=MN.IdMneda
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat
 LEFT JOIN adm_monedas AS M ON O.IdMoneda=M.IdMneda LEFT JOIN Empaques AS EP ON D.IdEmp=EP.IdEmp 
 LEFT JOIN Sys_Um AS UP ON D.UndMed=UP.UndMed LEFT JOIN Sys_Um AS UV ON D.UndVol=UV.UndMed
 WHERE O.TipDoc=@pmTipDoc AND O.FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND O.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraPresAnt] @pmNumPsto INT
 AS 
 SELECT NumPsto,Fecha,IdOrigen,IdDestino,TipoRuta,CdRuta,FecInicio,FecFinal,VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,CdTipoVeh
,TipoAfilVeh,CdTipoMot,CdCom,CdRango,ValorFijo,Observacion,Inactivo,NitCliente,CdMercancia,TipoServicio,Cantgalones,VrExtralegal,CdTipoCarr
,FechaCrea,FechaAct,IdUsuario
 FROM Trn_TraPresAnt
 WHERE NumPsto=@pmNumPsto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresAntFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPresAntFmt] @pmNumPstoIni INT,@pmNumPstoFin INT
 AS 
 SELECT P.NumPsto AS NumPrespto,Fecha,IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,TipoRuta,CdRuta,Ruta
,FecInicio,FecFinal,P.VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,Catpeaje,CdTipoVeh,TipoVehiculo,TipoAfilVeh,CdTipoMot,TipoMotor
,CdCom,TipoComb,CdRango,DescripRango,ValorFijo,P.Observacion,P.Inactivo AS Inactvo,NitCliente,CL.RazonSocial AS Cliente,CdMercancia,DescripMcia
,CdTipoCarr,TipoCar,P.TipoServicio,Cantgalones,VrExtralegal,FechaCrea,FechaAct,P.IdUsuario AS CdUsuario,Usuario
,D.IdConcepto AS CdConcepto,Concepto,Descripcion,Cantidad,VrUnitario,VrTotal,TipoRubro,CdClase,ClasePeaje,NitTercero,T.RazonSocial,CdTipOper,TipoOperacion
 FROM Trn_TraPresAnt AS P INNER JOIN Trn_TraPresItems AS D ON P.NumPsto=D.NumPsto
 INNER JOIN Localidades AS CO ON  P.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Rutas AS R ON P.CdRuta=R.IdRuta LEFT JOIN TiposVeh AS TV ON P.CdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN PeajesCat AS CP ON P.CdCat=CP.IdCat LEFT JOIN TiposMot AS TM ON P.CdTipoMot=TM.IdTipoMot
 LEFT JOIN TiposFuel AS TF ON P.CdCom=TF.IdCom LEFT JOIN RangosPeso AS RP ON P.CdRango=RP.IdRango
 LEFT JOIN ConcDiversos AS C ON D.IdConcepto=C.IdConcepto LEFT JOIN PeajesClase AS PC ON D.CdClase=PC.IdClase
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN TiposOperac AS TP ON D.CdTipOper=TP.IdTipoOper
 LEFT JOIN Terceros AS CL ON P.NitCliente=CL.IdTercero LEFT JOIN Mercancias AS MC ON P.CdMercancia=MC.IdMercancia
 LEFT JOIN TiposCar AS TCA ON P.CdTipoCarr=TCA.IdCrceria
 WHERE P.NumPsto BETWEEN @pmNumPstoIni AND @pmNumPstoFin
 ORDER BY P.NumPsto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresAntLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPresAntLta] @pmIdOrigen VARCHAR(8)=Null,@pmIdDestino VARCHAR(8)=Null,@pmTipoAfilVeh VARCHAR(10)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT P.NumPsto AS NumPrespto,Fecha,IdOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,TipoRuta,CdRuta,Ruta
,FecInicio,FecFinal,P.VrGastos,VrComb,VrPeajes,VrAnticipo,CdCat,Catpeaje,CdTipoVeh,TipoVehiculo,TipoAfilVeh,CdTipoMot,TipoMotor
,CdCom,TipoComb,CdRango,DescripRango,ValorFijo,P.Observacion,P.Inactivo AS Inactvo,NitCliente,CL.RazonSocial AS Cliente,CdMercancia,DescripMcia
,CdTipoCarr,TipoCar,Cantgalones,VrExtralegal,FechaCrea,FechaAct,P.IdUsuario AS CdUsuario,Usuario
,D.IdConcepto AS CdConcepto,Concepto,Descripcion,Cantidad,VrUnitario,VrTotal,TipoRubro,CdClase,ClasePeaje,NitTercero,T.RazonSocial,CdTipOper,TipoOperacion
 FROM Trn_TraPresAnt AS P INNER JOIN Trn_TraPresItems AS D ON P.NumPsto=D.NumPsto
 INNER JOIN Localidades AS CO ON  P.IdOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON P.IdDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN Rutas AS R ON P.CdRuta=R.IdRuta LEFT JOIN TiposVeh AS TV ON P.CdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN PeajesCat AS CP ON P.CdCat=CP.IdCat LEFT JOIN TiposMot AS TM ON P.CdTipoMot=TM.IdTipoMot
 LEFT JOIN TiposFuel AS TF ON P.CdCom=TF.IdCom LEFT JOIN RangosPeso AS RP ON P.CdRango=RP.IdRango
 LEFT JOIN ConcDiversos AS C ON D.IdConcepto=C.IdConcepto LEFT JOIN PeajesClase AS PC ON D.CdClase=PC.IdClase
 LEFT JOIN Terceros AS T ON D.NitTercero=T.IdTercero LEFT JOIN TiposOperac AS TP ON D.CdTipOper=TP.IdTipoOper
 LEFT JOIN Terceros AS CL ON P.NitCliente=CL.IdTercero LEFT JOIN Mercancias AS MC ON P.CdMercancia=MC.IdMercancia
 LEFT JOIN TiposCar AS TCA ON P.CdTipoCarr=TCA.IdCrceria
 WHERE IdOrigen LIKE ISNULL(@pmIdOrigen,'%') AND IdDestino LIKE ISNULL(@pmIdDestino,'%') AND TipoAfilVeh LIKE ISNULL(@pmTipoAfilVeh,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY P.NumPsto
GO
/****** Object:  StoredProcedure [dbo].[paQryTraPresItems]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraPresItems] @pmNumPsto INT
 AS 
 SELECT NumPsto,Item,IdConcepto,Descripcion,Cantidad,VrUnitario,VrTotal,TipoRubro,CdClase,NitTercero,CdTipOper
 FROM Trn_TraPresItems
 WHERE NumPsto=@pmNumPsto
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraReexpedido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraReexpedido] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Causacion,IdCia,Fecha,IdConcepto,IdEmpTrans,NumFactura,FecFactura,FecVence,VrTotal,VrImpuesto,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto
,PesoTotal,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,CodTarImp,CodTarRet,CodTarIca,Referencia,CxPagar,CdPlazo,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_TraReexpedido
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraReexpedidoFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraReexpedidoFmt] @pmTipDoc VARCHAR(3),@pmCausacionIni INT,@pmCausacionFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT C.Causacion AS NumCausac,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CdConcepto,Concepto,IdEmpTrans,T.RazonSocial AS NomEmpresa,NumFactura,FecFactura,FecVence,VrTotal,VrImpuesto
,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto,PesoTotal,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,CodTarImp
,CodTarRet,CodTarIca,Referencia,CxPagar,CdPlazo,Plazo,NVmto,TipCom,TipoCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,C.Observacion AS Observ,C.IdEstado AS CdEstado
--detalles
,Item,TipRem,Remesa,IdCiaRem,FecRemesa,Descripcion,Unidades,PesoNeto,D.UndMed AS CdUmed,UMP.Unidad AS UmPeso,Volumen,UndVol,UndTarifa,VrUnitario,ValorTotal
,pVehiculo,CedConductor,CDT.RazonSocial AS NomConductor
,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario,C.TipDoc AS CdTipDoc,TipoDoc,Leyenda
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM Trn_TraReexpedido AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN Terceros AS T ON C.IdEmpTrans=T.IdTercero INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 INNER JOIN Sys_TiposDoc AS TD ON C.TipDoc=TD.IdDoc INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN Trn_TraReexpedidoRem AS D ON C.TipDoc=D.TipDoc AND C.Causacion=D.Causacion  AND C.IdCia=D.IdCia
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN Plazos AS PZ ON C.CdPlazo=PZ.IdPlazo  LEFT JOIN TiposCom AS TCM ON C.TipCom=TCM.IdCom
 LEFT JOIN Terceros AS  CDT ON D.CedConductor=CDT.IdTercero 
 WHERE C.TipDoc=@pmTipDoc   AND C.Causacion BETWEEN @pmCausacionIni AND @pmCausacionFin  AND C.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraReexpedidoLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraReexpedidoLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdEmpTrans VARCHAR(16)=Null
 AS 
 SELECT  Causacion,C.IdCia AS CdCia,Compania,Fecha,C.IdConcepto AS CdConcepto,Concepto,IdEmpTrans,RazonSocial,NumFactura,FecFactura,FecVence,VrTotal,VrImpuesto
,VrRetencion,VrReteIca,VrOtrosCargos,VrOtrosDctos,VrNeto,PesoTotal,BaseImp,BaseRet,BaseIca,TarifaImp,TarifaRet,TarifaIca,CodTarImp
,CodTarRet,CodTarIca,Referencia,CxPagar,CdPlazo,Plazo,NVmto,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev
,C.Observacion AS Observ,C.IdEstado AS CdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,C.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraReexpedido AS C  INNER JOIN Companias AS CI ON C.IdCia=CI.IdCia INNER JOIN Conceptos AS CN ON C.IdConcepto=CN.IdConcepto
 INNER JOIN Terceros AS T ON C.IdEmpTrans=T.IdTercero INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 LEFT JOIN Plazos AS PZ ON C.CdPlazo=PZ.IdPlazo  
 WHERE C.TipDoc=@pmTipDoc   AND C.Fecha BETWEEN @pmFechaIni AND @pmFechaFin  AND C.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND  C.IdEmpTrans LIKE ISNULL(@pmIdEmpTrans,'%')
 ORDER BY C.IdCia,C.Causacion
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemAnexo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemAnexo] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,IdVend,IdTarifCom,NomCliente,NomRemite,NomDestino,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino
,TelContacDest,emlContacDest,TomadorPoliza,PolizaSeguro,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans,TipSal,NumSalida,IdCiaSal,NumInvent,IdCiaInv
,TipoRuta,TipoMintrans,NitEmpTransp,NumFactEmp,MvoAnulacion,PactoCargue,HorasPactoCargue,MinPactoCargue,HoraCitaCargue,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue
,PactoDescargue,HorasPactoDescargue,MinPactoDescargue,HoraCitaDescargue,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue,TipoDevRemesa,CodCiuTransb,MvoTransbordo,CantViajes,TipOrdMud,ItemOsm
,RemMTEstado,Rem_Descr_Prod,Rem_FecchaReg,PolizaMerPel,TipoConsolida
 FROM Trn_TraRemAnexo
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCancelaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemCancelaLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT CR.Fecha,CR.TipDoc AS TipFac,CR.Factura,CR.IdCia AS CdCiaFac,CF.Compania AS CiaFactura,CR.TipRem,CR.Remesa,CR.IdCiaRem,CN.Compania AS CiaRemesa,CR.Item
,D.IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,Volumen,UndVol,NitRemite,Remitente,NitDestntario,Destinatario
,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,TarifClie,UndTarifa,TarifPago,UndTarifPago,D.Remision,DocCliente,Referencia1,Referencia2,Referencia3
,R.Fecha AS FecRemesa,R.FecDespacho,R.IdCliente,T.RazonSocial AS NombreCliente,R.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia
,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,R.nRemolque,R.TipoAfiVehic,R.Modalidad
,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,Cumplido,IdCiaCump,FechaCump,DetalleCump
,TipOdp,NumeroOdp,IdCiaOdp,EstFactura,Anulado,FecDev,R.Observacion AS RemObserv,CR.Observacion,CR.IdUsuario AS CdUsuario,Usuario,CR.FechaCrea,CR.Id
FROM Trn_TraRemCancela AS CR INNER JOIN Companias AS CN ON CR.IdCiaRem=CN.IdCia INNER JOIN adm_Usuarios AS U ON CR.IdUsuario=U.IdUsuario
INNER JOIN Trn_TraRemesa AS R ON CR.TipRem=R.TipDoc AND CR.Remesa=R.NumOrden AND CR.IdCiaRem=R.IdCia
INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero INNER JOIN Terceros AS CDT ON R.IdConductor=CDT.IdTercero
LEFT JOIN Trn_TraRemMcias AS D ON CR.TipRem=D.TipDoc AND CR.Remesa=D.NumOrden AND CR.IdCiaRem=D.IdCia AND CR.Item=D.Item
LEFT JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
LEFT JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
LEFT JOIN Companias AS CF ON CR.IdCia=CF.IdCia LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
WHERE CR.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND CR.IdCiaRem LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCancelaOst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemCancelaOst] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
 AS 
 SELECT CR.Fecha,CR.TipDoc AS TipFac,CR.Factura,CR.IdCia AS CdCiaFac,CF.Compania AS CiaFactura,CR.TipRem AS TipOds,CR.Remesa AS NumOrden,CR.IdCiaRem AS CdCiaOrden,CN.Compania AS CiaOrden
 ,O.FecDespacho,O.IdCliente,T.RazonSocial AS NomCliente,O.IdAgencia AS CdAgencia,Agencia,O.IdVehiculo AS PlacaVeh,NumVeh,O.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor
,O.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,O.TipoAfiVehic,O.Modalidad,O.VrTotal,O.VrCosto,O.Cantidad AS Cant_Total,VrAnticipo
,O.IdOrigen,LO.Localidad AS Origen,O.IdDestino AS CdDestino,LD.Localidad AS NomDestino,TipoOrden
,TipoResiduo,O.RemCliente,O.NomRecibido,O.NumRemesa,O.CdCiaRem,O.EstCumplido,O.NumCump,O.CdCiaCum,O.EstFactura,O.EstOrden,O.TipLiq,O.NumLiquida,O.CdCiaLiq
,O.Observacion AS OrdenObserv,CR.Observacion,CR.IdUsuario AS CdUsuario,Usuario,CR.FechaCrea,CR.Id
FROM Trn_TraRemCancela AS CR INNER JOIN Companias AS CN ON CR.IdCiaRem=CN.IdCia INNER JOIN adm_Usuarios AS U ON CR.IdUsuario=U.IdUsuario
INNER JOIN Trn_TraOrdenServ AS O ON CR.TipRem=O.TipDoc AND CR.Remesa=O.NumOrden AND CR.IdCiaRem=O.IdCia
INNER JOIN Terceros AS T ON O.IdCliente=T.IdTercero INNER JOIN Terceros AS CDT ON O.IdConductor=CDT.IdTercero
INNER JOIN Terceros AS NP ON O.IdPoseedor=NP.IdTercero INNER JOIN Vehiculos AS V ON O.IdVehiculo=V.IdVehiculo
LEFT JOIN Localidades AS LO ON O.IdOrigen=LO.IdLocal LEFT JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
LEFT JOIN Localidades AS LD ON O.IdDestino=LD.IdLocal LEFT JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
LEFT JOIN Companias AS CF ON CR.IdCia=CF.IdCia LEFT JOIN Agencias AS A ON O.IdAgencia=A.IdAgencia
WHERE CR.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND CR.IdCiaRem LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCntdor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemCntdor] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Item,IdTipoCon,NumContdor,PesoNeto,IdTipoPre,NumPrecinto,ColorPrecinto,Sellos,Peligroso,Perecedero,Toxico,Inflamable,Difmanejo,Fragil
,DevCont,CdLocCont,PatioCont,Observacion,NumSalidaSello,CdCiaSalSello,ItemSalSello,CdProdSalida,NumSerialSello,NumComodato,FecVenceCom
 FROM Trn_TraRemCntdor
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemCntdorFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraRemCntdorFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Item,C.IdTipoCon AS CdTipoCon,TipoContndor,NumContdor,PesoNeto,C.IdTipoPre AS CdTipoPrec,Precinto,NumPrecinto,ColorPrecinto,Sellos
,Peligroso,Perecedero,Toxico,Inflamable,Difmanejo,Fragil,DevCont,CdLocCont,Localidad,PatioCont,C.Observacion,NumSalidaSello,CdCiaSalSello,ItemSalSello
,CdProdSalida,NumSerialSello,NumComodato,FecVenceCom
 FROM Trn_TraRemCntdor AS C INNER JOIN TiposCnd AS TC ON C.IdTipoCon=TC.IdTipoCon
 INNER JOIN TiposPcnto AS TP ON C.IdTipoPre=TP.IdTipoPre
 LEFT JOIN Localidades AS L ON C.CdLocCont=L.IdLocal
 WHERE TipDoc=@pmTipDoc AND NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND IdCia=@pmIdCia
 ORDER BY  NumOrden
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesa] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,IdAgencia,IdClieFact,IdRemitente,IdDestinatario,IdLocOrigen,IdLocDestino,IdLocFletes,IdVehiculo,IdConductor,nRemolque,TipoAfiVehic,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue
,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,VrDeclarado,VrSeguro,Cantidad,PesoTotal,Items,IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,CdRutaTarif
,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac,CdBodega,TipCom,Comprobante,IdCiaCom,VrTray_Vacio1,VrTray_Vacio2,OrigenAdd,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VigenciaOdc
 FROM Trn_TraRemesa
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaCnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaCnt] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
AS 
 SELECT R.TipDoc AS CdTipDoc,R.NumOrden AS Num_Orden,R.IdCia AS CdCia,Compania,R.Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,NomCliente,T.RazonSocial
,R.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,IdLocFletes,CF.Localidad AS LugarFletes,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic
--Datos de contendor
,CN.Item,CN.IdTipoCon AS CdTipoCon,TipoContndor,NumContdor,CN.IdTipoPre AS CdTipoPrec,Precinto,NumPrecinto,ColorPrecinto,Sellos,Peligroso,Perecedero,Toxico,Inflamable,Difmanejo,Fragil
,DevCont,CdLocCont,LD.Localidad,PatioCont,CN.Observacion,NumSalidaSello,CdCiaSalSello,ItemSalSello,CN.CdProdSalida,CN.NumSerialSello,CN.NumComodato,CN.FecVenceCom
,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,R.VrDeclarado AS ValDeclarado,R.VrSeguro AS ValSeguro,R.Cantidad AS CantTotal,PesoTotal
,R.IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,Concepto,CdRutaTarif,TipCom,Comprobante,IdCiaCom,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac
,Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS CdUsuario,Usuario
,RA.IdVend AS CdVend,VN.RazonSocial AS Vendedor,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,TomadorPoliza,PolizaSeguro
,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans,TipSal,NumSalida,IdCiaSal,TipoRuta,TipoMintrans,CdBodega 
--Datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,V.IdGrupo AS CdGrupoPro,GrupoProp
 FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Companias AS CI ON R.IdCia=CI.IdCia INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Localidades AS CF ON R.IdLocFletes=CF.IdLocal  INNER JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero  LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN  Conceptos AS C ON R.CdConcepto=C.IdConcepto
 LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Trn_TraRemCntdor AS CN ON R.TipDoc=CN.TipDoc AND R.NumOrden=CN.NumOrden AND R.IdCia=CN.IdCia
 LEFT JOIN TiposCnd AS TCN ON CN.IdTipoCon=TCN.IdTipoCon LEFT JOIN TiposPcnto AS TPC ON CN.IdTipoPre=TPC.IdTipoPre
 LEFT JOIN Localidades AS LD ON CN.CdLocCont=LD.IdLocal
 WHERE R.TipDoc=@pmTipDoc AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaFac]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT FR.TipDoc AS CdTipDoc,TipoDoc,Factura,FR.IdCia AS CdCia,CN.Compania AS NomCiaFact,FechaFact,Item,TipoReg,TipRem,Remesa,IdCiaRem,CR.Compania AS NomCiaRem,ItemRem,FecRemesa,FR.Descripcion AS DescripRem
,FR.Cantidad AS CantFact,VrUnitario,UndTarifa,VrCosto,UndCosto,CantPago,TarifaDct,VrDescuento,TarifaIva,VrImpuesto,TarifaRet,VrRetencion,TarifaIca,VrReteIca,VrFaltante,CantidadFalt,UnidadFalt,Unidades,PesoNeto,FR.UndMed AS CdUmPeso,Unidad
,Volumen,UndVol,Cases,Cajas,Palets,FR.CdConcepto AS CdConcept,CDV.Concepto AS DescConcept,CdMercancia,DescripMcia,CdAgencia,Agencia,CdCCosto,CCosto,FR.CdSubCos AS CdSubCentro,SubCosto,FR.TipoAfiVehic AS TipoAfiVeh,pVehiculo
,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,Remision,DocCliente,Referencia1,Referencia2,Referencia3,FR.Anulado AS FacAnulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,NumPedRem,CiaPedRem,RemTransb,CostoAdicTbdo
--datos de remesa
,Modalidad,IdRemitente,NomRemite,IdDestinatario,NomDestino,R.IdConductor AS RemCedCond,CDT.RazonSocial AS RemConductor,nRemolque,NumManif,IdCiaManif,R.Observacion AS RemObserv,RA.TipoRuta,RA.TipoMintrans
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo
--datos de factura encabezados
,FacCdConc,CF.Concepto AS FacConcepto,T.TipoId AS TercTipo,FacNitClie,T.Dv AS TercDv,T.RazonSocial AS NombreClie,FacNitVend,VN.RazonSocial AS Vendedor,FacCdCiudad,LF.Localidad AS FacCiudad,LF.IdDep AS FacCdDpto,DF.Departamento AS FacDpto,FacVrNeto
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
 FROM Trn_TraFacRemesas AS FR INNER JOIN Sys_TiposDoc AS TD ON FR.TipDoc=TD.IdDoc INNER JOIN Companias AS CN ON FR.IdCia=CN.IdCia 
 INNER JOIN Localidades AS LO ON FR.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON FR.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 --SUBQUERY FACTURAS
 INNER JOIN (SELECT F.TipDoc AS FacTipo,F.Factura AS FacNumero,F.IdCia AS FacCdCia,F.IdConcepto AS FacCdConc,F.IdCliente AS FacNitClie,F.IdAgencia AS FacIdAgenc
 ,F.IdVend AS FacNitVend,F.IdLocEnv AS FacCdCiudad,F.VrCargos AS FacVrCargos,F.VrOtrDcto AS FacVrOtrDctos,F.VrNeto AS FacVrNeto
 FROM Trn_Facturas AS F WHERE F.Fecha BETWEEN @pmFechaIni  AND @pmFechaFin AND  F.Modalidad='TRANSPORTE'  AND F.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND F.IdCliente LIKE ISNULL(@pmIdCliente,'%')
 UNION ALL
 SELECT D.TipDev,D.Devolucion,D.IdCia,D.IdConcepto,D.IdCliente,D.IdAgencia,D.IdVend,D.IdLocEnv,D.VrCargos,D.VrOtrDcto,D.VrNeto
 FROM Trn_DevFcr AS D WHERE D.Fecha BETWEEN @pmFechaIni  AND @pmFechaFin AND D.Modalidad='TRANSPORTE' AND D.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND D.IdCliente LIKE ISNULL(@pmIdCliente,'%') 
 UNION ALL
 SELECT N.TipDoc,N.NumNota,N.IdCia,N.IdConcepto,N.IdCliente,N.IdAgencia,N.IdVend,N.IdLocal,N.VrOtros,0,N.VrNeto
 FROM Trn_Notas AS N WHERE N.Fecha BETWEEN @pmFechaIni  AND @pmFechaFin AND N.Modalidad='REMESAS' AND  N.IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND N.IdCliente LIKE ISNULL(@pmIdCliente,'%')  ) AS F ON FR.TipDoc=F.FacTipo AND FR.Factura=F.FacNumero AND FR.IdCia=F.FacCdCia
 INNER JOIN Terceros AS T ON F.FacNitClie=T.IdTercero INNER JOIN TercCliente AS CLI ON F.FacNitClie=CLI.IdClie
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona  INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona 
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Terceros AS VN ON F.FacNitVend=VN.IdTercero INNER JOIN Conceptos AS CF ON F.FacCdConc=CF.IdConcepto
 LEFT JOIN Localidades AS LF ON F.FacCdCiudad=LF.IdLocal LEFT JOIN Departamentos AS DF ON LF.IdDep=DF.IdDep
 LEFT JOIN Companias AS CR ON FR.IdCiaRem=CR.IdCia  LEFT JOIN Sys_Um AS UMP ON FR.UndMed=UMP.UndMed
 LEFT JOIN ConcDiversos AS CDV ON FR.CdConcepto=CDV.IdConcepto  LEFT JOIN Agencias  AS A ON FR.CdAgencia=A.IdAgencia
 LEFT JOIN CentroCosto AS CC ON FR.CdCCosto=CC.IdCCosto  LEFT JOIN SubCentros AS SC ON FR.CdSubCos=SC.IdSubCos
 LEFT JOIN Trn_TraRemesa AS R ON FR.TipRem=R.TipDoc AND FR.Remesa=R.NumOrden AND FR.IdCiaRem=R.IdCia
 LEFT JOIN Trn_TraRemAnexo AS RA ON FR.TipRem=RA.TipDoc AND FR.Remesa=RA.NumOrden AND FR.IdCiaRem=RA.IdCia
 LEFT JOIN Terceros AS CDT ON R.IdConductor=CDT.IdTercero
 LEFT JOIN Vehiculos AS V ON FR.pVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 LEFT JOIN Mercancias AS MC ON FR.CdMercancia=MC.IdMercancia
 WHERE FR.FechaFact BETWEEN @pmFechaIni AND @pmFechaFin AND FR.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND F.FacNitClie LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaFmt] @pmTipDoc VARCHAR(3),@pmNumOrdenIni INT,@pmNumOrdenFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT R.TipDoc AS CdTipDoc,TipoDoc,R.NumOrden AS Num_Orden,R.IdCia AS CdCia,CN.Compania,R.Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli
,R.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,IdLocDestino,CD.Localidad AS CiuDestino
,IdLocFletes,CF.Localidad AS LugarFletes,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue
,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,R.VrDeclarado AS ValDeclarado,R.VrSeguro AS ValSeguro,R.Cantidad AS CantTotal,PesoTotal,Items,IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed
,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,Concepto,CdRutaTarif,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac,TipCom,TipoCom,Comprobante,IdCiaCom
,Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS CdUsuario,Usuario,Leyenda
,R.VrTray_Vacio1,R.VrTray_Vacio2,RA.IdVend AS CdVend,VN.RazonSocial AS Vendedor,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,TomadorPoliza,PolizaSeguro,RA.CantViajes
,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans,RA.RemMTEstado,RA.Rem_FecchaReg,RA.Rem_Descr_Prod,TipSal,NumSalida,IdCiaSal,TipOrdMud,NumInvent,IdCiaInv,TipoRuta,TipoMintrans,NitEmpTransp,NumFactEmp,CdBodega,Bodega,RA.TipoDevRemesa,RA.CodCiuTransb,LT.Localidad AS CiudadTransb,RA.MvoTransbordo
,PactoCargue,HorasPactoCargue,MinPactoCargue,HoraCitaCargue,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue,PactoDescargue,HorasPactoDescargue,MinPactoDescargue,HoraCitaDescargue,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue
--detalle mcias
,Item,D.IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,UMP.CodUMFE,dmsAlto,dmsAncho,dmsLargo,Volumen,D.UndVol,UMV.Unidad AS DescUMVol,UMV.CodUMFE AS CodUMVol,Cases,Cajas,Palets,NitRemite,Remitente
,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,TarifClie,TarifPago,TarifTabla,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3
,Contenedor1,Contenedor2,D.CdAgencia AS DetCdAgencia,DA.Agencia AS DetAgencia,Cumplido,IdCiaCump,FechaCump,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp,PesoCont,TipDocInv,NumDocInv,IdCiaDocInv,ItemDocInv,D.SedeRem,SDR.NomSede AS NomSedeRem,SDR.CoordLat AS CoordLatRem,SDR.CoordLong AS CoordLongRem,D.SedeDest,SDD.NomSede AS NomSedeDest,SDD.CoordLat AS CoordLatDest,SDD.CoordLong AS CoordLongDest
,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango,D.Cod_UN AS CodigoUN,MC.EstadoMcia,RSP.Designacion AS DescResPel,RSP.Clase AS ClaseResPel,RSP.PeligroSec,RSP.GrupoEmb
--Datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,CertJudicial,FecJudicial,VigJudicial,Licencia,CatLicencia,CT.IdLugar AS CdLugar,LugarLic,FecLicencia,VigLicencia
,RA.PolizaMerPel,MP.Vigencia AS MerPelVigencia,MP.NitCompania AS MerPelNit,MP.Compania AS MerPelCompania
 FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON R.TipDoc=D.TipDoc AND R.NumOrden=D.NumOrden AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Sys_TiposDoc AS TD ON R.TipDoc=TD.IdDoc  INNER JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal INNER JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal
 INNER JOIN Localidades AS CF ON R.IdLocFletes=CF.IdLocal  INNER JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia INNER JOIN Mercancias AS MC ON D.IdMercancia=MC.IdMercancia
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero  LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal LEFT JOIN Agencias AS DA ON D.CdAgencia=DA.IdAgencia
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed LEFT JOIN Sys_Um AS UMV ON D.UndVol=UMV.UndMed 
 LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango LEFT JOIN Conceptos AS C ON R.CdConcepto=C.IdConcepto
 LEFT JOIN TiposCom AS TCM ON R.TipCom=TCM.IdCom LEFT JOIN AlmBodegas AS BG ON R.CdBodega=BG.IdBodega
 LEFT JOIN TercCndtores AS CT ON R.IdConductor=CT.IdConductor LEFT JOIN ExpLicencias AS EL ON CT.IdLugar=EL.IdLugar
 LEFT JOIN TercSedes AS SDR ON D.NitRemite=SDR.IdTercero AND D.SedeRem=SDR.IdSede LEFT JOIN TercSedes AS SDD ON D.NitDestntario=SDD.IdTercero AND D.SedeDest=SDD.IdSede
 LEFT JOIN Localidades AS LT ON RA.CodCiuTransb=LT.IdLocal LEFT JOIN ResiduosPeligrosos AS RSP ON MC.CodigoUN=RSP.CodigoUN
 LEFT JOIN Polizas AS MP ON RA.PolizaMerPel=MP.NumPoliza
 WHERE R.TipDoc=@pmTipDoc AND R.NumOrden BETWEEN @pmNumOrdenIni AND @pmNumOrdenFin AND R.IdCia=@pmIdCia
 ORDER BY R.NumOrden
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaLta] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCliente VARCHAR(16)=Null
,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT R.NumOrden AS Num_Orden,R.IdCia AS CdCia,Fecha,HoraLlegada,FecDespacho,FecEntrega,IdCliente,NomCliente,R.IdAgencia AS CdAgencia,Agencia,IdClieFact,CF.RazonSocial AS ClienteFact,IdRemitente,NomRemite,IdLocOrigen,LO.Localidad AS CiudadOrigen,LugarCargue
,NomContacto,TelContacto,emlContacto,IdDestinatario,NomDestino,IdLocDestino,LD.Localidad AS CiudadDestino,LugarDescargue,ContacDestino,TelContacDest,emlContacDest,IdLocFletes,LF.Localidad AS LugarFletes
,IdVehiculo,nRemolque,TipoAfiVehic,IdConductor,NC.RazonSocial AS Conductor,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos
,VrDeclarado,VrSeguro,Cantidad,PesoTotal,Items,IdMneda,VrTasa,RA.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,TipOrdMud,NumInvent,IdCiaInv
,CdConcepto,CdRutaTarif,CdBodega,TipCom,Comprobante,IdCiaCom,OrigenAdd,Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac,VigenciaOdc,RA.CantViajes,PactoCargue,HorasPactoCargue,MinPactoCargue
,HoraCitaCargue,HoraLlegaCargue,HoraEntraCargue,HoraSaleCargue,PactoDescargue,HorasPactoDescargue,MinPactoDescargue,HoraCitaDescargue,HoraLlegaDescargue,HoraEntraDescargue,HoraSaleDescargue,RA.TipoDevRemesa,RA.CodCiuTransb,LT.Localidad AS CiudadTransb,RA.MvoTransbordo
,R.VrTray_Vacio1,R.VrTray_Vacio2,R.TimeSys,R.FecUpdate,R.IdCiaCrea,R.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraRemesa AS R  INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
 INNER JOIN Localidades AS LO ON R.IdLocOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON R.IdLocDestino=LD.IdLocal
 INNER JOIN Localidades AS LF ON R.IdLocFletes=LF.IdLocal  INNER JOIN Terceros AS NC ON R.IdConductor=NC.IdTercero 
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero LEFT JOIN Terceros AS CF ON R.IdClieFact=CF.IdTercero
 LEFT JOIN Localidades AS LT ON RA.CodCiuTransb=LT.IdLocal
 WHERE R.TipDoc=@pmTipDoc AND  Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY R.IdCia,R.NumOrden
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaMuc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaMuc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
SELECT R.TipDoc AS CdTipDoc,R.NumOrden AS NumRemesa,R.IdCia AS CdCia,Compania,R.Fecha AS FecRemesa,FecDespacho,IdCliente,T.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,Agencia
,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,R.TipoAfiVehic AS TipoAfiVeh,R.Modalidad AS TipoRemesa,R.TipDcm AS TipOdc,R.NumDocmto AS nOCargue,R.IdCiaDcm AS CdCiaOdc,R.FechaDcm AS FecOCargue
,EstCumplido,EstFactura,CdConcepto,Concepto,SerieGuia,NumGuia,R.Observacion AS Observ,R.IdEstado AS CdEdstado,RA.TipoRuta,RA.TipoMintrans,RA.TipOrdMud,RA.NumInvent,RA.IdCiaInv AS CdCiaInv,R.nRemolque AS RemRemolque
--detalles
,Item,IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,D.Volumen AS Volmen,UndVol,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,Cases,Cajas,Palets
,NitRemite,Remitente,NitDestntario,Destinatario,DirOrigen,IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,DirDestino,IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,TarifClie,D.TarifPago AS RemTarifPago
,D.TarifTabla AS RemTarifTabla,D.VrDeclarado AS ValDeclarado,D.VrSeguro AS ValSeguro,TarifSeguro,UndTarifa,UndTarifPago
,Remision,DocCliente,Referencia1,Referencia2,Referencia3,Cumplido,IdCiaCump,FechaCump,DetalleCump
,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
--columnas ocultas
--,NumManif,IdCiaManif,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp
--datos del pedido
,NumPedido,IdCiaPed,R.FechaPed AS FecPedido,ModalidadPed
--datos de factura
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,NumFactura,NumDevFact,FacCantidad,FacValorTotal,FacCostoTotal,FacFaltantes,FacPesoNeto
--datos de manifiesto
,TipoMuc,ISNULL(MucNumero,0) AS MucNumero,MucCdCia,FechaMuc,FecDespMuc,MucPlacaVeh,MucCdPoseedor,NP.RazonSocial AS NomPoseedor,MucCdRuta,MucTarifTabla,MucTarifPago,MUC.VrFletes AS VrTotFletes,MUC.VrRetencion AS MucVrRetencion
,MUC.VrReteIca AS MucVrReteIca,MUC.VrDescuento AS MucVrDcto,MUC.VrAnticipo AS MucVrAnticipo,VrAntAdic,MUC.TarifaRet AS MucTarifRet,MUC.TarifaIca AS MucTarifIca
,NumMintrans,EdoMintrans,MucObserv,MucTipOdp,ISNULL(MucOrdPago,0) AS MucOrdPago,MucCdCiaOdp,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,TotalEgresos
,dbo.FuncMucListaAntcipos(ISNULL(MucNumero,0),MucCdCia) AS Anticipos
--datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,V.IdGrupo AS CdGruProp,GP.GrupoProp
,RA.TipoDevRemesa,RA.CodCiuTransb,LT.Localidad AS CiudadTransb,RA.MvoTransbordo
 FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemMcias AS D ON R.TipDoc=D.TipDoc AND R.NumOrden=D.NumOrden AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
 LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Conceptos AS C ON R.CdConcepto=C.IdConcepto 
 LEFT JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 LEFT JOIN Localidades AS LT ON RA.CodCiuTransb=LT.IdLocal
--==== Consulta de pedidos
 LEFT JOIN (SELECT P.TipDoc AS TipoPed,P.Pedido AS nPedido,P.IdCia AS CdCiaPed,P.FecDespacho AS FechaPed,P.IdVend AS CdVend,P.Modalidad AS ModalidadPed
,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,P.Observacion AS PedObserv--,D.IdMercancia AS PedCdMcia,D.DescripMcias AS PedDescMcia
,SUM(D.Cantidad) AS PedCantidad,SUM(D.PesoNeto) AS PedPesoNeto,SUM(D.Volumen) AS PedVolumen,SUM(D.Cases) AS PedCases
,SUM(D.Cajas) AS PedCajas,SUM(D.Palets) AS PedPalets,MAX(D.TarifClie) AS PedTarifClie,MAX(D.TarifPago) AS PedTarifPago
 FROM Trn_TraPedido AS P INNER JOIN Trn_TraPedMcias AS D ON P.TipDoc=D.TipDoc AND P.Pedido=D.Pedido AND P.IdCia=D.IdCia
 WHERE P.TipDoc='PDT' AND P.Anulado=0 GROUP BY P.TipDoc,P.Pedido,P.IdCia,P.FecDespacho,P.IdVend,P.Modalidad,Cotizacion,IdCiaCot,NumAprob,IdCiaApr,FecAprob,P.Observacion--,D.IdMercancia,D.DescripMcias
 ) AS PD ON R.NumPedido=PD.nPedido AND R.IdCiaPed=PD.CdCiaPed --AND D.IdMercancia=PD.PedCdMcia
--==== consulta de facturas-detalles
 LEFT JOIN (SELECT TipRem,Remesa,IdCiaRem,ItemRem,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cantidad*-1 ELSE Cantidad END) AS FacCantidad
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE Cantidad*VrUnitario END) AS FacValorTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN (CantPago*VrCosto)*-1 ELSE CantPago*VrCosto END) AS FacCostoTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Unidades*-1 ELSE Unidades END) AS FacUnidades
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN PesoNeto*-1 ELSE PesoNeto END) AS FacPesoNeto
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Volumen*-1 ELSE Volumen END) AS FacVolumen
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cases*-1 ELSE Cases END) AS FacCases
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cajas*-1 ELSE Cajas END) AS FacCajas
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Palets*-1 ELSE Palets END) AS FacPalets
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN VrFaltante*-1 ELSE VrFaltante END) AS FacFaltantes
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE Factura END) AS NumFactura
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Factura ELSE 0 END) AS NumDevFact
FROM Trn_TraFacRemesas GROUP BY TipRem,Remesa,IdCiaRem,ItemRem) AS RF ON R.TipDoc=RF.TipRem AND R.NumOrden=RF.Remesa AND R.IdCia=RF.IdCiaRem AND D.Item=RF.ItemRem
--==== consulta de manifiestos 
 LEFT JOIN (SELECT RM.TipRem AS MucTipoRem,RM.Remesa AS MucNumRemesa,RM.IdCiaRem AS MucCdCiaRem,RM.ItemRem AS MucItemRem,RM.TipDoc AS TipoMuc,RM.Manifiesto AS MucNumero,RM.IdCia AS MucCdCia
,RM.TarifTabla AS MucTarifTabla,RM.TarifPago AS MucTarifPago,RemMintrans,M.Fecha AS FechaMuc,M.FecDespacho AS FecDespMuc,M.IdRuta AS MucCdRuta,M.IdOrigen AS MucCdOrigen,M.IdDestino AS MucCdDestino,M.IdVehiculo AS MucPlacaVeh
,M.IdConductor AS MucCedCond,M.nRemolque AS MucnRemolque,TipoAfiVehic,M.IdPoseedor AS MucCdPoseedor,VrFletes,VrRetencion,VrReteIca,VrDescuento,VrAnticipo,VrAntAdic,VrNeto,VrPagos
,VrCargos,VrDctos,TarifaFlete,TarifaRet,TarifaIca,NumMintrans,EdoMintrans,M.TipOdp AS MucTipOdp,M.OrdPago AS MucOrdPago,M.IdCiaOdp AS MucCdCiaOdp,M.FechaOdp AS MucFecOdp,M.Observacion AS MucObserv
FROM Trn_TraManifRem AS RM INNER JOIN Trn_TraManifiesto AS M ON RM.TipDoc=M.TipDoc AND RM.Manifiesto=M.Manifiesto AND RM.IdCia=M.IdCia
WHERE M.Anulado=0) AS MUC ON R.TipDoc=MUC.MucTipoRem AND R.NumOrden=MUC.MucNumRemesa AND R.IdCia=MUC.MucCdCiaRem AND D.Item=MUC.MucItemRem
--===== Orden de pago
 LEFT JOIN (SELECT M.TipMuc AS OdpTipMuc,M.Manifiesto AS OdpManif,M.IdCiaMuc AS OdpCdCiaMuc,M.TipDoc AS TipOdp,M.OrdPago AS NumOPago,M.IdCia AS OdpCdCia,OP.Fecha AS FechaOdp
,VrTotalFletes,VrDescuento,VrRetencion,VrReteIca,VrAnticipos,VrFaltantes,VrSeguros,VrFondos,VrAportes,VrOtrosDctos,VrImpuestos,VrEstampilla,VrOtrosPagos,VrNeto
,TarifaTabla,TarifaFlete,UnidTarifa,PesoTotal,Unidades,Volumen,TarifaRet,TarifaIca,TipoLiq,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,Referencia,CantFaltante,UnidadFalt,TolFaltNeto,OP.Observacion AS OdpObserv
 FROM Trn_TraOrdenManif AS M INNER JOIN Trn_TraOrdenPago AS OP ON M.TipDoc=OP.TipDoc AND M.OrdPago=OP.OrdPago AND M.IdCia=OP.IdCia
 WHERE OP.Anulado=0) AS ODP ON MUC.MucTipOdp=ODP.TipOdp AND MUC.MucOrdPago=ODP.NumOPago AND MUC.MucCdCiaOdp=ODP.OdpCdCia
 LEFT JOIN Terceros AS NP ON MUC.MucCdPoseedor=NP.IdTercero 
-- Egresos
 LEFT JOIN (SELECT EO.TipOdp AS TipOrden,EO.OrdPago AS NumOPago,EO.IdCiaOdp AS CdCiaOpago,SUM(VrAbonado) AS TotalEgresos
 FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
 WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EGT ON MUC.MucTipOdp=EGT.TipOrden AND MUC.MucOrdPago=EGT.NumOPago AND MUC.MucCdCiaOdp=EGT.CdCiaOpago

 WHERE R.TipDoc='RMT' AND R.Fecha BETWEEN @pmFechaIni AND  @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaNov] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT R.TipDoc AS TipRem,R.NumOrden AS NumRemesa,R.IdCia AS CdCia,Compania,Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,NomCliente,T.RazonSocial AS NombreClie
,R.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,IdLocFletes,CF.Localidad AS LugarFletes,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,TipoAfiVehic,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,R.VrDeclarado AS ValDeclarado,R.VrSeguro AS ValSeguro,R.Cantidad AS CantTotal,PesoTotal,Items
,IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,CR.Concepto AS DesConcRem,CdRutaTarif,TipCom,Comprobante,IdCiaCom,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac
,Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,RA.IdVend AS CdVend,VN.RazonSocial AS Vendedor,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,ManifMintrans,RemMintrans,TipoRuta,TipoMintrans
--datos de conceptos
,C.Item,C.Descripcion AS Descrpcion,Tarifa,TipoConc,RubroConcep,C.Cantidad AS CantConc,VrUnitario,TarifIva,C.IdConcepto AS CodConcepto,CDV.Concepto AS DescConcepto,CdCuenta,NomCuenta
,NitTercero,TC.RazonSocial AS NomTercero,CdTipoEsc,TipoEscolta,C.FechaNov,C.VrBase,C.TipoTarif,C.RefConc,C.Referencia2,C.Referencia3,C.Est_Factura,C.TipFact,C.NumFactura,C.CiaFact,C.VrTotalFact,C.Est_Liquida,C.TipLiq,C.NumLiquida,C.CiaLiq,C.VrTotalLiq
--Datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,Modelo,Config,V.Descripcion AS VehDescripcion,V.IdPoseedor AS NitPoseedor
 FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Localidades AS CF ON R.IdLocFletes=CF.IdLocal  INNER JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado 
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca 
 INNER JOIN Trn_TraConceptos AS C ON R.TipDoc=C.TipDoc AND R.NumOrden=C.Documento AND R.IdCia=C.IdCia
 LEFT JOIN ConcDiversos AS CDV ON C.IdConcepto=CDV.IdConcepto
 LEFT JOIN TiposEsc AS TE ON C.CdTipoEsc=TE.IdTipoEsc LEFT JOIN Terceros AS TC ON C.NitTercero=TC.IdTercero
 LEFT JOIN Puc AS P ON C.CdCuenta=P.IdCuenta
 LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero  
 LEFT JOIN Conceptos AS CR ON R.CdConcepto=CR.IdConcepto 
 WHERE R.TipDoc='RMT'  AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.Modalidad LIKE ISNULL(@pmModalidad,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaOdp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaOdp] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
AS 
SELECT R.TipDoc,R.NumOrden,R.IdCia AS CdCia,Compania,R.Fecha AS FecRemesa,D.Item,D.IdMercancia AS CdMercancia,D.DescripMcias,D.Cantidad,D.PesoNeto,D.UndMed,UMP.Unidad AS UmdPeso,D.Volumen,R.IdCliente AS NitCliente,T.RazonSocial AS NomCliente
,D.NitRemite,D.Remitente,D.DirOrigen,D.IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen,D.NitDestntario,D.Destinatario,D.DirDestino,D.IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,D.TarifClie,D.TarifPago,D.VrDeclarado,D.VrSeguro,D.TarifSeguro,D.UndTarifa,D.UndTarifPago,Remision,D.DocCliente,D.Referencia1,D.Referencia2,D.Referencia3,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida
,R.IdAgencia AS CdAgencia,A.Agencia,R.IdVehiculo,R.IdConductor,CDT.RazonSocial AS NomConductor,R.nRemolque,R.TipoAfiVehic,R.Modalidad,NumPedido,IdCiaPed,R.TipDcm,R.NumDocmto,R.IdCiaDcm,R.EstCumplido,D.Cumplido AS NumCumplido,D.IdCiaCump,R.EstFactura
--datos de factura
,RF.TipoFact,RF.NumFactura,RF.IdCiaFact,F.Fecha AS FacFecha,RF.FacCantidad,RF.FacValorTotal,F.IdCliente AS FacIdCliente,NCL.RazonSocial AS FacNomCliente,F.IdAgencia AS FacIdAgencia,AF.Agencia AS FacAgencia,F.IdVend AS FacIdVend,VN.RazonSocial AS Vendedor
--Manifiesto y ordenes
,MC.TipDoc AS MucTipo,MC.Manifiesto,MC.IdCia AS MucIdCia,MC.Fecha AS MucFecha,MC.IdRuta,Ruta,MC.IdPoseedor,NP.RazonSocial AS NomPoseedor,MC.Cumplido AS MucCumplido,MC.IdCiaCump AS MucIdCiaCump,MC.EstCumplido AS MucEstCumplido,MC.EstOrden AS MucEstOrden
,OP.OdpTipo,OP.OrdPago,OP.OdpIdCia,OP.OdpVrFlete,OP.OdpDescuento,OP.OdpRetencion,OP.OdpReteIca,OP.OdpVrCREE,OP.OdpAnticipos,OP.OdpFaltantes,OP.OdpSeguros,OP.OdpFondos,OP.OdpAportes,OP.OdpOtrosDcto,OP.OdpImpuestos
,OP.OdpEstampillas,OP.OdpOtrosPagos,OP.OdpVrNeto,OP.OdpTarifaUnd,OP.OdpPesoTotal,OP.TipEgr,OP.Egreso,OP.IdCiaEgr,EG.TotEgresos
FROM Trn_TraRemesa AS R INNER JOIN Trn_TraRemMcias AS D ON R.TipDoc=D.TipDoc AND R.NumOrden=D.NumOrden AND R.IdCia=D.IdCia
INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS CDT ON R.IdConductor=CDT.IdTercero 
INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd  
LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed
--Remeasa/Facturas
LEFT JOIN (SELECT TipRem,Remesa,IdCiaRem,ItemRem
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE Factura END) AS NumFactura
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Factura ELSE 0 END) AS NumDevFact
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN '0' ELSE TipDoc END) AS TipoFact
,MAX(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN '00' ELSE IdCia END) AS IdCiaFact
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Cantidad*-1 ELSE Cantidad END) AS FacCantidad
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN (Cantidad*VrUnitario)*-1 ELSE Cantidad*VrUnitario END) AS FacValorTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN (CantPago*VrCosto)*-1 ELSE CantPago*VrCosto END) AS FacCostoTotal
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Unidades*-1 ELSE Unidades END) AS FacUnidades
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN PesoNeto*-1 ELSE PesoNeto END) AS FacPesoNeto
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN Volumen*-1 ELSE Volumen END) AS FacVolumen
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN VrFaltante*-1 ELSE VrFaltante END) AS FacFaltantes
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE TarifaIva END) AS FacTarifIva
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE VrImpuesto END) AS FacImpuesto
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE TarifaRet END) AS FacTarifRet
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE VrRetencion END) AS FacRetencion
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE TarifaIca END) AS FacTarifIca
,SUM(CASE WHEN SUBSTRING(TipDoc,1,2)='DF' THEN 0 ELSE VrReteIca END) AS FacReteIca
FROM Trn_TraFacRemesas WHERE TipoReg=0 GROUP BY TipRem,Remesa,IdCiaRem,ItemRem) AS RF ON D.TipDoc=RF.TipRem AND D.NumOrden=RF.Remesa AND D.IdCia=RF.IdCiaRem AND D.Item=RF.ItemRem
LEFT JOIN (SELECT TipDoc,Factura,IdCia,Fecha,IdCliente,IdAgencia,IdVend,IdPlazo,BaseImp,BaseRet FROM Trn_Facturas WHERE Modalidad='TRANSPORTE' AND Anulado=0) AS F ON RF.TipoFact=F.TipDoc
AND RF.NumFactura=F.Factura AND RF.IdCiaFact=F.IdCia
--remesa/manifiesto
LEFT JOIN (SELECT MR.TipRem,MR.Remesa,MR.IdCiaRem,MR.ItemRem,MR.TipDoc,MR.Manifiesto,MR.IdCia,MR.TarifPago,MR.RemMintrans,M.Fecha,M.IdRuta,M.IdVehiculo,M.nRemolque,M.TipoAfiVehic,M.IdPoseedor,M.IdConductor
,M.VrFletes,M.VrRetencion,M.VrReteIca,M.VrAnticipo,M.VrAntAdic,M.VrCargos,M.VrDctos,M.VrFleteNeto,M.PesoTotal,M.TarifaRet,M.TarifaIca,M.Cumplido,M.IdCiaCump,M.FechaCump,M.EstCumplido,M.EstOrden
FROM Trn_TraManifRem AS MR INNER JOIN Trn_TraManifiesto AS M ON MR.TipDoc=M.TipDoc AND MR.Manifiesto=M.Manifiesto AND MR.IdCia=M.IdCia WHERE M.Anulado=0) AS MC ON D.TipDoc=MC.TipRem AND D.NumOrden=MC.Remesa AND D.IdCia=MC.IdCiaRem AND D.Item=MC.ItemRem
--Remesa/Manif/ordnenes
LEFT JOIN (SELECT OM.TipMuc,OM.Manifiesto,OM.IdCiaMuc,OM.TipDoc AS OdpTipo,OM.OrdPago,OM.IdCia AS OdpIdCia,OM.VrTotalFletes AS OdpVrFlete,OM.VrDescuento AS OdpDescuento,OM.VrRetencion AS OdpRetencion,OM.VrReteIca AS OdpReteIca
,OM.VrReteCREE AS OdpVrCREE,OM.VrAnticipos AS OdpAnticipos,OM.VrFaltantes AS OdpFaltantes,OM.VrSeguros AS OdpSeguros,OM.VrFondos AS OdpFondos,OM.VrAportes AS OdpAportes,OM.VrOtrosDctos AS OdpOtrosDcto,OM.VrImpuestos AS OdpImpuestos,OM.VrEstampilla AS OdpEstampillas
,OM.VrOtrosPagos AS OdpOtrosPagos,OM.VrNeto AS OdpVrNeto,OM.TarifaFlete AS OdpTarifaUnd,OM.PesoTotal AS OdpPesoTotal,OM.Unidades AS OdpCantidad,OM.Volumen AS OdpVolumen,OM.TipEgr,OM.Egreso,OM.IdCiaEgr
FROM Trn_TraOrdenManif AS OM INNER JOIN Trn_TraOrdenPago AS O ON OM.TipDoc=O.TipDoc AND OM.OrdPago=O.OrdPago AND OM.IdCia=O.IdCia WHERE O.Anulado=0) AS OP ON MC.TipDoc=OP.TipMuc AND MC.Manifiesto=OP.Manifiesto AND MC.IdCia=OP.IdCiaMuc
--Egresos
LEFT JOIN (SELECT EO.TipOdp,EO.OrdPago,EO.IdCiaOdp,SUM(VrAbonado) AS TotEgresos FROM Trn_TraEgrOrden AS EO INNER JOIN Trn_Comprobantes AS E ON EO.TipCom=E.TipCom AND EO.NumEgreso=E.Comprobante AND EO.IdCia=E.IdCia
WHERE E.Anulado=0 GROUP BY EO.TipOdp,EO.OrdPago,EO.IdCiaOdp) AS EG ON OP.OdpTipo=EG.TipOdp AND OP.OrdPago=EG.OrdPago AND OP.OdpIdCia=EG.IdCiaOdp
LEFT JOIN Terceros AS NCL ON F.IdCliente=NCL.IdTercero LEFT JOIN Agencias AS AF ON F.IdAgencia=AF.IdAgencia
LEFT JOIN Terceros AS VN ON F.IdVend=VN.IdTercero LEFT JOIN Terceros AS NP ON MC.IdPoseedor=NP.IdTercero
LEFT JOIN Rutas AS RT ON MC.IdRuta=RT.IdRuta
WHERE R.TipDoc='RMT' AND R.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND (@pmIdCia IS NULL OR R.IdCia=@pmIdCia)
AND (@pmIdCliente IS NULL OR R.IdCliente=@pmIdCliente) AND R.Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT R.TipDoc AS CdTipDoc,R.NumOrden AS Num_Orden,R.IdCia AS CdCia,Compania,Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli
,R.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,IdClieFact,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino,IdLocFletes,CF.Localidad AS LugarFletes,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,TipoAfiVehic,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,R.VrDeclarado AS ValDeclarado,R.VrSeguro AS ValSeguro,R.Cantidad AS CantTotal,PesoTotal,Items
,IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,Concepto,CdRutaTarif,TipCom,Comprobante,IdCiaCom,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac
,Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS CdUsuario,Usuario
,R.VrTray_Vacio1,R.VrTray_Vacio2,RA.IdVend AS CdVend,VN.RazonSocial AS Vendedor,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,TomadorPoliza,PolizaSeguro
,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans,TipSal,NumSalida,IdCiaSal,TipOrdMud,NumInvent,IdCiaInv,TipoRuta,TipoMintrans,CdBodega,Bodega,RA.TipoDevRemesa,RA.CodCiuTransb,LT.Localidad AS CiudadTransb,RA.MvoTransbordo
--Datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,V.IdGrupo AS CdGrupoPro,GrupoProp
 FROM Trn_TraRemesa AS R  INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal INNER JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal INNER JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
 INNER JOIN Localidades AS CF ON R.IdLocFletes=CF.IdLocal  INNER JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero  LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN  Conceptos AS C ON R.CdConcepto=C.IdConcepto 
 LEFT JOIN AlmBodegas AS BG ON R.CdBodega=BG.IdBodega LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Localidades AS LT ON RA.CodCiuTransb=LT.IdLocal
 WHERE R.TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND R.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 ORDER BY R.IdCia,R.NumOrden
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemesaRelDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemesaRelDet] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdCliente VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT R.TipDoc AS CdTipDoc,R.NumOrden AS Num_Orden,R.IdCia AS CdCia,Compania,Fecha,FecDespacho,FecEntrega,HoraLlegada,IdCliente,NomCliente,T.RazonSocial AS RazonSocialCli
,R.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,A.CodAgencia AS Cod_Agencia,IdClieFact,IdLocFletes,CF.Localidad AS LugarFletes,R.IdVehiculo AS PlacaVeh,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor
,nRemolque,TipoAfiVehic,Modalidad,TipoTarifa,VrCobro,VrPagos,VrFletes,VrCargue,VrDesCargue,VrEscolta,VrDevContdor,VrTraUrbano,VrEmbalajes,VrCargos,VrDctos,R.VrDeclarado AS ValDeclarado,R.VrSeguro AS ValSeguro,R.Cantidad AS CantTotal,PesoTotal,Items
,IdMneda,VrTasa,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,EstCumplido,EstFactura,CdConcepto,Concepto,CdRutaTarif,TipCom,Comprobante,IdCiaCom
,SerieGuia,NumGuia,CdForma,NumCausac,CdCiaCausac,EdoCausac,Anulado,FecDev,R.Observacion AS Observ,R.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,R.IdUsuario AS CdUsuario,Usuario
,R.VrTray_Vacio1,R.VrTray_Vacio2,RA.IdVend AS CdVend,VN.RazonSocial AS Vendedor,LugarCargue,LugarDescargue,NomContacto,TelContacto,emlContacto,ContacDestino,TelContacDest,emlContacDest,TomadorPoliza,PolizaSeguro
,NitCiaPoliza,NomCiaPoliza,FecVencePol,ManifMintrans,RemMintrans,TipSal,NumSalida,IdCiaSal,TipOrdMud,NumInvent,IdCiaInv,TipoRuta,TipoMintrans,CdBodega,Bodega,RA.TipoDevRemesa,RA.CodCiuTransb,LT.Localidad AS CiudadTransb,RA.MvoTransbordo
--detalles
,Item,IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,D.UndMed AS CdUmPeso,UMP.Unidad AS UmPeso,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,Cases,Cajas,Palets,NitRemite,Remitente,NitDestntario,Destinatario
,DirOrigen,IdOrigen,LO.Localidad AS CiuOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,DirDestino,IdDestino,LD.Localidad AS CiuDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,TarifClie,TarifPago,TarifTabla,D.VrDeclarado AS DetVrDeclarado,D.VrSeguro AS DetVrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3
,Contenedor1,Contenedor2,D.CdAgencia AS DetCdAgencia,Cumplido,IdCiaCump,FechaCump,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp,PesoCont
,D.IdUnd AS CdUnd,UM.Unidad AS UndMedida,D.IdEmp AS CdEmp,Empaque,D.IdNat AS CdNat,Natlzaprod,D.IdMnjo AS CdMnjo,ManejoMcia,D.IdTmcia AS CdTmcia,TipoMcia,CdRango,DescripRango
,D.SedeRem,SR.NomSede AS NomSedeRem,D.SedeDest,SD.NomSede AS NomSedeDest
--Datos del cliente
,T.TipoId AS TercTipId,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,NitRepLeg,NomRepLeg,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie
,A.DirAgncia AS AgeDireccion,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,A.TelAgncia AS AgeTelefono,A.Referencia AS AgeReferencia
--Datos del vehiculo
,NumVeh,V.IdTipoVeh AS CdTipVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinVeh,LineaVeh,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,Config
,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,NitEmpresa,NE.RazonSocial AS VehNomEmpresa,V.IdPoseedor AS NitPoseedor,NPO.RazonSocial AS Poseedor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,TipoAfil,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,CertGases,FecCertGas,VigCertGas,V.Descripcion AS VehDescripcion
,V.IdGrupo AS CdGrupoPro,GrupoProp
 FROM Trn_TraRemesa AS R  INNER JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia
 INNER JOIN Trn_TraRemMcias AS D ON R.TipDoc=D.TipDoc  AND R.NumOrden=D.NumOrden AND R.IdCia=D.IdCia
 INNER JOIN Companias AS CN ON R.IdCia=CN.IdCia  INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS CF ON R.IdLocFletes=CF.IdLocal  INNER JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero 
 INNER JOIN EstadoDoc AS ED ON R.IdEstado=ED.IdEstado INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal INNER JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 INNER JOIN UndMed AS UM ON D.IdUnd=UM.IdUnd INNER JOIN Empaques AS EMP ON D.IdEmp=EMP.IdEmp
 INNER JOIN TiposNat AS NZ ON D.IdNat=NZ.IdNat INNER JOIN TiposMnjo AS MJ ON D.IdMnjo=MJ.IdMnjo
 INNER JOIN TiposMcia AS TM ON D.IdTmcia=TM.IdTmcia 
 INNER JOIN Vehiculos AS V ON R.IdVehiculo=V.IdVehiculo  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS LV ON V.IdLinea=LV.IdLinea 
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN Terceros AS NPO ON V.IdPoseedor=NPO.IdTercero  INNER JOIN TiposPpt AS TPR ON V.IdPpd=TPR.IdPpd
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero
 LEFT JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero  LEFT JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia
 LEFT JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  LEFT JOIN  Conceptos AS C ON R.CdConcepto=C.IdConcepto 
 LEFT JOIN AlmBodegas AS BG ON R.CdBodega=BG.IdBodega LEFT JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
 LEFT JOIN Sys_Um AS UMP ON D.UndMed=UMP.UndMed LEFT JOIN RangosPeso AS RP ON D.CdRango=RP.IdRango
 LEFT JOIN TercSedes AS SR ON D.NitRemite=SR.IdTercero AND D.SedeRem=SR.IdSede LEFT JOIN TercSedes AS SD ON D.NitDestntario=SD.IdTercero AND D.SedeDest=SD.IdSede
 LEFT JOIN Localidades AS LT ON RA.CodCiuTransb=LT.IdLocal
 WHERE R.TipDoc=@pmTipDoc AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND R.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND R.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 ORDER BY R.IdCia,R.NumOrden
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemMcias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraRemMcias] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,NumOrden,IdCia,Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol,IdUnd,IdEmp,IdNat,IdTmcia,IdMnjo,CdRango,Cases,Cajas,Palets
,NitRemite,Remitente,DirOrigen,IdOrigen,NitDestntario,Destinatario,DirDestino,IdDestino,TarifClie,TarifPago,TarifTabla,VrDeclarado,VrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3
,Contenedor1,Contenedor2,CdAgencia,Cumplido,IdCiaCump,FechaCump,DetalleCump,CantidadCump,PesoCump,VolCump,CasesCump,CajasCump,PaletsCump,TarifCump,PagoCump,UndTarCump,UndTarPagoCump
,TipFac,Factura,IdCiaFac,FechaFac,TarifClieFac,TipOdp,NumeroOdp,IdCiaOdp,TarifOdp,PesoCont,SedeRem,SedeDest,TipDocInv,NumDocInv,IdCiaDocInv,ItemDocInv,TarifOtros,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP
 FROM Trn_TraRemMcias
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
 AND Item BETWEEN ISNULL(@pmItem,-1) AND  ISNULL(@pmItem,2147483647) 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraRemMciasOrd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraRemMciasOrd] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,IdMercancia,DescripMcias,Cantidad,PesoNeto,D.UndMed AS UndPeso,Cases,Cajas,Palets,D.IdUnd AS CdUnid,Unidad
,Remision,DocCliente,Referencia1,Referencia2,Referencia3,NitRemite,Remitente,SedeRem,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen
,NitDestntario,Destinatario,SedeDest,DirDestino,IdDestino,LD.Localidad AS CiudadDestino
,dmsLargo,dmsAncho,dmsAlto,Volumen,UndVol,Contenedor1,Contenedor2,CdRango,D.IdEmp AS CdEmpaque,Empaque
,IdNat,IdMnjo,IdTmcia,PesoCont,TipDocInv,NumDocInv,IdCiaDocInv,ItemDocInv,Cod_UN,Cod_Corr,Cod_Desg,DescripcionRP
 FROM Trn_TraRemMcias AS D INNER JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal INNER JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal
 INNER JOIN UndMed AS U ON D.IdUnd=U.IdUnd INNER JOIN Empaques AS E ON D.IdEmp=E.IdEmp
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTraslados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Traslado,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,Cantidad,NumDcmto,NumOrden,IdCCosto,IdSubCos,Modalidad
,TdOrden,CdCiaOrden,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
 FROM Trn_Traslados
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraslados_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraslados_Cr] @pmTipDoc VARCHAR(3),@pmTrasladoIni INT,@pmTrasladoFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT N.TipDoc AS Tip_Doc,TipoDoc,Traslado,N.IdCia AS CdCia,Compania,N.Fecha AS FechaDoc,N.IdConcepto AS CdConcepto,Concepto,N.IdTercero AS NitTercero,RazonSocial
,VrSubTotal,Cantidad,NumDcmto,N.TdOrden,N.NumOrden AS Num_Orden,N.CdCiaOrden,N.IdCCosto AS CdCcosto,CC.CCosto AS CentCosto,N.IdSubCos AS CdSubCent,SC.SubCosto AS SubcCosto,Modalidad
,OrigenAdd,TipCom,TipoCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado
,N.TimeSys AS Fec_Add,N.FecUpdate AS Fec_Update,IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario,Leyenda
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario
,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,VrReteEnt,VrReteSal,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote
,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,pVehiculo,K.Referencia AS KarReferencia
,Descripcion,Comptmntos,CdProdEquiv,TipOrd,K.NumOrden AS KarNumOrden,IdCiaOrd,Cotizacion,IdCiaCot
,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_Traslados AS N  INNER JOIN Trn_Kardex AS K ON N.TipDoc=K.TipDoc AND N.Traslado=K.Documento AND N.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia  INNER JOIN Sys_TiposDoc AS TD ON N.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd  
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 LEFT JOIN TiposCom AS TC ON N.TipCom=TC.IdCom
 WHERE N.TipDoc=@pmTipDoc AND Traslado BETWEEN @pmTrasladoIni AND @pmTrasladoFin AND N.IdCia=@pmIdCia
 ORDER BY Traslado,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryTrasladosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTrasladosLta]  @pmFechaIni SMALLDATETIME, @pmFechaFin SMALLDATETIME,@pmTrasladoIni INT=Null,@pmTrasladoFin INT=Null
,@pmIdCia CHAR(2)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdConcepto VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT Traslado,IdCia,Fecha,N.IdConcepto AS CdConcepto,Concepto,N.IdTercero AS NitTercero,RazonSocial,VrSubTotal,Cantidad,NumDcmto,TdOrden,NumOrden,CdCiaOrden,N.IdCCosto AS CdCcosto,CCosto
,IdSubCos,Modalidad,OrigenAdd,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado,TimeSys,FecUpdate,IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario
 FROM Trn_Traslados AS N INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero
 INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado
 INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON  N.IdCCosto=CC.IdCCosto
 WHERE  Fecha BETWEEN @pmFechaIni AND @pmFechaFin 
 AND Traslado BETWEEN ISNULL(@pmTrasladoIni,0) AND ISNULL(@pmTrasladoFin,2147483647)
 AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND N.IdTercero LIKE ISNULL(@pmIdTercero,'%')
 AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%') AND N.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 ORDER BY IdCia,Traslado
GO
/****** Object:  StoredProcedure [dbo].[paQryTrasladosOrd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTrasladosOrd] @pmNumOrden INT,@pmIdCia CHAR(2)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Traslado,IdCia,Fecha,IdConcepto,IdTercero,VrSubTotal,Cantidad,NumDcmto,NumOrden,Modalidad
,TipCom,Comprobante,IdCiaCom
 FROM Trn_Traslados
 WHERE NumOrden=@pmNumOrden  AND  IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND Modalidad LIKE ISNULL(@pmModalidad,'%')
ORDER BY IdCia,Traslado
GO
/****** Object:  StoredProcedure [dbo].[paQryTrasladosRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTrasladosRel] @pmTipDoc VARCHAR(3),@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdConcepto VARCHAR(4)=Null,@pmIdTercero VARCHAR(16)=Null,@pmIdCCosto VARCHAR(16)=Null,@pmModalidad VARCHAR(10)=Null
 AS 
 SELECT N.TipDoc AS Tip_Doc,Traslado,N.IdCia AS CdCia,Compania,N.Fecha AS FechaDoc,N.IdConcepto AS CdConcepto,Concepto,N.IdTercero AS NitTercero,RazonSocial
,VrSubTotal,Cantidad,NumDcmto,N.TdOrden,N.NumOrden AS Num_Orden,N.CdCiaOrden,N.IdCCosto AS CdCcosto,CC.CCosto AS CentCosto,N.IdSubCos AS CdSubCent,SC.SubCosto AS SubcCosto,Modalidad
,OrigenAdd,TipCom,Comprobante,IdCiaCom,N.Observacion AS Observ,N.IdEstado AS CdEstado,Estado
,N.TimeSys AS Fec_Add,N.FecUpdate AS Fec_Update,IdCiaCrea,N.IdUsuario AS IdUsuari,Usuario
,TipoId,Dv,T.Codigo AS CodTercero,NomCial,T.Direccion AS Terc_Direccion,T.IdLocal AS CdLocal,Localidad,L.IdDep AS CdDep,Departamento,Telefono,Fax,e_mail
,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,TipEnte
,Item,K.IdProducto AS CodProducto,DescripProd,K.IdBodega AS CdBodega,Bodega,Descrip AS BodDescrip,CdTanque,Entradas,Salidas,K.IdUnd AS CdUnid,UM.Unidad AS UnidMedida,VrUnitario
,VrPrecio,VrCostProm,TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,VrReteEnt,VrReteSal,VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote
,K.CdCCosto AS KarCodCenCosto,KC.CCosto AS Kar_Ccosto,K.CdSubCos AS KarCodSubcosto,KS.SubCosto AS Kar_Subcentro,pVehiculo,K.Referencia AS KarReferencia
,Descripcion,Comptmntos,CdProdEquiv,TipOrd,K.NumOrden AS KarNumOrden,IdCiaOrd,Cotizacion,IdCiaCot
,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,ImpGlobal
,OtroImpto,Unidades,ItemCombo,Servcios,EsCombo,EsProdBase,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden
--productos
,PM.Referencia AS Prod_Referencia,TipoRef,PM.IdSubgrupo AS CdSubgrupo,Subgrupo,SG.IdGrupo AS CdGrupo,Grupo,G.IdLinea AS CdLinea,Linea,PM.IdMarca AS CdMarca,Marca,Tamano,PM.UndMed AS CdUndMed
,SU.Unidad AS ProdUnidad,ExtciaMin,ExtciaMax,ExtciaAct,VrCostAnt,VrCosto,VrCostPmd,Precio1,Precio2,Precio3,Precio4,Precio5,FecUltcom,FecUltVta,Seriales,Lotes,Combo,Tanques,DescripLong
 FROM Trn_Traslados AS N  INNER JOIN Trn_Kardex AS K ON N.TipDoc=K.TipDoc AND N.Traslado=K.Documento AND N.IdCia=K.IdCia
 INNER JOIN Companias AS CN ON N.IdCia=CN.IdCia  
 INNER JOIN Terceros AS T ON N.IdTercero=T.IdTercero INNER JOIN  Conceptos AS C ON N.IdConcepto=C.IdConcepto
 INNER JOIN EstadoDoc AS ED ON N.IdEstado=ED.IdEstado   INNER JOIN adm_Usuarios AS U ON N.IdUsuario=U.IdUsuario
 INNER JOIN CentroCosto AS CC ON N.IdCCosto=CC.IdCCosto
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN ProdMcias  AS PM ON K.IdProducto=PM.IdProducto INNER JOIN Bodegas AS B ON K.IdBodega=B.IdBodega
 INNER JOIN UndMed AS UM ON K.IdUnd=UM.IdUnd  
 INNER JOIN SubGrupos AS SG ON PM.IdSubgrupo=SG.IdSubgrupo INNER JOIN Grupos AS G ON SG.IdGrupo=G.IdGrupo 
 INNER JOIN Lineas AS LN ON G.IdLinea=LN.IdLinea INNER JOIN Marcas AS M ON PM.IdMarca=M.IdMarca
 INNER JOIN Sys_Um AS SU ON PM.UndMed=SU.UndMed 
 LEFT JOIN CentroCosto AS KC ON K.CdCCosto=KC.IdCCosto LEFT JOIN SubCentros AS KS ON K.CdSubCos=KS.IdSubCos
 LEFT JOIN SubCentros AS SC ON N.IdSubCos=SC.IdSubCos
 WHERE N.TipDoc=@pmTipDoc  AND N.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 AND N.IdCia LIKE ISNULL(@pmIdCia,'%%') AND N.IdConcepto LIKE ISNULL(@pmIdConcepto,'%')
 AND N.IdTercero LIKE ISNULL(@pmIdTercero,'%') AND Modalidad LIKE ISNULL(@pmModalidad,'%')
 AND N.IdCCosto LIKE ISNULL(@pmIdCCosto,'%')  
 ORDER BY N.IdCia,Traslado
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTalonariosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryTraTalonariosLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 SELECT IdTalonario,Fecha,NumSerie,NumInicial,NumFinal,NumAuto,NumActual,IdRespons,NomRespons
,Anulado,TimeSys,T.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraTalonarios AS T INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
 ORDER BY IdTalonario
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTalonariosRmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraTalonariosRmt] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
AS 
 SELECT IdTalonario,T.Fecha AS FecTalon,NumSerie,NumInicial,NumFinal,NumAuto,NumActual,IdRespons,NomRespons
,T.Anulado,T.TimeSys AS FechaCrea,T.IdUsuario AS CdUsuario,Usuario
--datos de la remesa
,R.NumOrden AS NumRemesa,R.IdCia AS CdCia,Compania,SerieGuia,NumGuia,R.Fecha AS FecRemesa,FecDespacho,IdCliente,NC.RazonSocial AS NomCliente
,IdRemitente,NomRemite,IdDestinatario,NomDestino,IdLocOrigen,CO.Localidad AS CiuOrigen,CO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,IdLocDestino,CD.Localidad AS CiuDestino,CD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,IdVehiculo,R.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,nRemolque,TipoAfiVehic,Modalidad
,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm,NumManif,IdCiaManif,RA.IdVend AS CdVend,VN.RazonSocial AS Vendedor,R.Observacion AS Observ
FROM Trn_TraTalonarios AS T INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
LEFT JOIN Trn_TraRemesa AS R ON T.NumSerie=R.SerieGuia AND R.NumGuia BETWEEN T.NumInicial AND T.NumFinal
LEFT JOIN Trn_TraRemAnexo AS RA ON R.TipDoc=RA.TipDoc  AND R.NumOrden=RA.NumOrden AND R.IdCia=RA.IdCia 
LEFT JOIN Companias AS CN ON R.IdCia=CN.IdCia LEFT JOIN Terceros AS NC ON R.IdCliente=NC.IdTercero 
LEFT JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal LEFT JOIN Departamentos AS DPO ON CO.IdDep=DPO.IdDep
LEFT JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal LEFT JOIN Departamentos AS DPD ON CD.IdDep=DPD.IdDep
LEFT JOIN Terceros AS  CDT ON R.IdConductor=CDT.IdTercero LEFT JOIN Terceros AS VN ON RA.IdVend=VN.IdTercero 
WHERE T.Fecha BETWEEN @pmFechaIni AND @pmFechaFin
ORDER BY IdTalonario
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTraslados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Traslado,IdCia,Fecha,FecDespacho,TipoTraslado,IdBodega,IdBodDtno,IdVehiculo,IdConductor,Cantidad,PesoTotal,Manifiesto,CdCiaMuc,EstadoRec,FechaRec,CedRecibido,NomRecibido,Observacion,OrigenAdd,TimeSys,IdCiaCrea,IdUsuario
 FROM Trn_TraTraslados
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTrasladosFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraTrasladosFmt] @pmTipDoc VARCHAR(3),@pmTrasladoIni INT,@pmTrasladoFin INT,@pmIdCia CHAR(2)
AS 
 SELECT T.TipDoc AS CdTipDoc,T.Traslado AS NumTraslado,T.IdCia AS CdCia,Compania,Fecha,FecDespacho,TipoTraslado,T.IdBodega AS CdBodega,BG.Bodega AS BodegaOrig,IdBodDtno,BD.Bodega AS BodegaDtno
,IdVehiculo,IdConductor,CDT.RazonSocial AS NomConductor,Manifiesto,CdCiaMuc,EstadoRec,FechaRec,CedRecibido,NomRecibido
,T.Observacion AS Observ,OrigenAdd,TimeSys,IdCiaCrea,T.IdUsuario AS CdUsuario,Usuario
,DR.Item AS DetItem,TipRem,Remesa,IdCiaRem,ItemRem,EdoRecibido,Comentarios,IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol
,Cases,Cajas,Palets,NitRemite,Remitente,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,NitDestntario,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,TarifClie,VrDeclarado,VrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,CdNovedad,Novedad
 FROM Trn_TraTraslados AS T INNER JOIN Companias AS CN ON T.IdCia=CN.IdCia INNER JOIN Terceros AS CDT ON T.IdConductor=CDT.IdTercero 
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN AlmBodegas AS BG ON T.IdBodega=BG.IdBodega INNER JOIN AlmBodegas AS BD ON T.IdBodDtno=BD.IdBodega
 INNER JOIN Trn_TraTrasladoRem AS DR ON T.TipDoc=DR.TipDoc AND T.Traslado=DR.Traslado AND T.IdCia=DR.IdCia
 LEFT JOIN Trn_TraRemMcias AS D ON DR.TipRem=D.TipDoc AND DR.Remesa=D.NumOrden AND DR.IdCiaRem=D.IdCia AND DR.ItemRem=D.Item
 LEFT JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal LEFT JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal LEFT JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN NovedadTra AS NV ON DR.CdNovedad=NV.IdNovedad
 WHERE T.TipDoc=@pmTipDoc AND T.Traslado BETWEEN @pmTrasladoIni AND @pmTrasladoFin AND T.IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTrasladosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraTrasladosLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null
 AS 
 SELECT  Traslado,T.IdCia AS CdCia,Compania,Fecha,FecDespacho,TipoTraslado,T.IdBodega AS CdBodega,BG.Bodega AS BodegaOrig,IdBodDtno,BD.Bodega AS BodegaDtno,IdVehiculo
,IdConductor,CDT.RazonSocial AS NomConductor,Cantidad,PesoTotal,Manifiesto,CdCiaMuc,EstadoRec,FechaRec,CedRecibido,NomRecibido
,T.Observacion AS Observ,OrigenAdd,TimeSys,IdCiaCrea,T.IdUsuario AS CdUsuario,Usuario
 FROM Trn_TraTraslados AS T INNER JOIN Companias AS CN ON T.IdCia=CN.IdCia INNER JOIN Terceros AS CDT ON T.IdConductor=CDT.IdTercero 
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN AlmBodegas AS BG ON T.IdBodega=BG.IdBodega INNER JOIN AlmBodegas AS BD ON T.IdBodDtno=BD.IdBodega
 WHERE TipDoc='TRR' AND T.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND T.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND T.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND T.IdConductor LIKE ISNULL(@pmIdConductor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTrasladosRel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paQryTraTrasladosRel] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null
,@pmIdConductor VARCHAR(16)=Null
AS 
 SELECT T.TipDoc AS CdTipDoc,TipoDoc,T.Traslado AS NumTraslado,T.IdCia AS CdCia,Compania,T.Fecha AS FecTraslado,T.FecDespacho AS FecDespTrasl,TipoTraslado,T.IdBodega AS CdBodega,BG.Bodega AS BodegaOrig,IdBodDtno,BD.Bodega AS BodegaDtno
,T.IdVehiculo AS PlacaVeh,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,T.IdConductor AS CedConductor,CDT.RazonSocial AS NomConductor,Manifiesto,CdCiaMuc,EstadoRec,FechaRec,CedRecibido,NomRecibido
,T.Observacion AS Observ,T.OrigenAdd,T.TimeSys,T.IdCiaCrea,T.IdUsuario AS CdUsuario,Usuario
,DR.Item AS DetItem,TipRem,Remesa,IdCiaRem,ItemRem,EdoRecibido,Comentarios,IdMercancia,DescripMcias,D.Cantidad AS Cant,PesoNeto,UndMed,dmsAlto,dmsAncho,dmsLargo,Volumen,UndVol
,Cases,Cajas,Palets,NitRemite,Remitente,DirOrigen,IdOrigen,LO.Localidad AS CiudadOrigen,LO.IdDep AS CodDepOrigen,DPO.Departamento AS DptoOrigen
,NitDestntario,Destinatario,DirDestino,IdDestino,LD.Localidad AS CiudadDestino,LD.IdDep AS CodDepDestino,DPD.Departamento AS DptoDestino
,TarifClie,D.VrDeclarado AS VlrDeclarado,D.VrSeguro AS VlrSeguro,TarifSeguro,UndTarifa,UndTarifPago,Remision,DocCliente,Referencia1,Referencia2,Referencia3,CdNovedad,Novedad
,R.FecDespacho AS FecDespRemesa,CL.TipoId AS CliTipoId,R.IdCliente AS NitCliente,CL.Dv AS CliDv,CL.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,TipoAfiVehic,Modalidad,NumPedido,IdCiaPed,FechaPed,TipDcm,NumDocmto,IdCiaDcm,FechaDcm
,NumManif,IdCiaManif,EstCumplido,EstFactura,SerieGuia,NumGuia,R.CdBodega AS CodBodega,BR.Bodega AS BodActual
 FROM Trn_TraTraslados AS T INNER JOIN Companias AS CN ON T.IdCia=CN.IdCia INNER JOIN Terceros AS CDT ON T.IdConductor=CDT.IdTercero 
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario INNER JOIN Sys_TiposDoc AS TD ON T.TipDoc=TD.IdDoc
 INNER JOIN AlmBodegas AS BG ON T.IdBodega=BG.IdBodega INNER JOIN AlmBodegas AS BD ON T.IdBodDtno=BD.IdBodega
 INNER JOIN Trn_TraTrasladoRem AS DR ON T.TipDoc=DR.TipDoc AND T.Traslado=DR.Traslado AND T.IdCia=DR.IdCia
 INNER JOIN Trn_TraRemesa AS R ON DR.TipRem=R.TipDoc AND DR.Remesa=R.NumOrden AND DR.IdCiaRem=R.IdCia
 INNER JOIN Terceros AS CL ON R.IdCliente=CL.IdTercero  
 LEFT JOIN Trn_TraRemMcias AS D ON DR.TipRem=D.TipDoc AND DR.Remesa=D.NumOrden AND DR.IdCiaRem=D.IdCia AND DR.ItemRem=D.Item
 LEFT JOIN Localidades AS LO ON D.IdOrigen=LO.IdLocal LEFT JOIN Departamentos AS DPO ON LO.IdDep=DPO.IdDep
 LEFT JOIN Localidades AS LD ON D.IdDestino=LD.IdLocal LEFT JOIN Departamentos AS DPD ON LD.IdDep=DPD.IdDep
 LEFT JOIN NovedadTra AS NV ON DR.CdNovedad=NV.IdNovedad
 LEFT JOIN AlmBodegas AS BR ON R.CdBodega=BR.IdBodega 
 LEFT JOIN Vehiculos AS V ON T.IdVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh 
 WHERE  T.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND T.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND T.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND T.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND R.Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paQryTraTurnLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTraTurnLta] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdVehiculo VARCHAR(10)=Null 
 AS  
SELECT T.Numero,T.IdCia AS CdCia,Compania,T.IdVehiculo AS PlacaVeh,V.NumVeh AS NumVehiculo,T.nRemolque
,T.IndTurno AS Ind_Turno,T.Fecha,T.IdConductor AS CedConductor,NC.RazonSocial AS NomConductor,T.Estado
,CASE T.Estado WHEN 1 THEN 'EN ESPERA' WHEN 2 THEN 'EN TRANSITO' ELSE 'INACTIVO' END AS DescEstado
,TipOrd,NumOrden,IdCiaOrd,FecOrden,NitCliente,CLI.RazonSocial AS Cliente,T.FechaCrea,SedeClie,Autorizac,T.IdUsuario AS CdUsuario,Usuario
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.TipoAfil,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdColor AS CdColor,NomColor,V.Modelo
,Config,V.IdCat AS CdCateg,Catpeaje,CarrCapac,UndCapc,V.IdPoseedor AS NitPoseedor,NP.RazonSocial AS NomPoseedor,NumSoat,FecSoat,VigSoat,KmActual
,CdLocal,CU.Localidad,V.Ubicacion
,NC.TelMovil AS Cond_Celular,NC.Telefono AS Cond_Telefono,NC.e_mail AS Cond_Email,CND.Licencia AS NumLicencia,CND.CatLicencia,VigLicencia
FROM Trn_TraTurn AS T INNER JOIN Vehiculos AS V ON T.IdVehiculo=V.IdVehiculo INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
INNER JOIN Terceros AS NC ON T.IdConductor=NC.IdTercero INNER JOIN Companias AS CN ON T.IdCia=CN.IdCia
INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor
INNER JOIN Terceros AS NP ON V.IdPoseedor=NP.IdTercero
LEFT JOIN PeajesCat AS CP ON V.IdCat=CP.IdCat LEFT JOIN Localidades AS CU ON V.CdLocal=CU.IdLocal
LEFT JOIN TercCndtores AS CND ON T.IdConductor=CND.IdConductor LEFT JOIN Terceros AS CLI ON T.NitCliente=CLI.IdTercero
WHERE T.Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND T.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryTurnos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTurnos] @pmIdTurno VARCHAR(4)
 AS 
 SELECT IdTurno,Turno,HoraInicial,HoraFinal,Inactivo
 FROM Turnos
 WHERE IdTurno=@pmIdTurno
GO
/****** Object:  StoredProcedure [dbo].[paQryUm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryUm] @pmUndMed VARCHAR(10)
 AS 
 SELECT UndMed,Unidad,Carga,CodUMFE
 FROM Sys_Um
 WHERE UndMed LIKE ISNULL(@pmUndMed,'%')
 ORDER BY UndMed
GO
/****** Object:  StoredProcedure [dbo].[paQryUmDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUmDso] @pmCarga BIT=Null
 AS 
 SELECT UndMed,Unidad,UndMed+'  '+Unidad AS DsUnd
 FROM Sys_Um
 WHERE (Carga=ISNULL(@pmCarga,0) or Carga=ISNULL(@pmCarga,1))
 ORDER BY UndMed
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUndMed] @pmIdUnd VARCHAR(4)
 AS 
 SELECT IdUnd,Unidad,IdMat,IdEmp,FormRecp,ClaseEmp,DimAlto,DimAncho,DimLargo,DimVolm
,UndMed,PesoEpq,CapcMax,UndCapc,SimbUnd,Observ,Inactivo
 FROM UndMed
 WHERE IdUnd=@pmIdUnd
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMedDse]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUndMedDse] @pmClaseEmp VARCHAR(10)=Null
 AS 
 IF @pmClaseEmp IS NULL
  BEGIN
   SELECT U.IdUnd,U.Unidad,E.Empaque+ '-'+U.Unidad+' ('+ U.ClaseEmp+')' AS DsUnd
   FROM UndMed AS U LEFT JOIN Empaques AS E ON U.IdEmp=E.IdEmp 
   WHERE U.Inactivo=0
   ORDER BY E.Empaque
  END
 ELSE
  BEGIN 
   IF @pmClaseEmp='?'
    BEGIN
     SELECT U.IdUnd,U.Unidad,E.Empaque+ '-'+U.Unidad+' ('+ U.ClaseEmp+')' AS DsUnd
     FROM UndMed AS U LEFT JOIN Empaques AS E ON U.IdEmp=E.IdEmp 
     WHERE U.ClaseEmp IN ('EMBALAJE','PRIMARIO') AND U.Inactivo=0
     ORDER BY E.Empaque
    END
   ELSE
    BEGIN
     SELECT U.IdUnd,U.Unidad,E.Empaque+ '-'+U.Unidad+' ('+ U.ClaseEmp+')' AS DsUnd
     FROM UndMed AS U LEFT JOIN Empaques AS E ON U.IdEmp=E.IdEmp 
     WHERE U.ClaseEmp=@pmClaseEmp AND U.Inactivo=0
     ORDER BY E.Empaque
    END
   END
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMedDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUndMedDso] @pmClaseEmp VARCHAR(10)=Null
 AS 
 SELECT IdUnd,Unidad,Unidad+ ' ('+IdUnd+') '+ SimbUnd AS DsUnd
 FROM UndMed
 WHERE Inactivo=0 AND  ClaseEmp LIKE ISNULL(@pmClaseEmp,'%')
 ORDER BY Unidad
GO
/****** Object:  StoredProcedure [dbo].[paQryUndMedLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUndMedLta] @pmFormRecp VARCHAR(10)=Null,@pmClaseEmp VARCHAR(10)=Null
,@pmIdEmp VARCHAR(4)=Null,@pmInactivo BIT=Null
 AS 
 SELECT IdUnd,Unidad,U.IdMat AS CdMat,Material,U.IdEmp AS CdEmpq,Empaque,FormRecp,ClaseEmp,DimAlto,DimAncho,DimLargo,DimVolm
,UndMed,PesoEpq,CapcMax,UndCapc,SimbUnd,Observ,U.Inactivo AS Inactvo
 FROM UndMed AS U INNER JOIN TiposMat AS TM ON U.IdMat=TM.IdMat
 INNER JOIN Empaques AS E ON U.IdEmp=E.IdEmp
 WHERE FormRecp LIKE ISNULL(@pmFormRecp,'%') AND ClaseEmp LIKE ISNULL(@pmClaseEmp,'%')
 AND U.IdEmp LIKE ISNULL(@pmIdEmp,'%')
 AND (U.Inactivo=ISNULL(@pmInactivo,0) or U.Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY Unidad
GO
/****** Object:  StoredProcedure [dbo].[paQryUOpciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUOpciones] @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20)=Null
 AS 
 SELECT IdUsuario,NomOpcion,Valor
 FROM adm_UOpciones
 WHERE IdUsuario=@pmIdUsuario AND NomOpcion LIKE ISNULL(@pmNomOpcion,'%')
 ORDER BY NomOpcion
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUsuarios] @pmIdUsuario VARCHAR(11)
 AS 
 SELECT IdUsuario,Usuario,PwdLog,IdGrupo,IdEstacion,IdCargo,Conectado,FechaAcc,FechaClave
,Caducidad,LoginSQL,PwdSQL,ModoSQL,Inactivo
 FROM adm_Usuarios
 WHERE IdUsuario LIKE ISNULL(@pmIdUsuario,'%')
 ORDER BY IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosCnn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryUsuariosCnn] @pmIdUsuario VARCHAR(11)
AS
 SELECT IdUsuario,Usuario,Conectado,FechaAcc,Inactivo
 FROM adm_Usuarios
 WHERE Inactivo=0 AND Conectado<>0 AND IdGrupo<5 AND IdUsuario<>@pmIdUsuario
 ORDER BY IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUsuariosDso] @pmIdGrupo INT
AS
 SELECT IdUsuario,Usuario,IdGrupo,Usuario+' '+IdUsuario AS DsUsu,Inactivo
 FROM adm_Usuarios
 WHERE Inactivo=0  AND  IdGrupo<=@pmIdGrupo
 ORDER BY Usuario
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryUsuariosEst] @pmIdUsuario VARCHAR(11),@pmIdEstacion CHAR(2)
AS
 IF @pmIdUsuario IS NULL
  SELECT IdUsuario,Usuario,IdEstacion
  FROM adm_Usuarios WHERE  IdEstacion=@pmIdEstacion
 ELSE
  SELECT IdUsuario,Usuario,IdEstacion
  FROM adm_Usuarios WHERE  IdEstacion=@pmIdEstacion AND IdUsuario<>@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosGru]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUsuariosGru]  @pmIdUsuario VARCHAR(11)
AS
 IF @pmIdUsuario IS NULL
  SELECT IdUsuario,Usuario,PwdLog,IdGrupo
  FROM adm_Usuarios
  WHERE  IdUsuario<>'ADMIN' AND IdUsuario<>'SUPERVISOR'
 ORDER BY  IdUsuario
 ELSE
  SELECT IdUsuario,Usuario,PwdLog,IdGrupo
  FROM adm_Usuarios
  WHERE IdUsuario<>'ADMIN' AND IdUsuario<>'SUPERVISOR' AND IdUsuario<>@pmIdUsuario
  ORDER BY  IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryUsuariosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUsuariosLta] @pmIdGrupo INT,@pmInactivo BIT
AS
 SELECT IdUsuario,Usuario,IdGrupo,IdEstacion,Conectado,FechaAcc,Caducidad,FechaClave,LoginSQL,ModoSQL
,Inactivo,IdCargo,PwdLog,PwdSQL
 FROM adm_Usuarios 
 WHERE  IdGrupo<=@pmIdGrupo AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paQryUsucaja]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryUsucaja] @pmIdUsuario VARCHAR(11),@pmnFormato VARCHAR(10)
 AS 
 SELECT IdUsuario,nFormato,CdCajero,IdConcepto,CdBodega,LtaPrec,IdVend,CdCms,CdCCosto,CdSubCos,AbreCajon,FechaAdd
 FROM adm_Usucaja
 WHERE IdUsuario=@pmIdUsuario AND nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryUsucajaLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryUsucajaLta] @pmIdUsuario VARCHAR(11)=Null,@pmnFormato VARCHAR(10)=Null
 AS 
 SELECT UC.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario,nFormato,CdCajero,CJ.Usuario AS Cajero
,U.IdGrupo AS CdGrupo,U.IdEstacion AS CdEstacion,U.IdCargo AS CdCargo,Cargo,UC.IdConcepto AS CodConcepto,Concepto,IdDoc,CdBodega,Bodega
,LtaPrec,IdVend,RazonSocial,CdCms,CdCCosto,CCosto,CdSubCos,SubCosto,AbreCajon,UC.FechaAdd AS FecAdd
 FROM adm_Usucaja AS UC INNER JOIN adm_Usuarios AS U ON UC.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS T ON UC.IdVend=T.IdTercero
 INNER JOIN Conceptos AS C ON UC.IdConcepto=C.IdConcepto
 LEFT JOIN adm_Usuarios AS CJ ON UC.CdCajero=CJ.IdUsuario
 LEFT JOIN  Cargos AS CG ON U.IdCargo=CG.IdCargo
 LEFT JOIN Bodegas AS BG ON UC.CdBodega=BG.IdBodega
 LEFT JOIN CentroCosto AS CC ON UC.CdCCosto=CC.IdCCosto
 LEFT JOIN SubCentros AS SC ON UC.CdSubCos=SC.IdSubCos
 WHERE UC.IdUsuario LIKE ISNULL(@pmIdUsuario,'%')  AND nFormato LIKE ISNULL(@pmnFormato,'%')
 ORDER BY U.Usuario,nFormato
GO
/****** Object:  StoredProcedure [dbo].[paQryVales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,nRadica,IdCia,Item,TipoRango,IdRango,NumSerie,NumForma,Fecha,HoraServ,IdCliente
,IdAgencia,IdCuenta,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,PlacaVeh
,CdConductor,NomConductor,CantPasaj,Usuarios,TipFac,NumFactura,IdCiaFac,FechaFac,Anulado,NumDev,FecDev,Observacion,FechaUp,CdUsuario
 FROM Trn_Vales
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryVales_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVales_Cr]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmTipoRango VARCHAR(3)=Null,@pmNumFormaIni INT=Null,@pmNumFormaFin INT=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipoRango,IdRango,NumSerie,NumForma,V.Fecha AS FechaServ,HoraServ,V.nRadica AS NumRadica,V.IdCia AS CdCia,Compania,Item
,IdCliente,CL.RazonSocial AS NomCliente,V.IdAgencia AS ValAgencia,Agencia,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera,FactUnid,FactRutas,FactHoras
,VrPago,VrCobro,IdCuenta,CantPasaj,Usuarios,V.Observacion AS ValObserv,TipFac,NumFactura,IdCiaFac,FechaFac,V.Anulado AS ValAnulado,V.NumDev AS ValNumAnul,V.FecDev AS ValFechaDev
,FechaUp,CdUsuario,UV.Usuario AS ValUsuario
--datos de radicación
,R.Fecha AS FechaRad,FechaVence,R.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,R.Referencia AS DocReferncia,CxPagar,TipCom,Comprobante,IdCiaCom
,R.Anulado AS DocAnulado,R.NumDev AS DocNumDev,R.FecDev  AS DocFecDev,R.Observacion AS Observ,R.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--datos del cliente
,CL.TipoId AS CliTipoId,CL.Dv AS CliDv,CL.Codigo AS CliCodigo,CL.NomCial AS CliNomCial,CL.Direccion AS CliDireccion,CL.IdLocal AS CliCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento
,CL.Telefono AS CliTelefono,CL.Fax AS CliFax,CL.e_mail AS CliEmail,CL.IdSector AS CdSector,SectorEco,CL.IdRegimen AS CdRegimen,Regimen,CL.TipEnte AS CliTipoEnte
 FROM Trn_Vales AS V INNER JOIN Trn_RadicaVales AS R ON V.TipDoc=R.TipDoc AND V.nRadica=R.nRadica AND V.IdCia=R.IdCia
 INNER JOIN  Terceros AS CL ON V.IdCliente=CL.IdTercero
 INNER JOIN Localidades AS L ON CL.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON CL.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON CL.IdSector=SE.IdSector
 INNER JOIN Companias AS CN ON V.IdCia=CN.IdCia
 INNER JOIN  Terceros AS T ON R.IdTercero=T.IdTercero   INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 LEFT JOIN adm_Usuarios AS UV ON V.CdUsuario=UV.IdUsuario  LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia 
 WHERE  (R.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND  R.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND V.IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipoRango LIKE ISNULL(@pmTipoRango,'%')
 AND NumForma BETWEEN ISNULL(@pmNumFormaIni,0) AND ISNULL(@pmNumFormaFin,2147483647)
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 ORDER BY TipoRango,IdRango,NumForma
GO
/****** Object:  StoredProcedure [dbo].[paQryValesRad]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryValesRad] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Item,TipoRango,IdRango,NumSerie,NumForma,Fecha,HoraServ,IdCliente,RazonSocial,V.IdAgencia AS CdAgencia,Agencia
,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera,FactUnid,FactRutas,FactHoras,VrPago,VrCobro,IdCuenta
,CantPasaj,Usuarios,V.Observacion AS Observ,TipFac,NumFactura,IdCiaFac,FechaFac,Anulado,NumDev,FecDev
--,PlacaVeh,CdConductor,NomConductor
 FROM Trn_Vales AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia 
 ORDER BY  Item
GO
/****** Object:  StoredProcedure [dbo].[paQryValesRutas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryValesRutas] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2) 
 AS 
 SELECT Item,V.IdRuta AS CdRuta,DescripRuta,NomRuta,TipoRuta,Origen,Destino,CodRuta
 FROM  Trn_ValesRutas AS V INNER JOIN TaxRutas AS R ON V.IdRuta=R.IdRuta
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryValesRutas_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryValesRutas_Cr]  @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmIdCia CHAR(2)=Null
,@pmTipoRango VARCHAR(3)=Null,@pmNumFormaIni INT=Null,@pmNumFormaFin INT=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdRuta VARCHAR(4)=Null
 AS 
 SELECT  VR.IdRuta AS CdRuta,DescripRuta,VR.TarifPago AS VrPago,VR.TarifCobro AS VrCobro,TipoRango,IdRango,NumSerie,NumForma,V.Fecha AS FechaServ,HoraServ,V.nRadica AS NumRadica,V.IdCia AS CdCia,Compania,V.Item AS ValeItem
,IdCliente,CL.RazonSocial AS NomCliente,V.IdAgencia AS ValAgencia,Agencia,NumMovil,CentCosto,Unidades,HoraRec,HoraEspera,FactUnid,FactRutas,FactHoras
,IdCuenta,CantPasaj,Usuarios,V.Observacion AS ValObserv,TipFac,NumFactura,IdCiaFac,FechaFac,V.Anulado AS ValAnulado,V.NumDev AS ValNumAnul,V.FecDev AS ValFechaDev
,FechaUp,CdUsuario,UV.Usuario AS ValUsuario--,VrPago,VrCobro
--datos de radicación
,R.Fecha AS FechaRad,FechaVence,R.IdTercero AS NitTercero,T.RazonSocial AS NomTercero,R.Referencia AS DocReferncia,CxPagar,TipCom,Comprobante,IdCiaCom
,R.Anulado AS DocAnulado,R.NumDev AS DocNumDev,R.FecDev  AS DocFecDev,R.Observacion AS Observ,R.IdUsuario AS IdUsuari,U.Usuario AS NomUsuario
--datos de ruta
,NomRuta,TipoRuta,Origen,Destino,RT.CodRuta,RT.TarifPago AS RutTarifPago,RT.TarifCobro AS RutTarifCobro
,CL.TipoId AS CliTipoId,CL.Dv AS CliDv,CL.Codigo AS CliCodigo,CL.NomCial AS CliNomCial,CL.Direccion AS CliDireccion,CL.IdLocal AS CliCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,Departamento,CL.Telefono AS CliTelefono
 FROM Trn_Vales AS V INNER JOIN Trn_RadicaVales AS R ON V.TipDoc=R.TipDoc AND V.nRadica=R.nRadica AND V.IdCia=R.IdCia
 INNER JOIN  Terceros AS CL ON V.IdCliente=CL.IdTercero
 INNER JOIN Localidades AS L ON CL.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN Companias AS CN ON V.IdCia=CN.IdCia
 INNER JOIN  Terceros AS T ON R.IdTercero=T.IdTercero   INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 INNER JOIN Trn_ValesRutas AS VR  ON V.TipDoc=VR.TipDoc AND V.nRadica=VR.nRadica AND V.IdCia=VR.IdCia AND V.Item=VR.Item
 INNER JOIN TaxRutas AS RT ON VR.IdRuta=RT.IdRuta
 LEFT JOIN adm_Usuarios AS UV ON V.CdUsuario=UV.IdUsuario  LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia 
 WHERE  (R.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND  R.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND V.IdCia LIKE ISNULL(@pmIdCia,'%%') AND TipoRango LIKE ISNULL(@pmTipoRango,'%')
 AND NumForma BETWEEN ISNULL(@pmNumFormaIni,0) AND ISNULL(@pmNumFormaFin,2147483647)
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND VR.IdRuta LIKE ISNULL(@pmIdRuta,'%')
 ORDER BY TipoRango,IdRango,NumForma
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Contrato]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVeh_Contrato] @pmNumContrato INT
 AS 
 SELECT NumContrato,IdVehiculo,IdAdmon,IdTipCon,FecIngreso,FecRetiro,FecVigencia
,Observaciones,NumPagare,ArchPagare,FecUpdate,IdUsuario
 FROM Veh_Contrato
 WHERE NumContrato=@pmNumContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Contrato_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVeh_Contrato_Cr] @pmNumContrato INT,@pmIdContrato VARCHAR(4),@pmIdAdmon VARCHAR(4)
AS
  SELECT  VC.NumContrato AS Ncontrato, VC.IdVehiculo AS PlacaVeh,NumVeh,VC.IdAdmon AS IdAdmn,TipoAdmon,VC.IdTipCon AS IdContrat,TipoContrato
,VC.FecIngreso AS FechaIngreso,VC.FecVigencia AS FechaVigencia, VC.FecRetiro AS FechaRetiro, Observaciones, FecUpdate, VC.IdUsuario AS IdUsuari
,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,V.IdPropietario AS VehNitProp,VNP.RazonSocial AS VehPropietario,V.IdConductor AS VehCedConductor,VNC.RazonSocial AS VehConductor,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,NumPagare,ArchPagare
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado
,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
  FROM  Veh_Contrato AS VC INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo
  INNER JOIN TiposAdm AS TA ON VC.IdAdmon=TA.IdAdmon
  INNER JOIN TiposCon AS TC ON VC.IdTipCon=TC.IdTipCon
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor   INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TCU ON  V.IdCom=TCU.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  WHERE  VC.IdTipCon LIKE ISNULL(@pmIdContrato,'%')  AND VC.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
  AND ( VC.NumContrato>=ISNULL(@pmNumContrato,0)  AND  VC.NumContrato<=ISNULL(@pmNumContrato,2147483647))
 ORDER BY VC.NumContrato
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Cupos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVeh_Cupos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdVehiculo,IdClase,ValorCupo,ValorSaldo,FecUpdate,IdUsuario
 FROM Veh_Cupos
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Cupos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryVeh_Cupos_Cr] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4)
 AS
  SELECT  VC.IdVehiculo AS PlacaVeh,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor
,Modelo,FecRep,ClaseMat,V.IdCom AS CdComb,TipoComb,NumMotor,SerieChasis,PasjerosPie,PasjerosSen
,IdPropietario,VNP.RazonSocial AS Propietario,IdConductor,VNC.RazonSocial AS Conductor
,V.IdPpd AS CdTipProp,TipoProp,TipoAfil,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdTarifa,TB.Descripcion AS TipoTarifa,FecIngreso,FecVigencia,FecRetiro
,NumSoat,FecSoat,VigSoat,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,ObligaTProd,V.IdEstado AS VehCdEstado,EV.Estado AS VehEstado,V.Inactivo AS VehInactivo
 ,VC.IdClase AS CodClase,ClaseCuenta, VC.ValorCupo AS VrCupo,ValorSaldo, FecUpdate, VC.IdUsuario AS IdUsuari
  FROM   Veh_Cupos AS VC INNER JOIN BusClaseCue AS C ON VC.IdClase=C.IdClase
  INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo 
  INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor 
  INNER JOIN TiposVeh AS TV  ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
  INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
  INNER JOIN Terceros AS VNP ON V.IdPropietario=VNP.IdTercero INNER JOIN Terceros AS VNC ON V.IdConductor=VNC.IdTercero
  LEFT JOIN TiposFuel AS TC ON  V.IdCom=TC.IdCom LEFT JOIN TiposPpt AS TPR  ON V.IdPpd=TPR.IdPpd
  LEFT JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN TiposNivs AS VNS ON V.IdNiv=VNS.IdNiv
  LEFT JOIN  TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa 
  WHERE  VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND VC.IdClase LIKE ISNULL(@pmIdClase,'%')
  ORDER BY  VC.IdVehiculo,ClaseCuenta
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_CuposCte]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryVeh_CuposCte] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4)=Null
AS
 IF @pmIdClase IS NULL
  SELECT  IdVehiculo,V.IdClase AS CodClase,ClaseCuenta, ValorCupo,ValorSaldo, FecUpdate, IdUsuario
  FROM  Veh_Cupos AS V INNER JOIN BusClaseCue ON V.IdClase=BusClaseCue.IdClase
  WHERE  IdVehiculo=@pmIdVehiculo  AND V.IdClase IN ('ADM','OTR')
  ORDER BY V.IdClase
 ELSE
  SELECT  IdVehiculo,V.IdClase AS CodClase,ClaseCuenta, ValorCupo,ValorSaldo, FecUpdate, IdUsuario
  FROM  Veh_Cupos AS V INNER JOIN BusClaseCue ON V.IdClase=BusClaseCue.IdClase
  WHERE  IdVehiculo=@pmIdVehiculo AND V.IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Saldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVeh_Saldos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmIdCia CHAR(2)
 AS 
 SELECT IdVehiculo,IdClase,IdCia,ValorSaldo
 FROM Veh_Saldos
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase LIKE ISNULL(@pmIdClase,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_Saldos_Crr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryVeh_Saldos_Crr] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
,@pmIdAdmon VARCHAR(4)=Null,@pmTipoAfil VARCHAR(10)=Null,@pmIdCia CHAR(2)=Null
 AS
  SELECT  VC.IdVehiculo AS PlacaVeh,NumVeh,VC.IdClase AS CodClase,ClaseCuenta,VC.IdCia AS CodCia, Compania,VC.ValorSaldo AS TotalSaldoCia,VU.ValorCupo AS ValorCupoClase,VU.ValorSaldo AS TotalSaldoClase
,Marca,NomColor,ClaseVeh,TipoVehiculo,Modelo,IdPropietario,NP.RazonSocial AS Propietario,IdConductor,NC.RazonSocial AS Conductor
,V.IdEstado AS IdEstad,Estado,VrSaldoAct,VrLmtCred,CentFinal,V.IdGrupo AS IdGrup,GrupoProp,V.IdAdmon AS IdAdm,TipoAdmon,NContrato,FecIngreso
,CV.Descripcion AS ClaseTarif
  FROM  Veh_Saldos AS VC INNER JOIN BusClaseCue AS C ON VC.IdClase=C.IdClase
  INNER JOIN Companias AS CI ON VC.IdCia=CI.IdCia  INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo
  INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca   INNER JOIN TiposCol AS CO ON V.IdColor=CO.IdColor
  INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
  INNER JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NC ON V.IdConductor=NC.IdTercero
  INNER JOIN EstadoVeh AS E ON V.IdEstado=E.IdEstado INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
  INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon LEFT JOIN Veh_Cupos AS VU ON VC.IdVehiculo=VU.IdVehiculo AND VC.IdClase=VU.IdClase
  LEFT  JOIN TarifBuses AS CV ON V.CdTarifa=CV.IdTarifa 
  WHERE  VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
  AND VC.IdClase LIKE ISNULL(@pmIdClase,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%') AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%')
  AND VC.IdCia LIKE ISNULL(@pmIdCia,'%%') 
  AND TipoAfil LIKE ISNULL(@pmTipoAfil,'%')
 ORDER BY  VC.IdVehiculo,ClaseCuenta,VC.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_SaldosCla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVeh_SaldosCla] @pmIdVehiculo VARCHAR(10)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
 SELECT S.IdVehiculo AS IdVehic, S.IdClase AS IdClas,SUM(ValorSaldo) AS SValSal 
 FROM Veh_Saldos AS S INNER JOIN Vehiculos AS V ON S.IdVehiculo=V.IdVehiculo
 WHERE S.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 AND  S.IdClase LIKE ISNULL(@pmIdClase,'%')  AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 GROUP BY S.IdVehiculo, S.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_SaldosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryVeh_SaldosLta] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdCia CHAR(2)=Null
 AS
  SELECT VC.IdVehiculo AS PlacaVeh,NumVeh,VC.IdClase AS CodClase,ClaseCuenta,VC.IdCia AS CodCia, Compania,VC.ValorSaldo AS TotalSaldoCia,VU.ValorCupo AS ValorCupoClase,VU.ValorSaldo AS TotalSaldoClase
,IdPropietario,RazonSocial
 FROM  Veh_Saldos AS VC  INNER JOIN BusClaseCue AS C ON VC.IdClase=C.IdClase
 INNER JOIN Companias AS CI ON VC.IdCia=CI.IdCia  INNER JOIN Vehiculos AS V ON VC.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero
 LEFT JOIN Veh_Cupos AS VU ON VC.IdVehiculo=VU.IdVehiculo AND VC.IdClase=VU.IdClase
 WHERE  VC.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND VC.IdClase LIKE ISNULL(@pmIdClase, '%') AND VC.IdCia LIKE ISNULL(@pmIdCia,'%%')
 ORDER BY  VC.IdVehiculo,ClaseCuenta,VC.IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryVeh_SaldosSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVeh_SaldosSal] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmIdCia CHAR(2)
AS
   SELECT   IdVehiculo, IdClase, IdCia, ValorSaldo   
   FROM  Veh_Saldos
   WHERE IdVehiculo=@pmIdVehiculo AND  IdClase like ISNULL(@pmIdClase,'%') AND IdCia like ISNULL(@pmIdCia,'%%')
  ORDER BY IdClase, IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehClientes] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT IdVehiculo,NumVeh,IdTipoVeh,IdMarca,LinMarca,ColorVeh,IdTipoMot,Modelo,ClaseMat,Cilind,IdCom,IdLub,IdMarLub,IdTlla,IdMarlla,IdFiltro,IdMarFil,NumSoat,FecSoat,VigSoat
,NitEmpSoat,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,KmInicial,KmActual,NitCliente,CondPago,NumCredito,Observacion,PathFoto,FecPriServ,FecUltServ
,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM VehClientes
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehClientesLta]  @pmIdTipoVeh VARCHAR(4)=Null,@pmIdMarca VARCHAR(4)=Null,@pmIdTipoMot VARCHAR(4)=Null,@pmModelo VARCHAR(4)=Null
,@pmIdCom VARCHAR(4)=Null,@pmIdLub VARCHAR(4)=Null,@pmIdMarLub VARCHAR(4)=Null,@pmIdTlla VARCHAR(4)=Null,@pmIdMarlla VARCHAR(4)=Null
,@pmIdFiltro VARCHAR(4)=Null,@pmIdMarFil VARCHAR(4)=Null,@pmNitCliente VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmCondPago VARCHAR(10)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT IdVehiculo,NumVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,LinMarca,ColorVeh,V.IdTipoMot AS CdTipMotor,TipoMotor,Modelo,ClaseMat
,Cilind,V.IdCom AS CdTipComb,TipoComb,V.IdLub AS CdLub,TipoLub,IdMarLub,MU.Marca AS MarcaLub,V.IdTlla AS CdTipLlantas,TipoLlanta,IdMarlla,ML.Marca AS MarcaLlantas
,V.IdFiltro AS CdFiltro,TipoFiltro,IdMarFil,MF.Marca AS MarcaFiltro,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,KmInicial,KmActual,NitCliente,NC.RazonSocial AS Cliente,CondPago,NumCredito,V.Observacion AS Observ,PathFoto,FecPriServ,FecUltServ
,V.IdEstado AS CdEstado,Estado,V.Inactivo AS VehInactivo,V.FechaAdd AS FecAdd,V.FechaUpdate AS FecUpdate,V.IdUsuario AS CdUsuario,Usuario,EV.NColor AS NumColor,OutDemand
 FROM VehClientes  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca  INNER JOIN TiposMot AS TM ON V.IdTipoMot=TM.IdTipoMot
 INNER JOIN TiposFuel AS TF ON V.IdCom=TF.IdCom INNER JOIN TiposLub AS TL ON V.IdLub=TL.IdLub
 INNER JOIN TiposLla AS TLL ON V.IdTlla=TLL.IdTlla INNER JOIN Marcas AS ML ON V.IdMarlla=ML.IdMarca
 INNER JOIN Marcas AS MU ON V.IdMarLub=MU.IdMarca INNER JOIN TiposFil AS TFL ON  V.IdFiltro=TFL.IdFiltro
 INNER JOIN Marcas AS MF ON V.IdMarFil=MF.IdMarca
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS NC ON  V.NitCliente=NC.IdTercero   LEFT JOIN Terceros AS NS ON V.NitEmpSoat =NS.IdTercero 
 WHERE   V.IdTipoVeh LIKE ISNULL(@pmIdTipoVeh,'%')  AND V.IdMarca LIKE ISNULL(@pmIdMarca,'%') AND V.IdTipoMot LIKE ISNULL(@pmIdTipoMot,'%')
 AND Modelo LIKE ISNULL(@pmModelo,'%') AND V.IdCom LIKE ISNULL(@pmIdCom,'%')  AND V.IdLub LIKE ISNULL(@pmIdLub,'%')
 AND  IdMarLub LIKE ISNULL(@pmIdMarLub,'%') AND V.IdTlla LIKE ISNULL(@pmIdTlla,'%')  AND IdMarlla LIKE ISNULL(@pmIdMarlla,'%')
 AND V.IdFiltro LIKE ISNULL(@pmIdFiltro,'%') AND IdMarFil LIKE ISNULL(@pmIdMarFil ,'%')
 AND NitCliente LIKE ISNULL(@pmNitCliente,'%')  AND V.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND CondPago  LIKE ISNULL(@pmCondPago,'%') 
 AND (V.Inactivo=ISNULL(@pmInactivo,0) or V.Inactivo=ISNULL(@pmInactivo,1))
 AND (V.FechaAdd>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND V.FechaAdd<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY  IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientesNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehClientesNit] @pmNitCliente VARCHAR(16),@pmCondPago VARCHAR(10)=Null
 AS 
 SELECT IdVehiculo,NumVeh,NitCliente,CondPago,NumCredito,KmActual,IdEstado,Inactivo
 FROM VehClientes
 WHERE NitCliente=@pmNitCliente  AND Inactivo=0 AND CondPago LIKE ISNULL(@pmCondPago,'%')
 ORDER BY  IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehClientesNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehClientesNum] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmInactivo BIT=Null
 AS 
 SELECT IdVehiculo,NumVeh,IdTipoVeh,IdMarca,LinMarca,ColorVeh,IdTipoMot,Modelo,ClaseMat,Cilind,IdCom,IdLub,IdMarLub,IdTlla,IdMarlla,IdFiltro,IdMarFil,NumSoat,FecSoat,VigSoat
,NitEmpSoat,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,KmInicial,KmActual,NitCliente,CondPago,NumCredito,Observacion,PathFoto,FecPriServ,FecUltServ
,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario
 FROM VehClientes
 WHERE (IdVehiculo=@pmIdVehiculo OR NumVeh=@pmNumVeh)
 AND  (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY  IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehConductor] @pmIdVehiculo VARCHAR(10),@pmNumero INT
 AS 
 SELECT IdVehiculo,Numero,Fecha,IdPropietario,IdConductor,IdCondNuevo,Observacion,TimeSys,IdUsuario
 FROM Trn_VehConductor
 WHERE IdVehiculo=@pmIdVehiculo
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductorDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehConductorDso] @pmIdVehiculo VARCHAR(10)=Null,@pmIdConductor VARCHAR(16)=Null
,@pmIdCondNuevo VARCHAR(16)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT C.IdVehiculo AS PlacaVeh,Numero,Fecha,C.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario
,C.IdConductor AS CedConductor,NC.RazonSocial AS CondAnterior,IdCondNuevo,NN.RazonSocial AS NuevoConductor,C.Observacion AS Observ
,NumVeh,V.IdConductor AS VehCedCondtor,VC.RazonSocial AS VehConductor,TimeSys,C.IdUsuario AS IdUsuari,Usuario
 FROM Trn_VehConductor AS C INNER JOIN Vehiculos AS V ON C.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NP ON C.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NC ON C.IdConductor=NC.IdTercero 
 INNER JOIN Terceros AS NN ON C.IdCondNuevo=NN.IdTercero 
 INNER JOIN Terceros AS VC ON V.IdConductor=VC.IdTercero 
 INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE V.Inactivo=0 AND  C.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND C.IdConductor LIKE ISNULL(@pmIdConductor,'%')
 AND IdCondNuevo LIKE ISNULL(@pmIdCondNuevo,'%') 
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY C.IdVehiculo,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductoresLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehConductoresLta] @pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT  VP.IdVehiculo AS PlacaVeh,NumVeh,Item,CedConductor,T.RazonSocial AS Conductor,TipoCond,FechaIng,EstadoCond,IdPropietario,NP.RazonSocial AS VehPropietario
,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,NumMotor,SerieChasis,NumSerie
,NitEmpresa,NE.RazonSocial AS Empresa,IdPoseedor,NT.RazonSocial AS Poseedor,V.IdConductor AS VehCedCond,NC.RazonSocial AS VehConductor
,NContrato,FecIngreso, FecVigencia, FecRetiro,V.IdAdmon AS CdAdmon,TipoAdmon,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo
--datos del conductor
,T.Codigo AS TercCodigo,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM VehConductores AS VP INNER JOIN  Vehiculos  AS V ON VP.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS T ON  VP.CedConductor=T.IdTercero
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh  INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
 INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero  INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  
 INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 WHERE VP.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 ORDER BY  VP.IdVehiculo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVehConductorId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehConductorId] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT MAX(Numero) AS MxNum
 FROM Trn_VehConductor
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehiculos] @pmIdVehiculo VARCHAR(10)
 AS 
SELECT IdVehiculo,NumVeh,ClaseVeh,IdTipoVeh,IdMarca,IdLinea,IdColor,IdTipoMot,IdCrceria,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans,IdCat,CdCatv,ClaseMat,Cilind,CapTanq,IdCom,IdLub,IdTlla
,IdMarlla,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie,PasjerosSen,NitEmpresa
,IdPropietario,IdPoseedor,IdConductor,IdPpd,Adquisc,NitProv,FecCompra,VrComcial,VrAseg,VrAvaludo,VidaUtil,FecSalida,NContrato,IdAdmon,IdNiv,IdGrupo,CdGrupR,CdTarifa,FecIngreso,FecVigencia
,FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,TarjProp,FecTProp,VigTProp,CdLugTp,Ulttramite,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal,KmInicial,KmActual,Km2Actual
,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,Descripcion,Observacion,CdCenSer,CdLocal,Ubicacion,PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,IdEstado,Inactivo
,TipoAfil,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,FechaAdd,FechaUpdate,IdUsuario
,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil,CdRutaHab,DeclaracImp,TipoIngreso,IdOrgTra,GPSoperador,GPSUsuario,GPSClave,CantFiltros,GPSIdOper,LiqFletePropio,EdoVincula
 FROM Vehiculos
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosCau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosCau] @pmIdVehiculo VARCHAR(10),@pmIdEstado VARCHAR(4)
AS
 SELECT IdVehiculo,NumVeh,CdTarifa,IdTipoVeh,PasjerosPie,PasjerosSen,IdPropietario,IdPoseedor,IdConductor,IdPpd,IdGrupo,TipoAfil,IdAdmon,NContrato
,FecIngreso, FecRetiro,FecVigencia,DocCompleta,ObligaTProd,KmActual,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,IdEstado
 FROM  Vehiculos
 WHERE IdEstado<>@pmIdEstado AND  IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosCon] @pmIdVehiculo VARCHAR(10)
AS
 SELECT    IdVehiculo, NumVeh,IdGrupo,TipoAfil, IdAdmon,NContrato,FecIngreso,FecVigencia, FecRetiro
,FecSalida, VidaUtil,FecPagImp, DocCompleta,Observacion, IdEstado
 FROM     Vehiculos 
 WHERE   IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosFicha]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosFicha] @pmIdVehiculo VARCHAR(4)
 AS 
 SELECT IdVehiculo,NumVeh,ClaseVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinea,LineaVeh
,V.IdColor AS CdColor,NomColor,V.IdTipoMot AS CdTipMotor,TipoMotor,V.IdCrceria AS CdCarr,TipoCar,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans
,V.IdCat AS CodCatg,Catpeaje,CdCatv,ClaseMat,Cilind,CapTanq,V.IdCom AS CdTipComb,TipoComb,V.IdLub AS CdLub,TipoLub,V.IdTlla AS CdTipLlantas,TipoLlanta
,IdMarlla,ML.Marca AS MarcaLlantas,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque
,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie, PasjerosSen,NitEmpresa,NE.RazonSocial AS Empresa,IdPropietario,NP.RazonSocial AS Propietario
,IdPoseedor,NT.RazonSocial AS Poseedor,V.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,V.IdPpd AS CdTipProp,TipoProp,VehPropio,Adquisc,NitProv,NPV.RazonSocial AS Proveedor
,FecCompra,VrComcial,VrAseg,VrAvaludo,VidaUtil,FecSalida,NContrato, V.IdAdmon AS CdAdmon,TipoAdmon, V.IdNiv AS CdNivel,NivelServicio, V.IdGrupo AS CdGrupo,GrupoProp,CdGrupR,CdTarifa
,TB.Descripcion AS ClaseTarifa, FecIngreso, FecVigencia, FecRetiro
,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,TarjProp,FecTProp,VigTProp,CdLugTp,LT.Localidad AS LugarTarjProp,Ulttramite,RespCivil,FecRCivil,VigRCivil
,RegNalCarga,FecRegNal,VigRegNal,KmInicial,KmActual,Km2Actual,V.Descripcion AS VehDescripcion,V.Observacion AS Observ,CdCenSer,CentroServ,CdLocal,LU.Localidad AS CiuUbicacion,LU.IdDep AS CodDpto,Departamento
,Ubicacion,FecPriServ,FecUltServ,Regtradora,CentInicial, CentFinal, VrLmtCred, VrSaldoAct, FecUltAcc, TieneAcc, FecPagImp,V.IdEstado AS CdEstado,Estado
,V.Inactivo AS Inactvo,V.IdUsuario AS CdUsuario,Usuario,V.FechaAdd AS Fec_Add,V.FechaUpdate AS Fec_Upd,EV.NColor AS NumColor,OutDemand
,TipoAfil,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil
,DeclaracImp,TipoIngreso,V.IdOrgTra AS CdOrgTra,NomOrgTrans,GPSoperador,GPSUsuario,GPSClave,GPSIdOper,LiqFletePropio,V.EdoVincula
--datos de la licencia
,Licencia,LugarLic,CatLicencia,VigLicencia,CdRutaHab
 FROM Vehiculos  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposMot AS TM ON V.IdTipoMot=TM.IdTipoMot
 INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria INNER JOIN PeajesCat AS CP ON V.IdCat=CP.IdCat
 INNER JOIN TiposFuel AS TF ON V.IdCom=TF.IdCom INNER JOIN TiposLub AS TL ON V.IdLub=TL.IdLub
 INNER JOIN TiposLla AS TLL ON V.IdTlla=TLL.IdTlla INNER JOIN Marcas AS ML ON V.IdMarlla=ML.IdMarca
 INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
 INNER JOIN TiposNivs AS NV ON V.IdNiv=NV.IdNiv
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NPV ON V.NitProv=NPV.IdTercero
 LEFT JOIN Terceros AS NS ON V.NitEmpSoat =NS.IdTercero LEFT JOIN Localidades AS LT ON V.CdLugTp=LT.IdLocal
 LEFT JOIN CentrosServ AS CS ON V.CdCenSer =CS.IdCenSer 
 LEFT JOIN Localidades AS LU ON V.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
 LEFT JOIN TarifBuses AS TB ON V.CdTarifa =TB.IdTarifa LEFT JOIN  TercCndtores AS CT ON V.IdConductor=CT.IdConductor
  LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar LEFT JOIN OrgTransito AS OG ON V.IdOrgTra=OG.IdOrgTra
 WHERE  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehiculosLta] @pmClaseVeh VARCHAR(10)=Null,@pmIdTipoVeh VARCHAR(4)=Null,@pmIdMarca VARCHAR(4)=Null
,@pmIdTipoMot VARCHAR(4)=Null,@pmIdCrceria VARCHAR(4)=Null,@pmModelo VARCHAR(4)=Null,@pmConfig VARCHAR(5)=Null,@pmIdCat VARCHAR(4)=Null
,@pmClaseMat VARCHAR(10)=Null,@pmIdCom VARCHAR(4)=Null,@pmIdLub VARCHAR(4)=Null,@pmIdTlla VARCHAR(4)=Null,@pmIdMarlla VARCHAR(4)=Null
,@pmIdPropietario VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdPpd VARCHAR(4)=Null
,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null,@pmFecComIni SMALLDATETIME=Null,@pmFecComFin SMALLDATETIME=Null
,@pmIdAdmon VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=Null
 AS 
 SELECT IdVehiculo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,TC.TipoCar AS TipoCarr,CL.NomColor AS Color,V.Modelo AS ModeloVeh,FecRep,Config,V.IdCat AS CodCatg,CarrCapac
,PesoVacio,NumMotor,SerieChasis,RQ.IdCrceria AS RmqIdCarr,MR.Marca AS MarcaRmq,CR.NomColor AS ColorRmq,NitEmpresa,NE.RazonSocial AS Empresa
,IdPoseedor,NT.RazonSocial AS Poseedor,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,CdTarifa,TarjProp,RespCivil,VigRCivil,VrComcial,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo,FecPriServ,FecUltServ
,RegNalCarga,FecRegNal,VigRegNal,RevTecMec,FecTecMec,VigTecMec,V.Observacion AS Observ,TipoAfil
,NumVeh,ClaseVeh,V.IdTipoVeh AS CdTipo,V.IdLinea AS CdLinea,LineaVeh,V.IdColor AS CdColor,V.IdTipoMot AS CdTipMotor,TipoMotor
,V.IdCrceria AS CdCarr,VehArtic,NumLlan,NumLlans,Catpeaje,CdCatv,ClaseMat,Cilind,CapTanq,V.IdCom AS CdTipComb,TipoComb,V.IdLub AS CdLub
,TipoLub,V.IdTlla AS CdTipLlantas,TipoLlanta,IdMarlla,ML.Marca AS MarcaLlantas,PesoMax,NumSerie,V.NitProv AS NitProveedor,NPV.RazonSocial AS Proveedor,V.FecCompra AS FechaCompra
,VrAseg,V.VrAvaludo AS VlrAvaludo,V.VidaUtil AS Vida_Util,FecSalida,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon,V.IdNiv AS CdNivel,NivelServicio,V.IdGrupo AS CdGrupo,GrupoProp,CdGrupR,V.FecIngreso
,V.FecVigencia,V.FecRetiro,FecTProp,VigTProp,CdLugTp,LT.Localidad AS LugarTarjProp,Ulttramite,FecRCivil,KmInicial,KmActual,Km2Actual,V.Descripcion AS VehDescripcion,V.CdCenSer AS CodCentro,CentroServ
,V.CdLocal AS CodCiuUbic,LU.Localidad AS CiuUbicacion,LU.IdDep AS CodDpto,Departamento,V.Ubicacion,V.PathFoto,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,FecUltAcc,TieneAcc,FecPagImp
,V.IdUsuario AS CdUsuario,Usuario,V.FechaAdd AS Fec_Add,V.FechaUpdate AS Fec_Upd,EV.NColor AS NumColor,OutDemand,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion
,FecCertMovil,VigCertMovil,CdRutaHab,RQ.IdMarca AS RmqIdMarca,RQ.IdColor AS RmqIdColor,RC.TipoCar AS RmqTipoCar,GPSoperador,GPSUsuario,GPSClave,GPSIdOper,CantFiltros,LiqFletePropio,V.EdoVincula
--campos libres
,TarjOper,FecTarjOper,VigTarjOper,CertGases,FecCertGas,VigCertGas,DeclaracImp,TipoIngreso,V.IdOrgTra AS CdOrgTra,NomOrgTrans
--Informacion coductor
,V.IdConductor,NC.RazonSocial AS Conductor,NC.IdLugarCed,LCCE.Localidad AS LugCed,CND.TipoSangre,CND.FactorRh,CND.FecNacmto,NC.TelMovil AS CelCnd,NC.Telefono AS TelCnd,NC.e_mail AS Mailcnd,nc.Direccion AS DirCnd
,NC.IdLocal,LCND.Localidad AS LocCnd,CND.Licencia,CND.CatLicencia,CCND.ClaseCuenta AS TipCtaCnd,CND.NumCuenta AS CtaCnd,BCND.Banco AS BanCnd,FECN.Fondo AS FonEps,FPCN.Fondo AS FonPen,FACN.Fondo AS FonArl
--INFORMACION TRAILER Y PROPIETARIO
,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,V.UndCapc AS UndCapacidad,Comptmtos,CapComp,PasjerosPie,PasjerosSen,VR.IdPropietario AS IdPropTra,PT.RazonSocial AS NomPropTra,LPT.Localidad AS LugCedPt
,PT.Direccion AS DirProTra,PT.TelMovil AS CelProTra,PT.Telefono AS TelProTra
--INFORMACION PROPIEATARIO DEL VEHICULO
,V.IdPropietario AS NitPropietario,NP.RazonSocial AS Propietario,NP.Direccion AS DirProV,NP.TelMovil AS CelularProV,NP.Telefono AS TelProV,V.IdPpd AS CdTipProp,TipoProp,VehPropio,Adquisc
 FROM Vehiculos  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposMot AS TM ON V.IdTipoMot=TM.IdTipoMot
 INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria INNER JOIN PeajesCat AS CP ON V.IdCat=CP.IdCat
 INNER JOIN TiposFuel AS TF ON V.IdCom=TF.IdCom INNER JOIN TiposLub AS TL ON V.IdLub=TL.IdLub
 INNER JOIN TiposLla AS TLL ON V.IdTlla=TLL.IdTlla INNER JOIN Marcas AS ML ON V.IdMarlla=ML.IdMarca
 INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
 INNER JOIN TiposNivs AS NV ON V.IdNiv=NV.IdNiv
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NPV ON V.NitProv=NPV.IdTercero
 LEFT JOIN Terceros AS NS ON V.NitEmpSoat =NS.IdTercero LEFT JOIN Localidades AS LT ON V.CdLugTp=LT.IdLocal
 LEFT JOIN CentrosServ AS CS ON V.CdCenSer =CS.IdCenSer 
 LEFT JOIN Localidades AS LU ON V.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
 LEFT JOIN VehRemolq AS RQ ON V.CdRemque=RQ.IdRemque
 LEFT JOIN Marcas AS MR ON RQ.IdMarca=MR.IdMarca LEFT JOIN TiposCol AS CR ON RQ.IdColor=CR.IdColor 
 LEFT JOIN TiposCar AS RC ON RQ.IdCrceria=RC.IdCrceria LEFT JOIN OrgTransito AS OG ON V.IdOrgTra=OG.IdOrgTra
 --CONSULTA PARA INFORMACION DEL CONDUCTOR
 LEFT JOIN TercCndtores AS CND ON V.IdConductor=CND.IdConductor LEFT JOIN Localidades AS LCCE ON NC.IdLugarCed=LCCE.IdLocal
 LEFT JOIN Localidades AS LCND ON NC.IdLocal=LCND.IdLocal LEFT JOIN ClaseCta AS CCND ON CND.IdClase=CCND.IdClase
 LEFT JOIN Bancos AS BCND ON CND.IdBanco=BCND.IdBanco LEFT JOIN Fondos AS FECN ON CND.CdFonEps=FECN.IdFondo
 LEFT JOIN Fondos AS FPCN ON CND.CdFonPen=FPCN.IdFondo LEFT JOIN Fondos AS FACN ON CND.CdFonArp=FACN.IdFondo
 --CONSULTA TRAILER
 LEFT JOIN VehRemolq AS VR ON V.CdRemque=VR.IdRemque LEFT JOIN Terceros AS PT ON VR.IdPropietario=PT.IdTercero
 LEFT JOIN Localidades AS LPT ON PT.IdLugarCed=LPT.IdLocal
 WHERE ClaseVeh LIKE ISNULL(@pmClaseVeh,'%') AND V.IdTipoVeh LIKE ISNULL(@pmIdTipoVeh,'%')
 AND V.IdMarca LIKE ISNULL(@pmIdMarca,'%') AND V.IdTipoMot LIKE ISNULL(@pmIdTipoMot,'%')
 AND V.IdCrceria LIKE ISNULL(@pmIdCrceria,'%')  AND V.Modelo LIKE ISNULL(@pmModelo,'%')
 AND Config LIKE ISNULL(@pmConfig,'%') AND V.IdCat LIKE ISNULL(@pmIdCat ,'%')
 AND ClaseMat  LIKE ISNULL(@pmClaseMat,'%') AND V.IdCom LIKE ISNULL(@pmIdCom,'%')
 AND V.IdLub LIKE ISNULL(@pmIdLub,'%') AND V.IdTlla LIKE ISNULL(@pmIdTlla,'%')
 AND IdMarlla LIKE ISNULL(@pmIdMarlla,'%')  AND V.IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')  AND V.IdConductor LIKE ISNULL(@pmIdConductor,'%') 
 AND V.IdPpd LIKE ISNULL(@pmIdPpd,'%') AND V.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND V.IdAdmon LIKE ISNULL(@pmIdAdmon,'%') AND V.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND (V.Inactivo=ISNULL(@pmInactivo,0) or V.Inactivo=ISNULL(@pmInactivo,1))
 AND (V.FecCompra>=ISNULL(@pmFecComIni,CAST('19100101' AS SMALLDATETIME)) AND V.FecCompra<=ISNULL(@pmFecComFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY  IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosMay]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehiculosMay]  @pmIdTipoVeh VARCHAR(4)=Null,@pmIdMarca VARCHAR(4)=Null,@pmModelo VARCHAR(4)=Null
,@pmIdPropietario VARCHAR(16)=Null,@pmIdConductor VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmFecComIni SMALLDATETIME=Null,@pmFecComFin SMALLDATETIME=Null
 AS 
 SELECT IdVehiculo,NumVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinea,LineaVeh
,V.IdColor AS CdColor,NomColor,Modelo,VehArtic,NumMotor,SerieChasis,NumSerie,ClaseMat,CdRemque
,Comptmtos,CapComp,NitEmpresa,NE.RazonSocial AS Empresa,IdPropietario,NP.RazonSocial AS Propietario
,IdConductor,NC.RazonSocial AS Conductor,FecIngreso, FecVigencia, FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,TarjProp,FecTProp,VigTProp,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal
,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,Descripcion,V.Observacion AS Observ
,FecPriServ,FecUltServ,TipoAfil,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo,V.IdUsuario AS CdUsuario,Usuario
,V.FechaAdd AS Fec_Add,V.FechaUpdate AS Fec_Upd,EV.NColor AS NumColor,OutDemand,V.LiqFletePropio,V.EdoVincula
 FROM Vehiculos  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero 
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero 
 LEFT JOIN Terceros AS NS ON V.NitEmpSoat =NS.IdTercero 
 WHERE V.IdTipoVeh LIKE ISNULL(@pmIdTipoVeh,'%')  AND V.IdMarca LIKE ISNULL(@pmIdMarca,'%')
 AND Modelo LIKE ISNULL(@pmModelo,'%')   AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND  IdConductor LIKE ISNULL(@pmIdConductor,'%')  AND  V.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (V.Inactivo=ISNULL(@pmInactivo,0) or V.Inactivo=ISNULL(@pmInactivo,1))
 AND (FecCompra>=ISNULL(@pmFecComIni,CAST('19100101' AS SMALLDATETIME)) AND FecCompra<=ISNULL(@pmFecComFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY  IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosMayPol]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosMayPol] @pmFecha SMALLDATETIME,@pmIdPropietario VARCHAR(16)=Null,@pmInactivo BIT=Null
 AS 
 SELECT V.IdVehiculo AS PlacaVeh,NumVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinea,LineaVeh
,V.IdColor AS CdColor,NomColor,Modelo,VehArtic,NumMotor,SerieChasis,NumSerie,ClaseMat,CdRemque
,Comptmtos,CapComp,NitEmpresa,NE.RazonSocial AS Empresa,IdPropietario,NP.RazonSocial AS Propietario
,V.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,FecIngreso, V.FecVigencia AS FecVigContrato, FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora
,TarjProp,FecTProp,VigTProp,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal
,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper,Descripcion,V.Observacion AS Observ
,FecPriServ,FecUltServ,TipoAfil,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo,V.IdUsuario AS CdUsuario,Usuario
,V.FechaAdd AS Fec_Add,EV.NColor AS NumColor,OutDemand
--documentos del conductor
,Licencia,LugarLic,CatLicencia,VigLicencia,CertJudicial,FecJudicial,VigJudicial
,NumTarjeta,EdicTarjeta,FecTarjeta,VigTarjeta,PasSeguridad,FecPasSeg,VigPasSeg
--otras polizas
,VP.IdClase AS CodClase,ClasePoliza,Numero,FecEmision,VP.FecVigencia AS FecVencePoliza,NitCompania
,TCP.RazonSocial AS NombreCia,Valor,Comntarios
 FROM Vehiculos  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero 
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero  LEFT JOIN Terceros AS NS ON V.NitEmpSoat =NS.IdTercero 
 LEFT JOIN  TercCndtores AS CT ON V.IdConductor=CT.IdConductor   LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar 
 LEFT JOIN VehPolizas AS VP ON V.IdVehiculo=VP.IdVehiculo LEFT JOIN ClasePol AS CLP ON VP.IdClase=CLP.IdClase
 LEFT JOIN Terceros AS TCP ON VP.NitCompania=TCP.IdTercero
 WHERE V.IdVehiculo<>'0' AND  (VigSoat<=@pmFecha 
  OR ISNULL(VigTProp,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigRCivil,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigRegNal,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigTecMec,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigCertGas,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigTarjOper,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
--DEL CONDUCTOR
  OR ISNULL(VigLicencia,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigJudicial,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
  OR ISNULL(VigTarjeta,CAST('20781230' AS SMALLDATETIME))<=@pmFecha
--OTRAS POLIZAS
  OR ISNULL(VP.FecVigencia,CAST('20781230' AS SMALLDATETIME))<=@pmFecha  ) 
  AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND (V.Inactivo=ISNULL(@pmInactivo,0) or V.Inactivo=ISNULL(@pmInactivo,1))
ORDER BY  V.IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosMot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosMot]  @pmNumMotor VARCHAR(30),@pmInactivo BIT=Null
 AS 
 SELECT IdVehiculo,NumVeh,ClaseVeh,NumMotor,Inactivo,IdEstado
 FROM Vehiculos
 WHERE NumMotor=@pmNumMotor
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosNom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosNom] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT IdVehiculo,NumVeh,ClaseVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinea,LineaVeh
,V.IdColor AS CdColor,NomColor,V.IdCrceria AS CdCarr,TipoCar,Modelo,FecRep,Config,ClaseMat,V.IdCom AS CdTipComb,TipoComb
,NumMotor,SerieChasis,NumSerie,CdRemque,CarrCapac,UndCapc,Comptmtos,CapComp
,IdPropietario,NP.RazonSocial AS Propietario,IdPoseedor,NT.RazonSocial AS Poseedor,IdConductor,NC.RazonSocial AS Conductor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,NContrato,Descripcion,CdCenSer,CentroServ,CdLocal,LU.Localidad AS CiuUbicacion
,LU.IdDep AS CodDpto,Departamento,Ubicacion,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo,EV.NColor AS NumColor,OutDemand
, V.IdNiv AS CdNivel,NivelServicio,TipoAfil
 FROM Vehiculos  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor  INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria 
 INNER JOIN TiposFuel AS TF ON V.IdCom=TF.IdCom 
 INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado 
 LEFT JOIN CentrosServ AS CS ON V.CdCenSer =CS.IdCenSer 
 LEFT JOIN Localidades AS LU ON V.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
 LEFT JOIN TiposNivs AS NS ON V.IdNiv=NS.IdNiv
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosNum] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmInactivo BIT=Null
 AS 
 SELECT Vehiculos.*
 FROM Vehiculos
 WHERE (IdVehiculo=@pmIdVehiculo OR NumVeh=@pmNumVeh)
 AND (Inactivo=ISNULL(@pmInactivo,0) or Inactivo=ISNULL(@pmInactivo,1))
 ORDER BY IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPol]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosPol] @pmFEIni SMALLDATETIME=Null,@pmFEFin SMALLDATETIME=Null,@pmFVIni SMALLDATETIME=Null,@pmFVFin SMALLDATETIME=Null
 AS 
 SELECT V.IdVehiculo AS PlacaVeh,NumVeh,ClaseVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinea,LineaVeh
,V.IdColor AS CdColor,NomColor,V.IdTipoMot AS CdTipMotor,TipoMotor,V.IdCrceria AS CdCarr,TipoCar,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans
,V.IdCat AS CodCatg,Catpeaje,CdCatv,ClaseMat,Cilind,CapTanq,V.IdCom AS CdTipComb,TipoComb,V.IdLub AS CdLub,TipoLub,V.IdTlla AS CdTipLlantas,TipoLlanta
,IdMarlla,ML.Marca AS MarcaLlantas,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie,PasjerosSen
,NitEmpresa,NE.RazonSocial AS Empresa,IdPropietario,NP.RazonSocial AS Propietario,IdPoseedor,NT.RazonSocial AS Poseedor,IdConductor,NC.RazonSocial AS Conductor,V.IdPpd AS CdTipProp,TipoProp
,TP.VehPropio,V.TipoAfil,Adquisc,NitProv,NPV.RazonSocial AS Proveedor,FecCompra,VrComcial,VrAseg,VrAvaludo,VidaUtil,FecSalida,NContrato,V.IdAdmon AS CdAdmon,TipoAdmon,V.IdNiv AS CdNivel,NivelServicio
,V.IdGrupo AS CdGrupo,GrupoProp,CdGrupR,CdTarifa,FecIngreso,V.FecVigencia AS FechVigCont,V.FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,TarjProp,FecTProp,VigTProp
,CdLugTp,LT.Localidad AS LugarTarjProp,Ulttramite,RespCivil,FecRCivil,VigRCivil,RegNalCarga,FecRegNal,VigRegNal,V.RevTecMec,V.FecTecMec,V.VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper
,KmInicial,KmActual,Km2Actual,Regtradora,CentInicial,CentFinal,V.VrLmtCred,V.VrSaldoAct,V.Descripcion,V.Observacion AS Observ,V.CdCenSer,CentroServ,V.CdLocal,LU.Localidad AS CiuUbicacion
,LU.IdDep AS CodDpto,Departamento,V.Ubicacion,V.PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil
,CdRutaHab,DeclaracImp,TipoIngreso,V.IdOrgTra AS CdOrgTra,NomOrgTrans,GPSoperador,GPSUsuario,GPSClave,CantFiltros,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo,V.IdUsuario AS CdUsuario,Usuario
,V.FechaAdd AS Fec_Add,V.FechaUpdate AS Fec_Upd,EV.NColor AS NumColor,OutDemand
--información de polizas
,VP.IdClase AS CodClase,ClasePoliza,Numero,FecEmision,VP.FecVigencia AS FecVencePoliza,NitCompania,TCPX.RazonSocial AS NombreCia,Valor,Comntarios,DiasAviso
 FROM Vehiculos AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposMot AS TM ON V.IdTipoMot=TM.IdTipoMot
 INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria INNER JOIN PeajesCat AS CP ON V.IdCat=CP.IdCat
 INNER JOIN TiposFuel AS TF ON V.IdCom=TF.IdCom INNER JOIN TiposLub AS TL ON V.IdLub=TL.IdLub
 INNER JOIN TiposLla AS TLL ON V.IdTlla=TLL.IdTlla INNER JOIN Marcas AS ML ON V.IdMarlla=ML.IdMarca
 INNER JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON V.IdConductor=NC.IdTercero INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
 INNER JOIN TiposNivs AS NV ON V.IdNiv=NV.IdNiv
 LEFT JOIN Terceros AS NE ON V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NPV ON V.NitProv=NPV.IdTercero
 LEFT JOIN Terceros AS NS ON V.NitEmpSoat=NS.IdTercero LEFT JOIN Localidades AS LT ON V.CdLugTp=LT.IdLocal
 LEFT JOIN CentrosServ AS CS ON V.CdCenSer=CS.IdCenSer 
 LEFT JOIN Localidades AS LU ON V.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
 LEFT JOIN OrgTransito AS OG ON V.IdOrgTra=OG.IdOrgTra
 --subconsulta polizas  LEFT JOIN VehPolizas AS VP ON V.IdVehiculo=VP.IdVehiculo
 LEFT JOIN (SELECT * FROM VehPolizas WHERE FecEmision BETWEEN ISNULL(@pmFEIni,CAST('19900101' AS SMALLDATETIME)) AND ISNULL(@pmFEFin,CAST('20781230' AS SMALLDATETIME))
 AND FecVigencia BETWEEN ISNULL(@pmFVIni,CAST('19900101' AS SMALLDATETIME)) AND ISNULL(@pmFVFin,CAST('20781230' AS SMALLDATETIME))) AS VP ON V.IdVehiculo=VP.IdVehiculo
 LEFT JOIN ClasePol AS CLP ON VP.IdClase=CLP.IdClase LEFT JOIN Terceros AS TCPX ON VP.NitCompania=TCPX.IdTercero
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosPos] @pmIdPoseedor VARCHAR(16)
 AS 
SELECT IdVehiculo,NumVeh,ClaseVeh,IdPropietario,IdPoseedor,IdConductor,Descripcion
,IdEstado,Inactivo
 FROM Vehiculos
 WHERE Inactivo=0 AND  IdPoseedor=@pmIdPoseedor
 ORDER BY IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPpt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosPpt] @pmIdPropietario VARCHAR(16) 
AS
 SELECT  IdVehiculo, NumVeh,IdPropietario,IdConductor,IdPoseedor,IdConductor,IdGrupo
,TipoAfil,IdAdmon,VrLmtCred,VrSaldoAct, IdEstado,Inactivo
 FROM  Vehiculos 
 WHERE  IdPropietario=@pmIdPropietario AND Inactivo=0
 ORDER BY IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPpt1]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosPpt1] @pmIdPropietario VARCHAR(16) =Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 SELECT  IdVehiculo, NumVeh,IdPropietario,IdConductor,IdGrupo,TipoAfil,IdAdmon,VrLmtCred,VrSaldoAct, IdEstado,Inactivo
 FROM  Vehiculos 
 WHERE IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')  AND  IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 ORDER BY IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosPza]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosPza] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT V.IdVehiculo AS PlacaVeh,NumVeh,ClaseVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdLinea AS CdLinea,LineaVeh
,V.IdColor AS CdColor,NomColor,V.IdTipoMot AS CdTipMotor,TipoMotor,V.IdCrceria AS CdCarr,TipoCar,Modelo,FecRep,Config,VehArtic,NumLlan,NumLlans
,V.IdCat AS CodCatg,Catpeaje,CdCatv,ClaseMat,Cilind,CapTanq,V.IdCom AS CdTipComb,TipoComb,V.IdLub AS CdLub,TipoLub,V.IdTlla AS CdTipLlantas,TipoLlanta
,IdMarlla,ML.Marca AS MarcaLlantas,PesoVacio,PesoMax,NumMotor,SerieChasis,NumSerie,CdRemque
,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,PasjerosPie, PasjerosSen,NitEmpresa,NE.RazonSocial AS Empresa,IdPropietario,NP.RazonSocial AS Propietario
,IdPoseedor,NT.RazonSocial AS Poseedor,V.IdConductor AS CedConductor,NC.RazonSocial AS Conductor,V.IdPpd AS CdTipProp,TipoProp,VehPropio,Adquisc,NitProv,NPV.RazonSocial AS Proveedor
,FecCompra,VrComcial,VrAseg,VrAvaludo,VidaUtil,FecSalida,NContrato, V.IdAdmon AS CdAdmon,TipoAdmon, V.IdNiv AS CdNivel,NivelServicio, V.IdGrupo AS CdGrupo,GrupoProp,CdGrupR,CdTarifa, FecIngreso
,V.FecVigencia AS FechVigCont, FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,NS.RazonSocial AS CiaAsegurdora,TarjProp,FecTProp,VigTProp,CdLugTp,LT.Localidad AS LugarTarjProp,Ulttramite,RespCivil,FecRCivil,VigRCivil
,RegNalCarga,FecRegNal,VigRegNal,KmInicial,KmActual,Km2Actual,Descripcion,V.Observacion AS Observ,CdCenSer,CentroServ,CdLocal,LU.Localidad AS CiuUbicacion,LU.IdDep AS CodDpto,Departamento
,Ubicacion,FecPriServ,FecUltServ,Regtradora,CentInicial, CentFinal, VrLmtCred, VrSaldoAct, FecUltAcc, TieneAcc, FecPagImp,V.IdEstado AS CdEstado,Estado
,V.Inactivo AS Inactvo,V.IdUsuario AS CdUsuario,Usuario,V.FechaAdd AS Fec_Add,V.FechaUpdate AS Fec_Upd,EV.NColor AS NumColor,OutDemand
,TipoAfil,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,VigTarjOper
,Licencia,LugarLic,CatLicencia,VigLicencia
--información de polizas
,VP.IdClase AS CodClase,ClasePoliza,Numero,FecEmision,VP.FecVigencia AS FecVencePoliza,NitCompania,TCP.RazonSocial AS NombreCia,Valor,Comntarios,DiasAviso
 FROM Vehiculos  AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca INNER JOIN MarcasLin AS L ON V.IdLinea=L.IdLinea
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposMot AS TM ON V.IdTipoMot=TM.IdTipoMot
 INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria INNER JOIN PeajesCat AS CP ON V.IdCat=CP.IdCat
 INNER JOIN TiposFuel AS TF ON V.IdCom=TF.IdCom INNER JOIN TiposLub AS TL ON V.IdLub=TL.IdLub
 INNER JOIN TiposLla AS TLL ON V.IdTlla=TLL.IdTlla INNER JOIN Marcas AS ML ON V.IdMarlla=ML.IdMarca
 INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd
 INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON V.IdUsuario=U.IdUsuario
 INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon
 INNER JOIN TiposNivs AS NV ON V.IdNiv=NV.IdNiv
 LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero LEFT JOIN Terceros AS NPV ON V.NitProv=NPV.IdTercero
 LEFT JOIN Terceros AS NS ON V.NitEmpSoat =NS.IdTercero LEFT JOIN Localidades AS LT ON V.CdLugTp=LT.IdLocal
 LEFT JOIN CentrosServ AS CS ON V.CdCenSer =CS.IdCenSer 
 LEFT JOIN Localidades AS LU ON V.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
 LEFT JOIN VehPolizas AS VP ON V.IdVehiculo=VP.IdVehiculo LEFT JOIN ClasePol AS CLP ON VP.IdClase=CLP.IdClase
 LEFT JOIN Terceros AS TCP ON VP.NitCompania=TCP.IdTercero
 LEFT JOIN  TercCndtores AS CT ON V.IdConductor=CT.IdConductor   LEFT JOIN ExpLicencias AS ELC ON CT.IdLugar=ELC.IdLugar 
 WHERE V.IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehiculosSal] @pmIdVehiculo VARCHAR(10)
AS
 SELECT     IdVehiculo, NumVeh,VrSaldoAct,VrLmtCred,IdPropietario 
 FROM  Vehiculos WHERE   IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosSalCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryVehiculosSalCue] @pmSaldoActual MONEY,@pmIdAdmon VARCHAR(4)
AS
 SELECT  IdPoseedor AS IdPropietario, SUM(VrSaldoAct) AS StotSal
 FROM  Vehiculos
 WHERE IdAdmon<>@pmIdAdmon AND TipoAfil<>'PROPIO'
 GROUP BY IdPoseedor
 HAVING  SUM(VrSaldoAct)<=@pmSaldoActual
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosSalPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paQryVehiculosSalPro] @pmIdPropietario VARCHAR(16),@pmIdAdmon VARCHAR(4)
AS
 SELECT IdPoseedor AS IdPropietario,IdVehiculo,NumVeh,IdAdmon,TipoAfil,IdConductor,RazonSocial,IdGrupo,VrSaldoAct
 FROM  Vehiculos INNER JOIN Terceros ON Vehiculos.IdConductor=Terceros.IdTercero
 WHERE IdPoseedor=@pmIdPropietario AND IdAdmon<>@pmIdAdmon AND TipoAfil<>'PROPIO'
 ORDER  BY IdPoseedor,IdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehiculosUbi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehiculosUbi] @pmIdEst CHAR(2),@pmTipoRep INT,@pmFecInicio SMALLDATETIME,@pmIdTipoVeh VARCHAR(4)=Null,@pmIdEstado VARCHAR(4)=Null
 AS 
SELECT V.IdVehiculo AS PlacaVeh,V.NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca,V.IdLinea AS CdLinea,V.IdColor AS CdColor,CL.NomColor AS ColorVeh,V.IdCrceria AS CdCrceria,TipoCar,V.Modelo
,V.Config,V.PesoVacio,V.NumMotor,V.SerieChasis,V.CdRemque,V.CarrCapac,V.UndCapc,NitEmpresa,NE.RazonSocial AS Empresa,V.IdPropietario,NP.RazonSocial AS Propietario,V.IdPoseedor,NT.RazonSocial AS Poseedor
,V.IdConductor,NC.RazonSocial AS Conductor,V.TipoAfil,V.IdPpd,TipoProp,V.IdGrupo AS CdGrupo,GrupoProp,V.IdEstado AS CdEstado,EV.Estado,EV.NColor AS EstNColor,NumSoat,FecSoat,VigSoat,KmActual,V.Descripcion,V.Observacion,FecPriServ,FecUltServ
,V.Ubicacion,V.CdLocal AS CodCiuUbic,LU.Localidad AS CiuUbicacion,LU.IdDep AS CodDpto,Departamento,V.FechaAdd AS FechaCrea
--datos de ordenes
,TM.TipoOrd,TM.NumOrden,TM.IdCiaOrd,TM.Remesa,TM.IdCiaRem,R.Fecha AS FecOrden,R.IdCliente,C.RazonSocial AS NomCliente,IdLocOrigen,CO.Localidad AS CiuOrigen,IdLocDestino,CD.Localidad AS CiuDestino,TM.nRemolque
FROM Vehiculos AS V INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor INNER JOIN TiposCar AS TC ON V.IdCrceria=TC.IdCrceria
INNER JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero INNER JOIN Terceros AS NT ON V.IdPoseedor=NT.IdTercero
INNER JOIN Terceros AS NC ON V.IdConductor=NC.IdTercero INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd
INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado INNER JOIN GruposPro AS GP ON V.IdGrupo=GP.IdGrupo
LEFT JOIN Terceros AS NE ON V.NitEmpresa=NE.IdTercero 
LEFT JOIN Localidades AS LU ON V.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
LEFT JOIN (SELECT IdOperario,IdVehiculo,nRemolque,TipoOrd,NumOrden,IdCiaOrd,Remesa,IdCiaRem FROM tm_TraInfOper WHERE IdEst=@pmIdEst AND TipoRep=@pmTipoRep) AS TM ON V.IdVehiculo=TM.IdVehiculo
LEFT JOIN (SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdCliente,IdAgencia,IdLocOrigen,IdLocDestino,IdVehiculo,IdConductor,nRemolque
FROM Trn_TraRemesa WHERE TipDoc='OCT' AND Fecha>=@pmFecInicio
UNION ALL SELECT TipDoc,NumOrden,IdCia,Fecha,FecDespacho,IdCliente,IdAgencia,IdDestino,IdDestino AS CiuDstno,IdVehiculo,IdConductor,nRemolque
FROM Trn_TraOrdenServ WHERE TipDoc='OSA' AND Fecha>=@pmFecInicio) AS R ON TM.TipoOrd=R.TipDoc AND TM.NumOrden=R.NumOrden AND TM.IdCiaOrd=R.IdCia
LEFT JOIN Terceros AS C ON R.IdCliente=C.IdTercero LEFT JOIN Localidades AS CO ON R.IdLocOrigen=CO.IdLocal LEFT JOIN Localidades AS CD ON R.IdLocDestino=CD.IdLocal
WHERE V.Inactivo=0 AND (V.IdTipoVeh=@pmIdTipoVeh OR @pmIdTipoVeh IS NULL)
AND (V.IdEstado=@pmIdEstado OR @pmIdEstado IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehLecturas] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Numero,IdCia,Item,Fecha,TipoUnidad,pVehiculo,KmsAnterior,KmsActual,Kms2Anterior,Kms2Actual,TipoLectura,Observacion,TimeSys,IdUsuario
 FROM Trn_VehLecturas
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturasDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehLecturasDso] @pmTipDoc VARCHAR(3)=Null,@pmpVehiculo VARCHAR(10)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT TipDoc,L.Numero,L.IdCia AS CdCia,Compania,Item,Fecha,TipoUnidad,pVehiculo,TipoLectura,KmsAnterior,KmsActual
,Kms2Anterior,Kms2Actual,L.Observacion,L.TimeSys,L.IdUsuario AS CdUsuario,Usuario
--datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipoVeh,TipoVehiculo,V.IdMarca AS CdMarca,M.Marca AS MarcaVeh,V.IdColor AS CdColor,NomColor,V.Modelo,Config,VehArtic,NumMotor
,SerieChasis,NumSerie,V.CdRemque,TipoAfil,FecCompra,V.KmInicial,V.KmActual AS KmsOdometro,V.Km2Actual AS KmsManual,V.CentFinal AS KmsOtro,V.Descripcion
,V.Inactivo,V.IdEstado AS CdEstado,Estado
 FROM Trn_VehLecturas AS L INNER JOIN adm_Usuarios AS U ON L.IdUsuario=U.IdUsuario
 INNER JOIN Companias AS C ON L.IdCia=C.IdCia
 LEFT JOIN Vehiculos AS V ON L.pVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Marcas AS M ON V.IdMarca=M.IdMarca LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor
 LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 WHERE pVehiculo LIKE ISNULL(@pmpVehiculo,'%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 AND (L.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND L.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturasId]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehLecturasId] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MxNum
 FROM Trn_VehLecturas
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryVehLecturasVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehLecturasVeh] @pmTipoUnidad VARCHAR(3),@pmpVehiculo VARCHAR(10)=Null
 AS 
 SELECT TipDoc,Numero,IdCia,Item,Fecha,TipoUnidad,pVehiculo,KmsAnterior,KmsActual
,Kms2Anterior,Kms2Actual,TipoLectura,Observacion,TimeSys,IdUsuario
 FROM Trn_VehLecturas
 WHERE TipoUnidad=@pmTipoUnidad AND pVehiculo LIKE ISNULL(@pmpVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVehNumOrden]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehNumOrden] @pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT  IdVehiculo,Numero,Fecha,NumOrden,NuevoNum,Observacion, TimeSys, C.IdUsuario AS CdUsuario,Usuario
 FROM  Trn_VehNumOrden AS C INNER JOIN adm_Usuarios AS U ON C.IdUsuario=U.IdUsuario
 WHERE IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPartes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehPartes] @pmIdVehiculo VARCHAR(10),@pmNumParte VARCHAR(20)
 AS 
 SELECT IdVehiculo,NumParte,DescripParte,IdSistema,TipoControl,Intervalo_km,Intervalo_dias,Intervalo_Horas,kmActual
,kmManual,kmSat,kmCambio,kmCambioMan,kmCambioSat,FechaCambio,CdProdRep
,TipoUnidad,TipoParte,IdEstado,Inactivo,FechaRetiro,HorasTrab,HsUltCambio,MarcaParte,ModeloParte,NumSerie,FechaCrea,IdUsuario
 FROM VehPartes
 WHERE IdVehiculo=@pmIdVehiculo AND NumParte=@pmNumParte
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPartesLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehPartesLta] @pmIdVehiculo VARCHAR(10)=Null,@pmIdSistema VARCHAR(4)=Null
 AS 
 SELECT TipoUnidad,P.IdVehiculo AS PlacaVeh,NumParte,DescripParte,P.IdSistema AS CdSistema,Sistema,TipoParte,TipoControl
,Intervalo_km,Intervalo_dias,Intervalo_Horas,P.kmActual,kmManual,kmSat,P.kmCambio,kmCambioMan,kmCambioSat,FechaCambio,HorasTrab,HsUltCambio,CdProdRep,DescripProd
,P.IdEstado AS CdEstado,E.Estado,E.NColor,P.Inactivo,FechaRetiro,MarcaParte,P.ModeloParte,P.NumSerie,P.FechaCrea,P.IdUsuario AS CdUsuario,Usuario
--datos del vehículo
,NumVeh,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,MV.Marca AS MarcaVeh,V.IdColor AS CdColor,CL.NomColor AS Color
,V.IdLinea AS CdLinea,V.Modelo,FecRep,SerieChasis,CdRemque,V.IdPropietario,NP.RazonSocial AS Propietario,FecIngreso,V.KmInicial,V.KmActual AS kmsActual
,V.Km2Actual,NumSoat,FecSoat,VigSoat,V.Descripcion,V.IdEstado AS VehCodEstado,EV.Estado AS VehEstado,EV.NColor AS VehEdoColor,V.Inactivo AS VehInactivo
 FROM VehPartes AS P INNER JOIN MttoSistemas AS S ON P.IdSistema=S.IdSistema
 INNER JOIN EstadoSer AS E ON P.IdEstado=E.IdEstado INNER JOIN adm_Usuarios AS U ON P.IdUsuario=U.IdUsuario
 LEFT JOIN ProdMcias AS M ON P.CdProdRep=M.IdProducto
 LEFT JOIN Vehiculos AS V ON P.IdVehiculo=V.IdVehiculo LEFT JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh
 LEFT JOIN Marcas AS MV ON V.IdMarca=MV.IdMarca LEFT JOIN TiposCol AS CL ON V.IdColor=CL.IdColor
 LEFT JOIN Terceros AS NP ON V.IdPropietario=NP.IdTercero LEFT JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado
 WHERE P.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND P.IdSistema LIKE ISNULL(@pmIdSistema,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPolizas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehPolizas] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4)
 AS 
 SELECT IdVehiculo,IdClase,Numero,FecEmision,FecVigencia,NitCompania,Valor,Comntarios,DiasAviso
 FROM VehPolizas
 WHERE IdVehiculo=@pmIdVehiculo
  AND IdClase LIKE ISNULL(@pmIdClase,'%')
 ORDER BY IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPolizasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehPolizasLta] @pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT VP.IdVehiculo AS PlacaVeh,NumVeh,VP.IdClase AS CodClase,ClasePoliza,Numero,FecEmision
,VP.FecVigencia AS FecVence,NitCompania,RazonSocial,Valor,Comntarios,DiasAviso
 FROM VehPolizas AS VP INNER JOIN Vehiculos AS V ON VP.IdVehiculo=V.IdVehiculo
 INNER JOIN ClasePol AS CP ON VP.IdClase=CP.IdClase
 LEFT JOIN Terceros AS T ON VP.NitCompania=T.IdTercero
 WHERE V.Inactivo=0 AND VP.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
 ORDER BY VP.IdVehiculo,VP.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPolizasPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehPolizasPla] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT IdVehiculo,VP.IdClase AS CodClase,ClasePoliza,Numero,FecEmision
,FecVigencia,NitCompania,RazonSocial,Valor,Comntarios,DiasAviso
 FROM VehPolizas AS VP INNER JOIN ClasePol AS CP ON VP.IdClase=CP.IdClase
 LEFT JOIN Terceros AS T ON VP.NitCompania=T.IdTercero
 WHERE IdVehiculo=@pmIdVehiculo
 ORDER BY  VP.IdClase
GO
/****** Object:  StoredProcedure [dbo].[paQryVehPropietariosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehPropietariosLta] @pmIdVehiculo VARCHAR(10)=Null
 AS 
 SELECT  VP.IdVehiculo AS PlacaVeh,NumVeh,Item,NitPropietario,T.RazonSocial AS Propietario,PorcPartic,FechaIng,EstadoProp,IdPropietario,NP.RazonSocial AS VehPropietario
,V.IdTipoVeh AS CdTipo,TipoVehiculo,V.IdMarca AS CdMarca,Marca,V.IdColor AS CdColor,NomColor,Modelo,NumMotor,SerieChasis,NumSerie
,NitEmpresa,NE.RazonSocial AS Empresa,IdPoseedor,NT.RazonSocial AS Poseedor,IdConductor,NC.RazonSocial AS Conductor
,V.IdPpd AS CdTipProp,TipoProp,VehPropio,Adquisc,VrAvaludo,NContrato,FecIngreso, FecVigencia, FecRetiro,V.IdAdmon AS CdAdmon,TipoAdmon
,V.IdEstado AS CdEstado,Estado,V.Inactivo AS Inactvo
--datos del propietario
,T.Codigo AS TercCodigo,T.TipoId AS TercTipoId,T.Dv AS TercDv,T.Direccion AS TercDireccion,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
 FROM VehPropietarios AS VP INNER JOIN  Vehiculos  AS V ON VP.IdVehiculo=V.IdVehiculo INNER JOIN Terceros AS T ON  VP.NitPropietario=T.IdTercero
 INNER JOIN TiposVeh AS TV ON V.IdTipoVeh=TV.IdTipoVeh  INNER JOIN Marcas AS M ON V.IdMarca=M.IdMarca
 INNER JOIN TiposCol AS CL ON V.IdColor=CL.IdColor 
 INNER JOIN Terceros AS NP ON  V.IdPropietario=NP.IdTercero  INNER JOIN Terceros AS NT ON  V.IdPoseedor=NT.IdTercero
 INNER JOIN Terceros AS NC ON  V.IdConductor=NC.IdTercero
 INNER JOIN TiposPpt AS TP ON V.IdPpd=TP.IdPpd  INNER JOIN EstadoVeh AS EV ON V.IdEstado=EV.IdEstado  
 INNER JOIN TiposAdm AS TA ON V.IdAdmon=TA.IdAdmon  LEFT JOIN Terceros AS NE ON  V.NitEmpresa=NE.IdTercero
 WHERE VP.IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
 ORDER BY  VP.IdVehiculo,Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVehRemolq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehRemolq] @pmIdRemque VARCHAR(10)
 AS 
 SELECT IdRemque,IdMarca,IdColor,IdCrceria,Modelo,NEjes,nLlantas,Altura,Ancho,Largo,Vlumen,PesoKg,Capneta,UndCapc,NumComp,CapcComp
,NumSerial,IdPropietario,NitProv,FecCompra,VidaUtil,VrComercial,VrAvaludo,VrAsegurado,Kilmetraje,EquipoAdic,Descripcion,CdCenSer,CdLocal,Ubicacion
,Observacion,IdEstado,Inactivo,FecAdd,FecUpdate,IdUsuario,TarjetaProp,FecTarjProp,VigTarjProp,ConfEjes,Hidrostatica,FecPruebaHid,VigPruebaHid
,kmRuta,kmOtro,Kingpin,FecKingpin,VigKingpin,ArcFotoRem,FecVigExtintor,CdLocTarj,Operador_GPS,Usuario_GPS,Clave_GPS,IdOper_GPS,Tipo_Afil,EdoVincula,FechaVincula,FechaRetiro
 FROM VehRemolq
 WHERE IdRemque=@pmIdRemque
GO
/****** Object:  StoredProcedure [dbo].[paQryVehRemolqLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehRemolqLta] @pmIdMarca VARCHAR(4)=Null,@pmIdCrceria VARCHAR(4)=Null,@pmModelo VARCHAR(4)=Null
,@pmIdPropietario VARCHAR(16)=Null,@pmIdEstado VARCHAR(4)=Null,@pmInactivo BIT=Null
,@pmFecComIni SMALLDATETIME=Null,@pmFecComFin SMALLDATETIME=Null
 AS 
 SELECT IdRemque,R.IdMarca AS CdMarca,Marca,R.IdColor AS CodColor,NomColor,R.IdCrceria AS CodCarr,TipoCar,Modelo,ConfEjes,NEjes,nLlantas,Altura,Ancho,Largo,Vlumen
,PesoKg,Capneta,UndCapc,NumComp,CapcComp,NumSerial,IdPropietario,NP.RazonSocial AS Propietario,NitProv,NPV.RazonSocial AS Proveedor,FecCompra,VidaUtil
,VrComercial,VrAvaludo,VrAsegurado,Kilmetraje,kmRuta,kmOtro,EquipoAdic,Descripcion,CdCenSer,CentroServ,CdLocal,LU.Localidad AS CiuUbicacion
,LU.IdDep AS CodDpto,Departamento,Ubicacion,R.Observacion AS Observ,R.ArcFotoRem,R.IdEstado AS CodEstado,Estado,R.Inactivo AS Inactiv,R.IdUsuario AS IdUsuari,Usuario
,FecAdd,FecUpdate,EV.NColor AS NumColor,OutDemand,TarjetaProp,FecTarjProp,VigTarjProp,CdLocTarj,Hidrostatica,FecPruebaHid,VigPruebaHid,Kingpin,FecKingpin,VigKingpin,FecVigExtintor
,Operador_GPS,Usuario_GPS,Clave_GPS,IdOper_GPS,R.Tipo_Afil,R.EdoVincula,R.FechaVincula,R.FechaRetiro
 FROM VehRemolq AS R INNER JOIN Marcas AS M ON R.IdMarca=M.IdMarca  INNER JOIN TiposCol AS CL ON R.IdColor=CL.IdColor
 INNER JOIN TiposCar AS TC ON R.IdCrceria=TC.IdCrceria  INNER JOIN Terceros AS NP ON  R.IdPropietario=NP.IdTercero
 INNER JOIN EstadoVeh AS EV ON R.IdEstado=EV.IdEstado  INNER JOIN adm_Usuarios AS U ON R.IdUsuario=U.IdUsuario
 LEFT JOIN Terceros AS NPV ON R.NitProv=NPV.IdTercero
 LEFT JOIN CentrosServ AS CS ON R.CdCenSer =CS.IdCenSer 
 LEFT JOIN Localidades AS LU ON R.CdLocal=LU.IdLocal LEFT JOIN Departamentos AS DU ON LU.IdDep=DU.IdDep
 WHERE R.IdMarca LIKE ISNULL(@pmIdMarca,'%')  AND R.IdCrceria LIKE ISNULL(@pmIdCrceria,'%')
 AND Modelo LIKE ISNULL(@pmModelo,'%')  AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
 AND R.IdEstado LIKE ISNULL(@pmIdEstado,'%')
 AND (R.Inactivo=ISNULL(@pmInactivo,0) or R.Inactivo=ISNULL(@pmInactivo,1))
 AND (FecCompra>=ISNULL(@pmFecComIni,CAST('19100101' AS SMALLDATETIME)) AND FecCompra<=ISNULL(@pmFecComFin,CAST('20781230' AS SMALLDATETIME)))
ORDER BY  IdRemque
GO
/****** Object:  StoredProcedure [dbo].[paQryVehRemPolizasLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehRemPolizasLta] 
 AS 
SELECT P.IdRemque,P.IdClase AS CdClase,ClasePoliza,P.Numero,P.FecEmision,P.FecVigencia AS FecVence,P.NitCompania,RazonSocial
,P.Valor,P.DiasAviso,P.Comntarios 
FROM VehRemPolizas AS P INNER JOIN ClasePol AS CL ON P.IdClase=CL.IdClase
INNER JOIN VehRemolq AS R ON P.IdRemque=R.IdRemque
LEFT JOIN Terceros AS T ON P.NitCompania=T.IdTercero
WHERE R.Inactivo=0
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehTraspasos] @pmIdVehiculo VARCHAR(10),@pmNumero INT
 AS 
 SELECT IdVehiculo,Numero,Fecha,IdPpd,IdPropietario,IdPoseedor,IdPropNuevo,IdPoseeNuevo,IdNewPpd,IdGrupo,VrComercial
,VrCupo,VrAsegurado,Observacion,TipoAfil,TipoAfilNew,TimeSys,IdUsuario
 FROM Trn_VehTraspasos
 WHERE IdVehiculo=@pmIdVehiculo
 AND (Numero>=ISNULL(@pmNumero,0)  AND Numero<=ISNULL(@pmNumero,2147483647))
 ORDER BY Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasosDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVehTraspasosDso] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdPoseedor VARCHAR(16)=Null
,@pmIdPropNuevo VARCHAR(16)=Null,@pmIdPoseeNuevo VARCHAR(16)=Null,@pmIdPpd VARCHAR(4)=Null,@pmIdNewPpd VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT T.IdVehiculo AS PlacaVeh,T.Numero,T.Fecha,T.IdPropietario AS IdPropAnt,NP.RazonSocial AS PropAnterior,T.IdPoseedor AS IdPoseeAnt,NT.RazonSocial AS PoseeAnterior
,IdPropNuevo,NNP.RazonSocial AS NuevoPropietario,IdPoseeNuevo,NNT.RazonSocial AS NuevoPoseedor,T.IdPpd AS CdTipoProp,TP.TipoProp AS TipoPropAnt
,TP.VehPropio AS VehPropioAnt,IdNewPpd,TPN.TipoProp AS TipoPropNueva,TPN.VehPropio AS VehPropioNuevo,T.IdGrupo AS CdGrupo,GrupoProp,VrComercial,VrCupo,VrAsegurado,T.Observacion AS Observ
,NumVeh,Modelo,V.IdPropietario AS IdPropActual,NPA.RazonSocial AS PropActual,V.IdPoseedor AS IdPoseeActual,NTA.RazonSocial AS PoseeActual,IdConductor,NC.RazonSocial AS Conductor
,V.IdPpd AS CdTipPropActual,TPA.TipoProp AS TipoPropActual,V.FecCompra,T.TipoAfil AS TipoAfiAnt,TipoAfilNew,TimeSys,T.IdUsuario AS IdUsuari,Usuario
 FROM Trn_VehTraspasos AS T INNER JOIN Terceros AS NP ON T.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NT ON T.IdPoseedor=NT.IdTercero 
 INNER JOIN Terceros AS NNP ON T.IdPropNuevo=NNP.IdTercero 
 INNER JOIN Terceros AS NNT ON T.IdPoseeNuevo=NNT.IdTercero 
 INNER JOIN TiposPpt AS TP ON T.IdPpd=TP.IdPpd
 INNER JOIN TiposPpt AS TPN ON T.IdNewPpd=TPN.IdPpd
 INNER JOIN GruposPro AS G ON T.IdGrupo=G.IdGrupo
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN (SELECT IdVehiculo,NumVeh,Modelo,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,IdPpd,TipoAfil,FecCompra,VrComcial,VrAseg,VrAvaludo,FecIngreso,FecRetiro,Inactivo,EdoVincula FROM Vehiculos
 UNION ALL SELECT IdRemque,'0',Modelo,NitProv,IdPropietario,IdPropietario,IdPropietario,'0',Tipo_Afil,FecCompra,VrComercial,VrAsegurado,VrAvaludo,FechaVincula,FechaRetiro,Inactivo,EdoVincula FROM VehRemolq) AS V ON T.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NPA ON V.IdPropietario=NPA.IdTercero 
 INNER JOIN Terceros AS NTA ON V.IdPoseedor=NTA.IdTercero 
 LEFT JOIN TiposPpt AS TPA ON V.IdPpd=TPA.IdPpd
 LEFT JOIN Terceros AS NC ON V.IdConductor=NC.IdTercero 
 WHERE V.Inactivo=0  AND T.IdVehiculo like ISNULL(@pmIdVehiculo,'%')
 AND T.IdPropietario LIKE ISNULL(@pmIdPropietario,'%') AND T.IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
 AND IdPropNuevo LIKE ISNULL(@pmIdPropNuevo,'%') AND IdPoseeNuevo LIKE ISNULL(@pmIdPoseeNuevo,'%')
 AND T.IdPpd LIKE ISNULL(@pmIdPpd,'%') AND IdNewPpd LIKE ISNULL(@pmIdNewPpd,'%')
 AND (T.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND T.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.IdVehiculo,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasosID]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehTraspasosID] @pmIdVehiculo VARCHAR(10)
 AS 
 SELECT MAX(Numero) AS MxNum 
 FROM Trn_VehTraspasos
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paQryVehTraspasosVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVehTraspasosVeh] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null,@pmIdPropNuevo VARCHAR(16)=Null
 AS 
 SELECT T.IdVehiculo AS PlacaVeh,Numero,Fecha,T.IdPropietario AS IdPropAnt,NP.RazonSocial AS PropAnterior,T.IdPoseedor AS IdPoseeAnt,NT.RazonSocial AS PoseeAnterior
,IdPropNuevo,NNP.RazonSocial AS NuevoPropietario,IdPoseeNuevo,NNT.RazonSocial AS NuevoPoseedor,T.IdPpd AS CdTipoProp,TP.TipoProp AS TipoPropAnt
,TP.VehPropio AS VehPropioAnt,IdNewPpd,TPN.TipoProp AS TipoPropNueva,TPN.VehPropio AS VehPropioNuevo,T.IdGrupo AS CdGrupo,GrupoProp,VrComercial,VrCupo,VrAsegurado,T.Observacion AS Observ
,NumVeh,Modelo,V.IdPropietario AS IdPropActual,NPA.RazonSocial AS PropActual,V.IdPoseedor AS IdPoseeActual,NTA.RazonSocial AS PoseeActual,IdConductor,NC.RazonSocial AS Conductor
,V.IdPpd AS CdTipPropActual,TPA.TipoProp AS TipoPropActual,FecCompra,T.TipoAfil AS TipoAfiAnt,TipoAfilNew,TimeSys,T.IdUsuario AS IdUsuari,Usuario
 FROM Trn_VehTraspasos  AS T INNER JOIN Vehiculos AS V ON T.IdVehiculo=V.IdVehiculo
 INNER JOIN Terceros AS NP ON T.IdPropietario=NP.IdTercero 
 INNER JOIN Terceros AS NT ON T.IdPoseedor=NT.IdTercero 
 INNER JOIN Terceros AS NNP ON T.IdPropNuevo=NNP.IdTercero 
 INNER JOIN Terceros AS NNT ON T.IdPoseeNuevo=NNT.IdTercero 
 INNER JOIN TiposPpt AS TP ON T.IdPpd=TP.IdPpd
 INNER JOIN TiposPpt AS TPN ON T.IdNewPpd=TPN.IdPpd
 INNER JOIN GruposPro AS G ON T.IdGrupo=G.IdGrupo
 INNER JOIN adm_Usuarios AS U ON T.IdUsuario=U.IdUsuario
 INNER JOIN Terceros AS NC ON V.IdConductor=NC.IdTercero 
 INNER JOIN Terceros AS NPA ON V.IdPropietario=NPA.IdTercero 
 INNER JOIN Terceros AS NTA ON V.IdPoseedor=NTA.IdTercero 
 INNER JOIN TiposPpt AS TPA ON V.IdPpd=TPA.IdPpd
 WHERE    T.IdVehiculo like ISNULL(@pmIdVehiculo,'%')  AND T.IdPropietario LIKE ISNULL(@pmIdPropietario,'%')  
 AND IdPropNuevo LIKE ISNULL(@pmIdPropNuevo,'%')
 ORDER BY T.IdVehiculo,Numero
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonos] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipRec,Recibo,IdCia,Item,Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,IdCliente,IdAgencia
,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
 FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
  AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonos_Cr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonos_Cr] @pmTipRec VARCHAR(3),@pmReciboIni INT,@pmReciboFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipRec,Recibo,VA.IdCia AS CdCia,CN.Compania AS RecCompania,VA.Item AS ItemRec,VA.Fecha AS FechaRec
,VA.TipDoc AS TipoFac,VA.Factura AS NumFactura,IdCiaFac,CF.Compania AS FacCompania,ItemFac,VrAbono,VrDescto
,VrBaseCms,VA.IdCliente AS NitCliente,T.RazonSocial AS NombCliente,VA.IdAgencia AS IdAgncia,Agencia,CodAgencia
,VA.IdVend AS NitVendedor,VN.RazonSocial AS NomVendedor,VA.Comision AS ComisionCobro,VA.Detalle AS DetalleAbono
,FecPago,TipoAplica,TimeSys
--datos del vencimiento
,V.Fecha AS FechaFac,FechaVence,VrFactura,V.VrAbonado AS TotalAbonos,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,V.IdConcepto AS CdConcepto,Concepto
,V.Referencia AS Referncia,V.Detalle AS DetalleVecmto,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora
 FROM Trn_VencAbonos AS VA INNER JOIN Trn_Vencimientos AS V ON VA.TipDoc=V.TipDoc AND VA.Factura=V.Factura
 AND VA.IdCiaFac=V.IdCia AND VA.ItemFac=V.Item
 INNER JOIN Terceros AS T ON VA.IdCliente=T.IdTercero INNER JOIN Terceros AS VN ON VA.IdVend=VN.IdTercero
 INNER JOIN Companias AS CN ON VA.IdCia=CN.IdCia INNER JOIN Companias AS CF ON VA.IdCiaFac=CF.IdCia
 LEFT JOIN Agencias AS A ON VA.IdAgencia=A.IdAgencia  LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto
 WHERE TipRec=@pmTipRec AND Recibo BETWEEN @pmReciboIni AND @pmReciboFin  AND VA.IdCia=@pmIdCia
 ORDER BY Recibo,VA.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonos_Fac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonos_Fac] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2)
,@pmItemFac INT
 AS 
 SELECT TipRec,Recibo,A.IdCia AS CdCia,Compania,Item,Fecha,VrAbono,VrDescto,Detalle,TipoDoc,FecPago
,VrBaseCms,IdCliente,T.RazonSocial AS NombCliente,A.IdAgencia AS CdAgencia,Agencia
,A.IdVend AS NitVendedor,VN.RazonSocial AS NomVendedor,Comision,TipoAplica,ItemFac,TimeSys
 FROM Trn_VencAbonos AS A  INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero
 INNER JOIN Terceros AS VN ON A.IdVend=VN.IdTercero INNER JOIN Companias AS CN ON A.IdCia=CN.IdCia
 LEFT JOIN Agencias AS AG ON A.IdAgencia=AG.IdAgencia LEFT JOIN Sys_TiposDoc AS TD ON A.TipRec=TD.IdDoc
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura  AND IdCiaFac=@pmIdCiaFac
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647))
 ORDER BY TimeSys,Recibo
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosAbo] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2)
,@pmItemFac INT,@pmTipoAplicaExc VARCHAR(10)=Null
AS
 SELECT SUM(VrAbono) AS StotAbo
 FROM Trn_VencAbonos 
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCiaFac=@pmIdCiaFac
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647))
 AND TipoAplica<>@pmTipoAplicaExc
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosDap]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosDap] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,Factura,IdCiaFac,ItemFac,SUM(VrAbono) AS STotAbo
 FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 GROUP BY TipDoc,Factura,IdCiaFac,ItemFac
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosFec] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2)
,@pmItemFac INT
 AS 
 SELECT TipRec,Recibo,IdCia,Item,Fecha,ItemFac,VrAbono,VrDescto,IdCliente,IdAgencia,FecPago,TipoAplica
 FROM Trn_VencAbonos
 WHERE TipRec IN ('REC','NCR') AND TipDoc=@pmTipDoc  AND Factura=@pmFactura AND IdCiaFac=@pmIdCiaFac
 AND (ItemFac>=ISNULL(@pmItemFac,0)  AND ItemFac<=ISNULL(@pmItemFac,2147483647))
 ORDER BY FecPago
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosItm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosItm] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT MAX(Item) AS MXITM  
 FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosLrc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosLrc] @pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME,@pmFecActual SMALLDATETIME,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null,@pmFechaFacIni SMALLDATETIME=Null,@pmFechaFacFin SMALLDATETIME=Null,@pmIdZona VARCHAR(4)=Null
,@pmIdSzona VARCHAR(4)=Null,@pmIdGrupo VARCHAR(4)=NULL
 AS 
 SELECT  VA.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,VA.IdAgencia AS CdAgencia,A.Agencia AS NomAgencia,IdCiaFac,CI.Compania AS FactCompania,VA.TipDoc AS TipFact,TD.TipoDoc AS TipoFactura,VA.Factura AS NumFactura,VA.ItemFac AS NumVence
,V.Fecha AS FechaFact,FechaVence,FecPlazoCal,DATEDIFF(day,ISNULL(FecPlazoCal,FechaVence),@pmFecActual) AS DiasMora,VrFactura,VrAbonado,VrFactura-VrAbonado AS SaldoFactura
--recibo
,TipRec,TR.TipoDoc AS TipoRecibo,VA.Recibo AS NumRecibo,VA.IdCia AS RecIdCia,CR.Compania AS RecCompania,VA.Item AS RecItem,VA.FecPago AS FechaPago
,DATEDIFF(day,ISNULL(FecPlazoCal,V.FechaVence),VA.FecPago) AS DiasPago,VrAbono
,CASE WHEN VrFactura<>0 AND VrAbono>0 THEN (DATEDIFF(day,V.Fecha,VA.FecPago) *VrAbono)/VrFactura ELSE 0 END  AS PromDias,VA.Detalle AS RecDetalle,TipoAplica
,VA.IdVend AS RecCdVend,VR.RazonSocial AS RecVendedor,VrBaseCms,VA.Comision AS TarifComsCobro,VrDescto,VA.Fecha AS RecFecha
,V.IdAgencia AS FactIdAgencia,AF.Agencia AS FactAgencia,V.IdVend AS FactIdVend,VN.RazonSocial AS FactVendedor,V.Comision AS FactComision,V.Referencia AS FactReferencia,V.Detalle AS FactDetalle,TipRef,DocRef,IdCiaRef
,V.IdConcepto AS CdConcepto,Concepto
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.Direccion AS TercDireccion,T.IdLocal AS TercCdCiudad
,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.e_mail AS TercEmail
,T.IdSector AS CdSector,SectorEco
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato,CLI.CdBandera AS CliCdBandera,TB.TipoBandera AS CliBandera
,A.CodAgencia AS Cod_agencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,A.CiaCont AS AgeCiaCont,A.CdBandera AS AgeIdBandera,TBA.TipoBandera AS AgeBandera
 FROM  Trn_VencAbonos AS VA INNER JOIN Trn_Vencimientos AS V  ON  VA.TipDoc=V.TipDoc AND VA.Factura=V.Factura AND VA.IdCiaFac=V.IdCia AND VA.ItemFac=V.Item
 INNER JOIN Companias AS CR ON VA.IdCia=CR.IdCia  INNER JOIN  Companias AS CI ON VA.IdCiaFac=CI.IdCia
 INNER JOIN Sys_TiposDoc AS TD ON VA.TipDoc=TD.IdDoc
 INNER JOIN Terceros AS T ON VA.IdCliente=T.IdTercero INNER JOIN Agencias AS A ON VA.IdAgencia=A.IdAgencia
 INNER JOIN Terceros AS VR ON VA.IdVend=VR.IdTercero INNER JOIN Agencias AS AF ON V.IdAgencia=AF.IdAgencia 
 INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN TercCliente AS CLI ON VA.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto LEFT JOIN Sys_TiposDoc AS TR ON VA.TipRec=TR.IdDoc
 LEFT JOIN  TiposBan AS TB ON CLI.CdBandera=TB.IdBandera LEFT JOIN TiposBan AS TBA ON A.CdBandera=TBA.IdBandera
 WHERE  FecPago BETWEEN @pmFechaIni AND @pmFechaFin  AND  VA.IdCiaFac LIKE ISNULL(@pmIdCia,'%%')
 AND VA.IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND V.IdVend LIKE ISNULL(@pmIdVend,'%')  AND CLI.IdSzona LIKE ISNULL(@pmIdSzona,'%')
 AND  SZ.IdZona LIKE ISNULL(@pmIdZona,'%') AND CLI.IdGrupo LIKE ISNULL(@pmIdGrupo,'%')
 AND (V.Fecha>=ISNULL(@pmFechaFacIni,CAST('19100101' AS SMALLDATETIME)) AND V.Fecha<=ISNULL(@pmFechaFacFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial,VA.FecPago,VA.Factura,VA.ItemFac
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosLta] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 SELECT Item,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,Detalle,Fecha
,IdCliente,T.RazonSocial AS Cliente,IdAgencia,IdVend,V.RazonSocial AS Vendedor,Comision,FecPago,TipoAplica,TimeSys
 FROM Trn_VencAbonos AS A INNER JOIN Terceros AS T ON A.IdCliente=T.IdTercero
 INNER JOIN  Terceros AS V ON A.IdVend=V.IdTercero
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosSaf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosSaf] @pmTipRec VARCHAR(3),@pmRecibo INT
,@pmIdCia CHAR(2),@pmTipoAplica VARCHAR(10)=Null
 AS 
 SELECT TipRec,Recibo,IdCia,Item,Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,IdCliente,IdAgencia
,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
 FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 AND TipoAplica LIKE ISNULL(@pmTipoAplica,'%')
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosSaNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosSaNit] @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)=Null
 AS 
 SELECT SUM(VrAbono)  AS STOTABO
 FROM Trn_VencAbonos
 WHERE IdCliente=@pmIdCliente AND TipoAplica='ANTICIPO' AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosTnit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosTnit]  @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)=Null
 AS 
 SELECT SUM(VrAbono) AS STOTABO,SUM(VrDescto) AS STOTDCT,SUM(VrBaseCms) AS STOTCMS
 FROM Trn_VencAbonos
 WHERE IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVencAbonosTsaf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencAbonosTsaf] @pmTipRec VARCHAR(3),@pmRecibo INT
,@pmIdCia CHAR(2),@pmTipoAplica VARCHAR(10)=Null
 AS 
 SELECT SUM(VrAbono) AS STOTABO,SUM(VrDescto) AS STOTDCT,SUM(VrBaseCms) AS STOTBAS
 FROM Trn_VencAbonos
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia 
 AND TipoAplica LIKE ISNULL(@pmTipoAplica,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientos] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 SELECT TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,TipoDcto
,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,FecPlazoCal
 FROM Trn_Vencimientos
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientos_Crd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientos_Crd] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
 SELECT TipDoc,TipoDoc,Factura,V.IdCia AS CdCia,Compania,Item,Fecha,FechaVence,VrFactura,VrAbonado
,IdCliente,T.RazonSocial AS NombCliente,V.IdAgencia AS IdAgenc,Agencia,CodAgencia,V.IdVend AS CdVend,VN.RazonSocial AS NomVendedor,Comision,TarifDcto,TipoDcto
,TipoBase,FecLmtDcto,V.IdConcepto AS CdConcepto,Concepto,V.Referencia AS Referncia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,FecPlazoCal
 FROM Trn_Vencimientos AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Companias AS CN ON V.IdCia=CN.IdCia INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN Sys_TiposDoc AS TD ON V.TipDoc=TD.IdDoc INNER JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto
 LEFT JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia 
 WHERE TipDoc=@pmTipDoc AND Factura BETWEEN @pmFacturaIni AND @pmFacturaFin AND V.IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosAbo] @pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME,@pmTipDoc VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
,@pmFecAboIni SMALLDATETIME=Null,@pmFecAboFin SMALLDATETIME=Null,@pmReciboIni INT=Null,@pmReciboFin INT=Null
 AS 
 IF (@pmFecAboIni IS NULL AND @pmReciboIni IS NULL)
  BEGIN
  --Consulta Vencimientos con o sin abonos
  SELECT V.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,V.IdAgencia AS CdAgencia,Agencia,V.TipDoc AS IdTipFact,TD.TipoDoc AS TipoFact,V.Factura AS NumFactura,V.IdCia AS CdCia,CI.Compania AS NomCiaFact,V.Item AS nItemFact
 ,VrFactura,VrAbonado AS TotalAbonado,VrFactura-VrAbonado AS ValorSaldo,V.Fecha AS FechaEmision,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
--información de abonos
,TipRec,TR.TipoDoc AS TipoRecibo,VA.Recibo AS NumRecibo,VA.IdCia AS RecCodCia,CR.Compania AS RecCompania,VA.Item AS RecItem,VA.Fecha AS RecFecha,VA.FecPago AS FechaPago,VrAbono,VrDescto
,VA.Detalle AS RecDetalle,VA.IdVend AS RecCdVend,VR.RazonSocial AS RecVendedor,VrBaseCms,VA.Comision AS TarifComsCobro,TipoAplica,VA.TimeSys AS FecHoraCrea
--datos del recibo
,EnEfectivo,CdForma,NumForma,CdBanco,RC.Referencia AS RecReferencia
--mas inf. del vencimiento
,V.IdConcepto AS FacCodConcepto,Concepto,V.Referencia AS FacReferencia,V.Detalle AS FacDetalle,V.IdVend AS FacIdVend,VN.RazonSocial AS FacVendedor,V.Comision AS FacTarifComs
,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM Trn_Vencimientos AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia  INNER JOIN Sys_TiposDoc AS TD ON V.TipDoc=TD.IdDoc
 INNER JOIN Companias AS CI ON V.IdCia=CI.IdCia  INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN TercCliente AS CLI ON V.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto
 LEFT JOIN Trn_VencAbonos AS VA ON V.TipDoc=VA.TipDoc AND V.Factura=VA.Factura AND V.IdCia=VA.IdCiaFac AND V.Item=VA.ItemFac
 LEFT JOIN Sys_TiposDoc AS TR ON VA.TipRec=TR.IdDoc LEFT JOIN Companias AS CR ON VA.IdCia=CR.IdCia 
 LEFT JOIN Terceros AS VR ON VA.IdVend=VR.IdTercero
 LEFT JOIN Trn_Recibos AS RC ON VA.TipRec=RC.TipDoc AND VA.Recibo=RC.Recibo AND VA.IdCia=RC.IdCia
 WHERE (V.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND V.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (V.IdCia=@pmIdCia OR @pmIdCia IS NULL)
 AND (V.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL) 
 AND (VrFactura-VrAbonado)>@pmSaldo
 AND (V.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL) 
 AND (V.IdAgencia=@pmIdAgencia OR @pmIdAgencia IS NULL)
 AND (V.IdVend=@pmIdVend OR @pmIdVend IS NULL)
 --ORDER BY T.RazonSocial,FechaVence,V.Factura
 END
ELSE
 --Consulta Vencimientos que tengan relacionado abonos
 BEGIN
  SELECT V.IdCliente AS NitCliente,T.RazonSocial AS NomCliente,V.IdAgencia AS CdAgencia,Agencia,V.TipDoc AS IdTipFact,TD.TipoDoc AS TipoFact,V.Factura AS NumFactura,V.IdCia AS CdCia,CI.Compania AS NomCiaFact,V.Item AS nItemFact
 ,VrFactura,VrAbonado AS TotalAbonado,VrFactura-VrAbonado AS ValorSaldo,V.Fecha AS FechaEmision,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
 ,TipRec,TR.TipoDoc AS TipoRecibo,VA.Recibo AS NumRecibo,VA.IdCia AS RecCodCia,CR.Compania AS RecCompania,VA.Item AS RecItem,VA.Fecha AS RecFecha,VA.FecPago AS FechaPago,VrAbono,VrDescto
 ,VA.Detalle AS RecDetalle,VA.IdVend AS RecCdVend,VR.RazonSocial AS RecVendedor,VrBaseCms,VA.Comision AS TarifComsCobro,TipoAplica,VA.TimeSys AS FecHoraCrea
 ,EnEfectivo,CdForma,NumForma,CdBanco,RC.Referencia AS RecReferencia
 ,V.IdConcepto AS FacCodConcepto,Concepto,V.Referencia AS FacReferencia,V.Detalle AS FacDetalle,V.IdVend AS FacIdVend,VN.RazonSocial AS FacVendedor,V.Comision AS FacTarifComs
 ,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora
 ,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
 ,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
 ,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
 ,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
 ,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
 ,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM Trn_Vencimientos AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia  INNER JOIN Sys_TiposDoc AS TD ON V.TipDoc=TD.IdDoc
 INNER JOIN Companias AS CI ON V.IdCia=CI.IdCia  INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN TercCliente AS CLI ON V.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 INNER JOIN Trn_VencAbonos AS VA ON V.TipDoc=VA.TipDoc AND V.Factura=VA.Factura AND V.IdCia=VA.IdCiaFac AND V.Item=VA.ItemFac
 INNER JOIN Sys_TiposDoc AS TR ON VA.TipRec=TR.IdDoc INNER JOIN Companias AS CR ON VA.IdCia=CR.IdCia 
 LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto
 LEFT JOIN Terceros AS VR ON VA.IdVend=VR.IdTercero
 LEFT JOIN Trn_Recibos AS RC ON VA.TipRec=RC.TipDoc AND VA.Recibo=RC.Recibo AND VA.IdCia=RC.IdCia
 WHERE (V.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND V.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 AND (V.IdCia=@pmIdCia OR @pmIdCia IS NULL)
 AND (V.IdCliente=@pmIdCliente OR @pmIdCliente IS NULL) 
 AND (VrFactura-VrAbonado)>@pmSaldo
 AND (V.TipDoc=@pmTipDoc OR @pmTipDoc IS NULL) 
 AND (V.IdAgencia=@pmIdAgencia OR @pmIdAgencia IS NULL)
 AND (V.IdVend=@pmIdVend OR @pmIdVend IS NULL)
 AND (VA.Fecha>=ISNULL(@pmFecAboIni,CAST('19100101' AS SMALLDATETIME)) AND VA.Fecha<=ISNULL(@pmFecAboFin,CAST('20781230' AS SMALLDATETIME)))
 AND (VA.Recibo>=ISNULL(@pmReciboIni,0) AND VA.Recibo<=ISNULL(@pmReciboFin,2147483647))
END
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosAcu] @pmTipDoc VARCHAR(3),@pmnAnno INT,@pmnMes INT
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null
 AS 
 SELECT TipDoc,IdCliente,IdAgencia,IdCia,SUM(VrFactura) AS STOTFAC
 FROM Trn_Vencimientos
 WHERE YEAR(Fecha)=@pmnAnno AND MONTH(Fecha)=@pmnMes  AND TipDoc LIKE ISNULL(@pmTipDoc,'%')  
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 GROUP BY TipDoc,IdCliente,IdAgencia,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosAut]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosAut] @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null
 AS 
 SELECT TipDoc,Factura,IdCia,Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado,Fecha,FechaVence,Referencia,Detalle
,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,IdVend,VD.RazonSocial AS Vendedor,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto
,TipRef,DocRef,IdCiaRef,FecUltPago
 FROM Trn_Vencimientos AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Terceros AS VD ON V.IdVend=VD.IdTercero
 WHERE VrFactura>VrAbonado AND IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 ORDER BY  FechaVence,TipDoc,IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosDab]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosDab] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
,@pmItem INT=Null,@pmTipoAplicaExc VARCHAR(10)=Null
 AS 
 SELECT V.Item AS NItem,VrFactura,VrAbonado,SUM(VrAbono) AS STOTABO
 FROM Trn_Vencimientos AS V  INNER JOIN Trn_VencAbonos AS A ON V.TipDoc=A.TipDoc AND V.Factura=A.Factura
 AND V.IdCia=A.IdCiaFac AND V.Item=A.ItemFac
 WHERE V.TipDoc=@pmTipDoc AND V.Factura=@pmFactura AND V.IdCia=@pmIdCia AND TipoAplica<>@pmTipoAplicaExc
 AND (V.Item>=ISNULL(@pmItem,0)  AND V.Item<=ISNULL(@pmItem,2147483647))
 GROUP BY V.Item,VrFactura,VrAbonado
 ORDER BY  V.Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosDoc] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 SELECT  Item,Fecha,FechaVence,VrFactura,VrAbonado,VrFactura-VrAbonado AS TotalSaldo,IdVend,Comision,TarifDcto,TipoDcto
,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,IdCliente,IdAgencia
,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora,TipDoc,Factura,IdCia,FecPlazoCal
 FROM Trn_Vencimientos
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosLca]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosLca] @pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME,@pmTipDoc VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT IdCliente,T.RazonSocial AS NomCliente,V.IdAgencia AS CdAgencia,Agencia,TipDoc,TipoDoc,Factura,V.IdCia AS CdCia,Compania,Item
,VrFactura,VrAbonado,VrFactura-VrAbonado AS ValorSaldo,Fecha,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
,V.IdConcepto AS CdConcepto,Concepto,V.Referencia AS FacReferencia,Detalle,V.IdVend AS CdVend,VN.RazonSocial AS Vendedor,V.Comision AS TarifComs
,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM Trn_Vencimientos AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia  INNER JOIN Sys_TiposDoc AS TD ON V.TipDoc=TD.IdDoc
 INNER JOIN  Companias AS CI ON V.IdCia=CI.IdCia  INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN TercCliente AS CLI ON V.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto
 WHERE  (VrFactura-VrAbonado)>@pmSaldo AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  V.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND V.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 UNION
--saldos a favor
 SELECT IdCliente,T.RazonSocial AS NomCliente,V.IdAgencia AS CdAgencia,Agencia,'SAF','SALDO A FAVOR',0,V.IdCia AS CdCia,Compania,0
,SUM(VrAFavor-VrOtrosDb) AS VrFactura,SUM(VrAbono) AS VrAbonado,SUM(((VrAFavor-VrOtrosDb)-VrAbono)*-1) AS ValorSaldo,@pmFecActual,@pmFecActual,0
,'SAF','SALDO A FAVOR','','SALDO A FAVOR',V.IdVend AS CdVend,VN.RazonSocial AS Vendedor,0,0,'','',Null,'',0,'00',Null,0,'00',0,Null
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM Trn_RecAfavor AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia INNER JOIN  Companias AS CI ON V.IdCia=CI.IdCia 
 INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero INNER JOIN TercCliente AS CLI ON V.IdCliente=CLI.IdClie
 INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona
 INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 WHERE  (VrAFavor-VrOtrosDb)>VrAbono AND V.IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
 AND V.IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND V.IdVend LIKE ISNULL(@pmIdVend,'%')
 GROUP BY IdCliente,T.RazonSocial,V.IdAgencia,Agencia,V.IdCia,Compania,V.IdVend,VN.RazonSocial
,T.TipoId,T.Dv,T.Codigo,T.NomCial,T.SiglaRaz,T.Direccion,T.IdLocal,L.Localidad,L.IdDep,D.Departamento,T.Telefono
,T.Fax,T.e_mail,T.SitioWeb,T.IdSector,SectorEco,T.IdRegimen,Regimen,T.TipEnte
,CLI.IdSzona,Subzona,SZ.IdZona,Zona,CLI.IdGrupo,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato,CodAgencia,A.DirAgncia
,A.TelAgncia,A.FaxAgncia,A.IdLocal,LA.Localidad,LA.IdDep,DA.Departamento,A.Referencia,A.NContrato,CiaCont
UNION
--CHEQUES POSTFECHADOS
SELECT IdCliente,T.RazonSocial AS NomCliente,R.IdAgencia AS CdAgencia,Agencia,R.TipDoc AS TipDocRec,'CHEQUE',R.Recibo AS NumRecibo,R.IdCia AS CdCia,Compania,0
,VrForma,0,VrForma AS ValorSaldo,CH.Fecha AS FecEmision,FecPago,0,'CHE','CHEQUE POSTFECHADO',Numero,Detalle,CdVend,VN.RazonSocial AS Vendedor,0,0,'','',Null,'',0,'00',Null,0,'00',0,Null
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona,CLI.IdGrupo AS CdGrupoCli,GrupoClie,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM Trn_RecCheques AS R INNER JOIN  Trn_Cheques AS CH ON R.TipDoc=CH.TipRec AND R.Recibo=CH.Recibo AND R.IdCia=CH.IdCia
 INNER JOIN Terceros AS T ON R.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON R.IdAgencia=A.IdAgencia INNER JOIN  Companias AS CI ON R.IdCia=CI.IdCia 
 INNER JOIN TercCliente AS CLI ON R.IdCliente=CLI.IdClie  INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Terceros AS VN ON CH.CdVend=VN.IdTercero
 WHERE  CH.Anulado=0 AND R.Anulado=0 AND Documento<=0 AND CH.IdEstado<>'9998'  AND  R.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND R.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND CH.CdVend LIKE ISNULL(@pmIdVend,'%')
 AND (CH.Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND CH.Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial,FechaVence,V.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosLta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosLta] @pmSaldo DECIMAL(14,2),@pmFecActual SMALLDATETIME,@pmTipDoc VARCHAR(3)=Null
,@pmIdCia CHAR(2)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdAgencia VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 SELECT IdCliente,T.RazonSocial AS NomCliente,V.IdAgencia AS CdAgencia,Agencia,TipDoc,TipoDoc,Factura,V.IdCia AS CdCia,Compania,Item
,VrFactura,VrAbonado,VrFactura-VrAbonado AS ValorSaldo,Fecha,FechaVence,DATEDIFF(day,FechaVence,@pmFecActual) AS DiasMora
,V.IdConcepto AS CdConcepto,Concepto,V.Referencia AS FacReferencia,Detalle,V.IdVend AS CdVend,VN.RazonSocial AS Vendedor,V.Comision AS TarifComs
,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,TarifInt,FecLiqMora
--información del tercero
,T.TipoId AS TercTipo,T.Dv AS TercDv,T.Codigo AS TercCodigo,T.NomCial AS TercNomCial,T.SiglaRaz AS TercSigal,T.Direccion AS TercDireccion
,T.IdLocal AS TercCdCiudad,L.Localidad AS NomCiudad,L.IdDep AS CdDep,D.Departamento AS TercDpto,T.Telefono AS TercTelefono,T.Fax AS TercFax,T.e_mail AS TercEmail
,T.SitioWeb AS TercSitioWeb,T.IdSector AS CdSector,SectorEco,T.IdRegimen AS CdRegimen,Regimen,T.TipEnte AS TercTipEnte
--información del cliente
,NitRepLeg,NomRepLeg,CLI.NitContac AS ClieNitContac,CLI.NomContac AS ClieNomContacto,CLI.TelContac AS ClieTelContac,CLI.emlContac AS ClieEmailContac,CargContac,DiasEntga,CLI.IdSzona AS CdSubzona,Subzona,SZ.IdZona AS CdZona,Zona
,CLI.IdGrupo AS CdGrupoCli,GrupoClie,CLI.IdClase AS CdClaseCta,NumCuenta,CLI.IdBanco AS CdBanco,Banco,ExcIva,LiqFletes,CLI.FactSold AS FactSoldicom,Autoret,VrCupo,VrSaldo,Contrato,CLI.NContrato AS CliNumContrato
,CodAgencia,A.DirAgncia AS AgeDireccion,A.TelAgncia AS AgeTelefono,A.FaxAgncia AS AgeFax,A.IdLocal AS AgeIdCiudad,LA.Localidad AS AgeCiudad,LA.IdDep AS AgeCodDep
,DA.Departamento AS AgeDpto,A.Referencia AS AgeReferencia,A.NContrato AS AgeNumContrato,CiaCont
 FROM Trn_Vencimientos AS V INNER JOIN Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Agencias AS A ON V.IdAgencia=A.IdAgencia  INNER JOIN Sys_TiposDoc AS TD ON V.TipDoc=TD.IdDoc
 INNER JOIN  Companias AS CI ON V.IdCia=CI.IdCia  INNER JOIN Terceros AS VN ON V.IdVend=VN.IdTercero
 INNER JOIN TercCliente AS CLI ON V.IdCliente=CLI.IdClie INNER JOIN Subzonas AS SZ ON CLI.IdSzona=SZ.IdSzona 
 INNER JOIN  Zonas AS Z ON SZ.IdZona=Z.IdZona  INNER JOIN GruposCli AS GC ON CLI.IdGrupo=GC.IdGrupo
 INNER JOIN Bancos AS BC ON CLI.IdBanco=BC.IdBanco
 INNER JOIN Localidades AS LA ON A.IdLocal=LA.IdLocal  INNER JOIN Departamentos AS DA ON LA.IdDep=DA.IdDep 
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal  INNER JOIN Departamentos AS D ON L.IdDep=D.IdDep 
 INNER JOIN  RegimenDian AS RG ON T.IdRegimen=RG.IdRegimen INNER JOIN SectoresEco AS SE ON T.IdSector=SE.IdSector
 LEFT JOIN Conceptos AS C ON V.IdConcepto=C.IdConcepto
 WHERE  (VrFactura-VrAbonado)>@pmSaldo AND TipDoc LIKE ISNULL(@pmTipDoc,'%') AND  V.IdCia LIKE ISNULL(@pmIdCia,'%%')
 AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND V.IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
 AND V.IdVend LIKE ISNULL(@pmIdVend,'%')
 AND (Fecha>=ISNULL(@pmFechaIni,CAST('19100101' AS SMALLDATETIME)) AND Fecha<=ISNULL(@pmFechaFin,CAST('20781230' AS SMALLDATETIME)))
 ORDER BY T.RazonSocial,FechaVence,V.IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosMor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosMor] @pmIdCliente VARCHAR(16),@pmFechaAct SMALLDATETIME,@pmIdAgencia VARCHAR(16)=Null
,@pmTipDoc VARCHAR(3)=Null
AS
 SELECT TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia
,IdVend,Comision,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago
 FROM Trn_Vencimientos 
 WHERE IdCliente=@pmIdCliente AND VrFactura>VrAbonado AND FechaVence<@pmFechaAct
 AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%') AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 ORDER BY FechaVence,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosNit]  @pmFechaAct SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdVend VARCHAR(16)=Null,@pmTipDoc VARCHAR(3)=Null
 AS 
 SELECT TipDoc,Factura,IdCia,Item,VrFactura-VrAbonado AS ValorSaldo,VrFactura,VrAbonado,Fecha,FechaVence,DATEDIFF(day,FechaVence,@pmFechaAct) AS DiasMora
,Referencia,Detalle,IdCliente,T.RazonSocial AS NomCliente,IdAgencia,IdVend,VD.RazonSocial AS Vendedor,Comision,TarifDcto,TipoDcto,TipoBase,FecLmtDcto,IdConcepto
,TipRef,DocRef,IdCiaRef,FecUltPago
 FROM Trn_Vencimientos AS V INNER JOIN   Terceros AS T ON V.IdCliente=T.IdTercero
 INNER JOIN Terceros AS VD ON V.IdVend=VD.IdTercero
 WHERE VrFactura>VrAbonado AND IdCliente=@pmIdCliente AND IdVend LIKE ISNULL(@pmIdVend,'%')
 AND TipDoc LIKE ISNULL(@pmTipDoc,'%')
 ORDER BY  FechaVence,TipDoc,IdCia,Factura
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosTdoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosTdoc] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
 AS 
 SELECT VrSubTotal,VrNeto,SUM(VrFactura) AS STOTFAC,SUM(VrAbonado) AS STOTABO
 FROM Trn_Vencimientos AS V LEFT JOIN Trn_Facturas AS F ON V.TipDoc=F.TipDoc
 AND V.Factura=F.Factura AND V.IdCia=F.IdCia
 WHERE V.TipDoc=@pmTipDoc AND V.Factura=@pmFactura AND V.IdCia=@pmIdCia
 GROUP BY VrSubTotal,VrNeto
GO
/****** Object:  StoredProcedure [dbo].[paQryVencimientosTnit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryVencimientosTnit] @pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)=Null
 AS 
 SELECT COUNT(Factura) AS SCANT,SUM(VrFactura) AS STOTFAC,SUM(VrAbonado) AS STOTABO
 FROM Trn_Vencimientos
 WHERE IdCliente=@pmIdCliente AND IdAgencia LIKE ISNULL(@pmIdAgencia,'%')
GO
/****** Object:  StoredProcedure [dbo].[paQryZonas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryZonas] @pmIdZona VARCHAR(4)
 AS 
 SELECT IdZona,Zona,CdSubCos,Inactivo
 FROM Zonas
 WHERE IdZona=@pmIdZona
GO
/****** Object:  StoredProcedure [dbo].[paQryZonasDso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryZonasDso] 
 AS 
 SELECT IdZona,Zona
 FROM Zonas
 WHERE Inactivo=0
 ORDER BY Zona
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpActivos] @pmIdActivo VARCHAR(30),@pmNomActivo VARCHAR(250),@pmNumSerie VARCHAR(30),@pmCodInvent VARCHAR(16),@pmCodBarras VARCHAR(20),@pmIdGrupo VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdInstala VARCHAR(4),@pmIdDep VARCHAR(4),@pmIdRespons VARCHAR(16),@pmIdCia CHAR(2),@pmIdProv VARCHAR(16)
,@pmFecCompra SMALLDATETIME,@pmFecActivacion SMALLDATETIME,@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmVrCompra MONEY,@pmVrComercial MONEY,@pmVrBaseDep MONEY,@pmVrMejoras MONEY,@pmVrDisminucion MONEY,@pmVidaUtil INT,@pmFecFinDep DATETIME,@pmMetodoDep VARCHAR(10),@pmAjustable BIT
,@pmContable BIT,@pmCueEnGrupo BIT,@pmVrAjuInfAcum MONEY,@pmVrDepAcuHis MONEY,@pmVrDepAcuAju MONEY,@pmVrAjuInfDep MONEY,@pmNumMesesDep INT,@pmFecUltDep SMALLDATETIME,@pmMarca VARCHAR(30),@pmModelo VARCHAR(10),@pmNumPlaca VARCHAR(20),@pmNumDoc VARCHAR(20),@pmReferencia VARCHAR(50),@pmIdEstado VARCHAR(4)
,@pmFecRetiro SMALLDATETIME,@pmIdCausal VARCHAR(4),@pmVrVenta MONEY,@pmTipoContable VARCHAR(10),@pmVrSalvamento MONEY,@pmDepPartes BIT,@pmUndsProd INT,@pmTipComp VARCHAR(3),@pmNumComp INT,@pmCdCiaComp CHAR(2),@pmVUExtend INT
 AS 
 UPDATE Activos SET NomActivo=@pmNomActivo,NumSerie=@pmNumSerie,CodInvent=@pmCodInvent,CodBarras=@pmCodBarras,IdGrupo=@pmIdGrupo,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdInstala=@pmIdInstala,IdDep=@pmIdDep,IdRespons=@pmIdRespons,IdCia=@pmIdCia,IdProv=@pmIdProv,FecCompra=@pmFecCompra,FecActivacion=@pmFecActivacion
,NumOrden=@pmNumOrden,IdCiaOrden=@pmIdCiaOrden,NumEntrada=@pmNumEntrada,IdCiaEnt=@pmIdCiaEnt,VrCompra=@pmVrCompra,VrComercial=@pmVrComercial,VrBaseDep=@pmVrBaseDep,VrMejoras=@pmVrMejoras,VrDisminucion=@pmVrDisminucion,VidaUtil=@pmVidaUtil,FecFinDep=@pmFecFinDep,MetodoDep=@pmMetodoDep,Ajustable=@pmAjustable
,Contable=@pmContable,CueEnGrupo=@pmCueEnGrupo,VrAjuInfAcum=@pmVrAjuInfAcum,VrDepAcuHis=@pmVrDepAcuHis,VrDepAcuAju=@pmVrDepAcuAju,VrAjuInfDep=@pmVrAjuInfDep,NumMesesDep=@pmNumMesesDep,FecUltDep=@pmFecUltDep,Marca=@pmMarca,Modelo=@pmModelo,NumPlaca=@pmNumPlaca,NumDoc=@pmNumDoc,Referencia=@pmReferencia,IdEstado=@pmIdEstado,FecRetiro=@pmFecRetiro,IdCausal=@pmIdCausal,VrVenta=@pmVrVenta
,TipoContable=@pmTipoContable,VrSalvamento=@pmVrSalvamento,DepPartes=@pmDepPartes,UndsProd=@pmUndsProd,TipComp=@pmTipComp,NumComp=@pmNumComp,CdCiaComp=@pmCdCiaComp,VUExtend=@pmVUExtend
 WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_Anexo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpActivos_Anexo] @pmIdActivo VARCHAR(30),@pmIdCuenta VARCHAR(16),@pmIdCueDep VARCHAR(16),@pmIdCueGasto VARCHAR(16),@pmIdCueAjuste VARCHAR(16),@pmIdCueCorr VARCHAR(16),@pmIdCueAjuDep VARCHAR(16),@pmIdCueCorrAD VARCHAR(16),@pmNumPoliza VARCHAR(30)
,@pmNitCiaAseg VARCHAR(16),@pmFecPoliza SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmVrAsegurado MONEY,@pmVrCuotaMes MONEY,@pmVendPoliza VARCHAR(150),@pmTeleVend VARCHAR(30),@pmDiasGarantia INT,@pmComentGarantia VARCHAR(250),@pmPignorado BIT
,@pmFecIniPignor SMALLDATETIME,@pmFecFinPignor SMALLDATETIME,@pmGarantPignor VARCHAR(150),@pmMantenimiento BIT,@pmNumContrato VARCHAR(20),@pmFecIniCont SMALLDATETIME,@pmFecFinCont SMALLDATETIME,@pmPeriodicidad INT,@pmFecUltMnmto SMALLDATETIME
,@pmNitEmpMnmto VARCHAR(16),@pmComentMnmto VARCHAR(250),@pmDesUbicacion VARCHAR(100),@pmComentarios VARCHAR(250),@pmComentRetiro VARCHAR(250),@pmDatosTecnicos VARCHAR(4000),@pmCodNiifAct VARCHAR(16),@pmCodNiifDep VARCHAR(16),@pmCodNiifGasto VARCHAR(16)
 AS 
 UPDATE Activos_Anexo SET IdCuenta=@pmIdCuenta,IdCueDep=@pmIdCueDep,IdCueGasto=@pmIdCueGasto,IdCueAjuste=@pmIdCueAjuste,IdCueCorr=@pmIdCueCorr,IdCueAjuDep=@pmIdCueAjuDep,IdCueCorrAD=@pmIdCueCorrAD,NumPoliza=@pmNumPoliza,NitCiaAseg=@pmNitCiaAseg
,FecPoliza=@pmFecPoliza,FecVigencia=@pmFecVigencia,VrAsegurado=@pmVrAsegurado,VrCuotaMes=@pmVrCuotaMes,VendPoliza=@pmVendPoliza,TeleVend=@pmTeleVend,DiasGarantia=@pmDiasGarantia,ComentGarantia=@pmComentGarantia,Pignorado=@pmPignorado
,FecIniPignor=@pmFecIniPignor,FecFinPignor=@pmFecFinPignor,GarantPignor=@pmGarantPignor,Mantenimiento=@pmMantenimiento,NumContrato=@pmNumContrato,FecIniCont=@pmFecIniCont,FecFinCont=@pmFecFinCont,Periodicidad=@pmPeriodicidad,FecUltMnmto=@pmFecUltMnmto
,NitEmpMnmto=@pmNitEmpMnmto,ComentMnmto=@pmComentMnmto,DesUbicacion=@pmDesUbicacion,Comentarios=@pmComentarios,ComentRetiro=@pmComentRetiro,DatosTecnicos=@pmDatosTecnicos,CodNiifAct=@pmCodNiifAct,CodNiifDep=@pmCodNiifDep,CodNiifGasto=@pmCodNiifGasto
 WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_Partes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpActivos_Partes] @pmIdActivo VARCHAR(30),@pmItem INT,@pmDescParte VARCHAR(250),@pmNumParte VARCHAR(30),@pmFecIniDep SMALLDATETIME,@pmMetDeprec VARCHAR(10),@pmVidaUtil INT,@pmUndsProd INT,@pmVrCompra MONEY,@pmVrBaseDep MONEY,@pmVrSalvamento MONEY,@pmVrDepAcum MONEY,@pmVrDepAcumHis MONEY
,@pmNitProv VARCHAR(16),@pmIdEstado VARCHAR(4),@pmCueEnAfijo BIT,@pmIdCuenta VARCHAR(16),@pmIdCueDep VARCHAR(16),@pmIdCueGasto VARCHAR(16),@pmCodNiifAct VARCHAR(16),@pmCodNiifDep VARCHAR(16),@pmCodNiifGasto VARCHAR(16)
,@pmVrMejoras MONEY,@pmVrDisminuc MONEY,@pmVrAjuAcum MONEY,@pmVrAjuDepAcum MONEY,@pmFec_Retiro SMALLDATETIME
 AS 
 UPDATE Activos_Partes SET DescParte=@pmDescParte,NumParte=@pmNumParte,FecIniDep=@pmFecIniDep,MetDeprec=@pmMetDeprec,VidaUtil=@pmVidaUtil,UndsProd=@pmUndsProd,VrCompra=@pmVrCompra,VrBaseDep=@pmVrBaseDep,VrSalvamento=@pmVrSalvamento,VrDepAcum=@pmVrDepAcum,VrDepAcumHis=@pmVrDepAcumHis,NitProv=@pmNitProv,IdEstado=@pmIdEstado
,CueEnAfijo=@pmCueEnAfijo,IdCuenta=@pmIdCuenta,IdCueDep=@pmIdCueDep,IdCueGasto=@pmIdCueGasto,CodNiifAct=@pmCodNiifAct,CodNiifDep=@pmCodNiifDep,CodNiifGasto=@pmCodNiifGasto,VrMejoras=@pmVrMejoras,VrDisminuc=@pmVrDisminuc,VrAjuAcum=@pmVrAjuAcum,VrAjuDepAcum=@pmVrAjuDepAcum,Fec_Retiro=@pmFec_Retiro
 WHERE IdActivo=@pmIdActivo AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_PartesDis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpActivos_PartesDis] @pmIdActivo VARCHAR(30),@pmItem INT,@pmVrDisminucion MONEY,@pmAuto BIT
 AS 
 IF @pmAuto<>0 
  UPDATE Activos_Partes SET  VrDisminuc=(VrDisminuc+@pmVrDisminucion)  WHERE IdActivo=@pmIdActivo AND Item=@pmItem
 ELSE
  UPDATE Activos_Partes SET  VrDisminuc=@pmVrDisminucion  WHERE IdActivo=@pmIdActivo AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpActivos_PartesMej]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpActivos_PartesMej] @pmIdActivo VARCHAR(30),@pmItem INT,@pmVrMejoras MONEY,@pmAuto BIT
 AS 
 IF @pmAuto<>0 
  UPDATE Activos_Partes SET  VrMejoras=(VrMejoras+@pmVrMejoras)  WHERE IdActivo=@pmIdActivo AND Item=@pmItem
 ELSE
  UPDATE Activos_Partes SET  VrMejoras=@pmVrMejoras  WHERE IdActivo=@pmIdActivo AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpActivosAcu] @pmIdActivo VARCHAR(30),@pmVrAjuInfAcum MONEY,@pmVrDepAcuHis MONEY,@pmVrDepAcuAju MONEY,@pmVrAjuInfDep MONEY,@pmNumMesesDep INT
 AS 
 UPDATE Activos SET VrAjuInfAcum=@pmVrAjuInfAcum,VrDepAcuHis=@pmVrDepAcuHis
,VrDepAcuAju=@pmVrDepAcuAju,VrAjuInfDep=@pmVrAjuInfDep,NumMesesDep=@pmNumMesesDep
 WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosDis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpActivosDis] @pmIdActivo VARCHAR(30),@pmVrDisminucion MONEY,@pmAuto BIT
 AS 
 IF @pmAuto<>0 
  UPDATE Activos SET  VrDisminucion=(VrDisminucion+@pmVrDisminucion)  WHERE IdActivo=@pmIdActivo
 ELSE
  UPDATE Activos SET  VrDisminucion=@pmVrDisminucion  WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosMej]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpActivosMej] @pmIdActivo VARCHAR(30),@pmVrMejoras MONEY,@pmAuto BIT
 AS 
 IF @pmAuto<>0 
  UPDATE Activos SET  VrMejoras=(VrMejoras+@pmVrMejoras)  WHERE IdActivo=@pmIdActivo
 ELSE
  UPDATE Activos SET  VrMejoras=@pmVrMejoras  WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paUpActivosRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpActivosRet] @pmIdActivo VARCHAR(30),@pmIdEstado VARCHAR(4),@pmFecRetiro SMALLDATETIME
,@pmIdCausal VARCHAR(4),@pmVrVenta MONEY
 AS 
 UPDATE Activos SET  IdEstado=@pmIdEstado,FecRetiro=@pmFecRetiro,IdCausal=@pmIdCausal,VrVenta=@pmVrVenta
 WHERE IdActivo=@pmIdActivo
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuAportesSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuAportesSan] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT,@pmIdCia CHAR(2)=Null,@pmIdAsociado VARCHAR(16)=Null,@pmIdVehiculo VARCHAR(10)=Null
AS
 UPDATE AcuAportes SET AcuAportes.SaldoAnt=ISNULL(SA.NuevoSaldo,0)
 FROM AcuAportes INNER JOIN (SELECT nAnno,nMes,IdCia,IdAsociado,UndVehiculo,IdVehiculo,Concepto,SaldoAnt+VrAporte-VrDeduccion AS NuevoSaldo
 FROM AcuAportes WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuAportes.IdCia=SA.IdCia AND AcuAportes.IdAsociado=SA.IdAsociado
 AND AcuAportes.UndVehiculo=SA.UndVehiculo AND AcuAportes.IdVehiculo=SA.IdVehiculo AND AcuAportes.Concepto=SA.Concepto
 WHERE AcuAportes.nAnno=@pmnAnno AND AcuAportes.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuAportes.IdCia=@pmIdCia) AND (@pmIdAsociado IS NULL OR AcuAportes.IdAsociado=@pmIdAsociado) 
 AND (@pmIdVehiculo IS NULL OR AcuAportes.IdVehiculo=@pmIdVehiculo)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCaja]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCaja] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11),@pmSaldoAnt MONEY,@pmFacturas MONEY,@pmDevFacturas MONEY,@pmPlanillas MONEY,@pmDevPlanillas MONEY
,@pmRecibos MONEY,@pmDevRecibos MONEY,@pmIngCaja MONEY,@pmDevIngCaja MONEY,@pmEgrCaja MONEY,@pmDevEgrCaja MONEY,@pmConsignac MONEY,@pmDevConsig MONEY,@pmNotasCalibra MONEY,@pmDevCalibra MONEY,@pmOtrosIng MONEY,@pmOtrosEgr MONEY
 AS 
 UPDATE AcuCaja SET SaldoAnt=@pmSaldoAnt,Facturas=@pmFacturas,DevFacturas=@pmDevFacturas,Planillas=@pmPlanillas,DevPlanillas=@pmDevPlanillas,Recibos=@pmRecibos,DevRecibos=@pmDevRecibos,IngCaja=@pmIngCaja,DevIngCaja=@pmDevIngCaja
,EgrCaja=@pmEgrCaja,DevEgrCaja=@pmDevEgrCaja,Consignac=@pmConsignac,DevConsig=@pmDevConsig,NotasCalibra=@pmNotasCalibra,DevCalibra=@pmDevCalibra,OtrosIng=@pmOtrosIng,OtrosEgr=@pmOtrosEgr
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte AND IdCia=@pmIdCia AND IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCajaEgr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCajaEgr] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
,@pmEgrCaja MONEY,@pmDevEgrCaja MONEY
 AS 
 UPDATE AcuCaja SET EgrCaja=@pmEgrCaja,DevEgrCaja=@pmDevEgrCaja
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte AND IdCia=@pmIdCia AND IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCajaOtr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCajaOtr] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2),@pmIdUsuario VARCHAR(11)
,@pmOtrosIng MONEY,@pmOtrosEgr MONEY
 AS 
 UPDATE AcuCaja SET  OtrosIng=@pmOtrosIng,OtrosEgr=@pmOtrosEgr
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte AND IdCia=@pmIdCia AND IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCajaSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCajaSan] @pmFechaDia SMALLDATETIME,@pmNumCorte INT,@pmIdCia CHAR(2)
,@pmIdUsuario VARCHAR(11),@pmSaldoAnt MONEY
 AS 
 UPDATE AcuCaja SET SaldoAnt=@pmSaldoAnt
 WHERE FechaDia=@pmFechaDia AND NumCorte=@pmNumCorte AND IdCia=@pmIdCia AND IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuClientes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAcuClientes] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmSaldoAnt MONEY
,@pmFacturas MONEY,@pmDevFacturas MONEY,@pmRecibos MONEY,@pmDevRecibos MONEY,@pmNotasDeb MONEY,@pmNotasCre MONEY
 AS 
 UPDATE AcuClientes SET SaldoAnt=@pmSaldoAnt,Facturas=@pmFacturas,DevFacturas=@pmDevFacturas,Recibos=@pmRecibos,DevRecibos=@pmDevRecibos,NotasDeb=@pmNotasDeb,NotasCre=@pmNotasCre
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCliente=@pmIdCliente AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuClientesSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAcuClientesSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmSaldoAnt MONEY
 AS 
 UPDATE AcuClientes SET SaldoAnt=@pmSaldoAnt
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCliente=@pmIdCliente AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAgeSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasAgeSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentasAge SET AcuCuentasAge.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentasAge INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasAge WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuCuentasAge.IdCia=SA.IdCia AND AcuCuentasAge.IdCuenta=SA.IdCuenta
 AND AcuCuentasAge.IdTercero=SA.IdTercero AND AcuCuentasAge.CodAgncia=SA.CodAgncia AND AcuCuentasAge.TipoAcum=SA.TipoAcum
 WHERE AcuCuentasAge.nAnno=@pmnAnno AND AcuCuentasAge.nMes=@pmnMes AND AcuCuentasAge.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuCuentasAge.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentasAge.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAgeSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasAgeSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16)
,@pmTipoAcum CHAR(2),@pmSaldoAnterior MONEY
 AS 
 UPDATE AcuCuentasAge SET SaldoAnterior=@pmSaldoAnterior
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia
 AND IdCuenta=@pmIdCuenta AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia
 AND TipoAcum=@pmTipoAcum
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAuxSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasAuxSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(4),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentasAux SET AcuCuentasAux.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentasAux INNER JOIN (SELECT nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAfiVehic,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasAux WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuCuentasAux.IdCia=SA.IdCia AND AcuCuentasAux.IdCuenta=SA.IdCuenta
 AND AcuCuentasAux.IdTercero=SA.IdTercero AND AcuCuentasAux.CodAgncia=SA.CodAgncia AND AcuCuentasAux.IdCCosto=SA.IdCCosto AND AcuCuentasAux.IdSubCos=SA.IdSubCos
 AND AcuCuentasAux.SubAuxiliar=SA.SubAuxiliar AND AcuCuentasAux.TipoAfiVehic=SA.TipoAfiVehic
 WHERE AcuCuentasAux.nAnno=@pmnAnno AND AcuCuentasAux.nMes=@pmnMes AND AcuCuentasAux.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuCuentasAux.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentasAux.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasAuxSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasAuxSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmnReg INT,@pmIdCuenta VARCHAR(16),@pmSaldoAnterior MONEY
 AS 
 UPDATE AcuCuentasAux SET  SaldoAnterior=@pmSaldoAnterior
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND [Id]=@pmnReg
 AND IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasCcSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasCcSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentasCc SET AcuCuentasCc.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentasCc INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasCc WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuCuentasCc.IdCia=SA.IdCia AND AcuCuentasCc.IdCuenta=SA.IdCuenta
 AND AcuCuentasCc.IdCCosto=SA.IdCCosto AND AcuCuentasCc.IdSubCos=SA.IdSubCos AND AcuCuentasCc.TipoAcum=SA.TipoAcum
 WHERE AcuCuentasCc.nAnno=@pmnAnno AND AcuCuentasCc.nMes=@pmnMes AND AcuCuentasCc.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuCuentasCc.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentasCc.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasCcSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasCcSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmSaldoAnterior MONEY
 AS 
 UPDATE AcuCuentasCc SET SaldoAnterior=@pmSaldoAnterior
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia
 AND IdCuenta=@pmIdCuenta AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasNitSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasNitSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentasNit SET AcuCuentasNit.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentasNit INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasNit WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuCuentasNit.IdCia=SA.IdCia AND AcuCuentasNit.IdCuenta=SA.IdCuenta
 AND AcuCuentasNit.IdTercero=SA.IdTercero
 WHERE AcuCuentasNit.nAnno=@pmnAnno AND AcuCuentasNit.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuCuentasNit.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentasNit.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasNitSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasNitSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmSaldoAnterior MONEY
 AS 
 UPDATE AcuCuentasNit SET SaldoAnterior=@pmSaldoAnterior
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia
 AND IdCuenta=@pmIdCuenta AND IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentas SET AcuCuentas.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentas INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentas WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuCuentas.IdCia=SA.IdCia AND AcuCuentas.IdCuenta=SA.IdCuenta
 WHERE AcuCuentas.nAnno=@pmnAnno AND AcuCuentas.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuCuentas.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentas.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2)
,@pmIdCuenta VARCHAR(16),@pmSaldoAnterior MONEY
 AS 
 UPDATE AcuCuentas SET SaldoAnterior=@pmSaldoAnterior
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasVehSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasVehSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentasVeh SET AcuCuentasVeh.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentasVeh INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasVeh WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuCuentasVeh.IdCia=SA.IdCia AND AcuCuentasVeh.IdCuenta=SA.IdCuenta
 AND AcuCuentasVeh.IdVehiculo=SA.IdVehiculo
 WHERE AcuCuentasVeh.nAnno=@pmnAnno AND AcuCuentasVeh.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuCuentasVeh.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentasVeh.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasVehSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasVehSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmSaldoAnterior MONEY
 AS 
 UPDATE AcuCuentasVeh SET SaldoAnterior=@pmSaldoAnterior
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCuenta=@pmIdCuenta AND IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuCuentasVehtSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuCuentasVehtSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuCuentasVeht SET AcuCuentasVeht.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuCuentasVeht INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuCuentasVeht WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuCuentasVeht.IdCia=SA.IdCia AND AcuCuentasVeht.IdCuenta=SA.IdCuenta
 AND AcuCuentasVeht.IdTercero=SA.IdTercero AND AcuCuentasVeht.IdVehiculo=SA.IdVehiculo AND AcuCuentasVeht.TipoAfiVehic=SA.TipoAfiVehic AND AcuCuentasVeht.TipoAcum=SA.TipoAcum
 WHERE AcuCuentasVeht.nAnno=@pmnAnno AND AcuCuentasVeht.nMes=@pmnMes AND AcuCuentasVeht.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuCuentasVeht.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuCuentasVeht.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasAgeSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasAgeSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentasAge SET AcuFisCuentasAge.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentasAge INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentasAge WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuFisCuentasAge.IdCia=SA.IdCia AND AcuFisCuentasAge.IdCuenta=SA.IdCuenta
 AND AcuFisCuentasAge.IdTercero=SA.IdTercero AND AcuFisCuentasAge.CodAgncia=SA.CodAgncia AND AcuFisCuentasAge.TipoAcum=SA.TipoAcum
 WHERE AcuFisCuentasAge.nAnno=@pmnAnno AND AcuFisCuentasAge.nMes=@pmnMes AND AcuFisCuentasAge.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuFisCuentasAge.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentasAge.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasAuxSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasAuxSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(4),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentasAux SET AcuFisCuentasAux.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentasAux INNER JOIN (SELECT nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAfiVehic,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentasAux WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuFisCuentasAux.IdCia=SA.IdCia AND AcuFisCuentasAux.IdCuenta=SA.IdCuenta
 AND AcuFisCuentasAux.IdTercero=SA.IdTercero AND AcuFisCuentasAux.CodAgncia=SA.CodAgncia AND AcuFisCuentasAux.IdCCosto=SA.IdCCosto AND AcuFisCuentasAux.IdSubCos=SA.IdSubCos
 AND AcuFisCuentasAux.SubAuxiliar=SA.SubAuxiliar AND AcuFisCuentasAux.TipoAfiVehic=SA.TipoAfiVehic
 WHERE AcuFisCuentasAux.nAnno=@pmnAnno AND AcuFisCuentasAux.nMes=@pmnMes AND AcuFisCuentasAux.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuFisCuentasAux.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentasAux.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasCcSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasCcSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentasCc SET AcuFisCuentasCc.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentasCc INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentasCc WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuFisCuentasCc.IdCia=SA.IdCia AND AcuFisCuentasCc.IdCuenta=SA.IdCuenta
 AND AcuFisCuentasCc.IdCCosto=SA.IdCCosto AND AcuFisCuentasCc.IdSubCos=SA.IdSubCos AND AcuFisCuentasCc.TipoAcum=SA.TipoAcum
 WHERE AcuFisCuentasCc.nAnno=@pmnAnno AND AcuFisCuentasCc.nMes=@pmnMes AND AcuFisCuentasCc.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuFisCuentasCc.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentasCc.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasNitSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasNitSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentasNit SET AcuFisCuentasNit.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentasNit INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentasNit WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuFisCuentasNit.IdCia=SA.IdCia AND AcuFisCuentasNit.IdCuenta=SA.IdCuenta
 AND AcuFisCuentasNit.IdTercero=SA.IdTercero
 WHERE AcuFisCuentasNit.nAnno=@pmnAnno AND AcuFisCuentasNit.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuFisCuentasNit.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentasNit.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentas SET AcuFisCuentas.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentas INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentas WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuFisCuentas.IdCia=SA.IdCia AND AcuFisCuentas.IdCuenta=SA.IdCuenta
 WHERE AcuFisCuentas.nAnno=@pmnAnno AND AcuFisCuentas.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuFisCuentas.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentas.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasVehSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasVehSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentasVeh SET AcuFisCuentasVeh.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentasVeh INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentasVeh WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuFisCuentasVeh.IdCia=SA.IdCia AND AcuFisCuentasVeh.IdCuenta=SA.IdCuenta
 AND AcuFisCuentasVeh.IdVehiculo=SA.IdVehiculo
 WHERE AcuFisCuentasVeh.nAnno=@pmnAnno AND AcuFisCuentasVeh.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuFisCuentasVeh.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentasVeh.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuFisCuentasVehtSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuFisCuentasVehtSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuFisCuentasVeht SET AcuFisCuentasVeht.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuFisCuentasVeht INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuFisCuentasVeht WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuFisCuentasVeht.IdCia=SA.IdCia AND AcuFisCuentasVeht.IdCuenta=SA.IdCuenta
 AND AcuFisCuentasVeht.IdTercero=SA.IdTercero AND AcuFisCuentasVeht.IdVehiculo=SA.IdVehiculo AND AcuFisCuentasVeht.TipoAfiVehic=SA.TipoAfiVehic AND AcuFisCuentasVeht.TipoAcum=SA.TipoAcum
 WHERE AcuFisCuentasVeht.nAnno=@pmnAnno AND AcuFisCuentasVeht.nMes=@pmnMes AND AcuFisCuentasVeht.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuFisCuentasVeht.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuFisCuentasVeht.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInventarioSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuInventarioSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmSaldoAnt DECIMAL(14,4),@pmCostoAnt MONEY
 AS 
 UPDATE  AcuInventario SET SaldoAnt=@pmSaldoAnt,CostoAnt=@pmCostoAnt
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia 
 AND IdProducto=@pmIdProducto AND IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInvLotesSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuInvLotesSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdBodega VARCHAR(4),@pmNumLote VARCHAR(30),@pmSaldoAnt DECIMAL(14,4),@pmCostoAnt MONEY
 AS 
 UPDATE  AcuInvLotes SET SaldoAnt=@pmSaldoAnt,CostoAnt=@pmCostoAnt
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia 
 AND IdProducto=@pmIdProducto AND IdBodega=@pmIdBodega AND NumLote=@pmNumLote
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInvTanquesSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuInvTanquesSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdTanque VARCHAR(4),@pmSaldoAnt DECIMAL(14,4),@pmCostoAnt MONEY
 AS 
 UPDATE  AcuInvTanques SET SaldoAnt=@pmSaldoAnt,CostoAnt=@pmCostoAnt
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia 
 AND IdProducto=@pmIdProducto AND IdTanque=@pmIdTanque
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuInvUbicaSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuInvUbicaSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16)
,@pmIdUbic VARCHAR(10),@pmSaldoAnt DECIMAL(14,4),@pmCostoAnt MONEY
 AS 
 UPDATE  AcuInvUbica SET SaldoAnt=@pmSaldoAnt,CostoAnt=@pmCostoAnt
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia 
 AND IdProducto=@pmIdProducto AND IdUbic=@pmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasAgeSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasAgeSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentasAge SET AcuNiifCuentasAge.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentasAge INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,CodAgncia,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentasAge WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuNiifCuentasAge.IdCia=SA.IdCia AND AcuNiifCuentasAge.IdCuenta=SA.IdCuenta
 AND AcuNiifCuentasAge.IdTercero=SA.IdTercero AND AcuNiifCuentasAge.CodAgncia=SA.CodAgncia AND AcuNiifCuentasAge.TipoAcum=SA.TipoAcum
 WHERE AcuNiifCuentasAge.nAnno=@pmnAnno AND AcuNiifCuentasAge.nMes=@pmnMes AND AcuNiifCuentasAge.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuNiifCuentasAge.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentasAge.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasAuxSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasAuxSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(4),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentasAux SET AcuNiifCuentasAux.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentasAux INNER JOIN (SELECT nAnno,nMes,IdCia,nReg,IdCuenta,IdTercero,CodAgncia,IdCCosto,IdSubCos,SubAuxiliar,TipoAfiVehic,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentasAux WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuNiifCuentasAux.IdCia=SA.IdCia AND AcuNiifCuentasAux.IdCuenta=SA.IdCuenta
 AND AcuNiifCuentasAux.IdTercero=SA.IdTercero AND AcuNiifCuentasAux.CodAgncia=SA.CodAgncia AND AcuNiifCuentasAux.IdCCosto=SA.IdCCosto AND AcuNiifCuentasAux.IdSubCos=SA.IdSubCos
 AND AcuNiifCuentasAux.SubAuxiliar=SA.SubAuxiliar AND AcuNiifCuentasAux.TipoAfiVehic=SA.TipoAfiVehic
 WHERE AcuNiifCuentasAux.nAnno=@pmnAnno AND AcuNiifCuentasAux.nMes=@pmnMes AND AcuNiifCuentasAux.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuNiifCuentasAux.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentasAux.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasCcSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasCcSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum CHAR(2),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentasCc SET AcuNiifCuentasCc.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentasCc INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdCCosto,IdSubCos,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentasCc WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuNiifCuentasCc.IdCia=SA.IdCia AND AcuNiifCuentasCc.IdCuenta=SA.IdCuenta
 AND AcuNiifCuentasCc.IdCCosto=SA.IdCCosto AND AcuNiifCuentasCc.IdSubCos=SA.IdSubCos AND AcuNiifCuentasCc.TipoAcum=SA.TipoAcum
 WHERE AcuNiifCuentasCc.nAnno=@pmnAnno AND AcuNiifCuentasCc.nMes=@pmnMes AND AcuNiifCuentasCc.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuNiifCuentasCc.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentasCc.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasNitSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasNitSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentasNit SET AcuNiifCuentasNit.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentasNit INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentasNit WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuNiifCuentasNit.IdCia=SA.IdCia AND AcuNiifCuentasNit.IdCuenta=SA.IdCuenta
 AND AcuNiifCuentasNit.IdTercero=SA.IdTercero
 WHERE AcuNiifCuentasNit.nAnno=@pmnAnno AND AcuNiifCuentasNit.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuNiifCuentasNit.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentasNit.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentas SET AcuNiifCuentas.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentas INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentas WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuNiifCuentas.IdCia=SA.IdCia AND AcuNiifCuentas.IdCuenta=SA.IdCuenta
 WHERE AcuNiifCuentas.nAnno=@pmnAnno AND AcuNiifCuentas.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuNiifCuentas.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentas.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasVehSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasVehSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentasVeh SET AcuNiifCuentasVeh.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentasVeh INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdVehiculo,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentasVeh WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt) AS SA ON AcuNiifCuentasVeh.IdCia=SA.IdCia AND AcuNiifCuentasVeh.IdCuenta=SA.IdCuenta
 AND AcuNiifCuentasVeh.IdVehiculo=SA.IdVehiculo
 WHERE AcuNiifCuentasVeh.nAnno=@pmnAnno AND AcuNiifCuentasVeh.nMes=@pmnMes
 AND (@pmIdCia IS NULL OR AcuNiifCuentasVeh.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentasVeh.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuNiifCuentasVehtSA]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuNiifCuentasVehtSA] @pmnAnno INT,@pmnMes INT,@pmAnnoAnt INT,@pmMesAnt INT
,@pmTipoAcum VARCHAR(3),@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
AS 
 UPDATE AcuNiifCuentasVeht SET AcuNiifCuentasVeht.SaldoAnterior=ISNULL(SA.NuevoSaldo,0)
 FROM AcuNiifCuentasVeht INNER JOIN (SELECT nAnno,nMes,IdCia,IdCuenta,IdTercero,IdVehiculo,TipoAfiVehic,TipoAcum,SaldoAnterior+TotalDebitos-TotalCreditos AS NuevoSaldo
 FROM AcuNiifCuentasVeht WHERE nAnno=@pmAnnoAnt AND nMes=@pmMesAnt AND TipoAcum=@pmTipoAcum) AS SA ON AcuNiifCuentasVeht.IdCia=SA.IdCia AND AcuNiifCuentasVeht.IdCuenta=SA.IdCuenta
 AND AcuNiifCuentasVeht.IdTercero=SA.IdTercero AND AcuNiifCuentasVeht.IdVehiculo=SA.IdVehiculo AND AcuNiifCuentasVeht.TipoAfiVehic=SA.TipoAfiVehic AND AcuNiifCuentasVeht.TipoAcum=SA.TipoAcum
 WHERE AcuNiifCuentasVeht.nAnno=@pmnAnno AND AcuNiifCuentasVeht.nMes=@pmnMes AND AcuNiifCuentasVeht.TipoAcum=@pmTipoAcum
 AND (@pmIdCia IS NULL OR AcuNiifCuentasVeht.IdCia=@pmIdCia) AND (@pmIdCuenta IS NULL OR AcuNiifCuentasVeht.IdCuenta=@pmIdCuenta)
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuPrestamos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAcuPrestamos] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmSaldoAnt MONEY,@pmPrestamos MONEY,@pmDevPrestamos MONEY,@pmRecibos MONEY,@pmDevRecibos MONEY,@pmNotasDeb MONEY,@pmNotasCre MONEY
,@pmFacturas MONEY,@pmDevFacturas MONEY
 AS 
 UPDATE AcuPrestamos SET SaldoAnt=@pmSaldoAnt,Prestamos=@pmPrestamos,DevPrestamos=@pmDevPrestamos,Recibos=@pmRecibos,DevRecibos=@pmDevRecibos
,NotasDeb=@pmNotasDeb,NotasCre=@pmNotasCre,Facturas=@pmFacturas,DevFacturas=@pmDevFacturas
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCliente=@pmIdCliente AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuPrestamosSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAcuPrestamosSan] @pmnAnno INT,@pmnMes INT,@pmIdCia CHAR(2),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmSaldoAnt MONEY
 AS 
 UPDATE AcuPrestamos SET SaldoAnt=@pmSaldoAnt
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND IdCia=@pmIdCia AND IdCliente=@pmIdCliente AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAcuPropietarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpAcuPropietarios] @pmnAnno INT,@pmIdReg INT,@pmnMes INT,@pmIdPropietario VARCHAR(16),@pmIdVehiculo VARCHAR(10)
,@pmIdClase VARCHAR(4), @pmIdCia CHAR(2),@pmSaldoAnterior MONEY, @pmTotalDebitos MONEY, @pmTotalCreditos MONEY
AS
 UPDATE  AcuPropietarios  SET  SaldoAnterior=@pmSaldoAnterior, TotalDebitos=@pmTotalDebitos, TotalCreditos=@pmTotalCreditos
 WHERE  nAnno=@pmnAnno AND IdReg=@pmIdReg AND  nMes=@pmnMes AND IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paUpAduanas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAduanas] @pmIdAduana VARCHAR(4),@pmNomAduana VARCHAR(150),@pmIdPais VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE Aduanas SET NomAduana=@pmNomAduana,IdPais=@pmIdPais,Inactivo=@pmInactivo
 WHERE IdAduana=@pmIdAduana
GO
/****** Object:  StoredProcedure [dbo].[paUpAfAmortiza]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfAmortiza] @pmNumero INT,@pmFecha SMALLDATETIME,@pmEstado INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_AfAmortiza SET Fecha=@pmFecha,Estado=@pmEstado,IdCia=@pmIdCia
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpAfCausales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAfCausales] @pmIdCausal VARCHAR(4),@pmCausal VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE AfCausales SET Causal=@pmCausal,Inactivo=@pmInactivo
 WHERE IdCausal=@pmIdCausal
GO
/****** Object:  StoredProcedure [dbo].[paUpAfClasesCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAfClasesCue] @pmIdClase VARCHAR(4),@pmClaseCue VARCHAR(50),@pmConcepto VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE AfClasesCue SET ClaseCue=@pmClaseCue,Concepto=@pmConcepto,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpAfDeprecia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfDeprecia] @pmNumero INT,@pmFecha SMALLDATETIME,@pmEstado INT
,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_AfDeprecia SET Fecha=@pmFecha,Estado=@pmEstado,IdUsuario=@pmIdUsuario,FechaCrea=@pmFechaCrea,IdCia=@pmIdCia
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpAfEstados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAfEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE AfEstados SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpAfGrupos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfGrupos] @pmIdGrupo VARCHAR(4),@pmGrupo VARCHAR(50),@pmIdLinea VARCHAR(4),@pmVidaUtil INT,@pmInactivo BIT
 AS 
 UPDATE AfGrupos SET Grupo=@pmGrupo,IdLinea=@pmIdLinea,VidaUtil=@pmVidaUtil,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpAfGruposCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfGruposCue] @pmIdGrupo VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCuenta VARCHAR(16)
 AS 
 UPDATE AfGruposCue SET IdCuenta=@pmIdCuenta
 WHERE IdGrupo=@pmIdGrupo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpAfLineas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfLineas] @pmIdLinea VARCHAR(4),@pmLinea VARCHAR(50),@pmVidaUtil INT,@pmTarfDep DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE AfLineas SET Linea=@pmLinea,VidaUtil=@pmVidaUtil,TarfDep=@pmTarfDep,Inactivo=@pmInactivo
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paUpAfMantnmto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAfMantnmto] @pmNumero INT,@pmIdCia CHAR(2),@pmIdActivo VARCHAR(30),@pmFecha SMALLDATETIME,@pmNumContrato VARCHAR(20)
,@pmNitEmpresa VARCHAR(16),@pmNomEmpresa VARCHAR(150),@pmFinContrato BIT,@pmDiagnostico VARCHAR(2000),@pmComentarios VARCHAR(4000),@pmIdMtto VARCHAR(4),@pmVrMantnmto MONEY
 AS 
 UPDATE Trn_AfMantnmto SET IdCia=@pmIdCia,IdActivo=@pmIdActivo,Fecha=@pmFecha,NumContrato=@pmNumContrato,NitEmpresa=@pmNitEmpresa,NomEmpresa=@pmNomEmpresa
,FinContrato=@pmFinContrato,Diagnostico=@pmDiagnostico,Comentarios=@pmComentarios,IdMtto=@pmIdMtto,VrMantnmto=@pmVrMantnmto
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpAfTiposDif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAfTiposDif] @pmIdTipDif VARCHAR(4),@pmTipoDiferido VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE AfTiposDif SET TipoDiferido=@pmTipoDiferido,Inactivo=@pmInactivo
 WHERE IdTipDif=@pmIdTipDif
GO
/****** Object:  StoredProcedure [dbo].[paUpAfTiposMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfTiposMov] @pmIdMov VARCHAR(4),@pmTipoMov VARCHAR(50),@pmConsecutivo INT,@pmInactivo BIT
 AS 
 UPDATE AfTiposMov SET TipoMov=@pmTipoMov,Consecutivo=@pmConsecutivo,Inactivo=@pmInactivo
 WHERE IdMov=@pmIdMov
GO
/****** Object:  StoredProcedure [dbo].[paUpAfTiposMovCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAfTiposMovCon] @pmIdMov VARCHAR(4),@pmConsecutivo INT,@pmAuto BIT
 AS 
 IF @pmAuto <>0 
  UPDATE AfTiposMov SET Consecutivo=Consecutivo+1 WHERE IdMov=@pmIdMov
ELSE
  UPDATE AfTiposMov SET Consecutivo=@pmConsecutivo  WHERE IdMov=@pmIdMov
GO
/****** Object:  StoredProcedure [dbo].[paUpAgencias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAgencias] @pmIdAgencia VARCHAR(16),@pmCodAgencia VARCHAR(16),@pmIdClie VARCHAR(16),@pmAgencia VARCHAR(150),@pmDirAgncia VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelAgncia VARCHAR(20),@pmFaxAgncia VARCHAR(20),@pmNitCont VARCHAR(16),@pmNomCont VARCHAR(150)
,@pmemlCont VARCHAR(100),@pmCargoCont VARCHAR(50),@pmIdSzona VARCHAR(4),@pmIdPlazo VARCHAR(4),@pmCdPlazoComb VARCHAR(4),@pmIdForma VARCHAR(4),@pmCdBandera VARCHAR(4),@pmIdVend VARCHAR(16),@pmCdCms VARCHAR(4),@pmCdDct VARCHAR(4),@pmIntMora DECIMAL(14,4),@pmDiasGracia INT,@pmFactFletes BIT,@pmFactSold BIT
,@pmVrCupoCre MONEY,@pmVrSaldoAct MONEY,@pmFecUpCupo SMALLDATETIME,@pmNContrato INT,@pmCiaCont CHAR(2),@pmFecIngreso SMALLDATETIME,@pmReferencia VARCHAR(50),@pmComentarios VARCHAR(250),@pmCupoGalones DECIMAL(14,4),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTipoZona VARCHAR(10),@pmCodSicom VARCHAR(20)
,@pmCdTipAgenc VARCHAR(4),@pmCdSubAgenc VARCHAR(4),@pmCdGrupAgenc VARCHAR(4), @pmCdSubGrupAgenc VARCHAR(4), @pmCdFntePago VARCHAR(4), @pmPlazoSobtasa VARCHAR(20)
,@pmDocFinanc VARCHAR(3), @pmVolContMes DECIMAL(14,4), @pmVolContTotal DECIMAL(14,4), @pmVolViabMes DECIMAL(14,4),@pmVolViabTotal DECIMAL(14,4), @pmFecPriVenta SMALLDATETIME, @pmInvCtbObra MONEY, @pmInvCtbCapital MONEY, @pmInvCtbEfectivo MONEY, @pmInvCtbImagen MONEY, @pmInvCtbMntmto MONEY
,@pmFecDesemb SMALLDATETIME, @pmInvContObra MONEY, @pmInvContCapital MONEY, @pmInvContEfectivo MONEY, @pmInvContImagen MONEY, @pmCrtlAprovInv INT, @pmCrtlAprovImg INT,@pmFecVigCond SMALLDATETIME,@pmTasaIntArranq DECIMAL(14,4),@pmAgencOperando BIT,@pmTipoFactFletes INT,@pmCdCCBonif VARCHAR(16),@pmCdSubCCBonif VARCHAR(16)
,@pmCodRuta VARCHAR(4),@pmCodDiaEnt VARCHAR(4),@pmCdGruClie VARCHAR(4),@pmCupoElectcom DECIMAL(14,4),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Agencias SET CodAgencia=@pmCodAgencia,IdClie=@pmIdClie,Agencia=@pmAgencia,DirAgncia=@pmDirAgncia,IdLocal=@pmIdLocal,TelAgncia=@pmTelAgncia,FaxAgncia=@pmFaxAgncia,NitCont=@pmNitCont,NomCont=@pmNomCont,emlCont=@pmemlCont,CargoCont=@pmCargoCont,IdSzona=@pmIdSzona
,IdPlazo=@pmIdPlazo,CdPlazoComb=@pmCdPlazoComb,IdForma=@pmIdForma,CdBandera=@pmCdBandera,IdVend=@pmIdVend,CdCms=@pmCdCms,CdDct=@pmCdDct,IntMora=@pmIntMora,DiasGracia=@pmDiasGracia,FactFletes=@pmFactFletes,FactSold=@pmFactSold,VrCupoCre=@pmVrCupoCre,VrSaldoAct=@pmVrSaldoAct
,FecUpCupo=@pmFecUpCupo,FecIngreso=@pmFecIngreso,Referencia=@pmReferencia,Comentarios=@pmComentarios,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,NContrato=@pmNContrato,CiaCont=@pmCiaCont,CupoGalones=@pmCupoGalones,FechaUpdate=@pmFechaUpdate,TipoZona=@pmTipoZona,CodSicom=@pmCodSicom
,CdTipAgenc=@pmCdTipAgenc,CdSubAgenc=@pmCdSubAgenc,CdGrupAgenc=@pmCdGrupAgenc,CdSubGrupAgenc=@pmCdSubGrupAgenc,CdFntePago=@pmCdFntePago,PlazoSobtasa=@pmPlazoSobtasa,DocFinanc=@pmDocFinanc,VolContMes=@pmVolContMes,VolContTotal=@pmVolContTotal,VolViabMes=@pmVolViabMes,VolViabTotal=@pmVolViabTotal
,FecPriVenta=@pmFecPriVenta,InvCtbObra=@pmInvCtbObra,InvCtbCapital=@pmInvCtbCapital,InvCtbEfectivo=@pmInvCtbEfectivo,InvCtbImagen=@pmInvCtbImagen,InvCtbMntmto=@pmInvCtbMntmto,FecDesemb=@pmFecDesemb,InvContObra=@pmInvContObra,InvContCapital=@pmInvContCapital,InvContEfectivo=@pmInvContEfectivo
,InvContImagen=@pmInvContImagen,CrtlAprovInv=@pmCrtlAprovInv,CrtlAprovImg=@pmCrtlAprovImg,FecVigCond=@pmFecVigCond,TasaIntArranq=@pmTasaIntArranq,AgencOperando=@pmAgencOperando,TipoFactFletes=@pmTipoFactFletes,CdCCBonif=@pmCdCCBonif,CdSubCCBonif=@pmCdSubCCBonif,CodRuta=@pmCodRuta,CodDiaEnt=@pmCodDiaEnt,CdGruClie=@pmCdGruClie,CupoElectcom=@pmCupoElectcom
 WHERE IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAgenciasCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAgenciasCon] @pmIdAgencia VARCHAR(16),@pmNContrato INT,@pmCiaCont CHAR(2),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Agencias SET NContrato=@pmNContrato,CiaCont=@pmCiaCont,FechaUpdate=@pmFechaUpdate
 WHERE IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAgenciasEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAgenciasEst] @pmIdAgencia VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmComentarios VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Agencias SET  IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Comentarios=@pmComentarios,FechaUpdate=@pmFechaUpdate
 WHERE IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpAjuInv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAjuInv] @pmTipDoc VARCHAR(3),@pmAjuste INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16)
,@pmVrSubTotal MONEY,@pmCantidad DECIMAL(14,4),@pmBaseAjuInf MONEY,@pmTarifPaag DECIMAL(14,4),@pmNumDcmto INT,@pmNumOrden INT,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_AjuInv SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,VrSubTotal=@pmVrSubTotal,Cantidad=@pmCantidad,BaseAjuInf=@pmBaseAjuInf,TarifPaag=@pmTarifPaag
,NumDcmto=@pmNumDcmto,NumOrden=@pmNumOrden,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Modalidad=@pmModalidad,TipCom=@pmTipCom
,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Ajuste=@pmAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpAlmBodegas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAlmBodegas] @pmIdBodega VARCHAR(4),@pmBodega VARCHAR(100),@pmDireccion VARCHAR(100),@pmTelBodega VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE AlmBodegas SET Bodega=@pmBodega,Direccion=@pmDireccion,TelBodega=@pmTelBodega,Inactivo=@pmInactivo
 WHERE IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paUpAprobacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpAprobacion] @pmTipDoc VARCHAR(3),@pmAprobacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipoPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2)
,@pmFecPedido SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmVrCupoCred MONEY,@pmVrSaldoAct MONEY,@pmChequesDev BIT
,@pmClienteMora BIT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Aprobacion SET Fecha=@pmFecha,TipoPed=@pmTipoPed,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,FecPedido=@pmFecPedido,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia
,pVehiculo=@pmpVehiculo,VrCupoCred=@pmVrCupoCred,VrSaldoAct=@pmVrSaldoAct,ChequesDev=@pmChequesDev,ClienteMora=@pmClienteMora
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Aprobacion=@pmAprobacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpAprobacionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAprobacionAnu] @pmTipDoc VARCHAR(3),@pmAprobacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Aprobacion SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Aprobacion=@pmAprobacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpAreas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAreas] @pmIdArea VARCHAR(4),@pmArea VARCHAR(50),@pmJefeArea VARCHAR(50)
,@pmIdCCosto VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE Areas SET Area=@pmArea,JefeArea=@pmJefeArea,IdCCosto=@pmIdCCosto,Inactivo=@pmInactivo
 WHERE IdArea=@pmIdArea
GO
/****** Object:  StoredProcedure [dbo].[paUpAutoriza]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAutoriza] @pmTipAut VARCHAR(3),@pmAutoriza INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNumAutoriza INT,@pmIdUsuarioAut VARCHAR(11),@pmIdEstacion CHAR(2),@pmNitTercero VARCHAR(16)
,@pmpVehiculo VARCHAR(10),@pmTipoDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFechaDoc SMALLDATETIME,@pmDocRef INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmVrAprobado MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Autoriza SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,NumAutoriza=@pmNumAutoriza,IdUsuarioAut=@pmIdUsuarioAut,IdEstacion=@pmIdEstacion,NitTercero=@pmNitTercero,pVehiculo=@pmpVehiculo
,TipoDoc=@pmTipoDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,FechaDoc=@pmFechaDoc,DocRef=@pmDocRef,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,VrAprobado=@pmVrAprobado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipAut=@pmTipAut AND Autoriza=@pmAutoriza AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpAutorizaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAutorizaAnu] @pmTipAut VARCHAR(3),@pmAutoriza INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Autoriza SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=@pmIdEstado
 WHERE TipAut=@pmTipAut AND Autoriza=@pmAutoriza AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpAutorizaDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpAutorizaDoc] @pmTipAut VARCHAR(3),@pmAutoriza INT,@pmIdCia CHAR(2)
,@pmTipoDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFechaDoc SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Autoriza SET TipoDoc=@pmTipoDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc
,FechaDoc=@pmFechaDoc,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipAut=@pmTipAut AND Autoriza=@pmAutoriza AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpBancos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpBancos] @pmIdBanco VARCHAR(4),@pmBanco VARCHAR(50),@pmIdClase VARCHAR(4),@pmCodEntidad VARCHAR(20),@pmDireccion VARCHAR(50)
,@pmContacto VARCHAR(50),@pmComision DECIMAL(10,4),@pmInactivo BIT
 AS 
 UPDATE Bancos SET Banco=@pmBanco,IdClase=@pmIdClase,CodEntidad=@pmCodEntidad,Direccion=@pmDireccion,Contacto=@pmContacto,Comision=@pmComision,Inactivo=@pmInactivo
 WHERE IdBanco=@pmIdBanco
GO
/****** Object:  StoredProcedure [dbo].[paUpBodegas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpBodegas] @pmIdBodega VARCHAR(4),@pmBodega VARCHAR(50),@pmDescrip VARCHAR(100)
,@pmLtaPre CHAR(1),@pmTipoInv VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Bodegas SET Bodega=@pmBodega,Descrip=@pmDescrip
,LtaPre=@pmLtaPre,Inactivo=@pmInactivo,TipoInv=@pmTipoInv
 WHERE IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paUpBodUbic]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpBodUbic] @pmIdUbic VARCHAR(10),@pmUbicacion VARCHAR(50),@pmIdBodega VARCHAR(4),@pmPasillo VARCHAR(10),@pmNivel VARCHAR(10),@pmProfdad VARCHAR(10),@pmDimAltura DECIMAL(14,4),@pmDimAnch DECIMAL(14,4)
,@pmDimLong DECIMAL(14,4),@pmCapcVolm DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmCapcPeso DECIMAL(14,4),@pmUndPes VARCHAR(10),@pmCdTmcia VARCHAR(4),@pmCdMnjo VARCHAR(4),@pmNotas VARCHAR(250),@pmInactivo BIT
 AS 
 UPDATE BodUbic SET Ubicacion=@pmUbicacion,IdBodega=@pmIdBodega,Pasillo=@pmPasillo,Nivel=@pmNivel,Profdad=@pmProfdad,DimAltura=@pmDimAltura,DimAnch=@pmDimAnch,DimLong=@pmDimLong,CapcVolm=@pmCapcVolm,UndCapc=@pmUndCapc
,CapcPeso=@pmCapcPeso,UndPes=@pmUndPes,CdTmcia=@pmCdTmcia,CdMnjo=@pmCdMnjo,Notas=@pmNotas,Inactivo=@pmInactivo
 WHERE IdUbic=@pmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paUpBusClaseCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpBusClaseCue] @pmIdClase VARCHAR(4),@pmClaseCuenta VARCHAR(50),@pmPrioridad INT,@pmInactivo BIT
 AS 
 UPDATE BusClaseCue SET ClaseCuenta=@pmClaseCuenta,Prioridad=@pmPrioridad,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpCalndario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCalndario] @pmFechaDia SMALLDATETIME,@pmTipoFtvo VARCHAR(3)
 AS 
 UPDATE Calndario SET TipoFtvo=@pmTipoFtvo
 WHERE FechaDia=@pmFechaDia
GO
/****** Object:  StoredProcedure [dbo].[paUpCargos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCargos] @pmIdCargo VARCHAR(4),@pmCargo VARCHAR(50),@pmFunciones VARCHAR(3000),@pmInactivo BIT
 AS 
 UPDATE Cargos SET Cargo=@pmCargo,Funciones=@pmFunciones,Inactivo=@pmInactivo
 WHERE IdCargo=@pmIdCargo
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCausacion] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmFactura VARCHAR(15),@pmIdProveedor VARCHAR(16),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmReferencia VARCHAR(20),@pmModalidad VARCHAR(10),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16)
,@pmVehPropio BIT,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorIva MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorFletes MONEY,@pmValorNeto MONEY,@pmValorCCobrar MONEY,@pmBaseIva MONEY,@pmBaseRet MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmIdTarIva VARCHAR(4),@pmIdTarRet VARCHAR(4)
,@pmIdTarIca VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmCxcVarios BIT,@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCierreCte BIT,@pmIndFactura INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Causacion SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Factura=@pmFactura,IdProveedor=@pmIdProveedor,FecFactura=@pmFecFactura,FecVence=@pmFecVence,Referencia=@pmReferencia,Modalidad=@pmModalidad,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor,VehPropio=@pmVehPropio,ValorTotal=@pmValorTotal,ValorDcto=@pmValorDcto,ValorIva=@pmValorIva,ValorReteFte=@pmValorReteFte
,ValorReteIva=@pmValorReteIva,ValorReteIca=@pmValorReteIca,ValorOtros=@pmValorOtros,ValorFletes=@pmValorFletes,ValorNeto=@pmValorNeto,ValorCCobrar=@pmValorCCobrar,BaseIva=@pmBaseIva,BaseRet=@pmBaseRet,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,IdTarIva=@pmIdTarIva,IdTarRet=@pmIdTarRet,IdTarIca=@pmIdTarIca,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CxPagar=@pmCxPagar,CxcVarios=@pmCxcVarios
,TipEgr=@pmTipEgr,Egreso=@pmEgreso,IdCiaEgr=@pmIdCiaEgr,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CierreCte=@pmCierreCte,IndFactura=@pmIndFactura,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacionAnu] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmAnulado BIT, @pmNumDev INT, @pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250), @pmIdEstado VARCHAR(4)
AS
UPDATE Trn_Causacion SET   Anulado=@pmAnulado, NumDev=@pmNumDev, FecDev=@pmFecDev,Observacion=@pmObservacion, IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacionCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacionCmp] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmTipCom VARCHAR(3),@pmComprobante INT, @pmIdCiaCom CHAR(2),@pmIdEstado VARCHAR(4), @pmFecUpdate SMALLDATETIME
AS
UPDATE  Trn_Causacion SET  TipCom=@pmTipCom,Comprobante=@pmComprobante, IdCiaCom=@pmIdCiaCom,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacionNoInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacionNoInt] @pmTipDoc VARCHAR(3),@pmModalidad VARCHAR(10), @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmIdEstado VARCHAR(4)
AS
 UPDATE  Trn_Causacion SET Comprobante=0,IdCiaCom='',IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Modalidad=@pmModalidad AND  TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCiaCom=@pmIdCiaCom
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVence]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacVence] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecEmision SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmValorFactura MONEY,@pmValorAbono MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10)
,@pmVehPropio BIT,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdConcepto VARCHAR(4),@pmFecUltPago SMALLDATETIME,@pmNotaInt INT,@pmFecUltLiquida SMALLDATETIME,@pmFactura VARCHAR(15),@pmReferencia VARCHAR(20),@pmDetalle VARCHAR(100)
,@pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCiaRec CHAR(2),@pmValorAtcpo MONEY,@pmIdCuenta VARCHAR(16),@pmCombCant DECIMAL(14,4),@pmCombValor MONEY,@pmBaseImpu MONEY,@pmTarifa_Iva DECIMAL(14,4),@pmVrIva MONEY,@pmTarifa_Ret DECIMAL(14,4),@pmVrRetFte MONEY,@pmTarifa_Ica DECIMAL(14,4),@pmVrRetIca MONEY
,@pmCodTarifIva VARCHAR(4),@pmCodTarifRet VARCHAR(4),@pmCodTarifIca VARCHAR(4),@pmTipDocFac VARCHAR(3),@pmNumDocFac INT,@pmCdCiaFac CHAR(2)
 AS 
 UPDATE Trn_CausacVence SET FecEmision=@pmFecEmision,FecVence=@pmFecVence,ValorFactura=@pmValorFactura,ValorAbono=@pmValorAbono,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVehiculo=@pmIdVehiculo,VehPropio=@pmVehPropio,IdVendedor=@pmIdVendedor,Comision=@pmComision,IdCargo=@pmIdCargo,IdClase=@pmIdClase
,IdConcepto=@pmIdConcepto,FecUltPago=@pmFecUltPago,NotaInt=@pmNotaInt,FecUltLiquida=@pmFecUltLiquida,Factura=@pmFactura,Referencia=@pmReferencia,Detalle=@pmDetalle,TipRec=@pmTipRec,Recibo=@pmRecibo,IdCiaRec=@pmIdCiaRec,ValorAtcpo=@pmValorAtcpo,IdCuenta=@pmIdCuenta,CombCant=@pmCombCant,CombValor=@pmCombValor
,BaseImpu=@pmBaseImpu,Tarifa_Iva=@pmTarifa_Iva,VrIva=@pmVrIva,Tarifa_Ret=@pmTarifa_Ret,VrRetFte=@pmVrRetFte,Tarifa_Ica=@pmTarifa_Ica,VrRetIca=@pmVrRetIca,CodTarifIva=@pmCodTarifIva,CodTarifRet=@pmCodTarifRet,CodTarifIca=@pmCodTarifIca,TipDocFac=@pmTipDocFac,NumDocFac=@pmNumDocFac,CdCiaFac=@pmCdCiaFac
WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacVenceAbo] @pmTipDoc VARCHAR(3), @pmDocumento INT, @pmIdCia CHAR(2), @pmItem INT
,@pmValorAbono MONEY,@pmFecUltPago SMALLDATETIME
AS
UPDATE  Trn_CausacVence  SET  ValorAbono=@pmValorAbono,FecUltPago=ISNULL(@pmFecUltPago,FecUltPago)
WHERE  TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND  Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceAcp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacVenceAcp] @pmTipDoc VARCHAR(3),@pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null
AS
--limpia información de anticipos en los vencimientos
 UPDATE  Trn_CausacVence  SET TipRec='',Recibo=0,IdCiaRec='',ValorAtcpo=0
 WHERE  Recibo>0 AND TipDoc LIKE ISNULL(@pmTipDoc,'%') 
  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacVenceApl] @pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdClase VARCHAR(4)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
 UPDATE  Trn_CausacVence  SET Trn_CausacVence.ValorAbono=(SELECT ISNULL(SUM(Trn_RecFactura.ValorAbono-Trn_RecFactura.Devolucion),0)
 FROM Trn_RecFactura WHERE Trn_CausacVence.TipDoc=Trn_RecFactura.TipDoc AND Trn_CausacVence.Documento =Trn_RecFactura.Documento
 AND Trn_CausacVence.IdCia=Trn_RecFactura.IdCiaDoc AND Trn_CausacVence.Item=Trn_RecFactura.ItemDoc)
 WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin 
 AND  IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdCliente like ISNULL(@pmIdCliente,'%')
 AND IdCia like ISNULL(@pmIdCia,'%%')  AND IdClase like ISNULL(@pmIdClase,'%')  AND TipDoc like ISNULL(@pmTipDoc,'%')  
ELSE
 UPDATE  Trn_CausacVence  SET Trn_CausacVence.ValorAbono=(SELECT ISNULL(SUM(Trn_RecFactura.ValorAbono-Trn_RecFactura.Devolucion),0)
 FROM Trn_RecFactura WHERE Trn_CausacVence.TipDoc=Trn_RecFactura.TipDoc AND Trn_CausacVence.Documento =Trn_RecFactura.Documento
 AND Trn_CausacVence.IdCia=Trn_RecFactura.IdCiaDoc AND Trn_CausacVence.Item=Trn_RecFactura.ItemDoc)
 WHERE  IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdCliente like ISNULL(@pmIdCliente,'%')
 AND IdCia like ISNULL(@pmIdCia,'%%')  AND IdClase like ISNULL(@pmIdClase,'%')  AND TipDoc like ISNULL(@pmTipDoc,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpCausacVenceCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausacVenceCero] @pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdClase VARCHAR(4)=Null
,@pmTipDoc VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
  IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
   UPDATE  Trn_CausacVence  SET  ValorAbono=0
   WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND  IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdCliente like ISNULL(@pmIdCliente,'%')
  AND IdCia like ISNULL(@pmIdCia,'%%')   AND  TipDoc like ISNULL(@pmTipDoc,'%')  AND IdClase like ISNULL(@pmIdClase,'%')
 ELSE
    UPDATE  Trn_CausacVence  SET  ValorAbono=0
    WHERE  IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdCliente like ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
   AND  TipDoc LIKE ISNULL(@pmTipDoc,'%')  AND  IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpCausaVales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCausaVales] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY
,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4)
,@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_CausaVales SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrCargos=@pmVrCargos
,VrOtrDcto=@pmVrOtrDcto,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom
,CodTarCom=@pmCodTarCom,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CodTarArf=@pmCodTarArf,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,CodTarAri=@pmCodTarAri,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,FecUpdate=@pmFecUpdate 
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCausaValesAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCausaValesAnu] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_CausaVales SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCentroCosto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCentroCosto] @pmIdCCosto VARCHAR(16),@pmCCosto VARCHAR(100),@pmCodCias VARCHAR(500)
,@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE CentroCosto SET CCosto=@pmCCosto,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo,CodCias=@pmCodCias
 WHERE IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paUpCentrosServ]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCentrosServ] @pmIdCenSer VARCHAR(4),@pmCentroServ VARCHAR(50),@pmDirCentro VARCHAR(100),@pmIdLocal VARCHAR(8)
,@pmTelefonos VARCHAR(30),@pmTipoCentro VARCHAR(10),@pmNitResp VARCHAR(16),@pmRespnsable VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE CentrosServ SET CentroServ=@pmCentroServ,DirCentro=@pmDirCentro,IdLocal=@pmIdLocal,Telefonos=@pmTelefonos,TipoCentro=@pmTipoCentro
,NitResp=@pmNitResp,Respnsable=@pmRespnsable,Inactivo=@pmInactivo
 WHERE IdCenSer=@pmIdCenSer
GO
/****** Object:  StoredProcedure [dbo].[paUpCheques]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCheques] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmVrForma MONEY,@pmCtaForma VARCHAR(30)
,@pmBeneficiario VARCHAR(150),@pmReferncia1 VARCHAR(50),@pmReferncia2 VARCHAR(50),@pmDetalle VARCHAR(150),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmCdVend VARCHAR(16),@pmIdLocal VARCHAR(8),@pmTipRec VARCHAR(3)
,@pmRecibo INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmTipCon VARCHAR(3),@pmNumConsig INT,@pmIdCiaCon CHAR(2),@pmFecConsig SMALLDATETIME,@pmCdCta VARCHAR(4),@pmAnulado BIT
,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Cheques SET Fecha=@pmFecha,FecPago=@pmFecPago,VrForma=@pmVrForma,CtaForma=@pmCtaForma,Beneficiario=@pmBeneficiario,Referncia1=@pmReferncia1,Referncia2=@pmReferncia2,Detalle=@pmDetalle,NitCliente=@pmNitCliente
,CdAgencia=@pmCdAgencia,CdVend=@pmCdVend,IdLocal=@pmIdLocal,TipRec=@pmTipRec,Recibo=@pmRecibo,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,TipCon=@pmTipCon,NumConsig=@pmNumConsig
,IdCiaCon=@pmIdCiaCon,FecConsig=@pmFecConsig,CdCta=@pmCdCta,Anulado=@pmAnulado,FecDev=@pmFecDev,IdEstado=@pmIdEstado
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesACns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpChequesACns] @pmTipCon VARCHAR(3),@pmNumConsig INT,@pmIdCiaCon CHAR(2),@pmFecConsig SMALLDATETIME
 AS 
 UPDATE  Trn_Cheques SET TipCon='0',NumConsig=0,IdCiaCon='00',FecConsig=@pmFecConsig
 WHERE  Anulado=0 AND TipCon=@pmTipCon AND NumConsig=@pmNumConsig AND IdCiaCon=@pmIdCiaCon
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesAnuRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesAnuRec] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET Anulado=@pmAnulado,FecDev=@pmFecDev,IdEstado=@pmIdEstado
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesApl] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc
,FecDoc=@pmFecDoc,IdEstado=@pmIdEstado
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesCns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpChequesCns] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
,@pmTipCon VARCHAR(3),@pmNumConsig INT,@pmIdCiaCon CHAR(2),@pmFecConsig SMALLDATETIME,@pmCdCta VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET TipCon=@pmTipCon,NumConsig=@pmNumConsig,IdCiaCon=@pmIdCiaCon,FecConsig=@pmFecConsig,CdCta=@pmCdCta
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesDap]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesDap] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET  Documento=0,IdCiaDoc='00',IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
 AND TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesDDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesDDoc] @pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCiaDoc CHAR(2),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET  Documento=0,IdCiaDoc='00',IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
 AND  Recibo>0
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesEod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesEod] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmAnulado BIT,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc
,Anulado=@pmAnulado,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesNdb]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesNdb] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE  Trn_Cheques SET Anulado=@pmAnulado,FecDev=@pmFecDev,IdEstado=@pmIdEstado
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpChequesOdb]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpChequesOdb] @pmTipForma VARCHAR(3),@pmNumero VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCia CHAR(2)
,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE  Trn_Cheques SET  Documento=0,IdCiaDoc='00',Anulado=@pmAnulado,FecDev=@pmFecDev,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipForma=@pmTipForma AND Numero=@pmNumero AND IdBanco=@pmIdBanco AND IdCia=@pmIdCia
 AND TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseBan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseBan] @pmIdClase VARCHAR(4),@pmClaseBanco VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseBan SET ClaseBanco=@pmClaseBanco,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseCapac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseCapac] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE ClaseCapac SET NomClase=@pmNomClase,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseCta]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseCta] @pmIdClase VARCHAR(4),@pmClaseCuenta VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseCta SET ClaseCuenta=@pmClaseCuenta,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseDiv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpClaseDiv] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseDiv SET NomClase=@pmNomClase,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseDocCond]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseDocCond] @pmIdDoc VARCHAR(4),@pmDocumento VARCHAR(150),@pmVigencia BIT,@pmInactivo BIT
 AS 
 UPDATE ClaseDocCond SET Documento=@pmDocumento,Vigencia=@pmVigencia,Inactivo=@pmInactivo
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseFon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpClaseFon] @pmIdClase VARCHAR(4),@pmClaseFondo VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseFon SET ClaseFondo=@pmClaseFondo,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClasePol]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpClasePol] @pmIdClase VARCHAR(4),@pmClasePoliza VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClasePol SET ClasePoliza=@pmClasePoliza,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseRie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseRie] @pmIdClase VARCHAR(4),@pmClaseRiesgo VARCHAR(50),@pmTarifa DECIMAL(10,4),@pmInactivo BIT
,@pmCodClase VARCHAR(4)
 AS 
 UPDATE ClaseRie SET ClaseRiesgo=@pmClaseRiesgo,Tarifa=@pmTarifa,Inactivo=@pmInactivo,CodClase=@pmCodClase
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseSub] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseSub SET NomClase=@pmNomClase,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClaseTar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClaseTar] @pmIdClase VARCHAR(4),@pmNomClase VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ClaseTar SET NomClase=@pmNomClase,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpClieContado]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpClieContado] @pmIdCliente VARCHAR(16),@pmNombre VARCHAR(150),@pmTipoId CHAR(1),@pmDv CHAR(1)
,@pmDireccion VARCHAR(150),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmemail VARCHAR(100)
,@pmExcento BIT,@pmPosIniNom INT,@pmInactivo BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE ClieContado SET Nombre=@pmNombre,TipoId=@pmTipoId,Dv=@pmDv,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono
,email=@pmemail,Excento=@pmExcento,PosIniNom=@pmPosIniNom,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate
 WHERE IdCliente=@pmIdCliente
GO
/****** Object:  StoredProcedure [dbo].[paUpCnxextna]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCnxextna] @pmIdReg INT,@pmCnxEngine VARCHAR(10),@pmCnxDso VARCHAR(250),@pmCnxDbname VARCHAR(50),@pmCnxAutentic VARCHAR(3)
,@pmCnxUid VARCHAR(50),@pmCnxPwd VARCHAR(50),@pmCnxOwner VARCHAR(20),@pmCnxObserv VARCHAR(250),@pmCnxTipo VARCHAR(10),@pmCnxPpties VARCHAR(250)
,@pmCnxDriver VARCHAR(100),@pmCnxPort VARCHAR(30),@pmCnxTerminal VARCHAR(4)
 AS 
 UPDATE Sys_Cnxextna SET CnxEngine=@pmCnxEngine,CnxDso=@pmCnxDso,CnxDbname=@pmCnxDbname,CnxAutentic=@pmCnxAutentic,CnxUid=@pmCnxUid,CnxPwd=@pmCnxPwd
,CnxOwner=@pmCnxOwner,CnxObserv=@pmCnxObserv,CnxTipo=@pmCnxTipo,CnxPpties=@pmCnxPpties,CnxDriver=@pmCnxDriver,CnxPort=@pmCnxPort,CnxTerminal=@pmCnxTerminal
 WHERE IdReg=@pmIdReg
GO
/****** Object:  StoredProcedure [dbo].[paUpComDetalle]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpComDetalle] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmIdCuenta VARCHAR(16),@pmDetalle VARCHAR(250),@pmVrDebito MONEY,@pmVrCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmVehPropio INT,@pmVrBase MONEY,@pmTarifaBase DECIMAL(10,4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmCodConce VARCHAR(4),@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15)
,@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmFecVence SMALLDATETIME,@pmCodCta VARCHAR(4),@pmNumCheque VARCHAR(20),@pmIntegrado BIT,@pmTipoAplica CHAR(1),@pmConsolida BIT,@pmCodCargo VARCHAR(4),@pmNitOtros VARCHAR(16),@pmCodSubgpo VARCHAR(8),@pmCiuOrigen VARCHAR(8),@pmCodAgncia VARCHAR(16),@pmReferncia VARCHAR(50),@pmNitDoc VARCHAR(16),@pmTipDocRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmFecUpdate SMALLDATETIME
,@pmCdConcTrib VARCHAR(4),@pmCdTarifTrib VARCHAR(4),@pmNumEstablec VARCHAR(20),@pmPtoEmision VARCHAR(20),@pmNum_Autoriza VARCHAR(50),@pmFechAutoriza SMALLDATETIME,@pmCdCuentaNiif VARCHAR(16)
 AS 
 UPDATE Trn_ComDetalle SET Fecha=@pmFecha,IdCuenta=@pmIdCuenta,Detalle=@pmDetalle,VrDebito=@pmVrDebito,VrCredito=@pmVrCredito,IdTercero=@pmIdTercero,CodAgncia=@pmCodAgncia,IdVehiculo=@pmIdVehiculo,IdCCosto=@pmIdCCosto,VehPropio=@pmVehPropio,VrBase=@pmVrBase,TarifaBase=@pmTarifaBase,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,CodConce=@pmCodConce,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,ItemFac=@pmItemFac,FecVence=@pmFecVence,CodCta=@pmCodCta,NumCheque=@pmNumCheque
,IdSubCos=@pmIdSubCos,Integrado=@pmIntegrado,TipoAplica=@pmTipoAplica,Consolida=@pmConsolida,CodCargo=@pmCodCargo,NitOtros=@pmNitOtros,CodSubgpo=@pmCodSubgpo,CiuOrigen=@pmCiuOrigen,Referncia=@pmReferncia,NitDoc=@pmNitDoc,TipDocRef=@pmTipDocRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef,FecUpdate=@pmFecUpdate
,CdConcTrib=@pmCdConcTrib,CdTarifTrib=@pmCdTarifTrib,NumEstablec=@pmNumEstablec,PtoEmision=@pmPtoEmision,Num_Autoriza=@pmNum_Autoriza,FechAutoriza=@pmFechAutoriza,CdCuentaNiif=@pmCdCuentaNiif
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpComDetallePla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpComDetallePla] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmNumCheque VARCHAR(20),@pmItemFac INT,@pmCodCargo VARCHAR(4)
,@pmIdCuenta VARCHAR(16),@pmVrDebito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmCodAgncia VARCHAR(16)
,@pmReferncia VARCHAR(50),@pmFecUpdate SMALLDATETIME,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
 AS 
 UPDATE Trn_ComDetalle SET IdCuenta=@pmIdCuenta,VrDebito=@pmVrDebito,IdTercero=@pmIdTercero,CodAgncia=@pmCodAgncia,IdVehiculo=@pmIdVehiculo
,Referncia=@pmReferncia,FecUpdate=@pmFecUpdate,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc 
 AND NumCheque=@pmNumCheque AND ItemFac=@pmItemFac AND CodCargo=@pmCodCargo
GO
/****** Object:  StoredProcedure [dbo].[paUpComFactura]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpComFactura] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmItem INT,@pmIdProveedor VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecEmision SMALLDATETIME,@pmFecVence SMALLDATETIME
,@pmVrFactura MONEY,@pmVrAbonado MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmItemCom INT,@pmReferencia VARCHAR(50),@pmDetalle VARCHAR(100),@pmpVehiculo VARCHAR(10),@pmVehPropio BIT
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmEstadoApr INT,@pmMontoAprob MONEY,@pmFecProgPago SMALLDATETIME,@pmObservAprob VARCHAR(250)
 AS 
 UPDATE Trn_ComFactura SET IdCuenta=@pmIdCuenta,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,FecEmision=@pmFecEmision,FecVence=@pmFecVence,VrFactura=@pmVrFactura,VrAbonado=@pmVrAbonado,TipCom=@pmTipCom,Comprobante=@pmComprobante,ItemCom=@pmItemCom
,Referencia=@pmReferencia,Detalle=@pmDetalle,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio,TipRef=@pmTipRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef,EstadoApr=@pmEstadoApr,MontoAprob=@pmMontoAprob,FecProgPago=@pmFecProgPago,ObservAprob=@pmObservAprob
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia AND Item=@pmItem AND IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paUpComFacturaAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpComFacturaAbo] @pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCia CHAR(2),@pmItem INT,@pmIdProveedor VARCHAR(16),@pmVrAbonado MONEY
AS
 UPDATE   Trn_ComFactura SET VrAbonado=@pmVrAbonado
 WHERE TipFac=@pmTipFac AND Factura=@pmFactura AND IdCia=@pmIdCia AND Item=@pmItem
 AND IdProveedor=@pmIdProveedor
GO
/****** Object:  StoredProcedure [dbo].[paUpComFacturaApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpComFacturaApl] @pmIdProveedor VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmTipFac VARCHAR(3)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
  UPDATE  Trn_ComFactura  SET Trn_ComFactura.VrAbonado=(SELECT ISNULL(SUM(Trn_EgrFactura.VrAbono),0)
  FROM Trn_EgrFactura WHERE Trn_ComFactura.TipFac=Trn_EgrFactura.TipFac AND Trn_ComFactura.Factura=Trn_EgrFactura.Factura AND Trn_ComFactura.IdCia=Trn_EgrFactura.IdCiaFac
  AND Trn_ComFactura.Item=Trn_EgrFactura.ItemFac AND Trn_ComFactura.IdProveedor=Trn_EgrFactura.IdProveedor)
  WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND  IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  TipFac LIKE ISNULL(@pmTipFac,'%') 
 ELSE
  UPDATE  Trn_ComFactura  SET Trn_ComFactura.VrAbonado=(SELECT ISNULL(SUM(Trn_EgrFactura.VrAbono),0)
  FROM Trn_EgrFactura WHERE Trn_ComFactura.TipFac=Trn_EgrFactura.TipFac AND Trn_ComFactura.Factura=Trn_EgrFactura.Factura AND Trn_ComFactura.IdCia=Trn_EgrFactura.IdCiaFac
  AND Trn_ComFactura.Item=Trn_EgrFactura.ItemFac AND Trn_ComFactura.IdProveedor=Trn_EgrFactura.IdProveedor)
  WHERE IdProveedor LIKE ISNULL(@pmIdProveedor,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  TipFac LIKE ISNULL(@pmTipFac,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpComFacturaCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpComFacturaCero] @pmIdProveedor VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmTipFac VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null

AS
IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
 UPDATE  Trn_ComFactura  SET  VrAbonado=0
 WHERE FecEmision BETWEEN @pmFechaIni AND @pmFechaFin AND  IdProveedor LIKE ISNULL(@pmIdProveedor,'%') 
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')  AND  TipFac LIKE ISNULL(@pmTipFac,'%')
 ELSE
 UPDATE  Trn_ComFactura  SET  VrAbonado=0
 WHERE IdProveedor LIKE ISNULL(@pmIdProveedor,'%')   AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')  AND  TipFac LIKE ISNULL(@pmTipFac,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpCompanias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCompanias] @pmIdCia CHAR(2),@pmCompania VARCHAR(50),@pmDirInterface VARCHAR(255),@pmFechaActual SMALLDATETIME,@pmPeriodoActual SMALLDATETIME,@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmIdTercero VARCHAR(16),@pmCodSucsal VARCHAR(10),@pmDireccSuc VARCHAR(250),@pmTelefSuc VARCHAR(20),@pmFaxSuc VARCHAR(20),@pmIdLocal VARCHAR(8)
,@pmTipoEDS VARCHAR(10),@pmCodPlanta VARCHAR(20),@pmCodBodega VARCHAR(4),@pmFecModPrest SMALLDATETIME,@pmAutoIca BIT,@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE Companias SET Compania=@pmCompania,DirInterface=@pmDirInterface,FechaActual=@pmFechaActual,PeriodoActual=@pmPeriodoActual,IdCCosto=@pmIdCCosto
,IdSubCos=@pmIdSubCos,IdTercero=@pmIdTercero,CodSucsal=@pmCodSucsal,DireccSuc=@pmDireccSuc,TelefSuc=@pmTelefSuc,FaxSuc=@pmFaxSuc, IdLocal=@pmIdLocal,TipoEDS=@pmTipoEDS
,CodPlanta=@pmCodPlanta,CodBodega=@pmCodBodega,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo,FecModPrest=@pmFecModPrest,AutoIca=@pmAutoIca
 WHERE IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCompaniasFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCompaniasFec] @pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmConta BIT
AS
IF @pmConta<>0 
  UPDATE Companias SET PeriodoActual=@pmFecha  WHERE IdCia=@pmIdCia
ELSE
 UPDATE Companias SET FechaActual=@pmFecha  WHERE IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCompCaja]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCompCaja] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTotal MONEY,@pmVrTotDebito MONEY
,@pmVrTotCredito MONEY,@pmEnEfectivo BIT,@pmCdCta VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmNumForma VARCHAR(20)
,@pmCdBanco VARCHAR(4),@pmReferencia VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME,@pmNumVehiculo VARCHAR(10),@pmFacCalidad INT,@pmSemInicial INT,@pmSemFinal INT
 AS 
 UPDATE Trn_CompCaja SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,VrEfectivo=@pmVrEfectivo,VrOtros=@pmVrOtros,VrTotal=@pmVrTotal,VrTotDebito=@pmVrTotDebito,VrTotCredito=@pmVrTotCredito,EnEfectivo=@pmEnEfectivo,CdCta=@pmCdCta
,IdTercero=@pmIdTercero,CdAgencia=@pmCdAgencia,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdCajero=@pmIdCajero,NumForma=@pmNumForma,CdBanco=@pmCdBanco,Referencia=@pmReferencia,TipCom=@pmTipCom
,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,NumVehiculo=@pmNumVehiculo
,FacCalidad=@pmFacCalidad,SemInicial=@pmSemInicial,SemFinal=@pmSemFinal
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCompCajaDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCompCajaDev] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_CompCaja SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCompGastos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCompGastos] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdPlantilla VARCHAR(4),@pmIdTercero VARCHAR(16),@pmTipFact VARCHAR(3)
,@pmFactura VARCHAR(15),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrTotal MONEY,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_CompGastos SET Fecha=@pmFecha,IdPlantilla=@pmIdPlantilla,IdTercero=@pmIdTercero,TipFact=@pmTipFact,Factura=@pmFactura,FecFactura=@pmFecFactura,FecVence=@pmFecVence,VrTotal=@pmVrTotal
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpComprobantes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpComprobantes] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrTotal MONEY,@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmTipEgr VARCHAR(3),@pmNEgreso INT,@pmpVehiculo VARCHAR(10),@pmVehPropio INT,@pmCedCondtor VARCHAR(16),@pmCodConce VARCHAR(4),@pmBeneficiario VARCHAR(150),@pmVrDivisa1 MONEY,@pmVrDivisa2 MONEY,@pmVrDivisa3 MONEY,@pmPermEditar BIT,@pmIntegrado BIT,@pmEsEgreso BIT,@pmAnticipo BIT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmCdSustento VARCHAR(4),@pmTipo_Pago VARCHAR(10),@pmEstablec VARCHAR(20),@pmPEmision VARCHAR(20),@pmAutorizac VARCHAR(50),@pmFechaAut SMALLDATETIME,@pmNiifTipo VARCHAR(3),@pmNiifNumero INT,@pmFisTipo VARCHAR(3),@pmFisNumero INT,@pmDocSoporte INT,@pmCodRes VARCHAR(4),@pmDescServicio VARCHAR(500),@pmPropddes VARCHAR(50),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Comprobantes SET Fecha=@pmFecha,IdTercero=@pmIdTercero,VrTotal=@pmVrTotal,IdCta=@pmIdCta,EnEfectivo=@pmEnEfectivo,NumCheque=@pmNumCheque,FecCheque=@pmFecCheque,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,TipEgr=@pmTipEgr,NEgreso=@pmNEgreso,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio
,CedCondtor=@pmCedCondtor,CodConce=@pmCodConce,Beneficiario=@pmBeneficiario,PermEditar=@pmPermEditar,Integrado=@pmIntegrado,EsEgreso=@pmEsEgreso,Anticipo=@pmAnticipo,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Propddes=@pmPropddes
,VrDivisa1=@pmVrDivisa1,VrDivisa2=@pmVrDivisa2,VrDivisa3=@pmVrDivisa3,FecUpdate=@pmFecUpdate,CdSustento=@pmCdSustento,Tipo_Pago=@pmTipo_Pago,Establec=@pmEstablec,PEmision=@pmPEmision,Autorizac=@pmAutorizac,FechaAut=@pmFechaAut,NiifTipo=@pmNiifTipo,NiifNumero=@pmNiifNumero,FisTipo=@pmFisTipo,FisNumero=@pmFisNumero,DocSoporte=@pmDocSoporte,CodRes=@pmCodRes,DescServicio=@pmDescServicio
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpComprobantesAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpComprobantesAnu] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2), @pmAnulado BIT, @pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmIdEstado VARCHAR(4), @pmPermEditar BIT,@pmObservacion VARCHAR(250)
AS
 UPDATE  Trn_Comprobantes  SET  Anulado=@pmAnulado, NumDev=@pmNumDev,FecDev=@pmFecDev,IdEstado=@pmIdEstado,Observacion=@pmObservacion,PermEditar=@pmPermEditar
 WHERE TipCom=@pmTipCom AND  Comprobante=@pmComprobante AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpConcDivCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpConcDivCue] @pmIdConcepto VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmCdCueDev VARCHAR(16)
,@pmTipoMov CHAR(1),@pmTipoTerc CHAR(1),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE ConcDivCue SET IdCuenta=@pmIdCuenta,CdCueDev=@pmCdCueDev,TipoMov=@pmTipoMov,TipoTerc=@pmTipoTerc,FecUpdate=@pmFecUpdate
 WHERE IdConcepto=@pmIdConcepto AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpConcDiversos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConcDiversos] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmGrupo VARCHAR(20),@pmEsServicio BIT
,@pmDeManfsto BIT,@pmCdIva VARCHAR(4),@pmCdRet VARCHAR(4),@pmCdIca VARCHAR(4),@pmIdCueDeb VARCHAR(16),@pmIdCueCre VARCHAR(16)
,@pmInactivo BIT,@pmCdAutoret VARCHAR(4),@pmOrdenServ INT,@pmNovedadNom BIT,@pmCdConcDeveng VARCHAR(4),@pmCdConcDed VARCHAR(4)
,@pmRubroConc VARCHAR(50),@pmMudReajuste BIT,@pmCodFEDian VARCHAR(20),@pmTipoConcGat INT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE ConcDiversos SET Concepto=@pmConcepto,Grupo=@pmGrupo,EsServicio=@pmEsServicio,DeManfsto=@pmDeManfsto,CdIva=@pmCdIva
,CdRet=@pmCdRet,CdIca=@pmCdIca,Inactivo=@pmInactivo,IdCueDeb=@pmIdCueDeb,IdCueCre=@pmIdCueCre,CdAutoret=@pmCdAutoret
,NovedadNom=@pmNovedadNom,CdConcDeveng=@pmCdConcDeveng,CdConcDed=@pmCdConcDed,FechaUpdate=@pmFechaUpdate,OrdenServ=@pmOrdenServ
,RubroConc=@pmRubroConc,MudReajuste=@pmMudReajuste,CodFEDian=@pmCodFEDian,TipoConcGat=@pmTipoConcGat
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConceptos] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(100),@pmIdDoc VARCHAR(3),@pmIdCom VARCHAR(3),@pmVcmto BIT,@pmImptos BIT,@pmRetfte BIT
,@pmRetIca BIT,@pmObservacion VARCHAR(150),@pmPdterminado INT,@pmTrfaSanc DECIMAL(14,4),@pmRndTotal INT,@pmDcmtoEquiv BIT,@pmInactivo BIT
,@pmTipoContab VARCHAR(10),@pmCdComNiif VARCHAR(3),@pmCdComFiscal VARCHAR(3),@pmCodCiaTdo CHAR(2),@pmTipoConRev INT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Conceptos SET Concepto=@pmConcepto,IdDoc=@pmIdDoc,IdCom=@pmIdCom,Vcmto=@pmVcmto,Imptos=@pmImptos,Retfte=@pmRetfte,RetIca=@pmRetIca,Observacion=@pmObservacion
,Pdterminado=@pmPdterminado,TrfaSanc=@pmTrfaSanc,RndTotal=@pmRndTotal,Inactivo=@pmInactivo,DcmtoEquiv=@pmDcmtoEquiv
,TipoContab=@pmTipoContab,CdComNiif=@pmCdComNiif,CdComFiscal=@pmCdComFiscal,CodCiaTdo=@pmCodCiaTdo,TipoConRev=@pmTipoConRev,FechaUpdate=@pmFechaUpdate
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosAdmon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConceptosAdmon] @pmIdConcepto VARCHAR(4),@pmIdAdmon VARCHAR(4)
,@pmIdClase INT,@pmIdCuenta VARCHAR(16),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE ConceptosAdmon SET IdCuenta=@pmIdCuenta,FechaUpdate=@pmFechaUpdate
 WHERE IdConcepto=@pmIdConcepto AND IdAdmon=@pmIdAdmon AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConceptosCue] @pmIdConcepto VARCHAR(4),@pmIdClase INT,@pmDescripcion VARCHAR(50),@pmIdCuenta VARCHAR(16)
,@pmTipoMov CHAR(1),@pmDetalleMov VARCHAR(150),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipoTerc CHAR(1),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE ConceptosCue SET Descripcion=@pmDescripcion,IdCuenta=@pmIdCuenta,TipoMov=@pmTipoMov,DetalleMov=@pmDetalleMov
,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,FecUpdate=@pmFecUpdate,TipoTerc=@pmTipoTerc
 WHERE IdConcepto=@pmIdConcepto AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpConceptosPre]  @pmIdConcepto VARCHAR(4),@pmPdterminado INT,@pmIdDoc VARCHAR(3)
 AS 
 UPDATE Conceptos SET Pdterminado=0
 WHERE IdConcepto<>@pmIdConcepto  AND  Pdterminado=@pmPdterminado  AND IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpConceptosTrib]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConceptosTrib] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmCodigoConc VARCHAR(10)
,@pmIdClase VARCHAR(4),@pmCdTarifa VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE ConceptosTrib SET Concepto=@pmConcepto,CodigoConc=@pmCodigoConc,IdClase=@pmIdClase,CdTarifa=@pmCdTarifa,Inactivo=@pmInactivo
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpConsigna]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConsigna] @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmVrEfectivo MONEY,@pmVrOtros MONEY
,@pmVrTotal MONEY,@pmEnEfectivo BIT,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmIdCliente VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11)
,@pmNitDeptante VARCHAR(16),@pmDepositante VARCHAR(150),@pmTelDeptante VARCHAR(20),@pmReferencia VARCHAR(50),@pmReferncia2 VARCHAR(50),@pmNumConsigna VARCHAR(20)
,@pmRangosDoc VARCHAR(100),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecConsig SMALLDATETIME,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Consigna SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,VrEfectivo=@pmVrEfectivo,VrOtros=@pmVrOtros,VrTotal=@pmVrTotal,EnEfectivo=@pmEnEfectivo,IdCta=@pmIdCta,IdCuenta=@pmIdCuenta
,IdCliente=@pmIdCliente,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdCajero=@pmIdCajero,NitDeptante=@pmNitDeptante,Depositante=@pmDepositante,TelDeptante=@pmTelDeptante,Referencia=@pmReferencia
,Referncia2=@pmReferncia2,NumConsigna=@pmNumConsigna,RangosDoc=@pmRangosDoc,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecConsig=@pmFecConsig,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Consignacion=@pmConsignacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpConsignaDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConsignaDev] @pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Consigna SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Consignacion=@pmConsignacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCorrResiduos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCorrResiduos] @pmIdCorr VARCHAR(8),@pmGrupoRP VARCHAR(4),@pmCodigoCR VARCHAR(10),@pmCorrResiduo VARCHAR(500),@pmInactivo BIT
 AS 
 UPDATE CorrResiduos SET GrupoRP=@pmGrupoRP,CodigoCR=@pmCodigoCR,CorrResiduo=@pmCorrResiduo,Inactivo=@pmInactivo
 WHERE IdCorr=@pmIdCorr
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCotizacion] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4)
,@pmDirContacto VARCHAR(250),@pmIdLocal VARCHAR(8),@pmDiasVigencia INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargoContac VARCHAR(50),@pmIdForma VARCHAR(4)
,@pmDetallePago VARCHAR(250),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmModalidad VARCHAR(10)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4),@pmNumPedido INT,@pmCdCiaPed CHAR(2),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Cotizacion SET Fecha=@pmFecha,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrFletes=@pmVrFletes
,VrOtros=@pmVrOtros,VrOtrDcto=@pmVrOtrDcto,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,DirContacto=@pmDirContacto,IdLocal=@pmIdLocal,DiasVigencia=@pmDiasVigencia,NitContac=@pmNitContac
,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargoContac=@pmCargoContac,IdForma=@pmIdForma,DetallePago=@pmDetallePago,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CdMney=@pmCdMney,TipFac=@pmTipFac,Factura=@pmFactura
,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact,Modalidad=@pmModalidad,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NumAprob=@pmNumAprob
,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob,NumPedido=@pmNumPedido,CdCiaPed=@pmCdCiaPed,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionAbr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCotizacionAbr] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Cotizacion SET TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCotizacionAnu] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Cotizacion SET Anulado=@pmAnulado,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCotizacionApr] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2)
,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Cotizacion SET Observacion=@pmObservacion,IdEstado=@pmIdEstado,NumAprob=@pmNumAprob,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCotizacionFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCotizacionFac] @pmTipDoc VARCHAR(3),@pmCotizacion INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Cotizacion SET  TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac
,FechaFact=@pmFechaFact,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Cotizacion=@pmCotizacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpCtasCorrientes]    Script Date: 10/12/2025 8:11:25 ******/
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
/****** Object:  StoredProcedure [dbo].[paUpCtasCorrientesChe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpCtasCorrientesChe] @pmIdCta VARCHAR(4),@pmConsActual INT=Null
AS
 IF @pmConsActual =Null
  UPDATE  CtasCorrientes SET ConsActual=(ConsActual+1)  WHERE  IdCta=@pmIdCta
 ELSE
  UPDATE  CtasCorrientes SET ConsActual=@pmConsActual  WHERE  IdCta=@pmIdCta
GO
/****** Object:  StoredProcedure [dbo].[paUpDepartamentos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDepartamentos] @pmIdDep VARCHAR(8),@pmDepartamento VARCHAR(50)
,@pmCodigo VARCHAR(4),@pmIdPais VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE Departamentos SET Departamento=@pmDepartamento,Codigo=@pmCodigo,Inactivo=@pmInactivo
 ,IdPais=@pmIdPais
 WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paUpDependencias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDependencias] @pmIdDep VARCHAR(4),@pmDependencia VARCHAR(50),@pmJefeDep VARCHAR(50),@pmIdArea VARCHAR(4)
,@pmTipRiesgo DECIMAL(10,4),@pmIdSubCos VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE Dependencias SET Dependencia=@pmDependencia,JefeDep=@pmJefeDep,IdArea=@pmIdArea,TipRiesgo=@pmTipRiesgo
,Inactivo=@pmInactivo,IdSubCos=@pmIdSubCos
 WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paUpDesagregaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDesagregaciones] @pmIdDrp VARCHAR(8),@pmCodigoDR VARCHAR(10),@pmDesagregacion VARCHAR(500),@pmCodigoCR VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE Desagregaciones SET CodigoDR=@pmCodigoDR,Desagregacion=@pmDesagregacion,CodigoCR=@pmCodigoCR,Inactivo=@pmInactivo
 WHERE IdDrp=@pmIdDrp
GO
/****** Object:  StoredProcedure [dbo].[paUpDespachos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDespachos] @pmTipDoc VARCHAR(3),@pmCartulina INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdRuta VARCHAR(4),@pmNumOrden INT
,@pmFechaRec SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmIdConductor1 VARCHAR(16),@pmIdRelevador VARCHAR(16)
,@pmVehPropio BIT,@pmCentInicial INT,@pmCentFinal INT,@pmNPasajeros INT,@pmRecorridos INT,@pmValorProducido MONEY,@pmValorGastos MONEY,@pmValorAhorro MONEY
,@pmValorOtros MONEY,@pmValorVales MONEY,@pmValorAbono MONEY,@pmValorPasaje MONEY,@pmTipoAdmon VARCHAR(10),@pmIdTipRec VARCHAR(3),@pmReciboCaja INT,@pmIdCiaRec CHAR(2)
,@pmNumAutoriza VARCHAR(30),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Despachos SET Fecha=@pmFecha,IdRuta=@pmIdRuta,NumOrden=@pmNumOrden,FechaRec=@pmFechaRec,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor
,IdConductor1=@pmIdConductor1,IdRelevador=@pmIdRelevador,VehPropio=@pmVehPropio,CentInicial=@pmCentInicial,CentFinal=@pmCentFinal,NPasajeros=@pmNPasajeros,Recorridos=@pmRecorridos
,ValorProducido=@pmValorProducido,ValorGastos=@pmValorGastos,ValorAhorro=@pmValorAhorro,ValorOtros=@pmValorOtros,ValorVales=@pmValorVales,ValorAbono=@pmValorAbono
,ValorPasaje=@pmValorPasaje,TipoAdmon=@pmTipoAdmon,IdTipRec=@pmIdTipRec,ReciboCaja=@pmReciboCaja,IdCiaRec=@pmIdCiaRec,NumAutoriza=@pmNumAutoriza,Anulado=@pmAnulado
,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Cartulina=@pmCartulina AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDespachosAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDespachosAnu] @pmTipDoc VARCHAR(3),@pmCartulina INT,@pmIdCia CHAR(2)
,@pmAnulado BIT, @pmNumDev INT, @pmFecDev SMALLDATETIME, @pmObservacion VARCHAR(250), @pmIdEstado VARCHAR(4)
AS
 UPDATE Trn_Despachos  SET  Anulado=@pmAnulado, NumDev=@pmNumDev, FecDev=@pmFecDev, Observacion=@pmObservacion, IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Cartulina=@pmCartulina AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDespachosRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDespachosRec] @pmTipDoc VARCHAR(3),@pmCartulina INT,@pmIdCia CHAR(2),@pmCentInicial INT, @pmCentFinal INT,@pmNPasajeros INT, @pmRecorridos INT, @pmValorProducido MONEY, @pmValorGastos MONEY, @pmValorAhorro MONEY, @pmValorOtros MONEY, @pmValorVales MONEY
, @pmValorAbono MONEY, @pmValorPasaje MONEY, @pmIdTipRec VARCHAR(3), @pmReciboCaja INT, @pmIdCiaRec CHAR(2),@pmIdEstado VARCHAR(4),@pmIdRuta VARCHAR(4),@pmIdRelevador VARCHAR(16), @pmFecUpdate SMALLDATETIME

AS
 UPDATE Trn_Despachos  SET  CentInicial=@pmCentInicial, CentFinal=@pmCentFinal, NPasajeros=@pmNPasajeros, Recorridos=@pmRecorridos, ValorProducido=@pmValorProducido, ValorGastos=@pmValorGastos, ValorAhorro=@pmValorAhorro, ValorOtros=@pmValorOtros, ValorVales=@pmValorVales
, ValorAbono=@pmValorAbono, ValorPasaje=@pmValorPasaje, IdTipRec=@pmIdTipRec, ReciboCaja=@pmReciboCaja, IdCiaRec=@pmIdCiaRec,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,IdRuta=@pmIdRuta,IdRelevador=@pmIdRelevador
WHERE TipDoc=@pmTipDoc AND Cartulina=@pmCartulina AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevCaj]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevCaj] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrEfectivo MONEY
,@pmVrOtros MONEY,@pmVrTotal MONEY,@pmVrTotDebito MONEY,@pmVrTotCredito MONEY,@pmIdTercero VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmEnEfectivo BIT,@pmCdCta VARCHAR(4)
,@pmNumForma VARCHAR(20),@pmCdBanco VARCHAR(4),@pmReferencia VARCHAR(50),@pmNumAutoriza INT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmNumVehiculo VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevCaj SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Recibo=@pmRecibo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,VrEfectivo=@pmVrEfectivo,VrOtros=@pmVrOtros,VrTotal=@pmVrTotal,VrTotDebito=@pmVrTotDebito
,VrTotCredito=@pmVrTotCredito,IdTercero=@pmIdTercero,IdAgencia=@pmIdAgencia,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdCajero=@pmIdCajero,EnEfectivo=@pmEnEfectivo,CdCta=@pmCdCta,NumForma=@pmNumForma,CdBanco=@pmCdBanco
,Referencia=@pmReferencia,NumAutoriza=@pmNumAutoriza,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,NumVehiculo=@pmNumVehiculo
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevCausacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevCausacion] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorIva MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY
,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorFletes MONEY,@pmValorNeto MONEY,@pmValorCxc MONEY,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmFactura VARCHAR(15),@pmIdProveedor VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_DevCausacion SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdPropietario=@pmIdPropietario,VehPropio=@pmVehPropio,ValorTotal=@pmValorTotal,ValorDcto=@pmValorDcto,ValorIva=@pmValorIva,ValorReteFte=@pmValorReteFte,ValorReteIva=@pmValorReteIva,ValorReteIca=@pmValorReteIca,ValorOtros=@pmValorOtros,ValorFletes=@pmValorFletes,ValorNeto=@pmValorNeto
,ValorCxc=@pmValorCxc,IdPlazo=@pmIdPlazo,CxPagar=@pmCxPagar,Factura=@pmFactura,IdProveedor=@pmIdProveedor,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevCns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevCns] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmConsignacion INT,@pmIdCiaDoc CHAR(2)
,@pmFecDoc SMALLDATETIME,@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTotal MONEY,@pmEnEfectivo BIT,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmIdCliente VARCHAR(16),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmReferencia VARCHAR(50),@pmReferncia2 VARCHAR(50),@pmNumConsigna VARCHAR(20),@pmModdDev VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevCns SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Consignacion=@pmConsignacion,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,VrEfectivo=@pmVrEfectivo,VrOtros=@pmVrOtros
,VrTotal=@pmVrTotal,EnEfectivo=@pmEnEfectivo,IdCta=@pmIdCta,IdCuenta=@pmIdCuenta,IdCliente=@pmIdCliente,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdCajero=@pmIdCajero,Referencia=@pmReferencia
,Referncia2=@pmReferncia2,NumConsigna=@pmNumConsigna,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevEnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmIdProv VARCHAR(16),@pmFactura VARCHAR(15),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrSobretasa MONEY
,@pmVrImpGlobal MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmNitFletes VARCHAR(16),@pmCxPagar BIT,@pmDocEquiv VARCHAR(3),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmCdCCosto VARCHAR(16)
,@pmCdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmVrRetFlete MONEY,@pmVrIcaFlete MONEY,@pmFletesCosto BIT,@pmVrIvaMvc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY
,@pmVrImpCarbono MONEY,@pmVrImpuCons MONEY,@pmVrSobtasaCons MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevEnt SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Entrada=@pmEntrada,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdProv=@pmIdProv,Factura=@pmFactura,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento
,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto
,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,NitFletes=@pmNitFletes,CxPagar=@pmCxPagar,DocEquiv=@pmDocEquiv,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,Modalidad=@pmModalidad,ModdDev=@pmModdDev
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,VrRetFlete=@pmVrRetFlete,VrIcaFlete=@pmVrIcaFlete,FletesCosto=@pmFletesCosto,VrIvaMvc=@pmVrIvaMvc
,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,VrImpCarbono=@pmVrImpCarbono,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP
,VrImpuCons=@pmVrImpuCons,VrSobtasaCons=@pmVrSobtasaCons,BaseIvaIgp=@pmBaseIvaIgp,VrIvaIngProd=@pmVrIvaIngProd,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevFco]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevFco] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmnClieCon VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4)
,@pmCantPuntos DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmPedido INT,@pmIdCiaPed CHAR(2),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFecPedido SMALLDATETIME,@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmNumAutoriza INT,@pmPlacaVehic VARCHAR(10),@pmKmtVehic INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmCdMotDev VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevFco SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Factura=@pmFactura,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,nClieCon=@pmnClieCon,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion
,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,VrEfectivo=@pmVrEfectivo,VrPagosOtr=@pmVrPagosOtr,Cantidad=@pmCantidad,CantPuntos=@pmCantPuntos,BaseImp=@pmBaseImp
,BaseRet=@pmBaseRet,IdCajero=@pmIdCajero,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,NitCliente=@pmNitCliente,CdAgencia=@pmCdAgencia,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdLocal=@pmIdLocal,EnEfectivo=@pmEnEfectivo,PlacaVehic=@pmPlacaVehic,KmtVehic=@pmKmtVehic
,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,Remision=@pmRemision,IdCiaRem=@pmIdCiaRem,FecPedido=@pmFecPedido,Modalidad=@pmModalidad,ModdDev=@pmModdDev,NumAutoriza=@pmNumAutoriza,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion
,IdEstado=@pmIdEstado,VrImpCons=@pmVrImpCons,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,CdMotDev=@pmCdMotDev,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP
,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,VrAutRetIat=@pmVrAutRetIat,VrAutRetBom=@pmVrAutRetBom,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevFcr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevFcr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrFaltantes MONEY,@pmVrAnticipos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4)
,@pmCantPuntos DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdLocEnv VARCHAR(8),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmCotizacion INT
,@pmIdCiaCot CHAR(2),@pmFecPedido SMALLDATETIME,@pmModalidad VARCHAR(10),@pmPlacaVehic VARCHAR(10),@pmKmtVehic INT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmVrImpCons MONEY,@pmVrReteCREE MONEY
,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmDevMasivo INT,@pmNumRecibo INT,@pmCdCiaRec CHAR(2),@pmCdMotDev VARCHAR(4),@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY
,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevFcr SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Factura=@pmFactura,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA
,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrCostos=@pmVrCostos,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrFaltantes=@pmVrFaltantes,VrAnticipos=@pmVrAnticipos,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,CantPuntos=@pmCantPuntos,BaseImp=@pmBaseImp
,BaseRet=@pmBaseRet,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,IdLocEnv=@pmIdLocEnv,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,Remision=@pmRemision,IdCiaRem=@pmIdCiaRem,Cotizacion=@pmCotizacion,IdCiaCot=@pmIdCiaCot
,FecPedido=@pmFecPedido,Modalidad=@pmModalidad,ModdDev=@pmModdDev,PlacaVehic=@pmPlacaVehic,KmtVehic=@pmKmtVehic,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,ZonaFrontera=@pmZonaFrontera,VrImpCons=@pmVrImpCons,FecUpdate=@pmFecUpdate
,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,VrImpCarbono=@pmVrImpCarbono,DevMasivo=@pmDevMasivo,NumRecibo=@pmNumRecibo,CdCiaRec=@pmCdCiaRec,CdMotDev=@pmCdMotDev,BaseIvaIgp=@pmBaseIvaIgp,VrIvaIngProd=@pmVrIvaIngProd
,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,VrAutRetIat=@pmVrAutRetIat,VrAutRetBom=@pmVrAutRetBom
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevFvc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevFvc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4)
,@pmCodTarCom VARCHAR(4),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY
 AS 
 UPDATE Trn_DevFvc SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Factura=@pmFactura,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA
,VrReteIVA=@pmVrReteIVA,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,ModdDev=@pmModdDev
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevNpr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevNpr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumNota INT
,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY,@pmVrCostos MONEY,@pmCantEnt DECIMAL(14,4),@pmCantSal DECIMAL(14,4),@pmNumOrden INT
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevNpr SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumNota=@pmNumNota,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdTercero=@pmIdTercero,VrSubTotal=@pmVrSubTotal
,VrCostos=@pmVrCostos,CantEnt=@pmCantEnt,CantSal=@pmCantSal,NumOrden=@pmNumOrden,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Modalidad=@pmModalidad,ModdDev=@pmModdDev
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevPas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevPas] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmNitTercero VARCHAR(16),@pmCdJornada VARCHAR(4),@pmVrSubTotal MONEY,@pmVrSobretasa MONEY
,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmModdDev VARCHAR(10),@pmNumAutoriza INT
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevPas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,nNota=@pmnNota,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,NitTercero=@pmNitTercero,CdJornada=@pmCdJornada,VrSubTotal=@pmVrSubTotal,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrOtros=@pmVrOtros,VrCostos=@pmVrCostos
,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,IdCajero=@pmIdCajero,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Referencia=@pmReferencia,ModdDev=@pmModdDev,NumAutoriza=@pmNumAutoriza,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevPla] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmNitTercero VARCHAR(16),@pmIdJornada VARCHAR(4),@pmVrSubTotal MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY
,@pmVrOtros MONEY,@pmVrSobrantes MONEY,@pmVrFaltantes MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrCreditos MONEY,@pmVrGastComb MONEY,@pmVrGastOtros MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4),@pmVrConTotal MONEY,@pmVrConImp MONEY,@pmVrConDcto MONEY,@pmVrConCos MONEY,@pmConCant DECIMAL(14,4)
,@pmVrCreTotal MONEY,@pmVrCreImp MONEY,@pmVrCreDcto MONEY,@pmVrCreCos MONEY,@pmCreCant DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitRef VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmModalidad VARCHAR(10)
,@pmFecCorte SMALLDATETIME,@pmNumCorte INT,@pmModdDev VARCHAR(10),@pmNumAutoriza INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevPla SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Planilla=@pmPlanilla,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,NitTercero=@pmNitTercero,IdJornada=@pmIdJornada,VrSubTotal=@pmVrSubTotal,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrOtros=@pmVrOtros,VrSobrantes=@pmVrSobrantes,VrFaltantes=@pmVrFaltantes
,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,VrEfectivo=@pmVrEfectivo,VrCreditos=@pmVrCreditos,VrGastComb=@pmVrGastComb,VrGastOtros=@pmVrGastOtros,VrPagosOtr=@pmVrPagosOtr,Cantidad=@pmCantidad,VrConTotal=@pmVrConTotal,VrConImp=@pmVrConImp,VrConDcto=@pmVrConDcto,VrConCos=@pmVrConCos,ConCant=@pmConCant,VrCreTotal=@pmVrCreTotal
,VrCreImp=@pmVrCreImp,VrCreDcto=@pmVrCreDcto,VrCreCos=@pmVrCreCos,CreCant=@pmCreCant,IdCajero=@pmIdCajero,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,NitRef=@pmNitRef,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Referencia=@pmReferencia,Modalidad=@pmModalidad,FecCorte=@pmFecCorte
,NumCorte=@pmNumCorte,ModdDev=@pmModdDev,NumAutoriza=@pmNumAutoriza,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevPrestamos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevPrestamos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmPrestamo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmFechaPrest SMALLDATETIME,@pmTipoPlazo VARCHAR(10),@pmNumCuotas INT,@pmTipoCuota VARCHAR(10)
,@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY,@pmTasaInteres DECIMAL(14,4),@pmCxPagar BIT,@pmFactura VARCHAR(20),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_DevPrestamos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Prestamo=@pmPrestamo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,FechaPrest=@pmFechaPrest,TipoPlazo=@pmTipoPlazo,NumCuotas=@pmNumCuotas,TipoCuota=@pmTipoCuota,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor
,VehPropio=@pmVehPropio,ValorTotal=@pmValorTotal,TasaInteres=@pmTasaInteres,CxPagar=@pmCxPagar,Factura=@pmFactura,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrDescuento MONEY
,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrAhorro MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmVrEfectivo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16)
,@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmNumAutoriza INT,@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevRec SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Recibo=@pmRecibo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,FecPago=@pmFecPago,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrRecibido=@pmVrRecibido,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrOtros=@pmVrOtros
,VrOtrDcto=@pmVrOtrDcto,VrAhorro=@pmVrAhorro,VrPagosMas=@pmVrPagosMas,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado,VrAnticipo=@pmVrAnticipo,VrEfectivo=@pmVrEfectivo,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdCajero=@pmIdCajero,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,IdLocal=@pmIdLocal
,EnEfectivo=@pmEnEfectivo,Referencia=@pmReferencia,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,Modalidad=@pmModalidad,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NumAutoriza=@pmNumAutoriza
,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,CodTarifBom=@pmCodTarifBom,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,CodTarifAvta=@pmCodTarifAvta,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevRecBuses]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevRecBuses] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmModalidad VARCHAR(10),@pmValorRecibido MONEY,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorOtrosDct MONEY,@pmValorPagMas MONEY,@pmValorAhorro MONEY,@pmValorOConce MONEY
,@pmValorNeto MONEY,@pmValorAplicado MONEY,@pmValorAnticipo MONEY,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmIdTarCom VARCHAR(4),@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmIdBanco VARCHAR(4),@pmEsParcial BIT,@pmIdClase VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_DevRecBuses SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Recibo=@pmRecibo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,VehPropio=@pmVehPropio,Modalidad=@pmModalidad,ValorRecibido=@pmValorRecibido
,ValorTotal=@pmValorTotal,ValorDcto=@pmValorDcto,ValorReteFte=@pmValorReteFte,ValorReteIva=@pmValorReteIva,ValorReteIca=@pmValorReteIca,ValorOtros=@pmValorOtros,ValorOtrosDct=@pmValorOtrosDct,ValorPagMas=@pmValorPagMas,ValorAhorro=@pmValorAhorro,ValorOConce=@pmValorOConce,ValorNeto=@pmValorNeto,ValorAplicado=@pmValorAplicado
,ValorAnticipo=@pmValorAnticipo,IdVendedor=@pmIdVendedor,Comision=@pmComision,IdTarCom=@pmIdTarCom,IdCta=@pmIdCta,EnEfectivo=@pmEnEfectivo,NumCheque=@pmNumCheque,IdBanco=@pmIdBanco,EsParcial=@pmEsParcial,IdClase=@pmIdClase,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDevSal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCiaDoc CHAR(2)
,@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmBaseImp MONEY,@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16),@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmpVehiculo VARCHAR(10)
,@pmNContrato INT,@pmIdCiaCont CHAR(2),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmModRequis VARCHAR(10),@pmModalidad VARCHAR(10),@pmModdDev VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevSal SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Salida=@pmSalida,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdTercero=@pmIdTercero,VrSubTotal=@pmVrSubTotal,VrImpuesto=@pmVrImpuesto
,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,BaseImp=@pmBaseImp,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,TipOrd=@pmTipOrd,NumOrden=@pmNumOrden,IdCiaOrd=@pmIdCiaOrd,pVehiculo=@pmpVehiculo
,NContrato=@pmNContrato,IdCiaCont=@pmIdCiaCont,NitCliente=@pmNitCliente,CdAgencia=@pmCdAgencia,ModRequis=@pmModRequis
,Modalidad=@pmModalidad,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDevVal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDevVal] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16)
,@pmTotalPagos MONEY,@pmTotalCobros MONEY,@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmVrDescuento MONEY,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DevVal SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,nRadica=@pmnRadica,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdTercero=@pmIdTercero,TotalPagos=@pmTotalPagos,TotalCobros=@pmTotalCobros,Referencia=@pmReferencia
,CxPagar=@pmCxPagar,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,VrDescuento=@pmVrDescuento,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate 
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDiarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDiarios] @pmIdDiario VARCHAR(4),@pmDiario VARCHAR(50),@pmCodTransac VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Diarios SET Diario=@pmDiario,CodTransac=@pmCodTransac,Inactivo=@pmInactivo
 WHERE IdDiario=@pmIdDiario
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDiferidos] @pmIdDiferido VARCHAR(30),@pmNomDiferido VARCHAR(250),@pmIdTipDif VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdDep VARCHAR(4),@pmIdRespons VARCHAR(16),@pmIdCia CHAR(2),@pmFecInicio SMALLDATETIME,@pmValorTotal MONEY,@pmVrAdiciones MONEY,@pmVrDisminucion MONEY,@pmNumPeriodos INT
,@pmFecFinAmtza DATETIME,@pmAjustable BIT,@pmContable BIT,@pmVrAjuInfAcum MONEY,@pmVrAmtzaAcuHis MONEY,@pmVrAmtzaAcum MONEY,@pmVrAjuInfAmtza MONEY,@pmCuotasAmtza INT
,@pmVrCorrMonDifAcu MONEY,@pmCorrMonDiferida MONEY,@pmNumMesesDif INT,@pmFecUltAmtza SMALLDATETIME,@pmCueEnGrupo BIT,@pmIdCuenta VARCHAR(16),@pmIdCueAmortiza VARCHAR(16)
,@pmIdCueAjuDif VARCHAR(16),@pmIdCueCorrDif VARCHAR(16),@pmIdCueAjuAmtza VARCHAR(16),@pmIdCueCorrAA VARCHAR(16),@pmNumDoc VARCHAR(20),@pmReferencia VARCHAR(50)
,@pmDesUbicacion VARCHAR(150),@pmIdEstado VARCHAR(4),@pmFecRetiro SMALLDATETIME,@pmIdCausal VARCHAR(4),@pmComentRetiro VARCHAR(250),@pmComentarios VARCHAR(250)
,@pmTipoAmtza CHAR(1),@pmNitCliente VARCHAR(16),@pmAgenCliente VARCHAR(16),@pmCantGalones DECIMAL (14,4),@pmIdProv VARCHAR(16),@pmNumPlaca  VARCHAR(20),@pmCodInstala VARCHAR(4),@pmTipoInvers VARCHAR(10)
,@pmTipoContable VARCHAR(10),@pmCodNiifDif VARCHAR(16),@pmCodNiifAmtza VARCHAR(16),@pmTipComp VARCHAR(3),@pmNumComp INT,@pmCdCiaComp CHAR(2)
 AS 
 UPDATE Diferidos SET NomDiferido=@pmNomDiferido,IdTipDif=@pmIdTipDif,IdGrupo=@pmIdGrupo,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdDep=@pmIdDep
,IdRespons=@pmIdRespons,IdCia=@pmIdCia,FecInicio=@pmFecInicio,ValorTotal=@pmValorTotal,VrAdiciones=@pmVrAdiciones,VrDisminucion=@pmVrDisminucion
,NumPeriodos=@pmNumPeriodos,FecFinAmtza=@pmFecFinAmtza,Ajustable=@pmAjustable,Contable=@pmContable,VrAjuInfAcum=@pmVrAjuInfAcum,VrAmtzaAcuHis=@pmVrAmtzaAcuHis
,VrAmtzaAcum=@pmVrAmtzaAcum,VrAjuInfAmtza=@pmVrAjuInfAmtza,CuotasAmtza=@pmCuotasAmtza,VrCorrMonDifAcu=@pmVrCorrMonDifAcu,CorrMonDiferida=@pmCorrMonDiferida,NumMesesDif=@pmNumMesesDif
,FecUltAmtza=@pmFecUltAmtza,CueEnGrupo=@pmCueEnGrupo,IdCuenta=@pmIdCuenta,IdCueAmortiza=@pmIdCueAmortiza,IdCueAjuDif=@pmIdCueAjuDif,IdCueCorrDif=@pmIdCueCorrDif,IdCueAjuAmtza=@pmIdCueAjuAmtza
,IdCueCorrAA=@pmIdCueCorrAA,NumDoc=@pmNumDoc,Referencia=@pmReferencia,DesUbicacion=@pmDesUbicacion,IdEstado=@pmIdEstado,FecRetiro=@pmFecRetiro,IdCausal=@pmIdCausal
,ComentRetiro=@pmComentRetiro,Comentarios=@pmComentarios,TipoAmtza=@pmTipoAmtza,NitCliente=@pmNitCliente,AgenCliente=@pmAgenCliente,CantGalones=@pmCantGalones,IdProv=@pmIdProv
,NumPlaca=@pmNumPlaca,CodInstala=@pmCodInstala,TipoInvers=@pmTipoInvers,TipoContable=@pmTipoContable,CodNiifDif=@pmCodNiifDif,CodNiifAmtza=@pmCodNiifAmtza,TipComp=@pmTipComp,NumComp=@pmNumComp,CdCiaComp=@pmCdCiaComp
 WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDiferidosAcu] @pmIdDiferido VARCHAR(30),@pmVrAjuInfAcum MONEY,@pmVrAmtzaAcuHis MONEY,@pmVrAmtzaAcum MONEY
,@pmVrAjuInfAmtza MONEY,@pmCuotasAmtza INT,@pmVrCorrMonDifAcu MONEY
 AS 
 UPDATE Diferidos SET VrAjuInfAcum=@pmVrAjuInfAcum,VrAmtzaAcuHis=@pmVrAmtzaAcuHis,VrAmtzaAcum=@pmVrAmtzaAcum
,VrAjuInfAmtza=@pmVrAjuInfAmtza,CuotasAmtza=@pmCuotasAmtza,VrCorrMonDifAcu=@pmVrCorrMonDifAcu
 WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosDis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDiferidosDis] @pmIdDiferido VARCHAR(30),@pmVrDisminucion MONEY,@pmAuto BIT
 AS 
 IF @pmAuto<>0 
  UPDATE Diferidos SET  VrDisminucion=(VrDisminucion+@pmVrDisminucion)  WHERE IdDiferido=@pmIdDiferido
 ELSE
  UPDATE Diferidos SET  VrDisminucion=@pmVrDisminucion  WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosMej]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDiferidosMej] @pmIdDiferido VARCHAR(30),@pmVrAdiciones MONEY,@pmAuto BIT
 AS 
 IF @pmAuto<>0 
  UPDATE Diferidos SET  VrAdiciones=(VrAdiciones+@pmVrAdiciones)  WHERE IdDiferido=@pmIdDiferido
 ELSE
  UPDATE Diferidos SET  VrAdiciones=@pmVrAdiciones  WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paUpDiferidosRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDiferidosRet] @pmIdDiferido VARCHAR(30),@pmIdEstado VARCHAR(4),@pmFecRetiro SMALLDATETIME,@pmIdCausal VARCHAR(4)
,@pmComentRetiro VARCHAR(250)
 AS 
 UPDATE Diferidos SET IdEstado=@pmIdEstado,FecRetiro=@pmFecRetiro,IdCausal=@pmIdCausal
,ComentRetiro=@pmComentRetiro 
 WHERE IdDiferido=@pmIdDiferido
GO
/****** Object:  StoredProcedure [dbo].[paUpDisciplinario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDisciplinario]  @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecSuceso SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16)
,@pmIdRuta VARCHAR(4),@pmLugar VARCHAR(150),@pmNomReporta VARCHAR(150),@pmCedReporta VARCHAR(16),@pmVehiculoRep VARCHAR(10),@pmRepCond BIT,@pmCoordinador VARCHAR(150),@pmDespachador VARCHAR(150),@pmCitaDescargos BIT
,@pmFecCita SMALLDATETIME,@pmMemoCita VARCHAR(50),@pmImputacion VARCHAR(2500),@pmDescargos VARCHAR(3000),@pmFecDesc SMALLDATETIME,@pmRecibeDesc VARCHAR(150),@pmTipoSancion VARCHAR(10),@pmDescSancion VARCHAR(1000)
,@pmFecSancion SMALLDATETIME,@pmCantSancion DECIMAL(14,4),@pmCodInfracc INT,@pmReferencia VARCHAR(50),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmTipoInf VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Disciplinario SET Fecha=@pmFecha,FecSuceso=@pmFecSuceso,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor,IdRuta=@pmIdRuta,Lugar=@pmLugar,NomReporta=@pmNomReporta,CedReporta=@pmCedReporta
,VehiculoRep=@pmVehiculoRep,RepCond=@pmRepCond,Coordinador=@pmCoordinador,Despachador=@pmDespachador,CitaDescargos=@pmCitaDescargos,FecCita=@pmFecCita,MemoCita=@pmMemoCita,Imputacion=@pmImputacion,Descargos=@pmDescargos
,FecDesc=@pmFecDesc,RecibeDesc=@pmRecibeDesc,TipoSancion=@pmTipoSancion,DescSancion=@pmDescSancion,FecSancion=@pmFecSancion,CantSancion=@pmCantSancion,CodInfracc=@pmCodInfracc,Referencia=@pmReferencia,Observacion=@pmObservacion
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipoInf=@pmTipoInf
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDisciplinarioAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDisciplinarioAnu] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Disciplinario SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,IdEstado=@pmIdEstado,Observacion=@pmObservacion 
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDocMemo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDocMemo] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmComentarios VARCHAR(6500)
,@pmNota1 VARCHAR(500),@pmNota2 VARCHAR(500),@pmNota3 VARCHAR(500),@pmCantImp INT,@pmArchivoImg VARCHAR(150)
 AS 
 UPDATE Trn_DocMemo SET Comentarios=@pmComentarios
,Nota1=@pmNota1,Nota2=@pmNota2,Nota3=@pmNota3,ArchivoImg=@pmArchivoImg
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDocMemoImp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpDocMemoImp] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
AS
 IF EXISTS (SELECT * FROM Trn_DocMemo WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia)
  BEGIN
   UPDATE Trn_DocMemo SET CantImp=ISNULL(CantImp,0)+1
   WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia
  END
ELSE
  BEGIN
   INSERT INTO Trn_DocMemo (TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg)
   VALUES (@pmTipDoc,@pmDocumento,@pmIdCia,'','','','',1,Null)
  END
GO
/****** Object:  StoredProcedure [dbo].[paUpDocSopDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDocSopDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmBomberil DECIMAL(16,6),@pmImpAviTab DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmValorTotal DECIMAL(16,6)
,@pmBaseRet DECIMAL(16,6),@pmBaseBom DECIMAL(16,6),@pmCodRes VARCHAR(4),@pmDescServicio VARCHAR(500),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmNitCueProv VARCHAR(16),@pmCodCueProv VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500),@pmVrOtrosImpu DECIMAL(16,6)
 AS 
 UPDATE Trn_DocSopDev SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumDoc=@pmNumDoc,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdTercero=@pmIdTercero,SubTotal=@pmSubTotal,Descuento=@pmDescuento,Retencion=@pmRetencion,ReteIca=@pmReteIca,Bomberil=@pmBomberil,ImpAviTab=@pmImpAviTab,OtrosCargos=@pmOtrosCargos,OtrosDctos=@pmOtrosDctos,ValorTotal=@pmValorTotal,BaseRet=@pmBaseRet,BaseBom=@pmBaseBom,CodRes=@pmCodRes,DescServicio=@pmDescServicio,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos
,TipDocRef=@pmTipDocRef,NumDocRef=@pmNumDocRef,IdCiaRef=@pmIdCiaRef,NitCueProv=@pmNitCueProv,CodCueProv=@pmCodCueProv,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion,VrOtrosImpu=@pmVrOtrosImpu
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpDocSoporte]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpDocSoporte] @pmTipDoc VARCHAR(3),@pmNumDoc INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmIdAdquiriente VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmIdMedPago VARCHAR(4),@pmMetPago INT,@pmModalidad VARCHAR(20),@pmNumFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmBomberil DECIMAL(16,6),@pmImpAviTab DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmBaseRet DECIMAL(16,6),@pmBaseBom DECIMAL(16,6),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaBom DECIMAL(14,4),@pmTarifaAvta DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarifBom VARCHAR(4),@pmCodTarifAvta VARCHAR(4),@pmDescServicio VARCHAR(500),@pmCodRes VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmAnulado BIT,@pmTipDocDev VARCHAR(3),@pmNumDev INT,@pmCdCiaDev CHAR(2),@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmIdEstado VARCHAR(4),@pmCodCueProv VARCHAR(16),@pmNitCueProv VARCHAR(16),@pmVrOtrosImpu DECIMAL(16,6),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_DocSoporte SET Fecha=@pmFecha,IdTercero=@pmIdTercero,IdAdquiriente=@pmIdAdquiriente,IdConcepto=@pmIdConcepto,IdMedPago=@pmIdMedPago,MetPago=@pmMetPago,Modalidad=@pmModalidad,NumFactura=@pmNumFactura,FechaFac=@pmFechaFac,FechaVence=@pmFechaVence,SubTotal=@pmSubTotal,Descuento=@pmDescuento,Retencion=@pmRetencion,ReteIca=@pmReteIca,Bomberil=@pmBomberil,ImpAviTab=@pmImpAviTab,OtrosCargos=@pmOtrosCargos,OtrosDctos=@pmOtrosDctos,ValorTotal=@pmValorTotal,BaseRet=@pmBaseRet,BaseBom=@pmBaseBom,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaBom=@pmTarifaBom,TarifaAvta=@pmTarifaAvta,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarifBom=@pmCodTarifBom,CodTarifAvta=@pmCodTarifAvta,DescServicio=@pmDescServicio,CodRes=@pmCodRes,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,TipDocRef=@pmTipDocRef,NumDocRef=@pmNumDocRef,IdCiaRef=@pmIdCiaRef,Anulado=@pmAnulado,TipDocDev=@pmTipDocDev,NumDev=@pmNumDev,CdCiaDev=@pmCdCiaDev
,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CodCueProv=@pmCodCueProv,NitCueProv=@pmNitCueProv,VrOtrosImpu=@pmVrOtrosImpu,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumDoc=@pmNumDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCalibra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsCalibra] @pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNitTercero VARCHAR(16),@pmCdJornada VARCHAR(4),@pmVrSubTotal MONEY
,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4)
,@pmCodTarCom VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_EdsCalibra SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,NitTercero=@pmNitTercero,CdJornada=@pmCdJornada,VrSubTotal=@pmVrSubTotal,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal
,VrOtros=@pmVrOtros,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,IdCajero=@pmIdCajero,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,IdCCosto=@pmIdCCosto
,IdSubCos=@pmIdSubCos,Referencia=@pmReferencia,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev
,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND nNota=@pmnNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCalibraDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsCalibraDev] @pmTipDoc VARCHAR(3),@pmnNota INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_EdsCalibra SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND nNota=@pmnNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCortes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsCortes] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNitTercero VARCHAR(16),@pmIdJornada VARCHAR(4),@pmVrSubTotal MONEY
,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrOtros MONEY,@pmVrSobrantes MONEY,@pmVrFaltantes MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrCreditos MONEY,@pmVrGastComb MONEY
,@pmVrGastOtros MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4),@pmVrConTotal MONEY,@pmVrConImp MONEY,@pmVrConDcto MONEY,@pmVrConCos MONEY,@pmConCant DECIMAL(14,4),@pmVrCreTotal MONEY,@pmVrCreImp MONEY
,@pmVrCreDcto MONEY,@pmVrCreCos MONEY,@pmCreCant DECIMAL(14,4),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitRef VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmReferencia VARCHAR(50),@pmModalidad VARCHAR(10),@pmFecCorte SMALLDATETIME,@pmNumCorte INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoInt VARCHAR(10),@pmVrDctoClie MONEY,@pmNumTurno INT,@pmVrExcedClie MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_EdsCortes SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,NitTercero=@pmNitTercero,IdJornada=@pmIdJornada,VrSubTotal=@pmVrSubTotal,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrOtros=@pmVrOtros,VrSobrantes=@pmVrSobrantes
,VrFaltantes=@pmVrFaltantes,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,VrEfectivo=@pmVrEfectivo,VrCreditos=@pmVrCreditos,VrGastComb=@pmVrGastComb,VrGastOtros=@pmVrGastOtros,VrPagosOtr=@pmVrPagosOtr,Cantidad=@pmCantidad,VrConTotal=@pmVrConTotal
,VrConImp=@pmVrConImp,VrConDcto=@pmVrConDcto,VrConCos=@pmVrConCos,ConCant=@pmConCant,VrCreTotal=@pmVrCreTotal,VrCreImp=@pmVrCreImp,VrCreDcto=@pmVrCreDcto,VrCreCos=@pmVrCreCos,CreCant=@pmCreCant,IdCajero=@pmIdCajero,IdVend=@pmIdVend
,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Referencia=@pmReferencia,Modalidad=@pmModalidad,FecCorte=@pmFecCorte,NumCorte=@pmNumCorte,NitRef=@pmNitRef
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipoInt=@pmTipoInt,VrDctoClie=@pmVrDctoClie,NumTurno=@pmNumTurno,VrExcedClie=@pmVrExcedClie
 WHERE TipDoc=@pmTipDoc AND Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsCortesDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEdsCortesDev] @pmTipDoc VARCHAR(3),@pmPlanilla INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_EdsCortes SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEdsFormas] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT,@pmPlanilla INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmVrTotal MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdCuenta VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmnVehiculo VARCHAR(10),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmCdProducto VARCHAR(16)
,@pmCantidad DECIMAL(14,4),@pmIdForma VARCHAR(4),@pmItem INT,@pmReferencia VARCHAR(50),@pmCantPuntos DECIMAL(14,4),@pmObservacion VARCHAR(150),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmFechaDcm SMALLDATETIME,@pmAgencDcm VARCHAR(16),@pmAnulado BIT
,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmVrPrecio MONEY,@pmNumRef2 VARCHAR(50),@pmVrBase MONEY,@pmVrPrecioEsp MONEY
 AS 
 UPDATE Trn_EdsFormas SET Planilla=@pmPlanilla,IdCia=@pmIdCia,Fecha=@pmFecha,VrTotal=@pmVrTotal,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdCuenta=@pmIdCuenta,pVehiculo=@pmpVehiculo,nVehiculo=@pmnVehiculo,IdCajero=@pmIdCajero,IdVend=@pmIdVend,CdProducto=@pmCdProducto,Cantidad=@pmCantidad,IdForma=@pmIdForma,Item=@pmItem,Referencia=@pmReferencia,CantPuntos=@pmCantPuntos
,Observacion=@pmObservacion,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,FechaDcm=@pmFechaDcm,AgencDcm=@pmAgencDcm,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,VrPrecio=@pmVrPrecio,NumRef2=@pmNumRef2,VrBase=@pmVrBase,VrPrecioEsp=@pmVrPrecioEsp
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEdsFormasAnu] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_EdsFormas SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango 
AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasDfa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEdsFormasDfa]  @pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2)
 AS 
 UPDATE Trn_EdsFormas SET  TipDcm='0',Documento=0,IdCiaDcm='00'
 WHERE  TipDcm=@pmTipDcm AND Documento=@pmDocumento AND IdCiaDcm=@pmIdCiaDcm
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEdsFormasFac] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT
,@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmFechaDcm SMALLDATETIME,@pmAgencDcm VARCHAR(16)
 AS 
 UPDATE Trn_EdsFormas SET TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,FechaDcm=@pmFechaDcm,AgencDcm=@pmAgencDcm
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsFormasPla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEdsFormasPla] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT,@pmPlanilla INT,@pmIdCia CHAR(2),@pmVrTotal MONEY,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmIdCuenta VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmnVehiculo VARCHAR(10),@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmCdProducto VARCHAR(16),@pmCantidad DECIMAL(14,4)
,@pmIdForma VARCHAR(4),@pmReferencia VARCHAR(50),@pmCantPuntos DECIMAL(14,4),@pmObservacion VARCHAR(150),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmNumRef2 VARCHAR(50),@pmVrBase MONEY,@pmVrPrecioEsp MONEY,@pmVrPrecio MONEY
 AS 
 UPDATE Trn_EdsFormas SET VrTotal=@pmVrTotal,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdCuenta=@pmIdCuenta,pVehiculo=@pmpVehiculo,nVehiculo=@pmnVehiculo,IdCajero=@pmIdCajero
,IdVend=@pmIdVend,CdProducto=@pmCdProducto,Cantidad=@pmCantidad,IdForma=@pmIdForma,Referencia=@pmReferencia,CantPuntos=@pmCantPuntos,Observacion=@pmObservacion,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos
,NumRef2=@pmNumRef2,VrBase=@pmVrBase,VrPrecioEsp=@pmVrPrecioEsp,VrPrecio=@pmVrPrecio
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
 AND  Planilla=@pmPlanilla AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsRangos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsRangos] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmIdForma VARCHAR(4),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmnVehiculo VARCHAR(10),@pmIdCuenta VARCHAR(16),@pmNumSerie VARCHAR(5),@pmNumInicial INT,@pmNumFinal INT,@pmNumTarjeta VARCHAR(30)
,@pmVrCupo MONEY,@pmVrConsumos MONEY,@pmTipoConsumo INT,@pmReqPlaca BIT,@pmReqProd BIT,@pmReqGalones BIT,@pmVldAgencia BIT,@pmVldPlaca VARCHAR(10),@pmModalidad VARCHAR(10)
,@pmAnulado BIT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmNumAuto BIT,@pmNumActual INT,@pmCod_CCosto VARCHAR(16),@pmCod_SubCosto VARCHAR(16),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_EdsRangos SET IdForma=@pmIdForma,Fecha=@pmFecha,FecVence=@pmFecVence,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,pVehiculo=@pmpVehiculo,nVehiculo=@pmnVehiculo
,IdCuenta=@pmIdCuenta,NumSerie=@pmNumSerie,NumInicial=@pmNumInicial,NumFinal=@pmNumFinal,NumTarjeta=@pmNumTarjeta,VrCupo=@pmVrCupo,VrConsumos=@pmVrConsumos,TipoConsumo=@pmTipoConsumo
,ReqPlaca=@pmReqPlaca,ReqProd=@pmReqProd,ReqGalones=@pmReqGalones,VldAgencia=@pmVldAgencia,VldPlaca=@pmVldPlaca,Modalidad=@pmModalidad,Anulado=@pmAnulado,Observacion=@pmObservacion
,IdEstado=@pmIdEstado,NumAuto=@pmNumAuto,NumActual=@pmNumActual,Cod_CCosto=@pmCod_CCosto,Cod_SubCosto=@pmCod_SubCosto,FecUpdate=@pmFecUpdate
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsRangosCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsRangosCon] @pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumActual INT
 AS 
 UPDATE Trn_EdsRangos SET  NumActual=@pmNumActual
 WHERE TipoRango=@pmTipoRango AND IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsServicio]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsServicio] @pmIdEstacion VARCHAR(4),@pmEstServicio VARCHAR(50),@pmDireccion VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE EdsServicio SET EstServicio=@pmEstServicio,Direccion=@pmDireccion,Inactivo=@pmInactivo
 WHERE IdEstacion=@pmIdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paUpEdsUnion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEdsUnion] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmCdTanque VARCHAR(4),@pmCapacidad DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmNivAgua DECIMAL(14,4)
,@pmTipoTrasl VARCHAR(3),@pmNumTraslado INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_EdsUnion SET Fecha=@pmFecha,CdTanque=@pmCdTanque,Capacidad=@pmCapacidad,Cantidad=@pmCantidad,NivAgua=@pmNivAgua,TipoTrasl=@pmTipoTrasl,NumTraslado=@pmNumTraslado
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEgrAnticipoApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEgrAnticipoApl] @pmIdTercero VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null,@pmTipCom VARCHAR(3)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
  UPDATE Trn_EgrAnticipo SET Trn_EgrAnticipo.VrAplicado=(SELECT ISNULL(SUM(Trn_EgrAntAbonos.VrAbonado),0)
  FROM Trn_EgrAntAbonos WHERE Trn_EgrAnticipo.TipCom=Trn_EgrAntAbonos.TipCan AND Trn_EgrAnticipo.Comprobante=Trn_EgrAntAbonos.nAnticipo
  AND Trn_EgrAnticipo.IdCia=Trn_EgrAntAbonos.IdCiaAnt AND Trn_EgrAnticipo.Item=Trn_EgrAntAbonos.ItemAnt)
  WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  TipCom LIKE ISNULL(@pmTipCom,'%') 
 ELSE
  UPDATE Trn_EgrAnticipo SET Trn_EgrAnticipo.VrAplicado=(SELECT ISNULL(SUM(Trn_EgrAntAbonos.VrAbonado),0)
  FROM Trn_EgrAntAbonos WHERE Trn_EgrAnticipo.TipCom=Trn_EgrAntAbonos.TipCan AND Trn_EgrAnticipo.Comprobante=Trn_EgrAntAbonos.nAnticipo
  AND Trn_EgrAnticipo.IdCia=Trn_EgrAntAbonos.IdCiaAnt AND Trn_EgrAnticipo.Item=Trn_EgrAntAbonos.ItemAnt)
  WHERE IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
  AND  TipCom LIKE ISNULL(@pmTipCom,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpEgrAnticipoCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEgrAnticipoCero] @pmIdTercero VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmTipCom VARCHAR(3)=Null,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
 UPDATE Trn_EgrAnticipo  SET  VrAplicado=0
 WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND IdTercero LIKE ISNULL(@pmIdTercero,'%') 
  AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')  AND  TipCom LIKE ISNULL(@pmTipCom,'%')
 ELSE
 UPDATE Trn_EgrAnticipo  SET  VrAplicado=0
 WHERE IdTercero LIKE ISNULL(@pmIdTercero,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%') 
 AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%') AND TipCom LIKE ISNULL(@pmTipCom,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpEgrFactura]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEgrFactura] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipFac VARCHAR(3),@pmFactura VARCHAR(15),@pmIdCiaFac CHAR(2),@pmItemFac INT,@pmIdProveedor VARCHAR(16),@pmIdCuenta VARCHAR(16)
,@pmVrAbono MONEY,@pmEsEgreso BIT,@pmItemCom INT,@pmpVehiculo VARCHAR(10),@pmVehPropio BIT,@pmTipDev VARCHAR(3),@pmNumDev INT,@pmDetAbono VARCHAR(100)
 AS 
 UPDATE Trn_EgrFactura SET Fecha=@pmFecha,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,ItemFac=@pmItemFac,IdProveedor=@pmIdProveedor,IdCuenta=@pmIdCuenta,VrAbono=@pmVrAbono,EsEgreso=@pmEsEgreso
,ItemCom=@pmItemCom,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio,TipDev=@pmTipDev,NumDev=@pmNumDev,DetAbono=@pmDetAbono
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_Contrato]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEmp_Contrato] @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmIndefinido BIT,@pmIdCargo VARCHAR(4),@pmIdJornada VARCHAR(4),@pmIdDep VARCHAR(4),@pmIdArea VARCHAR(4),@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdCia CHAR(2),@pmIdNom VARCHAR(4),@pmTipoLiquida CHAR(1),@pmModPromdio CHAR(1),@pmVrSalario MONEY,@pmVrAuxTrans MONEY,@pmSalMinimo BIT,@pmSalIntegral BIT,@pmFPnomina VARCHAR(10),@pmModoRet INT,@pmFecAfiSeg SMALLDATETIME,@pmATFinMes BIT,@pmSegFinMes BIT,@pmDenyPEN BIT,@pmDenyEPS BIT,@pmDenyARP BIT,@pmDenyCaj BIT,@pmDenyCes BIT,@pmDenyPri BIT
,@pmDenyVac BIT,@pmDenyHex BIT,@pmBasePrest CHAR(2),@pmBaseSeg CHAR(2),@pmDchDotacion BIT,@pmDchCafeteria BIT,@pmReclmto VARCHAR(50),@pmNotas VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmIdClase VARCHAR(4),@pmTipoTrabj INT,@pmIdCot VARCHAR(4),@pmVrUpc MONEY,@pmIdGrupo VARCHAR(4),@pmDenyDcto BIT,@pmSubTipoCot VARCHAR(3),@pmDsoSabado BIT
,@pmFspFinmes BIT,@pmFecFinPrueba SMALLDATETIME,@pmTipoPrendDot VARCHAR(10),@pmTipoMedSent VARCHAR(4),@pmBenefPacto VARCHAR(100),@pmTipoTraspaso INT,@pmFechaTraspaso SMALLDATETIME,@pmContratoRef INT,@pmIdMedPago VARCHAR(4),@pmIdActEco VARCHAR(10),@pmIdConvCT INT,@pmCodGrupoCT VARCHAR(4),@pmCodBaseCT VARCHAR(4),@pmCodEscfon VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Emp_Contrato SET IdEmpleado=@pmIdEmpleado,IdTipCon=@pmIdTipCon,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,Indefinido=@pmIndefinido,IdCargo=@pmIdCargo,IdJornada=@pmIdJornada,IdDep=@pmIdDep,IdArea=@pmIdArea,IdInstala=@pmIdInstala,IdCCosto=@pmIdCCosto,IdCia=@pmIdCia,IdNom=@pmIdNom,TipoLiquida=@pmTipoLiquida,ModPromdio=@pmModPromdio
,VrSalario=@pmVrSalario,VrAuxTrans=@pmVrAuxTrans,SalMinimo=@pmSalMinimo,SalIntegral=@pmSalIntegral,FPnomina=@pmFPnomina,ModoRet=@pmModoRet,FecAfiSeg=@pmFecAfiSeg,ATFinMes=@pmATFinMes,SegFinMes=@pmSegFinMes,DenyPEN=@pmDenyPEN,DenyEPS=@pmDenyEPS,DenyARP=@pmDenyARP,DenyCaj=@pmDenyCaj,DenyCes=@pmDenyCes,DenyPri=@pmDenyPri,DenyVac=@pmDenyVac,DenyHex=@pmDenyHex
,BasePrest=@pmBasePrest,BaseSeg=@pmBaseSeg,DchDotacion=@pmDchDotacion,DchCafeteria=@pmDchCafeteria,Reclmto=@pmReclmto,Notas=@pmNotas,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate,IdSubCos=@pmIdSubCos,IdClase=@pmIdClase,TipoTrabj=@pmTipoTrabj ,IdCot=@pmIdCot,VrUpc=@pmVrUpc,IdGrupo=@pmIdGrupo,DenyDcto=@pmDenyDcto,SubTipoCot =@pmSubTipoCot
,DsoSabado=@pmDsoSabado,FspFinmes=@pmFspFinmes,FecFinPrueba=@pmFecFinPrueba,TipoPrendDot=@pmTipoPrendDot,TipoMedSent=@pmTipoMedSent,BenefPacto=@pmBenefPacto,TipoTraspaso=@pmTipoTraspaso,FechaTraspaso=@pmFechaTraspaso,ContratoRef=@pmContratoRef,IdMedPago=@pmIdMedPago,IdActEco=@pmIdActEco,IdConvCT=@pmIdConvCT,CodGrupoCT=@pmCodGrupoCT,CodBaseCT=@pmCodBaseCT,CodEscfon=@pmCodEscfon
 WHERE NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoAre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ContratoAre] @pmIdArea VARCHAR(4),@pmIdDep VARCHAR(4)
 AS 
 UPDATE Emp_Contrato SET IdArea=@pmIdArea
 WHERE IdDep=@pmIdDep
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoAum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ContratoAum] @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmVrSalario MONEY,@pmVrAuxTrans MONEY,@pmSalMinimo BIT
,@pmFecUltAum SMALLDATETIME,@pmFecUpdate SMALLDATETIME
 AS 
 BEGIN
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnContrato'
 BEGIN TRANSACTION @TrnNombre
 UPDATE Emp_Contrato SET VrSalario=@pmVrSalario,VrAuxTrans=@pmVrAuxTrans,SalMinimo=@pmSalMinimo,FecUpdate=@pmFecUpdate
 WHERE NContrato=@pmNContrato AND IdEmpleado=@pmIdEmpleado
 UPDATE Empleados SET FecUltAum=@pmFecUltAum WHERE  IdEmpleado=@pmIdEmpleado
 COMMIT TRANSACTION  @TrnNombre
 END
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ContratoCc]  @pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
 AS 
 UPDATE Emp_Contrato SET IdCCosto=@pmIdCCosto
 WHERE IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoIns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ContratoIns] @pmNContrato INT,@pmIdEmpleado VARCHAR(16),@pmIdInstala VARCHAR(4),@pmIdClase VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Emp_Contrato SET IdInstala=@pmIdInstala,IdClase=@pmIdClase,FecUpdate=@pmFecUpdate
 WHERE NContrato=@pmNContrato AND IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ContratoRet] @pmNContrato INT,@pmFecRetiro SMALLDATETIME,@pmIdEstado VARCHAR(4)
,@pmInactivo BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Emp_Contrato SET FecRetiro=@pmFecRetiro,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate
 WHERE NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ContratoTlq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ContratoTlq] @pmIdNom VARCHAR(4),@pmTipoLiquida CHAR(1)
 AS 
 UPDATE Emp_Contrato SET TipoLiquida=@pmTipoLiquida
 WHERE IdNom=@pmIdNom
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_Estudios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_Estudios] @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEstblecmto VARCHAR(50)
,@pmTitulo VARCHAR(50),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdClase VARCHAR(4),@pmHabilitado BIT
 AS 
 UPDATE Emp_Estudios SET Estblecmto=@pmEstblecmto,Titulo=@pmTitulo,Fecha=@pmFecha,FecVence=@pmFecVence
 ,IdClase=@pmIdClase,Habilitado=@pmHabilitado
 WHERE IdEmpleado=@pmIdEmpleado AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_ExpLaboral]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmp_ExpLaboral] @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmEmpresa VARCHAR(50),@pmCargo VARCHAR(20)
,@pmFecInicio SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmDirEmpresa VARCHAR(100),@pmTelEmpresa VARCHAR(20)
 AS 
 UPDATE Emp_ExpLaboral SET Empresa=@pmEmpresa,Cargo=@pmCargo,FecInicio=@pmFecInicio,FecRetiro=@pmFecRetiro,DirEmpresa=@pmDirEmpresa,TelEmpresa=@pmTelEmpresa
 WHERE IdEmpleado=@pmIdEmpleado AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpEmp_Parientes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEmp_Parientes] @pmIdEmpleado VARCHAR(16),@pmItem INT,@pmParntsco VARCHAR(10),@pmNombre VARCHAR(50)
,@pmFecNacmto SMALLDATETIME,@pmUltGrado VARCHAR(20),@pmDirccion VARCHAR(100),@pmTelefno VARCHAR(20),@pmTipoRef VARCHAR(10),@pmNitRef VARCHAR(16)
,@pmEmailRef VARCHAR(100),@pmCargoRef VARCHAR(50)
 AS 
 UPDATE Emp_Parientes SET Parntsco=@pmParntsco,Nombre=@pmNombre,FecNacmto=@pmFecNacmto,UltGrado=@pmUltGrado,Dirccion=@pmDirccion,Telefno=@pmTelefno
,TipoRef=@pmTipoRef,NitRef=@pmNitRef,EmailRef=@pmEmailRef,CargoRef=@pmCargoRef
 WHERE IdEmpleado=@pmIdEmpleado AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpaques]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEmpaques] @pmIdEmp VARCHAR(4),@pmEmpaque VARCHAR(50)
,@pmCodMintra VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Empaques SET Empaque=@pmEmpaque,CodMintra=@pmCodMintra,Inactivo=@pmInactivo
 WHERE IdEmp=@pmIdEmp
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEmpleados] @pmIdEmpleado VARCHAR(16),@pmApellidos VARCHAR(80),@pmNombres VARCHAR(70),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmIdLugarCed VARCHAR(8),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmTelMovil VARCHAR(20),@pme_mail VARCHAR(100),@pmVvdaPropia BIT,@pmFecNacmto SMALLDATETIME,@pmLugarNacmto VARCHAR(30),@pmTipoSangre CHAR(2),@pmFactorRh CHAR(1),@pmSexo CHAR(1)
,@pmIdEstCivil VARCHAR(4),@pmNHijos INT,@pmLibMilitar VARCHAR(25),@pmClaseLib INT,@pmFechaLib SMALLDATETIME,@pmDistMil VARCHAR(10),@pmCertJudicial VARCHAR(25),@pmFecJudicial SMALLDATETIME,@pmVigJudicial SMALLDATETIME,@pmPasporte VARCHAR(25),@pmVigPaspte SMALLDATETIME,@pmLicencia VARCHAR(25),@pmIdLugar VARCHAR(8),@pmCatLicencia INT,@pmFecLicencia SMALLDATETIME,@pmVigLicencia SMALLDATETIME,@pmIdProf VARCHAR(4),@pmTallaCam VARCHAR(5)
,@pmTallaPan VARCHAR(5),@pmTallaZap VARCHAR(5),@pmUsaGafas BIT,@pmConyugue VARCHAR(50),@pmConyFecNac SMALLDATETIME,@pmConyTrabaja BIT,@pmConyEmpresa VARCHAR(50),@pmConyCargo VARCHAR(20),@pmConyFing SMALLDATETIME,@pmConyTel VARCHAR(20),@pmIdFonPen VARCHAR(8),@pmIdFonEps VARCHAR(8),@pmIdFonArp VARCHAR(8),@pmIdFonCes VARCHAR(8),@pmIdCajaCom VARCHAR(8),@pmCdFonAvp VARCHAR(8),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(25),@pmIdBanco VARCHAR(4),@pmNContrato INT,@pmFecVincula SMALLDATETIME
,@pmFecUltAum SMALLDATETIME,@pmFecUltCes SMALLDATETIME,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME,@pmFecUltDot SMALLDATETIME,@pmFecUltExm SMALLDATETIME,@pmFecUltCap SMALLDATETIME,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME,@pmFecRetAnt SMALLDATETIME,@pmFotoEmp VARCHAR(30),@pmFotoLic VARCHAR(30),@pmFotoFirma VARCHAR(30),@pmEsCondtor BIT,@pmpVehiculo VARCHAR(10)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCdLocCue VARCHAR(8),@pmFecUltParc SMALLDATETIME,@pmDecRenta INT,@pmNivelEduc VARCHAR(4),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET Apellidos=@pmApellidos,Nombres=@pmNombres,Codigo=@pmCodigo,TipoId=@pmTipoId,Dv=@pmDv,IdLugarCed=@pmIdLugarCed,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,TelMovil=@pmTelMovil,e_mail=@pme_mail,VvdaPropia=@pmVvdaPropia,FecNacmto=@pmFecNacmto,LugarNacmto=@pmLugarNacmto,TipoSangre=@pmTipoSangre,FactorRh=@pmFactorRh,Sexo=@pmSexo,IdEstCivil=@pmIdEstCivil,NHijos=@pmNHijos,LibMilitar=@pmLibMilitar,ClaseLib=@pmClaseLib,FechaLib=@pmFechaLib,DistMil=@pmDistMil
,CertJudicial=@pmCertJudicial,FecJudicial=@pmFecJudicial,VigJudicial=@pmVigJudicial,Pasporte=@pmPasporte,VigPaspte=@pmVigPaspte,Licencia=@pmLicencia,IdLugar=@pmIdLugar,CatLicencia=@pmCatLicencia,FecLicencia=@pmFecLicencia,VigLicencia=@pmVigLicencia,IdProf=@pmIdProf,TallaCam=@pmTallaCam,TallaPan=@pmTallaPan,TallaZap=@pmTallaZap,UsaGafas=@pmUsaGafas,Conyugue=@pmConyugue,ConyFecNac=@pmConyFecNac,ConyTrabaja=@pmConyTrabaja,ConyEmpresa=@pmConyEmpresa,ConyCargo=@pmConyCargo,FecVincula=@pmFecVincula
,ConyFing=@pmConyFing,ConyTel=@pmConyTel,IdFonPen=@pmIdFonPen,IdFonEps=@pmIdFonEps,IdFonArp=@pmIdFonArp,IdFonCes=@pmIdFonCes,IdCajaCom=@pmIdCajaCom,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,NContrato=@pmNContrato,FecUltAum=@pmFecUltAum,FecUltCes=@pmFecUltCes,FecUltPri=@pmFecUltPri,FecUltVac=@pmFecUltVac,FecUltIng=@pmFecUltIng,FecUltRet=@pmFecUltRet,FecUltDot=@pmFecUltDot,FecUltExm=@pmFecUltExm,FecUltCap=@pmFecUltCap,FotoEmp=@pmFotoEmp,CdFonAvp=@pmCdFonAvp
,NCAnterior=@pmNCAnterior, FotoLic=@pmFotoLic,FotoFirma=@pmFotoFirma,pVehiculo=@pmpVehiculo,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,EsCondtor=@pmEsCondtor,FecIngAnt=@pmFecIngAnt,FecRetAnt=@pmFecRetAnt,CdLocCue=@pmCdLocCue,FecUltParc=@pmFecUltParc,DecRenta=@pmDecRenta,FechaUpdate=@pmFechaUpdate,NivelEduc=@pmNivelEduc
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmpleadosCon] @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmFecVincula SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET NContrato=@pmNContrato,FecUltIng=@pmFecUltIng,FecUltRet=@pmFecUltRet
,IdEstado=@pmIdEstado,FecVincula=@pmFecVincula,FechaUpdate=@pmFechaUpdate
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosFon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmpleadosFon] @pmIdEmpleado VARCHAR(16),@pmTipo VARCHAR(3),@pmIdFondo VARCHAR(8),@pmFechaUpdate SMALLDATETIME
AS
IF @pmTipo='PEN'
 UPDATE Empleados SET IdFonPen=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='EPS'
 UPDATE Empleados SET IdFonEps=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='ARP' or @pmTipo='APR'
 UPDATE Empleados SET IdFonArp=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='CES'
 UPDATE Empleados SET IdFonCes=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
IF @pmTipo='COM'
 UPDATE Empleados SET IdCajaCom=@pmIdFondo,FechaUpdate=@pmFechaUpdate WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosFul]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmpleadosFul] @pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='VAC'
  UPDATE Empleados SET FecUltVac=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='PRI'
  UPDATE Empleados SET FecUltPri=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='CES'
  UPDATE Empleados SET FecUltCes=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='SAL'
  UPDATE Empleados SET FecUltAum=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='DOT'
  UPDATE Empleados SET FecUltDot=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='EXM'
  UPDATE Empleados SET FecUltExm=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='CAP'
  UPDATE Empleados SET FecUltCap=@pmFecha  WHERE IdEmpleado=@pmIdEmpleado
 IF @pmTipo='RET'
   UPDATE Empleados SET FecUltCes=@pmFecha,FecUltPri=@pmFecha,FecUltVac=@pmFecha WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmpleadosRet] @pmIdEmpleado VARCHAR(16),@pmFecUltRet SMALLDATETIME,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME
,@pmFecRetAnt SMALLDATETIME,@pmFecUltCes SMALLDATETIME,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME
 AS 
 UPDATE Empleados SET FecUltRet=@pmFecUltRet,NCAnterior=@pmNCAnterior,FecIngAnt=@pmFecIngAnt,FecRetAnt=@pmFecRetAnt
,FecUltCes=@pmFecUltCes,FecUltPri=@pmFecUltPri,FecUltVac=@pmFecUltVac,Inactivo=1,IdEstado='9999'
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosRint]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmpleadosRint] @pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecUltIng SMALLDATETIME,@pmFecUltRet SMALLDATETIME
,@pmNCAnterior INT,@pmFecIngAnt SMALLDATETIME,@pmFecRetAnt SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmFecUltCes SMALLDATETIME
,@pmFecUltPri SMALLDATETIME,@pmFecUltVac SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET NContrato=@pmNContrato,FecUltIng=@pmFecUltIng,FecUltRet=@pmFecUltRet,NCAnterior=@pmNCAnterior,FecIngAnt=@pmFecIngAnt
,FecRetAnt=@pmFecRetAnt,IdEstado=@pmIdEstado,FecUltCes=@pmFecUltCes,FecUltPri=@pmFecUltPri,FecUltVac=@pmFecUltVac,FechaUpdate=@pmFechaUpdate
,Inactivo=0
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEmpleadosVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEmpleadosVeh] @pmIdEmpleado VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Empleados SET pVehiculo=@pmpVehiculo,FechaUpdate=@pmFechaUpdate
 WHERE IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosDve]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEntArticulosDve] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmSalidas DECIMAL(14,4)
 AS 
 UPDATE Trn_EntArticulos SET Salidas=Salidas+@pmSalidas
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosDvs]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEntArticulosDvs] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmIdProducto VARCHAR(16),@pmSalidas DECIMAL(14,4)
 AS 
 UPDATE Trn_EntArticulos SET Salidas=Salidas-@pmSalidas
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
  AND Item=@pmItem AND IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosDvsp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEntArticulosDvsp] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmSalidas DECIMAL(14,4)
 AS 
 UPDATE Trn_EntArticulos SET Salidas=Salidas-@pmSalidas
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
  AND IdProducto=@pmIdProducto AND IdBodega=@pmIdBodega
GO
/****** Object:  StoredProcedure [dbo].[paUpEntArticulosSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEntArticulosSal] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmIdProducto VARCHAR(16),@pmSalidas DECIMAL(14,4),@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2)
 AS 
 UPDATE Trn_EntArticulos SET Salidas=@pmSalidas,TipSal=@pmTipSal,NumSalida=@pmNumSalida,IdCiaSal=@pmIdCiaSal
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia AND Item=@pmItem
 AND IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paUpEntidades]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEntidades] @pmIdTabla VARCHAR(20),@pmNivelRel INT,@pmCamposPK VARCHAR(50),@pmFngKey BIT,@pmSp_Qry VARCHAR(30),@pmSp_Qpmt VARCHAR(50),@pmSp_Ins VARCHAR(30)
,@pmSp_Upd VARCHAR(30),@pmSp_Del VARCHAR(30)
 AS 
 UPDATE Sys_Entidades SET NivelRel=@pmNivelRel,CamposPK=@pmCamposPK,FngKey=@pmFngKey,Sp_Qry=@pmSp_Qry,Sp_Qpmt=@pmSp_Qpmt,Sp_Ins=@pmSp_Ins,Sp_Upd=@pmSp_Upd,Sp_Del=@pmSp_Del
 WHERE IdTabla=@pmIdTabla
GO
/****** Object:  StoredProcedure [dbo].[paUpEntradas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEntradas] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY
,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmNitFletes VARCHAR(16),@pmTipOdc VARCHAR(3),@pmOCompra INT,@pmIdCiaOdc CHAR(2)
,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmDocEquiv VARCHAR(3),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4)
,@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrRetFlete MONEY,@pmVrIcaFlete MONEY,@pmCodTarRetFle VARCHAR(4),@pmCodTarIcaFle VARCHAR(4),@pmFletesCosto BIT,@pmVrIvaMvc MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4)
,@pmCodTarifBom VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmTipoSA VARCHAR(3),@pmNumSalAlm INT,@pmCdCiaSA CHAR(2),@pmVrImpuCons MONEY,@pmVrSobtasaCons MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY
,@pmTipSop VARCHAR(3),@pmNumDocSop INT,@pmCdCiaSop CHAR(2),@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Entradas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdProv=@pmIdProv,Factura=@pmFactura,FechaFac=@pmFechaFac,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes
,VrOtros=@pmVrOtros,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,NitFletes=@pmNitFletes,TipOdc=@pmTipOdc,OCompra=@pmOCompra,IdCiaOdc=@pmIdCiaOdc,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CxPagar=@pmCxPagar,DocEquiv=@pmDocEquiv
,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,TipEgr=@pmTipEgr
,Egreso=@pmEgreso,IdCiaEgr=@pmIdCiaEgr,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,VrRetFlete=@pmVrRetFlete,VrIcaFlete=@pmVrIcaFlete,CodTarRetFle=@pmCodTarRetFle,CodTarIcaFle=@pmCodTarIcaFle,FletesCosto=@pmFletesCosto,VrIvaMvc=@pmVrIvaMvc,FecUpdate=@pmFecUpdate,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,CodTarifBom=@pmCodTarifBom,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom
,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,VrImpCarbono=@pmVrImpCarbono,TipoSA=@pmTipoSA,NumSalAlm=@pmNumSalAlm,CdCiaSA=@pmCdCiaSA,VrImpuCons=@pmVrImpuCons,VrSobtasaCons=@pmVrSobtasaCons,BaseIvaIgp=@pmBaseIvaIgp,VrIvaIngProd=@pmVrIvaIngProd,TipSop=@pmTipSop,NumDocSop=@pmNumDocSop,CdCiaSop=@pmCdCiaSop
,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,CodTarifAvta=@pmCodTarifAvta,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEntradasDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEntradasDev] @pmTipDoc VARCHAR(3),@pmEntrada INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmObservacion VARCHAR(250)
 AS 
 UPDATE Trn_Entradas SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Entrada=@pmEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpEstaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEstaciones] @pmIdEstacion CHAR(2),@pmEstacion VARCHAR(50)
 AS 
 UPDATE Sys_Estaciones SET Estacion=@pmEstacion
 WHERE IdEstacion=@pmIdEstacion
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoCiv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEstadoCiv] @pmIdEstado VARCHAR(4),@pmEstCivil VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE EstadoCiv SET EstCivil=@pmEstCivil,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEstadoDoc] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT
,@pmCodDcmto VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE EstadoDoc SET Estado=@pmEstado,NColor=@pmNColor,CodDcmto=@pmCodDcmto,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoGuia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEstadoGuia] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE EstadoGuia SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoOper]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEstadoOper] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE EstadoOper SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEstadoPro] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE EstadoPro SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoSer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpEstadoSer] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE EstadoSer SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoTer]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEstadoTer] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE EstadoTer SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstadoVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEstadoVeh] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmOutDemand BIT,@pmInactivo BIT
 AS 
 UPDATE EstadoVeh SET Estado=@pmEstado,NColor=@pmNColor,OutDemand=@pmOutDemand,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpEstratos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpEstratos] @pmIdEstrato VARCHAR(4),@pmEstrato VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE Estratos SET Estrato=@pmEstrato,Inactivo=@pmInactivo
 WHERE IdEstrato=@pmIdEstrato
GO
/****** Object:  StoredProcedure [dbo].[paUpExpLicencias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpExpLicencias] @pmIdLugar VARCHAR(8),@pmLugarLic VARCHAR(50)
,@pmCodDpto VARCHAR(8),@pmDpto VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE ExpLicencias SET LugarLic=@pmLugarLic,CodDpto=@pmCodDpto,Dpto=@pmDpto,Inactivo=@pmInactivo
 WHERE IdLugar=@pmIdLugar
GO
/****** Object:  StoredProcedure [dbo].[paUpFactcon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFactcon] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmnClieCon VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY
,@pmVrReteIVA MONEY,@pmVrFletes MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmVrEfectivo MONEY,@pmVrPagosOtr MONEY,@pmCantidad DECIMAL(14,4),@pmCantPuntos DECIMAL(14,4),@pmPuntosAcum DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY
,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCajero VARCHAR(11)
,@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmCdForma VARCHAR(4),@pmNumForma VARCHAR(20)
,@pmDetallePago VARCHAR(250),@pmReferncia1 VARCHAR(50),@pmReferncia2 VARCHAR(50),@pmCdBanco VARCHAR(4),@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFecPedido SMALLDATETIME,@pmModalidad VARCHAR(10)
,@pmPlacaVehic VARCHAR(10),@pmKmtVehic INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4)
,@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmTipoFE VARCHAR(3),@pmFechaFE SMALLDATETIME,@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Factcon SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,nClieCon=@pmnClieCon,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes,VrCargos=@pmVrCargos
,VrOtrDcto=@pmVrOtrDcto,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,VrEfectivo=@pmVrEfectivo,VrPagosOtr=@pmVrPagosOtr,Cantidad=@pmCantidad,CantPuntos=@pmCantPuntos,PuntosAcum=@pmPuntosAcum,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv
,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdCajero=@pmIdCajero,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom
,CodTarCom=@pmCodTarCom,NitCliente=@pmNitCliente,CdAgencia=@pmCdAgencia,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdLocal=@pmIdLocal,EnEfectivo=@pmEnEfectivo,CdForma=@pmCdForma,NumForma=@pmNumForma,DetallePago=@pmDetallePago,Referncia1=@pmReferncia1,Referncia2=@pmReferncia2
,TipPed=@pmTipPed,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,TipRem=@pmTipRem,Remision=@pmRemision,IdCiaRem=@pmIdCiaRem,FecPedido=@pmFecPedido,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado
,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CdBanco=@pmCdBanco,VrImpCons=@pmVrImpCons,FecUpdate=@pmFecUpdate
,PlacaVehic=@pmPlacaVehic,KmtVehic=@pmKmtVehic,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,TipoFE=@pmTipoFE,FechaFE=@pmFechaFE,CodTarArf=@pmCodTarArf,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte
,CodTarAri=@pmCodTarAri,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,CodTarifAvta=@pmCodTarifAvta,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,CodTarifBom=@pmCodTarifBom,VrAutRetIat=@pmVrAutRetIat,VrAutRetBom=@pmVrAutRetBom
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFactconDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFactconDev] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
AS
 UPDATE Trn_Factcon SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFacturas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFacturas] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrFletes MONEY
,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrCostos MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrFaltantes MONEY,@pmVrAnticipos MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmCantidad DECIMAL(14,4),@pmCantPuntos DECIMAL(14,4),@pmPuntosAcum DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4)
,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(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),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmpVehiculo VARCHAR(10)
,@pmCdConductor VARCHAR(16),@pmCdRuta VARCHAR(4),@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmTipCot VARCHAR(3),@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmFecPedido SMALLDATETIME,@pmAutzaMora INT,@pmAutzaCupo INT,@pmModalidad VARCHAR(10),@pmKmtVehic INT
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmPesoTotal DECIMAL(14,4),@pmUnidTotal DECIMAL(14,4),@pmVolTotal DECIMAL(14,4),@pmCantFalt DECIMAL(14,4),@pmVrCostoRem MONEY,@pmVrCostoAfi MONEY,@pmCodAutoRet VARCHAR(4)
,@pmVrImpCons MONEY,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmParqueadero BIT,@pmFecCuotaParq SMALLDATETIME,@pmBaseIvaObsq MONEY,@pmVrIvaObsequio MONEY,@pmVrImpCarbono MONEY,@pmTipoFE VARCHAR(3),@pmFechaFE SMALLDATETIME,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY
,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4),@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmVrAutRetIat MONEY,@pmVrAutRetBom MONEY,@pmTipoOperTra VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Facturas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrCostos=@pmVrCostos
,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrFaltantes=@pmVrFaltantes,VrAnticipos=@pmVrAnticipos,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado,Cantidad=@pmCantidad,CantPuntos=@pmCantPuntos,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva
,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,DirEnvio=@pmDirEnvio,IdLocEnv=@pmIdLocEnv,DiasEntraga=@pmDiasEntraga,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargoContac=@pmCargoContac
,IdForma=@pmIdForma,DetallePago=@pmDetallePago,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CdMney=@pmCdMney,NitEmpTrans=@pmNitEmpTrans,EmpTrans=@pmEmpTrans,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,CdRuta=@pmCdRuta,TipPed=@pmTipPed,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,TipRem=@pmTipRem,Remision=@pmRemision,IdCiaRem=@pmIdCiaRem,TipCot=@pmTipCot,Cotizacion=@pmCotizacion,IdCiaCot=@pmIdCiaCot
,FecPedido=@pmFecPedido,AutzaMora=@pmAutzaMora,AutzaCupo=@pmAutzaCupo,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,PuntosAcum=@pmPuntosAcum,KmtVehic=@pmKmtVehic,ZonaFrontera=@pmZonaFrontera,Parqueadero=@pmParqueadero,FecCuotaParq=@pmFecCuotaParq
,PesoTotal=@pmPesoTotal,UnidTotal=@pmUnidTotal,VolTotal=@pmVolTotal,CantFalt=@pmCantFalt,VrCostoRem=@pmVrCostoRem,VrCostoAfi=@pmVrCostoAfi,CodAutoRet=@pmCodAutoRet,VrImpCons=@pmVrImpCons,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,BaseIvaObsq=@pmBaseIvaObsq,VrIvaObsequio=@pmVrIvaObsequio,VrImpCarbono=@pmVrImpCarbono,TipoFE=@pmTipoFE,FechaFE=@pmFechaFE,BaseIvaIgp=@pmBaseIvaIgp,VrIvaIngProd=@pmVrIvaIngProd
,CodTarArf=@pmCodTarArf,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,CodTarAri=@pmCodTarAri,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,CodTarifAvta=@pmCodTarifAvta,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,CodTarifBom=@pmCodTarifBom,VrAutRetIat=@pmVrAutRetIat,VrAutRetBom=@pmVrAutRetBom,TipoOperTra=@pmTipoOperTra,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFacturasDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFacturasDev] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Facturas SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFcNotas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFcNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmVrNota MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY
,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmReferencia VARCHAR(50),@pmTipRec VARCHAR(3),@pmReciboFc INT,@pmIdCiaRec CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FcNotas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor,VehPropio=@pmVehPropio,VrNota=@pmVrNota,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos
,Referencia=@pmReferencia,TipRec=@pmTipRec,ReciboFc=@pmReciboFc,IdCiaRec=@pmIdCiaRec,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFcNotasDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFcNotasDev] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_FcNotas SET  Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFcSemanas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFcSemanas] @pmIdVehiculo VARCHAR(10),@pmnSemana INT,@pmNumCargue INT,@pmCiaCargue CHAR(2),@pmTipoSem INT,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrCargo MONEY,@pmVrOtros MONEY,@pmVrPagado MONEY
,@pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCiaRec CHAR(2),@pmFechaPago SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecSemIni SMALLDATETIME,@pmFecSemFin SMALLDATETIME
 AS 
 UPDATE Trn_FcSemanas SET NumCargue=@pmNumCargue,CiaCargue=@pmCiaCargue,TipoSem=@pmTipoSem,Fecha=@pmFecha,FecVence=@pmFecVence,VrCargo=@pmVrCargo,VrOtros=@pmVrOtros,VrPagado=@pmVrPagado
,TipRec=@pmTipRec,Recibo=@pmRecibo,IdCiaRec=@pmIdCiaRec,FechaPago=@pmFechaPago,Observacion=@pmObservacion,FecSemIni=@pmFecSemIni,FecSemFin=@pmFecSemFin
 WHERE IdVehiculo=@pmIdVehiculo AND nSemana=@pmnSemana
GO
/****** Object:  StoredProcedure [dbo].[paUpFcSemanasAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFcSemanasAbo]  @pmIdVehiculo VARCHAR(10)=Null
 AS 
  UPDATE Trn_FcSemanas SET VrPagado=0  WHERE  IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') 
  UPDATE Trn_FcSemanas SET  Trn_FcSemanas.VrPagado=(SELECT ISNULL(SUM(Trn_FcAbonos.VrAbono),0)
   FROM Trn_FcAbonos  WHERE Trn_FcSemanas.IdVehiculo=Trn_FcAbonos.IdVehiculo
   AND Trn_FcSemanas.nSemana=Trn_FcAbonos.nSemana)
  WHERE IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpFields]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFields] @pmIdEntidad VARCHAR(30),@pmIdCampo VARCHAR(20),@pmDescripcion VARCHAR(50),@pmTipoDato VARCHAR(15),@pmLongMax INT,@pmRequerido BIT,@pmPmryKey BIT,@pmFmtValue VARCHAR(20)
,@pmDftValue VARCHAR(20),@pmAliasFld VARCHAR(20),@pmAliasQry2 VARCHAR(20),@pmIndField INT,@pmTipoEntidad VARCHAR(5),@pmLstTipo VARCHAR(5),@pmLstClnaValor VARCHAR(20),@pmLstClnaLista VARCHAR(50),@pmLstQuery VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE Sys_Fields SET Descripcion=@pmDescripcion,TipoDato=@pmTipoDato,LongMax=@pmLongMax,Requerido=@pmRequerido,PmryKey=@pmPmryKey,FmtValue=@pmFmtValue,DftValue=@pmDftValue,AliasFld=@pmAliasFld,AliasQry2=@pmAliasQry2
,IndField=@pmIndField,TipoEntidad=@pmTipoEntidad,LstTipo=@pmLstTipo,LstClnaValor=@pmLstClnaValor,LstClnaLista=@pmLstClnaLista,LstQuery=@pmLstQuery,Inactivo=@pmInactivo
 WHERE IdEntidad=@pmIdEntidad AND IdCampo=@pmIdCampo
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFijos] @pmIdCargo VARCHAR(4),@pmConcepto VARCHAR(100), @pmObligatorio BIT, @pmTipoAplica VARCHAR(10),  @pmDiasSemana VARCHAR(20), @pmDiasMes VARCHAR(100)
, @pmValorMensual MONEY, @pmValorDiario MONEY, @pmIdCuentaDeb VARCHAR(16), @pmIdCuentaCre VARCHAR(16), @pmIdCueDebVp VARCHAR(16), @pmIdCueCreVp VARCHAR(16),@pmInactivo BIT
,@pmNCuotas INT,@pmDiasVcmto VARCHAR(50),@pmOrdenAbono INT,@pmTipoDcto CHAR(1),@pmDctoPpago DECIMAL(14,4),@pmVrCargoAdic MONEY,@pmFecLimiteIni SMALLDATETIME,@pmFecLimiteFin SMALLDATETIME
,@pmCdTarifaIva VARCHAR(4),@pmCdTarifaRet VARCHAR(4),@pmCdCuentaIva VARCHAR(16),@pmCdCuentaRet VARCHAR(16),@pmCdCuentaIca VARCHAR(16),@pmCodFEDian VARCHAR(20),@pmIvaIncluido BIT,@pmFechaUpdate SMALLDATETIME
AS
 UPDATE Fijos SET Concepto=@pmConcepto,Obligatorio=@pmObligatorio,TipoAplica=@pmTipoAplica, DiasSemana=@pmDiasSemana, DiasMes=@pmDiasMes, ValorMensual=@pmValorMensual, ValorDiario=@pmValorDiario,IdCuentaDeb=@pmIdCuentaDeb
,IdCuentaCre=@pmIdCuentaCre, IdCueDebVp=@pmIdCueDebVp, IdCueCreVp=@pmIdCueCreVp
,NCuotas=@pmNCuotas,DiasVcmto=@pmDiasVcmto,OrdenAbono=@pmOrdenAbono,TipoDcto=@pmTipoDcto,DctoPpago=@pmDctoPpago,VrCargoAdic=@pmVrCargoAdic,Inactivo=@pmInactivo,FecLimiteIni=@pmFecLimiteIni,FecLimiteFin=@pmFecLimiteFin,FechaUpdate= @pmFechaUpdate
,CdTarifaIva=@pmCdTarifaIva,CdTarifaRet=@pmCdTarifaRet,CdCuentaIva=@pmCdCuentaIva,CdCuentaRet=@pmCdCuentaRet,CdCuentaIca=@pmCdCuentaIca,CodFEDian=@pmCodFEDian,IvaIncluido=@pmIvaIncluido
WHERE IdCargo=@pmIdCargo
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos_Cla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFijos_Cla] @pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4),@pmValorMensual MONEY,@pmValorDiario MONEY

AS
 UPDATE  Fijos_Cla  SET ValorMensual=@pmValorMensual,ValorDiario =@pmValorDiario
 WHERE IdCargo=@pmIdCargo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos_Cue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpFijos_Cue]  @pmIdCargo VARCHAR(4), @pmIdAdmon VARCHAR(4),@pmIdCuentaDeb VARCHAR(16), @pmIdCuentaCre VARCHAR(16)
,@pmIdCueDebVp VARCHAR(16),@pmIdCueCreVp VARCHAR(16),@pmIdCuentaIva VARCHAR(16),@pmIdCuentaRet VARCHAR(16),@pmIdCuentaIca VARCHAR(16)
AS
 UPDATE Fijos_Cue SET IdCuentaDeb=@pmIdCuentaDeb,IdCuentaCre=@pmIdCuentaCre,IdCueDebVp=@pmIdCueDebVp,IdCueCreVp=@pmIdCueCreVp
,IdCuentaIva=@pmIdCuentaIva,IdCuentaRet=@pmIdCuentaRet,IdCuentaIca=@pmIdCuentaIca
 WHERE IdCargo=@pmIdCargo AND IdAdmon=@pmIdAdmon
GO
/****** Object:  StoredProcedure [dbo].[paUpFijos_Veh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFijos_Veh] @pmIdCargo VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmValorMensual MONEY,@pmValorDiario MONEY,@pmExcluir BIT

AS
 UPDATE Fijos_Veh SET ValorMensual=@pmValorMensual, ValorDiario=@pmValorDiario,  Excluir=@pmExcluir
 WHERE IdCargo=@pmIdCargo AND IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinAfavorAbo] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmVrAbono MONEY
 AS 
 UPDATE Trn_FinAfavor SET VrAbono=@pmVrAbono
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinAfavorApl] @pmIdCliente VARCHAR(16)=Null,@pmIdVend  VARCHAR(16)=Null
 AS 
 UPDATE Trn_FinAfavor SET  Trn_FinAfavor.VrAbono=(SELECT ISNULL(SUM(Trn_FinAbonos.TotalAbono),0)
   FROM Trn_FinAbonos  WHERE  Trn_FinAfavor.TipDoc=Trn_FinAbonos.TipRec AND Trn_FinAfavor.Recibo=Trn_FinAbonos.Recibo
   AND Trn_FinAfavor.IdCia=Trn_FinAbonos.IdCia AND TipoAplica=2)
  WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinAfavorDoc] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_FinAfavor SET  Trn_FinAfavor.VrAbono=(SELECT ISNULL(SUM(Trn_FinAbonos.TotalAbono),0)
   FROM Trn_FinAbonos  WHERE  Trn_FinAfavor.TipDoc=Trn_FinAbonos.TipRec AND Trn_FinAfavor.Recibo=Trn_FinAbonos.Recibo
   AND Trn_FinAfavor.IdCia=Trn_FinAbonos.IdCia AND TipoAplica=2)
  WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAfavorOdb]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinAfavorOdb] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmVrAbono MONEY,@pmVrOtrosDb MONEY
 AS 
 UPDATE Trn_FinAfavor  SET VrAbono=@pmVrAbono,VrOtrosDb=@pmVrOtrosDb
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAlmacenes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinAlmacenes] @pmIdAlmacen VARCHAR(4),@pmAlmacen VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE FinAlmacenes SET Almacen=@pmAlmacen,Inactivo=@pmInactivo
 WHERE IdAlmacen=@pmIdAlmacen
GO
/****** Object:  StoredProcedure [dbo].[paUpFinAportes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinAportes] @pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecLiquida SMALLDATETIME,@pmCodCia CHAR(2),@pmCodGrupo VARCHAR(4),@pmCodTipoTerc VARCHAR(4),@pmValorTotal MONEY,@pmBaseApo MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_FinAportes SET Fecha=@pmFecha,FecLiquida=@pmFecLiquida,CodCia=@pmCodCia,CodGrupo=@pmCodGrupo,CodTipoTerc=@pmCodTipoTerc,ValorTotal=@pmValorTotal,BaseApo=@pmBaseApo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
 WHERE TipLiq=@pmTipLiq AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCanAportes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinCanAportes] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmValorTotal MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(2000),@pmAnulado BIT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_FinCanAportes SET Fecha=@pmFecha,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,ValorTotal=@pmValorTotal,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,FecDev=@pmFecDev
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinClieSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinClieSaldos] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 UPDATE FinClieSaldos SET VrSaldo=@pmVrSaldo
 WHERE IdClie=@pmIdClie AND CdAgencia=@pmCdAgencia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinClieSaldosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinClieSaldosAcu] @pmIdClie VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 IF EXISTS(SELECT * FROM tempdb..sysobjects WHERE NAME LIKE '#FinClieSaldos%') 
 DROP TABLE #FinClieSaldos
 CREATE TABLE #FinClieSaldos (tmId INT PRIMARY KEY IDENTITY (1,1)
 ,IdClie VARCHAR(16),CdAgencia VARCHAR(16),IdCia CHAR(2),VrCuotas MONEY,VrAbonos MONEY,VrAFavor MONEY,VrAbonoSAF MONEY)
--cuotas
 INSERT INTO #FinClieSaldos (IdClie,CdAgencia,IdCia,VrCuotas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,SUM(VrTotal),0,0,0
 FROM Trn_FinCuotas
 WHERE IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia
--abonos de cuotas
 INSERT INTO #FinClieSaldos (IdClie,CdAgencia,IdCia,VrCuotas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,0,SUM(TotalAbono),0,0
 FROM Trn_FinAbonos
 WHERE IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia
--recibos a favor
 INSERT INTO #FinClieSaldos (IdClie,CdAgencia,IdCia,VrCuotas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,0,0,SUM(VrAFavor-VrOtrosDb),0
 FROM Trn_FinAfavor
 WHERE IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia
 --abonos de saldos a favor
 INSERT INTO #FinClieSaldos (IdClie,CdAgencia,IdCia,VrCuotas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,0,0,0,SUM(TotalAbono)
 FROM Trn_FinAbonos
 WHERE TipoAplica=2 AND IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia 
 --actualiza saldos
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnSaldos'
 BEGIN TRANSACTION @TrnNombre
 DELETE FROM FinClieSaldos WHERE IdClie LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 INSERT INTO FinClieSaldos (IdClie,CdAgencia,IdCia,VrSaldo)
 SELECT IdClie,CdAgencia,IdCia,SUM((VrCuotas-VrAbonos)-(VrAFavor-VrAbonoSAF)) 
 FROM #FinClieSaldos
 GROUP BY IdClie,CdAgencia,IdCia
 COMMIT TRANSACTION  @TrnNombre
--DROP TABLE #FinClieSaldos
GO
/****** Object:  StoredProcedure [dbo].[paUpFinClieSaldosLin]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinClieSaldosLin] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16)
,@pmIdLinea VARCHAR(4),@pmIdCia CHAR(2),@pmVrSaldoCap MONEY,@pmVrSaldoInt MONEY,@pmVrSaldoOtro MONEY
 AS 
 UPDATE FinClieSaldosLin SET VrSaldoCap=@pmVrSaldoCap,VrSaldoInt=@pmVrSaldoInt,VrSaldoOtro=@pmVrSaldoOtro
 WHERE IdClie=@pmIdClie AND CdAgencia=@pmCdAgencia AND IdLinea=@pmIdLinea AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinConcFactura]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinConcFactura] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmTipoConc VARCHAR(10),@pmGravado BIT,@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4)
,@pmIdCuenta VARCHAR(16),@pmCdCueIva VARCHAR(16),@pmCdCueRet VARCHAR(16),@pmCdCueIca VARCHAR(16),@pmInactivo BIT,@pmCodFEDian VARCHAR(20),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE FinConcFactura SET Concepto=@pmConcepto,TipoConc=@pmTipoConc,Gravado=@pmGravado,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,IdCuenta=@pmIdCuenta
,CdCueIva=@pmCdCueIva,CdCueRet=@pmCdCueRet,CdCueIca=@pmCdCueIca,Inactivo=@pmInactivo,CodFEDian=@pmCodFEDian,FechaUpdate=@pmFechaUpdate
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpFinConvenios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinConvenios] @pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmValorTotal MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(2000),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_FinConvenios SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdProveedor=@pmIdProveedor,NumFactura=@pmNumFactura,FecFactura=@pmFecFactura,FecVence=@pmFecVence,ValorTotal=@pmValorTotal,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
 WHERE TipLiq=@pmTipLiq AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCuotasAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinCuotasAbo] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT
,@pmVrAbonado MONEY,@pmFecUltPago SMALLDATETIME
 AS 
 UPDATE Trn_FinCuotas SET  VrAbonado=@pmVrAbonado,FecUltPago=@pmFecUltPago
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCuotasApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinCuotasApl]  @pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
   UPDATE Trn_FinCuotas SET  Trn_FinCuotas.VrAbonado=(SELECT ISNULL(SUM(Trn_FinAbonos.TotalAbono),0)
   FROM Trn_FinAbonos  WHERE Trn_FinCuotas.TipDoc=Trn_FinAbonos.TipDoc AND Trn_FinCuotas.IdPrestamo=Trn_FinAbonos.IdPrestamo
   AND Trn_FinCuotas.IdCia=Trn_FinAbonos.IdCiaPre  AND Trn_FinCuotas.Item=Trn_FinAbonos.ItemPre)
   WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
   AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ELSE
   UPDATE Trn_FinCuotas SET  Trn_FinCuotas.VrAbonado=(SELECT ISNULL(SUM(Trn_FinAbonos.TotalAbono),0)
   FROM Trn_FinAbonos  WHERE Trn_FinCuotas.TipDoc=Trn_FinAbonos.TipDoc AND Trn_FinCuotas.IdPrestamo=Trn_FinAbonos.IdPrestamo
   AND Trn_FinCuotas.IdCia=Trn_FinAbonos.IdCiaPre  AND Trn_FinCuotas.Item=Trn_FinAbonos.ItemPre)
   WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUpFinCuotasCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinCuotasCero]  @pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
 AS 
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
   UPDATE Trn_FinCuotas SET VrAbonado=0
   WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
   AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 ELSE
   UPDATE Trn_FinCuotas SET VrAbonado=0 WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUpFinDevFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinDevFac] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmIdVend VARCHAR(16),@pmIdLocal VARCHAR(8),@pmModdDev VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinDevFac SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Factura=@pmFactura,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto
,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrNeto=@pmVrNeto,IdVend=@pmIdVend,IdLocal=@pmIdLocal,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinDevPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinDevPre] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrPrestamo MONEY,@pmIdVend VARCHAR(16),@pmCxPagar BIT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinDevPre SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,IdPrestamo=@pmIdPrestamo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrPrestamo=@pmVrPrestamo,IdVend=@pmIdVend,CxPagar=@pmCxPagar
,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinDevRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinDevRec] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmFecPago SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY
,@pmVrOtrDcto MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmVrEfectivo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmEnEfectivo BIT,@pmReferencia VARCHAR(50),@pmNumAutoriza INT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinDevRec SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Recibo=@pmRecibo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,FecPago=@pmFecPago,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrRecibido=@pmVrRecibido,VrSubTotal=@pmVrSubTotal,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrOtros=@pmVrOtros,VrOtrDcto=@pmVrOtrDcto,VrPagosMas=@pmVrPagosMas,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado
,VrAnticipo=@pmVrAnticipo,VrEfectivo=@pmVrEfectivo,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,EnEfectivo=@pmEnEfectivo,Referencia=@pmReferencia,NumAutoriza=@pmNumAutoriza,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinFactint]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinFactint] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4)
,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdLocal VARCHAR(8),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoFactInt VARCHAR(10),@pmCodTarRtc VARCHAR(4),@pmTarifaRtc DECIMAL(14,4),@pmTipoFE VARCHAR(3),@pmFechaFE SMALLDATETIME,@pmCodTarArf VARCHAR(4),@pmTarifaArf DECIMAL(14,4),@pmVrAutRetFte MONEY,@pmCodTarAri VARCHAR(4),@pmTarifaAri DECIMAL(14,4),@pmVrAutRetIca MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinFactint SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrNeto=@pmVrNeto,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv
,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,IdLocal=@pmIdLocal,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,TipoFactInt=@pmTipoFactInt,TipoFE=@pmTipoFE,FechaFE=@pmFechaFE
,CodTarArf=@pmCodTarArf,TarifaArf=@pmTarifaArf,VrAutRetFte=@pmVrAutRetFte,CodTarAri=@pmCodTarAri,TarifaAri=@pmTarifaAri,VrAutRetIca=@pmVrAutRetIca,CodTarRtc=@pmCodTarRtc,TarifaRtc=@pmTarifaRtc,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinFactintDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpFinFactintDev] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev  SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_FinFactint SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
WHERE TipDoc=@pmTipDoc AND Factura=@pmFactura AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinNotas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrSancion MONEY,@pmVrOtros MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4)
,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmFecDcm SMALLDATETIME,@pmCdForma VARCHAR(4),@pmNumCheque VARCHAR(20)
,@pmCdBanco VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinNotas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrSancion=@pmVrSancion,VrOtros=@pmVrOtros,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado,VrAnticipo=@pmVrAnticipo,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv
,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,Referencia=@pmReferencia,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,FecDcm=@pmFecDcm,CdForma=@pmCdForma,NumCheque=@pmNumCheque,CdBanco=@pmCdBanco,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,Modalidad=@pmModalidad
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinPrestamo] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecPrestamo SMALLDATETIME,@pmFecCorte SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrPrestamo MONEY,@pmIdTasa VARCHAR(4),@pmNPlazos INT,@pmCausacion VARCHAR(10),@pmIdMora VARCHAR(4)
,@pmNContrato INT,@pmCdCiaCon CHAR(2),@pmNActaJunta INT,@pmNumCredito VARCHAR(20),@pmIdVend VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipoGarantia VARCHAR(10),@pmVrGarantia MONEY,@pmDescGarantia VARCHAR(250),@pmCxPagar BIT,@pmNumCuotaIni INT,@pmAcumCapital MONEY,@pmAcumIntereses MONEY,@pmAcumIntMora MONEY,@pmAcumCuotas INT,@pmPagosCapital MONEY
,@pmPagosIntereses MONEY,@pmPagosIntMora MONEY,@pmCuotasPagadas INT,@pmCuotasMora INT,@pmTipoAprob VARCHAR(20),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmDiaCausac INT,@pmDiaCausac2 INT,@pmDiasVence VARCHAR(50),@pmIdLinea VARCHAR(4),@pmTipoPlazo CHAR(1),@pmTipoCausac INT,@pmCdTasa2 VARCHAR(4),@pmVrSeguro MONEY,@pmVrIntereses MONEY,@pmVrNeto MONEY,@pmVrCuota MONEY,@pmTipoCredito VARCHAR(10),@pmCalcIntMora BIT,@pmNitEmpConv VARCHAR(16),@pmCuotasConv INT
,@pmRefinanciado INT,@pmNumPrestRef INT,@pmCiaPrestRef CHAR(2),@pmVrRefinanc MONEY,@pmDescRefinanc  VARCHAR(150),@pmCdAlmacen VARCHAR(4),@pmCauAnticipado BIT,@pmCdCtaPago VARCHAR(4),@pmVrInteresPM MONEY,@pmCantDiasPM INT,@pmNumNotaIni INT,@pmNumNotaFin INT,@pmFechaFinPM SMALLDATETIME,@pmIndDebAuto INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinPrestamo SET Fecha=@pmFecha,FecPrestamo=@pmFecPrestamo,FecCorte=@pmFecCorte,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrPrestamo=@pmVrPrestamo,IdTasa=@pmIdTasa,NPlazos=@pmNPlazos,Causacion=@pmCausacion,IdMora=@pmIdMora,NContrato=@pmNContrato,CdCiaCon=@pmCdCiaCon,NActaJunta=@pmNActaJunta,NumCredito=@pmNumCredito,IdVend=@pmIdVend
,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipoGarantia=@pmTipoGarantia,VrGarantia=@pmVrGarantia,DescGarantia=@pmDescGarantia,CxPagar=@pmCxPagar,NumCuotaIni=@pmNumCuotaIni,AcumCapital=@pmAcumCapital,AcumIntereses=@pmAcumIntereses,AcumIntMora=@pmAcumIntMora,AcumCuotas=@pmAcumCuotas,PagosCapital=@pmPagosCapital,PagosIntereses=@pmPagosIntereses,PagosIntMora=@pmPagosIntMora,CuotasPagadas=@pmCuotasPagadas
,CuotasMora=@pmCuotasMora,TipoAprob=@pmTipoAprob,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,CdTasa2=@pmCdTasa2,VrSeguro=@pmVrSeguro,VrIntereses=@pmVrIntereses,VrNeto=@pmVrNeto,VrCuota=@pmVrCuota,FecUpdate=@pmFecUpdate
,DiaCausac=@pmDiaCausac,DiaCausac2=@pmDiaCausac2,DiasVence=@pmDiasVence,IdLinea=@pmIdLinea,TipoPlazo=@pmTipoPlazo,TipoCausac=@pmTipoCausac
,TipoCredito=@pmTipoCredito,CalcIntMora=@pmCalcIntMora,NitEmpConv=@pmNitEmpConv,CuotasConv=@pmCuotasConv
,Refinanciado=@pmRefinanciado,NumPrestRef=@pmNumPrestRef,CiaPrestRef=@pmCiaPrestRef,VrRefinanc=@pmVrRefinanc,DescRefinanc=@pmDescRefinanc,CdAlmacen=@pmCdAlmacen,CauAnticipado=@pmCauAnticipado,CdCtaPago=@pmCdCtaPago,VrInteresPM=@pmVrInteresPM,CantDiasPM=@pmCantDiasPM,NumNotaIni=@pmNumNotaIni,NumNotaFin=@pmNumNotaFin,FechaFinPM=@pmFechaFinPM,IndDebAuto=@pmIndDebAuto
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoAcum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinPrestamoAcum]  @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_FinPrestamo SET Trn_FinPrestamo.AcumCapital=(SELECT ISNULL(SUM(Trn_FinCuotas.VrTotal),0)
 FROM Trn_FinCuotas  WHERE Trn_FinCuotas.TipDoc=Trn_FinPrestamo.TipDoc AND Trn_FinCuotas.IdPrestamo=Trn_FinPrestamo.IdPrestamo
 AND Trn_FinCuotas.IdCia=Trn_FinPrestamo.IdCia AND Concepto='CAPITAL')
 ,Trn_FinPrestamo.AcumCuotas=(SELECT ISNULL(COUNT(Trn_FinCuotas.NumCuota),0)
 FROM Trn_FinCuotas  WHERE Trn_FinCuotas.TipDoc=Trn_FinPrestamo.TipDoc AND Trn_FinCuotas.IdPrestamo=Trn_FinPrestamo.IdPrestamo
 AND Trn_FinCuotas.IdCia=Trn_FinPrestamo.IdCia AND Concepto='CAPITAL')
,Trn_FinPrestamo.AcumIntereses=(SELECT ISNULL(SUM(Trn_FinCuotas.VrTotal),0)
 FROM Trn_FinCuotas  WHERE Trn_FinCuotas.TipDoc=Trn_FinPrestamo.TipDoc AND Trn_FinCuotas.IdPrestamo=Trn_FinPrestamo.IdPrestamo
 AND Trn_FinCuotas.IdCia=Trn_FinPrestamo.IdCia AND Concepto='INTERESES')
  WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinPrestamoDev] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_FinPrestamo SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoMora]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinPrestamoMora]  @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_FinPrestamo SET Trn_FinPrestamo.AcumIntMora=(SELECT ISNULL(SUM(Trn_FinCuotas.VrTotal),0)
 FROM Trn_FinCuotas  WHERE Trn_FinCuotas.TipDoc='ND2' AND  Trn_FinCuotas.NumPreMora=Trn_FinPrestamo.IdPrestamo
 AND Trn_FinCuotas.IdCiaCau=Trn_FinPrestamo.IdCia AND Concepto='INTMORA')
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoPag]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinPrestamoPag]  @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_FinPrestamo SET Trn_FinPrestamo.PagosCapital=(SELECT ISNULL(SUM(Trn_FinAbonos.TotalAbono),0)
 FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo
 AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND  Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
  WHERE Trn_FinAbonos.TipDoc=Trn_FinPrestamo.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinPrestamo.IdPrestamo
 AND Trn_FinAbonos.IdCiaPre=Trn_FinPrestamo.IdCia  AND Concepto='CAPITAL')
--INTERESS
,Trn_FinPrestamo.PagosIntereses=(SELECT ISNULL(SUM(Trn_FinAbonos.TotalAbono),0)
 FROM Trn_FinAbonos INNER JOIN Trn_FinCuotas ON Trn_FinAbonos.TipDoc=Trn_FinCuotas.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinCuotas.IdPrestamo
 AND Trn_FinAbonos.IdCiaPre=Trn_FinCuotas.IdCia AND  Trn_FinAbonos.ItemPre=Trn_FinCuotas.Item
  WHERE Trn_FinAbonos.TipDoc=Trn_FinPrestamo.TipDoc AND Trn_FinAbonos.IdPrestamo=Trn_FinPrestamo.IdPrestamo
 AND Trn_FinAbonos.IdCiaPre=Trn_FinPrestamo.IdCia  AND Concepto='INTERESES')
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestamoTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinPrestamoTot] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2)
,@pmAcumCapital MONEY,@pmAcumIntereses MONEY,@pmAcumIntMora MONEY,@pmAcumCuotas INT,@pmPagosCapital MONEY
,@pmPagosIntereses MONEY,@pmPagosIntMora MONEY,@pmCuotasPagadas INT,@pmCuotasMora INT
 AS 
 UPDATE Trn_FinPrestamo SET  AcumCapital=@pmAcumCapital,AcumIntereses=@pmAcumIntereses,AcumIntMora=@pmAcumIntMora
,AcumCuotas=@pmAcumCuotas,PagosCapital=@pmPagosCapital,PagosIntereses=@pmPagosIntereses,PagosIntMora=@pmPagosIntMora
,CuotasPagadas=@pmCuotasPagadas,CuotasMora=@pmCuotasMora
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinPrestGarant]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinPrestGarant] @pmTipDoc VARCHAR(3),@pmIdPrestamo INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoGarant VARCHAR(20),@pmDescGarant VARCHAR(250),@pmCdInmueble VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmVrGarantia MONEY,@pmVrAvaluo MONEY,@pmPesoBruto DECIMAL(16,6),@pmPesoNeto DECIMAL(16,6),@pmPropietario VARCHAR(250),@pmDirInmueble VARCHAR(250),@pmCdCiudad VARCHAR(8),@pmMatricula VARCHAR(50),@pmEscritura VARCHAR(50),@pmNumNotaria VARCHAR(20),@pmMarcaVeh VARCHAR(20),@pmModelo VARCHAR(4)
,@pmCdBanco VARCHAR(4),@pmFecCheque SMALLDATETIME,@pmNumCheque VARCHAR(20),@pmOtroTipoVehic VARCHAR(50),@pmOtroInmueble VARCHAR(50),@pmCedFmnte1 VARCHAR(16),@pmNomFmnte1 VARCHAR(150),@pmCedFmnte2 VARCHAR(16),@pmNomFmnte2 VARCHAR(150),@pmCedFmnte3 VARCHAR(16),@pmNomFmnte3 VARCHAR(150),@pmCedFmnte4 VARCHAR(16),@pmNomFmnte4 VARCHAR(150),@pmCedFmnte5 VARCHAR(16),@pmNomFmnte5 VARCHAR(150),@pmCedFmnte6 VARCHAR(16),@pmNomFmnte6 VARCHAR(150),@pmArchivoImg VARCHAR(500)
 AS 
 UPDATE Trn_FinPrestGarant SET TipoGarant=@pmTipoGarant,DescGarant=@pmDescGarant,CdInmueble=@pmCdInmueble,CdTipoVeh=@pmCdTipoVeh,VrGarantia=@pmVrGarantia,VrAvaluo=@pmVrAvaluo,PesoBruto=@pmPesoBruto,PesoNeto=@pmPesoNeto,Propietario=@pmPropietario,DirInmueble=@pmDirInmueble,CdCiudad=@pmCdCiudad,Matricula=@pmMatricula,Escritura=@pmEscritura,NumNotaria=@pmNumNotaria,MarcaVeh=@pmMarcaVeh,Modelo=@pmModelo,CdBanco=@pmCdBanco,FecCheque=@pmFecCheque,NumCheque=@pmNumCheque,OtroTipoVehic=@pmOtroTipoVehic
,OtroInmueble=@pmOtroInmueble,CedFmnte1=@pmCedFmnte1,NomFmnte1=@pmNomFmnte1,CedFmnte2=@pmCedFmnte2,NomFmnte2=@pmNomFmnte2,CedFmnte3=@pmCedFmnte3,NomFmnte3=@pmNomFmnte3,CedFmnte4=@pmCedFmnte4,NomFmnte4=@pmNomFmnte4,CedFmnte5=@pmCedFmnte5,NomFmnte5=@pmNomFmnte5,CedFmnte6=@pmCedFmnte6,NomFmnte6=@pmNomFmnte6,ArchivoImg=@pmArchivoImg
 WHERE TipDoc=@pmTipDoc AND IdPrestamo=@pmIdPrestamo AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpFinRecibos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFinRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFecPago SMALLDATETIME,@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY
,@pmVrAplicado MONEY,@pmVrEfectivo MONEY,@pmVrAnticipo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmEnEfectivo BIT,@pmCdForma VARCHAR(4)
,@pmNumForma VARCHAR(20),@pmDetallePago VARCHAR(250),@pmCdBanco VARCHAR(4),@pmCdCta VARCHAR(4),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipoCredito VARCHAR(10),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmVrAboCapital MONEY,@pmLiqAboCapital INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmVrAboOtros MONEY,@pmVrPagoCuotas MONEY,@pmVrPagoAportes MONEY,@pmVrPagoConvenio MONEY,@pmVrAboCuotas MONEY,@pmVrAboAportes MONEY,@pmVrAboConvenio MONEY,@pmVrAntPrestamo MONEY,@pmVrAntAportes MONEY,@pmVrAntConvenio MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_FinRecibos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FecPago=@pmFecPago,VrRecibido=@pmVrRecibido,VrSubTotal=@pmVrSubTotal,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrOtros=@pmVrOtros,VrOtrDcto=@pmVrOtrDcto,VrPagosMas=@pmVrPagosMas,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado,VrEfectivo=@pmVrEfectivo,VrAnticipo=@pmVrAnticipo
,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,EnEfectivo=@pmEnEfectivo,CdForma=@pmCdForma,NumForma=@pmNumForma,DetallePago=@pmDetallePago,CdBanco=@pmCdBanco,CdCta=@pmCdCta
,Referencia=@pmReferencia,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipoCredito=@pmTipoCredito,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,VrAboCapital=@pmVrAboCapital,LiqAboCapital=@pmLiqAboCapital
,VrAboOtros=@pmVrAboOtros,VrPagoCuotas=@pmVrPagoCuotas,VrPagoAportes=@pmVrPagoAportes,VrPagoConvenio=@pmVrPagoConvenio,VrAboCuotas=@pmVrAboCuotas,VrAboAportes=@pmVrAboAportes,VrAboConvenio=@pmVrAboConvenio,VrAntPrestamo=@pmVrAntPrestamo,VrAntAportes=@pmVrAntAportes,VrAntConvenio=@pmVrAntConvenio,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFinRecibosDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFinRecibosDev] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_FinRecibos SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpFmtDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFmtDoc] @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmPredtmnado BIT,@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT
,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 UPDATE Sys_FmtDoc SET Descripcion=@pmDescripcion,Formato=@pmFormato,Predtmnado=@pmPredtmnado,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup
,NumCopias=@pmNumCopias,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location
 WHERE IdDoc=@pmIdDoc AND IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paUpFmtDocPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFmtDocPre] @pmIdDoc VARCHAR(3),@pmIdForma CHAR(2),@pmPredtmnado BIT
 AS 
 UPDATE Sys_FmtDoc SET Predtmnado=@pmPredtmnado
 WHERE IdDoc=@pmIdDoc AND IdForma<>@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paUpFmtFactura]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFmtFactura] @pmnFormato VARCHAR(10),@pmIdDoc VARCHAR(3),@pmCdForma CHAR(2)
 AS 
 UPDATE Sys_FmtFactura SET IdDoc=@pmIdDoc,CdForma=@pmCdForma
 WHERE nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paUpFondos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFondos] @pmIdFondo VARCHAR(8),@pmFondo VARCHAR(100)
,@pmIdClase VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCodigoEps VARCHAR(10),@pmCodigoPen VARCHAR(10),@pmCodigoArp VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Fondos SET Fondo=@pmFondo,IdClase=@pmIdClase,IdTercero=@pmIdTercero
,CodigoEps=@pmCodigoEps,CodigoPen=@pmCodigoPen,CodigoArp=@pmCodigoArp,Inactivo=@pmInactivo
 WHERE IdFondo=@pmIdFondo
GO
/****** Object:  StoredProcedure [dbo].[paUpFormasCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFormasCue] @pmIdForma VARCHAR(4),@pmIdConcepto VARCHAR(4)
,@pmIdCuenta VARCHAR(16),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE FormasCue SET IdCuenta=@pmIdCuenta,FechaUpdate=@pmFechaUpdate
 WHERE IdForma=@pmIdForma AND IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpFormaspago]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFormaspago] @pmIdForma VARCHAR(4),@pmFormaPago VARCHAR(50),@pmConsecutivo INT,@pmCuadreCaja BIT
,@pmRefDcmto BIT,@pmRefNit BIT,@pmRefBco BIT,@pmRefFech BIT,@pmRefAtza BIT,@pmRefOtro BIT,@pmVldRangos BIT,@pmVleConsumo BIT
,@pmCodIntegrity VARCHAR(20),@pmCodValera VARCHAR(10),@pmCodIntCom VARCHAR(20),@pmRefProducto BIT,@pmFactTicket BIT,@pmCdMedPago VARCHAR(4),@pmValCtaPago BIT,@pmInactivo BIT
 AS 
 UPDATE Formaspago SET FormaPago=@pmFormaPago,Consecutivo=@pmConsecutivo,CuadreCaja=@pmCuadreCaja,RefDcmto=@pmRefDcmto,RefNit=@pmRefNit
,RefBco=@pmRefBco,RefFech=@pmRefFech,RefAtza=@pmRefAtza,RefOtro=@pmRefOtro,VldRangos=@pmVldRangos,VleConsumo=@pmVleConsumo
,CodIntegrity=@pmCodIntegrity,CodValera=@pmCodValera,CodIntCom=@pmCodIntCom,RefProducto=@pmRefProducto,FactTicket=@pmFactTicket,CdMedPago=@pmCdMedPago,ValCtaPago=@pmValCtaPago,Inactivo=@pmInactivo
 WHERE IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paUpFuentesPago]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFuentesPago] @pmIdFuente VARCHAR(4),@pmFuentePago VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE FuentesPago SET FuentePago=@pmFuentePago,Inactivo=@pmInactivo
 WHERE IdFuente=@pmIdFuente
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAdicionales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatAdicionales] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrAporte MONEY,@pmVrSaldo MONEY,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatAdicionales SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrAporte=@pmVrAporte,VrSaldo=@pmVrSaldo,VrAvaluo=@pmVrAvaluo,TipoBaseLiq=@pmTipoBaseLiq,TipoAfiVeh=@pmTipoAfiVeh,Referencia=@pmReferencia,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAdicionalesDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatAdicionalesDev] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatAdicionales SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatAjustes] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmVrAjustes MONEY,@pmReferencia VARCHAR(50),@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmCiaDocRef CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmTipCau VARCHAR(3),@pmCausacion INT,@pmIdCiaCau CHAR(2)
 AS 
 UPDATE Trn_GatAjustes SET Fecha=@pmFecha,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,VrAjustes=@pmVrAjustes,Referencia=@pmReferencia,TipDocRef=@pmTipDocRef,NumDocRef=@pmNumDocRef,CiaDocRef=@pmCiaDocRef,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
,TipCau=@pmTipCau,Causacion=@pmCausacion,IdCiaCau=@pmIdCiaCau
 WHERE TipDoc=@pmTipDoc AND NumAjuste=@pmNumAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustesDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatAjustesDev] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatAjustes SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumAjuste=@pmNumAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustesPror]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatAjustesPror] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmTipPror VARCHAR(3),@pmNumProceso INT,@pmIdCiaPror CHAR(2),@pmVrAjustes MONEY,@pmReferencia VARCHAR(50),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatAjustesPror SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,TipPror=@pmTipPror,NumProceso=@pmNumProceso,IdCiaPror=@pmIdCiaPror,VrAjustes=@pmVrAjustes,Referencia=@pmReferencia,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumAjuste=@pmNumAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatAjustesProrDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatAjustesProrDev] @pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatAjustesPror SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumAjuste=@pmNumAjuste AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevAdicional]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevAdicional] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrDevolucion MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevAdicional SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumRegistro=@pmNumRegistro,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrDevolucion=@pmVrDevolucion,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevAjuPror]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevAjuPror] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(20),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevAjuPror SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumAjuste=@pmNumAjuste,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,Modalidad=@pmModalidad,VrDevolucion=@pmVrDevolucion,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevAjustes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevAjustes] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumAjuste INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(20),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevAjustes SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumAjuste=@pmNumAjuste,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,Modalidad=@pmModalidad,VrDevolucion=@pmVrDevolucion,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevLiquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevLiquida] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumLiquida INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(20),@pmVrDevolucion MONEY,@pmVrBaseLiq MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevLiquida SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumLiquida=@pmNumLiquida,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,Modalidad=@pmModalidad,VrDevolucion=@pmVrDevolucion,VrBaseLiq=@pmVrBaseLiq,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevProrr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevProrr] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(10),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10)
,@pmnRemolque VARCHAR(10),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevProrr SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumProceso=@pmNumProceso,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,Modalidad=@pmModalidad,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrDevolucion=@pmVrDevolucion
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevRetiros]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevRetiros] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumRetiro INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmTipoRetiro VARCHAR(10),@pmModalidad VARCHAR(10),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrDevolucion MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevRetiros SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumRetiro=@pmNumRetiro,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,TipoRetiro=@pmTipoRetiro,Modalidad=@pmModalidad,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrDevolucion=@pmVrDevolucion,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevTraslado]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevTraslado] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmTipDoc VARCHAR(3),@pmNumTraslado INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10)
,@pmIdAsociadoDtn VARCHAR(16),@pmUndVehicDtn CHAR(1),@pmIdVehiculoDtn VARCHAR(10),@pmVrDevolucion MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevTraslado SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,TipDoc=@pmTipDoc,NumTraslado=@pmNumTraslado,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,IdAsociadoDtn=@pmIdAsociadoDtn,UndVehicDtn=@pmUndVehicDtn,IdVehiculoDtn=@pmIdVehiculoDtn,VrDevolucion=@pmVrDevolucion,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatDevVinc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatDevVinc] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumDocVinc INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrIngresos MONEY,@pmVrTraslados MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatDevVinc SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumDocVinc=@pmNumDocVinc,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrIngresos=@pmVrIngresos,VrTraslados=@pmVrTraslados,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatLiquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatLiquida] @pmTipDoc VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaLiquida SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmPeriodos INT,@pmTarifaLiq DECIMAL(14,4),@pmVrAportes MONEY,@pmReferencia VARCHAR(50),@pmVrBaseLiq MONEY,@pmCdTarifLiq VARCHAR(4)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmTipCau VARCHAR(3),@pmCausacion INT,@pmIdCiaCau CHAR(2)
 AS 
 UPDATE Trn_GatLiquida SET Fecha=@pmFecha,FechaLiquida=@pmFechaLiquida,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,Periodos=@pmPeriodos,TarifaLiq=@pmTarifaLiq,VrAportes=@pmVrAportes,Referencia=@pmReferencia,VrBaseLiq=@pmVrBaseLiq,CdTarifLiq=@pmCdTarifLiq,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion,TipCau=@pmTipCau,Causacion=@pmCausacion,IdCiaCau=@pmIdCiaCau
 WHERE TipDoc=@pmTipDoc AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatLiquidaDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatLiquidaDev] @pmTipDoc VARCHAR(3),@pmNumLiquida INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatLiquida SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumLiquida=@pmNumLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatProrrateos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatProrrateos] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipDocActa VARCHAR(3),@pmNumDocActa INT,@pmIdCiaActa CHAR(2),@pmFecSuceso SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrAprobado MONEY,@pmVrAvaluo MONEY,@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatProrrateos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,TipDocActa=@pmTipDocActa,NumDocActa=@pmNumDocActa,IdCiaActa=@pmIdCiaActa,FecSuceso=@pmFecSuceso,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrAprobado=@pmVrAprobado,VrAvaluo=@pmVrAvaluo,TipoAfiVeh=@pmTipoAfiVeh,Referencia=@pmReferencia,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatProrrateosDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatProrrateosDev] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatProrrateos SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatRetiros]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatRetiros] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaRetiro SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipoRetiro VARCHAR(10),@pmModalidad VARCHAR(10),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrRetiro MONEY,@pmVrAportes MONEY,@pmVrVinculacion MONEY,@pmVrSaldoVinc MONEY,@pmVrGarantia MONEY,@pmVrSaldoApo MONEY,@pmVrTotalApo MONEY,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10)
,@pmReferencia VARCHAR(50),@pmFechaCorte SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatRetiros SET Fecha=@pmFecha,FechaRetiro=@pmFechaRetiro,IdConcepto=@pmIdConcepto,TipoRetiro=@pmTipoRetiro,Modalidad=@pmModalidad,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrRetiro=@pmVrRetiro,VrAportes=@pmVrAportes,VrVinculacion=@pmVrVinculacion,VrSaldoVinc=@pmVrSaldoVinc,VrGarantia=@pmVrGarantia,VrSaldoApo=@pmVrSaldoApo,VrTotalApo=@pmVrTotalApo,VrAvaluo=@pmVrAvaluo,TipoBaseLiq=@pmTipoBaseLiq,TipoAfiVeh=@pmTipoAfiVeh,Referencia=@pmReferencia,FechaCorte=@pmFechaCorte
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatRetirosDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatRetirosDev] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatRetiros SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatSaldos] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdAsociado VARCHAR(16),@pmUndVahiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmVrAportes MONEY,@pmVrVinculacion MONEY,@pmVrAvaluo MONEY,@pmVrComercial MONEY,@pmVrAsegurado MONEY,@pmTipoBaseLiq CHAR(1)
,@pmCantidad DECIMAL(14,4),@pmFecVincAsoc SMALLDATETIME,@pmFecLiquidaApo SMALLDATETIME,@pmTipoAfiVeh VARCHAR(10),@pmAnulado BIT,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatSaldos SET Fecha=@pmFecha,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVahiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,VrAportes=@pmVrAportes,VrVinculacion=@pmVrVinculacion,VrAvaluo=@pmVrAvaluo,VrComercial=@pmVrComercial,VrAsegurado=@pmVrAsegurado,TipoBaseLiq=@pmTipoBaseLiq,Cantidad=@pmCantidad,FecVincAsoc=@pmFecVincAsoc
,FecLiquidaApo=@pmFecLiquidaApo,TipoAfiVeh=@pmTipoAfiVeh,Anulado=@pmAnulado,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatTraslados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatTraslados] @pmTipDoc VARCHAR(3),@pmNumTraslado INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(20),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmIdAsociadoDtn VARCHAR(16),@pmUndVehicDtn CHAR(1),@pmIdVehiculoDtn VARCHAR(10),@pmVrTraslado MONEY,@pmVrAportes MONEY,@pmVrVinculacion MONEY,@pmVrSaldoVinc MONEY,@pmVrGarantia MONEY,@pmVrSaldoApo MONEY,@pmVrTotalApo MONEY
,@pmVrAvaluo MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50),@pmFechaCorte SMALLDATETIME,@pmVrAbonos MONEY,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmCiaDocRef CHAR(2),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500),@pmTarifaGar DECIMAL(14,4),@pmUndTarifGar CHAR(1),@pmComentarioGar VARCHAR(500)
 AS 
 UPDATE Trn_GatTraslados SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,IdAsociadoDtn=@pmIdAsociadoDtn,UndVehicDtn=@pmUndVehicDtn,IdVehiculoDtn=@pmIdVehiculoDtn,VrTraslado=@pmVrTraslado,VrAportes=@pmVrAportes,VrVinculacion=@pmVrVinculacion,VrSaldoVinc=@pmVrSaldoVinc,VrGarantia=@pmVrGarantia,VrSaldoApo=@pmVrSaldoApo,VrTotalApo=@pmVrTotalApo,VrAvaluo=@pmVrAvaluo,TipoBaseLiq=@pmTipoBaseLiq,TipoAfiVeh=@pmTipoAfiVeh,Referencia=@pmReferencia
,FechaCorte=@pmFechaCorte,VrAbonos=@pmVrAbonos,TipDocRef=@pmTipDocRef,NumDocRef=@pmNumDocRef,CiaDocRef=@pmCiaDocRef,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion,TarifaGar=@pmTarifaGar,UndTarifGar=@pmUndTarifGar,ComentarioGar=@pmComentarioGar
 WHERE TipDoc=@pmTipDoc AND NumTraslado=@pmNumTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatTrasladosDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatTrasladosDev] @pmTipDoc VARCHAR(3),@pmNumTraslado INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
AS 
 UPDATE Trn_GatTraslados SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumTraslado=@pmNumTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatVincula]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatVincula] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaIngreso SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdAsociado VARCHAR(16),@pmUndVehiculo CHAR(1),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmTarifaVinc DECIMAL(14,4),@pmVrVinculacion MONEY,@pmVrIngresos MONEY,@pmVrTraslados MONEY,@pmVrAvaluo MONEY,@pmVrComercial MONEY,@pmVrAsegurado MONEY,@pmTipoBaseLiq CHAR(1),@pmTipoAfiVeh VARCHAR(10),@pmReferencia VARCHAR(50),@pmCdTarifVinc VARCHAR(4)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmFecUltLiqApo SMALLDATETIME,@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatVincula SET Fecha=@pmFecha,FechaIngreso=@pmFechaIngreso,IdConcepto=@pmIdConcepto,IdAsociado=@pmIdAsociado,UndVehiculo=@pmUndVehiculo,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,TarifaVinc=@pmTarifaVinc,VrVinculacion=@pmVrVinculacion,VrIngresos=@pmVrIngresos,VrTraslados=@pmVrTraslados,VrAvaluo=@pmVrAvaluo,VrComercial=@pmVrComercial,VrAsegurado=@pmVrAsegurado,TipoBaseLiq=@pmTipoBaseLiq,TipoAfiVeh=@pmTipoAfiVeh,Referencia=@pmReferencia,CdTarifVinc=@pmCdTarifVinc,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,FecUltLiqApo=@pmFecUltLiqApo,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGatVinculaDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGatVinculaDev] @pmTipDoc VARCHAR(3),@pmNumRegistro INT,@pmIdCia CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_GatVincula SET Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumRegistro=@pmNumRegistro AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGrupos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGrupos] @pmIdGrupo VARCHAR(8),@pmGrupo VARCHAR(150),@pmIdLinea VARCHAR(8)
,@pmTipoInvent VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Grupos SET Grupo=@pmGrupo,IdLinea=@pmIdLinea,TipoInvent=@pmTipoInvent
,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGruposAgenc] @pmIdGrupo VARCHAR(4),@pmGrupoAgenc VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE GruposAgenc SET GrupoAgenc=@pmGrupoAgenc,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposAR]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGruposAR] @pmIdGrupo VARCHAR(4),@pmAltoRiesgo VARCHAR(50),@pmTarfaTrab DECIMAL(10,4),@pmTarfaEmp DECIMAL(10,4),@pmInactivo BIT
 AS 
 UPDATE GruposAR SET AltoRiesgo=@pmAltoRiesgo,TarfaTrab=@pmTarfaTrab,TarfaEmp=@pmTarfaEmp,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGruposCli] @pmIdGrupo VARCHAR(4),@pmGrupoClie VARCHAR(50),@pmModApp VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE GruposCli SET GrupoClie=@pmGrupoClie,ModApp=@pmModApp,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposMcia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGruposMcia] @pmIdGrupo VARCHAR(10),@pmGrupoMcia VARCHAR(250),@pmInactivo BIT
 AS 
 UPDATE GruposMcia SET GrupoMcia=@pmGrupoMcia,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposObj]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGruposObj] @pmIdGrupo VARCHAR(6),@pmGrupoObjeto VARCHAR(50),@pmnModulo VARCHAR(10)
 AS 
 UPDATE Sys_GruposObj SET GrupoObjeto=@pmGrupoObjeto,nModulo=@pmnModulo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGruposPro] @pmIdGrupo VARCHAR(4),@pmGrupoProp VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE GruposPro SET GrupoProp=@pmGrupoProp,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposRot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGruposRot] @pmIdGrupo VARCHAR(4),@pmGrupoRot VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE GruposRot SET GrupoRot=@pmGrupoRot,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGruposUsu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGruposUsu] @pmIdGrupo INT,@pmGrupo VARCHAR(50),@pmDescripcion VARCHAR(100)
 AS 
 UPDATE Sys_GruposUsu SET Grupo=@pmGrupo,Descripcion=@pmDescripcion
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpGuia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpGuia] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaDesp SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmCantidad DECIMAL(14,4)
,@pmDirEnvio VARCHAR(250),@pmIdLocal VARCHAR(8),@pmLugarEnv VARCHAR(50),@pmHorasVig DECIMAL(14,4),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmCdRuta VARCHAR(4),@pmCdCiuOrigen VARCHAR(8)
,@pmReferncia VARCHAR(50),@pmTipOcc VARCHAR(3),@pmOCargue INT,@pmIdCiaOcc CHAR(2),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmZonaFrontera INT,@pmTipoTemp VARCHAR(10),@pmTemperatura DECIMAL(14,4),@pmTipoOCargue INT,@pmRemolque VARCHAR(10),@pmNumVerifica INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Guia SET Fecha=@pmFecha,FechaDesp=@pmFechaDesp,FechaVence=@pmFechaVence,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,Cantidad=@pmCantidad,DirEnvio=@pmDirEnvio,IdLocal=@pmIdLocal,LugarEnv=@pmLugarEnv,HorasVig=@pmHorasVig,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor
,NitEmpTrans=@pmNitEmpTrans,EmpTrans=@pmEmpTrans,CdRuta=@pmCdRuta,Referncia=@pmReferncia,TipOcc=@pmTipOcc,OCargue=@pmOCargue,IdCiaOcc=@pmIdCiaOcc,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact,Anulado=@pmAnulado,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CdCiuOrigen=@pmCdCiuOrigen,ZonaFrontera=@pmZonaFrontera,TipoTemp=@pmTipoTemp,Temperatura=@pmTemperatura,TipoOCargue=@pmTipoOCargue,Remolque=@pmRemolque,NumVerifica=@pmNumVerifica,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Guia=@pmGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGuiaAbr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGuiaAbr] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Guia SET  TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Guia=@pmGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGuiaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGuiaAnu] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Guia SET Anulado=@pmAnulado,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Guia=@pmGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpGuiaFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpGuiaFac] @pmTipDoc VARCHAR(3),@pmGuia INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Guia SET  TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Guia=@pmGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpInstalaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpInstalaciones] @pmIdInstala VARCHAR(4),@pmInstlacion VARCHAR(50),@pmDirInstala VARCHAR(100)
,@pmCodCiu VARCHAR(8),@pmCodCia CHAR(2),@pmIdClase VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE Instalaciones SET Instlacion=@pmInstlacion,DirInstala=@pmDirInstala,CodCia=@pmCodCia
,CodCiu=@pmCodCiu,IdClase=@pmIdClase,Inactivo=@pmInactivo
 WHERE IdInstala=@pmIdInstala
GO
/****** Object:  StoredProcedure [dbo].[paUpInvDetalleSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpInvDetalleSal] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmItem INT
,@pmVrUnitario MONEY,@pmCantExist DECIMAL(14,4),@pmNoConteo BIT
 AS 
 UPDATE  Trn_InvDetalle SET VrUnitario=@pmVrUnitario,CantExist=@pmCantExist,NoConteo=@pmNoConteo
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisico]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpInvFisico] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmModalidad VARCHAR(10),@pmCdBodega VARCHAR(4),@pmCantFisico DECIMAL(14,4)
,@pmVrTotalFisico MONEY,@pmExistencias DECIMAL(14,4),@pmVrTotalCosto MONEY,@pmProcesado BIT,@pmFecProceso SMALLDATETIME,@pmNumAjuSob INT,@pmNumAjuFal INT
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFCodBodega VARCHAR(4),@pmFCodMarca VARCHAR(4),@pmFCodSubGrupo VARCHAR(8),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_InvFisico SET Fecha=@pmFecha,Modalidad=@pmModalidad,CdBodega=@pmCdBodega,CantFisico=@pmCantFisico,VrTotalFisico=@pmVrTotalFisico,Existencias=@pmExistencias,VrTotalCosto=@pmVrTotalCosto
,Procesado=@pmProcesado,FecProceso=@pmFecProceso,NumAjuSob=@pmNumAjuSob,NumAjuFal=@pmNumAjuFal,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,FCodBodega=@pmFCodBodega,FCodMarca=@pmFCodMarca,FCodSubGrupo=@pmFCodSubGrupo,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisicoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpInvFisicoAnu] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_InvFisico SET  Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisicoPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpInvFisicoPro] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmProcesado BIT,@pmFecProceso SMALLDATETIME,@pmNumAjuSob INT,@pmNumAjuFal INT
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_InvFisico SET Procesado=@pmProcesado,FecProceso=@pmFecProceso
,NumAjuSob=@pmNumAjuSob,NumAjuFal=@pmNumAjuFal
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpInvFisicoTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpInvFisicoTot] @pmTipDoc VARCHAR(3),@pmnInventario INT,@pmIdCia CHAR(2)
,@pmCantFisico DECIMAL(14,4),@pmVrTotalFisico MONEY,@pmExistencias DECIMAL(14,4),@pmVrTotalCosto MONEY
 AS 
 UPDATE Trn_InvFisico SET CantFisico=@pmCantFisico,VrTotalFisico=@pmVrTotalFisico,Existencias=@pmExistencias
,VrTotalCosto=@pmVrTotalCosto
 WHERE TipDoc=@pmTipDoc AND nInventario=@pmnInventario AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJornadas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJornadas] @pmIdJornada VARCHAR(4),@pmJornada VARCHAR(50),@pmHorasDia INT
,@pmRangos VARCHAR(25),@pmTurnoRotativo BIT,@pmInactivo BIT
 AS 
 UPDATE Jornadas SET Jornada=@pmJornada,HorasDia=@pmHorasDia,Rangos=@pmRangos,Inactivo=@pmInactivo,TurnoRotativo=@pmTurnoRotativo
 WHERE IdJornada=@pmIdJornada
GO
/****** Object:  StoredProcedure [dbo].[paUpJurActas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurActas] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumActa VARCHAR(20),@pmFechaActa SMALLDATETIME,@pmModalidad VARCHAR(10),@pmValorTotal MONEY,@pmReferencia VARCHAR(50),@pmEstadoPror INT,@pmTipPror VARCHAR(3),@pmNumPror INT,@pmIdCiaPror CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFechaDev SMALLDATETIME,@pmObservacion VARCHAR(500)
 AS 
 UPDATE Trn_JurActas SET Fecha=@pmFecha,NumActa=@pmNumActa,FechaActa=@pmFechaActa,Modalidad=@pmModalidad,ValorTotal=@pmValorTotal,Referencia=@pmReferencia,EstadoPror=@pmEstadoPror,TipPror=@pmTipPror,NumPror=@pmNumPror,IdCiaPror=@pmIdCiaPror,Anulado=@pmAnulado,NumDev=@pmNumDev,FechaDev=@pmFechaDev,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurAutoridades]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurAutoridades] @pmIdAutoridad VARCHAR(4),@pmNomAutoridad VARCHAR(50),@pmDireccion VARCHAR(100),@pmInactivo BIT
 AS 
 UPDATE JurAutoridades SET NomAutoridad=@pmNomAutoridad,Direccion=@pmDireccion,Inactivo=@pmInactivo
 WHERE IdAutoridad=@pmIdAutoridad
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCalifica]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurCalifica] @pmIdCalifica VARCHAR(4),@pmCalificaCaso VARCHAR(50),@pmIdClase VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE JurCalifica SET CalificaCaso=@pmCalificaCaso,IdClase=@pmIdClase,Inactivo=@pmInactivo
 WHERE IdCalifica=@pmIdCalifica
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurCasos] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmRadicacion VARCHAR(20),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmSinRecorrido BIT,@pmTipCar VARCHAR(3),@pmCartulina INT,@pmIdCiaCar CHAR(2),@pmFechaSuc SMALLDATETIME,@pmIdRuta VARCHAR(4),@pmIdAbogado VARCHAR(16),@pmIdAuxiliar VARCHAR(16),@pmIdAutoridad VARCHAR(4),@pmIdTipoPro VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdCalifica VARCHAR(4),@pmLugarAcc VARCHAR(100),@pmCausaAcc VARCHAR(3300)
,@pmComentario VARCHAR(3300),@pmObservacion VARCHAR(250),@pmContraparte VARCHAR(100),@pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20),@pmValDanosCParte MONEY,@pmValDanosEmp MONEY,@pmValDeducible MONEY,@pmEmpAsegdora VARCHAR(100),@pmAuxMutuo BIT,@pmArchivoCaso VARCHAR(100),@pmDocumntos VARCHAR(250),@pmCroquis VARCHAR(20),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmReclamaciones VARCHAR(1000)
,@pmCdCausal VARCHAR(4),@pmCedtraparte VARCHAR(16),@pmPolizaResCivil VARCHAR(30),@pmVigencResCivil SMALLDATETIME,@pmNitEmpAseg VARCHAR(16),@pmNombreAseg VARCHAR(150),@pmUndVehiculo CHAR(1),@pmNumRemolque VARCHAR(10),@pmTipActaJur VARCHAR(3),@pmNumActaJur INT,@pmCiaActaJur CHAR(2),@pmEstadoProc INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_JurCasos SET Fecha=@pmFecha,Radicacion=@pmRadicacion,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor,SinRecorrido=@pmSinRecorrido,TipCar=@pmTipCar,Cartulina=@pmCartulina,IdCiaCar=@pmIdCiaCar,FechaSuc=@pmFechaSuc,IdRuta=@pmIdRuta,IdAbogado=@pmIdAbogado,IdAuxiliar=@pmIdAuxiliar,IdAutoridad=@pmIdAutoridad,IdTipoPro=@pmIdTipoPro,IdClase=@pmIdClase,IdCalifica=@pmIdCalifica,LugarAcc=@pmLugarAcc,CausaAcc=@pmCausaAcc,Comentario=@pmComentario,Observacion=@pmObservacion,Contraparte=@pmContraparte,DirContraparte=@pmDirContraparte
,TelContraparte=@pmTelContraparte,ValDanosCParte=@pmValDanosCParte,ValDanosEmp=@pmValDanosEmp,ValDeducible=@pmValDeducible,EmpAsegdora=@pmEmpAsegdora,AuxMutuo=@pmAuxMutuo,ArchivoCaso=@pmArchivoCaso,Documntos=@pmDocumntos,Croquis=@pmCroquis,Anulado=@pmAnulado,FecDev=@pmFecDev,Reclamaciones=@pmReclamaciones,IdEstado=@pmIdEstado,UndVehiculo=@pmUndVehiculo,NumRemolque=@pmNumRemolque,TipActaJur=@pmTipActaJur,NumActaJur=@pmNumActaJur,CiaActaJur=@pmCiaActaJur,EstadoProc=@pmEstadoProc,FecUpdate=@pmFecUpdate
,CdCausal=@pmCdCausal,Cedtraparte=@pmCedtraparte,PolizaResCivil=@pmPolizaResCivil,VigencResCivil=@pmVigencResCivil,NitEmpAseg=@pmNitEmpAseg,NombreAseg=@pmNombreAseg
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurCasosAnu] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2), @pmAnulado BIT, @pmFecDev SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmObservacion VARCHAR(250)
AS 
 UPDATE Trn_JurCasos SET  Anulado=@pmAnulado, FecDev=@pmFecDev,IdEstado=@pmIdEstado
 ,Observacion=ISNULL(@pmObservacion,Observacion)
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosCie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurCasosCie] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2),@pmIdEstado VARCHAR(4)
,@pmObservacion VARCHAR(250),@pmArchivoCaso VARCHAR(100),@pmFecUpdate SMALLDATETIME
AS 
 UPDATE Trn_JurCasos SET IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Observacion=ISNULL(@pmObservacion,Observacion)
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosCpt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurCasosCpt] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2),@pmContraparte VARCHAR(100), @pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20)
,@pmValDanosCParte MONEY,@pmValDanosEmp MONEY, @pmValDeducible MONEY, @pmEmpAsegdora VARCHAR(100), @pmAuxMutuo BIT, @pmArchivoCaso VARCHAR(100),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
,@pmCedtraparte VARCHAR(16)
AS 
 UPDATE Trn_JurCasos SET  Contraparte=@pmContraparte, DirContraparte=@pmDirContraparte,TelContraparte=@pmTelContraparte,ValDanosCParte=@pmValDanosCParte, ValDanosEmp=@pmValDanosEmp, ValDeducible=@pmValDeducible
, EmpAsegdora=@pmEmpAsegdora, AuxMutuo=@pmAuxMutuo,Cedtraparte=@pmCedtraparte,FecUpdate=@pmFecUpdate,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID  AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosHis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurCasosHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT,@pmFechaUp SMALLDATETIME,@pmHistorial VARCHAR(3500),@pmEstadoAct VARCHAR(3500),@pmCierreProc BIT,@pmArchivoProc VARCHAR(100),@pmNombreCparte VARCHAR(100),@pmDirCparte VARCHAR(100),@pmTelCparte VARCHAR(20),@pmDanosCParte MONEY,@pmDanosEmp MONEY,@pmValorDeducible MONEY,@pmAseguradora VARCHAR(100)
,@pmAuxilioMutuo BIT,@pmIdEstado VARCHAR(4),@pmCedContparte VARCHAR(16)
 AS 
 UPDATE Trn_JurCasosHis SET FechaUp=@pmFechaUp,Historial=@pmHistorial,EstadoAct=@pmEstadoAct,CierreProc=@pmCierreProc,ArchivoProc=@pmArchivoProc,NombreCparte=@pmNombreCparte,DirCparte=@pmDirCparte,TelCparte=@pmTelCparte,DanosCParte=@pmDanosCParte,DanosEmp=@pmDanosEmp,ValorDeducible=@pmValorDeducible,Aseguradora=@pmAseguradora,AuxilioMutuo=@pmAuxilioMutuo,IdEstado=@pmIdEstado,CedContparte=@pmCedContparte
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia AND ActualizaID=@pmActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCasosVal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurCasosVal] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2),@pmValDanosCParte MONEY,@pmValDanosEmp MONEY, @pmValDeducible MONEY
, @pmEmpAsegdora VARCHAR(100), @pmAuxMutuo BIT,@pmArchivoCaso VARCHAR(100)
AS 
 UPDATE Trn_JurCasos SET  ValDanosCParte=ISNULL(@pmValDanosCParte,ValDanosCParte), ValDanosEmp=ISNULL(@pmValDanosEmp,ValDanosEmp), ValDeducible=ISNULL(@pmValDeducible,ValDeducible)
, EmpAsegdora=ISNULL(@pmEmpAsegdora,EmpAsegdora) , AuxMutuo=ISNULL(@pmAuxMutuo,AuxMutuo)
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID  AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurCausales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurCausales] @pmIdCausal VARCHAR(4),@pmCausal VARCHAR(50),@pmIdTipoPro VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE JurCausales SET Causal=@pmCausal,IdTipoPro=@pmIdTipoPro,Inactivo=@pmInactivo
 WHERE IdCausal=@pmIdCausal
GO
/****** Object:  StoredProcedure [dbo].[paUpJurClaseAcc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurClaseAcc] @pmIdClase VARCHAR(4),@pmClaseAccdte VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE JurClaseAcc SET ClaseAccdte=@pmClaseAccdte,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpJurDocumtos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurDocumtos] @pmIdDoc VARCHAR(4),@pmDocumnto VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE JurDocumtos SET Documnto=@pmDocumnto,Inactivo=@pmInactivo
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpJurEstados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmInactivo BIT,@pmNColor INT
 AS 
 UPDATE JurEstados SET Estado=@pmEstado,Inactivo=@pmInactivo,NColor=@pmNColor
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvesHis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurInvesHis] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmActualizaID INT,@pmFechaUp SMALLDATETIME,@pmHistorial VARCHAR(3000),@pmEstadoAct VARCHAR(3000),@pmPruebas VARCHAR(1200),@pmDocumntos VARCHAR(250)
,@pmCierreProc BIT,@pmArchivoProc VARCHAR(100),@pmNombreCparte VARCHAR(100),@pmDirCparte VARCHAR(100),@pmTelCparte VARCHAR(20),@pmCedContparte VARCHAR(16),@pmIdEstado VARCHAR(4) 
 AS 
 UPDATE Trn_JurInvesHis SET FechaUp=@pmFechaUp,Historial=@pmHistorial,EstadoAct=@pmEstadoAct,Pruebas=@pmPruebas,Documntos=@pmDocumntos,CierreProc=@pmCierreProc,ArchivoProc=@pmArchivoProc,NombreCparte=@pmNombreCparte,DirCparte=@pmDirCparte
,TelCparte=@pmTelCparte,CedContparte=@pmCedContparte,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia AND ActualizaID=@pmActualizaID
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestiga]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurInvestiga] @pmTipDoc VARCHAR(3),@pmCasoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmRadicacion VARCHAR(20),@pmIdAbogado VARCHAR(16),@pmIdAuxiliar VARCHAR(16),@pmIdAutoridad VARCHAR(4),@pmIdEmpresa VARCHAR(16)
,@pmObservacion VARCHAR(250),@pmContraparte VARCHAR(100),@pmDirContraparte VARCHAR(100),@pmTelContraparte VARCHAR(20),@pmArchivoCaso VARCHAR(100),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4)
,@pmCedtraparte VARCHAR(16),@pmCdTipoPro VARCHAR(4),@pmCdCausal VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_JurInvestiga SET Fecha=@pmFecha,Radicacion=@pmRadicacion,IdAbogado=@pmIdAbogado,IdAuxiliar=@pmIdAuxiliar,IdAutoridad=@pmIdAutoridad,IdEmpresa=@pmIdEmpresa,Observacion=@pmObservacion,Contraparte=@pmContraparte,DirContraparte=@pmDirContraparte,TelContraparte=@pmTelContraparte
,ArchivoCaso=@pmArchivoCaso,Anulado=@pmAnulado,FecDev=@pmFecDev,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Cedtraparte=@pmCedtraparte,CdTipoPro=@pmCdTipoPro,CdCausal=@pmCdCausal
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestigaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurInvestigaAnu] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2), @pmAnulado BIT, @pmFecDev SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmObservacion VARCHAR(250)
AS 
 UPDATE Trn_JurInvestiga SET  Anulado=@pmAnulado, FecDev=@pmFecDev,IdEstado=@pmIdEstado
 ,Observacion=ISNULL(@pmObservacion,Observacion)
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestigaCie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurInvestigaCie] @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2),@pmIdEstado VARCHAR(4)
,@pmObservacion VARCHAR(250),@pmArchivoCaso VARCHAR(100),@pmFecUpdate SMALLDATETIME
AS 
 UPDATE Trn_JurInvestiga SET IdEstado=@pmIdEstado, FecUpdate=@pmFecUpdate,Observacion=ISNULL(@pmObservacion,Observacion)
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurInvestigaCpt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpJurInvestigaCpt]  @pmTipDoc VARCHAR(3), @pmCasoID INT, @pmIdCia CHAR(2),@pmContraparte VARCHAR(100), @pmDirContraparte VARCHAR(100), @pmTelContraparte VARCHAR(20)
,@pmArchivoCaso VARCHAR(100),@pmIdEstado VARCHAR(4), @pmFecUpdate SMALLDATETIME,@pmCedtraparte VARCHAR(16)
AS
 UPDATE  Trn_JurInvestiga  SET Contraparte=@pmContraparte, DirContraparte=@pmDirContraparte,TelContraparte=@pmTelContraparte
,Cedtraparte=@pmCedtraparte,IdEstado=ISNULL(@pmIdEstado,IdEstado),FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND CasoID=@pmCasoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurPreguntas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurPreguntas] @pmIdPregunta VARCHAR(4),@pmPreguntaBas VARCHAR(250),@pmIdTipoPro VARCHAR(4),@pmTipoDato VARCHAR(15),@pmInactivo BIT
 AS 
 UPDATE JurPreguntas SET PreguntaBas=@pmPreguntaBas,IdTipoPro=@pmIdTipoPro,TipoDato=@pmTipoDato,Inactivo=@pmInactivo
 WHERE IdPregunta=@pmIdPregunta
GO
/****** Object:  StoredProcedure [dbo].[paUpJurReclamac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurReclamac] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaRec SMALLDATETIME,@pmTipSin VARCHAR(3),@pmSiniestro INT,@pmIdCiaSin CHAR(2),@pmIdReclamnte VARCHAR(16)
,@pmIdTipoRec VARCHAR(4),@pmVrReclamac MONEY,@pmObservacion VARCHAR(1000)
 AS 
 UPDATE Trn_JurReclamac SET Fecha=@pmFecha,FechaRec=@pmFechaRec,TipSin=@pmTipSin,Siniestro=@pmSiniestro,IdCiaSin=@pmIdCiaSin,IdReclamnte=@pmIdReclamnte,IdTipoRec=@pmIdTipoRec,VrReclamac=@pmVrReclamac,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND Reclamac=@pmReclamac AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpJurRecOfrecmto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpJurRecOfrecmto] @pmTipDoc VARCHAR(3),@pmReclamac INT,@pmIdCia CHAR(2),@pmItem INT,@pmFechaOfrec SMALLDATETIME,@pmVrOfrecmto MONEY,@pmOfcAceptado INT
,@pmFecAceptado SMALLDATETIME,@pmOfcPagado INT,@pmNumSolGiro VARCHAR(30),@pmComentarios VARCHAR(1000)
 AS 
 UPDATE Trn_JurRecOfrecmto SET FechaOfrec=@pmFechaOfrec,VrOfrecmto=@pmVrOfrecmto,OfcAceptado=@pmOfcAceptado,FecAceptado=@pmFecAceptado,OfcPagado=@pmOfcPagado
,NumSolGiro=@pmNumSolGiro,Comentarios=@pmComentarios
 WHERE TipDoc=@pmTipDoc AND Reclamac=@pmReclamac AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpJurTipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurTipos] @pmIdTipoPro VARCHAR(4),@pmTipoProceso VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE JurTipos SET TipoProceso=@pmTipoProceso,Inactivo=@pmInactivo
 WHERE IdTipoPro=@pmIdTipoPro
GO
/****** Object:  StoredProcedure [dbo].[paUpJurTiposRec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpJurTiposRec] @pmIdTipoRec VARCHAR(4),@pmTipReclamante VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE JurTiposRec SET TipReclamante=@pmTipReclamante,Inactivo=@pmInactivo
 WHERE IdTipoRec=@pmIdTipoRec
GO
/****** Object:  StoredProcedure [dbo].[paUpLineas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpLineas] @pmIdLinea VARCHAR(8),@pmLinea VARCHAR(150)
,@pmTipoInvent VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Lineas SET Linea=@pmLinea,Inactivo=@pmInactivo,TipoInvent=@pmTipoInvent
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paUpLineasCredCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpLineasCredCue] @pmIdLinea VARCHAR(4),@pmIdTipoTerc VARCHAR(4),@pmConcepto VARCHAR(10),@pmIdCuentaDb VARCHAR(16),@pmIdCuentaCr VARCHAR(16)
 AS 
 UPDATE LineasCredCue SET IdCuentaDb=@pmIdCuentaDb,IdCuentaCr=@pmIdCuentaCr
 WHERE IdLinea=@pmIdLinea AND IdTipoTerc=@pmIdTipoTerc AND Concepto=@pmConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpLocalidades]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpLocalidades] @pmIdLocal VARCHAR(8),@pmLocalidad VARCHAR(50),@pmIdDep VARCHAR(8),@pmTipLocal VARCHAR(20)
,@pmDist_Kmt DECIMAL(10,4),@pmTime_hh VARCHAR(8),@pmCelRow DECIMAL(14,4),@pmCelCol DECIMAL(14,4),@pmInactivo BIT
,@pmDistSede DECIMAL(10,4),@pmTimeSede VARCHAR(8),@pmCodAlias VARCHAR(10)
 AS 
 UPDATE Localidades SET Localidad=@pmLocalidad,IdDep=@pmIdDep,TipLocal=@pmTipLocal,Dist_Kmt=@pmDist_Kmt,Time_hh=@pmTime_hh,CelRow=@pmCelRow
,CelCol=@pmCelCol,Inactivo=@pmInactivo,DistSede=@pmDistSede,TimeSede=@pmTimeSede,CodAlias=@pmCodAlias
 WHERE IdLocal=@pmIdLocal
GO
/****** Object:  StoredProcedure [dbo].[paUpLog_Nomina]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpLog_Nomina] @pmIdNom VARCHAR(4),@pmIdPeriodo VARCHAR(8),@pmCerrado BIT
,@pmIntCtaCte BIT,@pmLogCtaCte VARCHAR(100)
 AS 
 UPDATE Log_Nomina SET Cerrado=@pmCerrado,IntCtaCte=@pmIntCtaCte,LogCtaCte=@pmLogCtaCte
 WHERE IdNom=@pmIdNom AND IdPeriodo=@pmIdPeriodo
GO
/****** Object:  StoredProcedure [dbo].[paUpLog_Periodos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpLog_Periodos]  @pmAnno INT,@pmIdCia CHAR(2),@pmnMes INT,@pmLock BIT
AS
 IF @pmnMes=1
  UPDATE Log_Periodos  SET  Ene=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=2
  UPDATE Log_Periodos SET Feb=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=3
  UPDATE Log_Periodos SET  Mar=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=4
  UPDATE Log_Periodos SET  Abr=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=5
  UPDATE Log_Periodos SET  May=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=6
  UPDATE Log_Periodos SET Jun=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=7
  UPDATE Log_Periodos SET Jul=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=8
  UPDATE Log_Periodos  SET Ago=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=9
  UPDATE Log_Periodos  SET Sep=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=10
  UPDATE Log_Periodos  SET  Oct=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=11
  UPDATE Log_Periodos  SET  Nov=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=12
  UPDATE Log_Periodos  SET  Dic=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 IF @pmnMes=13
  UPDATE Log_Periodos  SET  CierreAnno=@pmLock WHERE Anno=@pmAnno AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUpLotes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpLotes] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10)
,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmSaldoActual DECIMAL(14,4),@pmNitProv VARCHAR(16),@pmTipDoc VARCHAR(3),@pmEntrada INT
 AS 
 UPDATE Trn_Lotes SET Fecha=@pmFecha,FecVence=@pmFecVence,SaldoActual=@pmSaldoActual,NitProv=@pmNitProv,TipDoc=@pmTipDoc,Entrada=@pmEntrada
 WHERE NumLote=@pmNumLote AND IdProducto=@pmIdProducto AND IdCia=@pmIdCia AND IdBodega=@pmIdBodega AND IdUbic=@pmIdUbic
GO
/****** Object:  StoredProcedure [dbo].[paUpLotesCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpLotesCero] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16)
,@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4)
 AS 
 UPDATE Trn_Lotes SET SaldoActual=0
 WHERE NumLote LIKE ISNULL(@pmNumLote,'%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpLotesSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpLotesSal] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16)
,@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4)
 AS 
 UPDATE Trn_Lotes SET SaldoActual=(SELECT ISNULL(SUM(Entradas-Salidas),0)
 FROM  Trn_LotMov 
 WHERE Trn_Lotes.NumLote=Trn_LotMov.NumLote AND Trn_Lotes.IdProducto=Trn_LotMov.IdProducto AND Trn_Lotes.IdBodega=Trn_LotMov.IdBodega
 AND Trn_Lotes.IdCia=Trn_LotMov.IdCia  AND Trn_Lotes.IdUbic=Trn_LotMov.CdUbic)
 WHERE NumLote LIKE ISNULL(@pmNumLote,'%') AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdBodega LIKE ISNULL(@pmIdBodega,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpLotesSdo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpLotesSdo] @pmNumLote VARCHAR(30),@pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10)
,@pmSaldoActual DECIMAL(14,4)
 AS 
 UPDATE Trn_Lotes SET SaldoActual=@pmSaldoActual
 WHERE NumLote=@pmNumLote AND IdProducto=@pmIdProducto AND IdCia=@pmIdCia AND IdBodega=@pmIdBodega
 AND IdUbic LIKE ISNULL(@pmIdUbic,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpMarcas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMarcas] @pmIdMarca VARCHAR(4),@pmMarca VARCHAR(50),@pmTipoMarca VARCHAR(20)
,@pmCodigoMT VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Marcas SET Marca=@pmMarca,TipoMarca=@pmTipoMarca,CodigoMT=@pmCodigoMT,Inactivo=@pmInactivo
 WHERE IdMarca=@pmIdMarca
GO
/****** Object:  StoredProcedure [dbo].[paUpMarcasLin]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMarcasLin] @pmIdLinea VARCHAR(10),@pmLineaVeh VARCHAR(50),@pmIdMarca VARCHAR(4)
,@pmCodMT VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE MarcasLin SET LineaVeh=@pmLineaVeh,IdMarca=@pmIdMarca,CodMT=@pmCodMT,Inactivo=@pmInactivo
 WHERE IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paUpMayAnotaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayAnotaciones] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmDetalle VARCHAR(5000),@pmIdUsuario VARCHAR(11)
 AS 
 UPDATE Trn_MayAnotaciones SET Fecha=@pmFecha,Detalle=@pmDetalle,IdUsuario=@pmIdUsuario
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMayBonCuentas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayBonCuentas] @pmIdBonif VARCHAR(4),@pmTipoCue INT
,@pmCdTipo VARCHAR(4),@pmIdCuenta VARCHAR(16)
 AS 
 UPDATE MayBonCuentas SET IdCuenta=@pmIdCuenta
 WHERE IdBonif=@pmIdBonif AND TipoCue=@pmTipoCue AND CdTipo=@pmCdTipo
GO
/****** Object:  StoredProcedure [dbo].[paUpMayBonif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayBonif] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoProd VARCHAR(20),@pmVrInicial DECIMAL(14,4),@pmVrFinal DECIMAL(14,4),@pmUnidad VARCHAR(10)
,@pmTarifa DECIMAL(14,4),@pmTipoTarifa CHAR(1),@pmPeriodo VARCHAR(10),@pmCdProducto VARCHAR(16),@pmCdSubgrupo VARCHAR(8)
,@pmTipoMargen CHAR(1),@pmIntvExcluido BIT,@pmIntvGlobal BIT,@pmIvaIncluido BIT
 AS 
 UPDATE Trn_MayBonif SET TipoProd=@pmTipoProd,VrInicial=@pmVrInicial,VrFinal=@pmVrFinal,Unidad=@pmUnidad,Tarifa=@pmTarifa,TipoTarifa=@pmTipoTarifa
,Periodo=@pmPeriodo,CdProducto=@pmCdProducto,CdSubgrupo=@pmCdSubgrupo,TipoMargen=@pmTipoMargen,IntvExcluido=@pmIntvExcluido,IntvGlobal=@pmIntvGlobal,IvaIncluido=@pmIvaIncluido
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayContDoc] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdDoc VARCHAR(4),@pmFechaRad SMALLDATETIME
,@pmDependencia VARCHAR(50),@pmEstado VARCHAR(10),@pmFechaAprob SMALLDATETIME,@pmComentarios VARCHAR(250),@pmCdUsuario VARCHAR(11)
 AS 
 UPDATE Trn_MayContDoc SET IdDoc=@pmIdDoc,FechaRad=@pmFechaRad,Dependencia=@pmDependencia,Estado=@pmEstado
,FechaAprob=@pmFechaAprob,Comentarios=@pmComentarios,CdUsuario=@pmCdUsuario
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContratos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayContratos] @pmNContrato INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdTipo VARCHAR(4),@pmIdBonif VARCHAR(4),@pmConvBonif BIT
,@pmCuotaFija BIT,@pmCondPago BIT,@pmDiasGracia INT,@pmModPlazo VARCHAR(10),@pmPlazo INT,@pmFechaVence SMALLDATETIME,@pmModRecursos VARCHAR(150),@pmVrInversion MONEY,@pmVrInventario MONEY,@pmVrCuota MONEY
,@pmModCuota VARCHAR(10),@pmIdBandera VARCHAR(4),@pmAprobJunta INT,@pmFechaAprob SMALLDATETIME,@pmObservAprob VARCHAR(250),@pmObservacion VARCHAR(250),@pmIdVend VARCHAR(16),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
,@pmFechaInicio SMALLDATETIME,@pmCuotaMin DECIMAL(14,4),@pmTipoAprob VARCHAR(10),@pmNumInterno VARCHAR(20),@pmInvCombus DECIMAL(14,4),@pmCuotaBase DECIMAL(14,4),@pmFechaFirma SMALLDATETIME,@pmCdAprobNeg VARCHAR(4),@pmArchivoAprob VARCHAR(50)
,@pmClaseContrato VARCHAR(10),@pmDescTipoCont VARCHAR(250),@pmGarantHipoteca BIT,@pmGarantPrenda BIT,@pmGarantPoliza BIT,@pmGarantBanco BIT,@pmGarantPagare BIT,@pmGarantOtro BIT,@pmCdTipoBien VARCHAR(4),@pmVrAvaludo MONEY,@pmNroEscritura VARCHAR(50)
,@pmCdTipoPoliza VARCHAR(4),@pmDescPoliza VARCHAR(150),@pmVigencPoliza INT,@pmFecVencPoliza SMALLDATETIME,@pmValorPoliza MONEY,@pmEdoGarantias INT,@pmDescGarantOtro VARCHAR(250),@pmInverContab INT,@pmInverContrac INT,@pmVolContMes DECIMAL(14,4)
,@pmVolContTotal DECIMAL(14,4),@pmVolViabMes DECIMAL(14,4),@pmVolViabTotal DECIMAL(14,4),@pmInvCtbObra MONEY,@pmInvCtbCapital MONEY,@pmInvCtbEfectivo MONEY,@pmInvCtbImagen MONEY,@pmInvCtbMntmto MONEY,@pmFecDesemb SMALLDATETIME,@pmInvContObra MONEY
,@pmInvContCapital MONEY,@pmInvContEfectivo MONEY,@pmInvContImagen MONEY,@pmCrtlAprovInv INT,@pmCrtlAprovImg INT,@pmCdTipoBloq VARCHAR(4),@pmEdoDocmtos INT,@pmDescEdoDoc VARCHAR(250),@pmRentabInicial DECIMAL(14,4),@pmGraciaBonif INT
,@pmActFechaIni INT,@pmCdZonaCont VARCHAR(4),@pmContVigente BIT,@pmVolContrac INT,@pmDescHipotec VARCHAR(250),@pmVrAvaComerc MONEY,@pmFecRegEscritura SMALLDATETIME,@pmNotariaEsc VARCHAR(50),@pmCdTipPrenda VARCHAR(4),@pmVrAvaPrenda MONEY
,@pmPolizaPrenda VARCHAR(30),@pmFecVigPrenda SMALLDATETIME,@pmVrAsegPrenda MONEY,@pmContOperando BIT
 AS 
 UPDATE Trn_MayContratos SET Fecha=@pmFecha,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdTipo=@pmIdTipo,IdBonif=@pmIdBonif,ConvBonif=@pmConvBonif,CuotaFija=@pmCuotaFija,CondPago=@pmCondPago,DiasGracia=@pmDiasGracia
,ModPlazo=@pmModPlazo,Plazo=@pmPlazo,FechaVence=@pmFechaVence,ModRecursos=@pmModRecursos,VrInversion=@pmVrInversion,VrInventario=@pmVrInventario,VrCuota=@pmVrCuota,ModCuota=@pmModCuota,IdBandera=@pmIdBandera
,AprobJunta=@pmAprobJunta,FechaAprob=@pmFechaAprob,ObservAprob=@pmObservAprob,Observacion=@pmObservacion,IdEstado=@pmIdEstado,IdVend=@pmIdVend,FechaInicio=@pmFechaInicio,CuotaMin=@pmCuotaMin,TipoAprob=@pmTipoAprob
,NumInterno=@pmNumInterno,InvCombus=@pmInvCombus,CuotaBase=@pmCuotaBase,FecUpdate=@pmFecUpdate
,FechaFirma=@pmFechaFirma,CdAprobNeg=@pmCdAprobNeg,ArchivoAprob=@pmArchivoAprob,ClaseContrato=@pmClaseContrato,DescTipoCont=@pmDescTipoCont,GarantHipoteca=@pmGarantHipoteca,GarantPrenda=@pmGarantPrenda,GarantPoliza=@pmGarantPoliza,GarantBanco=@pmGarantBanco
,GarantPagare=@pmGarantPagare,GarantOtro=@pmGarantOtro,CdTipoBien=@pmCdTipoBien,VrAvaludo=@pmVrAvaludo,NroEscritura=@pmNroEscritura,CdTipoPoliza=@pmCdTipoPoliza,DescPoliza=@pmDescPoliza,VigencPoliza=@pmVigencPoliza,FecVencPoliza=@pmFecVencPoliza,ValorPoliza=@pmValorPoliza
,EdoGarantias=@pmEdoGarantias,DescGarantOtro=@pmDescGarantOtro,InverContab=@pmInverContab,InverContrac=@pmInverContrac,VolContMes=@pmVolContMes,VolContTotal=@pmVolContTotal,VolViabMes=@pmVolViabMes,VolViabTotal=@pmVolViabTotal,InvCtbObra=@pmInvCtbObra
,InvCtbCapital=@pmInvCtbCapital,InvCtbEfectivo=@pmInvCtbEfectivo,InvCtbImagen=@pmInvCtbImagen,InvCtbMntmto=@pmInvCtbMntmto,FecDesemb=@pmFecDesemb,InvContObra=@pmInvContObra,InvContCapital=@pmInvContCapital,InvContEfectivo=@pmInvContEfectivo,InvContImagen=@pmInvContImagen,CrtlAprovInv=@pmCrtlAprovInv
,CrtlAprovImg=@pmCrtlAprovImg,CdTipoBloq=@pmCdTipoBloq,EdoDocmtos=@pmEdoDocmtos,DescEdoDoc=@pmDescEdoDoc,RentabInicial=@pmRentabInicial,GraciaBonif=@pmGraciaBonif,ActFechaIni=@pmActFechaIni,CdZonaCont=@pmCdZonaCont,ContVigente=@pmContVigente,VolContrac=@pmVolContrac
,DescHipotec=@pmDescHipotec,VrAvaComerc=@pmVrAvaComerc,FecRegEscritura=@pmFecRegEscritura,NotariaEsc=@pmNotariaEsc,CdTipPrenda=@pmCdTipPrenda,VrAvaPrenda=@pmVrAvaPrenda,PolizaPrenda=@pmPolizaPrenda,FecVigPrenda=@pmFecVigPrenda,VrAsegPrenda=@pmVrAsegPrenda,ContOperando=@pmContOperando
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContratosApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayContratosApr] @pmNContrato INT,@pmIdCia CHAR(2),@pmAprobJunta INT
,@pmFechaAprob SMALLDATETIME,@pmObservAprob VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmTipoAprob VARCHAR(10),@pmCdAprobNeg VARCHAR(4),@pmArchivoAprob VARCHAR(50)

 AS 
 UPDATE Trn_MayContratos SET AprobJunta=@pmAprobJunta,FechaAprob=@pmFechaAprob
,ObservAprob=@pmObservAprob,IdEstado=@pmIdEstado,TipoAprob=@pmTipoAprob
,CdAprobNeg=@pmCdAprobNeg,ArchivoAprob=@pmArchivoAprob
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMayContratosEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayContratosEst] @pmNContrato INT,@pmIdCia CHAR(2),@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME,@pmCdTipoBloq VARCHAR(4)
 AS 
 UPDATE Trn_MayContratos SET  IdEstado=@pmIdEstado,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate
,CdTipoBloq=@pmCdTipoBloq
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMayEstados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50)
,@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE MayEstados SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpMayInventario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayInventario] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdArticulo VARCHAR(16),@pmDetalle VARCHAR(150),@pmCantidad DECIMAL(14,4)
,@pmVrUnitario MONEY,@pmVrTotal MONEY,@pmTipoArticulo VARCHAR(10),@pmReferencia VARCHAR(50),@pmIdTipo VARCHAR(4),@pmTipDoc VARCHAR(3),@pmDocumento INT
,@pmIdCiaDoc CHAR(2),@pmCantEntrega DECIMAL(14,4),@pmFecEntrega SMALLDATETIME,@pmEstado VARCHAR(10),@pmCdProd VARCHAR(16),@pmNumReq INT,@pmIdCiaReq CHAR(2)
,@pmCantReq DECIMAL(14,4),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmCantOrden DECIMAL(14,4)
 AS 
 UPDATE Trn_MayInventario SET IdArticulo=@pmIdArticulo,Detalle=@pmDetalle,Cantidad=@pmCantidad,VrUnitario=@pmVrUnitario,VrTotal=@pmVrTotal,TipoArticulo=@pmTipoArticulo
,Referencia=@pmReferencia,IdTipo=@pmIdTipo,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,CantEntrega=@pmCantEntrega,FecEntrega=@pmFecEntrega,Estado=@pmEstado
,CdProd=@pmCdProd,NumReq=@pmNumReq,IdCiaReq=@pmIdCiaReq,CantReq=@pmCantReq,NumOrden=@pmNumOrden,IdCiaOrd=@pmIdCiaOrd,CantOrden=@pmCantOrden
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMayItemsInv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayItemsInv] @pmIdArticulo VARCHAR(16),@pmDescrpcion VARCHAR(150)
,@pmUndMed VARCHAR(10),@pmGrupoArt VARCHAR(50),@pmCdProducto VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE MayItemsInv SET Descrpcion=@pmDescrpcion,UndMed=@pmUndMed,GrupoArt=@pmGrupoArt
,CdProducto=@pmCdProducto,Inactivo=@pmInactivo
 WHERE IdArticulo=@pmIdArticulo
GO
/****** Object:  StoredProcedure [dbo].[paUpMayLiqTotalesNcr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayLiqTotalesNcr] @pmNLiquida INT,@pmIdCia CHAR(2),@pmItem INT
,@pmNotaCred INT,@pmIdCiaNot CHAR(2)
 AS 
 UPDATE Trn_MayLiqTotales SET  NotaCred=@pmNotaCred,IdCiaNot=@pmIdCiaNot
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMayLiquidaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayLiquidaAnu] @pmNLiquida INT,@pmIdCia CHAR(2)
,@pmEstado INT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_MayLiquida SET Estado=@pmEstado,FecDev=@pmFecDev
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMayLiquidaCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayLiquidaCmp] @pmNLiquida INT,@pmIdCia CHAR(2)
,@pmEstado INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
 AS 
 UPDATE Trn_MayLiquida SET TipCom=@pmTipCom,Comprobante=@pmComprobante
 ,IdCiaCom=@pmIdCiaCom,Estado=@pmEstado
 WHERE NLiquida=@pmNLiquida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMayPspto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayPspto] @pmNContrato INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipoProd VARCHAR(20),@pmCantidad DECIMAL(14,4)
,@pmUnidad VARCHAR(10),@pmCantMes DECIMAL(14,4),@pmCdProducto VARCHAR(16),@pmCdSubgrupo VARCHAR(8)
 AS 
 UPDATE Trn_MayPspto SET TipoProd=@pmTipoProd,Cantidad=@pmCantidad,Unidad=@pmUnidad,CantMes=@pmCantMes
,CdProducto=@pmCdProducto,CdSubgrupo=@pmCdSubgrupo
 WHERE NContrato=@pmNContrato AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayTipos] @pmIdTipo VARCHAR(4),@pmTipContrato VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MayTipos SET TipContrato=@pmTipContrato,Inactivo=@pmInactivo
 WHERE IdTipo=@pmIdTipo
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposAprob]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayTiposAprob] @pmIdAprob VARCHAR(4),@pmTipoAprob VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MayTiposAprob SET TipoAprob=@pmTipoAprob,Inactivo=@pmInactivo
 WHERE IdAprob=@pmIdAprob
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposBienes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayTiposBienes] @pmIdTipBien VARCHAR(4),@pmTipoBien VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MayTiposBienes SET TipoBien=@pmTipoBien,Inactivo=@pmInactivo
 WHERE IdTipBien=@pmIdTipBien
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposBonif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayTiposBonif] @pmIdBonif VARCHAR(4),@pmTipoBonif VARCHAR(50)
,@pmAboCartera BIT,@pmAboPstmo BIT,@pmInactivo BIT
 AS 
 UPDATE MayTiposBonif SET TipoBonif=@pmTipoBonif,Inactivo=@pmInactivo,AboCartera=@pmAboCartera
,AboPstmo=@pmAboPstmo
 WHERE IdBonif=@pmIdBonif
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpMayTiposDoc] @pmIdDoc VARCHAR(4),@pmNombreDoc VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE MayTiposDoc SET NombreDoc=@pmNombreDoc,Inactivo=@pmInactivo
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpMayTiposPoliza]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMayTiposPoliza] @pmIdTipoPol VARCHAR(4),@pmTipoPoliza VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MayTiposPoliza SET TipoPoliza=@pmTipoPoliza,Inactivo=@pmInactivo
 WHERE IdTipoPol=@pmIdTipoPol
GO
/****** Object:  StoredProcedure [dbo].[paUpMercancias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMercancias] @pmIdMercancia VARCHAR(16),@pmDescripMcia VARCHAR(250),@pmCodigoMcia VARCHAR(16),@pmIdGrupo VARCHAR(10),@pmUndMed VARCHAR(10),@pmIdUnd VARCHAR(4)
,@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmEstadoMcia VARCHAR(20),@pmContenedor BIT,@pmIdProducto VARCHAR(16)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmUmCapac VARCHAR(10),@pmCodigoUN VARCHAR(30),@pmUM_Prod VARCHAR(10),@pmCodArancel VARCHAR(5),@pmCodSubpartida VARCHAR(5),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Mercancias SET DescripMcia=@pmDescripMcia,CodigoMcia=@pmCodigoMcia,IdGrupo=@pmIdGrupo,UndMed=@pmUndMed,IdUnd=@pmIdUnd
,IdNat=@pmIdNat,IdMnjo=@pmIdMnjo,IdTmcia=@pmIdTmcia,Contenedor=@pmContenedor,IdProducto=@pmIdProducto,IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,IdEmp=@pmIdEmp,EstadoMcia=@pmEstadoMcia,UmCapac=@pmUmCapac,CodigoUN=@pmCodigoUN,UM_Prod=@pmUM_Prod,CodArancel=@pmCodArancel,CodSubpartida=@pmCodSubpartida,FechaUpdate=@pmFechaUpdate
 WHERE IdMercancia=@pmIdMercancia
GO
/****** Object:  StoredProcedure [dbo].[paUpModulos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpModulos] @pmIdMod VARCHAR(3),@pmConsecutivo INT,@pmDescripcion VARCHAR(50)
,@pmValor BIT,@pmnModulo VARCHAR(10)
 AS 
 IF @pmIdMod IS NULL
  UPDATE Sys_Modulos SET Valor=@pmValor WHERE nModulo LIKE ISNULL(@pmnModulo,'%')
 ELSE
  UPDATE Sys_Modulos SET Consecutivo=@pmConsecutivo,Descripcion=@pmDescripcion,Valor=@pmValor,nModulo=@pmnModulo
  WHERE IdMod=@pmIdMod
GO
/****** Object:  StoredProcedure [dbo].[paUpmonedas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpmonedas] @pmIdMneda VARCHAR(5),@pmMneda VARCHAR(50),@pmSimbolo VARCHAR(10)
,@pmMneLocal BIT,@pmVrCambio DECIMAL(12,6),@pmInactivo BIT
 AS 
 UPDATE adm_monedas SET Mneda=@pmMneda,Simbolo=@pmSimbolo,MneLocal=@pmMneLocal,VrCambio=@pmVrCambio,Inactivo=@pmInactivo
 WHERE IdMneda=@pmIdMneda
GO
/****** Object:  StoredProcedure [dbo].[paUpmonedasLoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpmonedasLoc] @pmMneLocal BIT,@pmIdMneda VARCHAR(5)
 AS 
 UPDATE adm_monedas SET MneLocal=@pmMneLocal
 WHERE IdMneda<>@pmIdMneda
GO
/****** Object:  StoredProcedure [dbo].[paUpmonedasTas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpmonedasTas] @pmIdMneda VARCHAR(5),@pmVrCambio DECIMAL(12,6)
 AS 
 UPDATE adm_monedas SET VrCambio=@pmVrCambio
 WHERE IdMneda=@pmIdMneda
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoConceptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoConceptos] @pmIdConc VARCHAR(4),@pmConcepto VARCHAR(150),@pmIdSistema VARCHAR(4),@pmIdMtto VARCHAR(4),@pmTipoControl INT
,@pmIntervalo_km INT,@pmIntervalo_dias INT,@pmReq_Parte BIT,@pmInactivo BIT,@pmCodigoMO VARCHAR(16),@pmIntervalo_Horas INT,@pmCantHoras DECIMAL(14,2)
,@pmTarifaCosto DECIMAL(16,4),@pmTarifaClie DECIMAL(16,4),@pmIntvAlarma VARCHAR(50)
 AS 
 UPDATE MttoConceptos SET Concepto=@pmConcepto,IdSistema=@pmIdSistema,IdMtto=@pmIdMtto,TipoControl=@pmTipoControl,Intervalo_km=@pmIntervalo_km
,Intervalo_dias=@pmIntervalo_dias,Req_Parte=@pmReq_Parte,Inactivo=@pmInactivo,CodigoMO=@pmCodigoMO,Intervalo_Horas=@pmIntervalo_Horas 
,CantHoras=@pmCantHoras,TarifaCosto=@pmTarifaCosto,TarifaClie=@pmTarifaClie,IntvAlarma=@pmIntvAlarma
 WHERE IdConc=@pmIdConc
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoControles]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoControles] @pmTipoUnidad CHAR(1),@pmNumUnidad VARCHAR(10),@pmIdConc VARCHAR(4),@pmTipoControl INT,@pmIntervalo_km INT,@pmIntervalo_dias INT,@pmIntervalo_Horas INT,@pmkmUltMtto INT,@pmkmUltMttoRuta INT
,@pmkmUltMttoSat INT,@pmFecUltMtto SMALLDATETIME,@pmComentarios VARCHAR(1000),@pmInactivo BIT,@pmHsUltMtto INT
 AS 
 UPDATE MttoControles SET TipoControl=@pmTipoControl,Intervalo_km=@pmIntervalo_km,Intervalo_dias=@pmIntervalo_dias,Intervalo_Horas=@pmIntervalo_Horas,kmUltMtto=@pmkmUltMtto,kmUltMttoRuta=@pmkmUltMttoRuta,kmUltMttoSat=@pmkmUltMttoSat,FecUltMtto=@pmFecUltMtto
,HsUltMtto=@pmHsUltMtto,Comentarios=@pmComentarios,Inactivo=@pmInactivo
 WHERE TipoUnidad=@pmTipoUnidad AND NumUnidad=@pmNumUnidad AND IdConc=@pmIdConc
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoEstados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE MttoEstados SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoInspecciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoInspecciones] @pmIdInspec VARCHAR(4),@pmInspeccion VARCHAR(150),@pmIdSistema VARCHAR(4),@pmIdMtto VARCHAR(4)
,@pmTipoDato INT,@pmUndMed VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MttoInspecciones SET Inspeccion=@pmInspeccion,IdSistema=@pmIdSistema,IdMtto=@pmIdMtto,TipoDato=@pmTipoDato,UndMed=@pmUndMed,Inactivo=@pmInactivo
 WHERE IdInspec=@pmIdInspec
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoOrden]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaOrden SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdTipoOdt VARCHAR(4),@pmIdCenSer VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmIdOperario VARCHAR(16),@pmIdSupervisor VARCHAR(16),@pmModalidad VARCHAR(10),@pmkmVehiculo INT,@pmkmRemolque INT,@pmVrServicios MONEY,@pmVrRepuestos MONEY,@pmVrManoObra MONEY,@pmVrOtros MONEY,@pmFechaCierre SMALLDATETIME
,@pmNitCenSer VARCHAR(16),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmCdEstadoVeh VARCHAR(4),@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmIdCiaFact CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_MttoOrden SET Fecha=@pmFecha,FechaOrden=@pmFechaOrden,FechaVence=@pmFechaVence,IdTipoOdt=@pmIdTipoOdt,IdCenSer=@pmIdCenSer,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,IdConductor=@pmIdConductor,IdOperario=@pmIdOperario,IdSupervisor=@pmIdSupervisor
,Modalidad=@pmModalidad,kmVehiculo=@pmkmVehiculo,kmRemolque=@pmkmRemolque,VrServicios=@pmVrServicios,VrRepuestos=@pmVrRepuestos,VrManoObra=@pmVrManoObra,VrOtros=@pmVrOtros,FechaCierre=@pmFechaCierre,NitCenSer=@pmNitCenSer,IdEstado=@pmIdEstado,CdEstadoVeh=@pmCdEstadoVeh
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,TipFact=@pmTipFact,NumFactura=@pmNumFactura,IdCiaFact=@pmIdCiaFact,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoOrdenAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoOrdenAnu] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
,@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000)
 AS 
 UPDATE Trn_MttoOrden SET IdEstado=@pmIdEstado,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoOrdenDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoOrdenDet] @pmTipOdt VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmFechaServ SMALLDATETIME,@pmIdConc VARCHAR(4),@pmDescripcion VARCHAR(1000)
,@pmCantidad DECIMAL(14,4),@pmVrUnitario DECIMAL(16,6),@pmUndMed VARCHAR(50),@pmCdMtto VARCHAR(4),@pmIdEstado VARCHAR(4)
,@pmIdOperario VARCHAR(16),@pmNumVehic VARCHAR(10),@pmNumParte VARCHAR(20),@pmReq_Rep BIT,@pmReq_MO BIT,@pmTipoServ VARCHAR(10),@pmCodCentro VARCHAR(4),@pmNitCenServ VARCHAR(16)
 AS 
 UPDATE Trn_MttoOrdenDet SET FechaServ=@pmFechaServ,IdConc=@pmIdConc,Descripcion=@pmDescripcion,Cantidad=@pmCantidad,VrUnitario=@pmVrUnitario,UndMed=@pmUndMed
,CdMtto=@pmCdMtto,IdEstado=@pmIdEstado,IdOperario=@pmIdOperario,NumVehic=@pmNumVehic,NumParte=@pmNumParte,Req_Rep=@pmReq_Rep,Req_MO=@pmReq_MO,TipoServ=@pmTipoServ
,CodCentro=@pmCodCentro,NitCenServ=@pmNitCenServ
 WHERE TipOdt=@pmTipOdt AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoSistemas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoSistemas] @pmIdSistema VARCHAR(4),@pmSistema VARCHAR(50),@pmSeccion CHAR(1),@pmInactivo BIT
 AS 
 UPDATE MttoSistemas SET Sistema=@pmSistema,Seccion=@pmSeccion,Inactivo=@pmInactivo
 WHERE IdSistema=@pmIdSistema
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoTipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoTipos] @pmIdMtto VARCHAR(4),@pmTipoMtto VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MttoTipos SET TipoMtto=@pmTipoMtto,Inactivo=@pmInactivo
 WHERE IdMtto=@pmIdMtto
GO
/****** Object:  StoredProcedure [dbo].[paUpMttoTiposOdt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMttoTiposOdt] @pmIdTipoOdt VARCHAR(4),@pmTipoOrden VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE MttoTiposOdt SET TipoOrden=@pmTipoOrden,Inactivo=@pmInactivo
 WHERE IdTipoOdt=@pmIdTipoOdt
GO
/****** Object:  StoredProcedure [dbo].[paUpMudArticulos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudArticulos] @pmIdArticulo VARCHAR(16),@pmArticulo VARCHAR(250),@pmIdSeccion VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE MudArticulos SET Articulo=@pmArticulo,IdSeccion=@pmIdSeccion,Inactivo=@pmInactivo
 WHERE IdArticulo=@pmIdArticulo
GO
/****** Object:  StoredProcedure [dbo].[paUpMudContratos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudContratos] @pmTipDoc VARCHAR(3),@pmNumContrato INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCdBodega2 VARCHAR(4),@pmVrServicio MONEY,@pmVrImpuesto MONEY,@pmVrDeclarado MONEY
,@pmVrSeguro MONEY,@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmFechaRetiro SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(30),@pmemlContacto VARCHAR(150),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_MudContratos SET Fecha=@pmFecha,FechaInicio=@pmFechaInicio,FechaFinal=@pmFechaFinal,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdBodega=@pmIdBodega,CdBodega2=@pmCdBodega2,VrServicio=@pmVrServicio,VrImpuesto=@pmVrImpuesto,VrDeclarado=@pmVrDeclarado,VrSeguro=@pmVrSeguro,TipOrden=@pmTipOrden,NumOrden=@pmNumOrden,IdCiaOrden=@pmIdCiaOrden
,FechaRetiro=@pmFechaRetiro,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NomContacto=@pmNomContacto,TelsContacto=@pmTelsContacto,emlContacto=@pmemlContacto,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumContrato=@pmNumContrato AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMudEstados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudEstados] @pmIdEstado VARCHAR(4),@pmEstado VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE MudEstados SET Estado=@pmEstado,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpMudInventario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudInventario] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdTipoServ VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirCargue VARCHAR(500),@pmTipoInmRem VARCHAR(30),@pmPisoCargue VARCHAR(10),@pmTelsRemite VARCHAR(30),@pmCelRemite VARCHAR(30),@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDescargue VARCHAR(500)
,@pmTipoInmDest VARCHAR(30),@pmPisoDescargue VARCHAR(10),@pmTelsDest VARCHAR(30),@pmCelDest VARCHAR(30),@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdVend VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmNitEmpresa VARCHAR(16),@pmNomEmpresa VARCHAR(150),@pmCajasEmp INT,@pmCajasClie INT,@pmVrDeclarado MONEY,@pmVrServicio MONEY,@pmNumCotizac VARCHAR(20),@pmNumPlanilla VARCHAR(20),@pmNumActa VARCHAR(20)
,@pmTipOsm VARCHAR(3),@pmNumOrden INT,@pmIdCiaOsm CHAR(2),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmResponsable VARCHAR(150),@pmFormaPago VARCHAR(50),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmContactoDest VARCHAR(150),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_MudInventario SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,IdTipoServ=@pmIdTipoServ,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdRemitente=@pmIdRemitente,Remitente=@pmRemitente,DirCargue=@pmDirCargue,TipoInmRem=@pmTipoInmRem,PisoCargue=@pmPisoCargue,TelsRemite=@pmTelsRemite,CelRemite=@pmCelRemite,IdDestinatario=@pmIdDestinatario,Destinatario=@pmDestinatario,DirDescargue=@pmDirDescargue,TipoInmDest=@pmTipoInmDest,PisoDescargue=@pmPisoDescargue,TelsDest=@pmTelsDest,CelDest=@pmCelDest
,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdVend=@pmIdVend,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,nRemolque=@pmnRemolque,TipoAfiVehic=@pmTipoAfiVehic,NitEmpresa=@pmNitEmpresa,NomEmpresa=@pmNomEmpresa,CajasEmp=@pmCajasEmp,CajasClie=@pmCajasClie,VrDeclarado=@pmVrDeclarado,VrServicio=@pmVrServicio,NumCotizac=@pmNumCotizac,NumPlanilla=@pmNumPlanilla,NumActa=@pmNumActa,TipOsm=@pmTipOsm,NumOrden=@pmNumOrden,IdCiaOsm=@pmIdCiaOsm,NomContacto=@pmNomContacto,TelsContacto=@pmTelsContacto,emlContacto=@pmemlContacto
,Responsable=@pmResponsable,FormaPago=@pmFormaPago,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,ContactoDest=@pmContactoDest,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumInvent=@pmNumInvent AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMudOrdenServ]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdTipoServ VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmDirCargue VARCHAR(500),@pmTipoInmRem VARCHAR(30),@pmPisoCargue VARCHAR(10),@pmTelsRemite VARCHAR(30),@pmCelRemite VARCHAR(30),@pmDirDescargue VARCHAR(500)
,@pmTipoInmDest VARCHAR(30),@pmPisoDescargue VARCHAR(10),@pmTelsDest VARCHAR(30),@pmCelDest VARCHAR(30),@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmVrServicio MONEY,@pmVrEmpaque MONEY,@pmVrBodega MONEY,@pmVrOtros MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrNeto MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmServicios VARCHAR(50),@pmFormaPago VARCHAR(50),@pmReferencia VARCHAR(50)
,@pmTipInv VARCHAR(3),@pmNumInvent INT,@pmIdCiaInv CHAR(2),@pmTipRem VARCHAR(3),@pmNumRemesa INT,@pmIdCiaRem CHAR(2),@pmEstFactura INT,@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmCdCiaFact CHAR(2),@pmTipCausac VARCHAR(3),@pmCausacion INT,@pmCdCiaCau CHAR(2),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmContactoDest VARCHAR(150),@pmemlContDest VARCHAR(100)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmEstCumplido INT,@pmFechaCump SMALLDATETIME,@pmTipoRuta VARCHAR(10),@pmVolumen VARCHAR(50),@pmEstadoBod INT,@pmCdBodega VARCHAR(4),@pmFechaIngBod SMALLDATETIME,@pmFechaRetBod SMALLDATETIME,@pmNitRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmNitDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150)
,@pmNumAutCupo INT,@pmNumAutMora INT,@pmReferencias VARCHAR(1000),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_MudOrdenServ SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,IdTipoServ=@pmIdTipoServ,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVend=@pmIdVend,DirCargue=@pmDirCargue,TipoInmRem=@pmTipoInmRem,PisoCargue=@pmPisoCargue,TelsRemite=@pmTelsRemite,CelRemite=@pmCelRemite,DirDescargue=@pmDirDescargue,TipoInmDest=@pmTipoInmDest,PisoDescargue=@pmPisoDescargue,TelsDest=@pmTelsDest,CelDest=@pmCelDest
,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,VrServicio=@pmVrServicio,VrEmpaque=@pmVrEmpaque,VrBodega=@pmVrBodega,VrOtros=@pmVrOtros,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrNeto=@pmVrNeto,VrDeclarado=@pmVrDeclarado,VrSeguro=@pmVrSeguro,Servicios=@pmServicios,FormaPago=@pmFormaPago,Referencia=@pmReferencia,TipInv=@pmTipInv,NumInvent=@pmNumInvent,IdCiaInv=@pmIdCiaInv,TipRem=@pmTipRem,NumRemesa=@pmNumRemesa,IdCiaRem=@pmIdCiaRem
,EstFactura=@pmEstFactura,TipFact=@pmTipFact,NumFactura=@pmNumFactura,CdCiaFact=@pmCdCiaFact,TipCausac=@pmTipCausac,Causacion=@pmCausacion,CdCiaCau=@pmCdCiaCau,NomContacto=@pmNomContacto,TelsContacto=@pmTelsContacto,emlContacto=@pmemlContacto,ContactoDest=@pmContactoDest,emlContDest=@pmemlContDest,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,EstCumplido=@pmEstCumplido
,FechaCump=@pmFechaCump,TipoRuta=@pmTipoRuta,Volumen=@pmVolumen,EstadoBod=@pmEstadoBod,CdBodega=@pmCdBodega,FechaIngBod=@pmFechaIngBod,FechaRetBod=@pmFechaRetBod,NitRemitente=@pmNitRemitente,Remitente=@pmRemitente,NitDestinatario=@pmNitDestinatario,Destinatario=@pmDestinatario,NumAutCupo=@pmNumAutCupo,NumAutMora=@pmNumAutMora,Referencias=@pmReferencias,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpMudSecciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudSecciones] @pmIdSeccion VARCHAR(4),@pmSeccion VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE MudSecciones SET Seccion=@pmSeccion,Inactivo=@pmInactivo
 WHERE IdSeccion=@pmIdSeccion
GO
/****** Object:  StoredProcedure [dbo].[paUpMudServicios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpMudServicios] @pmIdTipoServ VARCHAR(4),@pmTipoServicio VARCHAR(150),@pmTransporte BIT,@pmBodega BIT,@pmEmpaque BIT,@pmPersonal BIT,@pmInactivo BIT
 AS 
 UPDATE MudServicios SET TipoServicio=@pmTipoServicio,Transporte=@pmTransporte,Bodega=@pmBodega,Empaque=@pmEmpaque,Personal=@pmPersonal,Inactivo=@pmInactivo
 WHERE IdTipoServ=@pmIdTipoServ
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifComp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNiifComp] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdTercero VARCHAR(16),@pmVrTotal MONEY,@pmIdCta VARCHAR(4),@pmEnEfectivo BIT,@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmTipEgr VARCHAR(3),@pmNEgreso INT,@pmpVehiculo VARCHAR(10),@pmVehPropio INT,@pmCedCondtor VARCHAR(16),@pmCodConce VARCHAR(4),@pmBeneficiario VARCHAR(250),@pmVrDivisa1 DECIMAL(16,6),@pmVrDivisa2 DECIMAL(16,6),@pmVrDivisa3 DECIMAL(16,6)
,@pmPermEditar BIT,@pmIntegrado BIT,@pmEsEgreso BIT,@pmAnticipo BIT,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmTipoNiif VARCHAR(10),@pmCdSustento VARCHAR(4),@pmTipo_Pago VARCHAR(10),@pmEstablec VARCHAR(20),@pmPEmision VARCHAR(20),@pmAutorizac VARCHAR(50),@pmFechaAut SMALLDATETIME
,@pmCtbTipo VARCHAR(3),@pmCtbNumero INT,@pmFisTipo VARCHAR(3),@pmFisNumero INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NiifComp SET Fecha=@pmFecha,IdTercero=@pmIdTercero,VrTotal=@pmVrTotal,IdCta=@pmIdCta,EnEfectivo=@pmEnEfectivo,NumCheque=@pmNumCheque,FecCheque=@pmFecCheque,TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,TipEgr=@pmTipEgr,NEgreso=@pmNEgreso
,pVehiculo=@pmpVehiculo,VehPropio=@pmVehPropio,CedCondtor=@pmCedCondtor,CodConce=@pmCodConce,Beneficiario=@pmBeneficiario,VrDivisa1=@pmVrDivisa1,VrDivisa2=@pmVrDivisa2,VrDivisa3=@pmVrDivisa3,PermEditar=@pmPermEditar,Integrado=@pmIntegrado,EsEgreso=@pmEsEgreso,Anticipo=@pmAnticipo,Observacion=@pmObservacion
,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipoNiif=@pmTipoNiif,CdSustento=@pmCdSustento,Tipo_Pago=@pmTipo_Pago,Establec=@pmEstablec,PEmision=@pmPEmision,Autorizac=@pmAutorizac,FechaAut=@pmFechaAut,CtbTipo=@pmCtbTipo,CtbNumero=@pmCtbNumero,FisTipo=@pmFisTipo,FisNumero=@pmFisNumero
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifCompAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNiifCompAnu] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2), @pmAnulado BIT, @pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmPermEditar BIT,@pmObservacion VARCHAR(1000)
AS
 UPDATE Trn_NiifComp SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,IdEstado=@pmIdEstado
,Observacion=@pmObservacion,PermEditar=@pmPermEditar
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifDetallePla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNiifDetallePla] @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCia CHAR(2)
,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmNumCheque VARCHAR(20),@pmItemFac INT,@pmCodCargo VARCHAR(4)
,@pmIdCuenta VARCHAR(16),@pmVrDebito MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmCodAgncia VARCHAR(16)
,@pmReferncia VARCHAR(50),@pmFecUpdate SMALLDATETIME,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmCodCuentaCG VARCHAR(16)
 AS 
 UPDATE Trn_NiifDetalle SET IdCuenta=@pmIdCuenta,VrDebito=@pmVrDebito,IdTercero=@pmIdTercero,CodAgncia=@pmCodAgncia,IdVehiculo=@pmIdVehiculo
,Referncia=@pmReferncia,FecUpdate=@pmFecUpdate,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,CodCuentaCG=@pmCodCuentaCG
 WHERE TipCom=@pmTipCom AND Comprobante=@pmComprobante AND IdCia=@pmIdCia
 AND TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCiaDoc=@pmIdCiaDoc 
 AND NumCheque=@pmNumCheque AND ItemFac=@pmItemFac AND CodCargo=@pmCodCargo
GO
/****** Object:  StoredProcedure [dbo].[paUpNiifPoliticas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNiifPoliticas] @pmIdPolitica INT,@pmDescripcion VARCHAR(250),@pmClasePol VARCHAR(100),@pmObjetivo VARCHAR(1000),@pmAlcance VARCHAR(2500),@pmReconocimiento VARCHAR(2500),@pmMed_Inicial VARCHAR(2000)
,@pmMed_Final VARCHAR(2000),@pmPdoVigencia INT,@pmVigencia VARCHAR(250),@pmNotas VARCHAR(1000),@pmAnexo VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE Trn_NiifPoliticas SET Descripcion=@pmDescripcion,ClasePol=@pmClasePol,Objetivo=@pmObjetivo,Alcance=@pmAlcance,Reconocimiento=@pmReconocimiento,Med_Inicial=@pmMed_Inicial,Med_Final=@pmMed_Final
,PdoVigencia=@pmPdoVigencia,Vigencia=@pmVigencia,Notas=@pmNotas,Anexo=@pmAnexo,Inactivo=@pmInactivo
 WHERE IdPolitica=@pmIdPolitica
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAbonos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomAbonos] @pmNPrestamo INT,@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmFechaAbo SMALLDATETIME,@pmVrAbono MONEY,@pmnCuotas INT,@pmIdPeriodo VARCHAR(8)
,@pmDscto VARCHAR(3),@pmDetalle VARCHAR(50),@pmNLiquida INT
 AS 
 UPDATE Trn_NomAbonos SET IdEmpleado=@pmIdEmpleado,FechaAbo=@pmFechaAbo,VrAbono=@pmVrAbono,nCuotas=@pmnCuotas,IdPeriodo=@pmIdPeriodo,Dscto=@pmDscto,Detalle=@pmDetalle,NLiquida=@pmNLiquida
 WHERE NPrestamo=@pmNPrestamo AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomActividades]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomActividades] @pmIdActEco VARCHAR(10),@pmIdSector VARCHAR(8),@pmCodAdicional VARCHAR(10),@pmDescActividad VARCHAR(1000),@pmInactivo BIT
 AS 
 UPDATE NomActividades SET IdSector=@pmIdSector,CodAdicional=@pmCodAdicional,DescActividad=@pmDescActividad,Inactivo=@pmInactivo
 WHERE IdActEco=@pmIdActEco
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAjustes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomAjustes] @pmTipNota VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmIdPeriodo VARCHAR(8),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdRegNom VARCHAR(30),@pmNumLiquida INT,@pmNumSemLiq INT,@pmIdNom VARCHAR(4),@pmTipoLiq CHAR(1),@pmObservacion VARCHAR(2000),@pmNA_Estado INT
,@pmNA_Prefijo VARCHAR(20),@pmNA_Numero INT,@pmNA_FecEnvio SMALLDATETIME,@pmNA_CUNE VARCHAR(500),@pmNE_Prefijo VARCHAR(20),@pmNE_Numero INT,@pmNE_CUNE VARCHAR(500),@pmNE_TipoAju INT
 AS 
 UPDATE Trn_NomAjustes SET IdEmpleado=@pmIdEmpleado,NContrato=@pmNContrato,IdPeriodo=@pmIdPeriodo,FechaInicial=@pmFechaInicial,FechaFinal=@pmFechaFinal,IdRegNom=@pmIdRegNom,NumLiquida=@pmNumLiquida,NumSemLiq=@pmNumSemLiq,IdNom=@pmIdNom,TipoLiq=@pmTipoLiq
,Observacion=@pmObservacion,NA_Estado=@pmNA_Estado,NA_Prefijo=@pmNA_Prefijo,NA_Numero=@pmNA_Numero,NA_FecEnvio=@pmNA_FecEnvio,NA_CUNE=@pmNA_CUNE,NE_Prefijo=@pmNE_Prefijo,NE_Numero=@pmNE_Numero,NE_CUNE=@pmNE_CUNE,NE_TipoAju=@pmNE_TipoAju
 WHERE TipNota=@pmTipNota AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAlqDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomAlqDet] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmApellido1 VARCHAR(50),@pmApellido2 VARCHAR(50),@pmNombre1 VARCHAR(50),@pmNombre2 VARCHAR(50),@pmIdFonPen VARCHAR(8),@pmIdFonSal VARCHAR(8),@pmIdFonRie VARCHAR(8),@pmIdCajCom VARCHAR(8),@pmSalBasico MONEY,@pmVrIBCPen MONEY
,@pmDiasPen DECIMAL(10,4),@pmTarifPen DECIMAL(10,4),@pmVrPension MONEY,@pmVrApoFsp MONEY,@pmVrApoFsu MONEY,@pmVrApoVolAfi MONEY,@pmVrApoVolApt MONEY,@pmVrNoReten MONEY,@pmVrIBCSal MONEY,@pmDiasSal DECIMAL(10,4),@pmTarifSal DECIMAL(10,4),@pmVrSalud MONEY,@pmVrUpc MONEY,@pmVrIncap MONEY,@pmVrLicencia MONEY,@pmNumAutInc VARCHAR(30),@pmNumAutLic VARCHAR(30),@pmVrIBCRie MONEY
,@pmDiasRie DECIMAL(10,4),@pmTarifRie DECIMAL(10,4),@pmVrRiesgos MONEY,@pmVrIncIrp MONEY,@pmNumAutIrp VARCHAR(30),@pmIdInstala VARCHAR(4),@pmVrIBCRef MONEY,@pmVrIBCCajas MONEY,@pmDiasCom DECIMAL(10,4),@pmTarifCom DECIMAL(10,4),@pmVrCajas MONEY,@pmTarifSen DECIMAL(10,4),@pmVrSena MONEY,@pmTarifIcb DECIMAL(10,4),@pmVrICBF MONEY,@pmTarifEsap DECIMAL(10,4),@pmVrESAP MONEY
,@pmTarifEdu DECIMAL(10,4),@pmVrMinEdu MONEY,@pmTarifFsp DECIMAL(10,4),@pmTarifFsu DECIMAL(10,4),@pmCdFonAvp VARCHAR(8),@pmVrIBCparaf MONEY,@pmCantHoras INT,@pmTipoSalario VARCHAR(10),@pmIdActEco VARCHAR(10)
 AS 
 UPDATE Trn_NomAlqDet SET IdEmpleado=@pmIdEmpleado,NContrato=@pmNContrato,Apellido1=@pmApellido1,Apellido2=@pmApellido2,Nombre1=@pmNombre1,Nombre2=@pmNombre2,IdFonPen=@pmIdFonPen,IdFonSal=@pmIdFonSal,IdFonRie=@pmIdFonRie,IdCajCom=@pmIdCajCom,SalBasico=@pmSalBasico,VrIBCPen=@pmVrIBCPen,DiasPen=@pmDiasPen,TarifPen=@pmTarifPen,VrPension=@pmVrPension,VrApoFsp=@pmVrApoFsp,VrApoFsu=@pmVrApoFsu
,VrApoVolAfi=@pmVrApoVolAfi,VrApoVolApt=@pmVrApoVolApt,VrNoReten=@pmVrNoReten,VrIBCSal=@pmVrIBCSal,DiasSal=@pmDiasSal,TarifSal=@pmTarifSal,VrSalud=@pmVrSalud,VrUpc=@pmVrUpc,VrIncap=@pmVrIncap,VrLicencia=@pmVrLicencia,NumAutInc=@pmNumAutInc,NumAutLic=@pmNumAutLic,VrIBCRie=@pmVrIBCRie,DiasRie=@pmDiasRie,TarifRie=@pmTarifRie,VrRiesgos=@pmVrRiesgos,VrIncIrp=@pmVrIncIrp,NumAutIrp=@pmNumAutIrp,IdInstala=@pmIdInstala
,VrIBCRef=@pmVrIBCRef,VrIBCCajas=@pmVrIBCCajas,DiasCom=@pmDiasCom,TarifCom=@pmTarifCom,VrCajas=@pmVrCajas,TarifSen=@pmTarifSen,VrSena=@pmVrSena,TarifIcb=@pmTarifIcb,VrICBF=@pmVrICBF,TarifEsap=@pmTarifEsap,VrESAP=@pmVrESAP,TarifEdu=@pmTarifEdu,VrMinEdu=@pmVrMinEdu,TarifFsp=@pmTarifFsp,TarifFsu=@pmTarifFsu,CdFonAvp=@pmCdFonAvp,VrIBCparaf=@pmVrIBCparaf,CantHoras=@pmCantHoras,TipoSalario=@pmTipoSalario,IdActEco=@pmIdActEco
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAlqNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomAlqNov] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmNovIng INT,@pmNovRet INT,@pmNovTde INT,@pmNovTae INT,@pmNovTdp INT,@pmNovTap INT
,@pmNovVsp INT,@pmNovVte INT,@pmNovVst INT,@pmNovSln INT,@pmNovIge INT,@pmNovLma INT,@pmNovVac INT,@pmNovAvp INT,@pmNovVct INT,@pmNovIrp INT,@pmCodNewPen VARCHAR(8),@pmCodNewSal VARCHAR(8)
,@pmCodNewIns VARCHAR(4),@pmCodNewRie VARCHAR(4),@pmCodNewGru VARCHAR(4),@pmDiasNov INT,@pmDiasSan DECIMAL(14,4),@pmDiasDnrPen INT,@pmDiasDnrSal INT,@pmNovDsr INT,@pmFecNovIng SMALLDATETIME,@pmFecNovRet SMALLDATETIME,@pmFecNovVsp SMALLDATETIME
,@pmFecIniSln SMALLDATETIME,@pmFecFinSln SMALLDATETIME,@pmFecIniIge SMALLDATETIME,@pmFecFinIge SMALLDATETIME,@pmFecIniLma SMALLDATETIME,@pmFecFinLma SMALLDATETIME,@pmFecIniVac SMALLDATETIME,@pmFecFinVac SMALLDATETIME
,@pmFecIniVct SMALLDATETIME,@pmFecFinVct SMALLDATETIME,@pmFecIniIrl SMALLDATETIME,@pmFecFinIrl SMALLDATETIME
 AS 
 UPDATE Trn_NomAlqNov SET IdEmpleado=@pmIdEmpleado,NovIng=@pmNovIng,NovRet=@pmNovRet,NovTde=@pmNovTde,NovTae=@pmNovTae,NovTdp=@pmNovTdp,NovTap=@pmNovTap,NovVsp=@pmNovVsp,NovVte=@pmNovVte
,NovVst=@pmNovVst,NovSln=@pmNovSln,NovIge=@pmNovIge,NovLma=@pmNovLma,NovVac=@pmNovVac,NovAvp=@pmNovAvp,NovVct=@pmNovVct,NovIrp=@pmNovIrp,CodNewPen=@pmCodNewPen,CodNewSal=@pmCodNewSal
,CodNewIns=@pmCodNewIns,CodNewRie=@pmCodNewRie,CodNewGru=@pmCodNewGru,DiasNov=@pmDiasNov,DiasSan=@pmDiasSan,DiasDnrPen=@pmDiasDnrPen,DiasDnrSal=@pmDiasDnrSal,NovDsr=@pmNovDsr,FecNovIng=@pmFecNovIng,FecNovRet=@pmFecNovRet
,FecNovVsp=@pmFecNovVsp,FecIniSln=@pmFecIniSln,FecFinSln=@pmFecFinSln,FecIniIge=@pmFecIniIge,FecFinIge=@pmFecFinIge,FecIniLma=@pmFecIniLma,FecFinLma=@pmFecFinLma,FecIniVac=@pmFecIniVac,FecFinVac=@pmFecFinVac
,FecIniVct=@pmFecIniVct,FecFinVct=@pmFecFinVct,FecIniIrl=@pmFecIniIrl,FecFinIrl=@pmFecFinIrl
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAlqTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomAlqTot] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmItem INT,@pmTipAdm VARCHAR(3),@pmIdFondo VARCHAR(8),@pmCodTipoApo CHAR(2),@pmVrTotalCot MONEY,@pmVrTotalFsp MONEY,@pmVrTotalFsu MONEY,@pmVrTotalAva MONEY,@pmVrTotalAve MONEY,@pmVrTotalUpc MONEY
,@pmVrTotalLic MONEY,@pmVrTotalInc MONEY,@pmVrTotalOtr MONEY,@pmDiasMora INT,@pmTarifMora DECIMAL(10,4),@pmVrIntMora MONEY,@pmVrIMoraOtr MONEY,@pmVrTotalSAF MONEY,@pmVrSAFUpc MONEY,@pmVrTotalPagar MONEY,@pmVrTotalFon MONEY,@pmTotalAfi INT,@pmNumAutLic VARCHAR(30),@pmNumAutInc VARCHAR(30)
,@pmNumPlaSAF VARCHAR(20),@pmTipoReg INT
 AS 
 UPDATE Trn_NomAlqTot SET TipAdm=@pmTipAdm,IdFondo=@pmIdFondo,CodTipoApo=@pmCodTipoApo,VrTotalCot=@pmVrTotalCot,VrTotalFsp=@pmVrTotalFsp,VrTotalFsu=@pmVrTotalFsu,VrTotalAva=@pmVrTotalAva,VrTotalAve=@pmVrTotalAve,VrTotalUpc=@pmVrTotalUpc,VrTotalLic=@pmVrTotalLic,VrTotalInc=@pmVrTotalInc
,VrTotalOtr=@pmVrTotalOtr,DiasMora=@pmDiasMora,TarifMora=@pmTarifMora,VrIntMora=@pmVrIntMora,VrIMoraOtr=@pmVrIMoraOtr,VrTotalSAF=@pmVrTotalSAF,VrSAFUpc=@pmVrSAFUpc,VrTotalPagar=@pmVrTotalPagar,VrTotalFon=@pmVrTotalFon,TotalAfi=@pmTotalAfi,NumAutLic=@pmNumAutLic,NumAutInc=@pmNumAutInc,NumPlaSAF=@pmNumPlaSAF
,TipoReg=@pmTipoReg
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAportante]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomAportante] @pmIdAportnte VARCHAR(16),@pmRazonSocial VARCHAR(200),@pmTipoId CHAR(1),@pmDvNit CHAR(1),@pmIdRepLegal VARCHAR(16),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pme_mail VARCHAR(100),@pmClaseApo CHAR(1),@pmTipoEco CHAR(1),@pmTipoPersna CHAR(1)
,@pmCIIUDane VARCHAR(8),@pmFecIniCndato SMALLDATETIME,@pmTipAccCndato INT,@pmFecFinCndato SMALLDATETIME,@pmCodOperInfo VARCHAR(10),@pmTipoApo CHAR(1),@pmFecMatMerc SMALLDATETIME,@pmExonParaf INT,@pmExonCajas INT,@pmCondEspecial VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE NomAportante SET RazonSocial=@pmRazonSocial,TipoId=@pmTipoId,DvNit=@pmDvNit,IdRepLegal=@pmIdRepLegal,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,Fax=@pmFax,e_mail=@pme_mail,ClaseApo=@pmClaseApo,TipoEco=@pmTipoEco,TipoPersna=@pmTipoPersna,CIIUDane=@pmCIIUDane,FecIniCndato=@pmFecIniCndato,TipAccCndato=@pmTipAccCndato
,FecFinCndato=@pmFecFinCndato,CodOperInfo=@pmCodOperInfo,FecUpdate=@pmFecUpdate,TipoApo=@pmTipoApo,FecMatMerc=@pmFecMatMerc,ExonParaf=@pmExonParaf,ExonCajas=@pmExonCajas,CondEspecial=@pmCondEspecial
 WHERE IdAportnte=@pmIdAportnte
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAstncia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomAstncia] @pmIdEmpleado VARCHAR(16),@pmFechaDia SMALLDATETIME,@pmHHDiurno DECIMAL(10,4),@pmHHNocturno DECIMAL(10,4),@pmHEDiurno DECIMAL(10,4),@pmHENocturno DECIMAL(10,4)
,@pmTipoJrnada VARCHAR(10),@pmEsDmncal BIT,@pmHorario VARCHAR(30),@pmCodTurno VARCHAR(4),@pmHoras_Dia DECIMAL(10,4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomAstncia SET HHDiurno=@pmHHDiurno,HHNocturno=@pmHHNocturno,HEDiurno=@pmHEDiurno,HENocturno=@pmHENocturno,TipoJrnada=@pmTipoJrnada,EsDmncal=@pmEsDmncal,Horario=@pmHorario
,CodTurno=@pmCodTurno,Horas_Dia=@pmHoras_Dia,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND FechaDia=@pmFechaDia
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAutoliq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomAutoliq] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmFecha SMALLDATETIME,@pmPerAutoliq VARCHAR(6),@pmPerAutoSal VARCHAR(6),@pmFechaPago SMALLDATETIME,@pmIdAportnte VARCHAR(16),@pmPresentacion CHAR(1),@pmCodCia CHAR(2),@pmCodFondo VARCHAR(8),@pmCodArp VARCHAR(8),@pmCodOper VARCHAR(10),@pmEsCorr BIT,@pmPerCorr VARCHAR(6),@pmNumCorr VARCHAR(20),@pmTotalEmp INT,@pmVrNomina MONEY,@pmVrPension MONEY,@pmVrSalud MONEY,@pmVrRiesgos MONEY,@pmVrCajas MONEY
,@pmVrSena MONEY,@pmVrIcbf MONEY,@pmVrEsap MONEY,@pmVrMinEduc MONEY,@pmTotalAfipen INT,@pmTotalAfiSal INT,@pmTotalAfiRie INT,@pmTotalAfiCaj INT,@pmTotalAfiSen INT,@pmTotalAfiIcb INT,@pmTotalAfiEsa INT,@pmTotalAfiEduc INT,@pmTotAdmPen INT,@pmTotAdmSal INT,@pmTotAdmRie INT,@pmTotAdmCom INT,@pmObservacion VARCHAR(250),@pmLogAdmon VARCHAR(250),@pmRedoMiles BIT,@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME,@pmTipoPlanilla VARCHAR(3)
 AS 
 UPDATE Trn_NomAutoliq SET Fecha=@pmFecha,PerAutoliq=@pmPerAutoliq,PerAutoSal=@pmPerAutoSal,FechaPago=@pmFechaPago,IdAportnte=@pmIdAportnte,Presentacion=@pmPresentacion,CodCia=@pmCodCia,CodFondo=@pmCodFondo,CodArp=@pmCodArp,CodOper=@pmCodOper,EsCorr=@pmEsCorr,PerCorr=@pmPerCorr,NumCorr=@pmNumCorr,TotalEmp=@pmTotalEmp,VrNomina=@pmVrNomina,VrPension=@pmVrPension,VrSalud=@pmVrSalud,VrRiesgos=@pmVrRiesgos,VrCajas=@pmVrCajas,VrSena=@pmVrSena,VrIcbf=@pmVrIcbf,VrEsap=@pmVrEsap,VrMinEduc=@pmVrMinEduc
,TotalAfipen=@pmTotalAfipen,TotalAfiSal=@pmTotalAfiSal,TotalAfiRie=@pmTotalAfiRie,TotalAfiCaj=@pmTotalAfiCaj,TotalAfiSen=@pmTotalAfiSen,TotalAfiIcb=@pmTotalAfiIcb,TotalAfiEsa=@pmTotalAfiEsa,TotalAfiEduc=@pmTotalAfiEduc,TotAdmPen=@pmTotAdmPen,TotAdmSal=@pmTotAdmSal,TotAdmRie=@pmTotAdmRie,TotAdmCom=@pmTotAdmCom,Observacion=@pmObservacion,LogAdmon=@pmLogAdmon,RedoMiles=@pmRedoMiles,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipoPlanilla=@pmTipoPlanilla
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomAutoliqAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomAutoliqAnu] @pmTipoLiq VARCHAR(3),@pmNumero VARCHAR(20),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomAutoliq SET Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomBasesConv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomBasesConv] @pmIdBase VARCHAR(4),@pmNombreBase VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE NomBasesConv SET NombreBase=@pmNombreBase,Inactivo=@pmInactivo
 WHERE IdBase=@pmIdBase
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCAdmon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomCAdmon] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmClaseAdmon VARCHAR(10),@pmFecIniNov SMALLDATETIME,@pmNNovedad INT
,@pmIdFondo VARCHAR(8),@pmIdFonNew VARCHAR(8),@pmObservacion VARCHAR(100),@pmAnulado BIT
 AS 
 UPDATE Trn_NomCAdmon SET Fecha=@pmFecha,NContrato=@pmNContrato,ClaseAdmon=@pmClaseAdmon,FecIniNov=@pmFecIniNov,NNovedad=@pmNNovedad,IdFondo=@pmIdFondo,IdFonNew=@pmIdFonNew
,Observacion=@pmObservacion,Anulado=@pmAnulado
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCAdmonAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomCAdmonAnu] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmAnulado BIT
,@pmObservacion VARCHAR(100)
 AS 
 UPDATE Trn_NomCAdmon SET Observacion=@pmObservacion,Anulado=@pmAnulado
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCapacitaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomCapacitaciones] @pmIdClase VARCHAR(4),@pmItem INT,@pmVigencia INT,@pmCdEmpleado VARCHAR(16),@pmCdProf VARCHAR(4)
,@pmCdCargo VARCHAR(4),@pmCdArea VARCHAR(4),@pmCdDep VARCHAR(4),@pmCumplimto VARCHAR(20),@pmInactivo BIT
 AS 
 UPDATE NomCapacitaciones SET Vigencia=@pmVigencia,CdEmpleado=@pmCdEmpleado,CdProf=@pmCdProf,CdCargo=@pmCdCargo
,CdArea=@pmCdArea,CdDep=@pmCdDep,Cumplimto=@pmCumplimto,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCausalesRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomCausalesRet] @pmIdCausa VARCHAR(4),@pmCausalRet VARCHAR(100),@pmIndmnizar BIT,@pmInactivo BIT
 AS 
 UPDATE NomCausalesRet SET CausalRet=@pmCausalRet,Indmnizar=@pmIndmnizar,Inactivo=@pmInactivo
 WHERE IdCausa=@pmIdCausa
GO
/****** Object:  StoredProcedure [dbo].[paUpNomCertf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomCertf] @pmIdEmpleado VARCHAR(16),@pmNumCertf VARCHAR(20),@pmnAnno INT,@pmnMes INT,@pmVrCertf MONEY
,@pmObservacion VARCHAR(100),@pmClaseCert VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomCertf SET nAnno=@pmnAnno,nMes=@pmnMes,VrCertf=@pmVrCertf,Observacion=@pmObservacion,ClaseCert=@pmClaseCert,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND NumCertf=@pmNumCertf
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConAuto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomConAuto] @pmIdReg INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmVrAplicar MONEY,@pmModalidad CHAR(1),@pmOrigenBase CHAR(2),@pmFrecAplica VARCHAR(10)
,@pmCedEmpleado VARCHAR(16),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodCcto VARCHAR(16),@pmCritSelect VARCHAR(4000),@pmFecFinal SMALLDATETIME,@pmExceptuar VARCHAR(8),@pmObservacion VARCHAR(50)
,@pmCodSubCos VARCHAR(16),@pmInactivo BIT,@pmNumPerMes INT,@pmNitTercero VARCHAR(16),@pmAplicaPrima INT,@pmAplicaVac INT,@pmPdoAplicaEsp VARCHAR(8),@pmVrAplicaEsp MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomConAuto SET IdConcepto=@pmIdConcepto,FecInicio=@pmFecInicio,VrAplicar=@pmVrAplicar,Modalidad=@pmModalidad,OrigenBase=@pmOrigenBase,FrecAplica=@pmFrecAplica,CedEmpleado=@pmCedEmpleado,CodNom=@pmCodNom
,CodDep=@pmCodDep,CodCcto=@pmCodCcto,CritSelect=@pmCritSelect,FecFinal=@pmFecFinal,Exceptuar=@pmExceptuar,Observacion=@pmObservacion,Inactivo=@pmInactivo,CodSubCos=@pmCodSubCos,NumPerMes=@pmNumPerMes
,NitTercero=@pmNitTercero,AplicaPrima=@pmAplicaPrima,AplicaVac=@pmAplicaVac,PdoAplicaEsp=@pmPdoAplicaEsp,VrAplicaEsp=@pmVrAplicaEsp,FecUpdate=@pmFecUpdate
 WHERE IdReg=@pmIdReg
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConcConv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomConcConv] @pmId INT,@pmIdPeriodo INT,@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdConv INT,@pmIdGrupo VARCHAR(4),@pmCodEscfon VARCHAR(4),@pmCodZona VARCHAR(4),@pmTipoNom VARCHAR(10),@pmIdConcepto VARCHAR(4),@pmDescripcion VARCHAR(500),@pmUnidad VARCHAR(10),@pmImporte MONEY,@pmObservaciones VARCHAR(1000),@pmInactivo BIT,@pmIdUsuario VARCHAR(11),@pmFechaCrea SMALLDATETIME
 AS 
 UPDATE Trn_NomConcConv SET IdPeriodo=@pmIdPeriodo,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,IdConv=@pmIdConv,IdGrupo=@pmIdGrupo,CodEscfon=@pmCodEscfon,CodZona=@pmCodZona,TipoNom=@pmTipoNom,IdConcepto=@pmIdConcepto,Descripcion=@pmDescripcion,Unidad=@pmUnidad,Importe=@pmImporte,Observaciones=@pmObservaciones,Inactivo=@pmInactivo
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConceptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomConceptos] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(100),@pmClaseCon VARCHAR(10),@pmUnidad VARCHAR(10),@pmTarifa DECIMAL(10,4)
,@pmBaseTrfa CHAR(2),@pmPdtermnado BIT,@pmInactivo BIT,@pmTarifaEmp DECIMAL(14,4),@pmDiasEmp INT,@pmIdConcNE VARCHAR(50),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE NomConceptos SET Concepto=@pmConcepto,ClaseCon=@pmClaseCon,Unidad=@pmUnidad,Tarifa=@pmTarifa,BaseTrfa=@pmBaseTrfa,Pdtermnado=@pmPdtermnado,Inactivo=@pmInactivo
,TarifaEmp=@pmTarifaEmp,DiasEmp=@pmDiasEmp,IdConcNE=@pmIdConcNE,FechaUpdate=@pmFechaUpdate
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConCuentas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomConCuentas] @pmIdConcepto VARCHAR(4),@pmItem INT,@pmNClase INT,@pmIdCuenta VARCHAR(16)
,@pmTipoMov CHAR(1),@pmCodNom VARCHAR(4),@pmCodDep VARCHAR(4),@pmCodFon VARCHAR(8),@pmNitTerc CHAR(1),@pmTipo_Nom VARCHAR(10)
 AS 
 UPDATE NomConCuentas SET NClase=@pmNClase,IdCuenta=@pmIdCuenta,TipoMov=@pmTipoMov,CodNom=@pmCodNom
,CodDep=@pmCodDep,CodFon=@pmCodFon,NitTerc=@pmNitTerc,Tipo_Nom=@pmTipo_Nom
 WHERE IdConcepto=@pmIdConcepto AND  Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConOpciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomConOpciones] @pmIdConcepto VARCHAR(4),@pmIdOpc INT,@pmNomOpcion VARCHAR(50),@pmAsignado BIT
 AS 
 UPDATE NomConOpciones SET NomOpcion=@pmNomOpcion,Asignado=@pmAsignado
 WHERE IdConcepto=@pmIdConcepto AND IdOpc=@pmIdOpc
GO
/****** Object:  StoredProcedure [dbo].[paUpNomConvenciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomConvenciones] @pmId INT,@pmFecha SMALLDATETIME,@pmProyecto VARCHAR(150),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdLocal VARCHAR(8),@pmNitTercero VARCHAR(16),@pmObservacion VARCHAR(500),@pmFecProrroga SMALLDATETIME,@pmFechaCrea SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE NomConvenciones SET Fecha=@pmFecha,Proyecto=@pmProyecto,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,IdLocal=@pmIdLocal,NitTercero=@pmNitTercero,Observacion=@pmObservacion,FecProrroga=@pmFecProrroga,Inactivo=@pmInactivo
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paUpNomDefault]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomDefault] @pmnAnno INT,@pmIdOpc VARCHAR(3),@pmDescripcion VARCHAR(100),@pmValor MONEY
 AS 
 UPDATE NomDefault SET Descripcion=@pmDescripcion,Valor=@pmValor
 WHERE nAnno=@pmnAnno AND IdOpc=@pmIdOpc
GO
/****** Object:  StoredProcedure [dbo].[paUpNomDetalle]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomDetalle] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmItem INT,@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantDevg DECIMAL(10,4),@pmCantDed DECIMAL(10,4),@pmVrUnitario MONEY,@pmVrTotDevg MONEY
,@pmVrTotDed MONEY,@pmUnidad VARCHAR(10),@pmClaseLiq VARCHAR(10),@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmDiasCalc DECIMAL(10,4),@pmDiasNov DECIMAL(10,4),@pmCodFondo VARCHAR(8),@pmNPrestamo INT,@pmNCuota INT,@pmOrigCargue VARCHAR(10),@pmVrBaseLiq MONEY,@pmVrBasExceso MONEY,@pmNitTercero VARCHAR(16)
,@pmHoraInicial DATETIME,@pmHoraFinal DATETIME,@pmTipoIncLab VARCHAR(20),@pmVrIngNoSal MONEY
 AS 
 UPDATE Trn_NomDetalle SET IdEmpleado=@pmIdEmpleado,IdConcepto=@pmIdConcepto,Detalle=@pmDetalle,CantDevg=@pmCantDevg,CantDed=@pmCantDed,VrUnitario=@pmVrUnitario,VrTotDevg=@pmVrTotDevg,VrTotDed=@pmVrTotDed,Unidad=@pmUnidad,ClaseLiq=@pmClaseLiq
,VrOrigen=@pmVrOrigen,Tarifa=@pmTarifa,DiasCalc=@pmDiasCalc,DiasNov=@pmDiasNov,CodFondo=@pmCodFondo,NPrestamo=@pmNPrestamo,NCuota=@pmNCuota,OrigCargue=@pmOrigCargue,VrBaseLiq=@pmVrBaseLiq,VrBasExceso=@pmVrBasExceso,NitTercero=@pmNitTercero,HoraInicial=@pmHoraInicial,HoraFinal=@pmHoraFinal,TipoIncLab=@pmTipoIncLab,VrIngNoSal=@pmVrIngNoSal
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomDotacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomDotacion] @pmIdCia CHAR(2),@pmNumero INT,@pmFecha SMALLDATETIME,@pmTipoDotac VARCHAR(10),@pmTipoEntrega INT,@pmPlazoEntrega INT
,@pmFecVence SMALLDATETIME,@pmTipoReg INT,@pmAnulado BIT,@pmObservacion VARCHAR(1000),@pmCritFiltros VARCHAR(250)
 AS 
 UPDATE Trn_NomDotacion SET Fecha=@pmFecha,TipoDotac=@pmTipoDotac,TipoEntrega=@pmTipoEntrega,PlazoEntrega=@pmPlazoEntrega,FecVence=@pmFecVence,TipoReg=@pmTipoReg
,Anulado=@pmAnulado,Observacion=@pmObservacion,CritFiltros=@pmCritFiltros
 WHERE IdCia=@pmIdCia AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomEscalafones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomEscalafones] @pmIdEscfon VARCHAR(4),@pmEscalafon VARCHAR(150),@pmIdConv INT,@pmIdGrupo VARCHAR(4),@pmIdCargo VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE NomEscalafones SET Escalafon=@pmEscalafon,IdConv=@pmIdConv,IdGrupo=@pmIdGrupo,IdCargo=@pmIdCargo,Inactivo=@pmInactivo
 WHERE IdEscfon=@pmIdEscfon
GO
/****** Object:  StoredProcedure [dbo].[paUpNomEstadosConv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomEstadosConv] @pmIdEstado VARCHAR(4),@pmEstadoConv VARCHAR(50),@pmNColor INT,@pmInactivo BIT
 AS 
 UPDATE NomEstadosConv SET EstadoConv=@pmEstadoConv,NColor=@pmNColor,Inactivo=@pmInactivo
 WHERE IdEstado=@pmIdEstado
GO
/****** Object:  StoredProcedure [dbo].[paUpNomFijos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomFijos] @pmIdEmpleado VARCHAR(16),@pmnAnno INT,@pmnMes INT,@pmTarifa DECIMAL(10,4),@pmVrBase MONEY,@pmVrSalarios MONEY,@pmVrPrima MONEY,@pmVrVacacnes MONEY,@pmVrSIntExcto MONEY,@pmVrOtrosIng MONEY,@pmVrIngresos MONEY
,@pmVrPensiones MONEY,@pmVrDedcido MONEY,@pmVrExcento MONEY,@pmVrCertEdu MONEY,@pmVrCertVda MONEY,@pmVrCertAFC MONEY,@pmVrCertfcado MONEY,@pmPeriodos DECIMAL(10,4),@pmVrTotalBase MONEY,@pmOrignPorc VARCHAR(10),@pmFecUpdate SMALLDATETIME
,@pmVrSalud MONEY,@pmIngNoSalario MONEY,@pmPagosMedicPre MONEY,@pmAportesVolPen MONEY,@pmGastosRep MONEY,@pmIndemnizac MONEY
 AS 
 UPDATE Trn_NomFijos SET Tarifa=@pmTarifa,VrBase=@pmVrBase,VrSalarios=@pmVrSalarios,VrPrima=@pmVrPrima,VrVacacnes=@pmVrVacacnes,VrSIntExcto=@pmVrSIntExcto,VrOtrosIng=@pmVrOtrosIng,VrIngresos=@pmVrIngresos,VrPensiones=@pmVrPensiones,VrDedcido=@pmVrDedcido
,VrExcento=@pmVrExcento,VrCertEdu=@pmVrCertEdu,VrCertVda=@pmVrCertVda,VrCertAFC=@pmVrCertAFC,VrCertfcado=@pmVrCertfcado,Periodos=@pmPeriodos,VrTotalBase=@pmVrTotalBase,OrignPorc=@pmOrignPorc,FecUpdate=@pmFecUpdate
,VrSalud=@pmVrSalud,IngNoSalario=@pmIngNoSalario,PagosMedicPre=@pmPagosMedicPre,AportesVolPen=@pmAportesVolPen,GastosRep=@pmGastosRep,Indemnizac=@pmIndemnizac
 WHERE IdEmpleado=@pmIdEmpleado AND nAnno=@pmnAnno AND nMes=@pmnMes
GO
/****** Object:  StoredProcedure [dbo].[paUpNomGruposConv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomGruposConv] @pmIdGrupo VARCHAR(4),@pmGrupoConv VARCHAR(150),@pmIdConv INT,@pmInactivo BIT
 AS 
 UPDATE NomGruposConv SET GrupoConv=@pmGrupoConv,IdConv=@pmIdConv,Inactivo=@pmInactivo
 WHERE IdGrupo=@pmIdGrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomina]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomina] @pmIdPeriodo VARCHAR(8),@pmKeyRegistro VARCHAR(30),@pmIdEmpleado VARCHAR(16),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmNContrato INT,@pmIdDep VARCHAR(4)
,@pmIdInstala VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmVrSalario MONEY,@pmVrATransMes MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmEsRetiro BIT,@pmNLiqRet INT,@pmTipoLiq CHAR(1),@pmCantNoRem DECIMAL(10,4),@pmCdTipoCot VARCHAR(4),@pmSubTipo_Cot VARCHAR(3),@pmSal_Integral BIT,@pmTipoIdent CHAR(1),@pmNotasAportante VARCHAR(250),@pmCantModifica INT,@pmNE_Estado INT,@pmNE_Prefijo VARCHAR(20)
,@pmNE_Numero INT,@pmNE_FecEnvio DATETIME,@pmNE_CUNE VARCHAR(500),@pmNE_ComAju BIT,@pmNE_CntAju INT,@pmNE_Ajustes VARCHAR(500),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Nomina SET IdEmpleado=@pmIdEmpleado,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,Cantidad=@pmCantidad,VrDevengado=@pmVrDevengado,VrDeducido=@pmVrDeducido,NContrato=@pmNContrato,IdDep=@pmIdDep,IdInstala=@pmIdInstala,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdNom=@pmIdNom
,VrSalario=@pmVrSalario,VrATransMes=@pmVrATransMes,pVehiculo=@pmpVehiculo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,EsRetiro=@pmEsRetiro,FecUpdate=@pmFecUpdate,NLiqRet=@pmNLiqRet,TipoLiq=@pmTipoLiq,CantNoRem=@pmCantNoRem
,CdTipoCot=@pmCdTipoCot,SubTipo_Cot=@pmSubTipo_Cot,Sal_Integral=@pmSal_Integral,TipoIdent=@pmTipoIdent,NotasAportante=@pmNotasAportante,CantModifica=@pmCantModifica,NE_Estado=@pmNE_Estado,NE_Prefijo=@pmNE_Prefijo,NE_Numero=@pmNE_Numero,NE_FecEnvio=@pmNE_FecEnvio,NE_CUNE=@pmNE_CUNE
,NE_ComAju=@pmNE_ComAju,NE_CntAju=@pmNE_CntAju,NE_Ajustes=@pmNE_Ajustes
 WHERE IdPeriodo=@pmIdPeriodo AND KeyRegistro=@pmKeyRegistro
GO
/****** Object:  StoredProcedure [dbo].[paUpNominaCmp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNominaCmp] @pmIdPeriodo VARCHAR(8),@pmIdNom VARCHAR(4),@pmEsRetiro BIT,@pmIdEmpleado VARCHAR(16)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Nomina SET TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE IdPeriodo=@pmIdPeriodo  AND IdNom=@pmIdNom  AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%')
 AND  (EsRetiro=ISNULL(@pmEsRetiro,0) or EsRetiro=ISNULL(@pmEsRetiro,1))
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLiquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomLiquida] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmFecha SMALLDATETIME,@pmSemstre INT,@pmVrTotal MONEY,@pmVrTotDed MONEY,@pmVrAplicado MONEY
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4), @pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomLiquida SET Fecha=@pmFecha,Semstre=@pmSemstre,VrTotal=@pmVrTotal,VrTotDed=@pmVrTotDed,VrAplicado=@pmVrAplicado,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLiquidaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomLiquidaAnu] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmAnulado BIT,@pmIdEstado VARCHAR(4), @pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomLiquida SET Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipoLiq=@pmTipoLiq AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLiquidaPar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomLiquidaPar] @pmTipoLiq VARCHAR(3),@pmNumero INT,@pmIdEstado VARCHAR(4),@pmAplica BIT
 AS 
 IF @pmAplica<>0
  UPDATE Trn_NomLiquida SET VrAplicado=VrTotal,IdEstado=@pmIdEstado  WHERE  TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Anulado=0
 ELSE
  UPDATE Trn_NomLiquida SET VrAplicado=0,IdEstado=@pmIdEstado  WHERE  TipoLiq=@pmTipoLiq AND Numero=@pmNumero AND Anulado=0
GO
/****** Object:  StoredProcedure [dbo].[paUpNomLogVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomLogVeh] @pmIdEmpleado VARCHAR(16),@pmNumReg INT,@pmFecha SMALLDATETIME,@pmpVehAnterior VARCHAR(10)
,@pmNitPropAnt VARCHAR(16),@pmpVehNew VARCHAR(10),@pmNitPropNew VARCHAR(16),@pmObservacion VARCHAR(100),@pmNitCondAnt VARCHAR(16)
 AS 
 UPDATE Trn_NomLogVeh SET Fecha=@pmFecha,pVehAnterior=@pmpVehAnterior,NitPropAnt=@pmNitPropAnt,pVehNew=@pmpVehNew,NitPropNew=@pmNitPropNew
,Observacion=@pmObservacion,NitCondAnt=@pmNitCondAnt
 WHERE IdEmpleado=@pmIdEmpleado AND NumReg=@pmNumReg
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomNov] @pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad DECIMAL(10,4),@pmVrUnitario MONEY
,@pmVrTotal MONEY,@pmVrOrigen MONEY,@pmTarifa DECIMAL(10,4),@pmOrigCargue VARCHAR(10),@pmNumDocRef VARCHAR(20),@pmNum_Contrato INT,@pmNit_Tercero VARCHAR(16),@pmHoraInicial DATETIME,@pmHoraFinal DATETIME,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomNov SET IdConcepto=@pmIdConcepto,Detalle=@pmDetalle,Cantidad=@pmCantidad,VrUnitario=@pmVrUnitario,VrTotal=@pmVrTotal,VrOrigen=@pmVrOrigen
,Tarifa=@pmTarifa,OrigCargue=@pmOrigCargue,NumDocRef=@pmNumDocRef,Num_Contrato=@pmNum_Contrato,FecUpdate=@pmFecUpdate,Nit_Tercero=@pmNit_Tercero,HoraInicial=@pmHoraInicial,HoraFinal=@pmHoraFinal
 WHERE IdPeriodo=@pmIdPeriodo AND IdEmpleado=@pmIdEmpleado AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNovConv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomNovConv] @pmId BIGINT,@pmIdPeriodo VARCHAR(8),@pmIdEmpleado VARCHAR(16),@pmNContrato INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmIdConv INT,@pmIdGrupo VARCHAR(4),@pmCodEscfon VARCHAR(4),@pmCodBase VARCHAR(4),@pmCodZona VARCHAR(4),@pmTipoNom VARCHAR(10),@pmCantidad DECIMAL(14,4),@pmVrDevengado MONEY,@pmVrDeducido MONEY,@pmVrSalario MONEY,@pmOrigenReg INT,@pmAnulado BIT
,@pmVrAuxTransp MONEY,@pmVrSalBasDia MONEY,@pmVrAuxTraDia MONEY,@pmVrPriConDia MONEY,@pmIdNom VARCHAR(4),@pmNumRegLog INT
 AS 
 UPDATE Trn_NomNovConv SET IdPeriodo=@pmIdPeriodo,IdEmpleado=@pmIdEmpleado,NContrato=@pmNContrato,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,IdConv=@pmIdConv,IdGrupo=@pmIdGrupo,CodEscfon=@pmCodEscfon,CodBase=@pmCodBase,CodZona=@pmCodZona,TipoNom=@pmTipoNom,Cantidad=@pmCantidad,VrDevengado=@pmVrDevengado,VrDeducido=@pmVrDeducido,VrSalario=@pmVrSalario,OrigenReg=@pmOrigenReg,Anulado=@pmAnulado
 ,VrAuxTransp=@pmVrAuxTransp,VrSalBasDia=@pmVrSalBasDia,VrAuxTraDia=@pmVrAuxTraDia,VrPriConDia=@pmVrPriConDia,IdNom=@pmIdNom,NumRegLog=@pmNumRegLog
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNovedad]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomNovedad] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmIdConcepto VARCHAR(4),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantDias INT,@pmDiaInicio INT
,@pmModalidad VARCHAR(10),@pmIdNov VARCHAR(4),@pmRemnrado BIT,@pmObservacion VARCHAR(250),@pmCodInstla VARCHAR(4),@pmInactivo BIT,@pmCodClsRie VARCHAR(4),@pmNumAutza VARCHAR(30),@pmCodNewFon VARCHAR(8)
,@pmCodOldFon VARCHAR(8),@pmVrCotVolAfi MONEY,@pmVrCotVolApo MONEY,@pmVrNoRetenido MONEY,@pmTipoIncap CHAR(1),@pmFechaDcto SMALLDATETIME,@pmVrDescuento MONEY,@pmTipoBaseLiq VARCHAR(3),@pmIncAlargado BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomNovedad SET IdConcepto=@pmIdConcepto,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,CantDias=@pmCantDias,DiaInicio=@pmDiaInicio,Modalidad=@pmModalidad,IdNov=@pmIdNov,Remnrado=@pmRemnrado
,Observacion=@pmObservacion,Inactivo=@pmInactivo,CodInstla=@pmCodInstla,CodClsRie=@pmCodClsRie,NumAutza=@pmNumAutza,CodNewFon=@pmCodNewFon,FecUpdate=@pmFecUpdate
,VrCotVolAfi=@pmVrCotVolAfi,VrCotVolApo=@pmVrCotVolApo,VrNoRetenido=@pmVrNoRetenido,TipoIncap=@pmTipoIncap,CodOldFon=@pmCodOldFon,FechaDcto=@pmFechaDcto,VrDescuento=@pmVrDescuento,TipoBaseLiq=@pmTipoBaseLiq,IncAlargado=@pmIncAlargado
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomNovedadAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomNovedadAnu] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmInactivo BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomNovedad SET Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrendas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomPrendas] @pmIdPrend VARCHAR(4),@pmDescPrenda VARCHAR(100),@pmTipoPrenda VARCHAR(10),@pmVrCostoUnd MONEY,@pmInactivo BIT
 AS 
 UPDATE NomPrendas SET DescPrenda=@pmDescPrenda,TipoPrenda=@pmTipoPrenda,Inactivo=@pmInactivo,VrCostoUnd=@pmVrCostoUnd
 WHERE IdPrend=@pmIdPrend
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrest]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomPrest] @pmNPrestamo INT,@pmFecha SMALLDATETIME,@pmIdEmpleado VARCHAR(16),@pmIdConcepto VARCHAR(4),@pmVrPrestamo MONEY,@pmNumCuotas INT,@pmVrCuota MONEY
,@pmFecInicio SMALLDATETIME,@pmFrecDcto VARCHAR(10),@pmExceptuar VARCHAR(8),@pmTotPrestamo MONEY,@pmTotAbonado MONEY,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3)
,@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmCxpagar BIT,@pmDsctNom INT,@pmDsctPri INT,@pmDsctVac INT,@pmDsctEspPer VARCHAR(8),@pmDsctEspVal MONEY
,@pmVrTmAbono MONEY,@pmNumPerMes INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomPrest SET Fecha=@pmFecha,IdEmpleado=@pmIdEmpleado,IdConcepto=@pmIdConcepto,VrPrestamo=@pmVrPrestamo,NumCuotas=@pmNumCuotas,VrCuota=@pmVrCuota,FecInicio=@pmFecInicio
,FrecDcto=@pmFrecDcto,Exceptuar=@pmExceptuar,TotPrestamo=@pmTotPrestamo,TotAbonado=@pmTotAbonado,Anulado=@pmAnulado,FecDev=@pmFecDev,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Cxpagar=@pmCxpagar,DsctNom=@pmDsctNom,DsctPri=@pmDsctPri,DsctVac=@pmDsctVac,DsctEspPer=@pmDsctEspPer,DsctEspVal=@pmDsctEspVal
,NumPerMes=@pmNumPerMes,VrTmAbono=@pmVrTmAbono,FecUpdate=@pmFecUpdate
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestAbn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomPrestAbn] @pmNPrestamo INT,@pmTotAbonado MONEY
 AS 
 UPDATE Trn_NomPrest SET TotAbonado=@pmTotAbonado
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomPrestAbo] @pmIdEmpleado VARCHAR(16)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest 
 SET TotAbonado=(SELECT ISNULL(SUM(VrAbono),0) 
 FROM Trn_NomAbonos  WHERE  Trn_NomPrest.NPrestamo=Trn_NomAbonos.NPrestamo)
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomPrestAnu] @pmNPrestamo INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomPrest SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=ISNULL(@pmObservacion,Observacion)
 ,FecUpdate=@pmFecUpdate
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestCan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomPrestCan] @pmNPrestamo INT,@pmTotAbonado MONEY,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomPrest SET TotAbonado=@pmTotAbonado,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate
 WHERE NPrestamo=@pmNPrestamo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomPrestCero] @pmIdEmpleado VARCHAR(16)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest SET TotAbonado=0,VrTmAbono=0
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestTAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomPrestTAbo] @pmIdEmpleado VARCHAR(16)=Null,@pmIdPeriodo VARCHAR(8)=Null
,@pmDscto VARCHAR(3)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest 
 SET VrTmAbono=(SELECT ISNULL(SUM(VrAbono),0) 
           FROM Trn_NomAbonos
          WHERE Trn_NomPrest.NPrestamo=Trn_NomAbonos.NPrestamo
         AND IdPeriodo LIKE ISNULL(@pmIdPeriodo,'%') AND Dscto LIKE ISNULL(@pmDscto,'%') )
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
 AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paUpNomPrestTCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomPrestTCero] @pmIdEmpleado VARCHAR(16)=Null,@pmNPrestamo INT=Null
 AS 
 UPDATE Trn_NomPrest SET VrTmAbono=0
 WHERE Anulado=0 AND IdEmpleado LIKE ISNULL(@pmIdEmpleado,'%') 
AND (NPrestamo>=ISNULL(@pmNPrestamo,0)  AND NPrestamo<=ISNULL(@pmNPrestamo,2147483647))
GO
/****** Object:  StoredProcedure [dbo].[paUpNomRangosFsu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomRangosFsu] @pmIdRango INT,@pmVrInicial DECIMAL(12,2),@pmVrFinal DECIMAL(12,2),@pmTarifa DECIMAL(10,4)
 AS 
 UPDATE NomRangosFsu SET VrInicial=@pmVrInicial,VrFinal=@pmVrFinal,Tarifa=@pmTarifa
 WHERE IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paUpNomRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomRet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmIdCausa VARCHAR(4),@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmDiasTrab INT,@pmDiasNoRem INT,@pmVrTotDev MONEY,@pmVrTotDed MONEY,@pmVrTotCes MONEY,@pmVrTotPri MONEY,@pmVrTotVac MONEY,@pmVrTotInt MONEY
,@pmVrTotInd MONEY,@pmVrNeto MONEY,@pmVrBaseCes MONEY,@pmVrBaseVac MONEY,@pmIdPeriodo VARCHAR(8),@pmKeyReg VARCHAR(30),@pmNPerVac INT,@pmVrSalario MONEY,@pmIdDep VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdNom VARCHAR(4),@pmTipoLiq CHAR(1),@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmVrParCes MONEY,@pmVrParInt MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomRet SET Fecha=@pmFecha,NContrato=@pmNContrato,IdCausa=@pmIdCausa,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,DiasTrab=@pmDiasTrab,DiasNoRem=@pmDiasNoRem,VrTotDev=@pmVrTotDev,VrTotDed=@pmVrTotDed,VrTotCes=@pmVrTotCes,VrTotPri=@pmVrTotPri,VrTotVac=@pmVrTotVac,VrTotInt=@pmVrTotInt,VrTotInd=@pmVrTotInd,VrNeto=@pmVrNeto,VrBaseCes=@pmVrBaseCes,TipoLiq=@pmTipoLiq
,VrBaseVac=@pmVrBaseVac,IdPeriodo=@pmIdPeriodo,KeyReg=@pmKeyReg,NPerVac=@pmNPerVac,VrSalario=@pmVrSalario,IdDep=@pmIdDep,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdNom=@pmIdNom,pVehiculo=@pmpVehiculo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,Anulado=@pmAnulado,IdEstado=@pmIdEstado
, VrParCes=@pmVrParCes,VrParInt=@pmVrParInt,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomRetAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomRetAnu] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmAnulado BIT,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomRet SET Anulado=@pmAnulado,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomSueldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomSueldos] @pmNumero INT,@pmIdEmpleado VARCHAR(16),@pmFecha SMALLDATETIME,@pmNContrato INT,@pmVrSueAnterior MONEY,@pmVrSueNuevo MONEY,@pmVrAtAnterior MONEY,@pmVrAtNuevo MONEY
,@pmMetodoUp CHAR(1),@pmReemplzado BIT,@pmFecUltAumto SMALLDATETIME,@pmCritSelect VARCHAR(250),@pmObservacion VARCHAR(100),@pmTipoActualiza VARCHAR(10),@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
 AS 
 UPDATE Trn_NomSueldos SET Fecha=@pmFecha,NContrato=@pmNContrato,VrSueAnterior=@pmVrSueAnterior,VrSueNuevo=@pmVrSueNuevo,VrAtAnterior=@pmVrAtAnterior,VrAtNuevo=@pmVrAtNuevo,MetodoUp=@pmMetodoUp
,Reemplzado=@pmReemplzado,FecUltAumto=@pmFecUltAumto,CritSelect=@pmCritSelect,Observacion=@pmObservacion,TipoActualiza=@pmTipoActualiza
 WHERE Numero=@pmNumero AND IdEmpleado=@pmIdEmpleado
GO
/****** Object:  StoredProcedure [dbo].[paUpNomTablaRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomTablaRet] @pmnAnno INT,@pmnIntrvalo INT,@pmVrInicial MONEY,@pmVrFinal MONEY,@pmTarifa DECIMAL(10,4),@pmVrRetncion MONEY
,@pmTarExcdnte DECIMAL(10,4),@pmVrBaseExc MONEY,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE NomTablaRet SET VrInicial=@pmVrInicial,VrFinal=@pmVrFinal,Tarifa=@pmTarifa,VrRetncion=@pmVrRetncion,TarExcdnte=@pmTarExcdnte,VrBaseExc=@pmVrBaseExc
,FechaUpdate=@pmFechaUpdate
 WHERE nAnno=@pmnAnno AND nIntrvalo=@pmnIntrvalo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomVac] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmFecha SMALLDATETIME,@pmNContrato INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCantidad DECIMAL(10,4),@pmVrLiquida MONEY,@pmVrBase MONEY,@pmFecIniPmd SMALLDATETIME,@pmFecFinPmd SMALLDATETIME,@pmDiasBase INT,@pmDiasNoRem INT
,@pmDiasVac INT,@pmNNovedad INT,@pmNPeriodos INT,@pmCantRem INT,@pmVrRemndo MONEY,@pmVrTotDed MONEY,@pmVrSalario MONEY,@pmpVehiculo VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmLogPmdio VARCHAR(1500),@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmDiasAjuste INT,@pmLiqParcial BIT,@pmDiasDom INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomVac SET Fecha=@pmFecha,NContrato=@pmNContrato,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,Cantidad=@pmCantidad,VrLiquida=@pmVrLiquida,VrBase=@pmVrBase,FecIniPmd=@pmFecIniPmd,FecFinPmd=@pmFecFinPmd,DiasBase=@pmDiasBase,DiasNoRem=@pmDiasNoRem,DiasVac=@pmDiasVac,NNovedad=@pmNNovedad,NPeriodos=@pmNPeriodos
,CantRem=@pmCantRem,VrRemndo=@pmVrRemndo,VrTotDed=@pmVrTotDed,VrSalario=@pmVrSalario,pVehiculo=@pmpVehiculo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,LogPmdio=@pmLogPmdio,IdEstado=@pmIdEstado,Anulado=@pmAnulado,DiasAjuste=@pmDiasAjuste,LiqParcial=@pmLiqParcial,DiasDom=@pmDiasDom,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVacAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomVacAnu] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmIdEstado VARCHAR(4),@pmAnulado BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NomVac SET IdEstado=@pmIdEstado,Anulado=@pmAnulado,FecUpdate=@pmFecUpdate
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVacDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNomVacDet] @pmIdEmpleado VARCHAR(16),@pmNumero INT,@pmItem INT,@pmIdConcepto VARCHAR(4),@pmDetalle VARCHAR(100),@pmCantidad INT,@pmVrDevgado MONEY,@pmVrDeducido MONEY
,@pmTarifa DECIMAL(10,4),@pmVrBaseLiq MONEY,@pmVrCertfcado MONEY,@pmVrPension MONEY,@pmNPrestamo INT,@pmNCuota INT,@pmIdPeriodo VARCHAR(8),@pmVrSalud MONEY,@pmCodFondo VARCHAR(8)
 AS 
 UPDATE Trn_NomVacDet SET IdConcepto=@pmIdConcepto,Detalle=@pmDetalle,Cantidad=@pmCantidad,VrDevgado=@pmVrDevgado,VrDeducido=@pmVrDeducido,Tarifa=@pmTarifa,VrBaseLiq=@pmVrBaseLiq,VrCertfcado=@pmVrCertfcado
,VrPension=@pmVrPension,VrSalud=@pmVrSalud,NPrestamo=@pmNPrestamo,NCuota=@pmNCuota,IdPeriodo=@pmIdPeriodo,CodFondo=@pmCodFondo
 WHERE IdEmpleado=@pmIdEmpleado AND Numero=@pmNumero AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpNomVehiculos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomVehiculos] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmClaseVeh VARCHAR(50),@pmTipoAdmon VARCHAR(50)
,@pmGrupoProp VARCHAR(50),@pmVehPropio BIT,@pmCedCond VARCHAR(16),@pmConductor VARCHAR(50)
 AS 
 UPDATE NomVehiculos SET NumVeh=@pmNumVeh,ClaseVeh=@pmClaseVeh,TipoAdmon=@pmTipoAdmon,GrupoProp=@pmGrupoProp
,VehPropio=@pmVehPropio,CedCond=@pmCedCond,Conductor=@pmConductor
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpNomZonasConv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNomZonasConv] @pmIdZona VARCHAR(4),@pmZonaConv VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE NomZonasConv SET ZonaConv=@pmZonaConv,Inactivo=@pmInactivo
 WHERE IdZona=@pmIdZona
GO
/****** Object:  StoredProcedure [dbo].[paUpNotaProd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNotaProd] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16)
,@pmVrSubTotal MONEY,@pmVrCostos MONEY,@pmCantEnt DECIMAL(14,4),@pmCantSal DECIMAL(14,4),@pmNumOrden INT,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoProd INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NotaProd SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,VrSubTotal=@pmVrSubTotal,VrCostos=@pmVrCostos,CantEnt=@pmCantEnt,CantSal=@pmCantSal
,NumOrden=@pmNumOrden,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,TipoProd=@pmTipoProd,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNotaProdDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNotaProdDev] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_NotaProd SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNotas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFechaVence SMALLDATETIME,@pmVrSubTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrCosto MONEY,@pmVrSancion MONEY,@pmVrOtros MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY
,@pmVrAnticipo MONEY,@pmCantidad DECIMAL(14,4),@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4)
,@pmCodTarCom VARCHAR(4),@pmCdCajero VARCHAR(11),@pmIdLocal VARCHAR(8),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2),@pmFecDcm SMALLDATETIME,@pmCdProducto VARCHAR(16),@pmCdForma VARCHAR(4),@pmNumCheque VARCHAR(20),@pmCdBanco VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmPrestCaja BIT
,@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmnRemesa INT,@pmCdCiaRem CHAR(2),@pmItemRem INT,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmIdConcFE INT,@pmTipoNotaFE INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Notas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FechaVence=@pmFechaVence,VrSubTotal=@pmVrSubTotal,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrCosto=@pmVrCosto,VrSancion=@pmVrSancion,VrOtros=@pmVrOtros,VrNeto=@pmVrNeto,VrAplicado=@pmVrAplicado,VrAnticipo=@pmVrAnticipo,Cantidad=@pmCantidad,BaseImp=@pmBaseImp
,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,CdCajero=@pmCdCajero,IdLocal=@pmIdLocal,Referencia=@pmReferencia
,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,FecDcm=@pmFecDcm,CdProducto=@pmCdProducto,CdForma=@pmCdForma,NumCheque=@pmNumCheque,CdBanco=@pmCdBanco,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,PrestCaja=@pmPrestCaja,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion
,IdEstado=@pmIdEstado,nRemesa=@pmnRemesa,CdCiaRem=@pmCdCiaRem,ItemRem=@pmItemRem,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,IdConcFE=@pmIdConcFE,TipoNotaFE=@pmTipoNotaFE,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNotasBuses]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpNotasBuses] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmValorTotal MONEY,@pmValorIva MONEY,@pmValorReteFte MONEY,@pmValorReteIca MONEY,@pmValorCosto MONEY,@pmValorSancion MONEY,@pmValorNeto MONEY,@pmValorAplicado MONEY
,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmIdTarCom VARCHAR(4),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmPrestCaja BIT,@pmIntMora BIT,@pmNumCheque VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdClase VARCHAR(4),@pmIdCargo VARCHAR(4),@pmReferencia VARCHAR(20),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmBaseIva MONEY,@pmBaseRet MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmIdTarIva VARCHAR(4)
,@pmIdTarRet VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmIdConcFE INT,@pmTipoNotaFE INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_NotasBuses SET Fecha=@pmFecha,FecVence=@pmFecVence,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,VehPropio=@pmVehPropio,ValorTotal=@pmValorTotal,ValorIva=@pmValorIva,ValorReteFte=@pmValorReteFte,ValorReteIca=@pmValorReteIca,ValorCosto=@pmValorCosto,ValorSancion=@pmValorSancion,ValorNeto=@pmValorNeto,ValorAplicado=@pmValorAplicado,IdVendedor=@pmIdVendedor,Comision=@pmComision
,IdTarCom=@pmIdTarCom,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,PrestCaja=@pmPrestCaja,IntMora=@pmIntMora,NumCheque=@pmNumCheque,IdBanco=@pmIdBanco,IdCCosto=@pmIdCCosto,IdClase=@pmIdClase,IdCargo=@pmIdCargo,Referencia=@pmReferencia,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,BaseIva=@pmBaseIva,BaseRet=@pmBaseRet,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,IdTarIva=@pmIdTarIva,IdTarRet=@pmIdTarRet,TipCom=@pmTipCom
,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,IdConcFE=@pmIdConcFE,TipoNotaFE=@pmTipoNotaFE,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpNovedadRep]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNovedadRep] @pmIdNov VARCHAR(4),@pmNovedad VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE NovedadRep SET Novedad=@pmNovedad,Inactivo=@pmInactivo
 WHERE IdNov=@pmIdNov
GO
/****** Object:  StoredProcedure [dbo].[paUpNovedadTra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpNovedadTra] @pmIdNovedad VARCHAR(4),@pmNovedad VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE NovedadTra SET Novedad=@pmNovedad,Inactivo=@pmInactivo
 WHERE IdNovedad=@pmIdNovedad
GO
/****** Object:  StoredProcedure [dbo].[paUpObjetosApp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpObjetosApp] @pmIdObj VARCHAR(10),@pmIdGrupo VARCHAR(6),@pmSubModulo VARCHAR(3),@pmIndObj INT,@pmNombre VARCHAR(100)
,@pmFormulario VARCHAR(10),@pmPermisos VARCHAR(20),@pmNivelMinimo INT,@pmNomArchivo VARCHAR(30)
 AS 
 UPDATE Sys_ObjetosApp SET IdGrupo=@pmIdGrupo,SubModulo=@pmSubModulo,IndObj=@pmIndObj,Nombre=@pmNombre
,Formulario=@pmFormulario,Permisos=@pmPermisos,NivelMinimo=@pmNivelMinimo,NomArchivo=@pmNomArchivo
 WHERE IdObj=@pmIdObj
GO
/****** Object:  StoredProcedure [dbo].[paUpOComb]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOComb] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaDesp SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdVend VARCHAR(16)
,@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmDirEnvio VARCHAR(250),@pmIdLocal VARCHAR(8),@pmLugarEnv VARCHAR(50),@pmDiasEntraga INT,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150)
,@pmCdRuta VARCHAR(4),@pmReferncia VARCHAR(50),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(150),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmTipGui VARCHAR(3),@pmGuia INT,@pmIdCiaGui CHAR(2),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2)
,@pmFechaFact SMALLDATETIME,@pmAutzaMora INT,@pmAutzaCupo INT,@pmAprobacion INT,@pmFechaAprob SMALLDATETIME,@pmDetalleAprob VARCHAR(250),@pmCdUsuAprob VARCHAR(11),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmIdTerminal VARCHAR(4),@pmTipoOrden INT,@pmRemolque VARCHAR(10),@pmVrImpCarbono MONEY,@pmVrIvaIngProd MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_OComb SET Fecha=@pmFecha,FechaDesp=@pmFechaDesp,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros,VrCargos=@pmVrCargos
,VrOtrDcto=@pmVrOtrDcto,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,DirEnvio=@pmDirEnvio,IdLocal=@pmIdLocal,LugarEnv=@pmLugarEnv,DiasEntraga=@pmDiasEntraga,IdVehiculo=@pmIdVehiculo
,IdConductor=@pmIdConductor,NitEmpTrans=@pmNitEmpTrans,EmpTrans=@pmEmpTrans,CdRuta=@pmCdRuta,Referncia=@pmReferncia,IdForma=@pmIdForma,DetallePago=@pmDetallePago,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,TipGui=@pmTipGui,Guia=@pmGuia,IdCiaGui=@pmIdCiaGui,TipFac=@pmTipFac,Factura=@pmFactura
,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact,TipPed=@pmTipPed,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,AutzaMora=@pmAutzaMora,AutzaCupo=@pmAutzaCupo,Aprobacion=@pmAprobacion,FechaAprob=@pmFechaAprob,DetalleAprob=@pmDetalleAprob,CdUsuAprob=@pmCdUsuAprob,Anulado=@pmAnulado
,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,ZonaFrontera=@pmZonaFrontera,IdTerminal=@pmIdTerminal,TipoOrden=@pmTipoOrden,Remolque=@pmRemolque,VrImpCarbono=@pmVrImpCarbono,VrIvaIngProd=@pmVrIvaIngProd,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombAbr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCombAbr] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
,@pmTipGui VARCHAR(3),@pmGuia INT,@pmIdCiaGui CHAR(2),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2)
,@pmFechaFact SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_OComb SET  TipGui=@pmTipGui,Guia=@pmGuia,IdCiaGui=@pmIdCiaGui,TipFac=@pmTipFac,Factura=@pmFactura
,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCombAnu] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OComb SET  Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOCombApr] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
,@pmAprobacion INT,@pmFechaAprob SMALLDATETIME,@pmDetalleAprob VARCHAR(250),@pmCdUsuAprob VARCHAR(11)
,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OComb SET Aprobacion=@pmAprobacion,FechaAprob=@pmFechaAprob,DetalleAprob=@pmDetalleAprob
,CdUsuAprob=@pmCdUsuAprob,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCombFac] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OComb SET TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCombGui]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCombGui] @pmTipDoc VARCHAR(3),@pmOCargue INT,@pmIdCia CHAR(2)
,@pmTipGui VARCHAR(3),@pmGuia INT,@pmIdCiaGui CHAR(2)
 AS 
 UPDATE Trn_OComb SET TipGui=@pmTipGui,Guia=@pmGuia,IdCiaGui=@pmIdCiaGui
 WHERE TipDoc=@pmTipDoc AND OCargue=@pmOCargue AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOCompra] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY
,@pmVrOtros MONEY,@pmVrCargos MONEY,@pmVrOtrDcto MONEY,@pmVrSobtasa MONEY,@pmVrImpGlobal MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdEmpresa VARCHAR(16),@pmDirEntrega VARCHAR(250),@pmIdLocEtga VARCHAR(8),@pmDiasEntraga INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150)
,@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(100),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmLiqFletes BIT
,@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipEnt VARCHAR(3),@pmEntrada INT,@pmIdCiaEnt CHAR(2),@pmNumAutoriza INT,@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME
,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4),@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmVrReteIVA MONEY,@pmCodTarRiv VARCHAR(4),@pmNivelAprob INT,@pmVrIvaMvc MONEY
,@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmNumDocSop INT,@pmCdCiaSop CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_OCompra SET Fecha=@pmFecha,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdProv=@pmIdProv,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrSobtasa=@pmVrSobtasa,VrImpGlobal=@pmVrImpGlobal
,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,IdEmpresa=@pmIdEmpresa,DirEntrega=@pmDirEntrega,IdLocEtga=@pmIdLocEtga,DiasEntraga=@pmDiasEntraga,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdForma=@pmIdForma,DetallePago=@pmDetallePago
,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CdMney=@pmCdMney,NitEmpTrans=@pmNitEmpTrans,EmpTrans=@pmEmpTrans,LiqFletes=@pmLiqFletes,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipEnt=@pmTipEnt,Entrada=@pmEntrada,IdCiaEnt=@pmIdCiaEnt,NumAutoriza=@pmNumAutoriza,Modalidad=@pmModalidad,Vigencia=@pmVigencia
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,NumAprob=@pmNumAprob,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob,IdEstado=@pmIdEstado,NivelAprob=@pmNivelAprob,VrIvaMvc=@pmVrIvaMvc
,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,FecUpdate=@pmFecUpdate,VrReteIVA=@pmVrReteIVA,CodTarRiv=@pmCodTarRiv,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP
,NumDocSop=@pmNumDocSop,CdCiaSop=@pmCdCiaSop
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraAbr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCompraAbr] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2)
,@pmEntrada INT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_OCompra SET IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Observacion=@pmObservacion
,Entrada=@pmEntrada
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCompraAnu] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OCompra SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraApb]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCompraApb] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2)
,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4)
,@pmNivelAprob INT
 AS 
 UPDATE Trn_OCompra SET Observacion=@pmObservacion,NumAprob=@pmNumAprob,FecAprob=@pmFecAprob
,CdUsuAprob=@pmCdUsuAprob,IdEstado=@pmIdEstado,NivelAprob=@pmNivelAprob
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOCompraApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOCompraApl] @pmTipDoc VARCHAR(3),@pmOCompra INT,@pmIdCia CHAR(2)
,@pmTipEnt VARCHAR(3),@pmEntrada INT,@pmIdCiaEnt CHAR(2),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OCompra 
 SET  TipEnt=@pmTipEnt,Entrada=@pmEntrada,IdCiaEnt=@pmIdCiaEnt,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND OCompra=@pmOCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOcupaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOcupaciones] @pmIdOcupac VARCHAR(4),@pmOcupacion VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE Ocupaciones SET Ocupacion=@pmOcupacion,Inactivo=@pmInactivo
 WHERE IdOcupac=@pmIdOcupac
GO
/****** Object:  StoredProcedure [dbo].[paUpOilAjustes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilAjustes] @pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecProceso SMALLDATETIME,@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmTipoProceso VARCHAR(10),@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCantEntradas DECIMAL(16,6),@pmCantSalidas DECIMAL(16,6),@pmCostoEnt DECIMAL(16,6),@pmCostoSal DECIMAL(16,6),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilAjustes SET Fecha=@pmFecha,FecProceso=@pmFecProceso,TipOrden=@pmTipOrden,NumOrden=@pmNumOrden,IdCiaOrden=@pmIdCiaOrden,TipoProceso=@pmTipoProceso,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,CantEntradas=@pmCantEntradas,CantSalidas=@pmCantSalidas,CostoEnt=@pmCostoEnt,CostoSal=@pmCostoSal,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCompra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilCompra] @pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCxPagar BIT,@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmImpuesto DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmReteIva DECIMAL(16,6),@pmIvaIngProd DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmFletes DECIMAL(16,6),@pmVrNeto DECIMAL(16,6),@pmCantidad DECIMAL(16,6),@pmBaseImp DECIMAL(16,6),@pmBaseRet DECIMAL(16,6),@pmBaseIvaIgp DECIMAL(16,6),@pmTarifaIva DECIMAL(16,6),@pmTarifaRet DECIMAL(16,6),@pmTarifaIca DECIMAL(16,6),@pmTarifaRiv DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4)
,@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmEstRegCosto INT,@pmNumRegCosto INT,@pmCiaRegCosto CHAR(2)
 AS 
 UPDATE Trn_OilCompra SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdProveedor=@pmIdProveedor,NumFactura=@pmNumFactura,FechaFac=@pmFechaFac,FechaVence=@pmFechaVence,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CxPagar=@pmCxPagar,SubTotal=@pmSubTotal,Descuento=@pmDescuento,Impuesto=@pmImpuesto,Retencion=@pmRetencion,ReteIca=@pmReteIca,ReteIva=@pmReteIva,IvaIngProd=@pmIvaIngProd,OtrosCargos=@pmOtrosCargos,OtrosDctos=@pmOtrosDctos,Fletes=@pmFletes,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIvaIgp=@pmBaseIvaIgp,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,Modalidad=@pmModalidad,FechaInicio=@pmFechaInicio,FechaFinal=@pmFechaFinal,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,FecDev=@pmFecDev,NumDev=@pmNumDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,EstRegCosto=@pmEstRegCosto,NumRegCosto=@pmNumRegCosto,CiaRegCosto=@pmCiaRegCosto
 WHERE TipDoc=@pmTipDoc AND NumCompra=@pmNumCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCompraDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilCompraDev] @pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilCompra SET Anulado=@pmAnulado,FecDev=@pmFecDev,NumDev=@pmNumDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumCompra=@pmNumCompra AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCostos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilCostos] @pmTipProc VARCHAR(3),@pmNumProceso INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmNitProveedor VARCHAR(16),@pmCodCiaFac CHAR(2),@pmCantidad DECIMAL(16,6),@pmSubTotal DECIMAL(20,6),@pmVrTransporte DECIMAL(20,6),@pmVrTraVacio DECIMAL(20,6),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000)
 AS 
 UPDATE Trn_OilCostos SET Fecha=@pmFecha,FechaInicio=@pmFechaInicio,FechaFinal=@pmFechaFinal,IdConcepto=@pmIdConcepto,NitProveedor=@pmNitProveedor,CodCiaFac=@pmCodCiaFac,Cantidad=@pmCantidad,SubTotal=@pmSubTotal,VrTransporte=@pmVrTransporte,VrTraVacio=@pmVrTraVacio,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,NumDev=@pmNumDev,Observacion=@pmObservacion
 WHERE TipProc=@pmTipProc AND NumProceso=@pmNumProceso AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilCostoVen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilCostoVen] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(20,6),@pmCantDev DECIMAL(16,6),@pmVrDevFact DECIMAL(20,6),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilCostoVen SET Fecha=@pmFecha,FechaInicio=@pmFechaInicio,FechaFinal=@pmFechaFinal,IdConcepto=@pmIdConcepto,Cantidad=@pmCantidad,ValorTotal=@pmValorTotal,CantDev=@pmCantDev,VrDevFact=@pmVrDevFact,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilDespClie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilDespClie] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecDescargue SMALLDATETIME,@pmHorasVig DECIMAL(14,4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmRemolque VARCHAR(10),@pmIdEstacion VARCHAR(4),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmLugarOrigen VARCHAR(150),@pmDirDestino VARCHAR(250),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmModalidad VARCHAR(10),@pmReferencia VARCHAR(50),@pmNumRemision VARCHAR(20),@pmDetSellos VARCHAR(500)
,@pmCodSicom VARCHAR(20),@pmZonaFrontera INT,@pmCantidad DECIMAL(16,6),@pmSubTotal DECIMAL(16,6),@pmVrIva DECIMAL(16,6),@pmVrTransporte DECIMAL(16,6),@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmEstFactura INT,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilDespClie SET Fecha=@pmFecha,FecCargue=@pmFecCargue,FecDespacho=@pmFecDespacho,FecDescargue=@pmFecDescargue,HorasVig=@pmHorasVig,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,NitEmpTrans=@pmNitEmpTrans,NomEmpTrans=@pmNomEmpTrans,Remolque=@pmRemolque,IdEstacion=@pmIdEstacion,IdLocOrigen=@pmIdLocOrigen,IdLocDestino=@pmIdLocDestino,LugarOrigen=@pmLugarOrigen,DirDestino=@pmDirDestino,NomContacto=@pmNomContacto,TelContacto=@pmTelContacto,emlContacto=@pmemlContacto,Modalidad=@pmModalidad,Referencia=@pmReferencia,NumRemision=@pmNumRemision,DetSellos=@pmDetSellos,CodSicom=@pmCodSicom,ZonaFrontera=@pmZonaFrontera,Cantidad=@pmCantidad,SubTotal=@pmSubTotal,VrIva=@pmVrIva
,VrTransporte=@pmVrTransporte,TipOrden=@pmTipOrden,NumOrden=@pmNumOrden,IdCiaOrden=@pmIdCiaOrden,EstFactura=@pmEstFactura,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilDevCompra]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilDevCompra] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumCompra INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmCxPagar BIT,@pmSubTotal DECIMAL(16,6),@pmDescuento DECIMAL(16,6),@pmImpuesto DECIMAL(16,6),@pmRetencion DECIMAL(16,6),@pmReteIca DECIMAL(16,6),@pmReteIva DECIMAL(16,6),@pmIvaIngProd DECIMAL(16,6),@pmOtrosCargos DECIMAL(16,6),@pmOtrosDctos DECIMAL(16,6),@pmFletes DECIMAL(16,6),@pmVrNeto DECIMAL(16,6),@pmCantidad DECIMAL(16,6),@pmBaseImp DECIMAL(16,6),@pmBaseRet DECIMAL(16,6),@pmBaseIvaIgp DECIMAL(16,6)
,@pmTarifaIva DECIMAL(16,6),@pmTarifaRet DECIMAL(16,6),@pmTarifaIca DECIMAL(16,6),@pmTarifaRiv DECIMAL(16,6),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(2000)
 AS 
 UPDATE Trn_OilDevCompra SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumCompra=@pmNumCompra,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdProveedor=@pmIdProveedor,NumFactura=@pmNumFactura,CxPagar=@pmCxPagar,SubTotal=@pmSubTotal,Descuento=@pmDescuento,Impuesto=@pmImpuesto,Retencion=@pmRetencion,ReteIca=@pmReteIca,ReteIva=@pmReteIva,IvaIngProd=@pmIvaIngProd,OtrosCargos=@pmOtrosCargos,OtrosDctos=@pmOtrosDctos,Fletes=@pmFletes,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIvaIgp=@pmBaseIvaIgp,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos
,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilDevCostos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilDevCostos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmNumProceso INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmCantidad DECIMAL(16,6),@pmSubTotal DECIMAL(20,6),@pmVrTransporte DECIMAL(20,6),@pmVrTraVacio DECIMAL(20,6),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(2000)
 AS 
 UPDATE Trn_OilDevCostos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,NumProceso=@pmNumProceso,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,Cantidad=@pmCantidad,SubTotal=@pmSubTotal,VrTransporte=@pmVrTransporte,VrTraVacio=@pmVrTraVacio,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilEntrada]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilEntrada] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmNumGuia INT,@pmIdCiaGuia CHAR(2),@pmFecDespacho SMALLDATETIME,@pmFecDescargue SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmRemolque VARCHAR(10),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT,@pmTipFactCxp VARCHAR(3),@pmNumFactura INT,@pmIdCiaCxp CHAR(2),@pmEstContable INT,@pmCdConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmTipoAju VARCHAR(3),@pmNumAjuInv INT,@pmIdCiaAju CHAR(2),@pmCantAjuste DECIMAL(16,6),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2)
 AS 
 UPDATE Trn_OilEntrada SET Fecha=@pmFecha,NumGuia=@pmNumGuia,IdCiaGuia=@pmIdCiaGuia,FecDespacho=@pmFecDespacho,FecDescargue=@pmFecDescargue,IdProveedor=@pmIdProveedor,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,NitEmpTrans=@pmNitEmpTrans,NomEmpTrans=@pmNomEmpTrans,Remolque=@pmRemolque,ValorTotal=@pmValorTotal,CtaPagar=@pmCtaPagar,TipFactCxp=@pmTipFactCxp,NumFactura=@pmNumFactura,IdCiaCxp=@pmIdCiaCxp,EstContable=@pmEstContable,CdConcepto=@pmCdConcepto,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=@pmIdEstado,TipoAju=@pmTipoAju,NumAjuInv=@pmNumAjuInv,IdCiaAju=@pmIdCiaAju,CantAjuste=@pmCantAjuste,NumFactTra=@pmNumFactTra,CdCiaFtr=@pmCdCiaFtr
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilGuia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilGuia] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdEstacion VARCHAR(4),@pmIdProducto VARCHAR(16),@pmCantBruto DECIMAL(16,6),@pmCantNeto DECIMAL(16,6),@pmUndMed VARCHAR(10),@pmTemperatura DECIMAL(16,6),@pmUnidTemp CHAR(1),@pmValorAPI DECIMAL(16,6),@pmValorVCW DECIMAL(16,6),@pmCantDescargue DECIMAL(16,6),@pmAPIDescargue DECIMAL(16,6),@pmTempDescargue DECIMAL(16,6),@pmFecDescargue SMALLDATETIME
,@pmNitEmpTrans VARCHAR(16),@pmNomEmpTrans VARCHAR(150),@pmNumRemision VARCHAR(20),@pmRemolque VARCHAR(10),@pmTipoEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaEnt CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmNumFactCom INT,@pmCdCiaFco CHAR(2),@pmNumFactTra INT,@pmCdCiaFtr CHAR(2)
 AS 
 UPDATE Trn_OilGuia SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,IdProveedor=@pmIdProveedor,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdEstacion=@pmIdEstacion,IdProducto=@pmIdProducto,CantBruto=@pmCantBruto,CantNeto=@pmCantNeto,UndMed=@pmUndMed,Temperatura=@pmTemperatura,UnidTemp=@pmUnidTemp,ValorAPI=@pmValorAPI,ValorVCW=@pmValorVCW,CantDescargue=@pmCantDescargue,APIDescargue=@pmAPIDescargue,TempDescargue=@pmTempDescargue,FecDescargue=@pmFecDescargue,NitEmpTrans=@pmNitEmpTrans,NomEmpTrans=@pmNomEmpTrans,NumRemision=@pmNumRemision,Remolque=@pmRemolque
,TipoEnt=@pmTipoEnt,NumEntrada=@pmNumEntrada,IdCiaEnt=@pmIdCiaEnt,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NumFactCom=@pmNumFactCom,CdCiaFco=@pmCdCiaFco,NumFactTra=@pmNumFactTra,CdCiaFtr=@pmCdCiaFtr
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilInvent]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilInvent] @pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmIdProveedor VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFechaFac SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT,@pmEstContable INT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmNumDev INT,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilInvent SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,IdProveedor=@pmIdProveedor,NumFactura=@pmNumFactura,FechaFac=@pmFechaFac,FechaVence=@pmFechaVence,Cantidad=@pmCantidad,ValorTotal=@pmValorTotal,CtaPagar=@pmCtaPagar,EstContable=@pmEstContable,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,NumDev=@pmNumDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipEnt=@pmTipEnt AND NumEntrada=@pmNumEntrada AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilInventDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilInventDev] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipEnt VARCHAR(3),@pmNumEntrada INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProveedor VARCHAR(16),@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmCtaPagar BIT
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(2000)
 AS 
 UPDATE Trn_OilInventDev SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipEnt=@pmTipEnt,NumEntrada=@pmNumEntrada,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdProveedor=@pmIdProveedor,Cantidad=@pmCantidad,ValorTotal=@pmValorTotal,CtaPagar=@pmCtaPagar,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilMediciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilMediciones] @pmTipDoc VARCHAR(3),@pmNumInvent INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecProceso SMALLDATETIME,@pmIdTurno VARCHAR(4),@pmIdOperario VARCHAR(16),@pmNomOperario VARCHAR(150),@pmAjuInvSob INT,@pmAjuInvFal INT,@pmIdCiaAin CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipDocAju VARCHAR(3),@pmVolPT DECIMAL(16,6),@pmVolMP DECIMAL(16,6),@pmNumNota INT,@pmFecProcAnt SMALLDATETIME,@pmNumHoras DECIMAL(14,4),@pmNumSalida INT,@pmNumNcp INT,@pmIdCiaNcp CHAR(2)
 AS 
 UPDATE Trn_OilMediciones SET Fecha=@pmFecha,FecProceso=@pmFecProceso,IdTurno=@pmIdTurno,IdOperario=@pmIdOperario,NomOperario=@pmNomOperario,AjuInvSob=@pmAjuInvSob,AjuInvFal=@pmAjuInvFal,IdCiaAin=@pmIdCiaAin,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,Modalidad=@pmModalidad,TipDocAju=@pmTipDocAju,VolPT=@pmVolPT,VolMP=@pmVolMP,NumNota=@pmNumNota,FecProcAnt=@pmFecProcAnt,NumHoras=@pmNumHoras,NumSalida=@pmNumSalida,NumNcp=@pmNumNcp,IdCiaNcp=@pmIdCiaNcp 
 WHERE TipDoc=@pmTipDoc AND NumInvent=@pmNumInvent AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilNotas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilNotas] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCantidad DECIMAL(16,6),@pmValorTotal DECIMAL(16,6),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilNotas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,Cantidad=@pmCantidad,ValorTotal=@pmValorTotal,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOilTraslado]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOilTraslado] @pmTipDoc VARCHAR(3),@pmNumNota INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaInicio SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmCantMP DECIMAL(16,6),@pmCantProducido DECIMAL(16,6),@pmCantConsumo DECIMAL(16,6),@pmCantCrudoCom DECIMAL(16,6),@pmTotal_MP DECIMAL(20,6),@pmVU_MP DECIMAL(20,6),@pmCantBrutoMP DECIMAL(16,6),@pmCantNetoMP DECIMAL(16,6),@pmCantFactMP DECIMAL(16,6),@pmTotal_TRA DECIMAL(20,6),@pmVU_TRA DECIMAL(20,6)
,@pmCantNetoTRA DECIMAL(16,6),@pmCantFactTRA DECIMAL(16,6),@pmTotal_TVacio DECIMAL(20,6),@pmVU_TVacio DECIMAL(20,6),@pmCantNetoTv DECIMAL(16,6),@pmCantFactTv DECIMAL(16,6),@pmTotal_Standby DECIMAL(20,6),@pmVU_Standby DECIMAL(20,6),@pmCant_Standby DECIMAL(16,6),@pmTotal_MOD DECIMAL(20,6),@pmTotal_CIF DECIMAL(20,6),@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_OilTraslado SET Fecha=@pmFecha,FechaInicio=@pmFechaInicio,FechaFinal=@pmFechaFinal,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,CantMP=@pmCantMP,CantProducido=@pmCantProducido,CantConsumo=@pmCantConsumo,CantCrudoCom=@pmCantCrudoCom,Total_MP=@pmTotal_MP,VU_MP=@pmVU_MP,CantBrutoMP=@pmCantBrutoMP,CantNetoMP=@pmCantNetoMP,CantFactMP=@pmCantFactMP,Total_TRA=@pmTotal_TRA,VU_TRA=@pmVU_TRA,CantNetoTRA=@pmCantNetoTRA,CantFactTRA=@pmCantFactTRA,Total_TVacio=@pmTotal_TVacio,VU_TVacio=@pmVU_TVacio,CantNetoTv=@pmCantNetoTv,CantFactTv=@pmCantFactTv
,Total_Standby=@pmTotal_Standby,VU_Standby=@pmVU_Standby,Cant_Standby=@pmCant_Standby,Total_MOD=@pmTotal_MOD,Total_CIF=@pmTotal_CIF,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumNota=@pmNumNota AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOpciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpciones] @pmIdOpc VARCHAR(3),@pmOpcion VARCHAR(100),@pmTipoDato VARCHAR(15)
,@pmValor VARCHAR(100),@pmNivUp INT,@pmnModulo VARCHAR(10)
 AS 
 UPDATE adm_Opciones SET Opcion=@pmOpcion,TipoDato=@pmTipoDato,Valor=@pmValor
,NivUp=@pmNivUp,nModulo=@pmnModulo
 WHERE IdOpc=@pmIdOpc
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOpedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdClieFact VARCHAR(16),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrCargos MONEY
,@pmVrOtrDcto MONEY,@pmVrSobretasa MONEY,@pmVrImpGlobal MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmDirEnvio VARCHAR(250),@pmIdLocEnv VARCHAR(8),@pmLugarEnvio VARCHAR(50),@pmDiasEntraga INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20)
,@pmemlContac VARCHAR(100),@pmCargoContac VARCHAR(50),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(100),@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmAsignarVeh BIT,@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmCdRuta VARCHAR(4),@pmListaPrec CHAR(1),@pmRefPedido VARCHAR(50)
,@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmNumAutoriza INT,@pmNumAutCupo INT,@pmNumAutCheq INT,@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME,@pmDetalleAprob VARCHAR(250),@pmCdUsuAprob VARCHAR(11),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2)
,@pmFechaRem SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmZonaFrontera INT,@pmTipoTrans INT,@pmTipoOrden VARCHAR(3),@pmTipoModifica VARCHAR(10),@pmNumCotizac INT,@pmCdCiaCotizac CHAR(2),@pmNumAutSicom VARCHAR(50),@pmVrImpCarbono MONEY,@pmBaseIvaIgp MONEY,@pmVrIvaIngProd MONEY,@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Opedido SET Fecha=@pmFecha,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdClieFact=@pmIdClieFact,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros,VrCargos=@pmVrCargos,VrOtrDcto=@pmVrOtrDcto,VrSobretasa=@pmVrSobretasa,VrImpGlobal=@pmVrImpGlobal,VrNeto=@pmVrNeto
,Cantidad=@pmCantidad,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,DirEnvio=@pmDirEnvio,IdLocEnv=@pmIdLocEnv,LugarEnvio=@pmLugarEnvio,DiasEntraga=@pmDiasEntraga,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargoContac=@pmCargoContac,IdForma=@pmIdForma,DetallePago=@pmDetallePago,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo
,CdMney=@pmCdMney,NitEmpTrans=@pmNitEmpTrans,EmpTrans=@pmEmpTrans,AsignarVeh=@pmAsignarVeh,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,CdRuta=@pmCdRuta,ListaPrec=@pmListaPrec,RefPedido=@pmRefPedido,Modalidad=@pmModalidad,Vigencia=@pmVigencia,NumAutoriza=@pmNumAutoriza,NumAutCupo=@pmNumAutCupo,NumAutCheq=@pmNumAutCheq,NumAprob=@pmNumAprob,IdCiaApr=@pmIdCiaApr
,FecAprob=@pmFecAprob,DetalleAprob=@pmDetalleAprob,CdUsuAprob=@pmCdUsuAprob,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact,TipRem=@pmTipRem,Remision=@pmRemision,IdCiaRem=@pmIdCiaRem,FechaRem=@pmFechaRem,NumCotizac=@pmNumCotizac,CdCiaCotizac=@pmCdCiaCotizac,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,TipoModifica=@pmTipoModifica,IdEstado=@pmIdEstado
,ZonaFrontera=@pmZonaFrontera,TipoTrans=@pmTipoTrans,TipoOrden=@pmTipoOrden, FecUpdate=@pmFecUpdate,NumAutSicom=@pmNumAutSicom,VrImpCarbono=@pmVrImpCarbono,BaseIvaIgp=@pmBaseIvaIgp,VrIvaIngProd=@pmVrIvaIngProd,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoAbf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoAbf] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmRemision INT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
AS 
 UPDATE Trn_Opedido SET TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Remision=@pmRemision,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoAnu] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Opedido SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoApr] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11)
,@pmIdEstado VARCHAR(4),@pmIdCiaApr CHAR(2),@pmDetalleAprob VARCHAR(250)
 AS 
 UPDATE Trn_Opedido SET IdEstado=@pmIdEstado,NumAprob=@pmNumAprob,FecAprob=@pmFecAprob
,CdUsuAprob=@pmCdUsuAprob,IdCiaApr=@pmIdCiaApr,DetalleAprob=@pmDetalleAprob
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoBlo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoBlo] @pmTipDoc VARCHAR(3),@pmIdCia CHAR(2),@pmModalidad VARCHAR(10)
,@pmFecha SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Opedido SET Anulado=@pmAnulado,FecDev=@pmFecDev,IdEstado=@pmIdEstado
,NumAprob=0,IdCiaApr='00'
 WHERE TipDoc=@pmTipDoc AND IdEstado='0001' AND Anulado=0 AND NumAprob>0 AND Factura<=0
 AND FechaVence<=@pmFecha
 AND Modalidad LIKE ISNULL(@pmModalidad,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoDvs]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoDvs] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmIdEstado VARCHAR(4)
AS 
 UPDATE Trn_Opedido SET TipFac='0',Factura=0,IdCiaFac='00',IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia AND TipFac='SAL'
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoFac] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmIdEstado VARCHAR(4)
AS 
 UPDATE Trn_Opedido SET TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac
,FechaFact=@pmFechaFact,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOpedidoRem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpOpedidoRem] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmTipRem VARCHAR(3),@pmRemision INT,@pmIdCiaRem CHAR(2),@pmFechaRem SMALLDATETIME
 AS 
 UPDATE Trn_Opedido SET TipRem=@pmTipRem,Remision=@pmRemision,IdCiaRem=@pmIdCiaRem,FechaRem=@pmFechaRem
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpOrgTransito]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpOrgTransito] @pmIdOrgTra VARCHAR(8),@pmNomOrgTrans VARCHAR(250),@pmIdLocal VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE OrgTransito SET NomOrgTrans=@pmNomOrgTrans,IdLocal=@pmIdLocal,Inactivo=@pmInactivo
 WHERE IdOrgTra=@pmIdOrgTra
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosACns]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPagosACns] @pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
 AS 
 UPDATE  Trn_Pagos SET  DocRef=0,IdCiaRef='00',ItemDoc=0
 WHERE TipDoc<>'CNS' AND TipRef=@pmTipRef AND DocRef=@pmDocRef AND IdCiaRef=@pmIdCiaRef
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosCnChe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPagosCnChe] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmIdForma VARCHAR(4),@pmIdBanco VARCHAR(4),@pmNumForma VARCHAR(20)
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmItemDoc INT
 AS 
 UPDATE  Trn_Pagos SET  TipRef=@pmTipRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef,ItemDoc=@pmItemDoc
 WHERE TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdForma=@pmIdForma AND Item=ISNULL(@pmItem,Item)
 AND IdBanco=@pmIdBanco AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosCnEfe]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPagosCnEfe] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmIdForma VARCHAR(4),@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2),@pmItemDoc INT
 AS 
 UPDATE  Trn_Pagos SET  TipRef=@pmTipRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef,ItemDoc=@pmItemDoc
 WHERE TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdForma=@pmIdForma AND Item=ISNULL(@pmItem,Item)
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPagosDoc] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
 AS 
 UPDATE  Trn_Pagos SET  TipRef=@pmTipRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef
 WHERE TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosEod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPagosEod] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmTipRef VARCHAR(3)
 AS 
 UPDATE  Trn_Pagos SET  TipRef='0',DocRef=0,IdCiaRef='00'
 WHERE TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia AND TipRef=@pmTipRef
GO
/****** Object:  StoredProcedure [dbo].[paUpPagosFor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPagosFor] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2)
,@pmIdForma VARCHAR(4),@pmIdBanco VARCHAR(4),@pmNumForma VARCHAR(20)
,@pmTipRef VARCHAR(3),@pmDocRef INT,@pmIdCiaRef CHAR(2)
 AS 
 UPDATE  Trn_Pagos SET  TipRef=@pmTipRef,DocRef=@pmDocRef,IdCiaRef=@pmIdCiaRef
 WHERE TipDoc=@pmTipDoc AND  Documento=@pmDocumento AND IdCia=@pmIdCia
 AND IdForma=@pmIdForma AND IdBanco=@pmIdBanco AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paUpPaises]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPaises] @pmIdPais VARCHAR(8),@pmCodISO VARCHAR(3),@pmNombrePais VARCHAR(50),@pmIdMneda VARCHAR(5)
 AS 
 UPDATE adm_Paises SET CodISO=@pmCodISO,NombrePais=@pmNombrePais,IdMneda=@pmIdMneda
 WHERE IdPais=@pmIdPais
GO
/****** Object:  StoredProcedure [dbo].[paUpPeajesCat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPeajesCat] @pmIdCat VARCHAR(4),@pmCatpeaje VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE PeajesCat SET Catpeaje=@pmCatpeaje,Inactivo=@pmInactivo
 WHERE IdCat=@pmIdCat
GO
/****** Object:  StoredProcedure [dbo].[paUpPeajesClase]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPeajesClase] @pmIdClase VARCHAR(4),@pmClasePeaje VARCHAR(50),@pmNitConsec VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE PeajesClase SET ClasePeaje=@pmClasePeaje,NitConsec=@pmNitConsec,Inactivo=@pmInactivo
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpPeajesTarf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPeajesTarf] @pmIdCat VARCHAR(4),@pmIdClase VARCHAR(4),@pmVrTarifa MONEY
 AS 
 UPDATE PeajesTarf SET VrTarifa=@pmVrTarifa
 WHERE IdCat=@pmIdCat AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpPermisos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPermisos] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmConsecutivo INT,@pmPerAdd BIT,@pmPerUpdate BIT
,@pmPerDelete BIT,@pmPerAnular BIT,@pmPerRead BIT,@pmPerRename BIT
 AS 
 UPDATE adm_Permisos SET PerAdd=@pmPerAdd,PerUpdate=@pmPerUpdate
,PerDelete=@pmPerDelete,PerAnular=@pmPerAnular,PerRead=@pmPerRead,PerRename=@pmPerRename
 ,Consecutivo=ISNULL(@pmConsecutivo,Consecutivo)
 WHERE IdUsuario=@pmIdUsuario AND IdObj=@pmIdObj
GO
/****** Object:  StoredProcedure [dbo].[paUpPermisosRoles]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPermisosRoles] @pmIdUsuario VARCHAR(11),@pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmAsignado BIT
 AS 
 UPDATE adm_PermisosRoles SET Asignado=@pmAsignado
 WHERE IdUsuario=@pmIdUsuario AND IdObj=@pmIdObj AND IdRole LIKE ISNULL(@pmIdRole,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpPicoPlaca]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPicoPlaca] @pmFecha SMALLDATETIME,@pmUltimoDig VARCHAR(50)
 AS 
 UPDATE PicoPlaca SET UltimoDig=@pmUltimoDig
 WHERE Fecha=@pmFecha
GO
/****** Object:  StoredProcedure [dbo].[paUpPlazos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPlazos] @pmIdPlazo VARCHAR(4),@pmPlazo VARCHAR(50),@pmNVmto INT
,@pmDiasPago VARCHAR(50),@pmCdDctoPp VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE Plazos SET Plazo=@pmPlazo,NVmto=@pmNVmto,DiasPago=@pmDiasPago,Inactivo=@pmInactivo,CdDctoPp=@pmCdDctoPp
 WHERE IdPlazo=@pmIdPlazo
GO
/****** Object:  StoredProcedure [dbo].[paUpPolizas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPolizas] @pmNumPoliza VARCHAR(30),@pmFecha SMALLDATETIME,@pmVigencia SMALLDATETIME,@pmNitCompania VARCHAR(16),@pmCompania VARCHAR(150),@pmNitTomador VARCHAR(16)
,@pmTomador VARCHAR(150),@pmNitAseg VARCHAR(16),@pmAsegurado VARCHAR(150),@pmNitBenef VARCHAR(16),@pmBeneficiario VARCHAR(150),@pmDescFirma VARCHAR(2000),@pmInactivo BIT,@pmCodEmpresa VARCHAR(20),@pmTipo_Poliza VARCHAR(20),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Polizas SET Fecha=@pmFecha,Vigencia=@pmVigencia,NitCompania=@pmNitCompania,Compania=@pmCompania,NitTomador=@pmNitTomador,Tomador=@pmTomador,NitAseg=@pmNitAseg
,Asegurado=@pmAsegurado,NitBenef=@pmNitBenef,Beneficiario=@pmBeneficiario,Inactivo=@pmInactivo,DescFirma=@pmDescFirma,CodEmpresa=@pmCodEmpresa,Tipo_Poliza=@pmTipo_Poliza,FechaUpdate=@pmFechaUpdate
 WHERE NumPoliza=@pmNumPoliza
GO
/****** Object:  StoredProcedure [dbo].[paUpPreCausacionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPreCausacionAnu] @pmCausacionID INT,@pmIdCia CHAR(2),@pmAnulado BIT, @pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
AS
 UPDATE  Trn_PreCausacion SET Anulado=@pmAnulado, FecDev=@pmFecDev,Observacion=@pmObservacion
 WHERE  CausacionID=@pmCausacionID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPrestamos] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecPrestamo SMALLDATETIME,@pmFecInicio SMALLDATETIME,@pmTipoPlazo VARCHAR(10),@pmNumCuotas INT,@pmDiasCausa VARCHAR(5),@pmDiasVence VARCHAR(5),@pmTipoCuota VARCHAR(10),@pmValorPrestamo MONEY,@pmTasaInteres DECIMAL(14,4)
,@pmTotalCausado MONEY,@pmTotalInteres MONEY,@pmUltimaCuota INT,@pmCancelado BIT,@pmIdConcepto VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVehPropio BIT,@pmCxPagar BIT,@pmReferencia VARCHAR(20),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT
,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Prestamos SET Fecha=@pmFecha,FecPrestamo=@pmFecPrestamo,FecInicio=@pmFecInicio,TipoPlazo=@pmTipoPlazo,NumCuotas=@pmNumCuotas,DiasCausa=@pmDiasCausa,DiasVence=@pmDiasVence,TipoCuota=@pmTipoCuota,ValorPrestamo=@pmValorPrestamo,TasaInteres=@pmTasaInteres,TotalCausado=@pmTotalCausado,TotalInteres=@pmTotalInteres,UltimaCuota=@pmUltimaCuota,Cancelado=@pmCancelado
,IdConcepto=@pmIdConcepto,IdVehiculo=@pmIdVehiculo,IdPropietario=@pmIdPropietario,IdConductor=@pmIdConductor,VehPropio=@pmVehPropio,CxPagar=@pmCxPagar,Referencia=@pmReferencia,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpPrestamosAcu] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmTotalCausado MONEY, @pmTotalInteres MONEY, @pmUltimaCuota INT
,@pmIdEstado VARCHAR(4), @pmFecUpdate  SMALLDATETIME,@pmCancelado BIT=Null
AS 
 UPDATE Trn_Prestamos SET TotalCausado=@pmTotalCausado, TotalInteres=@pmTotalInteres, UltimaCuota=@pmUltimaCuota,FecUpdate=@pmFecUpdate,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 ,Cancelado=ISNULL(@pmCancelado,Cancelado)
 WHERE TipDoc=@pmTipDoc  AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamosAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpPrestamosAnu] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmAnulado BIT, @pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250), @pmIdEstado VARCHAR(4)
AS 
 UPDATE Trn_Prestamos SET Anulado=@pmAnulado, NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion, IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc  AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpPrestamosCan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpPrestamosCan] @pmTipDoc VARCHAR(3),@pmPrestamoID INT,@pmIdCia CHAR(2),@pmTotalCausado MONEY, @pmTotalInteres MONEY, @pmUltimaCuota INT
,@pmIdEstado VARCHAR(4),@pmCancelado BIT, @pmFecUpdate  SMALLDATETIME
AS 
 UPDATE Trn_Prestamos SET Cancelado=@pmCancelado,TotalCausado=@pmTotalCausado,UltimaCuota=@pmUltimaCuota,IdEstado=@pmIdEstado
,FecUpdate=@pmFecUpdate,TotalInteres=ISNULL(@pmTotalInteres,TotalInteres)
 WHERE TipDoc=@pmTipDoc  AND PrestamoID=@pmPrestamoID AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpPresupuesto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPresupuesto] @pmNumero INT,@pmIdCia CHAR(2),@pmnAnno INT,@pmnMes INT,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmTipoPsto INT, @pmDetCentros BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Presupuesto SET nAnno=@pmnAnno,nMes=@pmnMes,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,TipoPsto=@pmTipoPsto, DetCentros=@pmDetCentros, FecUpdate=@pmFecUpdate
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdAditivos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdAditivos] @pmIdProducto VARCHAR(16),@pmIdAditivo VARCHAR(16),@pmCant DECIMAL(14,4)
,@pmUnidad VARCHAR(10),@pmCdBodega VARCHAR(4),@pmCdTanq VARCHAR(4)
 AS 
 UPDATE ProdAditivos SET Cant=@pmCant,Unidad=@pmUnidad,CdBodega=@pmCdBodega,CdTanq=@pmCdTanq
 WHERE IdProducto=@pmIdProducto AND IdAditivo=@pmIdAditivo
GO
/****** Object:  StoredProcedure [dbo].[paUpProdCombo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdCombo] @pmIdProducto VARCHAR(16),@pmItem INT,@pmIdProdBas VARCHAR(16),@pmCant DECIMAL(14,4)
,@pmCdBodega VARCHAR(4),@pmCdTanq VARCHAR(4),@pmFacMezcla VARCHAR(10),@pmExentoSob BIT
 AS 
 UPDATE ProdCombo SET IdProdBas=@pmIdProdBas,Cant=@pmCant,CdBodega=@pmCdBodega,CdTanq=@pmCdTanq
,FacMezcla=@pmFacMezcla,ExentoSob=@pmExentoSob
 WHERE IdProducto=@pmIdProducto AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpProdConsolida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdConsolida] @pmTipDoc VARCHAR(3),@pmNumCons INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdBodega VARCHAR(4),@pmCdBodDest VARCHAR(4),@pmIdBodIns VARCHAR(4),@pmCdBodInsDest VARCHAR(4),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmCritPedidos VARCHAR(500),@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_ProdConsolida SET Fecha=@pmFecha,IdBodega=@pmIdBodega,CdBodDest=@pmCdBodDest,IdBodIns=@pmIdBodIns,CdBodInsDest=@pmCdBodInsDest,Anulado=@pmAnulado,FecDev=@pmFecDev
,CritPedidos=@pmCritPedidos,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumCons=@pmNumCons AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdCostos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdCostos] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmCostoAnt MONEY
,@pmCostoUlt MONEY,@pmCostoPmd MONEY,@pmFecUltPmd SMALLDATETIME
 AS 
 UPDATE ProdCostos SET CostoAnt=@pmCostoAnt,CostoUlt=@pmCostoUlt,CostoPmd=@pmCostoPmd,FecUltPmd=@pmFecUltPmd
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdEntrega]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdEntrega] @pmTipDoc VARCHAR(3),@pmNumEntrega INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipOrden VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrden CHAR(2),@pmFecEntrega SMALLDATETIME,@pmCostoTotal MONEY,@pmDescuento MONEY,@pmCantTotal DECIMAL(14,4),@pmTipoEntrega VARCHAR(10),@pmNitTercero VARCHAR(16)
,@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmEdoOrden INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmCodConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmNumDev INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_ProdEntrega SET Fecha=@pmFecha,TipOrden=@pmTipOrden,NumOrden=@pmNumOrden,IdCiaOrden=@pmIdCiaOrden,FecEntrega=@pmFecEntrega,CostoTotal=@pmCostoTotal,Descuento=@pmDescuento,CantTotal=@pmCantTotal,TipoEntrega=@pmTipoEntrega,NitTercero=@pmNitTercero,NomContacto=@pmNomContacto,TelContacto=@pmTelContacto,EdoOrden=@pmEdoOrden
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CodConcepto=@pmCodConcepto,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,NumDev=@pmNumDev,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumEntrega=@pmNumEntrega AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdImpFron]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdImpFron] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT,@pmIdLocal VARCHAR(8),@pmTarifa DECIMAL(14,4),@pmSimbTfa CHAR(1),@pmCdTarifa VARCHAR(4)
,@pmRngFecha BIT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmLtaPre CHAR(1),@pmInactivo BIT,@pmFecUpdate SMALLDATETIME,@pmTarifZfe DECIMAL(14,4),@pmCdDpto VARCHAR(8)
 AS 
 UPDATE ProdImpFron SET IdLocal=@pmIdLocal,Tarifa=@pmTarifa,SimbTfa=@pmSimbTfa,CdTarifa=@pmCdTarifa,RngFecha=@pmRngFecha,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal
,LtaPre=@pmLtaPre,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate,TarifZfe=@pmTarifZfe,CdDpto=@pmCdDpto
 WHERE IdProducto=@pmIdProducto AND IdClase=@pmIdClase AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpProdImptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdImptos] @pmIdProducto VARCHAR(16),@pmIdClase VARCHAR(4),@pmItem INT,@pmTarifa DECIMAL(14,4),@pmSimbTfa CHAR(1),@pmCdTarifa VARCHAR(4)
,@pmRngFecha BIT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmLtaPre CHAR(1),@pmInactivo BIT,@pmFecUpdate SMALLDATETIME,@pmTarifZfe DECIMAL(14,4)
 AS 
 UPDATE ProdImptos SET Tarifa=@pmTarifa,SimbTfa=@pmSimbTfa,CdTarifa=@pmCdTarifa,RngFecha=@pmRngFecha,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,LtaPre=@pmLtaPre
,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate,TarifZfe=@pmTarifZfe
 WHERE IdProducto=@pmIdProducto AND IdClase=@pmIdClase AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpProdInsumos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdInsumos] @pmId INT,@pmIdProducto VARCHAR(16),@pmItem INT,@pmIdInsumo VARCHAR(16),@pmIdTipProc VARCHAR(4),@pmCantidad DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE ProdInsumos SET IdProducto=@pmIdProducto,Item=@pmItem,IdInsumo=@pmIdInsumo,IdTipProc=@pmIdTipProc,Cantidad=@pmCantidad,Inactivo=@pmInactivo
 WHERE Id=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMcias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdMcias] @pmIdProducto VARCHAR(16),@pmDescripProd VARCHAR(150),@pmDescripAbrv VARCHAR(50),@pmCodBarras VARCHAR(20),@pmReferencia VARCHAR(20),@pmTipoRef VARCHAR(10),@pmIdSubgrupo VARCHAR(8),@pmIdMarca VARCHAR(4),@pmColor VARCHAR(30),@pmTamano VARCHAR(30),@pmMedAlto DECIMAL(14,4),@pmMedAncho DECIMAL(14,4)
,@pmMedLargo DECIMAL(14,4),@pmMedVolm DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmIdUnd VARCHAR(4),@pmIdUndP VARCHAR(4),@pmCdUndS VARCHAR(4),@pmCdUndE VARCHAR(4),@pmCdUndEb VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmIdBodega VARCHAR(4),@pmIdUbic VARCHAR(10),@pmDesUbic VARCHAR(50)
,@pmIdProv VARCHAR(16),@pmGarProv INT,@pmGarClie INT,@pmCdDctCom VARCHAR(4),@pmVrCostAnt MONEY,@pmVrCosto MONEY,@pmVrCostPmd MONEY,@pmIdTarIva VARCHAR(4),@pmIvaInc VARCHAR(10),@pmLtPreDef CHAR(1),@pmPrecio1 MONEY,@pmPrecio2 MONEY,@pmPrecio3 MONEY,@pmPrecio4 MONEY,@pmPrecio5 MONEY,@pmCdMon1 VARCHAR(5),@pmCdMon2 VARCHAR(5)
,@pmCdMon3 VARCHAR(5),@pmCdMon4 VARCHAR(5),@pmCdMon5 VARCHAR(5),@pmBaseMgn VARCHAR(10),@pmCdMgn1 VARCHAR(4),@pmCdMgn2 VARCHAR(4),@pmCdMgn3 VARCHAR(4),@pmCdMgn4 VARCHAR(4),@pmCdMgn5 VARCHAR(4),@pmCdDct1 VARCHAR(4),@pmCdDct2 VARCHAR(4),@pmCdDct3 VARCHAR(4),@pmCdDct4 VARCHAR(4),@pmCdDct5 VARCHAR(4),@pmCdTarIca VARCHAR(4)
,@pmCdTarRet VARCHAR(4),@pmExtciaMin DECIMAL(14,4),@pmExtciaMax DECIMAL(14,4),@pmExtciaAct DECIMAL(14,4),@pmFactor1 DECIMAL(14,4),@pmFactor2 DECIMAL(14,4),@pmFactor3 DECIMAL(14,4),@pmFactor4 DECIMAL(14,4),@pmFactor5 DECIMAL(14,4),@pmSeriales BIT,@pmLotes BIT,@pmCombo BIT,@pmNoAjustes BIT,@pmTanques BIT,@pmValesComb BIT,@pmFecUltcom SMALLDATETIME,@pmFecUltVta SMALLDATETIME
,@pmCodMcia VARCHAR(10),@pmDescripLong VARCHAR(250),@pmCmntarios VARCHAR(250),@pmPathFoto VARCHAR(30),@pmCantTpv DECIMAL(14,4),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTipoZonaFront VARCHAR(3),@pmExcluidoImp BIT,@pmElectrocomb BIT,@pmIvaDetCombo BIT,@pmLtaBaseIva INT,@pmCodFEDian VARCHAR(20),@pmTallaje BIT,@pmTipoProdCo VARCHAR(10),@pmTipoIBAICU INT,@pmProcedencia INT,@pmCantAzucar DECIMAL(16,6),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE ProdMcias SET DescripProd=@pmDescripProd,DescripAbrv=@pmDescripAbrv,CodBarras=@pmCodBarras,Referencia=@pmReferencia,TipoRef=@pmTipoRef,IdSubgrupo=@pmIdSubgrupo,IdMarca=@pmIdMarca,Color=@pmColor,Tamano=@pmTamano,MedAlto=@pmMedAlto,MedAncho=@pmMedAncho,MedLargo=@pmMedLargo,MedVolm=@pmMedVolm,UndMed=@pmUndMed,IdUnd=@pmIdUnd,IdUndP=@pmIdUndP,CdUndS=@pmCdUndS
,CdUndE=@pmCdUndE,CdUndEb=@pmCdUndEb,IdEmp=@pmIdEmp,IdNat=@pmIdNat,IdMnjo=@pmIdMnjo,IdTmcia=@pmIdTmcia,IdBodega=@pmIdBodega,IdUbic=@pmIdUbic,DesUbic=@pmDesUbic,IdProv=@pmIdProv,GarProv=@pmGarProv,GarClie=@pmGarClie,CdDctCom=@pmCdDctCom,VrCostAnt=@pmVrCostAnt,VrCosto=@pmVrCosto,VrCostPmd=@pmVrCostPmd,IdTarIva=@pmIdTarIva,IvaInc=@pmIvaInc,LtPreDef=@pmLtPreDef,Precio1=@pmPrecio1
,Precio2=@pmPrecio2,Precio3=@pmPrecio3,Precio4=@pmPrecio4,Precio5=@pmPrecio5,CdMon1=@pmCdMon1,CdMon2=@pmCdMon2,CdMon3=@pmCdMon3,CdMon4=@pmCdMon4,CdMon5=@pmCdMon5,BaseMgn=@pmBaseMgn,CdMgn1=@pmCdMgn1,CdMgn2=@pmCdMgn2,CdMgn3=@pmCdMgn3,CdMgn4=@pmCdMgn4,CdMgn5=@pmCdMgn5,CdDct1=@pmCdDct1,CdDct2=@pmCdDct2,CdDct3=@pmCdDct3,CdDct4=@pmCdDct4,CdDct5=@pmCdDct5
,CdTarIca=@pmCdTarIca,CdTarRet=@pmCdTarRet,ExtciaMin=@pmExtciaMin,ExtciaMax=@pmExtciaMax,ExtciaAct=@pmExtciaAct,Factor1=@pmFactor1,Factor2=@pmFactor2,Factor3=@pmFactor3,Factor4=@pmFactor4,Factor5=@pmFactor5,Seriales=@pmSeriales,Lotes=@pmLotes,Combo=@pmCombo,NoAjustes=@pmNoAjustes,Tanques=@pmTanques,FecUltcom=@pmFecUltcom,FecUltVta=@pmFecUltVta,CodMcia=@pmCodMcia,DescripLong=@pmDescripLong
,Cmntarios=@pmCmntarios,PathFoto=@pmPathFoto,CantTpv=@pmCantTpv,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,ValesComb=@pmValesComb,TipoZonaFront=@pmTipoZonaFront,ExcluidoImp=@pmExcluidoImp,Electrocomb=@pmElectrocomb,IvaDetCombo=@pmIvaDetCombo,LtaBaseIva=@pmLtaBaseIva,CodFEDian=@pmCodFEDian,Tallaje=@pmTallaje,TipoProdCo=@pmTipoProdCo,TipoIBAICU=@pmTipoIBAICU,Procedencia=@pmProcedencia,CantAzucar=@pmCantAzucar,FechaUpdate=@pmFechaUpdate
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdMciasEst] @pmIdProducto VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmCmntarios VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE ProdMcias SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Cmntarios=@pmCmntarios,FechaUpdate=@pmFechaUpdate
 WHERE IdProducto=@pmIdProducto
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasIca]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdMciasIca] @pmIdSubgrupo VARCHAR(8),@pmCdTarIca VARCHAR(4),@pmIdNewIca VARCHAR(4)
 AS 
 UPDATE ProdMcias SET  CdTarIca=@pmIdNewIca
 WHERE IdSubgrupo=@pmIdSubgrupo AND CdTarIca=@pmCdTarIca
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasIva]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdMciasIva] @pmIdSubgrupo VARCHAR(8),@pmIdTarIva VARCHAR(4),@pmIdNewTar VARCHAR(4)
 AS 
 UPDATE ProdMcias SET IdTarIva=@pmIdNewTar
 WHERE IdSubgrupo=@pmIdSubgrupo AND IdTarIva=@pmIdTarIva
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdMciasRet] @pmIdSubgrupo VARCHAR(8),@pmCdTarRet VARCHAR(4),@pmIdNewRet VARCHAR(4)
 AS 
 UPDATE ProdMcias SET  CdTarRet=@pmIdNewRet
 WHERE IdSubgrupo=@pmIdSubgrupo AND CdTarRet=@pmCdTarRet
GO
/****** Object:  StoredProcedure [dbo].[paUpProdMciasSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdMciasSal] @pmIdProducto VARCHAR(16)=Null
 AS 
 IF @pmIdProducto IS NULL
  BEGIN
   UPDATE ProdMcias 
   SET ExtciaAct=(SELECT ISNULL(SUM(SaldoActual),0) FROM ProdSaldos WHERE ProdSaldos.IdProducto=ProdMcias.IdProducto)
   WHERE TipoRef<>'SERVICIO'
  END
 ELSE
  BEGIN
   UPDATE ProdMcias 
   SET ExtciaAct=(SELECT ISNULL(SUM(SaldoActual),0) FROM ProdSaldos WHERE ProdSaldos.IdProducto=ProdMcias.IdProducto)
   WHERE IdProducto=@pmIdProducto
  END
GO
/****** Object:  StoredProcedure [dbo].[paUpProdOrden]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdOrden] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipCons VARCHAR(3),@pmNumCons INT,@pmIdCiaCons CHAR(2),@pmModalidad VARCHAR(10),@pmIdTipProc VARCHAR(4),@pmIdTaller VARCHAR(4),@pmCostoTotal MONEY,@pmConPago BIT,@pmEdoOrden INT
,@pmFecEntrega SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmNitTercero VARCHAR(16),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmProcFinal BIT,@pmNum_Entrega INT,@pmCdCiaEnt CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_ProdOrden SET Fecha=@pmFecha,TipCons=@pmTipCons,NumCons=@pmNumCons,IdCiaCons=@pmIdCiaCons,Modalidad=@pmModalidad,IdTipProc=@pmIdTipProc,IdTaller=@pmIdTaller,CostoTotal=@pmCostoTotal,ConPago=@pmConPago,EdoOrden=@pmEdoOrden,FecEntrega=@pmFecEntrega
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NitTercero=@pmNitTercero,NomContacto=@pmNomContacto,TelContacto=@pmTelContacto,ProcFinal=@pmProcFinal,Num_Entrega=@pmNum_Entrega,CdCiaEnt=@pmCdCiaEnt,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdPrecCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdPrecCom] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmNumero INT,@pmTipoTarif VARCHAR(3),@pmnMes INT,@pmnAnno INT
,@pmTarifa DECIMAL(14,4),@pmNitProv VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE ProdPrecCom SET TipoTarif=@pmTipoTarif,nMes=@pmnMes,nAnno=@pmnAnno,Tarifa=@pmTarifa,NitProv=@pmNitProv,Inactivo=@pmInactivo
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpProdPrecCrudo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdPrecCrudo] @pmTipoTarif VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmIdProducto VARCHAR(16),@pmIdTercero VARCHAR(16),@pmDuracion VARCHAR(10),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
,@pmTarifa DECIMAL(16,6),@pmIdMoneda VARCHAR(5),@pmUndMed VARCHAR(10),@pmCodCiudad VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE ProdPrecCrudo SET IdCia=@pmIdCia,IdProducto=@pmIdProducto,IdTercero=@pmIdTercero,Duracion=@pmDuracion,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,Tarifa=@pmTarifa,IdMoneda=@pmIdMoneda
,UndMed=@pmUndMed,CodCiudad=@pmCodCiudad,Inactivo=@pmInactivo
 WHERE TipoTarif=@pmTipoTarif AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpProdPrecios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdPrecios] @pmIdProducto VARCHAR(16),@pmIdCia CHAR(2),@pmVrPrecio1 MONEY,@pmVrPrecio2 MONEY,@pmVrPrecio3 MONEY,@pmVrPrecio4 MONEY,@pmVrPrecio5 MONEY
,@pmIvaInc VARCHAR(10),@pmCdTarIva VARCHAR(4),@pmCdMoney1 VARCHAR(5),@pmCdMoney2 VARCHAR(5),@pmCdMoney3 VARCHAR(5),@pmCdMoney4 VARCHAR(5),@pmCdMoney5 VARCHAR(5)
,@pmCdMargen1 VARCHAR(4),@pmCdMargen2 VARCHAR(4),@pmCdMargen3 VARCHAR(4),@pmCdMargen4 VARCHAR(4),@pmCdMargen5 VARCHAR(4),@pmBaseMargen VARCHAR(10),@pmCdDcto1 VARCHAR(4)
,@pmCdDcto2 VARCHAR(4),@pmCdDcto3 VARCHAR(4),@pmCdDcto4 VARCHAR(4),@pmCdDcto5 VARCHAR(4),@pmIdUnd VARCHAR(4),@pmIdBodega VARCHAR(4)
 AS 
 UPDATE ProdPrecios SET VrPrecio1=@pmVrPrecio1,VrPrecio2=@pmVrPrecio2,VrPrecio3=@pmVrPrecio3,VrPrecio4=@pmVrPrecio4,VrPrecio5=@pmVrPrecio5,IvaInc=@pmIvaInc,CdTarIva=@pmCdTarIva
,CdMoney1=@pmCdMoney1,CdMoney2=@pmCdMoney2,CdMoney3=@pmCdMoney3,CdMoney4=@pmCdMoney4,CdMoney5=@pmCdMoney5,CdMargen1=@pmCdMargen1,CdMargen2=@pmCdMargen2,CdMargen3=@pmCdMargen3
,CdMargen4=@pmCdMargen4,CdMargen5=@pmCdMargen5,BaseMargen=@pmBaseMargen,CdDcto1=@pmCdDcto1,CdDcto2=@pmCdDcto2,CdDcto3=@pmCdDcto3,CdDcto4=@pmCdDcto4,CdDcto5=@pmCdDcto5,IdUnd=@pmIdUnd,IdBodega=@pmIdBodega
 WHERE IdProducto=@pmIdProducto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdProcesos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdProcesos] @pmId INT,@pmIdProducto VARCHAR(16),@pmItem INT,@pmIdTipProc VARCHAR(4),@pmCostoEst MONEY,@pmUltCosto MONEY,@pmProcFinal BIT
,@pmCostoMP BIT,@pmCDI_Adic BIT,@pmCodTarifCDI VARCHAR(4)
 AS 
 UPDATE ProdProcesos SET IdProducto=@pmIdProducto,Item=@pmItem,IdTipProc=@pmIdTipProc,CostoEst=@pmCostoEst,UltCosto=@pmUltCosto,ProcFinal=@pmProcFinal
,CostoMP=@pmCostoMP,CDI_Adic=@pmCDI_Adic,CodTarifCDI=@pmCodTarifCDI
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paUpProdProvee]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdProvee] @pmIdProducto VARCHAR(16),@pmIdProv VARCHAR(16),@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmDiasGar INT
,@pmCdDct VARCHAR(4),@pmVrCostCom MONEY,@pmVrCostPmd MONEY,@pmRefProv VARCHAR(20),@pmDcmento INT
 AS 
 UPDATE ProdProvee SET Fecha=@pmFecha,DiasGar=@pmDiasGar,CdDct=@pmCdDct,VrCostCom=@pmVrCostCom,VrCostPmd=@pmVrCostPmd,RefProv=@pmRefProv,Dcmento=@pmDcmento
 WHERE IdProducto=@pmIdProducto AND IdProv=@pmIdProv AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdSaldos] @pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4)
,@pmIdCia CHAR(2),@pmSaldoActual DECIMAL(14,4)
 AS 
 UPDATE ProdSaldos SET SaldoActual=@pmSaldoActual
 WHERE IdProducto=@pmIdProducto AND IdBodega=@pmIdBodega AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldosKar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdSaldosKar] @pmDelete BIT,@pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 IF @pmDelete<>0  
  BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SELECT @TrnNombre = 'TrnProdSaldos'
  BEGIN TRANSACTION @TrnNombre
   DELETE  FROM ProdSaldos WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
   INSERT INTO ProdSaldos  (IdProducto,IdBodega,IdCia,SaldoActual)
   SELECT K.IdProducto,K.IdBodega,IdCia,SUM(Entradas-Salidas)
   FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
   WHERE TipDoc NOT IN ('PED','REM','COT','ODC','GUI','OCC','ODS','VCC') AND TipoRef<>'SERVICIO'
   AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
   GROUP BY K.IdProducto,K.IdBodega,IdCia
  COMMIT TRANSACTION  @TrnNombre
  END
 ELSE
  INSERT INTO ProdSaldos  (IdProducto,IdBodega,IdCia,SaldoActual)
  SELECT K.IdProducto,K.IdBodega,IdCia,SUM(Entradas-Salidas)
  FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
  WHERE TipDoc NOT IN ('PED','REM','COT','ODC','GUI','OCC','ODS','VCC') AND TipoRef<>'SERVICIO'
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  GROUP BY K.IdProducto,K.IdBodega,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldoUbc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdSaldoUbc] @pmIdProducto VARCHAR(16),@pmIdUbic VARCHAR(10),@pmIdCia CHAR(2),@pmSaldoActual DECIMAL(14,4)
 AS 
 UPDATE ProdSaldoUbc SET SaldoActual=@pmSaldoActual
 WHERE IdProducto=@pmIdProducto AND IdUbic=@pmIdUbic AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdSaldoUbcKar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProdSaldoUbcKar] @pmDelete BIT,@pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 IF @pmDelete<>0  
  BEGIN
  DECLARE @TrnNombre VARCHAR(20)
  SELECT @TrnNombre = 'TrnProdSaldos'
  BEGIN TRANSACTION @TrnNombre
   DELETE  FROM ProdSaldoUbc WHERE IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
   INSERT INTO ProdSaldoUbc  (IdProducto,IdUbic,IdCia,SaldoActual)
   SELECT K.IdProducto,K.IdUbic,IdCia,SUM(Entradas-Salidas)
   FROM  Trn_KarUbic AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
   WHERE TipDoc NOT IN ('PED','REM','COT','ODC','GUI','OCC','ODS') 
    AND TipoRef<>'SERVICIO' AND Tanques=0 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
   GROUP BY K.IdProducto,K.IdUbic,IdCia
  COMMIT TRANSACTION  @TrnNombre
  END
 ELSE
   INSERT INTO ProdSaldoUbc  (IdProducto,IdUbic,IdCia,SaldoActual)
   SELECT K.IdProducto,K.IdUbic,IdCia,SUM(Entradas-Salidas)
   FROM  Trn_KarUbic AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
   WHERE TipDoc NOT IN ('PED','REM','COT','ODC','GUI','OCC','ODS') 
    AND TipoRef<>'SERVICIO' AND Tanques=0 AND IdCia LIKE ISNULL(@pmIdCia,'%%') AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%')
   GROUP BY K.IdProducto,K.IdUbic,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpProdTarf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpProdTarf] @pmTipo VARCHAR(3),@pmNumero INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmCdCia CHAR(2),@pmCdLinea VARCHAR(8),@pmCdGrupo VARCHAR(8),@pmCdSubgrupo VARCHAR(8),@pmCdMarca VARCHAR(4),@pmCdProducto VARCHAR(16),@pmTarifa DECIMAL(14,4),@pmSimbTfa CHAR(1),@pmLtaPre CHAR(1),@pmCdTarifa VARCHAR(4)
,@pmCdClie VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmCdVend VARCHAR(16),@pmCdCiudad VARCHAR(8),@pmCdZona VARCHAR(4)
,@pmCdSzona VARCHAR(4),@pmCdGruCli VARCHAR(4),@pmOtrosCrit VARCHAR(250),@pmAnulado BIT,@pmCodBod VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_ProdTarf SET FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,CdCia=@pmCdCia,CdLinea=@pmCdLinea,CdGrupo=@pmCdGrupo,CdSubgrupo=@pmCdSubgrupo,CdMarca=@pmCdMarca,CdProducto=@pmCdProducto,Tarifa=@pmTarifa,SimbTfa=@pmSimbTfa,LtaPre=@pmLtaPre,CdTarifa=@pmCdTarifa,CdClie=@pmCdClie,CdVend=@pmCdVend,CdCiudad=@pmCdCiudad,CdZona=@pmCdZona
,CdSzona=@pmCdSzona,CdGruCli=@pmCdGruCli,OtrosCrit=@pmOtrosCrit,Anulado=@pmAnulado,FecUpdate=@pmFecUpdate,CdAgencia=@pmCdAgencia,CodBod=@pmCodBod
 WHERE Tipo=@pmTipo AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpProfesiones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpProfesiones] @pmIdProf VARCHAR(4),@pmProfesion VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE Profesiones SET Profesion=@pmProfesion,Inactivo=@pmInactivo
 WHERE IdProf=@pmIdProf
GO
/****** Object:  StoredProcedure [dbo].[paUpPuc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuc] @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(100),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT,@pmSubCentro BIT,@pmVehiculo BIT,@pmCentroCosto BIT,@pmVencimiento BIT,@pmBaseGravable BIT
,@pmPorcntaje DECIMAL(10,4),@pmNaturaleza CHAR(1),@pmAjustable BIT,@pmCuentaAjuDeb VARCHAR(16),@pmCuentaAjuCre VARCHAR(16),@pmCheques BIT,@pmReferncias BIT
,@pmAgencia BIT,@pmFmtDian INT,@pmConDian INT,@pmRenDec INT,@pmCdTipDoc VARCHAR(3),@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT,@pmAfijos INT,@pmListarConc VARCHAR(4),@pmReqAutorizac BIT,@pmAntProveedor BIT,@pmIdCueNiif VARCHAR(16)
 AS 
 UPDATE Puc SET NomCuenta=@pmNomCuenta,Mayor=@pmMayor,Movimiento=@pmMovimiento,Tercero=@pmTercero,SubCentro=@pmSubCentro,Vehiculo=@pmVehiculo,CentroCosto=@pmCentroCosto,Vencimiento=@pmVencimiento,BaseGravable=@pmBaseGravable
,Porcntaje=@pmPorcntaje,Naturaleza=@pmNaturaleza,Ajustable=@pmAjustable,CuentaAjuDeb=@pmCuentaAjuDeb,CuentaAjuCre=@pmCuentaAjuCre,Cheques=@pmCheques,Referncias=@pmReferncias,Agencia=@pmAgencia
,FmtDian=@pmFmtDian,ConDian=@pmConDian,RenDec=@pmRenDec,CdTipDoc=@pmCdTipDoc,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo,Afijos=@pmAfijos,ListarConc=@pmListarConc,ReqAutorizac=@pmReqAutorizac,AntProveedor=@pmAntProveedor,IdCueNiif=@pmIdCueNiif 
 WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paUpPucNiif]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPucNiif] @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(250),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT,@pmVehiculo BIT,@pmAgencia BIT,@pmCentroCosto BIT,@pmSubCentro BIT,@pmVencimiento BIT,@pmBaseGravable BIT,@pmTarifaPred DECIMAL(14,4),@pmNaturaleza CHAR(1),@pmAjustable BIT
,@pmCuentaAjuDeb VARCHAR(16),@pmCuentaAjuCre VARCHAR(16),@pmCheques BIT,@pmReferencias BIT,@pmCdTipDoc VARCHAR(3),@pmInactivo BIT,@pmAfijos INT,@pmListarConc VARCHAR(4),@pmReqAutorizac BIT,@pmAntProveedor BIT,@pmFechaAct SMALLDATETIME
 AS 
 UPDATE PucNiif SET NomCuenta=@pmNomCuenta,Mayor=@pmMayor,Movimiento=@pmMovimiento,Tercero=@pmTercero,Vehiculo=@pmVehiculo,Agencia=@pmAgencia,CentroCosto=@pmCentroCosto,SubCentro=@pmSubCentro,Vencimiento=@pmVencimiento,BaseGravable=@pmBaseGravable,TarifaPred=@pmTarifaPred,Naturaleza=@pmNaturaleza
,Ajustable=@pmAjustable,CuentaAjuDeb=@pmCuentaAjuDeb,CuentaAjuCre=@pmCuentaAjuCre,Cheques=@pmCheques,Referencias=@pmReferencias,CdTipDoc=@pmCdTipDoc,FechaAct=@pmFechaAct,Inactivo=@pmInactivo,Afijos=@pmAfijos
,ListarConc=@pmListarConc,ReqAutorizac=@pmReqAutorizac,AntProveedor=@pmAntProveedor
 WHERE IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paUpPuestos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPuestos] @pmIdPto VARCHAR(4),@pmPtoControl VARCHAR(100),@pmTagPuesto VARCHAR(50),@pmIdLocal VARCHAR(8)
,@pmUbicacion VARCHAR(100),@pmContacto VARCHAR(150),@pmTelefono VARCHAR(20),@pmTelMovil VARCHAR(20),@pmReferencia VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE Puestos SET PtoControl=@pmPtoControl,TagPuesto=@pmTagPuesto,IdLocal=@pmIdLocal,Ubicacion=@pmUbicacion,Contacto=@pmContacto
,Telefono=@pmTelefono,TelMovil=@pmTelMovil,Referencia=@pmReferencia,Inactivo=@pmInactivo
 WHERE IdPto=@pmIdPto
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntBases]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuntBases] @pmIdProgrma INT,@pmCdSubgrupo VARCHAR(8),@pmCdProducto VARCHAR(16)
,@pmPuntos DECIMAL(14,4),@pmMonto DECIMAL(14,4)
 AS 
 UPDATE PuntBases SET Puntos=@pmPuntos,Monto=@pmMonto
 WHERE IdProgrma=@pmIdProgrma AND CdSubgrupo=@pmCdSubgrupo AND CdProducto=@pmCdProducto
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntFormas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuntFormas] @pmIdProgrma INT,@pmIdForma VARCHAR(4),@pmPuntos DECIMAL(14,4)
 AS 
 UPDATE PuntFormas SET Puntos=@pmPuntos
 WHERE IdProgrma=@pmIdProgrma AND IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpPuntos] @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME
,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrBase MONEY,@pmPuntFactura DECIMAL(14,4)
,@pmPuntExtra DECIMAL(14,4),@pmPuntRedim DECIMAL(14,4),@pmIdProgrma INT,@pmNumTarjeta VARCHAR(20),@pmDetalles VARCHAR(50),@pmReferncia VARCHAR(50)
 AS 
 UPDATE Trn_Puntos SET Fecha=@pmFecha,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrBase=@pmVrBase,PuntFactura=@pmPuntFactura
,PuntExtra=@pmPuntExtra,PuntRedim=@pmPuntRedim,IdProgrma=@pmIdProgrma,NumTarjeta=@pmNumTarjeta,Detalles=@pmDetalles,Referncia=@pmReferncia
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntPremios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuntPremios] @pmIdProgrma INT,@pmItem INT,@pmDescripcion VARCHAR(100)
,@pmIdProducto VARCHAR(16),@pmPuntos DECIMAL(14,4),@pmVrBono MONEY
 AS 
 UPDATE PuntPremios SET Descripcion=@pmDescripcion,IdProducto=@pmIdProducto,Puntos=@pmPuntos
,VrBono=@pmVrBono
 WHERE IdProgrma=@pmIdProgrma AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntProg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuntProg] @pmIdProgrma INT,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmMesesInact INT,@pmMesesVcmto INT
,@pmObservacion VARCHAR(250),@pmAnulado BIT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE PuntProg SET FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,MesesInact=@pmMesesInact,MesesVcmto=@pmMesesVcmto
,Observacion=@pmObservacion,Anulado=@pmAnulado,FecUpdate=@pmFecUpdate
 WHERE IdProgrma=@pmIdProgrma
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntTarjetas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuntTarjetas] @pmNumTarjeta VARCHAR(20),@pmIdClie VARCHAR(16),@pmFecha SMALLDATETIME,@pmTotalPuntos DECIMAL(14,4)
,@pmPuntRedim DECIMAL(14,4),@pmFecUltCompra SMALLDATETIME,@pmInactivo BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE PuntTarjetas SET IdClie=@pmIdClie,Fecha=@pmFecha,TotalPuntos=@pmTotalPuntos,PuntRedim=@pmPuntRedim,FecUltCompra=@pmFecUltCompra
,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate
 WHERE NumTarjeta=@pmNumTarjeta
GO
/****** Object:  StoredProcedure [dbo].[paUpPuntTarjetasAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpPuntTarjetasAcu] @pmNumTarjeta VARCHAR(20)
,@pmTotalPuntos DECIMAL(14,4),@pmFecUltCompra SMALLDATETIME
 AS 
 UPDATE PuntTarjetas SET TotalPuntos=@pmTotalPuntos,FecUltCompra=@pmFecUltCompra
 WHERE NumTarjeta=@pmNumTarjeta
GO
/****** Object:  StoredProcedure [dbo].[paUpRadicaVales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRadicaVales] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmTotalPagos MONEY,@pmTotalCobros MONEY
,@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmVrDescuento MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_RadicaVales SET Fecha=@pmFecha,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,TotalPagos=@pmTotalPagos,TotalCobros=@pmTotalCobros,Referencia=@pmReferencia,CxPagar=@pmCxPagar
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,VrDescuento=@pmVrDescuento
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRadicaValesDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRadicaValesDev] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmObservacion VARCHAR(250)
 AS 
 UPDATE Trn_RadicaVales SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRangosPeso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRangosPeso] @pmIdRango VARCHAR(4),@pmDescripRango VARCHAR(50),@pmValorInicial DECIMAL(14,4),@pmValorFinal DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE RangosPeso SET DescripRango=@pmDescripRango,ValorInicial=@pmValorInicial,ValorFinal=@pmValorFinal,Inactivo=@pmInactivo
 WHERE IdRango=@pmIdRango
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRecAfavorAbo] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmVrAbono MONEY
 AS 
 UPDATE Trn_RecAfavor SET VrAbono=@pmVrAbono
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRecAfavorApl] @pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 UPDATE Trn_RecAfavor SET Trn_RecAfavor.VrAbono=(SELECT ISNULL(SUM(Trn_VencAbonos.VrAbono),0)
   FROM Trn_VencAbonos  WHERE Trn_RecAfavor.TipDoc=Trn_VencAbonos.TipRec AND Trn_RecAfavor.Recibo=Trn_VencAbonos.Recibo
   AND Trn_RecAfavor.IdCia=Trn_VencAbonos.IdCia AND TipoAplica='ANTICIPO')
  WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorApld]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRecAfavorApld] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_RecAfavor SET Trn_RecAfavor.VrAbono=(SELECT ISNULL(SUM(Trn_VencAbonos.VrAbono),0)
   FROM Trn_VencAbonos  WHERE Trn_RecAfavor.TipDoc=Trn_VencAbonos.TipRec AND Trn_RecAfavor.Recibo=Trn_VencAbonos.Recibo
   AND Trn_RecAfavor.IdCia=Trn_VencAbonos.IdCia AND TipoAplica='ANTICIPO')
  WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRecAfavorCero] @pmIdCliente VARCHAR(16)=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 UPDATE Trn_RecAfavor SET VrAbono=0
 WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpRecAfavorOdb]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecAfavorOdb] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmVrAbono MONEY,@pmVrOtrosDb MONEY
 AS 
 UPDATE Trn_RecAfavor SET VrAbono=@pmVrAbono,VrOtrosDb=@pmVrOtrosDb
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBuses]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecBuses] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCar VARCHAR(3),@pmCartulina INT,@pmIdCiaCar CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16)
,@pmVehPropio BIT,@pmCentInicial INT,@pmCentFinal INT,@pmNPasajeros INT,@pmRecorridos INT,@pmValorRecibido MONEY,@pmValorTotal MONEY,@pmValorDcto MONEY,@pmValorReteFte MONEY,@pmValorReteIva MONEY,@pmValorReteIca MONEY,@pmValorOtros MONEY,@pmValorOtrosDct MONEY,@pmValorPagMas MONEY,@pmValorNeto MONEY,@pmValorAplicado MONEY
,@pmValorAnticipo MONEY,@pmValorAbono MONEY,@pmTotalProducido MONEY,@pmTotalGastos MONEY,@pmTotalAhorro MONEY,@pmTotalOtros MONEY,@pmTotalVales MONEY,@pmTotalAbono MONEY,@pmValorPasaje MONEY,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmIdTarCom VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdCta VARCHAR(4),@pmEnEfectivo BIT
,@pmNumCheque VARCHAR(20),@pmIdBanco VARCHAR(4),@pmReferencia VARCHAR(20),@pmBaseIva MONEY,@pmBaseRet MONEY,@pmBaseOtr MONEY,@pmTarifaIva DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaOtr DECIMAL(14,4),@pmIdTarIva VARCHAR(4),@pmIdTarRet VARCHAR(4),@pmIdTarOtr VARCHAR(4),@pmIdClase VARCHAR(4),@pmIdRuta VARCHAR(4),@pmIdRelevador VARCHAR(16)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_RecBuses SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,Modalidad=@pmModalidad,TipCar=@pmTipCar,Cartulina=@pmCartulina,IdCiaCar=@pmIdCiaCar,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,VehPropio=@pmVehPropio,CentInicial=@pmCentInicial,CentFinal=@pmCentFinal,NPasajeros=@pmNPasajeros,Recorridos=@pmRecorridos
,ValorRecibido=@pmValorRecibido,ValorTotal=@pmValorTotal,ValorDcto=@pmValorDcto,ValorReteFte=@pmValorReteFte,ValorReteIva=@pmValorReteIva,ValorReteIca=@pmValorReteIca,ValorOtros=@pmValorOtros,ValorOtrosDct=@pmValorOtrosDct,ValorPagMas=@pmValorPagMas,ValorNeto=@pmValorNeto,ValorAplicado=@pmValorAplicado,ValorAnticipo=@pmValorAnticipo,ValorAbono=@pmValorAbono,TotalProducido=@pmTotalProducido
,TotalGastos=@pmTotalGastos,TotalAhorro=@pmTotalAhorro,TotalOtros=@pmTotalOtros,TotalVales=@pmTotalVales,TotalAbono=@pmTotalAbono,ValorPasaje=@pmValorPasaje,IdVendedor=@pmIdVendedor,Comision=@pmComision,IdTarCom=@pmIdTarCom,IdCCosto=@pmIdCCosto,IdCta=@pmIdCta,EnEfectivo=@pmEnEfectivo,NumCheque=@pmNumCheque,IdBanco=@pmIdBanco,Referencia=@pmReferencia,BaseIva=@pmBaseIva,BaseRet=@pmBaseRet
,BaseOtr=@pmBaseOtr,TarifaIva=@pmTarifaIva,TarifaRet=@pmTarifaRet,TarifaOtr=@pmTarifaOtr,IdTarIva=@pmIdTarIva,IdTarRet=@pmIdTarRet,IdTarOtr=@pmIdTarOtr,IdClase=@pmIdClase,IdRuta=@pmIdRuta,IdRelevador=@pmIdRelevador,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpRecBusesAbo] @pmTipDoc VARCHAR(3), @pmRecibo INT, @pmIdCia CHAR(2),@pmValorAbono MONEY
AS
 UPDATE  Trn_RecBuses  SET ValorAbono=@pmValorAbono
 WHERE TipDoc=@pmTipDoc  AND  Recibo=@pmRecibo  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAcp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpRecBusesAcp] @pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null
AS
 UPDATE  Trn_RecBuses  SET  ValorAnticipo=0,ValorAbono=0
 WHERE Anulado<>0 AND ValorAnticipo>0  AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdCliente LIKE ISNULL(@pmIdCliente,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpRecBusesAnu] @pmTipDoc VARCHAR(3), @pmRecibo INT, @pmIdCia CHAR(2), @pmAnulado BIT
, @pmNumDev INT, @pmFecDev SMALLDATETIME, @pmObservacion VARCHAR(250), @pmIdEstado VARCHAR(4)
AS
 UPDATE  Trn_RecBuses  SET Anulado=@pmAnulado, NumDev=@pmNumDev, FecDev=@pmFecDev, Observacion=@pmObservacion, IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc  AND  Recibo=@pmRecibo  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecBusesApl] @pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdClase VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
  UPDATE  Trn_RecBuses  SET Trn_RecBuses.ValorAbono=ISNULL((SELECT SUM(ValorAbono)
  FROM  Trn_RecFactura  WHERE AplAntcpo<>0 AND Trn_RecFactura.TipRec=Trn_RecBuses.TipDoc AND Trn_RecFactura.Recibo=Trn_RecBuses.Recibo
   AND Trn_RecFactura.IdCia=Trn_RecBuses.IdCia),0) --HAVING SUM(ValorAbono)<=ValorAnticipo
  WHERE ValorAnticipo>0 AND   Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND  IdVehiculo like ISNULL(@pmIdVehiculo,'%')
  AND IdCliente like ISNULL(@pmIdCliente,'%')   AND IdCia like ISNULL(@pmIdCia,'%%')  AND IdClase like ISNULL(@pmIdClase,'%')
 ELSE
  UPDATE  Trn_RecBuses  SET Trn_RecBuses.ValorAbono=ISNULL((SELECT SUM(ValorAbono)
  FROM  Trn_RecFactura  WHERE AplAntcpo<>0 AND Trn_RecFactura.TipRec=Trn_RecBuses.TipDoc AND Trn_RecFactura.Recibo=Trn_RecBuses.Recibo
   AND Trn_RecFactura.IdCia=Trn_RecBuses.IdCia),0)
  WHERE ValorAnticipo>0 AND  IdVehiculo like ISNULL(@pmIdVehiculo,'%') AND IdCliente like ISNULL(@pmIdCliente,'%')
   AND IdCia like ISNULL(@pmIdCia,'%%')  AND IdClase like ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesAplVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecBusesAplVeh] @pmIdVehiculo VARCHAR(10)
AS
  UPDATE  Trn_RecBuses  SET Trn_RecBuses.ValorAbono=ISNULL((SELECT SUM(ValorAbono)
  FROM  Trn_RecFactura  WHERE AplAntcpo<>0 AND Trn_RecFactura.TipRec=Trn_RecBuses.TipDoc AND Trn_RecFactura.Recibo=Trn_RecBuses.Recibo
   AND Trn_RecFactura.IdCia=Trn_RecBuses.IdCia),0)
  WHERE ValorAnticipo>0 AND  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesCero]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecBusesCero] @pmIdVehiculo VARCHAR(10)=Null,@pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null,@pmIdClase VARCHAR(4)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null
AS
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
  UPDATE  Trn_RecBuses  SET  ValorAbono=0
  WHERE ValorAnticipo>0 AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND   IdVehiculo like ISNULL(@pmIdVehiculo,'%')
  AND IdCliente like ISNULL(@pmIdCliente,'%')  AND IdCia like ISNULL(@pmIdCia,'%%')  AND  IdClase like ISNULL(@pmIdClase,'%')
 ELSE
  UPDATE  Trn_RecBuses  SET  ValorAbono=0
  WHERE ValorAnticipo>0 AND  IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%')
  AND IdCliente LIKE ISNULL(@pmIdCliente,'%')  AND IdCia LIKE ISNULL(@pmIdCia,'%%')  AND  IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesCeroVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecBusesCeroVeh] @pmIdVehiculo VARCHAR(10)
AS
  UPDATE  Trn_RecBuses  SET  ValorAbono=0
  WHERE ValorAnticipo>0 AND  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpRecBusesTabo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpRecBusesTabo] @pmTipDoc VARCHAR(3), @pmRecibo INT, @pmIdCia CHAR(2),@pmValorAplicado MONEY, @pmValorAnticipo MONEY
AS
 UPDATE  Trn_RecBuses  SET ValorAplicado=@pmValorAplicado, ValorAnticipo=@pmValorAnticipo,ValorAbono=0
 WHERE TipDoc=@pmTipDoc  AND  Recibo=@pmRecibo  AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecCheques]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRecCheques] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16)
,@pmVrTotal MONEY,@pmCantidad DECIMAL(14,4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmPlacaVehic VARCHAR(10),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_RecCheques SET Fecha=@pmFecha,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrTotal=@pmVrTotal,Cantidad=@pmCantidad,
TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,PlacaVehic=@pmPlacaVehic,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecChequesAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRecChequesAnu] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_RecCheques SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecFactura]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecFactura] @pmTipRec VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmItem INT,@pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCiaDoc CHAR(2),@pmItemDoc INT,@pmFecha SMALLDATETIME,@pmIdCargo VARCHAR(4),@pmIdClase VARCHAR(4),@pmValorAbono MONEY,@pmDevolucion MONEY,@pmDescuento MONEY,@pmIdCliente VARCHAR(16)
,@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmVehPropio BIT,@pmIdVendedor VARCHAR(16),@pmComision DECIMAL(14,4),@pmDetalle VARCHAR(100),@pmFecPago SMALLDATETIME,@pmAplAntcpo BIT
 AS 
 UPDATE Trn_RecFactura SET TipDoc=@pmTipDoc,Documento=@pmDocumento,IdCiaDoc=@pmIdCiaDoc,ItemDoc=@pmItemDoc,Fecha=@pmFecha,IdCargo=@pmIdCargo,IdClase=@pmIdClase,ValorAbono=@pmValorAbono,Devolucion=@pmDevolucion,Descuento=@pmDescuento,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVehiculo=@pmIdVehiculo
,VehPropio=@pmVehPropio,IdVendedor=@pmIdVendedor,Comision=@pmComision,Detalle=@pmDetalle,FecPago=@pmFecPago,AplAntcpo=@pmAplAntcpo
 WHERE TipRec=@pmTipRec AND Recibo=@pmRecibo AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpRecibos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecibos] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmFecPago SMALLDATETIME,@pmVrRecibido MONEY,@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrRetencion MONEY,@pmVrReteICA MONEY,@pmVrReteIVA MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY
,@pmVrAhorro MONEY,@pmVrPagosMas MONEY,@pmVrNeto MONEY,@pmVrAplicado MONEY,@pmVrAnticipo MONEY,@pmVrEfectivo MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmBaseRiv MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmTarifaRiv DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdCajero VARCHAR(11),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmIdLocal VARCHAR(8),@pmEnEfectivo BIT,@pmCdForma VARCHAR(4),@pmNumForma VARCHAR(20),@pmDetallePago VARCHAR(250),@pmCdBanco VARCHAR(4),@pmCdCta VARCHAR(4),@pmReferencia VARCHAR(50),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmTipDcm VARCHAR(3),@pmDocumento INT,@pmIdCiaDcm CHAR(2)
,@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrReteCREE MONEY,@pmTarifaRtc DECIMAL(14,4),@pmCodTarRtc VARCHAR(4),@pmVrDevFact MONEY,@pmVrBomberil MONEY,@pmTarifaBom DECIMAL(14,4),@pmCodTarifBom VARCHAR(4),@pmImpAviTab MONEY,@pmTarifaAvta DECIMAL(14,4),@pmCodTarifAvta VARCHAR(4)
,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Recibos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,FecPago=@pmFecPago,VrRecibido=@pmVrRecibido,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrRetencion=@pmVrRetencion,VrReteICA=@pmVrReteICA,VrReteIVA=@pmVrReteIVA,VrOtros=@pmVrOtros,VrOtrDcto=@pmVrOtrDcto,VrAhorro=@pmVrAhorro,VrPagosMas=@pmVrPagosMas,VrNeto=@pmVrNeto
,VrAplicado=@pmVrAplicado,VrAnticipo=@pmVrAnticipo,VrEfectivo=@pmVrEfectivo,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,BaseRiv=@pmBaseRiv,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom
,IdLocal=@pmIdLocal,EnEfectivo=@pmEnEfectivo,CdForma=@pmCdForma,NumForma=@pmNumForma,DetallePago=@pmDetallePago,CdBanco=@pmCdBanco,CdCta=@pmCdCta,IdCajero=@pmIdCajero,Referencia=@pmReferencia,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,TipDcm=@pmTipDcm,Documento=@pmDocumento,IdCiaDcm=@pmIdCiaDcm,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,VrReteCREE=@pmVrReteCREE,TarifaRtc=@pmTarifaRtc,CodTarRtc=@pmCodTarRtc,VrDevFact=@pmVrDevFact,VrBomberil=@pmVrBomberil,TarifaBom=@pmTarifaBom,CodTarifBom=@pmCodTarifBom,ImpAviTab=@pmImpAviTab,TarifaAvta=@pmTarifaAvta,CodTarifAvta=@pmCodTarifAvta,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecibosDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRecibosDev] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Recibos SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRecTanqueosAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUpRecTanqueosAnu] @pmTipDoc VARCHAR(3),@pmRecibo INT,@pmIdCia CHAR(2),@pmCantidad DECIMAL(14,4)
AS
 UPDATE  Trn_RecTanqueos  SET  Cantidad=@pmCantidad
 WHERE TipDoc=@pmTipDoc AND Recibo=@pmRecibo AND  IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRegimenDian]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRegimenDian] @pmIdRegimen VARCHAR(4),@pmRegimen VARCHAR(50),@pmCodFiscal VARCHAR(20),@pmInactivo BIT
 AS 
 UPDATE RegimenDian SET Regimen=@pmRegimen,CodFiscal=@pmCodFiscal,Inactivo=@pmInactivo
 WHERE IdRegimen=@pmIdRegimen
GO
/****** Object:  StoredProcedure [dbo].[paUpRegistro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRegistro] @pmIdCia CHAR(2),@pmIdEmpresa VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmDvNit CHAR(1),@pmRazonSocial VARCHAR(250),@pmDescripcion VARCHAR(250)
,@pmDireccion VARCHAR(250),@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmIdLocal VARCHAR(8),@pmIdPais VARCHAR(8),@pme_mail VARCHAR(100),@pmArchivoLogo VARCHAR(30),@pmNumeroSerial VARCHAR(80)
,@pmRegimen VARCHAR(50),@pmLicencia VARCHAR(20),@pmVigenciaLic SMALLDATETIME,@pmPersoneria VARCHAR(40),@pmLeyenda VARCHAR(250),@pmFechaRegistro SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmCurrtyDate SMALLDATETIME
,@pmTipoId CHAR(1),@pmNitRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150),@pmTipoPersna CHAR(1),@pmCIIUDane VARCHAR(8),@pmCurDate1 SMALLDATETIME,@pmFechaPrest SMALLDATETIME
 AS 
 UPDATE adm_Registro SET IdEmpresa=@pmIdEmpresa,NitEmpresa=@pmNitEmpresa,DvNit=@pmDvNit,RazonSocial=@pmRazonSocial,Descripcion=@pmDescripcion,Direccion=@pmDireccion,Telefono=@pmTelefono
,Fax=@pmFax,IdLocal=@pmIdLocal,IdPais=@pmIdPais,e_mail=@pme_mail,ArchivoLogo=@pmArchivoLogo,NumeroSerial=@pmNumeroSerial,Regimen=@pmRegimen,Licencia=@pmLicencia,VigenciaLic=@pmVigenciaLic
,Personeria=@pmPersoneria,Leyenda=@pmLeyenda,FechaRegistro=@pmFechaRegistro,FechaVence=@pmFechaVence,CurrtyDate=@pmCurrtyDate
,TipoId=@pmTipoId,NitRepLegal=@pmNitRepLegal,RepLegal=@pmRepLegal,TipoPersna=@pmTipoPersna ,CIIUDane=@pmCIIUDane,CurDate1=@pmCurDate1,FechaPrest=@pmFechaPrest
GO
/****** Object:  StoredProcedure [dbo].[paUpRegistroFec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRegistroFec]  @pmCurrtyDate SMALLDATETIME,@pmUpCia BIT,@pmIdCia CHAR(2)=Null
 AS 
 IF @pmUpCia=1  
  BEGIN
  DECLARE @TrnCias VARCHAR(20)
  SELECT @TrnCias = 'TrnFecha'
  BEGIN TRANSACTION @TrnCias
  UPDATE adm_Registro SET CurrtyDate=@pmCurrtyDate
  UPDATE Companias SET FechaActual=@pmCurrtyDate WHERE IdCia=@pmIdCia
  COMMIT TRANSACTION  @TrnCias  
  END
 ELSE
  UPDATE adm_Registro SET CurrtyDate=@pmCurrtyDate
GO
/****** Object:  StoredProcedure [dbo].[paUpRelaciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRelaciones] @pmIdTabla VARCHAR(20),@pmTablaForanea VARCHAR(20),@pmCampoForaneo VARCHAR(20)
,@pmBasedeDatos VARCHAR(10),@pmNoValidar BIT
 AS 
 UPDATE Sys_Relaciones SET BasedeDatos=@pmBasedeDatos,NoValidar=@pmNoValidar
 WHERE IdTabla=@pmIdTabla AND TablaForanea=@pmTablaForanea AND CampoForaneo=@pmCampoForaneo
GO
/****** Object:  StoredProcedure [dbo].[paUpRemision]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRemision] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaDesp SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmUnidades DECIMAL(14,4),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(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),@pmMulPlazos BIT, @pmIdPlazo VARCHAR(4), @pmCdRuta VARCHAR(4)
,@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16)
,@pmDetalleEnvio VARCHAR(250),@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME,@pmTipPed VARCHAR(3),@pmPedido INT,@pmIdCiaPed CHAR(2),@pmFechaPed SMALLDATETIME,@pmNumAutoriza INT,@pmModalidad VARCHAR(10),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Remision SET Fecha=@pmFecha,FechaDesp=@pmFechaDesp,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,VrSubTotal=@pmVrSubTotal,VrDescuento=@pmVrDescuento,VrImpuesto=@pmVrImpuesto,VrFletes=@pmVrFletes,VrOtros=@pmVrOtros
,VrOtrDcto=@pmVrOtrDcto,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,Unidades=@pmUnidades,IdVend=@pmIdVend,TarifaCom=@pmTarifaCom,CodTarCom=@pmCodTarCom,DirEnvio=@pmDirEnvio,IdLocEnv=@pmIdLocEnv,DiasEntraga=@pmDiasEntraga,NitContac=@pmNitContac,NomContac=@pmNomContac
,TelContac=@pmTelContac,emlContac=@pmemlContac,CargoContac=@pmCargoContac,NitEmpTrans=@pmNitEmpTrans,EmpTrans=@pmEmpTrans,pVehiculo=@pmpVehiculo,CdConductor=@pmCdConductor,DetalleEnvio=@pmDetalleEnvio,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,TipPed=@pmTipPed,Pedido=@pmPedido,IdCiaPed=@pmIdCiaPed,NumAutoriza=@pmNumAutoriza,Modalidad=@pmModalidad,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,IdForma=@pmIdForma,DetallePago=@pmDetallePago,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,CdRuta=@pmCdRuta,FechaPed=@pmFechaPed
,NumAprob=@pmNumAprob,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionAbr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRemisionAbr] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Remision SET TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRemisionAnu] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Remision SET  Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRemisionApr] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2)
,@pmObservacion VARCHAR(250),@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Remision SET NumAprob=@pmNumAprob,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob
,IdEstado=@pmIdEstado,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRemisionFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRemisionFac] @pmTipDoc VARCHAR(3),@pmRemision INT,@pmIdCia CHAR(2)
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFact SMALLDATETIME
,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Remision SET  TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFact=@pmFechaFact
 ,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Remision=@pmRemision AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpReport]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpReport] @pmTipoRep VARCHAR(3),@pmIdRep CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmTipoPapel INT
,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50),@pmNomRep VARCHAR(50)
 AS 
 UPDATE Sys_Report SET Descripcion=@pmDescripcion,Formato=@pmFormato,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup
,NumCopias=@pmNumCopias,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location,NomRep=@pmNomRep
 WHERE TipoRep=@pmTipoRep AND IdRep=@pmIdRep
GO
/****** Object:  StoredProcedure [dbo].[paUpReportFmto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpReportFmto] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmTipoOrigen VARCHAR(10),@pmCrVersion INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 UPDATE Sys_ReportFmto SET TipoOrigen=@pmTipoOrigen,CrVersion=@pmCrVersion,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato
GO
/****** Object:  StoredProcedure [dbo].[paUpReportSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpReportSub] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmNombreSub VARCHAR(20),@pmTipoOrigen VARCHAR(10),@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 UPDATE Sys_ReportSub SET TipoOrigen=@pmTipoOrigen,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato AND NombreSub=@pmNombreSub
GO
/****** Object:  StoredProcedure [dbo].[paUpReportSubPmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpReportSubPmt] @pmTipoRep VARCHAR(10),@pmFormato VARCHAR(20)
,@pmNombreSub VARCHAR(20),@pmIndParam INT,@pmNomParam VARCHAR(30),@pmTipoDato VARCHAR(15),@pmValorPred VARCHAR(100)
 AS 
 UPDATE Sys_ReportSubPmt SET NomParam=@pmNomParam,TipoDato=@pmTipoDato,ValorPred=@pmValorPred
 WHERE TipoRep=@pmTipoRep AND Formato=@pmFormato AND NombreSub=@pmNombreSub AND IndParam=@pmIndParam
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRequisicion] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdRespons VARCHAR(16),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
,@pmIdDep VARCHAR(4),@pmVrSubTotal MONEY,@pmCantidad DECIMAL(14,4),@pmNContrato INT,@pmIdCiaCont CHAR(2),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmModalidad VARCHAR(10),@pmDirEntrega VARCHAR(250),@pmIdLocEnt VARCHAR(8)
,@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2),@pmFechaSal SMALLDATETIME,@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmNomContacto VARCHAR(150),@pmTelsContacto VARCHAR(50),@pmEmailContacto VARCHAR(100),@pmAnulado BIT
,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmNum_Vehic VARCHAR(10),@pmNum_Trailer VARCHAR(10),@pmTipoVigencia VARCHAR(10),@pmNivelAprob INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Requisicion SET Fecha=@pmFecha,FechaVence=@pmFechaVence,IdConcepto=@pmIdConcepto,IdRespons=@pmIdRespons,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,IdDep=@pmIdDep,VrSubTotal=@pmVrSubTotal
,Cantidad=@pmCantidad,NContrato=@pmNContrato,IdCiaCont=@pmIdCiaCont,NitCliente=@pmNitCliente,CdAgencia=@pmCdAgencia,Modalidad=@pmModalidad,DirEntrega=@pmDirEntrega
,IdLocEnt=@pmIdLocEnt,TipSal=@pmTipSal,NumSalida=@pmNumSalida,IdCiaSal=@pmIdCiaSal,FechaSal=@pmFechaSal,NumAprob=@pmNumAprob
,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,NomContacto=@pmNomContacto,TelsContacto=@pmTelsContacto,EmailContacto=@pmEmailContacto,Num_Vehic=@pmNum_Vehic,Num_Trailer=@pmNum_Trailer,TipoVigencia=@pmTipoVigencia,NivelAprob=@pmNivelAprob,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRequisicionAnu] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Requisicion SET  Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicionApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRequisicionApr] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
,@pmNumAprob INT,@pmFecAprob SMALLDATETIME,@pmCdUsuAprob VARCHAR(11),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmNivelAprob INT
 AS 
 UPDATE Trn_Requisicion SET  NumAprob=@pmNumAprob,FecAprob=@pmFecAprob,CdUsuAprob=@pmCdUsuAprob
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NivelAprob=@pmNivelAprob
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpRequisicionSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRequisicionSal] @pmTipDoc VARCHAR(3),@pmRequisicion INT,@pmIdCia CHAR(2)
,@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2),@pmFechaSal SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Requisicion SET TipSal=@pmTipSal,NumSalida=@pmNumSalida,IdCiaSal=@pmIdCiaSal,FechaSal=@pmFechaSal
,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Requisicion=@pmRequisicion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpResiduosPeligrosos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpResiduosPeligrosos] @pmCodigoUN VARCHAR(30),@pmDesignacion VARCHAR(500),@pmClase VARCHAR(10),@pmPeligroSec VARCHAR(10),@pmGrupoEmb VARCHAR(20),@pmIdCoRes VARCHAR(8),@pmIdCRdes VARCHAR(8),@pmInactivo BIT
 AS 
 UPDATE ResiduosPeligrosos SET Designacion=@pmDesignacion,Clase=@pmClase,PeligroSec=@pmPeligroSec,GrupoEmb=@pmGrupoEmb,IdCoRes=@pmIdCoRes,IdCRdes=@pmIdCRdes,Inactivo=@pmInactivo
 WHERE CodigoUN=@pmCodigoUN
GO
/****** Object:  StoredProcedure [dbo].[paUpRoles]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRoles] @pmIdObj VARCHAR(10),@pmIdRole VARCHAR(3),@pmFuncion VARCHAR(100)
 AS 
 UPDATE Sys_Roles SET Funcion=@pmFuncion
 WHERE IdObj=@pmIdObj AND IdRole=@pmIdRole
GO
/****** Object:  StoredProcedure [dbo].[paUpRutas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRutas] @pmIdRuta VARCHAR(4),@pmRuta VARCHAR(100),@pmIdLocOri VARCHAR(8),@pmIdLocDes VARCHAR(8),@pmEsLocal BIT
,@pmDistkmt DECIMAL(14,4),@pmTmHoras VARCHAR(8),@pmCodigoMt VARCHAR(5),@pmFleteTon MONEY,@pmCdCiaTurno CHAR(2),@pmPuntosRut DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE Rutas SET Ruta=@pmRuta,IdLocOri=@pmIdLocOri,IdLocDes=@pmIdLocDes,EsLocal=@pmEsLocal,Distkmt=@pmDistkmt
,TmHoras=@pmTmHoras,CodigoMt=@pmCodigoMt,FleteTon=@pmFleteTon,CdCiaTurno=@pmCdCiaTurno,PuntosRut=@pmPuntosRut,Inactivo=@pmInactivo
 WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paUpRutasPlan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpRutasPlan] @pmIdRuta VARCHAR(4),@pmIdPunto INT,@pmDescripcion VARCHAR(100),@pmDistancia DECIMAL(14,4)
,@pmTiempo VARCHAR(8),@pmClasePto VARCHAR(10),@pmCdPto VARCHAR(4),@pmIdLocal VARCHAR(8),@pmPosLat DECIMAL(14,4),@pmPosLon DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE RutasPlan SET Descripcion=@pmDescripcion,Distancia=@pmDistancia,Tiempo=@pmTiempo,ClasePto=@pmClasePto,CdPto=@pmCdPto
,IdLocal=@pmIdLocal,PosLat=@pmPosLat,PosLon=@pmPosLon,Inactivo=@pmInactivo
 WHERE IdRuta=@pmIdRuta AND IdPunto=@pmIdPunto
GO
/****** Object:  StoredProcedure [dbo].[paUpRutasTramos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpRutasTramos] @pmIdRuta VARCHAR(4),@pmNumTramo INT,@pmIdLocal VARCHAR(8),@pmkmstramo DECIMAL(14,4),@pmkmstotal DECIMAL(14,4)
 AS 
 UPDATE RutasTramos SET IdLocal=@pmIdLocal,kmstramo=@pmkmstramo,kmstotal=@pmkmstotal
 WHERE IdRuta=@pmIdRuta AND NumTramo=@pmNumTramo
GO
/****** Object:  StoredProcedure [dbo].[paUpSalidas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSalidas] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY
,@pmVrImpuesto MONEY,@pmVrCostos MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmBaseImp MONEY,@pmTarifaIva DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmTipOrd VARCHAR(3)
,@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmModalidad VARCHAR(10)
,@pmCdConductor VARCHAR(16),@pmCdDep VARCHAR(4),@pmNContrato INT,@pmIdCiaCont CHAR(2),@pmNitCliente VARCHAR(16),@pmCdAgencia VARCHAR(16),@pmModRequis VARCHAR(10)
,@pmDirEntrega VARCHAR(250),@pmIdLocEnt VARCHAR(8),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmGuiaComb INT,@pmCdCiaGuia CHAR(2),@pmNumDotac INT,@pmDiaVigDot INT,@pmFecVigDot SMALLDATETIME,@pmEdoDocEnt INT,@pmNumDocEnt INT,@pmCiaDocEnt CHAR(2),@pmVrImpuBA MONEY,@pmVrImpuCUP MONEY
,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Salidas SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,VrSubTotal=@pmVrSubTotal,VrImpuesto=@pmVrImpuesto,VrCostos=@pmVrCostos,VrNeto=@pmVrNeto,Cantidad=@pmCantidad
,BaseImp=@pmBaseImp,TarifaIva=@pmTarifaIva,CodTarIva=@pmCodTarIva,TipOrd=@pmTipOrd,NumOrden=@pmNumOrden,IdCiaOrd=@pmIdCiaOrd,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,pVehiculo=@pmpVehiculo
,CdConductor=@pmCdConductor,CdDep=@pmCdDep,NContrato=@pmNContrato,IdCiaCont=@pmIdCiaCont,NitCliente=@pmNitCliente,CdAgencia=@pmCdAgencia,ModRequis=@pmModRequis
,DirEntrega=@pmDirEntrega,IdLocEnt=@pmIdLocEnt,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev
,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,GuiaComb=@pmGuiaComb,CdCiaGuia=@pmCdCiaGuia,NumDotac=@pmNumDotac,DiaVigDot=@pmDiaVigDot,FecVigDot=@pmFecVigDot
,EdoDocEnt=@pmEdoDocEnt,NumDocEnt=@pmNumDocEnt,CiaDocEnt=@pmCiaDocEnt,VrImpuBA=@pmVrImpuBA,VrImpuCUP=@pmVrImpuCUP,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpSalidasDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSalidasDev] @pmTipDoc VARCHAR(3),@pmSalida INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_Salidas SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE TipDoc=@pmTipDoc AND Salida=@pmSalida AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpSAutoriza]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSAutoriza] @pmIdConcepto VARCHAR(4),@pmConceptoAut VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE Sys_Autoriza SET ConceptoAut=@pmConceptoAut,Inactivo=@pmInactivo
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpSectoresEco]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSectoresEco] @pmIdSector VARCHAR(8),@pmSectorEco VARCHAR(250),@pmCdTarifRtc VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE SectoresEco SET SectorEco=@pmSectorEco,Inactivo=@pmInactivo,CdTarifRtc=@pmCdTarifRtc
 WHERE IdSector=@pmIdSector
GO
/****** Object:  StoredProcedure [dbo].[paUpSecurity]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSecurity] @pmIdLla INT,@pmDescripcion VARCHAR(50),@pmPwd VARCHAR(10)
 AS 
 UPDATE Sys_Security SET Descripcion=@pmDescripcion,Pwd=@pmPwd
 WHERE IdLla=@pmIdLla
GO
/****** Object:  StoredProcedure [dbo].[paUpSeriales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSeriales] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4),@pmCdUbic VARCHAR(10),@pmFecEntrada SMALLDATETIME
,@pmFecSalida SMALLDATETIME,@pmNitProv VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmObservacion VARCHAR(250),@pmReferncia1 VARCHAR(50),@pmReferncia2 VARCHAR(50)
,@pmFecRef1 SMALLDATETIME,@pmFecRef2 SMALLDATETIME,@pmUbicacion VARCHAR(50)
 AS 
 UPDATE Trn_Seriales SET IdBodega=@pmIdBodega,CdUbic=@pmCdUbic,FecEntrada=@pmFecEntrada,FecSalida=@pmFecSalida,NitProv=@pmNitProv,IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Observacion=@pmObservacion,Referncia1=@pmReferncia1,Referncia2=@pmReferncia2,FecRef1=@pmFecRef1,FecRef2=@pmFecRef2,Ubicacion=@pmUbicacion
 WHERE IdProducto=@pmIdProducto AND NumSerial=@pmNumSerial AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpSerialesEtd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSerialesEtd] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE Trn_Seriales SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo
 WHERE IdProducto=@pmIdProducto AND NumSerial=@pmNumSerial AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpSerialesSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSerialesSal] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2)
,@pmFecSalida SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmReferncia1 VARCHAR(50),@pmReferncia2 VARCHAR(50)
,@pmObservacion  VARCHAR(250),@pmFecRef1 SMALLDATETIME,@pmFecRef2 SMALLDATETIME
 AS 
 UPDATE Trn_Seriales SET FecSalida=@pmFecSalida,IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Observacion=@pmObservacion,Referncia1=@pmReferncia1,Referncia2=@pmReferncia2,FecRef1=@pmFecRef1,FecRef2=@pmFecRef2
 WHERE IdProducto=@pmIdProducto AND NumSerial=@pmNumSerial AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpSerialesUbi]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSerialesUbi] @pmIdProducto VARCHAR(16),@pmNumSerial VARCHAR(30),@pmIdCia CHAR(2),@pmIdBodega VARCHAR(4),@pmCdUbic VARCHAR(10)
,@pmUbicacion VARCHAR(50),@pmObservacion VARCHAR(250)
 AS 
 UPDATE Trn_Seriales SET IdBodega=@pmIdBodega,CdUbic=@pmCdUbic
,Observacion=@pmObservacion,Ubicacion=@pmUbicacion
 WHERE IdProducto=@pmIdProducto AND NumSerial=@pmNumSerial AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpSobEntidades]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSobEntidades] @pmIdEnterr VARCHAR(8),@pmTipoEnterr VARCHAR(10),@pmNitEntidad VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmDirOficina VARCHAR(250)
,@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmSitioWeb VARCHAR(100),@pme_mail VARCHAR(100),@pmCedRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150)
,@pmFormaPago VARCHAR(10),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmCdLocCue VARCHAR(8)
,@pmCargoRep VARCHAR(50),@pmNomTitular VARCHAR(150),@pmNomEntidad VARCHAR(50),@pmInactivo BIT,@pmCodCtaPag VARCHAR(4)
 AS 
 UPDATE SobEntidades SET TipoEnterr=@pmTipoEnterr,NitEntidad=@pmNitEntidad,TipoId=@pmTipoId,Dv=@pmDv,DirOficina=@pmDirOficina,Telefono=@pmTelefono,Fax=@pmFax,SitioWeb=@pmSitioWeb
,e_mail=@pme_mail,CedRepLegal=@pmCedRepLegal,RepLegal=@pmRepLegal,FormaPago=@pmFormaPago,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,CdLocCue=@pmCdLocCue
,CargoRep=@pmCargoRep,NomTitular=@pmNomTitular,NomEntidad=@pmNomEntidad,Inactivo=@pmInactivo,CodCtaPag=@pmCodCtaPag
 WHERE IdEnterr=@pmIdEnterr
GO
/****** Object:  StoredProcedure [dbo].[paUpSobProductos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSobProductos] @pmIdClase INT,@pmIdProducto VARCHAR(16),@pmClaseProd VARCHAR(20)
 AS 
 UPDATE SobProductos SET IdProducto=@pmIdProducto,ClaseProd=@pmClaseProd
 WHERE IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpSobretasas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSobretasas] @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmFecha SMALLDATETIME,@pmnAnno INT,@pmnMes INT,@pmIdEnterr VARCHAR(8),@pmTipoEntidad VARCHAR(10),@pmVrSobretasa MONEY,@pmVrSanciones MONEY,@pmVrCompensa MONEY,@pmVrIntMora MONEY
,@pmVrTotalPagar MONEY,@pmVrFondoSubs MONEY,@pmVrRecaudoDep MONEY,@pmNitDeclara VARCHAR(16),@pmDvDeclara CHAR(1),@pmCedDeclara VARCHAR(16),@pmDeclarante VARCHAR(250),@pmDirEntidad VARCHAR(250),@pmEmailEnt VARCHAR(100),@pmNomRepres VARCHAR(150)
,@pmCargoRepres VARCHAR(50),@pmTipoFirma INT,@pmNitRevisor VARCHAR(16),@pmNomRevisor VARCHAR(150),@pmTpRevisor VARCHAR(20),@pmNumCheque VARCHAR(30),@pmCodBanco VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4)
,@pmCdLocCue VARCHAR(8),@pmTitularCuenta VARCHAR(150),@pmVrEfectivo MONEY,@pmVrOtros MONEY,@pmVrTransf MONEY,@pmVrPagado MONEY,@pmEstado INT,@pmAdhesivo VARCHAR(30),@pmFechaPago SMALLDATETIME,@pmEsCorr BIT,@pmNumCorr VARCHAR(30)
,@pmFecCorr SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME,@pmCodCta VARCHAR(4),@pmTipEgreso VARCHAR(3),@pmNumEgreso INT,@pmCiaEgreso CHAR(2)
 AS 
 UPDATE Trn_Sobretasas SET Fecha=@pmFecha,nAnno=@pmnAnno,nMes=@pmnMes,IdEnterr=@pmIdEnterr,TipoEntidad=@pmTipoEntidad,VrSobretasa=@pmVrSobretasa,VrSanciones=@pmVrSanciones,VrCompensa=@pmVrCompensa,VrIntMora=@pmVrIntMora,VrTotalPagar=@pmVrTotalPagar
,VrFondoSubs=@pmVrFondoSubs,VrRecaudoDep=@pmVrRecaudoDep,NitDeclara=@pmNitDeclara,DvDeclara=@pmDvDeclara,CedDeclara=@pmCedDeclara,Declarante=@pmDeclarante,DirEntidad=@pmDirEntidad,EmailEnt=@pmEmailEnt,NomRepres=@pmNomRepres
,CargoRepres=@pmCargoRepres,TipoFirma=@pmTipoFirma,NitRevisor=@pmNitRevisor,NomRevisor=@pmNomRevisor,TpRevisor=@pmTpRevisor,NumCheque=@pmNumCheque,CodBanco=@pmCodBanco,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco
,CdLocCue=@pmCdLocCue,TitularCuenta=@pmTitularCuenta,VrEfectivo=@pmVrEfectivo,VrOtros=@pmVrOtros,VrPagado=@pmVrPagado,VrTransf=@pmVrTransf,Estado=@pmEstado,Adhesivo=@pmAdhesivo,FechaPago=@pmFechaPago,EsCorr=@pmEsCorr,NumCorr=@pmNumCorr,FecCorr=@pmFecCorr
,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate,CodCta=@pmCodCta,TipEgreso=@pmTipEgreso,NumEgreso=@pmNumEgreso,CiaEgreso=@pmCiaEgreso
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paUpSobretasasCie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSobretasasCie] @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmEstado INT
,@pmObservacion VARCHAR(250),@pmAdhesivo VARCHAR(30),@pmFechaPago SMALLDATETIME,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Sobretasas SET Estado=@pmEstado,Observacion=@pmObservacion
,Adhesivo=@pmAdhesivo,FechaPago=@pmFechaPago,FecUpdate=@pmFecUpdate
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paUpSobretasasEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSobretasasEst] @pmIdDec VARCHAR(4),@pmNumDeclara INT,@pmEstado INT
,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Sobretasas SET Estado=@pmEstado,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate
 WHERE IdDec=@pmIdDec AND NumDeclara=@pmNumDeclara
GO
/****** Object:  StoredProcedure [dbo].[paUpSobTiposDec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSobTiposDec] @pmIdDec VARCHAR(4),@pmDeclaracion VARCHAR(100),@pmTipoDec VARCHAR(20),@pmNitDec VARCHAR(16),@pmTipoIdDec CHAR(1),@pmNombreDec VARCHAR(250)
,@pmDvDec CHAR(1),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(20),@pmCedRepLegal VARCHAR(16),@pmRepLegal VARCHAR(150),@pmTipoFirma INT,@pmNitRevisor VARCHAR(16)
,@pmNomRevisor VARCHAR(150),@pmTpRevisor VARCHAR(20),@pmTarifSubsidio DECIMAL(14,4),@pmConsecutivo INT
 AS 
 UPDATE SobTiposDec SET Declaracion=@pmDeclaracion,TipoDec=@pmTipoDec,NitDec=@pmNitDec,TipoIdDec=@pmTipoIdDec,NombreDec=@pmNombreDec,DvDec=@pmDvDec,Direccion=@pmDireccion
,IdLocal=@pmIdLocal,Telefono=@pmTelefono,CedRepLegal=@pmCedRepLegal,RepLegal=@pmRepLegal,TipoFirma=@pmTipoFirma,NitRevisor=@pmNitRevisor,NomRevisor=@pmNomRevisor
,TpRevisor=@pmTpRevisor,TarifSubsidio=@pmTarifSubsidio,Consecutivo=@pmConsecutivo
 WHERE IdDec=@pmIdDec
GO
/****** Object:  StoredProcedure [dbo].[paUpSobTiposDecNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSobTiposDecNum] @pmIdDec VARCHAR(4),@pmConsecutivo INT
 AS 
 IF @pmConsecutivo IS NULL
  UPDATE SobTiposDec SET  Consecutivo=Consecutivo+1 WHERE IdDec=@pmIdDec
 ELSE
  UPDATE SobTiposDec SET  Consecutivo=@pmConsecutivo WHERE IdDec=@pmIdDec
GO
/****** Object:  StoredProcedure [dbo].[paUpSubCentros]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSubCentros] @pmIdSubCos VARCHAR(16),@pmSubCosto VARCHAR(100),@pmIdCCosto VARCHAR(16),@pmFecUpdate SMALLDATETIME,@pmInactivo BIT
 AS 
 UPDATE SubCentros SET SubCosto=@pmSubCosto,IdCCosto=@pmIdCCosto,FecUpdate=@pmFecUpdate,Inactivo=@pmInactivo
 WHERE IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUpSubGrupos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSubGrupos] @pmIdSubgrupo VARCHAR(8),@pmSubgrupo VARCHAR(150),@pmIdGrupo VARCHAR(8)
,@pmCdTarIva VARCHAR(4),@pmCdTarAut VARCHAR(4),@pmCdTarRet VARCHAR(4)
,@pmCdTarIca VARCHAR(4),@pmTipoInvent VARCHAR(10),@pmCdTarifImv VARCHAR(4),@pmCdTarifIco VARCHAR(4),@pmCdTarIvp VARCHAR(4),@pmCdTarifIcu VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE SubGrupos SET Subgrupo=@pmSubgrupo,IdGrupo=@pmIdGrupo,CdTarIva=@pmCdTarIva
,CdTarAut=@pmCdTarAut,CdTarRet=@pmCdTarRet,CdTarIca=@pmCdTarIca
,TipoInvent=@pmTipoInvent,Inactivo=@pmInactivo,CdTarifImv=@pmCdTarifImv,CdTarifIco=@pmCdTarifIco,CdTarIvp=@pmCdTarIvp,CdTarifIcu=@pmCdTarifIcu
 WHERE IdSubgrupo=@pmIdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paUpSubGruposAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpSubGruposAgenc] @pmIdSubAgenc VARCHAR(4),@pmSubGrupoAgenc VARCHAR(50),@pmIdGrupo VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE SubGruposAgenc SET SubGrupoAgenc=@pmSubGrupoAgenc,IdGrupo=@pmIdGrupo,Inactivo=@pmInactivo
 WHERE IdSubAgenc=@pmIdSubAgenc
GO
/****** Object:  StoredProcedure [dbo].[paUpSubgruposCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpSubgruposCue] @pmIdSubgrupo VARCHAR(8),@pmIdClase VARCHAR(4),@pmIdCuenta VARCHAR(16)
,@pmCdCueDev VARCHAR(16),@pmCdCueCom VARCHAR(16),@pmCdCueCdv VARCHAR(16),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE SubgruposCue SET IdCuenta=@pmIdCuenta,CdCueDev=@pmCdCueDev,CdCueCom=@pmCdCueCom,CdCueCdv=@pmCdCueCdv,FecUpdate=@pmFecUpdate
 WHERE IdSubgrupo=@pmIdSubgrupo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpSubzonas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

CREATE PROCEDURE [dbo].[paUpSubzonas] @pmIdSzona VARCHAR(4),@pmSubzona VARCHAR(50),@pmIdZona VARCHAR(4),@pmCdRuta VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE Subzonas SET Subzona=@pmSubzona,IdZona=@pmIdZona,Inactivo=@pmInactivo,Cd_Rut=@pmCdRuta
 WHERE IdSzona=@pmIdSzona
GO
/****** Object:  StoredProcedure [dbo].[paUpTablapor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTablapor] @pmIdTarifa VARCHAR(4),@pmDescripcion VARCHAR(50),@pmIdClase VARCHAR(4),@pmTarifa DECIMAL(16,6)
,@pmSimbolo CHAR(1),@pmCdLocdad VARCHAR(8),@pmMinimo MONEY,@pmMaximo MONEY,@pmInactivo BIT
 AS 
 UPDATE Tablapor SET Descripcion=@pmDescripcion,IdClase=@pmIdClase,Tarifa=@pmTarifa,Simbolo=@pmSimbolo,CdLocdad=@pmCdLocdad
,Minimo=@pmMinimo,Maximo=@pmMaximo,Inactivo=@pmInactivo
 WHERE IdTarifa=@pmIdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paUpTalleres]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTalleres] @pmIdTaller VARCHAR(4),@pmNomTaller VARCHAR(100),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8),@pmTelefono VARCHAR(30),@pmTelCelular VARCHAR(30),@pmNitTercero VARCHAR(16),@pmTipoTaller VARCHAR(20),@pmInactivo BIT
 AS 
 UPDATE Talleres SET NomTaller=@pmNomTaller,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,TelCelular=@pmTelCelular,NitTercero=@pmNitTercero,TipoTaller=@pmTipoTaller,Inactivo=@pmInactivo
 WHERE IdTaller=@pmIdTaller
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqAforo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTanqAforo] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4),@pmCantidad DECIMAL(14,4)
 AS 
 UPDATE TanqAforo SET Cantidad=@pmCantidad
 WHERE IdTanque=@pmIdTanque AND UndAforo=@pmUndAforo
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqAforoFrac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTanqAforoFrac] @pmIdTanque VARCHAR(4),@pmUndAforo DECIMAL(14,4),@pmFraccion DECIMAL(14,4),@pmMilimetros DECIMAL(14,4)
 AS 
 UPDATE TanqAforoFrac SET Fraccion=@pmFraccion,Milimetros=@pmMilimetros
 WHERE IdTanque=@pmIdTanque AND UndAforo=@pmUndAforo
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqDispens]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTanqDispens] @pmIdMngra VARCHAR(10),@pmNumDisp VARCHAR(4),@pmNumPos VARCHAR(4),@pmNumMngra VARCHAR(4),@pmIdTanque VARCHAR(4),@pmDescripcion VARCHAR(50),@pmLecGalAnt DECIMAL(14,4),@pmLecGalUlt DECIMAL(14,4)
,@pmLecPesAnt MONEY,@pmLecPesUlt MONEY,@pmLtaPrec CHAR(1),@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT,@pmLecGalMax DECIMAL(14,4)
 AS 
 UPDATE TanqDispens SET NumDisp=@pmNumDisp,NumPos=@pmNumPos,NumMngra=@pmNumMngra,IdTanque=@pmIdTanque,Descripcion=@pmDescripcion,LecGalAnt=@pmLecGalAnt,LecGalUlt=@pmLecGalUlt,LecPesAnt=@pmLecPesAnt,LecPesUlt=@pmLecPesUlt
,LtaPrec=@pmLtaPrec,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo,LecGalMax=@pmLecGalMax
 WHERE IdMngra=@pmIdMngra
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqDispensLec]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTanqDispensLec] @pmIdMngra VARCHAR(10),@pmLecGalAnt DECIMAL(14,4),@pmLecGalUlt DECIMAL(14,4)
 AS 
 UPDATE TanqDispens SET LecGalAnt=@pmLecGalAnt,LecGalUlt=@pmLecGalUlt
 WHERE IdMngra=@pmIdMngra
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTanqSaldos] @pmIdTanque VARCHAR(4),@pmIdCia CHAR(2),@pmSaldoActual DECIMAL(14,4)
 AS 
 UPDATE TanqSaldos SET SaldoActual=@pmSaldoActual
 WHERE IdTanque=@pmIdTanque AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTanqSaldosKar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTanqSaldosKar] @pmDelete BIT,@pmIdProducto VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
 AS 
 IF @pmDelete<>0  
  BEGIN
   DECLARE @TrnNombre VARCHAR(20)
   SELECT @TrnNombre = 'TrnProdSaldos'
   BEGIN TRANSACTION @TrnNombre
    DELETE TanqSaldos
    FROM TanqSaldos AS TS INNER JOIN Tanques AS T ON TS.IdTanque=T.IdTanque
    WHERE IdCia LIKE ISNULL(@pmIdCia,'%%')  AND IdProducto LIKE ISNULL(@pmIdProducto,'%')
    INSERT INTO  TanqSaldos  (IdTanque,IdCia,SaldoActual)
    SELECT ISNULL(CdTanque,'0'),IdCia,SUM(Entradas-Salidas)
    FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
    WHERE TipDoc NOT IN ('PED','REM','COT','ODC','GUI','OCC','ODS','VCC') AND TipoRef<>'SERVICIO' AND Tanques<>0
    AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
    GROUP BY CdTanque,IdCia
   COMMIT TRANSACTION  @TrnNombre
   END
 ELSE
  INSERT INTO  TanqSaldos  (IdTanque,IdCia,SaldoActual)
  SELECT ISNULL(CdTanque,'0'),IdCia,SUM(Entradas-Salidas)
  FROM Trn_Kardex AS K INNER JOIN ProdMcias AS P ON K.IdProducto=P.IdProducto
  WHERE TipDoc NOT IN ('PED','REM','COT','ODC','GUI','OCC','ODS','VCC') AND TipoRef<>'SERVICIO' AND Tanques<>0
  AND K.IdProducto LIKE ISNULL(@pmIdProducto,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  GROUP BY CdTanque,IdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTanques]    Script Date: 10/12/2025 8:11:25 ******/
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
/****** Object:  StoredProcedure [dbo].[paUpTanquesSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTanquesSal] @pmIdProducto VARCHAR(16)=Null,@pmIdTanque VARCHAR(4)=Null
 AS 
 IF @pmIdProducto IS NULL AND @pmIdTanque IS NULL
  BEGIN 
   UPDATE Tanques SET SaldoActual=(SELECT ISNULL(SUM(SaldoActual),0) FROM TanqSaldos WHERE Tanques.IdTanque=TanqSaldos.IdTanque)
  END
 ELSE
  BEGIN
   IF @pmIdProducto IS NULL
    BEGIN
     UPDATE Tanques SET SaldoActual=(SELECT ISNULL(SUM(SaldoActual),0) FROM TanqSaldos WHERE Tanques.IdTanque=TanqSaldos.IdTanque)
     WHERE IdTanque=@pmIdTanque
    END
   ELSE
    BEGIN
     UPDATE Tanques SET SaldoActual=(SELECT ISNULL(SUM(SaldoActual),0) FROM TanqSaldos WHERE Tanques.IdTanque=TanqSaldos.IdTanque)
     WHERE IdProducto=@pmIdProducto AND (IdTanque=@pmIdTanque OR @pmIdTanque IS NULL)
    END
   END
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifAnticipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifAnticipos] @pmNumero INT,@pmCuotaMax DECIMAL(14,4),@pmTipoCuota VARCHAR(10),@pmTipoAplica VARCHAR(10)
,@pmCdOrigen VARCHAR(8),@pmCdDestino VARCHAR(8),@pmNitCliente VARCHAR(16),@pmCdTipoVeh VARCHAR(4)
,@pmTipoAfilVeh VARCHAR(10),@pmInactivo BIT,@pmCdRuta VARCHAR(4),@pmNitPropietario VARCHAR(16),@pmTipo_Egreso VARCHAR(20)
 AS 
 UPDATE TarifAnticipos SET CuotaMax=@pmCuotaMax,TipoCuota=@pmTipoCuota,TipoAplica=@pmTipoAplica,CdOrigen=@pmCdOrigen,CdDestino=@pmCdDestino
,NitCliente=@pmNitCliente,CdTipoVeh=@pmCdTipoVeh,TipoAfilVeh=@pmTipoAfilVeh,CdRuta=@pmCdRuta,Inactivo=@pmInactivo,NitPropietario=@pmNitPropietario
,Tipo_Egreso=@pmTipo_Egreso
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasAportes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifasAportes] @pmId INT,@pmFecha SMALLDATETIME,@pmIdTarifVinc VARCHAR(4),@pmIdTarifApo VARCHAR(4),@pmTarifTraslado DECIMAL(14,4),@pmUndTarifTdo VARCHAR(10),@pmBaseTarifVinc VARCHAR(10),@pmBaseLiqAportes VARCHAR(10),@pmFrecLiqAportes INT,@pmCodGrupo VARCHAR(4),@pmNitAsociado VARCHAR(16),@pmId_Vehiculo VARCHAR(10),@pmUndVehiculo CHAR(1),@pmTipoVigencia CHAR(1),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME
,@pmAnulado BIT,@pmObservacion VARCHAR(500),@pmFechaAct SMALLDATETIME
 AS 
 UPDATE TarifasAportes SET Fecha=@pmFecha,IdTarifVinc=@pmIdTarifVinc,IdTarifApo=@pmIdTarifApo,TarifTraslado=@pmTarifTraslado,UndTarifTdo=@pmUndTarifTdo,BaseTarifVinc=@pmBaseTarifVinc,BaseLiqAportes=@pmBaseLiqAportes,FrecLiqAportes=@pmFrecLiqAportes,CodGrupo=@pmCodGrupo,NitAsociado=@pmNitAsociado,Id_Vehiculo=@pmId_Vehiculo,UndVehiculo=@pmUndVehiculo,TipoVigencia=@pmTipoVigencia,FechaInicial=@pmFechaInicial,FechaFinal=@pmFechaFinal,Anulado=@pmAnulado,FechaAct=@pmFechaAct,Observacion=@pmObservacion
 WHERE [Id]=@pmId
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasFleMay]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifasFleMay] @pmIdAgencia VARCHAR(16),@pmTipoTarifa VARCHAR(10),@pmNumero INT,@pmNitEmpresa VARCHAR(16),@pmCapacMin DECIMAL(14,4),@pmCapacMax DECIMAL(14,4),@pmVrTarifa DECIMAL(14,4)
,@pmTipoLiquida VARCHAR(10),@pmDescTipoVeh VARCHAR(50),@pmInactivo BIT,@pmTipoVehic INT
 AS 
 UPDATE TarifasFleMay SET NitEmpresa=@pmNitEmpresa,CapacMin=@pmCapacMin,CapacMax=@pmCapacMax,VrTarifa=@pmVrTarifa,TipoLiquida=@pmTipoLiquida,DescTipoVeh=@pmDescTipoVeh,Inactivo=@pmInactivo,TipoVehic=@pmTipoVehic
 WHERE IdAgencia=@pmIdAgencia AND TipoTarifa=@pmTipoTarifa AND Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasFletes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifasFletes] @pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmNumero INT,@pmTipoTarifa VARCHAR(10),@pmTarifClie MONEY,@pmTarifPago MONEY,@pmTarifTabla MONEY,@pmIdMneda VARCHAR(5)
,@pmUndMed VARCHAR(10),@pmNitCliente VARCHAR(16),@pmCdNat VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmCdRango VARCHAR(4)
,@pmUndTarifClie VARCHAR(10),@pmUndTarifPago VARCHAR(10),@pmInactivo BIT,@pmCdRuta VARCHAR(4),@pmCdMercancia VARCHAR(16),@pmTipoAfiVehic VARCHAR(10)
,@pmTarifAfiliado DECIMAL(16,6),@pmTarifTercero DECIMAL(16,6),@pmTarifPropio DECIMAL(16,6),@pmTipoOper VARCHAR(10),@pmCdGrupo VARCHAR(4),@pmMargenMin DECIMAL(14,4),@pmCdAgencia VARCHAR(16)
 AS 
 UPDATE TarifasFletes SET TipoTarifa=@pmTipoTarifa,TarifClie=@pmTarifClie,TarifPago=@pmTarifPago,TarifTabla=@pmTarifTabla,IdMneda=@pmIdMneda,UndMed=@pmUndMed,NitCliente=@pmNitCliente
,CdNat=@pmCdNat,CdTipoVeh=@pmCdTipoVeh,CdRango=@pmCdRango,Inactivo=@pmInactivo,UndTarifClie=@pmUndTarifClie,UndTarifPago=@pmUndTarifPago,CdRuta=@pmCdRuta
,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,CdMercancia=@pmCdMercancia,TipoAfiVehic=@pmTipoAfiVehic
,TarifAfiliado=@pmTarifAfiliado,TarifTercero=@pmTarifTercero,TarifPropio=@pmTarifPropio,TipoOper=@pmTipoOper,CdGrupo=@pmCdGrupo,MargenMin=@pmMargenMin,CdAgencia=@pmCdAgencia
 WHERE  Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasMasivo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifasMasivo] @pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdTipoVeh VARCHAR(4),@pmTarifaUnd DECIMAL(14,4),@pmVrFletes DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE TarifasMasivo SET TarifaUnd=@pmTarifaUnd,VrFletes=@pmVrFletes,Inactivo=@pmInactivo
 WHERE IdOrigen=@pmIdOrigen AND IdDestino=@pmIdDestino AND IdTipoVeh=@pmIdTipoVeh
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasPaq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifasPaq] @pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmTarifaUnd DECIMAL(14,4),@pmTiempoEnt DECIMAL(14,4)
,@pmTarifaMin DECIMAL(14,4),@pmFormaPago VARCHAR(20),@pmInactivo BIT
 AS 
 UPDATE TarifasPaq SET TarifaUnd=@pmTarifaUnd,TiempoEnt=@pmTiempoEnt,TarifaMin=@pmTarifaMin,FormaPago=@pmFormaPago,Inactivo=@pmInactivo
 WHERE IdOrigen=@pmIdOrigen AND IdDestino=@pmIdDestino
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifasServ]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTarifasServ] @pmNumero INT,@pmTipoServ INT,@pmIdCliente VARCHAR(16),@pmIdMercancia VARCHAR(16),@pmIdEstacion VARCHAR(4),@pmUndMed VARCHAR(10),@pmTipoAfiVehic VARCHAR(10)
,@pmCdTipoVeh VARCHAR(4),@pmTarifaClie DECIMAL(16,4),@pmTarifaPago DECIMAL(16,4),@pmInactivo BIT,@pmMargenMin DECIMAL(14,4),@pmCdRuta VARCHAR(4),@pmCdCiuOrigen VARCHAR(8),@pmCdCiuDestino VARCHAR(8)
 AS 
 UPDATE TarifasServ SET TipoServ=@pmTipoServ,IdCliente=@pmIdCliente,IdMercancia=@pmIdMercancia,IdEstacion=@pmIdEstacion,UndMed=@pmUndMed,TipoAfiVehic=@pmTipoAfiVehic
,CdTipoVeh=@pmCdTipoVeh,TarifaClie=@pmTarifaClie,TarifaPago=@pmTarifaPago,Inactivo=@pmInactivo,MargenMin=@pmMargenMin,CdRuta=@pmCdRuta,CdCiuOrigen=@pmCdCiuOrigen,CdCiuDestino=@pmCdCiuDestino
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpTarifBuses]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTarifBuses] @pmIdTarifa VARCHAR(4),@pmDescripcion VARCHAR(20),@pmVrNormal MONEY,@pmVrFestivo MONEY,@pmInactivo BIT
 AS 
 UPDATE TarifBuses SET Descripcion=@pmDescripcion,VrNormal=@pmVrNormal,VrFestivo=@pmVrFestivo,Inactivo=@pmInactivo
 WHERE IdTarifa=@pmIdTarifa
GO
/****** Object:  StoredProcedure [dbo].[paUptasas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptasas] @pmIdMneda VARCHAR(5),@pmIdMnedaD VARCHAR(5),@pmFecha SMALLDATETIME,@pmTasaDia DECIMAL(14,6)
 AS 
 UPDATE Trn_tasas SET TasaDia=@pmTasaDia
 WHERE IdMneda=@pmIdMneda AND IdMnedaD=@pmIdMnedaD AND Fecha=@pmFecha
GO
/****** Object:  StoredProcedure [dbo].[paUpTasasDTF]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTasasDTF] @pmnAnno INT,@pmnMes INT,@pmnSem INT,@pmDTF_EA DECIMAL(14,4),@pmTIBC_EA DECIMAL(14,4),@pmFactor_Mon DECIMAL(14,4)
 AS 
 UPDATE TasasDTF SET DTF_EA=@pmDTF_EA,TIBC_EA=@pmTIBC_EA,Factor_Mon=@pmFactor_Mon
 WHERE nAnno=@pmnAnno AND nMes=@pmnMes AND nSem=@pmnSem
GO
/****** Object:  StoredProcedure [dbo].[paUpTasasInteres]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTasasInteres] @pmIdTasa VARCHAR(4),@pmDescTasa VARCHAR(50),@pmTipoInteres VARCHAR(10),@pmTipoPeriodo VARCHAR(10),@pmCausaInteres INT,@pmTipoDTF VARCHAR(10)
,@pmDTF_EA DECIMAL(14,4),@pmSpread_TA DECIMAL(14,4),@pmTasaEfectiva DECIMAL(14,4),@pmOpcCompra DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE TasasInteres SET DescTasa=@pmDescTasa,TipoInteres=@pmTipoInteres,TipoPeriodo=@pmTipoPeriodo,CausaInteres=@pmCausaInteres,TipoDTF=@pmTipoDTF,DTF_EA=@pmDTF_EA,Spread_TA=@pmSpread_TA
,TasaEfectiva=@pmTasaEfectiva,OpcCompra=@pmOpcCompra,Inactivo=@pmInactivo
 WHERE IdTasa=@pmIdTasa
GO
/****** Object:  StoredProcedure [dbo].[paUpTasasIntmora]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTasasIntmora] @pmIdMora VARCHAR(4),@pmDescMora VARCHAR(50),@pmTipoInteres VARCHAR(10)
,@pmTasaEA DECIMAL(14,4),@pmTasaEM DECIMAL(14,4),@pmDiasGracia INT,@pmInactivo BIT
 AS 
 UPDATE TasasIntmora SET DescMora=@pmDescMora,TipoInteres=@pmTipoInteres,TasaEA=@pmTasaEA,TasaEM=@pmTasaEM,DiasGracia=@pmDiasGracia,Inactivo=@pmInactivo
 WHERE IdMora=@pmIdMora
GO
/****** Object:  StoredProcedure [dbo].[paUpTaxRutas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTaxRutas] @pmIdRuta VARCHAR(4),@pmNomRuta VARCHAR(100),@pmTipoRuta VARCHAR(10),@pmTarifPago MONEY
,@pmTarifCobro MONEY,@pmOrigen VARCHAR(30),@pmDestino VARCHAR(30),@pmCodRuta VARCHAR(20),@pmInactivo BIT
 AS 
 UPDATE TaxRutas SET NomRuta=@pmNomRuta,TipoRuta=@pmTipoRuta,TarifPago=@pmTarifPago,TarifCobro=@pmTarifCobro,Origen=@pmOrigen
,Destino=@pmDestino,CodRuta=@pmCodRuta,Inactivo=@pmInactivo
 WHERE IdRuta=@pmIdRuta
GO
/****** Object:  StoredProcedure [dbo].[paUpTaxTarifas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTaxTarifas] @pmTipoTarif VARCHAR(10),@pmItem INT,@pmTipoHora INT,@pmNumInicial DECIMAL(14,4)
,@pmNumFinal DECIMAL(14,4),@pmTarifPago MONEY,@pmTarifCobro MONEY
 AS 
 UPDATE TaxTarifas SET TipoHora=@pmTipoHora,NumInicial=@pmNumInicial,NumFinal=@pmNumFinal,TarifPago=@pmTarifPago,TarifCobro=@pmTarifCobro
 WHERE TipoTarif=@pmTipoTarif AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTaxTarifClie]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTaxTarifClie] @pmTipoTarif VARCHAR(10),@pmItem INT,@pmIdClie VARCHAR(16),@pmTipoHora INT,@pmIdRuta VARCHAR(4),@pmNumInicial DECIMAL(14,4)
,@pmNumFinal DECIMAL(14,4),@pmTarifPago MONEY,@pmTarifCobro MONEY
 AS 
 UPDATE TaxTarifClie SET IdClie=@pmIdClie,TipoHora=@pmTipoHora,IdRuta=@pmIdRuta,NumInicial=@pmNumInicial,NumFinal=@pmNumFinal,TarifPago=@pmTarifPago,TarifCobro=@pmTarifCobro
 WHERE TipoTarif=@pmTipoTarif AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieGarant]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercClieGarant] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4),@pmItem INT,@pmTipoGarant VARCHAR(20),@pmCdInmueble VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmVrGarant MONEY,@pmVrAvaluo MONEY,@pmPropietario VARCHAR(250),@pmDirInmueble VARCHAR(250),@pmCdCiudad VARCHAR(8),@pmMatricula VARCHAR(50),@pmEscritura VARCHAR(50),@pmNumNotaria VARCHAR(20),@pmMarcaVeh VARCHAR(20),@pmModelo VARCHAR(4),@pmCdBanco VARCHAR(4),@pmFecCheque SMALLDATETIME,@pmNumCheque VARCHAR(20)
,@pmOtroTipoVehic VARCHAR(50),@pmOtroInmueble VARCHAR(50),@pmCedFmnte1 VARCHAR(16),@pmNomFmnte1 VARCHAR(150),@pmCedFmnte2 VARCHAR(16),@pmNomFmnte2 VARCHAR(150),@pmCedFmnte3 VARCHAR(16),@pmNomFmnte3 VARCHAR(150),@pmCedFmnte4 VARCHAR(16),@pmNomFmnte4 VARCHAR(150),@pmCedFmnte5 VARCHAR(16),@pmNomFmnte5 VARCHAR(150),@pmCedFmnte6 VARCHAR(16),@pmNomFmnte6 VARCHAR(150)
 AS 
 UPDATE TercClieGarant SET TipoGarant=@pmTipoGarant,CdInmueble=@pmCdInmueble,CdTipoVeh=@pmCdTipoVeh,VrGarant=@pmVrGarant,VrAvaluo=@pmVrAvaluo,Propietario=@pmPropietario,DirInmueble=@pmDirInmueble,CdCiudad=@pmCdCiudad,Matricula=@pmMatricula,Escritura=@pmEscritura,NumNotaria=@pmNumNotaria,MarcaVeh=@pmMarcaVeh,Modelo=@pmModelo,CdBanco=@pmCdBanco,FecCheque=@pmFecCheque,NumCheque=@pmNumCheque,OtroTipoVehic=@pmOtroTipoVehic,OtroInmueble=@pmOtroInmueble
,CedFmnte1=@pmCedFmnte1,NomFmnte1=@pmNomFmnte1,CedFmnte2=@pmCedFmnte2,NomFmnte2=@pmNomFmnte2,CedFmnte3=@pmCedFmnte3,NomFmnte3=@pmNomFmnte3,CedFmnte4=@pmCedFmnte4,NomFmnte4=@pmNomFmnte4,CedFmnte5=@pmCedFmnte5,NomFmnte5=@pmNomFmnte5,CedFmnte6=@pmCedFmnte6,NomFmnte6=@pmNomFmnte6
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia AND IdLinea=@pmIdLinea AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieLineas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercClieLineas] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdLinea VARCHAR(4),@pmIdTasa VARCHAR(4),@pmnPlazo INT,@pmTipoPlazo CHAR(1),@pmCupoCredito MONEY,@pmSaldoCapital MONEY,@pmSaldoInteres MONEY,@pmMaxCupoSmlv DECIMAL(14,4),@pmTipoCausac VARCHAR(10),@pmDiasVence VARCHAR(20)
,@pmFecPreAprob SMALLDATETIME,@pmPlazoAprob INT,@pmEtdoAprob INT,@pmTipoAprob VARCHAR(20),@pmDescAprob VARCHAR(250),@pmGarantias BIT,@pmTipoGarantia VARCHAR(10),@pmDescGarantia VARCHAR(250),@pmVrGarantia MONEY,@pmReqCheques BIT,@pmFecActCupo SMALLDATETIME,@pmEstadoAct INT,@pmLiqSeguro BIT
,@pmCdTasaConv VARCHAR(4),@pmNitConvenio VARCHAR(16),@pmCuotasConv INT,@pmCdTarifSeguro VARCHAR(4),@pmTasaIntLinea BIT,@pmFechaAct SMALLDATETIME
 AS 
 UPDATE TercClieLineas SET IdTasa=@pmIdTasa,nPlazo=@pmnPlazo,TipoPlazo=@pmTipoPlazo,CupoCredito=@pmCupoCredito,SaldoCapital=@pmSaldoCapital,SaldoInteres=@pmSaldoInteres,MaxCupoSmlv=@pmMaxCupoSmlv,TipoCausac=@pmTipoCausac,DiasVence=@pmDiasVence,FecPreAprob=@pmFecPreAprob,PlazoAprob=@pmPlazoAprob,EtdoAprob=@pmEtdoAprob
,TipoAprob=@pmTipoAprob,DescAprob=@pmDescAprob,Garantias=@pmGarantias,TipoGarantia=@pmTipoGarantia,DescGarantia=@pmDescGarantia,VrGarantia=@pmVrGarantia,ReqCheques=@pmReqCheques,FecActCupo=@pmFecActCupo,EstadoAct=@pmEstadoAct,LiqSeguro=@pmLiqSeguro,CdTasaConv=@pmCdTasaConv
,NitConvenio=@pmNitConvenio,CuotasConv=@pmCuotasConv,FechaAct=@pmFechaAct,CdTarifSeguro=@pmCdTarifSeguro,TasaIntLinea=@pmTasaIntLinea
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia AND IdLinea=@pmIdLinea
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCliente]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCliente] @pmIdClie VARCHAR(16),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100)
,@pmCargContac VARCHAR(50),@pmDirEnv VARCHAR(250),@pmIdLocEnv VARCHAR(8),@pmDiasEntga INT,@pmIdSzona VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4),@pmIdEstrato VARCHAR(4)
,@pmIdVend VARCHAR(16),@pmNitFact VARCHAR(16),@pmIdRuta VARCHAR(4),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmCdRet VARCHAR(4)
,@pmCdRiv VARCHAR(4),@pmCdCms VARCHAR(4),@pmExcIva BIT,@pmTrfIntMora DECIMAL(14,4),@pmDiasGracia INT,@pmLiqFletes BIT,@pmFactSold BIT,@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT,@pmIncIca BIT,@pmFactTipo INT,@pmVrCupo MONEY
,@pmVrSaldo MONEY,@pmUidClie VARCHAR(16),@pmPwdClie VARCHAR(10),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmMatMerc VARCHAR(20),@pmFecMat SMALLDATETIME
,@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmCmntario1 VARCHAR(250),@pmCmntario2 VARCHAR(250),@pmPlazosImp VARCHAR(20),@pmCdBandera VARCHAR(4),@pmContrato BIT,@pmNContrato INT,@pmCiaContMay CHAR(2)
,@pmCmntario3 VARCHAR(250),@pmPrendGarant VARCHAR(150),@pmFecUpCupo SMALLDATETIME,@pmTipoCliente VARCHAR(10),@pmRestric_Cia BIT,@pmCupoGalones DECIMAL(14,4)
,@pmCdPlazoComb VARCHAR(4),@pmCodClieSicom VARCHAR(20),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFecPlazoDoc SMALLDATETIME,@pmEdoRadicaDoc INT,@pmCdTipBloq VARCHAR(4),@pmDescEdoDoc VARCHAR(250),@pmComIndustrial INT
,@pmNumLista CHAR(1),@pmTermicas BIT,@pmCodRetCom VARCHAR(4),@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16),@pmCdDiaEnt VARCHAR(4),@pmAutoIca BIT,@pmExcImpBACU BIT,@pmTipoFMR INT,@pmFechaUpdate SMALLDATETIME 
 AS 
 UPDATE TercCliente SET NitRepLeg=@pmNitRepLeg,NomRepLeg=@pmNomRepLeg,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargContac=@pmCargContac,DirEnv=@pmDirEnv,IdLocEnv=@pmIdLocEnv
,DiasEntga=@pmDiasEntga,IdSzona=@pmIdSzona,IdGrupo=@pmIdGrupo,IdPlazo=@pmIdPlazo,IdForma=@pmIdForma,IdEstrato=@pmIdEstrato,IdVend=@pmIdVend,NitFact=@pmNitFact,IdRuta=@pmIdRuta,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco
,CdMney=@pmCdMney,CdDct=@pmCdDct,CdRet=@pmCdRet,CdRiv=@pmCdRiv,CdCms=@pmCdCms,ExcIva=@pmExcIva,TrfIntMora=@pmTrfIntMora,DiasGracia=@pmDiasGracia,LiqFletes=@pmLiqFletes,FactSold=@pmFactSold,Autoret=@pmAutoret,IncRet=@pmIncRet,IncRiv=@pmIncRiv
,IncIca=@pmIncIca,FactTipo=@pmFactTipo,VrCupo=@pmVrCupo,VrSaldo=@pmVrSaldo,UidClie=@pmUidClie,PwdClie=@pmPwdClie,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,MatMerc=@pmMatMerc,FecMat=@pmFecMat,PathFoto=@pmPathFoto
,PathFirma=@pmPathFirma,Cmntario1=@pmCmntario1,Cmntario2=@pmCmntario2,PlazosImp=@pmPlazosImp,CdBandera=@pmCdBandera,Contrato=@pmContrato,NContrato=@pmNContrato,CiaContMay=@pmCiaContMay,Cmntario3=@pmCmntario3,PrendGarant=@pmPrendGarant,FecUpCupo=@pmFecUpCupo
,CdPlazoComb=@pmCdPlazoComb,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,TipoCliente=@pmTipoCliente,FechaUpdate=@pmFechaUpdate,Restric_Cia=@pmRestric_Cia,CupoGalones=@pmCupoGalones,CodClieSicom=@pmCodClieSicom,FecPlazoDoc=@pmFecPlazoDoc,EdoRadicaDoc=@pmEdoRadicaDoc
,CdTipBloq=@pmCdTipBloq,DescEdoDoc=@pmDescEdoDoc,ComIndustrial=@pmComIndustrial,NumLista=@pmNumLista,Termicas=@pmTermicas,CodRetCom=@pmCodRetCom,CodCCosto=@pmCodCCosto,CodSubCosto=@pmCodSubCosto,CdDiaEnt=@pmCdDiaEnt,AutoIca=@pmAutoIca,ExcImpBACU=@pmExcImpBACU,TipoFMR=@pmTipoFMR
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClienteCon] @pmIdClie VARCHAR(16),@pmContrato BIT,@pmNContrato INT
,@pmCiaContMay CHAR(2),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercCliente SET Contrato=@pmContrato,NContrato=@pmNContrato
,CiaContMay=@pmCiaContMay,FechaUpdate=@pmFechaUpdate
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteCre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClienteCre]  @pmIdClie VARCHAR(16),@pmFecUpCupo SMALLDATETIME
AS 
 UPDATE TercCliente SET FecUpCupo=@pmFecUpCupo,VrCupo=(SELECT ISNULL(SUM(VrCupoCre),0) FROM Agencias
 WHERE IdClie=@pmIdClie  AND  Inactivo=0)
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClienteEst] @pmIdClie VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmCmntario1 VARCHAR(250),@pmFechaUpdate SMALLDATETIME 
 AS 
 UPDATE TercCliente SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo,Cmntario1=@pmCmntario1
,FechaUpdate=@pmFechaUpdate
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClienteSdo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClienteSdo] @pmIdClie VARCHAR(16),@pmVrSaldo MONEY
 AS 
 UPDATE TercCliente SET VrSaldo=@pmVrSaldo
 WHERE IdClie=@pmIdClie
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCliePreRef]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCliePreRef] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmItem INT,@pmTipoRef VARCHAR(10),@pmReferencia VARCHAR(150),@pmNitRefncia VARCHAR(16)
,@pmDirRefncia VARCHAR(150),@pmTelRefncia VARCHAR(30),@pmemlRefncia VARCHAR(100),@pmCargRefncia VARCHAR(50),@pmNumCuenta VARCHAR(30),@pmObservcion VARCHAR(250)
,@pmParentesco VARCHAR(10),@pmFechaNac SMALLDATETIME,@pmEdad INT,@pmBenSolidario BIT
 AS 
 UPDATE TercCliePreRef SET TipoRef=@pmTipoRef,Referencia=@pmReferencia,NitRefncia=@pmNitRefncia,DirRefncia=@pmDirRefncia,TelRefncia=@pmTelRefncia,emlRefncia=@pmemlRefncia
,CargRefncia=@pmCargRefncia,NumCuenta=@pmNumCuenta,Observcion=@pmObservcion,Parentesco=@pmParentesco,FechaNac=@pmFechaNac,Edad=@pmEdad,BenSolidario=@pmBenSolidario
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCliePrestamo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCliePrestamo] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50)
,@pmIdSzona VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmIdTipoTerc VARCHAR(4),@pmIdVend VARCHAR(16),@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmEsExento BIT,@pmCalcIntMora BIT,@pmDiasGracia INT,@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME
,@pmFecRetiro SMALLDATETIME,@pmVrSalBasico MONEY,@pmMaxDcto DECIMAL(14,4),@pmMatMerc VARCHAR(20),@pmFecMat SMALLDATETIME,@pmNomAgencia VARCHAR(150),@pmDirAgencia VARCHAR(250),@pmIdLocalAge VARCHAR(8),@pmComentarios VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTipoSalario CHAR(1)
,@pmNumTarj VARCHAR(30),@pmPwdTarj VARCHAR(30),@pmFecVenceTc SMALLDATETIME,@pmIncRetFte BIT,@pmFechaImp SMALLDATETIME,@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16)
,@pmFecNacmto SMALLDATETIME,@pmNacionalidad VARCHAR(50),@pmSexo CHAR(1),@pmCdEstCivil VARCHAR(4),@pmNumPerCargo INT,@pmNivelEduc VARCHAR(4),@pmTipoVivienda VARCHAR(10),@pmEstratoSocial INT,@pmIdOcupac VARCHAR(4),@pmVrPension MONEY,@pmVrOtrosDev MONEY
,@pmVrPasivo MONEY,@pmVrPatrimonio MONEY,@pmEmpresaLab VARCHAR(150),@pmFecIngLab SMALLDATETIME,@pmTelEmpresa VARCHAR(20),@pmDirEmpresa VARCHAR(250),@pmEmailEmpresa VARCHAR(100),@pmBaseAportes MONEY,@pmCdTarifApo VARCHAR(4),@pmVrAportes MONEY,@pmFecInicioApo SMALLDATETIME,@pmFecFinalApo SMALLDATETIME
,@pmDiaCausacApo VARCHAR(150),@pmFecRetiroApo SMALLDATETIME,@pmCausalRetiro VARCHAR(250),@pmSinDctoNom BIT,@pmSinLiqAporte BIT,@pmCabFamilia BIT,@pmDebitoAuto VARCHAR(20),@pmVrActivos MONEY,@pmFechaAct SMALLDATETIME
 AS 
 UPDATE TercCliePrestamo SET NitRepLeg=@pmNitRepLeg,NomRepLeg=@pmNomRepLeg,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargContac=@pmCargContac,IdSzona=@pmIdSzona,IdGrupo=@pmIdGrupo,IdTipoTerc=@pmIdTipoTerc,IdVend=@pmIdVend
,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,EsExento=@pmEsExento,CalcIntMora=@pmCalcIntMora,DiasGracia=@pmDiasGracia,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,VrSalBasico=@pmVrSalBasico,MaxDcto=@pmMaxDcto,MatMerc=@pmMatMerc,FecMat=@pmFecMat
,Comentarios=@pmComentarios,IdEstado=@pmIdEstado,NomAgencia=@pmNomAgencia,DirAgencia=@pmDirAgencia,IdLocalAge=@pmIdLocalAge,Inactivo=@pmInactivo,FechaAct=@pmFechaAct,TipoSalario=@pmTipoSalario,NumTarj=@pmNumTarj,PwdTarj=@pmPwdTarj,FecVenceTc=@pmFecVenceTc
,IncRetFte=@pmIncRetFte,FechaImp=@pmFechaImp,CodCCosto=@pmCodCCosto,CodSubCosto=@pmCodSubCosto
,FecNacmto=@pmFecNacmto,Nacionalidad=@pmNacionalidad,Sexo=@pmSexo,CdEstCivil=@pmCdEstCivil,NumPerCargo=@pmNumPerCargo,NivelEduc=@pmNivelEduc,TipoVivienda=@pmTipoVivienda,EstratoSocial=@pmEstratoSocial,IdOcupac=@pmIdOcupac,VrPension=@pmVrPension,VrOtrosDev=@pmVrOtrosDev,VrPasivo=@pmVrPasivo
,VrPatrimonio=@pmVrPatrimonio,EmpresaLab=@pmEmpresaLab,FecIngLab=@pmFecIngLab,TelEmpresa=@pmTelEmpresa,DirEmpresa=@pmDirEmpresa,EmailEmpresa=@pmEmailEmpresa,BaseAportes=@pmBaseAportes,CdTarifApo=@pmCdTarifApo,VrAportes=@pmVrAportes,FecInicioApo=@pmFecInicioApo,FecFinalApo=@pmFecFinalApo
,DiaCausacApo=@pmDiaCausacApo,FecRetiroApo=@pmFecRetiroApo,CausalRetiro=@pmCausalRetiro,SinDctoNom=@pmSinDctoNom,SinLiqAporte=@pmSinLiqAporte,CabFamilia=@pmCabFamilia,DebitoAuto=@pmDebitoAuto,VrActivos=@pmVrActivos
 WHERE IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieRef]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClieRef] @pmIdClie VARCHAR(16),@pmItem INT,@pmTipoRef VARCHAR(10),@pmReferencia VARCHAR(150)
,@pmNitRefncia VARCHAR(16),@pmDirRefncia VARCHAR(150),@pmTelRefncia VARCHAR(30),@pmemlRefncia VARCHAR(100)
,@pmCargRefncia VARCHAR(50),@pmNumCuenta VARCHAR(30),@pmObservcion VARCHAR(250)
 AS 
 UPDATE TercClieRef SET TipoRef=@pmTipoRef,Referencia=@pmReferencia,NitRefncia=@pmNitRefncia,DirRefncia=@pmDirRefncia
,TelRefncia=@pmTelRefncia,emlRefncia=@pmemlRefncia,CargRefncia=@pmCargRefncia,NumCuenta=@pmNumCuenta,Observcion=@pmObservcion
 WHERE IdClie=@pmIdClie AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieSaldos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercClieSaldos] @pmIdClie VARCHAR(16),@pmCdAgencia VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 UPDATE TercClieSaldos SET VrSaldo=@pmVrSaldo
 WHERE IdClie=@pmIdClie AND CdAgencia=@pmCdAgencia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieSaldosAcu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClieSaldosAcu] @pmIdClie VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmUpClie BIT=Null,@pmUpAge BIT=Null
 AS 
 IF EXISTS(SELECT * FROM tempdb..sysobjects WHERE NAME LIKE '#ClieSaldos%') 
 DROP TABLE #ClieSaldos
 CREATE TABLE #ClieSaldos (tmId INT PRIMARY KEY IDENTITY (1,1)
 ,IdClie VARCHAR(16),CdAgencia VARCHAR(16),IdCia CHAR(2),VrFacturas MONEY,VrAbonos MONEY,VrAFavor MONEY,VrAbonoSAF MONEY)
--facturas y vencimientos
 INSERT INTO #ClieSaldos (IdClie,CdAgencia,IdCia,VrFacturas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,SUM(VrFactura),0,0,0
 FROM Trn_Vencimientos
 WHERE IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia
--abonos de facturas
 INSERT INTO #ClieSaldos (IdClie,CdAgencia,IdCia,VrFacturas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,0,SUM(VrAbono),0,0
 FROM Trn_VencAbonos
 WHERE IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia
--recibos a favor
 INSERT INTO #ClieSaldos (IdClie,CdAgencia,IdCia,VrFacturas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,0,0,SUM(VrAFavor-VrOtrosDb),0
 FROM Trn_RecAfavor
 WHERE IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia
 --abonos de saldos a favor
 INSERT INTO #ClieSaldos (IdClie,CdAgencia,IdCia,VrFacturas,VrAbonos,VrAFavor,VrAbonoSAF) 
 SELECT IdCliente,IdAgencia,IdCia,0,0,0,SUM(VrAbono)
 FROM Trn_VencAbonos
 WHERE TipoAplica='ANTICIPO' AND IdCliente LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 GROUP BY  IdCliente,IdAgencia,IdCia 
 --actualiza saldos
 DECLARE @TrnNombre VARCHAR(20)
 SET @TrnNombre = 'TrnSaldos'
 BEGIN TRANSACTION @TrnNombre
 DELETE FROM TercClieSaldos WHERE IdClie LIKE ISNULL(@pmIdClie,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
 INSERT INTO TercClieSaldos (IdClie,CdAgencia,IdCia,VrSaldo)
 SELECT IdClie,CdAgencia,IdCia,SUM((VrFacturas-VrAbonos)-(VrAFavor-VrAbonoSAF)) 
 FROM #ClieSaldos
 GROUP BY IdClie,CdAgencia,IdCia
 COMMIT TRANSACTION  @TrnNombre
--DROP TABLE #ClieSaldos
IF @pmUpClie=1  
 BEGIN 
 UPDATE TercCliente SET VrSaldo=(SELECT ISNULL(SUM(VrSaldo),0) FROM TercClieSaldos
 WHERE TercClieSaldos.IdClie=TercCliente.IdClie)
 WHERE  IdClie LIKE ISNULL(@pmIdClie,'%') 
 END
IF @pmUpAge=1
 BEGIN
 UPDATE Agencias SET VrSaldoAct=(SELECT ISNULL(SUM(VrSaldo),0) FROM TercClieSaldos
 WHERE TercClieSaldos.IdClie=Agencias.IdClie AND TercClieSaldos.CdAgencia=Agencias.IdAgencia)
 WHERE  IdClie LIKE ISNULL(@pmIdClie,'%')  
 END
GO
/****** Object:  StoredProcedure [dbo].[paUpTercClieVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercClieVeh] @pmIdClie VARCHAR(16),@pmpVehiculo VARCHAR(10)
,@pmCdConductor VARCHAR(16),@pmNumVehiculo VARCHAR(10),@pmDescripcion VARCHAR(100)
 AS 
 UPDATE TercClieVeh SET CdConductor=@pmCdConductor,NumVehiculo=@pmNumVehiculo,Descripcion=@pmDescripcion
 WHERE IdClie=@pmIdClie AND pVehiculo=@pmpVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndContrato]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCndContrato] @pmNumContrato INT,@pmIdConductor VARCHAR(16),@pmIdTipCon VARCHAR(4),@pmIdModd VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME
,@pmFecVigencia SMALLDATETIME,@pmObservaciones VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE TercCndContrato SET IdConductor=@pmIdConductor,IdTipCon=@pmIdTipCon,IdModd=@pmIdModd,FecIngreso=@pmFecIngreso,FecRetiro=@pmFecRetiro,FecVigencia=@pmFecVigencia,Observaciones=@pmObservaciones,FecUpdate=@pmFecUpdate
 WHERE NumContrato=@pmNumContrato
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndReferencias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCndReferencias] @pmIdConductor VARCHAR(16),@pmItem INT,@pmTipoRef VARCHAR(10),@pmEmpresaRef VARCHAR(150),@pmNitRef VARCHAR(16),@pmDireccionRef VARCHAR(150),@pmTelefonoRef VARCHAR(30),@pmContactoRef VARCHAR(150)
,@pmEmailRef VARCHAR(100),@pmCargoRef VARCHAR(50),@pmCuentaBanco VARCHAR(30),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmVerificado VARCHAR(150),@pmObservRef VARCHAR(250)
 AS 
 UPDATE TercCndReferencias SET TipoRef=@pmTipoRef,EmpresaRef=@pmEmpresaRef,NitRef=@pmNitRef,DireccionRef=@pmDireccionRef,TelefonoRef=@pmTelefonoRef,ContactoRef=@pmContactoRef,EmailRef=@pmEmailRef,CargoRef=@pmCargoRef,CuentaBanco=@pmCuentaBanco
,FechaInicial=@pmFechaInicial,FechaFinal=@pmFechaFinal,Verificado=@pmVerificado,ObservRef=@pmObservRef
 WHERE IdConductor=@pmIdConductor AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndTarjetas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCndTarjetas] @pmIdConductor VARCHAR(16),@pmItem INT,@pmNumeroTarj VARCHAR(30)
,@pmSecuencia INT,@pmFecha SMALLDATETIME,@pmFecVence SMALLDATETIME
 AS 
 UPDATE TercCndTarjetas SET NumeroTarj=@pmNumeroTarj,Secuencia=@pmSecuencia,Fecha=@pmFecha,FecVence=@pmFecVence
 WHERE IdConductor=@pmIdConductor AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtores]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCndtores] @pmIdConductor VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmIdModd VARCHAR(4),@pmTipoSangre CHAR(2),@pmFactorRh CHAR(1),@pmLibMilitar VARCHAR(25),@pmClaseLib INT,@pmFechaLib SMALLDATETIME,@pmDistMil VARCHAR(10),@pmCertJudicial VARCHAR(25)
,@pmFecJudicial SMALLDATETIME,@pmVigJudicial SMALLDATETIME,@pmLicencia VARCHAR(25),@pmIdLugar VARCHAR(8),@pmCatLicencia INT,@pmFecLicencia SMALLDATETIME,@pmVigLicencia SMALLDATETIME
,@pmFecNacmto SMALLDATETIME,@pmLugarNacmto VARCHAR(30),@pmSexo CHAR(1),@pmIdEstCivil VARCHAR(4),@pmNHijos INT,@pmPasporte VARCHAR(25),@pmVigPaspte SMALLDATETIME,@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4)
,@pmCdLocCue VARCHAR(8),@pmCdFonPen VARCHAR(8),@pmCdFonEps VARCHAR(8),@pmCdFonArp VARCHAR(8),@pmpVehiculo VARCHAR(10),@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmPathLic VARCHAR(30),@pmCmntarios VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmNumTarjeta VARCHAR(30),@pmEdicTarjeta INT,@pmFecTarjeta SMALLDATETIME,@pmVigTarjeta SMALLDATETIME,@pmPasSeguridad VARCHAR(30),@pmFecPasSeg SMALLDATETIME,@pmVigPasSeg SMALLDATETIME,@pmNitEmpTrans VARCHAR(16),@pmFechaUpdate SMALLDATETIME
,@pmNum_Contrato INT,@pmContrato_Activo BIT,@pmCdTipCon VARCHAR(4),@pmFec_Ingreso SMALLDATETIME,@pmFec_Retiro SMALLDATETIME,@pmFec_Vigencia SMALLDATETIME,@pmFec_IngresoAnt SMALLDATETIME,@pmFec_UltimoAcc SMALLDATETIME
,@pmPasadoJudicial VARCHAR(250),@pmRestriccion VARCHAR(50),@pmFecPagoPen SMALLDATETIME,@pmFecPagoEps SMALLDATETIME,@pmFecPagoArp SMALLDATETIME,@pmCdTipoOper VARCHAR(4)
 AS 
 UPDATE TercCndtores SET IdGrupo=@pmIdGrupo,IdModd=@pmIdModd,TipoSangre=@pmTipoSangre,FactorRh=@pmFactorRh,LibMilitar=@pmLibMilitar,ClaseLib=@pmClaseLib,FechaLib=@pmFechaLib,DistMil=@pmDistMil,CertJudicial=@pmCertJudicial,FecJudicial=@pmFecJudicial,VigJudicial=@pmVigJudicial
,Licencia=@pmLicencia,IdLugar=@pmIdLugar,CatLicencia=@pmCatLicencia,FecLicencia=@pmFecLicencia,VigLicencia=@pmVigLicencia,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,CdLocCue=@pmCdLocCue,CdFonPen=@pmCdFonPen,CdFonEps=@pmCdFonEps
,CdFonArp=@pmCdFonArp,FecNacmto=@pmFecNacmto,LugarNacmto=@pmLugarNacmto,Sexo=@pmSexo,IdEstCivil=@pmIdEstCivil,NHijos=@pmNHijos,Pasporte=@pmPasporte,VigPaspte=@pmVigPaspte,pVehiculo=@pmpVehiculo,PathFoto=@pmPathFoto,PathFirma=@pmPathFirma
,PathLic=@pmPathLic,Cmntarios=@pmCmntarios,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,NumTarjeta=@pmNumTarjeta,EdicTarjeta=@pmEdicTarjeta,FecTarjeta=@pmFecTarjeta,VigTarjeta=@pmVigTarjeta,PasSeguridad=@pmPasSeguridad,FecPasSeg=@pmFecPasSeg,VigPasSeg=@pmVigPasSeg
,NitEmpTrans=@pmNitEmpTrans,FechaUpdate=@pmFechaUpdate,Num_Contrato=@pmNum_Contrato,Contrato_Activo=@pmContrato_Activo,CdTipCon=@pmCdTipCon,Fec_Ingreso=@pmFec_Ingreso,Fec_Retiro=@pmFec_Retiro,Fec_Vigencia=@pmFec_Vigencia,Fec_IngresoAnt=@pmFec_IngresoAnt
,Fec_UltimoAcc=@pmFec_UltimoAcc,PasadoJudicial=@pmPasadoJudicial,Restriccion=@pmRestriccion,FecPagoPen=@pmFecPagoPen,FecPagoEps=@pmFecPagoEps,FecPagoArp=@pmFecPagoArp,CdTipoOper=@pmCdTipoOper
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresCon] @pmIdConductor VARCHAR(16),@pmNum_Contrato INT,@pmContrato_Activo BIT,@pmCdTipCon VARCHAR(4)
,@pmFec_Ingreso SMALLDATETIME,@pmFec_Retiro SMALLDATETIME,@pmFec_Vigencia SMALLDATETIME,@pmIdModd VARCHAR(4)
 AS 
 UPDATE TercCndtores SET IdModd=@pmIdModd,Contrato_Activo=@pmContrato_Activo,CdTipCon=@pmCdTipCon
,Fec_Ingreso=@pmFec_Ingreso,Fec_Retiro=@pmFec_Retiro,Fec_Vigencia=@pmFec_Vigencia
 WHERE IdConductor=@pmIdConductor AND Num_Contrato=@pmNum_Contrato
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresCont]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresCont] @pmIdConductor VARCHAR(16),@pmNum_Contrato INT,@pmContrato_Activo BIT,@pmCdTipCon VARCHAR(4)
,@pmFec_Ingreso SMALLDATETIME,@pmFec_Retiro SMALLDATETIME,@pmFec_Vigencia SMALLDATETIME,@pmIdModd VARCHAR(4)
 AS 
 UPDATE TercCndtores SET Num_Contrato=@pmNum_Contrato,IdModd=@pmIdModd,Contrato_Activo=@pmContrato_Activo,CdTipCon=@pmCdTipCon
,Fec_Ingreso=@pmFec_Ingreso,Fec_Retiro=@pmFec_Retiro,Fec_Vigencia=@pmFec_Vigencia
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresEst] @pmIdConductor VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmCmntarios VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercCndtores SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Cmntarios=@pmCmntarios,FechaUpdate=@pmFechaUpdate
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresFtar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresFtar] @pmIdConductor VARCHAR(16),@pmNumTarjeta VARCHAR(30)
,@pmFecTarjeta SMALLDATETIME,@pmVigTarjeta SMALLDATETIME
 AS 
 UPDATE TercCndtores SET FecTarjeta=@pmFecTarjeta,VigTarjeta=@pmVigTarjeta
 WHERE IdConductor=@pmIdConductor AND NumTarjeta LIKE ISNULL(@pmNumTarjeta,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresRet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresRet] @pmIdConductor VARCHAR(16),@pmNum_Contrato INT,@pmContrato_Activo BIT
,@pmFec_Retiro SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCmntarios VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercCndtores SET Num_Contrato=@pmNum_Contrato,Contrato_Activo=@pmContrato_Activo,Fec_Retiro=@pmFec_Retiro,IdEstado=@pmIdEstado
,Inactivo=@pmInactivo,Cmntarios=@pmCmntarios,FechaUpdate=@pmFechaUpdate
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresTar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresTar] @pmIdConductor VARCHAR(16),@pmNumTarjeta VARCHAR(30),@pmEdicTarjeta INT
,@pmFecTarjeta SMALLDATETIME,@pmVigTarjeta SMALLDATETIME
 AS 
 UPDATE TercCndtores SET NumTarjeta=@pmNumTarjeta,FecTarjeta=@pmFecTarjeta,VigTarjeta=@pmVigTarjeta
,EdicTarjeta=ISNULL(@pmEdicTarjeta,EdicTarjeta)
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paUpTercCndtoresVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercCndtoresVeh] @pmIdConductor VARCHAR(16),@pmpVehiculo VARCHAR(10),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercCndtores SET pVehiculo=@pmpVehiculo,FechaUpdate=@pmFechaUpdate
 WHERE IdConductor=@pmIdConductor
GO
/****** Object:  StoredProcedure [dbo].[paUpTerceros]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTerceros] @pmIdTercero VARCHAR(16),@pmRazonSocial VARCHAR(250),@pmCodigo VARCHAR(16),@pmTipoId CHAR(1),@pmDv CHAR(1),@pmDireccion VARCHAR(250),@pmIdLocal VARCHAR(8)
,@pmTelefono VARCHAR(20),@pmFax VARCHAR(20),@pmTelMovil VARCHAR(20),@pmSitioWeb VARCHAR(100),@pme_mail VARCHAR(100),@pmEsCliente BIT,@pmEsVendedor BIT,@pmEsConductor BIT
,@pmEsPropietario BIT,@pmEsProveedor BIT,@pmEsEmpleado BIT,@pmEsOperario BIT,@pmEsAccnista BIT,@pmEsCiaAseg BIT,@pmIdSector VARCHAR(8),@pmIdRegimen VARCHAR(4),@pmIdLugarCed VARCHAR(8),@pmObservacion VARCHAR(250)
,@pmIniStgNom INT,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmNomCial VARCHAR(250),@pmSiglaRaz VARCHAR(50),@pmIdProf VARCHAR(4),@pmTipEnte CHAR(1),@pmFecExpCed SMALLDATETIME,@pmEsCliePres BIT,@pmImgFoto VARCHAR(30),@pmImgFirma VARCHAR(30)
,@pmImagenDoc1 VARCHAR(50),@pmImagenDoc2 VARCHAR(50),@pmImagenDoc3 VARCHAR(50),@pmFechaNac SMALLDATETIME,@pmIdEstOper VARCHAR(4),@pmIdLocUbic VARCHAR(8),@pmDescUbicac VARCHAR(150),@pmCdGrupoTerc VARCHAR(4),@pmRegimenFE BIT,@pmPN_RUT BIT
,@pmRecPublicos BIT,@pmCargoPublico VARCHAR(50),@pmFecInicioCP SMALLDATETIME,@pmFecFinalCp SMALLDATETIME,@pmPersonaPub BIT,@pmCargoPersPub VARCHAR(50),@pmFecInicioPP SMALLDATETIME,@pmFecFinalPP SMALLDATETIME
,@pmVrIngresos MONEY,@pmVrOtroIng MONEY,@pmVrGastos MONEY,@pmVrActivos MONEY,@pmVrPasivos MONEY,@pmVrPatrimonio MONEY,@pmConcOtrosIng VARCHAR(250),@pmOperActVirtual BIT,@pmTipoOperVirtual VARCHAR(150),@pmLavadoActivos BIT
,@pmRL_Nombre VARCHAR(150),@pmRL_Identificacion VARCHAR(16),@pmRL_Direccion VARCHAR(250),@pmRL_CodCiudad VARCHAR(8),@pmRL_Telefono VARCHAR(20),@pmRL_Email VARCHAR(150),@pmAsociado BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Terceros SET RazonSocial=@pmRazonSocial,Codigo=@pmCodigo,TipoId=@pmTipoId,Dv=@pmDv,Direccion=@pmDireccion,IdLocal=@pmIdLocal,Telefono=@pmTelefono,Fax=@pmFax,TelMovil=@pmTelMovil,SitioWeb=@pmSitioWeb,e_mail=@pme_mail
,EsCliente=@pmEsCliente,EsVendedor=@pmEsVendedor,EsConductor=@pmEsConductor,EsPropietario=@pmEsPropietario,EsProveedor=@pmEsProveedor,EsEmpleado=@pmEsEmpleado,EsOperario=@pmEsOperario,EsAccnista=@pmEsAccnista,EsCiaAseg=@pmEsCiaAseg 
,EsCliePres=@pmEsCliePres,IdSector=@pmIdSector,IdRegimen=@pmIdRegimen,IdLugarCed=@pmIdLugarCed,Observacion=@pmObservacion,IniStgNom=@pmIniStgNom,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate
,NomCial=@pmNomCial,SiglaRaz=@pmSiglaRaz,IdProf=@pmIdProf,TipEnte=@pmTipEnte,FecExpCed=@pmFecExpCed,ImgFoto=@pmImgFoto,ImgFirma=@pmImgFirma,ImagenDoc1=@pmImagenDoc1,ImagenDoc2=@pmImagenDoc2,ImagenDoc3=@pmImagenDoc3,FechaNac=@pmFechaNac
,IdEstOper=@pmIdEstOper,IdLocUbic=@pmIdLocUbic,DescUbicac=@pmDescUbicac,CdGrupoTerc=@pmCdGrupoTerc,RegimenFE=@pmRegimenFE,PN_RUT=@pmPN_RUT
,RecPublicos=@pmRecPublicos,CargoPublico=@pmCargoPublico,FecInicioCP=@pmFecInicioCP,FecFinalCp=@pmFecFinalCp,PersonaPub=@pmPersonaPub,CargoPersPub=@pmCargoPersPub,FecInicioPP=@pmFecInicioPP,FecFinalPP=@pmFecFinalPP,VrIngresos=@pmVrIngresos
,VrOtroIng=@pmVrOtroIng,VrGastos=@pmVrGastos,VrActivos=@pmVrActivos,VrPasivos=@pmVrPasivos,VrPatrimonio=@pmVrPatrimonio,ConcOtrosIng=@pmConcOtrosIng,OperActVirtual=@pmOperActVirtual,TipoOperVirtual=@pmTipoOperVirtual,LavadoActivos=@pmLavadoActivos
,RL_Nombre=@pmRL_Nombre,RL_Identificacion=@pmRL_Identificacion,RL_Direccion=@pmRL_Direccion,RL_CodCiudad=@pmRL_CodCiudad,RL_Telefono=@pmRL_Telefono,RL_Email=@pmRL_Email,Asociado=@pmAsociado
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosCdt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercerosCdt]  @pmIdTercero VARCHAR(16),@pmEsConductor BIT
 AS 
 UPDATE Terceros SET EsConductor=@pmEsConductor
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosCli]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercerosCli] @pmIdTercero VARCHAR(16),@pmEsCliente BIT
 AS 
 UPDATE Terceros SET EsCliente=@pmEsCliente
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercerosEst] @pmIdTercero VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmObservacion VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Terceros SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo,Observacion=@pmObservacion,FechaUpdate=@pmFechaUpdate
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosPrv]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercerosPrv] @pmIdTercero VARCHAR(16),@pmEsProveedor BIT
 AS 
 UPDATE Terceros SET EsProveedor=@pmEsProveedor
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpTercerosVen]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercerosVen] @pmIdTercero VARCHAR(16),@pmEsVendedor BIT
 AS 
 UPDATE Terceros SET EsVendedor=@pmEsVendedor
 WHERE IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUpTercPropietario]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercPropietario] @pmIdPropietario VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmCupoCredito MONEY,@pmSaldoActual MONEY,@pmAvala BIT,@pmIdAdmon VARCHAR(4),@pmIdTipCon VARCHAR(4),@pmContratoActivo BIT,@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmFecVigencia SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercPropietario SET IdGrupo=@pmIdGrupo,CupoCredito=@pmCupoCredito,SaldoActual=@pmSaldoActual,Avala=@pmAvala,IdAdmon=@pmIdAdmon,IdTipCon=@pmIdTipCon
,ContratoActivo=@pmContratoActivo,FecIngreso=@pmFecIngreso,FecRetiro=@pmFecRetiro,FecVigencia=@pmFecVigencia,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,FechaUpdate=@pmFechaUpdate
 WHERE IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paUpTercPropietarioSal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercPropietarioSal] @pmIdPropietario VARCHAR(16),@pmSaldoActual MONEY
AS
 IF @pmIdPropietario IS NULL
   UPDATE TercPropietario  SET SaldoActual=@pmSaldoActual
 ELSE
  UPDATE TercPropietario  SET SaldoActual=@pmSaldoActual  WHERE  IdPropietario=@pmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paUpTercProvee]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercProvee] @pmIdProv VARCHAR(16),@pmIdGrupo VARCHAR(4),@pmNitRepLeg VARCHAR(16),@pmNomRepLeg VARCHAR(150),@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20)
,@pmemlContac VARCHAR(100),@pmCargContac VARCHAR(50),@pmDirOrdComp VARCHAR(250),@pmIdLocOrd VARCHAR(8),@pmDiasEntga INT,@pmIdPlazo VARCHAR(4),@pmIdForma VARCHAR(4),@pmCdMney VARCHAR(5),@pmCdDct VARCHAR(4),@pmIdClase VARCHAR(4)
,@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmAutoret BIT,@pmIncRet BIT,@pmIncRiv BIT,@pmIncIca BIT,@pmLiqFletes BIT,@pmCdRet VARCHAR(4),@pmCdRiv VARCHAR(4),@pmGartProd INT,@pmFecIngreso SMALLDATETIME,@pmPathFoto VARCHAR(30)
,@pmPathFirma VARCHAR(30),@pmCmntarios VARCHAR(250),@pmContrato BIT,@pmNContrato VARCHAR(20),@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmObsFinanc VARCHAR(250),@pmObsJuridica VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmCodRetCom VARCHAR(4),@pmCupoElectcom DECIMAL(14,4),@pmAutoIca BIT,@pmCodRetIca VARCHAR(4),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercProvee SET IdGrupo=@pmIdGrupo,NitRepLeg=@pmNitRepLeg,NomRepLeg=@pmNomRepLeg,NitContac=@pmNitContac,NomContac=@pmNomContac,TelContac=@pmTelContac,emlContac=@pmemlContac,CargContac=@pmCargContac,DirOrdComp=@pmDirOrdComp,IdLocOrd=@pmIdLocOrd
,DiasEntga=@pmDiasEntga,IdPlazo=@pmIdPlazo,IdForma=@pmIdForma,CdMney=@pmCdMney,CdDct=@pmCdDct,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,Autoret=@pmAutoret,IncRet=@pmIncRet,IncRiv=@pmIncRiv,IncIca=@pmIncIca,LiqFletes=@pmLiqFletes,CdRet=@pmCdRet
,CdRiv=@pmCdRiv,GartProd=@pmGartProd,FecIngreso=@pmFecIngreso,PathFoto=@pmPathFoto,PathFirma=@pmPathFirma,Cmntarios=@pmCmntarios,Contrato=@pmContrato,NContrato=@pmNContrato,FecVigencia=@pmFecVigencia,FecRetiro=@pmFecRetiro,ObsFinanc=@pmObsFinanc,ObsJuridica=@pmObsJuridica
,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,CodRetCom=@pmCodRetCom,CupoElectcom=@pmCupoElectcom,AutoIca=@pmAutoIca,CodRetIca=@pmCodRetIca,FechaUpdate=@pmFechaUpdate
 WHERE IdProv=@pmIdProv
GO
/****** Object:  StoredProcedure [dbo].[paUpTercProveeEst]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTercProveeEst] @pmIdProv VARCHAR(16),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmCmntarios VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TercProvee SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo,Cmntarios=@pmCmntarios,FechaUpdate=@pmFechaUpdate
 WHERE IdProv=@pmIdProv
GO
/****** Object:  StoredProcedure [dbo].[paUpTercVendedor]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTercVendedor] @pmIdVend VARCHAR(16),@pmIdTarCms VARCHAR(4),@pmIdTarCm2 VARCHAR(4),@pmCdJorn VARCHAR(4),@pmIdSzona VARCHAR(4)
,@pmIdGrupo VARCHAR(4),@pmPathFoto VARCHAR(30),@pmPathFirma VARCHAR(30),@pmComntarios VARCHAR(250),@pmInactivo BIT
,@pmIdClase VARCHAR(4),@pmNumCuenta VARCHAR(30),@pmIdBanco VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE TercVendedor SET IdTarCms=@pmIdTarCms,IdTarCm2=@pmIdTarCm2,CdJorn=@pmCdJorn,IdSzona=@pmIdSzona,IdGrupo=@pmIdGrupo,PathFoto=@pmPathFoto
,PathFirma=@pmPathFirma,Comntarios=@pmComntarios,Inactivo=@pmInactivo,IdClase=@pmIdClase,NumCuenta=@pmNumCuenta,IdBanco=@pmIdBanco,FecUpdate=@pmFecUpdate
 WHERE IdVend=@pmIdVend
GO
/****** Object:  StoredProcedure [dbo].[paUpTerminales]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTerminales] @pmIdTerminal VARCHAR(4),@pmTerminal VARCHAR(50),@pmIdCia CHAR(2),@pmInactivo BIT
 AS 
 UPDATE Terminales SET Terminal=@pmTerminal,IdCia=@pmIdCia,Inactivo=@pmInactivo
 WHERE IdTerminal=@pmIdTerminal
GO
/****** Object:  StoredProcedure [dbo].[paUpTFmtos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTFmtos] @pmnFormato VARCHAR(10),@pmFmtoFactura VARCHAR(50),@pmTipFac VARCHAR(3)
 AS 
 UPDATE Sys_TFmtos SET FmtoFactura=@pmFmtoFactura,TipFac=@pmTipFac
 WHERE nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposAdm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposAdm] @pmIdAdmon VARCHAR(4),@pmTipoAdmon VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposAdm SET TipoAdmon=@pmTipoAdmon,Inactivo=@pmInactivo
 WHERE IdAdmon=@pmIdAdmon
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposAgenc] @pmIdTipAgenc VARCHAR(4),@pmTipoAgencia VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposAgenc SET TipoAgencia=@pmTipoAgencia,Inactivo=@pmInactivo
 WHERE IdTipAgenc=@pmIdTipAgenc
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposBan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposBan] @pmIdBandera VARCHAR(4),@pmTipoBandera VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposBan SET TipoBandera=@pmTipoBandera,Inactivo=@pmInactivo
 WHERE IdBandera=@pmIdBandera
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposBloq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposBloq] @pmIdTipBloq VARCHAR(4),@pmTipoBloqueo VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposBloq SET TipoBloqueo=@pmTipoBloqueo,Inactivo=@pmInactivo
 WHERE IdTipBloq=@pmIdTipBloq
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposCar] @pmIdCrceria VARCHAR(4),@pmTipoCar VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposCar SET TipoCar=@pmTipoCar,Inactivo=@pmInactivo
 WHERE IdCrceria=@pmIdCrceria
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCarga]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposCarga] @pmIdTipCarga VARCHAR(4),@pmTipoCarga VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposCarga SET TipoCarga=@pmTipoCarga,Inactivo=@pmInactivo
 WHERE IdTipCarga=@pmIdTipCarga
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCnd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposCnd] @pmIdTipoCon VARCHAR(4),@pmTipoContndor VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposCnd SET TipoContndor=@pmTipoContndor,Inactivo=@pmInactivo
 WHERE IdTipoCon=@pmIdTipoCon
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCol]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposCol] @pmIdColor VARCHAR(4),@pmNomColor VARCHAR(50),@pmNColor INT,@pmCodigoMT VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE TiposCol SET NomColor=@pmNomColor,NColor=@pmNColor,CodigoMT=@pmCodigoMT,Inactivo=@pmInactivo
 WHERE IdColor=@pmIdColor
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposCom] @pmIdCom VARCHAR(3),@pmTipoCom VARCHAR(50),@pmIdDiario VARCHAR(4)
,@pmEsEgreso BIT,@pmConsUnico BIT,@pmInactivo BIT,@pmClaseNiif VARCHAR(10),@pmDoc_Soporte BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TiposCom SET TipoCom=@pmTipoCom,IdDiario=@pmIdDiario,EsEgreso=@pmEsEgreso
,ConsUnico=@pmConsUnico,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate,ClaseNiif=@pmClaseNiif,Doc_Soporte=@pmDoc_Soporte
 WHERE IdCom=@pmIdCom
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComAgenc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposComAgenc] @pmIdSubAgenc VARCHAR(4),@pmSubTipoAgenc VARCHAR(50),@pmIdTipAgenc VARCHAR(4),@pmInactivo BIT
 AS 
 UPDATE TiposComAgenc SET SubTipoAgenc=@pmSubTipoAgenc,IdTipAgenc=@pmIdTipAgenc,Inactivo=@pmInactivo
 WHERE IdSubAgenc=@pmIdSubAgenc
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComCons]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposComCons] @pmIdCom VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT,@pmNumero INT
,@pmNumManual BIT,@pmFormato VARCHAR(20),@pmConfigFecha VARCHAR(10),@pmTipoPapel INT,@pmOrientacion INT
,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmCodResol VARCHAR(4),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TiposComCons SET LDesde=@pmLDesde,LHasta=@pmLHasta,Numero=@pmNumero,NumManual=@pmNumManual
,Formato=@pmFormato,ConfigFecha=@pmConfigFecha,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion
,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,CodResol=@pmCodResol,FechaUpdate=@pmFechaUpdate
 WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComConsNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposComConsNum] @pmIdCom VARCHAR(3),@pmIdCia CHAR(2),@pmNumero INT
 AS 
 IF @pmNumero IS NULL
  UPDATE TiposComCons SET Numero=Numero+1
  WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia
 ELSE
  UPDATE TiposComCons SET Numero=@pmNumero
  WHERE IdCom=@pmIdCom AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComFmt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposComFmt] @pmIdCom VARCHAR(3),@pmIdForma CHAR(2),@pmDescripcion VARCHAR(100),@pmFormato VARCHAR(20),@pmPredtmnado BIT
,@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmsp_Nombre VARCHAR(50),@pmInd_Location VARCHAR(50)
 AS 
 UPDATE TiposComFmt SET Descripcion=@pmDescripcion,Formato=@pmFormato,Predtmnado=@pmPredtmnado,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia
,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,sp_Nombre=@pmsp_Nombre,Ind_Location=@pmInd_Location
 WHERE IdCom=@pmIdCom AND IdForma=@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComFmtPre]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposComFmtPre] @pmIdCom VARCHAR(3),@pmIdForma CHAR(2),@pmPredtmnado BIT
 AS 
 UPDATE TiposComFmt SET Predtmnado=@pmPredtmnado
 WHERE IdCom=@pmIdCom AND IdForma<>@pmIdForma
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposComRes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposComRes] @pmIdRes VARCHAR(4),@pmResolucion VARCHAR(50),@pmPrefijo VARCHAR(5),@pmNumInicial INT,@pmNumFinal INT,@pmFechaExpRes SMALLDATETIME,@pmFechaVigencia SMALLDATETIME,@pmEstablecimiento VARCHAR(100)
 AS 
 UPDATE TiposComRes SET Resolucion=@pmResolucion,Prefijo=@pmPrefijo,NumInicial=@pmNumInicial,NumFinal=@pmNumFinal,FechaExpRes=@pmFechaExpRes,FechaVigencia=@pmFechaVigencia,Establecimiento=@pmEstablecimiento
 WHERE IdRes=@pmIdRes
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCon]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposCon] @pmIdTipCon VARCHAR(4),@pmTipoContrato VARCHAR(100)
,@pmDuracion INT,@pmVincLabUgpp VARCHAR(250),@pmCodDIAN VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE TiposCon SET TipoContrato=@pmTipoContrato,Duracion=@pmDuracion,Inactivo=@pmInactivo
,VincLabUgpp=@pmVincLabUgpp,CodDIAN=@pmCodDIAN
 WHERE IdTipCon=@pmIdTipCon
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposCot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposCot] @pmIdCot VARCHAR(4),@pmCotizante VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposCot SET Cotizante=@pmCotizante,Inactivo=@pmInactivo
 WHERE IdCot=@pmIdCot
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDoc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposDoc] @pmIdDoc VARCHAR(3),@pmTipoDoc VARCHAR(50),@pmConsUnico BIT
,@pmLeyenda VARCHAR(250),@pmInactivo BIT,@pmIntegraCias BIT
 AS 
 UPDATE Sys_TiposDoc SET TipoDoc=@pmTipoDoc,ConsUnico=@pmConsUnico
,Leyenda=@pmLeyenda,Inactivo=@pmInactivo,IntegraCias=@pmIntegraCias
 WHERE IdDoc=@pmIdDoc
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDocCons]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposDocCons] @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmLDesde INT,@pmLHasta INT,@pmResolucion VARCHAR(30),@pmRangoNum VARCHAR(50),@pmFechaRes SMALLDATETIME
,@pmPrefijo VARCHAR(5),@pmNumero INT,@pmNumManual BIT,@pmIntLotes BIT,@pmConfigFecha VARCHAR(10),@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT
,@pmVerSetup BIT,@pmNumCopias INT,@pmFechaVigRes SMALLDATETIME,@pmClaveTecDian VARCHAR(250),@pmCodResol VARCHAR(4),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE TiposDocCons SET LDesde=@pmLDesde,LHasta=@pmLHasta,Resolucion=@pmResolucion,RangoNum=@pmRangoNum,FechaRes=@pmFechaRes,Prefijo=@pmPrefijo
,Numero=@pmNumero,NumManual=@pmNumManual,IntLotes=@pmIntLotes,ConfigFecha=@pmConfigFecha,Formato=@pmFormato,TipoPapel=@pmTipoPapel
,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,FechaUpdate=@pmFechaUpdate
,FechaVigRes=@pmFechaVigRes,ClaveTecDian=@pmClaveTecDian,CodResol=@pmCodResol
 WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDocConsNum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposDocConsNum] @pmIdDoc VARCHAR(3),@pmIdCia CHAR(2),@pmNumero INT
 AS 
 IF @pmNumero IS NULL
  UPDATE TiposDocCons SET Numero=Numero+1
  WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia
 ELSE
  UPDATE TiposDocCons SET Numero=@pmNumero
  WHERE IdDoc=@pmIdDoc AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposDocCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposDocCue] @pmIdDoc VARCHAR(3),@pmIdClase INT
,@pmClaseCuenta VARCHAR(50),@pmTipoMov CHAR(1)
 AS 
 UPDATE Sys_TiposDocCue SET ClaseCuenta=@pmClaseCuenta,TipoMov=@pmTipoMov
 WHERE IdDoc=@pmIdDoc AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposEnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposEnt] @pmIdEnt VARCHAR(4),@pmDiaEntrega VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposEnt SET DiaEntrega=@pmDiaEntrega,Inactivo=@pmInactivo
 WHERE IdEnt=@pmIdEnt
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposEsc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposEsc] @pmIdTipoEsc VARCHAR(4),@pmTipoEscolta VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposEsc SET TipoEscolta=@pmTipoEscolta,Inactivo=@pmInactivo
 WHERE IdTipoEsc=@pmIdTipoEsc
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposFil]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposFil] @pmIdFiltro VARCHAR(4),@pmTipoFiltro VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposFil SET TipoFiltro=@pmTipoFiltro,Inactivo=@pmInactivo
 WHERE IdFiltro=@pmIdFiltro
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposFuel]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposFuel] @pmIdCom VARCHAR(4),@pmTipoComb VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposFuel SET TipoComb=@pmTipoComb,Inactivo=@pmInactivo
 WHERE IdCom=@pmIdCom
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposInm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposInm] @pmIdTipoInm VARCHAR(4),@pmTipoInmueble VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposInm SET TipoInmueble=@pmTipoInmueble,Inactivo=@pmInactivo
 WHERE IdTipoInm=@pmIdTipoInm
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposLla]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposLla] @pmIdTlla VARCHAR(4),@pmTipoLlanta VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposLla SET TipoLlanta=@pmTipoLlanta,Inactivo=@pmInactivo
 WHERE IdTlla=@pmIdTlla
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposLub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposLub] @pmIdLub VARCHAR(4),@pmTipoLub VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposLub SET TipoLub=@pmTipoLub,Inactivo=@pmInactivo
 WHERE IdLub=@pmIdLub
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposMat] @pmIdMat VARCHAR(4),@pmMaterial VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposMat SET Material=@pmMaterial,Inactivo=@pmInactivo
 WHERE IdMat=@pmIdMat
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMcia]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposMcia] @pmIdTmcia VARCHAR(4),@pmTipoMcia VARCHAR(50),@pmCodPeligrosidad VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE TiposMcia SET TipoMcia=@pmTipoMcia,CodPeligrosidad=@pmCodPeligrosidad,Inactivo=@pmInactivo
 WHERE IdTmcia=@pmIdTmcia
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMnjo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposMnjo] @pmIdMnjo VARCHAR(4),@pmManejoMcia VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposMnjo SET ManejoMcia=@pmManejoMcia,Inactivo=@pmInactivo
 WHERE IdMnjo=@pmIdMnjo
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMod]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposMod] @pmIdModd VARCHAR(4),@pmModalidad VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposMod SET Modalidad=@pmModalidad,Inactivo=@pmInactivo
 WHERE IdModd=@pmIdModd
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposMot] @pmIdTipoMot VARCHAR(4),@pmTipoMotor VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposMot SET TipoMotor=@pmTipoMotor,Inactivo=@pmInactivo
 WHERE IdTipoMot=@pmIdTipoMot
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposMotdev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposMotdev] @pmIdMotDev VARCHAR(4),@pmMotivoDev VARCHAR(150),@pmTipoFact VARCHAR(3)
,@pmInactivo BIT,@pmEstadoPed BIT,@pmCodEstadoPed VARCHAR(4),@pmBodegaDev BIT,@pmCodBodegaDev VARCHAR(4),@pmCodCias VARCHAR(500)
 AS 
 UPDATE TiposMotdev SET MotivoDev=@pmMotivoDev,TipoFact=@pmTipoFact,Inactivo=@pmInactivo
,EstadoPed=@pmEstadoPed,CodEstadoPed=@pmCodEstadoPed,BodegaDev=@pmBodegaDev,CodBodegaDev=@pmCodBodegaDev,CodCias=@pmCodCias
 WHERE IdMotDev=@pmIdMotDev
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNat]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposNat] @pmIdNat VARCHAR(4),@pmNatlzaprod VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposNat SET Natlzaprod=@pmNatlzaprod,Inactivo=@pmInactivo
 WHERE IdNat=@pmIdNat
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNivs]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposNivs] @pmIdNiv VARCHAR(4),@pmNivelServicio VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposNivs SET NivelServicio=@pmNivelServicio,Inactivo=@pmInactivo
 WHERE IdNiv=@pmIdNiv
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposNom] @pmIdNom VARCHAR(4),@pmTipoNomina VARCHAR(50),@pmAsistencia BIT,@pmNoDevenga BIT
,@pmTipoLiquida CHAR(1),@pmFechaActual SMALLDATETIME,@pmInactivo BIT,@pmCdCiaInt CHAR(2)
,@pmLiqEspSalud BIT,@pmDctoSalud DECIMAL(14,4),@pmPagoSalud DECIMAL(14,4),@pmNomDiario BIT
 AS 
 UPDATE TiposNom SET TipoNomina=@pmTipoNomina,Asistencia=@pmAsistencia,NoDevenga=@pmNoDevenga,TipoLiquida=@pmTipoLiquida
,FechaActual=@pmFechaActual,Inactivo=@pmInactivo,CdCiaInt=@pmCdCiaInt,LiqEspSalud=@pmLiqEspSalud,DctoSalud=@pmDctoSalud,PagoSalud=@pmPagoSalud,NomDiario=@pmNomDiario
 WHERE IdNom=@pmIdNom
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposNov] @pmIdNov VARCHAR(4),@pmNovedad VARCHAR(50),@pmAdmon VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE TiposNov SET Novedad=@pmNovedad,Admon=@pmAdmon,Inactivo=@pmInactivo
 WHERE IdNov=@pmIdNov
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposOperac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposOperac] @pmIdTipoOper VARCHAR(4),@pmTipoOperacion VARCHAR(50),@pmInactivo BIT
,@pmTipoIngreso VARCHAR(10),@pmTarifaIng DECIMAL(14,4)
 AS 
 UPDATE TiposOperac SET TipoOperacion=@pmTipoOperacion,Inactivo=@pmInactivo,TipoIngreso=@pmTipoIngreso,TarifaIng=@pmTarifaIng
 WHERE IdTipoOper=@pmIdTipoOper
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposOperarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposOperarios] @pmIdOper VARCHAR(4),@pmTipoOperario VARCHAR(50),@pmTarifaCom DECIMAL(14,4),@pmGrupoOper VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE TiposOperarios SET TipoOperario=@pmTipoOperario,TarifaCom=@pmTarifaCom,Inactivo=@pmInactivo,GrupoOper=@pmGrupoOper
 WHERE IdOper=@pmIdOper
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposPcnto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposPcnto] @pmIdTipoPre VARCHAR(4),@pmPrecinto VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposPcnto SET Precinto=@pmPrecinto,Inactivo=@pmInactivo
 WHERE IdTipoPre=@pmIdTipoPre
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposPpt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposPpt] @pmIdPpd VARCHAR(4),@pmTipoProp VARCHAR(50),@pmVehPropio BIT,@pmInactivo BIT
 AS 
 UPDATE TiposPpt SET TipoProp=@pmTipoProp,VehPropio=@pmVehPropio,Inactivo=@pmInactivo
 WHERE IdPpd=@pmIdPpd
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposPrend]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposPrend] @pmIdPrend VARCHAR(4),@pmTipoPrenda VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposPrend SET TipoPrenda=@pmTipoPrenda,Inactivo=@pmInactivo
 WHERE IdPrend=@pmIdPrend
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposProceso]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposProceso] @pmIdTipProc VARCHAR(4),@pmTipoProceso VARCHAR(150),@pmDescripcion VARCHAR(1000),@pmIndOrden INT,@pmInactivo BIT
 AS 
 UPDATE TiposProceso SET TipoProceso=@pmTipoProceso,Descripcion=@pmDescripcion,IndOrden=@pmIndOrden,Inactivo=@pmInactivo
 WHERE IdTipProc=@pmIdTipProc
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposRespFis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposRespFis] @pmIdResFis VARCHAR(10),@pmNomResFiscal VARCHAR(250),@pmInactivo BIT
 AS 
 UPDATE TiposRespFis SET NomResFiscal=@pmNomResFiscal,Inactivo=@pmInactivo
 WHERE IdResFis=@pmIdResFis
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposSustento]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposSustento] @pmIdSustento VARCHAR(4),@pmSustento VARCHAR(150),@pmInactivo BIT
 AS 
 UPDATE TiposSustento SET Sustento=@pmSustento,Inactivo=@pmInactivo
 WHERE IdSustento=@pmIdSustento
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposTasas]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposTasas] @pmIdTasa VARCHAR(4),@pmTipoTasa VARCHAR(50),@pmSimbolo VARCHAR(10),@pmUnidad VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposTasas SET TipoTasa=@pmTipoTasa,Simbolo=@pmSimbolo,Unidad=@pmUnidad,Inactivo=@pmInactivo
 WHERE IdTasa=@pmIdTasa
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposTerc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposTerc] @pmIdTipoTerc VARCHAR(4),@pmTipoTercero VARCHAR(100),@pmInactivo BIT
 AS 
 UPDATE TiposTerc SET TipoTercero=@pmTipoTercero,Inactivo=@pmInactivo
 WHERE IdTipoTerc=@pmIdTipoTerc
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposVeh] @pmIdTipoVeh VARCHAR(4),@pmTipoVehiculo VARCHAR(50)
,@pmConfiguracion VARCHAR(6),@pmEjes INT,@pmLlantas INT,@pmCapacPeso DECIMAL(14,4),@pmUndCapac VARCHAR(10)
,@pmCapacVol DECIMAL(14,4),@pmUndCapVol VARCHAR(10),@pmCubAlto DECIMAL(14,4),@pmCubLargo DECIMAL(14,4),@pmCubAncho DECIMAL(14,4)
,@pmPesoBruto DECIMAL(14,4),@pmInactivo BIT
 AS 
 UPDATE TiposVeh SET TipoVehiculo=@pmTipoVehiculo,Configuracion=@pmConfiguracion,Ejes=@pmEjes,Llantas=@pmLlantas
,CapacPeso=@pmCapacPeso,UndCapac=@pmUndCapac,CapacVol=@pmCapacVol,UndCapVol=@pmUndCapVol,CubAlto=@pmCubAlto
,CubLargo=@pmCubLargo,CubAncho=@pmCubAncho,PesoBruto=@pmPesoBruto,Inactivo=@pmInactivo
 WHERE IdTipoVeh=@pmIdTipoVeh
GO
/****** Object:  StoredProcedure [dbo].[paUpTiposZona]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTiposZona] @pmIdTipZona VARCHAR(4),@pmTipoZona VARCHAR(50),@pmInactivo BIT
 AS 
 UPDATE TiposZona SET TipoZona=@pmTipoZona,Inactivo=@pmInactivo
 WHERE IdTipZona=@pmIdTipZona
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AportesDet]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_AportesDet] @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmApellido1 VARCHAR(50),@pmtmApellido2 VARCHAR(50),@pmtmNombre1 VARCHAR(50),@pmtmNombre2 VARCHAR(50),@pmtmNContto INT,@pmtmDiasPen DECIMAL(10,4),@pmtmDiasSal DECIMAL(10,4),@pmtmDiasRie DECIMAL(10,4),@pmtmDiasCom DECIMAL(10,4),@pmtmBasePen MONEY,@pmtmBaseSal MONEY,@pmtmBaseRie MONEY,@pmtmBaseCom MONEY,@pmtmBaseRef MONEY,@pmtmValorPen MONEY,@pmtmValorSal MONEY,@pmtmValorRie MONEY,@pmtmValorCom MONEY,@pmtmValorSena MONEY,@pmtmValorIcbf MONEY,@pmtmValorFsp MONEY,@pmtmValorFsu MONEY,@pmtmValorESAP MONEY,@pmtmValorMin MONEY,@pmtmTarfaPen DECIMAL(10,4),@pmtmTarfaSal DECIMAL(10,4),@pmtmTarfaRie DECIMAL(10,4)
,@pmtmTarfaFsp DECIMAL(10,4),@pmtmTarfaFsu DECIMAL(10,4),@pmtmTarfaEsa DECIMAL(10,4),@pmtmTarfaMin DECIMAL(10,4),@pmtmTarfaCom DECIMAL(10,4),@pmtmTarfaIcb DECIMAL(10,4),@pmtmTarfaSen DECIMAL(10,4),@pmtmVrIncap MONEY,@pmtmVrLicencia MONEY,@pmtmVrVolAfi MONEY,@pmtmVrVolApo MONEY,@pmtmVrNoReten MONEY
,@pmtmVrUpc MONEY,@pmtmVrIncIrp MONEY,@pmtmNAutLic VARCHAR(30),@pmtmNAutInc VARCHAR(30),@pmtmNAutIrp VARCHAR(30),@pmtmIdFonPen VARCHAR(8),@pmtmIdFonSal VARCHAR(8),@pmtmIdFonRie VARCHAR(8),@pmtmIdFonCaj VARCHAR(8),@pmtmIdInstala VARCHAR(4),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16),@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVehiculo VARCHAR(10),@pmtmVrBasico MONEY
,@pmtmCdFonAvp VARCHAR(8),@pmtmDiasSan DECIMAL(14,4),@pmtmDiasDnrPen INT,@pmtmDiasDnrSal INT,@pmtmNovDsr INT,@pmtmFecNovIng SMALLDATETIME,@pmtmFecNovRet SMALLDATETIME,@pmtmFecNovVsp SMALLDATETIME,@pmtmFecIniSln SMALLDATETIME,@pmtmFecFinSln SMALLDATETIME
,@pmtmFecIniIge SMALLDATETIME,@pmtmFecFinIge SMALLDATETIME,@pmtmFecIniLma SMALLDATETIME,@pmtmFecFinLma SMALLDATETIME,@pmtmFecIniVac SMALLDATETIME,@pmtmFecFinVac SMALLDATETIME,@pmtmFecIniVct SMALLDATETIME,@pmtmFecFinVct SMALLDATETIME,@pmtmFecIniIrl SMALLDATETIME,@pmtmFecFinIrl SMALLDATETIME,@pmtmVrIBCparaf MONEY,@pmtmCantHoras INT,@pmtmTipSalario VARCHAR(10),@pmtmIdActEco VARCHAR(10)
 AS 
 UPDATE tm_Aportes SET tmIdEmpleado=@pmtmIdEmpleado,tmApellido1=@pmtmApellido1,tmApellido2=@pmtmApellido2,tmNombre1=@pmtmNombre1,tmNombre2=@pmtmNombre2,tmNContto=@pmtmNContto,tmDiasPen=@pmtmDiasPen,tmDiasSal=@pmtmDiasSal,tmDiasRie=@pmtmDiasRie,tmDiasCom=@pmtmDiasCom,tmBasePen=@pmtmBasePen,tmBaseSal=@pmtmBaseSal,tmBaseRie=@pmtmBaseRie,tmBaseCom=@pmtmBaseCom,tmBaseRef=@pmtmBaseRef,tmValorPen=@pmtmValorPen,tmValorSal=@pmtmValorSal,tmValorRie=@pmtmValorRie,tmValorCom=@pmtmValorCom,tmValorSena=@pmtmValorSena,tmValorIcbf=@pmtmValorIcbf,tmValorFsp=@pmtmValorFsp,tmValorFsu=@pmtmValorFsu,tmValorESAP=@pmtmValorESAP
,tmValorMin=@pmtmValorMin,tmTarfaPen=@pmtmTarfaPen,tmTarfaSal=@pmtmTarfaSal,tmTarfaRie=@pmtmTarfaRie,tmTarfaFsp=@pmtmTarfaFsp,tmTarfaFsu=@pmtmTarfaFsu,tmTarfaEsa=@pmtmTarfaEsa,tmTarfaMin=@pmtmTarfaMin,tmTarfaCom=@pmtmTarfaCom,tmTarfaIcb=@pmtmTarfaIcb,tmTarfaSen=@pmtmTarfaSen,tmVrIncap=@pmtmVrIncap,tmVrLicencia=@pmtmVrLicencia,tmVrVolAfi=@pmtmVrVolAfi,tmVrVolApo=@pmtmVrVolApo,tmVrNoReten=@pmtmVrNoReten,tmVrUpc=@pmtmVrUpc,tmVrIncIrp=@pmtmVrIncIrp,tmNAutLic=@pmtmNAutLic,tmNAutInc=@pmtmNAutInc,tmNAutIrp=@pmtmNAutIrp,tmIdFonPen=@pmtmIdFonPen,tmIdFonSal=@pmtmIdFonSal,tmIdFonRie=@pmtmIdFonRie,tmIdFonCaj=@pmtmIdFonCaj,tmIdInstala=@pmtmIdInstala
,tmIdDep=@pmtmIdDep,tmIdCCosto=@pmtmIdCCosto,tmIdSubCos=@pmtmIdSubCos,tmIdNom=@pmtmIdNom,tmVehiculo=@pmtmVehiculo,tmVrBasico=@pmtmVrBasico,tmCdFonAvp=@pmtmCdFonAvp,tmDiasSan=@pmtmDiasSan,tmDiasDnrPen=@pmtmDiasDnrPen,tmDiasDnrSal=@pmtmDiasDnrSal,tmNovDsr=@pmtmNovDsr,tmFecNovIng=@pmtmFecNovIng,tmFecNovRet=@pmtmFecNovRet,tmFecNovVsp=@pmtmFecNovVsp,tmFecIniSln=@pmtmFecIniSln,tmFecFinSln=@pmtmFecFinSln,tmFecIniIge=@pmtmFecIniIge,tmFecFinIge=@pmtmFecFinIge,tmFecIniLma=@pmtmFecIniLma,tmFecFinLma=@pmtmFecFinLma,tmFecIniVac=@pmtmFecIniVac,tmFecFinVac=@pmtmFecFinVac,tmIdActEco=@pmtmIdActEco
,tmFecIniVct=@pmtmFecIniVct,tmFecFinVct=@pmtmFecFinVct,tmFecIniIrl=@pmtmFecIniIrl,tmFecFinIrl=@pmtmFecFinIrl,tmVrIBCparaf=@pmtmVrIBCparaf,tmCantHoras=@pmtmCantHoras,tmTipSalario=@pmtmTipSalario
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AportesNov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_AportesNov] @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmNovIng INT,@pmtmNovRet INT,@pmtmNovTda INT,@pmtmNovTaa INT,@pmtmNovTdp INT,@pmtmNovTap INT
,@pmtmNovVsp INT,@pmtmNovVte INT,@pmtmNovVst INT,@pmtmNovSln INT,@pmtmNovIge INT,@pmtmNovLma INT,@pmtmNovVac INT,@pmtmNovAvp INT,@pmtmNovIrp INT,@pmtmNovVct INT
,@pmtmCodNewEps VARCHAR(8),@pmtmCodNewPen VARCHAR(8),@pmtmCodNewRie VARCHAR(8),@pmtmCodNewIns VARCHAR(4),@pmtmCodNewTar VARCHAR(4),@pmtmCodNewGru VARCHAR(4),@pmtmDiasNov DECIMAL(10,4),@pmtmDiasSan DECIMAL(14,4)
,@pmtmDiasDnrPen INT,@pmtmDiasDnrSal INT,@pmtmNovDsr INT,@pmtmFecNovIng SMALLDATETIME,@pmtmFecNovRet SMALLDATETIME,@pmtmFecNovVsp SMALLDATETIME,@pmtmFecIniSln SMALLDATETIME,@pmtmFecFinSln SMALLDATETIME
,@pmtmFecIniIge SMALLDATETIME,@pmtmFecFinIge SMALLDATETIME,@pmtmFecIniLma SMALLDATETIME,@pmtmFecFinLma SMALLDATETIME,@pmtmFecIniVac SMALLDATETIME,@pmtmFecFinVac SMALLDATETIME,@pmtmFecIniVct SMALLDATETIME
,@pmtmFecFinVct SMALLDATETIME,@pmtmFecIniIrl SMALLDATETIME,@pmtmFecFinIrl SMALLDATETIME
 AS 
 UPDATE tm_Aportes SET tmNovIng=@pmtmNovIng,tmNovRet=@pmtmNovRet,tmNovTda=@pmtmNovTda,tmNovTaa=@pmtmNovTaa,tmNovTdp=@pmtmNovTdp,tmNovTap=@pmtmNovTap,tmNovVsp=@pmtmNovVsp,tmNovVte=@pmtmNovVte,tmNovVst=@pmtmNovVst,tmNovSln=@pmtmNovSln
,tmNovIge=@pmtmNovIge,tmNovLma=@pmtmNovLma,tmNovVac=@pmtmNovVac,tmNovAvp=@pmtmNovAvp,tmNovIrp=@pmtmNovIrp,tmNovVct=@pmtmNovVct,tmCodNewEps=@pmtmCodNewEps,tmCodNewPen=@pmtmCodNewPen,tmCodNewRie=@pmtmCodNewRie,tmCodNewIns=@pmtmCodNewIns
,tmCodNewTar=@pmtmCodNewTar,tmCodNewGru=@pmtmCodNewGru,tmDiasNov=@pmtmDiasNov,tmDiasSan=@pmtmDiasSan,tmDiasDnrPen=@pmtmDiasDnrPen,tmDiasDnrSal=@pmtmDiasDnrSal,tmNovDsr=@pmtmNovDsr,tmFecNovIng=@pmtmFecNovIng,tmFecNovRet=@pmtmFecNovRet
,tmFecNovVsp=@pmtmFecNovVsp,tmFecIniSln=@pmtmFecIniSln,tmFecFinSln=@pmtmFecFinSln,tmFecIniIge=@pmtmFecIniIge,tmFecFinIge=@pmtmFecFinIge,tmFecIniLma=@pmtmFecIniLma,tmFecFinLma=@pmtmFecFinLma,tmFecIniVac=@pmtmFecIniVac
,tmFecFinVac=@pmtmFecFinVac,tmFecIniVct=@pmtmFecIniVct,tmFecFinVct=@pmtmFecFinVct,tmFecIniIrl=@pmtmFecIniIrl,tmFecFinIrl=@pmtmFecFinIrl
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AutTot]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_AutTot] @pmtmEst VARCHAR(5),@pmtmItem INT,@pmtmTipAdm VARCHAR(3),@pmtmIdFondo VARCHAR(8),@pmtmCodTipoApo CHAR(2),@pmtmTotalCot MONEY,@pmtmTotalFsp MONEY,@pmtmTotalFsu MONEY,@pmtmTotalAva MONEY,@pmtmTotalAve MONEY
,@pmtmTotalUpc MONEY,@pmtmTotalLic MONEY,@pmtmTotalInc MONEY,@pmtmTotalOtr MONEY,@pmtmDiasMora INT,@pmtmTarifMora DECIMAL(10,4),@pmtmIntMora MONEY,@pmtmIMoraOtr MONEY,@pmtmTotalSAF MONEY,@pmtmSAFUpc MONEY,@pmtmTotalPagar MONEY,@pmtmTotalFon MONEY
,@pmtmTotalAfi INT,@pmtmNumAutLic VARCHAR(30),@pmtmNumAutInc VARCHAR(30),@pmtmNumPlaSAF VARCHAR(20)
 AS 
 UPDATE tm_AutTot SET tmTipAdm=@pmtmTipAdm,tmIdFondo=@pmtmIdFondo,tmCodTipoApo=@pmtmCodTipoApo,tmTotalCot=@pmtmTotalCot,tmTotalFsp=@pmtmTotalFsp,tmTotalFsu=@pmtmTotalFsu,tmTotalAva=@pmtmTotalAva,tmTotalAve=@pmtmTotalAve,tmTotalUpc=@pmtmTotalUpc,tmTotalLic=@pmtmTotalLic
,tmTotalInc=@pmtmTotalInc,tmTotalOtr=@pmtmTotalOtr,tmDiasMora=@pmtmDiasMora,tmTarifMora=@pmtmTarifMora,tmIntMora=@pmtmIntMora,tmIMoraOtr=@pmtmIMoraOtr,tmTotalSAF=@pmtmTotalSAF,tmSAFUpc=@pmtmSAFUpc,tmTotalPagar=@pmtmTotalPagar,tmTotalFon=@pmtmTotalFon,tmTotalAfi=@pmtmTotalAfi
,tmNumAutLic=@pmtmNumAutLic,tmNumAutInc=@pmtmNumAutInc,tmNumPlaSAF=@pmtmNumPlaSAF
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AuxInvCpm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_AuxInvCpm] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdCia CHAR(2)
,@pmtmCostoProm MONEY
 AS 
 UPDATE tm_AuxInv SET  tmCostoProm=@pmtmCostoProm
 WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AuxInvSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_AuxInvSan] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4),@pmtmIdCia CHAR(2)
,@pmtmNumLote VARCHAR(30),@pmtmSaldoAnt DECIMAL(14,4),@pmtmCostoAnt MONEY,@pmtmCostoProm MONEY
 AS 
 UPDATE tm_AuxInv SET tmSaldoAnt=@pmtmSaldoAnt,tmCostoAnt=@pmtmCostoAnt,tmCostoProm=@pmtmCostoProm
 WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto AND tmIdBodega=@pmtmIdBodega 
 AND tmIdCia=@pmtmIdCia AND tmNumLote=@pmtmNumLote
GO
/****** Object:  StoredProcedure [dbo].[paUptm_AuxInvSanKar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_AuxInvSanKar] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16),@pmtmIdBodega VARCHAR(4)
,@pmtmIdCia CHAR(2),@pmtmNumLote VARCHAR(30),@pmtmSaldoAnt DECIMAL(14,4),@pmtmCostoAnt MONEY
 AS 
 UPDATE tm_AuxInv SET tmSaldoAnt=@pmtmSaldoAnt,tmCostoAnt=@pmtmCostoAnt
 WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto AND tmIdBodega=@pmtmIdBodega 
 AND tmIdCia=@pmtmIdCia AND tmNumLote=@pmtmNumLote
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalComparaDos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_BalComparaDos] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT
,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY
 AS 
 UPDATE tm_BalCompara SET tmSalAnt2=@pmtmSalAnt2,tmDebitos2=@pmtmDebitos2,tmCreditos2=@pmtmCreditos2,tmSaldo2=@pmtmSaldo2
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalComparaTres]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_BalComparaTres] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT
,@pmtmSalAnt3 MONEY,@pmtmDebitos3 MONEY,@pmtmCreditos3 MONEY,@pmtmSaldo3 MONEY
 AS 
 UPDATE tm_BalCompara SET tmSalAnt3=@pmtmSalAnt3,tmDebitos3=@pmtmDebitos3,tmCreditos3=@pmtmCreditos3,tmSaldo3=@pmtmSaldo3
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalComSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_BalComSan] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT
,@pmtmTipo VARCHAR(4),@pmtmSaldoAnterior MONEY,@pmtmNuevoSaldo MONEY
 AS 
 UPDATE tm_BalCom SET  tmSaldoAnterior=@pmtmSaldoAnterior,tmNuevoSaldo=@pmtmNuevoSaldo
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmItem=@pmtmItem AND tmTipo=@pmtmTipo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalGenDos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_BalGenDos] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2)
,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY
 AS 
 UPDATE tm_BalGen SET  tmSalAnt2=@pmtmSalAnt2,tmDebitos2=@pmtmDebitos2
,tmCreditos2=@pmtmCreditos2,tmSaldo2=@pmtmSaldo2
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmIdCia=@pmtmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUptm_BalGenUno]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_BalGenUno] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmIdCia CHAR(2)
,@pmtmSaldoAnterior MONEY,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY,@pmtmNuevoSaldo MONEY
 AS 
 UPDATE tm_BalGen SET tmSaldoAnterior=@pmtmSaldoAnterior,tmTotalDebitos=@pmtmTotalDebitos
,tmTotalCreditos=@pmtmTotalCreditos,tmNuevoSaldo=@pmtmNuevoSaldo
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmIdCia=@pmtmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUptm_CargosAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_CargosAnt] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmAuto BIT,@pmtmAbonado MONEY
,@pmtmTipDocAnt VARCHAR(3),@pmtmDocAnticipo INT,@pmtmCiaDocAnt  CHAR(2)
AS
 IF @pmAuto<>0 
  UPDATE tm_Cargos SET tmAbonado=(tmAbonado+@pmtmAbonado),tmTipDocAnt=@pmtmTipDocAnt, tmDocAnticipo=@pmtmDocAnticipo,tmCiaDocAnt=@pmtmCiaDocAnt
  WHERE  tmNumero=@pmtmNumero  AND  tmItem=@pmtmItem
 ELSE
  UPDATE tm_Cargos SET tmAbonado=@pmtmAbonado,tmTipDocAnt=@pmtmTipDocAnt, tmDocAnticipo=@pmtmDocAnticipo,tmCiaDocAnt=@pmtmCiaDocAnt
  WHERE  tmNumero=@pmtmNumero  AND  tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_CxCobrarAbo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_CxCobrarAbo] @pmtmNumero VARCHAR(5),@pmtmItem INT
,@pmtmTotAbono MONEY
 AS 
 UPDATE tm_CxCobrar SET tmTotAbono=@pmtmTotAbono
 WHERE  tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EdsFormasTap]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_EdsFormasTap] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipAplica VARCHAR(10)
 AS 
 UPDATE  tm_EdsFormas  SET tmTipAplica=@pmtmTipAplica
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EstadoGypDos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_EstadoGypDos] @pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmItem INT
,@pmtmSalAnt2 MONEY,@pmtmDebitos2 MONEY,@pmtmCreditos2 MONEY,@pmtmSaldo2 MONEY
 AS 
 UPDATE tm_EstadoGyp SET tmSalAnt2=@pmtmSalAnt2,tmDebitos2=@pmtmDebitos2,tmCreditos2=@pmtmCreditos2,tmSaldo2=@pmtmSaldo2
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EstCueCtePro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUptm_EstCueCtePro] @pmtmEst CHAR(2),@pmtmIdCliente VARCHAR(16),@pmtmIdClase VARCHAR(4),@pmtmIdCia CHAR(2)
,@pmtmIdVehiculo VARCHAR(10),@pmtmSaldoAnt MONEY,@pmFld VARCHAR(3)
AS
 IF @pmFld='CIA'
   UPDATE tm_EstCueCte SET tmSalAntProCia=@pmtmSaldoAnt
   WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente AND tmIdVehiculo=@pmtmIdVehiculo
 --AND tmIdClase=@pmtmIdClase AND  tmIdCia=@pmtmIdCia
  ELSE
 BEGIN
  IF @pmFld='CLA'
   UPDATE tm_EstCueCte SET tmSalAntProCla=@pmtmSaldoAnt
   WHERE tmEst=@pmtmEst AND  tmIdCliente=@pmtmIdCliente AND tmIdClase=@pmtmIdClase AND tmIdVehiculo=@pmtmIdVehiculo
  ELSE
   UPDATE tm_EstCueCte SET tmSalAntPro=@pmtmSaldoAnt
   WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente 
 END
GO
/****** Object:  StoredProcedure [dbo].[paUptm_EstCueCteVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUptm_EstCueCteVeh] @pmtmEst CHAR(2),@pmtmIdVehiculo VARCHAR(10),@pmtmIdClase VARCHAR(4)
,@pmtmIdCia CHAR(2),@pmtmSaldoAnt MONEY,@pmFld VARCHAR(3)
AS
 IF @pmFld='CIA'
   UPDATE tm_EstCueCte SET tmSaldoAntCia=@pmtmSaldoAnt
   WHERE tmEst=@pmtmEst AND tmIdVehiculo=@pmtmIdVehiculo AND tmIdClase=@pmtmIdClase AND  tmIdCia=@pmtmIdCia
 ELSE
 BEGIN
  IF @pmFld='CLA'
   UPDATE tm_EstCueCte SET tmSaldoAntCla=@pmtmSaldoAnt
   WHERE tmEst=@pmtmEst AND tmIdVehiculo=@pmtmIdVehiculo AND tmIdClase=@pmtmIdClase
  ELSE
   UPDATE tm_EstCueCte SET tmSaldoAnt=@pmtmSaldoAnt
   WHERE tmEst=@pmtmEst AND tmIdVehiculo=@pmtmIdVehiculo
 END
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_ExtVehNit]  @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16),@pmtmSalAntPro MONEY
AS
 UPDATE tm_ExtVeh SET tmSalAntPro=@pmtmSalAntPro
 WHERE tmEst=@pmtmEst AND tmIdPropietario=@pmtmIdPropietario
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehPro]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE  [dbo].[paUptm_ExtVehPro] @pmtmEst CHAR(2),@pmtmIdCliente VARCHAR(16)
,@pmtmIdVehiculo VARCHAR(10),@pmtmSaldoAnt MONEY
AS
 UPDATE tm_ExtVeh SET tmSaldoAnt=@pmtmSaldoAnt
 WHERE tmEst=@pmtmEst AND tmIdPropietario=@pmtmIdCliente AND tmIdVehiculo=@pmtmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehProd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_ExtVehProd] @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmTotalProducido MONEY,@pmtmMaxProducido MONEY,@pmtmMinProducido MONEY,@pmtmTotalRecrridos INT,@pmtmTotalPasaj INT,@pmtmTotalDias INT
 AS 
 UPDATE tm_ExtVeh SET tmTotalProducido=@pmtmTotalProducido,tmMaxProducido=@pmtmMaxProducido,tmMinProducido=@pmtmMinProducido,tmTotalRecrridos=@pmtmTotalRecrridos,tmTotalPasaj=@pmtmTotalPasaj,tmTotalDias=@pmtmTotalDias
 WHERE tmEst=@pmtmEst AND tmIdPropietario=@pmtmIdPropietario AND tmIdVehiculo=@pmtmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehVal]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_ExtVehVal] @pmtmEst CHAR(2),@pmtmIdPropietario VARCHAR(16),@pmtmIdVehiculo VARCHAR(10),@pmtmTotaDebito MONEY,@pmtmTotaCredito MONEY
,@pmtmTotalCausac MONEY,@pmtmGalones DECIMAL(14,4),@pmtmValorComb MONEY
 AS 
 UPDATE tm_ExtVeh SET tmTotaDebito=@pmtmTotaDebito,tmTotaCredito=@pmtmTotaCredito,tmTotalCausac=@pmtmTotalCausac,tmGalones=@pmtmGalones,tmValorComb=@pmtmValorComb
 WHERE tmEst=@pmtmEst AND tmIdPropietario=@pmtmIdPropietario AND tmIdVehiculo=@pmtmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_ExtVehVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_ExtVehVeh]  @pmtmEst CHAR(2),@pmtmIdVehiculo VARCHAR(10),@pmtmSaldoAnt MONEY
AS
 UPDATE tm_ExtVeh SET tmSalAntProCla=@pmtmSaldoAnt
 WHERE tmEst=@pmtmEst AND tmIdVehiculo=@pmtmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_IntNomina]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_IntNomina] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmIdVehiculo VARCHAR(10),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConductor VARCHAR(16)
,@pmtmIdPropietario VARCHAR(16),@pmtmVehPropio BIT,@pmtmConductor VARCHAR(100),@pmtmTercero VARCHAR(100),@pmtmCcosto VARCHAR(16),@pmtmValorAbono MONEY
 AS 
 UPDATE tm_IntNomina SET tmIdVehiculo=@pmtmIdVehiculo,tmIdEmpleado=@pmtmIdEmpleado,tmIdConductor=@pmtmIdConductor,tmIdPropietario=@pmtmIdPropietario,tmVehPropio=@pmtmVehPropio
,tmConductor=@pmtmConductor,tmTercero=@pmtmTercero,tmCcosto=@pmtmCcosto,tmValorAbono=@pmtmValorAbono
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_KdexExto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_KdexExto] @pmtmNumero VARCHAR(5),@pmTipo VARCHAR(3)
 AS 
 IF @pmTipo='RET'
  UPDATE  tm_Kdex SET tmVrRete=0,tmTarifaRet=0  WHERE  tmNumero=@pmtmNumero  AND  tmVrRete>0
 ELSE
 BEGIN
  IF @pmTipo='ICA'
   UPDATE  tm_Kdex SET tmVrIca=0,tmTarifaIca=0  WHERE  tmNumero=@pmtmNumero  AND  tmVrIca>0
  ELSE--IVA
   UPDATE  tm_Kdex SET tmVrIva=0,tmTarifaIva=0  WHERE  tmNumero=@pmtmNumero  AND  tmVrIva>0
 END
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LibOf]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_LibOf] @pmtmEst CHAR(2),@pmtmTipCom VARCHAR(3),@pmtmItem INT
,@pmtmTotalDebitos MONEY,@pmtmTotalCreditos MONEY
 AS 
 UPDATE tm_LibOf SET tmTotalDebitos=@pmtmTotalDebitos,tmTotalCreditos=@pmtmTotalCreditos
 WHERE tmEst=@pmtmEst AND tmTipCom=@pmtmTipCom AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LibOfSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_LibOfSan] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmtmIdCuenta VARCHAR(16),@pmtmSaldoAnterior MONEY
,@pmtmIdTercero VARCHAR(16)=Null,@pmtmIdCCosto VARCHAR(16)=Null,@pmtmIdSubCos VARCHAR(16)=Null,@pmtmIdCia CHAR(2)=Null
 AS 
 IF @pmTipo='CUE'
  UPDATE tm_LibOf SET tmSaldoAnterior=@pmtmSaldoAnterior  WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
 ELSE
   IF @pmTipo='NIT'
    UPDATE tm_LibOf SET tmSanNit=@pmtmSaldoAnterior  WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta
    AND tmIdTercero=@pmtmIdTercero  AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
   ELSE
    IF  @pmTipo='CC'
     UPDATE tm_LibOf SET tmSanNitcc=@pmtmSaldoAnterior  WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta
     AND tmIdTercero=@pmtmIdTercero AND tmIdCCosto=@pmtmIdCCosto AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
    ELSE
     IF  @pmTipo='SUB'
      UPDATE tm_LibOf SET tmSanNitCcSub=@pmtmSaldoAnterior  WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta
      AND tmIdTercero=@pmtmIdTercero AND tmIdCCosto=@pmtmIdCCosto AND tmIdSubCos=@pmtmIdSubCos AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUptm_Liquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_Liquida] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4),@pmtmDetalle VARCHAR(100),@pmtmFecUltLiq SMALLDATETIME,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmVrBase MONEY,@pmtmCantidad INT,@pmtmVrLiquida MONEY
,@pmtmVrDeducido MONEY,@pmtmFecIniPmd SMALLDATETIME,@pmtmFecFinPmd SMALLDATETIME,@pmtmDiasBase INT,@pmtmDiasNoRem INT,@pmtmTarifa DECIMAL(10,4),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmLogPmdio VARCHAR(1500),@pmtmNContrato INT,@pmtmpVehiculo VARCHAR(10),@pmtmIdDep VARCHAR(4),@pmtmIdCCosto VARCHAR(16)
,@pmtmIdSubCos VARCHAR(16),@pmtmIdNom VARCHAR(4),@pmtmVrSalario MONEY,@pmtmVrParcial MONEY,@pmtmNitTercero VARCHAR(16)
 AS 
 UPDATE tm_Liquida SET tmIdEmpleado=@pmtmIdEmpleado,tmIdConcepto=@pmtmIdConcepto,tmDetalle=@pmtmDetalle,tmFecUltLiq=@pmtmFecUltLiq,tmFecInicial=@pmtmFecInicial,tmFecFinal=@pmtmFecFinal,tmVrBase=@pmtmVrBase,tmCantidad=@pmtmCantidad,tmVrLiquida=@pmtmVrLiquida,tmVrDeducido=@pmtmVrDeducido,tmFecIniPmd=@pmtmFecIniPmd
,tmFecFinPmd=@pmtmFecFinPmd,tmDiasBase=@pmtmDiasBase,tmDiasNoRem=@pmtmDiasNoRem,tmTarifa=@pmtmTarifa,tmNPrestamo=@pmtmNPrestamo,tmNCuota=@pmtmNCuota,tmLogPmdio=@pmtmLogPmdio,tmNContrato=@pmtmNContrato,tmpVehiculo=@pmtmpVehiculo,tmIdDep=@pmtmIdDep,tmIdCCosto=@pmtmIdCCosto,tmIdSubCos=@pmtmIdSubCos
,tmIdNom=@pmtmIdNom,tmVrSalario=@pmtmVrSalario,tmVrParcial=@pmtmVrParcial,tmNitTercero=@pmtmNitTercero
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LiquidaInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_LiquidaInt] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmIdConcepto VARCHAR(4) ,@pmtmVrBase MONEY
,@pmtmVrLiquida MONEY,@pmtmVrDeducido MONEY
 AS 
 UPDATE tm_Liquida SET tmVrBase=@pmtmVrBase,tmVrLiquida=@pmtmVrLiquida,tmVrDeducido=@pmtmVrDeducido
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmIdConcepto=@pmtmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUptm_LiquidaPar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_LiquidaPar] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmFecInicial SMALLDATETIME,@pmtmFecFinal SMALLDATETIME,@pmtmVrBase MONEY,@pmtmCantidad INT,@pmtmVrLiquida MONEY,@pmtmVrDeducido MONEY,@pmtmDiasBase INT,@pmtmDiasNoRem INT
,@pmtmTarifa DECIMAL(10,4),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmVrParcial MONEY
 AS 
 UPDATE tm_Liquida SET tmFecInicial=@pmtmFecInicial,tmFecFinal=@pmtmFecFinal,tmVrBase=@pmtmVrBase,tmCantidad=@pmtmCantidad,tmVrLiquida=@pmtmVrLiquida,tmVrDeducido=@pmtmVrDeducido,tmDiasBase=@pmtmDiasBase,tmDiasNoRem=@pmtmDiasNoRem
,tmTarifa=@pmtmTarifa,tmNPrestamo=@pmtmNPrestamo,tmNCuota=@pmtmNCuota,tmVrParcial=@pmtmVrParcial
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovClientesSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovClientesSan] @pmtmEst CHAR(2),@pmTipo VARCHAR(3),@pmtmIdCliente VARCHAR(16),@pmtmIdAgencia VARCHAR(16),@pmtmIdCia CHAR(2),@pmSaldoAnt MONEY
 AS 
 IF @pmTipo='CLI'
   UPDATE tm_MovClientes SET tmSanClie=@pmSaldoAnt WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente
 ELSE
  BEGIN
   IF @pmTipo='AGE' 
    UPDATE tm_MovClientes SET tmSanAge=@pmSaldoAnt WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente AND tmIdAgencia=@pmtmIdAgencia
  ELSE
    BEGIN
      IF @pmTipo='CIA'
       UPDATE tm_MovClientes SET tmSanClieCia=@pmSaldoAnt WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente AND tmIdCia=@pmtmIdCia
      ELSE --AGC
        UPDATE tm_MovClientes SET tmSanAgeCia=@pmSaldoAnt WHERE tmEst=@pmtmEst AND tmIdCliente=@pmtmIdCliente AND tmIdAgencia=@pmtmIdAgencia AND  tmIdCia=@pmtmIdCia
     END
  END
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueCc] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCCosto VARCHAR(16),@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanCcCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia AND IdCCosto=@pmIdCCosto
 ELSE
  UPDATE tm_MovCue SET VrSanCc=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND   IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueCcSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueCcSub] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanCcSubCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
 ELSE
  UPDATE tm_MovCue SET VrSanCcSub=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta
  AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNit]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNit] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdTercero VARCHAR(16),@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia AND IdTercero=@pmIdTercero
 ELSE
  UPDATE tm_MovCue SET VrSanNit=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdTercero=@pmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitAge]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitAge] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitAgeCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia
 ELSE
  UPDATE tm_MovCue SET VrSanNitAge=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitAgeCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitAgeCc] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16)
,@pmIdCCosto VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitAgeCcCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia AND IdCCosto=@pmIdCCosto
 ELSE
  UPDATE tm_MovCue SET VrSanNitAgeCc=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia AND IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitAgeCcSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitAgeCcSub] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmCodAgncia VARCHAR(16)
,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitAgeCcSubCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia 
  AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
 ELSE
  UPDATE tm_MovCue SET VrSanNitAgeCcSub=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero AND CodAgncia=@pmCodAgncia 
  AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitCc] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmIdCCosto VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitCcCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND IdCCosto=@pmIdCCosto
 ELSE
  UPDATE tm_MovCue SET VrSanNitCc=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero  AND IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitCcSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitCcSub] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitCcSubCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
 ELSE
  UPDATE tm_MovCue SET VrSanNitCcSub=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero AND  IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitVeh] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitVehCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND IdVehiculo=@pmIdVehiculo
 ELSE
  UPDATE tm_MovCue SET VrSanNitVeh=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero AND  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitVehCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitVehCc] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10)
,@pmIdCCosto VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanNitVehCcCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdTercero=@pmIdTercero AND IdVehiculo=@pmIdVehiculo AND IdCCosto=@pmIdCCosto
 ELSE
  UPDATE tm_MovCue SET VrSanNitVehCc=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND IdTercero=@pmIdTercero AND IdVehiculo=@pmIdVehiculo AND IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueNitVehCcSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueNitVehCcSub] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdTercero VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanVehCcSubCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdVehiculo=@pmIdVehiculo  AND IdTercero=@pmIdTercero
   AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
 ELSE
  UPDATE tm_MovCue SET VrSanVehCcSub=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND  IdVehiculo=@pmIdVehiculo AND IdTercero=@pmIdTercero
  AND  IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueSan] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16),@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanCueCia=@pmVrSaldo WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
 ELSE
  UPDATE tm_MovCue SET VrSanCue=@pmVrSaldo WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueVeh]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueVeh] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdVehiculo VARCHAR(10),@pmIdCia CHAR(2),@pmVrSaldo MONEY
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanVehCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia AND IdVehiculo=@pmIdVehiculo
 ELSE
  UPDATE tm_MovCue SET VrSanVeh=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueVehCc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueVehCc] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanVehCcCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdVehiculo=@pmIdVehiculo AND IdCCosto=@pmIdCCosto
 ELSE
  UPDATE tm_MovCue SET VrSanVehCc=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND  IdVehiculo=@pmIdVehiculo  AND IdCCosto=@pmIdCCosto
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovCueVehCcSub]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovCueVehCcSub] @pmTipo VARCHAR(3),@pmtmEst CHAR(2),@pmIdCuenta VARCHAR(16)
,@pmIdCia CHAR(2),@pmVrSaldo MONEY,@pmIdVehiculo VARCHAR(10),@pmIdCCosto VARCHAR(16)
,@pmIdSubCos VARCHAR(16)
 AS 
 IF @pmTipo='CIA'
  UPDATE tm_MovCue SET VrSanVehCcSubCia=@pmVrSaldo
   WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta AND IdCia=@pmIdCia
   AND IdVehiculo=@pmIdVehiculo AND IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
 ELSE
  UPDATE tm_MovCue SET VrSanVehCcSub=@pmVrSaldo
  WHERE  tmEst=@pmtmEst AND IdCuenta=@pmIdCuenta 
  AND  IdVehiculo=@pmIdVehiculo AND  IdCCosto=@pmIdCCosto AND IdSubCos=@pmIdSubCos
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovInventDos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovInventDos] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmEntradas2 DECIMAL(14,4),@pmtmSalidas2 DECIMAL(14,4),@pmtmCostoEnt2 MONEY,@pmtmCostoSal2 MONEY,@pmtmValorEnt2 MONEY
,@pmtmValorSal2 MONEY,@pmtmDctosEnt2 MONEY,@pmtmDctosSal2 MONEY,@pmtmIvaEnt2 MONEY,@pmtmIvaSal2 MONEY,@pmtmOtrosImpEnt2 MONEY,@pmtmOtrosImpSal2 MONEY,@pmtmUnidVolumen2 DECIMAL(14,4)
 AS 
 UPDATE tm_MovInvent SET  tmEntradas2=@pmtmEntradas2,tmSalidas2=@pmtmSalidas2,tmCostoEnt2=@pmtmCostoEnt2,tmCostoSal2=@pmtmCostoSal2,tmValorEnt2=@pmtmValorEnt2,tmValorSal2=@pmtmValorSal2
,tmDctosEnt2=@pmtmDctosEnt2,tmDctosSal2=@pmtmDctosSal2,tmIvaEnt2=@pmtmIvaEnt2,tmIvaSal2=@pmtmIvaSal2,tmOtrosImpEnt2=@pmtmOtrosImpEnt2,tmOtrosImpSal2=@pmtmOtrosImpSal2,tmUnidVolumen2=@pmtmUnidVolumen2
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovTanquesFis]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovTanquesFis] @pmtmEst CHAR(2),@pmtmIdProducto VARCHAR(16)
,@pmtmIdCia CHAR(2),@pmtmItem INT,@pmtmSaldoAntDia DECIMAL(14,4),@pmtmCostoAntDia MONEY
,@pmtmNuevoSaldo DECIMAL(14,4),@pmtmCostoNsal MONEY,@pmtmCantFisico DECIMAL(14,4)
,@pmtmCantAgua DECIMAL(14,4),@pmtmDiferencia DECIMAL(14,4)
 AS 
 UPDATE tm_MovTanques SET tmSaldoAntDia=@pmtmSaldoAntDia,tmCostoAntDia=@pmtmCostoAntDia
,tmNuevoSaldo=@pmtmNuevoSaldo,tmCostoNsal=@pmtmCostoNsal,tmCantFisico=@pmtmCantFisico
,tmCantAgua=@pmtmCantAgua,tmDiferencia=@pmtmDiferencia
 WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto AND  tmItem=@pmtmItem
 AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovTanquesSan]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_MovTanquesSan] @pmtmEst CHAR(2),@pmTipo VARCHAR(3),@pmtmIdProducto VARCHAR(16),@pmtmIdTanque VARCHAR(4)
,@pmtmIdCia CHAR(2),@pmtmSaldoAnt DECIMAL(14,4),@pmtmCostoAnt MONEY
 AS 
 IF @pmTipo='PRO' 
  UPDATE tm_MovTanques SET tmSaldoAntPro=@pmtmSaldoAnt,tmCostoSanPro=@pmtmCostoAnt   WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto 
 ELSE
  BEGIN 
    IF @pmTipo='CIA'
     UPDATE tm_MovTanques SET tmSaldoAntCia=@pmtmSaldoAnt,tmCostoSanCia=@pmtmCostoAnt  WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto  AND tmIdCia=@pmtmIdCia
    ELSE
      BEGIN
       IF @pmTipo='TAN'
         UPDATE tm_MovTanques SET tmSaldoAntTan=@pmtmSaldoAnt,tmCostoSanTan=@pmtmCostoAnt  WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto  AND tmIdTanque=@pmtmIdTanque
       ELSE
         UPDATE tm_MovTanques SET tmSaldoAnt=@pmtmSaldoAnt,tmCostoAnt=@pmtmCostoAnt  WHERE tmEst=@pmtmEst AND tmIdProducto=@pmtmIdProducto  AND  tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') AND tmIdTanque LIKE ISNULL(@pmtmIdTanque,'%')
      END
  END
GO
/****** Object:  StoredProcedure [dbo].[paUptm_MovVentasDos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_MovVentasDos] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmEntradas2 DECIMAL(14,4),@pmtmSalidas2 DECIMAL(14,4),@pmtmCostoEnt2 MONEY,@pmtmCostoSal2 MONEY,@pmtmValorEnt2 MONEY
,@pmtmValorSal2 MONEY,@pmtmDctosEnt2 MONEY,@pmtmDctosSal2 MONEY,@pmtmIvaEnt2 MONEY,@pmtmIvaSal2 MONEY,@pmtmImpGlobalEnt2 MONEY,@pmtmImpGlobalSal2 MONEY,@pmtmOtrosEnt2 MONEY
,@pmtmOtrosSal2 MONEY,@pmtmUnidVolumen2 DECIMAL(14,4),@pmtmImpConEnt2 MONEY,@pmtmImpConSal2 MONEY,@pmtmImpuBaEnt2 MONEY,@pmtmImpuBaSal2 MONEY,@pmtmImpuCupEnt2 MONEY,@pmtmImpuCupSal2 MONEY
 AS 
 UPDATE tm_MovVentas SET  tmEntradas2=@pmtmEntradas2,tmSalidas2=@pmtmSalidas2,tmCostoEnt2=@pmtmCostoEnt2,tmCostoSal2=@pmtmCostoSal2,tmValorEnt2=@pmtmValorEnt2,tmValorSal2=@pmtmValorSal2
,tmDctosEnt2=@pmtmDctosEnt2,tmDctosSal2=@pmtmDctosSal2,tmIvaEnt2=@pmtmIvaEnt2,tmIvaSal2=@pmtmIvaSal2,tmImpGlobalEnt2=@pmtmImpGlobalEnt2,tmImpGlobalSal2=@pmtmImpGlobalSal2,tmOtrosEnt2=@pmtmOtrosEnt2
,tmOtrosSal2=@pmtmOtrosSal2,tmUnidVolumen2=@pmtmUnidVolumen2,tmImpConEnt2=@pmtmImpConEnt2,tmImpConSal2=@pmtmImpConSal2,tmImpuBaEnt2=@pmtmImpuBaEnt2,tmImpuBaSal2=@pmtmImpuBaSal2,tmImpuCupEnt2=@pmtmImpuCupEnt2,tmImpuCupSal2=@pmtmImpuCupSal2
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_Nomina]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_Nomina] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT,@pmtmIdConcepto VARCHAR(4),@pmtmClaseCon VARCHAR(10),@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(10,4)
,@pmtmCantDed DECIMAL(10,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY,@pmtmUnidad VARCHAR(10),@pmtmClaseLiq VARCHAR(10),@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasCalc DECIMAL(10,4)
,@pmtmDiasNov DECIMAL(10,4),@pmtmCodFondo VARCHAR(8),@pmtmNPrestamo INT,@pmtmNCuota INT,@pmtmOrigCargue VARCHAR(10),@pmtmVrBaseLiq MONEY,@pmtmNContto INT,@pmtmFecIni SMALLDATETIME,@pmtmFecFin SMALLDATETIME,@pmtmIdPeriodo VARCHAR(8)
,@pmtmVrPension MONEY,@pmtmVrSalud MONEY,@pmtmBasExceso MONEY,@pmtmNitTercero VARCHAR(16),@pmtmHoraInicial DATETIME,@pmtmHoraFinal DATETIME,@pmtmTipoInc VARCHAR(20),@pmtmVrIngNoSal MONEY
 AS 
 UPDATE tm_Nomina SET tmIdConcepto=@pmtmIdConcepto,tmClaseCon=@pmtmClaseCon,tmDetalle=@pmtmDetalle,tmCantDevg=@pmtmCantDevg,tmCantDed=@pmtmCantDed,tmVrUnitario=@pmtmVrUnitario,tmVrTotDevg=@pmtmVrTotDevg,tmVrTotDed=@pmtmVrTotDed
,tmUnidad=@pmtmUnidad,tmClaseLiq=@pmtmClaseLiq,tmVrOrigen=@pmtmVrOrigen,tmTarifa=@pmtmTarifa,tmDiasCalc=@pmtmDiasCalc,tmDiasNov=@pmtmDiasNov,tmCodFondo=@pmtmCodFondo,tmNPrestamo=@pmtmNPrestamo,tmNCuota=@pmtmNCuota,tmOrigCargue=@pmtmOrigCargue
,tmVrBaseLiq=@pmtmVrBaseLiq,tmNContto=@pmtmNContto,tmFecIni=@pmtmFecIni,tmFecFin=@pmtmFecFin,tmIdPeriodo=@pmtmIdPeriodo,tmVrPension=@pmtmVrPension,tmVrSalud=@pmtmVrSalud,tmBasExceso=@pmtmBasExceso,tmNitTercero=@pmtmNitTercero
,tmHoraInicial=@pmtmHoraInicial,tmHoraFinal=@pmtmHoraFinal,tmTipoInc=@pmtmTipoInc,tmVrIngNoSal=@pmtmVrIngNoSal
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_NominaPar]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_NominaPar] @pmtmNumero VARCHAR(5),@pmtmIdEmpleado VARCHAR(16),@pmtmItem INT,@pmtmDetalle VARCHAR(100),@pmtmCantDevg DECIMAL(10,4),@pmtmCantDed DECIMAL(10,4),@pmtmVrUnitario MONEY,@pmtmVrTotDevg MONEY,@pmtmVrTotDed MONEY,@pmtmUnidad VARCHAR(10)
,@pmtmVrOrigen MONEY,@pmtmTarifa DECIMAL(10,4),@pmtmDiasCalc DECIMAL(10,4),@pmtmDiasNov DECIMAL(10,4),@pmtmVrBaseLiq MONEY,@pmtmFecIni SMALLDATETIME,@pmtmFecFin SMALLDATETIME,@pmtmFecUltLiq SMALLDATETIME
 AS 
 UPDATE tm_Nomina SET tmDetalle=@pmtmDetalle,tmCantDevg=@pmtmCantDevg,tmCantDed=@pmtmCantDed,tmVrUnitario=@pmtmVrUnitario,tmVrTotDevg=@pmtmVrTotDevg,tmVrTotDed=@pmtmVrTotDed,tmUnidad=@pmtmUnidad,tmVrOrigen=@pmtmVrOrigen
,tmTarifa=@pmtmTarifa,tmDiasCalc=@pmtmDiasCalc,tmDiasNov=@pmtmDiasNov,tmVrBaseLiq=@pmtmVrBaseLiq,tmFecIni=@pmtmFecIni,tmFecFin=@pmtmFecFin,tmFecUltLiq=@pmtmFecUltLiq
 WHERE tmNumero=@pmtmNumero AND tmIdEmpleado=@pmtmIdEmpleado AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PagosCam]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_PagosCam] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmVrCambio MONEY
 AS 
 UPDATE  tm_Pagos  SET tmVrCambio=@pmtmVrCambio
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PagosTap]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_PagosTap] @pmtmNumero VARCHAR(5),@pmtmItem INT,@pmtmTipAplica VARCHAR(10)
 AS 
 UPDATE  tm_Pagos  SET tmTipAplica=@pmtmTipAplica
 WHERE tmNumero=@pmtmNumero AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PlasueldosObs]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_PlasueldosObs] @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30),@pmtmObserv VARCHAR(1000)
 AS 
 UPDATE  tm_Plasueldos  SET tmObserv=@pmtmObserv
 WHERE tmIdPeriodo=@pmtmIdPeriodo AND tmKeyRegistro LIKE ISNULL(@pmtmKeyRegistro,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PlasueldosVac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_PlasueldosVac] @pmtmIdPeriodo VARCHAR(8),@pmtmKeyRegistro VARCHAR(30)
,@pmtmVrVacLiquida MONEY,@pmtmVrVacPen MONEY,@pmtmVrVacSal MONEY,@pmtmVrVacFsp MONEY,@pmtmVrVacOtr MONEY
 AS 
 UPDATE  tm_Plasueldos  SET tmVrVacLiquida=@pmtmVrVacLiquida,tmVrVacPen=@pmtmVrVacPen
,tmVrVacSal=@pmtmVrVacSal,tmVrVacFsp=@pmtmVrVacFsp,tmVrVacOtr=@pmtmVrVacOtr
 WHERE tmIdPeriodo=@pmtmIdPeriodo  AND tmKeyRegistro=@pmtmKeyRegistro
GO
/****** Object:  StoredProcedure [dbo].[paUptm_PreExtoCuo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_PreExtoCuo] @pmtmEst CHAR(2),@pmtmTipoRep INT,@pmFechaIni SMALLDATETIME,@pmFechaFin SMALLDATETIME
 AS 
 UPDATE tm_PreExto SET tmCargos=ISNULL((SELECT SUM(VrTotal) FROM Trn_FinCuotas WHERE TipDoc='PR1' AND TipDoc=tmTipDoc AND IdPrestamo=tmNumero
 AND IdCia=tmIdCia AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Concepto='CAPITAL'),0)
--CUOTA
,tmNCuota=ISNULL((SELECT MAX(NumCuota) FROM Trn_FinCuotas WHERE TipDoc='PR1' AND TipDoc=tmTipDoc AND IdPrestamo=tmNumero
 AND IdCia=tmIdCia AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Concepto='CAPITAL'),0)
,tmDTF_EA=ISNULL((SELECT MAX(DTF_EA) FROM Trn_FinCuotas WHERE TipDoc='PR1' AND TipDoc=tmTipDoc AND IdPrestamo=tmNumero
 AND IdCia=tmIdCia AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Concepto='CAPITAL'),0)
,tmTasaNom=ISNULL((SELECT MAX(TasaNom) FROM Trn_FinCuotas WHERE TipDoc='PR1' AND TipDoc=tmTipDoc AND IdPrestamo=tmNumero
 AND IdCia=tmIdCia AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Concepto='CAPITAL'),0)
,tmTasaEfe=ISNULL((SELECT MAX(TasaEfe) FROM Trn_FinCuotas WHERE TipDoc='PR1' AND TipDoc=tmTipDoc AND IdPrestamo=tmNumero
 AND IdCia=tmIdCia AND Fecha BETWEEN @pmFechaIni AND @pmFechaFin AND Concepto='CAPITAL'),0)
 WHERE tmEst=@pmtmEst AND tmTipoRep=@pmtmTipoRep AND tmTipDoc='PR1' AND tmConcepto='CAPITAL'
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_SaldosAnt] @pmtmEst CHAR(2),@pmtmIdCia CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdTercero VARCHAR(16),@pmtmCdSubgrupo VARCHAR(8),@pmtmCostoAnt MONEY,@pmtmSaldoAnt DECIMAL(14,4)
 AS 
 UPDATE tm_Saldos SET tmCostoAnt=@pmtmCostoAnt,tmSaldoAnt=@pmtmSaldoAnt
 WHERE tmEst=@pmtmEst AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%') AND tmIdCuenta LIKE ISNULL(@pmtmIdCuenta,'%')
 AND tmIdTercero LIKE ISNULL(@pmtmIdTercero,'%') AND tmCdSubgrupo LIKE ISNULL(@pmtmCdSubgrupo,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosCos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_SaldosCos] @pmtmEst CHAR(2),@pmtmIdCia CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdTercero VARCHAR(16),@pmtmCostoEnt MONEY,@pmtmCostoSal MONEY
 AS 
 UPDATE tm_Saldos SET tmCostoEnt=@pmtmCostoEnt,tmCostoSal=@pmtmCostoSal
 WHERE tmEst=@pmtmEst AND tmIdCia=@pmtmIdCia AND tmIdCuenta=@pmtmIdCuenta AND tmIdTercero=@pmtmIdTercero
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosCue]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_SaldosCue] @pmtmEst CHAR(2),@pmtmIdCia CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdTercero VARCHAR(16),@pmtmCdSubgrupo VARCHAR(8),@pmtmSanCue MONEY
 AS 
 UPDATE tm_Saldos SET tmSanCue=@pmtmSanCue
 WHERE tmEst=@pmtmEst AND tmIdCuenta=@pmtmIdCuenta  AND tmIdTercero=@pmtmIdTercero 
 AND tmCdSubgrupo LIKE ISNULL(@pmtmCdSubgrupo,'%') AND tmIdCia LIKE ISNULL(@pmtmIdCia,'%%')
GO
/****** Object:  StoredProcedure [dbo].[paUptm_SaldosMov]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_SaldosMov] @pmtmEst CHAR(2),@pmtmIdCia CHAR(2),@pmtmIdCuenta VARCHAR(16)
,@pmtmIdTercero VARCHAR(16),@pmtmCdSubgrupo VARCHAR(8),@pmtmDebitos MONEY,@pmtmCreditos MONEY
 AS 
 UPDATE tm_Saldos SET tmDebitos=@pmtmDebitos,tmCreditos=@pmtmCreditos
 WHERE tmEst=@pmtmEst AND tmIdCia=@pmtmIdCia AND tmIdCuenta=@pmtmIdCuenta
 AND tmIdTercero=@pmtmIdTercero AND tmCdSubgrupo=@pmtmCdSubgrupo
GO
/****** Object:  StoredProcedure [dbo].[paUptm_vce]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptm_vce] @pmtmTipDoc VARCHAR(3),@pmtmDocumento INT,@pmtmIdCia CHAR(2),@pmtmItem INT
,@pmtmValorAbono MONEY,@pmtmFecUltPago SMALLDATETIME
 AS 
 UPDATE tm_vce SET tmValorAbono=@pmtmValorAbono,tmFecUltPago=@pmtmFecUltPago
 WHERE tmTipDoc=@pmtmTipDoc AND tmDocumento=@pmtmDocumento AND tmIdCia=@pmtmIdCia AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUptm_VentasCom]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUptm_VentasCom] @pmtmEst CHAR(2),@pmtmItem INT,@pmtmUnidades2 DECIMAL(14,4),@pmtmVentaNeto2 MONEY
,@pmtmCostoNeto2 MONEY,@pmtmImpuestos2 MONEY,@pmtmImpGlobal2 MONEY,@pmtmSoldicom2 MONEY,@pmtmVolumen2 DECIMAL(14,4),@pmtmImpConsumo2 MONEY,@pmtmImpuBa2 MONEY,@pmtmImpuCup2 MONEY 
 AS 
 UPDATE tm_VentasCom SET tmUnidades2=@pmtmUnidades2,tmVentaNeto2=@pmtmVentaNeto2,tmCostoNeto2=@pmtmCostoNeto2
,tmImpuestos2=@pmtmImpuestos2,tmImpGlobal2=@pmtmImpGlobal2,tmSoldicom2=@pmtmSoldicom2,tmVolumen2=@pmtmVolumen2,tmImpConsumo2=@pmtmImpConsumo2,tmImpuBa2=@pmtmImpuBa2,tmImpuCup2=@pmtmImpuCup2 
 WHERE tmEst=@pmtmEst AND tmItem=@pmtmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticipos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraAnticipos] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVrAnticipo MONEY,@pmVrAbonado MONEY,@pmModalidad VARCHAR(10)
,@pmTipoPago VARCHAR(10),@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmBeneficiario VARCHAR(150),@pmCantidad DECIMAL(14,4),@pmFechaVence SMALLDATETIME,@pmNumPresAnt INT, @pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCedBenef VARCHAR(16),@pmPreAnticipo INT,@pmNumCargue INT,@pmCiaCargue CHAR(2),@pmVrDeduccion MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraAnticipos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipMuc=@pmTipMuc,Manifiesto=@pmManifiesto,IdCiaMuc=@pmIdCiaMuc,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,VrAnticipo=@pmVrAnticipo,VrAbonado=@pmVrAbonado,Modalidad=@pmModalidad,TipoPago=@pmTipoPago,NumCheque=@pmNumCheque,FecCheque=@pmFecCheque
,IdCta=@pmIdCta,IdCuenta=@pmIdCuenta,Beneficiario=@pmBeneficiario,Cantidad=@pmCantidad,FechaVence=@pmFechaVence,NumPresAnt=@pmNumPresAnt,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CedBenef=@pmCedBenef
,PreAnticipo=@pmPreAnticipo,FecUpdate=@pmFecUpdate,NumCargue=@pmNumCargue,CiaCargue=@pmCiaCargue,VrDeduccion=@pmVrDeduccion
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticiposAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraAnticiposAnu] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2),@pmVrAbonado MONEY
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraAnticipos SET  VrAbonado=@pmVrAbonado,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticiposApl]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraAnticiposApl] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2)
 AS 
 UPDATE Trn_TraAnticipos SET  VrAbonado=(SELECT ISNULL(SUM(Trn_TraAntAbonos.VrAbono),0)
 FROM Trn_TraAntAbonos WHERE Trn_TraAntAbonos.TipAnt=Trn_TraAnticipos.TipDoc AND Trn_TraAntAbonos.Anticipo=Trn_TraAnticipos.Anticipo
  AND Trn_TraAntAbonos.IdCiaAnt=Trn_TraAnticipos.IdCia)
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraAnticiposApp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraAnticiposApp] @pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS 
 UPDATE Trn_TraAnticipos SET  VrAbonado=(SELECT ISNULL(SUM(Trn_TraAntAbonos.VrAbono),0)
 FROM Trn_TraAntAbonos WHERE Trn_TraAntAbonos.TipAnt=Trn_TraAnticipos.TipDoc AND Trn_TraAntAbonos.Anticipo=Trn_TraAnticipos.Anticipo
  AND Trn_TraAntAbonos.IdCiaAnt=Trn_TraAnticipos.IdCia)
 WHERE  IdCia LIKE ISNULL(@pmIdCia,'%%') AND IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdPoseedor LIKE ISNULL(@pmIdPoseedor,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCausacion]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraCausacion] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdProv VARCHAR(16),@pmFactura VARCHAR(20),@pmVrTotal MONEY
,@pmVrOtros MONEY,@pmVrNeto MONEY,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraCausacion SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdProv=@pmIdProv,Factura=@pmFactura,VrTotal=@pmVrTotal,VrOtros=@pmVrOtros,VrNeto=@pmVrNeto,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCausacionAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraCausacionAnu] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraCausacion SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraConcCausac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraConcCausac] @pmIdConcepto VARCHAR(4),@pmConcepto VARCHAR(250),@pmIdCuenta VARCHAR(16)
,@pmTipoConc VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE TraConcCausac SET Concepto=@pmConcepto,IdCuenta=@pmIdCuenta,TipoConc=@pmTipoConc,Inactivo=@pmInactivo
 WHERE IdConcepto=@pmIdConcepto
GO
/****** Object:  StoredProcedure [dbo].[paUpTraConceptos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraConceptos]  @pmTipDoc VARCHAR(3),@pmDocumento INT,@pmIdCia CHAR(2),@pmItem INT,@pmDescripcion VARCHAR(250),@pmTarifa DECIMAL(14,4),@pmTipoConc VARCHAR(10),@pmRubroConcep VARCHAR(20),@pmCantidad DECIMAL(14,4)
,@pmVrUnitario MONEY,@pmTarifIva DECIMAL(14,4),@pmIdConcepto VARCHAR(4),@pmCdCuenta VARCHAR(16),@pmNitTercero VARCHAR(16),@pmCdTipoEsc VARCHAR(4),@pmFechaNov SMALLDATETIME,@pmVrBase MONEY,@pmTipoTarif CHAR(1),@pmRefConc VARCHAR(50)
,@pmFijos BIT,@pmIncBaseRet INT,@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmEst_Factura INT,@pmEst_Liquida INT,@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmCiaFact CHAR(2),@pmVrTotalFact MONEY,@pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmCiaLiq CHAR(2),@pmVrTotalLiq MONEY
 AS 
 UPDATE Trn_TraConceptos SET Descripcion=@pmDescripcion,Tarifa=@pmTarifa,TipoConc=@pmTipoConc,RubroConcep=@pmRubroConcep,Cantidad=@pmCantidad,VrUnitario=@pmVrUnitario,TarifIva=@pmTarifIva,IdConcepto=@pmIdConcepto,CdCuenta=@pmCdCuenta
,NitTercero=@pmNitTercero,CdTipoEsc=@pmCdTipoEsc,FechaNov=@pmFechaNov,VrBase=@pmVrBase,TipoTarif=@pmTipoTarif,RefConc=@pmRefConc,Fijos=@pmFijos,IncBaseRet=@pmIncBaseRet,Referencia2=@pmReferencia2,Referencia3=@pmReferencia3
,Est_Factura=@pmEst_Factura,Est_Liquida=@pmEst_Liquida,TipFact=@pmTipFact,NumFactura=@pmNumFactura,CiaFact=@pmCiaFact,VrTotalFact=@pmVrTotalFact,TipLiq=@pmTipLiq,NumLiquida=@pmNumLiquida,CiaLiq=@pmCiaLiq,VrTotalLiq=@pmVrTotalLiq
 WHERE TipDoc=@pmTipDoc AND Documento=@pmDocumento AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCumplido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraCumplido] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmModalidad VARCHAR(10),@pmDiasPlazo INT
,@pmFecPago SMALLDATETIME,@pmTipoMargen VARCHAR(10),@pmMargenFalt DECIMAL(14,4),@pmUndCalcFalt VARCHAR(10),@pmTarifFaltPago MONEY,@pmTarifFaltCobro MONEY,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4)
,@pmNRadicaDoc INT,@pmIdCiaRadic CHAR(2),@pmCdCiaOfic CHAR(2),@pmFecRadic SMALLDATETIME,@pmCdRuta VARCHAR(4),@pmCdOrigen VARCHAR(8),@pmCdDestino VARCHAR(8),@pmTipoComp VARCHAR(3),@pmNumComp INT,@pmCodConcepto VARCHAR(4)
,@pmTipoCumpMT VARCHAR(3),@pmMotivoSusp VARCHAR(3),@pmConsecSusp VARCHAR(3),@pmVrAdicCargue DECIMAL(16,4),@pmVrAdicDescargue DECIMAL(16,4),@pmVrAdicFlete DECIMAL(16,4),@pmMotivoVrAdic VARCHAR(3)
,@pmVrDctoFlete DECIMAL(16,4),@pmMotivoVrDcto VARCHAR(3),@pmVrAdicAnticipo DECIMAL(16,4),@pmFecEntregaDoc SMALLDATETIME,@pmMvoAnulaCump VARCHAR(5),@pmObservAnulado VARCHAR(250),@pmNumViajesCum INT,@pmPesoLiqPago INT,@pmPesoLiqFact INT,@pmCdPlazoPago VARCHAR(4)
,@pmNumDevCum INT,@pmMvoRechazo INT,@pmMunOrigVacio1 VARCHAR(8),@pmMunDestVacio1 VARCHAR(8),@pmMunOrigVacio2 VARCHAR(8),@pmMunDestVacio2 VARCHAR(8),@pmVrTrayVacio1 MONEY,@pmVrTrayVacio2 MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraCumplido SET Fecha=@pmFecha,TipMuc=@pmTipMuc,Manifiesto=@pmManifiesto,IdCiaMuc=@pmIdCiaMuc,IdVehiculo=@pmIdVehiculo,Modalidad=@pmModalidad,DiasPlazo=@pmDiasPlazo,FecPago=@pmFecPago,TipoMargen=@pmTipoMargen
,MargenFalt=@pmMargenFalt,UndCalcFalt=@pmUndCalcFalt,TarifFaltPago=@pmTarifFaltPago,TarifFaltCobro=@pmTarifFaltCobro,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,NRadicaDoc=@pmNRadicaDoc,IdCiaRadic=@pmIdCiaRadic,CdCiaOfic=@pmCdCiaOfic,FecRadic=@pmFecRadic,CdRuta=@pmCdRuta,CdOrigen=@pmCdOrigen,CdDestino=@pmCdDestino,TipoComp=@pmTipoComp,NumComp=@pmNumComp,CodConcepto=@pmCodConcepto,FecUpdate=@pmFecUpdate
,TipoCumpMT=@pmTipoCumpMT,MotivoSusp=@pmMotivoSusp,ConsecSusp=@pmConsecSusp,VrAdicCargue=@pmVrAdicCargue,VrAdicDescargue=@pmVrAdicDescargue,VrAdicFlete=@pmVrAdicFlete,MotivoVrAdic=@pmMotivoVrAdic,VrDctoFlete=@pmVrDctoFlete
,MotivoVrDcto=@pmMotivoVrDcto,VrAdicAnticipo=@pmVrAdicAnticipo,FecEntregaDoc=@pmFecEntregaDoc,MvoAnulaCump=@pmMvoAnulaCump,ObservAnulado=@pmObservAnulado,NumViajesCum=@pmNumViajesCum,PesoLiqPago=@pmPesoLiqPago,PesoLiqFact=@pmPesoLiqFact,CdPlazoPago=@pmCdPlazoPago
,NumDevCum=@pmNumDevCum,MvoRechazo=@pmMvoRechazo,MunOrigVacio1=@pmMunOrigVacio1,MunDestVacio1=@pmMunDestVacio1,MunOrigVacio2=@pmMunOrigVacio2,MunDestVacio2=@pmMunDestVacio2,VrTrayVacio1=@pmVrTrayVacio1,VrTrayVacio2=@pmVrTrayVacio2
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCumplidoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraCumplidoAnu] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4)
,@pmMvoAnulaCump VARCHAR(5),@pmObservAnulado VARCHAR(250),@pmNumDevCum INT,@pmMvoRechazo INT
 AS 
 UPDATE Trn_TraCumplido SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
,MvoAnulaCump=@pmMvoAnulaCump,ObservAnulado=@pmObservAnulado,NumDevCum=@pmNumDevCum,MvoRechazo=@pmMvoRechazo
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraCumRadica]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraCumRadica] @pmNumRadica INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmCdCiaRad CHAR(2),@pmDocAnexos VARCHAR(1000),@pmCantDoc INT,@pmFormaEnvio VARCHAR(50)
,@pmNomRadica VARCHAR(150),@pmCedRadica VARCHAR(16),@pmFuncionario VARCHAR(150),@pmObservacion VARCHAR(2000),@pmNumeroCum INT,@pmIdCiaCum CHAR(2),@pmFechaCum SMALLDATETIME
 AS 
 UPDATE Trn_TraCumRadica SET Fecha=@pmFecha,TipMuc=@pmTipMuc,Manifiesto=@pmManifiesto,IdCiaMuc=@pmIdCiaMuc,CdCiaRad=@pmCdCiaRad,DocAnexos=@pmDocAnexos,CantDoc=@pmCantDoc,FormaEnvio=@pmFormaEnvio,NomRadica=@pmNomRadica,CedRadica=@pmCedRadica,Funcionario=@pmFuncionario
,Observacion=@pmObservacion,NumeroCum=@pmNumeroCum,IdCiaCum=@pmIdCiaCum,FechaCum=@pmFechaCum
 WHERE NumRadica=@pmNumRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDecAduana]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDecAduana] @pmTipDoc VARCHAR(3),@pmNumDeclara INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdAduCarga VARCHAR(4),@pmIdDestino VARCHAR(8),@pmIdAduOrigen VARCHAR(4),@pmIdAduDestino VARCHAR(4),@pmIdAduFrontera VARCHAR(4),@pmIdDeclarante VARCHAR(16),@pmDeclarante VARCHAR(150),@pmDirDeclara VARCHAR(250),@pmCdLocalDec VARCHAR(8),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirOrigen VARCHAR(250),@pmCdLocalRem VARCHAR(8),@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDestino VARCHAR(250)
,@pmCdLocalDest VARCHAR(8),@pmIdConsig VARCHAR(16),@pmConsignatario VARCHAR(150),@pmDirConsig VARCHAR(250),@pmCdLocalConsig VARCHAR(8),@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmDocAnexos VARCHAR(500),@pmVehiculos VARCHAR(250),@pmRemolques VARCHAR(250),@pmManifiestos VARCHAR(100),@pmContenedores VARCHAR(500),@pmPrecintos VARCHAR(250),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmCondicPago VARCHAR(1000),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDecAduana SET Fecha=@pmFecha,FecEmision=@pmFecEmision,IdOrigen=@pmIdOrigen,IdAduCarga=@pmIdAduCarga,IdDestino=@pmIdDestino,IdAduOrigen=@pmIdAduOrigen,IdAduDestino=@pmIdAduDestino,IdAduFrontera=@pmIdAduFrontera,IdDeclarante=@pmIdDeclarante,Declarante=@pmDeclarante,DirDeclara=@pmDirDeclara,CdLocalDec=@pmCdLocalDec,IdRemitente=@pmIdRemitente,Remitente=@pmRemitente,DirOrigen=@pmDirOrigen,CdLocalRem=@pmCdLocalRem,IdDestinatario=@pmIdDestinatario,Destinatario=@pmDestinatario,DirDestino=@pmDirDestino,CdLocalDest=@pmCdLocalDest,IdConsig=@pmIdConsig,Consignatario=@pmConsignatario,DirConsig=@pmDirConsig
,CdLocalConsig=@pmCdLocalConsig,IdMoneda=@pmIdMoneda,ValorTotal=@pmValorTotal,PesoTotal=@pmPesoTotal,DocAnexos=@pmDocAnexos,Vehiculos=@pmVehiculos,Remolques=@pmRemolques,Manifiestos=@pmManifiestos,Contenedores=@pmContenedores,Precintos=@pmPrecintos,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Negociacion=@pmNegociacion,CondicPago=@pmCondicPago
 WHERE TipDoc=@pmTipDoc AND NumDeclara=@pmNumDeclara AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDespachos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDespachos] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdRuta VARCHAR(4)
,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmNitRemite VARCHAR(16),@pmRemitente VARCHAR(250),@pmNitDestntario VARCHAR(16),@pmDestinatario VARCHAR(250),@pmDescMcia VARCHAR(150),@pmPesoTotal DECIMAL(14,4)
,@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmEstado INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDespachos SET Fecha=@pmFecha,FecCargue=@pmFecCargue,FecDespacho=@pmFecDespacho,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdRuta=@pmIdRuta,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdPoseedor=@pmIdPoseedor
,NitRemite=@pmNitRemite,Remitente=@pmRemitente,NitDestntario=@pmNitDestntario,Destinatario=@pmDestinatario,DescMcia=@pmDescMcia,PesoTotal=@pmPesoTotal,NumOrden=@pmNumOrden,IdCiaOrd=@pmIdCiaOrd,Remesa=@pmRemesa,IdCiaRem=@pmIdCiaRem
,Estado=@pmEstado,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDespachosAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraDespachosAnu] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
,@pmEstado INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250)
 AS 
 UPDATE Trn_TraDespachos SET Estado=@pmEstado,Anulado=@pmAnulado,FecDev=@pmFecDev
,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDespProgram]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraDespProgram] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmCdRuta VARCHAR(4),@pmIdPunto INT,@pmHoraProg SMALLDATETIME
,@pmTipoProg INT,@pmObservProg VARCHAR(250)
 AS 
 UPDATE Trn_TraDespProgram SET CdRuta=@pmCdRuta,IdPunto=@pmIdPunto,HoraProg=@pmHoraProg,TipoProg=@pmTipoProg,ObservProg=@pmObservProg
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevAnt] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdVehiculo VARCHAR(10)
,@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmVrDevolucion MONEY,@pmCdCta VARCHAR(4),@pmCdCuenta VARCHAR(16),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevAnt SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Anticipo=@pmAnticipo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,VrDevolucion=@pmVrDevolucion
,CdCta=@pmCdCta,CdCuenta=@pmCdCuenta,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevAos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevAos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrDevolucion MONEY,@pmCdCta VARCHAR(4),@pmCdCuenta VARCHAR(16),@pmModdDev VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevAos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Anticipo=@pmAnticipo,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,VrDevolucion=@pmVrDevolucion,CdCta=@pmCdCta,CdCuenta=@pmCdCuenta,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevCau]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevCau] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdProv VARCHAR(16),@pmFactura VARCHAR(20),@pmVrTotal MONEY,@pmVrOtros MONEY
,@pmVrNeto MONEY,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevCau SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Causacion=@pmCausacion,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdProv=@pmIdProv,Factura=@pmFactura,VrTotal=@pmVrTotal,VrOtros=@pmVrOtros,VrNeto=@pmVrNeto,ModdDev=@pmModdDev
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevCos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevCos] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCiaDoc CHAR(2)
,@pmFecDoc SMALLDATETIME,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250)
 AS 
 UPDATE Trn_TraDevCos SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Cumplido=@pmCumplido,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,ModdDev=@pmModdDev
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevLeg]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevLeg] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmModalidad VARCHAR(10),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16)
,@pmNitEmpresa VARCHAR(16),@pmVrAnticipos MONEY,@pmVrGastos MONEY,@pmVrCombustible MONEY,@pmVrDiferencia MONEY,@pmgalsComb DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrOtrosCred MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevLeg SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Liquidacion=@pmLiquidacion,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,Modalidad=@pmModalidad,TipMuc=@pmTipMuc,Manifiesto=@pmManifiesto,IdCiaMuc=@pmIdCiaMuc,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdPropietario=@pmIdPropietario,IdPoseedor=@pmIdPoseedor,NitEmpresa=@pmNitEmpresa,VrAnticipos=@pmVrAnticipos,VrGastos=@pmVrGastos,VrCombustible=@pmVrCombustible
,VrDiferencia=@pmVrDiferencia,VrOtrosCred=@pmVrOtrosCred,galsComb=@pmgalsComb,PesoTotal=@pmPesoTotal,Cantidad=@pmCantidad,Volumen=@pmVolumen,ModdDev=@pmModdDev,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevLgo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevLgo] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmVrTotal MONEY,@pmVrCosto MONEY,@pmVrAnticipo MONEY,@pmVrGastos MONEY,@pmVrIva MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY
,@pmVrReteCREE MONEY,@pmVrReteIva MONEY,@pmVrOtros MONEY,@pmVrDescuento MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmCxPagar BIT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmModdDev VARCHAR(10),@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmVrImpAvTa MONEY,@pmVrBomberil MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevLgo SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Liquidacion=@pmLiquidacion,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,VrTotal=@pmVrTotal,VrCosto=@pmVrCosto,VrAnticipo=@pmVrAnticipo,VrGastos=@pmVrGastos,VrIva=@pmVrIva,VrRetencion=@pmVrRetencion,VrReteIca=@pmVrReteIca,VrReteCREE=@pmVrReteCREE,VrReteIva=@pmVrReteIva,VrOtros=@pmVrOtros
,VrDescuento=@pmVrDescuento,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,CxPagar=@pmCxPagar,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion,VrImpAvTa=@pmVrImpAvTa,VrBomberil=@pmVrBomberil,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate 
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevOdp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevOdp] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdVehiculo VARCHAR(10)
,@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmCxPagar BIT,@pmModdDev VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevOdp SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,OrdPago=@pmOrdPago,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,CxPagar=@pmCxPagar,ModdDev=@pmModdDev
,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraDevReex]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraDevReex] @pmTipDev VARCHAR(3),@pmDevolucion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCiaDoc CHAR(2),@pmFecDoc SMALLDATETIME,@pmIdEmpTrans VARCHAR(16),@pmNumFactura VARCHAR(15)
,@pmFecFactura SMALLDATETIME,@pmVrTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrOtrosCargos MONEY,@pmVrOtrosDctos MONEY,@pmVrNeto MONEY,@pmPesoTotal DECIMAL(14,4),@pmCxPagar BIT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmModdDev VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraDevReex SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipDoc=@pmTipDoc,Causacion=@pmCausacion,IdCiaDoc=@pmIdCiaDoc,FecDoc=@pmFecDoc,IdEmpTrans=@pmIdEmpTrans,NumFactura=@pmNumFactura,FecFactura=@pmFecFactura,VrTotal=@pmVrTotal,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteIca=@pmVrReteIca
,VrOtrosCargos=@pmVrOtrosCargos,VrOtrosDctos=@pmVrOtrosDctos,VrNeto=@pmVrNeto,PesoTotal=@pmPesoTotal,CxPagar=@pmCxPagar,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,ModdDev=@pmModdDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDev=@pmTipDev AND Devolucion=@pmDevolucion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraFijos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraFijos] @pmNumero INT,@pmIdConcepto VARCHAR(4),@pmDescConc VARCHAR(250),@pmTipoConc VARCHAR(10),@pmTarifa DECIMAL(14,4),@pmTipoTarif CHAR(1),@pmTipoAfilVeh VARCHAR(10)
,@pmCdTipoVeh VARCHAR(4),@pmAnulado BIT,@pmTipoTerc CHAR(1),@pmCdCiuOrigen VARCHAR(8),@pmCdCiuDestino VARCHAR(8),@pmpVehiculo VARCHAR(10),@pmCedConductor VARCHAR(16),@pmCdRuta VARCHAR(4)
,@pmTipoVigencia CHAR(1),@pmFechaInicial SMALLDATETIME,@pmFechaFinal SMALLDATETIME,@pmNitCliente VARCHAR(16),@pmCdMercancia VARCHAR(16),@pmIdentProp VARCHAR(16)
 AS 
 UPDATE TraFijos SET IdConcepto=@pmIdConcepto,DescConc=@pmDescConc,TipoConc=@pmTipoConc,Tarifa=@pmTarifa,TipoTarif=@pmTipoTarif,TipoAfilVeh=@pmTipoAfilVeh,CdTipoVeh=@pmCdTipoVeh
,Anulado=@pmAnulado,TipoTerc=@pmTipoTerc,CdCiuOrigen=@pmCdCiuOrigen,CdCiuDestino=@pmCdCiuDestino,pVehiculo=@pmpVehiculo,CedConductor=@pmCedConductor,CdRuta=@pmCdRuta
,TipoVigencia=@pmTipoVigencia,FechaInicial=@pmFechaInicial,FechaFinal=@pmFechaFinal,NitCliente=@pmNitCliente,CdMercancia=@pmCdMercancia,IdentProp=@pmIdentProp
 WHERE Numero=@pmNumero
GO
/****** Object:  StoredProcedure [dbo].[paUpTraGuias]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraGuias] @pmTipDoc VARCHAR(3),@pmNumGuia INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmModalidad VARCHAR(10),@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmNomRemitente VARCHAR(150),@pmIdDestinatario VARCHAR(16),@pmNomDestinatario VARCHAR(150),@pmDirOrigen VARCHAR(250),@pmIdLocOrigen VARCHAR(8),@pmDirDestino VARCHAR(250),@pmIdLocDestino VARCHAR(8),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(150),@pmTelRemitente VARCHAR(30),@pmemlRemitente VARCHAR(150),@pmTelDestinatario VARCHAR(30),@pmemlDestinatario VARCHAR(150),@pmIdResponsable VARCHAR(16),@pmNomResponsable VARCHAR(150),@pmVrTotal MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmVrCargos MONEY,@pmCantidad DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmTipRem VARCHAR(3)
,@pmNumRemesa INT,@pmIdCiaRem CHAR(2),@pmEstFactura INT,@pmTipFac VARCHAR(3),@pmNumFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmCdConcepto VARCHAR(4),@pmCdForma VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2000),@pmIdEstado VARCHAR(4),@pmEstLiquida INT,@pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmIdCiaLiq CHAR(2),@pmNumRemision VARCHAR(20),@pmFechaModif SMALLDATETIME
 AS 
 UPDATE Trn_TraGuias SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,FecVigencia=@pmFecVigencia,Modalidad=@pmModalidad,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdRemitente=@pmIdRemitente,NomRemitente=@pmNomRemitente,IdDestinatario=@pmIdDestinatario,NomDestinatario=@pmNomDestinatario,DirOrigen=@pmDirOrigen,IdLocOrigen=@pmIdLocOrigen,DirDestino=@pmDirDestino,IdLocDestino=@pmIdLocDestino,NomContacto=@pmNomContacto,TelContacto=@pmTelContacto,emlContacto=@pmemlContacto,TelRemitente=@pmTelRemitente,emlRemitente=@pmemlRemitente,TelDestinatario=@pmTelDestinatario,emlDestinatario=@pmemlDestinatario,IdResponsable=@pmIdResponsable,NomResponsable=@pmNomResponsable,VrTotal=@pmVrTotal,VrDeclarado=@pmVrDeclarado,VrSeguro=@pmVrSeguro,VrCargos=@pmVrCargos,Cantidad=@pmCantidad,PesoTotal=@pmPesoTotal,TipRem=@pmTipRem,NumRemesa=@pmNumRemesa,IdCiaRem=@pmIdCiaRem
,EstFactura=@pmEstFactura,TipFac=@pmTipFac,NumFactura=@pmNumFactura,IdCiaFac=@pmIdCiaFac,FechaFac=@pmFechaFac,EstLiquida=@pmEstLiquida,TipLiq=@pmTipLiq,NumLiquida=@pmNumLiquida,IdCiaLiq=@pmIdCiaLiq,NumRemision=@pmNumRemision
,CdConcepto=@pmCdConcepto,CdForma=@pmCdForma,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FechaModif=@pmFechaModif
 WHERE TipDoc=@pmTipDoc AND NumGuia=@pmNumGuia AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraInfViajes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraInfViajes] @pmTipDoc VARCHAR(3),@pmNumViaje INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdRuta VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10)
,@pmVrFletes MONEY,@pmPesoTotal DECIMAL(14,4),@pmNumManif INT,@pmIdCiaManif CHAR(2),@pmNumMintrans DECIMAL(14,2),@pmMvoAnulacion VARCHAR(5),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraInfViajes SET Fecha=@pmFecha,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdRuta=@pmIdRuta,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,nRemolque=@pmnRemolque,TipoAfiVehic=@pmTipoAfiVehic,VrFletes=@pmVrFletes,PesoTotal=@pmPesoTotal,NumManif=@pmNumManif,IdCiaManif=@pmIdCiaManif,NumMintrans=@pmNumMintrans
,MvoAnulacion=@pmMvoAnulacion,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumViaje=@pmNumViaje AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiquida]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraLiquida] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16)
,@pmVrTotal MONEY,@pmCxPagar BIT,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmFecIniCau SMALLDATETIME,@pmFecFinCau SMALLDATETIME,@pmFecIniOdp SMALLDATETIME,@pmFecFinOdp SMALLDATETIME,@pmModLiquida VARCHAR(10),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraLiquida SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,VrTotal=@pmVrTotal,CxPagar=@pmCxPagar,TipCom=@pmTipCom,Comprobante=@pmComprobante
,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecIniCau=@pmFecIniCau,FecFinCau=@pmFecFinCau,FecIniOdp=@pmFecIniOdp,FecFinOdp=@pmFecFinOdp
,ModLiquida=@pmModLiquida,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiquidaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraLiquidaAnu] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraLiquida SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiqViajes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraLiqViajes] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmTipMuc VARCHAR(3),@pmManifiesto INT,@pmIdCiaMuc CHAR(2),@pmFechaMuc SMALLDATETIME,@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmNitEmpresa VARCHAR(16),@pmVrAnticipos MONEY,@pmVrGastos MONEY,@pmVrCombustible MONEY
,@pmVrDiferencia MONEY,@pmgalsComb DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmVolumen DECIMAL(14,4),@pmIdRuta VARCHAR(4),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmReferencia VARCHAR(50),@pmDescMcias VARCHAR(150),@pmkmtInicial DECIMAL(14,4),@pmkmtFinal DECIMAL(14,4),@pmEstFactura INT
,@pmTipDocRef VARCHAR(3),@pmNumDocRef INT,@pmIdCiaRef CHAR(2),@pmFecDocRef SMALLDATETIME,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmVrOtrosCred MONEY,@pmLiqMixto BIT,@pmNum_Ppto INT,@pmVrGuiasCe MONEY,@pmVrGuiasSeg MONEY,@pmVrGuiasOtr MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraLiqViajes SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,TipMuc=@pmTipMuc,Manifiesto=@pmManifiesto,IdCiaMuc=@pmIdCiaMuc,FechaMuc=@pmFechaMuc,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,IdPropietario=@pmIdPropietario,IdPoseedor=@pmIdPoseedor,NitEmpresa=@pmNitEmpresa,VrAnticipos=@pmVrAnticipos,VrGastos=@pmVrGastos,VrCombustible=@pmVrCombustible,VrDiferencia=@pmVrDiferencia,galsComb=@pmgalsComb
,PesoTotal=@pmPesoTotal,Cantidad=@pmCantidad,Volumen=@pmVolumen,IdRuta=@pmIdRuta,IdLocOrigen=@pmIdLocOrigen,IdLocDestino=@pmIdLocDestino,Referencia=@pmReferencia,DescMcias=@pmDescMcias,kmtInicial=@pmkmtInicial,kmtFinal=@pmkmtFinal,EstFactura=@pmEstFactura,TipDocRef=@pmTipDocRef,NumDocRef=@pmNumDocRef,IdCiaRef=@pmIdCiaRef,FecDocRef=@pmFecDocRef,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,VrOtrosCred=@pmVrOtrosCred,LiqMixto=@pmLiqMixto,Num_Ppto=@pmNum_Ppto,VrGuiasCe=@pmVrGuiasCe,VrGuiasSeg=@pmVrGuiasSeg,VrGuiasOtr=@pmVrGuiasOtr,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraLiqViajesAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraLiqViajesAnu] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraLiqViajes SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraManifiesto]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraManifiesto] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdRuta VARCHAR(4),@pmIdRutaFle VARCHAR(4),@pmIdVehiculo VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmVrFletes MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrDescuento MONEY,@pmVrAnticipo MONEY,@pmVrAntAdic MONEY,@pmVrNeto MONEY,@pmVrPagos MONEY
,@pmVrCargos MONEY,@pmVrDctos MONEY,@pmTarifaFlete MONEY,@pmCantidad DECIMAL(14,4),@pmPesoTotal DECIMAL(14,4),@pmBaseRet MONEY,@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(14,4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmIdLocFletes VARCHAR(8),@pmFechaPago SMALLDATETIME
,@pmPagoCargue VARCHAR(50),@pmPagoDescargue VARCHAR(50),@pmNumMintrans DECIMAL(14,2),@pmEdoMintrans VARCHAR(5),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmCumplido INT,@pmIdCiaCump CHAR(2),@pmFechaCump SMALLDATETIME,@pmEstCumplido INT,@pmTipOdp VARCHAR(3),@pmOrdPago INT,@pmIdCiaOdp CHAR(2)
,@pmFechaOdp SMALLDATETIME,@pmEstOrden INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmVrFleteNeto MONEY,@pmTipInfVia VARCHAR(3),@pmNumViaje INT,@pmCiaInfViaje CHAR(2)
,@pmCdCatPeaje VARCHAR(4),@pmCdCondRelev VARCHAR(16),@pmVrTrayVacio1 MONEY,@pmVrTrayVacio2 MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraManifiesto SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,FecEntrega=@pmFecEntrega,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdRuta=@pmIdRuta,IdRutaFle=@pmIdRutaFle,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,nRemolque=@pmnRemolque,TipoAfiVehic=@pmTipoAfiVehic,IdPropietario=@pmIdPropietario,IdPoseedor=@pmIdPoseedor
,VrFletes=@pmVrFletes,VrRetencion=@pmVrRetencion,VrReteIca=@pmVrReteIca,VrDescuento=@pmVrDescuento,VrAnticipo=@pmVrAnticipo,VrAntAdic=@pmVrAntAdic,VrNeto=@pmVrNeto,VrPagos=@pmVrPagos,VrCargos=@pmVrCargos,VrDctos=@pmVrDctos,TarifaFlete=@pmTarifaFlete,Cantidad=@pmCantidad,PesoTotal=@pmPesoTotal,BaseRet=@pmBaseRet,TarifaRet=@pmTarifaRet
,TarifaIca=@pmTarifaIca,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,IdLocFletes=@pmIdLocFletes,FechaPago=@pmFechaPago,PagoCargue=@pmPagoCargue,PagoDescargue=@pmPagoDescargue,NumMintrans=@pmNumMintrans,EdoMintrans=@pmEdoMintrans,Remesa=@pmRemesa,IdCiaRem=@pmIdCiaRem,Cumplido=@pmCumplido,IdCiaCump=@pmIdCiaCump
,FechaCump=@pmFechaCump,EstCumplido=@pmEstCumplido,TipOdp=@pmTipOdp,OrdPago=@pmOrdPago,IdCiaOdp=@pmIdCiaOdp,FechaOdp=@pmFechaOdp,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,EstOrden=@pmEstOrden,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,VrFleteNeto=@pmVrFleteNeto,TipInfVia=@pmTipInfVia,NumViaje=@pmNumViaje,CiaInfViaje=@pmCiaInfViaje,CdCatPeaje=@pmCdCatPeaje,FecUpdate=@pmFecUpdate,CdCondRelev=@pmCdCondRelev,VrTrayVacio1=@pmVrTrayVacio1,VrTrayVacio2=@pmVrTrayVacio2
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraManifiestoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraManifiestoAnu] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
,@pmEdoMintrans VARCHAR(5)
 AS 
 UPDATE Trn_TraManifiesto SET   EdoMintrans=@pmEdoMintrans,Anulado=@pmAnulado,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraManifInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraManifInt] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdVehiculo VARCHAR(10),@pmnRemolque VARCHAR(10),@pmIdConductor VARCHAR(16),@pmIdCondRelev VARCHAR(16),@pmNatCarga VARCHAR(50),@pmCdAduana VARCHAR(4),@pmCdAduanaDest VARCHAR(4)
,@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmNumMuc INT,@pmCdCiaMuc CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraManifInt SET Fecha=@pmFecha,FecEmision=@pmFecEmision,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdVehiculo=@pmIdVehiculo,nRemolque=@pmnRemolque,IdConductor=@pmIdConductor,IdCondRelev=@pmIdCondRelev,NatCarga=@pmNatCarga,CdAduana=@pmCdAduana,CdAduanaDest=@pmCdAduanaDest,IdMoneda=@pmIdMoneda,ValorTotal=@pmValorTotal,PesoTotal=@pmPesoTotal
,NumMuc=@pmNumMuc,CdCiaMuc=@pmCdCiaMuc,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Negociacion=@pmNegociacion
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenAnt] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipOds VARCHAR(3),@pmNumOrden INT,@pmIdCiaOds CHAR(2),@pmVrAnticipo MONEY,@pmVrAbonado MONEY,@pmTipoPago VARCHAR(10),@pmNumCheque VARCHAR(20),@pmFecCheque SMALLDATETIME,@pmIdCta VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmBeneficiario VARCHAR(150),@pmCedBenef VARCHAR(16),@pmFechaVence SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTipoAncpo VARCHAR(10),@pmNumPresAnt INT,@pmCantidad DECIMAL(14,4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraOrdenAnt SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipOds=@pmTipOds,NumOrden=@pmNumOrden,IdCiaOds=@pmIdCiaOds,VrAnticipo=@pmVrAnticipo,VrAbonado=@pmVrAbonado,TipoPago=@pmTipoPago,NumCheque=@pmNumCheque,FecCheque=@pmFecCheque,IdCta=@pmIdCta,IdCuenta=@pmIdCuenta,Beneficiario=@pmBeneficiario,CedBenef=@pmCedBenef,FechaVence=@pmFechaVence,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipoAncpo=@pmTipoAncpo,NumPresAnt=@pmNumPresAnt,Cantidad=@pmCantidad
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenAntAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenAntAnu] @pmTipDoc VARCHAR(3),@pmAnticipo INT,@pmIdCia CHAR(2),@pmVrAbonado MONEY
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraOrdenAnt SET VrAbonado=@pmVrAbonado,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Anticipo=@pmAnticipo AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenAntApp]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenAntApp] @pmIdCia CHAR(2)=Null,@pmIdVehiculo VARCHAR(10)=Null,@pmIdPoseedor VARCHAR(16)=Null
 AS
 UPDATE Trn_TraOrdenAnt SET Trn_TraOrdenAnt.VrAbonado=(SELECT ISNULL(SUM(Trn_TraOrdenAbo.VrAbono),0)
 FROM Trn_TraOrdenAbo WHERE Trn_TraOrdenAbo.TipAnt=Trn_TraOrdenAnt.TipDoc AND Trn_TraOrdenAbo.Anticipo=Trn_TraOrdenAnt.Anticipo AND Trn_TraOrdenAbo.IdCiaAnt=Trn_TraOrdenAnt.IdCia)
 FROM Trn_TraOrdenAnt INNER JOIN Trn_TraOrdenServ ON Trn_TraOrdenAnt.TipOds=Trn_TraOrdenServ.TipDoc AND Trn_TraOrdenAnt.NumOrden=Trn_TraOrdenServ.NumOrden AND Trn_TraOrdenAnt.IdCiaOds=Trn_TraOrdenServ.IdCia
 WHERE (Trn_TraOrdenAnt.IdCia=@pmIdCia OR @pmIdCia IS NULL)
 AND (Trn_TraOrdenServ.IdVehiculo=@pmIdVehiculo OR @pmIdVehiculo IS NULL)
 AND (Trn_TraOrdenServ.IdPoseedor=@pmIdPoseedor OR @pmIdPoseedor IS NULL)
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenCum]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenCum] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipOds VARCHAR(3),@pmNumOrden INT,@pmIdCiaOds CHAR(2),@pmTipoAfiVehic VARCHAR(10),@pmFecDespacho SMALLDATETIME,@pmFecRecibo SMALLDATETIME,@pmFecIngCertif SMALLDATETIME,@pmFecCertificado SMALLDATETIME,@pmDescServicio VARCHAR(100)
,@pmCantidad DECIMAL(14,4),@pmVrTotal MONEY,@pmVrCosto MONEY,@pmRemCliente VARCHAR(30),@pmFuncionario VARCHAR(150),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmNumReferencia VARCHAR(50),@pmNumAprobCO INT,@pmCiaAprobCO CHAR(2),@pmFecAprobCO SMALLDATETIME,@pmObservAprobCO VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraOrdenCum SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipOds=@pmTipOds,NumOrden=@pmNumOrden,IdCiaOds=@pmIdCiaOds,TipoAfiVehic=@pmTipoAfiVehic,FecDespacho=@pmFecDespacho,FecRecibo=@pmFecRecibo,FecIngCertif=@pmFecIngCertif,FecCertificado=@pmFecCertificado,DescServicio=@pmDescServicio,Cantidad=@pmCantidad,VrTotal=@pmVrTotal,VrCosto=@pmVrCosto
,RemCliente=@pmRemCliente,Funcionario=@pmFuncionario,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,NumReferencia=@pmNumReferencia,NumAprobCO=@pmNumAprobCO,CiaAprobCO=@pmCiaAprobCO,FecAprobCO=@pmFecAprobCO,ObservAprobCO=@pmObservAprobCO
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenCumAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenCumAnu] @pmTipDoc VARCHAR(3),@pmCumplido INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4)
AS 
 UPDATE Trn_TraOrdenCum SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenLiq]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenLiq] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmTipOds VARCHAR(3),@pmNumOrden INT,@pmIdCiaOds CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmTipoAfiVehic VARCHAR(10),@pmVrTotal MONEY,@pmVrCosto MONEY
,@pmVrAnticipo MONEY,@pmVrGastos MONEY,@pmVrIva MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrReteCREE MONEY,@pmVrReteIva MONEY,@pmVrOtros MONEY,@pmVrDescuento MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmTarifaPago MONEY,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmTarifaImp DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4)
,@pmTarifaIca DECIMAL(16,6),@pmTarifaRiv DECIMAL(14,4),@pmTarifaRtc DECIMAL(14,4),@pmCodTarIva VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmCodTarRiv VARCHAR(4),@pmCodTarRtc VARCHAR(4),@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmCdPlazo VARCHAR(4),@pmFechaVence SMALLDATETIME,@pmUndMed VARCHAR(10)
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmTipEgr VARCHAR(3),@pmEgreso INT,@pmIdCiaEgr CHAR(2),@pmNumCheque VARCHAR(20),@pmVrConcCargos MONEY,@pmVrConcDed MONEY,@pmCdCCosto VARCHAR(16),@pmCdSubCos VARCHAR(16),@pmNumDocSop INT,@pmCiaDocSop CHAR(2),@pmReferencia2 VARCHAR(50)
,@pmCdTarAvta VARCHAR(4),@pmTarifaAvta DECIMAL(14,4),@pmVrImpAvTa MONEY,@pmCdTarBom VARCHAR(4),@pmTarifaBom DECIMAL(14,4),@pmVrBomberil MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraOrdenLiq SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,TipOds=@pmTipOds,NumOrden=@pmNumOrden,IdCiaOds=@pmIdCiaOds,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,TipoAfiVehic=@pmTipoAfiVehic,VrTotal=@pmVrTotal,VrCosto=@pmVrCosto,VrAnticipo=@pmVrAnticipo,VrGastos=@pmVrGastos,VrIva=@pmVrIva,VrRetencion=@pmVrRetencion
,VrReteIca=@pmVrReteIca,VrReteCREE=@pmVrReteCREE,VrReteIva=@pmVrReteIva,VrOtros=@pmVrOtros,VrDescuento=@pmVrDescuento,VrNeto=@pmVrNeto,Cantidad=@pmCantidad,TarifaPago=@pmTarifaPago,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,TarifaImp=@pmTarifaImp,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,TarifaRiv=@pmTarifaRiv,TarifaRtc=@pmTarifaRtc
,CodTarIva=@pmCodTarIva,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,CodTarRiv=@pmCodTarRiv,CodTarRtc=@pmCodTarRtc,Referencia=@pmReferencia,CxPagar=@pmCxPagar,CdPlazo=@pmCdPlazo,FechaVence=@pmFechaVence,UndMed=@pmUndMed,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,TipEgr=@pmTipEgr,Egreso=@pmEgreso,IdCiaEgr=@pmIdCiaEgr,NumCheque=@pmNumCheque,VrConcCargos=@pmVrConcCargos,VrConcDed=@pmVrConcDed,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,NumDocSop=@pmNumDocSop,CiaDocSop=@pmCiaDocSop,Referencia2=@pmReferencia2,CdTarAvta=@pmCdTarAvta,TarifaAvta=@pmTarifaAvta,VrImpAvTa=@pmVrImpAvTa,CdTarBom=@pmCdTarBom,TarifaBom=@pmTarifaBom,VrBomberil=@pmVrBomberil
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenLiqAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenLiqAnu] @pmTipDoc VARCHAR(3),@pmLiquidacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraOrdenLiq SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Liquidacion=@pmLiquidacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenPago]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenPago] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmModalidad VARCHAR(10),@pmLiqRemesas BIT,@pmCxPagar BIT,@pmMulPlazos BIT,@pmIdPlazo VARCHAR(4),@pmFechaVence SMALLDATETIME
,@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmNumDocSop INT,@pmCiaDocSop CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraOrdenPago SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,Modalidad=@pmModalidad,LiqRemesas=@pmLiqRemesas,CxPagar=@pmCxPagar,MulPlazos=@pmMulPlazos,IdPlazo=@pmIdPlazo,FechaVence=@pmFechaVence,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom
,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,NumDocSop=@pmNumDocSop,CiaDocSop=@pmCiaDocSop,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenPagoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenPagoAnu] @pmTipDoc VARCHAR(3),@pmOrdPago INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraOrdenPago SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND OrdPago=@pmOrdPago AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenServ]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenServ] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecRecibo SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVehiculo VARCHAR(10),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmModalidad VARCHAR(10)
,@pmVrTotal MONEY,@pmVrCosto MONEY,@pmCantidad DECIMAL(14,4),@pmVrAnticipo MONEY,@pmIdDestino VARCHAR(8),@pmTipoOrden VARCHAR(10),@pmIdEstacion VARCHAR(4),@pmNomEstacion VARCHAR(50),@pmTipoResiduo VARCHAR(100),@pmRemCliente VARCHAR(30),@pmNomRecibido VARCHAR(150),@pmFecIngCertif SMALLDATETIME,@pmFecCertificado SMALLDATETIME,@pmNumRemesa INT,@pmCdCiaRem CHAR(2)
,@pmEstCumplido INT,@pmEstFactura INT,@pmTipFact VARCHAR(3),@pmNumFactura INT,@pmCdCiaFact CHAR(2),@pmkmtInicial INT,@pmkmtFinal INT,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4),@pmEstOrden INT,@pmTipLiq VARCHAR(3),@pmNumLiquida INT,@pmCdCiaLiq CHAR(2),@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME,@pmUsuAprob VARCHAR(11),@pmObservAprob VARCHAR(250)
,@pmCdRuta VARCHAR(4),@pmIdOrigen VARCHAR(8),@pmCantkms INT,@pmNumCump INT,@pmCdCiaCum CHAR(2),@pmCdTarIva VARCHAR(4),@pmCdTarRiv VARCHAR(4),@pmCdTarRet VARCHAR(4),@pmCdTarIca VARCHAR(4),@pmCdTarRtc VARCHAR(4),@pmNumReferencia VARCHAR(50),@pmCdTarAvta VARCHAR(4),@pmCdTarBom VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraOrdenServ SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,FecRecibo=@pmFecRecibo,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdVehiculo=@pmIdVehiculo,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,nRemolque=@pmnRemolque,TipoAfiVehic=@pmTipoAfiVehic,Modalidad=@pmModalidad,VrTotal=@pmVrTotal,VrCosto=@pmVrCosto,Cantidad=@pmCantidad,VrAnticipo=@pmVrAnticipo
,IdDestino=@pmIdDestino,TipoOrden=@pmTipoOrden,IdEstacion=@pmIdEstacion,NomEstacion=@pmNomEstacion,TipoResiduo=@pmTipoResiduo,RemCliente=@pmRemCliente,NomRecibido=@pmNomRecibido,FecIngCertif=@pmFecIngCertif,FecCertificado=@pmFecCertificado,NumRemesa=@pmNumRemesa,CdCiaRem=@pmCdCiaRem,EstCumplido=@pmEstCumplido,EstFactura=@pmEstFactura,TipFact=@pmTipFact,NumFactura=@pmNumFactura,CdCiaFact=@pmCdCiaFact
,kmtInicial=@pmkmtInicial,kmtFinal=@pmkmtFinal,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,EstOrden=@pmEstOrden,TipLiq=@pmTipLiq,NumLiquida=@pmNumLiquida,CdCiaLiq=@pmCdCiaLiq,NumAprob=@pmNumAprob,IdCiaApr=@pmIdCiaApr,FecAprob=@pmFecAprob,UsuAprob=@pmUsuAprob,ObservAprob=@pmObservAprob
,CdRuta=@pmCdRuta,IdOrigen=@pmIdOrigen,Cantkms=@pmCantkms,NumCump=@pmNumCump,CdCiaCum=@pmCdCiaCum,CdTarIva=@pmCdTarIva,CdTarRiv=@pmCdTarRiv,CdTarRet=@pmCdTarRet,CdTarIca=@pmCdTarIca,CdTarRtc=@pmCdTarRtc,NumReferencia=@pmNumReferencia,CdTarAvta=@pmCdTarAvta,CdTarBom=@pmCdTarBom
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraOrdenServAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraOrdenServAnu] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(1000),@pmIdEstado VARCHAR(4)
AS 
 UPDATE Trn_TraOrdenServ SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedAnexo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraPedAnexo] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmNomCliente VARCHAR(150),@pmNomRemite VARCHAR(150),@pmNomDestino VARCHAR(150),@pmLugarCargue VARCHAR(150),@pmLugarDescargue VARCHAR(150),@pmNomContacto VARCHAR(150)
,@pmTelContacto VARCHAR(30),@pmemlContacto VARCHAR(100),@pmContacDestino VARCHAR(150),@pmTelContacDest VARCHAR(30),@pmemlContacDest VARCHAR(100),@pmPolizaEsp BIT,@pmNumPolizaEsp VARCHAR(50),@pmNitCiaPoliza VARCHAR(16),@pmNomCiaPoliza VARCHAR(150),@pmFecVencePol SMALLDATETIME
,@pmVrLimiteDesp MONEY,@pmSeguros VARCHAR(10),@pmCargue VARCHAR(20),@pmDescargue VARCHAR(20),@pmCdTipoEsc VARCHAR(4),@pmNitSIA VARCHAR(16),@pmNombreSIA VARCHAR(150),@pmContactoSIA VARCHAR(150),@pmTelContacSIA VARCHAR(30),@pmIdLocCont VARCHAR(8),@pmPatioCont VARCHAR(50)
,@pmCdTipoVeh VARCHAR(4),@pmTipoMargen VARCHAR(10),@pmMargenFalt DECIMAL(14,4),@pmEmbAdicional VARCHAR(150),@pmTipoRuta VARCHAR(10),@pmTipoTrans VARCHAR(10),@pmEmbarque VARCHAR(10),@pmCdTipCarga VARCHAR(4),@pmDevContenedor BIT,@pmUndCalcFalt VARCHAR(10),@pmTarifFaltPago MONEY
,@pmTarifFaltCobro MONEY,@pmCdRutaTarif VARCHAR(4),@pmTipoServicio VARCHAR(10),@pmCodTipoOper VARCHAR(4)
 AS 
 UPDATE Trn_TraPedAnexo SET NomCliente=@pmNomCliente,NomRemite=@pmNomRemite,NomDestino=@pmNomDestino,LugarCargue=@pmLugarCargue,LugarDescargue=@pmLugarDescargue,NomContacto=@pmNomContacto,TelContacto=@pmTelContacto,emlContacto=@pmemlContacto,ContacDestino=@pmContacDestino,TelContacDest=@pmTelContacDest,emlContacDest=@pmemlContacDest
,PolizaEsp=@pmPolizaEsp,NumPolizaEsp=@pmNumPolizaEsp,NitCiaPoliza=@pmNitCiaPoliza,NomCiaPoliza=@pmNomCiaPoliza,FecVencePol=@pmFecVencePol,VrLimiteDesp=@pmVrLimiteDesp,Seguros=@pmSeguros,Cargue=@pmCargue,Descargue=@pmDescargue,CdTipoEsc=@pmCdTipoEsc,NitSIA=@pmNitSIA,NombreSIA=@pmNombreSIA,ContactoSIA=@pmContactoSIA
,TelContacSIA=@pmTelContacSIA,IdLocCont=@pmIdLocCont,PatioCont=@pmPatioCont,CdTipoVeh=@pmCdTipoVeh,TipoMargen=@pmTipoMargen,MargenFalt=@pmMargenFalt,EmbAdicional=@pmEmbAdicional,UndCalcFalt=@pmUndCalcFalt,TarifFaltPago=@pmTarifFaltPago,TarifFaltCobro=@pmTarifFaltCobro
,TipoRuta=@pmTipoRuta,TipoTrans=@pmTipoTrans,Embarque=@pmEmbarque,CdTipCarga=@pmCdTipCarga,DevContenedor=@pmDevContenedor,CdRutaTarif=@pmCdRutaTarif,TipoServicio=@pmTipoServicio,CodTipoOper=@pmCodTipoOper
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraPedido] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFechaVence SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdClieFact VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmIdDestinatario VARCHAR(16),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8)
,@pmIdVend VARCHAR(16),@pmIdTarifCom VARCHAR(4),@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmTipoTarifa VARCHAR(10),@pmVrCobro MONEY,@pmVrPagos MONEY,@pmVrFletes MONEY,@pmVrCargue MONEY,@pmVrDesCargue MONEY,@pmVrEscolta MONEY,@pmVrDevContdor MONEY,@pmVrTraUrbano MONEY,@pmVrEmbalajes MONEY,@pmVrCargos MONEY,@pmVrDctos MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY
,@pmCantidad DECIMAL(14,4),@pmCantDesp DECIMAL(14,4),@pmIdMneda VARCHAR(5),@pmVrTasa DECIMAL(14,4),@pmCotizacion INT,@pmIdCiaCot CHAR(2),@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME,@pmTipOdc VARCHAR(3),@pmOCargue INT,@pmIdCiaOdc CHAR(2),@pmFechaOdc SMALLDATETIME,@pmTipRem VARCHAR(3),@pmRemesa INT,@pmIdCiaRem CHAR(2),@pmFechaRem SMALLDATETIME,@pmTipFac VARCHAR(3)
,@pmFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraPedido SET Fecha=@pmFecha,FechaVence=@pmFechaVence,FecDespacho=@pmFecDespacho,FecEntrega=@pmFecEntrega,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdClieFact=@pmIdClieFact,IdRemitente=@pmIdRemitente,IdDestinatario=@pmIdDestinatario,IdLocOrigen=@pmIdLocOrigen,IdLocDestino=@pmIdLocDestino,IdVend=@pmIdVend,IdTarifCom=@pmIdTarifCom,Modalidad=@pmModalidad,Vigencia=@pmVigencia
,TipoTarifa=@pmTipoTarifa,VrCobro=@pmVrCobro,VrPagos=@pmVrPagos,VrFletes=@pmVrFletes,VrCargue=@pmVrCargue,VrDesCargue=@pmVrDesCargue,VrEscolta=@pmVrEscolta,VrDevContdor=@pmVrDevContdor,VrTraUrbano=@pmVrTraUrbano,VrEmbalajes=@pmVrEmbalajes,VrCargos=@pmVrCargos,VrDctos=@pmVrDctos,VrDeclarado=@pmVrDeclarado,VrSeguro=@pmVrSeguro,Cantidad=@pmCantidad,CantDesp=@pmCantDesp
,IdMneda=@pmIdMneda,VrTasa=@pmVrTasa,Cotizacion=@pmCotizacion,IdCiaCot=@pmIdCiaCot,NumAprob=@pmNumAprob,IdCiaApr=@pmIdCiaApr,FecAprob=@pmFecAprob,TipOdc=@pmTipOdc,OCargue=@pmOCargue,IdCiaOdc=@pmIdCiaOdc,FechaOdc=@pmFechaOdc,TipRem=@pmTipRem,Remesa=@pmRemesa,IdCiaRem=@pmIdCiaRem,FechaRem=@pmFechaRem,TipFac=@pmTipFac,Factura=@pmFactura,IdCiaFac=@pmIdCiaFac,FechaFac=@pmFechaFac
,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedidoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paUpTraPedidoAnu] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraPedido SET Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPedidoApr]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraPedidoApr] @pmTipDoc VARCHAR(3),@pmPedido INT,@pmIdCia CHAR(2)
,@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmFecAprob SMALLDATETIME,@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraPedido SET  NumAprob=@pmNumAprob,IdCiaApr=@pmIdCiaApr,FecAprob=@pmFecAprob,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Pedido=@pmPedido AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPorteInt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraPorteInt] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecEmision SMALLDATETIME,@pmFecCargue SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmIdNotificado VARCHAR(16),@pmNotificado VARCHAR(150),@pmIdRemitente VARCHAR(16),@pmRemitente VARCHAR(150),@pmDirOrigen VARCHAR(250)
,@pmIdDestinatario VARCHAR(16),@pmDestinatario VARCHAR(150),@pmDirDestino VARCHAR(250),@pmIdConsig VARCHAR(16),@pmConsignatario VARCHAR(150),@pmDirConsig VARCHAR(250),@pmInsTransporte VARCHAR(1000),@pmDocRemitente VARCHAR(500),@pmIdMoneda VARCHAR(5),@pmValorTotal MONEY,@pmPesoTotal DECIMAL(14,4),@pmManifiesto INT,@pmCdCiaManif CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(2500),@pmIdEstado VARCHAR(4),@pmNegociacion VARCHAR(1000),@pmCondic_Pago VARCHAR(1000),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraPorteInt SET Fecha=@pmFecha,FecEmision=@pmFecEmision,FecCargue=@pmFecCargue,FecEntrega=@pmFecEntrega,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,IdNotificado=@pmIdNotificado,Notificado=@pmNotificado,IdRemitente=@pmIdRemitente,Remitente=@pmRemitente,DirOrigen=@pmDirOrigen,IdDestinatario=@pmIdDestinatario,Destinatario=@pmDestinatario,DirDestino=@pmDirDestino,IdConsig=@pmIdConsig
,Consignatario=@pmConsignatario,DirConsig=@pmDirConsig,InsTransporte=@pmInsTransporte,DocRemitente=@pmDocRemitente,IdMoneda=@pmIdMoneda,ValorTotal=@pmValorTotal,PesoTotal=@pmPesoTotal,Manifiesto=@pmManifiesto,CdCiaManif=@pmCdCiaManif,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate,Negociacion=@pmNegociacion,Condic_Pago=@pmCondic_Pago
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraPresAnt]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraPresAnt] @pmNumPsto INT,@pmFecha SMALLDATETIME,@pmIdOrigen VARCHAR(8),@pmIdDestino VARCHAR(8),@pmFecInicio SMALLDATETIME,@pmFecFinal SMALLDATETIME
,@pmVrGastos MONEY,@pmVrComb MONEY,@pmVrPeajes MONEY,@pmVrAnticipo MONEY,@pmCdCat VARCHAR(4),@pmCdTipoVeh VARCHAR(4),@pmTipoAfilVeh VARCHAR(10),@pmCdTipoMot VARCHAR(4)
,@pmCdCom VARCHAR(4),@pmCdRango VARCHAR(4),@pmValorFijo BIT,@pmObservacion VARCHAR(250),@pmInactivo BIT,@pmTipoRuta VARCHAR(10),@pmCdRuta  VARCHAR(4),@pmNitCliente VARCHAR(16)
,@pmCdMercancia VARCHAR(16),@pmTipoServicio INT,@pmCantgalones DECIMAL(14,4),@pmVrExtralegal MONEY,@pmCdTipoCarr VARCHAR(4),@pmFechaAct SMALLDATETIME 
 AS 
 UPDATE Trn_TraPresAnt SET Fecha=@pmFecha,IdOrigen=@pmIdOrigen,IdDestino=@pmIdDestino,FecInicio=@pmFecInicio,FecFinal=@pmFecFinal,VrGastos=@pmVrGastos,VrComb=@pmVrComb,VrPeajes=@pmVrPeajes
,VrAnticipo=@pmVrAnticipo,CdCat=@pmCdCat,CdTipoVeh=@pmCdTipoVeh,TipoAfilVeh=@pmTipoAfilVeh,CdTipoMot=@pmCdTipoMot,CdCom=@pmCdCom,CdRango=@pmCdRango,ValorFijo=@pmValorFijo
,Observacion=@pmObservacion,Inactivo=@pmInactivo,TipoRuta=@pmTipoRuta,CdRuta=@pmCdRuta,FechaAct=@pmFechaAct,NitCliente=@pmNitCliente,CdMercancia=@pmCdMercancia,TipoServicio=@pmTipoServicio
,Cantgalones=@pmCantgalones,VrExtralegal=@pmVrExtralegal,CdTipoCarr=@pmCdTipoCarr
 WHERE NumPsto=@pmNumPsto
GO
/****** Object:  StoredProcedure [dbo].[paUpTraReexpedido]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraReexpedido] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdEmpTrans VARCHAR(16),@pmNumFactura VARCHAR(15),@pmFecFactura SMALLDATETIME,@pmFecVence SMALLDATETIME,@pmVrTotal MONEY,@pmVrImpuesto MONEY,@pmVrRetencion MONEY,@pmVrReteIca MONEY,@pmVrOtrosCargos MONEY,@pmVrOtrosDctos MONEY,@pmVrNeto MONEY,@pmPesoTotal DECIMAL(14,4)
,@pmBaseImp MONEY,@pmBaseRet MONEY,@pmBaseIca MONEY,@pmTarifaImp DECIMAL(14,4),@pmTarifaRet DECIMAL(14,4),@pmTarifaIca DECIMAL(16,6),@pmCodTarImp VARCHAR(4),@pmCodTarRet VARCHAR(4),@pmCodTarIca VARCHAR(4),@pmReferencia VARCHAR(50),@pmCxPagar BIT,@pmCdPlazo VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraReexpedido SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdEmpTrans=@pmIdEmpTrans,NumFactura=@pmNumFactura,FecFactura=@pmFecFactura,FecVence=@pmFecVence,VrTotal=@pmVrTotal,VrImpuesto=@pmVrImpuesto,VrRetencion=@pmVrRetencion,VrReteIca=@pmVrReteIca,VrOtrosCargos=@pmVrOtrosCargos,VrOtrosDctos=@pmVrOtrosDctos,VrNeto=@pmVrNeto,PesoTotal=@pmPesoTotal,BaseImp=@pmBaseImp,BaseRet=@pmBaseRet,BaseIca=@pmBaseIca,TarifaImp=@pmTarifaImp
,TarifaRet=@pmTarifaRet,TarifaIca=@pmTarifaIca,CodTarImp=@pmCodTarImp,CodTarRet=@pmCodTarRet,CodTarIca=@pmCodTarIca,Referencia=@pmReferencia,CxPagar=@pmCxPagar,CdPlazo=@pmCdPlazo,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraReexpedidoAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraReexpedidoAnu] @pmTipDoc VARCHAR(3),@pmCausacion INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4) 
 AS 
 UPDATE Trn_TraReexpedido SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND Causacion=@pmCausacion AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemAnexo]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraRemAnexo] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmIdVend VARCHAR(16),@pmIdTarifCom VARCHAR(4),@pmNomCliente VARCHAR(150),@pmNomRemite VARCHAR(150),@pmNomDestino VARCHAR(150),@pmLugarCargue VARCHAR(150),@pmLugarDescargue VARCHAR(150),@pmNomContacto VARCHAR(150),@pmTelContacto VARCHAR(30)
,@pmemlContacto VARCHAR(100),@pmContacDestino VARCHAR(150),@pmTelContacDest VARCHAR(30),@pmemlContacDest VARCHAR(100),@pmPolizaSeguro VARCHAR(50),@pmNitCiaPoliza VARCHAR(16),@pmNomCiaPoliza VARCHAR(150),@pmFecVencePol SMALLDATETIME,@pmManifMintrans DECIMAL(14,2),@pmRemMintrans DECIMAL(14,2),@pmTipSal VARCHAR(3),@pmNumSalida INT,@pmIdCiaSal CHAR(2)
,@pmNumInvent INT,@pmIdCiaInv CHAR(2),@pmTomadorPoliza CHAR(1),@pmTipoRuta VARCHAR(10),@pmTipoMintrans VARCHAR(10),@pmNitEmpTransp VARCHAR(16),@pmNumFactEmp VARCHAR(20)
,@pmMvoAnulacion VARCHAR(3),@pmPactoCargue BIT,@pmHorasPactoCargue INT,@pmMinPactoCargue INT,@pmHoraCitaCargue SMALLDATETIME,@pmHoraLlegaCargue SMALLDATETIME,@pmHoraEntraCargue SMALLDATETIME,@pmHoraSaleCargue SMALLDATETIME
,@pmPactoDescargue BIT,@pmHorasPactoDescargue INT,@pmMinPactoDescargue INT,@pmHoraCitaDescargue SMALLDATETIME,@pmHoraLlegaDescargue SMALLDATETIME,@pmHoraEntraDescargue SMALLDATETIME,@pmHoraSaleDescargue SMALLDATETIME,@pmTipoDevRemesa VARCHAR(3),@pmCodCiuTransb VARCHAR(8),@pmMvoTransbordo VARCHAR(3),@pmCantViajes INT,@pmTipOrdMud VARCHAR(3),@pmItemOsm INT
,@pmRemMTEstado INT,@pmRem_Descr_Prod VARCHAR(500),@pmRem_FecchaReg DATETIME,@pmPolizaMerPel VARCHAR(30),@pmTipoConsolida VARCHAR(10) 
 AS 
 UPDATE Trn_TraRemAnexo SET IdVend=@pmIdVend,IdTarifCom=@pmIdTarifCom,NomCliente=@pmNomCliente,NomRemite=@pmNomRemite,NomDestino=@pmNomDestino,LugarCargue=@pmLugarCargue,LugarDescargue=@pmLugarDescargue,NomContacto=@pmNomContacto,TelContacto=@pmTelContacto,emlContacto=@pmemlContacto,ContacDestino=@pmContacDestino,TelContacDest=@pmTelContacDest
,emlContacDest=@pmemlContacDest,PolizaSeguro=@pmPolizaSeguro,NitCiaPoliza=@pmNitCiaPoliza,NomCiaPoliza=@pmNomCiaPoliza,FecVencePol=@pmFecVencePol,ManifMintrans=@pmManifMintrans,RemMintrans=@pmRemMintrans,TipSal=@pmTipSal,NumSalida=@pmNumSalida,IdCiaSal=@pmIdCiaSal,NumInvent=@pmNumInvent,IdCiaInv=@pmIdCiaInv,TomadorPoliza=@pmTomadorPoliza
,TipoRuta=@pmTipoRuta,TipoMintrans=@pmTipoMintrans,NitEmpTransp=@pmNitEmpTransp,NumFactEmp=@pmNumFactEmp,MvoAnulacion=@pmMvoAnulacion,PactoCargue=@pmPactoCargue,HorasPactoCargue=@pmHorasPactoCargue,MinPactoCargue=@pmMinPactoCargue
,HoraCitaCargue=@pmHoraCitaCargue,HoraLlegaCargue=@pmHoraLlegaCargue,HoraEntraCargue=@pmHoraEntraCargue,HoraSaleCargue=@pmHoraSaleCargue,PactoDescargue=@pmPactoDescargue,HorasPactoDescargue=@pmHorasPactoDescargue,MinPactoDescargue=@pmMinPactoDescargue
,HoraCitaDescargue=@pmHoraCitaDescargue,HoraLlegaDescargue=@pmHoraLlegaDescargue,HoraEntraDescargue=@pmHoraEntraDescargue,HoraSaleDescargue=@pmHoraSaleDescargue,TipoDevRemesa=@pmTipoDevRemesa,CodCiuTransb=@pmCodCiuTransb,MvoTransbordo=@pmMvoTransbordo,CantViajes=@pmCantViajes,TipOrdMud=@pmTipOrdMud,ItemOsm=@pmItemOsm
,RemMTEstado=@pmRemMTEstado,Rem_Descr_Prod=@pmRem_Descr_Prod,Rem_FecchaReg=@pmRem_FecchaReg,PolizaMerPel=@pmPolizaMerPel,TipoConsolida=@pmTipoConsolida
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemesa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraRemesa] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmFecEntrega SMALLDATETIME,@pmHoraLlegada SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdClieFact VARCHAR(16),@pmIdRemitente VARCHAR(16),@pmIdDestinatario VARCHAR(16),@pmIdLocOrigen VARCHAR(8),@pmIdLocDestino VARCHAR(8),@pmIdLocFletes VARCHAR(8),@pmIdVehiculo VARCHAR(10)
,@pmIdConductor VARCHAR(16),@pmnRemolque VARCHAR(10),@pmTipoAfiVehic VARCHAR(10),@pmModalidad VARCHAR(10),@pmTipoTarifa VARCHAR(10),@pmVrCobro MONEY,@pmVrPagos MONEY,@pmVrFletes MONEY,@pmVrCargue MONEY,@pmVrDesCargue MONEY,@pmVrEscolta MONEY,@pmVrDevContdor MONEY,@pmVrTraUrbano MONEY,@pmVrEmbalajes MONEY,@pmVrCargos MONEY,@pmVrDctos MONEY,@pmVrDeclarado MONEY,@pmVrSeguro MONEY,@pmCantidad DECIMAL(14,4)
,@pmPesoTotal DECIMAL(14,4),@pmItems INT,@pmIdMneda VARCHAR(5),@pmVrTasa DECIMAL(14,4),@pmNumPedido INT,@pmIdCiaPed CHAR(2),@pmFechaPed SMALLDATETIME,@pmTipDcm VARCHAR(3),@pmNumDocmto INT,@pmIdCiaDcm CHAR(2),@pmFechaDcm SMALLDATETIME,@pmNumManif INT,@pmIdCiaManif CHAR(2),@pmEstCumplido INT,@pmEstFactura INT,@pmCdConcepto VARCHAR(4),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2),@pmAnulado BIT,@pmFecDev SMALLDATETIME
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmCdRutaTarif VARCHAR(4),@pmSerieGuia CHAR(2),@pmNumGuia INT,@pmCdForma VARCHAR(4),@pmNumCausac INT,@pmCdCiaCausac CHAR(2),@pmEdoCausac INT,@pmCdBodega VARCHAR(4),@pmVigenciaOdc INT,@pmVrTray_Vacio1 MONEY,@pmVrTray_Vacio2 MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_TraRemesa SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,FecEntrega=@pmFecEntrega,HoraLlegada=@pmHoraLlegada,IdCliente=@pmIdCliente,IdAgencia=@pmIdAgencia,IdClieFact=@pmIdClieFact,IdRemitente=@pmIdRemitente,IdDestinatario=@pmIdDestinatario,IdLocOrigen=@pmIdLocOrigen,IdLocDestino=@pmIdLocDestino,IdLocFletes=@pmIdLocFletes,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,nRemolque=@pmnRemolque,TipoAfiVehic=@pmTipoAfiVehic,Modalidad=@pmModalidad,TipoTarifa=@pmTipoTarifa
,VrCobro=@pmVrCobro,VrPagos=@pmVrPagos,VrFletes=@pmVrFletes,VrCargue=@pmVrCargue,VrDesCargue=@pmVrDesCargue,VrEscolta=@pmVrEscolta,VrDevContdor=@pmVrDevContdor,VrTraUrbano=@pmVrTraUrbano,VrEmbalajes=@pmVrEmbalajes,VrCargos=@pmVrCargos,VrDctos=@pmVrDctos,VrDeclarado=@pmVrDeclarado,VrSeguro=@pmVrSeguro,Cantidad=@pmCantidad,PesoTotal=@pmPesoTotal,Items=@pmItems,IdMneda=@pmIdMneda,VrTasa=@pmVrTasa,NumPedido=@pmNumPedido,IdCiaPed=@pmIdCiaPed,FechaPed=@pmFechaPed
,TipDcm=@pmTipDcm,NumDocmto=@pmNumDocmto,IdCiaDcm=@pmIdCiaDcm,FechaDcm=@pmFechaDcm,NumManif=@pmNumManif,IdCiaManif=@pmIdCiaManif,EstCumplido=@pmEstCumplido,EstFactura=@pmEstFactura,CdConcepto=@pmCdConcepto,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion,IdEstado=@pmIdEstado,CdRutaTarif=@pmCdRutaTarif,SerieGuia=@pmSerieGuia,NumGuia=@pmNumGuia,CdForma=@pmCdForma
,NumCausac=@pmNumCausac,CdCiaCausac=@pmCdCiaCausac,EdoCausac=@pmEdoCausac,CdBodega=@pmCdBodega,VigenciaOdc=@pmVigenciaOdc,VrTray_Vacio1=@pmVrTray_Vacio1,VrTray_Vacio2=@pmVrTray_Vacio2,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemesaAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraRemesaAnu] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmFecDev SMALLDATETIME,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Trn_TraRemesa SET  Anulado=@pmAnulado,FecDev=@pmFecDev,Observacion=@pmObservacion
,IdEstado=@pmIdEstado
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraRemMciasMuc]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraRemMciasMuc] @pmTipDoc VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdMercancia VARCHAR(16),@pmDescripMcias VARCHAR(250),@pmCantidad DECIMAL(14,4),@pmPesoNeto DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmdmsAlto DECIMAL(14,4),@pmdmsAncho DECIMAL(14,4),@pmdmsLargo DECIMAL(14,4),@pmVolumen DECIMAL(14,4)
,@pmUndVol VARCHAR(10),@pmIdUnd VARCHAR(4),@pmIdEmp VARCHAR(4),@pmIdNat VARCHAR(4),@pmIdTmcia VARCHAR(4),@pmIdMnjo VARCHAR(4),@pmCdRango VARCHAR(4),@pmCases INT,@pmCajas INT,@pmPalets INT,@pmNitRemite VARCHAR(16),@pmRemitente VARCHAR(250),@pmDirOrigen VARCHAR(250),@pmIdOrigen VARCHAR(8),@pmNitDestntario VARCHAR(16),@pmDestinatario VARCHAR(250)
,@pmDirDestino VARCHAR(250),@pmIdDestino VARCHAR(8),@pmTarifPago MONEY,@pmTarifTabla MONEY,@pmRemision DECIMAL(18,2),@pmDocCliente VARCHAR(30),@pmReferencia1 VARCHAR(50),@pmReferencia2 VARCHAR(50),@pmReferencia3 VARCHAR(50),@pmSedeRem VARCHAR(10),@pmSedeDest VARCHAR(10)
 AS 
 UPDATE Trn_TraRemMcias SET IdMercancia=@pmIdMercancia,DescripMcias=@pmDescripMcias,Cantidad=@pmCantidad,PesoNeto=@pmPesoNeto,UndMed=@pmUndMed,dmsAlto=@pmdmsAlto,dmsAncho=@pmdmsAncho,dmsLargo=@pmdmsLargo,Volumen=@pmVolumen,UndVol=@pmUndVol,IdUnd=@pmIdUnd,IdEmp=@pmIdEmp,IdNat=@pmIdNat,IdTmcia=@pmIdTmcia,IdMnjo=@pmIdMnjo,CdRango=@pmCdRango
,Cases=@pmCases,Cajas=@pmCajas,Palets=@pmPalets,NitRemite=@pmNitRemite,Remitente=@pmRemitente,DirOrigen=@pmDirOrigen,IdOrigen=ISNULL(@pmIdOrigen,IdOrigen),NitDestntario=@pmNitDestntario,Destinatario=@pmDestinatario,DirDestino=@pmDirDestino,IdDestino=ISNULL(@pmIdDestino,IdDestino),TarifPago=ISNULL(@pmTarifPago,TarifPago),TarifTabla=ISNULL(@pmTarifTabla,TarifTabla)
,Remision=@pmRemision,DocCliente=@pmDocCliente,Referencia1=@pmReferencia1,Referencia2=@pmReferencia2,Referencia3=@pmReferencia3,SedeRem=@pmSedeRem,SedeDest=@pmSedeDest
 WHERE TipDoc=@pmTipDoc AND NumOrden=@pmNumOrden AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTraReportes]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraReportes] @pmTipDoc VARCHAR(3),@pmManifiesto INT,@pmIdCia CHAR(2),@pmItem INT,@pmCdRuta VARCHAR(4),@pmIdPunto INT,@pmFecReporte SMALLDATETIME,@pmTipoRep VARCHAR(10)
,@pmEstadoRep INT,@pmCdNovedad VARCHAR(4),@pmObservRep VARCHAR(250),@pmTipoPunto VARCHAR(10),@pmCdPuesto VARCHAR(4),@pmNomConductor VARCHAR(150)
 AS 
 UPDATE Trn_TraReportes SET CdRuta=@pmCdRuta,IdPunto=@pmIdPunto,FecReporte=@pmFecReporte,TipoRep=@pmTipoRep,EstadoRep=@pmEstadoRep,CdNovedad=@pmCdNovedad,ObservRep=@pmObservRep
,TipoPunto=@pmTipoPunto,CdPuesto=@pmCdPuesto,NomConductor=@pmNomConductor
 WHERE TipDoc=@pmTipDoc AND Manifiesto=@pmManifiesto AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpTraslados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmIdConcepto VARCHAR(4),@pmIdTercero VARCHAR(16),@pmVrSubTotal MONEY,@pmCantidad DECIMAL(14,4)
,@pmNumDcmto INT,@pmNumOrden INT,@pmIdCCosto VARCHAR(16),@pmIdSubCos VARCHAR(16),@pmModalidad VARCHAR(10),@pmTipCom VARCHAR(3),@pmComprobante INT,@pmIdCiaCom CHAR(2)
,@pmObservacion VARCHAR(250),@pmIdEstado VARCHAR(4),@pmTdOrden VARCHAR(3),@pmCdCiaOrden CHAR(2),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Trn_Traslados SET Fecha=@pmFecha,IdConcepto=@pmIdConcepto,IdTercero=@pmIdTercero,VrSubTotal=@pmVrSubTotal,Cantidad=@pmCantidad,NumDcmto=@pmNumDcmto,NumOrden=@pmNumOrden
,IdCCosto=@pmIdCCosto,IdSubCos=@pmIdSubCos,Modalidad=@pmModalidad,TipCom=@pmTipCom,Comprobante=@pmComprobante,IdCiaCom=@pmIdCiaCom,Observacion=@pmObservacion,TdOrden=@pmTdOrden,CdCiaOrden=@pmCdCiaOrden
,IdEstado=@pmIdEstado,FecUpdate=@pmFecUpdate
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTalonarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraTalonarios] @pmIdTalonario INT,@pmFecha SMALLDATETIME,@pmNumSerie CHAR(2),@pmNumInicial INT,@pmNumFinal INT,@pmNumAuto BIT,@pmNumActual INT
,@pmIdRespons VARCHAR(16),@pmNomRespons VARCHAR(150),@pmAnulado BIT
 AS 
 UPDATE Trn_TraTalonarios SET Fecha=@pmFecha,NumSerie=@pmNumSerie,NumInicial=@pmNumInicial,NumFinal=@pmNumFinal,NumAuto=@pmNumAuto
,NumActual=@pmNumActual,IdRespons=@pmIdRespons,NomRespons=@pmNomRespons,Anulado=@pmAnulado
 WHERE IdTalonario=@pmIdTalonario
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTraslados]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraTraslados] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2),@pmFecha SMALLDATETIME,@pmFecDespacho SMALLDATETIME,@pmTipoTraslado INT,@pmIdBodega VARCHAR(4),@pmIdBodDtno VARCHAR(4),@pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmCantidad INT,@pmPesoTotal DECIMAL(14,4)
,@pmManifiesto INT,@pmCdCiaMuc CHAR(2),@pmEstadoRec INT,@pmFechaRec SMALLDATETIME,@pmCedRecibido VARCHAR(16),@pmNomRecibido VARCHAR(150),@pmObservacion VARCHAR(1000)
 AS 
 UPDATE Trn_TraTraslados SET Fecha=@pmFecha,FecDespacho=@pmFecDespacho,TipoTraslado=@pmTipoTraslado,IdBodega=@pmIdBodega,IdBodDtno=@pmIdBodDtno,IdVehiculo=@pmIdVehiculo,IdConductor=@pmIdConductor,Cantidad=@pmCantidad,PesoTotal=@pmPesoTotal,Manifiesto=@pmManifiesto
,CdCiaMuc=@pmCdCiaMuc,EstadoRec=@pmEstadoRec,FechaRec=@pmFechaRec,CedRecibido=@pmCedRecibido,NomRecibido=@pmNomRecibido,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTrasladosAnu]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraTrasladosAnu] @pmTipDoc VARCHAR(3),@pmTraslado INT,@pmIdCia CHAR(2)
,@pmEstadoRec INT,@pmFechaRec SMALLDATETIME,@pmObservacion VARCHAR(1000)
 AS 
 UPDATE Trn_TraTraslados SET EstadoRec=@pmEstadoRec,FechaRec=@pmFechaRec,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND Traslado=@pmTraslado AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTraTurn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTraTurn] @pmNumero INT,@pmIdCia CHAR(2),@pmIdVehiculo VARCHAR(10),@pmIndTurno INT,@pmFecha SMALLDATETIME,@pmIdConductor VARCHAR(16)
,@pmnRemolque VARCHAR(10),@pmEstado INT,@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCiaOrd CHAR(2),@pmFecOrden SMALLDATETIME,@pmNitCliente VARCHAR(16),@pmSedeClie VARCHAR(10),@pmAutorizac INT
 AS 
 UPDATE Trn_TraTurn SET IdVehiculo=@pmIdVehiculo,IndTurno=@pmIndTurno,Fecha=@pmFecha,IdConductor=@pmIdConductor,nRemolque=@pmnRemolque,Estado=@pmEstado
,TipOrd=@pmTipOrd,NumOrden=@pmNumOrden,IdCiaOrd=@pmIdCiaOrd,FecOrden=@pmFecOrden,NitCliente=@pmNitCliente,SedeClie=@pmSedeClie,Autorizac=@pmAutorizac
 WHERE Numero=@pmNumero AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpTurnos]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTurnos] @pmIdTurno VARCHAR(4),@pmTurno VARCHAR(50),@pmHoraInicial VARCHAR(10),@pmHoraFinal VARCHAR(10),@pmInactivo BIT
 AS 
 UPDATE Turnos SET Turno=@pmTurno,HoraInicial=@pmHoraInicial,HoraFinal=@pmHoraFinal,Inactivo=@pmInactivo
 WHERE IdTurno=@pmIdTurno
GO
/****** Object:  StoredProcedure [dbo].[paUpUm]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpUm] @pmUndMed VARCHAR(10),@pmUnidad VARCHAR(50),@pmCarga BIT,@pmCodUMFE VARCHAR(20)
 AS 
 UPDATE Sys_Um SET Unidad=@pmUnidad,Carga=@pmCarga,CodUMFE=@pmCodUMFE
 WHERE UndMed=@pmUndMed
GO
/****** Object:  StoredProcedure [dbo].[paUpUndMed]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpUndMed] @pmIdUnd VARCHAR(4),@pmUnidad VARCHAR(50),@pmIdMat VARCHAR(4),@pmIdEmp VARCHAR(4),@pmFormRecp VARCHAR(10),@pmClaseEmp VARCHAR(10),@pmDimAlto DECIMAL(14,4)
,@pmDimAncho DECIMAL(14,4),@pmDimLargo DECIMAL(14,4),@pmDimVolm DECIMAL(14,4),@pmUndMed VARCHAR(10),@pmPesoEpq DECIMAL(14,4),@pmCapcMax DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmSimbUnd VARCHAR(10)
,@pmObserv VARCHAR(250),@pmInactivo BIT
 AS 
 UPDATE UndMed SET Unidad=@pmUnidad,IdMat=@pmIdMat,IdEmp=@pmIdEmp,FormRecp=@pmFormRecp,ClaseEmp=@pmClaseEmp,DimAlto=@pmDimAlto,DimAncho=@pmDimAncho,DimLargo=@pmDimLargo,DimVolm=@pmDimVolm
,UndMed=@pmUndMed,PesoEpq=@pmPesoEpq,CapcMax=@pmCapcMax,UndCapc=@pmUndCapc,SimbUnd=@pmSimbUnd,Observ=@pmObserv,Inactivo=@pmInactivo
 WHERE IdUnd=@pmIdUnd
GO
/****** Object:  StoredProcedure [dbo].[paUpUOpciones]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpUOpciones] @pmIdUsuario VARCHAR(11),@pmNomOpcion VARCHAR(20),@pmValor VARCHAR(50)
 AS 
 UPDATE adm_UOpciones SET Valor=@pmValor
 WHERE IdUsuario=@pmIdUsuario AND NomOpcion=@pmNomOpcion
GO
/****** Object:  StoredProcedure [dbo].[paUpUsuarios]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpUsuarios] @pmIdUsuario VARCHAR(11),@pmUsuario VARCHAR(50),@pmPwdLog VARCHAR(30),@pmIdGrupo INT,@pmIdEstacion CHAR(2),@pmIdCargo VARCHAR(4),@pmConectado BIT,@pmFechaAcc SMALLDATETIME
,@pmFechaClave SMALLDATETIME,@pmCaducidad INT,@pmLoginSQL VARCHAR(20),@pmPwdSQL VARCHAR(20),@pmModoSQL VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE adm_Usuarios SET Usuario=@pmUsuario,PwdLog=@pmPwdLog,IdGrupo=@pmIdGrupo,IdEstacion=@pmIdEstacion,IdCargo=@pmIdCargo,Conectado=@pmConectado,FechaAcc=@pmFechaAcc,FechaClave=@pmFechaClave,Caducidad=@pmCaducidad
,LoginSQL=@pmLoginSQL,PwdSQL=@pmPwdSQL,ModoSQL=@pmModoSQL,Inactivo=@pmInactivo
 WHERE IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpUsuariosCnn]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpUsuariosCnn]  @pmConectado BIT,@pmFechaAcc SMALLDATETIME,@pmIdUsuario VARCHAR(11)
AS
 IF @pmConectado<>0
 UPDATE adm_Usuarios SET Conectado=@pmConectado,FechaAcc=@pmFechaAcc WHERE IdUsuario=@pmIdUsuario
ELSE
 UPDATE adm_Usuarios SET Conectado=@pmConectado  WHERE IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpUsuariosPwd]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpUsuariosPwd]  @pmPwdLog VARCHAR(30),@pmFechaClave SMALLDATETIME,@pmIdUsuario VARCHAR(11)
AS
UPDATE adm_Usuarios SET PwdLog=@pmPwdLog,FechaClave=@pmFechaClave
WHERE IdUsuario=@pmIdUsuario
GO
/****** Object:  StoredProcedure [dbo].[paUpUsucaja]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpUsucaja] @pmIdUsuario VARCHAR(11),@pmnFormato VARCHAR(10),@pmCdCajero VARCHAR(11),@pmIdConcepto VARCHAR(4)
,@pmCdBodega VARCHAR(4),@pmLtaPrec CHAR(1),@pmIdVend VARCHAR(16),@pmCdCms VARCHAR(4),@pmCdCCosto VARCHAR(16)
,@pmCdSubCos VARCHAR(16),@pmAbreCajon VARCHAR(10)
 AS 
 UPDATE adm_Usucaja SET CdCajero=@pmCdCajero,IdConcepto=@pmIdConcepto,CdBodega=@pmCdBodega,LtaPrec=@pmLtaPrec,IdVend=@pmIdVend
,CdCms=@pmCdCms,CdCCosto=@pmCdCCosto,CdSubCos=@pmCdSubCos,AbreCajon=@pmAbreCajon
 WHERE IdUsuario=@pmIdUsuario AND nFormato=@pmnFormato
GO
/****** Object:  StoredProcedure [dbo].[paUpValesDev]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpValesDev] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_Vales SET  Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpValesDevItem]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpValesDevItem] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2)
,@pmTipoRango VARCHAR(3),@pmIdRango INT,@pmNumSerie VARCHAR(5),@pmNumForma INT
,@pmAnulado BIT,@pmNumDev INT,@pmFecDev SMALLDATETIME
 AS 
 UPDATE Trn_Vales SET Anulado=@pmAnulado,NumDev=@pmNumDev,FecDev=@pmFecDev
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia 
 AND TipoRango=@pmTipoRango AND IdRango=@pmIdRango AND NumSerie=@pmNumSerie AND NumForma=@pmNumForma
GO
/****** Object:  StoredProcedure [dbo].[paUpValesDfa]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpValesDfa] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmItem INT
 AS 
 UPDATE Trn_Vales SET  TipFac='0',NumFactura=0,IdCiaFac='00'
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpValesFac]    Script Date: 10/12/2025 8:11:25 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpValesFac] @pmTipDoc VARCHAR(3),@pmnRadica INT,@pmIdCia CHAR(2),@pmItem INT
,@pmTipFac VARCHAR(3),@pmNumFactura INT,@pmIdCiaFac CHAR(2),@pmFechaFac SMALLDATETIME
 AS 
 UPDATE Trn_Vales SET TipFac=@pmTipFac,NumFactura=@pmNumFactura,IdCiaFac=@pmIdCiaFac,FechaFac=@pmFechaFac
 WHERE TipDoc=@pmTipDoc AND nRadica=@pmnRadica AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_Contrato]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVeh_Contrato] @pmNumContrato INT,@pmIdVehiculo VARCHAR(10),@pmIdAdmon VARCHAR(4),@pmIdTipCon VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecRetiro SMALLDATETIME
,@pmFecVigencia SMALLDATETIME,@pmObservaciones VARCHAR(250),@pmNumPagare VARCHAR(20),@pmArchPagare VARCHAR(50),@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Veh_Contrato SET IdVehiculo=@pmIdVehiculo,IdAdmon=@pmIdAdmon,IdTipCon=@pmIdTipCon,FecIngreso=@pmFecIngreso,FecRetiro=@pmFecRetiro
,FecVigencia=@pmFecVigencia,Observaciones=@pmObservaciones,NumPagare=@pmNumPagare,ArchPagare=@pmArchPagare,FecUpdate=@pmFecUpdate
 WHERE NumContrato=@pmNumContrato
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_Cupos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVeh_Cupos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmValorCupo MONEY
,@pmValorSaldo MONEY,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE Veh_Cupos SET ValorCupo=@pmValorCupo,ValorSaldo=@pmValorSaldo,FecUpdate=@pmFecUpdate
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_CuposAll]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVeh_CuposAll] @pmIdVehiculo VARCHAR(10)=Null,@pmIdClase VARCHAR(4)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
 IF @pmIdVehiculo IS NULL
  UPDATE  Veh_Cupos SET   ValorSaldo=0
  FROM Vehiculos AS V INNER JOIN  Veh_Cupos AS C ON V.IdVehiculo=C.IdVehiculo
  WHERE   C.IdClase LIKE ISNULL(@pmIdClase,'%') AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%') 
 ELSE
  UPDATE  Veh_Cupos SET   ValorSaldo=0 
  WHERE IdVehiculo=@pmIdVehiculo AND IdClase LIKE ISNULL(@pmIdClase,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_CuposSal]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVeh_CuposSal] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmValorSaldo MONEY

AS
  UPDATE Veh_Cupos  SET ValorSaldo=@pmValorSaldo
  WHERE  IdVehiculo=@pmIdVehiculo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpVeh_Saldos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVeh_Saldos] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmIdCia CHAR(2),@pmValorSaldo MONEY
 AS 
 UPDATE Veh_Saldos SET ValorSaldo=@pmValorSaldo
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase=@pmIdClase AND IdCia=@pmIdCia
GO
/****** Object:  StoredProcedure [dbo].[paUpVehClientes]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehClientes] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmIdTipoVeh VARCHAR(4),@pmIdMarca VARCHAR(4),@pmLinMarca VARCHAR(30),@pmColorVeh VARCHAR(30),@pmIdTipoMot VARCHAR(4),@pmModelo VARCHAR(4),@pmClaseMat VARCHAR(10),@pmCilind DECIMAL(14,4),@pmIdCom VARCHAR(4),@pmIdLub VARCHAR(4)
,@pmIdMarLub VARCHAR(4),@pmIdTlla VARCHAR(4),@pmIdMarlla VARCHAR(4),@pmIdFiltro VARCHAR(4),@pmIdMarFil VARCHAR(4),@pmNumSoat VARCHAR(30),@pmFecSoat SMALLDATETIME,@pmVigSoat SMALLDATETIME,@pmNitEmpSoat VARCHAR(16),@pmRevTecMec VARCHAR(30),@pmFecTecMec SMALLDATETIME,@pmVigTecMec SMALLDATETIME
,@pmCertGases VARCHAR(30),@pmFecCertGas SMALLDATETIME,@pmVigCertGas SMALLDATETIME,@pmKmInicial INT,@pmKmActual INT,@pmNitCliente VARCHAR(16),@pmCondPago VARCHAR(10),@pmNumCredito VARCHAR(30),@pmObservacion VARCHAR(250),@pmPathFoto VARCHAR(30),@pmFecPriServ SMALLDATETIME,@pmFecUltServ SMALLDATETIME
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE VehClientes SET NumVeh=@pmNumVeh,IdTipoVeh=@pmIdTipoVeh,IdMarca=@pmIdMarca,LinMarca=@pmLinMarca,ColorVeh=@pmColorVeh,IdTipoMot=@pmIdTipoMot,Modelo=@pmModelo,ClaseMat=@pmClaseMat,Cilind=@pmCilind,IdCom=@pmIdCom,IdLub=@pmIdLub,IdMarLub=@pmIdMarLub,IdTlla=@pmIdTlla,IdMarlla=@pmIdMarlla,IdFiltro=@pmIdFiltro
,IdMarFil=@pmIdMarFil,NumSoat=@pmNumSoat,FecSoat=@pmFecSoat,VigSoat=@pmVigSoat,NitEmpSoat=@pmNitEmpSoat,RevTecMec=@pmRevTecMec,FecTecMec=@pmFecTecMec,VigTecMec=@pmVigTecMec,CertGases=@pmCertGases,FecCertGas=@pmFecCertGas,VigCertGas=@pmVigCertGas,KmInicial=@pmKmInicial,KmActual=@pmKmActual
,NitCliente=@pmNitCliente,CondPago=@pmCondPago,NumCredito=@pmNumCredito,Observacion=@pmObservacion,PathFoto=@pmPathFoto,FecPriServ=@pmFecPriServ,FecUltServ=@pmFecUltServ,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FechaUpdate=@pmFechaUpdate
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehiculos] @pmIdVehiculo VARCHAR(10),@pmNumVeh VARCHAR(10),@pmClaseVeh VARCHAR(10),@pmIdTipoVeh VARCHAR(4),@pmIdMarca VARCHAR(4),@pmIdLinea VARCHAR(10),@pmIdColor VARCHAR(4),@pmIdTipoMot VARCHAR(4),@pmIdCrceria VARCHAR(4),@pmModelo VARCHAR(4),@pmFecRep SMALLDATETIME,@pmConfig VARCHAR(5),@pmVehArtic BIT,@pmNumLlan INT,@pmNumLlans INT,@pmIdCat VARCHAR(4),@pmCdCatv VARCHAR(4)
,@pmClaseMat VARCHAR(10),@pmCilind DECIMAL(14,4),@pmCapTanq DECIMAL(14,4),@pmIdCom VARCHAR(4),@pmIdLub VARCHAR(4),@pmIdTlla VARCHAR(4),@pmIdMarlla VARCHAR(4),@pmPesoVacio DECIMAL(14,4),@pmPesoMax DECIMAL(14,4),@pmNumMotor VARCHAR(30),@pmSerieChasis VARCHAR(30),@pmNumSerie VARCHAR(30),@pmCdRemque VARCHAR(10),@pmLongitud DECIMAL(14,4),@pmCarrAlto DECIMAL(14,4),@pmCarrAncho DECIMAL(14,4),@pmCarrLargo DECIMAL(14,4)
,@pmCarrCapac DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmComptmtos INT,@pmCapComp VARCHAR(50),@pmPasjerosPie INT,@pmPasjerosSen INT,@pmNitEmpresa VARCHAR(16),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16),@pmIdConductor VARCHAR(16),@pmIdPpd VARCHAR(4),@pmAdquisc VARCHAR(10),@pmNitProv VARCHAR(16),@pmFecCompra SMALLDATETIME,@pmVrComcial MONEY,@pmVrAseg MONEY,@pmVrAvaludo MONEY,@pmVidaUtil INT
,@pmFecSalida SMALLDATETIME,@pmNContrato INT,@pmIdAdmon VARCHAR(4),@pmIdNiv VARCHAR(4),@pmIdGrupo VARCHAR(4),@pmCdGrupR VARCHAR(4),@pmCdTarifa VARCHAR(4),@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME,@pmNumSoat VARCHAR(30),@pmFecSoat SMALLDATETIME,@pmVigSoat SMALLDATETIME,@pmNitEmpSoat VARCHAR(16),@pmTarjProp VARCHAR(30),@pmFecTProp SMALLDATETIME
,@pmVigTProp SMALLDATETIME,@pmCdLugTp VARCHAR(8),@pmUlttramite VARCHAR(150),@pmRespCivil VARCHAR(30),@pmFecRCivil SMALLDATETIME,@pmVigRCivil SMALLDATETIME,@pmRegNalCarga VARCHAR(30),@pmFecRegNal SMALLDATETIME,@pmVigRegNal SMALLDATETIME,@pmKmInicial INT,@pmKmActual INT,@pmKm2Actual INT,@pmRegtradora BIT,@pmCentInicial INT,@pmCentFinal INT,@pmVrLmtCred MONEY,@pmVrSaldoAct MONEY,@pmDescripcion VARCHAR(100)
,@pmObservacion VARCHAR(250),@pmCdCenSer VARCHAR(4),@pmCdLocal VARCHAR(8),@pmUbicacion VARCHAR(100),@pmPathFoto VARCHAR(30),@pmFecPriServ SMALLDATETIME,@pmFecUltServ SMALLDATETIME,@pmFecUltAcc SMALLDATETIME,@pmTieneAcc BIT,@pmFecPagImp SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmTipoAfil VARCHAR(10),@pmRevTecMec VARCHAR(30),@pmFecTecMec SMALLDATETIME,@pmVigTecMec SMALLDATETIME,@pmCertGases VARCHAR(30),@pmFecCertGas SMALLDATETIME,@pmVigCertGas SMALLDATETIME,@pmTarjOper VARCHAR(30),@pmFecTarjOper SMALLDATETIME,@pmVigTarjOper SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
,@pmValorCupo MONEY,@pmObligaTProd BIT,@pmGarantiaAcc BIT,@pmDocCompleta BIT,@pmCertMovilizacion VARCHAR(20),@pmFecCertMovil SMALLDATETIME,@pmVigCertMovil SMALLDATETIME,@pmCdRutaHab VARCHAR(4),@pmDeclaracImp VARCHAR(50),@pmTipoIngreso VARCHAR(4),@pmIdOrgTra VARCHAR(8),@pmGPSoperador VARCHAR(250),@pmGPSUsuario VARCHAR(50),@pmGPSClave VARCHAR(50),@pmCantFiltros DECIMAL(14,4),@pmGPSIdOper VARCHAR(16),@pmLiqFletePropio BIT,@pmEdoVincula INT
 AS 
 UPDATE Vehiculos SET NumVeh=@pmNumVeh,ClaseVeh=@pmClaseVeh,IdTipoVeh=@pmIdTipoVeh,IdMarca=@pmIdMarca,IdLinea=@pmIdLinea,IdColor=@pmIdColor,IdTipoMot=@pmIdTipoMot,IdCrceria=@pmIdCrceria,Modelo=@pmModelo,FecRep=@pmFecRep,Config=@pmConfig,VehArtic=@pmVehArtic,NumLlan=@pmNumLlan,NumLlans=@pmNumLlans,IdCat=@pmIdCat,CdCatv=@pmCdCatv,ClaseMat=@pmClaseMat,Cilind=@pmCilind,CapTanq=@pmCapTanq,IdCom=@pmIdCom,IdLub=@pmIdLub
,IdTlla=@pmIdTlla,IdMarlla=@pmIdMarlla,PesoVacio=@pmPesoVacio,PesoMax=@pmPesoMax,NumMotor=@pmNumMotor,SerieChasis=@pmSerieChasis,NumSerie=@pmNumSerie,CdRemque=@pmCdRemque,Longitud=@pmLongitud,CarrAlto=@pmCarrAlto,CarrAncho=@pmCarrAncho,CarrLargo=@pmCarrLargo,CarrCapac=@pmCarrCapac,UndCapc=@pmUndCapc,Comptmtos=@pmComptmtos,CapComp=@pmCapComp,PasjerosPie=@pmPasjerosPie,PasjerosSen=@pmPasjerosSen,NitEmpresa=@pmNitEmpresa
,IdPropietario=@pmIdPropietario,IdPoseedor=@pmIdPoseedor,IdConductor=@pmIdConductor,IdPpd=@pmIdPpd,Adquisc=@pmAdquisc,NitProv=@pmNitProv,FecCompra=@pmFecCompra,VrComcial=@pmVrComcial,VrAseg=@pmVrAseg,VrAvaludo=@pmVrAvaludo,VidaUtil=@pmVidaUtil,FecSalida=@pmFecSalida,NContrato=@pmNContrato,IdAdmon=@pmIdAdmon,IdNiv=@pmIdNiv,IdGrupo=@pmIdGrupo,CdGrupR=@pmCdGrupR,CdTarifa=@pmCdTarifa,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia
,FecRetiro=@pmFecRetiro,NumSoat=@pmNumSoat,FecSoat=@pmFecSoat,VigSoat=@pmVigSoat,NitEmpSoat=@pmNitEmpSoat,TarjProp=@pmTarjProp,FecTProp=@pmFecTProp,VigTProp=@pmVigTProp,CdLugTp=@pmCdLugTp,Ulttramite=@pmUlttramite,RespCivil=@pmRespCivil,FecRCivil=@pmFecRCivil,VigRCivil=@pmVigRCivil,RegNalCarga=@pmRegNalCarga,FecRegNal=@pmFecRegNal,VigRegNal=@pmVigRegNal,KmInicial=@pmKmInicial,KmActual=@pmKmActual,Km2Actual=@pmKm2Actual
,Regtradora=@pmRegtradora,CentInicial=@pmCentInicial,CentFinal=@pmCentFinal,VrLmtCred=@pmVrLmtCred,VrSaldoAct=@pmVrSaldoAct,Descripcion=@pmDescripcion,Observacion=@pmObservacion,CdCenSer=@pmCdCenSer,CdLocal=@pmCdLocal,Ubicacion=@pmUbicacion,PathFoto=@pmPathFoto,FecPriServ=@pmFecPriServ,FecUltServ=@pmFecUltServ,FecUltAcc=@pmFecUltAcc,TieneAcc=@pmTieneAcc,FecPagImp=@pmFecPagImp,IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,TipoAfil=@pmTipoAfil,RevTecMec=@pmRevTecMec,FecTecMec=@pmFecTecMec,VigTecMec=@pmVigTecMec,CertGases=@pmCertGases,FecCertGas=@pmFecCertGas,VigCertGas=@pmVigCertGas,TarjOper=@pmTarjOper,FecTarjOper=@pmFecTarjOper,VigTarjOper=@pmVigTarjOper,FechaUpdate=@pmFechaUpdate
,ValorCupo=@pmValorCupo,ObligaTProd=@pmObligaTProd,GarantiaAcc=@pmGarantiaAcc,DocCompleta=@pmDocCompleta,CertMovilizacion=@pmCertMovilizacion,FecCertMovil=@pmFecCertMovil,VigCertMovil=@pmVigCertMovil,CdRutaHab=@pmCdRutaHab,DeclaracImp=@pmDeclaracImp,TipoIngreso=@pmTipoIngreso,IdOrgTra=@pmIdOrgTra,GPSoperador=@pmGPSoperador,GPSUsuario=@pmGPSUsuario,GPSClave=@pmGPSClave,CantFiltros=@pmCantFiltros,GPSIdOper=@pmGPSIdOper,LiqFletePropio=@pmLiqFletePropio,EdoVincula=@pmEdoVincula
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosAcu]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosAcu] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
 IF @pmIdVehiculo IS NULL
  UPDATE Vehiculos SET VrSaldoAct=(SELECT ISNULL(SUM(ValorSaldo),0) FROM Veh_Saldos 
  WHERE Vehiculos.IdVehiculo=Veh_Saldos.IdVehiculo)
  WHERE  IdPropietario LIKE ISNULL(@pmIdPropietario,'%') 
ELSE
  UPDATE Vehiculos SET VrSaldoAct=(SELECT ISNULL(SUM(ValorSaldo),0) FROM Veh_Saldos 
  WHERE Vehiculos.IdVehiculo=Veh_Saldos.IdVehiculo)
  WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCdt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosCdt] @pmIdVehiculo VARCHAR(10),@pmIdConductor VARCHAR(16),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Vehiculos SET IdConductor=@pmIdConductor,FechaUpdate=@pmFechaUpdate
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCen]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosCen] @pmIdVehiculo VARCHAR(10),@pmCentInicial INT,@pmCentFinal INT
AS
 UPDATE  Vehiculos  SET  CentInicial=@pmCentInicial,CentFinal=@pmCentFinal
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCon]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosCon] @pmIdVehiculo VARCHAR(10),@pmNContrato INT,@pmIdAdmon VARCHAR(4)
,@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME
 AS 
 UPDATE Vehiculos SET NContrato=@pmNContrato,IdAdmon=@pmIdAdmon,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia
,FecRetiro=@pmFecRetiro
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosCup]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosCup] @pmIdVehiculo VARCHAR(10),@pmVrLmtCred MONEY,@pmVrSaldoAct MONEY
 AS 
 UPDATE Vehiculos SET  VrLmtCred=@pmVrLmtCred,VrSaldoAct=@pmVrSaldoAct
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosEcon]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosEcon] @pmIdVehiculo VARCHAR(10),@pmNContrato INT,@pmIdAdmon VARCHAR(4)
,@pmFecIngreso SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmFecRetiro SMALLDATETIME
 AS 
 UPDATE Vehiculos SET NContrato=0,IdAdmon=@pmIdAdmon,FecIngreso=@pmFecIngreso,FecVigencia=@pmFecVigencia
,FecRetiro=@pmFecRetiro
 WHERE IdVehiculo=@pmIdVehiculo AND NContrato=@pmNContrato
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosEst]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosEst] @pmIdVehiculo VARCHAR(10),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmObservacion VARCHAR(250),@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Vehiculos SET IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Observacion=@pmObservacion,FechaUpdate=@pmFechaUpdate
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosKmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosKmt] @pmIdVehiculo VARCHAR(10),@pmKmActual INT,@pmKm2Actual INT,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Vehiculos SET KmActual=@pmKmActual,Km2Actual=@pmKm2Actual,FechaUpdate=@pmFechaUpdate
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosMuc]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosMuc] @pmIdVehiculo VARCHAR(10),@pmCdLocal VARCHAR(8),@pmUbicacion VARCHAR(100)
,@pmFecMuc SMALLDATETIME,@pmCdRutaHab VARCHAR(4)
 AS 
 UPDATE Vehiculos SET CdLocal=@pmCdLocal,Ubicacion=@pmUbicacion,FecUltServ=@pmFecMuc
,FecPriServ=ISNULL(FecPriServ,@pmFecMuc),CdRutaHab=@pmCdRutaHab
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosRet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosRet] @pmIdVehiculo VARCHAR(10),@pmIdEstado VARCHAR(4),@pmInactivo BIT
,@pmObservacion VARCHAR(250),@pmFecRetiro SMALLDATETIME,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Vehiculos SET FecRetiro=@pmFecRetiro,IdEstado=@pmIdEstado,Inactivo=@pmInactivo
,Observacion=@pmObservacion,FechaUpdate=@pmFechaUpdate
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosRetB]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosRetB]  @pmIdVehiculo VARCHAR(10),@pmNumContrato INT
,@pmFecRetiro SMALLDATETIME,@pmIdEstado VARCHAR(4),@pmObservacion VARCHAR(250)
,@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT
AS
 UPDATE  Vehiculos  SET  NContrato=@pmNumContrato,FecRetiro=@pmFecRetiro
 ,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,Observacion=@pmObservacion,FechaUpdate=@pmFechaUpdate
 WHERE  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosSal]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosSal] @pmIdVehiculo VARCHAR(10),@pmSaldoActual MONEY
AS
  UPDATE Vehiculos  SET VrSaldoAct=@pmSaldoActual
  WHERE  IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosSCero]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosSCero] @pmIdVehiculo VARCHAR(10)=Null,@pmIdPropietario VARCHAR(16)=Null
AS
  UPDATE Vehiculos  SET VrSaldoAct=0
  WHERE  IdVehiculo LIKE ISNULL(@pmIdVehiculo,'%') AND IdPropietario LIKE ISNULL(@pmIdPropietario,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosTra]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehiculosTra] @pmIdVehiculo VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmIdPoseedor VARCHAR(16)
,@pmIdPpd VARCHAR(4),@pmVrComcial MONEY,@pmVrAseg MONEY,@pmIdGrupo VARCHAR(4),@pmTipoAfil VARCHAR(10)
,@pmFechaUpdate SMALLDATETIME
 AS 
 UPDATE Vehiculos SET IdPropietario=@pmIdPropietario,IdPoseedor=@pmIdPoseedor,IdPpd=@pmIdPpd,TipoAfil=@pmTipoAfil
,VrComcial=@pmVrComcial,VrAseg=@pmVrAseg,IdGrupo=@pmIdGrupo,FechaUpdate=@pmFechaUpdate
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehiculosUbi]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehiculosUbi] @pmIdVehiculo VARCHAR(10),@pmCdLocal VARCHAR(8),@pmUbicacion VARCHAR(100)
,@pmCdCenSer VARCHAR(4),@pmIdEstado VARCHAR(4)
 AS 
 UPDATE Vehiculos SET CdLocal=@pmCdLocal,Ubicacion=@pmUbicacion
,CdCenSer=ISNULL(@pmCdCenSer,CdCenSer),IdEstado=ISNULL(@pmIdEstado,IdEstado)
 WHERE IdVehiculo=@pmIdVehiculo
GO
/****** Object:  StoredProcedure [dbo].[paUpVehLecturas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehLecturas] @pmTipDoc VARCHAR(3),@pmNumero INT,@pmIdCia CHAR(2),@pmItem INT,@pmFecha SMALLDATETIME,@pmTipoUnidad VARCHAR(3),@pmpVehiculo VARCHAR(10)
,@pmKmsAnterior INT,@pmKmsActual INT,@pmKms2Anterior INT,@pmKms2Actual INT,@pmTipoLectura VARCHAR(10),@pmObservacion VARCHAR(250)
 AS 
 UPDATE Trn_VehLecturas SET Fecha=@pmFecha,TipoUnidad=@pmTipoUnidad,pVehiculo=@pmpVehiculo,KmsAnterior=@pmKmsAnterior,KmsActual=@pmKmsActual,Kms2Anterior=@pmKms2Anterior,Kms2Actual=@pmKms2Actual
,TipoLectura=@pmTipoLectura,Observacion=@pmObservacion
 WHERE TipDoc=@pmTipDoc AND Numero=@pmNumero AND IdCia=@pmIdCia AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpVehPartes]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehPartes] @pmIdVehiculo VARCHAR(10),@pmNumParte VARCHAR(20),@pmDescripParte VARCHAR(250),@pmIdSistema VARCHAR(4),@pmTipoControl INT,@pmIntervalo_km INT,@pmIntervalo_dias INT,@pmkmActual INT,@pmkmCambio INT
,@pmFechaCambio SMALLDATETIME,@pmCdProdRep VARCHAR(16),@pmTipoUnidad CHAR(1),@pmTipoParte VARCHAR(10),@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmFechaRetiro SMALLDATETIME,@pmIntervalo_Horas INT
,@pmkmManual INT,@pmkmSat INT,@pmkmCambioMan INT,@pmkmCambioSat INT,@pmHorasTrab INT,@pmHsUltCambio INT,@pmMarcaParte VARCHAR(20),@pmModeloParte VARCHAR(20),@pmNumSerie VARCHAR(30)
 AS 
 UPDATE VehPartes SET DescripParte=@pmDescripParte,IdSistema=@pmIdSistema,TipoControl=@pmTipoControl,Intervalo_km=@pmIntervalo_km,Intervalo_dias=@pmIntervalo_dias,kmActual=@pmkmActual,kmCambio=@pmkmCambio,FechaCambio=@pmFechaCambio,CdProdRep=@pmCdProdRep
,TipoUnidad=@pmTipoUnidad,TipoParte=@pmTipoParte,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FechaRetiro=@pmFechaRetiro,Intervalo_Horas=@pmIntervalo_Horas
,kmManual=@pmkmManual,kmSat=@pmkmSat,kmCambioMan=@pmkmCambioMan,kmCambioSat=@pmkmCambioSat,HorasTrab=@pmHorasTrab,HsUltCambio=@pmHsUltCambio,MarcaParte=@pmMarcaParte,ModeloParte=@pmModeloParte,NumSerie=@pmNumSerie
 WHERE IdVehiculo=@pmIdVehiculo AND NumParte=@pmNumParte
GO
/****** Object:  StoredProcedure [dbo].[paUpVehPolizas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehPolizas] @pmIdVehiculo VARCHAR(10),@pmIdClase VARCHAR(4),@pmNumero VARCHAR(30)
,@pmFecEmision SMALLDATETIME,@pmFecVigencia SMALLDATETIME,@pmNitCompania VARCHAR(16),@pmValor MONEY
,@pmComntarios VARCHAR(100),@pmDiasAviso INT
 AS 
 UPDATE VehPolizas SET Numero=@pmNumero,FecEmision=@pmFecEmision,FecVigencia=@pmFecVigencia,NitCompania=@pmNitCompania
,Valor=@pmValor,Comntarios=@pmComntarios,DiasAviso=@pmDiasAviso
 WHERE IdVehiculo=@pmIdVehiculo AND IdClase=@pmIdClase
GO
/****** Object:  StoredProcedure [dbo].[paUpVehRemolq]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehRemolq] @pmIdRemque VARCHAR(10),@pmIdMarca VARCHAR(4),@pmIdColor VARCHAR(4),@pmIdCrceria VARCHAR(4),@pmModelo VARCHAR(4),@pmNEjes INT,@pmnLlantas INT,@pmAltura DECIMAL(14,4),@pmAncho DECIMAL(14,4),@pmLargo DECIMAL(14,4)
,@pmVlumen DECIMAL(14,4),@pmPesoKg DECIMAL(14,4),@pmCapneta DECIMAL(14,4),@pmUndCapc VARCHAR(10),@pmNumComp INT,@pmCapcComp VARCHAR(50),@pmNumSerial VARCHAR(30),@pmIdPropietario VARCHAR(16),@pmNitProv VARCHAR(16),@pmFecCompra SMALLDATETIME
,@pmVidaUtil INT,@pmVrComercial MONEY,@pmVrAvaludo MONEY,@pmVrAsegurado MONEY,@pmKilmetraje INT,@pmEquipoAdic VARCHAR(50),@pmDescripcion VARCHAR(100),@pmCdCenSer VARCHAR(4),@pmCdLocal VARCHAR(8),@pmUbicacion VARCHAR(100),@pmObservacion VARCHAR(250)
,@pmIdEstado VARCHAR(4),@pmInactivo BIT,@pmTarjetaProp VARCHAR(30),@pmFecTarjProp  SMALLDATETIME,@pmVigTarjProp SMALLDATETIME,@pmConfEjes VARCHAR(5),@pmHidrostatica VARCHAR(30),@pmFecPruebaHid SMALLDATETIME,@pmVigPruebaHid SMALLDATETIME,@pmkmRuta INT,@pmkmOtro INT
,@pmKingpin VARCHAR(50),@pmFecKingpin SMALLDATETIME,@pmVigKingpin SMALLDATETIME,@pmArcFotoRem VARCHAR(50),@pmFecVigExtintor SMALLDATETIME,@pmCdLocTarj VARCHAR(8),@pmOperador_GPS VARCHAR(250),@pmUsuario_GPS VARCHAR(50),@pmClave_GPS VARCHAR(50),@pmIdOper_GPS VARCHAR(16)
,@pmTipo_Afil VARCHAR(10),@pmEdoVincula INT,@pmFechaVincula SMALLDATETIME,@pmFechaRetiro SMALLDATETIME,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE VehRemolq SET IdMarca=@pmIdMarca,IdColor=@pmIdColor,IdCrceria=@pmIdCrceria,Modelo=@pmModelo,NEjes=@pmNEjes,nLlantas=@pmnLlantas,ConfEjes=@pmConfEjes,Altura=@pmAltura,Ancho=@pmAncho,Largo=@pmLargo,Vlumen=@pmVlumen,PesoKg=@pmPesoKg,Capneta=@pmCapneta,UndCapc=@pmUndCapc
,NumComp=@pmNumComp,CapcComp=@pmCapcComp,NumSerial=@pmNumSerial,IdPropietario=@pmIdPropietario,NitProv=@pmNitProv,FecCompra=@pmFecCompra,VidaUtil=@pmVidaUtil,VrComercial=@pmVrComercial,VrAvaludo=@pmVrAvaludo,VrAsegurado=@pmVrAsegurado,Kilmetraje=@pmKilmetraje
,EquipoAdic=@pmEquipoAdic,Descripcion=@pmDescripcion,CdCenSer=@pmCdCenSer,CdLocal=@pmCdLocal,Ubicacion=@pmUbicacion,Observacion=@pmObservacion,IdEstado=@pmIdEstado,Inactivo=@pmInactivo,FecUpdate=@pmFecUpdate,TarjetaProp=@pmTarjetaProp,FecTarjProp=@pmFecTarjProp,VigTarjProp=@pmVigTarjProp
,Hidrostatica=@pmHidrostatica,FecPruebaHid=@pmFecPruebaHid,VigPruebaHid=@pmVigPruebaHid,kmRuta=@pmkmRuta,kmOtro=@pmkmOtro,Kingpin=@pmKingpin,FecKingpin=@pmFecKingpin,VigKingpin=@pmVigKingpin,ArcFotoRem=@pmArcFotoRem,FecVigExtintor=@pmFecVigExtintor,CdLocTarj=@pmCdLocTarj
,Operador_GPS=@pmOperador_GPS,Usuario_GPS=@pmUsuario_GPS,Clave_GPS=@pmClave_GPS,IdOper_GPS=@pmIdOper_GPS,Tipo_Afil=@pmTipo_Afil,EdoVincula=@pmEdoVincula,FechaVincula=@pmFechaVincula,FechaRetiro=@pmFechaRetiro
 WHERE IdRemque=@pmIdRemque
GO
/****** Object:  StoredProcedure [dbo].[paUpVehRemolqKmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVehRemolqKmt] @pmIdRemque VARCHAR(10),@pmKilmetraje INT,@pmFecUpdate SMALLDATETIME
 AS 
 UPDATE VehRemolq SET Kilmetraje=@pmKilmetraje,FecUpdate=@pmFecUpdate
 WHERE IdRemque=@pmIdRemque
GO
/****** Object:  StoredProcedure [dbo].[paUpVehRemolqTra]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpVehRemolqTra] @pmIdRemque VARCHAR(10),@pmIdPropietario VARCHAR(16),@pmVrComcial MONEY,@pmVrAseg MONEY,@pmTipoAfil VARCHAR(10),@pmFechaUpdate SMALLDATETIME
 AS  
 UPDATE VehRemolq SET IdPropietario=@pmIdPropietario,Tipo_Afil=@pmTipoAfil,VrComercial=@pmVrComcial,VrAsegurado=@pmVrAseg,FecUpdate=@pmFechaUpdate
 WHERE IdRemque=@pmIdRemque
GO
/****** Object:  StoredProcedure [dbo].[paUpVencimientosAbo]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVencimientosAbo] @pmTipDoc VARCHAR(3),@pmFactura INT,@pmIdCia CHAR(2)
,@pmItem INT,@pmVrAbonado MONEY,@pmFecUltPago SMALLDATETIME
 AS 
 IF @pmFecUltPago IS NULL
  UPDATE Trn_Vencimientos SET VrAbonado=@pmVrAbonado
  WHERE TipDoc=@pmTipDoc  AND Factura=@pmFactura  AND IdCia=@pmIdCia  AND Item=@pmItem
 ELSE
  UPDATE Trn_Vencimientos SET VrAbonado=@pmVrAbonado,FecUltPago=@pmFecUltPago
  WHERE TipDoc=@pmTipDoc  AND Factura=@pmFactura  AND IdCia=@pmIdCia  AND Item=@pmItem
GO
/****** Object:  StoredProcedure [dbo].[paUpVencimientosApl]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVencimientosApl]  @pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
   UPDATE Trn_Vencimientos SET  Trn_Vencimientos.VrAbonado=(SELECT ISNULL(SUM(Trn_VencAbonos.VrAbono),0)
   FROM Trn_VencAbonos  WHERE Trn_Vencimientos.TipDoc=Trn_VencAbonos.TipDoc AND Trn_Vencimientos.Factura=Trn_VencAbonos.Factura
   AND Trn_Vencimientos.IdCia=Trn_VencAbonos.IdCiaFac  AND Trn_Vencimientos.Item=Trn_VencAbonos.ItemFac)
   WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
   AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdVend LIKE ISNULL(@pmIdVend,'%')
 ELSE
   UPDATE Trn_Vencimientos SET  Trn_Vencimientos.VrAbonado=(SELECT ISNULL(SUM(Trn_VencAbonos.VrAbono),0)
   FROM Trn_VencAbonos  WHERE Trn_Vencimientos.TipDoc=Trn_VencAbonos.TipDoc AND Trn_Vencimientos.Factura=Trn_VencAbonos.Factura
   AND Trn_Vencimientos.IdCia=Trn_VencAbonos.IdCiaFac  AND Trn_Vencimientos.Item=Trn_VencAbonos.ItemFac)
   WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
   AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpVencimientosCero]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpVencimientosCero]  @pmIdCliente VARCHAR(16)=Null,@pmIdCia CHAR(2)=Null
,@pmFechaIni SMALLDATETIME=Null,@pmFechaFin SMALLDATETIME=Null,@pmIdVend VARCHAR(16)=Null
 AS 
 IF ISDATE(@pmFechaIni)>0 AND ISDATE(@pmFechaFin)>0--POR FECHA
   UPDATE Trn_Vencimientos SET VrAbonado=0
   WHERE Fecha BETWEEN @pmFechaIni AND @pmFechaFin
   AND IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
  AND IdVend LIKE ISNULL(@pmIdVend,'%')
 ELSE
   UPDATE Trn_Vencimientos SET VrAbonado=0
   WHERE IdCliente LIKE ISNULL(@pmIdCliente,'%') AND IdCia LIKE ISNULL(@pmIdCia,'%%')
   AND IdVend LIKE ISNULL(@pmIdVend,'%')
GO
/****** Object:  StoredProcedure [dbo].[paUpZonas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpZonas] @pmIdZona VARCHAR(4),@pmZona VARCHAR(50),@pmCdSubCos VARCHAR(16),@pmInactivo BIT
 AS 
 UPDATE Zonas SET Zona=@pmZona,CdSubCos=@pmCdSubCos,Inactivo=@pmInactivo
 WHERE IdZona=@pmIdZona
GO
/****** Object:  StoredProcedure [dbo].[paWcfGetCTraFijos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfGetCTraFijos]
	@TipoAfilVeh [varchar](10) = null,
	@CdTipoVeh [varchar](4) = null,
	@pVehiculo [varchar](10) = null,
	@CedConductor [varchar](16) = null,
	@CdRuta [varchar](4) = null
WITH EXECUTE AS CALLER
AS
BEGIN
 SELECT
 @TipoAfilVeh= CASE WHEN @TipoAfilVeh IS NULL  OR @TipoAfilVeh='' THEN '0' ELSE @TipoAfilVeh END, 
 @CdTipoVeh= CASE WHEN @CdTipoVeh IS NULL OR @CdTipoVeh='' THEN '0' ELSE @CdTipoVeh END,
 @pVehiculo= CASE WHEN @pVehiculo IS NULL  OR @pVehiculo='' THEN '0' ELSE @pVehiculo END,
 @CedConductor= CASE WHEN @CedConductor IS NULL OR @CedConductor='' THEN '0' ELSE @CedConductor END,
 --@CedPropietario= CASE WHEN @CedPropietario IS NULL OR  @CedPropietario='0' OR @CedPropietario='' THEN NULL ELSE @CedPropietario END,
 @CdRuta= CASE WHEN @CdRuta IS NULL OR @CdRuta='' THEN '0' ELSE @CdRuta END

SELECT 
TF.Numero, TF.IdConcepto, CD.IdCueDeb,CD.IdCueCre, TF.DescConc, TF.TipoConc, TF.Tarifa, TF.TipoTarif, TF.TipoAfilVeh, TF.CdTipoVeh, TF.TipoTerc, TF.Anulado, 
TF.CdCiuOrigen, TF.CdCiuDestino, TF.pVehiculo, TF.CedConductor, TF.CdRuta,TF.TipoVigencia,TF.FechaInicial,TF.FechaFinal
FROM            
(
	SELECT 
		TF.Numero, TF.IdConcepto, TF.DescConc, TF.TipoConc, TF.Tarifa, TF.TipoTarif, TF.TipoTerc, TF.Anulado, 
		TF.CdCiuOrigen, TF.CdCiuDestino,
		CASE WHEN TipoAfilVeh = '' or TipoAfilVeh = '0' THEN '0' ELSE TipoAfilVeh END AS TipoAfilVeh,
		CASE WHEN CdTipoVeh = '' or CdTipoVeh = '0' THEN '0' ELSE CdTipoVeh END AS CdTipoVeh,
		CASE WHEN pVehiculo = '' or pVehiculo = '0' THEN '0' ELSE pVehiculo END AS pVehiculo,
		CASE WHEN CedConductor = '' or CedConductor = '0' THEN '0' ELSE CedConductor END AS CedConductor,
		CASE WHEN CdRuta = '' or CdRuta = '0' THEN '0' ELSE CdRuta END AS CdRuta,
		TipoVigencia,
		FechaInicial,
		FechaFinal
	FROM
		TraFijos TF
	WHERE
		TF.Anulado = 0 AND TF.TipoConc<> 'SEGURO' AND TF.TipoConc<> 'IMPUESTO'
) AS TF 
JOIN ConcDiversos AS CD ON TF.IdConcepto = CD.IdConcepto 
WHERE 
	TipoAfilVeh = CASE WHEN TipoAfilVeh<>'0' THEN @TipoAfilVeh ELSE TipoAfilVeh END AND
	CdTipoVeh = CASE WHEN CdTipoVeh<>'0' THEN @CdTipoVeh ELSE CdTipoVeh END AND
	pVehiculo = CASE WHEN pVehiculo<>'0' THEN @pVehiculo ELSE pVehiculo END AND
	CedConductor = CASE WHEN CedConductor<>'0' THEN @CedConductor ELSE CedConductor END AND
	CdRuta = CASE WHEN CdRuta<>'0' THEN @CdRuta ELSE CdRuta END
ORDER BY TF.Numero

END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsadm_Opciones]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsadm_Opciones]
	@adm_Opciones [dbo].[dataTypeadm_Opciones] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @adm_Opciones))
			begin
			 UPDATE adm_Opciones
			 SET IdOpc = T2.IdOpc, Opcion = T2.Opcion,TipoDato = T2.TipoDato,Valor = T2.Valor,NivUp = T2.NivUp,nModulo = T2.nModulo
			 FROM adm_Opciones T1
			 JOIN @adm_Opciones T2 ON T1.IdOpc = T2.IdOpc
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @adm_Opciones))
			BEGIN
			 INSERT INTO adm_Opciones(
			 IdOpc, Opcion,TipoDato,Valor,NivUp,nModulo)
			 SELECT 
			 IdOpc, Opcion,TipoDato,Valor,NivUp,nModulo
			 FROM @adm_Opciones
			 WHERE IdOpc NOT IN(SELECT IdOpc FROM adm_Opciones)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(3)
			 SELECT @id = IdOpc FROM @adm_Opciones
			 DELETE FROM adm_Opciones WHERE IdOpc = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsadm_Registro]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsadm_Registro]
	@adm_Registro [dbo].[dataTypeadm_Registro] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE adm_Registro
			 SET 
			 IdCia = t2.IdCia,TipoId = t2.TipoId,IdEmpresa = t2.IdEmpresa,
			 NitEmpresa = t2.NitEmpresa, DvNit = t2.DvNit, RazonSocial = t2.RazonSocial, NitRepLegal = t2.NitRepLegal, RepLegal = t2.RepLegal,
			 Descripcion = t2.Descripcion, Direccion = t2.Direccion, Telefono = t2.Telefono, Fax = t2.Fax, IdLocal = t2.IdLocal, IdPais = t2.IdPais,
			 e_mail = t2.e_mail, ArchivoLogo = t2.ArchivoLogo, NumeroSerial = t2.NumeroSerial, Regimen = t2.Regimen,TipoPersna = t2.TipoPersna,
			 Licencia = t2.Licencia, VigenciaLic = t2.VigenciaLic, Personeria = t2.Personeria, CIIUDane = t2.CIIUDane, Leyenda = t2.Leyenda, 
			 FechaRegistro = t2.FechaRegistro, FechaVence = t2.FechaVence, CurrtyDate = t2.CurrtyDate, CurDate1 = t2.CurDate1, FechaPrest = t2.FechaPrest
		     FROM adm_Registro t1
			 JOIN @adm_Registro t2 ON t1.IdEmpresa = t2.IdEmpresa and t1.NitEmpresa = t2.NitEmpresa
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO adm_Registro(
			 IdCia,TipoId,IdEmpresa,NitEmpresa,DvNit,RazonSocial,NitRepLegal,RepLegal,Descripcion,Direccion,Telefono,Fax,IdLocal,
			 IdPais,e_mail,ArchivoLogo,NumeroSerial,Regimen,TipoPersna,Licencia,VigenciaLic,Personeria,CIIUDane,Leyenda,FechaRegistro,
			 FechaVence,CurrtyDate,CurDate1,FechaPrest
			 )
			 SELECT 
			 IdCia,TipoId,IdEmpresa,NitEmpresa,DvNit,RazonSocial,NitRepLegal,RepLegal,Descripcion,Direccion,Telefono,Fax,IdLocal,
			 IdPais,e_mail,ArchivoLogo,NumeroSerial,Regimen,TipoPersna,Licencia,VigenciaLic,Personeria,CIIUDane,Leyenda,FechaRegistro,
			 FechaVence,CurrtyDate,CurDate1,FechaPrest
			 FROM @adm_Registro
			 WHERE IdEmpresa NOT IN(SELECT IdEmpresa FROM adm_Registro)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id char(2)
			 SELECT @id = IdEmpresa FROM @adm_Registro
			 DELETE FROM adm_Registro WHERE IdEmpresa = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsadm_Usuarios]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsadm_Usuarios]
	@adm_Usuarios [dbo].[dataTypeadm_Usuarios] READONLY,
	@adm_Permisos [dbo].[dataTypeadm_Permisos] READONLY,
	@adm_UOpciones [dbo].[dataTypeadm_UOpciones] READONLY,
	@adm_PermisosRoles [dbo].[dataTypeadm_PermisosRoles] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @adm_Usuarios))
			begin
			 UPDATE adm_Usuarios
			 SET 
			 IdUsuario = t2.IdUsuario, Usuario = t2.Usuario, PwdLog = t2.PwdLog, IdGrupo = t2.IdGrupo, IdEstacion = t2.IdEstacion,
			 IdCargo = t2.IdCargo, Conectado = t2.Conectado, FechaAcc = t2.FechaAcc, FechaClave = t2.FechaClave, Caducidad = t2.Caducidad,
			 LoginSQL = t2.LoginSQL, PwdSQL = t2.PwdSQL, ModoSQL = t2.ModoSQL, Inactivo = t2.Inactivo
			 FROM adm_Usuarios t1
			 JOIN @adm_Usuarios t2 ON t1.IdUsuario = t2.IdUsuario
			 WHERE t1.IdUsuario = t2.IdUsuario
			end

			IF(EXISTS(SELECT TOP 1 * FROM @adm_Permisos))
			begin
			 --Actualizar los que existen
			 UPDATE adm_Permisos
			 SET 
			 IdUsuario = t2.IdUsuario, IdObj = t2.IdObj, Consecutivo = t2.Consecutivo,PerAdd = t2.PerAdd,
			 PerUpdate = t2.PerUpdate,PerDelete = t2.PerDelete,PerAnular = t2.PerAnular,PerRead = t2.PerRead,
			 PerRename = t2.PerRename
			 FROM adm_Permisos t1
			 JOIN @adm_Permisos t2 ON t1.IdUsuario = t2.IdUsuario and t1.IdObj = t2.IdObj
			 WHERE t1.IdUsuario = t2.IdUsuario and t1.IdObj = t2.IdObj
			 --Inserta los que no existen
			 INSERT INTO adm_Permisos(
			 IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename)
			 SELECT 
			 IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename
			 FROM @adm_Permisos
			 WHERE (IdUsuario+IdObj) NOT IN(SELECT (IdUsuario+IdObj) FROM adm_Permisos)
			end

			IF(EXISTS(SELECT TOP 1 * FROM @adm_UOpciones))
			begin
			 --Actualizar los que existen
			 UPDATE adm_UOpciones
			 SET IdUsuario = T2.IdUsuario,NomOpcion = T2.NomOpcion,Valor = T2.Valor
			 FROM adm_UOpciones T1
			 JOIN @adm_UOpciones T2 ON T1.IdUsuario = T2.IdUsuario and t1.NomOpcion = T2.NomOpcion
			 --Inserta los que no existen
			 INSERT INTO adm_UOpciones(IdUsuario,NomOpcion,Valor)
			 SELECT IdUsuario,NomOpcion,Valor FROM @adm_UOpciones
			 WHERE (IdUsuario+NomOpcion) NOT IN(SELECT (IdUsuario+NomOpcion) FROM adm_UOpciones)
			end

			IF(EXISTS(SELECT TOP 1 * FROM @adm_PermisosRoles))
			begin
			 --Actualiza los que existen
			 UPDATE adm_PermisosRoles
			 SET IdUsuario = t2.IdUsuario, IdObj = t2.IdObj, IdRole = t2.IdRole, Asignado = t2.Asignado FROM adm_PermisosRoles T1
			 JOIN @adm_PermisosRoles T2 ON T1.IdUsuario = T2.IdUsuario and T1.IdObj = T2.IdObj and T1.IdRole = t2.IdRole
			 WHERE T1.IdUsuario = T2.IdUsuario and T1.IdObj = T2.IdObj and T1.IdRole = t2.IdRole
			 --Inserta los que no existen
			 INSERT INTO adm_PermisosRoles(IdUsuario,IdObj,IdRole,Asignado)
			 SELECT IdUsuario,IdObj,IdRole,Asignado FROM @adm_PermisosRoles
			 WHERE (IdUsuario+IdObj+IdRole) NOT IN(SELECT (IdUsuario+IdObj+IdRole) FROM adm_PermisosRoles)
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @adm_Usuarios))
			BEGIN
			 INSERT INTO adm_Usuarios(
			 IdUsuario, Usuario, PwdLog, IdGrupo, IdEstacion, IdCargo, Conectado, FechaAcc, FechaClave,
			 Caducidad, LoginSQL, PwdSQL, ModoSQL, Inactivo)
			 SELECT 
			 IdUsuario,Usuario,PwdLog,IdGrupo,IdEstacion,IdCargo,Conectado,FechaAcc,FechaClave,
			 Caducidad,LoginSQL,PwdSQL,ModoSQL,Inactivo			 
			 FROM @adm_Usuarios
			 WHERE IdUsuario NOT IN(SELECT IdUsuario FROM adm_Usuarios)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @adm_Permisos))
			BEGIN
			 INSERT INTO adm_Permisos(
			 IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename)
			 SELECT 
			 IdUsuario,IdObj,Consecutivo,PerAdd,PerUpdate,PerDelete,PerAnular,PerRead,PerRename
			 FROM @adm_Permisos
			 WHERE (IdUsuario+IdObj) NOT IN(SELECT (IdUsuario+IdObj) FROM adm_Permisos)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @adm_UOpciones))
			BEGIN
			 INSERT INTO adm_UOpciones(
			 IdUsuario,NomOpcion,Valor
			 )
			 SELECT 
			 IdUsuario,NomOpcion,Valor
			 FROM @adm_UOpciones
			 WHERE (IdUsuario+NomOpcion) NOT IN(SELECT (IdUsuario+NomOpcion) FROM adm_UOpciones)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @adm_PermisosRoles))
			BEGIN
			 INSERT INTO adm_PermisosRoles(
			 IdUsuario,IdObj,IdRole,Asignado
			 )
			 SELECT 
			 IdUsuario,IdObj,IdRole,Asignado
			 FROM @adm_PermisosRoles
			 WHERE (IdUsuario+IdObj+IdRole) NOT IN(SELECT (IdUsuario+IdObj+IdRole) FROM adm_PermisosRoles)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id VARCHAR (11)
			 SELECT @id = IdUsuario FROM @adm_Usuarios

			 DELETE FROM adm_Permisos WHERE IdUsuario = @id			
			 DELETE FROM adm_Usuarios WHERE IdUsuario = @id
			 DELETE FROM adm_PermisosRoles WHERE IdUsuario = @id
			 DELETE FROM adm_UOpciones WHERE IdUsuario = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCalndario]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsCalndario]
	@Calndario [dbo].[dataTypeCalndario] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		DECLARE @id smalldatetime

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN

			 --Eliminar el mes que se va a actualizar
		     SELECT @id = FechaDia FROM @Calndario
			 DELETE FROM Calndario WHERE (MONTH(FechaDia) = MONTH(@id)) AND (YEAR(FechaDia) = YEAR(@id))

			 --Insertar el mes que se actualiza
			 INSERT INTO Calndario( FechaDia, TipoFtvo )
			 SELECT FechaDia, TipoFtvo FROM @Calndario WHERE FechaDia NOT IN(SELECT FechaDia FROM Calndario)

			 --UPDATE Calndario
			 --SET 
			 --FechaDia = t2.FechaDia, TipoFtvo = t2.TipoFtvo
		  --   FROM Calndario t1
			 --JOIN @Calndario t2 ON t1.FechaDia = t2.FechaDia
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Calndario( FechaDia, TipoFtvo )
			 SELECT FechaDia, TipoFtvo FROM @Calndario WHERE FechaDia NOT IN(SELECT FechaDia FROM Calndario)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 SELECT @id = FechaDia FROM @Calndario
			 DELETE FROM Calndario WHERE (MONTH(FechaDia) = MONTH(@id)) AND (YEAR(FechaDia) = YEAR(@id))
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCargos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsCargos]
	@Cargos [dbo].[dataTypeCargos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Cargos
			 SET 
				IdCargo = t2.IdCargo,
				Cargo = t2.Cargo,
				Funciones = t2.Funciones,
				Inactivo = t2.Inactivo
		     FROM Cargos t1
			 JOIN @Cargos t2 ON t1.IdCargo = t2.IdCargo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Cargos(
			 IdCargo,Cargo,Funciones,Inactivo
			 )
			 SELECT 
			 IdCargo,Cargo,Funciones,Inactivo
			 FROM @Cargos
			 WHERE IdCargo NOT IN(SELECT IdCargo FROM Cargos)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdCargo FROM @Cargos
			 DELETE FROM Cargos WHERE IdCargo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCentrosServ]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsCentrosServ]
	@CentrosServ [dbo].[dataTypeCentrosServ] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE CentrosServ
			 SET 
			 IdCenSer = t2.IdCenSer, CentroServ = t2.CentroServ, DirCentro = t2.DirCentro, 
			 IdLocal = t2.IdLocal, Telefonos = t2.Telefonos, TipoCentro = t2.TipoCentro,
			 NitResp = t2.NitResp, Respnsable = t2.Respnsable, Inactivo = t2.Inactivo
		     FROM CentrosServ t1
			 JOIN @CentrosServ t2 ON t1.IdCenSer = t2.IdCenSer
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO CentrosServ(
			 IdCenSer,CentroServ,DirCentro,IdLocal,Telefonos,TipoCentro,NitResp,Respnsable,Inactivo
			 )
			 SELECT 
			 IdCenSer,CentroServ,DirCentro,IdLocal,Telefonos,TipoCentro,NitResp,Respnsable,Inactivo
			 FROM @CentrosServ
			 WHERE IdCenSer NOT IN(SELECT IdCenSer FROM CentrosServ)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdCenSer FROM @CentrosServ
			 DELETE FROM CentrosServ WHERE IdCenSer = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseCapac]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsClaseCapac]
	@ClaseCapac [dbo].[dataTypeClaseCapac] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE ClaseCapac
			 SET 
			 IdClase = t2.IdClase,NomClase = t2.NomClase,Inactivo = t2.Inactivo
		     FROM ClaseCapac t1
			 JOIN @ClaseCapac t2 ON t1.IdClase = t2.IdClase
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO ClaseCapac(
			 IdClase,NomClase,Inactivo
			 )
			 SELECT 
			 IdClase,NomClase,Inactivo	
			 FROM @ClaseCapac
			 WHERE IdClase NOT IN(SELECT IdClase FROM ClaseCapac)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdClase FROM @ClaseCapac
			 DELETE FROM ClaseCapac WHERE IdClase = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseCta]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsClaseCta]
	@ClaseCta [dbo].[dataTypeClaseCta] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @ClaseCta))
			begin
			 UPDATE ClaseCta
			 SET 
			 IdClase = t2.IdClase, ClaseCuenta = t2.ClaseCuenta, Inactivo = t2.Inactivo
			 FROM ClaseCta T1
			 JOIN @ClaseCta T2 ON T1.IdClase = T2.IdClase
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @ClaseCta))
			BEGIN
			 INSERT INTO ClaseCta(
			 IdClase,ClaseCuenta,Inactivo
			 )
			 SELECT 
			 IdClase,ClaseCuenta,Inactivo
			 FROM @ClaseCta
			 WHERE IdClase NOT IN(SELECT IdClase FROM ClaseCta)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdClase FROM @ClaseCta
			 DELETE FROM ClaseCta WHERE IdClase = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseDiv]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsClaseDiv]
	@ClaseDiv [dbo].[dataTypeClaseDiv] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE ClaseDiv
			 SET 
			 IdClase = t2.IdClase,NomClase = t2.NomClase,Inactivo = t2.Inactivo
		     FROM ClaseDiv t1
			 JOIN @ClaseDiv t2 ON t1.IdClase = t2.IdClase
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO ClaseDiv(
			 IdClase,NomClase,Inactivo
			 )
			 SELECT 
			 IdClase,NomClase,Inactivo
			 FROM @ClaseDiv
			 WHERE IdClase NOT IN(SELECT IdClase FROM ClaseDiv)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdClase FROM @ClaseDiv
			 DELETE FROM ClaseDiv WHERE IdClase = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClaseDocCond]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsClaseDocCond]
	@ClaseDocCond [dbo].[dataTypeClaseDocCond] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE ClaseDocCond
			 SET 
			 IdDoc = t2.IdDoc,Documento = t2.Documento,Vigencia = t2.Vigencia,Inactivo = t2.Inactivo
		     FROM ClaseDocCond t1
			 JOIN @ClaseDocCond t2 ON t1.IdDoc = t2.IdDoc
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO ClaseDocCond(
			 IdDoc,Documento,Vigencia,Inactivo
			 )
			 SELECT 
			 IdDoc,Documento,Vigencia,Inactivo
			 FROM @ClaseDocCond
			 WHERE IdDoc NOT IN(SELECT IdDoc FROM ClaseDocCond)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdDoc FROM @ClaseDocCond
			 DELETE FROM ClaseDocCond WHERE IdDoc = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsClasePol]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsClasePol]
	@ClasePol [dbo].[dataTypeClasePol] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE ClasePol
			 SET 
			 IdClase = t2.IdClase,ClasePoliza = t2.ClasePoliza,Inactivo = t2.Inactivo
		     FROM ClasePol t1
			 JOIN @ClasePol t2 ON t1.IdClase = t2.IdClase
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO ClasePol(
			 IdClase,ClasePoliza,Inactivo
			 )
			 SELECT 
			 IdClase,ClasePoliza,Inactivo
			 FROM @ClasePol
			 WHERE IdClase NOT IN(SELECT IdClase FROM ClasePol)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdClase FROM @ClasePol
			 DELETE FROM ClasePol WHERE IdClase = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsCompanias]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsCompanias]
	@Companias [dbo].[dataTypeCompanias] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Companias))
			begin
			 UPDATE Companias
			 SET 
			 IdCia = t2.IdCia,Compania = t2.Compania,DirInterface = t2.DirInterface,FechaActual = t2.FechaActual,
			 PeriodoActual = t2.PeriodoActual,IdCCosto = t2.IdCCosto,IdSubCos = t2.IdSubCos,IdTercero = t2.IdTercero,
			 CodSucsal = t2.CodSucsal,DireccSuc = t2.DireccSuc,TelefSuc = t2.TelefSuc,FaxSuc = t2.FaxSuc,
			 IdLocal = t2.IdLocal,TipoEDS = t2.TipoEDS,CodPlanta = t2.CodPlanta,FechaAdd = t2.FechaAdd,
			 FechaUpdate = t2.FechaUpdate,Inactivo = t2.Inactivo,CodBodega = t2.CodBodega,FecModPrest = t2.FecModPrest,
			 AutoIca = t2.AutoIca
			 FROM Companias T1
			 JOIN @Companias T2 ON T1.IdCia = T2.IdCia
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Companias))
			BEGIN
			 INSERT INTO Companias(
			 IdCia,Compania,DirInterface,FechaActual,PeriodoActual,IdCCosto,IdSubCos,IdTercero,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,
			 TipoEDS,CodPlanta,FechaAdd,FechaUpdate,Inactivo,CodBodega,FecModPrest,AutoIca
			 )
			 SELECT 
			 IdCia,Compania,DirInterface,FechaActual,PeriodoActual,IdCCosto,IdSubCos,IdTercero,CodSucsal,DireccSuc,TelefSuc,FaxSuc,IdLocal,
			 TipoEDS,CodPlanta,FechaAdd,FechaUpdate,Inactivo,CodBodega,FecModPrest,AutoIca
			 FROM @Companias
			 WHERE IdCia NOT IN(SELECT IdCia FROM Companias)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id char(2)
			 SELECT @id = IdCia FROM @Companias
			 DELETE FROM Companias WHERE IdCia = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsConceptosDiv]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsConceptosDiv]
	@ConcDiversos [dbo].[dataTypeConcDiversos] READONLY,
	@ConcDivCue [dbo].[dataTypeConcDivCue] READONLY,
	@ConcDivCia [dbo].[dataTypeConcDivCia] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @ConcDiversos))
			begin
			 UPDATE ConcDiversos
			 SET
			  IdConcepto = t2.IdConcepto,Concepto = t2.Concepto,Grupo = t2.Grupo,EsServicio = t2.EsServicio,
			  DeManfsto = t2.DeManfsto,CdIva = t2.CdIva,CdRet = t2.CdRet,CdIca = t2.CdIca,CdAutoret = t2.CdAutoret,
			  IdCueDeb = t2.IdCueDeb,IdCueCre = t2.IdCueCre,Inactivo = t2.Inactivo,FechaAdd = t2.FechaAdd,
			  FechaUpdate = t2.FechaUpdate,IdUsuario = t2.IdUsuario,OrdenServ = t2.OrdenServ,NovedadNom = t2.NovedadNom,
			  CdConcDeveng = t2.CdConcDeveng,CdConcDed = t2.CdConcDed,RubroConc = t2.RubroConc,MudReajuste=t2.MudReajuste,
			  CodFEDian = t2.CodFEDian
			 FROM ConcDiversos t1
			 JOIN @ConcDiversos t2 ON t1.IdConcepto = t2.IdConcepto
			 WHERE t1.IdConcepto = t2.IdConcepto
			end

			IF(EXISTS(SELECT TOP 1 * FROM @ConcDivCia))
			begin
			  declare @id varchar(4) 
			  select top 1 @id = IdConcepto from @ConcDivCia
				delete from ConcDivCia where IdConcepto = @id
				
				insert into ConcDivCia(
				IdConcepto,IdCia )
				select 
				IdConcepto,IdCia
				from @ConcDivCia 
				where (IdConcepto+Idcia) NOT IN(SELECT (IdConcepto+Idcia) FROM ConcDivCia) 
			end

			IF(EXISTS(SELECT TOP 1 * FROM @ConcDivCue))
			begin
			 --Actualizar los que existen
			 UPDATE ConcDivCue
			 SET 
			  IdConcepto = t2.IdConcepto,IdClase = t2.IdClase,
			  IdCuenta = t2.IdCuenta,CdCueDev = t2.CdCueDev,
			  TipoMov = t2.TipoMov,TipoTerc = t2.TipoTerc,
			  FecAdd = t2.FecAdd,FecUpdate = t2.FecUpdate
			 FROM ConcDivCue t1
			 JOIN @ConcDivCue t2 ON t1.IdConcepto = t2.IdConcepto and t1.IdClase = t2.IdClase
			 WHERE t1.IdConcepto = t2.IdConcepto and t1.IdClase = t2.IdClase
			 --Inserta los que no existen
			 INSERT INTO ConcDivCue(
			  IdConcepto,IdClase,IdCuenta,CdCueDev,TipoMov,TipoTerc,FecAdd,FecUpdate
			 )
			 SELECT 
			  IdConcepto,IdClase,IdCuenta,CdCueDev,TipoMov,TipoTerc,FecAdd,FecUpdate
			 FROM @ConcDivCue
			 WHERE (IdConcepto+IdClase) NOT IN(SELECT (IdConcepto+IdClase) FROM ConcDivCue)
			end					
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @ConcDiversos))
			BEGIN
			INSERT INTO ConcDiversos(
			IdConcepto,Concepto,Grupo,EsServicio,DeManfsto,CdIva,CdRet,CdIca,CdAutoret,
			IdCueDeb,IdCueCre,Inactivo,FechaAdd,FechaUpdate,IdUsuario,OrdenServ,NovedadNom,
			CdConcDeveng,CdConcDed,RubroConc,MudReajuste,CodFEDian
			)
			SELECT 
			IdConcepto,Concepto,Grupo,EsServicio,DeManfsto,CdIva,CdRet,CdIca,CdAutoret,
			IdCueDeb,IdCueCre,Inactivo,FechaAdd,FechaUpdate,IdUsuario,OrdenServ,NovedadNom,
			CdConcDeveng,CdConcDed,RubroConc,MudReajuste,CodFEDian
			FROM @ConcDiversos
			WHERE IdConcepto NOT IN(SELECT IdConcepto FROM ConcDiversos)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @ConcDivCia))
			BEGIN
			INSERT INTO ConcDivCia(
			IdConcepto,IdCia)
			SELECT 
			IdConcepto,IdCia
			FROM @ConcDivCia 
			WHERE (IdConcepto+Idcia) NOT IN(SELECT (IdConcepto+Idcia) FROM ConcDivCia)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @ConcDivCue))
			BEGIN
			INSERT INTO ConcDivCue(
			IdConcepto,IdClase,IdCuenta,CdCueDev,TipoMov,TipoTerc,FecAdd,FecUpdate)
			SELECT 
			IdConcepto,IdClase,IdCuenta,CdCueDev,TipoMov,TipoTerc,FecAdd,FecUpdate
			FROM @ConcDivCue
			WHERE (IdConcepto+IdClase) NOT IN(SELECT (IdConcepto+IdClase) FROM ConcDivCue)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @_id VARCHAR(4)
			 DECLARE @idcl int
			 
			 IF(EXISTS(SELECT TOP 1 * FROM @ConcDiversos))	
			 BEGIN
				SELECT @_id = IdConcepto FROM @ConcDiversos
				DELETE FROM ConcDivCue WHERE IdConcepto = @_id
				DELETE FROM ConcDivCia WHERE IdConcepto = @_id
				DELETE FROM ConcDiversos WHERE IdConcepto = @_id	
			 END

			 IF(EXISTS(SELECT TOP 1 * FROM @ConcDivCue))
			 BEGIN
				if((SELECT TOP 1 IdClase FROM @ConcDivCue) > 0)
				begin 
				 SELECT @_id = IdConcepto, @idcl = IdClase FROM @ConcDivCue
				 DELETE FROM ConcDivCue WHERE IdConcepto = @_id and IdClase = @idcl
				end
				else 
				begin
				 SELECT @_id = IdConcepto FROM @ConcDivCue
				 DELETE FROM ConcDivCue WHERE IdConcepto = @_id
				end
			 END
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsConceptosFijos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsConceptosFijos]
	@Fijos [dbo].[dataTypeFijos] READONLY,
	@Fijos_Cue [dbo].[dataTypeFijos_Cue] READONLY,
	@Fijos_Veh [dbo].[dataTypeFijos_Veh] READONLY,
	@Fijos_Cla [dbo].[dataTypeFijos_Cla] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos))
			begin
			 UPDATE Fijos
			 SET
			  IdCargo = t2.IdCargo, Concepto = t2.Concepto, Obligatorio = t2.Obligatorio,
			  TipoAplica = t2.TipoAplica, DiasSemana = t2.DiasSemana, DiasMes = t2.DiasMes, ValorMensual = t2.ValorMensual,
			  ValorDiario = t2.ValorDiario, IdCuentaDeb = t2.IdCuentaDeb, IdCuentaCre = t2.IdCuentaCre, IdCueDebVp = t2.IdCueDebVp,
			  IdCueCreVp = t2.IdCueCreVp,NCuotas = t2.NCuotas,DiasVcmto = t2.DiasVcmto,OrdenAbono = t2.OrdenAbono,
			  TipoDcto = t2.TipoDcto,DctoPpago = t2.DctoPpago,VrCargoAdic = t2.VrCargoAdic,FecLimiteIni = t2.FecLimiteIni,
			  FecLimiteFin = t2.FecLimiteFin,Inactivo = t2.Inactivo,FechaAdd = t2.FechaAdd,FechaUpdate = t2.FechaUpdate,IdUsuario = t2.IdUsuario
			 FROM Fijos t1
			 JOIN @Fijos t2 ON t1.IdCargo = t2.IdCargo
			 WHERE t1.IdCargo = t2.IdCargo
			end

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Cue))
			begin
			  declare @id varchar(4) 
			  select top 1 @id = IdCargo from @Fijos_Cue
				delete from Fijos_Cue where IdCargo = @id
				
				insert into Fijos_Cue(
				IdCargo,IdAdmon,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp)
				select 
				IdCargo,IdAdmon,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp
				from @Fijos_Cue 
				where (IdCargo+IdAdmon) NOT IN(SELECT (IdCargo+IdAdmon) FROM Fijos_Cue) 
			end

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Veh))
			begin
			 --Actualizar los que existen
			 UPDATE Fijos_Veh
			 SET 
			  IdCargo = t2.IdCargo,IdVehiculo = t2.IdVehiculo,ValorMensual = t2.ValorMensual,
			  ValorDiario = t2.ValorDiario,Excluir = t2.Excluir
			 FROM Fijos_Veh t1
			 JOIN @Fijos_Veh t2 ON t1.IdCargo = t2.IdCargo and t1.IdVehiculo = t2.IdVehiculo
			 WHERE t1.IdCargo = t2.IdCargo and t1.IdVehiculo = t2.IdVehiculo
			 --Inserta los que no existen
			 INSERT INTO Fijos_Veh(
			  IdCargo,IdVehiculo,ValorMensual,ValorDiario,Excluir)
			 SELECT 
			  IdCargo,IdVehiculo,ValorMensual,ValorDiario,Excluir
			 FROM @Fijos_Veh
			 WHERE (IdCargo+IdVehiculo) NOT IN(SELECT (IdCargo+IdVehiculo) FROM Fijos_Veh)
			end		

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Cla))
			begin
			 --Actualizar los que existen
			 UPDATE Fijos_Cla
			 SET 
			  IdCargo = t2.IdCargo,IdClase = t2.IdClase,ValorMensual = t2.ValorMensual,ValorDiario = t2.ValorDiario
			 FROM Fijos_Cla t1
			 JOIN @Fijos_Cla t2 ON t1.IdCargo = t2.IdCargo and t1.IdClase = t2.IdClase
			 WHERE t1.IdCargo = t2.IdCargo and t1.IdClase = t2.IdClase
			 --Inserta los que no existen
			 INSERT INTO Fijos_Cla(
			  IdCargo,IdClase,ValorMensual,ValorDiario)
			 SELECT 
			  IdCargo,IdClase,ValorMensual,ValorDiario
			 FROM @Fijos_Cla
			 WHERE (IdCargo+IdClase) NOT IN(SELECT (IdCargo+IdClase) FROM Fijos_Cla)
			end					
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos))
			BEGIN
			INSERT INTO Fijos(
			IdCargo,Concepto,Obligatorio,TipoAplica,DiasSemana,DiasMes,ValorMensual,
			ValorDiario,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,NCuotas,DiasVcmto,
			OrdenAbono,TipoDcto,DctoPpago,VrCargoAdic,FecLimiteIni,FecLimiteFin,Inactivo,
			FechaAdd,FechaUpdate,IdUsuario
			)
			SELECT 
			IdCargo,Concepto,Obligatorio,TipoAplica,DiasSemana,DiasMes,ValorMensual,
			ValorDiario,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp,NCuotas,DiasVcmto,
			OrdenAbono,TipoDcto,DctoPpago,VrCargoAdic,FecLimiteIni,FecLimiteFin,Inactivo,
			FechaAdd,FechaUpdate,IdUsuario
			FROM @Fijos
			WHERE IdCargo NOT IN(SELECT IdCargo FROM Fijos)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Cue))
			BEGIN
			INSERT INTO Fijos_Cue(
			IdCargo,IdAdmon,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp
			)
			SELECT 
			IdCargo,IdAdmon,IdCuentaDeb,IdCuentaCre,IdCueDebVp,IdCueCreVp
			FROM @Fijos_Cue 
			WHERE (IdCargo+IdAdmon) NOT IN(SELECT (IdCargo+IdAdmon) FROM Fijos_Cue)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Veh))
			BEGIN
			INSERT INTO Fijos_Veh(
			IdCargo,IdVehiculo,ValorMensual,ValorDiario,Excluir)
			SELECT 
			IdCargo,IdVehiculo,ValorMensual,ValorDiario,Excluir
			FROM @Fijos_Veh
			WHERE (IdCargo+IdVehiculo) NOT IN(SELECT (IdCargo+IdVehiculo) FROM Fijos_Veh)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Cla))
			BEGIN
			INSERT INTO Fijos_Cla(
			IdCargo,IdClase,ValorMensual,ValorDiario)
			SELECT 
			IdCargo,IdClase,ValorMensual,ValorDiario
			FROM @Fijos_Cla
			WHERE (IdCargo+IdClase) NOT IN(SELECT (IdCargo+IdClase) FROM Fijos_Cla)
			END

		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @_id VARCHAR (4)
			 DECLARE @idcl int
			 
			 IF(EXISTS(SELECT TOP 1 * FROM @Fijos))	
			 BEGIN
				SELECT @_id = IdCargo FROM @Fijos
				DELETE FROM Fijos_Cue WHERE IdCargo = @_id
				DELETE FROM Fijos_Cla WHERE IdCargo = @_id
				DELETE FROM Fijos_Veh WHERE IdCargo = @_id
				DELETE FROM Fijos WHERE IdCargo = @_id	
			 END

			 IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Cla))
			 BEGIN
				if((SELECT TOP 1 IdClase FROM @Fijos_Cla) > 0)
				begin 
				 SELECT @_id = IdCargo, @idcl = IdClase FROM @Fijos_Cla
				 DELETE FROM Fijos_Cla WHERE IdCargo = @_id and IdClase = @idcl
				end
				else 
				begin
				 SELECT @_id = IdCargo FROM @Fijos_Cla
				 DELETE FROM Fijos_Cla WHERE IdCargo = @_id
				end
			 END

			 IF(EXISTS(SELECT TOP 1 * FROM @Fijos_Veh))
			 BEGIN				
				 SELECT @_id = IdCargo, @idcl = IdVehiculo  FROM @Fijos_Veh
				 DELETE FROM Fijos_Veh WHERE IdCargo = @_id and IdVehiculo = @idcl
			 END

		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsDepartamentos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsDepartamentos]
	@Departamentos [dbo].[dataTypeDepartamentos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Departamentos))
			begin
			 UPDATE Departamentos
			 SET 
			 IdDep = t2.IdDep,Departamento = t2.Departamento,Codigo = t2.Codigo,IdPais = t2.IdPais,Inactivo = t2.Inactivo
			 FROM Departamentos T1
			 JOIN @Departamentos T2 ON T1.IdDep = T2.IdDep
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Departamentos))
			BEGIN
			 INSERT INTO Departamentos(
			 IdDep,Departamento,Codigo,IdPais,Inactivo
			 )
			 SELECT 
			 IdDep,Departamento,Codigo,IdPais,Inactivo
			 FROM @Departamentos
			 WHERE IdDep NOT IN(SELECT IdDep FROM Departamentos)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(8)
			 SELECT @id = IdDep FROM @Departamentos
			 DELETE FROM Departamentos WHERE IdDep = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsDocConceptos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsDocConceptos]
	@Conceptos [dbo].[dataTypeConceptos] READONLY,
	@ConceptosCue [dbo].[dataTypeConceptosCue] READONLY,
	@ConceptosCia [dbo].[dataTypeConceptosCia] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Conceptos))
			begin
			 UPDATE Conceptos
			 SET
			  IdConcepto = t2.IdConcepto, Concepto = t2.Concepto, IdDoc = t2.IdDoc, IdCom = t2.IdCom,
			  Vcmto = t2.Vcmto, Imptos = t2.Imptos, Retfte = t2.Retfte, RetIca = t2.RetIca,
			  Observacion = t2.Observacion, Pdterminado = t2.Pdterminado, TrfaSanc = t2.TrfaSanc, RndTotal = t2.RndTotal,
			  DcmtoEquiv = t2.DcmtoEquiv, Inactivo = t2.Inactivo, FechaAdd = t2.FechaAdd, FechaUpdate = t2.FechaUpdate,
			  IdUsuario = t2.IdUsuario, TipoContab = t2.TipoContab, CdComNiif = t2.CdComNiif, CdComFiscal = t2.CdComFiscal,CodCiaTdo=t2.CodCiaTdo,
			  TipoConRev = t2.TipoConRev
			 FROM Conceptos t1
			 JOIN @Conceptos t2 ON t1.IdConcepto = t2.IdConcepto
			 WHERE t1.IdConcepto = t2.IdConcepto
			end

			IF(EXISTS(SELECT TOP 1 * FROM @ConceptosCia))
			begin
			  declare @id varchar(4) 
			  select top 1 @id = IdConcepto from @ConceptosCia
				delete from ConceptosCia where IdConcepto = @id
				
				insert into ConceptosCia(
				IdConcepto,IdCia )
				select 
				IdConcepto,IdCia
				from @ConceptosCia 
				where (IdConcepto+Idcia) NOT IN(SELECT (IdConcepto+Idcia) FROM ConceptosCia) 
			end

			IF(EXISTS(SELECT TOP 1 * FROM @ConceptosCue))
			begin
			 --Actualizar los que existen
			 UPDATE ConceptosCue
			 SET 
			  IdConcepto = t2.IdConcepto, IdClase = t2.IdClase,
			  Descripcion = t2.Descripcion, IdCuenta = t2.IdCuenta,
			  TipoMov = t2.TipoMov, DetalleMov = t2.DetalleMov,
			  CdCCosto = t2.CdCCosto, CdSubCos = t2.CdSubCos,
			  TipoTerc = t2.TipoTerc, FecAdd = t2.FecAdd, FecUpdate = t2.FecUpdate
			 FROM ConceptosCue t1
			 JOIN @ConceptosCue t2 ON t1.IdConcepto = t2.IdConcepto and t1.IdClase = t2.IdClase
			 WHERE t1.IdConcepto = t2.IdConcepto and t1.IdClase = t2.IdClase
			 --Inserta los que no existen
			 INSERT INTO ConceptosCue(
			  IdConcepto,IdClase,Descripcion,IdCuenta,TipoMov,DetalleMov,
			  CdCCosto,CdSubCos,TipoTerc,FecAdd,FecUpdate
			 )
			 SELECT 
			  IdConcepto,IdClase,Descripcion,IdCuenta,TipoMov,DetalleMov,
			  CdCCosto,CdSubCos,TipoTerc,FecAdd,FecUpdate
			 FROM @ConceptosCue
			 WHERE (IdConcepto+Convert(varchar,IdClase)) NOT IN(SELECT (IdConcepto+Convert(varchar,IdClase)) FROM ConceptosCue)
			end					
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Conceptos))
			BEGIN
			INSERT INTO Conceptos(
			IdConcepto,Concepto,IdDoc,IdCom,Vcmto,
			Imptos,Retfte,RetIca,Observacion,Pdterminado,
			TrfaSanc,RndTotal,DcmtoEquiv,Inactivo,FechaAdd,
			FechaUpdate,IdUsuario,TipoContab,CdComNiif,CdComFiscal,CodCiaTdo,TipoConRev
			)
			SELECT 
			IdConcepto,Concepto,IdDoc,IdCom,Vcmto,
			Imptos,Retfte,RetIca,Observacion,Pdterminado,
			TrfaSanc,RndTotal,DcmtoEquiv,Inactivo,FechaAdd,
			FechaUpdate,IdUsuario,TipoContab,CdComNiif,CdComFiscal,CodCiaTdo,TipoConRev
			FROM @Conceptos
			WHERE IdConcepto NOT IN(SELECT IdConcepto FROM Conceptos)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @ConceptosCia))
			BEGIN
			INSERT INTO ConceptosCia(
			IdConcepto,IdCia )
			SELECT 
			IdConcepto,IdCia
			FROM @ConceptosCia 
			WHERE (IdConcepto+Idcia) NOT IN(SELECT (IdConcepto+Idcia) FROM ConceptosCia)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @ConceptosCue))
			BEGIN
			INSERT INTO ConceptosCue(
			IdConcepto,IdClase,Descripcion,IdCuenta,TipoMov,DetalleMov,
			CdCCosto,CdSubCos,TipoTerc,FecAdd,FecUpdate)
			SELECT 
			IdConcepto,IdClase,Descripcion,IdCuenta,TipoMov,DetalleMov,
			CdCCosto,CdSubCos,TipoTerc,FecAdd,FecUpdate
			FROM @ConceptosCue
			WHERE (IdConcepto+Convert(varchar,IdClase)) NOT IN(SELECT (IdConcepto+Convert(varchar,IdClase)) FROM ConceptosCue)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @_id VARCHAR (4)
			 DECLARE @idcl int
			 
			 IF(EXISTS(SELECT TOP 1 * FROM @Conceptos))	
			 BEGIN
				SELECT @_id = IdConcepto FROM @Conceptos
				 DELETE FROM ConceptosCue WHERE IdConcepto = @_id
				DELETE FROM ConceptosCia WHERE IdConcepto = @_id
				DELETE FROM Conceptos WHERE IdConcepto = @_id	
			 END

			 IF(EXISTS(SELECT TOP 1 * FROM @ConceptosCue))
			 BEGIN
				if((SELECT count(IdClase) FROM @ConceptosCue) = 1)
				begin 
				 SELECT @_id = IdConcepto, @idcl = IdClase FROM @ConceptosCue
				 DELETE FROM ConceptosCue WHERE IdConcepto = @_id and IdClase = @idcl
				end
				else 
				begin
				 SELECT @_id = IdConcepto FROM @ConceptosCue
				 DELETE FROM ConceptosCue WHERE IdConcepto = @_id
				end
			 END
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEdsServicio]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsEdsServicio]
	@EdsServicio [dbo].[dataTypeEdsServicio] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE EdsServicio
			 SET 
			 IdEstacion = t2.IdEstacion,EstServicio = t2.EstServicio,Direccion = t2.Direccion,Inactivo = t2.Inactivo
		     FROM EdsServicio t1
			 JOIN @EdsServicio t2 ON t1.IdEstacion = t2.IdEstacion
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO EdsServicio(
			 IdEstacion,EstServicio,Direccion,Inactivo
			 )
			 SELECT 
			 IdEstacion,EstServicio,Direccion,Inactivo
			 FROM @EdsServicio
			 WHERE IdEstacion NOT IN(SELECT IdEstacion FROM EdsServicio)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdEstacion FROM @EdsServicio
			 DELETE FROM EdsServicio WHERE IdEstacion = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEstadoDoc]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsEstadoDoc]
	@EstadoDoc [dbo].[dataTypeEstadoDoc] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @EstadoDoc))
			begin
			 UPDATE EstadoDoc
			 SET 
			 IdEstado = t2.IdEstado,Estado = t2.Estado,NColor = t2.NColor,CodDcmto = t2.CodDcmto,Inactivo = t2.Inactivo
			 FROM EstadoDoc T1
			 JOIN @EstadoDoc T2 ON T1.IdEstado = T2.IdEstado
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @EstadoDoc))
			BEGIN
			 INSERT INTO EstadoDoc(
			 IdEstado,Estado,NColor,CodDcmto,Inactivo
			 )
			 SELECT 
			 IdEstado,Estado,NColor,CodDcmto,Inactivo
			 FROM @EstadoDoc
			 WHERE IdEstado NOT IN(SELECT IdEstado FROM EstadoDoc)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdEstado FROM @EstadoDoc		
			 DELETE FROM EstadoDoc WHERE IdEstado = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEstadoTer]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsEstadoTer]
	@EstadoTer [dbo].[dataTypeEstadoTer] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @EstadoTer))
			begin
			 UPDATE EstadoTer
			 SET 
			 IdEstado = t2.IdEstado,Estado = t2.Estado,NColor = t2.NColor,Inactivo = t2.Inactivo
			 FROM EstadoTer T1
			 JOIN @EstadoTer T2 ON T1.IdEstado = T2.IdEstado
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @EstadoTer))
			BEGIN
			 INSERT INTO EstadoTer(
			 IdEstado,Estado,NColor,Inactivo
			 )
			 SELECT 
			 IdEstado,Estado,NColor,Inactivo
			 FROM @EstadoTer
			 WHERE IdEstado NOT IN(SELECT IdEstado FROM EstadoTer)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdEstado FROM @EstadoTer
			 DELETE FROM EstadoTer WHERE IdEstado = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsEstadoVeh]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsEstadoVeh]
	@EstadoVeh [dbo].[dataTypeEstadoVeh] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @EstadoVeh))
			begin
			 UPDATE EstadoVeh
			 SET 
			 IdEstado = t2.IdEstado, Estado = t2.Estado,
			 NColor = t2.NColor, OutDemand = t2.OutDemand,
			 Inactivo = t2.Inactivo
			 FROM EstadoVeh T1
			 JOIN @EstadoVeh T2 ON T1.IdEstado = T2.IdEstado
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @EstadoVeh))
			BEGIN
			 INSERT INTO EstadoVeh(
			 IdEstado,Estado,NColor,OutDemand,Inactivo
			 )
			 SELECT 
			 IdEstado,Estado,NColor,OutDemand,Inactivo
			 FROM @EstadoVeh
			 WHERE IdEstado NOT IN(SELECT IdEstado FROM EstadoVeh)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdEstado FROM @EstadoVeh
			 DELETE FROM EstadoVeh WHERE IdEstado = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsExpLicencias]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsExpLicencias]
	@ExpLicencias [dbo].[dataTypeExpLicencias] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE ExpLicencias
			 SET 
			 IdLugar = t2.IdLugar,LugarLic = t2.LugarLic,CodDpto = t2.CodDpto,Dpto = t2.Dpto,Inactivo = t2.Inactivo
		     FROM ExpLicencias t1
			 JOIN @ExpLicencias t2 ON t1.IdLugar = t2.IdLugar
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO ExpLicencias(
			 IdLugar,LugarLic,CodDpto,Dpto,Inactivo
			 )
			 SELECT 
			 IdLugar,LugarLic,CodDpto,Dpto,Inactivo
			 FROM @ExpLicencias
			 WHERE IdLugar NOT IN(SELECT IdLugar FROM ExpLicencias)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(8)
			 SELECT @id = IdLugar FROM @ExpLicencias
			 DELETE FROM ExpLicencias WHERE IdLugar = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsGruposCli]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsGruposCli]
	@GruposCli [dbo].[dataTypeGruposCli] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE GruposCli
			 SET 
			 IdGrupo = t2.IdGrupo,GrupoClie = t2.GrupoClie,ModApp = t2.ModApp,Inactivo = t2.Inactivo
		     FROM GruposCli t1
			 JOIN @GruposCli t2 ON t1.IdGrupo = t2.IdGrupo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO GruposCli(
			 IdGrupo,GrupoClie,ModApp,Inactivo
			 )
			 SELECT 
			 IdGrupo,GrupoClie,ModApp,Inactivo
			 FROM @GruposCli
			 WHERE IdGrupo NOT IN(SELECT IdGrupo FROM GruposCli)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdGrupo FROM @GruposCli
			 DELETE FROM GruposCli WHERE IdGrupo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsGruposPro]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsGruposPro]
	@GruposPro [dbo].[dataTypeGruposPro] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE GruposPro
			 SET
			 IdGrupo = t2.IdGrupo, GrupoProp = t2.GrupoProp, Inactivo = t2.Inactivo
		     FROM GruposPro t1
			 JOIN @GruposPro t2 ON t1.IdGrupo = t2.IdGrupo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO GruposPro(
			 IdGrupo,GrupoProp,Inactivo
			 )
			 SELECT 
			 IdGrupo,GrupoProp,Inactivo
			 FROM @GruposPro
			 WHERE IdGrupo NOT IN(SELECT IdGrupo FROM GruposPro)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdGrupo FROM @GruposPro
			 DELETE FROM GruposPro WHERE IdGrupo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsGruposRot]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsGruposRot]
	@GruposRot [dbo].[dataTypeGruposRot] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE GruposRot
			 SET
			 IdGrupo = t2.IdGrupo,GrupoRot = t2.GrupoRot,Inactivo = t2.Inactivo
		     FROM GruposRot t1
			 JOIN @GruposRot t2 ON t1.IdGrupo = t2.IdGrupo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO GruposRot(
			 IdGrupo,GrupoRot,Inactivo
			 )
			 SELECT 
			 IdGrupo,GrupoRot,Inactivo
			 FROM @GruposRot
			 WHERE IdGrupo NOT IN(SELECT IdGrupo FROM GruposRot)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdGrupo FROM @GruposRot
			 DELETE FROM GruposRot WHERE IdGrupo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsListaPasajeros]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsListaPasajeros]
	@Trn_TraEspPasajeros [dbo].[dataTypeTrn_TraEspPasajeros] READONLY,
	@Trn_TraEspListaPasajeros [dbo].[dataTypeTrn_TraEspListaPasajeros] READONLY,
	@Trn_TraEspContratoVehLista [dbo].[dataTypeTrn_TraEspContratoVehLista] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Numero INT --Esta variable guarda el nÃºmero de consecutivo de la lista

	BEGIN TRAN
		BEGIN TRY

			IF(@operacion = 'i')
			BEGIN
				SELECT @Numero = ISNULL(MAX(IdLista),0) + 1  FROM Trn_TraEspLista
			END

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			   if(EXISTS(SELECT * FROM @Trn_TraEspPasajeros))
			   begin
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspPasajeros(
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				)
				SELECT 
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				FROM @Trn_TraEspPasajeros
				WHERE (TipId + Documento) NOT IN(SELECT (TipId + Documento) FROM Trn_TraEspPasajeros)

			   --UPDATE Trn_TraEspPasajeros
			   --SET 
			   --TipId = t2.TipId,Documento = t2.Documento,Apellidos = t2.Apellidos,
			   --Nombres = t2.Nombres,Cargo = t2.Cargo,EsMonitor = t2.EsMonitor,
			   --Telefono = t2.Telefono,Observacion = t2.Observacion
			   --FROM Trn_TraEspPasajeros t1
			   --JOIN @Trn_TraEspPasajeros t2 ON t1.TipId = t2.TipId and t1.Documento = t2.Documento			   
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspListaPasajeros))
			   begin
			   UPDATE Trn_TraEspListaPasajeros
			   SET 
			   IdLista = t2.IdLista,Documento = t2.Documento
		       FROM Trn_TraEspListaPasajeros t1
			   JOIN @Trn_TraEspListaPasajeros t2 ON t1.IdLista = t2.IdLista and t1.Documento = t2.Documento
			   --Insertar si no existe
			    INSERT INTO Trn_TraEspListaPasajeros(
				IdLista,Documento) 
				SELECT 
				IdLista,Documento
				FROM @Trn_TraEspListaPasajeros
				WHERE (CONVERT(VARCHAR(16),IdLista) + Documento) NOT IN(SELECT (CONVERT(VARCHAR(16),IdLista) + Documento) FROM Trn_TraEspListaPasajeros)
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspContratoVehLista))
			   begin
			   UPDATE Trn_TraEspContratoVehLista
			   SET 
			   IdLista = t2.IdLista,TipDoc = t2.TipDoc,Contrato = t2.Contrato,
			   IdCia = t2.IdCia,Item = t2.Item,IdVehiculo = t2.IdVehiculo,Fecha = t2.Fecha,IdEstado = t2.IdEstado,
			   FecUpdate = t2.FecUpdate,IdUsuario = t2.IdUsuario
		       FROM Trn_TraEspContratoVehLista t1
			   JOIN @Trn_TraEspContratoVehLista t2 ON t1.IdLista = t2.IdLista and t1.TipDoc = t2.TipDoc and t1.Contrato = t2.Contrato and t1.IdCia = t2.IdCia and t1.IdVehiculo = t2.IdVehiculo
			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN

				IF(EXISTS(SELECT * FROM @Trn_TraEspPasajeros))
				begin
				INSERT INTO Trn_TraEspPasajeros(
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				)
				SELECT 
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				FROM @Trn_TraEspPasajeros
				WHERE (TipId + Documento) NOT IN(SELECT (TipId + Documento) FROM Trn_TraEspPasajeros)
				end

				INSERT INTO Trn_TraEspLista(IdLista) values (@Numero)

				IF(EXISTS(SELECT * FROM @Trn_TraEspListaPasajeros))
				begin
				INSERT INTO Trn_TraEspListaPasajeros(
				IdLista,Documento
				) 
				SELECT 
				@Numero,Documento
				FROM @Trn_TraEspListaPasajeros
				WHERE (CONVERT(VARCHAR(16),IdLista) + Documento) NOT IN(SELECT (CONVERT(VARCHAR(16),IdLista) + Documento) FROM Trn_TraEspListaPasajeros)
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspContratoVehLista))
				begin
				INSERT INTO Trn_TraEspContratoVehLista(
				IdLista,TipDoc,Contrato,IdCia,Item,IdVehiculo,Fecha,IdEstado,FecUpdate,IdUsuario
				) 
				SELECT 
				@Numero,TipDoc,Contrato,IdCia,Item,IdVehiculo,Fecha,IdEstado,FecUpdate,IdUsuario
				FROM @Trn_TraEspContratoVehLista
				end						

			 END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 declare @Pedido int
			 select @Pedido = IdLista from @Trn_TraEspListaPasajeros
				 DELETE FROM Trn_TraEspListaPasajeros WHERE IdLista = @Pedido 

			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
			  UPDATE Trn_TraEspContratoVehLista 
			  SET IdEstado = '9999' 
			  WHERE 
			  IdLista = (select IdLista from @Trn_TraEspContratoVehLista) and TipDoc = (select TipDoc from @Trn_TraEspContratoVehLista) and IdCia = (select IdCIa from @Trn_TraEspContratoVehLista) and Contrato = (select Contrato from @Trn_TraEspContratoVehLista) and Item = (select Item from @Trn_TraEspContratoVehLista)
			END

			SELECT '1'

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsListaPasaRes]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsListaPasaRes]
	@Trn_TraEspPasajeros [dbo].[dataTypeTrn_TraEspPasajeros] READONLY,
	@Trn_TraEspListaPasajeros [dbo].[dataTypeTrn_TraEspListaPasajeros] READONLY,
	@Trn_TraEspReservaVehLista [dbo].[dataTypeTrn_TraEspReservaVehLista] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Numero INT --Esta variable guarda el nÃºmero de consecutivo de la lista

	BEGIN TRAN
		BEGIN TRY

			IF(@operacion = 'i')
			BEGIN
				SELECT @Numero = ISNULL(MAX(IdLista),0) + 1  FROM Trn_TraEspListaRes
			END

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			   if(EXISTS(SELECT * FROM @Trn_TraEspPasajeros))
			   begin
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspPasajeros(
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				)
				SELECT 
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				FROM @Trn_TraEspPasajeros
				WHERE (TipId + Documento) NOT IN(SELECT (TipId + Documento) FROM Trn_TraEspPasajeros)

			   --UPDATE Trn_TraEspPasajeros
			   --SET 
			   --TipId = t2.TipId,Documento = t2.Documento,Apellidos = t2.Apellidos,
			   --Nombres = t2.Nombres,Cargo = t2.Cargo,EsMonitor = t2.EsMonitor,
			   --Telefono = t2.Telefono,Observacion = t2.Observacion
			   --FROM Trn_TraEspPasajeros t1
			   --JOIN @Trn_TraEspPasajeros t2 ON t1.TipId = t2.TipId and t1.Documento = t2.Documento			   
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspListaPasajeros))
			   begin
			   UPDATE Trn_TraEspListaPasaRes
			   SET 
			   IdLista = t2.IdLista,Documento = t2.Documento
		       FROM Trn_TraEspListaPasaRes t1
			   JOIN @Trn_TraEspListaPasajeros t2 ON t1.IdLista = t2.IdLista and t1.Documento = t2.Documento
			   --Insertar si no existe
			    INSERT INTO Trn_TraEspListaPasaRes(
				IdLista,Documento) 
				SELECT 
				IdLista,Documento
				FROM @Trn_TraEspListaPasajeros
				WHERE (CONVERT(VARCHAR(16),IdLista) + Documento) NOT IN(SELECT (CONVERT(VARCHAR(16),IdLista) + Documento) FROM Trn_TraEspListaPasaRes)
				--Eliminar los pasajeros que no existen en el tipo de dato
			   delete from Trn_TraEspListaPasaRes
			   WHERE Documento NOT IN(SELECT Documento FROM @Trn_TraEspListaPasajeros) and IdLista = (SELECT TOP 1 IdLista FROM @Trn_TraEspListaPasajeros)
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspReservaVehLista))
			   begin
			   UPDATE Trn_TraEspReservaVehLista
			   SET 
			   IdLista = t2.IdLista,TipDoc = t2.TipDoc,Reserva = t2.Reserva,
			   IdCia = t2.IdCia,Item = t2.Item,IdVehiculo = t2.IdVehiculo,Fecha = t2.Fecha,IdEstado = t2.IdEstado,
			   FecUpdate = t2.FecUpdate,IdUsuario = t2.IdUsuario, IdListaCOE = t2.IdListaCOE
		       FROM Trn_TraEspReservaVehLista t1
			   JOIN @Trn_TraEspReservaVehLista t2 ON t1.IdLista = t2.IdLista and t1.TipDoc = t2.TipDoc and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCia and t1.IdVehiculo = t2.IdVehiculo
			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN

				IF(EXISTS(SELECT * FROM @Trn_TraEspPasajeros))
				begin
				INSERT INTO Trn_TraEspPasajeros(
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				)
				SELECT 
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				FROM @Trn_TraEspPasajeros
				WHERE (TipId + Documento) NOT IN(SELECT (TipId + Documento) FROM Trn_TraEspPasajeros)
				end

				INSERT INTO Trn_TraEspListaRes(IdLista) values (@Numero)

				IF(EXISTS(SELECT * FROM @Trn_TraEspListaPasajeros))
				begin
				INSERT INTO Trn_TraEspListaPasaRes(
				IdLista,Documento
				) 
				SELECT 
				@Numero,Documento
				FROM @Trn_TraEspListaPasajeros
				WHERE (CONVERT(VARCHAR(16),IdLista) + Documento) NOT IN(SELECT (CONVERT(VARCHAR(16),IdLista) + Documento) FROM Trn_TraEspListaPasaRes)
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspReservaVehLista))
				begin
				INSERT INTO Trn_TraEspReservaVehLista(
				IdLista,TipDoc,Reserva,IdCia,Item,IdVehiculo,Fecha,IdEstado,FecUpdate,IdUsuario,IdListaCOE
				) 
				SELECT 
				@Numero,TipDoc,Reserva,IdCia,Item,IdVehiculo,Fecha,IdEstado,FecUpdate,IdUsuario,IdlistaCOE
				FROM @Trn_TraEspReservaVehLista
				end						

			 END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 declare @Pedido int
			 select @Pedido = IdLista from @Trn_TraEspListaPasajeros
				 DELETE FROM Trn_TraEspListaPasaRes WHERE IdLista = @Pedido 

			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
			  UPDATE Trn_TraEspReservaVehLista 
			  SET IdEstado = '9999' 
			  WHERE 
			  IdLista = (select IdLista from @Trn_TraEspReservaVehLista) and TipDoc = (select TipDoc from @Trn_TraEspReservaVehLista) and IdCia = (select IdCIa from @Trn_TraEspReservaVehLista) and Reserva = (select Reserva from @Trn_TraEspReservaVehLista) and Item = (select Item from @Trn_TraEspReservaVehLista)
			END

			SELECT '1'

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsListaPasaResProceso]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsListaPasaResProceso]
	@TrnListaPasaResProceso [dbo].[dataTypeListaPasaResProceso] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY
		--------------------------Varibales del procedimiento---------------------------------------------		 
		DECLARE @Numero INT --Esta variable guarda el nÃºmero de consecutivo de la lista
		DECLARE @NumeroListaCopy INT  --Esta variable guarda el nÃºmero de consecutivo de la lista a copiar
		--DECLARE @TipRes VARCHAR(3)  --Tipo de doc de la Reserva destino de rÃ©plica
		--DECLARE @Reserva INT --NÃºmero de la Reserva destino de rÃ©plica
		--DECLARE @ItemRes INT --Ãtem de la Reserva destino de rÃ©plica
		--DECLARE @IdCiaRes CHAR(2)  --CÃ­a de la Reserva destino de rÃ©plica
		---------------------------------------------------------------------------------------------------
		SELECT @Numero = ISNULL(MAX(IdLista),0) + 1  FROM Trn_TraEspListaRes
		SELECT @NumeroListaCopy = IdLista FROM @TrnListaPasaResProceso
		--Insertar el nuevo consecutivo para la lista
		INSERT INTO Trn_TraEspListaRes VALUES(@Numero)
		--Insertar los pasajeros para la nueva lista en base a una lista anterior
		INSERT INTO Trn_TraEspListaPasaRes(
			IdLista,Documento) 
			SELECT 
			@Numero,pa.Documento
			FROM Trn_TraEspListaPasaRes AS pa
			WHERE IdLista = @NumeroListaCopy
		INSERT INTO Trn_TraEspReservaVehLista(IdLista, TipDoc, Reserva, IdCia, Item, IdVehiculo, Fecha, IdEstado, FecUpdate, IdUsuario, IdListaCOE)
		SELECT @Numero, TipRes, Reserva, IdCiaRes, ItemRes, IdVehiculo, Fecha, '0001', NULL, IdUsuario, 0
		FROM @TrnListaPasaResProceso
		--Respuesta Devuelta
		SELECT @Numero

		COMMIT TRAN
	END TRY
BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLocalidades]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsLocalidades]
	@Localidades [dbo].[dataTypeLocalidades] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Localidades
			 SET 
			 IdLocal = t2.IdLocal,Localidad = t2.Localidad,IdDep = t2.IdDep,TipLocal = t2.TipLocal,Dist_Kmt = t2.Dist_Kmt,Time_hh = t2.Time_hh,
			 DistSede = t2.DistSede,TimeSede = t2.TimeSede,CelRow = t2.CelRow,CelCol = t2.CelCol,CodAlias = t2.CodAlias,Inactivo = t2.Inactivo
		     FROM Localidades t1
			 JOIN @Localidades t2 ON t1.IdLocal = t2.IdLocal
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Localidades(
			 IdLocal,Localidad,IdDep,TipLocal,Dist_Kmt,Time_hh,DistSede,TimeSede,CelRow,CelCol,CodAlias,Inactivo
			 )
			 SELECT 
			 IdLocal,Localidad,IdDep,TipLocal,Dist_Kmt,Time_hh,DistSede,TimeSede,CelRow,CelCol,CodAlias,Inactivo
			 FROM @Localidades
			 WHERE IdLocal NOT IN(SELECT IdLocal FROM Localidades)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id VARCHAR (8)
			 SELECT @id = IdLocal FROM @Localidades
			 DELETE FROM Localidades WHERE IdLocal = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLogTraEspInOut]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsLogTraEspInOut]
	@LogTraEspInOut [dbo].[dataTypeLogTraEspInOut] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
		BEGIN TRY

		DECLARE @num INT 
		SELECT @num = Count(*) FROM LogTraEspInOut WHERE IdUsuario = (SELECT TOP 1 IdUsuario FROM @LogTraEspInOut) AND IdCia = (SELECT TOP 1 IdCia FROM @LogTraEspInOut)

		if(@operacion = 'i')
		begin
			INSERT INTO LogTraEspInOut(
			IdLog,IdCia,IdUsuario,Fecha,HoraEntrada,HoraSalida,Finalizo,Nombre,Dsname
			)
			SELECT			
			(@num + IdLog),IdCia,IdUsuario,Fecha,HoraEntrada,HoraSalida,Finalizo,Nombre,Dsname
			FROM @LogTraEspInOut
		end

		if(@operacion = 'u')
		begin
			update LogTraEspInOut
			set 			
			HoraSalida = t2.HoraSalida,Finalizo = t2.Finalizo
			from LogTraEspInOut	t1
			join @LogTraEspInOut t2 on t1.IdLog = t2.IdLog and t1.IdCia = t2.IdCia and t1.IdUsuario = t2.IdUsuario
		end

		SELECT	(@num + (select idlog from @LogTraEspInOut)) 

		COMMIT TRAN
		END TRY
		BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
        DECLARE @ErrorSeverity INT;
        DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR (
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLogTraEspPro]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsLogTraEspPro]
	@LogTraEspPro [dbo].[dataTypeLogTraEspPro] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
		BEGIN TRY

		DECLARE @num INT 
		SELECT @num = Count(*) FROM LogTraEspPro WHERE IdCia = (SELECT TOP 1 IdCia FROM @LogTraEspPro)
		--IdUsuario = (SELECT TOP 1 IdUsuario FROM @LogTraEspPro) AND IdCia = (SELECT TOP 1 IdCia FROM @LogTraEspPro)

		if(@operacion = 'i')
		begin
			INSERT INTO LogTraEspPro(
			IdLog,IdPro,IdCia,Fecha,TimeSys,IdUsuario,Nombre,NomTabla,Observacion,nModulo,Dsname
			)
			SELECT			
			(@num + IdLog),IdPro,IdCia,Fecha,TimeSys,IdUsuario,Nombre,NomTabla,Observacion,nModulo,Dsname
			FROM @LogTraEspPro
		end


		SELECT	(@num + (select idlog from @LogTraEspPro)) 

		COMMIT TRAN
		END TRY
		BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
        DECLARE @ErrorSeverity INT;
        DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR (
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsLogTraEspSys]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	Joe Alexander Núñez Yaguna
-- Create date(dd/MM/yyyy): 26/10/2016
-- Description:	Guardar LogTraEspSys
-- =============================================
CREATE PROCEDURE [dbo].[paWcfSeInsLogTraEspSys]
	@LogTraEspSys dataTypeLogTraEspSys READONLY, --Tipo de dato definido por el usuario que representa la tabla LogTraEspSys
	@LogTraEspTarifas dataTypeLogTraEspTarifas READONLY, --Tipo de dato definido por el usuario que representa la tabla LogTraEspTarifas
	@operacion varchar(1)
AS
	BEGIN TRAN
		BEGIN TRY

		DECLARE @num INT 
		SELECT @num = Count(*) FROM LogTraEspSys WHERE TipDoc = (SELECT TOP 1 TipDoc FROM @LogTraEspSys) AND Documento = (SELECT TOP 1 Documento FROM @LogTraEspSys) AND IdCia = (SELECT TOP 1 IdCia FROM @LogTraEspSys)

		IF(@operacion = 'i')
		BEGIN
			INSERT INTO LogTraEspSys(
			IdLog,TipDoc,Documento,IdCia,Fecha,TimeSys,IdUsuario,Nombre,Observacion,IdTercero,
			IdVehiculo,EsCom,Eliminado,Modificado,nModulo,Dsname
			)
			SELECT			
			(@num + IdLog),TipDoc,Documento,IdCia,Fecha,TimeSys,IdUsuario,Nombre,Observacion,IdTercero,
			IdVehiculo,EsCom,Eliminado,Modificado,nModulo,Dsname		
			FROM @LogTraEspSys

			IF(EXISTS(SELECT TOP 1 * FROM @LogTraEspTarifas))
			BEGIN 
				IF EXISTS(SELECT 1 
					FROM LogTraEspTarifas LTESP
					INNER JOIN @LogTraEspTarifas AS LT 
											 ON LT.TipDoc = LTESP.TipDoc
											 AND LT.Numero = LTESP.Numero
											 AND LT.IdCia = LTESP.IdCia
											 AND LT.Item = LTESP.Item)
				BEGIN
					UPDATE LTESP
					SET 
					LTESP.Fecha = LT.Fecha,
					LTESP.CdCarga = LT.CdCarga,
					LTESP.DescripCarga = LT.DescripCarga,
					LTESP.Cantidad = LT.Cantidad,
					LTESP.PesoNeto = LT.PesoNeto,
					LTESP.TarifClie = LT.TarifClie,
					LTESP.TarifPago = LT.TarifPago,
					LTESP.VrTotal = LT.VrTotal,
					LTESP.IdUsuario = LT.IdUsuario,
					LTESP.Nombre = LT.Nombre
					FROM LogTraEspTarifas AS LTESP
					INNER JOIN @LogTraEspTarifas AS LT 
												 ON LT.TipDoc = LTESP.TipDoc
												 AND LT.Numero = LTESP.Numero
												 AND LT.IdCia = LTESP.IdCia
												 AND LT.Item = LTESP.Item
				END
				
				INSERT INTO LogTraEspTarifas(
				TipDoc,Numero,IdCia,Item,Fecha,CdCarga,DescripCarga,Cantidad,PesoNeto,TarifClie,TarifPago,
				VrTotal,IdUsuario,Nombre
				)
				SELECT			
				TipDoc,Numero,IdCia,Item,Fecha,CdCarga,DescripCarga,Cantidad,PesoNeto,TarifClie,TarifPago,
				VrTotal,IdUsuario,Nombre	
				FROM @LogTraEspTarifas LT
				WHERE NOT EXISTS (
						SELECT 1 FROM LogTraEspTarifas LTESP
						WHERE LT.TipDoc = LTESP.TipDoc
						AND LT.Numero = LTESP.Numero
						AND LT.IdCia = LTESP.IdCia
						AND LT.Item = LTESP.Item);
			END
		END

		select '1'

		COMMIT TRAN
		END TRY
		BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
        DECLARE @ErrorSeverity INT;
        DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR (
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
		END CATCH
RETURN 0

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMarcas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMarcas]
	@Marcas [dbo].[dataTypeMarcas] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Marcas
			 SET 
			 IdMarca = t2.IdMarca,Marca = t2.Marca,TipoMarca = t2.TipoMarca,CodigoMT = t2.CodigoMT,Inactivo = t2.Inactivo
		     FROM Marcas t1
			 JOIN @Marcas t2 ON t1.IdMarca = t2.IdMarca
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Marcas(
			 IdMarca,Marca,TipoMarca,CodigoMT,Inactivo
			 )
			 SELECT 
			 IdMarca,Marca,TipoMarca,CodigoMT,Inactivo
			 FROM @Marcas
			 WHERE IdMarca NOT IN(SELECT IdMarca FROM Marcas)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdMarca FROM @Marcas
			 DELETE FROM Marcas WHERE IdMarca = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMarcasLin]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMarcasLin]
	@MarcasLin [dbo].[dataTypeMarcasLin] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE MarcasLin
			 SET 
			 IdLinea = t2.IdLinea,LineaVeh = t2.LineaVeh,IdMarca = t2.IdMarca,CodMT = t2.CodMT,Inactivo = t2.Inactivo
		     FROM MarcasLin t1
			 JOIN @MarcasLin t2 ON t1.IdLinea = t2.IdLinea 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO MarcasLin(
			 IdLinea,LineaVeh,IdMarca,CodMT,Inactivo
			 )
			 SELECT 
			 IdLinea,LineaVeh,IdMarca,CodMT,Inactivo
			 FROM @MarcasLin
			 WHERE (IdLinea NOT IN(SELECT IdLinea FROM MarcasLin)) 
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 DECLARE @idmarca varchar(4)
			 SELECT @id = IdLinea, @idmarca = IdMarca FROM @MarcasLin
			 DELETE FROM MarcasLin WHERE IdMarca = @idmarca and IdLinea = @id 
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvFuec]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMsvFuec]
	-- @Trn_TraEspFuec [dbo].[dataTypeTrn_TraEspFuec] READONLY,
	@Trn_TraEspFuecDetalle [dbo].[dataTypeTrn_TraEspFuecDetalle] READONLY,
	@Trn_TraEspFuecAnexo [dbo].[dataTypeTrn_TraEspFuecAnexo] READONLY,
	@Trn_TraEspFuecCndtores [dbo].[dataTypeTrn_TraEspFuecCndtores] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Fuec
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Fuec
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Fuec
--declare @item int
	BEGIN TRAN
		BEGIN TRY
		
			CREATE TABLE #LogFuecDetalle(
			TipDocFuec varchar(3) NOT NULL,
			Fuec int NOT NULL,
			IdCiaFuec char(2) NOT NULL,
			IdVehiculo varchar(10) NOT NULL,
			TipDocRes varchar(3) NOT NULL,
			Reservas int NOT NULL,
			IdCiaRes char(2) NOT NULL,
			ItemRes int NOT NULL
			)

			--declare @NumProc int = 1
			declare @TipDocu varchar(3)
			declare @Fuec INT
			declare @CiaFuec varchar(2)
			declare @IdVehiculo varchar(10)
			declare @TipDocRes varchar(3)
			declare @Reservas int
			declare @IdCiaRes char(2)
			declare @ItemRes int
			--esta variable para ir asignando el consecutivo fuec
			declare @Resolucion varchar(30)
			declare @ConsecutivoFUEC int = 0
			declare @_TipDocCOE varchar(3) ='COE'
			declare @_COE INT = 0
			declare @_CiaCOE char(2) ='00'
			declare @TipDocCOE varchar(3)
			declare @COE INT
			declare @CiaCOE char(2)
			declare @TipDocPgr varchar(3)
			declare @NumPgr INT
			declare @IdCiaPgr char(2)
			declare @ItemPgr INT
			--

			--DECLARE fueccursor CURSOR
			--FOR SELECT TipDoc,Fuec,IdCia,IdVehiculo,TipDocCnt,Contrato,CiaCnt,TipDocPgr,NumPgr,IdCiaPgr,ItemPgr FROM @Trn_TraEspFuec order by TipDocCnt, Contrato, CiaCnt
			--OPEN fueccursor
			--FETCH NEXT FROM fueccursor INTO @TipDocu,@Fuec,@CiaFuec,@IdVehiculo,@TipDocCOE,@COE,@CiaCOE,@TipDocPgr,@NumPgr,@IdCiaPgr,@ItemPgr
			--WHILE @@FETCH_STATUS = 0
			--BEGIN

			--	--Seleccionar Variables
			--	IF(@operacion = 'i')
			--	BEGIN
			--		SELECT TOP 1 @TipDoc = @TipDocu, @IdCia = @CiaFuec
			--		SELECT @Documento = (Numero + 1 ), @Resolucion = Resolucion FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

			--		IF(@Documento <> '')
			--			UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
			--		ELSE
			--		BEGIN
			--			SELECT @Documento = 1
			--			INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			--		END
			--	END

			--	--INSERT NO-EXISTE RECORDS
			--	IF(@operacion = 'i')
			--	BEGIN
			--		--Para asignar el nÃºmro de consecutivo
			--		if((@_TipDocCOE =  @TipDocCOE) AND (@_COE = @COE) AND (@_CiaCOE = @CiaCOE))
			--		begin
			--			SET @ConsecutivoFUEC = @ConsecutivoFUEC + 1;
			--		end
			--		ELSE
			--		BEGIN
			--			set @ConsecutivoFUEC = 0
			--			SELECT Top 1  @ConsecutivoFUEC = (ISNULL(MAX(Consecutivo), 0) + 1), @_TipDocCOE = TipDocCnt, @_COE = Contrato,  @_CiaCOE = CiaCnt  FROM Trn_TraEspFuec where ((TipDocCnt + CONVERT(varchar, Contrato) + CiaCnt)IN(@TipDocCOE + CONVERT(varchar, @COE) + @CiaCOE)) group by Consecutivo, TipDocCnt, Contrato, CiaCnt order by Consecutivo desc
			--			IF(@ConsecutivoFUEC = 0)
			--			BEGIN
			--				SET @ConsecutivoFUEC = 1
			--			END
			--			IF(@ConsecutivoFUEC = 1)
			--			BEGIN
			--				SET  @_TipDocCOE = @TipDocCOE
			--				SET @_COE = @COE
			--				SET @_CiaCOE = @CiaCOE
			--			END
			--		END

			--		IF(EXISTS(SELECT * FROM @Trn_TraEspFuec))
			--		begin
			--		--this.txtvNumResolucion.Text + Convert.ToDateTime(this.msktxtFecFUECTES.Text).Year.ToString() + this.txtvNumCOE.Text.PadLeft(4, '0') + Fuec.Fuec.Consecutivo.ToString().PadLeft(4, '0');
			--		INSERT INTO Trn_TraEspFuec(
			--		TipDoc, Fuec, IdCia, Numero, Fecha, FechaInicio, FechaFin, CdCarga, IdVehiculo, IdConductor, IdConductor2, IdConductor3, IdPoseedor, 
			--		IdRuta, CdTipRuta, IdOrigen, IdDestino, Modalidad, CantPasajeros, CodTarRet,CodTarIca, VrPresupuesto, VrCobro, VrPagos, VrCargos, VrDctos,
			--		VrIva, VrRetencion, VrReteIca, Cantidad, Peso, TipDocPgr, NumPgr, IdCiaPgr, ItemPgr, TipDocCnt, Contrato, CiaCnt, OrigenAdd, Anulado, FecDev, 
			--		IdEstado,TimeSys, FecUpdate, IdCiaCrea, IdUsuario, Consecutivo, Itinerario, FuecParcial, ComenParcial
			--		)
			--		SELECT 
			--		@TipDoc,@Documento,@IdCia,SUBSTRING(convert(varchar, (@Resolucion + convert(varchar, DATEPART(YEAR, Fecha))  + (right(('0000' + convert(varchar, Contrato)), 4)) + (right(('0000' + convert(varchar, @ConsecutivoFUEC)), 4)))), 1, 21), Fecha, FechaInicio, FechaFin, CdCarga, IdVehiculo, IdConductor, IdConductor2, IdConductor3, IdPoseedor, 
			--		IdRuta, CdTipRuta, IdOrigen, IdDestino, Modalidad, CantPasajeros, CodTarRet,CodTarIca, VrPresupuesto, VrCobro, VrPagos, VrCargos, VrDctos,
			--		VrIva, VrRetencion, VrReteIca, Cantidad, Peso, TipDocPgr, NumPgr, IdCiaPgr, ItemPgr, TipDocCnt, Contrato, CiaCnt, OrigenAdd, Anulado, FecDev, 
			--		IdEstado,TimeSys, FecUpdate, IdCiaCrea, IdUsuario, @ConsecutivoFUEC, Itinerario, FuecParcial, ComenParcial
			--		FROM @Trn_TraEspFuec f WHERE f.TipDoc= @TipDocu and f.Fuec = @Fuec and f.IdCia = @CiaFuec
			--		end
			
			--		IF(EXISTS(SELECT * FROM @Trn_TraEspFuecDetalle))
			--		begin
			--		select @TipDocRes = TipRes, @Reservas = Reserva, @IdCiaRes = IdCiaRes, @ItemRes = ItemRes FROM @Trn_TraEspFuecDetalle df WHERE df.TipDoc = @TipDocu and df.Fuec = @Fuec and df.IdCia = @CiaFuec
			--		INSERT INTO Trn_TraEspFuecDetalle(
			--		TipDoc, Fuec, IdCia, Item, TipRes, Reserva, IdCiaRes, ItemRes, NumPasajeros, PesoNeto, VrCobro, VrPagos, Referencia1, Referencia2, Referencia3,
			--		CdTipServicio, EsRutaCliente, Kilometros, DirOrigen, FecOrigen, DirDestino, FecDestino
			--		) 
			--		SELECT 
			--		@TipDoc,@Documento,@IdCia,Item, TipRes, Reserva, IdCiaRes, ItemRes, NumPasajeros, PesoNeto, VrCobro, VrPagos, Referencia1, Referencia2, Referencia3,
			--		CdTipServicio, EsRutaCliente, Kilometros, DirOrigen, FecOrigen, DirDestino, FecDestino
			--		FROM @Trn_TraEspFuecDetalle df WHERE df.TipDoc = @TipDocu and df.Fuec = @Fuec and df.IdCia = @CiaFuec
			--		end
					
			--		IF(EXISTS(SELECT * FROM @Trn_TraEspFuecAnexo))
			--		begin
			--		INSERT INTO Trn_TraEspFuecAnexo(
			--		TipDoc, Fuec, IdCia, TipContrato, IdContrato, ObjContrato, DescripCarga, Observacion, RespViaje, VehConvenio, EmpresaVehCon
			--		) 
			--		SELECT 
			--		@TipDoc,@Documento,@IdCia,TipContrato, IdContrato, ObjContrato, DescripCarga, Observacion, RespViaje, VehConvenio, EmpresaVehCon
			--		FROM @Trn_TraEspFuecAnexo df WHERE df.TipDoc = @TipDocu and df.Fuec = @Fuec and df.IdCia = @CiaFuec
			--		end

			--		IF(EXISTS(SELECT * FROM @Trn_TraEspFuecCndtores))
			--		begin
			--		INSERT INTO Trn_TraEspFuecCndtores(
			--		TipDoc, Fuec, IdCia, Item, IdConductor) 
			--		SELECT 
			--		@TipDoc,@Documento,@IdCia,Item, IdConductor
			--		FROM @Trn_TraEspFuecCndtores df WHERE df.TipDoc = @TipDocu and df.Fuec = @Fuec and df.IdCia = @CiaFuec
			--		end

			--		--ACTUALIZAR PORGRAMACIONES 
			--		UPDATE Trn_TraEspProgramaDet
			--		SET TipDocFuec = @TipDoc,NumFuec = @Documento, IdCiaFuec = @CiaFuec
			--		FROM Trn_TraEspProgramaDet
			--		--@Trn_TraEspFuecDetalle t3
			--		WHERE TipDoc = 'PGR' and Programa = @NumPgr and IdCia = @IdCiaPgr and Item = @ItemPgr;

			--		INSERT INTO #LogFuecDetalle(TipDocFuec,Fuec,IdCiaFuec,IdVehiculo,TipDocRes,Reservas,IdCiaRes,ItemRes)
			--		select @TipDocu,@Fuec,@CiaFuec,@IdVehiculo,@TipDocRes,@Reservas,@IdCiaRes,@ItemRes
			--	END
			--FETCH NEXT FROM fueccursor INTO @TipDocu,@Fuec,@CiaFuec,@IdVehiculo,@TipDocCOE,@COE,@CiaCOE,@TipDocPgr,@NumPgr,@IdCiaPgr,@ItemPgr
			--END
			--CLOSE fueccursor
			--DEALLOCATE fueccursor

			SELECT * FROM #LogFuecDetalle
			--SELECT * FROM #LogProgDetalle
			--select @NumProc

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
-- ==========================================================================================================================================================================================================================================================================
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvLiquidacion]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMsvLiquidacion]
	@Trn_TraEspLiquida [dbo].[dataTypeTrn_TraEspLiquida] READONLY,
	@Trn_TraEspLiquidaDed [dbo].[dataTypeTrn_TraEspLiquidaDed] READONLY,
	@Trn_TraEspLiquidaOdp [dbo].[dataTypeTrn_TraEspLiquidaOdp] READONLY,
	@Trn_TraEspLiquidaOtr [dbo].[dataTypeTrn_TraEspLiquidaOtr] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeNiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY
		
			CREATE TABLE #LogLiquida(
			Numero int NOT NULL,
			Fecha smalldatetime NULL,
			EstadoProc int NULL,
			Observacion varchar(1000) NULL,
			TimeSys smalldatetime NULL,
			IdUsuario varchar(11) NULL,
			Nombre varchar(50) NULL
			)

			CREATE TABLE #LogLiquidaDet(
			Numero int NULL,
			Item int NULL,
			TipDoc varchar(3) NULL,
			Liquidacion int NULL,
			IdCia char(2) NULL,
			FechaLiq smalldatetime NULL,
			FechaDed smalldatetime NULL,
			FechaIniOdp smalldatetime NULL,
			FechaFinOdp smalldatetime NULL,
			IdConcepto varchar(4) NULL,
			CXP bit NULL, 
			TipoCom varchar(3) NULL,
			Comprobante int NULL,
			IdVehiculo varchar(10) NULL,
			IdConductor varchar(16) NULL,
			IdPoseedor varchar(16) NULL,
			Causaciones varchar(MAX) NULL,
			IdCiaCaus varchar(MAX) NULL,
			ItemCaus varchar(max) null,
			Odps varchar(MAX) NULL,
			IdCiaOdps  varchar(MAX) NULL,
			OtrPagos  varchar(MAX) NULL,
			IdCiaOtrpagos varchar(MAX) NULL,
			ItemOtros varchar(max) null,
			VrTotalLiq MONEY NULL,
			Comentarios varchar(1000) NULL
			)

			declare @Causaciones varchar(max) 
			declare @IdCiaCaus varchar(max)
			declare @ItemCaus varchar(max)
			declare @Odps varchar(max)  
			declare @IdCiaOdps varchar(max)
			declare @OtrPagos varchar(max) 
			declare @IdCiaOtrpagos varchar(max)
			declare @ItemOtros varchar(max) 
			declare @TipDocu varchar(3)
			declare @Liq int
			declare @IdCia CHAR(2)	
			declare @NumProc int = 1
			declare @ItemProc int = 1

			DECLARE liqcursor CURSOR
			FOR SELECT TipDoc,Liquidacion,IdCia FROM @Trn_TraEspLiquida
			OPEN liqcursor
			FETCH NEXT FROM liqcursor INTO @TipDocu,@Liq,@IdCia
			WHILE @@FETCH_STATUS = 0
			BEGIN
			
				IF(@operacion = 'i')
				begin
				SELECT TOP 1 @TipDoc = @TipDocu, @Cia = @IdCia, @IdCiaComp = @IdCia, @IdCiaCompNiif = @IdCia, @IdCiaCompFis = @IdCia
				SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

				IF(@Numero > 0)
					UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
				ELSE
				BEGIN
					SELECT @Numero = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes where TipDoc = @TipDocu and Documento = @Liq and  IdCiaDoc = @IdCia
					SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
					--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
					IF(@Comprobante <> '')
						UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
					ELSE
					BEGIN
						SELECT @Comprobante = 1
						INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
				BEGIN
					SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF' and TipDoc = @TipDocu and Documento = @Liq and  IdCiaDoc = @IdCia
					SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif

					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
					ELSE
					BEGIN
						SELECT @CompNiif = 1
						INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
				BEGIN
					SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL' and TipDoc = @TipDocu and Documento = @Liq and  IdCiaDoc = @IdCia
					SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis

					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
					ELSE
					BEGIN
						SELECT @CompFis = 1
						INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				--DIEGO ROMERO DICE QUE SI NO EXISTE EL COMPROBANTE CON ELMISMO NOMBRE DE DOC DEVOLUCIÃ“N INSERTA UN COMPROBANTE CON EL  TIPCOM SEA IIGUAL AL TIPDEV, en la tabla TiposCom(tipos de comprobantes)
				--es INACTIVO = 1, PARA PODER INSERTAR EN EGRFACTURA ESTE TIPCOM
				IF(NOT EXISTS(SELECT IdCom FROM TiposCom where IdCom = @TipDoc))
				BEGIN
				  INSERT INTO TiposCom VALUES (@TipDoc,'LIQUIDACION DE ORDENES ESPECIAL',0,0,0,1,CURRENT_TIMESTAMP,NULL,NULL,null)
				END
				--

				end

				IF(@operacion = 'i')
				begin
					IF(EXISTS(SELECT * FROM @Trn_TraEspLiquida))
					BEGIN
					INSERT INTO Trn_TraEspLiquida(
					TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,IdVehiculo,IdPoseedor,IdConductor,VrTotal,CxPagar,TipCom,Comprobante,IdCiaCom,
					Anulado,NumDev,FecDev,Observacion,IdEstado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,
					IdUsuario,ModLiquida
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Fecha,IdConcepto,IdVehiculo,IdPoseedor,IdConductor,VrTotal,CxPagar,@TipComp,@Comprobante,@IdCiaComp,
					Anulado,NumDev,FecDev,Observacion,IdEstado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,
					IdUsuario,ModLiquida
					FROM @Trn_TraEspLiquida where TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_TraEspLiquidaDed))
					BEGIN
					INSERT INTO Trn_TraEspLiquidaDed(
					TipDoc,Liquidacion,IdCia,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,IdConcepto,Descripcion,VrAbono,NitPoseedor,pVehiculo,
					EsVence,TipOdp,OrdenPago,IdCiaOdp,TipRes,Reserva,IdCiaRes,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CdSubCos,TipoFac
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,IdConcepto,Descripcion,VrAbono,NitPoseedor,pVehiculo,
					EsVence,TipOdp,OrdenPago,IdCiaOdp,TipRes,Reserva,IdCiaRes,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CdSubCos,TipoFac
					FROM @Trn_TraEspLiquidaDed where TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_TraEspLiquidaOdp))
					BEGIN
					INSERT INTO Trn_TraEspLiquidaOdp(
					TipDoc,Liquidacion,IdCia,Item,TipOdp,OrdPago,IdCiaOdp,VrAbonado
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Item,TipOdp,OrdPago,IdCiaOdp,VrAbonado
					FROM @Trn_TraEspLiquidaOdp where TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_TraEspLiquidaOtr))
					BEGIN
					INSERT INTO Trn_TraEspLiquidaOtr(
					TipDoc,Liquidacion,IdCia,Item,TipCau,Causacion,IdCiaCau,ItemCau,Factura,ItemFac,IdProveedor,pVehiculo,VrAbono,TipFac,VrFactura
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Item,TipCau,Causacion,IdCiaCau,ItemCau,Factura,ItemFac,IdProveedor,pVehiculo,VrAbono,TipFac,VrFactura
					FROM @Trn_TraEspLiquidaOtr where TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_EgrFactura))
					BEGIN
					INSERT INTO Trn_EgrFactura(
					TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,
					ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,
					VehPropio,TipDev,NumDev,DetAbono
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Item,Fecha,TipFac,Factura,IdCiaFac,
					ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,
					VehPropio,TipDev,NumDev,DetAbono
					FROM @Trn_EgrFactura where TipCom = @TipDocu and Comprobante = @Liq and  IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
					INSERT INTO Trn_Comprobantes(
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
					NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
					TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
					Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
					PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
					CodRes, DescServicio
					)
					SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
					NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
					TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
					Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
					PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
					CodRes, DescServicio
					FROM @Trn_Comprobantes where TipDoc = @TipDocu and Documento = @Liq and  IdCiaDoc = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
					BEGIN
					INSERT INTO Trn_ComDetalle(
					TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
					IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
					IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
					CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
					)
					SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
					IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
					CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
					CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
					FROM @Trn_ComDetalle where TipDoc = @TipDocu and Documento = @Liq and  IdCiaDoc = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp))
					BEGIN
					INSERT INTO Trn_NiifComp(
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
					EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
					FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
					VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
					IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
					Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
					CtbTipo, CtbNumero,
					FisTipo, FisNumero 
					)
					SELECT 
					CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
					@Cia, 
					C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
					C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
					C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
					C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
					C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
					C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
					CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
					CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
					FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
					where C.TipDoc = @TipDocu and C.Documento = @Liq and C.IdCia = @IdCia and N.TipDoc = @TipDocu and N.Documento = @Liq and N.IdCiaDoc = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
					BEGIN
					INSERT INTO Trn_NiifDetalle(
					TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
					VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
					VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
					NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
					FechAutoriza, CodCuentaCG
					)
					SELECT 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END,
					@Cia,
					N.Item, N.Fecha, N.IdCuenta, N.Detalle,
					N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
					N.VrBase, N.TarifaBase, @TipDoc,@Numero,@Cia, N.CodConce,
					N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
					N.FechAutoriza, N.CodCuentaCG
					FROM @Trn_NiifDetalle as N
					JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante and NC.TipDoc = @TipDocu and NC.Documento = @Liq and NC.IdCiaDoc = @IdCia
					where N.TipDoc = @TipDocu and N.Documento = @Liq and N.IdCia = @IdCia
					END
				end

				IF(@operacion = 'i')
				begin

				
				  declare @TipCau varchar(3)
				  declare @Causacion int
				  declare @IdCiaCau varchar(2)	
				  declare @ItemCau int		  
				  declare @VrAbonoCau decimal(14,4)
				  -- actualizar causaciones con deducciones
				  DECLARE ccausac CURSOR
	  			  FOR SELECT TipCau, Causacion, IdCiaCau, ItemCau, VrAbono from @Trn_TraEspLiquidaDed WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia
				  OPEN ccausac
				  FETCH NEXT FROM ccausac into @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
				  WHILE @@FETCH_STATUS = 0
				  BEGIN
			  
					  UPDATE Trn_TraEspCauDetalle
					  SET TipoLiq = @TipDoc, NumLiquida = @Numero, CiaLiquida = @Cia, VrAbonado = VrAbonado + @VrAbonoCau
					  FROM Trn_TraEspCauDetalle t1
					  WHERE t1.TipDoc = @TipCau and t1.Causacion = @Causacion and t1.IdCia = @IdCiaCau and t1.Item = @ItemCau

				  FETCH NEXT FROM ccausac INTO @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
				  END
				  CLOSE ccausac
				  DEALLOCATE ccausac

				  -- actualizar causaciones con otros pagos
				  DECLARE pcausac CURSOR
	  			  FOR SELECT TipCau,Causacion,IdCiaCau,ItemCau, VrAbono from @Trn_TraEspLiquidaOtr WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia
				  OPEN pcausac
				  FETCH NEXT FROM pcausac into @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
				  WHILE @@FETCH_STATUS = 0
				  BEGIN
			  
					  UPDATE Trn_TraEspCauDetalle
					  SET TipoLiq = @TipDoc, NumLiquida = @Numero, CiaLiquida = @Cia, VrAbonado = VrAbonado + @VrAbonoCau
					  FROM Trn_TraEspCauDetalle t1
					  WHERE t1.TipDoc = @TipCau and t1.Causacion = @Causacion and t1.IdCia = @IdCiaCau and t1.Item = @ItemCau

				  FETCH NEXT FROM pcausac INTO @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
				  END
				  CLOSE pcausac
				  DEALLOCATE pcausac

				  --actualizar Trn_ComFactura
				  declare @FactTipFac varchar(3)
				  declare @FactIdCiaFac varchar(2)
				  declare @FactFactura int
				  declare @FactIdProveedor varchar(16)
				  declare @VrAbono decimal(14,4)
				  declare @ItemFac int
				  DECLARE cprincipal CURSOR
	  			  FOR SELECT TipFac, Factura, IdCiaFac,ItemFac, IdProveedor, VrAbono FROM @Trn_EgrFactura WHERE TipCom = @TipDocu and Comprobante = @Liq and  IdCia = @IdCia
				  OPEN cprincipal
				  FETCH NEXT FROM cprincipal into @FactTipFac, @FactFactura, @FactIdCiaFac,@ItemFac, @FactIdProveedor, @VrAbono
				  WHILE @@FETCH_STATUS = 0
				  BEGIN
						  IF(@VrAbono > 0)
						  BEGIN
							  UPDATE Trn_ComFactura 
							  SET VrAbonado = VrAbonado + @VrAbono
							  FROM Trn_ComFactura t1 
							  WHERE t1.TipFac = @FactTipFac and t1.Factura = @FactFactura and t1.IdCia = @FactIdCiaFac and t1.Item = @ItemFac and t1.IdProveedor = @FactIdProveedor
						  END

				  FETCH NEXT FROM cprincipal INTO @FactTipFac, @FactFactura, @FactIdCiaFac,@ItemFac, @FactIdProveedor, @VrAbono
				  END
				  CLOSE cprincipal
				  DEALLOCATE cprincipal

				  --actualizar orden pago
				  update Trn_TraEspOrdenReservas
				  set EdoLiqCausac =  1
				  from Trn_TraEspOrdenReservas t1, @Trn_TraEspLiquidaDed t2
				  where t2.TipOdp = t1.TipDoc and t2.OrdenPago = t1.OrdPago and t2.IdCiaOdp = t1.IdCia

				end

				--Causaciones para la liquidaciÃ³n seleccionada
				select @Causaciones = SUBSTRING((SELECT ',' + cast(Causacion as VARCHAR(max)) FROM @Trn_TraEspLiquidaDed WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)
				select @IdCiaCaus = SUBSTRING((SELECT ',' + cast(IdCiaCau as VARCHAR(max)) FROM @Trn_TraEspLiquidaDed WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)
				select @ItemCaus = SUBSTRING((SELECT ',' + cast(ItemCau as VARCHAR(max)) FROM @Trn_TraEspLiquidaDed WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)

				--Ordenes de pago para la liquidaciÃ³n seleccionada
				select @Odps = SUBSTRING((SELECT ',' + cast(OrdPago as VARCHAR(max)) FROM @Trn_TraEspLiquidaOdp WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)
				select @IdCiaOdps = SUBSTRING((SELECT ',' + cast(IdCiaOdp as VARCHAR(max)) FROM @Trn_TraEspLiquidaOdp WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)

				--Otros pagos para la liquidaciÃ³n seleccionada
				select @OtrPagos = SUBSTRING((SELECT ',' + cast(Causacion as VARCHAR(max)) FROM @Trn_TraEspLiquidaOtr WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)
				select @IdCiaOtrpagos = SUBSTRING((SELECT ',' + cast(IdCiaCau as VARCHAR(max)) FROM @Trn_TraEspLiquidaOtr WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)
				select @ItemOtros = SUBSTRING((SELECT ',' + cast(ItemCau as VARCHAR(max)) FROM @Trn_TraEspLiquidaOtr WHERE TipDoc = @TipDocu and Liquidacion = @Liq and  IdCia = @IdCia FOR XML PATH('')), 2 , 9999)

				IF(@NumProc = @ItemProc)
				BEGIN
					INSERT INTO #LogLiquida(
					Numero,Fecha,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre
					)
					SELECT 
					@NumProc,t1.Fecha,1,t1.Observacion,t1.TimeSys,t1.IdUsuario,u.Usuario
					FROM @Trn_TraEspLiquida as t1
					left join adm_Usuarios u on u.IdUsuario = t1.IdUsuario
					WHERE t1.TipDoc = @TipDocu and t1.Liquidacion = @Liq and t1.IdCia = @IdCia
				END 

				INSERT INTO #LogLiquidaDet(
				Numero,Item,TipDoc,Liquidacion,IdCia,FechaLiq,FechaDed,FechaIniOdp,FechaFinOdp,IdConcepto,
				CXP,TipoCom,Comprobante,IdVehiculo,IdConductor,IdPoseedor,
				Causaciones,IdCiaCaus,ItemCaus,Odps,IdCiaOdps,OtrPagos,IdCiaOtrpagos,ItemOtros,
				VrTotalLiq,Comentarios)
				SELECT 
				@NumProc,@ItemProc,@TipDoc,@Numero,@Cia,t1.Fecha,t1.FecFinCau,t1.FecIniOdp,t1.FecFinOdp,t1.IdConcepto,
				t1.CxPagar,@TipComp,@Comprobante,t1.IdVehiculo,t1.IdConductor,t1.IdPoseedor,
				@Causaciones,@IdCiaCaus,@ItemCaus,@Odps,@IdCiaOdps,@OtrPagos,@IdCiaOtrpagos,@ItemOtros,
				t1.VrTotal,'Se guarda correctamente'
				FROM (select * from @Trn_TraEspLiquida where TipDoc = @TipDocu and Liquidacion = @Liq and IdCia = @IdCia) as t1

				select @ItemProc = @ItemProc + 1

			FETCH NEXT FROM liqcursor INTO @TipDocu,@Liq,@IdCia
			END
			CLOSE liqcursor
			DEALLOCATE liqcursor

			SELECT * FROM #LogLiquida
			SELECT * FROM #LogLiquidaDet

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvOrdenPago]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMsvOrdenPago]
	@Trn_TraEspOrdenPago [dbo].[dataTypeTrn_TraEspOrdenPago] READONLY,
	@Trn_TraEspOrdenReservas [dbo].[dataTypeTrn_TraEspOrdenReservas] READONLY,
	@Trn_TraEspOrdenProg [dbo].[dataTypeTrn_TraEspOrdenProg] READONLY,
	@Trn_TraEspConceptos [dbo].[dataTypeTrn_TraEspConceptos] READONLY,
	@Trn_TraEspAntAbonos [dbo].[dataTypeTrn_TraEspAntAbonos] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_ComFactura [dbo].[dataTypeTrn_ComFactura] READONLY,
	@Trn_Pagos [dbo].[dataTypeTrn_Pagos] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeNiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY
			
			 CREATE TABLE #LogOrden(
			 Numero int NOT NULL,
			 Fecha smalldatetime NOT NULL,
			 EstadoProc int NOT NULL,
			 Observacion varchar(1000) NULL,
			 TimeSys smalldatetime NOT NULL,
			 IdUsuario varchar(11) NOT NULL,
			 Nombre varchar(50) NOT NULL
			 )

			 CREATE TABLE #LogOrdenDet(
			 Numero int NOT NULL,
			 Item int NOT NULL,
			 TipDoc varchar(3) NOT NULL,
			 Orden int NOT NULL,
			 IdCia char(2) NOT NULL,
			 Fecha smalldatetime NOT NULL,
			 IdConcepto varchar(4) NOT NULL,
			 TipoCom varchar(3) NULL,
			 Comprobante int NOT NULL,
			 TipRes varchar(3) NOT NULL,
			 Reserva int NOT NULL,
			 IdCiaRes char(2) NOT NULL,
			 ItemRes int NOT NULL,
			 IdOrigen varchar(8) NOT NULL,
			 CiuOrigen varchar(50) NULL,
			 IdDestino varchar(8) NOT NULL,
			 CiuDestino varchar(50) NULL,
			 IdRuta varchar(4) NOT NULL,
			 Ruta varchar(100) NULL,
			 IdVehiculo varchar(10) NOT NULL,
			 IdConductor varchar(16) NOT NULL,
			 IdPropietario varchar(16) NOT NULL,
			 IdPoseedor varchar(16) NOT NULL,
			 Cumplido int NOT NULL,
			 IdCiaCum varchar(2) NOT NULL,
			 EstadoReg int NOT NULL,
			 VrServicio money NOT NULL,
			 VrDescuento money NOT NULL,
			 VrRetencion money NOT NULL,
			 VrReteIca money NOT NULL,
			 VrReteCREE money NOT NULL,
			 VrAnticipos money NOT NULL,
			 VrOtrosDctos money NOT NULL,
			 VrImpuestos money NOT NULL,
			 VrOtrosPagos money NOT NULL,
			 VrNeto money NOT NULL,
			 TarifaRet decimal(14, 4) NOT NULL,
			 TarifaIca decimal(14, 4) NOT NULL,
			 TarifaRtc decimal(14, 4) NOT NULL,
			 CodTarRet varchar(4) NULL,
			 CodTarIca varchar(4) NULL,
			 CodTarRtc varchar(4) NULL,
			 VrConcPagos money NOT NULL,
			 VrConcDctos money NOT NULL,
			 VrConcFondo money NOT NULL,
			 VrConcSeguro money NOT NULL,
			 VrConcAporte money NOT NULL,
			 VrConcImpuesto money NOT NULL,
			 VrRecCaja money NOT NULL,
			 CdForma varchar(4) NULL,
			 IdCCosto varchar(16) NULL,
			 IdSubCos varchar(16) NULL,
			 VrSeguros money NOT NULL,
			 VrFondos money NOT NULL,
			 VrAportes money NOT NULL,
			 Comentarios varchar(1000) NULL		 
			 )

			declare @TipDocu varchar(3)
			declare @Orden int
			declare @IdCia CHAR(2)		
			DECLARE @Reserva INT --Esta variable guarda el nÃºmero de reserva
			DECLARE @IdCiaRes CHAR(2)  --Esta variable guarda la compaÃ±ia de la reserva
			DECLARE @ItemRes INT --Esta variable guarda el nÃºmero de Ã­tem de reserva
			DECLARE @VrPagos MONEY = 0 --En esta variable va guarda el valor de pago real de la reserva
			DECLARE @VrTotalPagosaRES MONEY = 0 --En esta variable va guarda el valor de pagos hechas a la reserva por ordenes de pago
			DECLARE @TipoTarifa varchar(20)
			declare @NumProc int = 1
			declare @ItemProc int = 1

			DECLARE ordencursor CURSOR
			FOR SELECT TipDoc,OrdPago,IdCia FROM @Trn_TraEspOrdenPago
			OPEN ordencursor
			FETCH NEXT FROM ordencursor INTO @TipDocu,@Orden,@IdCia
			WHILE @@FETCH_STATUS = 0
			BEGIN
				
					IF(@operacion = 'i')
					begin					
						SELECT @TipDoc = @TipDocu, @Cia = @IdCia, @IdCiaComp = @IdCia, @IdCiaCompNiif = @IdCia, @IdCiaCompFis = @IdCia
						SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

						IF(@Numero > 0)
							UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
						ELSE
						BEGIN
							SELECT @Numero = 1
							INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
						END

						IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
						BEGIN
							SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes where TipDoc = @TipDocu and Documento = @Orden and  IdCiaDoc = @IdCia
							SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
							--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
							IF(@Comprobante <> '')
								UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
							ELSE
							BEGIN
								SELECT @Comprobante = 1
								INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
							END
						END

						IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
						BEGIN
							SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF' and TipDoc = @TipDocu and Documento = @Orden and  IdCiaDoc = @IdCia
							SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
							--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
							IF(@CompNiif <> '')
								UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
							ELSE
							BEGIN
								SELECT @CompNiif = 1
								INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
							END
						END

						IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
						BEGIN
							SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL' and TipDoc = @TipDocu and Documento = @Orden and  IdCiaDoc = @IdCia
							SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
							--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
							IF(@CompNiif <> '')
								UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
							ELSE
							BEGIN
								SELECT @CompFis = 1
								INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
							END
						END
					end

					IF(@operacion = 'i')
					begin					
						IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenPago))
						BEGIN
						INSERT INTO Trn_TraEspOrdenPago(
						TipDoc,OrdPago,IdCia,Fecha,TipRes,Reserva,IdCiaRes,IdConcepto,Cantidad,Modalidad,LiqReservas,CxPagar,MulPlazos,IdPlazo,FechaVence,
						TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Fecha,TipRes,Reserva,IdCiaRes,IdConcepto,Cantidad,Modalidad,LiqReservas,CxPagar,MulPlazos,IdPlazo,FechaVence,
						@TipComp,@Comprobante,@IdCiaComp,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
						FROM @Trn_TraEspOrdenPago where TipDoc = @TipDocu and OrdPago = @Orden and IdCia = @IdCia
						END 

						IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenReservas))
						BEGIN
						INSERT INTO Trn_TraEspOrdenReservas(
						TipDoc,OrdPago,IdCia,Item,Fecha,TipRes,Reserva,IdCiaRes,ItemRes,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,VrServicio,VrDescuento,VrRetencion,
						VrReteIca,VrReteCREE,VrAnticipos,VrOtrosDctos,VrImpuestos,VrOtrosPagos,VrNeto,BaseRet,BaseIca,BaseCree,TarifaRet,TarifaIca,TarifaRtc,CodTarRet,
						CodTarIca,CodTarRtc,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,Referencia,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,
						VrRecCaja,CdForma,CdCenCosto,CdSubCenCos,VrSeguros,VrFondos,VrAportes,EdoLiqCausac,EstadoItem
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,Fecha,TipRes,Reserva,IdCiaRes,ItemRes,IdVehiculo,IdConductor,IdPropietario,IdPoseedor,VrServicio,VrDescuento,VrRetencion,
						VrReteIca,VrReteCREE,VrAnticipos,VrOtrosDctos,VrImpuestos,VrOtrosPagos,VrNeto,BaseRet,BaseIca,BaseCree,TarifaRet,TarifaIca,TarifaRtc,CodTarRet,
						CodTarIca,CodTarRtc,TipEgr,Egreso,IdCiaEgr,FechaEgr,NumCheque,Referencia,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,
						VrRecCaja,CdForma,CdCenCosto,CdSubCenCos,VrSeguros,VrFondos,VrAportes,EdoLiqCausac,EstadoItem
						FROM @Trn_TraEspOrdenReservas where TipDoc = @TipDocu and OrdPago = @Orden and IdCia = @IdCia
						END 

						IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenProg))
						BEGIN
						INSERT INTO Trn_TraEspOrdenProg(
						TipDoc,OrdPago,IdCia,Item,TipRes,Reserva,IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr,VrRecorrido
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,TipRes,Reserva,IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr,VrRecorrido
						FROM @Trn_TraEspOrdenProg where TipDoc = @TipDocu and OrdPago = @Orden and IdCia = @IdCia
						END 

						IF(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
						BEGIN
						INSERT INTO Trn_TraEspConceptos(
						TipDoc,Documento,IdCia,Item,Descripcion,Tarifa,TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva,IdConcepto,CdCuenta,NitTercero,
						CdTipoEsc,FechaNov,VrBase,TipoTarif,RefConc,Fijos,IncBaseRet,Referencia2,Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,Descripcion,Tarifa,TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva,IdConcepto,CdCuenta,NitTercero,
						CdTipoEsc,FechaNov,VrBase,TipoTarif,RefConc,Fijos,IncBaseRet,Referencia2,Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
						FROM @Trn_TraEspConceptos where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_TraEspAntAbonos))
						BEGIN
						INSERT INTO Trn_TraEspAntAbonos(
						TipDoc,Documento,IdCia,Item,Fecha,TipAnt,Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,Fecha,TipAnt,Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
						FROM @Trn_TraEspAntAbonos where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
						BEGIN
						INSERT INTO Trn_DetCuentas(
						TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
						VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
						VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
						FROM @Trn_DetCuentas where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_ComFactura))
						BEGIN
						INSERT INTO Trn_ComFactura(
						TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,
						Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,IdProveedor,IdCuenta,@TipDoc,@Numero,@Cia,FecEmision,FecVence,VrFactura,VrAbonado,@TipComp,@Comprobante,ItemCom,
						Referencia,Detalle,pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,MontoAprob
						FROM @Trn_ComFactura  where TipDoc = @TipDocu and Documento = @Orden and IdCiaDoc = @IdCia
						END 

						IF(EXISTS(SELECT * FROM @Trn_Pagos))
						BEGIN
						INSERT INTO Trn_Pagos(
						TipDoc, Documento, IdCia, Item, Fecha, IdForma, Detalle, VrPagado,
						VrCambio, EsCaja, IdBanco, NitCliente, CdAgencia, NumForma, FecForma, 
						CtaForma, Beneficiario, Referncia1, Referncia2, CdLocal, NumAutoriza, 
						VrDenom, Cantidad, TipDenom, TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
						CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, 
						ConsCP, CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
						)
						SELECT 
						@TipDoc, @Numero, @Cia, Item, Fecha, IdForma, Detalle, VrPagado,
						VrCambio, EsCaja, IdBanco, NitCliente, CdAgencia, NumForma, FecForma, 
						CtaForma, Beneficiario, Referncia1, Referncia2, CdLocal, NumAutoriza, 
						VrDenom, Cantidad, TipDenom, TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
						CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, 
						ConsCP, CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
						FROM @Trn_Pagos where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
						BEGIN
						INSERT INTO Trn_Comprobantes(
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
						NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
						TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
						PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
						CodRes, DescServicio
						)
						SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
						NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
						TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
						PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
						CodRes, DescServicio
						FROM @Trn_Comprobantes where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
						BEGIN
						INSERT INTO Trn_ComDetalle(
						TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
						IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,IdCiaDoc,
						CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
						NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
						CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
						IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
						)
						SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
						IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
						CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
						NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
						CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
						IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
						FROM @Trn_ComDetalle where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_NiifComp))
						BEGIN
						INSERT INTO Trn_NiifComp(
						TipCom, 
						Comprobante, 
						IdCia,Fecha, IdTercero, VrTotal, IdCta,
						EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
						FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
						VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
						IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
						Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
						CtbTipo, CtbNumero,
						FisTipo, FisNumero 
						)
						SELECT 
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
						@Cia,C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
						C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
						C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
						C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
						C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
						C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
						CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
						FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont 
						where C.TipDoc = @TipDocu and C.Documento = @Orden and C.IdCia = @IdCia
							  and N.TipDoc = @TipDocu and N.Documento = @Orden and N.IdCiaDoc = @IdCia
						END

						IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
						BEGIN
						INSERT INTO Trn_NiifDetalle(
						TipCom, 
						Comprobante, 
						IdCia,Item, Fecha, IdCuenta, Detalle,
						VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
						VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
						NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
						NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
						CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
						DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
						CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
						FechAutoriza, CodCuentaCG
						)
						SELECT 
						CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
						CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
						@Cia,N.Item, N.Fecha, N.IdCuenta, N.Detalle,
						N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
						N.VrBase, N.TarifaBase, @TipDoc, @Numero, @Cia, N.CodConce,
						N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
						N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
						N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
						N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
						N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
						N.FechAutoriza, N.CodCuentaCG
						FROM @Trn_NiifDetalle as N 
						JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante and NC.TipDoc = @TipDocu and NC.Documento = @Orden and NC.IdCiaDoc = @IdCia
						where N.TipDoc = @TipDocu and N.Documento = @Orden and N.IdCia = @IdCia
						END
					end	

					IF(@operacion = 'i')
					begin					
						--actualiza los items de la programnaciÃ³n detalle de cada reserva agregada en la Orden de Pago
						UPDATE Trn_TraEspProgramaDet
						SET TipDocOdp = 'OPE',NumOdp = @Numero, IdCiaOdp = @Cia, FechaOdp = t3.Fecha
						FROM Trn_TraEspProgramaDet t1 
						,(Select TipRes,Reserva,IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr from Trn_TraEspOrdenProg where TipDoc = 'OPE' and OrdPago = @Numero and IdCia = @Cia) as t2
						,(Select Fecha from Trn_TraEspOrdenPago where TipDoc = 'OPE' and OrdPago = @Numero and IdCia = @Cia) as t3					 
						WHERE t1.TipDocRes = t2.TipRes and t1.Reserva = t2.Reserva and t1.IdCiaRes = t2.IdCiaRes and t1.ItemRes = t2.ItemRes and t1.TipDoc = t2.TipPgr and t1.Programa = t2.Programa and t1.IdCia = t2.IdCiaPgr and t1.Item = t2.ItemPgr 

						--actualizaciÃ³n de la resdetalle
						Select @Reserva = Reserva, @IdCiaRes = IdCiaRes, @ItemRes = ItemRes from @Trn_TraEspOrdenReservas where TipDoc = @TipDocu and OrdPago = @Orden and IdCia = @IdCia
										
						SELECT @TipoTarifa = TipoTarifa FROM Trn_TraEspResDetalle WHERE Reserva = @Reserva AND IdCia = @IdCiaRes AND Item = @ItemRes

						SELECT @VrTotalPagosaRES = ISNULL(SUM(R.VrServicio),0) 
						FROM Trn_TraEspOrdenReservas R
						LEFT JOIN Trn_TraEspOrdenPago AS OP ON R.TipDoc = OP.TipDoc AND  R.OrdPago = OP.OrdPago AND  R.IdCia = OP.IdCia
						WHERE R.Reserva = @Reserva AND R.IdCiaRes = @IdCiaRes AND R.ItemRes = @ItemRes AND OP.Anulado = 0
						
						IF(upper(@TipoTarifa) <> 'DIA')
						BEGIN
							SELECT @VrPagos = VrPagos FROM Trn_TraEspResDetalle WHERE Reserva = @Reserva AND IdCia = @IdCiaRes AND Item = @ItemRes

							IF(@VrTotalPagosaRES >= @VrPagos)
							BEGIN
								UPDATE Trn_TraEspResDetalle
								SET EstadoItem ='LIQUIDADA'
								WHERE Reserva = @Reserva AND IdCia = @IdCiaRes AND Item = @ItemRes
							END
							ELSE -- revisar que la cant de veh se vayan a liquidar(programados no novedad) ya hayan sido liquidados(pasan de xliquidar a liquidado) y que la reserva no se haya vencido
							BEGIN
							  declare @cantveh int= 0, @cantord int = 0, @fechares date, @fechasys date,@idveh varchar(10)

							  select @cantveh = count(*) from trn_traespprogramadet where Reserva = @Reserva AND IdCiaRes = @IdCiaRes AND ItemRes = @ItemRes and IdNovedad = '0' and IdVehiculo <>'0'
							  select @fechares = fechafin from trn_traespreservas where Reserva = @Reserva AND IdCia = @IdCiaRes
							  select @fechasys = FechaActual from companias where IdCia = @IdCiaRes

							  --selecciono  los progdetalle de esos vehiculos
							  declare @Trn_TraEspProgramaDet dataTypeTrn_TraEspProgramaDet 
							  INSERT INTO @Trn_TraEspProgramaDet(
							  TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
							  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
							  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
							  CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion
							  ) 
							  SELECT 
							  TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
							  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
							  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
							  CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion
							  FROM Trn_TraEspProgramaDet  where Reserva = @Reserva AND IdCiaRes = @IdCiaRes AND ItemRes = @ItemRes and IdNovedad = '0' and IdVehiculo <>'0'
					  
							  --cursor para verififcar si los vehiculos fueron pagados en ordenes de pago					   
							  DECLARE verificar CURSOR
							  FOR SELECT IdVehiculo  FROM @Trn_TraEspProgramaDet
							  OPEN verificar
							  FETCH NEXT FROM verificar INTO @idveh
							  WHILE @@FETCH_STATUS = 0
							  BEGIN

							  --verifico la cantidad que ya fueron liquidados(tine encuenta la actual)
							   if (exists(select * from Trn_TraEspOrdenReservas where Reserva = @Reserva AND IdCiaRes = @IdCiaRes AND ItemRes = @ItemRes and IdVehiculo = @idveh))
								select @cantord = @cantord + 1

								FETCH NEXT FROM verificar INTO @idveh 
							  END
							  CLOSE verificar
							  DEALLOCATE verificar

							  --se verifica que cumpal para colocar la resrva a liquidada
							  IF((@cantord >= @cantveh) AND (@fechasys  >= @fechares))
							  BEGIN 
								UPDATE Trn_TraEspResDetalle
								SET EstadoItem ='LIQUIDADA'
								WHERE Reserva = @Reserva AND IdCia = @IdCiaRes AND Item = @ItemRes
							  END

							END

						END
						ELSE
						BEGIN 
							SELECT @VrPagos = ISNULL(SUM(VrPagos),0)  FROM Trn_TraEspProgramaDet WHERE Reserva = @Reserva AND IdCiaRes = @IdCiaRes AND ItemRes = @ItemRes and IdNovedad = '0' and IdVehiculo <>'0'

							IF(@VrTotalPagosaRES >= @VrPagos)
							BEGIN
								UPDATE Trn_TraEspResDetalle
								SET EstadoItem ='LIQUIDADA'
								WHERE Reserva = @Reserva AND IdCia = @IdCiaRes AND Item = @ItemRes
							END
						END

						--actualiza los anticipos
						UPDATE Trn_TraEspAnticipos
						SET VrAbonado = t2.VrAbono + VrAbonado
						FROM Trn_TraEspAnticipos t1
						,(Select TipAnt,Anticipo,IdCiaAnt,VrAbono from @Trn_TraEspAntAbonos where TipDoc = @TipDocu and Documento = @Orden and IdCia = @IdCia) as t2
						WHERE t1.TipDoc = t2.TipAnt and t1.Anticipo = t2.Anticipo and t1.IdCia = t2.IdCiaAnt 
						  
					end

					IF(@NumProc = @ItemProc)
					BEGIN
						INSERT INTO #LogOrden(
						Numero,Fecha,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre
						)
						SELECT 
						@NumProc,t1.Fecha,1,t1.Observacion,t1.TimeSys,t1.IdUsuario,u.Usuario
						FROM @Trn_TraEspOrdenPago as t1
						left join adm_Usuarios u on u.IdUsuario = t1.IdUsuario
						WHERE t1.TipDoc = @TipDocu and t1.OrdPago = @Orden and t1.IdCia = @IdCia
					END

					INSERT INTO #LogOrdenDet(
					Numero,Item,TipDoc,Orden,IdCia,Fecha,IdConcepto,TipoCom,Comprobante,TipRes,Reserva,IdCiaRes,
					ItemRes,IdOrigen,CiuOrigen,IdDestino,CiuDestino,IdRuta,Ruta,IdVehiculo,IdConductor,IdPropietario,
					IdPoseedor,Cumplido,IdCiaCum,EstadoReg,VrServicio,VrDescuento,VrRetencion,VrReteIca,VrReteCREE,VrAnticipos,VrOtrosDctos,VrImpuestos,
					VrOtrosPagos,VrNeto,TarifaRet,TarifaIca,TarifaRtc,CodTarRet,CodTarIca,CodTarRtc,VrConcPagos,VrConcDctos,
					VrConcFondo,VrConcSeguro,VrConcAporte,VrConcImpuesto,VrRecCaja,CdForma,IdCCosto,IdSubCos,VrSeguros,VrFondos,
					VrAportes,Comentarios
					)
					SELECT 
					@NumProc,@ItemProc,@TipDoc,@Numero,@Cia,t1.Fecha,t1.IdConcepto,@TipComp,@Comprobante,t2.TipRes,t2.Reserva,t2.IdCiaRes,
					t2.ItemRes,t3.CdCiuOrigen,t3.CiuOrigen,t3.CdCiuDestino,t3.CiuDestino,t3.IdRuta,t3.Ruta,t2.IdVehiculo,t2.IdConductor,t2.IdPropietario,
					t2.IdPoseedor,t3.Cumplido,t3.IdCiaCum,1,t2.VrServicio,t2.VrDescuento,t2.VrRetencion,t2.VrReteIca,t2.VrReteCREE,t2.VrAnticipos,t2.VrOtrosDctos,t2.VrImpuestos,
					t2.VrOtrosPagos,t2.VrNeto,t2.TarifaRet,t2.TarifaIca,t2.TarifaRtc,t2.CodTarRet,t2.CodTarIca,t2.CodTarRtc,t2.VrConcPagos,t2.VrConcDctos,
					t2.VrConcFondo,t2.VrConcSeguro,t2.VrConcAporte,t2.VrConcImpuesto,t2.VrRecCaja,t2.CdForma,t2.CdCenCosto,t2.CdSubCenCos,t2.VrSeguros,t2.VrFondos,
					t2.VrAportes,'Se guarda correctamente'
					FROM (SELECT * FROM @Trn_TraEspOrdenPago WHERE TipDoc = @TipDocu and OrdPago = @Orden and IdCia = @IdCia) AS t1,
					(SELECT * FROM @Trn_TraEspOrdenReservas WHERE TipDoc = @TipDocu and OrdPago = @Orden and IdCia = @IdCia) AS t2,
					(SELECT r.IdRuta,rt.Ruta,r.CdCiuOrigen,lo.Localidad AS CiuOrigen,r.CdCiuDestino, ld.Localidad AS CiuDestino,r.Cumplido,r.IdCiaCum 
					 FROM @Trn_TraEspOrdenReservas AS ord 
					 join Trn_TraEspResDetalle r ON r.TipDoc = ord.TipRes and r.Reserva = ord.Reserva and r.IdCia = ord.IdCiaRes and r.Item = ord.ItemRes
					 left join Rutas rt ON rt.IdRuta = r.IdRuta 
					 left join Localidades lo ON lo.IdLocal = r.CdCiuOrigen 
					 left join Localidades ld ON ld.IdLocal = r.CdCiuDestino
					 WHERE ord.TipDoc = @TipDocu and ord.OrdPago = @Orden and ord.IdCia = @IdCia) AS t3

					SELECT @ItemProc = @ItemProc + 1
				
			FETCH NEXT FROM ordencursor INTO @TipDocu,@Orden,@IdCia
			END
			CLOSE ordencursor
			DEALLOCATE ordencursor

			SELECT * FROM #LogOrden
			SELECT * FROM #LogOrdenDet

		COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = Convert(varchar(10),ERROR_LINE()) +' '+ ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvPrograma]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMsvPrograma]
	@Trn_TraEspPrograma [dbo].[dataTypeTrn_TraEspPrograma] READONLY,
	@Trn_TraEspProgramaDet [dbo].[dataTypeTrn_TraEspProgramaDet] READONLY,
	@Trn_TraEspProgramaPers [dbo].[dataTypeTrn_TraEspProgramaPers] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Reserva/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Reserva/CotizaciÃ³n
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Reserva/CotizaciÃ³n
declare @IdEstado varchar(4)
declare @item int
	BEGIN TRAN
		BEGIN TRY
		
			CREATE TABLE #LogPrograma(
			Numero int NOT NULL,
			Fecha smalldatetime NOT NULL,
			EstadoProc int NOT NULL,
			Observacion varchar(250) NULL,
			TimeSys smalldatetime NOT NULL,
			IdUsuario varchar(11) NOT NULL,
			Nombre varchar(50) NOT NULL
			)

			--CREATE TABLE #LogProgDetalle(
			--Numero int NOT NULL,
			--Item int NOT NULL,
			--TipDoc varchar(3) NOT NULL,
			--Programa int NOT NULL,
			--IdCia char(2) NOT NULL,
			--FechaIni smalldatetime NOT NULL,
			--FechaFin smalldatetime NOT NULL,
			--IdVehiculo varchar(10) NOT NULL,
			--Reservas int NOT NULL,
			--IdCiaRes char(2) NOT NULL,
			--ItemRes int NOT NULL,
			--Comentarios varchar(max) NULL
			--)
			
			--declare @IdVehiculo varchar(max)
			--declare @Reservas varchar(max)
			--declare @IdCiaRes varchar(max)
			--declare @ItemRes varchar(max)

			declare @NumProc int = 1
			declare @ItemProc int = 1
			declare @TipDocu varchar(3)
			declare @Programa INT
			declare @CiaProg varchar(2)
			declare @FechaInicio datetime
			declare @FechaFin datetime
			declare @observ varchar(250)

			--esta variable para cuando se haga actualizaciÃ³n de programaciÃ³n masiva
			declare @itempgr int = 0
			--

			DECLARE progcursor CURSOR
			FOR SELECT TipDoc,Programa,IdCia FROM @Trn_TraEspPrograma
			OPEN progcursor
			FETCH NEXT FROM progcursor INTO @TipDocu,@Programa,@CiaProg
			WHILE @@FETCH_STATUS = 0
			BEGIN

				--Seleccionar Variables
				IF(@operacion = 'i')
				BEGIN
					SELECT TOP 1 @TipDoc = @TipDocu, @IdCia = @CiaProg
					SELECT @Documento = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

					IF(@Documento <> '')
						UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
					ELSE
					BEGIN
						SELECT @Documento = 1
						INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
					END
				END
				ELSE IF(@operacion = 'u')
				BEGIN
					SELECT TOP 1 @TipDoc = @TipDocu, @IdCia = @CiaProg, @Documento = @Programa
				END

				--INSERT NO-EXISTE RECORDS
				IF(@operacion = 'i' or @operacion = 'u')
				BEGIN
					
					IF(@operacion = 'i')
					BEGIN
						IF(EXISTS(SELECT * FROM @Trn_TraEspPrograma))
						begin
						INSERT INTO Trn_TraEspPrograma(
						TipDoc,Programa,IdCia,Fecha,OrigenAdd,Anulado,FecDev,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
						)
						SELECT 
						@TipDoc,@Documento,@IdCia,Fecha,OrigenAdd,Anulado,FecDev,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
						FROM @Trn_TraEspPrograma p WHERE p.TipDoc = @TipDocu and p.Programa = @Programa and p.IdCia = @CiaProg
						end
					END

					IF(@operacion = 'i')
					BEGIN
						IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
						begin
						INSERT INTO Trn_TraEspProgramaDet(
						TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
						IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
						IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
						CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
						) 
						SELECT 
						@TipDoc,@Documento,@IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
						IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
						IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
						CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,'',VLargo
						FROM @Trn_TraEspProgramaDet dp WHERE dp.TipDoc = @TipDocu and dp.Programa = @Programa and dp.IdCia = @CiaProg
						end
					END
					ELSE IF(@operacion = 'u')
					BEGIN
						select @itempgr =  isnull(MAX(Item),0) from Trn_TraEspProgramaDet where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia

						IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
						begin
						INSERT INTO Trn_TraEspProgramaDet(
						TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
						IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
						IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
						CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
						) 
						SELECT 
						@TipDoc, @Documento, @IdCia,(@itempgr + ROW_NUMBER() OVER(ORDER BY Item ASC)),FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
						IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
						IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
						CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,'',VLargo
						FROM @Trn_TraEspProgramaDet dp WHERE dp.TipDoc = @TipDocu and dp.Programa = @Programa and dp.IdCia = @CiaProg
						end
					END

					IF(@operacion = 'i')
					BEGIN
						IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaPers))
						begin
						INSERT INTO Trn_TraEspProgramaPers(
						TipDoc,Programa,IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
						) 
						SELECT 
						@TipDoc,@Documento,@IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
						FROM @Trn_TraEspProgramaPers pp WHERE pp.TipDoc = @TipDocu and pp.Programa = @Programa and pp.IdCia = @CiaProg
						end
					END
					ELSE IF(@operacion = 'u')
					BEGIN						
						IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaPers))
						begin
						INSERT INTO Trn_TraEspProgramaPers(
						TipDoc,Programa,IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
						) 
						SELECT 
						@TipDoc,@Documento,@IdCia,(@itempgr + Item),IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
						FROM @Trn_TraEspProgramaPers pp WHERE pp.TipDoc = @TipDocu and pp.Programa = @Programa and pp.IdCia = @CiaProg
						end
					END

					--ACTUALIZAR RESERVAS 
					declare @actReserva int
					declare @actCiaRes varchar(2)
					declare @actItem int

					DECLARE actres CURSOR
					FOR SELECT Reserva,IdCiaRes,ItemRes FROM @Trn_TraEspProgramaDet WHERE TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg
					OPEN actres
					FETCH NEXT FROM actres INTO @actReserva,@actCiaRes,@actItem
					WHILE @@FETCH_STATUS = 0
					BEGIN
						UPDATE Trn_TraEspResDetalle
						SET EstadoItem = 'PROGRAMADA'
						FROM Trn_TraEspResDetalle r
						WHERE  r.TipDoc = 'RES' and r.Reserva = @actReserva and r.IdCia = @actCiaRes and r.Item = @actItem
					FETCH NEXT FROM actres INTO @actReserva,@actCiaRes,@actItem
					END
					CLOSE actres
					DEALLOCATE actres

					----ACTUALIZAR VEHICULOS 
					declare @actTipDoc varchar(3)
					declare @actPrograma int
					declare @actCiaProg varchar(2)
					declare @actIdVeh varchar(10)

					DECLARE actveh CURSOR
					FOR SELECT IdVehiculo FROM @Trn_TraEspProgramaDet WHERE TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg and IdVehiculo != '0' 
					OPEN actveh
					FETCH NEXT FROM actveh INTO @actIdVeh
					WHILE @@FETCH_STATUS = 0
					BEGIN
						UPDATE Vehiculos
						SET IdEstado = '0002'
						FROM Vehiculos v
						WHERE v.IdVehiculo = @actIdVeh
					FETCH NEXT FROM actveh INTO @actIdVeh
					END
					CLOSE actveh
					DEALLOCATE actveh

				 END
				
				IF(@NumProc = @ItemProc)
				BEGIN
					select top 1 @observ = Observacion FROM @Trn_TraEspProgramaDet  WHERE TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg 
					INSERT INTO #LogPrograma(
					Numero,Fecha,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre
					)
					SELECT 
					@NumProc,t1.Fecha,1,@observ,t1.TimeSys,t1.IdUsuario,u.Usuario
					FROM @Trn_TraEspPrograma as t1
					left join adm_Usuarios u on u.IdUsuario = t1.IdUsuario
					WHERE t1.TipDoc = @TipDocu and t1.Programa = @Programa and t1.IdCia = @CiaProg
				END
				
				--Se cambia el 28/12/2017 por orden del dueÃ±o.
				--select @IdVehiculo = SUBSTRING((SELECT ',' + cast(IdVehiculo as VARCHAR(max)) FROM @Trn_TraEspProgramaDet where TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg FOR XML PATH('')), 2 , 9999)
				--select @Reservas = SUBSTRING((SELECT ',' + cast(Reserva as VARCHAR(max)) FROM @Trn_TraEspProgramaDet where TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg FOR XML PATH('')), 2 , 9999)
				--select @ItemRes = SUBSTRING((SELECT ',' + cast(ItemRes as VARCHAR(max)) FROM @Trn_TraEspProgramaDet where TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg FOR XML PATH('')), 2 , 9999)
				--select @IdCiaRes = SUBSTRING((SELECT ',' + cast(IdCiaRes as VARCHAR(max)) FROM @Trn_TraEspProgramaDet where TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg FOR XML PATH('')), 2 , 9999)
				--select @FechaInicio = min(FechaInicio), @FechaFin = max(FechaFin)  from @Trn_TraEspProgramaDet where TipDoc = @TipDocu and Programa = @Programa and IdCia = @CiaProg
				
				--select @cantidad = count(*) from #LogProgDetalle
				--INSERT INTO #LogProgDetalle(
				--Numero,Item,TipDoc,Programa,IdCia,FechaIni,FechaFin,IdVehiculo,Reservas,IdCiaRes,ItemRes,Comentarios
				--)
				--SELECT 
				--@NumProc,(@ItemProc + dp.Item),@TipDoc,@Documento,@IdCia,dp.FechaInicio,dp.FechaFin,dp.IdVehiculo,dp.Reserva,dp.IdCiaRes,dp.ItemRes,dp.Observacion
				--FROM @Trn_TraEspProgramaDet dp WHERE dp.TipDoc = @TipDocu and dp.Programa = @Programa and dp.IdCia = @CiaProg

				SELECT @ItemProc = @ItemProc + 1

			FETCH NEXT FROM progcursor INTO @TipDocu,@Programa,@CiaProg
			END
			CLOSE progcursor
			DEALLOCATE progcursor

			SELECT * FROM #LogPrograma
			--SELECT * FROM #LogProgDetalle

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvTrn_DevFcr]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMsvTrn_DevFcr]
	@Trn_DevFcr [dbo].[dataTypeTrn_DevFcr] READONLY,
	@Trn_TraEspFacReservas [dbo].[dataTypeTrn_TraEspFacReservas] READONLY,
	@Trn_RecAfavor [dbo].[dataTypeTrn_RecAfavor] READONLY,
	@Trn_VencAbonos [dbo].[dataTypeTrn_VencAbonos] READONLY,
	@Trn_DocMemo [dbo].[dataTypeTrn_DocMemo] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeNiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY		 
			
			CREATE TABLE #LogTraEspFacturas(
			Numero int NOT NULL DEFAULT ((0)),
			Fecha smalldatetime NOT NULL,
			EstadoProc int NOT NULL DEFAULT ((0)),
			Observacion varchar(250) NULL,
			TimeSys smalldatetime NOT NULL,
			IdUsuario varchar(11) NOT NULL,
			Nombre varchar(50) NOT NULL,
			Tipo varchar(10) NOT NULL
			)	
			
			CREATE TABLE #LogTraEspFacReservas(
			Numero int NOT NULL,
			Item int NOT NULL,
			TipFac varchar(3) NOT NULL,
			Factura int NOT NULL,
			IdCia char(2) NOT NULL,
			TipoReg int NOT NULL DEFAULT ((0)),
			FechaFact smalldatetime NOT NULL,
			TipRes varchar(3) NOT NULL DEFAULT ('RES'),
			Reserva int NOT NULL DEFAULT ((0)),
			IdCiaRes char(2) NOT NULL DEFAULT ('01'),
			ItemRes int NOT NULL DEFAULT ((0)),
			FecReserva smalldatetime NOT NULL,
			Descripcion varchar(250) NOT NULL,
			Cantidad decimal(14, 4) NOT NULL DEFAULT ((0)),
			VrServicio money NOT NULL DEFAULT ((0)),
			VrUnitario money NOT NULL DEFAULT ((0)),
			VrCosto money NOT NULL DEFAULT ((0)),
			TarifaIva decimal(14, 4) NOT NULL DEFAULT ((0)),
			VrImpuesto money NOT NULL DEFAULT ((0)),
			TarifaDct decimal(14, 4) NOT NULL DEFAULT ((0)),
			VrDescuento money NOT NULL DEFAULT ((0)),
			DocCliente varchar(30) NOT NULL,
			Referencia1 varchar(50) NULL,
			Referencia2 varchar(50) NULL,
			Referencia3 varchar(50) NULL,
			CdConcepto varchar(4) NOT NULL,
			CdCCosto varchar(16) NULL,
			CdSubCos varchar(16) NULL,
			NitTercero varchar(16) NOT NULL DEFAULT ('0'),
			CdAgencia varchar(16) NOT NULL DEFAULT ('0'),
			pVehiculo varchar(10) NOT NULL DEFAULT ('0'),
			TipoAfiVehic varchar(10) NOT NULL DEFAULT ('TERCEROS'),
			IdOrigen varchar(8) NOT NULL,
			IdDestino varchar(8) NOT NULL,
			Anulado int NOT NULL DEFAULT ((0)),
			TipDocRef varchar(3) NULL,
			NumDocRef int NOT NULL DEFAULT ((0)),
			IdCiaRef char(2) NULL DEFAULT ('01'),
			FecDocRef smalldatetime NULL,
			CodTarDct varchar(4) NULL,
			CodTarRet varchar(4) NULL,
			CodTarIca varchar(4) NULL,
			TarifaRet decimal(14, 4) NOT NULL,
			VrRetencion money NOT NULL,
			TarifaIca decimal(14, 4) NOT NULL,
			VrReteIca money NOT NULL,
			Comentarios varchar(max) NULL
			) 

			declare @NumProc int = 1
			declare @ItemProc int = 1
			declare @TipDev varchar(3)
			declare @Devolucion INT
			declare @IdCia varchar(2)
			declare @TipFac varchar(3)
			declare @Factura INT
			declare @IdCiaDoc varchar(2)
			declare @Fecha datetime
			declare @observ varchar(250)
			declare @IdCliente varchar(16)
			declare @VrNeto money
			DECLARE @modalidad varchar(10)
			declare @fecdev smalldatetime

			DECLARE dvfactcursor CURSOR
			FOR SELECT TipDev,Devolucion,IdCia,TipDoc,Factura,IdCiaDoc,Fecha,IdCliente,VrNeto,Modalidad FROM @Trn_DevFcr
			OPEN dvfactcursor
			FETCH NEXT FROM dvfactcursor INTO @TipDev,@Devolucion,@IdCia, @TipFac,@Factura,@IdCiaDoc,@fecdev,@IdCliente,@VrNeto,@modalidad
			WHILE @@FETCH_STATUS = 0
			BEGIN

				IF(@operacion = 'i')
				begin
			
					SELECT TOP 1 @TipDoc = @TipDev, @Cia = @IdCia, @IdCiaComp = @IdCia, @IdCiaCompNiif = @IdCia, @IdCiaCompFis = @IdCia
					
					SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

					IF(@Numero > 0)
						UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
					ELSE
					BEGIN
						SELECT @Numero = 1
						INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
					END

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
						SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
						SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
						--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
						IF(@Comprobante <> '')
							UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
						ELSE
						BEGIN
							SELECT @Comprobante = 1
							INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
					BEGIN
						SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
						SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
						--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
						IF(@CompNiif <> '')
							UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
						ELSE
						BEGIN
							SELECT @CompNiif = 1
							INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
					BEGIN
						SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
						SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
						--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
						IF(@CompNiif <> '')
							UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
						ELSE
						BEGIN
							SELECT @CompFis = 1
							INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END
				end

				IF(@operacion = 'i')
				begin
					IF(EXISTS(SELECT * FROM @Trn_DevFcr))
					BEGIN
					INSERT INTO Trn_DevFcr(
					TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,
					VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,
					VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,IdLocEnv,Pedido,IdCiaPed,Remision,
					IdCiaRem,Cotizacion,IdCiaCot,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,ZonaFrontera,OrigenAdd,TipCom,Comprobante,IdCiaCom,
					Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,
					VrImpCarbono,DevMasivo,NumRecibo,CdCiaRec,CdMotDev,BaseIvaIgp,VrIvaIngProd
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,VrDescuento,VrImpuesto,
					VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,
					VrNeto,Cantidad,CantPuntos,BaseImp,BaseRet,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,IdLocEnv,Pedido,IdCiaPed,Remision,
					IdCiaRem,Cotizacion,IdCiaCot,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,ZonaFrontera,OrigenAdd,@TipComp,@Comprobante,@IdCiaComp,
					Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,
					VrImpCarbono,DevMasivo,NumRecibo,CdCiaRec,CdMotDev,BaseIvaIgp,VrIvaIngProd
					FROM @Trn_DevFcr df WHERE df.TipDev = @TipDev and df.Devolucion = @Devolucion and df.IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_TraEspFacReservas))
					BEGIN
					INSERT INTO Trn_TraEspFacReservas(
					TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
					TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
					pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
					TarifaIca,VrReteIca,EstadoItem
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
					TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
					pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
					TarifaIca,VrReteIca,EstadoItem
					FROM @Trn_TraEspFacReservas dfr WHERE dfr.TipDoc = @TipDev and dfr.Factura = @Devolucion and dfr.IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_RecAFavor))
					BEGIN
					INSERT INTO Trn_RecAFavor(
					TipDoc,Recibo,IdCia,Fecha,VrAFavor,VrOtrosDb,VrAbono,IdCliente,IdAgencia,IdVend
					)
					SELECT
					@TipDev,@Devolucion,@IdCia,Fecha,VrAFavor,VrOtrosDb,VrAbono,IdCliente,IdAgencia,IdVend
					FROM @Trn_RecAFavor ra WHERE ra.TipDoc = @TipDev and ra.Recibo = @Devolucion and ra.IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_VencAbonos))
					BEGIN
						declare @tiprec varchar(3)
						declare @recibo int
						declare @idciarec varchar(2)
						declare @item int 
						SELECT TOP 1 @tiprec = TipRec, @idciarec = IdCia, @recibo = Recibo FROM @Trn_VencAbonos va where va.TipDoc = @TipFac and va.Factura = @Factura and va.IdCiaFac = @IdCiaDoc
						select @item =  isnull(MAX(Item),0) from Trn_VencAbonos where TipRec = @tiprec and Recibo = @recibo and IdCia = @idciarec

						INSERT INTO Trn_VencAbonos(
						TipRec,Recibo,IdCia,Item,Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,
						VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
						)
						SELECT 
						@TipDoc,@Numero,@Cia,(@item + ROW_NUMBER() OVER(ORDER BY Item ASC)),Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,
						VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
						FROM @Trn_VencAbonos
					END 

					IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
					BEGIN
					INSERT INTO Trn_DetCuentas(
					TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
					VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
					VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
					FROM @Trn_DetCuentas dc WHERE dc.TipDoc = @TipDev and dc.Documento = @Devolucion and dc.IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_DocMemo))
					BEGIN
					INSERT INTO Trn_DocMemo(
					TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
					)
					SELECT 
					@TipDoc,@Numero,@Cia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
					FROM @Trn_DocMemo dm WHERE dm.TipDoc = @TipDev and dm.Documento = @Devolucion and dm.IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
					INSERT INTO Trn_Comprobantes(
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
					NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
					TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
					Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
					PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
					CodRes, DescServicio
					)
					SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
					NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
					TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
					Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
					PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
					CodRes, DescServicio
					FROM @Trn_Comprobantes cp WHERE cp.TipDoc = @TipDev and cp.Documento = @Devolucion and cp.IdCiaDoc = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
					BEGIN
					INSERT INTO Trn_ComDetalle(
					TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
					IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
					IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
					CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
					)
					SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
					IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
					CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
					CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
					FROM @Trn_ComDetalle cd WHERE cd.TipDoc = @TipDev and cd.Documento = @Devolucion and cd.IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp))
					BEGIN
					INSERT INTO Trn_NiifComp(
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
					EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
					FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
					VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
					IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
					Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
					CtbTipo, CtbNumero,
					FisTipo, FisNumero 
					)
					SELECT 
					CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
					@Cia, 
					C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
					C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
					C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
					C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
					C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
					C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
					CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
					CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
					FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
					where C.TipDoc = @TipDev and C.Documento = @Devolucion and C.IdCia = @IdCia
					      and N.TipDoc = @TipDev and N.Documento = @Devolucion and N.IdCiaDoc = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
					BEGIN
					INSERT INTO Trn_NiifDetalle(
					TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
					VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
					VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
					NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
					FechAutoriza, CodCuentaCG
					)
					SELECT 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
					@Cia,
					N.Item, N.Fecha, N.IdCuenta, N.Detalle,
					N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
					N.VrBase, N.TarifaBase, @TipDoc,@Numero,@Cia, N.CodConce,
					N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
					N.FechAutoriza, N.CodCuentaCG
					FROM @Trn_NiifDetalle as N
					JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante and NC.TipDoc = @TipDev and NC.Documento = @Devolucion and NC.IdCiaDoc = @IdCia
					where N.TipDoc = @TipDev and N.Documento = @Devolucion and N.IdCiaDoc = @IdCia		
					END

				end	

				IF(@operacion = 'i')
				begin
				  --actualiza los items de las reservas con los que se relacionan en el tipo de datos nuevo de las facturasreservas
				  UPDATE Trn_TraEspResDetalle
				  SET  Factura = 0, IdCiaFac = '00', FechaFac = null, EstadoItem = r.EstadoItem
				  FROM Trn_TraEspResDetalle d, @Trn_TraEspFacReservas r 
				  WHERE d.TipDoc = r.TipRes  and d.Reserva = r.Reserva and d.IdCia = r.IdCia and d.Item = r.ItemRes

				  --ACTUALIZAR FACTURA
				  IF(UPPER(@modalidad) = 'TOTAL')
				  BEGIN 
					  UPDATE Trn_Facturas
					  SET Anulado = 1,NumDev = @Numero,FecDev = @fecdev
					  FROM Trn_Facturas F, @Trn_DevFcr DF
					  WHERE F.TipDoc = DF.TipDoc AND F.Factura = DF.Factura AND F.IdCia = DF.IdCiaDoc
				  END

				  --actualiza el cliente
				  UPDATE TercCliente
				  SET  VrSaldo = c.VrSaldo - f.VrNeto
				  FROM TercCliente c, @Trn_DevFcr f
				  WHERE c.IdClie = f.IdCliente

				  --actualizar vencimientos,cuando es necesario
				  IF(EXISTS(SELECT * FROM @Trn_VencAbonos))
				  BEGIN 
					 UPDATE Trn_Vencimientos
					 SET  VrAbonado = v.VrAbonado + dv.VrAbono
					 FROM Trn_Vencimientos v, @Trn_VencAbonos dv
					 WHERE v.TipDoc = dv.TipDoc and v.Factura = dv.Factura and v.IdCia = dv.IdCiaFac
				  END

				end

				IF(@NumProc = @ItemProc)
				BEGIN
					select top 1 @observ = Observacion FROM @Trn_DevFcr  WHERE TipDoc = @TipDev and Devolucion = @Devolucion and IdCia = @IdCia
					INSERT INTO #LogTraEspFacturas(
					Numero,Fecha,EstadoProc,Observacion,TimeSys,IdUsuario,Nombre,Tipo
					)
					SELECT 
					@NumProc,t1.Fecha,1,@observ,t1.TimeSys,t1.IdUsuario,u.Usuario,'DEVOLUCION'
					FROM @Trn_DevFcr as t1
					left join adm_Usuarios u on u.IdUsuario = t1.IdUsuario
					WHERE t1.TipDev = @TipDev and t1.Devolucion = @Devolucion and t1.IdCia = @IdCia
				END

				SELECT @ItemProc = @ItemProc + 1
				
				INSERT INTO #LogTraEspFacReservas(
				Numero,Item,TipFac,Factura,IdCia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
				TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
				pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
				TarifaIca,VrReteIca,Comentarios
				)
				SELECT
				@NumProc,@item,TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
				TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
				pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
				TarifaIca,VrReteIca,EstadoItem
				FROM Trn_TRaEspFAcReservas where TipDoc = @TipDoc and Factura = @Factura and IdCia = @IdCia

			FETCH NEXT FROM dvfactcursor INTO @TipDev,@Devolucion,@IdCia, @TipFac,@Factura,@IdCiaDoc,@fecdev,@IdCliente,@VrNeto,@modalidad
			END
			CLOSE dvfactcursor
			DEALLOCATE dvfactcursor
			
			SELECT * FROM #LogTraEspFacturas
			SELECT * FROM #LogTraEspFacReservas

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsMsvTrn_Facturas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsMsvTrn_Facturas]
	@Trn_Facturas [dbo].[dataTypeTrn_Facturas] READONLY,
	@Trn_TraEspFacReservas [dbo].[dataTypeTrn_TraEspFacReservas] READONLY,
	@Trn_TraEspFacResVehiculos [dbo].[dataTypeTrn_TraEspFacResVehiculos] READONLY,
	@Trn_DocMemo [dbo].[dataTypeTrn_DocMemo] READONLY,
	@Trn_TraEspAuxFactura [dbo].[dataTypeTrn_TraEspAuxFactura] READONLY,
	@Trn_RecAfavor [dbo].[dataTypeTrn_RecAfavor] READONLY,
	@Trn_VencAbonos [dbo].[dataTypeTrn_VencAbonos] READONLY,
	@Trn_Vencimientos [dbo].[dataTypeTrn_Vencimientos] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifCompFMsv] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif CHAR(2) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis CHAR(2) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @CodigoPre VARCHAR(3)
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
declare @FechaFac smalldatetime
	BEGIN TRAN
		BEGIN TRY	
		
			--CREATE TABLE #LogTraEspFacturas(
			--Numero int NOT NULL DEFAULT ((0)),
			--Fecha smalldatetime NOT NULL,
			--EstadoProc int NOT NULL DEFAULT ((0)),
			--Observacion varchar(250) NULL,
			--TimeSys smalldatetime NOT NULL,
			--IdUsuario varchar(11) NOT NULL,
			--Nombre varchar(50) NOT NULL,
			--Tipo varchar(10) NOT NULL
			--)	
			
			CREATE TABLE #LogTraEspFacReservas(
			NewTipFac varchar(3) NOT NULL,
			NewFactura int NOT NULL,
			NewIdCiaFac char(2) NOT NULL,
			OldTipFac varchar(3) NOT NULL,
			OldFactura int NOT NULL,
			OldIdCiaFac char(2) NOT NULL,
			) 

			declare @NumProc int = 1
			declare @ItemProc int = 1
			declare @TipFac varchar(3)
			declare @Factura INT
			declare @IdCia varchar(2)
			declare @Fecha datetime
			declare @observ varchar(250)
			declare @IdCliente varchar(16)
			declare @VrNeto money

			DECLARE factcursor CURSOR
			FOR SELECT TipDoc,Factura,IdCia,Fecha,IdCliente,VrNeto FROM @Trn_Facturas
			OPEN factcursor
			FETCH NEXT FROM factcursor INTO @TipFac,@Factura,@IdCia,@Fecha,@IdCliente,@VrNeto
			WHILE @@FETCH_STATUS = 0
			BEGIN
				IF(@operacion = 'i')
				BEGIN
					SET @TipDoc = @TipFac
					SET @Cia = @IdCia
					SET @IdCiaComp = @IdCia
					SET @IdCiaCompNiif = @IdCia
					SET @IdCiaCompFis = @IdCia
					SET @FechaFac = @Fecha 
				
					SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

					IF(@Numero > 0)
						UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
					ELSE
					BEGIN
						SELECT @Numero = 1
						INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
					END

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
						SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
						SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
						--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
						IF(@Comprobante <> '')
							UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
						ELSE
						BEGIN
							SELECT @Comprobante = 1
							INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF' AND Documento = @Factura))
					BEGIN
						SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
						SELECT @CompNiif = (Numero + 1) FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
						
						--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
						IF(@CompNiif > 0)
						BEGIN
							--declare @bcpCommand varchar(255), @Result int
							--declare @FileName varchar(255)
							--set @FileName ='D:\hola.txt'
							--set @bcpCommand = 'bcp "Select 1 as a" queryout "' + @FileName + '" -c -t, -T -S '

							--exec @Result = master..xp_cmdshell @bcpCommand, no_output
							UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
						END
						ELSE
						BEGIN
							SELECT @CompNiif = 1
							INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END
					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL' AND Documento = @Factura))
					BEGIN
						SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
						SELECT @CompFis = (Numero + 1) FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
						--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
						IF(@CompFis > 0)
						BEGIN
							UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
						END
						ELSE
						BEGIN
							SELECT @CompFis = 1
							INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END
	
					IF(EXISTS(SELECT * FROM @Trn_Facturas))
					BEGIN
						INSERT INTO Trn_Facturas(
						TipDoc, Factura, IdCia, Fecha, IdConcepto, IdCliente, IdAgencia, FechaVence, VrSubTotal, VrDescuento, VrImpuesto, VrRetencion, VrReteICA, VrReteIVA, VrFletes, VrOtros, 
						VrCargos, VrOtrDcto, VrCostos, VrSobretasa, VrImpGlobal, VrFaltantes, VrAnticipos, VrNeto, VrAplicado, Cantidad, CantPuntos, PuntosAcum, BaseImp, BaseRet, BaseIca, 
						BaseRiv, TarifaIva, TarifaRet, TarifaIca, TarifaRiv, CodTarIva, CodTarRet, CodTarIca, CodTarRiv, IdCCosto, IdSubCos, IdVend, TarifaCom, CodTarCom, DirEnvio, IdLocEnv, 
						DiasEntraga, NitContac, NomContac, TelContac, emlContac, CargoContac, IdForma, DetallePago, MulPlazos, IdPlazo, CdMney, NitEmpTrans, EmpTrans, pVehiculo, CdConductor, 
						CdRuta, TipPed, Pedido, IdCiaPed, TipRem, Remision, IdCiaRem, TipCot, Cotizacion, IdCiaCot, FecPedido, AutzaMora, AutzaCupo, Modalidad, KmtVehic, ZonaFrontera, PesoTotal, 
						UnidTotal, VolTotal, CantFalt, VrCostoRem, VrCostoAfi, CodAutoRet, OrigenAdd, TipCom, Comprobante, IdCiaCom, Anulado, NumDev, FecDev, Observacion, IdEstado, TimeSys, 
						FecUpdate, IdCiaCrea, IdUsuario, VrImpCons, VrReteCREE, TarifaRtc, CodTarRtc, Parqueadero, FecCuotaParq, BaseIvaObsq, VrIvaObsequio, VrImpCarbono, TipoFE, FechaFE, 
						BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrOtros,
						VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,
						BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,
						DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,
						CdRuta,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,ZonaFrontera,PesoTotal,
						UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,CodAutoRet,OrigenAdd,@TipComp,@Comprobante,@IdCiaComp,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,
						FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,TipoFE,FechaFE,
						BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
						FROM @Trn_Facturas p WHERE p.TipDoc = @TipFac and p.Factura = @Factura and p.IdCia = @IdCia
					END
					 
					IF(EXISTS(SELECT * FROM @Trn_TraEspFacReservas))
					BEGIN
						INSERT INTO Trn_TraEspFacReservas(
						TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
						TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
						pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
						TarifaIca,VrReteIca,EstadoItem
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
						TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
						pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
						TarifaIca,VrReteIca,EstadoItem
						FROM @Trn_TraEspFacReservas p WHERE p.TipDoc = @TipFac and p.Factura = @Factura and p.IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_TraEspFacResVehiculos))
					BEGIN
						INSERT INTO Trn_TraEspFacResVehiculos(
						TipDoc,Factura,IdCIa,Item,TipRes,Reserva,IdCIaRes,ItemRes,IdVehiculo,TipoAfil,VrRecorrido
						)
						SELECT
						@TipDoc,@Numero,@Cia,Item,TipRes,Reserva,IdCIaRes,ItemRes,IdVehiculo,TipoAfil,VrRecorrido
						FROM @Trn_TraEspFacResVehiculos p WHERE p.TipDoc = @TipFac and p.Factura = @Factura and p.IdCia = @IdCia 
					END

					IF(EXISTS(SELECT * FROM @Trn_Vencimientos))
					BEGIN
						INSERT INTO Trn_Vencimientos(
						TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,
						TipoDcto,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,
						TarifInt,FecLiqMora,FecPlazoCal
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,
						TipoDcto,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,
						TarifInt,FecLiqMora,FecPlazoCal
						FROM @Trn_Vencimientos p WHERE p.TipDoc = @TipFac and p.Factura = @Factura and p.IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_DocMemo))
					BEGIN
					INSERT INTO Trn_DocMemo(
						TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
						FROM @Trn_DocMemo p WHERE p.TipDoc = @TipFac and p.Documento = @Factura and p.IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_TraEspAuxFactura))
					BEGIN
						INSERT INTO Trn_TraEspAuxFactura(
						TipFac,Factura,IdCiaFac,Resolucion,Rango,FechaResl,Prefijo,TipDocPf,PreFactura,IdCiaPf,CodigoPreFact
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Resolucion,Rango,FechaResl,Prefijo,TipDocPf,PreFactura,IdCiaPf,CodigoPreFact
						FROM @Trn_TraEspAuxFactura p WHERE p.TipFac = @TipFac and p.Factura = @Factura and p.IdCiaFac = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_RecAfavor))
					BEGIN
						update Trn_RecAfavor
						set VrAbono = t1.VrAbono + t2.VrAbono
						from Trn_RecAfavor t1, @Trn_RecAfavor t2
						where t1.TipDoc = t2.TipDoc and t1.Recibo = t2.Recibo and t1.IdCia = t2.IdCia and t1.IdCliente = t2.IdCliente and t1.IdAgencia = t2.IdAgencia and t1.IdVend = t2.IdVend
							--and TipDoc = @TipDoc and t1.Factura = @Factura and t1.IdCia = @IdCia
					END 

					IF(EXISTS(SELECT * FROM @Trn_VencAbonos))
					BEGIN
						declare @tiprec varchar(3)
						declare @recibo int
						declare @idciarec varchar(2)
						declare @item int 
						SELECT TOP 1 @tiprec = TipRec, @idciarec = IdCia, @recibo = Recibo FROM @Trn_VencAbonos WHERE TipDoc = @TipFac and Factura = @Factura and IdCiaFac = @IdCia
						
						if((@tiprec <> null and @tiprec <> '') and @recibo > 0)
						BEGIN
							SELECT @item =  isnull(MAX(Item),0) FROM Trn_VencAbonos WHERE TipRec = @tiprec and Recibo = @recibo and IdCia = @idciarec

							INSERT INTO Trn_VencAbonos(
							TipRec,Recibo,IdCia,Item,Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,
							VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
							)
							SELECT 
							TipRec,Recibo,IdCia,(@item + ROW_NUMBER() OVER(ORDER BY Item ASC)),Fecha,@TipDoc,@Numero,@Cia,ItemFac,VrAbono,VrDescto,
							VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
							FROM @Trn_VencAbonos WHERE TipDoc = @TipFac and Factura = @Factura and IdCiaFac = @IdCia

							IF(EXISTS(SELECT * FROM @Trn_RecAfavor))
							BEGIN
								UPDATE Trn_RecAfavor
								SET VrAbono = t1.VrAbono + t2.VrAbono
								FROM Trn_RecAfavor t1
								JOIN(SELECT ra.TipDoc,ra.Recibo,ra.IdCia,ra.Fecha,ra.VrAFavor,ra.VrOtrosDb,ra.VrAbono,ra.IdCliente,ra.IdAgencia,ra.IdVend FROM @Trn_RecAfavor ra
										JOIN @Trn_VencAbonos va on ra.TipDoc = va.TipRec and ra. Recibo = va.Recibo and ra.IdCia = va.IdCia
										WHERE va.TipDoc = @TipFac and va.Factura = @Factura and va.IdCiaFac = @IdCia) AS t2
								ON t1.TipDoc = t2.TipDoc and t1.Recibo = t2.Recibo and t1.IdCia = t2.IdCia and t1.IdCliente = t2.IdCliente and t1.IdAgencia = t2.IdAgencia and t1.IdVend = t2.IdVend
							END
						END
					END 

					IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
					BEGIN
						INSERT INTO Trn_DetCuentas(
						TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
						VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
						VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
						FROM @Trn_DetCuentas where TipDoc = @TipFac and Documento = @Factura and IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
						INSERT INTO Trn_Comprobantes(
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
						NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
						TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
						PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
						CodRes, DescServicio
						)
						SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
						NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
						TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
						PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
						CodRes, DescServicio
						FROM @Trn_Comprobantes where TipDoc = @TipFac and Documento = @Factura and IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
					BEGIN
						INSERT INTO Trn_ComDetalle(
						TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
						IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
						IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
						NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
						CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
						IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
						)
						SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
						IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
						CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
						NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
						CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
						IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
						FROM @Trn_ComDetalle where TipDoc = @TipFac and Documento = @Factura and IdCia = @IdCia
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF' AND Documento = @Factura))
					BEGIN
						INSERT INTO Trn_NiifComp(
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
						EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
						FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
						VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
						IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
						Tipo_Pago, Establec, PEmision, Autorizac,FechaAut, CtbTipo, CtbNumero, FisTipo, FisNumero 
						)
						SELECT 
						@TipCompNiif, @CompNiif, @IdCia,C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
						C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @IdCia, C.Anulado, C.NumDev,
						C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
						C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
						C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
						C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut, @TipCompNiif, @CompNiif, NULL, 0
						FROM @Trn_NiifComp  AS N 
						JOIN  @Trn_Comprobantes AS C ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
						WHERE C.Documento = N.Documento AND N.Documento = @Factura AND N.TipoNiif = 'NIIF'

						IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
						BEGIN
							INSERT INTO Trn_NiifDetalle(
							TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
							VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
							VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
							NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
							NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
							CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
							DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
							CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
							FechAutoriza, CodCuentaCG
							)
							SELECT 
							@TipCompNiif, @CompNiif, @IdCia, N.Item, N.Fecha, N.IdCuenta, N.Detalle,
							N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
							N.VrBase, N.TarifaBase, @TipDoc,@Numero,@IdCia, N.CodConce,
							N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
							N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
							N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
							N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
							N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
							N.FechAutoriza, N.CodCuentaCG
							FROM @Trn_NiifComp  as NC
							JOIN @Trn_NiifDetalle AS N ON N.Comprobante = NC.ComprobanteCont  AND N.TipCom = @TipCompNiif
							--AND NC.TipoNiif = 'NIIF' 
							where N.Documento = @Factura  AND N.Documento = NC.Documento AND NC.TipoNiif = 'NIIF' 
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL' AND Documento = @Factura))
					BEGIN
						INSERT INTO Trn_NiifComp(
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
						EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
						FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
						VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
						IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
						Tipo_Pago, Establec, PEmision, Autorizac,FechaAut, CtbTipo, CtbNumero, FisTipo, FisNumero 
						)
						SELECT 
						@TipCompFis, @CompFis, @IdCia,C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
						C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @IdCia, C.Anulado, C.NumDev,
						C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
						C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
						C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
						C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut, @TipCompFis, @CompFis, NULL, 0
						FROM @Trn_NiifComp  AS N 
						JOIN  @Trn_Comprobantes AS C ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
						WHERE C.Documento = N.Documento AND N.Documento = @Factura AND N.TipoNiif = 'FISCAL'

						IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
						BEGIN
							INSERT INTO Trn_NiifDetalle(
							TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
							VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
							VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
							NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
							NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
							CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
							DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
							CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
							FechAutoriza, CodCuentaCG
							)
							SELECT 
							@TipCompFis, @CompFis, @IdCia, N.Item, N.Fecha, N.IdCuenta, N.Detalle,
							N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
							N.VrBase, N.TarifaBase, @TipDoc,@Numero,@IdCia, N.CodConce,
							N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
							N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
							N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
							N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
							N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
							N.FechAutoriza, N.CodCuentaCG
							FROM @Trn_NiifComp as NC
							JOIN @Trn_NiifDetalle AS N ON N.Comprobante = NC.ComprobanteCont  AND N.TipCom = @TipCompFis
							--AND NC.TipoNiif = 'FISCAL' 
							where N.Documento = @Factura AND N.Documento = NC.Documento AND NC.TipoNiif = 'FISCAL' 
						END
					END
					
					--actualiza los items de las reservas con los que se relacionan en el tipo de datos nuevo de las facturasreservas
					DECLARE @TipRes VARCHAR(3) 
					DECLARE @CiaRes VARCHAR(2) 
					DECLARE @NumRes INT 
					DECLARE @ItemRes INT
					DECLARE @Ref VARCHAR(50) 
					DECLARE @reserva Int = 0 
					DECLARE @cantres Int = 0 
					DECLARE @cantresfact Int = 0 

					DECLARE faccursor CURSOR
					FOR SELECT TipRes,Reserva,IdCiaRes,ItemRes, Referencia1 FROM @Trn_TraEspFacReservas where TipDoc = @TipFac and Factura = @Factura and IdCia = @IdCia
					OPEN faccursor
					FETCH NEXT FROM faccursor INTO @TipRes,@NumRes,@CiaRes,@ItemRes, @Ref
					WHILE @@FETCH_STATUS = 0
					BEGIN
						IF(@Ref = 'CLIENTE')
						BEGIN
							UPDATE Trn_TraEspResDetalle
							SET  TipFac = @TipDoc, Factura = @Numero, IdCiaFac = @IdCia, FechaFac = @FechaFac, EstadoItem = 'FACTURADA'
							FROM Trn_TraEspResDetalle d
							WHERE d.TipDoc = @TipRes  and d.Reserva = @NumRes and d.IdCia = @CiaRes and d.Item = @ItemRes
						END
						IF (@NumRes <> @reserva)
						BEGIN
						SET @reserva = @NumRes
						
						SELECT @cantres = count(*)
						FROM Trn_TraEspResDetalle AS rd
						WHERE rd.TipDoc = @TipRes  and rd.Reserva = @NumRes and rd.IdCia = @CiaRes

						SELECT @cantresfact = count(*)
						FROM Trn_TraEspResDetalle AS rd
						WHERE rd.TipDoc = @TipRes  and rd.Reserva = @NumRes and rd.IdCia = @CiaRes and rd.EstadoItem = 'FACTURADA'
						
						IF (@cantresfact = @cantres)
						BEGIN
							UPDATE Trn_TraEspReservas 
							SET EstadoRes = 'FACTURADA' 
							WHERE TipDoc = @TipRes  and Reserva = @NumRes and IdCia = @CiaRes                     
						END
						END
				  
					FETCH NEXT FROM faccursor INTO @TipRes,@NumRes,@CiaRes,@ItemRes,@Ref
					END
					CLOSE faccursor
					DEALLOCATE faccursor

					--actualizar el cliente de cada factura
					UPDATE TercCliente
					SET  VrSaldo = c.VrSaldo + @VrNeto
					FROM TercCliente c
					WHERE c.IdClie = @IdCliente

					--Tabla a Deovler para los nuevos numeros de factura
					INSERT INTO #LogTraEspFacReservas(NewTipFac,NewFactura,NewIdCiaFac,OldTipFac,OldFactura,OldIdCiaFac)
					SELECT @TipDoc,@Numero,@Cia,@TipFac, @Factura, @IdCia
				END
			FETCH NEXT FROM factcursor INTO @TipFac,@Factura,@IdCia,@Fecha,@IdCliente,@VrNeto
			END
			CLOSE factcursor
			DEALLOCATE factcursor

			--SELECT * FROM #LogTraEspFacturas
			SELECT * FROM #LogTraEspFacReservas
			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsOtroSiFromCOE]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsOtroSiFromCOE]
	@Trn_TraEspContratos [dbo].[dataTypeTrn_TraEspContratos] READONLY,
	@Trn_TraEspContratoDet [dbo].[dataTypeTrn_TraEspContratoDet] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @IdOtroSi INT --Esta variable guarda el nÃºmero de consecutivo del otrosÃ­
DECLARE @Contrato INT --Esta variable guarda el nÃºmero de consecutivo del contrato a quien se le ha insertado un OtroSÃ­
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de contrato a quien se le ha insertado un OtroSÃ­
DECLARE @IdCia VARCHAR(2) --Esta variable guarda la cÃ­a de contrato a quien se le ha insertado un OtroSÃ­
DECLARE @VrAdicion DECIMAL --Esta variable guarda el valor a adicionar al contrato a quien se le ha insertado un OtroSÃ­
DECLARE @FechaFinNew SMALLDATETIME --Esta variable guarda el valor dela nueva fecha del contrato a quien se le ha insertado un OtroSÃ­
DECLARE @Item INT --Esta variable guarda el nÃºmero de consecutivo del Item contrato a quien se le ha insertado un OtroSÃ­
DECLARE @VrCobro DECIMAL --Esta variable actualiza el valor a cobrar al contrato a quien se le ha insertado un OtroSÃ­
--declare @item int
	BEGIN TRAN
		BEGIN TRY
		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			BEGIN
				SELECT @TipDoc= TipDoc, @Contrato = Contrato, @IdCia = IdCia From @Trn_TraEspContratos
				IF(EXISTS(SELECT * FROM @Trn_TraEspContratoDet))
				begin
					SET @VrCobro = (select (sum(VrDia * DiasDisp) + sum(VrMonitor * CantMonitor) + sum(VrUnitario)) FROM @Trn_TraEspContratoDet)
				end
				-- --Actualizar contrato
				UPDATE Trn_TraEspContratos SET VrCobro = VrCobro + ISNULL(@VrCobro, 0)
				WHERE TipDoc = @TipDoc AND Contrato = @Contrato and IdCia = @IdCia
				--AgrergarItems de Contrato Detalle
				IF(EXISTS(SELECT * FROM @Trn_TraEspContratoDet))
				begin
					SELECT TOP 1 @IdOtroSi = IdOtroSi FROM @Trn_TraEspContratoDet
					SET @Item = (select max(Item) from trn_traespcontratodet where TipDoc = @TipDoc AND contrato = @Contrato AND idcia = @IdCia)
					INSERT INTO Trn_TraEspContratoDet(
					TipDoc,Contrato,IdCia,Item,IdHorario,TipPed,Pedido,CiaPed,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
					Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
					DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,IdOtroSi,ItemAnuladoOS,
					EsItemPME
					) 
					SELECT --(Item + @Item)
					@TipDoc,@Contrato,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),IdHorario,TipPed,Pedido,@IdCia,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
					Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
					DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,IdOtroSi,ItemAnuladoOS,
					EsItemPME
					FROM @Trn_TraEspContratoDet
				end
				--Cerrar el OtroSÃ­
				UPDATE Trn_TraEspOtroSi SET Aplicado = 1 WHERE IdOtroSi = @IdOtroSi
			 END
			SELECT '1' 

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsPreFacturas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsPreFacturas]
	@Trn_Facturas [dbo].[dataTypeTrn_Facturas] READONLY,
	@Trn_TraEspFacReservas [dbo].[dataTypeTrn_TraEspFacReservas] READONLY,
	@Trn_TraEspFacResVehiculos [dbo].[dataTypeTrn_TraEspFacResVehiculos] READONLY,
	@Trn_DocMemo [dbo].[dataTypeTrn_DocMemo] READONLY,
	@Trn_TraEspAuxFactura [dbo].[dataTypeTrn_TraEspAuxFactura] READONLY,
	@Trn_RecAfavor [dbo].[dataTypeTrn_RecAfavor] READONLY,
	@Trn_VencAbonos [dbo].[dataTypeTrn_VencAbonos] READONLY,
	@Trn_Vencimientos [dbo].[dataTypeTrn_Vencimientos] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @TipDocPre VARCHAR(3)
DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
declare @FechaFac smalldatetime
declare @OpcUco VARCHAR
	BEGIN TRAN
		BEGIN TRY		 
			
			IF(@operacion = 'i')
			BEGIN
				--OPCION DE UNIFICAR CONSECUTIVOS DE PREFACTURAS CON LAS FACTURAS
				SELECT @OpcUco  = Valor FROM adm_Opciones WHERE IdOpc = 'UCO' 
				IF(@OpcUco = '1')
					SELECT @TipDocPre = TipDoc, @TipDoc = CodigoPreFact FROM @Trn_Facturas
				ELSE 
					SELECT @TipDocPre = TipDoc, @TipDoc = TipDoc FROM @Trn_Facturas
				----

				SELECT TOP 1  @Cia = IdCia, @FechaFac = Fecha FROM @Trn_Facturas
				SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

				IF(@Numero > 0)
				BEGIN
					IF(@OpcUco = '1')
					begin
						UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
						UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDocPre AND IdCia = @Cia
					end
					else
						UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDocPre AND IdCia = @Cia
				END
				ELSE
				BEGIN
					SELECT @Numero = 1
					IF(@OpcUco = '1')
					begin
						INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
						INSERT INTO TiposDocCons VALUES (@TipDocPre,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
					end
					else
						INSERT INTO TiposDocCons VALUES (@TipDocPre,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			
				IF(EXISTS(SELECT * FROM @Trn_Facturas))
				BEGIN
				INSERT INTO Trn_Facturas(
				TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,
				VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,
				CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,
				CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,
				CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,TipPed,Pedido,IdCiaPed,
				TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,ZonaFrontera,PesoTotal,
				UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,CodAutoRet,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,
				IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,
				VrImpCarbono,TipoFE,FechaFE,BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
				)
				SELECT
				@TipDocPre,@Numero,@Cia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,
				VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,
				CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,
				CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,
				CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,TipPed,Pedido,IdCiaPed,
				TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,ZonaFrontera,PesoTotal,
				UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,CodAutoRet,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,
				IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,
				VrImpCarbono,TipoFE,FechaFE,BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
				FROM @Trn_Facturas
				END 

				IF(EXISTS(SELECT * FROM @Trn_TraEspFacReservas))
				BEGIN
				INSERT INTO Trn_TraEspFacReservas(
				TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
				TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
				pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
				TarifaIca,VrReteIca,EstadoItem
				)
				SELECT 
				@TipDocPre,@Numero,@Cia,Item,TipoReg,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,
				TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
				pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,VrRetencion,
				TarifaIca,VrReteIca,EstadoItem
				FROM @Trn_TraEspFacReservas
				END

				IF(EXISTS(SELECT * FROM @Trn_TraEspFacResVehiculos))
				BEGIN
				INSERT INTO Trn_TraEspFacResVehiculos(
				TipDoc,Factura,IdCIa,Item,TipRes,Reserva,IdCIaRes,ItemRes,IdVehiculo,TipoAfil,VrRecorrido
				)
				SELECT
				@TipDocPre,@Numero,@Cia,Item,TipRes,Reserva,IdCIaRes,ItemRes,IdVehiculo,TipoAfil,VrRecorrido
				FROM @Trn_TraEspFacResVehiculos
				END

				IF(EXISTS(SELECT * FROM @Trn_TraEspAuxFactura))
				BEGIN
				INSERT INTO Trn_TraEspAuxFactura(
				TipFac,Factura,IdCiaFac,Resolucion,Rango,FechaResl,Prefijo,TipDocPf,PreFactura,IdCiaPf,CodigoPreFact
				)
				SELECT 
				@TipDocPre,@Numero,@Cia,Resolucion,Rango,FechaResl,Prefijo,TipDocPf,PreFactura,IdCiaPf,CodigoPreFact
				FROM @Trn_TraEspAuxFactura
				END 
			END	

			SELECT @Numero

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsRutas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsRutas]
	@Rutas [dbo].[dataTypeRutas] READONLY,
	@RutasRecorridos [dbo].[dataTypeRutasRecorridos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 
		 CREATE TABLE #rutas(
		 IdRuta		VARCHAR (20)		NOT NULL,
		 Ruta		VARCHAR (100)	NOT NULL,
		 IdLocOri	VARCHAR (8)		NOT NULL,
		 IdLocDes	VARCHAR (8)		NOT NULL,
		 EsLocal	BIT				DEFAULT ((0)) NOT NULL,
		 Distkmt	DECIMAL (14, 4)	DEFAULT ((0)) NOT NULL,
		 TmHoras	VARCHAR (8)		NULL,
		 CodigoMt	VARCHAR (5)		NULL,
		 FleteTon	MONEY			DEFAULT ((0)) NULL,
		 Inactivo	BIT				DEFAULT ((0)) NOT NULL,
		 CdCiaTurno	CHAR (2)		NULL,
		 PuntosRut	DECIMAL (14, 4)	DEFAULT ((0)) NOT NULL,
		 Error      varchar(250)    NULL
		 )

		 CREATE TABLE #recorridos(
		 IdRuta		VARCHAR (4)		NOT NULL,
		 NumTramo	INT				DEFAULT ((0)) NOT NULL,
		 IdLocal	VARCHAR (8)		NOT NULL,
		 Detalle	VARCHAR (1000)	NULL,
		 kmstramo	DECIMAL (14, 4)	DEFAULT ((0)) NOT NULL,
		 kmstotal	DECIMAL (14, 4)	DEFAULT ((0)) NOT NULL,
		 Alterno	BIT				DEFAULT ((0)) NOT NULL,
		 Error      varchar(250)    null
		 )

		 --UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Rutas))
			begin
			 UPDATE Rutas
			 SET 
			 IdRuta = t2.IdRuta,Ruta = t2.Ruta,IdLocOri = t2.IdLocOri,IdLocDes = t2.IdLocDes,
			 EsLocal = t2.EsLocal,Distkmt = t2.Distkmt,TmHoras = t2.TmHoras,CodigoMt = t2.CodigoMt,
			 FleteTon = t2.FleteTon,Inactivo = t2.Inactivo,CdCiaTurno = t2.CdCiaTurno,PuntosRut = t2.PuntosRut
			 FROM Rutas t1
			 JOIN @Rutas t2 ON t1.IdRuta = t2.IdRuta
			end

			IF(EXISTS(SELECT TOP 1 * FROM @RutasRecorridos))
			BEGIN
			 UPDATE RutasRecorridos
			 SET 
			 IdRuta = t2.IdRuta,NumTramo = t2.NumTramo,IdLocal = t2.IdLocal,
			 Detalle = t2.Detalle,kmstramo = t2.kmstramo,kmstotal = t2.kmstotal,
			 Alterno = t2.Alterno
			 FROM RutasRecorridos t1
			 JOIN @RutasRecorridos t2 ON t1.IdRuta = t2.IdRuta and t1.NumTramo = t2.NumTramo
			 WHERE t1.IdRuta = t2.IdRuta and t1.NumTramo = t2.NumTramo
			 --Inserta los que no existen
			 INSERT INTO RutasRecorridos(
			 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno)
			 SELECT 
			 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno
			 FROM @RutasRecorridos
			 WHERE (IdRuta + Convert(varchar,NumTramo)) NOT IN(SELECT (IdRuta +Convert(varchar,NumTramo)) FROM RutasRecorridos)
			END

			--IF(EXISTS(SELECT TOP 1 * FROM @RutasPlan))
			--begin
			-- UPDATE RutasPlan
			-- SET 
			-- IdRuta = t2.IdRuta,IdPunto = t2.IdPunto,Descripcion = t2.Descripcion,Distancia = t2.Distancia,
			-- Tiempo = t2.Tiempo,ClasePto = t2.ClasePto,CdPto = t2.CdPto,IdLocal = t2.IdLocal,PosLat = t2.PosLat,
			-- PosLon = t2.PosLon,Inactivo = t2.Inactivo
			-- FROM RutasPlan t1
			-- JOIN @RutasPlan t2 ON t1.IdRuta = t2.IdRuta
			--end

			--IF(EXISTS(SELECT TOP 1 * FROM @RutasTramos))
			--begin
			-- UPDATE RutasTramos
			-- SET 
			-- IdRuta = t2.IdRuta,NumTramo = t2.NumTramo,IdLocal = t2.IdLocal,kmstramo = t2.kmstramo,kmstotal = t2.kmstotal
			-- FROM RutasTramos T1
			-- JOIN @RutasTramos T2 ON T1.IdRuta = T2.IdRuta
			--end
			
		 END

		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Rutas))
			BEGIN
			 INSERT INTO Rutas(
			 IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,Inactivo,CdCiaTurno,PuntosRut
			 )
			 SELECT 
			 IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,Inactivo,CdCiaTurno,PuntosRut
			 FROM @Rutas
			 WHERE IdRuta NOT IN(SELECT IdRuta FROM Rutas)
			END

			
			IF(EXISTS(SELECT TOP 1 * FROM @RutasRecorridos))
			BEGIN
			 INSERT INTO RutasRecorridos(
			 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno
			 )
			 SELECT 
			 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno
			 FROM @RutasRecorridos
			 WHERE (IdRuta + Convert(varchar,NumTramo)) NOT IN(SELECT (IdRuta +Convert(varchar,NumTramo)) FROM RutasRecorridos)
			END

			--IF(EXISTS(SELECT TOP 1 * FROM @RutasPlan))
			--BEGIN
			-- INSERT INTO RutasPlan(
			-- IdRuta,IdPunto,Descripcion,Distancia,Tiempo,ClasePto,CdPto,IdLocal,PosLat,PosLon,Inactivo
			-- )
			-- SELECT 
			-- IdRuta,IdPunto,Descripcion,Distancia,Tiempo,ClasePto,CdPto,IdLocal,PosLat,PosLon,Inactivo
			-- FROM @RutasPlan
			-- WHERE IdRuta NOT IN(SELECT IdRuta FROM RutasPlan)
			--END

			--IF(EXISTS(SELECT TOP 1 * FROM @RutasTramos))
			--BEGIN
			-- INSERT INTO RutasTramos(
			-- IdRuta,NumTramo,IdLocal,kmstramo,kmstotal
			-- )
			-- SELECT 
			-- IdRuta,NumTramo,IdLocal,kmstramo,kmstotal
			-- FROM @RutasTramos
			-- WHERE IdRuta NOT IN(SELECT IdRuta FROM @RutasTramos)
			--END
						
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id VARCHAR (4)
			 SELECT @id = IdRuta FROM @Rutas
			 --DELETE FROM RutasTramos WHERE IdRuta = @id
			 --DELETE FROM RutasPlan WHERE IdRuta = @id
			 DELETE FROM RutasRecorridos WHERE IdRuta = @id
			 DELETE FROM Rutas WHERE IdRuta = @id
		 END

		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'p')
		 BEGIN
		    IF(EXISTS(SELECT TOP 1 * FROM @Rutas))
			BEGIN
				DECLARE @IdRuta VARCHAR (20)
				DECLARE rutacursor CURSOR
				FOR SELECT IdRuta FROM @Rutas
				OPEN rutacursor
				FETCH NEXT FROM rutacursor into @IdRuta
				WHILE @@FETCH_STATUS = 0
				BEGIN
					BEGIN TRY
					 if(NOT EXISTS(SELECT IdRuta FROM Rutas WHERE IdRuta = @IdRuta))
					 BEGIN
						 INSERT INTO Rutas(
						 IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,Inactivo,CdCiaTurno,PuntosRut)
						 SELECT 
						 IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,0,CdCiaTurno,PuntosRut
						 FROM @Rutas WHERE IdRuta = @IdRuta
					 END
					 ELSE if(EXISTS(SELECT IdRuta FROM Rutas WHERE IdRuta = @IdRuta))
					 BEGIN
						--SE AGREGA LA LINEA NO INSERTADA PORQUE YA EXISTE
						 INSERT INTO #rutas
						 SELECT 
						 IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,0,CdCiaTurno,PuntosRut, 'La Ruta ya existe.'
						 FROM @Rutas WHERE IdRuta = @IdRuta
					 END
					END TRY
					BEGIN CATCH
					 --SE AGREGA LA LINEA NO INSERTADA
					 INSERT INTO #rutas
					 SELECT 
					 IdRuta,Ruta,IdLocOri,IdLocDes,EsLocal,Distkmt,TmHoras,CodigoMt,FleteTon,0,CdCiaTurno,PuntosRut, ERROR_MESSAGE()
					 FROM @Rutas WHERE IdRuta = @IdRuta
					END CATCH
				   FETCH NEXT FROM rutacursor INTO @IdRuta
				END
				CLOSE rutacursor
				DEALLOCATE rutacursor
			END

			IF(EXISTS(SELECT TOP 1 * FROM @RutasRecorridos))
			BEGIN
				DECLARE @IdRutRec VARCHAR (4)
				Declare @Numero INT

				DECLARE recorridocursor CURSOR
					FOR SELECT IdRuta, NumTramo FROM @RutasRecorridos
				OPEN recorridocursor
				FETCH NEXT FROM recorridocursor into @IdRutRec,@Numero
				WHILE @@FETCH_STATUS = 0
				BEGIN
					BEGIN TRY				
						IF(NOT EXISTS(SELECT IdRuta FROM RutasRecorridos WHERE IdRuta = @IdRutRec and NumTramo = @Numero))
						BEGIN
						 INSERT INTO RutasRecorridos(
						 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno)
						 SELECT 
						 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno
						 FROM @RutasRecorridos WHERE IdRuta = @IdRutRec and NumTramo = @Numero
						END 
						ELSE IF(EXISTS(SELECT IdRuta FROM RutasRecorridos WHERE IdRuta = @IdRutRec and NumTramo = @Numero))
						BEGIN
						--SE AGREGA LA LINEA NO INSERTADA PORQUE YA EXISTE
						 INSERT INTO #recorridos
						 SELECT 
						 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno, 'El recorrido ya existe.'
						 FROM @RutasRecorridos WHERE IdRuta = @IdRutRec and NumTramo = @Numero
						END
					END TRY
					BEGIN CATCH
					 --SE AGREGA LA LINEA NO INSERTADA
					 INSERT INTO #recorridos
					 SELECT
					 IdRuta,NumTramo,IdLocal,Detalle,kmstramo,kmstotal,Alterno,ERROR_MESSAGE()
					 FROM @RutasRecorridos WHERE IdRuta = @IdRutRec and NumTramo = @Numero
					END CATCH
				   FETCH NEXT FROM recorridocursor INTO @IdRutRec, @Numero
				END
				CLOSE recorridocursor
				DEALLOCATE recorridocursor
			END

		 END

		IF(@operacion <> 'p')
			SELECT '1'
		ELSE
		BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Rutas))
				SELECT * FROM #rutas
			IF(EXISTS(SELECT TOP 1 * FROM @RutasRecorridos))
				SELECT * FROM #recorridos
		END

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Autoriza]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_Autoriza]
	@Sys_Autoriza [dbo].[dataTypeSys_Autoriza] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Sys_Autoriza
			 SET 
			 IdConcepto = t2.IdConcepto,ConceptoAut = t2.ConceptoAut,Inactivo = t2.Inactivo
		     FROM Sys_Autoriza t1
			 JOIN @Sys_Autoriza t2 ON t1.IdConcepto = t2.IdConcepto
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_Autoriza(
			 IdConcepto,ConceptoAut,Inactivo
			 )
			 SELECT 
			 IdConcepto,ConceptoAut,Inactivo
			 FROM @Sys_Autoriza
			 WHERE IdConcepto NOT IN(SELECT IdConcepto FROM Sys_Autoriza)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdConcepto FROM @Sys_Autoriza
			 DELETE FROM Sys_Autoriza WHERE IdConcepto = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Cnxextna]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_Cnxextna]
	@Sys_Cnxextna [dbo].[dataTypeSys_Cnxextna] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Sys_Cnxextna
			 SET 
			 IdReg = t2.IdReg, CnxTipo = t2.CnxTipo, CnxEngine = t2.CnxEngine, CnxDso = t2.CnxDso,
			 CnxDbname = t2.CnxDbname, CnxAutentic = t2.CnxAutentic, CnxUid = t2.CnxUid, CnxPwd = t2.CnxPwd,
			 CnxOwner = t2.CnxOwner, CnxPpties = t2.CnxPpties, CnxObserv = t2.CnxObserv, CnxDriver = t2.CnxDriver,
			 CnxPort = t2.CnxPort, CnxTerminal = t2.CnxTerminal
		     FROM Sys_Cnxextna t1
			 JOIN @Sys_Cnxextna t2 ON t1.IdReg = t2.IdReg
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_Cnxextna(
			 IdReg, CnxTipo, CnxEngine, CnxDso, CnxDbname, CnxAutentic, CnxUid, CnxPwd, 
			 CnxOwner, CnxPpties,  CnxObserv, CnxDriver, CnxPort, CnxTerminal
			 )
			 SELECT 
			 IdReg, CnxTipo, CnxEngine, CnxDso, CnxDbname, CnxAutentic, CnxUid, CnxPwd, 
			 CnxOwner, CnxPpties,  CnxObserv, CnxDriver, CnxPort, CnxTerminal			 
			 FROM @Sys_Cnxextna
			 WHERE IdReg NOT IN(SELECT IdReg FROM Sys_Cnxextna)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @idreg int
			 SELECT @idreg = IdReg FROM @Sys_Cnxextna
			 DELETE FROM Sys_Cnxextna WHERE IdReg = @idreg
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Estaciones]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_Estaciones]
	@Sys_Estaciones [dbo].[dataTypeSys_Estaciones] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Sys_Estaciones
			 SET 
			 IdEstacion = t2.IdEstacion, Estacion = t2.Estacion
		     FROM Sys_Estaciones t1
			 JOIN @Sys_Estaciones t2 ON t1.IdEstacion = t2.IdEstacion
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_Estaciones(
			 IdEstacion, Estacion
			 )
			 SELECT 
			 IdEstacion, Estacion
			 FROM @Sys_Estaciones
			 WHERE IdEstacion NOT IN(SELECT IdEstacion FROM Sys_Estaciones)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(2)
			 SELECT @id = IdEstacion FROM @Sys_Estaciones
			 DELETE FROM Sys_Estaciones WHERE IdEstacion = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_FmtDoc]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_FmtDoc]
	@Sys_FmtDoc [dbo].[dataTypeSys_FmtDoc] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Sys_FmtDoc
			 SET 
			 IdDoc = t2.IdDoc,IdForma = t2.IdForma,Descripcion = t2.Descripcion,Formato = t2.Formato,
			 Predtmnado = t2.Predtmnado,TipoPapel = t2.TipoPapel,Orientacion = t2.Orientacion,
			 VistaPrevia = t2.VistaPrevia,VerSetup = t2.VerSetup,NumCopias = t2.NumCopias,sp_Nombre = t2.sp_Nombre,
			 Ind_Location = t2.Ind_Location
		     FROM Sys_FmtDoc t1
			 JOIN @Sys_FmtDoc t2 ON t1.IdDoc = t2.IdDoc and t1.IdForma = t2.IdForma 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_FmtDoc(
			 IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
			 )
			 SELECT 
			 IdDoc,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
			 FROM @Sys_FmtDoc
			 WHERE (IdDoc + IdForma NOT IN(SELECT IdDoc + IdForma FROM Sys_FmtDoc)) 
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @IdDoc varchar(3)
			 DECLARE @IdForma varchar(2)
			 SELECT @IdDoc = IdDoc, @IdForma = IdForma FROM @Sys_FmtDoc
			 DELETE FROM Sys_FmtDoc WHERE IdDoc = @IdDoc and IdForma = @IdForma
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_GruposUsu]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_GruposUsu]
	@Sys_GruposUsu [dbo].[dataTypeSys_GruposUsu] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Sys_GruposUsu
			 SET 
			 IdGrupo = t2.IdGrupo, Grupo = t2.Grupo, Descripcion = t2.Descripcion
		     FROM Sys_GruposUsu t1
			 JOIN @Sys_GruposUsu t2 ON t1.IdGrupo = t2.IdGrupo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_GruposUsu(
			 IdGrupo,Grupo,Descripcion
			 )
			 SELECT 
			 IdGrupo,Grupo,Descripcion
			 FROM @Sys_GruposUsu
			 WHERE IdGrupo NOT IN(SELECT IdGrupo FROM Sys_GruposUsu)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id int
			 SELECT @id = IdGrupo FROM @Sys_GruposUsu
			 DELETE FROM Sys_GruposUsu WHERE IdGrupo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Modulos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_Modulos]
	@Sys_Modulos [dbo].[dataTypeSys_Modulos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
		 	 --Actualizar los que existen
			 UPDATE Sys_Modulos
			 SET 
			 IdMod = t2.IdMod, Consecutivo = t2.Consecutivo, Descripcion = t2.Descripcion,
			 Valor = t2.Valor, nModulo = t2.nModulo
		     FROM Sys_Modulos t1
			 JOIN @Sys_Modulos t2 ON t1.IdMod = t2.IdMod
			 --Inserta los que no existen
			 INSERT INTO Sys_Modulos(
			 IdMod,Consecutivo,Descripcion,Valor,nModulo
			 )
			 SELECT IdMod,Consecutivo,Descripcion,Valor,nModulo 
			 FROM @Sys_Modulos 
			 WHERE IdMod NOT IN(SELECT IdMod FROM Sys_Modulos)
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_Modulos(
			 IdMod,Consecutivo,Descripcion,Valor,nModulo
			 )
			 SELECT 
			 IdMod,Consecutivo,Descripcion,Valor,nModulo
			 FROM @Sys_Modulos
			 WHERE IdMod NOT IN(SELECT IdMod FROM Sys_Modulos)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(3)
			 SELECT @id = IdMod FROM @Sys_Modulos
			 DELETE FROM Sys_Modulos WHERE IdMod = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Report]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_Report]
	@Sys_Report [dbo].[dataTypeSys_Report] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Sys_Report
			 SET 
			 TipoRep = t2.TipoRep, IdRep = t2.IdRep, Descripcion = t2.Descripcion, Formato = t2.Formato,
			 TipoPapel = t2.TipoPapel, Orientacion = t2.Orientacion, VistaPrevia = t2.VistaPrevia,
			 VerSetup = t2.VerSetup, NumCopias = t2.NumCopias, sp_Nombre = t2.sp_Nombre,
			 Ind_Location = t2.Ind_Location, NomRep = t2.NomRep
		     FROM Sys_Report t1
			 JOIN @Sys_Report t2 ON t1.TipoRep = t2.TipoRep and t1.IdRep = t2.IdRep
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Sys_Report(
			 TipoRep,IdRep,Descripcion,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location,NomRep
			 )
			 SELECT 
			 TipoRep,IdRep,Descripcion,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location,NomRep
			 FROM @Sys_Report
			 WHERE (TipoRep + IdRep) NOT IN(SELECT (TipoRep + IdRep) FROM Sys_Report)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @tiporep varchar(3)
			 DECLARE @idrep char(2)

			 SELECT @tiporep = TipoRep ,@idrep = IdRep FROM @Sys_Report
			 if(@idrep <> null)
				DELETE FROM Sys_Report WHERE TipoRep = @tiporep and IdRep = @idrep
			 else
				DELETE FROM Sys_Report WHERE TipoRep = @tiporep
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsSys_Security]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsSys_Security]
	@Sys_Security [dbo].[dataTypeSys_Security] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Sys_Security))
			begin
			 UPDATE Sys_Security
			 SET 
			 IdLla = t2.IdLla,Descripcion = t2.Descripcion,Pwd = t2.Pwd
			 FROM Sys_Security T1
			 JOIN @Sys_Security T2 ON T1.IdLla = T2.IdLla
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Sys_Security))
			BEGIN
			 INSERT INTO Sys_Security(
			 IdLla,Descripcion,Pwd
			 )
			 SELECT 
			 IdLla,Descripcion,Pwd
			 FROM @Sys_Security
			 WHERE IdLLa NOT IN(SELECT IdLla FROM Sys_Security)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdLla FROM @Sys_Security		
			 DELETE FROM Sys_Security WHERE IdLla = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTablaPor]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTablaPor]
	@TablaPor [dbo].[dataTypeTablaPor] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Tablapor
			 SET 
			 IdTarifa = t2.IdTarifa, Descripcion = t2.Descripcion,  IdClase = t2.IdClase, Tarifa = t2.Tarifa, 
			 Simbolo = t2.Simbolo, CdLocdad = t2.CdLocdad, Minimo = t2.Minimo, Maximo = t2.Maximo,  Inactivo = t2.Inactivo
		     FROM Tablapor t1
			 JOIN @TablaPor t2 ON t1.IdTarifa = t2.IdTarifa
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Tablapor(
			 IdTarifa, Descripcion, IdClase, Tarifa, Simbolo, CdLocdad, Minimo, Maximo, Inactivo)
			 SELECT 
			 IdTarifa, Descripcion, IdClase, Tarifa, Simbolo, CdLocdad, Minimo, Maximo, Inactivo
			 FROM @TablaPor
			 WHERE IdTarifa NOT IN(SELECT IdTarifa FROM Tablapor)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = idtarifa FROM @TablaPor
			 DELETE FROM Tablapor WHERE IdTarifa = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTarifasEsp]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTarifasEsp]
	@TarifasEsp [dbo].[dataTypeTarifasEsp] READONLY,
	@operacion [varchar](1),
	@IdUsuario [varchar](11) = null,
	@FechaCrea [datetime] = null
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		
	
		 CREATE TABLE #consolidado (
			 Numero		 INT					DEFAULT ((0))	NULL,
			 CdRuta		 VARCHAR (4)			DEFAULT ('0')   NULL,
			 IdOrigen	 VARCHAR (8)			NULL,
			 IdDestino	 VARCHAR (8)			NULL,
			 TipoTarifa	 VARCHAR (10)		DEFAULT ('RUTA')  NULL,
			 CdTipoVeh	 VARCHAR (4)			NULL,
			 TipAfilVeh	 VARCHAR (10)		NULL,
			 Kilometros	 DECIMAL (16, 4)		DEFAULT ((0))  NULL,
			 TarifClie	 MONEY				DEFAULT ((0))  NULL,
			 TarifPago	 MONEY				DEFAULT ((0))  NULL,
			 IdMneda	 VARCHAR (5)			DEFAULT ('COP')  NULL,
			 Inactivo	 BIT					DEFAULT ((0))	NULL,
			 FechaCrea	 SMALLDATETIME		NULL,
		 	 IdUsuario	 VARCHAR (11)		NULL,
			 VrDia		 MONEY				DEFAULT ((0))  NULL,
			 Horas		 INT					DEFAULT ((0))  NULL,
			 Nit         varchar(126)        DEFAULT ((0))  NULL,   
			 VrMonitor   decimal             DEFAULT ((0))  NULL,
			 TarifaXRuta BIT					DEFAULT ((1))	NULL,
			 Error      varchar(250)		null
			 )

		declare @CantRow int
		--declare @TAR varchar
		declare @item int 
		select @item =  isnull(MAX(Numero),0) from TarifasEsp

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TarifasEsp
			 SET 
			 Numero = t2.Numero,CdRuta = t2.CdRuta,IdOrigen = t2.IdOrigen,IdDestino = t2.IdDestino,
			 TipoTarifa = t2.TipoTarifa,CdTipoVeh = t2.CdTipoVeh,TipAfilVeh = t2.TipAfilVeh,
			 Kilometros = t2.Kilometros,TarifClie = t2.TarifClie,TarifPago = t2.TarifPago,
			 IdMneda = t2.IdMneda,Inactivo = t2.Inactivo,FechaCrea = t2.FechaCrea,
			 IdUsuario = t2.IdUsuario,VrDia = t2.VrDia, Horas = t2.Horas,Nit = t2.Nit,VrMonitor=t2.VrMonitor, TarifaXRuta=t2.TarifaXRuta
		     FROM TarifasEsp t1
			 JOIN @TarifasEsp t2 ON t1.Numero = t2.Numero
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 --select @CantRow = Count(t1.CdRuta) 
			 --from TarifasEsp t1 
			 --inner join @TarifasEsp t2 
			 --on t1.CdRuta= t2.CdRuta and t1.IdOrigen = t2.IdOrigen and t1.IdDestino = t2.IdDestino 
			 --and t1.TipoTarifa = t2.TipoTarifa  and t1.CdTipoVeh = t2.CdTipoVeh and t1.TipAfilVeh = t2.TipAfilVeh 
			 --and t1.IdMneda= t2.IdMneda
			 
			 --IF(@CantRow = 0)
			 --BEGIN
				 INSERT INTO TarifasEsp(
				 Numero,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
				 TarifClie,TarifPago,IdMneda,Inactivo,FechaCrea,IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta)
				 SELECT 
				 (@Item + ROW_NUMBER() OVER(ORDER BY Numero ASC)),CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
				 TarifClie,TarifPago,IdMneda,Inactivo,FechaCrea,IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta
				 FROM @TarifasEsp
				 WHERE Numero NOT IN(SELECT Numero FROM TarifasEsp)
			 --END
		 END

		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'p')
		 BEGIN
			DECLARE @Numero INT
			--DECLARE @TarifClie money
			--DECLARE @TarifPago money
			DECLARE tarifacursor CURSOR
			FOR SELECT Numero FROM @TarifasEsp
			OPEN tarifacursor
			FETCH NEXT FROM tarifacursor into @Numero
			declare @contador int
			select @contador = @item+1
			WHILE @@FETCH_STATUS = 0
			BEGIN
				BEGIN TRY

					select @CantRow = Count(t1.CdRuta) 
					from TarifasEsp t1 
					inner join @TarifasEsp t2 
					on t1.CdRuta= t2.CdRuta and t1.IdOrigen = t2.IdOrigen and t1.IdDestino = t2.IdDestino and t1.TipoTarifa = t2.TipoTarifa and t1.TarifaXRuta = t2.TarifaXRuta 
					and (t1.CdTipoVeh = t2.CdTipoVeh or  t1.CdTipoVeh is null or t1.CdTipoVeh = '') and (t1.TipAfilVeh = t2.TipAfilVeh or  t1.TipAfilVeh is null or t1.TipAfilVeh = '') 
					and t1.IdMneda= t2.IdMneda and t1.Nit = t2.Nit  where t2.numero = @Numero 

					----

					IF(@CantRow = 0)
					BEGIN
						IF(NOT EXISTS(SELECT Numero FROM TarifasEsp WHERE Numero = @contador))
						BEGIN
							--IF((@TarifClie > @TarifPago) OR ((@TarifClie < @TarifPago) AND @TAR = '1'))
							--BEGIN
							 INSERT INTO TarifasEsp(
							 Numero,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
							 TarifClie,TarifPago,IdMneda,Inactivo,FechaCrea,IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta)
							 SELECT 
							 @contador,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
							 TarifClie,TarifPago,IdMneda,0,@FechaCrea,@IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta
							 FROM @TarifasEsp WHERE Numero = @Numero	
							--END
							--ELSE
							-- BEGIN 
							--  --SE AGREGA LA LINEA NO INSERTADA TARIFA DE COBRO MENOR A LA DE PAGO
							--  INSERT INTO #consolidado
							--  SELECT 
							--  Numero,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
							--  TarifClie,TarifPago,IdMneda,0,@FechaCrea,@IdUsuario,VrDia,Horas,'LA TARIFA DE COBRO ES MENOR A LA TARIFA DE PAGO.'
							--  FROM @TarifasEsp WHERE Numero = @Numero
							--END
						 END
						 ELSE if(EXISTS(SELECT Numero FROM TarifasEsp WHERE Numero = @Numero))
						 BEGIN
							 --SE AGREGA LA LINEA NO INSERTADA PORQUE YA EXISTE
							 INSERT INTO #consolidado
							 SELECT 
							 Numero,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
							 TarifClie,TarifPago,IdMneda,0,@FechaCrea,@IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta,'La Tarifa ya existe.'
							 FROM @TarifasEsp WHERE Numero = @Numero
						 END
					END
					ELSE IF(@CantRow >= 1)
					BEGIN
						--SE AGREGA LA LINEA NO INSERTADA PORQUE YA EXISTE UNA TARIFA IGUALES CONDICIONES
						INSERT INTO #consolidado
						SELECT 
						Numero,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
						TarifClie,TarifPago,IdMneda,0,@FechaCrea,@IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta,'Existe una tarifa con las mismas condiciones.'
						FROM @TarifasEsp WHERE Numero = @Numero
					END
				END TRY
				BEGIN CATCH
				 --SE AGREGA LA LINEA NO INSERTADA
				 INSERT INTO #consolidado
				 SELECT 
				 Numero,CdRuta,IdOrigen,IdDestino,TipoTarifa,CdTipoVeh,TipAfilVeh,Kilometros,
				 TarifClie,TarifPago,IdMneda,0,@FechaCrea,@IdUsuario,VrDia,Horas,Nit,VrMonitor,TarifaXRuta,ERROR_MESSAGE()
				 FROM @TarifasEsp WHERE Numero = @Numero
				END CATCH
				select @contador = @contador +1
			   FETCH NEXT FROM tarifacursor INTO @Numero
			END
			CLOSE tarifacursor
			DEALLOCATE tarifacursor
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = Numero FROM @TarifasEsp
			 DELETE FROM TarifasEsp WHERE Numero = @id
		 END

		IF(@operacion <> 'p')
			SELECT '1'
		else
			select * from #consolidado

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercAccionistas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[paWcfSeInsTercAccionistas]
	@TercAccionistas dbo.dataTypeTercAccionistas READONLY
AS
BEGIN
		SET NOCOUNT ON;

		DECLARE @filasAfectadas INT = 0;  

		UPDATE T --Se actualizan los registros que ya existen
		SET
			T.NitAccionista = D.NitAccionista,
			T.NomAccionista = D.NomAccionista,
			T.Participacion = D.Participacion
		FROM TercAccionistas AS T
		INNER JOIN  @TercAccionistas AS D ON T.IdTercero = D.IdTercero		
					AND T.NitAccionista = D.NitAccionista;
		SET @filasAfectadas += @@ROWCOUNT;
		INSERT INTO TercAccionistas(IdTercero,NitAccionista,NomAccionista,Participacion) 
		SELECT 
			D.IdTercero,
			D.NitAccionista,
			D.NomAccionista,
			D.Participacion
		FROM @TercAccionistas AS D
		WHERE NOT EXISTS(
			SELECT 1
			FROM TercAccionistas AS T
			WHERE T.IdTercero = D.IdTercero AND T.NitAccionista = D.NitAccionista
		)
		SET @filasAfectadas += @@ROWCOUNT;
		  IF (@filasAfectadas = 0)
			  BEGIN
				SELECT 'No se insertó nada nuevo' AS Mensaje;
			  END
		  ELSE
			BEGIN
				SELECT '1' AS Mensaje;
			END
END
PRINT'[paWcfSeInsTercAccionistas] creado'
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndCapac]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercCndCapac]
	@TercCndCapac [dbo].[dataTypeTercCndCapac] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Item),0) FROM TercCndCapac WHERE IdConductor = (select IdConductor from @TercCndCapac)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercCndCapac
			 SET 
			 IdConductor = t2.IdConductor,Item = t2.Item,IdClase = t2.IdClase,Fecha = t2.Fecha,FecVence = t2.FecVence,Habilitado = t2.Habilitado
		     FROM TercCndCapac t1
			 JOIN @TercCndCapac t2 ON t1.IdConductor = t2.IdConductor and t1.Item = t2.Item

		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercCndCapac(
			 IdConductor,Item,IdClase,Fecha,FecVence,Habilitado
			 )
			 SELECT 
			 IdConductor,Item,IdClase,Fecha,FecVence,Habilitado
			 FROM @TercCndCapac
			 WHERE (IdConductor + Convert(varchar, (@Item+1))) NOT IN(SELECT IdConductor + Convert(varchar, Item) FROM TercCndCapac)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdConductor, @item = Item FROM @TercCndCapac
			 DELETE FROM TercCndCapac WHERE IdConductor = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndContrato]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercCndContrato]
	@TercCndContrato [dbo].[dataTypeTercCndContrato] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercCndContrato
			 SET 
			 NumContrato = t2.NumContrato, IdConductor = t2.IdConductor,
			 IdTipCon = t2.IdTipCon, IdModd = t2.IdModd,
			 FecIngreso = t2.FecIngreso, FecRetiro = t2.FecRetiro,
			 FecVigencia = t2.FecVigencia, Observaciones = t2.Observaciones,
			 FecUpdate = t2.FecUpdate, IdUsuario = t2.IdUsuario
		     FROM TercCndContrato t1
			 JOIN @TercCndContrato t2 ON t1.IdConductor = t2.IdConductor and t1.NumContrato = t2.NumContrato

			 --Actualizar tabla TercCndtores
			 if((select FecRetiro from @TercCndContrato) <> null)
			 begin
				 update TercCndtores 
				 set				 
				 CdTipCon = t2.IdTipCon, Fec_Ingreso = t2.FecIngreso, Fec_Vigencia = t2.FecVigencia,
				 Contrato_Activo = '0', Fec_Retiro = t2.FecRetiro,
				 FechaUpdate = CURRENT_TIMESTAMP
				 from TercCndtores t1
				 JOIN @TercCndContrato t2 ON t1.IdConductor = t2.IdConductor and t1.Num_Contrato = t2.NumContrato
			 end
			 else 
			 begin
				 update TercCndtores 
				 set 
				 Num_Contrato = t2.NumContrato, Contrato_Activo = '1', CdTipCon = t2.IdTipCon
				 ,Fec_Ingreso = t2.FecIngreso, Fec_Vigencia = t2.FecVigencia
				 ,FechaUpdate = CURRENT_TIMESTAMP
				 from TercCndtores t1
				 JOIN @TercCndContrato t2 ON t1.IdConductor = t2.IdConductor and t1.Num_Contrato = t2.NumContrato
			 end
		 END
 
		--INSERT NO-EXISTE RECORDS
		IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercCndContrato(
			 NumContrato,IdConductor,IdTipCon,IdModd,FecIngreso,FecRetiro,FecVigencia,Observaciones,FecUpdate,IdUsuario
			 )
			 SELECT 
			 NumContrato,IdConductor,IdTipCon,IdModd,FecIngreso,FecRetiro,FecVigencia,Observaciones,FecUpdate,IdUsuario
			 FROM @TercCndContrato
			 WHERE (Convert(varchar,NumContrato) + IdConductor) NOT IN(SELECT (Convert(varchar,NumContrato)+IdConductor) FROM TercCndContrato)

			 --Actualizar tabla TercCndtores
			 update TercCndtores 
			 set 
			 Num_Contrato = t2.NumContrato, Contrato_Activo = '1', CdTipCon = t2.IdTipCon
			 ,Fec_Ingreso = t2.FecIngreso, Fec_Retiro = t2.FecRetiro, Fec_Vigencia = t2.FecVigencia
			 ,FechaUpdate = CURRENT_TIMESTAMP
			 from TercCndtores t1
			 JOIN @TercCndContrato t2 ON t1.IdConductor = t2.IdConductor

		 END

		--DELETE RECORDS
		IF(@operacion = 'd')
		BEGIN
			DECLARE @id varchar(16)
			declare @num int
			SELECT @num = NumContrato FROM @TercCndContrato
			SELECT @id = IdConductor FROM @TercCndContrato
			DELETE FROM TercCndContrato WHERE IdConductor = @id and NumContrato = @num
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndDoc]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercCndDoc]
	@TercCndDoc [dbo].[dataTypeTercCndDoc] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Item),0) FROM TercCndDoc WHERE IdConductor = (select IdConductor from @TercCndDoc)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercCndDoc
			 SET 
			 IdConductor = t2.IdConductor,Item = t2.Item,IdDoc = t2.IdDoc,Fecha = t2.Fecha,
			 FecVence = t2.FecVence,Radicado = t2.Radicado,Descripcion = t2.Descripcion
		     FROM TercCndDoc t1
			 JOIN @TercCndDoc t2 ON t1.IdConductor = t2.IdConductor and t1.Item = t2.Item
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercCndDoc(
			 IdConductor,Item,IdDoc,Fecha,FecVence,Radicado,Descripcion
			 )
			 SELECT 
			 IdConductor,(@item + 1),IdDoc,Fecha,FecVence,Radicado,Descripcion
			 FROM @TercCndDoc
			 WHERE (IdConductor + Convert(varchar, (@item + 1))) NOT IN(SELECT (IdConductor + Convert(varchar, Item)) FROM TercCndDoc)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdConductor, @item = Item FROM @TercCndDoc
			 DELETE FROM TercCndDoc WHERE IdConductor = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndReferencias]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercCndReferencias]
	@TercCndReferencias [dbo].[dataTypeTercCndReferencias] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Item),0) FROM TercCndReferencias WHERE IdConductor = (select IdConductor from @TercCndReferencias)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercCndReferencias
			 SET 
			 CargoRef = t2.CargoRef,ContactoRef = t2.ContactoRef,CuentaBanco = t2.CuentaBanco,
			 DireccionRef = t2.DireccionRef,EmailRef = t2.EmailRef,EmpresaRef = t2.EmpresaRef,
			 FechaFinal = t2.FechaFinal,FechaInicial = t2.FechaInicial,IdConductor = t2.IdConductor,
			 Item = t2.Item,NitRef = t2.NitRef,ObservRef = t2.ObservRef,TelefonoRef = t2.TelefonoRef,
			 TipoRef = t2.TipoRef,Verificado = t2.Verificado
		     FROM TercCndReferencias t1
			 JOIN @TercCndReferencias t2 ON t1.IdConductor = t2.IdConductor and t1.Item = t2.Item
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercCndReferencias(
			 CargoRef,ContactoRef,CuentaBanco,DireccionRef,EmailRef,EmpresaRef,
			 FechaFinal,FechaInicial,IdConductor,Item,NitRef,ObservRef,TelefonoRef,
			 TipoRef,Verificado
			 )
			 SELECT 
			 CargoRef,ContactoRef,CuentaBanco,DireccionRef,EmailRef,EmpresaRef,
			 FechaFinal,FechaInicial,IdConductor,(@item+1),NitRef,ObservRef,TelefonoRef,
			 TipoRef,Verificado			 
			 FROM @TercCndReferencias
			 WHERE (IdConductor + Convert(varchar, (@item + 1))) NOT IN(SELECT (IdConductor +Convert(varchar, Item)) FROM TercCndReferencias)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdConductor, @item = Item FROM @TercCndReferencias
			 DELETE FROM TercCndReferencias WHERE IdConductor = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndTarjetas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercCndTarjetas]
	@TercCndTarjetas [dbo].[dataTypeTercCndTarjetas] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Item),0) FROM TercCndTarjetas WHERE IdConductor = (select IdConductor from @TercCndTarjetas)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercCndTarjetas
			 SET 
			 IdConductor = t2.IdConductor,Item = t2.Item,NumeroTarj = t2.NumeroTarj,
			 Secuencia = t2.Secuencia,Fecha = t2.Fecha,FecVence = t2.FecVence
		     FROM TercCndTarjetas t1
			 JOIN @TercCndTarjetas t2 ON t1.IdConductor = t2.IdConductor and t1.Item = t2.Item
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercCndTarjetas(
			 IdConductor,Item,NumeroTarj,Secuencia,Fecha,FecVence
			 )
			 SELECT 
			 IdConductor,Item,NumeroTarj,Secuencia,Fecha,FecVence
			 FROM @TercCndTarjetas
			 WHERE (IdConductor +'_'+ Convert(varchar,Item)) NOT IN(SELECT (IdConductor +'_'+ Convert(varchar,Item)) FROM TercCndTarjetas)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdConductor, @item = Item FROM @TercCndTarjetas
			 DELETE FROM TercCndTarjetas WHERE IdConductor = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercCndtores]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercCndtores]
	@TercCndtores [dbo].[dataTypeTercCndtores] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercCndtores
			 SET 
			 IdConductor = t2.IdConductor, IdGrupo = t2.IdGrupo, IdModd = t2.IdModd, 
			 TipoSangre = t2.TipoSangre, FactorRh = t2.FactorRh, FecNacmto = t2.FecNacmto, 
			 LugarNacmto = t2.LugarNacmto, Sexo = t2.Sexo, IdEstCivil = t2.IdEstCivil, 
			 NHijos = t2.NHijos, LibMilitar = t2.LibMilitar, ClaseLib = t2.ClaseLib, 
			 FechaLib = t2.FechaLib, DistMil = t2.DistMil, CertJudicial = t2.CertJudicial, 
			 FecJudicial = t2.FecJudicial, VigJudicial = t2.VigJudicial, Pasporte = t2.Pasporte, 
			 VigPaspte = t2.VigPaspte, Licencia = t2.Licencia, IdLugar = t2.IdLugar, 
			 CatLicencia = t2.CatLicencia, FecLicencia = t2.FecLicencia, VigLicencia = t2.VigLicencia, 
			 IdClase = t2.IdClase, NumCuenta = t2.NumCuenta, IdBanco = t2.IdBanco, 
			 CdLocCue = t2.CdLocCue, CdFonPen = t2.CdFonPen, CdFonEps = t2.CdFonEps, 
			 CdFonArp = t2.CdFonArp, pVehiculo = t2.pVehiculo, PathFoto = t2.PathFoto, 
			 PathFirma = t2.PathFirma, PathLic = t2.PathLic, Cmntarios = t2.Cmntarios, 
			 IdEstado = t2.IdEstado, Inactivo = t2.Inactivo, NumTarjeta = t2.NumTarjeta, 
			 EdicTarjeta = t2.EdicTarjeta, FecTarjeta = t2.FecTarjeta, VigTarjeta = t2.VigTarjeta, 
			 PasSeguridad = t2.PasSeguridad, FecPasSeg = t2.FecPasSeg, VigPasSeg = t2.VigPasSeg, 
			 NitEmpTrans = t2.NitEmpTrans, FechaAdd = t2.FechaAdd, FechaUpdate = t2.FechaUpdate, 
			 IdUsuario = t2.IdUsuario, Num_Contrato = t2.Num_Contrato, Contrato_Activo = t2.Contrato_Activo, 
			 CdTipCon = t2.CdTipCon,  Fec_Ingreso = t2.Fec_Ingreso, Fec_Retiro = t2.Fec_Retiro, 
			 Fec_Vigencia = t2.Fec_Vigencia, Fec_IngresoAnt = t2.Fec_IngresoAnt, Fec_UltimoAcc = t2.Fec_UltimoAcc, 
			 PasadoJudicial = t2.PasadoJudicial, Restriccion = t2.Restriccion, FecPagoPen = t2.FecPagoPen, 
			 FecPagoEps = t2.FecPagoEps, FecPagoArp = t2.FecPagoArp, CdTipoOper = t2.CdTipoOper 
		     FROM TercCndtores t1
			 JOIN @TercCndtores t2 ON t1.IdConductor = t2.IdConductor 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercCndtores(
			 IdConductor, IdGrupo, IdModd, TipoSangre, FactorRh, FecNacmto, 
			 LugarNacmto, Sexo, IdEstCivil, NHijos, LibMilitar, ClaseLib, 
			 FechaLib, DistMil, CertJudicial, FecJudicial, VigJudicial, Pasporte, 
			 VigPaspte, Licencia, IdLugar, CatLicencia, FecLicencia, VigLicencia, 
			 IdClase, NumCuenta, IdBanco, CdLocCue, CdFonPen, CdFonEps, 
			 CdFonArp,  pVehiculo, PathFoto, PathFirma, PathLic, Cmntarios, 
			 IdEstado, Inactivo, NumTarjeta, EdicTarjeta, FecTarjeta, VigTarjeta, 
			 PasSeguridad, FecPasSeg, VigPasSeg, NitEmpTrans, FechaAdd, FechaUpdate, 
			 IdUsuario, Num_Contrato, Contrato_Activo, CdTipCon, Fec_Ingreso, Fec_Retiro, 
			 Fec_Vigencia, Fec_IngresoAnt, Fec_UltimoAcc, PasadoJudicial, Restriccion, FecPagoPen, 
			 FecPagoEps, FecPagoArp, CdTipoOper 
			 )
			 SELECT 
			 IdConductor, IdGrupo, IdModd, TipoSangre, FactorRh, FecNacmto, 
			 LugarNacmto, Sexo, IdEstCivil, NHijos, LibMilitar, ClaseLib, 
			 FechaLib, DistMil, CertJudicial, FecJudicial, VigJudicial, Pasporte, 
			 VigPaspte, Licencia, IdLugar, CatLicencia, FecLicencia, VigLicencia, 
			 IdClase, NumCuenta, IdBanco, CdLocCue, CdFonPen, CdFonEps, 
			 CdFonArp,  pVehiculo, PathFoto, PathFirma, PathLic, Cmntarios, 
			 IdEstado, Inactivo, NumTarjeta, EdicTarjeta, FecTarjeta, VigTarjeta, 
			 PasSeguridad, FecPasSeg, VigPasSeg, NitEmpTrans, FechaAdd, FechaUpdate, 
			 IdUsuario, Num_Contrato, Contrato_Activo, CdTipCon, Fec_Ingreso, Fec_Retiro, 
			 Fec_Vigencia, Fec_IngresoAnt, Fec_UltimoAcc, PasadoJudicial, Restriccion, FecPagoPen, 
			 FecPagoEps, FecPagoArp, CdTipoOper 
			 FROM @TercCndtores
			 WHERE IdConductor NOT IN(SELECT IdConductor FROM TercCndtores)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdConductor FROM @TercCndtores
			 DELETE FROM TercCndtores WHERE IdConductor = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercDocumentos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercDocumentos] 
	@TercDocumentos dbo.dataTypeTercDocumentos READONLY
AS
BEGIN
	SET NOCOUNT ON;
		DECLARE @filasAfectadas INT = 0;
	 UPDATE T--Actualizo los documentos que ya existen
    SET
        Documento = D.Documento,
        CodDoc = D.CodDoc,
        Item = D.Item,
        Inactivo = D.Inactivo
    FROM TercDocumentos T
    INNER JOIN @TercDocumentos D  ON T.IdTercero = D.IdTercero
       AND T.Item      = D.Item; 
	SET @filasAfectadas += @@ROWCOUNT;

	INSERT INTO TercDocumentos (IdTercero, Documento, CodDoc, Item, Inactivo)--Iserto los nuevos
    SELECT
        IdTercero,
        Documento,
        CodDoc,
        Item,
        Inactivo
    FROM @TercDocumentos D
    WHERE NOT EXISTS (
        SELECT 1
        FROM TercDocumentos T
        WHERE T.IdTercero = D.IdTercero AND T.Item = D.Item
    )
	SET @filasAfectadas += @@ROWCOUNT;
	IF(@filasAfectadas = 0)
		BEGIN
			SELECT 'No se isertó nada nuevo' AS Mensaje
		END
	ELSE
		BEGIN
			SELECT '1' AS Mensaje;
		END
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTerceros]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTerceros]
	@Terceros [dbo].[dataTypeTerceros] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Terceros
			 SET 
			 IdTercero = t2.IdTercero, RazonSocial = t2.RazonSocial, Codigo = t2.Codigo, TipoId = t2.TipoId,
			 Dv = t2.Dv, NomCial = t2.NomCial, SiglaRaz = t2.SiglaRaz, Direccion = t2.Direccion, IdLocal = t2.IdLocal,
			 Telefono = t2.Telefono, Fax = t2.Fax, TelMovil = t2.TelMovil, SitioWeb = t2.SitioWeb, e_mail = t2.e_mail,
			 EsCliente = t2.EsCliente, EsVendedor = t2.EsVendedor, EsConductor = t2.EsConductor, EsPropietario = t2.EsPropietario,
			 EsProveedor = t2.EsProveedor, EsEmpleado = t2.EsEmpleado, EsOperario = t2.EsOperario, EsAccnista = t2.EsAccnista,
			 EsCiaAseg = t2.EsCiaAseg, EsCliePres = t2.EsCliePres, IdSector = t2.IdSector, IdProf = t2.IdProf, IdRegimen = t2.IdRegimen,
			 TipEnte = t2.TipEnte, IdLugarCed = t2.IdLugarCed, FecExpCed = t2.FecExpCed, Observacion = t2.Observacion,
			 IniStgNom = t2.IniStgNom, IdEstado = t2.IdEstado, Inactivo = t2.Inactivo, FechaAdd = t2.FechaAdd, FechaUpdate = t2.FechaUpdate,
			 IdUsuario = t2.IdUsuario, ImgFoto = t2.ImgFoto, ImgFirma = t2.ImgFirma, ImagenDoc1 = t2.ImagenDoc1, ImagenDoc2 = t2.ImagenDoc2, 
			 ImagenDoc3 = t2.ImagenDoc3, FechaNac = t2.FechaNac,IdEstOper = t2.IdEstOper, IdLocUbic = t2.IdLocUbic, DescUbicac = t2.DescUbicac, 
			 CdGrupoTerc = t2.CdGrupoTerc, RegimenFE = t2.RegimenFE, PN_RUT = t2.PN_RUT, RecPublicos = ISNULL(t2.RecPublicos,0),CargoPublico = t2.CargoPublicO,
			 FecInicioCP = t2.FecInicioCP, FecFinalCp = t2.FecFinalCp, PersonaPub = ISNULL(t2.PersonaPub, 0), CargoPersPub = t2.CargoPersPub,
			 FecInicioPP = t2.FecInicioPP, FecFinalPP = t2.FecFinalPP, VrIngresos = ISNULL(t2.VrIngresos,0),VrOtroIng = ISNULL(t2.VrOtroIng,0),
			 VrGastos = ISNULL(t2.VrGastos,0), VrActivos = ISNULL(t2.VrActivos, 0), VrPasivos = ISNULL(t2.VrPasivos,0), VrPatrimonio = ISNULL(t2.VrPatrimonio,0),
			 ConcOtrosIng = t2.ConcOtrosIng,OperActVirtual = ISNULL(t2.OperActVirtual,0), TipoOperVirtual = t2.TipoOperVirtual,LavadoActivos = ISNULL(t2.LavadoActivos,0),
			 RL_Nombre = t2.RL_Nombre, RL_Identificacion = t2.RL_Identificacion, RL_Direccion = t2.RL_Direccion, RL_CodCiudad = t2.RL_CodCiudad, 
			 RL_Telefono = t2.RL_Telefono, RL_Email = t2.RL_Email,
			 Asociado = ISNULL(t2.Asociado, 0) -- ← CAMPO NUEVO AGREGADO
		     FROM Terceros t1
			 JOIN @Terceros t2 ON t1.IdTercero = t2.IdTercero
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Terceros(
			 IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,
			 Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,
			 EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdProf,IdRegimen,TipEnte,
			 IdLugarCed,FecExpCed,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario,
			 ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,
			 CdGrupoTerc, RegimenFE, PN_RUT,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,
			 CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,
			 VrOtroIng,VrGastos,VrActivos,VrPasivos,VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,
			 LavadoActivos,RL_Nombre,RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,
			 Asociado -- ← CAMPO NUEVO AGREGADO
			 )
			 SELECT 
			 IdTercero,RazonSocial,Codigo,TipoId,Dv,NomCial,SiglaRaz,Direccion,IdLocal,Telefono,
			 Fax,TelMovil,SitioWeb,e_mail,EsCliente,EsVendedor,EsConductor,EsPropietario,EsProveedor,
			 EsEmpleado,EsOperario,EsAccnista,EsCiaAseg,EsCliePres,IdSector,IdProf,IdRegimen,TipEnte,
			 IdLugarCed,FecExpCed,Observacion,IniStgNom,IdEstado,Inactivo,FechaAdd,FechaUpdate,IdUsuario,
			 ImgFoto,ImgFirma,ImagenDoc1,ImagenDoc2,ImagenDoc3,FechaNac,IdEstOper,IdLocUbic,DescUbicac,
			 CdGrupoTerc,RegimenFE, PN_RUT,RecPublicos,CargoPublico,FecInicioCP,FecFinalCp,PersonaPub,
			 CargoPersPub,FecInicioPP,FecFinalPP,VrIngresos,VrOtroIng,VrGastos,VrActivos,VrPasivos,
			 VrPatrimonio,ConcOtrosIng,OperActVirtual,TipoOperVirtual,LavadoActivos,RL_Nombre,
			 RL_Identificacion,RL_Direccion,RL_CodCiudad,RL_Telefono,RL_Email,
			 ISNULL(Asociado, 0) -- ← CAMPO NUEVO AGREGADO
			 FROM @Terceros
			 WHERE IdTercero NOT IN(SELECT IdTercero FROM Terceros)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdTercero FROM @Terceros
			 DELETE FROM Terceros WHERE IdTercero = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTercPropietario]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTercPropietario]
	@TercPropietario [dbo].[dataTypeTercPropietario] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TercPropietario
			 SET 
			 IdPropietario = t2.IdPropietario, IdGrupo = t2.IdGrupo, CupoCredito = t2.CupoCredito, 
			 SaldoActual = t2.SaldoActual, Avala = t2.Avala, IdAdmon = t2.IdAdmon, IdTipCon = t2.IdTipCon,
			 ContratoActivo = t2.ContratoActivo, FecIngreso = t2.FecIngreso, FecRetiro = t2.FecRetiro,
			 FecVigencia = t2.FecVigencia, Observacion = t2.Observacion, IdEstado = t2.IdEstado,
			 FechaAdd = t2.FechaAdd, FechaUpdate = t2.FechaUpdate, IdUsuario = t2.IdUsuario
		     FROM TercPropietario t1
			 JOIN @TercPropietario t2 ON t1.IdPropietario = t2.IdPropietario
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TercPropietario(
			 IdPropietario,IdGrupo,CupoCredito,SaldoActual,Avala,IdAdmon,IdTipCon,
			 ContratoActivo,FecIngreso,FecRetiro,FecVigencia,Observacion,IdEstado,
			 FechaAdd,FechaUpdate,IdUsuario
			 )
			 SELECT 
			 IdPropietario,IdGrupo,CupoCredito,SaldoActual,Avala,IdAdmon,IdTipCon,
			 ContratoActivo,FecIngreso,FecRetiro,FecVigencia,Observacion,IdEstado,
			 FechaAdd,FechaUpdate,IdUsuario
			 FROM @TercPropietario
			 WHERE IdPropietario NOT IN(SELECT IdPropietario FROM TercPropietario)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(16)
			 SELECT @id = IdPropietario FROM @TercPropietario
			 DELETE FROM TercPropietario WHERE IdPropietario = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposAdm]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposAdm]
	@TiposAdm [dbo].[dataTypeTiposAdm] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposAdm
			 SET 
			 IdAdmon = t2.IdAdmon, TipoAdmon = t2.TipoAdmon, Inactivo = t2.Inactivo
		     FROM TiposAdm t1
			 JOIN @TiposAdm t2 ON t1.IdAdmon = t2.IdAdmon
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposAdm(
			 IdAdmon,TipoAdmon,Inactivo
			 )
			 SELECT 
			 IdAdmon,TipoAdmon,Inactivo
			 FROM @TiposAdm
			 WHERE IdAdmon NOT IN(SELECT IdAdmon FROM TiposAdm)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdAdmon FROM @TiposAdm
			 DELETE FROM TiposAdm WHERE IdAdmon = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCalendarPgr]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposCalendarPgr]
	@TiposCalendarPgr [dbo].[dataTypeTiposCalendarPgr] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposCalendarPgr
			 SET 
			 Codigo = t2.Codigo, Dias = t2.Dias, Inactivo = t2.Inactivo,IncFestivo = t2.IncFestivo
		     FROM TiposCalendarPgr t1
			 JOIN @TiposCalendarPgr t2 ON t1.Codigo = t2.Codigo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposCalendarPgr(
			 Codigo,Dias,Inactivo,IncFestivo
			 )
			 SELECT 
			 Codigo,Dias,Inactivo,IncFestivo
			 FROM @TiposCalendarPgr
			 WHERE (Codigo+''+ Dias) NOT IN(SELECT (Codigo+''+Dias) FROM TiposCalendarPgr)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(3)
			 SELECT @id = Codigo FROM @TiposCalendarPgr
			 DELETE FROM TiposCalendarPgr WHERE Codigo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0


GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCatLic]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposCatLic]
	@TiposCatLic [dbo].[dataTypeTiposCatLic] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposCatLic
			 SET
			 IdCateg = t2.IdCateg,CategMT = t2.CategMT 
		     FROM TiposCatLic t1
			 JOIN @TiposCatLic t2 ON t1.IdCateg = t2.IdCateg
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposCatLic(
			 IdCateg, CategMT
			 )
			 SELECT 
			 IdCateg, CategMT
			 FROM @TiposCatLic
			 WHERE IdCateg NOT IN(SELECT IdCateg FROM TiposCatLic)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id int
			 SELECT @id = IdCateg FROM @TiposCatLic
			 DELETE FROM TiposCatLic WHERE IdCateg = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCol]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposCol]
	@TiposCol [dbo].[dataTypeTiposCol] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposCol
			 SET 
			 IdColor = t2.IdColor,NomColor = t2.NomColor,NColor = t2.NColor,Inactivo = t2.Inactivo,CodigoMT = t2.CodigoMT
		     FROM TiposCol t1
			 JOIN @TiposCol t2 ON t1.IdColor = t2.IdColor
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposCol(
			 IdColor,NomColor,NColor,Inactivo,CodigoMT
			 )
			 SELECT 
			 IdColor,NomColor,NColor,Inactivo,CodigoMT
			 FROM @TiposCol
			 WHERE IdColor NOT IN(SELECT IdColor FROM TiposCol)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdColor FROM @TiposCol
			 DELETE FROM TiposCol WHERE IdColor = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposComFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposComFmt]
	@TiposComFmt [dbo].[dataTypeTiposComFmt] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @TiposComFmt))
			begin
			 UPDATE TiposComFmt
			 SET 
			 IdCom = t2.IdCom, IdForma = t2.IdForma, Descripcion = t2.Descripcion,
			 Formato = t2.Formato, Predtmnado = t2.Predtmnado, TipoPapel = t2.TipoPapel,
			 Orientacion = t2.Orientacion, VistaPrevia = t2.VistaPrevia, VerSetup = t2.VerSetup,
			 NumCopias = t2.NumCopias, sp_Nombre = t2.sp_Nombre, Ind_Location = t2.Ind_Location
			 FROM TiposComFmt T1
			 JOIN @TiposComFmt T2 ON T1.IdCom = T2.IdCom and T1.IdForma = T2.IdForma
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @TiposComFmt))
			BEGIN
			 INSERT INTO TiposComFmt(
			 IdCom,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
			 )
			 SELECT 
			 IdCom,IdForma,Descripcion,Formato,Predtmnado,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,sp_Nombre,Ind_Location
			 FROM @TiposComFmt
			 WHERE (IdCom + IdForma) NOT IN(SELECT (IdCom + IdForma) FROM TiposComFmt)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @idcom varchar(3)
			 DECLARE @idforma varchar(2)
			 SELECT @idcom = IdCom, @idforma = IdForma FROM @TiposComFmt		
			 DELETE FROM TiposComFmt WHERE IdCom = @idcom and IdForma = @idforma
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposCon]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposCon]
	@TiposCon [dbo].[dataTypeTiposCon] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposCon
			 SET
			 IdTipCon = t2.IdTipCon, TipoContrato = t2.TipoContrato, Duracion = t2.Duracion,
			 Inactivo = t2.Inactivo, VincLabUgpp = t2.VincLabUgpp
		     FROM TiposCon t1
			 JOIN @TiposCon t2 ON t1.IdTipCon = t2.IdTipCon
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposCon(
			 IdTipCon,TipoContrato,Duracion,Inactivo,VincLabUgpp
			 )
			 SELECT 
			 IdTipCon,TipoContrato,Duracion,Inactivo,VincLabUgpp
			 FROM @TiposCon
			 WHERE IdTipCon NOT IN(SELECT IdTipCon FROM TiposCon)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdTipCon FROM @TiposCon
			 DELETE FROM TiposCon WHERE IdTipCon = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposDocumentos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposDocumentos]
	@Sys_TiposDoc [dbo].[dataTypeSys_TiposDoc] READONLY,
	@Sys_TiposDocCue [dbo].[dataTypeSys_TiposDocCue] READONLY,
	@TiposDocCons [dbo].[dataTypeTiposDocCons] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Sys_TiposDoc))
			begin
			 UPDATE Sys_TiposDoc
			 SET 
			 IdDoc = t2.IdDoc, TipoDoc = t2.TipoDoc,
			 ConsUnico = t2.ConsUnico, Leyenda = t2.Leyenda,
			 Inactivo = t2.Inactivo, IntegraCias = t2.IntegraCias
			 FROM Sys_TiposDoc t1
			 JOIN @Sys_TiposDoc t2 ON t1.IdDoc = t2.IdDoc
			 WHERE t1.IdDoc = t2.IdDoc
			end

			IF(EXISTS(SELECT TOP 1 * FROM @Sys_TiposDocCue))
			begin
			 --Actualizar los que existen
			 UPDATE Sys_TiposDocCue
			 SET 
			 IdDoc = t2.IdDoc, IdClase = t2.IdClase,
			 ClaseCuenta = t2.ClaseCuenta, TipoMov = t2.TipoMov
			 FROM Sys_TiposDocCue t1
			 JOIN @Sys_TiposDocCue t2 ON t1.IdDoc = t2.IdDoc and t1.IdClase = t2.IdClase
			 WHERE t1.IdDoc = t2.IdDoc and t1.IdClase = t2.IdClase
			 --Inserta los que no existen
			 INSERT INTO Sys_TiposDocCue(
			 IdDoc,IdClase,ClaseCuenta,TipoMov)
			 SELECT 
			 IdDoc,IdClase,ClaseCuenta,TipoMov
			 FROM @Sys_TiposDocCue
			 WHERE (IdDoc+Convert(varchar,IdClase)) NOT IN(SELECT (IdDoc+Convert(varchar,IdClase)) FROM Sys_TiposDocCue)
			end

			IF(EXISTS(SELECT TOP 1 * FROM @TiposDocCons))
			begin
			 --Actualizar los que existen
			 UPDATE TiposDocCons
			 SET 
			 IdDoc = t2.IdDoc, IdCia = t2.IdCia, LDesde = t2.LDesde,
			 LHasta = t2.LHasta, Resolucion = t2.Resolucion, RangoNum = t2.RangoNum, 
			 FechaRes = t2.FechaRes, Prefijo = t2.Prefijo, Numero = t2.Numero, 
			 NumManual = t2.NumManual, IntLotes = t2.IntLotes,ConfigFecha = t2.ConfigFecha, 
			 Formato = t2.Formato, TipoPapel = t2.TipoPapel, Orientacion = t2.Orientacion, 
			 VistaPrevia = t2.VistaPrevia, VerSetup = t2.VerSetup, NumCopias = t2.NumCopias, 
			 FechaAdd = t2.FechaAdd, FechaUpdate = t2.FechaUpdate, FechaVigRes=t2.FechaVigRes,
			 ClaveTecDian=t2.ClaveTecDian, CodResol = t2.CodResol
			 FROM TiposDocCons T1
			 JOIN @TiposDocCons T2 ON T1.IdDoc = T2.IdDoc and T1.IdCia = T2.IdCia
			 --Inserta los que no existen
			 INSERT INTO TiposDocCons(
			 IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,
			 FechaRes,Prefijo,Numero,NumManual,IntLotes,ConfigFecha,
			 Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,
			 FechaAdd,FechaUpdate,FechaVigRes,ClaveTecDian,CodResol
			 )
			 SELECT 
			 IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,
			 FechaRes,Prefijo,Numero,NumManual,IntLotes,ConfigFecha,
			 Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,
			 FechaAdd,FechaUpdate,FechaVigRes,ClaveTecDian,CodResol
			 FROM @TiposDocCons
			 WHERE (IdDoc+IdCia) NOT IN(SELECT (IdDoc+IdCia) FROM TiposDocCons)
			end			
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @Sys_TiposDoc))
			BEGIN
			 INSERT INTO Sys_TiposDoc(
			 IdDoc,TipoDoc,ConsUnico,Leyenda,Inactivo,IntegraCias
			 )
			 SELECT 
			 IdDoc,TipoDoc,ConsUnico,Leyenda,Inactivo,IntegraCias
			 FROM @Sys_TiposDoc
			 WHERE IdDoc NOT IN(SELECT IdDoc FROM Sys_TiposDoc)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @Sys_TiposDocCue))
			BEGIN
			 INSERT INTO Sys_TiposDocCue(
			 IdDoc,IdClase,ClaseCuenta,TipoMov
			 )
			 SELECT 
			 IdDoc,IdClase,ClaseCuenta,TipoMov
			 FROM @Sys_TiposDocCue
			 WHERE (IdDoc+Convert(varchar,IdClase)) NOT IN(SELECT (IdDoc+Convert(varchar,IdClase)) FROM Sys_TiposDocCue)
			END

			IF(EXISTS(SELECT TOP 1 * FROM @TiposDocCons))
			BEGIN
			 INSERT INTO TiposDocCons(
			 IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,
			 FechaRes,Prefijo,Numero,NumManual,IntLotes,ConfigFecha,
			 Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,
			 FechaAdd,FechaUpdate,FechaVigRes,ClaveTecDian,CodResol
			 )
			 SELECT 
			 IdDoc,IdCia,LDesde,LHasta,Resolucion,RangoNum,
			 FechaRes,Prefijo,Numero,NumManual,IntLotes,ConfigFecha,
			 Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,
			 FechaAdd,FechaUpdate,FechaVigRes,ClaveTecDian,CodResol
			 FROM @TiposDocCons
			 WHERE (IdDoc+IdCia) NOT IN(SELECT (IdDoc+IdCia) FROM TiposDocCons)
			END

		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id VARCHAR (11)
			
			 IF(EXISTS(SELECT TOP 1 * FROM @Sys_TiposDocCue))
			 BEGIN 
				SELECT @id = IdDoc FROM @Sys_TiposDocCue
				DELETE FROM Sys_TiposDocCue WHERE IdDoc = @id
			 END

			 IF(EXISTS(SELECT TOP 1 * FROM @TiposDocCons))
			 BEGIN 
				SELECT @id = IdDoc FROM @TiposDocCons
				DELETE FROM TiposDocCons WHERE IdDoc = @id
			 END

			 IF(EXISTS(SELECT TOP 1 * FROM @Sys_TiposDoc))	
			 BEGIN
				SELECT @id = IdDoc FROM @Sys_TiposDoc
				DELETE FROM Sys_TiposDoc WHERE IdDoc = @id	
			 END
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposFuel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposFuel]
	@TiposFuel [dbo].[dataTypeTiposFuel] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposFuel
			 SET 
			 IdCom = t2.IdCom, TipoComb = t2.TipoComb, Inactivo = t2.Inactivo
		     FROM TiposFuel t1
			 JOIN @TiposFuel t2 ON t1.IdCom = t2.IdCom
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposFuel(
			 IdCom,TipoComb,Inactivo
			 )
			 SELECT 
			 IdCom,TipoComb,Inactivo
			 FROM @TiposFuel
			 WHERE IdCom NOT IN(SELECT IdCom FROM TiposFuel)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdCom FROM @TiposFuel
			 DELETE FROM TiposFuel WHERE IdCom = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposLla]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposLla]
	@TiposLla [dbo].[dataTypeTiposLla] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposLla
			 SET 
			 IdTlla = t2.IdTlla,TipoLlanta = t2.TipoLlanta,Inactivo = t2.Inactivo
		     FROM TiposLla t1
			 JOIN @TiposLla t2 ON t1.IdTlla = t2.IdTlla
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposLla(
			 IdTlla,TipoLlanta,Inactivo
			 )
			 SELECT 
			 IdTlla,TipoLlanta,Inactivo
			 FROM @TiposLla
			 WHERE IdTlla NOT IN(SELECT IdTlla FROM TiposLla)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdTlla FROM @TiposLla
			 DELETE FROM TiposLla WHERE IdTlla = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposLub]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposLub]
	@TiposLub [dbo].[dataTypeTiposLub] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposLub
			 SET 
			 IdLub = t2.IdLub,TipoLub = t2.TipoLub,Inactivo = t2.Inactivo
		     FROM TiposLub t1
			 JOIN @TiposLub t2 ON t1.IdLub = t2.IdLub
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposLub(
			 IdLub,TipoLub,Inactivo
			 )
			 SELECT 
			 IdLub,TipoLub,Inactivo
			 FROM @TiposLub
			 WHERE IdLub NOT IN(SELECT IdLub FROM TiposLub)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdLub FROM @TiposLub
			 DELETE FROM TiposLub WHERE IdLub = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposMod]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposMod]
	@TiposMod [dbo].[dataTypeTiposMod] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposMod
			 SET 
			 IdModd = t2.IdModd,Modalidad = t2.Modalidad,Inactivo = t2.Inactivo
		     FROM TiposMod t1
			 JOIN @TiposMod t2 ON t1.IdModd = t2.IdModd
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposMod(
			 IdModd,Modalidad,Inactivo
			 )
			 SELECT 
			 IdModd,Modalidad,Inactivo
			 FROM @TiposMod
			 WHERE IdModd NOT IN(SELECT IdModd FROM TiposMod)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdModd FROM @TiposMod
			 DELETE FROM TiposMod WHERE IdModd = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposMot]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposMot]
	@TiposMot [dbo].[dataTypeTiposMot] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposMot
			 SET 
			 IdTipoMot = t2.IdTipoMot,TipoMotor = t2.TipoMotor,Inactivo = t2.Inactivo
		     FROM TiposMot t1
			 JOIN @TiposMot t2 ON t1.IdTipoMot = t2.IdTipoMot
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposMot(
			 IdTipoMot,TipoMotor,Inactivo	
			 )
			 SELECT 
			 IdTipoMot,TipoMotor,Inactivo	
			 FROM @TiposMot
			 WHERE IdTipoMot NOT IN(SELECT IdTipoMot FROM TiposMot)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdTipoMot FROM @TiposMot
			 DELETE FROM TiposMot WHERE IdTipoMot = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposNivs]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposNivs]
	@TiposNivs [dbo].[dataTypeTiposNivs] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposNivs
			 SET 
			 IdNiv = t2.IdNiv, NivelServicio = t2.NivelServicio, Inactivo = t2.Inactivo
		     FROM TiposNivs t1
			 JOIN @TiposNivs t2 ON t1.IdNiv = t2.IdNiv
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposNivs(
			 IdNiv, NivelServicio, Inactivo
			 )
			 SELECT 
			 IdNiv, NivelServicio, Inactivo
			 FROM @TiposNivs
			 WHERE IdNiv NOT IN(SELECT IdNiv FROM TiposNivs)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdNiv FROM @TiposNivs
			 DELETE FROM TiposNivs WHERE IdNiv = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposNovPgr]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposNovPgr]
	@TiposNovPgr [dbo].[dataTypeTiposNovPgr] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposNovPgr
			 SET 
			 IdNovedad = t2.IdNovedad,Novedad = t2.Novedad, Tipo = t2.Tipo,IdEstado = t2.IdEstado,Inactivo = t2.Inactivo
		     FROM TiposNovPgr t1
			 JOIN @TiposNovPgr t2 ON t1.IdNovedad = t2.IdNovedad
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposNovPgr(
			 IdNovedad,Novedad,Tipo,IdEstado,Inactivo
			 )
			 SELECT 
			 IdNovedad,Novedad,Tipo,IdEstado,Inactivo
			 FROM @TiposNovPgr
			 WHERE IdNovedad NOT IN(SELECT IdNovedad FROM TiposNovPgr)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdNovedad FROM @TiposNovPgr
			 DELETE FROM TiposNovPgr WHERE IdNovedad = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposOperac]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposOperac]
	@TiposOperac [dbo].[dataTypeTiposOperac] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposOperac
			 SET 
			 IdTipoOper = t2.IdTipoOper,TipoOperacion = t2.TipoOperacion,Inactivo = t2.Inactivo
		     FROM TiposOperac t1
			 JOIN @TiposOperac t2 ON t1.IdTipoOper = t2.IdTipoOper
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposOperac(
			 IdTipoOper,TipoOperacion,Inactivo
			 )
			 SELECT 
			 IdTipoOper,TipoOperacion,Inactivo
			 FROM @TiposOperac
			 WHERE IdTipoOper NOT IN(SELECT IdTipoOper FROM TiposOperac)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdTipoOper FROM @TiposOperac
			 DELETE FROM TiposOperac WHERE IdTipoOper = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposPpt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposPpt]
	@TiposPpt [dbo].[dataTypeTiposPpt] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @TiposPpt))
			begin
			 UPDATE TiposPpt
			 SET 
			 IdPpd = t2.IdPpd,TipoProp = t2.TipoProp,VehPropio = t2.VehPropio,Inactivo = t2.Inactivo
			 FROM TiposPpt T1
			 JOIN @TiposPpt T2 ON T1.IdPpd = T2.IdPpd
			end
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @TiposPpt))
			BEGIN
			 INSERT INTO TiposPpt(
			 IdPpd,TipoProp,VehPropio,Inactivo
			 )
			 SELECT 
			 IdPpd,TipoProp,VehPropio,Inactivo
			 FROM @TiposPpt
			 WHERE IdPpd NOT IN(SELECT IdPpd FROM TiposPpt)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdPpd FROM @TiposPpt		
			 DELETE FROM TiposPpt WHERE IdPpd = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposVeh]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposVeh]
	@TiposVeh [dbo].[dataTypeTiposVeh] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposVeh
			 SET
			 IdTipoVeh = t2.IdTipoVeh, TipoVehiculo = t2.TipoVehiculo, Configuracion = t2.Configuracion, Ejes = t2.Ejes, 
			 Llantas = t2.Llantas, CapacPeso = t2.CapacPeso, UndCapac = t2.UndCapac, CapacVol = t2.CapacVol, 
			 UndCapVol = t2.UndCapVol, CubAlto = t2.CubAlto, CubLargo = t2.CubLargo, CubAncho = t2.CubAncho, 
			 PesoBruto = t2.PesoBruto, Inactivo = t2.Inactivo 
		     FROM TiposVeh t1
			 JOIN @TiposVeh t2 ON t1.IdTipoVeh = t2.IdTipoVeh
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposVeh(
			 IdTipoVeh, TipoVehiculo, Configuracion, Ejes, Llantas, CapacPeso, UndCapac, CapacVol, 
			 UndCapVol, CubAlto, CubLargo, CubAncho, PesoBruto, Inactivo
			 )
			 SELECT 
			 IdTipoVeh, TipoVehiculo, Configuracion, Ejes, Llantas, CapacPeso, UndCapac, CapacVol, 
			 UndCapVol, CubAlto, CubLargo, CubAncho, PesoBruto, Inactivo
			 FROM @TiposVeh
			 WHERE IdTipoVeh NOT IN(SELECT IdTipoVeh FROM TiposVeh)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdTipoVeh FROM @TiposVeh
			 DELETE FROM TiposVeh WHERE IdTipoVeh = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTiposVehFactor]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTiposVehFactor]
	@TiposVehFactor [dbo].[dataTypeTiposVehFactor] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TiposVehFactor
			 SET 
			 IdTipoVeh = t2.IdTipoVeh,nSemana = t2.nSemana,TarifaFc = t2.TarifaFc
		     FROM TiposVehFactor t1
			 JOIN @TiposVehFactor t2 ON t1.IdTipoVeh = t2.IdTipoVeh and t1.nSemana = t2.nSemana
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TiposVehFactor(
			 IdTipoVeh,nSemana,TarifaFc
			 )
			 SELECT 
			 IdTipoVeh,nSemana,TarifaFc
			 FROM @TiposVehFactor
			 WHERE IdTipoVeh + '_' + Convert(varchar,nSemana) NOT IN(SELECT IdTipoVeh + '_' + Convert(varchar,nSemana) FROM TiposVehFactor)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 declare @nsem int
			 SELECT @id = IdTipoVeh, @nsem = nSemana FROM @TiposVehFactor
			 DELETE FROM TiposVehFactor WHERE IdTipoVeh = @id and nSemana = @nsem
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraConcCausac]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraConcCausac]
	@TraConcCausac [dbo].[dataTypeTraConcCausac] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @TraConcCausac))
			begin
			 UPDATE TraConcCausac
			 SET
			  IdConcepto = t2.IdConcepto,
			  Concepto = t2.Concepto,
			  IdCuenta = t2.IdCuenta,
			  TipoConc = t2.TipoConc,
			  Inactivo = t2.Inactivo
			 FROM TraConcCausac t1
			 JOIN @TraConcCausac t2 ON t1.IdConcepto = t2.IdConcepto
			 WHERE t1.IdConcepto = t2.IdConcepto
			end
							
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(EXISTS(SELECT TOP 1 * FROM @TraConcCausac))
			BEGIN
			INSERT INTO TraConcCausac(
			IdConcepto,Concepto,IdCuenta,TipoConc,Inactivo
			)
			SELECT 
			IdConcepto,Concepto,IdCuenta,TipoConc,Inactivo
			FROM @TraConcCausac
			WHERE IdConcepto NOT IN(SELECT IdConcepto FROM TraConcCausac)
			END
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @_id VARCHAR(4)
			 
			 IF(EXISTS(SELECT TOP 1 * FROM @TraConcCausac))	
			 BEGIN
				SELECT @_id = IdConcepto FROM @TraConcCausac
				DELETE FROM TraConcCausac WHERE IdConcepto = @_id			 
			 END
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspColegios]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraEspColegios]
	@TraEspColegios [dbo].[dataTypeTraEspColegios] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TraEspColegios
			 SET 
			 IdColegio = t2.IdColegio,NomColegio = t2.NomColegio,IdGrupo = t2.IdGrupo,Inactivo = t2.Inactivo
		     FROM TraEspColegios t1
			 JOIN @TraEspColegios t2 ON t1.IdColegio = t2.IdColegio
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TraEspColegios(
			 IdColegio,NomColegio,IdGrupo,Inactivo
			 )
			 SELECT 
			 IdColegio,NomColegio,IdGrupo,Inactivo
			 FROM @TraEspColegios
			 WHERE IdColegio NOT IN(SELECT IdColegio FROM TraEspColegios)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdColegio FROM @TraEspColegios
			 DELETE FROM TraEspColegios WHERE IdColegio = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspGruposCol]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraEspGruposCol]
	@TraEspGruposCol [dbo].[dataTypeTraEspGruposCol] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TraEspGruposCol
			 SET 
			 IdGrupo = t2.IdGrupo,Grupo = t2.Grupo,Inactivo = t2.Inactivo
		     FROM TraEspGruposCol t1
			 JOIN @TraEspGruposCol t2 ON t1.IdGrupo = t2.IdGrupo
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TraEspGruposCol(
			 IdGrupo,Grupo,Inactivo
			 )
			 SELECT 
			 IdGrupo,Grupo,Inactivo
			 FROM @TraEspGruposCol
			 WHERE IdGrupo NOT IN(SELECT IdGrupo FROM TraEspGruposCol)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdGrupo FROM @TraEspGruposCol
			 DELETE FROM TraEspGruposCol WHERE IdGrupo = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspHorario]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraEspHorario]
	@TraEspHorario [dbo].[dataTypeTraEspHorario] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TraEspHorario
			 SET 
			 IdHorario = t2.IdHorario, Item = t2.Item, Inicio = t2.Inicio, Final = t2.Final, Inactivo = t2.Inactivo
		     FROM TraEspHorario t1
			 JOIN @TraEspHorario t2 ON t1.IdHorario = t2.IdHorario and t1.Item = t2.Item 
			 --Insertar lo que no existe
			 INSERT INTO TraEspHorario(
			 IdHorario,Item,Inicio,Final,Inactivo
			 )
			 SELECT 
			 IdHorario,Item,Inicio,Final,Inactivo
			 FROM @TraEspHorario
			 WHERE (IdHorario + Convert(varchar,Item)) NOT IN(SELECT (IdHorario + Convert(varchar,Item)) FROM TraEspHorario)
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TraEspHorario(
			 IdHorario,Item,Inicio,Final,Inactivo
			 )
			 SELECT 
			 IdHorario,Item,Inicio,Final,Inactivo
			 FROM @TraEspHorario
			 WHERE (IdHorario + Convert(varchar,Item)) NOT IN(SELECT (IdHorario + Convert(varchar,Item)) FROM TraEspHorario)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 DECLARE @item varchar(4)
			 SELECT @id = IdHorario, @item = Item FROM @TraEspHorario
			 DELETE FROM TraEspHorario WHERE IdHorario = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspObjContratos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraEspObjContratos]
	@TraEspObjContratos [dbo].[dataTypeTraEspObjContratos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY
		DECLARE  @Pdtminado bit	
		IF(@operacion = 'u' OR @operacion = 'i')
		BEGIN	 
			select TOP (1) @Pdtminado = Predtminado from @TraEspObjContratos
		END
		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			IF(@Pdtminado = 1)
			BEGIN
				UPDATE TraEspObjContratos SET Predtminado = 0
			END
			 UPDATE TraEspObjContratos
			 SET 
			 IdObj = t2.IdObj,Objeto = t2.Objeto, Predtminado = t2.Predtminado ,Inactivo = t2.Inactivo
		     FROM TraEspObjContratos t1
			 JOIN @TraEspObjContratos t2 ON t1.IdObj = t2.IdObj
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			IF(@Pdtminado = 1)
			BEGIN
				UPDATE TraEspObjContratos SET Predtminado = 0
			END
			 INSERT INTO TraEspObjContratos(
			 IdObj,Objeto,Predtminado,Inactivo
			 )
			 SELECT 
			 IdObj,Objeto,Predtminado,Inactivo
			 FROM @TraEspObjContratos
			 WHERE IdObj NOT IN(SELECT IdObj FROM TraEspObjContratos)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(4)
			 SELECT @id = IdObj FROM @TraEspObjContratos
			 DELETE FROM TraEspObjContratos WHERE IdObj = @id
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraEspPolizas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraEspPolizas]
	@TraEspPolizas [dbo].[dataTypeTraEspPolizas] READONLY,
	@TraEspPolDetalle [dbo].[dataTypeTraEspPolDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo de las Polizas
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento de las Polizas 
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia de las Polizas
declare @item int
	BEGIN TRAN
		BEGIN TRY

			--Seleccionar Variables
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia FROM @TraEspPolizas
				SELECT @Documento = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

				IF(@Documento <> '')
					UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
				ELSE
				BEGIN
					SELECT @Documento = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			end

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			   if(EXISTS(SELECT * FROM @TraEspPolizas))
			   begin
			   UPDATE TraEspPolizas
			   SET 
			   TipDoc = t2.TipDoc,NumDoc = t2.NumDoc,IdCia = t2.IdCia,Fecha = t2.Fecha,FechaExp = t2.FechaExp,FechaVence = t2.FechaVence,
			   TipoPol = t2.TipoPol,IdProv = t2.IdProv,NumPoliza = t2.NumPoliza,VrPoliza = t2.VrPoliza,VrCobro = t2.VrCobro,
			   IdTipoVeh = t2.IdTipoVeh,TipoAfil = t2.TipoAfil,Todos = t2.Todos,OnlyActivos = t2.OnlyActivos,IdVehiculo = t2.IdVehiculo,
			   IdConcepto = t2.IdConcepto,TipCom = t2.TipCom,Comprobante = t2.Comprobante,IdCiaCom = t2.IdCiaCom,NCuotasOtros = t2.NCuotasOtros,NCuotasSocios = t2.NCuotasSocios,
			   IdMneda = t2.IdMneda,OrigenAdd = t2.OrigenAdd,IdEstado = t2.IdEstado,TimeSys = t2.TimeSys,FecUpdate = t2.FecUpdate,
			   IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario,Inactivo = t2.Inactivo
		       FROM TraEspPolizas t1
			   JOIN @TraEspPolizas t2 ON t1.TipDoc = t2.TipDoc and t1.NumDoc = t2.NumDoc and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @TraEspPolDetalle))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = NumDoc FROM @TraEspPolDetalle
			   select @item = isnull(MAX(Item),0) from TraEspPolDetalle where TipDoc = @TipDoc and NumDoc = @Documento and IdCia = @IdCia

			   --actualizar los que vienen en el tipo de dato y coincida con los que ya estÃ¡n en la tabla
			   UPDATE TraEspPolDetalle
			   SET 
			   TipDoc = t2.TipDoc,NumDoc = t2.NumDoc,IdCia = t2.IdCia,Item = t2.Item,IdVehiculo = t2.IdVehiculo
		       FROM TraEspPolDetalle t1
			   JOIN @TraEspPolDetalle t2 ON t1.TipDoc = t2.TipDoc and t1.NumDoc = t2.NumDoc and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.NumDoc = t2.NumDoc and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO TraEspPolDetalle(
			   TipDoc,NumDoc,IdCia,Item,IdVehiculo
			   ) 
			   SELECT 
			   @TipDoc,@Documento,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),IdVehiculo
			   FROM @TraEspPolDetalle
			   WHERE (TipDoc + Convert(varchar,NumDoc)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,NumDoc)+IdCia+Convert(varchar,Item)) FROM TraEspPolDetalle)
			   --Eliminar los que no existen en lo que envian
			   delete from TraEspPolDetalle
			   WHERE TipDoc = @TipDoc and NumDoc = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @TraEspPolDetalle)

			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN
			  	select @item = isnull(MAX(Item),0) from TraEspPolDetalle where TipDoc = @TipDoc and NumDoc = @Documento and IdCia = @IdCia

				IF(EXISTS(SELECT * FROM @TraEspPolizas))
				begin
				INSERT INTO TraEspPolizas(
				TipDoc,NumDoc,IdCia,Fecha,FechaExp,FechaVence,TipoPol,IdProv,NumPoliza,VrPoliza,VrCobro,IdTipoVeh,TipoAfil,Todos,
				OnlyActivos,IdVehiculo,IdConcepto,TipCom,Comprobante,IdCiaCom,NCuotasOtros,NCuotasSocios,IdMneda,OrigenAdd,IdEstado,TimeSys,FecUpdate,
				IdCiaCrea,IdUsuario,Inactivo
				)
				SELECT 
				@TipDoc,@Documento,@IdCia,Fecha,FechaExp,FechaVence,TipoPol,IdProv,NumPoliza,VrPoliza,VrCobro,IdTipoVeh,TipoAfil,Todos,
				OnlyActivos,IdVehiculo,IdConcepto,TipCom,Comprobante,IdCiaCom,NCuotasOtros,NCuotasSocios,IdMneda,OrigenAdd,IdEstado,TimeSys,FecUpdate,
				IdCiaCrea,IdUsuario,Inactivo
				FROM @TraEspPolizas
				end

				IF(EXISTS(SELECT * FROM @TraEspPolDetalle))
				begin
				INSERT INTO TraEspPolDetalle(
				TipDoc,NumDoc,IdCia,Item,IdVehiculo
				) 
				SELECT 
				@TipDoc,@Documento,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),IdVehiculo
				FROM @TraEspPolDetalle
				end

			 END

			 IF(@operacion = 'i' or @operacion = 'u')
			 begin
			    UPDATE Vehiculos
				SET FecRCivil = t3.FechaExp , VigRCivil = t3.FechaVence, RespCivil = T3.NumPoliza
				FROM Vehiculos t1, @TraEspPolDetalle t2, @TraEspPolizas t3
				WHERE t1.IdVehiculo = t2.IdVehiculo and t3.TipoPol = 'RCC'

				UPDATE VehAnexo
				SET FecEmisionRCE = t3.FechaExp , FecVigenciaRCE = t3.FechaVence, PolizaRCE = T3.NumPoliza
				FROM VehAnexo t1, @TraEspPolDetalle t2, @TraEspPolizas t3
				WHERE t1.IdVehiculo = t2.IdVehiculo and t3.TipoPol <> 'RCC'
			end

			SELECT @Documento

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTraFijos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTraFijos]
	@TraFijos [dbo].[dataTypeTraFijos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		if(@operacion = 'i')
		begin
			SELECT @item = isnull(MAX(Numero),0) + 1 FROM  TraFijos 
		end 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE TraFijos
			 SET 
			 Numero = t2.Numero,IdConcepto = t2.IdConcepto,DescConc = t2.DescConc,TipoConc = t2.TipoConc,Tarifa = t2.Tarifa,
			 TipoTarif = t2.TipoTarif,TipoAfilVeh = t2.TipoAfilVeh,CdTipoVeh = t2.CdTipoVeh,TipoTerc = t2.TipoTerc,Anulado = t2.Anulado,
			 CdCiuOrigen = t2.CdCiuOrigen,CdCiuDestino = t2.CdCiuDestino,pVehiculo = t2.pVehiculo,CedConductor = t2.CedConductor,CdRuta = t2.CdRuta,
			 TipoVigencia = t2.TipoVigencia, FechaInicial = t2.FechaInicial, FechaFinal = t2.FechaFinal, NitCliente = t2.NitCliente, CdMercancia = t2.CdMercancia
		     FROM TraFijos t1
			 JOIN @TraFijos t2 ON t1.Numero = t2.Numero and t1.IdConcepto = t2.IdConcepto
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO TraFijos(
			 Numero,IdConcepto,DescConc,TipoConc,Tarifa,TipoTarif,TipoAfilVeh,CdTipoVeh,TipoTerc,Anulado,CdCiuOrigen,CdCiuDestino,pVehiculo,
			 CedConductor,CdRuta,TipoVigencia,FechaInicial,FechaFinal,NitCliente,CdMercancia
			 )
			 SELECT 
			 @item,IdConcepto,DescConc,TipoConc,Tarifa,TipoTarif,TipoAfilVeh,CdTipoVeh,TipoTerc,Anulado,CdCiuOrigen,CdCiuDestino,pVehiculo,
			 CedConductor,CdRuta,TipoVigencia,FechaInicial,FechaFinal,NitCliente,CdMercancia
			 FROM @TraFijos
			 WHERE (Convert(varchar,Numero) + IdConcepto) NOT IN(SELECT (Convert(varchar,Numero) + IdConcepto) FROM TraFijos)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DELETE FROM TraFijos WHERE Numero = (Select Numero from @TraFijos)
			 -- and IdConcepto = (Select IdConcepto from @TraFijos)
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_Aprobacion]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_Aprobacion]
	@Trn_Aprobacion [dbo].[dataTypeTrn_Aprobacion] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el tipo de documento aprobaciÃ³n
DECLARE @IdCia VARCHAR(2) --En esta variable se guarda la compaÃ±ia del documento aprobaciÃ³n
DECLARE @Tabla VARCHAR(250) --En esta variable se guarda el nombre de la tabla que se acutalizarÃ¡ 
DECLARE @ColTabla VARCHAR(250) --En esta variable se guarda la columna que se actualizarÃ¡
DECLARE @Estado VARCHAR(4) --En esta variable se guarda el estado del documento que se aprobarÃ¡
DECLARE @TipoPed VARCHAR(3) --En esta variable se guarda el tipo del documento que se actualizarÃ¡
DECLARE @IdCiaPed VARCHAR(2) --En esta variable se guarda la compaÃ±ia del documento que se actualizarÃ¡
DECLARE @Pedido INT --En esta variable se guarda el numero del documento que se aprobarÃ¡
DECLARE @Fecha SMALLDATETIME --En esta variable se guarda la fecha del documento
	BEGIN TRAN
		BEGIN TRY
		    
			--Consecutivos
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Tabla = Tabla, @ColTabla = ColTabla, @TipoPed = TipoPed, @IdCiaPed = IdCiaPed, @Pedido = Pedido, @Fecha = Fecha FROM @Trn_Aprobacion
				SELECT @Documento = Numero + 1  FROM TiposDocCons WHERE IdDoc = @TipDoc and IdCia = @IdCia
				--SELECT @Estado = IdEstado FROM EstadoDoc WHERE Estado = 'ACTIVO'

				IF(@Documento <> '')
					UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
				ELSE
				BEGIN
					SELECT @Documento = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			end
			
			--UPDATE SI-EXISTE RECORDS
			 IF(@operacion = 'u')
			 BEGIN
			 UPDATE Trn_Aprobacion
			 SET 
			 TipDoc = t2.TipDoc,Aprobacion = t2.Aprobacion,IdCia = t2.IdCia,Fecha = t2.Fecha,
			 TipoPed = t2.TipoPed,Pedido = t2.Pedido,IdCiaPed = t2.IdCiaPed,FecPedido = t2.FecPedido,
			 IdCliente = t2.IdCliente,IdAgencia = t2.IdAgencia,pVehiculo = t2.pVehiculo,VrCupoCred = t2.VrCupoCred,
			 VrSaldoAct = t2.VrSaldoAct,ChequesDev = t2.ChequesDev,ClienteMora = t2.ClienteMora,OrigenAdd = t2.OrigenAdd,
			 Anulado = t2.Anulado,FecDev = t2.FecDev,Observacion = t2.Observacion,IdEstado = t2.IdEstado,
			 TimeSys = t2.TimeSys,FecUpdate = t2.FecUpdate,IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario
			 FROM Trn_Aprobacion t1
			 JOIN @Trn_Aprobacion t2 ON t1.TipDoc = t2.TipDoc and t1.Aprobacion = t2.Aprobacion and t1.IdCia = t2.IdCia
			 END

			--INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			BEGIN
			INSERT INTO Trn_Aprobacion(
			TipDoc, Aprobacion, IdCia, Fecha, TipoPed, Pedido, IdCiaPed, FecPedido, IdCliente, IdAgencia,
			pVehiculo, VrCupoCred, VrSaldoAct, ChequesDev, ClienteMora, OrigenAdd, Anulado, FecDev, Observacion, 
			IdEstado, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
			)
			SELECT			
			@TipDoc, @Documento, @IdCia, Fecha, TipoPed, Pedido, IdCiaPed, FecPedido, IdCliente, IdAgencia,
			pVehiculo, VrCupoCred, VrSaldoAct, ChequesDev, ClienteMora, OrigenAdd, Anulado, FecDev, Observacion, 
			'0001', TimeSys, FecUpdate, IdCiaCrea, IdUsuario			
			FROM @Trn_Aprobacion
			END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 DECLARE @Aprobacion int
			 SELECT @Aprobacion = Aprobacion FROM @Trn_Aprobacion
			 DELETE FROM Trn_Aprobacion WHERE TipDoc = @TipDoc and Aprobacion = @Aprobacion and IdCia = @IdCia
			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
			  declare @IdEstado varchar(4)
			  --select @IdEstado = IdEstado from EstadoDoc where Estado = 'ANULADO'
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Aprobacion from @Trn_Aprobacion
			  UPDATE Trn_Aprobacion SET IdEstado = '9999', Anulado = '1' WHERE TipDoc = @TipDoc and Aprobacion = @Documento and IdCia = @IdCia
			  --Actualizar Documento al cual se anula la aprobacion
			  SELECT TOP 1 @Tabla = Tabla, @ColTabla = ColTabla, @TipoPed = TipoPed, @IdCiaPed = IdCiaPed, @Pedido = Pedido FROM @Trn_Aprobacion
			  --SELECT @IdEstado = IdEstado from EstadoDoc where Estado = 'RADICADO'
			  EXEC('UPDATE '+@Tabla+' SET IdEstado = ''0002'', NumAprob = 0, IdCiaApr = ''00'' WHERE TipDoc = '''+@TipoPed+''' AND Idcia = '''+@IdciaPed+''' AND '+@ColTabla+' = '+@Pedido)
			END

			--IF(EXISTS(SELECT * FROM @Trn_Autoriza))
			--BEGIN
			--declare @numaut int
			--declare @idaut char(2) 
			--select @numaut = Autoriza, @idaut = IdCia from @dataTypeTrn_Autoriza

			--	UPDATE Trn_Autoriza SET IdEstado = '9998' WHERE Trn_Autoriza.NumAutoriza = @numaut AND Trn_Autoriza.IdCia = @idaut
			--END

			IF(@operacion = 'i')
			BEGIN
				SELECT @IdEstado = '0001'
				EXEC('UPDATE '+@Tabla+' SET IdEstado = '''+@IdEstado+''', NumAprob = '+@Documento+', IdCiaApr = '''+@IdCia+''', FecAprob = '''+@Fecha+'''  WHERE TipDoc = '''+@TipoPed+''' AND Idcia = '''+@IdciaPed+''' AND '+@ColTabla+' = '+@Pedido)
			END

			SELECT '1'

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
            DECLARE @ErrorSeverity INT;
            DECLARE @ErrorState INT;

		    SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR (
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_DevFco]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_DevFco]
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃƒÂºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃƒÂ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃƒÂºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃƒÂ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃƒÂºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃƒÂ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃƒÂ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃƒÂ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃƒÂ³n
	BEGIN TRAN
		BEGIN TRY		 
			
			--SELECT TOP 1 @TipDoc = TipDoc, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_DevFco
			--SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

			--IF(@Numero > 0)
			--	UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
			--ELSE
			--BEGIN
			--	SELECT @Numero = 1
			--	INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--END

			--IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			--BEGIN
			--	SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
			--	SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
			--	--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
			--	IF(@Comprobante <> '')
			--		UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
			--	ELSE
			--	BEGIN
			--		SELECT @Comprobante = 1
			--		INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--	END
			--END

			--IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			--BEGIN
			--	SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
			--	SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
			--	--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
			--	IF(@CompNiif <> '')
			--		UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
			--	ELSE
			--	BEGIN
			--		SELECT @CompNiif = 1
			--		INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--	END
			--END

			--IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			--BEGIN
			--	SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
			--	SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
			--	--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
			--	IF(@CompNiif <> '')
			--		UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
			--	ELSE
			--	BEGIN
			--		SELECT @CompFis = 1
			--		INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--	END
			--END
			
			--IF(@operacion = 'i')
			--begin
			--	IF(EXISTS(SELECT * FROM @Trn_DevFco))
			--	BEGIN
			--	INSERT INTO Trn_DevFco(
			--	TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,
			--	VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,BaseImp,BaseRet,IdCajero,
			--	IdVend,TarifaCom,CodTarCom,NitCliente,CdAgencia,IdCCosto,IdSubCos,IdLocal,EnEfectivo,Pedido,IdCiaPed,Remision,IdCiaRem,FecPedido,
			--	Modalidad,ModdDev,NumAutoriza,PlacaVehic,KmtVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,
			--	IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Fecha,IdConcepto,TipDoc,Factura,IdCiaDoc,FecDoc,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,
			--	VrReteICA,VrReteIVA,VrFletes,VrCargos,VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,BaseImp,BaseRet,IdCajero,
			--	IdVend,TarifaCom,CodTarCom,NitCliente,CdAgencia,IdCCosto,IdSubCos,IdLocal,EnEfectivo,Pedido,IdCiaPed,Remision,IdCiaRem,FecPedido,
			--	Modalidad,ModdDev,NumAutoriza,PlacaVehic,KmtVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,
			--	IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
			--	FROM @Trn_DevFco
			--	END 

			--	IF(EXISTS(SELECT * FROM @Trn_FacReservas))
			--	BEGIN
			--	INSERT INTO Trn_TraEspFacReservas(
			--	TipDoc,Factura,IdCia,Item,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,UndTarifa,
			--	TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
			--	pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Item,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,UndTarifa,
			--	TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
			--	pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct
			--	FROM @Trn_FacReservas
			--	END 

			--	IF(EXISTS(SELECT * FROM @Trn_Kardex))
			--	BEGIN
			--	INSERT INTO Trn_Kardex(
			--	TipDoc,Documento,IdCia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,
			--	TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,
			--	VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,
			--	IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,
			--	IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,
			--	ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,
			--	CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,
			--	Temperatura,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo,MgenCont,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,
			--	TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,
			--	VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,
			--	IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,
			--	IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,
			--	ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,
			--	CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,
			--	Temperatura,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo,MgenCont,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
			--	FROM @Trn_Kardex
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_Pagos))
			--	BEGIN
			--	INSERT INTO Trn_Pagos(
			--	TipDoc,Documento,IdCia,Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma,
			--	CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,
			--	CdCta,IdUsuario
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma,
			--	CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,
			--	CdCta,IdUsuario
			--	FROM @Trn_Pagos
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_DocMemo))
			--	BEGIN
			--	INSERT INTO Trn_DocMemo(
			--	TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Comentarios,Nota1,Nota2,Nota3,CantImp
			--	FROM @Trn_DocMemo
			--	END 

			--	IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			--	BEGIN
			--	INSERT INTO Trn_Comprobantes(
			--	TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			--	NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
			--	TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			--	VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			--	Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			--	PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero
			--	)
			--	SELECT 
			--	@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			--	NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
			--	TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			--	VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			--	Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			--	PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis
			--	FROM @Trn_Comprobantes
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			--	BEGIN
			--	INSERT INTO Trn_ComDetalle(
			--	TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
			--	IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
			--	IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
			--	NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
			--	CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
			--	IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
			--	)
			--	SELECT 
			--	@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
			--	IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
			--	CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
			--	NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
			--	CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
			--	IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
			--	FROM @Trn_ComDetalle
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			--	BEGIN
			--	INSERT INTO Trn_NiifComp(
			--	TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
			--	EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
			--	FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
			--	VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
			--	IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
			--	Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
			--	CtbTipo, CtbNumero,
			--	FisTipo, FisNumero 
			--	)
			--	SELECT 
			--	CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, CASE N.TipoNiif WHEN 'NIIF' THEN @IdCiaCompNiif ELSE @IdCiaCompFis END, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
			--	C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
			--	C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
			--	C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
			--	C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
			--	C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
			--	CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
			--	CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
			--	FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			--	BEGIN
			--	INSERT INTO Trn_NiifDetalle(
			--	TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
			--	VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
			--	VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
			--	NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
			--	NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
			--	CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
			--	DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
			--	CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
			--	FechAutoriza, CodCuentaCG
			--	)
			--	SELECT 
			--	CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @IdCiaCompNiif ELSE @IdCiaCompFis END, N.Item, C.Fecha, N.IdCuenta, N.Detalle,
			--	N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo, N.IdCCosto, N.IdSubCos,
			--	C.VrBase, C.TarifaBase, @TipDoc, @Numero, @Cia, C.CodConce,
			--	C.NitDoc, C.TipFac, C.Factura, C.IdCiaFac, C.ItemFac, C.FecVence, C.CodCta, 
			--	C.NumCheque, C.Integrado, C.TipoAplica, C.Consolida, C.CodCargo, C.NitOtros,
			--	C.CodSubgpo, C.CiuOrigen, C.CodAgncia, C.VehPropio, N.Referncia, C.TipDocRef,
			--	C.DocRef, C.IdCiaRef, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario,
			--	C.CdConcTrib, C.CdTarifTrib, C.NumEstablec,C.PtoEmision, C.Num_Autoriza,
			--	C.FechAutoriza, C.IdCuenta
			--	FROM @Trn_ComDetalle AS C JOIN @Trn_NiifDetalle AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont AND C.Item = N.Item JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
			--	END
			--end

			----IF(@operacion = 'i')
			----begin
			----  --actualiza los items de un contrato con los que se relacionan en el tipo de datos nuevo
			----  UPDATE Trn_TraEspResDetalle
			----  SET  EstadoItem = 'FACTURADA'
			----  FROM Trn_TraEspResDetalle d, @Trn_FacReservas r 
			----  WHERE d.TipDoc = r.TipRes  and d.Reserva = r.Reserva and d.IdCia = r.IdCia and d.Item = r.ItemRes
			----end
						
			--SELECT @Numero

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_DevFcr]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_DevFcr]
	@Trn_DevFcr [dbo].[dataTypeTrn_DevFcr] READONLY,
	@Trn_TraEspFacReservas [dbo].[dataTypeTrn_TraEspFacReservas] READONLY,
	@Trn_RecAfavor [dbo].[dataTypeTrn_RecAfavor] READONLY,
	@Trn_VencAbonos [dbo].[dataTypeTrn_VencAbonos] READONLY,
	@Trn_DocMemo [dbo].[dataTypeTrn_DocMemo] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
	DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
	DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
	DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

	DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
	DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
	DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

	DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
	DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
	DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

	DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n

	BEGIN TRAN
	BEGIN TRY		 
			
		declare @fecdev smalldatetime
		DECLARE @modalidad varchar(10)

		IF(@operacion = 'i')
		begin
			
			SELECT TOP 1 @TipDoc = TipDev, @Cia = IdCia,@fecdev = Fecha,@modalidad = ModdDev, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia 
			FROM @Trn_DevFcr

			SELECT @Numero = Numero + 1  
			FROM TiposDocCons 
			where IdDoc = @TipDoc 
				AND IdCia = @Cia

			IF(@Numero > 0)
				UPDATE TiposDocCons 
				SET Numero = @Numero 
				WHERE IdDoc = @TipDoc 
					AND IdCia = @Cia
			ELSE
			BEGIN
				SELECT @Numero = 1

				INSERT INTO TiposDocCons 
				VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom 
				FROM @Trn_Comprobantes

				SELECT @Comprobante = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipComp 
					AND IdCia = @IdCiaComp
				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons 
					SET Numero = @Comprobante 
					WHERE IdCom = @TipComp 
						and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1

					INSERT INTO TiposComCons 
					VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'NIIF'

				SELECT @CompNiif = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompNiif 
					AND IdCia = @IdCiaCompNiif
				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompNiif 
					WHERE IdCom = @TipCompNiif 
						and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'FISCAL'

				SELECT @CompFis = Numero + 1  
				FROM TiposComCons
				where IdCom  = @TipCompFis 
					AND IdCia = @IdCiaCompFis
				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompFis
					WHERE IdCom = @TipCompFis 
						and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END
		end

		IF(@operacion = 'i')
		begin
			IF(EXISTS(SELECT * FROM @Trn_DevFcr))
			BEGIN
				INSERT INTO Trn_DevFcr ( -- REVISAR
					TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,
					Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,
					VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,
					VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,
					VrFaltantes,VrAnticipos,VrNeto,Cantidad,CantPuntos,BaseImp,
					BaseRet,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,
					IdLocEnv,Pedido,IdCiaPed,Remision,IdCiaRem,Cotizacion,
					IdCiaCot,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,
					ZonaFrontera,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,
					IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,
					VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,
					DevMasivo,NumRecibo,CdCiaRec,CdMotDev,BaseIvaIgp,VrIvaIngProd,
					TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP
				)
				SELECT 
					@TipDoc,@Numero,@Cia,Fecha,IdConcepto,TipDoc,
					Factura,IdCiaDoc,FecDoc,IdCliente,IdAgencia,VrSubTotal,
					VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,
					VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,
					VrFaltantes,VrAnticipos,VrNeto,Cantidad,CantPuntos,BaseImp,
					BaseRet,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,
					IdLocEnv,Pedido,IdCiaPed,Remision,IdCiaRem,Cotizacion,
					IdCiaCot,FecPedido,Modalidad,ModdDev,PlacaVehic,KmtVehic,
					ZonaFrontera,OrigenAdd,@TipComp,@Comprobante,@IdCiaComp,Observacion,
					IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,
					VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio,VrImpCarbono,
					DevMasivo,NumRecibo,CdCiaRec,CdMotDev,BaseIvaIgp,VrIvaIngProd,
					TarifaArf,VrAutRetFte,TarifaAri,VrAutRetIca,VrImpuBA,VrImpuCUP
				FROM 
					@Trn_DevFcr
			END 

			IF(EXISTS(SELECT * FROM @Trn_TraEspFacReservas))
			BEGIN
				INSERT INTO Trn_TraEspFacReservas( -- REVISAR
					TipDoc,Factura,IdCia,Item,TipoReg,FechaFact,
					TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,
					Cantidad,VrServicio,VrUnitario,VrCosto,TarifaIva,VrImpuesto,
					TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,
					CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,pVehiculo,
					TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,
					IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,
					VrRetencion,TarifaIca,VrReteIca,EstadoItem
				)
				SELECT 
					@TipDoc,@Numero,@Cia,Item,TipoReg,FechaFact,
					TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,
					Cantidad,VrServicio,VrUnitario,VrCosto,TarifaIva,VrImpuesto,
					TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,
					CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,pVehiculo,
					TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,
					IdCiaRef,FecDocRef,CodTarDct,CodTarRet,CodTarIca,TarifaRet,
					VrRetencion,TarifaIca,VrReteIca,EstadoItem
				FROM 
					@Trn_TraEspFacReservas
			END

			IF(EXISTS(SELECT * FROM @Trn_RecAFavor))
			BEGIN
				INSERT INTO Trn_RecAFavor(
					TipDoc,	Recibo,	IdCia, Fecha, VrAFavor, VrOtrosDb,	
					VrAbono, IdCliente, IdAgencia, IdVend
				)
				SELECT
					@TipDoc, @Numero, @Cia,	Fecha, VrAFavor, VrOtrosDb,	
					VrAbono, IdCliente, IdAgencia, IdVend
				FROM 
					@Trn_RecAFavor
			END

			IF(EXISTS(SELECT * FROM @Trn_VencAbonos))
			BEGIN
				declare @tiprec varchar(3)
				declare @recibo int
				declare @idciarec varchar(2)
				declare @item int 

				SELECT TOP 1 @tiprec = TipRec, @idciarec = IdCia, @recibo = Recibo 
				FROM @Trn_VencAbonos

				select @item =  isnull(MAX(Item),0) 
				from Trn_VencAbonos 
				where TipRec = @tiprec	
					and Recibo = @recibo 
					and IdCia = @idciarec

				INSERT INTO Trn_VencAbonos( -- REVISAR
					TipRec,Recibo,IdCia,Item,Fecha,TipDoc,
					Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,
					IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,
					TipoAplica,TimeSys
				)
				SELECT 
					@TipDoc,@Numero,@Cia,(@item + ROW_NUMBER() OVER(ORDER BY Item ASC)),Fecha,TipDoc,
					Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,VrBaseCms,
					IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,
					TipoAplica,TimeSys
				FROM 
					@Trn_VencAbonos
			END 

			IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
			BEGIN
				INSERT INTO Trn_DetCuentas(
					TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,
					Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,
					pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac,
					FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,
					CodConc,CodTarif
				)
				SELECT 
					@TipDoc,@Numero,@Cia,Concepto,Item,IdCuenta,
					Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,
					pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac,
					FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,
					CodConc,CodTarif
				FROM 
					@Trn_DetCuentas
			END

			IF(EXISTS(SELECT * FROM @Trn_DocMemo))
			BEGIN
				INSERT INTO Trn_DocMemo(
					TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,
					Nota3,CantImp,ArchivoImg
				)
				SELECT 
					@TipDoc,@Numero,@Cia,Comentarios,Nota1,Nota2,
					Nota3,CantImp,ArchivoImg
				FROM 
					@Trn_DocMemo
			END 

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				INSERT INTO Trn_Comprobantes(
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, 
					IdCiaDoc, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
					CodRes, DescServicio
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, @TipDoc, @Numero, 
					@Cia, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
					CodRes, DescServicio
				FROM	
					@Trn_Comprobantes
			END

			IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			BEGIN
				INSERT INTO Trn_ComDetalle (
					TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, 
					Detalle, VrDebito, VrCredito,
					IdTercero, 
					IdVehiculo, 
					IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
					IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, 
					ItemFac, FecVence, CodCta, NumCheque, Integrado, TipoAplica, 
					Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia,
					VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, 
					FecUpdate, IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec,
					PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, C.Item, Fecha, 
					COALESCE(
						( -- Retencion en detalle, buscar tarifa
							SELECT DISTINCT T.IdCuenta
							FROM @Trn_TraEspFacReservas AS O
							LEFT JOIN TarifCuentas T ON T.IdTarifa = (
								CASE C.Referncia
									WHEN 'RETENCION EN LA FUENTE' THEN O.CodTarRet
									WHEN 'RETENCION ICA' THEN O.CodTarIca
								END)
								AND T.TipDoc = 'DFE'
							WHERE O.Reserva = C.DocRef
						),
						( -- Retencion en total, buscar tarifa
							SELECT T.IdCuenta
							FROM @Trn_DevFcr AS TDF
							LEFT JOIN Trn_Facturas AS TF ON TF.TipDoc = TDF.TipDoc
								AND TF.Factura = TDF.Factura
								AND TF.IdCia = TDF.IdCia
							LEFT JOIN TarifCuentas T ON T.IdTarifa = (
								CASE C.Referncia
									WHEN 'RETENCION EN LA FUENTE' THEN TF.CodTarRet
									WHEN 'RETENCION ICA' THEN TF.CodTarIca
								END)
								AND T.TipDoc = 'DFE'
						),
						C.IdCuenta -- Cuenta concepto.
					) AS IdCuenta,
					Detalle, VrDebito, VrCredito,
					CASE -- IdTercer
						WHEN IdVehiculo = '0' THEN IdTercero
						ELSE (
							COALESCE(	
								(
									SELECT DISTINCT CD.IdTercero 
									FROM Trn_ComDetalle AS CD 
									WHERE CD.Comprobante = (
										SELECT TOP 1 Factura
										FROM @Trn_DevFcr
									)
									AND CD.TipCom = 'FCE'
									AND CD.Item = C.Item
								),
								(
									SELECT F.NitTercero 
									FROM @Trn_TraEspFacReservas F 
									WHERE 
										F.pVehiculo = C.IdVehiculo 
										AND F.TipDoc = 'FCE'
										AND F.Item = C.Item
								),
								IdTercero
							)
						)
					END, 
					CASE -- IdVehiculo
						WHEN IdVehiculo = '0' THEN IdVehiculo
						ELSE ISNULL(
							(
								SELECT DISTINCT CD.IdVehiculo 
								FROM Trn_ComDetalle AS CD 
								WHERE CD.Comprobante = (
									SELECT TOP 1 Factura
									FROM @Trn_DevFcr
								)
								AND CD.TipCom = 'FCE'
								AND CD.Item = C.Item
							),
							IdVehiculo
						)
					END, 
					IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero,
					@Cia, CodConce, NitDoc, TipFac, Factura, IdCiaFac, 
					ItemFac, FecVence, CodCta,NumCheque, Integrado, TipoAplica, 
					Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia, 
					VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, 
					FecUpdate, IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, 
					PtoEmision, Num_Autoriza, FechAutoriza, CdCuentaNiif
				FROM 
					@Trn_ComDetalle c
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			BEGIN
					INSERT INTO Trn_NiifComp (
						TipCom, 
						Comprobante, 
						IdCia, Fecha, IdTercero, VrTotal, IdCta,EnEfectivo, 
						NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, 
						NumDev, FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, 
						CedCondtor, CodConce, Beneficiario, VrDivisa1, VrDivisa2, VrDivisa3, 
						PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado, 
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, 
						CdSustento, Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
						CtbTipo, 
						CtbNumero,
						FisTipo, 
						FisNumero 
					)
					SELECT 
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
						@Cia, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta, C.EnEfectivo, 
						C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, 
						C.NumDev,C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, 
						C.CedCondtor, C.CodConce, C.Beneficiario,C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, 
						C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion, C.IdEstado, 
						C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, 
						C.CdSustento, C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
						CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, 
						CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM 
					@Trn_Comprobantes AS C 
				JOIN
					@Trn_NiifComp AS N ON C.TipCom = N.TipComCont 
					AND C.Comprobante = N.ComprobanteCont
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			BEGIN
				INSERT INTO Trn_NiifDetalle (
					TipCom, 
					Comprobante, 
					IdCia, Item, Fecha, IdCuenta, Detalle,VrDebito, 
					VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,VrBase, 
					TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce, NitDoc, 
					TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef, 
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, 
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza, 
					CodCuentaCG
				)
				SELECT 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
					@Cia,N.Item, N.Fecha, N.IdCuenta, N.Detalle,N.VrDebito, 
					N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,N.VrBase, 
					N.TarifaBase, @TipDoc,@Numero,@Cia, N.CodConce,N.NitDoc, 
					N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,N.FechAutoriza, 
					N.CodCuentaCG
				FROM 
					@Trn_NiifDetalle as N
				JOIN 
					@Trn_NiifComp AS NC ON N.TipCom = NC.TipCom 
					AND N.Comprobante = NC.Comprobante				
			END

		end	

		IF(@operacion = 'i')
		begin
			--esto antes de la versiÃ³n 5048 estaba desuÃ©s del cursor ahora no para poder buscar solo las factruas activas
			--ACTUALIZAR FACTURA
			IF(UPPER(@modalidad) = 'TOTAL')
			BEGIN 
				UPDATE Trn_Facturas
				SET Anulado = 1,NumDev = @Numero,FecDev = @fecdev
				FROM Trn_Facturas F, @Trn_DevFcr DF
				WHERE F.TipDoc = DF.TipDoc 
					AND F.Factura = DF.Factura 
					AND F.IdCia = DF.IdCiaDoc
			END
			--actualiza los items de las reservas con los que se relacionan en el tipo de datos nuevo de las facturasreservas
			--Antes de la versiÃ³n 48 esto hacÃ­a Joe
			--UPDATE Trn_TraEspResDetalle
			--SET  Factura = 0, IdCiaFac = '00', FechaFac = null, EstadoItem = r.EstadoItem
			--FROM Trn_TraEspResDetalle d, @Trn_TraEspFacReservas r 
			--WHERE d.TipDoc = r.TipRes  and d.Reserva = r.Reserva and d.IdCia = r.IdCiaRes and d.Item = r.ItemRes
			--VersiÃ³n 48 se debe buscar si la opciÃ³n FRM estÃ¡ activa y si estÃ¡ activa debe colocar la Ãºltima factura que no estÃ© anulada de la reserva (Con este parÃ¡metro se puede factrar muchas veces la reserva)
			--Si la factrua que se anula es menor a la Ãºltima se debe seguir dejando la Ãºltima factura, ejemplo: si la Ãºltima factura de esa reserva es la 3 y se anula la factrua 2 correspondiente a esa reserva
			--Se sigue dejando la 3
			IF((SELECT ISNULL(Valor, '0') FROM adm_Opciones where IdOpc ='FRM') = '1')
			BEGIN
				DECLARE @TipRes VARCHAR(3)
				DECLARE @TipDocFacDev VARCHAR(3)
				DECLARE @TipDocFacActual VARCHAR(3)
				DECLARE @TipDocFac VARCHAR(3) 
				DECLARE @CiaRes VARCHAR(2) 
				DECLARE @CiaFac VARCHAR(2)
				DECLARE @CiaFacDev VARCHAR(2)
				DECLARE @CiaFacActual VARCHAR(2)
				DECLARE @NumRes INT
				DECLARE @NumFacDev INT 
				DECLARE @NumFacActual INT 
				DECLARE @NumFac INT 
				DECLARE @ItemRes INT 
				DECLARE @reserva Int = 0 
				DECLARE @cantres Int = 0 
				DECLARE @cantresfact Int = 0
				DECLARE @FechaFac datetime
				DECLARE @asingadofa BIT = 0
				SELECT TOP (1) @TipDocFacDev = TipDoc, @NumFacDev = Factura, @CiaFacDev = IdCiaDoc  FROM @Trn_DevFcr
				DECLARE faccursor CURSOR
				--Verificar todas las reservas que viene en la devoluciÃ³n, tenga facturas
				FOR SELECT TipRes,Reserva,IdCiaRes,ItemRes FROM @Trn_TraEspFacReservas 
				OPEN faccursor
				FETCH NEXT FROM faccursor INTO @TipRes,@NumRes,@CiaRes,@ItemRes
				WHILE @@FETCH_STATUS = 0
				BEGIN
					SELECT @TipDocFacActual = TipFac,  @NumFacActual = Factura, @CiaFacActual = IdCiaFac 
					FROM Trn_TraEspResDetalle 
					WHERE TipDoc = @TipRes 
						and Reserva = @NumRes 
						and IdCia = @CiaRes 
						and Item = @ItemRes

					IF(@TipDocFacActual = @TipDocFacDev and  @NumFacActual = @NumFacDev and @CiaFacActual = @CiaFacDev)
					BEGIN
						IF(EXISTS(
							SELECT TOP(1) fd.Factura 
							FROM Trn_TraEspFacReservas AS fd 
							JOIN Trn_Facturas AS f ON fd.TipDoc = f.TipDoc 
								AND fd.Factura = f.Factura 
								AND fd.IdCia = f.IdCia 
							WHERE fd.TipRes = @TipRes 
								AND fd.Reserva = @NumRes 
								AND fd.IdCia = @CiaRes 
								AND fd.Item = @ItemRes 
								AND f.Anulado = 0 
								and fd.TipDoc = @TipDocFacDev 
								and fd.Factura  < @NumFacDev 
								and fd.IdCia = @CiaFacDev 
								and  fd.Factura <> @NumFacDev  order by fd.Factura desc
						))
						BEGIN
							SELECT TOP(1) @TipDocFac = fd.TipDoc, @NumFac = fd.Factura,  @CiaFac = fd.IdCia, @FechaFac = f.Fecha 
							FROM Trn_TraEspFacReservas AS fd 
							JOIN Trn_Facturas AS f ON fd.TipDoc = f.TipDoc 
								AND fd.Factura = f.Factura 
								AND fd.IdCia = f.IdCia WHERE fd.TipRes = @TipRes 
								AND fd.Reserva = @NumRes 
								AND fd.IdCia = @CiaRes 
								AND fd.Item = @ItemRes 
								AND f.Anulado = 0 
								and fd.TipDoc = @TipDocFacDev 
								and fd.Factura < @NumFacDev 
								and fd.IdCia = @CiaFacDev  
								and fd.Factura <> @NumFacDev  
							order by 
								Fd.Factura desc

							UPDATE d
							SET d.Factura = @NumFac, d.IdCiaFac = @CiaFac, d.FechaFac = @FechaFac, d.EstadoItem = r.EstadoItem
							FROM Trn_TraEspResDetalle AS d 
							JOIN @Trn_TraEspFacReservas AS r  ON d.TipDoc = r.TipRes  
								and d.Reserva = r.Reserva 
								and d.IdCia = r.IdCiaRes
							WHERE d.TipDoc = @TipRes 
								and d.Reserva = @NumRes 
								and d.IdCia = @CiaRes 
								and d.Item = @ItemRes
							--DECLARE facupdatecursor CURSOR
							--FOR SELECT fd.TipDoc, fd.Factura, fd.IdCia, f.Fecha FROM Trn_TraEspFacReservas AS fd JOIN Trn_Facturas AS f ON fd.TipDoc = f.TipDoc AND fd.Factura = f.Factura AND fd.IdCia = f.IdCia  WHERE fd.TipRes = @TipRes AND fd.Reserva = @NumRes AND fd.IdCia = @CiaRes AND fd.Item = @ItemRes AND f.Anulado = 0
							--OPEN facupdatecursor
							--FETCH NEXT FROM facupdatecursor INTO @TipDocFac,@NumFac,@CiaFac,@FechaFac
							--WHILE @@FETCH_STATUS = 0 
							----OR @asingadofa = 0
							--BEGIN
							--	--La factura actual de la reserva debe ser menor
							--	IF((SELECT Factura FROM Trn_TraEspResDetalle WHERE TipDoc = @TipRes and Reserva = @NumRes and IdCia = @CiaRes and @ItemRes = Item) = @NumFac) -- AND @asingadofa = 0
							--	begin
							--		UPDATE d
							--		SET  d.Factura = @NumFac, d.IdCiaFac = @CiaFac, d.FechaFac = @FechaFac, d.EstadoItem = r.EstadoItem
							--		FROM Trn_TraEspResDetalle AS d 
							--		JOIN @Trn_TraEspFacReservas AS r  ON d.TipDoc = r.TipRes  and d.Reserva = r.Reserva and d.IdCia = r.IdCiaRes
							--		WHERE d.TipDoc = @TipRes and d.Reserva = @NumRes and d.IdCia = @CiaRes and d.Item = @ItemRes
							--		--set @asingadofa = 1
							--		BREAK
							--	end
							--FETCH NEXT FROM facupdatecursor INTO @TipDocFac,@NumFac,@CiaFac,@FechaFac
							--END
							--CLOSE facupdatecursor
							--DEALLOCATE facupdatecursor
						END
						ELSE
						BEGIN
							UPDATE Trn_TraEspResDetalle
							SET  Factura = 0, IdCiaFac = '00', FechaFac = null, EstadoItem = r.EstadoItem
							FROM Trn_TraEspResDetalle d, @Trn_TraEspFacReservas r 
							WHERE d.TipDoc = r.TipRes  
								and d.Reserva = r.Reserva 
								and d.IdCia = r.IdCiaRes 
								and d.Item = r.ItemRes
						END
					END
				FETCH NEXT FROM faccursor INTO @TipRes,@NumRes,@CiaRes,@ItemRes
				END
				CLOSE faccursor
				DEALLOCATE faccursor
			END
			ELSE
			BEGIN
			UPDATE Trn_TraEspResDetalle
				SET  Factura = 0, IdCiaFac = '00', FechaFac = null, EstadoItem = r.EstadoItem
				FROM Trn_TraEspResDetalle d, @Trn_TraEspFacReservas r 
				WHERE d.TipDoc = r.TipRes  
					and d.Reserva = r.Reserva 
					and d.IdCia = r.IdCiaRes 
					and d.Item = r.ItemRes
			END

			--actualiza el cliente
			UPDATE TercCliente
			SET  VrSaldo = c.VrSaldo - f.VrNeto
			FROM TercCliente c, @Trn_DevFcr f
			WHERE c.IdClie = f.IdCliente

			--actualizar vencimientos,cuando es necesario
			IF(EXISTS(SELECT * FROM @Trn_VencAbonos))
			BEGIN 
				UPDATE Trn_Vencimientos
				SET  VrAbonado = v.VrAbonado + dv.VrAbono
				FROM Trn_Vencimientos v, @Trn_VencAbonos dv
				WHERE v.TipDoc = dv.TipDoc 
					and v.Factura = dv.Factura 
					and v.IdCia = dv.IdCiaFac
			END

		end

		SELECT @Numero, @Comprobante

		COMMIT TRAN
	END TRY

    BEGIN CATCH
		ROLLBACK TRAN

		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
			@ErrorMessage = CONCAT(
				' Mensaje de error:', ERROR_MESSAGE(), 
				' Numero error:', ERROR_NUMBER(), 
				' Error severity:', ERROR_SEVERITY(), 
				' Linea:', ERROR_LINE(), 
				' Error Procedure', ERROR_PROCEDURE()),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
		);
	END CATCH

RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_Factcon]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_Factcon]
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY		 
			
			--SELECT TOP 1 @TipDoc = TipDoc, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_Factcon
			--SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

			--IF(@Numero > 0)
			--	UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
			--ELSE
			--BEGIN
			--	SELECT @Numero = 1
			--	INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--END

			--IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			--BEGIN
			--	SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
			--	SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
			--	--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
			--	IF(@Comprobante <> '')
			--		UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
			--	ELSE
			--	BEGIN
			--		SELECT @Comprobante = 1
			--		INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--	END
			--END

			--IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			--BEGIN
			--	SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
			--	SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
			--	--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
			--	IF(@CompNiif <> '')
			--		UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
			--	ELSE
			--	BEGIN
			--		SELECT @CompNiif = 1
			--		INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--	END
			--END

			--IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			--BEGIN
			--	SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
			--	SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
			--	--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
			--	IF(@CompNiif <> '')
			--		UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
			--	ELSE
			--	BEGIN
			--		SELECT @CompFis = 1
			--		INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null)
			--	END
			--END
			
			--IF(@operacion = 'i')
			--begin
			--	IF(EXISTS(SELECT * FROM @Trn_Factcon))
			--	BEGIN
			--	INSERT INTO Trn_Factcon(
			--	TipDoc,Factura,IdCia,Fecha,IdConcepto,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,
			--	VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,
			--	TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCajero,IdVend,TarifaCom,CodTarCom,NitCliente,CdAgencia,IdCCosto,IdSubCos,
			--	IdLocal,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido,
			--	Modalidad,PlacaVehic,KmtVehic,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,
			--	IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Fecha,IdConcepto,nClieCon,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,VrReteIVA,VrFletes,VrCargos,
			--	VrOtrDcto,VrCostos,VrNeto,VrEfectivo,VrPagosOtr,Cantidad,CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,
			--	TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,CodTarRiv,IdCajero,IdVend,TarifaCom,CodTarCom,NitCliente,CdAgencia,IdCCosto,IdSubCos,
			--	IdLocal,EnEfectivo,CdForma,NumForma,DetallePago,Referncia1,Referncia2,CdBanco,TipPed,Pedido,IdCiaPed,TipRem,Remision,IdCiaRem,FecPedido,
			--	Modalidad,PlacaVehic,KmtVehic,OrigenAdd,@TipComp,@Comprobante,@IdCiaComp,Anulado,NumDev,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,
			--	IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,BaseIvaObsq,VrIvaObsequio
			--	FROM @Trn_Factcon
			--	END 

			--	IF(EXISTS(SELECT * FROM @Trn_FacReservas))
			--	BEGIN
			--	INSERT INTO Trn_TraEspFacReservas(
			--	TipDoc,Factura,IdCia,Item,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,UndTarifa,
			--	TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
			--	pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Item,FechaFact,TipRes,Reserva,IdCiaRes,ItemRes,FecReserva,Descripcion,Cantidad,VrServicio,VrUnitario,VrCosto,UndTarifa,
			--	TarifaIva,VrImpuesto,TarifaDct,VrDescuento,DocCliente,Referencia1,Referencia2,Referencia3,CdConcepto,CdCCosto,CdSubCos,NitTercero,CdAgencia,
			--	pVehiculo,TipoAfiVehic,IdOrigen,IdDestino,Anulado,TipDocRef,NumDocRef,IdCiaRef,FecDocRef,CodTarDct
			--	FROM @Trn_FacReservas
			--	END 

			--	IF(EXISTS(SELECT * FROM @Trn_Kardex))
			--	BEGIN
			--	INSERT INTO Trn_Kardex(
			--	TipDoc,Documento,IdCia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,
			--	TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,
			--	VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,
			--	IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,
			--	IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,
			--	ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,
			--	CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,
			--	Temperatura,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo,MgenCont,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Item,Fecha,IdProducto,IdBodega,CdTanque,Entradas,Salidas,IdUnd,VrUnitario,VrPrecio,VrCostProm,
			--	TarifaIva,VrIvaEnt,VrIvaSal,TarifaDct,VrDctoEnt,VrDctoSal,VrCostoEnt,VrCostoSal,TarifaRet,VrReteEnt,VrReteSal,TarifaIca,
			--	VrIcaEnt,VrIcaSal,VrBruto,CdUbic,NumLote,FechLote,IdConcepto,IdTercero,CdAgencia,CdCCosto,CdSubCos,CdLocal,CdSzona,pVehiculo,
			--	IdVend,Comision,CdOperario,ComisnOper,Referencia,Descripcion,Comptmntos,CdProdEquiv,TipOrd,NumOrden,IdCiaOrd,Cotizacion,
			--	IdCiaCot,Remision,IdCiaRem,Factura,TipDocDev,NumDocDev,CdMngra,NumInicial,NumFinal,Sobretasa,TasaNac,TasaDep,TasaMun,Soldicom,
			--	ImpGlobal,OtroImpto,Unidades,ItemCombo,Servcios,NoVentas,EsCombo,EsProdBase,CodTarDct,CodTarIva,CodTarIca,CodTarRet,CodTarCom,
			--	CodTarCmc,ListaPrec,VrBase,CdMoneda,VrTasaCamb,VrDivisa1,VrDivisa2,VrDivisa3,Referencia2,FecOrden,galsbruto,galsneto,
			--	Temperatura,UmTemp,Densidad,TimeSys,IdUsuario,Rec_Costo,MgenCont,VrImvCosto,TarifaIco,VrImpCon,CantObseq,VrIvaObseq
			--	FROM @Trn_Kardex
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_Pagos))
			--	BEGIN
			--	INSERT INTO Trn_Pagos(
			--	TipDoc,Documento,IdCia,Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma,
			--	CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,
			--	CdCta,IdUsuario
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Item,Fecha,IdForma,Detalle,VrPagado,VrCambio,EsCaja,IdBanco,NitCliente,CdAgencia,NumForma,FecForma,
			--	CtaForma,Beneficiario,Referncia1,Referncia2,CdLocal,NumAutoriza,VrDenom,Cantidad,TipDenom,TipRef,DocRef,IdCiaRef,ItemDoc,
			--	CdCta,IdUsuario
			--	FROM @Trn_Pagos
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_DocMemo))
			--	BEGIN
			--	INSERT INTO Trn_DocMemo(
			--	TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp
			--	)
			--	SELECT 
			--	@TipDoc,@Numero,@Cia,Comentarios,Nota1,Nota2,Nota3,CantImp
			--	FROM @Trn_DocMemo
			--	END 

			--	IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			--	BEGIN
			--	INSERT INTO Trn_Comprobantes(
			--	TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			--	NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
			--	TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			--	VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			--	Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			--	PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero
			--	)
			--	SELECT 
			--	@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			--	NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
			--	TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			--	VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			--	Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			--	PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis
			--	FROM @Trn_Comprobantes
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			--	BEGIN
			--	INSERT INTO Trn_ComDetalle(
			--	TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
			--	IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
			--	IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
			--	NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
			--	CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
			--	IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
			--	)
			--	SELECT 
			--	@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
			--	IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
			--	CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
			--	NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
			--	CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
			--	IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
			--	FROM @Trn_ComDetalle
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			--	BEGIN
			--	INSERT INTO Trn_NiifComp(
			--	TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
			--	EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
			--	FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
			--	VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
			--	IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
			--	Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
			--	CtbTipo, CtbNumero,
			--	FisTipo, FisNumero 
			--	)
			--	SELECT 
			--	CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, CASE N.TipoNiif WHEN 'NIIF' THEN @IdCiaCompNiif ELSE @IdCiaCompFis END, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
			--	C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
			--	C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
			--	C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
			--	C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
			--	C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
			--	CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
			--	CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
			--	FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
			--	END

			--	IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			--	BEGIN
			--	INSERT INTO Trn_NiifDetalle(
			--	TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
			--	VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
			--	VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
			--	NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
			--	NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
			--	CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
			--	DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
			--	CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
			--	FechAutoriza, CodCuentaCG
			--	)
			--	SELECT 
			--	CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @IdCiaCompNiif ELSE @IdCiaCompFis END, N.Item, C.Fecha, N.IdCuenta, N.Detalle,
			--	N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo, N.IdCCosto, N.IdSubCos,
			--	C.VrBase, C.TarifaBase, @TipDoc, @Numero, @Cia, C.CodConce,
			--	C.NitDoc, C.TipFac, C.Factura, C.IdCiaFac, C.ItemFac, C.FecVence, C.CodCta, 
			--	C.NumCheque, C.Integrado, C.TipoAplica, C.Consolida, C.CodCargo, C.NitOtros,
			--	C.CodSubgpo, C.CiuOrigen, C.CodAgncia, C.VehPropio, N.Referncia, C.TipDocRef,
			--	C.DocRef, C.IdCiaRef, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario,
			--	C.CdConcTrib, C.CdTarifTrib, C.NumEstablec,C.PtoEmision, C.Num_Autoriza,
			--	C.FechAutoriza, C.IdCuenta
			--	FROM @Trn_ComDetalle AS C JOIN @Trn_NiifDetalle AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont AND C.Item = N.Item JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
			--	END
			--end

			--IF(@operacion = 'i')
			--begin
			--  --actualiza los items de un contrato con los que se relacionan en el tipo de datos nuevo
			--  UPDATE Trn_TraEspResDetalle
			--  SET  EstadoItem = 'FACTURADA'
			--  FROM Trn_TraEspResDetalle d, @Trn_FacReservas r 
			--  WHERE d.TipDoc = r.TipRes  and d.Reserva = r.Reserva and d.IdCia = r.IdCia and d.Item = r.ItemRes
			--end
						
			--SELECT @Numero

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_Facturas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_Facturas]
	@Trn_Facturas [dbo].[dataTypeTrn_Facturas] READONLY,
	@Trn_TraEspFacReservas [dbo].[dataTypeTrn_TraEspFacReservas] READONLY,
	@Trn_TraEspFacResVehiculos [dbo].[dataTypeTrn_TraEspFacResVehiculos] READONLY,
	@Trn_DocMemo [dbo].[dataTypeTrn_DocMemo] READONLY,
	@Trn_TraEspAuxFactura [dbo].[dataTypeTrn_TraEspAuxFactura] READONLY,
	@Trn_RecAfavor [dbo].[dataTypeTrn_RecAfavor] READONLY,
	@Trn_VencAbonos [dbo].[dataTypeTrn_VencAbonos] READONLY,
	@Trn_Vencimientos [dbo].[dataTypeTrn_Vencimientos] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @CodigoPre VARCHAR(3)
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
declare @FechaFac smalldatetime
	BEGIN TRAN
		BEGIN TRY		 

			IF NOT EXISTS (
				SELECT 1
				FROM Trn_Facturas AS TF
				INNER JOIN @Trn_Facturas AS TFT 
					ON TF.TipDoc = TFT.TipDoc 
					AND TF.Factura = TFT.Factura
					AND TF.IdCia = TFT.IdCia
			)
			BEGIN
				PRINT '1';
				IF(@operacion = 'i')
				BEGIN
					SELECT TOP 1 @TipDoc = TipDoc,@CodigoPre = CodigoPreFact, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia, @FechaFac = Fecha FROM @Trn_Facturas
				
					IF(@CodigoPre is not null or @CodigoPre <> '')
					 select @Numero = (SELECT TOP 1 Factura FROM @Trn_Facturas)
					ELSE
					BEGIN
						SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

						IF(@Numero > 0)
							UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
						ELSE
						BEGIN
							SELECT @Numero = 1
							INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
						SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
						SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
						--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
						IF(@Comprobante <> '')
							UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
						ELSE
						BEGIN
							SELECT @Comprobante = 1
							INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
					BEGIN
						SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
						SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
						--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
						IF(@CompNiif <> '')
							UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
						ELSE
						BEGIN
							SELECT @CompNiif = 1
							INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
					BEGIN
						SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
						SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
						--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
						IF(@CompFis <> '')
							UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
						ELSE
						BEGIN
							SELECT @CompFis = 1
							INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
						END
					END
				END

				IF(@operacion = 'i')
				BEGIN
					IF(EXISTS(SELECT * FROM @Trn_Facturas))
					BEGIN
						INSERT INTO Trn_Facturas(
						TipDoc,Factura,IdCia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,
						VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,
						CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,
						CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,
						CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,TipPed,Pedido,IdCiaPed,
						TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,ZonaFrontera,PesoTotal,
						UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,CodAutoRet,OrigenAdd,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,
						IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,
						VrImpCarbono,TipoFE,FechaFE,BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Fecha,IdConcepto,IdCliente,IdAgencia,FechaVence,VrSubTotal,VrDescuento,VrImpuesto,VrRetencion,VrReteICA,
						VrReteIVA,VrFletes,VrOtros,VrCargos,VrOtrDcto,VrCostos,VrSobretasa,VrImpGlobal,VrFaltantes,VrAnticipos,VrNeto,VrAplicado,Cantidad,
						CantPuntos,PuntosAcum,BaseImp,BaseRet,BaseIca,BaseRiv,TarifaIva,TarifaRet,TarifaIca,TarifaRiv,CodTarIva,CodTarRet,CodTarIca,
						CodTarRiv,IdCCosto,IdSubCos,IdVend,TarifaCom,CodTarCom,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,
						CargoContac,IdForma,DetallePago,MulPlazos,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,TipPed,Pedido,IdCiaPed,
						TipRem,Remision,IdCiaRem,TipCot,Cotizacion,IdCiaCot,FecPedido,AutzaMora,AutzaCupo,Modalidad,KmtVehic,ZonaFrontera,PesoTotal,
						UnidTotal,VolTotal,CantFalt,VrCostoRem,VrCostoAfi,CodAutoRet,OrigenAdd,@TipComp,@Comprobante,@IdCiaComp,Anulado,NumDev,FecDev,Observacion,
						IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,VrImpCons,VrReteCREE,TarifaRtc,CodTarRtc,Parqueadero,FecCuotaParq,BaseIvaObsq,VrIvaObsequio,
						VrImpCarbono,TipoFE,FechaFE,BaseIvaIgp,VrIvaIngProd,CodTarArf,TarifaArf,VrAutRetFte,CodTarAri,TarifaAri,VrAutRetIca
						FROM @Trn_Facturas
					END 

					IF(EXISTS(SELECT * FROM @Trn_TraEspFacReservas))
					BEGIN
						INSERT INTO Trn_TraEspFacReservas(
							TipDoc, Factura, IdCia, Item,
							TipoReg, FechaFact, TipRes, Reserva,
							IdCiaRes, ItemRes, FecReserva, Descripcion,
							Cantidad, VrServicio, VrUnitario, VrCosto,
							TarifaIva, VrImpuesto, TarifaDct, VrDescuento, 
							DocCliente, Referencia1, Referencia2, Referencia3,
							CdConcepto, CdCCosto, CdSubCos, NitTercero, 
							CdAgencia, pVehiculo, TipoAfiVehic, IdOrigen, 
							IdDestino, Anulado, TipDocRef, NumDocRef, 
							IdCiaRef, FecDocRef, CodTarDct, CodTarRet, 
							CodTarIca, TarifaRet,VrRetencion, TarifaIca, 
							VrReteIca, EstadoItem, CodTarAvTa,
							TarifaAvTa, VrAvTa, CodTarBom,
							TarifaBom, VrBom
						)
						SELECT 
							@TipDoc, @Numero, @Cia, Item,
							TipoReg, FechaFact, TipRes, Reserva,
							IdCiaRes, ItemRes, FecReserva, Descripcion,
							Cantidad, VrServicio, VrUnitario, VrCosto,
							TarifaIva, VrImpuesto, TarifaDct, VrDescuento, 
							DocCliente, Referencia1, Referencia2, Referencia3,
							CdConcepto, CdCCosto, CdSubCos, NitTercero,
							CdAgencia, pVehiculo, TipoAfiVehic, IdOrigen,
							IdDestino, Anulado, TipDocRef, NumDocRef,
							IdCiaRef, FecDocRef, CodTarDct, CodTarRet,
							CodTarIca, TarifaRet, VrRetencion, TarifaIca,
							VrReteIca, EstadoItem, CodTarAvTa,
							TarifaAvTa, VrAvTa, CodTarBom,
							TarifaBom, VrBom
						FROM 
							@Trn_TraEspFacReservas
					END

					IF(EXISTS(SELECT * FROM @Trn_TraEspFacResVehiculos))
					BEGIN
						INSERT INTO Trn_TraEspFacResVehiculos(
						TipDoc,Factura,IdCIa,Item,TipRes,Reserva,IdCIaRes,ItemRes,IdVehiculo,TipoAfil,VrRecorrido
						)
						SELECT
						@TipDoc,@Numero,@Cia,Item,TipRes,Reserva,IdCIaRes,ItemRes,IdVehiculo,TipoAfil,VrRecorrido
						FROM @Trn_TraEspFacResVehiculos
					END

					IF(EXISTS(SELECT * FROM @Trn_Vencimientos))
					BEGIN
						INSERT INTO Trn_Vencimientos(
						TipDoc,Factura,IdCia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,
						TipoDcto,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,
						TarifInt,FecLiqMora,FecPlazoCal
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Item,Fecha,FechaVence,VrFactura,VrAbonado,IdCliente,IdAgencia,IdVend,Comision,TarifDcto,
						TipoDcto,TipoBase,FecLmtDcto,IdConcepto,Referencia,Detalle,TipRef,DocRef,IdCiaRef,FecUltPago,NumNota,IdCiaNot,
						TarifInt,FecLiqMora,FecPlazoCal
						FROM @Trn_Vencimientos
					END

					IF(EXISTS(SELECT * FROM @Trn_DocMemo))
						BEGIN
						INSERT INTO Trn_DocMemo(
						TipDoc,Documento,IdCia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Comentarios,Nota1,Nota2,Nota3,CantImp,ArchivoImg
						FROM @Trn_DocMemo
					END 

					IF(EXISTS(SELECT * FROM @Trn_TraEspAuxFactura))
					BEGIN
						INSERT INTO Trn_TraEspAuxFactura(
						TipFac,Factura,IdCiaFac,Resolucion,Rango,FechaResl,Prefijo,TipDocPf,PreFactura,IdCiaPf,CodigoPreFact
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Resolucion,Rango,FechaResl,Prefijo,TipDocPf,PreFactura,IdCiaPf,CodigoPreFact
						FROM @Trn_TraEspAuxFactura
					END 

					IF(EXISTS(SELECT * FROM @Trn_RecAfavor))
					BEGIN
						update Trn_RecAfavor
						set VrAbono = t1.VrAbono + t2.VrAbono
						from Trn_RecAfavor t1, @Trn_RecAfavor t2
						where t1.TipDoc = t2.TipDoc and t1.Recibo = t2.Recibo and t1.IdCia = t2.IdCia and t1.IdCliente = t2.IdCliente and t1.IdAgencia = t2.IdAgencia and t1.IdVend = t2.IdVend
					END 

					IF(EXISTS(SELECT * FROM @Trn_VencAbonos))
					BEGIN
						declare @tiprec varchar(3)
						declare @recibo int
						declare @idciarec varchar(2)
						declare @item int 
						SELECT TOP 1 @tiprec = TipRec, @idciarec = IdCia, @recibo = Recibo FROM @Trn_VencAbonos
						select @item =  isnull(MAX(Item),0) from Trn_VencAbonos where TipRec = @tiprec and Recibo = @recibo and IdCia = @idciarec

						INSERT INTO Trn_VencAbonos(
						TipRec,Recibo,IdCia,Item,Fecha,TipDoc,Factura,IdCiaFac,ItemFac,VrAbono,VrDescto,
						VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
						)
						SELECT 
						TipRec,Recibo,IdCia,(@item + ROW_NUMBER() OVER(ORDER BY Item ASC)),Fecha,@TipDoc,@Numero,@Cia,ItemFac,VrAbono,VrDescto,
						VrBaseCms,IdCliente,IdAgencia,IdVend,Comision,Detalle,FecPago,TipoAplica,TimeSys
						FROM @Trn_VencAbonos
					END 

					IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
					BEGIN
						INSERT INTO Trn_DetCuentas(
						TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
						VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif 
						)
						SELECT 
						@TipDoc,@Numero,@Cia,Concepto,Item,IdCuenta,Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,pVehiculo,
						VrBase,TipFac,Factura,IdCiaFac,ItemFac,FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,CodConc,CodTarif
						FROM @Trn_DetCuentas
					END

					IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
					BEGIN
						INSERT INTO Trn_Comprobantes(
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
						NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
						TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
						PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
						CodRes, DescServicio
						)
						SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
						NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
						TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
						Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
						PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
						CodRes, DescServicio
						FROM @Trn_Comprobantes
					END

					IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
					BEGIN
						--FUNCION PARA AGREGAR EL NIT APORPIADO AL IDVEHICULO
						INSERT INTO Trn_ComDetalle (
							TipCom, Comprobante, IdCia, Item, 
							Fecha, IdCuenta, Detalle, VrDebito, VrCredito, 
							IdTercero, 
							IdVehiculo, 
							IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, 
							Documento, IdCiaDoc, CodConce, NitDoc, 
							TipFac, Factura, IdCiaFac, ItemFac, 
							FecVence, CodCta, NumCheque, Integrado, 
							TipoAplica, Consolida, CodCargo, NitOtros, 
							CodSubgpo, CiuOrigen, CodAgncia, VehPropio, 
							Referncia, TipDocRef, DocRef, IdCiaRef, 
							TimeSys, FecUpdate, IdCiaCrea, IdUsuario, 
							CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
							Num_Autoriza, FechAutoriza, CdCuentaNiif
						)
						SELECT 
							@TipComp, @Comprobante, @IdCiaComp, Item, 
							Fecha, 
							COALESCE(
								( -- Retencion en detalle, buscar tarifa
									SELECT DISTINCT T.IdCuenta
									FROM @Trn_TraEspFacReservas AS O
									LEFT JOIN TarifCuentas T ON T.IdTarifa = (
										CASE C.Referncia
											WHEN 'RETENCION EN LA FUENTE' THEN O.CodTarRet
											WHEN 'RETENCION ICA' THEN O.CodTarIca
										END)
										AND T.TipDoc = 'FCE'
									WHERE O.Reserva = C.DocRef
								),
								( -- Retencion en total, buscar tarifa
									SELECT T.IdCuenta
									FROM @Trn_Facturas AS TF
									LEFT JOIN TarifCuentas T ON T.IdTarifa = (
										CASE C.Referncia
											WHEN 'RETENCION EN LA FUENTE' THEN TF.CodTarRet
											WHEN 'RETENCION ICA' THEN TF.CodTarIca
										END)
										AND T.TipDoc = 'FCE'
								),
								C.IdCuenta -- Cuenta concepto.
							) AS IdCuenta,  
							Detalle, VrDebito, VrCredito,
							--IdTercero, IdVehiculo, 
							CASE 
								WHEN IdVehiculo = '0' THEN IdTercero
								ELSE isnull((SELECT F.NitTercero FROM @Trn_TraEspFacReservas F WHERE F.pVehiculo = C.IdVehiculo AND F.TipDocRef = 'RES'), IdTercero)
							END,
							C.IdVehiculo, IdCCosto, IdSubCos, VrBase, 
							TarifaBase, @TipDoc, @Numero, @Cia, 
							CodConce, NitDoc, TipFac, Factura, 
							IdCiaFac, ItemFac, FecVence, CodCta, 
							NumCheque, Integrado, TipoAplica, Consolida, 
							CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
							CodAgncia, VehPropio, Referncia, TipDocRef, 
							DocRef, IdCiaRef, TimeSys, FecUpdate, 
							IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, 
							NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza, 
							CdCuentaNiif
						FROM 
							@Trn_ComDetalle C
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifComp))
					BEGIN
						INSERT INTO Trn_NiifComp(
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
						EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
						FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
						VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
						IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
						Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
						CtbTipo, CtbNumero,
						FisTipo, FisNumero 
						)
						SELECT 
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
						@Cia, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
						C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
						C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
						C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
						C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
						C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
						CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
						FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
						---------------factura una
					END

					IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
					BEGIN
					INSERT INTO Trn_NiifDetalle(
					TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
					VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
					VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
					NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
					FechAutoriza, CodCuentaCG
					)
					SELECT 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
					@Cia,
					N.Item, N.Fecha, N.IdCuenta, N.Detalle,
					N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
					N.VrBase, N.TarifaBase, @TipDoc,@Numero,@Cia, N.CodConce,
					N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
					N.FechAutoriza, N.CodCuentaCG
					FROM @Trn_NiifDetalle as N
					JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
					END
				END	

				IF(@operacion = 'i')
				BEGIN
				 IF(UPPER((SELECT TipDoc FROM @Trn_Facturas)) <> 'PFE')
				 BEGIN
					  --actualiza los items de las reservas con los que se relacionan en el tipo de datos nuevo de las facturasreservas
					  DECLARE @TipRes VARCHAR(3) 
					  DECLARE @CiaRes VARCHAR(2) 
					  DECLARE @NumRes INT 
					  DECLARE @ItemRes INT 
					  DECLARE @reserva Int = 0 
					  DECLARE @cantres Int = 0 
					  DECLARE @cantresfact Int = 0 

					  DECLARE faccursor CURSOR
					  FOR SELECT TipRes,Reserva,IdCiaRes,ItemRes FROM @Trn_TraEspFacReservas
					  OPEN faccursor
					  FETCH NEXT FROM faccursor INTO @TipRes,@NumRes,@CiaRes,@ItemRes
					  WHILE @@FETCH_STATUS = 0
					  BEGIN

						  UPDATE Trn_TraEspResDetalle
						  SET  TipFac = @TipDoc, Factura = @Numero, IdCiaFac = @Cia, FechaFac = @FechaFac, EstadoItem = 'FACTURADA'
						  FROM Trn_TraEspResDetalle d
						  WHERE d.TipDoc = @TipRes  and d.Reserva = @NumRes and d.IdCia = @CiaRes and d.Item = @ItemRes

						  --se agrega 11/04/2018 para sacar este codigo de la aplicaciÃ³n
						  IF (@NumRes <> @reserva)
						  BEGIN
							SET @reserva = @NumRes
						
							SELECT @cantres = count(*)
							FROM Trn_TraEspResDetalle AS rd
							WHERE rd.TipDoc = @TipRes  and rd.Reserva = @NumRes and rd.IdCia = @CiaRes

							SELECT @cantresfact = count(*)
							FROM Trn_TraEspResDetalle AS rd
							WHERE rd.TipDoc = @TipRes  and rd.Reserva = @NumRes and rd.IdCia = @CiaRes and rd.EstadoItem = 'FACTURADA'
						
							IF (@cantresfact = @cantres)
							BEGIN
								UPDATE Trn_TraEspReservas 
								SET EstadoRes = 'FACTURADA' 
								WHERE TipDoc = @TipRes  and Reserva = @NumRes and IdCia = @CiaRes                     
							END

						  END
						  -------------------------------------------------------------
				  
					  FETCH NEXT FROM faccursor INTO @TipRes,@NumRes,@CiaRes,@ItemRes
					  END
					  CLOSE faccursor
					  DEALLOCATE faccursor

					  --actualiza el cliente
					  UPDATE TercCliente
					  SET  VrSaldo = c.VrSaldo + f.VrNeto
					  FROM TercCliente c, @Trn_Facturas f
					  WHERE c.IdClie = f.IdCliente
				  END
				END
			END
			ELSE
			BEGIN
				SELECT 
					@TipDoc = TipDoc,
					@Numero = Factura,
					@Cia = IdCia
				FROM @Trn_Facturas

				UPDATE TF
				SET 
					TF.Fecha = T.Fecha,
					TF.IdConcepto = T.IdConcepto,
					TF.IdCliente = T.IdCliente,
					TF.IdAgencia = T.IdAgencia,
					TF.FechaVence = T.FechaVence,
					TF.VrSubTotal = T.VrSubTotal,
					TF.VrDescuento = T.VrDescuento,
					TF.VrImpuesto = T.VrImpuesto,
					TF.VrRetencion = T.VrRetencion,
					TF.VrReteICA = T.VrReteICA,
					TF.VrReteIVA = T.VrReteIVA,
					TF.VrFletes = T.VrFletes,
					TF.VrOtros = T.VrOtros,
					TF.VrCargos = T.VrCargos,
					TF.VrOtrDcto = T.VrOtrDcto,
					TF.VrCostos = T.VrCostos,
					TF.VrSobretasa = T.VrSobretasa,
					TF.VrImpGlobal = T.VrImpGlobal,
					TF.VrFaltantes = T.VrFaltantes,
					TF.VrAnticipos = T.VrAnticipos,
					TF.VrNeto = T.VrNeto,
					TF.VrAplicado = T.VrAplicado,
					TF.Cantidad = T.Cantidad,
					TF.CantPuntos = T.CantPuntos,
					TF.PuntosAcum = T.PuntosAcum,
					TF.BaseImp = T.BaseImp,
					TF.BaseRet = T.BaseRet,
					TF.BaseIca = T.BaseIca,
					TF.BaseRiv = T.BaseRiv,
					TF.TarifaIva = T.TarifaIva,
					TF.TarifaRet = T.TarifaRet,
					TF.TarifaIca = T.TarifaIca,
					TF.TarifaRiv = T.TarifaRiv,
					TF.CodTarIva = T.CodTarIva,
					TF.CodTarRet = T.CodTarRet,
					TF.CodTarIca = T.CodTarIca,
					TF.CodTarRiv = T.CodTarRiv,
					TF.IdCCosto = T.IdCCosto,
					TF.IdSubCos = T.IdSubCos,
					TF.IdVend = T.IdVend,
					TF.TarifaCom = T.TarifaCom,
					TF.CodTarCom = T.CodTarCom,
					TF.DirEnvio = T.DirEnvio,
					TF.IdLocEnv = T.IdLocEnv,
					TF.DiasEntraga = T.DiasEntraga,
					TF.NitContac = T.NitContac,
					TF.NomContac = T.NomContac,
					TF.TelContac = T.TelContac,
					TF.emlContac = T.emlContac,
					TF.CargoContac = T.CargoContac,
					TF.IdForma = T.IdForma,
					TF.DetallePago = T.DetallePago,
					TF.MulPlazos = T.MulPlazos,
					TF.IdPlazo = T.IdPlazo,
					TF.CdMney = T.CdMney,
					TF.NitEmpTrans = T.NitEmpTrans,
					TF.EmpTrans = T.EmpTrans,
					TF.pVehiculo = T.pVehiculo,
					TF.CdConductor = T.CdConductor,
					TF.CdRuta = T.CdRuta,
					TF.TipPed = T.TipPed,
					TF.Pedido = T.Pedido,
					TF.IdCiaPed = T.IdCiaPed,
					TF.TipRem = T.TipRem,
					TF.Remision = T.Remision,
					TF.IdCiaRem = T.IdCiaRem,
					TF.TipCot = T.TipCot,
					TF.Cotizacion = T.Cotizacion,
					TF.IdCiaCot = T.IdCiaCot,
					TF.FecPedido = T.FecPedido,
					TF.AutzaMora = T.AutzaMora,
					TF.AutzaCupo = T.AutzaCupo,
					TF.Modalidad = T.Modalidad,
					TF.KmtVehic = T.KmtVehic,
					TF.ZonaFrontera = T.ZonaFrontera,
					TF.PesoTotal = T.PesoTotal,
					TF.UnidTotal = T.UnidTotal,
					TF.VolTotal = T.VolTotal,
					TF.CantFalt = T.CantFalt,
					TF.VrCostoRem = T.VrCostoRem,
					TF.VrCostoAfi = T.VrCostoAfi,
					TF.CodAutoRet = T.CodAutoRet,
					TF.OrigenAdd = T.OrigenAdd,
					TF.TipCom = @TipComp,
					TF.Comprobante = @Comprobante,
					TF.IdCiaCom = @IdCiaComp
				FROM Trn_Facturas AS TF
				INNER JOIN @Trn_Facturas AS T
					ON TF.TipDoc = T.TipDoc
					AND TF.Factura = T.Factura
					AND TF.IdCia = T.IdCia;

				MERGE INTO Trn_TraEspFacReservas AS TF
				USING @Trn_TraEspFacReservas AS T
					ON TF.TipDoc = T.TipDoc
					AND TF.Factura = T.Factura
					AND TF.IdCia = T.IdCia
					AND TF.Item = T.Item
				WHEN MATCHED THEN
					UPDATE SET
						TF.TipoReg = T.TipoReg,
						TF.FechaFact = T.FechaFact,
						TF.TipRes = T.TipRes,
						TF.Reserva = T.Reserva,
						TF.IdCiaRes = T.IdCiaRes,
						TF.ItemRes = T.ItemRes,
						TF.FecReserva = T.FecReserva,
						TF.Descripcion = T.Descripcion,
						TF.Cantidad = T.Cantidad,
						TF.VrServicio = T.VrServicio,
						TF.VrUnitario = T.VrUnitario,
						TF.VrCosto = T.VrCosto,
						TF.TarifaIva = T.TarifaIva,
						TF.VrImpuesto = T.VrImpuesto,
						TF.TarifaDct = T.TarifaDct,
						TF.VrDescuento = T.VrDescuento,
						TF.DocCliente = T.DocCliente,
						TF.Referencia1 = T.Referencia1,
						TF.Referencia2 = T.Referencia2,
						TF.Referencia3 = T.Referencia3,
						TF.CdConcepto = T.CdConcepto,
						TF.CdCCosto = T.CdCCosto,
						TF.CdSubCos = T.CdSubCos,
						TF.NitTercero = T.NitTercero,
						TF.CdAgencia = T.CdAgencia,
						TF.pVehiculo = T.pVehiculo,
						TF.TipoAfiVehic = T.TipoAfiVehic,
						TF.IdOrigen = T.IdOrigen,
						TF.IdDestino = T.IdDestino,
						TF.Anulado = T.Anulado,
						TF.TipDocRef = T.TipDocRef,
						TF.NumDocRef = T.NumDocRef,
						TF.IdCiaRef = T.IdCiaRef,
						TF.FecDocRef = T.FecDocRef,
						TF.CodTarDct = T.CodTarDct,
						TF.CodTarRet = T.CodTarRet,
						TF.CodTarIca = T.CodTarIca,
						TF.TarifaRet = T.TarifaRet,
						TF.VrRetencion = T.VrRetencion,
						TF.TarifaIca = T.TarifaIca,
						TF.VrReteIca = T.VrReteIca,
						TF.EstadoItem = T.EstadoItem,
						TF.CodTarAvTa = T.CodTarAvTa,
						TF.TarifaAvTa = T.TarifaAvTa,
						TF.VrAvTa = T.VrAvTa,
						TF.CodTarBom = T.CodTarBom,
						TF.TarifaBom = T.TarifaBom,
						TF.VrBom = T.VrBom
				WHEN NOT MATCHED BY TARGET THEN
					 INSERT (TipDoc, Factura, IdCia, Item, TipoReg, FechaFact, TipRes, Reserva, IdCiaRes, ItemRes, FecReserva, Descripcion, Cantidad, VrServicio, VrUnitario, VrCosto,
							 TarifaIva, VrImpuesto, TarifaDct, VrDescuento, DocCliente, Referencia1, Referencia2, Referencia3, CdConcepto, CdCCosto, CdSubCos, NitTercero, CdAgencia, pVehiculo, TipoAfiVehic, IdOrigen, IdDestino,
							 Anulado, TipDocRef, NumDocRef, IdCiaRef, FecDocRef, CodTarDct, CodTarRet, CodTarIca, TarifaRet, VrRetencion, TarifaIca, VrReteIca, EstadoItem, CodTarAvTa, TarifaAvTa, VrAvTa, CodTarBom, TarifaBom, VrBom)
					 VALUES (T.TipDoc, T.Factura, T.IdCia, T.Item, T.TipoReg, T.FechaFact, T.TipRes, T.Reserva, T.IdCiaRes, T.ItemRes, T.FecReserva, T.Descripcion, T.Cantidad, T.VrServicio, T.VrUnitario, T.VrCosto,
							 T.TarifaIva, T.VrImpuesto, T.TarifaDct, T.VrDescuento, T.DocCliente, T.Referencia1, T.Referencia2, T.Referencia3, T.CdConcepto, T.CdCCosto, T.CdSubCos, T.NitTercero, T.CdAgencia, T.pVehiculo, T.TipoAfiVehic, T.IdOrigen, T.IdDestino,
							 T.Anulado, T.TipDocRef, T.NumDocRef, T.IdCiaRef, T.FecDocRef, T.CodTarDct, T.CodTarRet, T.CodTarIca, T.TarifaRet, T.VrRetencion, T.TarifaIca, T.VrReteIca, T.EstadoItem, T.CodTarAvTa, T.TarifaAvTa, T.VrAvTa, T.CodTarBom, T.TarifaBom, T.VrBom);

				DELETE FR
				FROM Trn_TraEspFacReservas AS FR
				WHERE FR.TipDoc = @TipDoc
				  AND FR.Factura = @Numero
				  AND FR.IdCia = @Cia
				  AND NOT EXISTS (
					  SELECT 1
					  FROM @Trn_TraEspFacReservas AS TTFR
					  WHERE TTFR.TipDoc = FR.TipDoc
						AND TTFR.Factura = FR.Factura
						AND TTFR.IdCia = FR.IdCia
						AND TTFR.Item = FR.Item
				  );

				IF(@operacion = 'a')
				BEGIN
					UPDATE Trn_Facturas
					SET IdEstado = '9999',
						Anulado = 1
					FROM Trn_Facturas AS TF
					INNER JOIN @Trn_Facturas AS TFT 
						ON TF.TipDoc = TFT.TipDoc 
						AND TF.Comprobante = TFT.Comprobante
						AND TF.IdCia = TFT.IdCia
				END
			END


			SELECT @Numero, @Comprobante
				
			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_FcSemanas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_FcSemanas]
	@Trn_FcSemanas [dbo].[dataTypeTrn_FcSemanas] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Trn_FcSemanas
			 SET 
			 IdVehiculo = t2.IdVehiculo,nSemana = t2.nSemana,NumCargue = t2.NumCargue,CiaCargue = t2.CiaCargue,
			 TipoSem = t2.TipoSem,Fecha = t2.Fecha,FecVence = t2.FecVence,VrCargo = t2.VrCargo,VrOtros = t2.VrOtros,
			 VrPagado = t2.VrPagado,TipRec = t2.TipRec,Recibo = t2.Recibo,IdCiaRec = t2.IdCiaRec,FechaPago = t2.FechaPago,
			 Observacion = t2.Observacion,FecSemIni = t2.FecSemIni,FecSemFin = t2.FecSemFin,TimeSys = t2.TimeSys,IdUsuario = t2.IdUsuario
		     FROM Trn_FcSemanas t1
			 JOIN @Trn_FcSemanas t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.nSemana = t2.nSemana
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Trn_FcSemanas(
			 IdVehiculo,nSemana,NumCargue,CiaCargue,TipoSem,Fecha,FecVence,VrCargo,VrOtros,
			 VrPagado,TipRec,Recibo,IdCiaRec,FechaPago,Observacion,FecSemIni,FecSemFin,TimeSys,IdUsuario
			 )
			 SELECT 
			 IdVehiculo,nSemana,NumCargue,CiaCargue,TipoSem,Fecha,FecVence,VrCargo,VrOtros,
			 VrPagado,TipRec,Recibo,IdCiaRec,FechaPago,Observacion,FecSemIni,FecSemFin,TimeSys,IdUsuario
			 FROM @Trn_FcSemanas
			 WHERE (IdVehiculo +'_'+ Convert(varchar,nSemana)) NOT IN(SELECT (IdVehiculo +'_'+ Convert(varchar,nSemana)) FROM Trn_FcSemanas)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @idvehiculo varchar(10)
			 DECLARE @nsemana int
			 SELECT @idvehiculo = IdVehiculo, @nsemana = nSemana FROM @Trn_FcSemanas
			 DELETE FROM Trn_FcSemanas WHERE IdVehiculo = @idvehiculo and nSemana = @nsemana
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspAnticipos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspAnticipos]
	@Trn_TraEspAnticipos [dbo].[dataTypeTrn_TraEspAnticipos] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@Trn_ComFactura [dbo].[dataTypeTrn_ComFactura] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TDAnt VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @CiaAnt VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Anticipo INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
--DECLARE @Trn_TraComprobantes dataTypeTrn_Comprobantes --En esta variable se guarda el consecutivo del documento aprobaciÃ³n NO
--DECLARE @Trn_ComDetalle dataTypeTrn_ComDetalle --En esta variable se guarda el consecutivo del documento aprobaciÃ³n NO

	BEGIN TRAN
		BEGIN TRY		 
			declare @idcta varchar(4)
			declare @tpago varchar(10)
			declare @consecutivoCh int = 0
			declare @numcheque VARCHAR (20)
			declare @rango varchar(20)
			declare @rangof varchar(20)
			declare @TipFac varchar(3)
			declare @Factura varchar(15)
			declare @IdCiaFac varchar(2)

			if(@operacion = 'i')
			BEGIN

			SELECT TOP 1 @TDAnt = TipDoc, @CiaAnt = IdCia, @idcta = IdCta, @tpago = TipoPago, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia, @numcheque = NumCheque FROM @Trn_TraEspAnticipos
			SELECT @Anticipo = Numero + 1  FROM TiposDocCons where IdDoc = @TDAnt AND IdCia = @CiaAnt

			IF(@Anticipo > 0)
				UPDATE TiposDocCons SET Numero = @Anticipo WHERE IdDoc = @TDAnt AND IdCia = @CiaAnt
			ELSE
			BEGIN
				SELECT @Anticipo = 1
				INSERT INTO TiposDocCons VALUES (@TDAnt,@CiaAnt,0,0,0,0,NULL,'',@Anticipo,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
				SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1
					INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
				SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif

				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1
					INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
				SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis

				IF(@CompFis <> '')
					UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1
					INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF((select UPPER(TipoPago) from @Trn_TraEspAnticipos) = 'CHEQUE')
			BEGIN
				if((select ConsCheques from CtasCorrientes where IdCta = @idcta) = '1')
				begin
					begin try
						select 
						@consecutivoCh = (ConsActual + 1),
						@rango = (substring(RangoCons,1,(charindex('-',RangoCons)-1))), 
						@rangof = (substring(RangoCons,(charindex('-',RangoCons)+1),len(RangoCons))) 
						from CtasCorrientes where IdCta = @idcta
								
						if not(@consecutivoCh >= Convert(int,@rango) and @consecutivoCh <= Convert(int,@rangof))
						begin
							RAISERROR('Error, el consecutivo de cheque fuera del rango establecido', 16, 1);
						end
						else
						begin
							update CtasCorrientes set ConsActual = @consecutivoCh where IdCta = @idcta
						end
					end try
					begin catch
						RAISERROR('Error, el consecutivo de cheque fuera del rango establecido', 16, 1);
					end catch
				end
			END

			--4052
			IF (EXISTS(SELECT * FROM @Trn_ComFactura) AND (SELECT TOP 1 Modalidad FROM  @Trn_TraEspAnticipos) = 'COMBUSTBLE' AND (SELECT TOP 1 p.Vencimiento FROM Puc as p WHERE p.IdCuenta = (SELECT TOP 1 IdCuenta FROM @Trn_TraEspAnticipos)) = 1)
			BEGIN
				SELECT TOP 1 @TipFac =  TipFac, @Factura = Factura, @IdCiaFac = IdCia FROM @Trn_ComFactura
			END
			INSERT INTO Trn_TraEspAnticipos(
			TipDoc,Anticipo,IdCia,Fecha,IdConcepto,TipRes,Reserva,IdCiaRes,ItemRes,IdVehiculo,IdPoseedor,IdConductor,VrAnticipo,
			VrAbonado,Modalidad,TipoPago,NumCheque,FecCheque,IdCta,IdCuenta,Beneficiario,CedBenef,Cantidad,FechaVence,
			NumPresAnt,TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,
			IdCiaCrea,IdUsuario,PreAnticipo
			)
			SELECT 
			@TDAnt,@Anticipo,@CiaAnt,Fecha,IdConcepto,TipRes,Reserva,IdCiaRes,ItemRes,IdVehiculo,IdPoseedor,IdConductor,VrAnticipo,
			VrAbonado,Modalidad,TipoPago,
			(CASE WHEN Modalidad  = 'COMBUSTBLE' THEN 
				(CASE WHEN (SELECT TOP 1 p.Vencimiento FROM Puc as p WHERE p.IdCuenta = (SELECT TOP 1 IdCuenta FROM @Trn_TraEspAnticipos)) = 0  THEN 
					NumCheque 
				ELSE 
					ISNULL(NumCheque, @Anticipo) 
				END) 
			ELSE 
				(CASE WHEN @consecutivoCh > 0 THEN Convert(Varchar(20),@consecutivoCh) ELSE @numcheque END) 
			END),
			FecCheque,IdCta,IdCuenta,Beneficiario,CedBenef,Cantidad,FechaVence,
			NumPresAnt,@TipComp, @Comprobante, @IdCiaComp,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,TimeSys,FecUpdate,
			IdCiaCrea,IdUsuario,PreAnticipo
			FROM @Trn_TraEspAnticipos

			--IF(EXISTS(SELECT * FROM @dataTypeTrn_ComFactura))
			--BEGIN
			--INSERT INTO Trn_ComFactura(
			--TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,
			--VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,
			--DocRef,IdCiaRef,EstadoApr,MontoAprob
			--)
			--SELECT 
			--TipFac,CONVERT(VARCHAR(15), @Anticipo),IdCia,Item,IdProveedor,IdCuenta,@TDAnt,@Anticipo,@CiaAnt,FecEmision,FecVence,
			--VrFactura,VrAbonado,@TipComp,@Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,
			--DocRef,IdCiaRef,EstadoApr
			--FROM @dataTypeTrn_ComFactura
			--END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
			INSERT INTO Trn_Comprobantes(
			TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
			TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
			CodRes, DescServicio
			)
			SELECT 
			@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			NumCheque, FecCheque, @TDAnt, @Anticipo, @CiaAnt, Anulado, NumDev, FecDev,
			TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
			CodRes, DescServicio
			FROM @Trn_Comprobantes
			END

			IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			BEGIN
			INSERT INTO Trn_ComDetalle(
			TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
			IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
			IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
			NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
			CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
			IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
			)
			SELECT 
			@TipComp, @Comprobante, @IdCiaComp, cd.Item, cd.Fecha, cd.IdCuenta, cd.Detalle, cd.VrDebito, cd.VrCredito,
			cd.IdTercero, cd.IdVehiculo, cd.IdCCosto, cd.IdSubCos, cd.VrBase, cd.TarifaBase, @TDAnt, @Anticipo, @CiaAnt,
			cd.CodConce, cd.NitDoc, 
			(CASE WHEN (SELECT TOP 1 p.Vencimiento FROM Puc as p WHERE p.IdCuenta = cd.IdCuenta) = 1  THEN ISNULL(@TipFac, (case WHEN cd.TipFac <> '' THEN @TDAnt ELSE '' END)) ELSE (case WHEN cd.TipFac <> '' THEN @TDAnt ELSE '' END) END), 
			(CASE WHEN (SELECT TOP 1 p.Vencimiento FROM Puc as p WHERE p.IdCuenta = cd.IdCuenta) = 1  THEN ISNULL(@Factura, (case WHEN cd.Factura <> '' THEN CONVERT(varchar(15), @Anticipo) ELSE '' END)) ELSE (case WHEN cd.Factura <> '' THEN CONVERT(varchar(15), @Anticipo) ELSE '' END) END), 
			(CASE WHEN (SELECT TOP 1 p.Vencimiento FROM Puc as p WHERE p.IdCuenta = cd.IdCuenta) = 1  THEN ISNULL(@IdCiaFac, (case WHEN cd.IdCiaFac <> '' THEN @CiaAnt ELSE '' END))ELSE (case WHEN cd.TipFac <> '' THEN @CiaAnt ELSE '' END) END),  
			cd.ItemFac, cd.FecVence, cd.CodCta,
			cd.NumCheque, cd.Integrado, cd.TipoAplica, cd.Consolida, cd.CodCargo, cd.NitOtros, cd.CodSubgpo, cd.CiuOrigen, 
			cd.CodAgncia,cd.VehPropio, cd.Referncia, cd.TipDocRef, cd.DocRef, cd.IdCiaRef, cd.TimeSys, cd.FecUpdate, cd.IdCiaCrea, 
			cd.IdUsuario, cd.CdConcTrib, cd.CdTarifTrib, cd.NumEstablec, cd.PtoEmision, cd.Num_Autoriza, cd.FechAutoriza,cd.CdCuentaNiif
			FROM @Trn_ComDetalle cd
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			BEGIN
			INSERT INTO Trn_NiifComp(
			TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
			EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
			FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
			VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
			IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
			Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
			CtbTipo, CtbNumero,
			FisTipo, FisNumero 
			)
			SELECT 
			CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
			CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
			@CiaAnt,
			C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
			C.EnEfectivo, C.NumCheque, C.FecCheque, @TDAnt, @Anticipo, @CiaAnt, C.Anulado, C.NumDev,
			C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
			C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
			C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
			C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
			CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
		    CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
			FROM @Trn_Comprobantes AS C 
			JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			BEGIN
			INSERT INTO Trn_NiifDetalle(
			TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
			VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
			VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
			NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
			NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
			CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
			DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
			CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
			FechAutoriza, CodCuentaCG
			)
			SELECT 
			CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
			CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
			@CiaAnt,
			N.Item, N.Fecha, N.IdCuenta, N.Detalle,
			N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
			N.VrBase, N.TarifaBase, @TDAnt, @Anticipo, @CiaAnt, N.CodConce,
			N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
			N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
			N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
			N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
			N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
			N.FechAutoriza, N.CodCuentaCG
			FROM @Trn_NiifDetalle as N
			JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante

			END
			IF(EXISTS(SELECT * FROM @Trn_ComFactura))--5042 SE AGREGA ANTICIPOS DE COMBUSTIBLES
			BEGIN
				INSERT INTO Trn_ComFactura(
				TipFac, Factura, IdCia, Item, IdProveedor, IdCuenta, TipDoc, Documento, IdCiaDoc, 
				FecEmision, FecVence, VrFactura, VrAbonado, TipCom, Comprobante, ItemCom, Referencia, 
				Detalle, pVehiculo, VehPropio, TipRef, DocRef, IdCiaRef, EstadoApr, MontoAprob
				)
				SELECT 
				ISNULL(TipFac, @TDAnt), ISNULL(Factura, @Anticipo),  ISNULL(IdCia, @CiaAnt), 1, IdProveedor, 
				IdCuenta, @TDAnt, @Anticipo, @CiaAnt, FecEmision, FecVence, VrFactura, VrAbonado, @TipComp, 
				@Comprobante, 0, Referencia, Detalle, pVehiculo, VehPropio, TipRef, DocRef, IdCiaRef, EstadoApr, 
				MontoAprob
				FROM @Trn_ComFactura 
			END

			END

			if(@operacion = 's')
			begin
				update Trn_TraEspAnticipos 
				set  VrAbonado = t1.VrAnticipo 
				from Trn_TraEspAnticipos t1, @Trn_TraEspAnticipos t2
				where t1.TipDoc = t2.TipDoc  and t1.Anticipo = t2.Anticipo and t1.IdCia = t2.IdCia
			end
						
			SELECT @Anticipo,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspCausacion]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspCausacion]
	@Trn_TraEspCausacion [dbo].[dataTypeTrn_TraEspCausacion] READONLY,
	@Trn_TraEspCauDetalle [dbo].[dataTypeTrn_TraEspCauDetalle] READONLY,
	@Trn_ComFactura [dbo].[dataTypeTrn_ComFactura] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY		 
			
			IF(@operacion = 'i')
			BEGIN
			SELECT TOP 1 @TipDoc = TipDoc, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_TraEspCausacion
			SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

			IF(@Numero > 0)
				UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
			ELSE
			BEGIN
				SELECT @Numero = 1
				INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
				SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1
					INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
				SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1
					INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
				SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1
					INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END
			END

			IF(@operacion = 'i')
			begin
				IF(EXISTS(SELECT * FROM @Trn_TraEspCausacion))
				BEGIN
				INSERT INTO Trn_TraEspCausacion(
				TipDoc,Causacion,IdCia,Fecha,IdConcepto,IdProv,Factura,VrTotal,VrOtros,VrNeto,
				TipCom,Comprobante,IdCiaCom,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,
				TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Fecha,IdConcepto,IdProv,Factura,VrTotal,VrOtros,VrNeto,
				@TipComp, @Comprobante, @IdCiaComp,Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,
				TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				FROM @Trn_TraEspCausacion
				END 

				IF(EXISTS(SELECT * FROM @Trn_TraEspCauDetalle))
				BEGIN
				INSERT INTO Trn_TraEspCauDetalle(
				TipDoc,Causacion,IdCia,Item,IdConcepto,Descripcion,TipoConc,VrDebito,VrCredito,CdCuenta,
				NitTercero,CdCCosto,CdSubCos,pVehiculo,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,
				TipFac,Factura,IdCiaFac,ItemFac,FecVence,EstadoReg,TipoLiq,NumLiquida,CiaLiquida,VrAbonado
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Item,IdConcepto,Descripcion,TipoConc,VrDebito,VrCredito,CdCuenta,
				NitTercero,CdCCosto,CdSubCos,pVehiculo,TipoAfiVehic,VrBase,TarifBase,Referencia,TipDocRef,DocRef,
				TipFac,Factura,IdCiaFac,ItemFac,FecVence,EstadoReg,TipoLiq,NumLiquida,CiaLiquida,VrAbonado
				FROM @Trn_TraEspCauDetalle
				END 

				IF(EXISTS(SELECT * FROM @Trn_ComFactura))
				BEGIN
				INSERT INTO Trn_ComFactura(
				TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,
				VrFactura,VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,
				DocRef,IdCiaRef,EstadoApr,MontoAProb
				)
				SELECT 
				TipFac,Factura,@Cia,Item,IdProveedor,IdCuenta,@TipDoc,@Numero,@Cia,FecEmision,FecVence,
				VrFactura,VrAbonado,@TipComp,@Comprobante,ItemCom,Referencia,Detalle,pVehiculo,VehPropio,TipRef,
				DocRef,IdCiaRef,EstadoApr,MontoAprob
				FROM @Trn_ComFactura
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
				INSERT INTO Trn_Comprobantes(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
				CodRes, DescServicio
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
				CodRes, DescServicio
				FROM @Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
				INSERT INTO Trn_ComDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,IdCiaDoc, 
				CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, cd.Item, cd.Fecha, cd.IdCuenta, cd.Detalle, cd.VrDebito, cd.VrCredito,
				cd.IdTercero, cd.IdVehiculo, cd.IdCCosto,cd.IdSubCos, cd.VrBase , cd.TarifaBase, @TipDoc, @Numero, @Cia,
				cd.CodConce, cd.NitDoc, cd.TipFac, cd.Factura, cd.IdCiaFac, cd.ItemFac, cd.FecVence, cd.CodCta,
				cd.NumCheque, cd.Integrado, cd.TipoAplica, cd.Consolida, cd.CodCargo, cd.NitOtros, cd.CodSubgpo, cd.CiuOrigen, 
				cd.CodAgncia, cd.VehPropio, cd.Referncia, cd.TipDocRef, cd.DocRef, cd.IdCiaRef, cd.TimeSys, cd.FecUpdate, cd.IdCiaCrea, 
				cd.IdUsuario, cd.CdConcTrib, cd.CdTarifTrib, cd.NumEstablec, cd.PtoEmision, cd.Num_Autoriza, cd.FechAutoriza,cd.CdCuentaNiif
				FROM @Trn_ComDetalle cd
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
				INSERT INTO Trn_NiifComp(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
				EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
				FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
				VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
				IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
				Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
				CtbTipo, CtbNumero,
				FisTipo, FisNumero 
				)
				SELECT 
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@Cia, 
				C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
				C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
				C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
				C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
				C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
				C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
				CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				INSERT INTO Trn_NiifDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				FechAutoriza, CodCuentaCG
				)
				SELECT 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@Cia,
				N.Item, N.Fecha, N.IdCuenta, N.Detalle,
				N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
				N.VrBase, N.TarifaBase, @TipDoc, @Numero, @Cia, N.CodConce,
				N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
				N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
				N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
				N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
				N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
				N.FechAutoriza, N.CodCuentaCG
				FROM @Trn_NiifDetalle as N
				JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
				END
			end
						
			IF(@operacion = 'a')
			begin
				update Trn_TraEspCausacion 
				set  Anulado = '1', FecUpdate = GETDATE() 
				from  Trn_TraEspCausacion t1, @Trn_TraEspCausacion t2
				where t1.TipDoc = t2.TipDoc  and t1.Causacion = t2.Causacion and t1.IdCia = t2.IdCia
				select @Numero = (select Causacion from @Trn_TraEspCausacion)
			end

			if(@operacion = 's')
			begin
				update Trn_TraEspCauDetalle 
				set  
				VrAbonado = (t2.VrDebito + t2.VrCredito), EstadoReg = 1, 
				TipoLiq = t2.TipDoc, NumLiquida = t2.Causacion, CiaLiquida = t2.IdCia 
				from Trn_TraEspCauDetalle t1, @Trn_TraEspCauDetalle t2
				where t1.TipDoc = t2.TipDoc  and t1.Causacion = t2.Causacion and t1.IdCia = t2.IdCia  and t1.Item = t2.Item

				select @Numero = (select top 1 Causacion from @Trn_TraEspCauDetalle)
			end

			SELECT @Numero,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspConceptos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspConceptos]
	@Trn_TraEspConceptos [dbo].[dataTypeTrn_TraEspConceptos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Pedido/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Pedido/CotizaciÃ³n
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Pedido/CotizaciÃ³n
DECLARE @ItemNov int
DECLARE @ItemDoc int
DECLARE @Cliente bit
DECLARE @Vehiculo bit
BEGIN TRAN
		BEGIN TRY
		--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
				BEGIN
					IF(EXISTS(SELECT COUNT(1) FROM @Trn_TraEspConceptos))
						BEGIN
							SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Documento FROM @Trn_TraEspConceptos
							SELECT @ItemNov =  isnull(MAX(Item),0) FROM Trn_TraEspConceptos WHERE TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia

							--actualizar los que vienen en el tipo de dato y coincidan con los que ya estan en la tabla
							UPDATE Trn_TraEspConceptos
							SET 
							TipDoc = t2.TipDoc,Documento = t2.Documento,IdCia = t2.IdCia,Item = t2.Item,
							Descripcion = t2.Descripcion,Tarifa = t2.Tarifa,TipoConc = t2.TipoConc,
							RubroConcep = t2.RubroConcep,Cantidad = t2.Cantidad,VrUnitario = t2.VrUnitario,
							TarifIva = t2.TarifIva,IdConcepto = t2.IdConcepto,CdCuenta = t2.CdCuenta,
							NitTercero = t2.NitTercero,CdTipoEsc = t2.CdTipoEsc,FechaNov = t2.FechaNov,
							VrBase = t2.VrBase,TipoTarif = t2.TipoTarif,RefConc = t2.RefConc,Fijos = t2.Fijos,
							IncBaseRet = t2.IncBaseRet,Referencia2 = t2.Referencia2,Referencia3 = t2.Referencia3,
							Cliente = t2.Cliente,Conductor = t2.Conductor,Vehiculo=t2.Vehiculo,ItemDoc=t2.ItemDoc,
							IdVehiculo = t2.IdVehiculo
							FROM Trn_TraEspConceptos t1
							JOIN @Trn_TraEspConceptos t2 ON t1.TipDoc = t2.TipDoc and t1.Documento = t2.Documento and t1.IdCia = t2.IdCia and t1.Item = t2.Item
							WHERE t1.TipDoc = t2.TipDoc and t1.Documento = t2.Documento and t1.IdCia = t2.IdCia and t1.Item = t2.Item
							--Inserta los que no existen
							INSERT INTO Trn_TraEspConceptos(
							TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
							TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
							CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
							IncBaseRet,Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo)
							SELECT 
							TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
							TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
							CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
							IncBaseRet,Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
							FROM @Trn_TraEspConceptos
							WHERE (TipDoc + Convert(varchar,Documento)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Documento)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspConceptos)
							--Eliminar los que no existen en el tipo de dato
							DELETE FROM Trn_TraEspConceptos
							WHERE TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @Trn_TraEspConceptos)
						END
					END

			--INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
				BEGIN
					IF(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
						BEGIN
							SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Documento, @ItemDoc = ItemDoc, @Cliente = Cliente, @Vehiculo = Vehiculo FROM @Trn_TraEspConceptos
							DELETE FROM Trn_TraEspConceptos WHERE TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia and ItemDoc = @ItemDoc  and Cliente = @Cliente and Vehiculo = @Vehiculo
							INSERT INTO Trn_TraEspConceptos(
							TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
							TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
							CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
							IncBaseRet,Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
							) 
							SELECT 
							TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
							TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
							CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
							IncBaseRet,Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
							FROM @Trn_TraEspConceptos
						END
				END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
				SELECT @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Documento, @ItemNov = Item, @ItemDoc = ItemDoc, @Cliente = Cliente, @Vehiculo = Vehiculo from @Trn_TraEspConceptos
				DELETE FROM Trn_TraEspConceptos WHERE TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia and Item = @ItemNov and ItemDoc = @ItemDoc and Cliente = @Cliente and Vehiculo = @Vehiculo
			END
				SELECT '1'
			COMMIT TRAN
		END TRY
BEGIN CATCH
	ROLLBACK TRAN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;

	SELECT 
	@ErrorMessage = ERROR_MESSAGE(),
	@ErrorSeverity = ERROR_SEVERITY(),
	@ErrorState = ERROR_STATE();
	RAISERROR(
	@ErrorMessage, -- Message text.
	@ErrorSeverity, -- Severity.
	@ErrorState -- State.
	);
END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspContratos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspContratos]
	@Trn_TraEspContratos [dbo].[dataTypeTrn_TraEspContratos] READONLY,
	@Trn_TraEspContratoAnexo [dbo].[dataTypeTrn_TraEspContratoAnexo] READONLY,
	@Trn_TraEspContratoDet [dbo].[dataTypeTrn_TraEspContratoDet] READONLY,
	@Trn_TraEspConceptos [dbo].[dataTypeTrn_TraEspConceptos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Contrato/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Contrato/CotizaciÃ³n
DECLARE @IdCia VARCHAR(2) --Esta variable guarda la compaÃ±ia del Contrato/CotizaciÃ³n
declare @item int
	BEGIN TRAN
		BEGIN TRY

			--Seleccionar Variables
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia FROM @Trn_TraEspContratos
				SELECT @Documento = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

				IF(@Documento <> '')
					UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
				ELSE
				BEGIN
					SELECT @Documento = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			end

			--Seleccionar Variables
			--IF(@operacion = 'u')
			--begin
			--	SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Contrato FROM @Trn_TraEspContratos
			--end

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN
			   if(EXISTS(SELECT * FROM @Trn_TraEspContratos))
			   begin
			   UPDATE Trn_TraEspContratos
			   SET 
			   TipDoc = t2.TipDoc,Contrato = t2.Contrato,IdCia = t2.IdCia,Fecha = t2.Fecha,FechaInicio = t2.FechaInicio,FechaFin = t2.FechaFin,
			   IdCliente = t2.IdCliente,IdVend = t2.IdVend,IdTarifCom = t2.IdTarifCom,IdForma = t2.IdForma,Plazos = t2.Plazos,TipoPago = t2.TipoPago,
			   Modalidad = t2.Modalidad,TipoLiquid = t2.TipoLiquid,CodTarRet = t2.CodTarRet,CodTarIca = t2.CodTarIca,VrPresupuesto = t2.VrPresupuesto,VrSaldoPresup = t2.VrSaldoPresup,
			   VrCobro = t2.VrCobro,VrCargos = t2.VrCargos,VrRetencion = t2.VrRetencion,VrReteIca = t2.VrReteIca,VrDctos = t2.VrDctos,Cantidad = t2.Cantidad,
			   Peso = t2.Peso,NumAprob = t2.NumAprob,IdCiaApr = t2.IdCiaApr,FecAprob = t2.FecAprob,TipOdp = t2.TipOdp,NumOdp = t2.NumOdp,IdCiaOdp = t2.IdCiaOdp,
			   FechaOdp = t2.FechaOdp,TipFac = t2.TipFac,Factura = t2.Factura,IdCiaFac = t2.IdCiaFac,FechaFac = t2.FechaFac,OrigenAdd = t2.OrigenAdd,
			   EsLicitacion = t2.EsLicitacion,Anulado = t2.Anulado,FecDev = t2.FecDev,Observacion = t2.Observacion,IdEstado = t2.IdEstado,TimeSys = t2.TimeSys,
			   FecUpdate = t2.FecUpdate,IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario,CdCarga = t2.CdCarga,IdAgencia = t2.IdAgencia,IdMneda = t2.IdMneda,
			   VrIva = t2.VrIva,CantPasajeros = t2.CantPasajeros, CdDescuento = t2.CdDescuento,UnionTemporal = t2.UnionTemporal,IdGrupo = t2.IdGrupo,IdRutaG = t2.IdRutaG
		       FROM Trn_TraEspContratos t1
			   JOIN @Trn_TraEspContratos t2 ON t1.TipDoc = t2.TipDoc and t1.Contrato = t2.Contrato and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspContratoAnexo))
			   begin
			   UPDATE Trn_TraEspContratoAnexo
			   SET 
			   TipDoc = t2.TipDoc,Contrato = t2.Contrato,IdCia = t2.IdCia,TipContrato = t2.TipContrato,IdContrato = t2.IdContrato,IdObjCOE = t2.IdObjCOE, ObjContrato = t2.ObjContrato,
			   NomCliente = t2.NomCliente,TelCliente = t2.TelCliente,emlCliente = t2.emlCliente,DireccionCli = t2.DireccionCli,Observacion = t2.Observacion,
			   NombArchivo = t2.NombArchivo,DescripCarga = t2.DescripCarga,Clausulas = t2.Clausulas,Responsable = t2.Responsable,NombreResp=t2.NombreResp
		       FROM Trn_TraEspContratoAnexo t1
			   JOIN @Trn_TraEspContratoAnexo t2 ON t1.TipDoc = t2.TipDoc and t1.Contrato = t2.Contrato and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspContratoDet))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Contrato FROM @Trn_TraEspContratoDet
			   select @item = isnull(MAX(Item),0) from Trn_TraEspContratoDet where TipDoc = @TipDoc and Contrato = @Documento and IdCia = @IdCia

			   --actualizar los que vienen en el tipo de dato y coincida con los que ya estÃ¡n en la tabla
			   UPDATE Trn_TraEspContratoDet
			   SET 
			   TipDoc = t2.TipDoc,Contrato = t2.Contrato,IdCia = t2.IdCia,Item = t2.Item,IdHorario = t2.IdHorario,TipPed = t2.TipPed,Pedido = t2.Pedido,CiaPed = t2.CiaPed,
			   ItemPed = t2.ItemPed,TipRes = t2.TipRes,NumRes = t2.NumRes,IdCiaRes = t2.IdCiaRes,ItemRes = t2.ItemRes,IdVehiculo = t2.IdVehiculo,
			   CdTipVeh = t2.CdTipVeh,NumPasajeros = t2.NumPasajeros,PesoNeto = t2.PesoNeto,VrUnitario = t2.VrUnitario,VrPago= t2.Vrpago,
			   IdRuta = t2.IdRuta,Referencia1 = t2.Referencia1,Referencia2 = t2.Referencia2,Referencia3 = t2.Referencia3,EsRutaCliente = t2.EsRutaCliente,
			   CdCiuOrigen = t2.CdCiuOrigen,DirOrigen = t2.DirOrigen,FecOrigen = t2.FecOrigen,CdCiuDestino = t2.CdCiuDestino,DirDestino = t2.DirDestino,
			   FecDestino = t2.FecDestino,DiasDisp = t2.DiasDisp,VrDia = t2.VrDia,Parada = t2.Parada,CdTipRuta = t2.CdTipRuta,CdTipServicio = t2.CdTipServicio,
			   CantVeh=t2.CantVeh,Retorno=t2.Retorno,VrMonitor=t2.VrMonitor,CantMonitor=t2.CantMonitor,VrMaxRec=t2.VrMaxRec,NumDias=t2.NumDias,TipoTarifa=t2.TipoTarifa,IdColegio = t2.IdColegio,Codigo = t2.Codigo,
			   Itinerario = t2.Itinerario, VLargo = t2.VLargo, IdOtroSi = t2.IdOtroSi, ItemAnuladoOS = t2.ItemAnuladoOS, EsItemPME = t2.EsItemPME
		       FROM Trn_TraEspContratoDet t1
			   JOIN @Trn_TraEspContratoDet t2 ON t1.TipDoc = t2.TipDoc and t1.Contrato = t2.Contrato and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Contrato = t2.Contrato and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspContratoDet(
			   TipDoc,Contrato,IdCia,Item,IdHorario,
			   TipPed,Pedido,CiaPed,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
				Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
				DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,
				IdOtroSi,ItemAnuladoOS,EsItemPME
				) 
				SELECT 
				@TipDoc,@Documento,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),IdHorario,
				TipPed,Pedido,@IdCia,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
				Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
				DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,
				IdOtroSi,ItemAnuladoOS,EsItemPME
				FROM @Trn_TraEspContratoDet
				WHERE (TipDoc + Convert(varchar,Contrato)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Contrato)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspContratoDet)
			   --Eliminar los que no existen en lo que envian
			   delete from Trn_TraEspContratoDet
			   WHERE TipDoc = @TipDoc and Contrato = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @Trn_TraEspContratoDet)

			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Documento FROM @Trn_TraEspConceptos
			   select @item = isnull(MAX(Item),0) from Trn_TraEspConceptos where TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia
			   
			   --actualizar los que vienen en el tipo de dato y coincida con los que ya estÃ¡n en la tabla
			   UPDATE Trn_TraEspConceptos
			   SET 
			   TipDoc = t2.TipDoc,Documento = t2.Documento,IdCia = t2.IdCia,Item = t2.Item,
			   Descripcion = t2.Descripcion,Tarifa = t2.Tarifa,TipoConc = t2.TipoConc,
			   RubroConcep = t2.RubroConcep,Cantidad = t2.Cantidad,VrUnitario = t2.VrUnitario,
			   TarifIva = t2.TarifIva,IdConcepto = t2.IdConcepto,CdCuenta = t2.CdCuenta,
			   NitTercero = t2.NitTercero,CdTipoEsc = t2.CdTipoEsc,FechaNov = t2.FechaNov,
			   VrBase = t2.VrBase,TipoTarif = t2.TipoTarif,RefConc = t2.RefConc,Fijos = t2.Fijos,
			   IncBaseRet = t2.IncBaseRet,Referencia2 = t2.Referencia2,Referencia3 = t2.Referencia3,
			   Cliente = t2.Cliente,Conductor = t2.Conductor,Vehiculo = t2.Vehiculo,ItemDoc=t2.ItemDoc,
			   IdVehiculo = t2.IdVehiculo
		       FROM Trn_TraEspConceptos t1
			   JOIN @Trn_TraEspConceptos t2 ON t1.TipDoc = t2.TipDoc and t1.Documento = t2.Documento and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Documento = t2.Documento and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspConceptos(
			    TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo)
			   SELECT 
			    @TipDoc, @Documento, @IdCia, (@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)), Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
			   FROM @Trn_TraEspConceptos
			   WHERE (TipDoc + Convert(varchar,Documento)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Documento)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspConceptos)
			   --Eliminar los que no existen en lo que envian
			   delete from Trn_TraEspConceptos
			   WHERE TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @Trn_TraEspConceptos)
			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN
				IF(EXISTS(SELECT * FROM @Trn_TraEspContratos))
				begin
				INSERT INTO Trn_TraEspContratos(
				TipDoc,Contrato,IdCia,Fecha,FechaInicio,FechaFin,IdCliente,IdVend,IdTarifCom,IdForma,Plazos,TipoPago,Modalidad,TipoLiquid,CodTarRet,CodTarIca,
				VrPresupuesto,VrSaldoPresup,VrCobro,VrCargos,VrRetencion,VrReteIca,VrDctos,Cantidad,Peso,NumAprob,IdCiaApr,FecAprob,TipOdp,NumOdp,
				IdCiaOdp,FechaOdp,TipFac,Factura,IdCiaFac,FechaFac,OrigenAdd,EsLicitacion,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,
				IdUsuario,CdCarga,IdAgencia,IdMneda,VrIva,CantPasajeros,CdDescuento,UnionTemporal,IdGrupo,IdRutaG
				)
				SELECT 
				@TipDoc,@Documento,@IdCia,Fecha,FechaInicio,FechaFin,IdCliente,IdVend,IdTarifCom,IdForma,Plazos,TipoPago,Modalidad,TipoLiquid,CodTarRet,CodTarIca,
				VrPresupuesto,VrPresupuesto,VrCobro,VrCargos,VrRetencion,VrReteIca,VrDctos,Cantidad,Peso,NumAprob,IdCiaApr,FecAprob,TipOdp,NumOdp,
				IdCiaOdp,FechaOdp,TipFac,Factura,IdCiaFac,FechaFac,OrigenAdd,EsLicitacion,Anulado,FecDev,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,
				IdUsuario,CdCarga,IdAgencia,IdMneda,VrIva,CantPasajeros,CdDescuento,UnionTemporal,IdGrupo,IdRutaG
				FROM @Trn_TraEspContratos
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspContratoAnexo))
				begin
				INSERT INTO Trn_TraEspContratoAnexo(
				TipDoc,Contrato,IdCia,TipContrato,IdContrato,IdObjCOE,ObjContrato,NomCliente,TelCliente,emlCliente,DireccionCli,
				Observacion,NombArchivo,DescripCarga,Clausulas,Responsable,NombreResp
				) 
				SELECT 
				@TipDoc, @Documento, @IdCia,TipContrato,IdContrato,IdObjCOE,ObjContrato,NomCliente,TelCliente,emlCliente,DireccionCli,
				Observacion,NombArchivo,DescripCarga,Clausulas,Responsable,NombreResp
				FROM @Trn_TraEspContratoAnexo
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspContratoDet))
				begin
				INSERT INTO Trn_TraEspContratoDet(
			    TipDoc,Contrato,IdCia,Item,IdHorario,TipPed,Pedido,CiaPed,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
				Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
				DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,IdOtroSi,ItemAnuladoOS,
				EsItemPME
				) 
				SELECT 
				@TipDoc,@Documento,@IdCia,Item,IdHorario,TipPed,Pedido,@IdCia,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
				Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
				DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,IdOtroSi,ItemAnuladoOS,
				EsItemPME
				FROM @Trn_TraEspContratoDet
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
				BEGIN
				INSERT INTO Trn_TraEspConceptos(
				TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
				) 
				SELECT 
				@TipDoc, @Documento, @IdCia, Item, Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
				FROM @Trn_TraEspConceptos
				END

			    --Actualizar cotizaciÃ³n
			    UPDATE Trn_TraEspPedDetalle
			    SET TipCtn = @TipDoc, NumCnt = @Documento, IdCiaCnt = @IdCia,ItemCnt = d.Item
			    FROM Trn_TraEspPedDetalle p, @Trn_TraEspContratoDet d 
			    WHERE p.TipDoc = 'CTE'  and p.Pedido = d.Pedido and p.IdCia = d.CiaPed and p.Item = d.ItemPed and d.Pedido > 0 and d.CiaPed <> '00'

			    --Actualizar Contratos
			    IF(((SELECT upper(Modalidad) FROM @Trn_TraEspContratos) = 'OCASIONAL') AND ((SELECT Valor FROM adm_Opciones WHERE IdOpc = 'ACO') = '0'))
			    BEGIN
				  UPDATE Trn_TraEspContratos 
				  SET IdEstado = '9998'
				  WHERE TipDoc = @TipDoc and Contrato = @Documento and IdCia = @IdCia
			    END

			    --Actualizar Facturas de Contado
			    IF((SELECT TipoPago FROM @Trn_TraEspContratos) = '0001')
			    BEGIN
				  UPDATE Trn_Factcon
				  SET TipRem = 'COE', Remision = @Documento, IdCiaRem = @IdCia
				  FROM Trn_Factcon F, @Trn_TraEspContratos C
				  WHERE F.TipDoc = C.TipFac and F.Factura = C.Factura and F.IdCia = C.IdCiaFac
			    END

			 END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 declare @Contrato int
			 select @TipDoc = TipDoc, @IdCia = IdCia,  @Contrato = Contrato from @Trn_TraEspContratos
				 DELETE FROM Trn_TraEspContratoAnexo WHERE TipDoc = @TipDoc and Contrato = @Contrato and IdCia = @IdCia
				 DELETE FROM Trn_TraEspContratoDet WHERE TipDoc = @TipDoc and Contrato = @Contrato and IdCia = @IdCia
				 DELETE FROM Trn_TraEspConceptos WHERE TipDoc = @TipDoc and Documento = @Contrato and IdCia = @IdCia
				 DELETE FROM Trn_TraEspContratos WHERE TipDoc = @TipDoc and Contrato = @Contrato and IdCia = @IdCia
			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
			  --declare @IdEstado varchar(4)
			  --select @IdEstado = IdEstado from EstadoDoc where Estado = 'ANULADO'
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Contrato from @Trn_TraEspContratos
			  UPDATE Trn_TraEspContratos SET IdEstado = '9999', Anulado = '1' WHERE TipDoc = @TipDoc and Contrato = @Documento and IdCia = @IdCia

			  UPDATE Trn_TraEspPedDetalle
			  SET TipCtn = 'COE', NumCnt = 0, IdCiaCnt = '00',ItemCnt = 0
			  FROM Trn_TraEspPedDetalle p, @Trn_TraEspContratos d 
			  WHERE p.TipCtn = 'COE'  and p.NumCnt = d.Contrato and p.IdCiaCnt = d.IdCia --and p.Item = d.ItemPed

			  --Actualizar Facturas de Contado
			  IF((SELECT TipoPago FROM @Trn_TraEspContratos) = '0001')
			  BEGIN
				UPDATE Trn_Factcon
				SET TipRem = 'REM', Remision = 0, IdCiaRem = '00'
				FROM Trn_Factcon F, @Trn_TraEspContratos C
				WHERE F.TipDoc = C.TipFac and F.Factura = C.Factura and F.IdCia = C.IdCiaFac
			  END
			END

			SELECT @Documento

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspCumplido]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspCumplido]
	@Trn_TraEspCumplido [dbo].[dataTypeTrn_TraEspCumplido] READONLY,
	@Trn_TraEspCumReservas [dbo].[dataTypeTrn_TraEspCumReservas] READONLY,
	@Trn_TraEspCumplidoProg [dbo].[dataTypeTrn_TraEspCumplidoProg] READONLY,
	@Trn_TraEspCumFacturas [dbo].[dataTypeTrn_TraEspCumFacturas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @CiaDoc VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cumplido INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @FechaCum smalldatetime
	BEGIN TRAN
		BEGIN TRY		 

			IF(@operacion = 'i')
			BEGIN

				SELECT TOP 1 @TDoc = TipDoc, @CiaDoc = IdCia,  @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia, @FechaCum = Fecha FROM @Trn_TraEspCumplido
				SELECT @Cumplido = Numero + 1  FROM TiposDocCons where IdDoc = @TDoc AND IdCia = @CiaDoc

				IF(@Cumplido > 0)
					UPDATE TiposDocCons SET Numero = @Cumplido WHERE IdDoc = @TDoc AND IdCia = @CiaDoc
				ELSE
				BEGIN
					SELECT @Cumplido = 1
					INSERT INTO TiposDocCons VALUES (@TDoc,@CiaDoc,0,0,0,0,NULL,'',@Cumplido,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
					SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
					--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
					IF(@Comprobante <> '')
						UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
					ELSE
					BEGIN
						SELECT @Comprobante = 1
						INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
				BEGIN
					SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
					SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif

					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
					ELSE
					BEGIN
						SELECT @CompNiif = 1
						INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
				BEGIN
					SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
					SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis

					IF(@CompFis <> '')
						UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
					ELSE
					BEGIN
						SELECT @CompFis = 1
						INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END
			END

			IF(@operacion = 'i')
			BEGIN

				IF(EXISTS(SELECT * FROM @Trn_TraEspCumplido))
				begin
				INSERT INTO Trn_TraEspCumplido(
				TipDoc, Cumplido, IdCia, Fecha, TipRes, Reserva, IdCiaRes,ItemRes,TipFac,Factura,IdCiaFac,IdClieFac, CdRuta, CdOrigen, CdDestino, Anulado,
				NumDev, FecDev, TipoComp, NumComp, CodConcepto, Observacion, IdEstado, OrigenAdd, TimeSys, FecUpdate,
				IdCiaCrea, IdUsuario, ObservAnulado, CdCenCosto, CdSubCenCos,VrPago,VrCobro, VrAfiliados, VrPropios, VrTotalServ, 
				VrTotalPagos, CodTarRtc, BaseRet, VrReteCree, VrNeto
				)
				SELECT 
				@TDoc,@Cumplido,@CiaDoc, Fecha, TipRes, Reserva, IdCiaRes,ItemRes,TipFac,Factura,IdCiaFac,IdClieFac, CdRuta, CdOrigen, CdDestino, Anulado,
				NumDev, FecDev, @TipComp, @Comprobante, CodConcepto, Observacion, IdEstado, OrigenAdd, TimeSys, FecUpdate,
				IdCiaCrea, IdUsuario, ObservAnulado, CdCenCosto, CdSubCenCos,VrPago,VrCobro, VrAfiliados, VrPropios, VrTotalServ, 
				VrTotalPagos, CodTarRtc, BaseRet, VrReteCree, VrNeto
				FROM @Trn_TraEspCumplido
				end 

				IF(EXISTS(SELECT * FROM @Trn_TraEspCumReservas))
				begin
				INSERT INTO Trn_TraEspCumReservas(
				TipDoc,Cumplido,IdCia,Item,TipRes,Reserva,IdCiaRes,ItemRes,EstadoItemRes,VrRecorridos,
				IdVehiculo,IdPoseedor,IdConductor,TipoAfil
				)
				SELECT 
				@TDoc,@Cumplido,@CiaDoc,Item,TipRes,Reserva,IdCiaRes,ItemRes,EstadoItemRes,VrRecorridos,
				IdVehiculo,IdPoseedor,IdConductor,TipoAfil
				FROM @Trn_TraEspCumReservas
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspCumplidoProg))
				begin
				INSERT INTO Trn_TraEspCumplidoProg(
				 TipDoc,Cumplido,IdCia,Item,TipRes,Reserva,IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr,VrRecorrido
				)
				SELECT 
				@TDoc,@Cumplido,@CiaDoc,Item,TipRes,Reserva,IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr,VrRecorrido
				FROM @Trn_TraEspCumplidoProg
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspCumFacturas))
				begin
				INSERT INTO Trn_TraEspCumFacturas(
				 TipDoc, Cumplido, IdCia, TipFac, Factura, IdCiaFac, IdCliente, VrIngreso
				)
				SELECT 
				@TDoc,@Cumplido,@CiaDoc, TipFac, Factura, IdCiaFac, IdCliente, VrIngreso
				FROM @Trn_TraEspCumFacturas
				end

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
				INSERT INTO Trn_Comprobantes(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
				CodRes, DescServicio
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, @TDoc, @Cumplido, @CiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
				CodRes, DescServicio
				FROM @Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
				INSERT INTO Trn_ComDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
				IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, cd.Item, cd.Fecha, cd.IdCuenta, cd.Detalle, cd.VrDebito, cd.VrCredito,
				cd.IdTercero, cd.IdVehiculo, cd.IdCCosto, cd.IdSubCos, cd.VrBase, cd.TarifaBase, @TDoc, @Cumplido, @CiaDoc,
				cd.CodConce, cd.NitDoc, case WHEN cd.TipFac <> '' THEN @TDoc ELSE '' END, case WHEN cd.TipFac <> '' THEN @Cumplido ELSE '' END, case WHEN cd.TipFac <> '' THEN @CiaDoc ELSE '' END, 
				cd.ItemFac, cd.FecVence, cd.CodCta,
				cd.NumCheque, cd.Integrado, cd.TipoAplica, cd.Consolida, cd.CodCargo, cd.NitOtros, cd.CodSubgpo, cd.CiuOrigen, 
				cd.CodAgncia,cd.VehPropio, cd.Referncia, cd.TipDocRef, cd.DocRef, cd.IdCiaRef, cd.TimeSys, cd.FecUpdate, cd.IdCiaCrea, 
				cd.IdUsuario, cd.CdConcTrib, cd.CdTarifTrib, cd.NumEstablec, cd.PtoEmision, cd.Num_Autoriza, cd.FechAutoriza,cd.CdCuentaNiif
				FROM @Trn_ComDetalle cd
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
				INSERT INTO Trn_NiifComp(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
				EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
				FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
				VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
				IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
				Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
				CtbTipo, CtbNumero,
				FisTipo, FisNumero 
				)
				SELECT 
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@CiaDoc,
				C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
				C.EnEfectivo, C.NumCheque, C.FecCheque, @TDoc, @Cumplido, @CiaDoc, C.Anulado, C.NumDev,
				C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
				C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
				C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
				C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
				CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM @Trn_Comprobantes AS C 
				JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				INSERT INTO Trn_NiifDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				FechAutoriza, CodCuentaCG
				)
				SELECT 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@CiaDoc,
				N.Item, N.Fecha, N.IdCuenta, N.Detalle,
				N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
				N.VrBase, N.TarifaBase, @TDoc, @Cumplido, @CiaDoc, N.CodConce,
				N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
				N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
				N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
				N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
				N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
				N.FechAutoriza, N.CodCuentaCG
				FROM @Trn_NiifDetalle as N
				JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante

				END

			END

			IF(@operacion = 'i')
			BEGIN
				--Actualizar ResDetalles
				UPDATE Trn_TraEspResDetalle
				SET TipCum = @TDoc, Cumplido = @Cumplido, IdCiaCum = @CiaDoc, FechaCum = @FechaCum
				FROM Trn_TraEspResDetalle t1, @Trn_TraEspCumReservas t2
				WHERE t1.TipDoc = t2.TipRes and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCiaRes and t1.Item = t2.ItemRes
			END

			SELECT @Cumplido,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevAnt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevAnt]
	@Trn_TraEspDevAnt [dbo].[dataTypeTrn_TraEspDevAnt] READONLY,
	@Trn_TraEspAntAbonos [dbo].[dataTypeTrn_TraEspAntAbonos] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDev VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @CiaDev VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Dev INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @DocAnt VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @IdCiaAnt VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Antic INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
declare @VrDev money 

	BEGIN TRAN
		BEGIN TRY		 
			
			--Seleecionar variables de consecutivos
			if(@operacion = 'i')
			BEGIN

				SELECT TOP 1 @TipDev = TipDev, @CiaDev = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia, @DocAnt = TipDoc, @IdCiaAnt = IdCiaDoc, @Antic = Anticipo FROM @Trn_TraEspDevAnt
				SELECT @Dev = Numero + 1  FROM TiposDocCons where IdDoc = @TipDev AND IdCia = @CiaDev

				IF(@Dev > 0)
					UPDATE TiposDocCons SET Numero = @Dev WHERE IdDoc = @TipDev AND IdCia = @CiaDev
				ELSE
				BEGIN
					SELECT @Dev = 1
					INSERT INTO TiposDocCons VALUES (@TipDev,@CiaDev,0,0,0,0,NULL,'',@Dev,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
					SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
					--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
					IF(@Comprobante <> '')
						UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
					ELSE
					BEGIN
						SELECT @Comprobante = 1
						INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
				BEGIN
					SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
					SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
					--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
					ELSE
					BEGIN
						SELECT @CompNiif = 1
						INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
				BEGIN
					SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
					SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
					--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
					ELSE
					BEGIN
						SELECT @CompFis = 1
						INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END
			
				select @VrDev = isnull((sum(VrDevolucion)),0) from Trn_TraEspDevAnt where TipDoc = @DocAnt and Anticipo = @Antic and IdCiaDoc = @IdCiaAnt

				INSERT INTO Trn_TraEspDevAnt(
				TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Anticipo,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,
				VrDevolucion,CdCta,CdCuenta,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,
				FecUpdate,IdCiaCrea,IdUsuario
				)
				SELECT 
				@TipDev,@Dev,@CiaDev,Fecha,IdConcepto,@DocAnt,@Antic,@IdCiaAnt,FecDoc,IdVehiculo,IdPoseedor,IdConductor,
				VrDevolucion,CdCta,CdCuenta,ModdDev,OrigenAdd,@TipComp,@Comprobante,@IdCiaComp,Observacion,IdEstado,TimeSys,
				FecUpdate,IdCiaCrea,IdUsuario
				FROM @Trn_TraEspDevAnt

				INSERT INTO Trn_TraEspAntAbonos(
				TipDoc,Documento,IdCia,Item,Fecha,TipAnt,Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
				)
				SELECT
				@TipDev,@Dev,@CiaDev,Item,Fecha,@DocAnt,@Antic,@IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
				FROM @Trn_TraEspAntAbonos

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
				INSERT INTO Trn_Comprobantes(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
				CodRes, DescServicio
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, @TipDev, @Dev, @CiaDev, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
				CodRes, DescServicio
				FROM @Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
				INSERT INTO Trn_ComDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
				IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDev, @Dev, @CiaDev,
				CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				FROM @Trn_ComDetalle
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
				INSERT INTO Trn_NiifComp(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
				EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
				FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
				VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
				IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
				Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
				CtbTipo, CtbNumero,
				FisTipo, FisNumero 
				)
				SELECT 
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@CiaDev, 
				C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
				C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDev, @Dev, @CiaDev, C.Anulado, C.NumDev,
				C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
				C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
				C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
				C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
				CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				INSERT INTO Trn_NiifDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				FechAutoriza, CodCuentaCG
				)
				SELECT 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@CiaDev,
				N.Item, N.Fecha, N.IdCuenta, N.Detalle,
				N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
				N.VrBase, N.TarifaBase, @TipDev, @Dev, @CiaDev, N.CodConce,
				N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
				N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
				N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
				N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
				N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
				N.FechAutoriza, N.CodCuentaCG
				FROM @Trn_NiifDetalle as N
				JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
				END

				IF(EXISTS(SELECT * FROM @Trn_EgrFactura))
				BEGIN
					DECLARE @TipFac varchar(3)
					DECLARE @Factura varchar(16)
					DECLARE @IdCiaFac varchar(2)
					DECLARE @VrAbonocf MONEY
					IF NOT EXISTS(SELECT IdCom FROM TiposCom WHERE IdCom = @TipDev) --Crea el tipo de comprobante por debajo para el tipo de devoluciÃ³n para poder gaurdar en la @Trn_EgrFactura
					begin
						INSERT INTO TiposCom VALUES(@TipDev,'DEVOLUCION DE ANTICIPOS TESPECIAL',0,0,0,1,getdate(),NULL,'CONTAB',0)
					end
					SELECT TOP 1 @TipFac = TipFac, @Factura = Factura, @IdCiaFac = IdCiaFac, @VrAbonocf = VrAbono FROM @Trn_EgrFactura
					INSERT INTO Trn_EgrFactura(
					TipCom, Comprobante, IdCia, Item, Fecha, TipFac, Factura, IdCiaFac, ItemFac, 
					IdProveedor, IdCuenta, VrAbono, EsEgreso, ItemCom, pVehiculo, VehPropio, TipDev, 
					NumDev, DetAbono
					)
					SELECT
					@TipDev,@Dev,@CiaDev, Item, Fecha, TipFac, Factura, IdCiaFac, ItemFac, 
					IdProveedor, IdCuenta, VrAbono, EsEgreso, ItemCom, pVehiculo, 
					(CASE WHEN UPPER((SELECT TipoAfil FROM Vehiculos WHERE IdVehiculo = pVehiculo)) = 'PROPIO' THEN 1 ELSE 0 END), 
					@TipDev, @Dev, DetAbono 
					FROM @Trn_EgrFactura

					UPDATE Trn_ComFactura SET VrAbonado = VrAbonado + @VrAbonocf WHERE TipFac = @TipFac AND Factura = @Factura AND IdCia = @IdCiaFac
				END
			END
			
			if(@operacion = 'i')
			begin 

				declare @VrAntic money
				declare @VrAbono money
				declare @VrDevN money
				declare @fecdev smalldatetime

				select @VrAntic = VrAnticipo, @VrAbono = VrAbonado from Trn_TraEspAnticipos where TipDoc = @DocAnt and Anticipo = @Antic and IdCia = @IdCiaAnt
				select @fecdev = Fecha,@VrDevN = VrDevolucion from @Trn_TraEspDevAnt

				update Trn_TraEspAnticipos 
				set NumDev = @Dev, FecDev = @fecdev, VrAbonado = (@VrAbono + @VrDevN)  
				where TipDoc = @DocAnt and Anticipo = @Antic and IdCia = @IdCiaAnt

				if(@VrAntic = (@VrAbono + @VrDevN))
				begin
					update Trn_TraEspAnticipos 
					set Anulado = 1  
					where TipDoc = @DocAnt and Anticipo = @Antic and IdCia = @IdCiaAnt
				end

			end 

			--if(@operacion = 'a')
			--begin
			--	update Trn_TraEspDevAnt set anu where TipDoc = (Select TipDoc from @Trn_TraEspAnticipos) and Anticipo = (Select Anticipo from @Trn_TraEspAnticipos) and IdCia = (Select IdCia from @Trn_TraEspAnticipos)
			--end

			SELECT @Dev,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevCau]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevCau]
	@Trn_TraEspDevCau [dbo].[dataTypeTrn_TraEspDevCau] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDev VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @DevCia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Dev INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @TipFac VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @CiaFac VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Fact VARCHAR(15) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY		 
			

			declare @fecdev smalldatetime

			--Seleccionar Variables
			IF(@operacion = 'i')
			BEGIN
			SELECT TOP 1 @TipDev = TipDev, @DevCia = IdCia, @fecdev = Fecha, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_TraEspDevCau
			SELECT TOP 1 @TipFac = TipFac, @CiaFac = IdCiaFac, @Fact = Factura from @Trn_EgrFactura
			SELECT @Dev = Numero + 1  FROM TiposDocCons where IdDoc = @TipDev AND IdCia = @DevCia

			IF(@Dev > 0)
				UPDATE TiposDocCons SET Numero = @Dev WHERE IdDoc = @TipDev AND IdCia = @DevCia
			ELSE
			BEGIN
				SELECT @Dev = 1
				INSERT INTO TiposDocCons VALUES (@TipDev,@DevCia,0,0,0,0,NULL,'',@Dev,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
				SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1
					INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
				SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1
					INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
				SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1
					INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END
			END
			
			IF(@operacion = 'i')
			begin
				IF(EXISTS(SELECT * FROM @Trn_TraEspDevCau))
				BEGIN
				INSERT INTO Trn_TraEspDevCau(
				TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdProv,Factura,
				VrTotal,VrOtros,VrNeto,ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,
				TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				)
				SELECT 
				@TipDev,@Dev,@DevCia,Fecha,IdConcepto,TipDoc,Causacion,IdCiaDoc,FecDoc,IdProv,Factura,
				VrTotal,VrOtros,VrNeto,ModdDev,OrigenAdd,@TipComp, @Comprobante, @IdCiaComp,Observacion,IdEstado,
				TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				FROM @Trn_TraEspDevCau
				END 

				IF(EXISTS(SELECT * FROM @Trn_EgrFactura))
				BEGIN
				INSERT INTO Trn_EgrFactura(
				TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,
				ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,
				VehPropio,TipDev,NumDev,DetAbono
				)
				SELECT 
				@TipComp,@Comprobante,@DevCia,Item,Fecha,TipFac,Factura,IdCiaFac,
				ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,
				VehPropio,TipDev,NumDev,DetAbono
				FROM @Trn_EgrFactura
				END 

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
				INSERT INTO Trn_Comprobantes(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
				CodRes, DescServicio
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque,@TipDev,@Dev,@DevCia, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
				CodRes, DescServicio
				FROM @Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
				INSERT INTO Trn_ComDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
				IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase,@TipDev,@Dev,@DevCia,
				CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				FROM @Trn_ComDetalle
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
				INSERT INTO Trn_NiifComp(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
				EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
				FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
				VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
				IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
				Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
				CtbTipo, CtbNumero,
				FisTipo, FisNumero 
				)
				SELECT 
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@DevCia, 
				C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
				C.EnEfectivo, C.NumCheque, C.FecCheque,@TipDev,@Dev,@DevCia, C.Anulado, C.NumDev,
				C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
				C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
				C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
				C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
				CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				--INSERT INTO Trn_NiifDetalle(
				--TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				--VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				--VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				--NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				--NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				--CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				--DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				--CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				--FechAutoriza, CodCuentaCG
				--)
				--SELECT 
				--CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @IdCiaCompNiif ELSE @IdCiaCompFis END,
				--C.Item, C.Fecha, N.IdCuenta, C.Detalle,
				--C.VrDebito, C.VrCredito, C.IdTercero, C.IdVehiculo, C.IdCCosto, C.IdSubCos,
				--C.VrBase, C.TarifaBase,@TipDev,@Dev,@DevCia, C.CodConce,
				--C.NitDoc, C.TipFac, C.Factura, C.IdCiaFac, C.ItemFac, C.FecVence, C.CodCta, 
				--C.NumCheque, C.Integrado, C.TipoAplica, C.Consolida, C.CodCargo, C.NitOtros,
				--C.CodSubgpo, C.CiuOrigen, C.CodAgncia, C.VehPropio, C.Referncia, C.TipDocRef,
				--C.DocRef, C.IdCiaRef, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario,
				--C.CdConcTrib, C.CdTarifTrib, C.NumEstablec,C.PtoEmision, C.Num_Autoriza,
				--C.FechAutoriza, C.IdCuenta
				--FROM @Trn_ComDetalle AS C 
				--JOIN @Trn_NiifDetalle AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont AND C.Item = N.Item 
				--JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante

				INSERT INTO Trn_NiifDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				FechAutoriza, CodCuentaCG
				)
				SELECT 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@DevCia,
				N.Item, N.Fecha, N.IdCuenta, N.Detalle,
				N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
				N.VrBase, N.TarifaBase, @TipDev,@Dev,@DevCia, N.CodConce,
				N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
				N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
				N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
				N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
				N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
				N.FechAutoriza, N.CodCuentaCG
				FROM @Trn_NiifDetalle as N
				JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
				END
			end
						
			IF(@operacion = 'i')
			begin
				update Trn_TraEspCausacion 
				set NumDev = t2.Devolucion, FecDev = @fecdev, Anulado = 1 
				from Trn_TraEspCausacion t1, @Trn_TraEspDevCau t2
				where t1.TipDoc = t2.TipDoc  and t1.Causacion = t2.Causacion and t1.IdCia = t2.IdCiaDoc
				
				update Trn_ComFactura 
				set VrAbonado =  t2.VrAbono
				from Trn_ComFactura t1, @Trn_EgrFactura t2
				where t1.TipFac = t2.TipFac and t1.Factura = t2.Factura and t1.IdCia = t2.IdCiaFac and t1.Item = t2.Item and t1.IdProveedor = t2.IdProveedor
			end

			SELECT @Dev,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevCum]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevCum]
	@Trn_TraEspDevCum [dbo].[dataTypeTrn_TraEspDevCum] READONLY,
	@Trn_TraEspCumReservas [dbo].[dataTypeTrn_TraEspCumReservas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDev VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @DevCia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Dev INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n

	BEGIN TRAN
		BEGIN TRY

			IF(@operacion = 'i')
			BEGIN

				SELECT TOP 1 @TipDev = TipDev, @DevCia = IdCia,  @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_TraEspDevCum
				SELECT @Dev = Numero + 1  FROM TiposDocCons where IdDoc = @TipDev AND IdCia = @DevCia

				IF(@Dev > 0)
					UPDATE TiposDocCons SET Numero = @Dev WHERE IdDoc = @TipDev AND IdCia = @DevCia
				ELSE
				BEGIN
					SELECT @Dev = 1
					INSERT INTO TiposDocCons VALUES (@TipDev,@DevCia,0,0,0,0,NULL,'',@Dev,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
					SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
					--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
					IF(@Comprobante <> '')
						UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
					ELSE
					BEGIN
						SELECT @Comprobante = 1
						INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
				BEGIN
					SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
					SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif

					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
					ELSE
					BEGIN
						SELECT @CompNiif = 1
						INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
				BEGIN
					SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
					SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis

					IF(@CompFis <> '')
						UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
					ELSE
					BEGIN
						SELECT @CompFis = 1
						INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END
			END

			IF(@operacion = 'i')
			BEGIN

			IF(EXISTS(SELECT * FROM @Trn_TraEspDevCum))
			BEGIN
			INSERT INTO Trn_TraEspDevCum(
			TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev,OrigenAdd,
			TipCom,Comprobante,IdCiaCom,Observacion,TimeSys,IdCiaCrea,IdUsuario
			)
			SELECT 
			@TipDev,@Dev,@DevCia,Fecha,IdConcepto,TipDoc,Cumplido,IdCiaDoc,FecDoc,ModdDev,OrigenAdd,
			@TipComp,@Comprobante,@IdCiaComp,Observacion,TimeSys,IdCiaCrea,IdUsuario
			FROM @Trn_TraEspDevCum
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
			INSERT INTO Trn_Comprobantes(
			TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
			TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
			CodRes, DescServicio
			)
			SELECT 
			@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
			NumCheque, FecCheque, @TipDev, @Dev, @DevCia, Anulado, NumDev, FecDev,
			TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
			VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
			Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
			PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
			CodRes, DescServicio
			FROM @Trn_Comprobantes
			END

			IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			BEGIN
			INSERT INTO Trn_ComDetalle(
			TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
			IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
			IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
			NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
			CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
			IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
			)
			SELECT 
			@TipComp, @Comprobante, @IdCiaComp, cd.Item, cd.Fecha, cd.IdCuenta, cd.Detalle, cd.VrDebito, cd.VrCredito,
			cd.IdTercero, cd.IdVehiculo, cd.IdCCosto, cd.IdSubCos, cd.VrBase, cd.TarifaBase, @TipDev, @Dev, @DevCia,
			cd.CodConce, cd.NitDoc, case WHEN cd.TipFac <> '' THEN @TipDev ELSE '' END, case WHEN cd.TipFac <> '' THEN @Dev ELSE '' END, case WHEN cd.TipFac <> '' THEN @DevCia ELSE '' END, 
			cd.ItemFac, cd.FecVence, cd.CodCta,
			cd.NumCheque, cd.Integrado, cd.TipoAplica, cd.Consolida, cd.CodCargo, cd.NitOtros, cd.CodSubgpo, cd.CiuOrigen, 
			cd.CodAgncia,cd.VehPropio, cd.Referncia, cd.TipDocRef, cd.DocRef, cd.IdCiaRef, cd.TimeSys, cd.FecUpdate, cd.IdCiaCrea, 
			cd.IdUsuario, cd.CdConcTrib, cd.CdTarifTrib, cd.NumEstablec, cd.PtoEmision, cd.Num_Autoriza, cd.FechAutoriza,cd.CdCuentaNiif
			FROM @Trn_ComDetalle cd
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			BEGIN
			INSERT INTO Trn_NiifComp(
			TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
			EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
			FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
			VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
			IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
			Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
			CtbTipo, CtbNumero,
			FisTipo, FisNumero 
			)
			SELECT 
			CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
			CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
			@DevCia,
			C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
			C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDev, @Dev, @DevCia, C.Anulado, C.NumDev,
			C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
			C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
			C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
			C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
			CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
		    CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
			FROM @Trn_Comprobantes AS C 
			JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			BEGIN
			
			INSERT INTO Trn_NiifDetalle(
			TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
			VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
			VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
			NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
			NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
			CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
			DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
			CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
			FechAutoriza, CodCuentaCG
			)
			SELECT 
			CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
			CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
			@DevCia,
			N.Item, N.Fecha, N.IdCuenta, N.Detalle,
			N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
			N.VrBase, N.TarifaBase,  @TipDev, @Dev, @DevCia, N.CodConce,
			N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
			N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
			N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
			N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
			N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
			N.FechAutoriza, N.CodCuentaCG
			FROM @Trn_NiifDetalle as N
			JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante

			END

			UPDATE Trn_TraEspCumplido
			SET Anulado = '1', NumDev = @Dev, FecDev = D.Fecha
			FROM Trn_TraEspCumplido C, @Trn_TraEspDevCum D
			WHERE C.TipDoc = D.TipDoc AND C.Cumplido = D.Cumplido AND C.IdCia = D.IdCiaDoc

			END

			IF(@operacion = 'i')
			BEGIN
				--Actualizar ResDetalles
				UPDATE Trn_TraEspResDetalle
				--SET Cumplido = 0, IdCiaCum = '00', FechaCum = null, JOE NO ACTUALIZABA EL ITEM
				SET Cumplido = 0, IdCiaCum = '00', FechaCum = null, EstadoItem = t2.EstadoItemRes
				FROM Trn_TraEspResDetalle t1, @Trn_TraEspCumReservas t2
				WHERE t1.TipDoc = t2.TipRes and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCiaRes and t1.Item = t2.ItemRes
			END

			SELECT @Dev,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevLiq]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevLiq]
	@Trn_TraEspDevLiq [dbo].[dataTypeTrn_TraEspDevLiq] READONLY,
	@Trn_TraEspLiquidaDed [dbo].[dataTypeTrn_TraEspLiquidaDed] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY		 


		    if(@operacion = 'i')
			begin	
				SELECT TOP 1 @TipDoc = TipDev, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_TraEspDevLiq
				SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

				IF(@Numero > 0)
					UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
				ELSE
				BEGIN
					SELECT @Numero = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
					SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
					--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
					IF(@Comprobante <> '')
						UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
					ELSE
					BEGIN
						SELECT @Comprobante = 1
						INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
				BEGIN
					SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
					SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
					--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
					ELSE
					BEGIN
						SELECT @CompNiif = 1
						INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
				BEGIN
					SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
					SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
					--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
					IF(@CompNiif <> '')
						UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
					ELSE
					BEGIN
						SELECT @CompFis = 1
						INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

			end

			IF(@operacion = 'i')
			begin
				IF(EXISTS(SELECT * FROM @Trn_TraEspDevLiq))
				BEGIN
				INSERT INTO Trn_TraEspDevLiq(
				TipDev,Devolucion,IdCia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,VrTotal,
				ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Fecha,IdConcepto,TipDoc,Liquidacion,IdCiaDoc,FecDoc,IdVehiculo,IdPoseedor,IdConductor,VrTotal,
				ModdDev,OrigenAdd,TipCom,Comprobante,IdCiaCom,Observacion,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				FROM @Trn_TraEspDevLiq
				END 

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
				INSERT INTO Trn_Comprobantes(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
				CodRes, DescServicio
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
				CodRes, DescServicio
				FROM @Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
				INSERT INTO Trn_ComDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
				IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
				CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				FROM @Trn_ComDetalle
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
				INSERT INTO Trn_NiifComp(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
				EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
				FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
				VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
				IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
				Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
				CtbTipo, CtbNumero,
				FisTipo, FisNumero 
				)
				SELECT 
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END,
				CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@Cia, 
				C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
				C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
				C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
				C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
				C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
				C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
				CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				--INSERT INTO Trn_NiifDetalle(
				--TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				--VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				--VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				--NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				--NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				--CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				--DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				--CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				--FechAutoriza, CodCuentaCG
				--)
				--SELECT 
				--CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, CASE NC.TipoNiif WHEN 'NIIF' THEN @IdCiaCompNiif ELSE @IdCiaCompFis END, 
				--C.Item, C.Fecha, N.IdCuenta, C.Detalle,
				--C.VrDebito, C.VrCredito, C.IdTercero, C.IdVehiculo, C.IdCCosto, C.IdSubCos,
				--C.VrBase, C.TarifaBase, @TipDoc, @Numero, @Cia, C.CodConce,
				--C.NitDoc, C.TipFac, C.Factura, C.IdCiaFac, C.ItemFac, C.FecVence, C.CodCta, 
				--C.NumCheque, C.Integrado, C.TipoAplica, C.Consolida, C.CodCargo, C.NitOtros,
				--C.CodSubgpo, C.CiuOrigen, C.CodAgncia, C.VehPropio, C.Referncia, C.TipDocRef,
				--C.DocRef, C.IdCiaRef, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario,
				--C.CdConcTrib, C.CdTarifTrib, C.NumEstablec,C.PtoEmision, C.Num_Autoriza,
				--C.FechAutoriza, C.IdCuenta
				--FROM @Trn_ComDetalle AS C JOIN @Trn_NiifDetalle AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont AND C.Item = N.Item JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante

				INSERT INTO Trn_NiifDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				FechAutoriza, CodCuentaCG
				)
				SELECT 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@Cia,
				N.Item, N.Fecha, N.IdCuenta, N.Detalle,
				N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
				N.VrBase, N.TarifaBase, @TipDoc, @Numero, @Cia, N.CodConce,
				N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
				N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
				N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
				N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
				N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
				N.FechAutoriza, N.CodCuentaCG
				FROM @Trn_NiifDetalle as N
				JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
				END
			end	

			IF(@operacion = 'i')
			begin
			  -- actualizar causaciones 
			  declare @TipCau varchar(3)
			  declare @Causacion int
			  declare @IdCiaCau varchar(2)	
			  declare @ItemCau int		  
			  declare @VrAbonoCau decimal(14,4)
			  DECLARE ccausac CURSOR
	  		  FOR SELECT TipCau, Causacion, IdCiaCau, ItemCau, VrAbono from @Trn_TraEspLiquidaDed
	          OPEN ccausac
			  FETCH NEXT FROM ccausac into @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
			  WHILE @@FETCH_STATUS = 0
			  BEGIN
			  
				  UPDATE Trn_TraEspCauDetalle
					SET TipoLiq = '0', NumLiquida = 0, CiaLiquida = '00', VrAbonado = VrAbonado - @VrAbonoCau
				  FROM Trn_TraEspCauDetalle t1
				  WHERE t1.TipDoc = @TipCau and t1.Causacion = @Causacion and t1.IdCia = @IdCiaCau and t1.Item = @ItemCau

			  FETCH NEXT FROM ccausac INTO @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
			  END
			  CLOSE ccausac
			  DEALLOCATE ccausac

			  -- actualizar liquidaciones 
			  UPDATE Trn_TraEspLiquida
			  SET Anulado = '1',NumDev = @Numero, FecDev= t2.Fecha
			  FROM Trn_TraEspLiquida t1, @Trn_TraEspDevLiq t2
			  WHERE t1.TipDoc = t2.TipDoc and t1.Liquidacion = t2.Liquidacion and t1.IdCia = t2.IdCiaDoc

			  --actualizar Trn_ComFactura
			  declare @FactTipFac varchar(3)
			  declare @FactIdCiaFac varchar(2)
			  declare @FactFactura varchar(15)
			  declare @FactIdProveedor varchar(16)
			  declare @VrAbono decimal(14,4)
			  declare @ItemFac int
			  DECLARE cprincipal CURSOR
	  		  FOR select TipFac, Factura, IdCiaFac,ItemFac, IdProveedor, VrAbono from @Trn_EgrFactura
	          OPEN cprincipal
			  FETCH NEXT FROM cprincipal into @FactTipFac, @FactFactura, @FactIdCiaFac, @ItemFac, @FactIdProveedor, @VrAbono
			  WHILE @@FETCH_STATUS = 0
			  BEGIN

					  if(@VrAbono > 0)
					  begin
						  update Trn_ComFactura 
						  set VrAbonado = VrAbonado - @VrAbono
						  from Trn_ComFactura t1 
						  where t1.TipFac = @FactTipFac and t1.Factura = @FactFactura and t1.IdCia = @FactIdCiaFac and t1.Item = @ItemFac and t1.IdProveedor = @FactIdProveedor
					 end

				  --declare @acumulado decimal(14,4)
				  --declare @vrfactura decimal(14,4)
				  --declare @vrabonado decimal(14,4)
				  --declare @itemFact int
				  --declare @valor decimal(14,4)
				  --set @acumulado = @FactSaldo

				  --DECLARE csecundario CURSOR
	  			--  FOR SELECT Item, VrFactura, VrAbonado FROM Trn_ComFactura t1 WHERE t1.TipFac = @FactTipFac and t1.Factura = @FactFactura and t1.IdCia = @FactIdCiaFac and t1.IdProveedor = @FactIdProveedor order by FecVence asc
				  --OPEN csecundario
				  --FETCH NEXT FROM csecundario into @itemFact, @vrfactura, @vrabonado
				  --WHILE @@FETCH_STATUS = 0
				  --BEGIN
				  
					 -- if(@acumulado >= @vrfactura)
					 -- begin
						--  set @valor =  @vrfactura
						--  set @acumulado = @acumulado - @vrfactura
					 -- end
					 -- else
					 -- begin
						--  set @valor =  @acumulado
						--  set @acumulado = 0						
					 -- end

					 -- if(@valor > 0)
					 -- begin
						--  update Trn_ComFactura 
						--  set VrAbonado = VrAbonado - @valor
						--  from Trn_ComFactura t1 
						--  where t1.TipFac = @FactTipFac and t1.Factura = @FactFactura and t1.IdCia = @FactIdCiaFac and t1.Item = @itemFact and t1.IdProveedor = @FactIdProveedor
					 --end
	
   			--	  FETCH NEXT FROM csecundario INTO @itemFact, @vrfactura
				  --END
				  --CLOSE csecundario
				  --DEALLOCATE csecundario

			  FETCH NEXT FROM cprincipal INTO @FactTipFac, @FactFactura, @FactIdCiaFac, @ItemFac, @FactIdProveedor, @VrAbono
			  END
			  CLOSE cprincipal
			  DEALLOCATE cprincipal
			  
			  --actualizar orden pago
			  update Trn_TraEspOrdenReservas
			  set EdoLiqCausac =  0
			  from Trn_TraEspOrdenReservas t1, @Trn_TraEspLiquidaDed t2
			  where t2.TipOdp = t1.TipDoc and t2.OrdenPago = t1.OrdPago and t2.IdCiaOdp = t1.IdCia

			  --Eliminar los egreso factura
			  delete Trn_EgrFactura
			  from Trn_EgrFactura t1
			  inner join @Trn_EgrFactura t2 on t1.TipCom = t2.TipCom
			  where t1.Comprobante = t2.Comprobante and t1.IdCia = t2.IdCia
			end

			SELECT @Numero,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevOdp]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevOdp]
	@Trn_TraEspDevOdp [dbo].[dataTypeTrn_TraEspDevOdp] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@Trn_TraEspAntAbonos [dbo].[dataTypeTrn_TraEspAntAbonos] READONLY,
	@Trn_Pagos [dbo].[dataTypeTrn_Pagos] READONLY,
	@Trn_TraEspOrdenReservas [dbo].[dataTypeTrn_TraEspOrdenReservas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
	DECLARE @Comprobante INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante
	DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
	DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante

	DECLARE @CompNiif INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante Niif
	DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
	DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaï¿½ia del comprobante Niif

	DECLARE @CompFis INT = 0 --Esta variable guarda el nï¿½mero consecutivo de comprobante Fiscal
	DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
	DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante Fiscal

	DECLARE @TipDev VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @CiaDev VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Dev INT --En esta variable se guarda el consecutivo del documento aprobaciï¿½n

	DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n

	BEGIN TRAN

	BEGIN TRY		 
		declare @fecdev smalldatetime

		IF(@operacion = 'i')
		begin	
			SELECT TOP 1 @TipDev = TipDev, @CiaDev = IdCia,@TipDoc = TipDoc, @Cia = IdCiaDoc,@fecdev = Fecha, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia 
			FROM @Trn_TraEspDevOdp
				
			SELECT @Dev = Numero + 1  
			FROM TiposDocCons 
			where IdDoc = @TipDev AND IdCia = @CiaDev

			IF(@Dev > 0)
				UPDATE TiposDocCons 
				SET Numero = @Dev 
				WHERE IdDoc = @TipDev AND IdCia = @CiaDev
			ELSE
			BEGIN
				SELECT @Dev = 1

				INSERT INTO TiposDocCons 
				VALUES (@TipDev,@CiaDev,0,0,0,0,NULL,'',@Dev,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END
			--John Roa--DIEGO ROMERO DICE QUE SI NO EXISTE EL COMPROBANTE CON ELMISMO NOMBRE DE DOC DEVOLUCIï¿½N INSERTA UN COMPROBANTE CON EL  TIPCOM SEA IIGUAL AL TIPDEV, en la tabla TiposCom(tipos de comprobantes)
			--es INACTIVO = 1, PARA PODER INSERTAR EN EGRFACTURA ESTE TIPCOM
			IF(NOT EXISTS(SELECT IdCom FROM TiposCom where IdCom = @TipDev))
			BEGIN
				INSERT INTO TiposCom 
				VALUES (@TipDev,'DEVOLUCION DE ORDEN DE PAGO ESPECIAL',0,0,0,1,CURRENT_TIMESTAMP,NULL,NULL,null)
			END
			--
			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom 
				FROM @Trn_Comprobantes

				SELECT @Comprobante = Numero + 1  
				FROM TiposComCons
				where IdCom  = @TipComp 
					AND IdCia = @IdCiaComp

				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons 
					SET Numero = @Comprobante 
					WHERE IdCom = @TipComp and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1

					INSERT INTO TiposComCons 
					VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'NIIF'

				SELECT @CompNiif = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif

				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompNiif 
					WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'FISCAL'

				SELECT @CompFis = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompFis 
					AND IdCia = @IdCiaCompFis

				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompFis 
					WHERE IdCom = @TipCompFis 
						and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END
		end
			
		IF(@operacion = 'i')
		begin
			IF(EXISTS(SELECT * FROM @Trn_TraEspDevOdp))
			BEGIN
				INSERT INTO Trn_TraEspDevOdp (
					TipDev, Devolucion, IdCia, Fecha, IdConcepto, TipDoc,
					OrdPago, IdCiaDoc, FecDoc, IdVehiculo, IdPoseedor, IdConductor,
					CxPagar, ModdDev, TipCom, Comprobante, IdCiaCom, Observacion,
					IdEstado, OrigenAdd, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Fecha, IdConcepto, TipDoc,
					OrdPago, IdCiaDoc, FecDoc, IdVehiculo, IdPoseedor, IdConductor,
					CxPagar, ModdDev, @TipComp, @Comprobante, @IdCiaComp, Observacion,
					IdEstado, OrigenAdd, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
				FROM 
					@Trn_TraEspDevOdp
			END 

			IF(EXISTS(SELECT * FROM @Trn_EgrFactura))
			BEGIN
				INSERT INTO Trn_EgrFactura (
					TipCom, Comprobante, IdCia, Item, Fecha, TipFac, 
					Factura, IdCiaFac, ItemFac, IdProveedor, IdCuenta, VrAbono,
					EsEgreso, ItemCom, pVehiculo, VehPropio, TipDev, NumDev,
					DetAbono
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Item, Fecha, TipFac,
					Factura, IdCiaFac, ItemFac, IdProveedor, IdCuenta, VrAbono,
					EsEgreso, ItemCom, pVehiculo, VehPropio, @TipDev, @Dev,
					DetAbono
				FROM 
					@Trn_EgrFactura
			END 

			IF(EXISTS(SELECT * FROM @Trn_TraEspAntAbonos))
			BEGIN
				INSERT INTO Trn_TraEspAntAbonos (
					TipDoc, Documento, IdCia, Item, Fecha, TipAnt, 
					Anticipo, IdCiaAnt, VrAbono, TipoAplica, Detalle, CdCuentaAnt
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Item, Fecha, TipAnt, 
					Anticipo, IdCiaAnt, (-VrAbono), TipoAplica, Detalle, CdCuentaAnt
				FROM 
					@Trn_TraEspAntAbonos
			END

			IF(EXISTS(SELECT * FROM @Trn_Pagos))
			BEGIN
				INSERT INTO Trn_Pagos (
					TipDoc, Documento, IdCia, Item, Fecha, IdForma, 
					Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
					CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
					Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
					TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
					CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
					CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Item, Fecha, IdForma, 
					Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
					CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
					Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
					TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
					CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
					CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
				FROM 
					@Trn_Pagos
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				INSERT INTO Trn_Comprobantes (
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, 
					IdCiaDoc, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
					CodRes, DescServicio
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, @TipDev, @Dev, 
					@CiaDev, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
					CodRes, DescServicio
				FROM 
					@Trn_Comprobantes
			END

			IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			BEGIN
				INSERT INTO Trn_ComDetalle (
					TipCom, Comprobante, IdCia, Item, Fecha, 
					IdCuenta, 
					Detalle, VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, 
					IdSubCos, VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, 
					CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, 
					FecVence, CodCta, NumCheque, Integrado, TipoAplica, Consolida, 
					CodCargo, NitOtros, CodSubgpo, CiuOrigen,  CodAgncia, VehPropio, 
					Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, 
					IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
					Num_Autoriza, FechAutoriza, CdCuentaNiif
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, 
					(
						SELECT DISTINCT 
							ISNULL(T.IdCuenta, TCD.IdCuenta)
						FROM 
							@Trn_TraEspOrdenReservas AS O
						LEFT JOIN 
							TarifCuentas T ON T.IdTarifa = (
								CASE TCD.Detalle
									WHEN 'RETENCION EN LA FUENTE' THEN O.CodTarRet
									WHEN 'RETENCION ICA' THEN O.CodTarIca
								END
							)
							AND T.TipDoc = 'OPE'
					) AS IdCuenta,
					Detalle, VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, 
					IdSubCos, VrBase, TarifaBase, @TipDev, @Dev, @CiaDev,
					CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, 
					FecVence, CodCta, NumCheque, Integrado, TipoAplica, Consolida, 
					CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, 
					Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, 
					IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
					Num_Autoriza, FechAutoriza, CdCuentaNiif
				FROM 
					@Trn_ComDetalle AS TCD
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			BEGIN
				INSERT INTO Trn_NiifComp(
					TipCom, 
					Comprobante, 
					IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo, 
					NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, 
					NumDev, FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, 
					CedCondtor, CodConce, Beneficiario, VrDivisa1, VrDivisa2, VrDivisa3, 
					PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado, 
					Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, 
					CdSustento, Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
					CtbTipo, 
					CtbNumero,
					FisTipo, 
					FisNumero 
				)
				SELECT 
					CASE 
						N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif 
						ELSE @TipCompFis 
					END, 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE @CompFis 
					END, 
					@CiaDev, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta, C.EnEfectivo, 
					C.NumCheque, C.FecCheque, @TipDev, @Dev, @CiaDev, C.Anulado, 
					C.NumDev, C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, 
					C.CedCondtor, C.CodConce, C.Beneficiario, C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, 
					C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion, C.IdEstado, 
					C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, 
					C.CdSustento, C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE NULL 
					END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif 
						ELSE 0 
					END,
					CASE N.TipoNiif 
						WHEN 'FISCAL' THEN @TipCompFis 
						ELSE NULL 
					END, 
					CASE N.TipoNiif 
						WHEN 'FISCAL' THEN @CompFis 
						ELSE 0 
					END
				FROM 
					@Trn_Comprobantes AS C 
				JOIN 
					@Trn_NiifComp AS N ON C.TipCom = N.TipComCont 
					AND C.Comprobante = N.ComprobanteCont
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			BEGIN
				INSERT INTO Trn_NiifDetalle (
					TipCom, 
					Comprobante, 
					IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, 
					VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos, VrBase, 
					TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce, NitDoc, 
					TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza, 
					CodCuentaCG
				)
				SELECT 
					CASE NC.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE @TipCompFis 
					END, 
					CASE NC.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE @CompFis 
					END, 
					@CiaDev, N.Item, N.Fecha, N.IdCuenta, N.Detalle, N.VrDebito, 
					N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos, N.VrBase, 
					N.TarifaBase, @TipDev, @Dev, @CiaDev, N.CodConce, N.NitDoc, 
					N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza, N.FechAutoriza, 
					N.CodCuentaCG
				FROM 
					@Trn_NiifDetalle as N
				JOIN 
					@Trn_NiifComp AS NC ON N.TipCom = NC.TipCom 
					AND N.Comprobante = NC.Comprobante
			END
		end	

		IF(@operacion = 'i')
		begin
			--Se actualiza la orden de pago con los datos de la devoluciï¿½n
			update Trn_TraEspOrdenPago 
			set NumDev = @Dev, FecDev = @fecdev,Anulado = 1  
			from Trn_TraEspOrdenPago t1, @Trn_TraEspDevOdp t2
			where t1.TipDoc = t2.TipDoc 
				and t1.OrdPago = t2.OrdPago 
				and t1.IdCia = t2.IdCiaDoc 
			  
			--se actualiza la Trn_Comfactura
			update Trn_ComFactura 
			set VrAbonado =  t1.VrAbonado + t2.VrAbono 
			from Trn_ComFactura t1, @Trn_EgrFactura t2
			where t1.TipFac = t2.TipFac 
				and t1.Factura = t2.Factura 
				and t1.IdCia = t2.Idcia 
				and t1.Item = t2.ItemFac and t1.IdProveedor = t2.IdProveedor

			--Actualiza los items de la programaciï¿½n detalle de cada reserva agregada en la Orden de Pago y que se devuelve
			UPDATE Trn_TraEspProgramaDet
			SET TipDocOdp = 'OPE',NumOdp = 0, IdCiaOdp = '00'
			FROM Trn_TraEspProgramaDet t1, @Trn_TraEspDevOdp t2
			WHERE t1.TipDocOdp = 'OPE' 
				and t1.NumOdp = t2.OrdPago 
				and t1.IdCiaOdp = t2.IdCiaDoc 

			--Actualizar item de Reservas al estado en el que se encontraba antes de cuando le realizaron la Orden de Pago
			UPDATE Trn_TraEspResDetalle
			SET EstadoItem = t.EstadoItem
			FROM Trn_TraEspResDetalle r, @Trn_TraEspOrdenReservas t
			WHERE r.TipDoc = t.TipRes 
				and r.Reserva = t.Reserva 
				and r.IdCia = t.IdCiaRes 
				and r.Item = t.ItemRes

			--actualiza los anticipos(restar) para que quede como estaba antes de hacer la Orden de Pago
			UPDATE Trn_TraEspAnticipos
			SET VrAbonado = t2.VrAbono - VrAbonado
			FROM Trn_TraEspAnticipos t1, @Trn_TraEspAntAbonos t2
			WHERE t1.TipDoc = t2.TipAnt 
				and t1.Anticipo = t2.Anticipo 
				and t1.IdCia = t2.IdCiaAnt

		end

		SELECT @Dev, @Comprobante

		COMMIT TRAN
	END TRY

    BEGIN CATCH
		ROLLBACK TRAN

		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH

	RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspDevOdpGIE]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspDevOdpGIE]
	@Trn_TraEspDevOdp [dbo].[dataTypeTrn_TraEspDevOdp] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@Trn_TraEspAntAbonos [dbo].[dataTypeTrn_TraEspAntAbonos] READONLY,
	@Trn_Pagos [dbo].[dataTypeTrn_Pagos] READONLY,
	@Trn_TraEspOrdenReservas [dbo].[dataTypeTrn_TraEspOrdenReservas] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
	DECLARE @Comprobante INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante
	DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
	DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante

	DECLARE @CompNiif INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante Niif
	DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
	DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaï¿½ia del comprobante Niif

	DECLARE @CompFis INT = 0 --Esta variable guarda el nï¿½mero consecutivo de comprobante Fiscal
	DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
	DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante Fiscal

	DECLARE @TipDev VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @CiaDev VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Dev INT --En esta variable se guarda el consecutivo del documento aprobaciï¿½n

	DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n

	BEGIN TRAN
		
	BEGIN TRY		 
		declare @fecdev smalldatetime

		IF(@operacion = 'i')
		begin
				
			SELECT TOP 1 @TipDev = TipDev, @CiaDev = IdCia,@TipDoc = TipDoc, @Cia = IdCiaDoc,@fecdev = Fecha, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia 
			FROM @Trn_TraEspDevOdp
				
			SELECT @Dev = Numero + 1  
			FROM TiposDocCons 
			where IdDoc = @TipDev 
				AND IdCia = @CiaDev

			IF(@Dev > 0)
				UPDATE TiposDocCons 
				SET Numero = @Dev 
				WHERE IdDoc = @TipDev 
					AND IdCia = @CiaDev
			ELSE
			BEGIN
				SELECT @Dev = 1

				INSERT INTO TiposDocCons 
				VALUES (@TipDev,@CiaDev,0,0,0,0,NULL,'',@Dev,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END
			--John Roa--DIEGO ROMERO DICE QUE SI NO EXISTE EL COMPROBANTE CON ELMISMO NOMBRE DE DOC DEVOLUCIï¿½N INSERTA UN COMPROBANTE CON EL  TIPCOM SEA IIGUAL AL TIPDEV, en la tabla TiposCom(tipos de comprobantes)
			--es INACTIVO = 1, PARA PODER INSERTAR EN EGRFACTURA ESTE TIPCOM
			IF(NOT EXISTS(SELECT IdCom FROM TiposCom where IdCom = @TipDev))
			BEGIN
				INSERT INTO TiposCom 
				VALUES (@TipDev,'DEVOLUCION DE ORDEN DE PAGO ESPECIAL',0,0,0,1,CURRENT_TIMESTAMP,NULL,NULL,null)
			END
			--
			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom 
				FROM @Trn_Comprobantes

				SELECT @Comprobante = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipComp
					AND IdCia = @IdCiaComp

				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons 
					SET Numero = @Comprobante 
					WHERE IdCom = @TipComp 
						and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1

					INSERT INTO TiposComCons 
					VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'NIIF'

				SELECT @CompNiif = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompNiif 
					AND IdCia = @IdCiaCompNiif
				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompNiif 
					WHERE IdCom = @TipCompNiif 
						and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom 
				FROM @Trn_NiifComp
				WHERE TipoNiif = 'FISCAL'

				SELECT @CompFis = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompFis 
					AND IdCia = @IdCiaCompFis

				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompFis 
					WHERE IdCom = @TipCompFis 
						and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END
		end
			
		IF(@operacion = 'i')
		begin
			IF(EXISTS(SELECT * FROM @Trn_TraEspDevOdp))
			BEGIN
				INSERT INTO Trn_TraEspDevOdp (
					TipDev, Devolucion, IdCia, Fecha, IdConcepto, TipDoc,
					OrdPago, IdCiaDoc, FecDoc, IdVehiculo, IdPoseedor, IdConductor,
					CxPagar, ModdDev, TipCom, Comprobante, IdCiaCom, Observacion,
					IdEstado, OrigenAdd, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Fecha, IdConcepto, TipDoc, 
					OrdPago, IdCiaDoc, FecDoc, IdVehiculo, IdPoseedor, IdConductor, 
					CxPagar, ModdDev, @TipComp, @Comprobante, @IdCiaComp, Observacion, 
					IdEstado, OrigenAdd, TimeSys, FecUpdate, IdCiaCrea, IdUsuario
				FROM 
					@Trn_TraEspDevOdp
			END 

			IF(EXISTS(SELECT * FROM @Trn_EgrFactura))
			BEGIN
				INSERT INTO Trn_EgrFactura (
					TipCom, Comprobante, IdCia, Item, Fecha, TipFac, Factura,
					IdCiaFac, ItemFac, IdProveedor, IdCuenta, VrAbono, EsEgreso, 
					ItemCom, pVehiculo, VehPropio, TipDev, NumDev, DetAbono
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Item, Fecha, TipFac, 
					Factura, IdCiaFac, ItemFac, IdProveedor, IdCuenta, VrAbono,
					EsEgreso, ItemCom, pVehiculo, VehPropio, @TipDev, @Dev, 
					DetAbono
				FROM 
					@Trn_EgrFactura
			END 

			IF(EXISTS(SELECT * FROM @Trn_TraEspAntAbonos))
			BEGIN
				INSERT INTO Trn_TraEspAntAbonos (
					TipDoc, Documento, IdCia, Item, Fecha, TipAnt,
					Anticipo, IdCiaAnt, VrAbono, TipoAplica, Detalle, CdCuentaAnt
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Item, Fecha, TipAnt, 
					Anticipo, IdCiaAnt, (-VrAbono), TipoAplica, Detalle, CdCuentaAnt
				FROM 
					@Trn_TraEspAntAbonos
			END

			IF(EXISTS(SELECT * FROM @Trn_Pagos))
			BEGIN
				INSERT INTO Trn_Pagos (
					TipDoc, Documento, IdCia, Item, Fecha, IdForma, 
					Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
					CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
					Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
					TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
					CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
					CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
				)
				SELECT 
					@TipDev, @Dev, @CiaDev, Item, Fecha, IdForma, 
					Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
					CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
					Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
					TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
					CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
					CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
				FROM 
					@Trn_Pagos
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				INSERT INTO Trn_Comprobantes (
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, 
					IdCiaDoc, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
					CodRes, DescServicio
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, @TipDev, @Dev, 
					@CiaDev, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
					CodRes, DescServicio
				FROM 
					@Trn_Comprobantes
			END

			IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			BEGIN
				INSERT INTO Trn_ComDetalle (
					TipCom, Comprobante, IdCia, Item, Fecha, 
					IdCuenta, 
					Detalle, VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, 
					IdSubCos, VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, 
					CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, 
					FecVence, CodCta, NumCheque, Integrado, TipoAplica, Consolida, 
					CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, 
					Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, 
					IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
					Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, 
					(
						SELECT DISTINCT 
							ISNULL(T.IdCuenta, TCD.IdCuenta)
						FROM 
							@Trn_TraEspOrdenReservas AS O
						LEFT JOIN 
							TarifCuentas T ON T.IdTarifa = (
								CASE TCD.Detalle
									WHEN 'RETENCION EN LA FUENTE' THEN O.CodTarRet
									WHEN 'RETENCION ICA' THEN O.CodTarIca
								END
							)
							AND T.TipDoc = 'OPE'
					) AS IdCuenta,
					Detalle, VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, 
					IdSubCos, VrBase, TarifaBase, @TipDev, @Dev, @CiaDev,
					CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, 
					FecVence, CodCta, NumCheque, Integrado, TipoAplica, Consolida, 
					CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, 
					Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, 
					IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
					Num_Autoriza, FechAutoriza, CdCuentaNiif
				FROM 
					@Trn_ComDetalle AS TCD
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			BEGIN
				INSERT INTO Trn_NiifComp (
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
					EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
					FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
					VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
					IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
					Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
					CtbTipo, CtbNumero,
					FisTipo, FisNumero 
				)
				SELECT 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE @TipCompFis 
					END, 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE @CompFis 
					END, 
					@CiaDev, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta, C.EnEfectivo, 
					C.NumCheque, C.FecCheque, @TipDev, @Dev, @CiaDev, C.Anulado, 
					C.NumDev, C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, 
					C.CedCondtor, C.CodConce, C.Beneficiario, C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, 
					C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion, C.IdEstado, 
					C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, 
					C.CdSustento, C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE NULL 
					END, 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE 0 
					END,
					CASE N.TipoNiif 
						WHEN 'FISCAL' THEN @TipCompFis 
						ELSE NULL 
					END, 
					CASE N.TipoNiif 
						WHEN 'FISCAL' THEN @CompFis 
						ELSE 0 
					END
				FROM 
					@Trn_Comprobantes AS C 
				JOIN 
					@Trn_NiifComp AS N ON C.TipCom = N.TipComCont 
					AND C.Comprobante = N.ComprobanteCont
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			BEGIN
				INSERT INTO Trn_NiifDetalle (
					TipCom, 
					Comprobante, 
					IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, 
					VrCredito, IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, 
					TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce, NitDoc, 
					TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza, 
					CodCuentaCG
				)
				SELECT 
					CASE NC.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE @TipCompFis 
					END, 
					CASE NC.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE @CompFis 
					END, 
					@CiaDev, N.Item, N.Fecha, N.IdCuenta, N.Detalle, N.VrDebito, 
					N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos, N.VrBase, 
					N.TarifaBase, @TipDev, @Dev, @CiaDev, N.CodConce, N.NitDoc, 
					N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza, N.FechAutoriza, 
					N.CodCuentaCG
				FROM 
					@Trn_NiifDetalle as N
				JOIN 
					@Trn_NiifComp AS NC ON N.TipCom = NC.TipCom 
					AND N.Comprobante = NC.Comprobante
			END
		end	

		IF(@operacion = 'i')
		begin
			--Se actualiza la orden de pago con los datos de la devoluciï¿½n
			update Trn_TraEspOrdenPago 
			set NumDev = @Dev, FecDev = @fecdev,Anulado = 1  
			from Trn_TraEspOrdenPago t1, @Trn_TraEspDevOdp t2
			where t1.TipDoc = t2.TipDoc 
				and t1.OrdPago = t2.OrdPago 
				and t1.IdCia = t2.IdCiaDoc 
			  
			--se actualiza la Trn_Comfactura
			update Trn_ComFactura 
			set VrAbonado =  t1.VrAbonado + t2.VrAbono 
			from Trn_ComFactura t1, @Trn_EgrFactura t2
			where t1.TipFac = t2.TipFac 
				and t1.Factura = t2.Factura 
				and t1.IdCia = t2.Idcia 
				and t1.Item = t2.ItemFac 
				and t1.IdProveedor = t2.IdProveedor

			--Actualizar item de Reservas al estado en el que se encontraba antes de cuando le realizaron la Orden de Pago
			UPDATE Trn_TraEspResDetalle
			SET EstadoItem = t.EstadoItem
			FROM Trn_TraEspResDetalle r, @Trn_TraEspOrdenReservas t
			WHERE r.TipDoc = t.TipRes 
				and r.Reserva = t.Reserva 
				and r.IdCia = t.IdCiaRes 
				and r.Item = t.ItemRes

			--actualiza los anticipos(restar) para que quede como estaba antes de hacer la Orden de Pago
			UPDATE Trn_TraEspAnticipos
			SET VrAbonado = t2.VrAbono - VrAbonado
			FROM Trn_TraEspAnticipos t1, @Trn_TraEspAntAbonos t2
			WHERE t1.TipDoc = t2.TipAnt 
				and t1.Anticipo = t2.Anticipo 
				and t1.IdCia = t2.IdCiaAnt

		end

		SELECT @Dev,@Comprobante

		COMMIT TRAN
	END TRY

    BEGIN CATCH
		ROLLBACK TRAN

		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH

	RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspFuec]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspFuec]
	@Trn_TraEspFuec [dbo].[dataTypeTrn_TraEspFuec] READONLY,
	@Trn_TraEspFuecAnexo [dbo].[dataTypeTrn_TraEspFuecAnexo] READONLY,
	@Trn_TraEspFuecDetalle [dbo].[dataTypeTrn_TraEspFuecDetalle] READONLY,
	@Trn_TraEspFuecCndtores [dbo].[dataTypeTrn_TraEspFuecCndtores] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
	DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Fuec
	DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Fuec
	DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Fuec
	declare @item int
	declare @consecutivo int = 0
	declare @numcontrato int
	declare @idciacnt varchar(4)

	BEGIN TRAN

	BEGIN TRY

		--Seleccionar Variables
		IF(@operacion = 'i')
		begin
			SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia,@idciacnt = CiaCnt, @numcontrato = Contrato 
			FROM @Trn_TraEspFuec

			SELECT @Documento = Numero + 1  
			FROM TiposDocCons 
			where IdDoc = @TipDoc 
				AND IdCia = @IdCia

			select @consecutivo = (ISNULL(MAX(Consecutivo),0) + 1) 
			from Trn_TraEspFuec 
			where TipDocCnt = 'COE' 
				and Contrato = @numcontrato 
				AND CiaCnt = @idciacnt

			IF(@Documento <> '' OR @Documento is not null)
				UPDATE TiposDocCons 
				SET Numero = @Documento 
				WHERE IdDoc = @TipDoc 
					and IdCia = @IdCia
			ELSE
			BEGIN
				SELECT @Documento = 1

				INSERT INTO TiposDocCons 
				VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END
		end

		--Seleccionar Variables
		--IF(@operacion = 'u')
		--begin
		--	SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Fuec FROM @Trn_TraEspFuec
		--end

		--UPDATE SI-EXISTE RECORDS
		IF(@operacion = 'u')
		BEGIN

			if(EXISTS(SELECT * FROM @Trn_TraEspFuec))
			begin
				UPDATE Trn_TraEspFuec
				SET 
					TipDoc = t2.TipDoc, Fuec = t2.Fuec, IdCia = t2.IdCia,
					Numero = t2.Numero, Fecha = t2.Fecha, FechaInicio = t2.FechaInicio,
					FechaFin = t2.FechaFin, CdCarga = t2.CdCarga, IdVehiculo = t2.IdVehiculo,
					IdConductor = t2.IdConductor, IdConductor2 = t2.IdConductor2, IdConductor3 = t2.IdConductor3,
					IdPoseedor = t2.IdPoseedor, IdRuta = t2.IdRuta,
					CdTipRuta = t2.CdTipRuta, IdOrigen = t2.IdOrigen, IdDestino = t2.IdDestino,
					Modalidad = t2.Modalidad, CantPasajeros = t2.CantPasajeros, CodTarRet = t2.CodTarRet,
					CodTarIca = t2.CodTarIca, VrPresupuesto = t2.VrPresupuesto, VrCobro = t2.VrCobro,
					VrPagos = t2.VrPagos, VrCargos = t2.VrCargos, VrDctos = t2.VrDctos,
					VrIva = t2.VrIva, VrRetencion = t2.VrRetencion, VrReteIca = t2.VrReteIca,
					Cantidad = t2.Cantidad, Peso = t2.Peso, TipDocPgr = t2.TipDocPgr, 
					NumPgr = t2.NumPgr, IdCiaPgr = t2.IdCiaPgr, ItemPgr = t2.ItemPgr,
					TipDocCnt = t2.TipDocCnt, Contrato = t2.Contrato, CiaCnt = t2.CiaCnt,
					OrigenAdd = t2.OrigenAdd, Anulado = t2.Anulado, FecDev = t2.FecDev,
					IdEstado = t2.IdEstado, TimeSys = t2.TimeSys, FecUpdate = t2.FecUpdate,
					IdCiaCrea = t2.IdCiaCrea, IdUsuario = t2.IdUsuario, Consecutivo = t2.Consecutivo,
					Itinerario=t2.Itinerario, FuecParcial = t2.FuecParcial, ComenParcial = t2.ComenParcial,
					Qr = t2.Qr
				FROM 
					Trn_TraEspFuec t1
				JOIN 
					@Trn_TraEspFuec t2 
					ON t1.TipDoc = t2.TipDoc 
					and t1.Fuec = t2.Fuec 
					and t1.IdCia = t2.IdCia
			end

			if(EXISTS(SELECT * FROM @Trn_TraEspFuecAnexo))
			begin
				UPDATE Trn_TraEspFuecAnexo
				SET 
					TipDoc = t2.TipDoc, Fuec = t2.Fuec, IdCia = t2.IdCia,
					TipContrato = t2.TipContrato, IdContrato = t2.IdContrato, ObjContrato = t2.ObjContrato,
					DescripCarga = t2.DescripCarga, Observacion = t2.Observacion, RespViaje = t2.RespViaje,
					VehConvenio=t2.VehConvenio, EmpresaVehCon = t2.EmpresaVehCon
				FROM 
					Trn_TraEspFuecAnexo t1
				JOIN 
					@Trn_TraEspFuecAnexo t2 
					ON t1.TipDoc = t2.TipDoc 
					and t1.Fuec = t2.Fuec 
					and t1.IdCia = t2.IdCia
			end

			if(EXISTS(SELECT * FROM @Trn_TraEspFuecDetalle))
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Fuec 
				FROM @Trn_TraEspFuecDetalle

				select @item = isnull(MAX(Item),0) 
				from Trn_TraEspFuecDetalle 
				where TipDoc = @TipDoc 
					and Fuec = @Documento 
					and IdCia = @IdCia

				--actualizar los que vienen en el tipo de dato y coincida con los que ya estÃ¡n en la tabla
				UPDATE Trn_TraEspFuecDetalle
				SET 
					TipDoc = t2.TipDoc, Fuec = t2.Fuec, IdCia = t2.IdCia,
					Item = t2.Item, TipRes = t2.TipRes, Reserva = t2.Reserva,
					IdCiaRes = t2.IdCiaRes, ItemRes = t2.ItemRes, NumPasajeros = t2.NumPasajeros,
					PesoNeto = t2.PesoNeto, VrCobro = t2.VrCobro, VrPagos = t2.VrPagos,
					Referencia1 = t2.Referencia1, Referencia2 = t2.Referencia2, Referencia3 = t2.Referencia3,
					CdTipServicio = t2.CdTipServicio, EsRutaCliente = t2.EsRutaCliente, Kilometros = t2.Kilometros,
					DirOrigen = t2.DirOrigen, FecOrigen = t2.FecOrigen, DirDestino = t2.DirDestino,
					FecDestino = t2.FecDestino
				FROM 
					Trn_TraEspFuecDetalle t1
				JOIN 
					@Trn_TraEspFuecDetalle t2 
					ON t1.TipDoc = t2.TipDoc 
					and t1.Fuec = t2.Fuec 
					and t1.IdCia = t2.IdCia 
					and t1.Item = t2.Item
				WHERE 
					t1.TipDoc = t2.TipDoc 
					and t1.Fuec = t2.Fuec 
					and t1.IdCia = t2.IdCia 
					and t1.Item = t2.Item

				--Inserta los que no existen
				INSERT INTO Trn_TraEspFuecDetalle(
					TipDoc,Fuec,IdCia,Item,TipRes,Reserva,
					IdCiaRes,ItemRes,NumPasajeros,PesoNeto,VrCobro,VrPagos,
					Referencia1,Referencia2,Referencia3,CdTipServicio,EsRutaCliente,Kilometros,
					DirOrigen,FecOrigen,DirDestino,FecDestino
				) 
				SELECT 
					@TipDoc, @Documento, @IdCia, (@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),TipRes, Reserva, 
					IdCiaRes, ItemRes, NumPasajeros, PesoNeto, VrCobro, VrPagos,
					Referencia1, Referencia2, Referencia3, CdTipServicio, EsRutaCliente, Kilometros,
					DirOrigen, FecOrigen, DirDestino, FecDestino
				FROM 
					@Trn_TraEspFuecDetalle
				WHERE 
					(TipDoc + Convert(varchar,Fuec) + IdCia + Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar, Fuec) + IdCia + Convert(varchar,Item)) FROM Trn_TraEspFuecDetalle)
				
				--Eliminar los que no existen en lo que envian
				delete from Trn_TraEspFuecDetalle
				WHERE TipDoc = @TipDoc 
					and Fuec = @Documento 
					and IdCia = @IdCia 
					and Item NOT IN(SELECT Item FROM @Trn_TraEspFuecDetalle)
			end

			if(EXISTS(SELECT * FROM @Trn_TraEspFuecAnexo))
			begin

				UPDATE Trn_TraEspFuecAnexo
				SET 
					TipDoc = t2.TipDoc, Fuec = t2.Fuec, IdCia = t2.IdCia, 
					TipContrato = t2.TipContrato, IdContrato = t2.IdContrato, ObjContrato = t2.ObjContrato,
					DescripCarga = t2.DescripCarga, Observacion = t2.Observacion, RespViaje = t2.RespViaje,
					VehConvenio=t2.VehConvenio, EmpresaVehCon=t2.EmpresaVehCon
				FROM 
					Trn_TraEspFuecAnexo t1
				JOIN 
					@Trn_TraEspFuecAnexo t2 
					ON t1.TipDoc = t2.TipDoc 
					and t1.Fuec = t2.Fuec 
					and t1.IdCia = t2.IdCia
			end

			if(EXISTS(SELECT top 1 Fuec FROM @Trn_TraEspFuecCndtores))
				begin
					SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Fuec 
					FROM @Trn_TraEspFuecCndtores

					select @item = isnull(MAX(Item),0) 
					from @Trn_TraEspFuecCndtores 
					where TipDoc = @TipDoc 
						and Fuec = @Documento 
						and IdCia = @IdCia

					--actualizar los que vienen en el tipo de dato y coincida con los que ya estÃ¡n en la tabla
					UPDATE Trn_TraEspFuecCndtores
					SET 
						TipDoc = t2.TipDoc, Fuec = t2.Fuec, IdCia = t2.IdCia, 
						Item = t2.Item, IdConductor = t2.IdConductor
					FROM 
						Trn_TraEspFuecCndtores t1
					JOIN 
						@Trn_TraEspFuecCndtores t2 
						ON t1.TipDoc = t2.TipDoc 
						and t1.Fuec = t2.Fuec 
						and t1.IdCia = t2.IdCia 
						and t1.Item = t2.Item
					WHERE 
						t1.TipDoc = t2.TipDoc 
						and t1.Fuec = t2.Fuec 
						and t1.IdCia = t2.IdCia 
						and t1.Item = t2.Item
					
					--Eliminar los que no existen en lo que envian
					delete from Trn_TraEspFuecCndtores
					WHERE TipDoc = @TipDoc 
						and Fuec = @Documento 
						and IdCia = @IdCia 
						and Item NOT IN(SELECT Item FROM @Trn_TraEspFuecCndtores)
					
					--Inserta los que no existen
					INSERT INTO Trn_TraEspFuecCndtores(
						TipDoc, Fuec, IdCia, Item, IdConductor
					) 
					SELECT 
						@TipDoc, @Documento, @IdCia, (@item + ROW_NUMBER() OVER(ORDER BY Item ASC)), IdConductor
					FROM 
						@Trn_TraEspFuecCndtores
					WHERE 
						(TipDoc + Convert(varchar, Fuec) + IdCia + Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar, Fuec) + IdCia+Convert(varchar, Item)) FROM Trn_TraEspFuecCndtores)		
				end

		END

		--INSERT NO-EXISTE RECORDS
		IF(@operacion = 'i')
			BEGIN

			IF(EXISTS(SELECT * FROM @Trn_TraEspFuec))
			begin
				INSERT INTO Trn_TraEspFuec(
					TipDoc, Fuec, IdCia, Numero, Fecha, FechaInicio,
					FechaFin, CdCarga, IdVehiculo, IdConductor, IdConductor2, IdConductor3,
					IdPoseedor, IdRuta, CdTipRuta, IdOrigen, IdDestino, Modalidad,
					CantPasajeros, CodTarRet, CodTarIca, VrPresupuesto, VrCobro, VrPagos, 
					VrCargos, VrDctos, VrIva, VrRetencion, VrReteIca, Cantidad, 
					Peso, TipDocPgr, NumPgr, IdCiaPgr, ItemPgr, TipDocCnt, 
					Contrato, CiaCnt, OrigenAdd, Anulado, FecDev, IdEstado, 
					TimeSys, FecUpdate, IdCiaCrea, IdUsuario, Consecutivo, Itinerario, 
					FuecParcial, ComenParcial, Qr
				)
				SELECT 
					@TipDoc,@Documento,@IdCia,Numero,Fecha,FechaInicio,
					FechaFin,CdCarga,IdVehiculo,IdConductor,IdConductor2,IdConductor3,
					IdPoseedor,IdRuta,CdTipRuta,IdOrigen,IdDestino,Modalidad,
					CantPasajeros,CodTarRet,CodTarIca,VrPresupuesto,VrCobro,VrPagos,
					VrCargos,VrDctos,VrIva,VrRetencion,VrReteIca,Cantidad,
					Peso,TipDocPgr,NumPgr,IdCiaPgr,ItemPgr,TipDocCnt,
					Contrato,CiaCnt,OrigenAdd,Anulado,FecDev,IdEstado,
					TimeSys,FecUpdate,IdCiaCrea,IdUsuario,@consecutivo,Itinerario,
					FuecParcial,ComenParcial, Qr
				FROM 
					@Trn_TraEspFuec
			end

			IF(EXISTS(SELECT * FROM @Trn_TraEspFuecAnexo))
			begin
				INSERT INTO Trn_TraEspFuecAnexo(
					TipDoc,Fuec,IdCia,TipContrato,IdContrato,ObjContrato,
					DescripCarga,Observacion,RespViaje,VehConvenio,EmpresaVehCon
				)
				SELECT 
					@TipDoc,@Documento,@IdCia,TipContrato,IdContrato,ObjContrato,
					DescripCarga,Observacion,RespViaje,VehConvenio,EmpresaVehCon
				FROM 
					@Trn_TraEspFuecAnexo
			end

			IF(EXISTS(SELECT * FROM @Trn_TraEspFuecDetalle))
			begin
				INSERT INTO Trn_TraEspFuecDetalle(
					TipDoc,Fuec,IdCia,Item,TipRes,Reserva,
					IdCiaRes,ItemRes,NumPasajeros,PesoNeto,VrCobro,VrPagos,
					Referencia1,Referencia2,Referencia3,CdTipServicio,EsRutaCliente,Kilometros,
					DirOrigen,FecOrigen,DirDestino,FecDestino
				) 
				SELECT 
					@TipDoc,@Documento,@IdCia,Item,TipRes,Reserva,
					IdCiaRes,ItemRes,NumPasajeros,PesoNeto,VrCobro,VrPagos,
					Referencia1,Referencia2,Referencia3,CdTipServicio,EsRutaCliente,Kilometros,
					DirOrigen,FecOrigen,DirDestino,FecDestino
				FROM 
					@Trn_TraEspFuecDetalle
			end

			IF(EXISTS(SELECT TOP 1 Fuec FROM @Trn_TraEspFuecCndtores))
			begin
				INSERT INTO Trn_TraEspFuecCndtores(
					TipDoc,Fuec,IdCia,Item,IdConductor
				) 
				SELECT 
					@TipDoc,@Documento,@IdCia,Item, IdConductor
				FROM 
					@Trn_TraEspFuecCndtores
			end

			--Actualizar ProgramaciÃ³n-Detalles
			UPDATE 
				Trn_TraEspProgramaDet
			SET 
				TipDocFuec = @TipDoc,NumFuec = @Documento, IdCiaFuec = @IdCia
			FROM 
				Trn_TraEspProgramaDet t1, @Trn_TraEspFuec t2, @Trn_TraEspFuecDetalle t3
			WHERE 
				t1.TipDoc = 'PGR' 
				and t1.Programa = t2.NumPgr 
				and t1.IdCia = t2.IdCiaPgr 
				and t1.TipDocRes = t3.TipRes 
				and t1.Reserva = t3.Reserva 
				and t1.IdCiaRes = t3.IdCiaRes 
				and t1.ItemRes = t3.ItemRes
			END

		--DELETE RECORDS
		IF(@operacion = 'd')
		BEGIN
			declare @Fuec int

			select @TipDoc = TipDoc, @IdCia = IdCia,  @Fuec = Fuec 
			from @Trn_TraEspFuec

			DELETE FROM Trn_TraEspFuecDetalle
			WHERE TipDoc = @TipDoc 
				and Fuec = @Fuec 
				and IdCia = @IdCia

			DELETE FROM Trn_TraEspFuecAnexo 
			WHERE TipDoc = @TipDoc 
				and Fuec = @Fuec 
				and IdCia = @IdCia

			DELETE FROM Trn_TraEspFuec 
			WHERE TipDoc = @TipDoc 
				and Fuec = @Fuec 
				and IdCia = @IdCia

			DELETE FROM Trn_TraEspFuecCndtores 
			WHERE TipDoc = @TipDoc 
				and Fuec = @Fuec 
				and IdCia = @IdCia
		END

		--ANULAR RECORDS
		IF(@operacion = 'a')
		BEGIN
			select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Fuec 
			from @Trn_TraEspFuec

			UPDATE Trn_TraEspFuec 
			SET IdEstado = '9999', Anulado = 1
			WHERE TipDoc = @TipDoc 
				and Fuec = @Documento 
				and IdCia = @IdCia

			UPDATE Trn_TraEspProgramaDet
			SET TipDocFuec = 'FUE',NumFuec = 0, IdCiaFuec = '00'
			FROM Trn_TraEspProgramaDet t1, @Trn_TraEspFuec t2
			WHERE t1.TipDocFuec = 'FUE' 
				and t1.NumFuec = t2.Fuec 
				and t1.IdCiaFuec = t2.IdCia
		END

		SELECT @Documento

		COMMIT TRAN
	END TRY

	BEGIN CATCH
		ROLLBACK TRAN

		DECLARE 
			@ErrorMessage NVARCHAR(4000),
			@ErrorSeverity INT,
			@ErrorState INT

		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
		);
	END CATCH
	
	RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspLiquida]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspLiquida]
	@Trn_TraEspLiquida [dbo].[dataTypeTrn_TraEspLiquida] READONLY,
	@Trn_TraEspLiquidaDed [dbo].[dataTypeTrn_TraEspLiquidaDed] READONLY,
	@Trn_TraEspLiquidaOdp [dbo].[dataTypeTrn_TraEspLiquidaOdp] READONLY,
	@Trn_TraEspLiquidaOtr [dbo].[dataTypeTrn_TraEspLiquidaOtr] READONLY,
	@Trn_EgrFactura [dbo].[dataTypeTrn_EgrFactura] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeTrn_NiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Comprobante INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante
DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante

DECLARE @CompNiif INT = 0 --Esta variable guarda el nÃºmero consecutivo del comprobante Niif
DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaÃ±ia del comprobante Niif

DECLARE @CompFis INT = 0 --Esta variable guarda el nÃºmero consecutivo de comprobante Fiscal
DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaÃ±ia del comprobante Fiscal

DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciÃ³n
	BEGIN TRAN
		BEGIN TRY		 
			
			if(@operacion = 'i')
			begin
			SELECT TOP 1 @TipDoc = TipDoc, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia FROM @Trn_TraEspLiquida
			SELECT @Numero = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @Cia

			IF(@Numero > 0)
				UPDATE TiposDocCons SET Numero = @Numero WHERE IdDoc = @TipDoc AND IdCia = @Cia
			ELSE
			BEGIN
				SELECT @Numero = 1
				INSERT INTO TiposDocCons VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom FROM @Trn_Comprobantes
				SELECT @Comprobante = Numero + 1  FROM TiposComCons where IdCom  = @TipComp AND IdCia = @IdCiaComp
				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1
					INSERT INTO TiposComCons VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'
				SELECT @CompNiif = Numero + 1  FROM TiposComCons where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif
				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1
					INSERT INTO TiposComCons VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'
				SELECT @CompFis = Numero + 1  FROM TiposComCons where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis
				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1
					INSERT INTO TiposComCons VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			--DIEGO ROMERO DICE QUE SI NO EXISTE EL COMPROBANTE CON ELMISMO NOMBRE DE DOC DEVOLUCIÃ“N INSERTA UN COMPROBANTE CON EL  TIPCOM SEA IIGUAL AL TIPDEV, en la tabla TiposCom(tipos de comprobantes)
			--es INACTIVO = 1, PARA PODER INSERTAR EN EGRFACTURA ESTE TIPCOM
			IF(NOT EXISTS(SELECT IdCom FROM TiposCom where IdCom = @TipDoc))
			BEGIN
			  INSERT INTO TiposCom VALUES (@TipDoc,'LIQUIDACION DE ORDENES ESPECIAL',0,0,0,1,CURRENT_TIMESTAMP,NULL,NULL,null)
			END
			--

			end

			IF(@operacion = 'i')
			begin
				IF(EXISTS(SELECT * FROM @Trn_TraEspLiquida))
				BEGIN
				INSERT INTO Trn_TraEspLiquida(
				TipDoc,Liquidacion,IdCia,Fecha,IdConcepto,IdVehiculo,IdPoseedor,IdConductor,VrTotal,CxPagar,TipCom,Comprobante,IdCiaCom,
				Anulado,NumDev,FecDev,Observacion,IdEstado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,
				IdUsuario,ModLiquida
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Fecha,IdConcepto,IdVehiculo,IdPoseedor,IdConductor,VrTotal,CxPagar,TipCom,Comprobante,IdCiaCom,
				Anulado,NumDev,FecDev,Observacion,IdEstado,FecIniCau,FecFinCau,FecIniOdp,FecFinOdp,OrigenAdd,TimeSys,FecUpdate,IdCiaCrea,
				IdUsuario,ModLiquida
				FROM @Trn_TraEspLiquida
				END 

				IF(EXISTS(SELECT * FROM @Trn_TraEspLiquidaDed))
				BEGIN
				INSERT INTO Trn_TraEspLiquidaDed(
				TipDoc,Liquidacion,IdCia,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,IdConcepto,Descripcion,VrAbono,NitPoseedor,pVehiculo,
				EsVence,TipOdp,OrdenPago,IdCiaOdp,TipRes,Reserva,IdCiaRes,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CdSubCos,TipoFac
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Item,TipCau,Causacion,IdCiaCau,ItemCau,FechaCau,IdConcepto,Descripcion,VrAbono,NitPoseedor,pVehiculo,
				EsVence,TipOdp,OrdenPago,IdCiaOdp,TipRes,Reserva,IdCiaRes,VrSaldoOrden,CdCuenta,CdCuePagar,NumFactura,CdCCosto,CdSubCos,TipoFac
				FROM @Trn_TraEspLiquidaDed
				END 

				IF(EXISTS(SELECT * FROM @Trn_TraEspLiquidaOdp))
				BEGIN
				INSERT INTO Trn_TraEspLiquidaOdp(
				TipDoc,Liquidacion,IdCia,Item,TipOdp,OrdPago,IdCiaOdp,VrAbonado
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Item,TipOdp,OrdPago,IdCiaOdp,VrAbonado
				FROM @Trn_TraEspLiquidaOdp
				END

				IF(EXISTS(SELECT * FROM @Trn_TraEspLiquidaOtr))
				BEGIN
				INSERT INTO Trn_TraEspLiquidaOtr(
				TipDoc,Liquidacion,IdCia,Item,TipCau,Causacion,IdCiaCau,ItemCau,Factura,ItemFac,IdProveedor,pVehiculo,VrAbono,TipFac,VrFactura
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Item,TipCau,Causacion,IdCiaCau,ItemCau,Factura,ItemFac,IdProveedor,pVehiculo,VrAbono,TipFac,VrFactura
				FROM @Trn_TraEspLiquidaOtr
				END

				IF(EXISTS(SELECT * FROM @Trn_EgrFactura))
				BEGIN
				INSERT INTO Trn_EgrFactura(
				TipCom,Comprobante,IdCia,Item,Fecha,TipFac,Factura,IdCiaFac,
				ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,
				VehPropio,TipDev,NumDev,DetAbono
				)
				SELECT 
				@TipDoc,@Numero,@Cia,Item,Fecha,TipFac,Factura,IdCiaFac,
				ItemFac,IdProveedor,IdCuenta,VrAbono,EsEgreso,ItemCom,pVehiculo,
				VehPropio,TipDev,NumDev,DetAbono
				FROM @Trn_EgrFactura
				END 

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
				INSERT INTO Trn_Comprobantes(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
				CodRes, DescServicio
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo,
				NumCheque, FecCheque, @TipDoc, @Numero, @Cia, Anulado, NumDev, FecDev,
				TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
				VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado,
				Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, CdSustento, Tipo_Pago, Establec,
				PEmision, Autorizac, FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
				CodRes, DescServicio
				FROM @Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
				INSERT INTO Trn_ComDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, TipDoc, Documento,
				IdCiaDoc, CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				)
				SELECT 
				@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, IdCuenta, Detalle, VrDebito, VrCredito,
				IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
				CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta,
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, CodSubgpo, CiuOrigen, 
				CodAgncia, VehPropio, Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
				IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza,CdCuentaNiif
				FROM @Trn_ComDetalle
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
				INSERT INTO Trn_NiifComp(
				TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, IdCta,
				EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, NumDev,
				FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario,
				VrDivisa1, VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
				IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, CdSustento,
				Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
				CtbTipo, CtbNumero,
				FisTipo, FisNumero 
				)
				SELECT 
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
				@Cia, 
				C.Fecha, C.IdTercero, C.VrTotal, C.IdCta,
				C.EnEfectivo, C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, C.NumDev,
				C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, C.CedCondtor, C.CodConce, C.Beneficiario,
				C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
				C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, C.CdSustento,
				C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
				CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
				CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
				FROM @Trn_Comprobantes AS C JOIN @Trn_NiifComp AS N ON C.TipCom = N.TipComCont AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				INSERT INTO Trn_NiifDetalle(
				TipCom, Comprobante, IdCia, Item, Fecha, IdCuenta, Detalle,
				VrDebito, VrCredito, IdTercero, IdVehiculo,IdCCosto, IdSubCos,
				VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce,
				NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
				NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros,
				CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef,
				DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario,
				CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza,
				FechAutoriza, CodCuentaCG
				)
				SELECT 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
				CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END,
				@Cia,
				N.Item, N.Fecha, N.IdCuenta, N.Detalle,
				N.VrDebito, N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos,
				N.VrBase, N.TarifaBase, @TipDoc,@Numero,@Cia, N.CodConce,
				N.NitDoc, N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
				N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
				N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, N.Referncia, N.TipDocRef,
				N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
				N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza,
				N.FechAutoriza, N.CodCuentaCG
				FROM @Trn_NiifDetalle as N
				JOIN @Trn_NiifComp AS NC ON N.TipCom = NC.TipCom AND N.Comprobante = NC.Comprobante
				END
			end	

			IF(@operacion = 'i')
			begin

			  -- actualizar causaciones con deducciones
			  declare @TipCau varchar(3)
			  declare @Causacion int
			  declare @IdCiaCau varchar(2)	
			  declare @ItemCau int		  
			  declare @VrAbonoCau decimal(14,4)
			  
			  -- actualizar causaciones con deducciones
			  DECLARE ccausac CURSOR
	  		  FOR SELECT TipCau, Causacion, IdCiaCau, ItemCau, VrAbono from @Trn_TraEspLiquidaDed
	          OPEN ccausac
			  FETCH NEXT FROM ccausac into @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
			  WHILE @@FETCH_STATUS = 0
			  BEGIN
			  
				  UPDATE Trn_TraEspCauDetalle
				  SET TipoLiq = @TipDoc, NumLiquida = @Numero, CiaLiquida = @Cia, VrAbonado = VrAbonado + @VrAbonoCau
				  FROM Trn_TraEspCauDetalle t1
				  WHERE t1.TipDoc = @TipCau and t1.Causacion = @Causacion and t1.IdCia = @IdCiaCau and t1.Item = @ItemCau

			  FETCH NEXT FROM ccausac INTO @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
			  END
			  CLOSE ccausac
			  DEALLOCATE ccausac

			  -- actualizar causaciones con otros pagos
			  DECLARE pcausac CURSOR
	  		  FOR SELECT TipCau,Causacion,IdCiaCau,ItemCau, VrAbono from @Trn_TraEspLiquidaOtr
			  OPEN pcausac
			  FETCH NEXT FROM pcausac into @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
			  WHILE @@FETCH_STATUS = 0
			  BEGIN
			
				UPDATE Trn_TraEspCauDetalle
				SET TipoLiq = @TipDoc, NumLiquida = @Numero, CiaLiquida = @Cia, VrAbonado = VrAbonado + @VrAbonoCau
				FROM Trn_TraEspCauDetalle t1
				WHERE t1.TipDoc = @TipCau and t1.Causacion = @Causacion and t1.IdCia = @IdCiaCau and t1.Item = @ItemCau
			
			  FETCH NEXT FROM pcausac INTO @TipCau, @Causacion, @IdCiaCau, @ItemCau, @VrAbonoCau
			  END
			  CLOSE pcausac
			  DEALLOCATE pcausac

			  --actualizar Trn_ComFactura
			  declare @FactTipFac varchar(3)
			  declare @FactIdCiaFac varchar(2)
			  declare @FactFactura varchar(15)
			  declare @FactIdProveedor varchar(16)
			  declare @VrAbono decimal(14,4)
			  declare @ItemFac int
			  DECLARE cprincipal CURSOR
	  		  FOR select TipFac, Factura, IdCiaFac,ItemFac, IdProveedor, VrAbono from @Trn_EgrFactura
	          OPEN cprincipal
			  FETCH NEXT FROM cprincipal into @FactTipFac, @FactFactura, @FactIdCiaFac,@ItemFac, @FactIdProveedor, @VrAbono
			  WHILE @@FETCH_STATUS = 0
			  BEGIN

					  if(@VrAbono > 0)
					  begin
						  update Trn_ComFactura 
						  set VrAbonado = VrAbonado + @VrAbono
						  from Trn_ComFactura t1 
						  where t1.TipFac = @FactTipFac and t1.Factura = @FactFactura and t1.IdCia = @FactIdCiaFac and t1.Item = @ItemFac and t1.IdProveedor = @FactIdProveedor
					 end

			  FETCH NEXT FROM cprincipal INTO @FactTipFac, @FactFactura, @FactIdCiaFac,@ItemFac, @FactIdProveedor, @VrAbono
			  END
			  CLOSE cprincipal
			  DEALLOCATE cprincipal

			  --actualizar orden pago
			  update Trn_TraEspOrdenReservas
			  set EdoLiqCausac =  1
			  from Trn_TraEspOrdenReservas t1, @Trn_TraEspLiquidaDed t2
			  where t2.TipOdp = t1.TipDoc and t2.OrdenPago = t1.OrdPago and t2.IdCiaOdp = t1.IdCia

			end

			SELECT @Numero,@Comprobante

			COMMIT TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspOrdenPago]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspOrdenPago]
	@Trn_TraEspOrdenPago [dbo].[dataTypeTrn_TraEspOrdenPago] READONLY,
	@Trn_TraEspOrdenReservas [dbo].[dataTypeTrn_TraEspOrdenReservas] READONLY,
	@Trn_TraEspOrdenProg [dbo].[dataTypeTrn_TraEspOrdenProg] READONLY,
	@Trn_TraEspConceptos [dbo].[dataTypeTrn_TraEspConceptos] READONLY,
	@Trn_TraEspAntAbonos [dbo].[dataTypeTrn_TraEspAntAbonos] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_ComFactura [dbo].[dataTypeTrn_ComFactura] READONLY,
	@Trn_Pagos [dbo].[dataTypeTrn_Pagos] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeNiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
	DECLARE @Comprobante INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante
	DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
	DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante

	DECLARE @CompNiif INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante Niif
	DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
	DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaï¿½ia del comprobante Niif

	DECLARE @CompFis INT = 0 --Esta variable guarda el nï¿½mero consecutivo de comprobante Fiscal
	DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
	DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante Fiscal

	DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	--Nuevas variables
	DECLARE @Reserva INT = (SELECT  TOP 1 Reserva FROM @Trn_TraEspOrdenReservas) --Esta variable guarda el nï¿½mero de reserva
	DECLARE @ItemRes INT = (SELECT  TOP 1 ItemRes FROM @Trn_TraEspOrdenReservas) --Esta variable guarda el nï¿½mero de ï¿½tem de reserva
	DECLARE @IdCiaRes CHAR(2) = (SELECT  TOP 1 IdCiaRes FROM @Trn_TraEspOrdenReservas)  --Esta variable guarda la compaï¿½ia de la reserva
	DECLARE @VrPagos MONEY = 0 --En esta variable va guarda el valor de pago real de la reserva
	DECLARE @VrTotalPagosaRES MONEY = 0 --En esta variable va guarda el valor de pagos hechas a la reserva por ordenes de pago
	DECLARE @TipoTarifa varchar(20)

	BEGIN TRAN
		BEGIN TRY		 
			
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia 
				FROM @Trn_TraEspOrdenPago

				SELECT @Numero = Numero + 1  
				FROM TiposDocCons 
				where IdDoc = @TipDoc 
					AND IdCia = @Cia

				IF(@Numero > 0)
					UPDATE TiposDocCons 
					SET Numero = @Numero 
					WHERE IdDoc = @TipDoc 
						AND IdCia = @Cia
				ELSE
				BEGIN
					SELECT @Numero = 1

					INSERT INTO TiposDocCons 
					VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					SELECT TOP 1 @TipComp = TipCom 
					FROM @Trn_Comprobantes

					SELECT @Comprobante = Numero + 1  
					FROM TiposComCons 
					where IdCom  = @TipComp 
						AND IdCia = @IdCiaComp
					--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
					IF(@Comprobante <> '')
						UPDATE TiposComCons 
						SET Numero = @Comprobante
						WHERE IdCom = @TipComp 
							and IdCia = @IdCiaComp
					ELSE
					BEGIN
						SELECT @Comprobante = 1

						INSERT INTO TiposComCons 
						VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
				BEGIN
					SELECT TOP 1 @TipCompNiif = TipCom 
					FROM @Trn_NiifComp 
					WHERE TipoNiif = 'NIIF'

					SELECT @CompNiif = Numero + 1  
					FROM TiposComCons 
					where IdCom  = @TipCompNiif 
						AND IdCia = @IdCiaCompNiif
					--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
					IF(@CompNiif <> '')
						UPDATE TiposComCons 
						SET Numero = @CompNiif 
						WHERE IdCom = @TipCompNiif 
							and IdCia = @IdCiaCompNiif
					ELSE
					BEGIN
						SELECT @CompNiif = 1

						INSERT INTO TiposComCons 
						VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
				BEGIN
					SELECT TOP 1 @TipCompFis = TipCom 
					FROM @Trn_NiifComp
					WHERE TipoNiif = 'FISCAL'

					SELECT @CompFis = Numero + 1  
					FROM TiposComCons
					where IdCom  = @TipCompFis 
						AND IdCia = @IdCiaCompFis
					--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
					IF(@CompNiif <> '')
						UPDATE TiposComCons 
						SET Numero = @CompFis 
						WHERE IdCom = @TipCompFis 
							and IdCia = @IdCiaCompFis
					ELSE
					BEGIN
						SELECT @CompFis = 1

						INSERT INTO TiposComCons 
						VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
					END
				END
			end

			IF(@operacion = 'i')
			begin
				IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenPago))
				BEGIN
					INSERT INTO Trn_TraEspOrdenPago (
					TipDoc,OrdPago,IdCia,Fecha,TipRes,Reserva,
					IdCiaRes,IdConcepto,Cantidad,Modalidad,LiqReservas,CxPagar,
					MulPlazos,IdPlazo,FechaVence,TipCom,Comprobante,IdCiaCom,
					Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,
					TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				)
				SELECT 
					@TipDoc,@Numero,@Cia,Fecha,TipRes,Reserva,
					IdCiaRes,IdConcepto,Cantidad,Modalidad,LiqReservas,CxPagar,
					MulPlazos,IdPlazo,FechaVence,@TipComp,@Comprobante,@IdCiaComp,
					Anulado,NumDev,FecDev,Observacion,IdEstado,OrigenAdd,
					TimeSys,FecUpdate,IdCiaCrea,IdUsuario
					FROM 
						@Trn_TraEspOrdenPago
				END 

				IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenReservas))
				BEGIN
					INSERT INTO Trn_TraEspOrdenReservas (
						TipDoc,OrdPago,IdCia,Item,Fecha,TipRes,
						Reserva,IdCiaRes,ItemRes,IdVehiculo,IdConductor,IdPropietario,
						IdPoseedor,VrServicio,VrDescuento,VrRetencion,VrReteIca,VrReteCREE,
						VrAnticipos,VrOtrosDctos,VrImpuestos,VrOtrosPagos,VrNeto,BaseRet,
						BaseIca,BaseCree,TarifaRet,TarifaIca,TarifaRtc,CodTarRet,
						CodTarIca,CodTarRtc,TipEgr,Egreso,IdCiaEgr,FechaEgr,
						NumCheque,Referencia,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,
						VrConcAporte,VrConcImpuesto,VrRecCaja,CdForma,CdCenCosto,CdSubCenCos,
						VrSeguros,VrFondos,VrAportes,EdoLiqCausac,EstadoItem
					)
					SELECT 
						@TipDoc,@Numero,@Cia,Item,Fecha,TipRes,
						Reserva,IdCiaRes,ItemRes,IdVehiculo,IdConductor,IdPropietario,
						IdPoseedor,VrServicio,VrDescuento,VrRetencion,VrReteIca,VrReteCREE,
						VrAnticipos,VrOtrosDctos,VrImpuestos,VrOtrosPagos,VrNeto,BaseRet,
						BaseIca,BaseCree,TarifaRet,TarifaIca,TarifaRtc,CodTarRet,
						CodTarIca,CodTarRtc,TipEgr,Egreso,IdCiaEgr,FechaEgr,
						NumCheque,Referencia,VrConcPagos,VrConcDctos,VrConcFondo,VrConcSeguro,
						VrConcAporte,VrConcImpuesto,VrRecCaja,CdForma,CdCenCosto,CdSubCenCos,
						VrSeguros,VrFondos,VrAportes,EdoLiqCausac,EstadoItem
					FROM 
						@Trn_TraEspOrdenReservas
				END

				IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenProg))
				BEGIN
					INSERT INTO Trn_TraEspOrdenProg (
						TipDoc,OrdPago,IdCia,Item,TipRes,Reserva,
						IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr,
						VrRecorrido
					)
					SELECT 
						@TipDoc,@Numero,@Cia,Item,TipRes,Reserva,
						IdCiaRes,ItemRes,TipPgr,Programa,IdCiaPgr,ItemPgr,
						VrRecorrido
					FROM 
						@Trn_TraEspOrdenProg
				END 

				IF(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
				BEGIN
					INSERT INTO Trn_TraEspConceptos (
						TipDoc,Documento,IdCia,Item,Descripcion,Tarifa,
						TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva,IdConcepto,
						CdCuenta,NitTercero,CdTipoEsc,FechaNov,VrBase,TipoTarif,
						RefConc,Fijos,IncBaseRet,Referencia2,Referencia3,Cliente,
						Conductor,Vehiculo,ItemDoc,IdVehiculo
					)
					SELECT 
						@TipDoc,@Numero,@Cia,Item,Descripcion,Tarifa,
						TipoConc,RubroConcep,Cantidad,VrUnitario,TarifIva,IdConcepto,
						CdCuenta,NitTercero,CdTipoEsc,FechaNov,VrBase,TipoTarif,
						RefConc,Fijos,IncBaseRet,Referencia2,Referencia3,Cliente,
						Conductor,Vehiculo,ItemDoc,IdVehiculo
					FROM 
						@Trn_TraEspConceptos
				END

				IF(EXISTS(SELECT * FROM @Trn_TraEspAntAbonos))
				BEGIN
					INSERT INTO Trn_TraEspAntAbonos(
						TipDoc,Documento,IdCia,Item,Fecha,TipAnt,
						Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
					)
					SELECT 
						@TipDoc,@Numero,@Cia,Item,Fecha,TipAnt,
						Anticipo,IdCiaAnt,VrAbono,TipoAplica,Detalle,CdCuentaAnt
					FROM 
						@Trn_TraEspAntAbonos
				END

				IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
				BEGIN
					INSERT INTO Trn_DetCuentas (
						TipDoc,Documento,IdCia,Concepto,Item,IdCuenta,
						Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,
						pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac,
						FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,
						CodConc,CodTarif
					)
					SELECT 
						@TipDoc,@Numero,@Cia,Concepto,Item,IdCuenta,
						Valor,Detalle,IdTercero,CodAgncia,CdCCosto,CdSubCos,
						pVehiculo,VrBase,TipFac,Factura,IdCiaFac,ItemFac,
						FecVence,Cheque,CiuOrigen,Referencia,VrTarifa,TipoTarif,
						CodConc,CodTarif
					FROM 
						@Trn_DetCuentas
				END

				IF(EXISTS(SELECT * FROM @Trn_ComFactura))
				BEGIN
					INSERT INTO Trn_ComFactura(
						TipFac,Factura,IdCia,Item,IdProveedor,IdCuenta,
						TipDoc,Documento,IdCiaDoc,FecEmision,FecVence,VrFactura,
						VrAbonado,TipCom,Comprobante,ItemCom,Referencia,Detalle,
						pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,
						MontoAprob
					)
					SELECT 
						@TipDoc,@Numero,@Cia,Item,IdProveedor,IdCuenta,
						@TipDoc,@Numero,@Cia,FecEmision,FecVence,VrFactura,
						VrAbonado,@TipComp,@Comprobante,ItemCom,Referencia,Detalle,
						pVehiculo,VehPropio,TipRef,DocRef,IdCiaRef,EstadoApr,
						MontoAprob
					FROM 
						@Trn_ComFactura
				END 

				IF(EXISTS(SELECT * FROM @Trn_Pagos))
				BEGIN
					INSERT INTO Trn_Pagos (
						TipDoc, Documento, IdCia, Item, Fecha, IdForma, 
						Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
						CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
						Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
						TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
						CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
						CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
					)
					SELECT 
						@TipDoc, @Numero, @Cia, Item, Fecha, IdForma,
						Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
						CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
						Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
						TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
						CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
						CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
					FROM 
						@Trn_Pagos
				END

				IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
				BEGIN
					INSERT INTO Trn_Comprobantes (
						TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, 
						IdCta, EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, 
						IdCiaDoc, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
						pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
						Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
						IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
						FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
						CodRes, DescServicio
					)
					SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal,
						IdCta, EnEfectivo, NumCheque, FecCheque, @TipDoc, @Numero, 
						@Cia, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
						pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
						VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo,
						Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
						IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
						FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
						CodRes, DescServicio
					FROM 
						@Trn_Comprobantes
				END

				IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
				BEGIN
					INSERT INTO Trn_ComDetalle (
						TipCom, Comprobante, IdCia, Item, Fecha, 
						IdCuenta, 
						Detalle, VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, 
						IdSubCos, VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, 
						CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, 
						FecVence, CodCta, NumCheque, Integrado, TipoAplica, Consolida, 
						CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, 
						Referncia, TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, 
						IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
						Num_Autoriza, FechAutoriza, CdCuentaNiif
					)
					SELECT 
						@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, 
						(
							SELECT DISTINCT 
								ISNULL(T.IdCuenta, TCD.IdCuenta)
							FROM 
								@Trn_TraEspOrdenReservas AS O
							LEFT JOIN 
								TarifCuentas T ON T.IdTarifa = (
									CASE TCD.Detalle
										WHEN 'RETENCION EN LA FUENTE' THEN O.CodTarRet
										WHEN 'RETENCION ICA' THEN O.CodTarIca
									END
								)
								AND T.TipDoc = 'OPE'
						) AS IdCuenta,
						Detalle, VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, 
						IdSubCos, VrBase, TarifaBase, @TipDoc, @Numero, @Cia,
						CodConce, NitDoc, TipFac, Factura, IdCiaFac, ItemFac, 
						FecVence, CodCta, NumCheque, Integrado, TipoAplica, Consolida, 
						CodCargo, NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, 
						SUBSTRING(Referncia, 0, 50), TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, 
						IdCiaCrea, IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, 
						Num_Autoriza, FechAutoriza, CdCuentaNiif
					FROM 
						@Trn_ComDetalle AS TCD
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifComp))
				BEGIN
					INSERT INTO Trn_NiifComp (
						TipCom, 
						Comprobante, 
						IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo, 
						NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, 
						NumDev,FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, 
						CedCondtor, CodConce, Beneficiario, VrDivisa1, VrDivisa2, VrDivisa3, 
						PermEditar, Integrado, EsEgreso, Anticipo, Observacion,
						IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, 
						TipoNiif, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac,FechaAut,
						CtbTipo, 
						CtbNumero,
						FisTipo, 
						FisNumero 
					)
					SELECT 
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
						@Cia, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta, C.EnEfectivo, 
						C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, 
						C.NumDev, C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, 
						C.CedCondtor, C.CodConce, C.Beneficiario, C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, 
						C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion,
						C.IdEstado, C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, 
						N.TipoNiif, C.CdSustento, C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
						CASE N.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE NULL END, 
						CASE N.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE 0 END,
						CASE N.TipoNiif WHEN 'FISCAL' THEN @TipCompFis ELSE NULL END, 
						CASE N.TipoNiif WHEN 'FISCAL' THEN @CompFis ELSE 0 END
					FROM 
						@Trn_Comprobantes AS C 
					JOIN 
						@Trn_NiifComp AS N ON C.TipCom = N.TipComCont 
							AND C.Comprobante = N.ComprobanteCont
				END

				IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
				BEGIN
				INSERT INTO Trn_NiifDetalle (
					TipCom, 
					Comprobante, 
					IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, 
					VrCredito, IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, 
					TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce, NitDoc, 
					TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, 
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef, 
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, 
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza, 
					CodCuentaCG
				)
				SELECT 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @TipCompNiif ELSE @TipCompFis END, 
					CASE NC.TipoNiif WHEN 'NIIF' THEN @CompNiif ELSE @CompFis END, 
					@Cia, N.Item, N.Fecha, N.IdCuenta, N.Detalle, N.VrDebito, 
					N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos, N.VrBase,
					N.TarifaBase, @TipDoc, @Numero, @Cia, N.CodConce, N.NitDoc, 
					N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, SUBSTRING(N.Referncia,0,50), N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza, N.FechAutoriza, 
					N.CodCuentaCG
				FROM 
					@Trn_NiifDetalle as N
				JOIN 
					@Trn_NiifComp AS NC ON N.TipCom = NC.TipCom 
						AND N.Comprobante = NC.Comprobante
				END
			end	

			IF(@operacion = 'i')
			begin
				--actualiza los items de la programaciï¿½n detalle de cada reserva agregada en la Orden de Pago
				UPDATE Trn_TraEspProgramaDet
				SET TipDocOdp = 'OPE',NumOdp = @Numero, IdCiaOdp = t3.IdCia, FechaOdp = t3.Fecha
				FROM Trn_TraEspProgramaDet t1, @Trn_TraEspOrdenProg t2, @Trn_TraEspOrdenPago t3
				WHERE t1.TipDoc = t2.TipPgr 
					and t1.Programa = t2.Programa 
					and t1.IdCia = t2.IdCiaPgr 
					and t1.Item = t2.ItemPgr 
					and t1.TipDocRes = t2.TipRes 
					and t1.Reserva = t2.Reserva 
					and t1.IdCiaRes = t2.IdCiaRes 
					and t1.ItemRes = t2.ItemRes

				--JHON ROA-->Nuevo lï¿½nea de cï¿½digo actualizar el estado de la reserva cuando ya se cumpla el valor total de la reserva
				--11/12/2017 Se cambia para tener en cuenta cuando TipoTarifa de la reserva es diaria.
				SELECT @TipoTarifa = TipoTarifa 
				FROM Trn_TraEspResDetalle 
				WHERE Reserva = @Reserva 
					AND IdCia = @IdCiaRes 
					AND Item = @ItemRes
				
				--No se necesita traer la actual reserva, poque ya fue insertada arriba en este procedimiento
				SELECT @VrTotalPagosaRES = ROUND(ISNULL(SUM(R.VrServicio),0), 1) 
				FROM Trn_TraEspOrdenReservas R
				LEFT JOIN Trn_TraEspOrdenPago AS OP ON R.TipDoc = OP.TipDoc 
					AND  R.OrdPago = OP.OrdPago 
					AND  R.IdCia = OP.IdCia
				WHERE R.Reserva = @Reserva 
					AND R.IdCiaRes = @IdCiaRes 
					AND R.ItemRes = @ItemRes 
					AND OP.Anulado = 0;

				IF(upper(@TipoTarifa) <> 'DIA')
				BEGIN
					SELECT @VrPagos = VrPagos 
					FROM Trn_TraEspResDetalle 
					WHERE Reserva = @Reserva 
						AND IdCia = @IdCiaRes 
						AND Item = @ItemRes

					IF(@VrTotalPagosaRES >= @VrPagos)
					BEGIN
						UPDATE Trn_TraEspResDetalle
						SET EstadoItem ='LIQUIDADA'
						WHERE Reserva = @Reserva 
							AND IdCia = @IdCiaRes 
							AND Item = @ItemRes
					END
					ELSE -- revisar que la cant de veh que se vayan a liquidar(programados no novedad) ya hayan sido liquidados(pasan de xliquidar a liquidado) y que la reserva no se haya vencido
					BEGIN
						declare 
							@cantveh int= 0, 
							@cantord int = 0, 
							@fechares date, 
							@fechasys date,
							@idveh varchar(10)

						select @cantveh = count(*) 
						from trn_traespprogramadet 
						where Reserva = @Reserva 
							AND IdCiaRes = @IdCiaRes 
							AND ItemRes = @ItemRes 
							and IdNovedad = '0' 
							and IdVehiculo <>'0'

						select @fechares = fechafin 
						from trn_traespreservas 
						where Reserva = @Reserva 
							AND IdCia = @IdCiaRes

						select @fechasys = FechaActual 
						from companias 
						where IdCia = @IdCiaRes

						--selecciono  los progdetalle de esos vehiculos
						declare 
							@Trn_TraEspProgramaDet dataTypeTrn_TraEspProgramaDet 

						INSERT INTO @Trn_TraEspProgramaDet (
							TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,
							TipDocRes,Reserva,IdCiaRes,ItemRes,IdOrigen,IdDestino,
							IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
							IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,
							Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,
							DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,
							CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,
							Observacion
						) 
						SELECT 
							TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,
							TipDocRes,Reserva,IdCiaRes,ItemRes,IdOrigen,IdDestino,
							IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
							IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,
							Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,
							DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,
							CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,
							Observacion
						FROM 
							Trn_TraEspProgramaDet  
						where 
							Reserva = @Reserva 
								AND IdCiaRes = @IdCiaRes 
								AND ItemRes = @ItemRes 
								and IdNovedad = '0' 
								and IdVehiculo <>'0'
					  
						--cursor para verififcar si los vehiculos fueron pagados en ordenes de pago					   
						DECLARE verificar CURSOR
						FOR SELECT IdVehiculo  FROM @Trn_TraEspProgramaDet
						OPEN verificar
						FETCH NEXT FROM verificar INTO @idveh
						WHILE @@FETCH_STATUS = 0
						BEGIN
							--verifico la cantidad que ya fueron liquidados(tiene en cuenta la actual)
							if (exists(select * from Trn_TraEspOrdenReservas where Reserva = @Reserva AND IdCiaRes = @IdCiaRes AND ItemRes = @ItemRes and IdVehiculo = @idveh))
								select @cantord = @cantord + 1

							FETCH NEXT FROM verificar INTO @idveh 
							END
							CLOSE verificar
							DEALLOCATE verificar

							--se verifica que cumpal para colocar la resrva a liquidada
							IF((@cantord >= @cantveh) AND (@fechasys  >= @fechares))
							BEGIN 
								UPDATE Trn_TraEspResDetalle
								SET EstadoItem ='LIQUIDADA'
								WHERE Reserva = @Reserva 
									AND IdCia = @IdCiaRes 
									AND Item = @ItemRes
							END
						END
				END
				ELSE
				BEGIN
					SELECT @VrPagos = ISNULL(SUM(VrPagos),0)  
					FROM Trn_TraEspProgramaDet AS PD 
					JOIN Trn_TraEspPrograma  AS P ON P.TipDoc = PD.TipDoc 
						AND P.Programa = PD.Programa 
						AND P.IdCia = PD.IdCia 
					WHERE Reserva = @Reserva 
						AND IdCiaRes = @IdCiaRes 
						AND ItemRes = @ItemRes 
						and IdNovedad = '0' 
						and IdVehiculo <>'0' 
						and p.Anulado = 0

					IF(@VrTotalPagosaRES >= @VrPagos)
					BEGIN
						UPDATE Trn_TraEspResDetalle
						SET EstadoItem ='LIQUIDADA'
						WHERE Reserva = @Reserva 
							AND IdCia = @IdCiaRes 
							AND Item = @ItemRes
					END
				END

				--actualiza los anticipos
				UPDATE Trn_TraEspAnticipos
				SET VrAbonado = VrAbonado + t2.VrAbono
				FROM Trn_TraEspAnticipos t1, @Trn_TraEspAntAbonos t2
				WHERE t1.TipDoc = t2.TipAnt 
					and t1.Anticipo = t2.Anticipo 
					and t1.IdCia = t2.IdCiaAnt
			end

			SELECT @Numero,@Comprobante

			COMMIT TRAN
		END TRY

        BEGIN CATCH
			ROLLBACK TRAN

			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
				@ErrorMessage = ERROR_MESSAGE(),
				@ErrorSeverity = ERROR_SEVERITY(),
				@ErrorState = ERROR_STATE();

			RAISERROR(
				@ErrorMessage, -- Message text.
				@ErrorSeverity, -- Severity.
				@ErrorState -- State.
			);
		END CATCH
	
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspOrdenPagoGIE]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspOrdenPagoGIE]
	@Trn_TraEspOrdenPago [dbo].[dataTypeTrn_TraEspOrdenPago] READONLY,
	@Trn_TraEspOrdenReservas [dbo].[dataTypeTrn_TraEspOrdenReservas] READONLY,
	@Trn_TraEspOrdenProg [dbo].[dataTypeTrn_TraEspOrdenProg] READONLY,
	@Trn_TraEspConceptos [dbo].[dataTypeTrn_TraEspConceptos] READONLY,
	@Trn_TraEspAntAbonos [dbo].[dataTypeTrn_TraEspAntAbonos] READONLY,
	@Trn_DetCuentas [dbo].[dataTypeTrn_DetCuentas] READONLY,
	@Trn_ComFactura [dbo].[dataTypeTrn_ComFactura] READONLY,
	@Trn_Pagos [dbo].[dataTypeTrn_Pagos] READONLY,
	@Trn_Comprobantes [dbo].[dataTypeTrn_Comprobantes] READONLY,
	@Trn_ComDetalle [dbo].[dataTypeTrn_ComDetalle] READONLY,
	@Trn_NiifComp [dbo].[dataTypeNiifComp] READONLY,
	@Trn_NiifDetalle [dbo].[dataTypeNiifDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
	DECLARE @Comprobante INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante
	DECLARE @TipComp VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante
	DECLARE @IdCiaComp VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante

	DECLARE @CompNiif INT = 0 --Esta variable guarda el nï¿½mero consecutivo del comprobante Niif
	DECLARE @TipCompNiif VARCHAR(3) = '0' --Esta variable guarda el tipo de comprobante Niif
	DECLARE @IdCiaCompNiif VARCHAR(4) = '00'--Esta variable guarda la compaï¿½ia del comprobante Niif

	DECLARE @CompFis INT = 0 --Esta variable guarda el nï¿½mero consecutivo de comprobante Fiscal
	DECLARE @TipCompFis VARCHAR(3)  = '0' --Esta variable guarda el tipo de comprobante Fiscal
	DECLARE @IdCiaCompFis VARCHAR(4) = '00' --Esta variable guarda la compaï¿½ia del comprobante Fiscal

	DECLARE @TipDoc VARCHAR(3) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Cia VARCHAR(2) --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	DECLARE @Numero INT --En esta variable se guarda el consecutivo del documento aprobaciï¿½n
	--Nuevas variables
	DECLARE @Reserva INT = (SELECT  TOP 1 Reserva FROM @Trn_TraEspOrdenReservas) --Esta variable guarda el nï¿½mero de reserva
	DECLARE @ItemRes INT = (SELECT  TOP 1 ItemRes FROM @Trn_TraEspOrdenReservas) --Esta variable guarda el nï¿½mero de ï¿½tem de reserva
	DECLARE @IdCiaRes CHAR(2) = (SELECT  TOP 1 IdCiaRes FROM @Trn_TraEspOrdenReservas)  --Esta variable guarda la compaï¿½ia de la reserva
	DECLARE @VrPagos MONEY = 0 --En esta variable va guarda el valor de pago real de la reserva
	DECLARE @VrTotalPagosaRES MONEY = 0 --En esta variable va guarda el valor de pagos hechas a la reserva por ordenes de pago
	DECLARE @TipoTarifa varchar(20)

	BEGIN TRAN

	BEGIN TRY		 
			
		IF(@operacion = 'i')
		begin
			SELECT TOP 1 @TipDoc = TipDoc, @Cia = IdCia, @IdCiaComp = IdCia, @IdCiaCompNiif = IdCia, @IdCiaCompFis = IdCia 
			FROM @Trn_TraEspOrdenPago

			SELECT @Numero = Numero + 1  
			FROM TiposDocCons 
			where IdDoc = @TipDoc AND IdCia = @Cia

			IF(@Numero > 0)
				UPDATE TiposDocCons
				SET Numero = @Numero 
				WHERE IdDoc = @TipDoc AND IdCia = @Cia
			ELSE
			BEGIN
				SELECT @Numero = 1

				INSERT INTO TiposDocCons 
				VALUES (@TipDoc,@Cia,0,0,0,0,NULL,'',@Numero,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				SELECT TOP 1 @TipComp = TipCom 
				FROM @Trn_Comprobantes

				SELECT @Comprobante = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipComp AND IdCia = @IdCiaComp

				--UPDATE TiposComCons SET Numero = @Comprobante WHERE IdCom = @TipComp AND IdCia = @IdCiaComp
				IF(@Comprobante <> '')
					UPDATE TiposComCons 
					SET Numero = @Comprobante 
					WHERE IdCom = @TipComp and IdCia = @IdCiaComp
				ELSE
				BEGIN
					SELECT @Comprobante = 1

					INSERT INTO TiposComCons 
					VALUES (@TipComp,@IdCiaComp,0,0,@Comprobante,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'NIIF'))
			BEGIN
				SELECT TOP 1 @TipCompNiif = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'NIIF'

				SELECT @CompNiif = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompNiif AND IdCia = @IdCiaCompNiif

				--UPDATE TiposComCons SET Numero = @CompNiif WHERE IdCom = @TipCompNiif AND IdCia = @IdCiaCompNiif
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompNiif
					WHERE IdCom = @TipCompNiif and IdCia = @IdCiaCompNiif
				ELSE
				BEGIN
					SELECT @CompNiif = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompNiif,@IdCiaCompNiif,0,0,@CompNiif,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp WHERE TipoNiif = 'FISCAL'))
			BEGIN
				SELECT TOP 1 @TipCompFis = TipCom 
				FROM @Trn_NiifComp 
				WHERE TipoNiif = 'FISCAL'

				SELECT @CompFis = Numero + 1  
				FROM TiposComCons 
				where IdCom  = @TipCompFis AND IdCia = @IdCiaCompFis

				--UPDATE TiposComCons SET Numero = @CompFis WHERE IdCom = @TipCompFis AND IdCia = @IdCiaCompFis
				IF(@CompNiif <> '')
					UPDATE TiposComCons 
					SET Numero = @CompFis 
					WHERE IdCom = @TipCompFis and IdCia = @IdCiaCompFis
				ELSE
				BEGIN
					SELECT @CompFis = 1

					INSERT INTO TiposComCons 
					VALUES (@TipCompFis,@IdCiaCompFis,0,0,@CompFis,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null)
				END
			END
		end

		IF(@operacion = 'i')
		begin
			IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenPago))
			BEGIN
				INSERT INTO Trn_TraEspOrdenPago (
					TipDoc, OrdPago, IdCia, Fecha, TipRes, Reserva,
					IdCiaRes, IdConcepto, Cantidad, Modalidad, LiqReservas, CxPagar, 
					MulPlazos, IdPlazo, FechaVence, TipCom, Comprobante, IdCiaCom, 
					Anulado, NumDev, FecDev, Observacion, IdEstado, OrigenAdd, 
					TimeSys, FecUpdate, IdCiaCrea, IdUsuario
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Fecha, TipRes, Reserva, 
					IdCiaRes, IdConcepto, Cantidad, Modalidad, LiqReservas, CxPagar, 
					MulPlazos, IdPlazo, FechaVence, @TipComp, @Comprobante, @IdCiaComp, 
					Anulado, NumDev, FecDev, Observacion, IdEstado, OrigenAdd, 
					TimeSys, FecUpdate, IdCiaCrea, IdUsuario
				FROM 
					@Trn_TraEspOrdenPago
			END 

			IF(EXISTS(SELECT * FROM @Trn_TraEspOrdenReservas))
			BEGIN
				INSERT INTO Trn_TraEspOrdenReservas (
					TipDoc, OrdPago, IdCia, Item, Fecha, TipRes, 
					Reserva, IdCiaRes, ItemRes, IdVehiculo, IdConductor, IdPropietario,
					IdPoseedor, VrServicio, VrDescuento, VrRetencion, VrReteIca, VrReteCREE,
					VrAnticipos, VrOtrosDctos, VrImpuestos, VrOtrosPagos, VrNeto, BaseRet,
					BaseIca, BaseCree, TarifaRet, TarifaIca, TarifaRtc, CodTarRet,
					CodTarIca, CodTarRtc, TipEgr, Egreso, IdCiaEgr, FechaEgr,
					NumCheque, Referencia, VrConcPagos, VrConcDctos, VrConcFondo, VrConcSeguro,
					VrConcAporte, VrConcImpuesto, VrRecCaja, CdForma, CdCenCosto, CdSubCenCos,
					VrSeguros, VrFondos, VrAportes, EdoLiqCausac, EstadoItem
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Item, Fecha, TipRes,
					Reserva, IdCiaRes, ItemRes, IdVehiculo, IdConductor, IdPropietario,
					IdPoseedor, VrServicio, VrDescuento, VrRetencion, VrReteIca, VrReteCREE,
					VrAnticipos, VrOtrosDctos, VrImpuestos, VrOtrosPagos, VrNeto, BaseRet,
					BaseIca, BaseCree, TarifaRet, TarifaIca, TarifaRtc, CodTarRet,
					CodTarIca, CodTarRtc, TipEgr, Egreso, IdCiaEgr, FechaEgr,
					NumCheque, Referencia, VrConcPagos, VrConcDctos, VrConcFondo, VrConcSeguro,
					VrConcAporte, VrConcImpuesto, VrRecCaja, CdForma, CdCenCosto, CdSubCenCos,
					VrSeguros, VrFondos, VrAportes, EdoLiqCausac, EstadoItem
				FROM 
					@Trn_TraEspOrdenReservas
			END

			IF(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
			BEGIN
				INSERT INTO Trn_TraEspConceptos(
					TipDoc, Documento, IdCia, Item, Descripcion, Tarifa,
					TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto,
					CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase, TipoTarif,
					RefConc, Fijos, IncBaseRet, Referencia2, Referencia3, Cliente,
					Conductor, Vehiculo, ItemDoc, IdVehiculo
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Item, Descripcion, Tarifa,
					TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto,
					CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase, TipoTarif,
					RefConc, Fijos, IncBaseRet, Referencia2, Referencia3, Cliente,
					Conductor, Vehiculo, ItemDoc, IdVehiculo
				FROM	
					@Trn_TraEspConceptos
			END

			IF(EXISTS(SELECT * FROM @Trn_TraEspAntAbonos))
			BEGIN
				INSERT INTO Trn_TraEspAntAbonos(
					TipDoc, Documento, IdCia, Item, Fecha, TipAnt,
					Anticipo, IdCiaAnt, VrAbono, TipoAplica, Detalle, CdCuentaAnt
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Item, Fecha, TipAnt, 
					Anticipo, IdCiaAnt, VrAbono, TipoAplica, Detalle, CdCuentaAnt
				FROM
					@Trn_TraEspAntAbonos
			END

			IF(EXISTS(SELECT * FROM @Trn_DetCuentas))
			BEGIN
				INSERT INTO Trn_DetCuentas (
					TipDoc, Documento, IdCia, Concepto, Item, IdCuenta, 
					Valor, Detalle, IdTercero, CodAgncia, CdCCosto, CdSubCos, 
					pVehiculo, VrBase, TipFac, Factura, IdCiaFac, ItemFac, 
					FecVence, Cheque, CiuOrigen, Referencia, VrTarifa, TipoTarif,
					CodConc, CodTarif
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Concepto, Item, IdCuenta,
					Valor, Detalle, IdTercero, CodAgncia, CdCCosto, CdSubCos,
					pVehiculo, VrBase, TipFac, Factura, IdCiaFac, ItemFac, 
					FecVence, Cheque, CiuOrigen, Referencia, VrTarifa, TipoTarif,
					CodConc, CodTarif
				FROM 
					@Trn_DetCuentas
			END

			IF(EXISTS(SELECT * FROM @Trn_ComFactura))
			BEGIN
				INSERT INTO Trn_ComFactura(
					TipFac, Factura, IdCia, Item, IdProveedor, IdCuenta,
					TipDoc, Documento, IdCiaDoc, FecEmision, FecVence, VrFactura, 
					VrAbonado, TipCom, Comprobante, ItemCom, Referencia, Detalle, 
					pVehiculo, VehPropio, TipRef, DocRef, IdCiaRef, EstadoApr, 
					MontoAprob
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Item, IdProveedor, IdCuenta, 
					@TipDoc, @Numero, @Cia, FecEmision, FecVence, VrFactura, 
					VrAbonado, @TipComp, @Comprobante, ItemCom, Referencia, Detalle, 
					pVehiculo, VehPropio, TipRef, DocRef, IdCiaRef, EstadoApr, 
					MontoAprob
				FROM 
					@Trn_ComFactura
			END 

			IF(EXISTS(SELECT * FROM @Trn_Pagos))
			BEGIN
				INSERT INTO Trn_Pagos (
					TipDoc, Documento, IdCia, Item, Fecha, IdForma, 
					Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
					CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
					Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
					TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
					CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
					CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
				)
				SELECT 
					@TipDoc, @Numero, @Cia, Item, Fecha, IdForma, 
					Detalle, VrPagado, VrCambio, EsCaja, IdBanco, NitCliente, 
					CdAgencia, NumForma, FecForma, CtaForma, Beneficiario, Referncia1, 
					Referncia2, CdLocal, NumAutoriza, VrDenom, Cantidad, TipDenom, 
					TipRef, DocRef, IdCiaRef, ItemDoc, CdCta, IdUsuario,
					CdProducto, FE_Ticket, Cant_Gals, PrecioBase, PrecioUnit, ConsCP, 
					CodCueCons, PrecioPub, RefVehiculo, RefNumVeh
				FROM 
					@Trn_Pagos
			END

			IF(EXISTS(SELECT * FROM @Trn_Comprobantes))
			BEGIN
				INSERT INTO Trn_Comprobantes (
					TipCom, Comprobante, IdCia, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, TipDoc, Documento, 
					IdCiaDoc, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, NiifTipo, NiifNumero, FisTipo, FisNumero, DocSoporte,
					CodRes, DescServicio
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Fecha, IdTercero, VrTotal, 
					IdCta, EnEfectivo, NumCheque, FecCheque, @TipDoc, @Numero, 
					@Cia, Anulado, NumDev, FecDev, TipEgr, NEgreso, 
					pVehiculo, VehPropio, CedCondtor, CodConce, Beneficiario, VrDivisa1,
					VrDivisa2, VrDivisa3, PermEditar, Integrado, EsEgreso, Anticipo, 
					Observacion, IdEstado, Propddes, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, 
					FechaAut, @TipCompNiif, @CompNiif, @TipCompFis, @CompFis, DocSoporte,
					CodRes, DescServicio
				FROM 
					@Trn_Comprobantes
			END

			IF(EXISTS(SELECT * FROM @Trn_ComDetalle))
			BEGIN
				INSERT INTO Trn_ComDetalle(
					TipCom, Comprobante, IdCia, Item, Fecha, 
					IdCuenta, 
					Detalle, 
					VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, IdSubCos, 
					VrBase, TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce, 
					NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, 
					CodCta, NumCheque, Integrado, TipoAplica, Consolida, CodCargo, 
					NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, 
					TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, 
					FechAutoriza,CdCuentaNiif
				)
				SELECT 
					@TipComp, @Comprobante, @IdCiaComp, Item, Fecha, 
					(
						SELECT DISTINCT 
							ISNULL(T.IdCuenta, D.IdCuenta)
						FROM 
							@Trn_TraEspOrdenReservas AS O
						LEFT JOIN 
							TarifCuentas T ON T.IdTarifa = (
								CASE D.Detalle
									WHEN 'RETENCION EN LA FUENTE' THEN O.CodTarRet
									WHEN 'RETENCION ICA' THEN O.CodTarIca
								END
							)
							AND T.TipDoc = 'OPE'
					) AS IdCuenta,
					CASE 
						WHEN D.Detalle = 'CUENTA POR PAGAR' THEN (
							CASE 
								WHEN EXISTS (SELECT 1 FROM @Trn_TraEspOrdenReservas WHERE Referencia != '') THEN 'CUENTA POR PAGAR-REF:' + (SELECT Referencia FROM @Trn_TraEspOrdenReservas WHERE Referencia != '')
								ELSE 'CUENTA POR PAGAR' 
							END
						)
						ELSE D.Detalle 
					END AS Detalle, 
					VrDebito, VrCredito, IdTercero, IdVehiculo, IdCCosto, IdSubCos, 
					VrBase, TarifaBase, @TipDoc, @Numero, @Cia, CodConce, 
					NitDoc, TipFac, Factura, IdCiaFac, ItemFac, FecVence, 
					CodCta, NumCheque, Integrado, TipoAplica, Consolida, CodCargo, 
					NitOtros, CodSubgpo, CiuOrigen, CodAgncia, VehPropio, SUBSTRING(Referncia, 0, 50), 
					TipDocRef, DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, 
					IdUsuario, CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, 
					FechAutoriza, CdCuentaNiif
				FROM 
					@Trn_ComDetalle D
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifComp))
			BEGIN
				INSERT INTO Trn_NiifComp(
					TipCom, 
					Comprobante, 
					IdCia, Fecha, IdTercero, VrTotal, IdCta, EnEfectivo, 
					NumCheque, FecCheque, TipDoc, Documento, IdCiaDoc, Anulado, 
					NumDev, FecDev, TipEgr, NEgreso, pVehiculo, VehPropio, 
					CedCondtor, CodConce, Beneficiario, VrDivisa1, VrDivisa2, VrDivisa3, 
					PermEditar, Integrado, EsEgreso, Anticipo, Observacion, IdEstado, 
					Propddes, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, TipoNiif, 
					CdSustento, Tipo_Pago, Establec, PEmision, Autorizac, FechaAut,
					CtbTipo, 
					CtbNumero,
					FisTipo, 
					FisNumero 
				)
				SELECT 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE @TipCompFis 
					END, 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE @CompFis 
					END, 
					@Cia, C.Fecha, C.IdTercero, C.VrTotal, C.IdCta, C.EnEfectivo, 
					C.NumCheque, C.FecCheque, @TipDoc, @Numero, @Cia, C.Anulado, 
					C.NumDev, C.FecDev, C.TipEgr, C.NEgreso, C.pVehiculo, C.VehPropio, 
					C.CedCondtor, C.CodConce, C.Beneficiario, C.VrDivisa1, C.VrDivisa2, C.VrDivisa3, 
					C.PermEditar, C.Integrado, C.EsEgreso, C.Anticipo, C.Observacion, C.IdEstado, 
					C.Propddes, C.TimeSys, C.FecUpdate, C.IdCiaCrea, C.IdUsuario, N.TipoNiif, 
					C.CdSustento, C.Tipo_Pago, C.Establec, C.PEmision, C.Autorizac, C.FechaAut,
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE NULL 
					END, 
					CASE N.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE 0 
					END,
					CASE N.TipoNiif 
						WHEN 'FISCAL' THEN @TipCompFis 
						ELSE NULL 
					END, 
					CASE N.TipoNiif 
						WHEN 'FISCAL' THEN @CompFis 
						ELSE 0 
					END
					FROM 
						@Trn_Comprobantes AS C 
					JOIN 
						@Trn_NiifComp AS N ON C.TipCom = N.TipComCont 
						AND C.Comprobante = N.ComprobanteCont
			END

			IF(EXISTS(SELECT * FROM @Trn_NiifDetalle))
			BEGIN
				INSERT INTO Trn_NiifDetalle (
					TipCom, 
					Comprobante, 
					IdCia, Item, Fecha, IdCuenta, Detalle, VrDebito, 
					VrCredito, IdTercero, IdVehiculo, IdCCosto, IdSubCos, VrBase, 
					TarifaBase, TipDoc, Documento, IdCiaDoc, CodConce, NitDoc, 
					TipFac, Factura, IdCiaFac, ItemFac, FecVence, CodCta, 
					NumCheque, Integrado, TipoAplica, Consolida, CodCargo, NitOtros, 
					CodSubgpo, CiuOrigen, CodAgncia, VehPropio, Referncia, TipDocRef, 
					DocRef, IdCiaRef, TimeSys, FecUpdate, IdCiaCrea, IdUsuario, 
					CdConcTrib, CdTarifTrib, NumEstablec, PtoEmision, Num_Autoriza, FechAutoriza, 
					CodCuentaCG
				)
				SELECT 
					CASE NC.TipoNiif 
						WHEN 'NIIF' THEN @TipCompNiif 
						ELSE @TipCompFis 
					END, 
					CASE NC.TipoNiif 
						WHEN 'NIIF' THEN @CompNiif 
						ELSE @CompFis 
					END, 
					@Cia, N.Item, N.Fecha, N.IdCuenta, N.Detalle, N.VrDebito, 
					N.VrCredito, N.IdTercero, N.IdVehiculo,N.IdCCosto, N.IdSubCos, N.VrBase, 
					N.TarifaBase, @TipDoc, @Numero, @Cia, N.CodConce, N.NitDoc, 
					N.TipFac, N.Factura, N.IdCiaFac, N.ItemFac, N.FecVence, N.CodCta, 
					N.NumCheque, N.Integrado, N.TipoAplica, N.Consolida, N.CodCargo, N.NitOtros,
					N.CodSubgpo, N.CiuOrigen, N.CodAgncia, N.VehPropio, SUBSTRING(N.Referncia,0,50), N.TipDocRef,
					N.DocRef, N.IdCiaRef, N.TimeSys, N.FecUpdate, N.IdCiaCrea, N.IdUsuario,
					N.CdConcTrib, N.CdTarifTrib, N.NumEstablec, N.PtoEmision ,N.Num_Autoriza, N.FechAutoriza, 
					N.CodCuentaCG
				FROM 
					@Trn_NiifDetalle as N
				JOIN 
					@Trn_NiifComp AS NC ON N.TipCom = NC.TipCom 
					AND N.Comprobante = NC.Comprobante
			END

			BEGIN 
				UPDATE 
					Trn_TraEspResDetalle
				SET 
					EstadoItem ='LIQUIDADA'
				WHERE 
					Reserva = @Reserva 
					AND IdCia = @IdCiaRes 
					AND Item = @ItemRes
			END
		end	

		SELECT @Numero,@Comprobante

		COMMIT TRAN
	END TRY
	BEGIN CATCH
		ROLLBACK TRAN

		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
		);
	END CATCH

	RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspOtroSi]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspOtroSi]
	@Trn_TraEspOtroSi [dbo].[dataTypeTrn_TraEspOtroSi] READONLY,
	@Trn_TraEspOtroSiContratos [dbo].[dataTypeTrn_TraEspOtroSiContratos] READONLY,
	@Trn_TraEspContratoDet [dbo].[dataTypeTrn_TraEspContratoDet] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @IdOtroSi INT --Esta variable guarda el nÃºmero de consecutivo del OtroSÃ­ insertado actualmente
DECLARE @Contrato INT --Esta variable guarda el nÃºmero de consecutivo del contrato a quien se le ha insertado un OtroSÃ­
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de contrato a quien se le ha insertado un OtroSÃ­
DECLARE @IdCia VARCHAR(2) --Esta variable guarda la cÃ­a de contrato a quien se le ha insertado un OtroSÃ­
DECLARE @VrAdicion DECIMAL --Esta variable guarda el valor a adicionar al contrato a quien se le ha insertado un OtroSÃ­
DECLARE @FechaFinNew SMALLDATETIME --Esta variable guarda el valor dela nueva fecha del contrato a quien se le ha insertado un OtroSÃ­
DECLARE @Item INT --Esta variable guarda el nÃºmero de consecutivo del Item contrato a quien se le ha insertado un OtroSÃ­
DECLARE @VrCobro DECIMAL --Esta variable actualiza el valor a cobrar al contrato a quien se le ha insertado un OtroSÃ­
--declare @item int
	BEGIN TRAN
		BEGIN TRY

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN
				IF(EXISTS(SELECT * FROM @Trn_TraEspOtroSi))
				begin
					INSERT INTO Trn_TraEspOtroSi(
					Fecha, Adicion, CFecha, Items, Aplicado, TimeSys, Observacion, IdUsuario, Anulado, FecDev
					)
					SELECT 
					Fecha, Adicion, CFecha, Items, Aplicado, TimeSys, Observacion, IdUsuario, Anulado, FecDev
					FROM @Trn_TraEspOtroSi
				end
				SET @IdOtroSi = SCOPE_IDENTITY()
				IF(EXISTS(SELECT * FROM @Trn_TraEspOtroSiContratos))
				begin
					EXEC('DISABLE TRIGGER [dbo].[Tr_OtroSiCOE] on Trn_TraEspOtroSiContratos');
					INSERT INTO Trn_TraEspOtroSiContratos(
					IdOtroSi, TipDocCnt, Contrato, IdCiaCnt, FechaFinAnt, FechaFinNew, VrPpto, VrSaldoPpo, VrAdicionPpto
					)
					SELECT 
					@IdOtroSi, TipDocCnt, Contrato, IdCiaCnt, FechaFinAnt, FechaFinNew, VrPpto, VrSaldoPpo, VrAdicionPpto
					FROM @Trn_TraEspOtroSiContratos
					SELECT @TipDoc = TipDocCnt,  @Contrato = Contrato, @IdCia = IdCiaCnt, @VrAdicion = VrAdicionPpto, @FechaFinNew = FechaFinNew  FROM @Trn_TraEspOtroSiContratos
					EXEC('ENABLE TRIGGER [dbo].[Tr_OtroSiCOE] on Trn_TraEspOtroSiContratos');
				end
				--row["VrTotal"] = (((Convert.ToDecimal(this.txtvVrDiaAdi.Value) * Convert.ToInt32(this.txtvDiasAdi.Value)) + (Convert.ToDecimal(this.txtvVrMonitor.Value) * Convert.ToInt32(this.txtvCantMo.Value)) + Convert.ToDecimal(row["VrUnitario"])) * Convert.ToInt32(row["Cantveh"]));
			   IF(EXISTS(SELECT * FROM @Trn_TraEspContratoDet))
				begin
					SET @VrCobro = (select (sum(VrDia * DiasDisp) + sum(VrMonitor * CantMonitor) + sum(VrUnitario)) FROM @Trn_TraEspContratoDet)
				end
			   -- --Actualizar contrato
				UPDATE Trn_TraEspContratos SET VrPresupuesto = (VrPresupuesto + @VrAdicion), VrSaldoPresup = (VrSaldoPresup + @VrAdicion), FechaFin = @FechaFinNew, VrCobro = VrCobro + ISNULL(@VrCobro, 0)
				WHERE TipDoc = @TipDoc AND Contrato = @Contrato and IdCia = @IdCia
				--AgrergarItems de Contrato Detalle
				IF(EXISTS(SELECT * FROM @Trn_TraEspContratoDet))
				begin
					SET @Item = (select max(Item) from trn_traespcontratodet where TipDoc = @TipDoc AND contrato = @Contrato AND idcia = @IdCia)
					INSERT INTO Trn_TraEspContratoDet(
					TipDoc,Contrato,IdCia,Item,IdHorario,TipPed,Pedido,CiaPed,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
					Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
					DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,IdOtroSi,ItemAnuladoOS,
					EsItemPME
					) 
					SELECT --(Item + @Item)
					@TipDoc,@Contrato,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),IdHorario,TipPed,Pedido,@IdCia,ItemPed,TipRes,NumRes,IdCiaRes,ItemRes,IdVehiculo,CdTipVeh,NumPasajeros,PesoNeto,VrUnitario,VrPago,IdRuta,
					Referencia1,Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,
					DiasDisp,VrDia,Parada,CdTipRuta,CdTipServicio,CantVeh,Retorno,VrMonitor,CantMonitor,VrMaxRec,NumDias,TipoTarifa,IdColegio,Codigo,Itinerario,VLargo,@IdOtroSi,ItemAnuladoOS,EsItemPME
					FROM @Trn_TraEspContratoDet
				end
			 END

			 --ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
				declare @FecDev smalldatetime 
				select @IdOtroSi = IdOtroSi, @FecDev = FecDev from @Trn_TraEspOtroSi
				SET @VrCobro = (select (sum(VrDia * DiasDisp) + sum(VrMonitor * CantMonitor) + sum(VrUnitario)) FROM Trn_TraEspContratoDet where IdOtroSi = @IdOtroSi)
				UPDATE Trn_TraEspOtroSi SET Anulado = 1, FecDev = @FecDev  WHERE IdOtroSi = @IdOtroSi
				--Devolver el contrato a los datos anteiores al OtroSÃ­
				UPDATE  C SET  C.FechaFin = OSC.FechaFinAnt, C.VrPresupuesto = OSC.VrPpto, C.VrSaldoPresup = (OSC.VrSaldoPpo  - OSC.VrAdicionPpto) , C.VrCobro  = (C.VrCobro -ISNULL(@VrCobro, 0))
				FROM Trn_TraEspContratos as C
				JOIN Trn_TraEspContratoDet AS D ON C.TipDoc = D.TipDoc AND C.Contrato = D.Contrato AND C.IdCia = D.IdCia
				LEFT JOIN  Trn_TraEspOtroSiContratos OSC ON OSC.IdOtroSi = @IdOtroSi AND D.TipDoc = OSC.TipDocCnt AND OSC.Contrato = D.Contrato AND OSC.IdCiaCnt = D.IdCia
				Where D.IdOtroSi = @IdOtroSi 
				--Anula los Ã­tems de OtroSÃ­
				UPDATE Trn_TraEspContratoDet
				SET ItemAnuladoOS = 1, VrUnitario = 0, VrDia = 0, DiasDisp = 0,  VrMonitor = 0, CantMonitor = 0 WHERE IdOtroSi = @IdOtroSi
				  ------------------------------------
			END

			SELECT @IdOtroSi

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPasajeros]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPasajeros]
	@Trn_TraEspPasajeros [dbo].[dataTypeTrn_TraEspPasajeros] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Numero INT --Esta variable guarda el nÃºmero de consecutivo de la lista

	BEGIN TRAN
		BEGIN TRY

			--IF(@operacion = 'i')
			--BEGIN
			--	SELECT @Numero = ISNULL(MAX(IdLista),0) + 1  FROM Trn_TraEspListaPasajeros
			--END

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			   IF(EXISTS(SELECT * FROM @Trn_TraEspPasajeros))
			   begin
			   UPDATE Trn_TraEspPasajeros
			   SET 
			   TipId = t2.TipId,Documento = t2.Documento,Apellidos = t2.Apellidos,
			   Nombres = t2.Nombres,Cargo = t2.Cargo,EsMonitor = t2.EsMonitor,
			   Telefono = t2.Telefono,Observacion = t2.Observacion,
			   EsEstudiante = t2.EsEstudiante,IdResponsable = t2.IdResponsable,
			   Porcentaje = t2.Porcentaje,VrPago = t2.VrPago,IdColegio = t2.IdColegio,
			   CdEstudiante = t2.CdEstudiante,Jornada = t2.Jornada,Sede = t2.Sede,Inactivo = t2.Inactivo,
			   FechaNac = t2.FechaNac, IncluirPeriodo = t2.IncluirPeriodo
			   FROM Trn_TraEspPasajeros t1
			   JOIN @Trn_TraEspPasajeros t2 ON t1.TipId = t2.TipId and t1.Documento = t2.Documento
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspPasajeros(
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				)
				SELECT 
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				FROM @Trn_TraEspPasajeros
				WHERE (Documento) NOT IN(SELECT (Documento) FROM Trn_TraEspPasajeros)
			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			BEGIN
				IF(EXISTS(SELECT * FROM @Trn_TraEspPasajeros))
				begin
				INSERT INTO Trn_TraEspPasajeros(
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				)
				SELECT 
				TipId,Documento,Apellidos,Nombres,Cargo,EsMonitor,Telefono,Observacion,
				EsEstudiante,IdResponsable,Porcentaje,VrPago,IdColegio,CdEstudiante,
				Jornada,Sede,Inactivo,FechaNac,IncluirPeriodo
				FROM @Trn_TraEspPasajeros
				WHERE (Documento) NOT IN(SELECT (Documento) FROM Trn_TraEspPasajeros)
				end					
			END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			  DELETE FROM Trn_TraEspPasajeros WHERE Documento = (select Documento from @Trn_TraEspPasajeros)
			END

			SELECT '1'

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPedido]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPedido]
	@Trn_TraEspPedido [dbo].[dataTypeTrn_TraEspPedido] READONLY,
	@Trn_TraEspPedAnexo [dbo].[dataTypeTrn_TraEspPedAnexo] READONLY,
	@Trn_TraEspPedDetalle [dbo].[dataTypeTrn_TraEspPedDetalle] READONLY,
	@Trn_TraEspConceptos [dbo].[dataTypeTrn_TraEspConceptos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Pedido/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Pedido/CotizaciÃ³n
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Pedido/CotizaciÃ³n
declare @item int
	BEGIN TRAN
		BEGIN TRY

			--Seleccionar Variables
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia FROM @Trn_TraEspPedido
				SELECT @Documento = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

				IF(@Documento <> '')
					UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
				ELSE
				BEGIN
					SELECT @Documento = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			end

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			   if(EXISTS(SELECT * FROM @Trn_TraEspPedido))
			   begin
			   UPDATE Trn_TraEspPedido
			   SET 
			   TipDoc = t2.TipDoc,Pedido = t2.Pedido,IdCia = t2.IdCia,Fecha = t2.Fecha,FechaVence = t2.FechaVence,
			   FecInicio = t2.FecInicio,FecFinal = t2.FecFinal,IdCliente = t2.IdCliente,IdAgencia = t2.IdAgencia,
			   IdVend = t2.IdVend,IdTarifCom = t2.IdTarifCom,TipoContrato = t2.TipoContrato,TipoPago = t2.TipoPago,
			   Modalidad = t2.Modalidad,Vigencia = t2.Vigencia,VrCobro = t2.VrCobro,VrPagos = t2.VrPagos,VrCargos = t2.VrCargos,
			   VrDctos = t2.VrDctos,VrIva = t2.VrIva,CdDescuento = t2.CdDescuento,Presupuesto = t2.Presupuesto,
			   CantPasajeros = t2.CantPasajeros,Cantidad = t2.Cantidad,Peso = t2.Peso,IdMneda = t2.IdMneda,
			   NumAprob = t2.NumAprob,IdCiaApr = t2.IdCiaApr,
			   FecAprob = t2.FecAprob,EsLicitacion = t2.EsLicitacion,OrigenAdd = t2.OrigenAdd,Anulado = t2.Anulado,
			   FecDev = t2.FecDev,Observacion = t2.Observacion,IdEstado = t2.IdEstado,TimeSys = t2.TimeSys,FecUpdate = t2.FecUpdate,
			   IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario,CdCarga = t2.CdCarga,VrEditado = t2.VrEditado,CantDias = t2.CantDias
		       FROM Trn_TraEspPedido t1
			   JOIN @Trn_TraEspPedido t2 ON t1.TipDoc = t2.TipDoc and t1.Pedido = t2.Pedido and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspPedAnexo))
			   begin
			   UPDATE Trn_TraEspPedAnexo
			   SET 
			   TipDoc = t2.TipDoc,Pedido = t2.Pedido,IdCia = t2.IdCia,NomCliente = t2.NomCliente,DirCliente = t2.DirCliente,
			   NomContacto = t2.NomContacto,TelContacto = t2.TelContacto,emlContacto = t2.emlContacto,emlCliente = t2.emlCliente,
			   DescripCarga = t2.DescripCarga,Clausulas = t2.Clausulas
		       FROM Trn_TraEspPedAnexo t1
			   JOIN @Trn_TraEspPedAnexo t2 ON t1.TipDoc = t2.TipDoc and t1.Pedido = t2.Pedido and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspPedDetalle))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Pedido FROM @Trn_TraEspPedDetalle
			   select @item =  isnull(MAX(Item),0) from Trn_TraEspPedDetalle where TipDoc = @TipDoc and Pedido = @Documento and IdCia = @IdCia

			   --actualizar los que vienen en el tipo de dato y coincidan con los que ya estan en la tabla
			   UPDATE Trn_TraEspPedDetalle
			   SET 
			   TipDoc = t2.TipDoc,Pedido = t2.Pedido,IdCia = t2.IdCia,Item = t2.Item,CdTipVeh = t2.CdTipVeh,NumPasajeros = t2.NumPasajeros,
			   Parada = t2.Parada,PesoNeto = t2.PesoNeto,VrUnitario = t2.VrUnitario,IdRuta = t2.IdRuta,Referencia1 = t2.Referencia1,
			   Referencia2 = t2.Referencia2,Referencia3 = t2.Referencia3,EsRutaCliente = t2.EsRutaCliente,CdCiuOrigen = t2.CdCiuOrigen,
			   DirOrigen = t2.DirOrigen,FecOrigen = t2.FecOrigen,CdCiuDestino = t2.CdCiuDestino,DirDestino = t2.DirDestino,FecDestino = t2.FecDestino,
			   CdTipRuta = t2.CdTipRuta,CdTipServicio = t2.CdTipServicio,DiasDisp = t2.DiasDisp,VrDia = t2.VrDia,
			   TipCtn=t2.TipCtn,NumCnt=t2.NumCnt,IdCiaCnt=t2.IdCiaCnt,ItemCnt=t2.ItemCnt, CantVeh=t2.CantVeh,Retorno=t2.Retorno
			   ,VrMonitor = t2.VrMonitor,CantMonitor=t2.CantMonitor,TipoTarifa=t2.TipoTarifa,Dias = t2.Dias,Itinerario = t2.Itinerario,VLargo = t2.VLargo
			   ,ItemPpalRet = t2.ItemPpalRet,CiaPpalRet = t2.CiaPpalRet,VrPago = t2.VrPago
		       FROM Trn_TraEspPedDetalle t1
			   JOIN @Trn_TraEspPedDetalle t2 ON t1.TipDoc = t2.TipDoc and t1.Pedido = t2.Pedido and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Pedido = t2.Pedido and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspPedDetalle(
				TipDoc,Pedido,IdCia,Item,CdTipVeh,NumPasajeros,Parada,PesoNeto,VrUnitario,IdRuta,Referencia1,Referencia2,
				Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,CdTipRuta,
				CdTipServicio,DiasDisp,VrDia,TipCtn,NumCnt,IdCiaCnt,ItemCnt,CantVeh,Retorno,VrMonitor,CantMonitor,TipoTarifa,Dias,Itinerario,
				VLargo,ItemPpalRet,CiaPpalRet,VrPago) 
				SELECT 
				@TipDoc,@Documento,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)),CdTipVeh,NumPasajeros,Parada,PesoNeto,VrUnitario,IdRuta,Referencia1,Referencia2,
				Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,CdTipRuta,
				CdTipServicio,DiasDisp,VrDia,TipCtn,NumCnt,IdCiaCnt,ItemCnt,CantVeh,Retorno,VrMonitor,CantMonitor,TipoTarifa,Dias,Itinerario,
				VLargo,ItemPpalRet,CiaPpalRet,VrPago
				FROM @Trn_TraEspPedDetalle
				WHERE (TipDoc + Convert(varchar,Pedido)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Pedido)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspPedDetalle)
			   --Eliminar los que no existen en lo que envian
			   delete from Trn_TraEspPedDetalle
			   WHERE TipDoc = @TipDoc and Pedido = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @Trn_TraEspPedDetalle)

			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Documento FROM @Trn_TraEspConceptos
			   select @item =  isnull(MAX(Item),0) from Trn_TraEspConceptos where TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia

			   --actualizar los que vienen en el tipo de dato y coincidan con los que ya estan en la tabla
			   UPDATE Trn_TraEspConceptos
			   SET 
			   TipDoc = t2.TipDoc,Documento = t2.Documento,IdCia = t2.IdCia,Item = t2.Item,
			   Descripcion = t2.Descripcion,Tarifa = t2.Tarifa,TipoConc = t2.TipoConc,
			   RubroConcep = t2.RubroConcep,Cantidad = t2.Cantidad,VrUnitario = t2.VrUnitario,
			   TarifIva = t2.TarifIva,IdConcepto = t2.IdConcepto,CdCuenta = t2.CdCuenta,
			   NitTercero = t2.NitTercero,CdTipoEsc = t2.CdTipoEsc,FechaNov = t2.FechaNov,
			   VrBase = t2.VrBase,TipoTarif = t2.TipoTarif,RefConc = t2.RefConc,Fijos = t2.Fijos,
			   IncBaseRet = t2.IncBaseRet,Referencia2 = t2.Referencia2,Referencia3 = t2.Referencia3,
			   Cliente = t2.Cliente,Conductor = t2.Conductor,Vehiculo=t2.Vehiculo,ItemDoc=t2.ItemDoc,
			   IdVehiculo = t2.IdVehiculo
		       FROM Trn_TraEspConceptos t1
			   JOIN @Trn_TraEspConceptos t2 ON t1.TipDoc = t2.TipDoc and t1.Documento = t2.Documento and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Documento = t2.Documento and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspConceptos(
			    TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo)
			   SELECT 
			    @TipDoc, @Documento, @IdCia, (@Item + ROW_NUMBER() OVER(ORDER BY Item ASC)), Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
			   FROM @Trn_TraEspConceptos
			   WHERE (TipDoc + Convert(varchar,Documento)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Documento)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspConceptos)
			   --Eliminar los que no existen en el tipo de dato
			   delete from Trn_TraEspConceptos
			   WHERE TipDoc = @TipDoc and Documento = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @Trn_TraEspConceptos)

			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN

				IF(EXISTS(SELECT * FROM @Trn_TraEspPedido))
				begin
				INSERT INTO Trn_TraEspPedido(
				TipDoc,Pedido,IdCia,Fecha,FechaVence,FecInicio,FecFinal,IdCliente,IdAgencia,IdVend,
				IdTarifCom,TipoContrato,TipoPago,Modalidad,Vigencia,VrCobro,VrPagos,VrCargos,VrDctos,
				VrIva,CdDescuento,Presupuesto,CantPasajeros,Cantidad,Peso,IdMneda,
				NumAprob,IdCiaApr,FecAprob,EsLicitacion,OrigenAdd,Anulado,FecDev,Observacion,
				IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdCarga,VrEditado,CantDias
				)
				SELECT 
				@TipDoc,@Documento,@IdCia,Fecha,FechaVence,FecInicio,FecFinal,IdCliente,IdAgencia,IdVend,
				IdTarifCom,TipoContrato,TipoPago,Modalidad,Vigencia,VrCobro,VrPagos,VrCargos,VrDctos,
				VrIva,CdDescuento,Presupuesto,CantPasajeros,Cantidad,Peso,IdMneda,
				NumAprob,IdCiaApr,FecAprob,EsLicitacion,OrigenAdd,Anulado,FecDev,Observacion,
				IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario,CdCarga,VrEditado,CantDias
				FROM @Trn_TraEspPedido
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspPedAnexo))
				begin
				INSERT INTO Trn_TraEspPedAnexo(
				TipDoc,Pedido,IdCia,NomCliente,DirCliente,NomContacto,TelContacto,emlContacto,emlCliente,DescripCarga,Clausulas
				) 
				SELECT 
				@TipDoc, @Documento, @IdCia,NomCliente,DirCliente,NomContacto,TelContacto,emlContacto,emlCliente,DescripCarga,Clausulas
				FROM @Trn_TraEspPedAnexo
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspPedDetalle))
				begin
				INSERT INTO Trn_TraEspPedDetalle(
				TipDoc,Pedido,IdCia,Item,CdTipVeh,NumPasajeros,Parada,PesoNeto,VrUnitario,IdRuta,Referencia1,Referencia2,
				Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,CdTipRuta,
				CdTipServicio,DiasDisp,VrDia,TipCtn,NumCnt,IdCiaCnt,ItemCnt,CantVeh,Retorno,VrMonitor,CantMonitor,TipoTarifa,Dias,Itinerario,VLargo
				,ItemPpalRet,CiaPpalRet,VrPago
				) 
				SELECT 
				@TipDoc,@Documento,@IdCia,Item,CdTipVeh,NumPasajeros,Parada,PesoNeto,VrUnitario,IdRuta,Referencia1,Referencia2,
				Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,CdTipRuta,
				CdTipServicio,DiasDisp,VrDia,TipCtn,NumCnt,IdCiaCnt,ItemCnt,CantVeh,Retorno,VrMonitor,CantMonitor,TipoTarifa,Dias,Itinerario,VLargo
				,ItemPpalRet,CiaPpalRet,VrPago
				FROM @Trn_TraEspPedDetalle
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspConceptos))
				BEGIN
				INSERT INTO Trn_TraEspConceptos(
				TipDoc, Documento, IdCia, Item, Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
				) 
				SELECT 
				@TipDoc, @Documento, @IdCia, Item, Descripcion, Tarifa, 
				TipoConc, RubroConcep, Cantidad, VrUnitario, TarifIva, IdConcepto, 
				CdCuenta, NitTercero, CdTipoEsc, FechaNov, VrBase,TipoTarif,RefConc,Fijos,
				Referencia2, Referencia3,Cliente,Conductor,Vehiculo,ItemDoc,IdVehiculo
				FROM @Trn_TraEspConceptos
				END

			 END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 declare @Pedido int
			 select @TipDoc = TipDoc, @IdCia = IdCia,  @Pedido = Pedido from @Trn_TraEspPedido
				 DELETE FROM Trn_TraEspPedAnexo WHERE TipDoc = @TipDoc and Pedido = @Pedido and IdCia = @IdCia
				 DELETE FROM Trn_TraEspPedDetalle WHERE TipDoc = @TipDoc and Pedido = @Pedido and IdCia = @IdCia
				 DELETE FROM Trn_TraEspConceptos WHERE TipDoc = @TipDoc and Documento = @Pedido and IdCia = @IdCia
				 DELETE FROM Trn_TraEspPedido WHERE TipDoc = @TipDoc and Pedido = @Pedido and IdCia = @IdCia
			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
			  declare @IdEstado varchar(4)
			  --select @IdEstado = IdEstado from EstadoDoc where Estado = 'ANULADO'
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Pedido from @Trn_TraEspPedido
			  UPDATE Trn_TraEspPedido SET IdEstado = '9999', Anulado = '1' WHERE TipDoc = @TipDoc and Pedido = @Documento and IdCia = @IdCia
			END

			SELECT @Documento

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPicoPlaca]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPicoPlaca]
	@Trn_TraEspPicoPlaca [dbo].[dataTypeTrn_TraEspPicoPlaca] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Trn_TraEspPicoPlaca
			 SET 
			 IdLocal = t2.IdLocal,Fecha = t2.Fecha, UltimoDig = t2.UltimoDig,Observacion = t2.Observacion,
			 ClaseMat = t2.ClaseMat,IdTipoVeh = t2.IdTipoVeh,Horas = t2.Horas
		     FROM Trn_TraEspPicoPlaca t1
			 JOIN @Trn_TraEspPicoPlaca t2 ON t1.Idlocal = t2.IdLocal and t1.Fecha = t2.Fecha and t1.ClaseMat = t2.ClaseMat and t1.IdTipoVeh = t2.IdTipoVeh and t1.Horas = t2.Horas
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Trn_TraEspPicoPlaca(
			 IdLocal,Fecha,UltimoDig,Observacion,ClaseMat,IdTipoVeh,Horas
			 )
			 SELECT 
			 IdLocal,Fecha,UltimoDig,Observacion,ClaseMat,IdTipoVeh,Horas
			 FROM @Trn_TraEspPicoPlaca
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DELETE FROM Trn_TraEspPicoPlaca 
			 WHERE IdLocal = (select IdLocal from @Trn_TraEspPicoPlaca) 
			 and Fecha = (select Fecha from @Trn_TraEspPicoPlaca) 
			 and ClaseMat = (select ClaseMat from @Trn_TraEspPicoPlaca) 
			 and IdTipoVeh = (select IdTipoVeh from @Trn_TraEspPicoPlaca) 
			 and Horas = (select Horas from @Trn_TraEspPicoPlaca) 
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspPrograma]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspPrograma]
	@Trn_TraEspPrograma [dbo].[dataTypeTrn_TraEspPrograma] READONLY,
	@Trn_TraEspProgramaDet [dbo].[dataTypeTrn_TraEspProgramaDet] READONLY,
	@Trn_TraEspProgramaPers [dbo].[dataTypeTrn_TraEspProgramaPers] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Reserva/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Reserva/CotizaciÃ³n
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Reserva/CotizaciÃ³n
declare @IdEstado varchar(4)
declare @item int 
declare @kmp varchar 
	BEGIN TRAN
		BEGIN TRY

			--Seleccionar Variables
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia FROM @Trn_TraEspPrograma
				SELECT @Documento = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

				IF(@Documento <> '')
					UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
				ELSE
				BEGIN
					SELECT @Documento = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			end

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			   IF(EXISTS(SELECT * FROM @Trn_TraEspPrograma))
			   begin
			   UPDATE Trn_TraEspPrograma
			   SET 
			   TipDoc = t2.TipDoc,Programa = t2.Programa,IdCia = t2.IdCia,
			   Fecha = t2.Fecha,OrigenAdd = t2.OrigenAdd,Anulado = t2.Anulado,
			   FecDev = t2.FecDev,IdEstado = t2.IdEstado,TimeSys = t2.TimeSys,
			   FecUpdate = t2.FecUpdate,IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario
		       FROM Trn_TraEspPrograma t1
			   JOIN @Trn_TraEspPrograma t2 ON t1.TipDoc = t2.TipDoc and t1.Programa = t2.Programa and t1.IdCia = t2.IdCia
			   end

			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Programa FROM @Trn_TraEspProgramaDet
			   select @item =  isnull(MAX(Item),0) from Trn_TraEspProgramaDet where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia

			   --se actuallizan los que vienen en el tipo de dato y coincidan con los que estan el la tabla
			   UPDATE Trn_TraEspProgramaDet
			   SET 
			   TipDoc = t2.TipDoc,Programa = t2.Programa,IdCia = t2.IdCia,Item = t2.Item,
			   FechaInicio = t2.FechaInicio,FechaFin = t2.FechaFin,TipDocRes = t2.TipDocRes,
			   Reserva = t2.Reserva,IdCiaRes = t2.IdCiaRes,ItemRes = t2.ItemRes,IdOrigen = t2.IdOrigen,
			   IdDestino = t2.IdDestino,IdVehiculo = t2.IdVehiculo,
			   CdTipVeh = t2.CdTipVeh,IdConductor = t2.IdConductor,NumPasajeros = t2.NumPasajeros,TipDocFuec = t2.TipDocFuec,
			   NumFuec = t2.NumFuec,IdCiaFuec = t2.IdCiaFuec,TipDocOdp = t2.TipDocOdp,NumOdp = t2.NumOdp,
			   IdCiaOdp = t2.IdCiaOdp,FechaOdp=t2.FechaOdp,IdNovedad = t2.IdNovedad,Novedad = t2.Novedad,Cumplido = t2.Cumplido,FecIniCump = t2.FecIniCump, FecFinCump = t2.FecFinCump,
			   VrCobro = t2.VrCobro, VrPagos = t2.VrPagos,DiasDisp= t2.DiasDisp,Parada= t2.Parada,CdTipServicio= t2.CdTipServicio,
			   DirOrigen= t2.DirOrigen,DirDestino= t2.DirDestino,IdRuta= t2.IdRuta,CdTipRuta= t2.CdTipRuta,PesoNeto= t2.PesoNeto,EstadoItem=t2.EstadoItem,
			   VrMonitor=t2.VrMonitor,CantMonitor=t2.CantMonitor,VrRecorrido= t2.VrRecorrido, Observacion= t2.Observacion,VLargo = t2.VLargo
		       FROM Trn_TraEspProgramaDet t1
			   JOIN @Trn_TraEspProgramaDet t2 ON t1.TipDoc = t2.TipDoc and t1.Programa = t2.Programa and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Programa = t2.Programa and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspProgramaDet(
			   TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			   IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			   IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
			   CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
	           ) 
			   SELECT 
			   @TipDoc,@Documento,@IdCia,(@item + ROW_NUMBER() OVER(ORDER BY Item ASC)),FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			   IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			   IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
			   CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
			   FROM @Trn_TraEspProgramaDet
			   WHERE (TipDoc + Convert(varchar,Programa)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Programa)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspProgramaDet)
			    
			   --Actualizar estado de vehiculo CUANDO NO TIENE NOVEDAD
			   UPDATE Vehiculos
			   SET IdEstado = '0002'
			   FROM Vehiculos v
			   JOIN (SELECT DISTINCT IdVehiculo FROM @Trn_TraEspProgramaDet where IdNovedad = '0' and Cumplido = 0) AS pd ON v.IdVehiculo = pd.IdVehiculo 
			   WHERE v.IdVehiculo = pd.IdVehiculo 


			   --Actualizar estado de vehiculo CUANDO TENGA NOVEDAD DE TIPO VEHICULO
			   ----DECLARE @IDNOV VARCHAR(4)
			   ----SELECT @IDNOV = IdNovedad FROM @Trn_TraEspProgramaDet
			   ----IF(UPPER((select Tipo from TiposNovPgr where IdNovedad = @IDNOV)) = 'VEHICULO')
			   ----BEGIN
				  ---- UPDATE Vehiculos
				  ---- SET IdEstado = (select IdEstado from TiposNovPgr where IdNovedad = pd.IdNovedad and Tipo = 'VEHICULO')
				  ---- FROM Vehiculos v
				  ---- JOIN @Trn_TraEspProgramaDet pd ON v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad != '0' and pd.Cumplido = 0
				  ---- WHERE v.IdVehiculo = pd.IdVehiculo 
			   ----END

			   --se cambia el cursor de Joe el dÃ­a 25 de octubre porque demoraba la actualizaciÃ³n, cuando la prograamciÃ³nn tiene muchos Ã­tems, cambio opr JohnRoa-------
				--   declare @acveh varchar(11)
				--   declare @acidnov varchar(4)
				----declare @acItem int
				
				--DECLARE acvehic CURSOR
				--FOR SELECT IdVehiculo,IdNovedad FROM @Trn_TraEspProgramaDet where IdNovedad != '0' and Cumplido = 0
				--OPEN acvehic
				--FETCH NEXT FROM acvehic INTO @acveh,@acidnov
				--WHILE @@FETCH_STATUS = 0
				--BEGIN
				--   UPDATE Vehiculos
				--   SET IdEstado = tn.IdEstado
				--   FROM Vehiculos v, TiposNovPgr tn
				--   WHERE v.IdVehiculo = @acveh and tn.IdNovedad = @acidnov and tn.Tipo = 'VEHICULO'
				--FETCH NEXT FROM acvehic INTO @acveh,@acidnov
				--END
				--CLOSE acvehic
				--DEALLOCATE acvehic
				-------------------------------------------------------------John Roa --------------------------------------------------------------------------
				-----------------------------------Esto reemplaza al cursor anterior----------------------------------------------------------------------------
				--UPDATE Vehiculos
				--SET IdEstado = tn.IdEstado
				--FROM Vehiculos v
				--JOIN @Trn_TraEspProgramaDet pd ON v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad != '0' and pd.Cumplido = 0
				--JOIN TiposNovPgr AS tn ON tn.IdNovedad = pd.IdNovedad and tn.Tipo = 'VEHICULO'
				--WHERE v.IdVehiculo = pd.IdVehiculo

				UPDATE Vehiculos
				SET IdEstado = tn.IdEstado
				FROM Vehiculos v
				JOIN (SELECT DISTINCT IdVehiculo, IdNovedad FROM @Trn_TraEspProgramaDet WHERE  IdNovedad != '0' and Cumplido = 0) AS pd ON v.IdVehiculo = pd.IdVehiculo 
				JOIN TiposNovPgr AS tn ON tn.IdNovedad = pd.IdNovedad and tn.Tipo = 'VEHICULO'
				WHERE v.IdVehiculo = pd.IdVehiculo
				-------------------------------------------------------------------------------------------------------------------------------------------------
			   --ACTUALIZAR RESERVAS 
			   ----UPDATE Trn_TraEspResDetalle
			   ----SET EstadoItem = 'PROGRAMADA'
			   ----FROM Trn_TraEspResDetalle p
			   ----JOIN @Trn_TraEspProgramaDet d ON p.TipDoc = d.TipDocRes  and p.Reserva = d.Reserva and p.IdCia = d.IdCiaRes and p.Item = d.ItemRes
			   ----WHERE d.TipDoc = @TipDoc and d.Programa = @Documento and d.IdCia = @IdCia and d.IdNovedad = '0' and d.Cumplido = 0

			   	--se cambia el cursor de Joe el dÃ­a 25 de octubre porque demoraba la actualizaciÃ³n, cuando la prograamciÃ³nn tiene muchos Ã­tems, cambio opr JohnRoa-------
			 --  	declare @acReserva int
				--declare @acCiaRes varchar(2)
				--declare @acItem int
				
				--DECLARE acres CURSOR
				--FOR SELECT Reserva,IdCiaRes,ItemRes FROM @Trn_TraEspProgramaDet where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and IdNovedad = '0' and Cumplido = 0
				--OPEN acres
				--FETCH NEXT FROM acres INTO @acReserva,@acCiaRes,@acItem
				--WHILE @@FETCH_STATUS = 0
				--BEGIN
				--	UPDATE Trn_TraEspResDetalle
				--	SET EstadoItem = 'PROGRAMADA'
				--	FROM Trn_TraEspResDetalle p
				--	WHERE  p.TipDoc = 'RES' and p.Reserva = @acReserva and p.IdCia = @acCiaRes and p.Item = @acItem
				--	-- Fecha:20/11/2017 Se desactiva esta condiciÃ³n porque al entrar 2 usuarios a hacer la misma operaciÃ³n queda desactualizado 
				--	-- el nÃºmero de consecutivo que se obtiene en el software y se actualizarÃ­a reservas del primera operaciÃ³n, en este caso, quedarÃ­a mal para la segunada transacciÃ³n.
				--	--WHERE d.TipDoc = @TipDoc and d.Programa = @Documento and d.IdCia = @IdCia
				--FETCH NEXT FROM acres INTO @acReserva,@acCiaRes,@acItem
				--END
				--CLOSE acres
				--DEALLOCATE acres
				-------------------------------------------------------------John Roa --------------------------------------------------------------------------
				-----------------------------------Esto reemplaza al cursor anterior----------------------------------------------------------------------------
				--UPDATE p
				--SET p.EstadoItem = 'PROGRAMADA'
				--FROM Trn_TraEspResDetalle p
				--JOIN @Trn_TraEspProgramaDet pd ON p.TipDoc = pd.TipDocRes and p.IdCia = pd.IdCiaRes and p.Item = pd.ItemRes
				--WHERE  p.TipDoc = 'RES' and p.Reserva = pd.Reserva and p.IdCia = pd.IdCiaRes and p.Item = pd.ItemRes

				UPDATE p
				SET p.EstadoItem = 'PROGRAMADA'
				FROM (SELECT DISTINCT TipDocRes, Reserva, IdCiaRes, ItemRes FROM @Trn_TraEspProgramaDet where IdNovedad = '0' and Cumplido = 0) AS pd 
				JOIN  Trn_TraEspResDetalle p ON p.TipDoc = pd.TipDocRes and p.Reserva = pd.Reserva and p.IdCia = pd.IdCiaRes and p.Item = pd.ItemRes
				WHERE  p.TipDoc = 'RES' and p.Reserva = pd.Reserva and p.IdCia = pd.IdCiaRes and p.Item = pd.ItemRes 
				------------------------------------------------------------------------------------------------------------------------------------------------

			   --ACTUALIZAR Vehiculos en ProgramaPers 
			   UPDATE Trn_TraEspProgramaPers
			   SET IdVehiculo = d.IdVehiculo
			   FROM Trn_TraEspProgramaPers p
			   JOIN @Trn_TraEspProgramaDet d ON p.TipDoc = d.TipDoc  and p.Programa = d.Programa and p.IdCia = d.IdCia and p.Item = d.Item
			   WHERE p.TipDoc = d.TipDoc and p.Programa = d.Programa and p.IdCia = d.IdCia and p.Item= d.Item and d.IdNovedad = '0' and d.Cumplido = 0

			   end

			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaPers))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Programa, @item = Item FROM @Trn_TraEspProgramaPers
			
			  --Eliminar los registros
			   delete from Trn_TraEspProgramaPers where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and Item = @item 
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspProgramaPers(
			   TipDoc,Programa,IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
	           ) 
			   SELECT 
			   @TipDoc,@Documento,@IdCia,@item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
			   FROM @Trn_TraEspProgramaPers
			   			   
			   end

			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN

				IF(EXISTS(SELECT * FROM @Trn_TraEspPrograma))
				begin
				INSERT INTO Trn_TraEspPrograma(
				TipDoc,Programa,IdCia,Fecha,OrigenAdd,Anulado,FecDev,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				)
				SELECT 
				@TipDoc,@Documento,@IdCia,Fecha,OrigenAdd,Anulado,FecDev,IdEstado,TimeSys,FecUpdate,IdCiaCrea,IdUsuario
				FROM @Trn_TraEspPrograma
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
				begin
				INSERT INTO Trn_TraEspProgramaDet(
			    TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			    IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			    IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
				CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
				) 
			    SELECT 
			    @TipDoc,@Documento,@IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			    IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			    IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
				CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
			    FROM @Trn_TraEspProgramaDet
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaPers))
				begin
				INSERT INTO Trn_TraEspProgramaPers(
			    TipDoc,Programa,IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
				) 
			    SELECT 
			    @TipDoc,@Documento,@IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
			    FROM @Trn_TraEspProgramaPers
				end

				--ACTUALIZAR VEHICULOS 
				UPDATE Vehiculos
				SET IdEstado = '0002'
				FROM Vehiculos v
				JOIN @Trn_TraEspProgramaDet pd ON v.IdVehiculo = pd.IdVehiculo 
				WHERE v.IdVehiculo = pd.IdVehiculo --AND pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia

				--ACTUALIZAR RESERVAS 
				declare @actReserva int
				declare @actCiaRes varchar(2)
				declare @actItem int
				
				DECLARE actres CURSOR
				FOR SELECT Reserva,IdCiaRes,ItemRes FROM @Trn_TraEspProgramaDet
				OPEN actres
				FETCH NEXT FROM actres INTO @actReserva,@actCiaRes,@actItem
				WHILE @@FETCH_STATUS = 0
				BEGIN
					UPDATE Trn_TraEspResDetalle
					SET EstadoItem = 'PROGRAMADA'
					FROM Trn_TraEspResDetalle p
					WHERE  p.TipDoc = 'RES' and p.Reserva = @actReserva and p.IdCia = @actCiaRes and p.Item = @actItem
					-- Fecha:20/11/2017 Se desactiva esta condiciÃ³n porque al entrar 2 usuarios a hacer la misma operaciÃ³n queda desactualizado 
					-- el nÃºmero de consecutivo que se obtiene en el software y se actualizarÃ­a reservas del primera operaciÃ³n, en este caso, quedarÃ­a mal para la segunada transacciÃ³n.
					--WHERE d.TipDoc = @TipDoc and d.Programa = @Documento and d.IdCia = @IdCia
				FETCH NEXT FROM actres INTO @actReserva,@actCiaRes,@actItem
				END
				CLOSE actres
				DEALLOCATE actres

			 END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 declare @Programa int
			 select @TipDoc = TipDoc, @IdCia = IdCia,  @Programa = Programa from @Trn_TraEspPrograma
			 DELETE FROM Trn_TraEspProgramaPers WHERE TipDoc = @TipDoc and Programa = @Programa and IdCia = @IdCia
			 DELETE FROM Trn_TraEspProgramaDet WHERE TipDoc = @TipDoc and Programa = @Programa and IdCia = @IdCia
			 DELETE FROM Trn_TraEspPrograma WHERE TipDoc = @TipDoc and Programa = @Programa and IdCia = @IdCia
			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
			  --select @IdEstado = IdEstado from EstadoDoc where Estado = 'ANULADO'
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Programa from @Trn_TraEspPrograma
			  UPDATE Trn_TraEspPrograma SET IdEstado = '9999',Anulado = '1' WHERE TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia

			  --ACTUALIZAR VEHICULOS 
			  UPDATE Vehiculos
			  SET IdEstado = '0001'
			  FROM Vehiculos v
			  JOIN Trn_TraEspProgramaDet pd ON v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad = '0'
			  WHERE v.IdVehiculo = pd.IdVehiculo AND pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia

			  -- --ACTUALIZAR Reservas 
			  --UPDATE Trn_TraEspResDetalle
			  --SET 
			  --FROM Trn_TraEspResDetalle rd
			  --JOIN Trn_TraEspProgramaDet pd ON pd.TipDocRes = rd.TipDoc and rd.Reserva = pd.Reserva and pd.IdCiaRes = rd.IdCia
			  ----WHERE v.IdVehiculo = pd.IdVehiculo AND pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia
			END

			--CERRAR PROGRAMACIÃ“N
			IF(@operacion = 'c')
			BEGIN
			  DECLARE @cFechaProg date
			  DECLARE @cthirtydaysago DATE
			  declare @date date
			  select @date = Convert(date, getdate())
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Programa, @cFechaProg= FECHA from @Trn_TraEspPrograma
			  SET @cthirtydaysago = DATEADD(DAY,-30,@cFechaProg)

			  ------------------------------------------------------- Inicio SecciÃ³n para VIAJES NO LARGOS / VIAJES LARGOS-------------------------------------------
			  ------------------------------------------------------- Inicio SecciÃ³n para verificacion de TiposCalendarPgr y lo de Incluir Festivos -------------------------------------------
			  --Actualizar las reservasdet al estado XLIQUIDAR, cuando tienen tiposcalendarpgr
			  --verficar que el dia se encuentre en tiposcalendarpgr a travÃ©s de una funcion sql
			  --VERIFICAR SI LA SIGUIENTE PROGRAMACION ES IGUAL A LA FECHA FINAL Y SI ESTA ES FESTIVA(VERIFICAR SI ESTA INCLUIDO EL FESTIVO EN TIPOSCALENDARPGR)
			  
			  DECLARE @Trn_TraEspProgramaDet2 dataTypeTrn_TraEspProgramaDet	  
			  INSERT INTO @Trn_TraEspProgramaDet2(
			  TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
			  CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
			  ) 
			  select 
			  V.TipDoc,V.Programa,V.IdCia,V.Item,FechaInicio,FechaFin,TipDocRes,V.Reserva,IdCiaRes,ItemRes,
			  IdOrigen,IdDestino,V.IdVehiculo,V.CdTipVeh,V.IdConductor,V.NumPasajeros,TipDocFuec,NumFuec,
			  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,V.Cumplido,FecIniCump,FecFinCump,
			  V.VrCobro,V.VrPagos,V.DiasDisp,V.Parada,V.CdTipServicio,V.DirOrigen,V.DirDestino,V.IdRuta,V.CdTipRuta,
			  V.PesoNeto,V.EstadoItem,V.VrMonitor,V.CantMonitor,V.VrRecorrido,Observacion,V.VLargo		
			  FROM Trn_TraEspProgramaDet  v 
			  --from 
			  --(
				 -- SELECT 
				 -- TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
				 -- IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
				 -- IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
				 -- CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
				 -- FROM Trn_TraEspProgramaDet  where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and VLargo = 0 and IdNovedad = 0
				  --UNION
				  --SELECT 
				  --TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
				  --IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
				  --IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
				  --CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
				  --FROM Trn_TraEspProgramaDet d where  d.VLargo = 1 and D.IdNovedad = '0' and (Convert(DATE,d.FechaFin) BETWEEN @cthirtydaysago and @cFechaProg)
			  --) as v 
			  JOIN Trn_TraEspResDetalle t2 ON t2.TipDoc = V.TipDocRes and t2.Reserva = V.Reserva and t2.IdCia = V.IdCiaRes and t2.Item = V.ItemRes and (t2.EstadoItem ='PROGRAMADA' or (t2.EstadoItem = 'FACTURADA' and t2.Factura > 0))
			  --04/07/2018 - 05/07/2018 Se cambia el Join(Abajo por el de Arriba) para tener en cuenta aquellas reservas que se facturan antes de Cerrar las Programaciones
			  --JOIN Trn_TraEspResDetalle t2 ON t2.TipDoc = V.TipDocRes and t2.Reserva = V.Reserva and t2.IdCia = V.IdCiaRes and t2.Item = V.ItemRes and t2.EstadoItem = 'PROGRAMADA'
			  WHERE v.TipDoc = @TipDoc and v.Programa = @Documento and v.IdCia = @IdCia and v.VLargo = 0 and v.IdNovedad = 0 and (Convert(DATE,@date) >= Convert(DATE,t2.FecDestino))

			  declare @xlqTipDoc varchar(3),@xlqTipDocRes varchar(3), @xlqPrograma int, @xlqCiaPgr varchar(2), @xlqItemPgr int,@fechaitem date
			  declare @xlqReserva int,@xlqCiares varchar(2),@xlqItemRes int
			  DECLARE cerrarlq CURSOR
			  FOR SELECT p.TipDoc,p.Programa,p.IdCia,p.Item,Convert(date,p.FechaFin),p.Reserva,p.IdCiaRes,p.ItemRes 
			  FROM @Trn_TraEspProgramaDet2 p JOIN trn_traespresdetalle r on r.TipDoc = p.TipDocRes and r.Reserva = p.Reserva and r.IdCia = p.IdCiaRes and r.Item = p.ItemRes and (r.EstadoItem ='PROGRAMADA' or (r.EstadoItem = 'FACTURADA' and r.Factura > 0))
			  --04/07/2018 - 05/07/2018 Se cambia el Join(Abajo por el de Arriba) para tener en cuenta aquellas reservas que se facturan antes de Cerrar las Programaciones
			  --FROM @Trn_TraEspProgramaDet2 p JOIN trn_traespresdetalle r on r.TipDoc = p.TipDocRes and r.Reserva = p.Reserva and r.IdCia = p.IdCiaRes and r.Item = p.ItemRes and r.EstadoItem = 'PROGRAMADA'
			  OPEN cerrarlq
			  FETCH NEXT FROM cerrarlq INTO @xlqTipDoc,@xlqPrograma,@xlqCiaPgr,@xlqItemPgr,@fechaitem,@xlqReserva,@xlqCiaRes,@xlqItemRes
			  WHILE @@FETCH_STATUS = 0
			  BEGIN

			  declare @EsFest bit = '0'
			  declare @DI varchar(max)
			  declare @DI2 varchar(max)
			  declare @fechafin date
			  declare @DIAS varchar(max)
			  declare @IncFest bit
			  declare @valor DATE = Convert(date, dateadd(day,1,@fechaitem))
			  declare @resultado INT = 0
			  declare @prox INT = 0

			  select @fechafin = Convert(date,r.FechaFin), @DIAS = tc.Dias, @IncFest = ISNULL(tc.IncFestivo,0)
			  from Trn_TraEspResDetalle rd 
			  inner join Trn_TraEspReservas r on r.Reserva=rd.Reserva and r.IdCia=rd.IdCia
			  left join TiposCalendarPgr tc on tc.Codigo = rd.Codigo
			  where rd.Reserva = @xlqReserva and rd.IdCia = @xlqCiaRes and rd.Item = @xlqItemRes and rd.Codigo <> ''
		  			 			  			 
			  IF(datediff(day,@fechaitem, @fechafin) <= 7)
			  BEGIN
			
				WHILE ((@valor <= @fechafin) and (@resultado = 0))
				BEGIN
				   SET @DI = Datename(DW,(@valor))
				  
				   IF (@DI = 'MiÃ©rcoles')
					Set @DI = 'Miercoles'
				   ELSE IF (@DI = 'SÃ¡bado')
					Set @DI = 'Sabado'
				   
				   --verficar que el dia se encuentre en tiposcalendarpgr a travÃ©s de una funcion sql 		  	
				   SELECT @resultado = 1 WHERE @DI in (SELECT splitdata FROM FuncEspSplit(@DIAS,'-'))
				   SET @valor = dateadd(day,1,@valor)
				END	
										    
			  END

			  IF (@resultado = 0) 
				UPDATE Trn_TraEspResDetalle SET EstadoItem = 'XLIQUIDAR' WHERE Reserva = @xlqReserva and IdCia = @xlqCiaRes and Item = @xlqItemRes
			  
			  --VERIFICAR SI LA SIGUIENTE PROGRAMACION ES IGUAL A LA FECHA FINAL Y SI ESTA ES FESTIVA(VERIFICAR SI ESTA INCLUIDO EL FESTIVO EN TIPOSCALENDARPGR)
			  IF(@IncFest = '0')
			  BEGIN
				SET @fechaitem = dateadd(day,1,@fechaitem)
				declare @siguiente int = 1
				WHILE ((@fechaitem <= @fechafin) and @siguiente = 1)
				BEGIN
					SET @DI = Datename(DW,(@fechaitem))
					IF (@DI = 'MiÃ©rcoles')
					Set @DI = 'Miercoles'
				    ELSE IF (@DI = 'SÃ¡bado')
					Set @DI = 'Sabado'

					SELECT @prox = 1 WHERE @DI in (SELECT splitdata FROM FuncEspSplit(@DIAS,'-'))

					IF(@prox = 1)
					BEGIN 
						select @EsFest = '1' from Calndario where FechaDia in (@fechaitem) and TipoFtvo = 'FES'

						IF((@fechaitem = @fechafin) and @EsFest = '1')
						BEGIN
						 UPDATE Trn_TraEspResDetalle SET EstadoItem = 'XLIQUIDAR' WHERE Reserva = @xlqReserva and IdCia = @xlqCiaRes and Item = @xlqItemRes
						 SET @siguiente = 0	
						END
						ELSE 
						 SET @siguiente = 0						 
					END

					--Aumentar @fechaitem
					SET @fechaitem = dateadd(day,1,@fechaitem)
				END
			  END

			  FETCH NEXT FROM cerrarlq INTO @xlqTipDoc,@xlqPrograma,@xlqCiaPgr,@xlqItemPgr,@fechaitem,@xlqReserva,@xlqCiaRes,@xlqItemRes
			  END
			  CLOSE cerrarlq
			  DEALLOCATE cerrarlq

			  --cerrar las programaciones y programacion detalle
			  UPDATE Trn_TraEspPrograma SET IdEstado = '9998' WHERE TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia
			  
			  UPDATE Trn_TraEspProgramaDet 
			  SET EstadoItem = '0' 
			  from Trn_TraEspProgramaDet pd
			  JOIN @Trn_TraEspProgramaDet2 pdv on pd.TipDoc = pdv.TipDoc and pd.Programa = pdv.Programa and pd.IdCia = pdv.IdCia --WHERE TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia AND VLargo = 0

			  --Actualizar las reservasdet al estado XLIQUIDAR, las que cumplan con la condiciÃ³n de que la fecha sea igual al dia actual
			  DECLARE @auxTrn_TraEspProgramaDet2 dataTypeTrn_TraEspProgramaDet 
			  INSERT INTO @auxTrn_TraEspProgramaDet2(
			  TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,
			  FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,
			  CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
			  ) 
			  select 
			  V.TipDoc,V.Programa,V.IdCia,V.Item,FechaInicio,FechaFin,TipDocRes,V.Reserva,IdCiaRes,ItemRes,
			  IdOrigen,IdDestino,V.IdVehiculo,V.CdTipVeh,V.IdConductor,V.NumPasajeros,TipDocFuec,NumFuec,
			  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,V.Cumplido,FecIniCump,FecFinCump,
			  V.VrCobro,V.VrPagos,V.DiasDisp,V.Parada,V.CdTipServicio,V.DirOrigen,V.DirDestino,V.IdRuta,V.CdTipRuta,
			  V.PesoNeto,V.EstadoItem,V.VrMonitor,V.CantMonitor,V.VrRecorrido,Observacion,V.VLargo				
			  from 
			  (
				  SELECT 
				  TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
				  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
				  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,
				  FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,
				  CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
				  FROM Trn_TraEspProgramaDet  where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and VLargo = 0 and IdNovedad = '0'
				  UNION
				  SELECT 
				  TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
				  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
				  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,
				  FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,
				  CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
				  FROM Trn_TraEspProgramaDet d where d.VLargo = 1 and IdNovedad = '0'  and (Convert(DATE,d.FechaFin) BETWEEN @cthirtydaysago and @cFechaProg)
			  ) as v
			  JOIN Trn_TraEspResDetalle t2 on t2.TipDoc = V.TipDocRes and t2.Reserva = V.Reserva and t2.IdCia = V.IdCiaRes and t2.Item = V.ItemRes and (t2.EstadoItem ='PROGRAMADA' or (t2.EstadoItem = 'FACTURADA' and t2.Factura > 0))
			  --04/07/2018 - 05/07/2018 Se cambia el Join(Abajo por el de Arriba) para tener en cuenta aquellas reservas que se facturan antes de Cerrar las Programaciones
			  --JOIN Trn_TraEspResDetalle t2 on t2.TipDoc = V.TipDocRes and t2.Reserva = V.Reserva and t2.IdCia = V.IdCiaRes and t2.Item = V.ItemRes and t2.EstadoItem = 'PROGRAMADA'
			  where (Convert(date,@date) >= Convert(date,t2.FecDestino))

			  declare @lqTipDocRes varchar(3), @lqReserva int,@lqCiares varchar(2),@lqItemRes int 
			  DECLARE cerrarOtr CURSOR
			  FOR SELECT Reserva, IdCiaRes, ItemRes FROM @auxTrn_TraEspProgramaDet2
			  OPEN cerrarOtr
			  FETCH NEXT FROM cerrarOtr INTO @lqReserva,@lqCiaRes,@lqItemRes
			  WHILE @@FETCH_STATUS = 0
			  BEGIN
				
				UPDATE Trn_TraEspResDetalle
				SET EstadoItem = 'XLIQUIDAR'
				from Trn_TraEspResDetalle rd
				where rd.Reserva = @lqReserva and rd.IdCia = @lqCiaRes and rd.Item = @lqItemRes and (Convert(date,@date) >= Convert(date,rd.FecDestino))

				FETCH NEXT FROM cerrarOtr INTO @lqReserva,@lqCiaRes,@lqItemRes
			  END
			  CLOSE cerrarOtr
			  DEALLOCATE cerrarOtr
			  -------------------------------------------------------------------------------------------------------------------------------------------

			  --actualizar vehiculos
			  select @kmp = Valor from adm_opciones where IdOpc = 'kmp'
			  IF(@kmp = '2')
			  BEGIN
				UPDATE Vehiculos 
				SET Km2Actual = (Km2Actual + (SELECT Distkmt FROM Rutas WHERE IdRuta = pd.IdRuta))
				FROM Vehiculos v
				JOIN @Trn_TraEspProgramaDet2 pd ON pd.IdVehiculo = v.IdVehiculo --and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia
			  END

			  --Actualizar fechas de servicio
			  UPDATE Vehiculos 
			  SET FecPriServ = CASE WHEN FecPriServ <> NULL THEN v.FecPriServ ELSE pd.FecIniCump END, FecUltServ = pd.FecFinCump
			  FROM Vehiculos v
			  JOIN @Trn_TraEspProgramaDet2 pd on v.IdVehiculo = pd.IdVehiculo --and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia

			  --Actualizar estado de vehiculo
			  UPDATE Vehiculos 
			  SET IdEstado = '0001'
			  FROM Vehiculos v
			  JOIN @Trn_TraEspProgramaDet2 pd on v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad = '0' --and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia
			  where v.IdEstado = '0002' 

			  ------------------------------------------------------- Fin SecciÃ³n para verificacion de TiposCalendarPgr y lo de Incluir Festivos ----------------------------------------------
			  ------------------------------------------------------- Fin SecciÃ³n para VIAJES NO LARGOS / VIAJES LARGOS----------------------------------------------


			 -- ------------------------------------------------------- Inicio SecciÃ³n para VIAJES LARGOS -------------------------------------------
			 -- ------------------------------------------------------- Inicio SecciÃ³n para verificacion de TiposCalendarPgr y lo de Incluir Festivos -------------------------------------------
			 -- --Actualizar las reservasdet al estado XLIQUIDAR, cuando tienen tiposcalendarpgr
			 -- --verficar que el dia se encuentre en tiposcalendarpgr a travÃ©s de una funcion sql
			 -- --VERIFICAR SI LA SIGUIENTE PROGRAMACION ES IGUAL A LA FECHA FINAL Y SI ESTA ES FESTIVA(VERIFICAR SI ESTA INCLUIDO EL FESTIVO EN TIPOSCALENDARPGR)
			 -- DECLARE @cFechaProg datetime
			 -- SELECT @cFechaProg = Fecha FROM Trn_TraEspPrograma p
			 -- JOIN (SELECT TOP 1 TipDoc,Programa,IdCia  FROM @Trn_TraEspProgramaDet) AS pd ON p.TipDoc = pd.TipDoc and p.Programa = pd.Programa and p.IdCia = pd.IdCia

			 -- DECLARE @cthirtydaysago DATETIME
			 -- SET @cthirtydaysago = DATEADD(DAY,-30,@cFechaProg)

			 -- declare @Trn_TraEspProgramaDetC dataTypeTrn_TraEspProgramaDet 
			 -- INSERT INTO @Trn_TraEspProgramaDetC(
			 -- TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			 -- IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			 -- IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
			 -- CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
			 -- ) 
			 -- SELECT 
			 -- TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
			 -- IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
			 -- IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
			 -- CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
			 -- FROM Trn_TraEspProgramaDet  where VLargo = 1  and Convert(DATE,d.FechaFin) between Convert(DATE,@cthirtydaysago) and Convert(DATE,@cFechaProg)

			 -- declare @xlqTipDoc varchar(3), @xlqPrograma int, @xlqCiaPgr varchar(2), @xlqItemPgr int,@fechaitem date
			 -- declare @xlqReserva int,@xlqCiares varchar(2),@xlqItemRes int
			 -- DECLARE cerrarlq CURSOR
			 -- FOR SELECT p.TipDoc,p.Programa,p.IdCia,p.Item,Convert(date,p.FechaFin), p.Reserva,p.IdCiaRes,p.ItemRes 
			 -- FROM @Trn_TraEspProgramaDetC p JOIN trn_traespresdetalle r on r.EstadoItem = 'PROGRAMADA' and r.TipDoc = p.TipDocRes and r.Reserva = p.Reserva and r.IdCia = p.IdCiaRes and r.Item = p.ItemRes
			 -- OPEN cerrarlq
			 -- FETCH NEXT FROM cerrarlq INTO @xlqTipDoc,@xlqPrograma,@xlqCiaPgr,@xlqItemPgr,@fechaitem,@xlqReserva,@xlqCiaRes,@xlqItemRes
			 -- WHILE @@FETCH_STATUS = 0
			 -- BEGIN

			 -- declare @EsFest bit = '0'
			 -- declare @DI varchar(max)
			 -- declare @DI2 varchar(max)
			 -- declare @fechafin date
			 -- declare @DIAS varchar(max)
			 -- declare @IncFest bit
			 -- declare @valor DATE = Convert(date, dateadd(day,1,@fechaitem))
			 -- declare @resultado INT = 0
			 -- declare @prox INT = 0

			 -- select @fechafin = Convert(date,r.FechaFin), @DIAS = tc.Dias, @IncFest = ISNULL(tc.IncFestivo,0)
			 -- from Trn_TraEspResDetalle rd 
			 -- inner join Trn_TraEspReservas r on r.Reserva=rd.Reserva and r.IdCia=rd.IdCia
			 -- left join TiposCalendarPgr tc on tc.Codigo = rd.Codigo
			 -- where rd.Reserva = @xlqReserva and rd.IdCia = @xlqCiaRes and rd.Item = @xlqItemRes and rd.Codigo <> ''
		  			 			  			 
			 -- IF(datediff(day,@fechaitem, @fechafin) <= 7)
			 -- BEGIN
			
				--WHILE ((@valor <= @fechafin) and (@resultado = 0))
				--BEGIN
				--   SET @DI = Datename(DW,(@valor))
				  
				--   IF (@DI = 'MiÃ©rcoles')
				--	Set @DI = 'Miercoles'
				--   ELSE IF (@DI = 'SÃ¡bado')
				--	Set @DI = 'Sabado'
				   
				--   --verficar que el dia se encuentre en tiposcalendarpgr a travÃ©s de una funcion sql 		  	
				--   SELECT @resultado = 1 WHERE @DI in (SELECT splitdata FROM FuncEspSplit(@DIAS,'-'))
				--   SET @valor = dateadd(day,1,@valor)
				--END	
										    
			 -- END

			 -- IF (@resultado = 0) 
				--UPDATE Trn_TraEspResDetalle SET EstadoItem = 'XLIQUIDAR' WHERE Reserva = @xlqReserva and IdCia = @xlqCiaRes and Item = @xlqItemRes
			  
			 -- --VERIFICAR SI LA SIGUIENTE PROGRAMACION ES IGUAL A LA FECHA FINAL Y SI ESTA ES FESTIVA(VERIFICAR SI ESTA INCLUIDO EL FESTIVO EN TIPOSCALENDARPGR)
			 -- IF(@IncFest = '0')
			 -- BEGIN
				--SET @fechaitem = dateadd(day,1,@fechaitem)
				--declare @siguiente int = 1
				--WHILE ((@fechaitem <= @fechafin) and @siguiente = 1)
				--BEGIN
				--	SET @DI = Datename(DW,(@fechaitem))
				--	IF (@DI = 'MiÃ©rcoles')
				--	Set @DI = 'Miercoles'
				--    ELSE IF (@DI = 'SÃ¡bado')
				--	Set @DI = 'Sabado'

				--	SELECT @prox = 1 WHERE @DI in (SELECT splitdata FROM FuncEspSplit(@DIAS,'-'))

				--	IF(@prox = 1)
				--	BEGIN 
				--		select @EsFest = '1' from Calndario where FechaDia in (@fechaitem) and TipoFtvo = 'FES'

				--		IF((@fechaitem = @fechafin) and @EsFest = '1')
				--		BEGIN
				--		 UPDATE Trn_TraEspResDetalle SET EstadoItem = 'XLIQUIDAR' WHERE Reserva = @xlqReserva and IdCia = @xlqCiaRes and Item = @xlqItemRes
				--		 SET @siguiente = 0	
				--		END
				--		ELSE 
				--		 SET @siguiente = 0						 
				--	END

				--	--Aumentar @fechaitem
				--	SET @fechaitem = dateadd(day,1,@fechaitem)
				--END
			 -- END

			 -- FETCH NEXT FROM cerrarlq INTO @xlqTipDoc,@xlqPrograma,@xlqCiaPgr,@xlqItemPgr,@fechaitem,@xlqReserva,@xlqCiaRes,@xlqItemRes
			 -- END
			 -- CLOSE cerrarlq
			 -- DEALLOCATE cerrarlq

			 -- --cerrar las programaciones 
			 -- UPDATE Trn_TraEspPrograma SET IdEstado = '9998' WHERE TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia
			 -- UPDATE Trn_TraEspProgramaDet SET EstadoItem = '0' WHERE TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia AND VLargo = 0

			 -- --Actualizar las reservasdet al estado XLIQUIDAR, las que cumplan con la condiciÃ³n de que la fecha sea igual al dia actual
			 -- UPDATE Trn_TraEspResDetalle
			 -- SET EstadoItem = 'XLIQUIDAR'
		  --    FROM Trn_TraEspResDetalle t1
			 -- JOIN Trn_TraEspProgramaDet t2 ON t1.TipDoc = t2.TipDocRes and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCiaRes and t1.Item = t2.ItemRes
			 -- where (@date >= Convert(date,t1.FecDestino)) AND t2.TipDoc = @TipDoc and t2.Programa = @Documento and t2.IdCia = @IdCia and t2.VLargo = 0

			 -- --actualizar vehiculos
			  
			 -- select @kmp = Valor from adm_opciones where IdOpc = 'kmp'
			 -- IF(@kmp = '2')
			 -- BEGIN
				--UPDATE Vehiculos 
				--SET 
				--Km2Actual = (Km2Actual + (SELECT Distkmt FROM Rutas WHERE IdRuta = pd.IdRuta))
				--FROM Vehiculos v
				--JOIN Trn_TraEspProgramaDet pd ON pd.IdVehiculo = v.IdVehiculo and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia and VLargo = 0
			 -- END

			 -- --Actualizar fechas de servicio
			 -- UPDATE Vehiculos 
			 -- SET 
			 -- FecPriServ = CASE WHEN FecPriServ <> NULL THEN v.FecPriServ ELSE pd.FecIniCump END, 
			 -- FecUltServ = pd.FecFinCump
			 -- FROM Vehiculos v
			 -- JOIN Trn_TraEspProgramaDet pd on v.IdVehiculo = pd.IdVehiculo and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia and pd.VLargo = 0

			 -- --Actualizar estado de vehiculo
			 -- UPDATE Vehiculos 
			 -- SET 
			 -- IdEstado = '0001'
			 -- FROM Vehiculos v
			 -- JOIN Trn_TraEspProgramaDet pd on v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad = '0' and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia and pd.VLargo = 0
			 -- where v.IdEstado = '0002' 


			 -- ------------------------------------------------------- Fin SecciÃ³n para verificacion de TiposCalendarPgr y lo de Incluir Festivos ----------------------------------------------
			 -- ------------------------------------------------------- Fin SecciÃ³n para VIAJES LARGOS ----------------------------------------------

			END

			--ABRIR PROGRAMACIÃ“N
			IF(@operacion = 'o')
			BEGIN
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Programa from @Trn_TraEspPrograma

			  --abrir las programaciones 
			  UPDATE Trn_TraEspPrograma SET IdEstado = '0001' WHERE TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia

			  --Actualizar las reservasdet al estado programada porque se abre la programacion
			  UPDATE Trn_TraEspResDetalle
			  SET EstadoItem = 'PROGRAMADA'
		      FROM Trn_TraEspResDetalle t1
			  --JOIN Trn_TraEspProgramaDet t2 ON t1.TipDoc = t2.TipDocRes and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCiaRes and t1.Item = t2.ItemRes
			  --SOLO SE ABREN LAS Q ESTÃ‰N DIFERENTE DE POR LIQUIDAR
			  JOIN Trn_TraEspProgramaDet t2 ON t1.TipDoc = t2.TipDocRes and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCiaRes and t1.Item = t2.ItemRes and t1.EstadoItem <>'XLIQUIDAR'
			  			  
			  --actualizar vehiculos
			  declare @kmpa varchar 
			  select @kmpa = Valor from adm_opciones where IdOpc = 'kmp'
			  IF(@kmpa = '2')
			  BEGIN
				UPDATE Vehiculos 
				SET 
				Km2Actual = (Km2Actual - (SELECT Distkmt FROM Rutas WHERE IdRuta = pd.IdRuta))
				FROM Vehiculos v
				JOIN Trn_TraEspProgramaDet pd ON pd.IdVehiculo = v.IdVehiculo and pd.TipDoc = @TipDoc and pd.Programa = @Documento and pd.IdCia = @IdCia
			  END

			END

			--Cumplido de Detalles y Personas
			IF(@operacion = 'f')
			BEGIN
			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
			   BEGIN
					-------------------------------Inicio SecciÃ³n para cumplir cuando NO ES VIAJES LARGOS / VIAJES LARGOS----------------------------------------------------------------
					 --declare @date date
					 --select @date = Convert(date, getdate())
					 select top 1 @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Programa from @Trn_TraEspProgramaDet

					declare @fTipDoc varchar(MAX)
					declare @fPrograma int
					declare @fCiaPgr varchar(2)
					declare @fItemPgr int
					declare @fCumplido bit
					declare @fFecIniCump datetime
					declare @fFecFinCump datetime
					declare @fvehiculo varchar(10)
					declare @fObser varchar(MAX)
					declare @fVLargo bit 
					DECLARE @fFechaProg datetime
					declare @auxTrn_TraEspProgramaDet dataTypeTrn_TraEspProgramaDet 
					DECLARE @thirtydaysago DATETIME

					SELECT @fFechaProg = Fecha FROM Trn_TraEspPrograma p where p.TipDoc = @TipDoc and p.Programa = @Documento and p.IdCia = @IdCia										
					SET @thirtydaysago = DATEADD(DAY,-30,@fFechaProg)

					INSERT INTO @auxTrn_TraEspProgramaDet(
					TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
					IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
					IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
					CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
					) 
					select 
					TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
					IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
					IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
					CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo				
					from 
					(						
						SELECT 
						TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
						IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
						IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,VrCobro,VrPagos,DiasDisp,Parada,
						CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
						FROM @Trn_TraEspProgramaDet  where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and VLargo = 0
						UNION
						(
						  SELECT 
						  D.TipDoc,D.Programa,D.IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
						  IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
						  IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FechaInicio,FechaFin,VrCobro,VrPagos,DiasDisp,Parada,
						  CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,('Cumplido por el sistema automÃ¡ticamente por viaje largo, el dÃ­a: '+ convert(varchar(30),getdate(),100) + isnull(Observacion,'')),VLargo
						  FROM Trn_TraEspProgramaDet d JOIN Trn_TraEspPrograma p ON p.TipDoc = d.TipDoc and p.Programa = d.Programa and p.IdCia = d.IdCia
						  WHERE D.VLargo = 1 and d.IdNovedad = 0 and p.Anulado = 0 and d.Cumplido = 0 and Convert(DATE,d.FechaFin) between Convert(DATE,@thirtydaysago) and Convert(DATE,@fFechaProg)
						)
					)as auxv

					DECLARE cumpserv CURSOR
					FOR SELECT TipDoc,Programa,IdCia,Item,Cumplido,FecIniCump,FecFinCump,IdVehiculo,Observacion,VLargo FROM @auxTrn_TraEspProgramaDet
					OPEN cumpserv
					FETCH NEXT FROM cumpserv INTO @fTipDoc,@fPrograma,@fCiaPgr,@fItemPgr,@fCumplido,@fFecIniCump,@fFecFinCump,@fvehiculo,@fObser,@fVLargo
					WHILE @@FETCH_STATUS = 0
					BEGIN
				   
					   --IF(@fVLargo = 0)
					   --BEGIN
						   UPDATE Trn_TraEspProgramaDet
						   SET Cumplido = '1',FecIniCump = @fFecIniCump, FecFinCump = @fFecFinCump, Observacion = @fObser			   
						   FROM Trn_TraEspProgramaDet 
						   WHERE TipDoc = @fTipDoc and Programa = @fPrograma and IdCia = @fCiaPgr  and Item = @fItemPgr

						   UPDATE Trn_TraEspProgramaPers
						   SET Cumplido = '1'
						   from Trn_TraEspProgramaPers
						   WHERE TipDoc = @fTipDoc and Programa = @fPrograma and IdCia = @fCiaPgr  and Item = @fItemPgr

						   --Actualizar estado de vehiculo
						   UPDATE Vehiculos SET IdEstado = '0001' FROM Vehiculos v WHERE v.IdEstado = '0002' and v.IdVehiculo = @fvehiculo
					   --END
				
					FETCH NEXT FROM cumpserv INTO @fTipDoc,@fPrograma,@fCiaPgr,@fItemPgr,@fCumplido,@fFecIniCump,@fFecFinCump,@fvehiculo,@fObser,@fVLargo
					END
					CLOSE cumpserv
					DEALLOCATE cumpserv

					---------------------------------------------------------------------CÃ³digo Anterior-----------------------------------------------------------
					-------------------------------Fin SecciÃ³n para el requerimiento cuando NO ES VIAJES LARGOS / VIAJES LARGOS----------------------------------------------------------------
					------------------------------Inicio SecciÃ³n para cumplir cuando ES VIAJES LARGOS---------------------------------------------------------------------

					--SELECT @fFechaProg = Fecha FROM Trn_TraEspPrograma p
					--JOIN (SELECT TOP 1 TipDoc,Programa,IdCia  FROM @Trn_TraEspProgramaDet) AS pd ON p.TipDoc = pd.TipDoc and p.Programa = pd.Programa and p.IdCia = pd.IdCia

					--DECLARE @thirtydaysago DATETIME
					--SET @thirtydaysago = DATEADD(DAY,-30,@fFechaProg)

					--DECLARE @Trn_TraEspProgramaDet3 dataTypeTrn_TraEspProgramaDet 

					--INSERT INTO @Trn_TraEspProgramaDet3(
					--TipDoc,Programa,IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
					--IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
					--IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,
					--VrCobro,VrPagos,DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,
					--EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
					--) 
					--SELECT 
					--D.TipDoc,D.Programa,D.IdCia,Item,FechaInicio,FechaFin,TipDocRes,Reserva,IdCiaRes,ItemRes,
					--IdOrigen,IdDestino,IdVehiculo,CdTipVeh,IdConductor,NumPasajeros,TipDocFuec,NumFuec,
					--IdCiaFuec,TipDocOdp,NumOdp,IdCiaOdp,FechaOdp,IdNovedad,Novedad,Cumplido,FecIniCump,FecFinCump,
					--VrCobro,VrPagos,DiasDisp,Parada,CdTipServicio,DirOrigen,DirDestino,IdRuta,CdTipRuta,PesoNeto,
					--EstadoItem,VrMonitor,CantMonitor,VrRecorrido,Observacion,VLargo
					--FROM Trn_TraEspProgramaDet d 					 
					--JOIN Trn_TraEspPrograma p ON p.TipDoc = d.TipDoc and p.Programa = d.Programa and p.IdCia = d.IdCia
					--WHERE D.VLargo = 1 and d.IdNovedad = 0 and p.Anulado = 0 and d.Cumplido = 0 and Convert(DATE,d.FechaFin) between Convert(DATE,@thirtydaysago) and Convert(DATE,@fFechaProg)

					--IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet3))
					--BEGIN
					--	DECLARE @fvlTipDoc varchar(MAX)
					--	DECLARE @fvlPrograma int
					--	DECLARE @fvlCiaPgr varchar(2)
					--	DECLARE @fvlItemPgr int
					--	DECLARE @fvlCumplido bit
					--	DECLARE @fvlFecIniCump datetime
					--	DECLARE @fvlFecFinCump datetime
					--	DECLARE @fvlvehiculo varchar(10)
					--	DECLARE @fvlVLargo bit 
					--	DECLARE @fvlFechaProg datetime

					--	set @fvlFecFinCump = GETDATE()

					--	DECLARE vlcumpserv CURSOR
					--	FOR SELECT TipDoc,Programa,IdCia,Item,FechaInicio,IdVehiculo,VLargo FROM @Trn_TraEspProgramaDet3
					--	OPEN vlcumpserv
					--	FETCH NEXT FROM vlcumpserv INTO @fvlTipDoc,@fvlPrograma,@fvlCiaPgr,@fvlItemPgr,@fvlFecIniCump,@fvlvehiculo,@fvlVLargo
					--	WHILE @@FETCH_STATUS = 0
					--	BEGIN
				   
					--	   IF(@fvlVLargo = 1)
					--	   BEGIN
					--		   UPDATE Trn_TraEspProgramaDet
					--		   SET Cumplido = 1,FecIniCump = @fvlFecIniCump, FecFinCump = @fvlFecFinCump			   
					--		   FROM Trn_TraEspProgramaDet 
					--		   WHERE TipDoc = @fvlTipDoc and Programa = @fvlPrograma and IdCia = @fvlCiaPgr  and Item = @fvlItemPgr

					--		   UPDATE Trn_TraEspProgramaPers
					--		   SET Cumplido = 1
					--		   from Trn_TraEspProgramaPers
					--		   WHERE TipDoc = @fvlTipDoc and Programa = @fvlPrograma and IdCia = @fvlCiaPgr  and Item = @fvlItemPgr

					--		   --Actualizar estado de vehiculo
					--		   UPDATE Vehiculos SET IdEstado = '0001' FROM Vehiculos v WHERE v.IdEstado = '0002' and v.IdVehiculo = @fvlvehiculo
					--	   END
				
					--	FETCH NEXT FROM vlcumpserv INTO @fvlTipDoc,@fvlPrograma,@fvlCiaPgr,@fvlItemPgr,@fvlFecIniCump,@fvlvehiculo,@fvlVLargo
					--	END
					--	CLOSE vlcumpserv
					--	DEALLOCATE vlcumpserv
					--END

					------------------------------Fin SecciÃ³n para cumplir cuando ES VIAJES LARGOS------------------------------------------------------------------------

			   END
			END

			--Cancelar servicio
			IF(@operacion = 's')
			BEGIN
			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
			   BEGIN

			    declare @cveh varchar(11)
			    declare @cidnov varchar(4)
				declare @cnov varchar(MAX)
				declare @cObserv varchar(MAX)
				declare @cPrograma int
				declare @cCiaPgr varchar(2)
				declare @cItemPgr int
				declare @cEstadoItem int

				DECLARE cancelserv CURSOR
				FOR SELECT IdVehiculo,IdNovedad,Novedad,Programa,IdCia,Item,Observacion,EstadoItem FROM @Trn_TraEspProgramaDet where IdNovedad != '0'
				OPEN cancelserv
				FETCH NEXT FROM cancelserv INTO @cveh,@cidnov,@cnov,@cPrograma,@cCiaPgr,@cItemPgr,@cObserv,@cEstadoItem
				WHILE @@FETCH_STATUS = 0
				BEGIN
				   --Actualizar programa detalles las columnas de la novedad
				   UPDATE Trn_TraEspProgramaDet
				   SET IdNovedad = @cidnov, Novedad = @cnov, Observacion = @cObserv,EstadoItem = @cEstadoItem
				   FROM Trn_TraEspProgramaDet
				   WHERE TipDoc = 'PGR' and Programa = @cPrograma and IdCia = @cCiaPgr  and Item=  @cItemPgr

				   --Verificar vehiculos
				   declare @count int
				   select @count = count(*) from Trn_TraEspProgramaDet 
				   WHERE IdVehiculo = @cveh and  TipDoc = 'PGR' and Programa = @cPrograma and IdCia = @cCiaPgr

				   IF(@count = 1)
				   BEGIN
					   UPDATE Vehiculos
					   SET IdEstado = '0001'
					   FROM Vehiculos
					   WHERE IdVehiculo = @cveh 
				   END

				   --Eliminar personas de la programacion detalle cancelada
				   DELETE FROM Trn_TraEspProgramaPers WHERE TipDoc = 'PGR' and Programa = @cPrograma and IdCia = @cCiaPgr  and Item =  @cItemPgr

				FETCH NEXT FROM cancelserv INTO @cveh,@cidnov,@cnov,@cPrograma,@cCiaPgr,@cItemPgr,@cObserv,@cEstadoItem
				END
				CLOSE cancelserv
				DEALLOCATE cancelserv

			   END
			END

			--Not Cumplido de Detalles y Personas
			IF(@operacion = 'n')
			BEGIN
			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
			   BEGIN
			    declare @nfTipDoc varchar(MAX)
				declare @nfPrograma int
				declare @nfCiaPgr varchar(2)
				declare @nfItemPgr int
				declare @nfCumplido bit
				--declare @nfFecIniCump datetime
				--declare @nfFecFinCump datetime
				declare @nfvehiculo varchar(10)

			    DECLARE ncumpserv CURSOR
				FOR SELECT TipDoc,Programa,IdCia,Item,Cumplido,IdVehiculo FROM @Trn_TraEspProgramaDet
				OPEN ncumpserv
				FETCH NEXT FROM ncumpserv INTO @nfTipDoc,@nfPrograma,@nfCiaPgr,@nfItemPgr,@nfCumplido,@nfvehiculo
				WHILE @@FETCH_STATUS = 0
				BEGIN

				   UPDATE Trn_TraEspProgramaDet
				   SET Cumplido = '0',FecIniCump = null, FecFinCump = null			   
				   FROM Trn_TraEspProgramaDet 
				   WHERE TipDoc = @nfTipDoc and Programa = @nfPrograma and IdCia = @nfCiaPgr  and Item = @nfItemPgr

				   UPDATE Trn_TraEspProgramaPers
				   SET Cumplido = '0'
				   from Trn_TraEspProgramaPers
				   WHERE TipDoc = @nfTipDoc and Programa = @nfPrograma and IdCia = @nfCiaPgr  and Item = @nfItemPgr

				   --Actualizar estado de vehiculo Es mejor no actulizar el vehÃ­culo por temas de otras programciones y si estÃ¡ en mantenimiento o otro estado
				   --UPDATE Vehiculos SET IdEstado = '0002' FROM Vehiculos v WHERE v.IdEstado = '0001' and v.IdVehiculo = @nfvehiculo
				
				FETCH NEXT FROM ncumpserv INTO @nfTipDoc,@nfPrograma,@nfCiaPgr,@nfItemPgr,@nfCumplido,@nfvehiculo
				END
				CLOSE ncumpserv
				DEALLOCATE ncumpserv

			   END
			END

			SELECT @Documento

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspReservas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspReservas]
	@Trn_TraEspReservas [dbo].[dataTypeTrn_TraEspReservas] READONLY,
	@Trn_TraEspResAnexo [dbo].[dataTypeTrn_TraEspResAnexo] READONLY,
	@Trn_TraEspResDetalle [dbo].[dataTypeTrn_TraEspResDetalle] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Reserva/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Reserva/CotizaciÃ³n
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Reserva/CotizaciÃ³n
declare @item int
declare @vranterior money
DECLARE @Detalle dataTypeTrn_TraEspResDetalle --Tipo de dato definido por el usuario que representa la tabla Trn_TraEspEspDetalle

	BEGIN TRAN
		BEGIN TRY

			--Seleccionar Variables
			IF(@operacion = 'i')
			begin
				SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia FROM @Trn_TraEspReservas
				SELECT @Documento = Numero + 1  FROM TiposDocCons where IdDoc = @TipDoc AND IdCia = @IdCia

				IF(@Documento <> '')
					UPDATE TiposDocCons SET Numero = @Documento WHERE IdDoc = @TipDoc and IdCia = @IdCia
				ELSE
				BEGIN
					SELECT @Documento = 1
					INSERT INTO TiposDocCons VALUES (@TipDoc,@IdCia,0,0,0,0,NULL,'',@Documento,0,0,'','',1,1,1,0,1,CURRENT_TIMESTAMP,null,null,null,null)
				END
			end

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Reserva FROM @Trn_TraEspResDetalle

			    --captura el valor de cobro para ver si cambia o no cambia para actualizarlo en el contrato
			   select @vranterior = VrCobro from Trn_TraEspReservas where TipDoc = (select TipDoc from @Trn_TraEspReservas) and IdCia = (select IdCia from @Trn_TraEspReservas) and Reserva = (select Reserva from @Trn_TraEspReservas)
			   
			   INSERT INTO @Detalle(
			   TipDoc,Reserva,IdCia,Item,ItemCnt,IdVehiculo,CdTipVeh,IdConductor,IdRuta,CdTipRuta,NumPasajeros,PesoNeto,VrCobro,VrPagos,Referencia1,
			   Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,DiasDisp,VrDia,
			   Parada,CdTipServicio,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,NumDias,TipoTarifa,IdColegio,TipFac,Factura,IdCiaFac,FechaFac,
			   TipCum,Cumplido,IdCiaCum,FechaCum,Codigo,Itinerario,VLargo,IdOtroSi,EsItemPME)
			   SELECT 
			   TipDoc,Reserva,IdCia,Item,ItemCnt,IdVehiculo,CdTipVeh,IdConductor,IdRuta,CdTipRuta,NumPasajeros,PesoNeto,VrCobro,VrPagos,Referencia1,
			   Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,DiasDisp,VrDia,
			   Parada,CdTipServicio,EstadoItem,VrMonitor,CantMonitor,VrRecorrido,NumDias,TipoTarifa,IdColegio,TipFac,Factura,IdCiaFac,FechaFac,
			   TipCum,Cumplido,IdCiaCum,FechaCum,Codigo,Itinerario,VLargo,IdOtroSi,EsItemPME
			   FROM Trn_TraEspResDetalle WHERE TipDoc = @TipDoc and Reserva = @Documento and IdCia = @IdCia

			   if(EXISTS(SELECT * FROM @Trn_TraEspReservas))
			   begin
			   UPDATE Trn_TraEspReservas
			   SET 
			   TipDoc = t2.TipDoc,Reserva = t2.Reserva,IdCia = t2.IdCia,Fecha = t2.Fecha,FechaInicio = t2.FechaInicio,FechaFin = t2.FechaFin,
			   TipDocCnt = t2.TipDocCnt,Contrato = t2.Contrato,IdCiaCnt = t2.IdCiaCnt,EstadoRes = t2.EstadoRes,IdCliente = t2.IdCliente,
			   IdAgencia = t2.IdAgencia,IdMneda = t2.IdMneda,CdCarga = t2.CdCarga,Modalidad = t2.Modalidad,TipoLiquid = t2.TipoLiquid,
			   TipFac = t2.TipFac,Factura = t2.Factura,IdCiaFac = t2.IdCiaFac,FechaFac = t2.FechaFac,
			   TipFuec = t2.TipFuec,NumFuec = t2.NumFuec,IdCiaFuec = t2.IdCiaFuec,
			   VrCobro = t2.VrCobro,VrPagos = t2.VrPagos,OrigenAdd = t2.OrigenAdd,Anulado = t2.Anulado,FecDev = t2.FecDev,
			   IdEstado = t2.IdEstado,TimeSys = t2.TimeSys,FecUpdate = t2.FecUpdate,IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario,
			   IdGrupo = t2.IdGrupo, IdRutaG = t2.IdRutaG, NoRequiereGIE = t2.NoRequiereGIE
		       FROM Trn_TraEspReservas t1
			   JOIN @Trn_TraEspReservas t2 ON t1.TipDoc = t2.TipDoc and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspResAnexo))
			   begin
			   UPDATE Trn_TraEspResAnexo
			   SET 
			   TipDoc = t2.TipDoc,Reserva = t2.Reserva,IdCia = t2.IdCia,NomCliente = t2.NomCliente,TelCliente = t2.TelCliente,
			   emlCliente = t2.emlCliente,DireccionCli = t2.DireccionCli,Observacion = t2.Observacion,NombArchivo = t2.NombArchivo,
			   DescripCarga = t2.DescripCarga,Clausulas = t2.Clausulas,Responsable = t2.Responsable
		       FROM Trn_TraEspResAnexo t1
			   JOIN @Trn_TraEspResAnexo t2 ON t1.TipDoc = t2.TipDoc and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCia
			   end

			   if(EXISTS(SELECT * FROM @Trn_TraEspResDetalle))
			   begin
			   select @item =  isnull(MAX(Item),0) from Trn_TraEspResDetalle where TipDoc = @TipDoc and Reserva = @Documento and IdCia = @IdCia

			   --actualizar los que vienen en el tipo de datos y coincida con los que estan en la tabla
			   UPDATE Trn_TraEspResDetalle
			   SET 
			   TipDoc = t2.TipDoc,Reserva = t2.Reserva,IdCia = t2.IdCia,Item = t2.Item,ItemCnt = t2.ItemCnt,IdVehiculo = t2.IdVehiculo,
			   CdTipVeh = t2.CdTipVeh,IdConductor = t2.IdConductor,IdRuta = t2.IdRuta,CdTipRuta = t2.CdTipRuta,NumPasajeros = t2.NumPasajeros,
			   PesoNeto = t2.PesoNeto,VrCobro = t2.VrCobro,VrPagos = t2.VrPagos,Referencia1 = t2.Referencia1,Referencia2 = t2.Referencia2,
			   Referencia3 = t2.Referencia3,EsRutaCliente = t2.EsRutaCliente,CdCiuOrigen = t2.CdCiuOrigen,DirOrigen = t2.DirOrigen,
			   FecOrigen = t2.FecOrigen,CdCiuDestino = t2.CdCiuDestino,DirDestino = t2.DirDestino,FecDestino = t2.FecDestino,DiasDisp = t2.DiasDisp,
			   VrDia = t2.VrDia,Parada = t2.Parada,CdTipServicio = t2.CdTipServicio,EstadoItem = t2.EstadoItem,VrMonitor = t2.VrMonitor,CantMonitor = t2.CantMonitor,
			   VrRecorrido = t2.VrRecorrido,NumDias=t2.NumDias,TipoTarifa=t2.TipoTarifa,IdColegio = t2.IdColegio,
			   TipFac = t2.TipFac,Factura = t2.Factura,IdCiaFac = t2.IdCiaFac,FechaFac = t2.FechaFac,
			   TipCum = t2.TipCum,Cumplido = t2.Cumplido,IdCiaCum = t2.IdCiaCum,FechaCum = t2.FechaCum,Codigo=t2.Codigo, Itinerario=t2.Itinerario,VLargo = t2.VLargo,
			   IdOtroSi = t2.IdOtroSi, EsItemPME = t2.EsItemPME
		       FROM Trn_TraEspResDetalle t1
			   JOIN @Trn_TraEspResDetalle t2 ON t1.TipDoc = t2.TipDoc and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspResDetalle(
			   TipDoc,Reserva,IdCia,Item,ItemCnt,IdVehiculo,CdTipVeh,IdConductor,IdRuta,CdTipRuta,NumPasajeros,PesoNeto,VrCobro,VrPagos,Referencia1,
			   Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,DiasDisp,VrDia,Parada,CdTipServicio,EstadoItem,
			   VrMonitor,CantMonitor,VrRecorrido,NumDias,TipoTarifa,IdColegio,TipFac,Factura,IdCiaFac,FechaFac,TipCum,Cumplido,IdCiaCum,FechaCum,Codigo,Itinerario,VLargo,
			   IdOtroSi,EsItemPME
	           ) 
			   SELECT 
			   @TipDoc,@Documento,@IdCia,(@Item + ROW_NUMBER() OVER(ORDER BY Item ASC))
			   ,ItemCnt,IdVehiculo,CdTipVeh,IdConductor,IdRuta,CdTipRuta,NumPasajeros,PesoNeto,VrCobro,VrPagos,Referencia1,
			   Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,DiasDisp,VrDia,Parada,CdTipServicio,EstadoItem
			   ,VrMonitor,CantMonitor,VrRecorrido,NumDias,TipoTarifa,IdColegio,TipFac,Factura,IdCiaFac,FechaFac,TipCum,Cumplido,IdCiaCum,FechaCum,isnull(Codigo,null),
			   Itinerario,VLargo,IdOtroSi,EsItemPME
			   FROM @Trn_TraEspResDetalle
			   WHERE (TipDoc + Convert(varchar,Reserva)+IdCia+Convert(varchar,Item)) NOT IN(SELECT(TipDoc + Convert(varchar,Reserva)+IdCia+Convert(varchar,Item)) FROM Trn_TraEspResDetalle)
			   --Eliminar los que no existen en el tipo de dato
			   delete from Trn_TraEspResDetalle
			   WHERE TipDoc = @TipDoc and Reserva = @Documento and IdCia = @IdCia and Item NOT IN(SELECT Item FROM @Trn_TraEspResDetalle)
			   end
			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN

				IF(EXISTS(SELECT * FROM @Trn_TraEspReservas))
				begin
				INSERT INTO Trn_TraEspReservas(
				TipDoc,Reserva,IdCia,Fecha,FechaInicio,FechaFin,TipDocCnt,Contrato,IdCiaCnt,EstadoRes,IdCliente,IdAgencia,IdMneda,CdCarga,Modalidad,TipoLiquid,
				TipFac,Factura,IdCiaFac,FechaFac,TipFuec,NumFuec,IdCiaFuec,VrCobro,VrPagos,OrigenAdd,Anulado,FecDev,IdEstado,
				TimeSys,FecUpdate,IdCiaCrea,IdUsuario,IdGrupo,IdRutaG,NoRequiereGIE
				)
				SELECT 
				@TipDoc,@Documento,@IdCia,Fecha,FechaInicio,FechaFin,TipDocCnt,Contrato,IdCiaCnt,EstadoRes,IdCliente,IdAgencia,IdMneda,CdCarga,Modalidad,TipoLiquid,
				TipFac,Factura,IdCiaFac,FechaFac,TipFuec,NumFuec,IdCiaFuec,VrCobro,VrPagos,OrigenAdd,Anulado,FecDev,IdEstado,
				TimeSys,FecUpdate,IdCiaCrea,IdUsuario,IdGrupo,IdRutaG,NoRequiereGIE
				FROM @Trn_TraEspReservas
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspResAnexo))
				begin
				INSERT INTO Trn_TraEspResAnexo(
				TipDoc,Reserva,IdCia,NomCliente,TelCliente,emlCliente,DireccionCli,Observacion,
				NombArchivo,DescripCarga,Clausulas,Responsable
				)
				SELECT 
				@TipDoc,@Documento,@IdCia,NomCliente,TelCliente,emlCliente,DireccionCli,Observacion,
				NombArchivo,DescripCarga,Clausulas,Responsable
				FROM @Trn_TraEspResAnexo
				end

				IF(EXISTS(SELECT * FROM @Trn_TraEspResDetalle))
				begin
				INSERT INTO Trn_TraEspResDetalle(
			    TipDoc,Reserva,IdCia,Item,ItemCnt,IdVehiculo,CdTipVeh,IdConductor,IdRuta,CdTipRuta,NumPasajeros,PesoNeto,VrCobro,VrPagos,Referencia1,
			    Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,DiasDisp,VrDia,Parada,CdTipServicio,EstadoItem,
				VrMonitor,CantMonitor,VrRecorrido,NumDias,TipoTarifa,IdColegio,TipFac,Factura,IdCiaFac,FechaFac,TipCum,Cumplido,IdCiaCum,FechaCum,Codigo,Itinerario,VLargo,
				IdOtroSi,EsItemPME
	            ) 
			    SELECT 
			    @TipDoc,@Documento,@IdCia,Item,ItemCnt,IdVehiculo,CdTipVeh,IdConductor,IdRuta,CdTipRuta,NumPasajeros,PesoNeto,VrCobro,VrPagos,Referencia1,
			    Referencia2,Referencia3,EsRutaCliente,CdCiuOrigen,DirOrigen,FecOrigen,CdCiuDestino,DirDestino,FecDestino,DiasDisp,VrDia,Parada,CdTipServicio,EstadoItem,
				VrMonitor,CantMonitor,VrRecorrido,NumDias,TipoTarifa,IdColegio,TipFac,Factura,IdCiaFac,FechaFac,TipCum,Cumplido,IdCiaCum,FechaCum,isnull(Codigo, null),
				Itinerario,VLargo,IdOtroSi,EsItemPME
			    FROM @Trn_TraEspResDetalle
				end

			 END

			--DELETE RECORDS
			IF(@operacion = 'd')
			BEGIN
			 declare @Reserva int
			 select @TipDoc = TipDoc, @IdCia = IdCia,  @Reserva = Reserva from @Trn_TraEspReservas
				 DELETE FROM Trn_TraEspResDetalle WHERE TipDoc = @TipDoc and Reserva = @Reserva and IdCia = @IdCia
				 DELETE FROM Trn_TraEspResAnexo WHERE TipDoc = @TipDoc and Reserva = @Reserva and IdCia = @IdCia
				 DELETE FROM Trn_TraEspReservas WHERE TipDoc = @TipDoc and Reserva = @Reserva and IdCia = @IdCia
			END

			--ANULAR RECORDS
			IF(@operacion = 'a')
			BEGIN
				declare @FecDev smalldatetime 
			  select @TipDoc = TipDoc, @IdCia = IdCia,  @Documento = Reserva, @FecDev = FecDev from @Trn_TraEspReservas
			  UPDATE Trn_TraEspReservas SET IdEstado = '9999',Anulado = '1', FecDev = @FecDev  WHERE TipDoc = @TipDoc and Reserva = @Documento and IdCia = @IdCia

			  UPDATE Trn_TraEspContratoDet
			  SET TipRes = 'RES', NumRes = 0, IdCiaRes = '00',ItemRes = 0
			  FROM Trn_TraEspContratoDet cd
			  WHERE cd.TipRes = @TipDoc  and cd.NumRes = @Documento and cd.IdCiaRes = @IdCia

			  --actualizar el valor de presupuesto del contrato cuando se anula una reserva
			  UPDATE Trn_TraEspContratos
			  SET VrSaldoPresup = p.VrSaldoPresup + r.VrCobro
			  FROM Trn_TraEspContratos p 
			  JOIN Trn_TraEspReservas r on r.TipDoc = @TipDoc and r.Reserva = @Documento and r.IdCia = @IdCia
			  WHERE p.TipDoc = r.TipDocCnt  and p.Contrato = r.Contrato and p.IdCia = r.IdCiaCnt

			  UPDATE Trn_TraEspContratos
			  SET IdEstado = '0001'
			  FROM Trn_TraEspContratos p
			  JOIN Trn_TraEspReservas r on r.TipDoc = @TipDoc and r.Reserva = @Documento and r.IdCia = @IdCia
			  WHERE p.TipDoc = r.TipDocCnt  and p.Contrato = r.Contrato and p.IdCia = r.IdCiaCnt and p.VrSaldoPresup > 0 and p.IdEstado = '9998'
			  ------------------------------------
			END

			--ACTUALIZAR DETALLES DE CONTRATOS
			IF(@operacion = 'i')
			BEGIN
			  UPDATE Trn_TraEspContratoDet
			  SET TipRes = @TipDoc, NumRes = @Documento, IdCiaRes = @IdCia,ItemRes = d.Item
			  FROM Trn_TraEspContratoDet cd, @Trn_TraEspResDetalle d, @Trn_TraEspReservas r 
			  WHERE cd.TipDoc = r.TipDocCnt  and cd.Contrato = r.Contrato and cd.IdCia = r.IdCiaCnt and cd.Item = d.ItemCnt

			  --actualizar el valor de presupuestro del contrato, luego de insertar una reserva
			  UPDATE Trn_TraEspContratos
			  SET VrSaldoPresup = p.VrSaldoPresup - r.VrCobro
			  FROM Trn_TraEspContratos p, @Trn_TraEspReservas r 
			  WHERE p.TipDoc = r.TipDocCnt  and p.Contrato = r.Contrato and p.IdCia = r.IdCiaCnt

			  UPDATE Trn_TraEspContratos
			  SET IdEstado = '9998'
			  FROM Trn_TraEspContratos p, @Trn_TraEspReservas r 
			  WHERE p.TipDoc = r.TipDocCnt  and p.Contrato = r.Contrato and p.IdCia = r.IdCiaCnt and p.VrSaldoPresup = 0
			  ----------------------------------------
			END

			IF(@operacion = 'u')
			BEGIN

			--actualiza los items de un contrato con los que se relacionan en el tipo de datos nuevo
			  UPDATE Trn_TraEspContratoDet
			  SET TipRes = 'RES', NumRes = 0, IdCiaRes = '00',ItemRes = 0
			  FROM Trn_TraEspContratoDet cd, @Detalle d, @Trn_TraEspReservas r 
			  WHERE cd.TipDoc = r.TipDocCnt  and cd.Contrato = r.Contrato and cd.IdCia = r.IdCiaCnt and cd.Item = d.ItemCnt

			  UPDATE Trn_TraEspContratoDet
			  SET TipRes = @TipDoc, NumRes = @Documento, IdCiaRes = @IdCia,ItemRes = d.Item
			  FROM Trn_TraEspContratoDet cd, @Trn_TraEspResDetalle d, @Trn_TraEspReservas r 
			  WHERE cd.TipDoc = r.TipDocCnt  and cd.Contrato = r.Contrato and cd.IdCia = r.IdCiaCnt and cd.Item = d.ItemCnt

			  --actualizar el valor de presupuestro del contrato
			  if(@vranterior <> (select VrCobro from @Trn_TraEspReservas))
			  begin
				  UPDATE Trn_TraEspContratos
				  SET VrSaldoPresup = (p.VrSaldoPresup + @vranterior) - r.VrCobro
				  FROM Trn_TraEspContratos p, @Trn_TraEspReservas r 
				  WHERE p.TipDoc = r.TipDocCnt  and p.Contrato = r.Contrato and p.IdCia = r.IdCiaCnt
			  end 

			  UPDATE Trn_TraEspContratos
			  SET IdEstado = '9998'
			  FROM Trn_TraEspContratos p, @Trn_TraEspReservas r 
			  WHERE p.TipDoc = r.TipDocCnt  and p.Contrato = r.Contrato and p.IdCia = r.IdCiaCnt and p.VrSaldoPresup = 0


			END

			SELECT @Documento

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_TraEspSedes]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_TraEspSedes]
	@Trn_TraEspSedes [dbo].[dataTypeTrn_TraEspSedes] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
		BEGIN TRY

			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN
			   IF(EXISTS(SELECT * FROM @Trn_TraEspSedes))
			   begin
			   UPDATE Trn_TraEspSedes
			   SET 
			   IdColegio = t2.IdColegio, IdSede = t2.IdSede, NomSede = t2.NomSede, Inactivo = t2.Inactivo
		       FROM Trn_TraEspSedes t1
			   JOIN @Trn_TraEspSedes t2 ON t1.IdColegio = t2.IdColegio and t1.IdSede = t2.IdSede 
			   end
			END

		    --INSERT NO-EXISTE RECORDS
			IF(@operacion = 'i')
			 BEGIN
				IF(EXISTS(SELECT * FROM @Trn_TraEspSedes))
				begin
				INSERT INTO Trn_TraEspSedes(
				IdColegio,IdSede,NomSede,Inactivo
				)
				SELECT 
				IdColegio,IdSede,NomSede,Inactivo
				FROM @Trn_TraEspSedes
				end
			 END

			 --DELETE RECORDS
			 IF(@operacion = 'd')
			 BEGIN
				 DECLARE @idcol varchar(4) DECLARE @idsede varchar(4)
				 SELECT @idcol = idcolegio, @idsede = idsede FROM @Trn_TraEspSedes
				 DELETE FROM Trn_TraEspSedes WHERE idcolegio = @idcol and idsede = @idsede
			 END

			SELECT '1'

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehConductor]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_VehConductor]
	@Trn_VehConductor [dbo].[dataTypeTrn_VehConductor] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = ISNULL(MAX(Numero),0) FROM Trn_VehConductor WHERE IdVehiculo = (select IdVehiculo from @Trn_VehConductor)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Trn_VehConductor
			 SET
			 IdVehiculo = t2.IdVehiculo,Numero = t2.Numero,Fecha = t2.Fecha,IdPropietario = t2.IdPropietario,
			 IdConductor = t2.IdConductor,IdCondNuevo = t2.IdCondNuevo,Observacion = t2.Observacion,
			 TimeSys = t2.TimeSys,IdUsuario = t2.IdUsuario
		     FROM Trn_VehConductor t1
			 JOIN @Trn_VehConductor t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.Numero = t2.Numero
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Trn_VehConductor(
			 IdVehiculo,Numero,Fecha,IdPropietario,IdConductor,IdCondNuevo,Observacion,TimeSys,IdUsuario
			 )
			 SELECT 
			 IdVehiculo,(@item+1),Fecha,IdPropietario,IdConductor,IdCondNuevo,Observacion,TimeSys,IdUsuario
			 FROM @Trn_VehConductor
			 WHERE (IdVehiculo + Convert(varchar,(@item+1))) NOT IN(SELECT (IdVehiculo + Convert(varchar,Numero)) FROM Trn_VehConductor)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id VARCHAR (10)
			 declare @Numero int

			 SELECT @id = IdVehiculo, @item = Numero  FROM @Trn_VehConductor
			 DELETE FROM Trn_VehConductor WHERE IdVehiculo = @id and Numero = @item
		 END

		 IF(@operacion = 'i' or @operacion = 'u')
		 BEGIN
			 --Actualizar tabla de Vehiculos
			 UPDATE Vehiculos SET IdConductor = (SELECT IdCondNuevo FROM @Trn_VehConductor) WHERE IdVehiculo = (SELECT IdVehiculo FROM @Trn_VehConductor)
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehLecturas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_VehLecturas]
	@Trn_VehLecturas [dbo].[dataTypeTrn_VehLecturas] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 
		
		declare @tipo varchar(3)
		declare @item int
		declare @num int 

		SELECT @item = isnull(MAX(Item),0) FROM Trn_VehLecturas WHERE TipDoc = (select TipDoc from @Trn_VehLecturas) and IdCia = (select IdCia from @Trn_VehLecturas) and pVehiculo = (select pVehiculo from @Trn_VehLecturas) and Numero = (select Numero from @Trn_VehLecturas)
		
		if(@item = 0)
		begin
		 SELECT @num = MAX(Numero) + 1, @item = 1 FROM Trn_VehLecturas WHERE TipDoc = (select TipDoc from @Trn_VehLecturas) and IdCia = (select IdCia from @Trn_VehLecturas)
		end
		
		select @tipo = TipoUnidad from @Trn_VehLecturas

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Trn_VehLecturas
			 SET 
			 TipDoc = t2.TipDoc,Numero = t2.Numero,IdCia = t2.IdCia,
			 Item = t2.Item,Fecha = t2.Fecha,TipoUnidad = t2.TipoUnidad,
			 pVehiculo = t2.pVehiculo,KmsAnterior = t2.KmsAnterior,
			 KmsActual = t2.KmsActual,Kms2Anterior = t2.Kms2Anterior,
			 Kms2Actual = t2.Kms2Actual,TipoLectura = t2.TipoLectura,
			 Observacion = t2.Observacion,TimeSys = t2.TimeSys,
			 IdUsuario = t2.IdUsuario
		     FROM Trn_VehLecturas t1
			 JOIN @Trn_VehLecturas t2 ON t1.pVehiculo = t2.pVehiculo and t1.Numero = t2.Numero and t1.Item = t2.Item and t1.IdCia = t2.IdCia
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Trn_VehLecturas(
			 TipDoc,Numero,IdCia,Item,Fecha,TipoUnidad,pVehiculo,
			 KmsAnterior,KmsActual,Kms2Anterior,Kms2Actual,TipoLectura,
			 Observacion,TimeSys,IdUsuario
			 )
			 SELECT 
			 TipDoc,@num,IdCia,@item,Fecha,TipoUnidad,pVehiculo,
			 KmsAnterior,KmsActual,Kms2Anterior,Kms2Actual,TipoLectura,
			 Observacion,TimeSys,IdUsuario
			 FROM @Trn_VehLecturas
			 WHERE (pVehiculo + Convert(varchar,(@num)) + IdCia + Convert(varchar,@item)) NOT IN(SELECT (pVehiculo + Convert(varchar,Numero) + IdCia + Convert(varchar,Item)) FROM Trn_VehLecturas)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 SELECT @id = pVehiculo FROM @Trn_VehLecturas
			 DELETE FROM Trn_VehLecturas WHERE pVehiculo = @id and Numero = @num and Item = @item
		 END

		 IF(@operacion = 'u' or @operacion = 'i')
		 BEGIN
			if(@tipo = 'V')
			begin
			 --Actualizar la tabla Vehiculos
		     UPDATE Vehiculos SET KmActual = (Select KmsActual from @Trn_VehLecturas) FROM Vehiculos where IdVehiculo = (Select pVehiculo from @Trn_VehLecturas)
			end

			if(@tipo = 'R')
			begin
			 --Actualizar la tabla Veh-Remolques
		     UPDATE VehRemolq SET Kilmetraje = (Select KmsActual from @Trn_VehLecturas) FROM VehRemolq where IdRemque = (Select pVehiculo from @Trn_VehLecturas)
			end
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehNumOrden]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_VehNumOrden]
	@Trn_VehNumOrden [dbo].[dataTypeTrn_VehNumOrden] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Numero),0) FROM Trn_VehNumOrden WHERE IdVehiculo = (select IdVehiculo from @Trn_VehNumOrden)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Trn_VehNumOrden
			 SET 
			 IdVehiculo = t2.IdVehiculo,Numero = t2.Numero,Fecha = t2.Fecha,
			 NumOrden = t2.NumOrden,NuevoNum = t2.NuevoNum,Observacion = t2.Observacion,
			 TimeSys = t2.TimeSys,IdUsuario = t2.IdUsuario
		     FROM Trn_VehNumOrden t1
			 JOIN @Trn_VehNumOrden t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.Numero = t2.Numero 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Trn_VehNumOrden(
			 IdVehiculo,Numero,Fecha,NumOrden,NuevoNum,Observacion,TimeSys,IdUsuario
			 )
			 SELECT 
			 IdVehiculo,(@item+1),Fecha,NumOrden,NuevoNum,Observacion,TimeSys,IdUsuario
			 FROM @Trn_VehNumOrden
			 WHERE (IdVehiculo + Convert(varchar,(@item+1))) NOT IN(SELECT (IdVehiculo + Convert(varchar,Numero)) FROM Trn_VehNumOrden)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 SELECT @id = IdVehiculo, @item = Numero FROM @Trn_VehNumOrden
			 DELETE FROM Trn_VehNumOrden WHERE IdVehiculo = @id and Numero = @item
		 END

		 IF(@operacion = 'u' or @operacion = 'i')
		 BEGIN
		 --Actualizar la tabla Vehiculos
		     UPDATE Vehiculos SET NumVeh = (Select NuevoNum from @Trn_VehNumOrden), FechaUpdate = current_timestamp FROM Vehiculos where IdVehiculo = (Select IdVehiculo from @Trn_VehNumOrden)
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsTrn_VehTraspasos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsTrn_VehTraspasos]
	@Trn_VehTraspasos [dbo].[dataTypeTrn_VehTraspasos] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Numero),0) FROM Trn_VehTraspasos WHERE IdVehiculo = (select IdVehiculo from @Trn_VehTraspasos)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			PRINT 'A'
			 UPDATE Trn_VehTraspasos
			 SET 
				 IdVehiculo = t2.IdVehiculo,
				 Numero = t2.Numero,
				 Fecha = t2.Fecha,
				 IdPpd = t2.IdPpd,
				 IdPropietario = t2.IdPropietario,
				 IdPoseedor = t2.IdPoseedor,
				 IdPropNuevo = t2.IdPropNuevo,
				 IdPoseeNuevo = t2.IdPoseeNuevo,
				 IdNewPpd = t2.IdNewPpd,
				 IdGrupo = t2.IdGrupo,
				 VrComercial = t2.VrComercial,
				 VrCupo = t2.VrCupo,
				 VrAsegurado = t2.VrAsegurado,
				 Observacion = t2.Observacion,
				 TipoAfil = t2.TipoAfil,
				 TipoAfilNew = t2.TipoAfilNew,
				 TimeSys = t2.TimeSys,
				 IdUsuario = t2.IdUsuario
		     FROM Trn_VehTraspasos t1
			 JOIN @Trn_VehTraspasos t2 
				ON t1.IdVehiculo = t2.IdVehiculo 
				and t1.Numero = t2.Numero 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Trn_VehTraspasos(
			 IdVehiculo,Numero,Fecha,IdPpd,IdPropietario,IdPoseedor,
			 IdPropNuevo,IdPoseeNuevo,IdNewPpd,IdGrupo,VrComercial,VrCupo,
			 VrAsegurado,Observacion,TipoAfil,TipoAfilNew,TimeSys,IdUsuario
			 )
			 SELECT 
			 IdVehiculo,(@item+1),Fecha,IdPpd,IdPropietario,IdPoseedor,
			 IdPropNuevo,IdPoseeNuevo,IdNewPpd,IdGrupo,VrComercial,VrCupo,
			 VrAsegurado,Observacion,TipoAfil,TipoAfilNew,TimeSys,IdUsuario
			 FROM @Trn_VehTraspasos
			 WHERE (IdVehiculo + Convert(varchar,(@item+1))) NOT IN(SELECT (IdVehiculo + Convert(varchar,Numero)) FROM Trn_VehTraspasos)

			 UPDATE vehiculos 
			 SET IdPropietario = IdPropNuevo, IdPoseedor = IdPoseeNuevo,IdPpd = IdNewPpd
			 FROM vehiculos v
			 join @Trn_VehTraspasos vt on v.IdVehiculo = vt.IdVehiculo	
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 declare @num int
			 SELECT @id = IdVehiculo, @num = Numero FROM @Trn_VehTraspasos
			 DELETE FROM Trn_VehTraspasos WHERE IdVehiculo = @id and Numero = @num
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsUpdateEstadoItem]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsUpdateEstadoItem]
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
		BEGIN TRY		 

		UPDATE TE
		SET TE.EstadoItem = ISNULL(V.Estado, 'NOPROGRAMADA')
		FROM Trn_TraEspOrdenReservas TE
		LEFT JOIN (SELECT TipDocRes, Reserva, IdCiaRes, ItemRes, 'PROGRAMADA' as Estado FROM Trn_TraEspProgramaDet E JOIN Trn_TraEspPrograma P ON (E.TipDoc = P.TipDoc and E.Programa = P.Programa and E.IdCia = P.IdCia) WHERE E.Cumplido=1 and P.Anulado = 0) V 
		ON TE.TipRes = V.TipDocRes and TE.Reserva = V.Reserva and TE.IdCiaRes = V.IdCiaRes and TE.ItemRes = V.ItemRes

		--Actualizar las reservasdet al estado XLIQUIDAR, las que cumplan con la condiciÃ³n de que la fecha sea igual al dia actual
--Actualizar las reservasdet al estado XLIQUIDAR, las que cumplan con la condiciÃ³n de que la fecha sea igual al dia actual
  UPDATE TE
  SET TE.EstadoItem = 'XLIQUIDAR'
  FROM Trn_TraEspOrdenReservas TE
  JOIN Trn_TraEspResDetalle t1 ON TE.TipRes = t1.TipDoc and TE.Reserva = t1.Reserva and TE.IdCiaRes = t1.IdCia and TE.ItemRes = t1.Item
  JOIN Trn_TraEspProgramaDet t2 ON t1.TipDoc = t2.TipDocRes and t1.Reserva = t2.Reserva and t1.IdCia = t2.IdCiaRes and t1.Item = t2.ItemRes
  where (CURRENT_TIMESTAMP >= Convert(date,t1.FecDestino))

		UPDATE TE
		SET TE.EstadoItem = ISNULL(V.EstadoItemRes, 
		CASE WHEN V.EstadoItem='LIQUIDADA' then 
		'XLIQUIDAR' 
		WHEN V.ESTADOITEM='LIQUIDADA' AND V.ANULADO = 1 THEN 'XLIQUIDAR' ELSE V.Estado END)
		FROM Trn_TraEspOrdenReservas TE
		JOIN (SELECT R.TipRes, R.Reserva, R.IdCiaRes, R.ItemRes, 'FACTURADA' as Estado, R.EstadoItem,C.EstadoItemRes, F.ANULADO
		FROM Trn_TraEspFacReservas R
		JOIN TRN_FACTURAS AS F ON  R.TipDoc = F.TipDoc and R.Factura = F.Factura and R.idcia= R.idcia

		LEFT JOIN Trn_TraEspCumReservas C ON (R.TipRes = C.TipRes and R.Reserva = C.Reserva and R.IdCiaRes = C.IdCiaRes and R.ItemRes = C.ItemRes)) V 
		ON TE.TipRes = V.TipRes and TE.Reserva = V.Reserva and TE.IdCiaRes = V.IdCiaRes and TE.ItemRes = V.ItemRes

				SELECT * FROM Trn_TraEspOrdenReservas
				COMMIT TRAN
---ROLLBACK TRAN
		END TRY
        BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVeh_Contrato]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsVeh_Contrato]
	@Veh_Contrato [dbo].[dataTypeVeh_Contrato] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Veh_Contrato
			 SET 
			 NumContrato = t2.NumContrato, IdVehiculo = t2.IdVehiculo, IdAdmon = t2.IdAdmon,
			 IdTipCon = t2.IdTipCon, FecIngreso = t2.FecIngreso,FecRetiro = t2.FecRetiro, 
			 FecVigencia = t2.FecVigencia, Observaciones = t2.Observaciones, NumPagare = t2.NumPagare, 
			 ArchPagare = t2.ArchPagare, FecUpdate = t2.FecUpdate, IdUsuario = t2.IdUsuario 
		     FROM Veh_Contrato t1
			 JOIN @Veh_Contrato t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.NumContrato = t2.NumContrato
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Veh_Contrato(
			 NumContrato, IdVehiculo, IdAdmon, IdTipCon, FecIngreso, 
			 FecRetiro, FecVigencia, Observaciones, NumPagare, ArchPagare, 
			 FecUpdate, IdUsuario 
			 )
			 SELECT 
			 NumContrato, IdVehiculo, IdAdmon, IdTipCon, FecIngreso, 
			 FecRetiro, FecVigencia, Observaciones, NumPagare, ArchPagare, 
			 FecUpdate, IdUsuario  
			 FROM @Veh_Contrato
			 WHERE (IdVehiculo + Convert(varchar,NumContrato)) NOT IN(SELECT (IdVehiculo + Convert(varchar,NumContrato)) FROM Veh_Contrato)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 declare @num int
			 SELECT @id = IdVehiculo, @num = NumContrato FROM @Veh_Contrato
			 DELETE FROM Veh_Contrato WHERE IdVehiculo = @id and NumContrato = @num
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehConductores]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsVehConductores]
	@VehConductores [dbo].[dataTypeVehConductores] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Item),0) FROM VehConductores WHERE IdVehiculo = (select IdVehiculo from @VehConductores)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE VehConductores
			 SET 
			 IdVehiculo = t2.IdVehiculo,Item = t2.Item,CedConductor = t2.CedConductor,
			 TipoCond = t2.TipoCond,FechaIng = t2.FechaIng,EstadoCond = t2.EstadoCond
		     FROM VehConductores t1
			 JOIN @VehConductores t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.Item = t2.Item 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO VehConductores(
			 IdVehiculo,Item,CedConductor,TipoCond,FechaIng,EstadoCond
			 )
			 SELECT 
			 IdVehiculo,(@item+1),CedConductor,TipoCond,FechaIng,1
			 FROM @VehConductores
			 WHERE (IdVehiculo + Convert(varchar,(@item+1))) NOT IN(SELECT (IdVehiculo + Convert(varchar,Item)) FROM VehConductores)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 SELECT @id = IdVehiculo FROM @VehConductores
			 DELETE FROM VehConductores WHERE idvehiculo = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehiculos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsVehiculos]
	@Vehiculos [dbo].[dataTypeVehiculos] READONLY,
	@VehAnexo [dbo].[dataTypeVehAnexo] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE Vehiculos
			 SET 
			 IdVehiculo = t2.IdVehiculo, NumVeh = t2.NumVeh, ClaseVeh = t2.ClaseVeh, IdTipoVeh = t2.IdTipoVeh, IdMarca = t2.IdMarca, IdLinea = t2.IdLinea,
			 IdColor = t2.IdColor, IdTipoMot = t2.IdTipoMot, IdCrceria = t2.IdCrceria,  Modelo = t2.Modelo, FecRep = t2.FecRep, Config = t2.Config,
			 VehArtic = t2.VehArtic, NumLlan = t2.NumLlan, NumLlans = t2.NumLlans, IdCat = t2.IdCat, CdCatv = t2.CdCatv, ClaseMat = t2.ClaseMat,
			 Cilind = t2.Cilind, CapTanq = t2.CapTanq, IdCom = t2.IdCom, IdLub = t2.IdLub, IdTlla = t2.IdTlla, IdMarlla = t2.IdMarlla,
			 PesoVacio = t2.PesoVacio, PesoMax = t2.PesoMax, NumMotor = t2.NumMotor, SerieChasis = t2.SerieChasis, NumSerie = t2.NumSerie, CdRemque = t2.CdRemque,
			 Longitud = t2.Longitud, CarrAlto = t2.CarrAlto, CarrAncho = t2.CarrAncho,  CarrLargo = t2.CarrLargo, CarrCapac = t2.CarrCapac, UndCapc = t2.UndCapc,
			 Comptmtos = t2.Comptmtos, CapComp = t2.CapComp, PasjerosPie = t2.PasjerosPie, PasjerosSen = t2.PasjerosSen, NitEmpresa = t2.NitEmpresa, IdPropietario = t2.IdPropietario,
			 IdPoseedor = t2.IdPoseedor, IdConductor = t2.IdConductor, IdPpd = t2.IdPpd, TipoAfil = t2.TipoAfil, Adquisc = t2.Adquisc, NitProv = t2.NitProv, 
			 FecCompra = t2.FecCompra, VrComcial = t2.VrComcial, VrAseg = t2.VrAseg, VrAvaludo = t2.VrAvaludo, VidaUtil = t2.VidaUtil, FecSalida = t2.FecSalida, 
			 NContrato = t2.NContrato, IdAdmon = t2.IdAdmon, IdNiv = t2.IdNiv, IdGrupo = t2.IdGrupo, CdGrupR = t2.CdGrupR, CdTarifa = t2.CdTarifa, 
			 FecIngreso = t2.FecIngreso, FecVigencia = t2.FecVigencia, FecRetiro = t2.FecRetiro, NumSoat = t2.NumSoat, FecSoat = t2.FecSoat, VigSoat = t2.VigSoat, 
			 NitEmpSoat = t2.NitEmpSoat, TarjProp = t2.TarjProp, FecTProp = t2.FecTProp, VigTProp = t2.VigTProp, CdLugTp = t2.CdLugTp, Ulttramite = t2.Ulttramite, 
			 RespCivil = t2.RespCivil, FecRCivil = t2.FecRCivil, VigRCivil = t2.VigRCivil, RegNalCarga = t2.RegNalCarga, FecRegNal = t2.FecRegNal, VigRegNal = t2.VigRegNal, 
			 RevTecMec = t2.RevTecMec, FecTecMec = t2.FecTecMec, VigTecMec = t2.VigTecMec, CertGases = t2.CertGases, FecCertGas = t2.FecCertGas, VigCertGas = t2.VigCertGas, 
			 TarjOper = t2.TarjOper, FecTarjOper = t2.FecTarjOper, VigTarjOper = t2.VigTarjOper, KmInicial = t2.KmInicial, KmActual = t2.KmActual, Km2Actual = t2.Km2Actual, 
			 Regtradora = t2.Regtradora, CentInicial = t2.CentInicial, CentFinal = t2.CentFinal, VrLmtCred = t2.VrLmtCred, VrSaldoAct = t2.VrSaldoAct, Descripcion = t2.Descripcion, 
			 Observacion = t2.Observacion, CdCenSer = t2.CdCenSer, CdLocal = t2.CdLocal, Ubicacion = t2.Ubicacion, PathFoto = t2.PathFoto, FecPriServ = t2.FecPriServ, 
			 FecUltServ = t2.FecUltServ,FecUltAcc = t2.FecUltAcc,TieneAcc = t2.TieneAcc, FecPagImp = t2.FecPagImp, IdEstado = t2.IdEstado, Inactivo = t2.Inactivo, 
			 FechaAdd = t2.FechaAdd, FechaUpdate = t2.FechaUpdate, IdUsuario = t2.IdUsuario, ValorCupo = t2.ValorCupo, ObligaTProd = t2.ObligaTProd, GarantiaAcc = t2.GarantiaAcc, 
			 DocCompleta = t2.DocCompleta, CertMovilizacion = t2.CertMovilizacion, FecCertMovil = t2.FecCertMovil, VigCertMovil = t2.VigCertMovil, CdRutaHab = t2.CdRutaHab, 
			 DeclaracImp = t2.DeclaracImp, TipoIngreso = t2.TipoIngreso, IdOrgTra = t2.IdOrgTra, GPSoperador = t2.GPSoperador,  GPSUsuario = t2.GPSUsuario, GPSClave = t2.GPSClave,
			 CantFiltros = t2.CantFiltros,GPSIdOper=t2.GPSIdOper,LiqFletePropio=t2.LiqFletepropio
			 FROM Vehiculos t1
			 JOIN @Vehiculos t2 ON t1.Idvehiculo = t2.IdVehiculo
			 where t1.IdVehiculo = t2.IdVehiculo

			 UPDATE VehAnexo
			 SET 
			 IdVehiculo = t2.IdVehiculo,
			 PolizaRCE = t2.PolizaRCE,
			 FecEmisionRCE = t2.FecEmisionRCE,
			 FecVigenciaRCE = t2.FecVigenciaRCE,
			 appPyP = t2.appPyP
			 FROM VehAnexo t1
			 JOIN @VehAnexo t2 ON t1.Idvehiculo = t2.IdVehiculo
			 where t1.IdVehiculo = t2.IdVehiculo
			 --Inserta los que no existen
			 INSERT INTO VehAnexo(
			 IdVehiculo,PolizaRCE,FecEmisionRCE,FecVigenciaRCE,appPyP
	         ) 
			 SELECT 
			 IdVehiculo,PolizaRCE,FecEmisionRCE,FecVigenciaRCE,appPyP
			 FROM @VehAnexo
			 WHERE IdVehiculo NOT IN(SELECT IdVehiculo FROM VehAnexo)
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO Vehiculos(
			 IdVehiculo,NumVeh,ClaseVeh,IdTipoVeh,IdMarca,IdLinea,IdColor,IdTipoMot,IdCrceria,Modelo,FecRep,Config,VehArtic,NumLlan,
			 NumLlans,IdCat,CdCatv,ClaseMat,Cilind,CapTanq, IdCom,IdLub,IdTlla,IdMarlla,PesoVacio,PesoMax,
			 NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,
			 PasjerosPie,PasjerosSen,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,IdPpd,TipoAfil,Adquisc,NitProv,FecCompra,VrComcial,
			 VrAseg,VrAvaludo,VidaUtil,FecSalida,NContrato,IdAdmon,IdNiv,IdGrupo,CdGrupR,CdTarifa,FecIngreso,FecVigencia,
			 FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,TarjProp,FecTProp,VigTProp,CdLugTp,Ulttramite,RespCivil,FecRCivil,
			 VigRCivil,RegNalCarga,FecRegNal,VigRegNal,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,
			 VigTarjOper,KmInicial,KmActual,Km2Actual,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,Descripcion,Observacion,CdCenSer,
			 CdLocal,Ubicacion,PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,IdEstado,Inactivo,FechaAdd,FechaUpdate,
			 IdUsuario,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil,CdRutaHab,DeclaracImp,TipoIngreso,IdOrgTra,
			 GPSoperador,GPSUsuario,GPSClave, CantFiltros,GPSIdOper,LiqFletePropio
			 )
			 SELECT 
			 IdVehiculo,NumVeh,ClaseVeh,IdTipoVeh,IdMarca,IdLinea,IdColor,IdTipoMot,IdCrceria,Modelo,FecRep,Config,VehArtic,NumLlan,
			 NumLlans,IdCat,CdCatv,ClaseMat,Cilind,CapTanq, IdCom,IdLub,IdTlla,IdMarlla,PesoVacio,PesoMax,
			 NumMotor,SerieChasis,NumSerie,CdRemque,Longitud,CarrAlto,CarrAncho,CarrLargo,CarrCapac,UndCapc,Comptmtos,CapComp,
			 PasjerosPie,PasjerosSen,NitEmpresa,IdPropietario,IdPoseedor,IdConductor,IdPpd,TipoAfil,Adquisc,NitProv,FecCompra,VrComcial,
			 VrAseg,VrAvaludo,VidaUtil,FecSalida,NContrato,IdAdmon,IdNiv,IdGrupo,CdGrupR,CdTarifa,FecIngreso,FecVigencia,
			 FecRetiro,NumSoat,FecSoat,VigSoat,NitEmpSoat,TarjProp,FecTProp,VigTProp,CdLugTp,Ulttramite,RespCivil,FecRCivil,
			 VigRCivil,RegNalCarga,FecRegNal,VigRegNal,RevTecMec,FecTecMec,VigTecMec,CertGases,FecCertGas,VigCertGas,TarjOper,FecTarjOper,
			 VigTarjOper,KmInicial,KmActual,Km2Actual,Regtradora,CentInicial,CentFinal,VrLmtCred,VrSaldoAct,Descripcion,Observacion,CdCenSer,
			 CdLocal,Ubicacion,PathFoto,FecPriServ,FecUltServ,FecUltAcc,TieneAcc,FecPagImp,IdEstado,Inactivo,FechaAdd,FechaUpdate,
			 IdUsuario,ValorCupo,ObligaTProd,GarantiaAcc,DocCompleta,CertMovilizacion,FecCertMovil,VigCertMovil,CdRutaHab,DeclaracImp,TipoIngreso,IdOrgTra,
			 GPSoperador,GPSUsuario,GPSClave, CantFiltros,GPSIdOper,LiqFletePropio
			 FROM @Vehiculos
			 WHERE IdVehiculo NOT IN(SELECT IdVehiculo FROM Vehiculos)

			 INSERT INTO VehAnexo(
			 IdVehiculo,PolizaRCE,FecEmisionRCE,FecVigenciaRCE,appPyP
			 )
			 SELECT 
			 IdVehiculo,PolizaRCE,FecEmisionRCE,FecVigenciaRCE,appPyP
			 FROM @VehAnexo
			 WHERE IdVehiculo NOT IN(SELECT IdVehiculo FROM VehAnexo)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id VARCHAR (10)
			 SELECT @id = IdVehiculo FROM @Vehiculos
			 DELETE FROM VehAnexo WHERE IdVehiculo = @id
			 DELETE FROM Vehiculos WHERE IdVehiculo = @id
		 END

	SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehPolizas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsVehPolizas]
	@VehPolizas [dbo].[dataTypeVehPolizas] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE VehPolizas
			 SET 
			 IdVehiculo = t2.IdVehiculo,IdClase = t2.IdClase,Numero = t2.Numero,
			 FecEmision = t2.FecEmision,FecVigencia = t2.FecVigencia,
			 NitCompania = t2.NitCompania,Valor = t2.Valor,Comntarios = t2.Comntarios,
			 DiasAviso = t2.DiasAviso
		     FROM VehPolizas t1
			 JOIN @VehPolizas t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.IdClase = t2.IdClase 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN
			 INSERT INTO VehPolizas(
			 IdVehiculo,IdClase,Numero,FecEmision,
			 FecVigencia,NitCompania,Valor,
			 Comntarios,DiasAviso
			 )
			 SELECT 
			 IdVehiculo,IdClase,Numero,FecEmision,
			 FecVigencia,NitCompania,Valor,
			 Comntarios,DiasAviso
			 FROM @VehPolizas
			 WHERE (IdVehiculo + IdClase) NOT IN(SELECT (IdVehiculo + IdClase) FROM VehPolizas)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 DECLARE @idcl varchar(4)
			 SELECT @id = IdVehiculo, @idcl = IdClase FROM @VehPolizas
			 DELETE FROM VehPolizas WHERE idvehiculo = @id and IdClase = @idcl
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeInsVehPropietarios]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeInsVehPropietarios]
	@VehPropietarios [dbo].[dataTypeVehPropietarios] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 

		declare @item int 
		SELECT @item = isnull(MAX(Item),0) FROM VehPropietarios WHERE IdVehiculo = (select IdVehiculo from @VehPropietarios)

		--UPDATE SI-EXISTE RECORDS
		 IF(@operacion = 'u')
		 BEGIN
			 UPDATE VehPropietarios
			 SET 
			 IdVehiculo = t2.IdVehiculo,Item = t2.Item,NitPropietario = t2.NitPropietario,
			 PorcPartic = t2.PorcPartic,FechaIng = t2.FechaIng,EstadoProp = t2.EstadoProp
		     FROM VehPropietarios t1
			 JOIN @VehPropietarios t2 ON t1.IdVehiculo = t2.IdVehiculo and t1.Item = t2.Item 
		 END
 
		 --INSERT NO-EXISTE RECORDS
		 IF(@operacion = 'i')
		 BEGIN			 
			 INSERT INTO VehPropietarios(
			 IdVehiculo,Item,NitPropietario,PorcPartic,FechaIng,EstadoProp
			 )
			 SELECT 
			 IdVehiculo,(@item + 1),NitPropietario,PorcPartic,FechaIng,EstadoProp
			 FROM @VehPropietarios
			 WHERE (IdVehiculo + Convert(varchar,(@item+1)))NOT IN(SELECT (IdVehiculo + Convert(varchar,Item)) FROM VehPropietarios)
		 END

		 --DELETE RECORDS
		 IF(@operacion = 'd')
		 BEGIN
			 DECLARE @id varchar(10)
			 SELECT @id = IdVehiculo FROM @VehPropietarios
			 DELETE FROM VehPropietarios WHERE IdVehiculo = @id and Item = @item
		 END

		SELECT '1'

	COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLis_DirTe]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLis_DirTe]
WITH EXECUTE AS CALLER
AS
SELECT '' as IdDTE, '' as Descripcion
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLis_NovPgr]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLis_NovPgr]
WITH EXECUTE AS CALLER
AS
SELECT '' AS IdNovedad, '' AS Novedad, '' AS Tipo, '' AS IdEstado,CAST('' AS BIT) AS Inactivo
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLis_VehiculosPza]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLis_VehiculosPza]
WITH EXECUTE AS CALLER
AS
SELECT  '' AS IdVehiculo,'' AS NumVeh, '' AS ClaseVeh, '' AS IdTipoVeh,'' AS TipoVehiculo, '' AS IdMarca, '' AS Marca, ''AS IdLinea,
'' AS LineaVeh, '' AS IdColor, '' AS NomColor, '' AS IdTipoMot, '' AS TipoMotor, '' AS IdCrceria, '' AS TipoCar, '' AS Modelo,
CAST('' AS datetime) AS FecRep, '' AS Config, CAST ('' AS BIT) AS VehArtic, CAST ('' AS INT) AS NumLlan, CAST ('' AS INT) AS NumLlans,
'' AS IdCat, '' AS Catpeaje, '' AS CdCatv, '' AS ClaseMat, '' AS Cilind, '' AS CapTanq, '' AS IdCom, '' AS TipoComb, '' AS IdLub,
'' AS TipoLub, '' AS IdTlla, '' AS TipoLlanta, '' AS IdMarlla, '' AS MarcaLlantas, '' AS PesoVacio, '' AS PesoMax, '' AS NumMotor,
'' AS SerieChasis, '' AS NumSerie, '' AS CdRemque, '' AS Longitud, '' AS CarrAlto,'' AS CarrAncho,'' AS CarrLargo, '' AS CarrCapac,
'' AS UndCapc, CAST ('' AS INT) AS Comptmtos, '' AS CapComp, CAST('' AS INT) AS PasjerosPie, CAST('' AS INT) AS PasjerosSen, '' AS NitEmpresa,
'' AS Empresa, '' AS IdPropietario, '' AS Propietario, '' AS IdPoseedor,'' AS Poseedor, '' AS IdConductor, '' AS Conductor, '' AS IdPpd, '' AS TipoProp, 
CAST('' AS BIT) AS VehPropio, '' AS Adquisc, '' AS NitProv, '' AS Proveedor, CAST('' AS datetime) AS FecCompra, CAST('' AS money) AS VrComcial, CAST('' AS money) AS  VrAseg,
CAST('' AS money) AS VrAvaludo, CAST('' AS INT) AS VidaUtil, CAST('' AS datetime) AS FecSalida, CAST('' AS INT) AS NContrato, '' AS IdAdmon, '' AS TipoAdmon, '' AS IdNiv, 
'' AS NivelServicio, '' AS IdGrupo, '' AS GrupoProp, '' AS CdGrupR, '' AS CdTarifa, CAST('' AS datetime) AS FecIngreso, CAST('' AS datetime) AS FecVigencia, 
CAST('' AS datetime) AS FecRetiro, '' AS NumSoat, CAST('' AS datetime) AS FecSoat, CAST('' AS datetime) AS VigSoat, '' AS NitEmpSoat,
'' AS CiaAsegurdora, '' AS TarjProp, CAST('' AS datetime) AS FecTProp, CAST('' AS datetime) AS VigTProp, '' AS CdLugTp, '' AS LugarTarjProp,
'' AS Ulttramite, '' AS RespCivil, CAST('' AS datetime) AS FecRCivil, CAST('' AS datetime) AS VigRCivil, '' AS RegNalCarga,
CAST('' AS datetime) AS FecRegNal, CAST('' AS datetime) AS VigRegNal, '' AS KmInicial, '' AS KmActual, '' AS Km2Actual, '' AS Descripcion,
''AS Observacion, '' AS CdCenSer, '' AS CentroServ, '' AS CdLocal, '' AS CiuUbicacion, '' AS CodDpto, '' AS Departamento, '' AS Ubicacion,
CAST('' AS datetime) AS FecPriServ, CAST('' AS datetime) AS FecUltServ, '' AS Regtradora, '' AS CentInicial, '' AS CentFinal, 
CAST('' AS money) AS VrLmtCred,  CAST('' AS money) AS VrSaldoAct,  CAST('' AS datetime) AS FecUltAcc, CAST('' AS BIT) AS TieneAcc, 
CAST('' AS datetime) AS FecPagImp, '' AS IdEstado, '' AS Estado,  CAST('' AS BIT) AS Inactivo, '' AS IdUsuario, '' AS Usuario,
CAST('' AS datetime) AS FechaAdd, CAST('' AS datetime) AS FechaUpdate, '' AS NColor, CAST('' AS BIT) AS OutDemand, '' AS TipoAfil,
'' AS RevTecMec, CAST('' AS datetime) AS FecTecMec, CAST('' AS datetime) AS VigTecMec, '' AS CertGases, CAST('' AS datetime) AS FecCertGas,
CAST('' AS datetime) AS VigCertGas, '' AS TarjOper, CAST('' AS datetime) AS FecTarjOper, CAST('' AS datetime) AS VigTarjOper , '' AS Licencia,
'' AS LugarLic, '' AS CatLicencia, CAST('' AS datetime) AS VigLicencia,
--informaciÃ³n de polizas
'' AS IdClase, '' AS ClasePoliza, '' AS Numero, CAST('' AS datetime) AS FecEmision, CAST('' AS datetime) AS FecVencePoliza, '' AS NitCompania, 
'' AS NombreCia, CAST('' AS money) AS Valor, '' AS Comntarios, CAST('' AS INT) AS DiasAviso, '' AS PolizaRCE, CAST('' AS datetime) AS FecEmisionRCE,
CAST('' AS datetime) AS FecVigenciaRCE
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Cesar Fernando Carre?o 
-- Create date: 04/01/2024
-- Description:	Metodo para cargar tabla temporal 
-- =============================================
CREATE PROCEDURE [dbo].[paWcfSeLisTm_TraEspTempCargarDetCons]	
	@Usuario varchar(20)
AS
	set @Usuario = (
		select 'CCD' + IdEstacion as Estacion 
		from adm_Usuarios 
		where IdUsuario = @Usuario
	)
BEGIN
	select 
		[TipDoc],
		[Causacion],
		[IdCia],
		[Item],
		[IdConcepto],
		[Descripcion],
		[TipoConc],
		[VrDebito],
		[VrCredito],
		[CdCuenta],
		[NitTercero],
		[RazonSocial],
		[CdCCosto],
		[CCosto],
		[CdSubCos],
		[SubCosto],
		[pVehiculo],
		[NumVeh],
		[ClaseMat],
		[TipoAfiVehic],
		[VrBase],
		[TarifBase],
		[Referencia],
		[TipDocRef],
		[DocRef],
		[TipFac],
		[Factura],
		[IdCiaFac],
		[ItemFac],
		[FecVence],
		[EstadoReg],
		[TipoLiq],
		[NumLiquida],
		[CiaLiquida],
		[VrAbonado] 
	from 
		tm_TraEsDetConc 
	where 
		TmNumero = @Usuario
	 
	DELETE FROM [dbo].[tm_TraEsDetConc]
	WHERE TmNumero = @Usuario

END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTm_TraEspTempDetCons]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Cesar Fernando Carre?o 
-- Create date: 04/01/2024
-- Description:	Metodo para cargar tabla temporal 
-- =============================================
CREATE PROCEDURE [dbo].[paWcfSeLisTm_TraEspTempDetCons]    
   @temp dbo.wcfItm_TraEsDetConc READONLY,
	@Usuario varchar(20)
AS

BEGIN
set @Usuario = (select 'CCD' + IdEstacion as Estacion from adm_Usuarios where IdUsuario = @Usuario)

INSERT INTO [dbo].[tm_TraEsDetConc]
          ([TmNumero]
           ,[TipDoc]
           ,[Causacion]
           ,[IdCia]
           ,[Item]
           ,[IdConcepto]
           ,[Descripcion]
           ,[TipoConc]
           ,[VrDebito]
           ,[VrCredito]
           ,[CdCuenta]
           ,[NitTercero]
           ,[RazonSocial]
           ,[CdCCosto]
           ,[CCosto]
           ,[CdSubCos]
           ,[SubCosto]
           ,[pVehiculo]
           ,[NumVeh]
           ,[ClaseMat]
           ,[TipoAfiVehic]
           ,[VrBase]
           ,[TarifBase]
           ,[Referencia]
           ,[TipDocRef]
           ,[DocRef]
           ,[TipFac]
           ,[Factura]
           ,[IdCiaFac]
           ,[ItemFac]
           ,[FecVence]
           ,[EstadoReg]
           ,[TipoLiq]
           ,[NumLiquida]
           ,[CiaLiquida]
           ,[VrAbonado])
     SELECT @Usuario           
           ,TipDoc
           ,0 
           ,[IdCia]
           ,CAST(Item AS INT)
		   --,0
           ,[IdConcepto]
           ,[Descripcion]
           ,[TipoConc]
           ,CAST(VrDebito AS decimal(18, 4))
           ,CAST(VrCredito AS decimal(18, 4))
		   --,0
		   --,0
           ,[CdCuenta]
           ,[NitTercero]
           ,[RazonSocial]
           ,[CdCCosto]
           ,[CCosto]
           ,[CdSubCos]
           ,[SubCosto]
           ,[pVehiculo]
           ,[NumVeh]
           ,[ClaseMat]
           ,[TipoAfiVehic]
           --,CAST(VrBase AS decimal(18, 4))
           --,CAST(TarifBase AS decimal(18, 4))
		   ,0
		   ,0
           ,[Referencia]
           ,[TipDocRef]
           ,CAST(DocRef AS INT)
		   --,0
           ,[TipFac]
           ,[Factura]
           ,[IdCiaFac]
           ,CAST(ItemFac AS INT)
		   --,0
           ,[FecVence]
		   --,null
           ,0
           ,[TipoLiq]
           ,0
           ,[CiaLiquida]
           ,0
		   FROM @temp
		   			 
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspAntAbonos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspAntAbonos]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Documento,'' AS IdCia, CAST('' AS INT) AS Item, CAST('' AS datetime) AS Fecha, '' AS TipAnt, CAST('' AS INT) AS Anticipo,
'' AS IdCiaAnt, CAST('' AS Money) AS VrAbono,  CAST('' AS Money) AS VrAnticipo, CAST('' AS Money) AS VrAbonado, CAST ('' AS Money) AS VsSaldo,
''AS  TipoAplica, ''AS Detalle, '' AS CdCuentaAnt, '' AS Observacion, '' AS IdVehiculo

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspAnticiposRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspAnticiposRel]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT '' AS TipDoc, CAST('' AS INT) AS Anticipo, '' AS IdCia, '' AS Compania, CAST('' AS datetime) AS Fecha, '' AS IdConcepto, '' AS TipRes, 
CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, '' AS IdVehiculo, '' AS IdPoseedor,'' AS NomPoseedor, '' AS IdConductor,
'' AS NomConductor, CAST('' AS Money) AS VrAnticipo, CAST('' AS Money) AS VrAbonado,  CAST('' AS Money) AS VrSaldo, '' AS Modalidad, '' AS TipoPago,
'' AS NumCheque, CAST('' AS datetime) AS FecCheque, '' AS IdCta, '' AS NumeroCta, '' AS IdBanco, '' AS Banco, '' AS IdCuenta, '' AS Beneficiario,
'' AS CedBenef, CAST('' AS INT) AS  Cantidad, CAST('' AS datetime) AS FechaVence, CAST('' AS INT) AS  NumPresAnt, '' AS TipCom, CAST('' AS INT) AS  Comprobante,
'' AS IdCiaCom, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS datetime) AS FecDev, '' AS Observacion, '' AS IdEstado, '' AS Estado,
'' AS OrigenAdd, CAST('' AS datetime) AS TimeSys, CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario, CAST('' AS INT) AS PreAnticipo
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCauRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCauRel]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT CAST('' AS INT) AS Causacion, '' AS CdCia, '' AS Compania, CAST('' AS datetime) AS Fecha, '' AS CdConcepto, '' AS Concepto, '' AS IdProv,
'' AS RazonSocial, '' AS Factura, CAST('' AS Money) AS VrTotal, CAST('' AS Money) AS VrOtros, CAST('' AS Money) AS VrNeto, '' AS TipCom,
CAST('' AS INT) AS  Comprobante, '' AS IdCiaCom, CAST('' AS BIT) AS  Anulado, CAST('' AS INT) AS NumDev, CAST('' AS datetime) AS FecDev,
'' AS  Observacion,  '' AS CdEstado, '' AS OrigenAdd, CAST('' AS datetime) AS TimeSys, CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,
'' AS CdUsuario, '' AS Usuario
           
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCauRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCauRelDet]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
--Detalle de CCE
SELECT '' as TipCau, CAST('' AS INT) AS NumCausac, '' AS CdCia, '' AS Compania, CAST('' AS INT) AS Item, '' AS CdConcCausac, '' AS ConcCausac, '' AS DetDescripcion,
'' AS TipConcept, CAST('' AS Money) AS VrDebito, CAST('' AS Money) AS VrCredito, '' AS CdCuenta, '' AS NomCuenta, '' AS pVehiculo, '' AS NitTercero,
'' AS Razon_Social, '' AS CdCCosto, '' AS CCosto, '' AS CdSubCos, '' AS SubCosto, '' AS TipoAfiVehic,  CAST('' AS Money) AS VrBase, 
CAST(@VrDef AS DECIMAL(14,4)) AS  TarifBase, '' AS TipDocRef, CAST('' AS INT) AS DocRef, '' AS TipFac, '' AS DetFactura, '' AS IdCiaFac,
CAST('' AS INT) AS ItemFac, CAST('' AS DATETIME) AS FecVence,  CAST('' AS INT) AS NumLiquida, '' AS CiaLiquida, CAST('' AS Money) AS VrAbonado,
CAST('' AS INT) AS EstadoReg
END        
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCausacionLiq]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCausacionLiq]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
 --CONSULTA PARA TRAER OTROS PAGOS QUE SE REALIZARON EN LA LIQUIDACION
'' AS TipDoc, CAST('' AS INT) AS Causacion, '' AS IdCia, CAST('' AS DATETIME) AS Fecha, CAST('' AS DATETIME) AS FecVence, ''AS IdProv,
'' AS IdConcepto, '' AS Descripcion, '' AS TipoConc, CAST('' AS MONEY) AS VrCredito, '' AS CdCuenta, '' AS NitTercero, '' AS pVehiculo, 
'' AS TipoAfiVehic, '' AS TipFac, ''AS Factura, '' AS IdCiaFac, CAST('' AS INT) AS ItemFac, ''AS TipCom, CAST('' AS INT) AS Comprobante,
'' AS IdCiaCom, CAST('' AS INT) AS  Item, CAST('' AS BIT) AS EsEgreso, '' AS DetAbono, CAST('' AS DATETIME) AS FecEgr, CAST('' AS MONEY) AS VrAbono,
'' AS TipLiq, CAST('' AS INT) AS  Liquidacion, '' AS IdCiaLiq, CAST('' AS DATETIME) AS  FecIniOdp, CAST('' AS DATETIME) AS  FecFinOdp
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspComFacturaNit]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspComFacturaNit]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipFac, CAST('' AS INT) AS Factura, '' AS IdCia, CAST('' AS INT) AS Item,  CAST('' AS MONEY) AS  ValorSaldo, CAST('' AS MONEY) AS VrFactura,
CAST('' AS MONEY) AS VrAbonado, '' AS  TipDoc,  '' AS Documento, '' AS IdCiaDoc, '' AS TipRef, '' AS DocRef, '' AS IdCiaRef, CAST('' AS DATETIME) AS FecEmision,
CAST('' AS DATETIME) AS FecVence, '' AS IdCuent, '' AS NomCuenta, '' AS TipCom,CAST('' AS INT) AS Comprobante, CAST('' AS INT) AS ItemCom, '' AS Referencia,
'' AS Detalle, '' AS IdProveedor, '' AS RazonSocial, '' AS pVehiculo, '' AS VehPropio, CAST('' AS INT) EstadoApr, CAST('' AS MONEY) AS MontoAprob
 END


GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspContratoFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspContratoFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
--Encabezado
'' AS TipDoc, CAST('' AS INT) AS Contrato, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, CAST('' AS DATETIME) AS FechaInicio, CAST('' AS DATETIME) AS FechaFin,
'' AS IdCliente, '' AS RazonSocial, '' AS UnionTemporal, '' AS IdAgencia, '' AS Agencia, '' AS IdVend, '' AS NomVendedor,'' AS IdTarifCom, '' AS IdForma, CAST('' AS BIT) AS Plazos,
'' AS  TipoPago, '' AS Modalidad, '' AS TipoLiquid, '' AS CodTarRet, '' AS CodTarIca, CAST('' AS MONEY) AS  VrPresupuesto, CAST('' AS MONEY) AS  VrSaldoPresup, CAST('' AS MONEY) AS  VrCobro,
CAST('' AS MONEY) AS  VrCargos, CAST('' AS MONEY) AS  VrRetencion, CAST('' AS MONEY) AS  VrReteIca, CAST('' AS MONEY) AS  VrDctos, CAST('' AS MONEY) AS VrIva, '' AS CdDescuento,
CAST(@VrDef AS DECIMAL(14,4)) AS Cantidad, CAST(@VrDef AS DECIMAL(14,4)) AS CantPasajeros, '' AS IdMneda, '' AS Mneda, CAST(@VrDef AS DECIMAL(14,4)) AS Peso, CAST('' AS INT) AS NumAprob,
''AS IdCiaApr, CAST('' AS DATETIME) AS FecAprob, '' AS TipOdp, CAST('' AS INT) AS NumOdp, ''AS IdCiaOdp, CAST('' AS DATETIME) AS FechaOdp, '' AS TipFac, CAST('' AS INT) AS Factura, 
''AS IdCiaFac, CAST('' AS DATETIME) AS FechaFac, '' AS OrigenAdd, CAST('' AS BIT) AS EsLicitacion, CAST('' AS BIT) AS Anulado, CAST('' AS DATETIME) AS FecDev, '' AS Observacion,
'' AS IdEstado, '' AS  Estado, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario, '' AS CdCarga,  '' AS IdGrupo,
'' AS Grupo, '' AS IdRutaG, '' AS RutaG,
-- Datos de anexo
'' AS TipContrato, '' AS IdContrato, '' AS IdObjCOE, '' AS ObjContrato, '' AS NomCliente, '' AS TelCliente, '' AS emlCliente, '' AS DireccionCli, '' AS Observacion, '' AS NombArchivo, 
'' AS DescripCarga, '' AS Clausulas,  '' AS Responsable, '' AS NombreResp,
--Datos de detalles
CAST('' AS INT) AS Item, '' AS IdHorario, '' AS TipPed, CAST('' AS INT) AS Pedido, '' AS CiaPed, CAST('' AS INT) AS ItemPed, '' AS IdVehiculo, '' AS CdTipVeh, '' AS TipoVehiculo,
CAST('' AS INT) AS NumPasajeros, CAST(@VrDef AS DECIMAL(14,4)) AS PesoNeto, CAST('' AS MONEY) AS VrUnitario, CAST('' AS MONEY) AS VrPago, '' AS IdRuta, '' AS Ruta,
'' AS Referencia1, '' AS Referencia2, ''AS Referencia3, CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' AS CiuOrigenD, '' AS DeptOrigen, '' AS DirOrigen, CAST('' AS DATETIME) AS FecOrigen,
'' AS CdCiuDestino, '' AS  CiuDestinoD, '' AS  DeptDestino, '' AS DirDestino, CAST('' AS DATETIME) AS FecDestino, CAST('' AS INT) AS DiasDisp, CAST('' AS MONEY) AS  VrDia, '' AS Parada,
'' AS CdTipRuta, '' AS CdTipServicio, '' AS TipRes, CAST('' AS INT) AS NumRes, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS INT) AS Cantveh, CAST('' AS BIT) AS Retorno,
CAST('' AS MONEY) AS VrMonitor, CAST('' AS INT) AS CantMonitor, CAST('' AS MONEY) AS VrMaxRec, CAST('' AS INT) AS NumDias, '' AS TipoTarifa,  '' AS IdColegio, '' AS NomColegio, '' AS Codigo,
'' AS Itinerario, CAST('' AS BIT) AS VLargo, CAST('' AS INT) AS IdOtroSi,  CAST('' AS BIT) AS ItemAnuladoOS, CAST('' AS BIT) AS ProcEstudte,
--Datos de conceptos
'' AS TipDocC, CAST('' AS INT) AS DocumentoC, '' AS IdCiaC, CAST('' AS INT) AS Itemc, '' AS Descripcion, CAST(@VrDef AS DECIMAL(14,4)) AS Tarifa, '' AS TipoConc, '' AS RubroConcep, CAST('' AS INT) AS Cantidadc,
CAST('' AS MONEY) AS VrUnitarioc, CAST(@VrDef AS DECIMAL(14,4)) AS TarifIva, '' AS IdConcepto, '' AS CdCuenta, '' AS NitTercero, '' AS  NombreTerc, '' AS CdTipoEscc, '' AS TipEsc, CAST('' AS DATETIME) AS FechaNov, 
CAST('' AS MONEY) AS VrBase, '' AS TipoTarif, '' AS RefConc, CAST('' AS BIT) AS Fijos, CAST('' AS INT) AS IncBaseRet, '' AS Referencia2c, '' AS Referencia3c, CAST('' AS INT) AS ItemDoc,
--Datos del cliente
'' AS TipoId, '' AS Dv, ''AS CodCliente, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail,
'' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona, '' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupoClie, '' AS GrupoClie
 END

         
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspContratoRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspContratoRel]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Contrato,'' IdCia,'' AS Compania,'' AS CdCarga,'' AS DescripCarga,CAST('' AS datetime) AS Fecha, CAST('' AS datetime) AS FechaInicio,CAST('' AS datetime) AS FechaFin,
'' AS UnionTemporal,'' AS IdCliente,'' AS RazonSocial,'' AS IdAgencia, '' AS CodAgencia,'' AS Agencia,'' AS DirAgncia,'' AS TelAgncia,CAST('' AS Money) AS VrCupo,CAST('' AS Money) AS VrSaldo,
'' AS NomCliente,'' AS TelCliente, '' AS emlCliente , '' AS DireccionCli,'' AS IdVend,''  AS NomVendedor,'' AS IdTarifCom, '' AS TipContrato,
'' AS IdContrato, '' AS IdObjCOE,'' AS ObjContrato,  '' AS IdForma, '' AS IdMneda, '' AS Mneda,'' AS  Plazos,'' AS  TipoPago,'' AS  Modalidad, '' AS  TipoLiquid, '' AS  CodTarRet,
'' AS  CodTarIca, CAST('' AS Money) AS VrPresupuesto,CAST('' AS Money) AS  VrSaldoPresup,CAST('' AS Money) AS  VrCobro,CAST('' AS Money) AS  VrCargos,CAST('' AS Money) AS  VrRetencion, CAST('' AS Money) AS  VrReteIca,
CAST('' AS Money) AS  VrDctos, CAST('' AS Money) AS  VrIva, CAST('' AS INT) AS  Cantidad,CAST('' AS INT) AS CantPasajeros, '' AS  NumAprob,'' AS IdCiaApr,CAST('' AS datetime) AS FecAprob,
'' AS TipOdp, CAST('' AS INT) AS  NumOdp, '' AS IdCiaOdp,CAST('' AS datetime) AS FechaOdp, '' AS TipFac, CAST('' AS INT) AS  Factura, '' AS IdCiaFac,CAST('' AS datetime) AS FechaFac,
'' AS OrigenAdd, CAST('' AS bit) AS EsLicitacion, CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev,'' AS  Observacion, '' AS  Clausulas, '' AS  Responsable,
'' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate,'' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario, '' AS IdGrupo, '' AS Grupo, '' AS IdRutaG, '' AS  RutaG

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspContratoRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspContratoRelDet]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT '' AS TipDoc, CAST('' AS INT) AS Contrato, '' AS IdCia, '' AS Compania, CAST('' as datetime) AS Fecha, CAST('' as datetime) AS FecInicio, CAST('' as datetime) AS FechaFin,
'' AS UnionTemporal,'' AS IdCliente,'' AS RazonSocial,'' AS IdAgencia,'' AS Agencia, '' AS IdVend,''  AS NomVendedor,'' AS IdTarifCom, '' AS TipContrato, '' AS IdForma,
'' AS  Plazos,'' AS  TipoPago,'' AS  Modalidad, '' AS  TipoLiquid, '' AS  CodTarRet, '' AS  CodTarIca, 
CAST('' AS Money) AS VrPresupuesto,CAST('' AS Money) AS  VrSaldoPresup,CAST('' AS Money) AS  VrCobro,CAST('' AS Money) AS  VrCargos,
CAST('' AS Money) AS  VrRetencion, CAST('' AS Money) AS  VrReteIca, CAST('' AS Money) AS  VrDctos, CAST('' AS Money) AS  VrIva,
'' AS CdDescuento, CAST('' AS INT) AS  Cantidad,CAST('' AS INT) AS CantPasajeros, '' AS IdMneda,'' AS Mneda,'' AS Peso, '' AS  NumAprob,'' AS IdCiaApr,CAST('' AS datetime) AS FecAprob,
'' AS TipOdp, CAST('' AS INT) AS  NumOdp, '' AS IdCiaOdp,CAST('' AS datetime) AS FechaOdp, '' AS TipFac, CAST('' AS INT) AS  Factura, '' AS IdCiaFac,CAST('' AS datetime) AS FechaFac,
'' AS OrigenAdd, CAST('' AS bit) AS EsLicitacion, CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev,'' AS  Observacion,
'' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate,'' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario, '' AS CdCarga,
--Anexos
'' AS TipContrato, '' AS IdContrato, '' AS IdObjCOE, '' AS ObjContrato,'' AS NomCliente, '' AS TelCliente, '' AS emlCliente,'' AS DireccionCli,
'' AS Observacion,''  AS NombArchivo,'' AS DescripCarga, '' AS Clausulas, '' AS Responsable,
--Detalles
CAST('' AS INT) AS Item, '' AS IdHorario,'' AS TipPed, CAST('' AS INT) AS Pedido, '' AS CiaPed, CAST('' AS INT) AS ItemPed, '' AS IdVehiculo,
'' AS CdTipVeh, '' AS TipoVehiculo, CAST('' AS INT) AS NumPasajeros, '' AS PesoNeto, CAST('' AS Money) AS VrUnitario, CAST('' AS Money) AS VrPago, '' AS IdRuta,
'' AS Ruta, '' AS  Referencia1, '' AS Referencia2, '' AS Referencia3, CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' as CiuOrigenD, '' AS DeptOrigen, '' AS DirOrigen, 
CAST('' AS datetime) AS FecOrigen, '' AS CdCiuDestino, '' AS  CiuDestinoD,'' AS DeptDestino, '' AS DirDestino,CAST('' AS datetime) AS FecDestino, CAST('' AS INT) AS  DiasDisp,
CAST('' AS Money) AS VrDia, '' AS Parada, '' AS CdTipRuta, '' AS CdTipServicio,'' AS TipRes,CAST('' AS INT) AS NumRes, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS INT) AS Cantveh,
CAST('' AS BIT) AS Retorno, CAST('' AS MONEY) AS VrMonitor, CAST('' AS INT) AS CantMonitor, CAST('' AS MONEY) AS VrMaxRec, CAST('' AS INT) AS NumDias, '' AS TipoTarifa, 
''AS IdColegio, '' AS NomColegio, '' AS Itinerario, CAST('' AS BIT) AS VLargo,
--Conceptos
'' AS TipoDocC, '' AS DocumentoC,''  AS IdCiaC, CAST('' AS INT) AS Itemc, '' AS Descripcion,'' AS Tarifa, '' AS TipoConc, '' AS RubroConcep, 
CAST('' AS INT) AS Cantidadc, CAST('' AS Money) AS VrUnitarioc, '' AS TarifIva, '' AS IdConcepto, '' AS CdCuenta, '' AS NitTercero,
'' AS NombreTerc,'' AS CdTipoEscc, '' AS TipEsc, CAST('' AS datetime) AS FechaNov, CAST('' AS Money) AS VrBase, ''  AS TipoTarif, '' AS RefConc,
'' AS Fijos, '' AS IncBaseRet, '' AS Referencia2c,'' AS Referencia3c,
--Datos del cliente
'' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail, '' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona,
'' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupo, '' AS GrupoClie
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCuenta]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Cesar Fernando Carre?o 
-- Create date: 04/01/2024
-- Description:	Metodo para tarifa cuenta
-- =============================================
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCuenta]	
	@Operacion varchar(10),
	@IdTarifa varchar(5),
	@TipDoc varchar(5),
	@IdCuenta varchar(20),
	@ClaseTarif Varchar(5),
	@CdCueOtr varchar(20),		
	@AntIdTarifa varchar(5),
	@AntTipDoc varchar(5),
	@AntIdCuenta varchar(20),
	@AntClaseTarif Varchar(5),
	@AntCdCueOtr varchar(20)
AS
begin
    SET @IdTarifa = CASE WHEN @IdTarifa = null THEN '' ELSE @IdTarifa END;
    SET @TipDoc = CASE WHEN @TipDoc = null THEN '' ELSE @TipDoc END;
    SET @IdCuenta = CASE WHEN @IdCuenta = null THEN '' ELSE @IdCuenta END;
    SET @ClaseTarif = CASE WHEN @ClaseTarif = null THEN '' ELSE @ClaseTarif END;
    SET @CdCueOtr = CASE WHEN @CdCueOtr = null THEN '' ELSE @CdCueOtr END;
    
    SET @AntIdTarifa = CASE WHEN @AntIdTarifa = null THEN '' ELSE @AntIdTarifa END;
    SET @AntTipDoc = CASE WHEN @AntTipDoc = null THEN '' ELSE @AntTipDoc END;
    SET @AntIdCuenta = CASE WHEN @AntIdCuenta = null THEN '' ELSE @AntIdCuenta END;
    SET @AntClaseTarif = CASE WHEN @AntClaseTarif = null THEN '' ELSE @AntClaseTarif END;
    SET @AntCdCueOtr = CASE WHEN @AntCdCueOtr = null THEN '' ELSE @AntCdCueOtr END;

	IF(@Operacion = 'GUARDAR')
	BEGIN		
		--select 'gua' 'gua'
		INSERT INTO [dbo].[TarifCuentas] (
			[IdTarifa],
			[TipDoc],
			[IdCuenta],
			[ClaseTarif],
			[CdCueOtr]
		)
        VALUES (
			@IdTarifa,
            @TipDoc,
            @IdCuenta,
            @ClaseTarif,
            @CdCueOtr
		)        				
	END

	IF(@Operacion = 'EDITAR')
	BEGIN		
		UPDATE 
			[dbo].[TarifCuentas]
		SET 
			[IdTarifa] = @IdTarifa,
			[TipDoc] = @TipDoc,
			[IdCuenta] = @IdCuenta,
			[ClaseTarif] = @ClaseTarif,
			[CdCueOtr] = @CdCueOtr
		WHERE 
			IdTarifa = @AntIdTarifa 
			AND TipDoc = @AntTipDoc 
			AND IdCuenta = @AntIdCuenta 
			AND ClaseTarif = @AntClaseTarif 
			AND ISNULL(CdCueOtr, '') = ISNULL(@AntCdCueOtr, '');
	END

	IF(@Operacion = 'ELIMINAR')
	BEGIN
		--select 'elei' 'elil'
		DELETE FROM 
			[dbo].[TarifCuentas]
		WHERE 
			IdTarifa = @AntIdTarifa 
			AND TipDoc = @AntTipDoc 
			AND IdCuenta = @AntIdCuenta 
			AND ClaseTarif = @AntClaseTarif 
			AND CdCueOtr = @AntCdCueOtr
	END
	
end

BEGIN
	--tabla para mostrar los datos de clases de tarifa 
	select IdDoc, TipoDoc 
	from Sys_TiposDoc 
	where IdDoc in ('FC1', 'OPE', 'DF1', 'DF2', 'DFC', 'DFO', 'DOE', 'FCR', 'FCE', 'DFE') AND Inactivo = 0;

	--Mostrar las clases de tarifa
	select IdClase, NomClase 
	from ClaseTar 
	where IdClase in ('ICA', 'BOM', 'IAT', 'RET', 'RTC') AND Inactivo = 0;

	--Mostrar Codigos De Tarifa
	select IdTarifa, Tarifa, Simbolo, Descripcion 
	from TablaPor 
	where IdClase in ('ICA', 'BOM', 'IAT', 'RET', 'RTC') AND Inactivo = 0;

	--Mostrar Tabla Cuentas
	select IdCuenta, NomCuenta 
	from PUC 
	where Movimiento = 1 and Inactivo = 0;

	--Datos ya guardados
	select * 
	from TarifCuentas 
	where ClaseTarif in ('ICA', 'BOM', 'IAT', 'RET', 'RTC') AND TipDoc in ('FC1', 'OPE', 'DF1', 'DF2', 'DFC', 'DFO', 'DOE', 'FCR', 'FCE', 'DFE')
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspCumplidosFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspCumplidosFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc,  CAST('' AS INT) AS Cumplido, '' AS IdCia, '' AS Compania,  CAST('' AS DATETIME) AS Fecha,'' AS TipResE, CAST('' AS INT) AS ReservaE, 
'' AS IdCiaResE, CAST('' AS INT) AS ItemResE, CAST('' AS DATETIME) AS FecReserva, '' AS IdClieFac, '' AS Cliente, '' AS TipFac, 
CAST('' AS INT) AS Factura, '' AS IdCiaFac, '' AS CdRuta,  '' AS Ruta, '' AS CdOrigen, '' AS CiudadOrigen,
'' AS CdDestino, '' AS CiudadDestino, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev, 
'' AS TipoComp, CAST('' AS INT) AS NumComp,  '' AS CodConcepto,  '' AS Observacion, 
'' AS IdEstado, '' AS Estado, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, 
'' AS IdUsuario, '' AS ObservAnulado, '' AS CdCenCosto, '' AS CdSubCenCos, CAST('' AS MONEY) AS VrPago,  CAST('' AS MONEY) AS VrCobro,  
CAST('' AS MONEY) AS VrAfiliados,  CAST('' AS MONEY) AS VrPropios, CAST('' AS MONEY) AS VrTotalServ,  CAST('' AS MONEY) AS VrTotalPagos, 
'' AS CodTarRtc,  CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrNeto,
--Detalle
 CAST('' AS INT) AS Item, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, 
 '' AS EstadoItemRes, CAST('' AS MONEY) AS VrRecorridos, '' AS IdVehiculo,'' AS IdPoseedor, '' AS NomPoseedor,
 '' AS IdConductor,'' AS NomConductor,  '' AS TipoAfil
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevAntRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevAntRel]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS datetime) AS FechaDev, '' AS IdConcepto, '' AS Concepto, '' AS TipDoc, 
CAST('' AS INT) AS Anticipo, '' AS IdCiaDoc,  CAST('' AS datetime) AS FecDoc, '' AS TipDoc, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, 
'' AS IdVehiculo, '' AS NitPoseedor,'' AS Poseedor, '' AS CedConductor, '' AS Conductor,  CAST('' AS Money) AS VrDevolucion, '' AS CdCta, '' AS NumeroCta, '' AS IdBanco, 
'' AS Banco, '' AS CdCuenta, '' AS TipoPago, '' AS NumCheque, CAST('' AS datetime) AS FecCheque,  '' AS Beneficiario, '' AS Modalidad, CAST('' AS Money) AS VrAnticipo, 
CAST('' AS Money) AS VrAbonado,  CAST('' AS Money) AS SaldoActual, '' AS ModdDev, '' AS Origen_Add, '' AS TipCom, CAST('' AS INT) AS  Comprobante, '' AS IdCiaCom,
'' AS NumCheque, CAST('' AS datetime) AS FecCheque, '' AS IdCta, '' AS NumeroCta, '' AS IdBanco, '' AS Banco, '' AS IdCuenta, '' AS Beneficiario,
'' AS CedBenef, CAST('' AS INT) AS  Cantidad, CAST('' AS datetime) AS FechaVence, CAST('' AS INT) AS  NumPresAnt, '' AS TipCom, CAST('' AS INT) AS  Comprobante,
'' AS IdCiaCom, '' AS Observacion, '' AS IdEstado, CAST('' AS datetime) AS TimeSys,  '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevCauRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevCauRel]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT CAST('' AS INT) AS Devolucion, '' AS CdCia, '' AS Compania, CAST('' AS datetime) AS Fecha, '' AS CdConcepto, '' AS Concepto, 
'' AS TipDoc, CAST('' AS INT) AS Causacion, '' AS IdCiaDoc,  CAST('' AS datetime) AS FecDoc, '' AS IdProv, '' AS RazonSocial, '' AS Factura, 
CAST('' AS Money) AS VrTotal, CAST('' AS Money) AS VrOtros, CAST('' AS Money) AS VrNeto, '' AS ModdDev, '' AS OrigenAddM, '' AS TipCom,
CAST('' AS INT) AS  Comprobante, '' AS IdCiaCom, '' AS Observ, '' AS CdEstado, CAST('' AS datetime) AS TimeSys, CAST('' AS datetime) AS FecUpdate,
'' AS IdCiaCrea, '' AS CdUsuario, '' AS Usuario
           
           
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevCumFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevCumFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, '' AS TipoDoc, CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, '' AS TipDoc,
CAST('' AS INT) AS Cumplido, '' AS IdCiaDoc,  CAST('' AS DATETIME) AS FecDoc, '' AS ModdDev, '' AS OrigenAdd, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, 
'' AS Observacion, CAST('' AS DATETIME) AS TimeSys, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario,
--DatosCumplido
CAST('' AS DATETIME) AS FechaCum, '' AS TipResE, CAST('' AS INT) AS ReservaE, '' AS IdCiaResE, CAST('' AS INT) AS ItemResE, '' AS TipFac,
CAST('' AS INT) AS Factura, '' AS IdCiaFac, '' AS IdClieFac, '' AS Cliente, '' AS CdRuta, '' AS Ruta, '' AS CdOrigen, '' AS CiuOrigen, 
'' AS CdDestino, '' AS CiuDestino, CAST('' AS BIT) AS Anulado, '' AS TipoComp,  CAST('' AS INT) AS NumComp, '' AS CodConcepto, '' AS ConceptoCum, '' AS ObservCum,
CAST('' AS MONEY) AS VrPago,  CAST('' AS MONEY) AS VrCobro,  CAST('' AS MONEY) AS VrAfiliados,  CAST('' AS MONEY) AS VrPropios,  CAST('' AS MONEY) AS VrTotalServ, 
CAST('' AS MONEY) AS VrTotalPagos, '' AS CodTarRtc,  CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS VrReteCree,  CAST('' AS MONEY) AS VrNeto,
--Detalles CumplidosReservas
CAST('' AS INT) AS Item, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, '' AS EstadoItemRes, CAST('' AS MONEY) AS VrRecorridos,
'' AS IdVehiculo, '' AS IdPoseedor, '' AS  NomPoseedor, '' AS IdConductor, '' AS  NomConductor, '' AS TipoAfil
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevFacFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevFacFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, '' AS TipoDoc, CAST('' AS INT) AS Devolucion, '' AS CdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS DescConcepto, '' AS TipoFac,
CAST('' AS INT) AS NumFactura, '' AS IdCiaDoc,  CAST('' AS DATETIME) AS FecDoc, '' AS IdCliente, ''  AS NomCliente, '' AS Cod_Agencia, '' AS NomAgencia, '' AS Cod_Agencia,
CAST('' AS MONEY) AS VrSubTotal, CAST('' AS MONEY) AS VrDcto, CAST('' AS MONEY) AS VrIva, CAST('' AS MONEY) AS VrRetFte, CAST('' AS MONEY) AS VrRetIca, CAST('' AS MONEY) AS VrReteIVA,
CAST('' AS MONEY) AS VrFletes,  CAST('' AS MONEY) AS VrOtros,  CAST('' AS MONEY) AS VrCargos,  CAST('' AS MONEY) AS VrOtrDcto,  CAST('' AS MONEY) AS VrCostos,  CAST('' AS MONEY) AS VrSobretasa,
CAST('' AS MONEY) AS VrImpGlobal,  CAST('' AS MONEY) AS VrFaltantes, CAST('' AS MONEY) AS VrAnticipos, CAST('' AS MONEY) AS VrNeto, CAST('' AS MONEY) AS CantTotal, CAST('' AS MONEY) AS BaseImp,
CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS VrReteCREE, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodTarRtc, '' AS CdVend, '' AS Vendedor, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaCom,
'' AS CdLocEnv, '' AS CiudadEnvio,  CAST('' AS INT) AS Pedido, '' AS IdCiaPed,  CAST('' AS INT) AS Cotizacion, '' AS IdCiaCot, CAST('' AS DATETIME) AS FecPedido, '' AS Modalidad, '' AS ModdDev,
'' AS TipCom, '' AS TipoCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, '' AS Observ, CAST('' AS DATETIME) AS TimeSys, '' AS IdCiaCrea, '' AS CdUsuario, '' AS Usuario, '' AS Leyenda,
----detalles
CAST('' AS INT) AS  Item, CAST('' AS DATETIME) AS FechaFact, '' AS TipRes, CAST('' AS INT) AS Reserva, ''AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS DATETIME) AS FecReserva, '' AS Descripcion,
CAST('' AS INT) AS Cantidad, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrUnitario, CAST('' AS MONEY) AS VrCosto, '' AS UndTarifa, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIva,
CAST('' AS MONEY) AS VrImpuesto, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaDct, CAST('' AS MONEY) AS VrDescuento, '' AS DocCliente, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3,
'' AS CdConcepto, '' AS CdCCosto, '' AS CdSubCos, '' AS NitTercero, '' AS CdAgencia, '' AS pVehiculo, '' AS TipoAfiVehic, '' AS IdOrigen, '' AS IdDestino, CAST('' AS BIT) AS Anulado,
'' AS TipDocRef,  CAST('' AS INT) AS NumDocRef, '' AS IdCiaRef, CAST('' AS DATETIME) AS FecDocRef, '' AS CodTarDct,
----InformaciÃ³n del cliente
'' AS TercTipo, '' AS  TercDv, '' AS TercCodigo, '' AS TercNomCial, '' AS TercSigal, '' AS TercDireccion, '' AS TercCdCiudad, '' AS NomCiudad, '' AS CdDep, '' AS TercDpto, '' AS TercTelefono,
'' AS TercFax, '' AS TercEmail, '' AS TercSitioWeb, '' AS CdSector, '' AS SectorEco, '' AS CdRegimen, '' AS Regimen, '' AS TercTipEnte,  '' AS NitRepLeg, '' AS NomRepLeg, '' AS ClieNitContac,
'' AS ClieNomContacto, '' AS ClieTelContac, '' AS ClieEmailContac, '' AS CargContac, CAST('' AS INT) AS DiasEntga, ''  AS CdSubzona, '' AS Subzona, '' AS Zona, '' AS CdGrupoCli, '' AS GrupoClie,
CAST('' AS BIT) AS ExcIva, CAST('' AS BIT) AS LiqFletes, CAST('' AS BIT) AS Autoret, CAST('' AS MONEY) AS VrCupo, CAST('' AS MONEY) AS VrSaldo, '' AS AgeDireccion, '' AS AgeTelefono, '' AS AgeFax,
'' AS AgeIdCiudad, '' AS AgeCiudad, '' AS AgeCodDep, '' AS AgeDpto, '' AS AgeReferencia,
--FACE
'' AS EstadoFE, '' AS PrefijoFace, CAST('' AS INT) AS NumFace, '' AS CUFE, '' AS ResolucionFace, '' AS RangoNum, '' AS FecVigencia, CAST('' AS IMAGE) AS QR, CAST('' AS DATETIME) AS FechaValidacion,
--FACE InformaciÃ³n de la factura devuelta
'' AS CUFEFac, CAST('' AS DATETIME) AS FecValidaFac, '' AS PrefijoFACEFac
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevFacturasRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevFacturasRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, CAST('' AS INT) AS Devolucion, '' AS IdCia, CAST('' AS DATETIME) AS Fecha, '' AS CdConcepto, '' AS Concepto, 
'' AS TipDoc, CAST('' AS INT) AS Factura, '' AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, '' AS IdCliente,''  AS NomCliente, 
'' AS IdAgencia, CAST('' AS MONEY) AS VrSubTotal, CAST('' AS MONEY) AS VrDescuento, CAST('' AS MONEY) AS VrImpuesto, 
CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteICA, CAST('' AS MONEY) AS VrReteIVA, CAST('' AS MONEY) AS VrFletes,  CAST('' AS MONEY) AS VrOtros,
CAST('' AS MONEY) AS VrCargos, CAST('' AS MONEY) AS VrOtrDcto, CAST('' AS MONEY) AS  VrCostos, CAST('' AS MONEY) AS VrSobretasa, CAST('' AS MONEY) AS VrImpGlobal, CAST('' AS MONEY) AS VrFaltantes,
CAST('' AS MONEY) AS VrAnticipos, CAST('' AS MONEY) AS VrNeto, CAST('' AS MONEY) AS VrAplicado, CAST(@VrDef AS DECIMAL(14,4)) AS Cantidad, CAST(@VrDef AS DECIMAL(14,4)) AS CantPuntos, 
CAST(@VrDef AS DECIMAL(14,4)) AS PuntosAcum, CAST(@VrDef AS DECIMAL(14,4)) AS BaseImp, CAST(@VrDef AS DECIMAL(14,4)) AS BaseRet, CAST(@VrDef AS DECIMAL(14,4)) AS BaseIca, 
CAST(@VrDef AS DECIMAL(14,4)) AS BaseRiv, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIva, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRiv, '' AS CodTarIva, '' AS CodTarRet, '' AS CodTarIca, '' AS CodTarRiv, '' AS IdCCosto, '' AS IdSubCos, '' AS IdVend, '' AS Vendedor,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaCom, '' AS CodTarCom, '' AS DirEnvio, '' AS IdLocEnv, CAST('' AS INT) AS DiasEntraga, '' AS NitContac, '' AS NomContac, '' AS TelContac,
'' AS emlContac, '' AS CargoContac, '' AS IdForma, '' AS DetallePago, CAST('' AS BIT) AS MulPlazos,  '' AS IdPlazo, '' AS CdMney, '' AS NitEmpTrans, '' AS EmpTrans,
'' AS pVehiculo, '' AS CdConductor, CAST('' AS INT) AS KmtVehic, '' AS CdRuta, '' AS TipPed, CAST('' AS INT) AS Pedido,  '' AS IdCiaPed,  '' AS TipRem, CAST('' AS INT) AS Remision, 
'' AS IdCiaRem, '' AS TipCot, CAST('' AS INT) AS Cotizacion, '' AS IdCiaCot, CAST('' AS DATETIME) AS FecPedido, CAST('' AS INT) AS AutzaMora, CAST('' AS INT) AS AutzaCupo,
'' AS Modalidad, '' AS CodAutoRet, '' AS OrigenAdd, '' AS TipCom,  CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, CAST('' AS INT) AS ZonaFrontera, CAST(@VrDef AS DECIMAL(14,4)) AS PesoTotal,
CAST(@VrDef AS DECIMAL(14,4)) AS UnidTotal, CAST(@VrDef AS DECIMAL(14,4)) AS VolTotal, CAST(@VrDef AS DECIMAL(14,4)) AS CantFalt, CAST('' AS MONEY) AS VrCostoRem, CAST('' AS MONEY) AS VrCostoAfi,
CAST('' AS MONEY) AS VrImpCons, CAST('' AS MONEY) AS VrReteCREE, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodTarRtc, CAST('' AS MONEY) AS BaseIvaObsq, CAST('' AS MONEY) AS VrIvaObsequio,
CAST('' AS MONEY) AS VrImpCarbono, CAST('' AS BIT) AS Parqueadero, CAST('' AS DATETIME) AS FecCuotaParq, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev,
'' AS Observ, '' AS CdEstado, '' AS Estado, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuari, '' AS Usuario
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevGenRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevGenRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
CAST('' AS INT) AS Devolucion, '' AS IdCia, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS TipDoc, CAST('' AS INT) AS Cumplido,
'' AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, '' AS ModdDev, '' AS OrigenAdd, '' AS TipCom,  CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,
'' AS Observacion, CAST('' AS DATETIME) AS TimeSys, '' AS IdCiaCrea, '' AS IdUsuario
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevLiq]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevLiq]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, 
'' AS TipDoc, CAST('' AS INT) AS Liquidacion, '' AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, '' AS IdVehiculo, '' AS IdPoseedor,
''  AS Poseedor, '' AS IdConductor, '' AS Conductor, CAST('' AS MONEY) AS VrTotal, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,
'' AS ModdDev, '' AS Observacion, '' AS IdEstado, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, 
'' AS IdUsuario, '' AS Usuario
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevLiqRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevLiqRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, 
'' AS TipDoc, CAST('' AS INT) AS Liquidacion, '' AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, '' AS IdVehiculo, '' AS IdPoseedor,
''  AS Poseedor, '' AS IdConductor, '' AS Conductor, CAST('' AS MONEY) AS VrTotal, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,
'' AS ModdDev, '' AS Observacion, '' AS IdEstado, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, 
'' AS IdUsuario, '' AS Usuario
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevLiquidaFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevLiquidaFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, '' AS TipoDoc, CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, 
'' AS Concepto, '' AS TipDoc, CAST('' AS INT) AS Liquidacion, ''AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, '' AS IdVehiculo, '' AS IdPoseedor,
'' AS Poseedor, '' AS IdConductor, '' AS NomConductor, CAST('' AS MONEY) AS VrTotal, '' AS ModdDev, '' AS TipCom, CAST('' AS INT) AS Comprobante,
''AS IdCiaCom, '' AS Observacion,  CAST('' AS DATETIME) AS TimeSys, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario, '' AS Leyenda,
CAST('' AS INT) AS Item, '' AS TipCau, CAST('' AS INT) AS Causacion, '' AS IdCiaCau, CAST('' AS INT) AS ItemCau, CAST('' AS DATETIME) AS FechaCau,
'' AS CdConcCausac, '' AS Descripcion, CAST('' AS MONEY) AS VrAbono, '' AS NitPoseedor, '' AS NomPoseedor, '' AS pVehiculo, CAST('' AS BIT) AS EsVence,
'' AS TipOdp,  CAST('' AS INT) AS OrdenPago, '' AS IdCiaOdp, '' AS TipRes,  CAST('' AS INT) AS Reserva, '' AS IdCiaRes,  CAST('' AS MONEY) AS VrSaldoOrden,
'' AS CdCuenta, '' AS CdCuePagar, '' AS NumFactura,  '' AS CdCCosto, '' AS CCosto, '' AS CdSubCos, '' AS SubCosto,
--Datos Liquidacion
'' AS  IdConceptoLq, '' AS ConceptoLq,
--datos del poseedor
'' AS TercTipId, ''  AS TercDv, ''  AS TercCodigo, '' AS TercNomCial, '' AS TercDireccion, '' AS TercCdCiudad, '' AS NomCiudad, '' AS TercTelefono, '' AS TercEmail,
'' AS NumVeh, '' AS CdTipVeh, '' AS TipoVehiculo, '' AS CdMarca, '' AS MarcaVeh, '' AS CdLinVeh, '' AS LineaVeh, '' AS CdColor, '' AS NomColor, '' AS CdCarr, '' AS TipoCar, '' AS Modelo,
'' AS Config, CAST(@VrDef AS DECIMAL(14,4)) AS PesoVacio, CAST(@VrDef AS DECIMAL(14,4)) PesoMax, ''AS NumMotor, '' AS SerieChasis, '' AS NumSerie, '' AS CdRemque, '' AS NitEmpresa, 
'' AS VehNomEmpresa, '' AS CdTipProp, '' AS TipoProp, '' AS VehPropio, '' AS TipoAfil, '' AS NumSoat, CAST('' AS DATETIME) FecSoat, CAST('' AS DATETIME) AS VigSoat,
'' AS NitEmpSoat, '' AS CertGases,  CAST('' AS DATETIME) FecCertGas,  CAST('' AS DATETIME) AS VigCertGas, '' AS VehDescripcion
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevOdpFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevOdpFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDev, CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, '' AS TipDoc,
CAST('' AS INT) AS OrdPago, ''AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, ''AS IdVehiculo, '' AS NumVeh, '' AS IdPropietario, '' AS  Propietario,
'' AS IdPoseedor, '' AS Poseedor, '' AS IdConductor, '' AS  Conductor, CAST('' AS BIT) AS CxPagar, '' AS ModdDev, '' AS TipCom, '' AS TipoCom,
CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,'' AS Observacion, '' AS IdEstado, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys,
CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario,
--Orden Reserva
'' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento,  
CAST('' AS MONEY) AS VrRetencion,  CAST('' AS MONEY) AS VrReteIca, CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrAnticipos,  
CAST('' AS MONEY) AS VrOtrosDctos,  CAST('' AS MONEY) AS VrImpuestos,  CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto,
CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS BaseIca, CAST('' AS MONEY) AS BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca,
CAST(@VrDef AS DECIMAL(14,4)) AS  TarifaRtc, '' AS Referencia,  CAST('' AS MONEY) AS VrConcPagos,  CAST('' AS MONEY) AS VrConcDctos,  CAST('' AS MONEY) AS VrConcFondo,
CAST('' AS MONEY) AS VrConcSeguro,  CAST('' AS MONEY) AS VrConcAporte,  CAST('' AS MONEY) AS VrConcImpuesto, CAST('' AS MONEY) AS VrRecCaja, CAST('' AS MONEY) AS VrSeguros,
CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrAportes,
  --Datos de OPAGO
'' AS  Modalidad, '' AS IdConcOP, '' AS ConcOP, CAST('' AS INT) AS Cantidad,
--DATOS RESERVA
CAST('' AS MONEY) AS  VrPagos,
            --Datos del vehiculo
'' AS TipoId, ''AS Dv, '' AS IdLocal, '' AS Localidad, '' AS Direccion, '' AS Telefono, '' AS TelMovil, '' AS e_mail, '' AS IdLugar, '' AS Localidad,
'' AS IdTipoVeh, '' AS TipoVehiculo, '' AS IdMarca,'' AS Marca, '' AS Modelo, '' AS Config, '' AS TipoAfil, '' AS Descripcion
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspDevOdpRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspDevOdpRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
CAST('' AS INT) AS Devolucion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto,
'' AS TipDoc, CAST('' AS INT) AS OrdPago, '' AS IdCiaDoc, CAST('' AS DATETIME) AS FecDoc, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, 
'' AS IdVehiculo, '' AS NumVeh, '' AS IdPoseedor, ''  AS Poseedor, '' AS IdConductor, '' AS Conductor, CAST('' AS BIT) AS CxPagar,
CAST('' AS DATETIME) AS FechaVence, CAST('' AS BIT) AS LiqReservas, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento,
CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteIca, CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrAnticipos,
CAST('' AS MONEY) AS VrOtrosDctos, CAST('' AS MONEY) AS VrImpuestos, CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto,
CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS BaseIca, CAST('' AS MONEY) AS BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet,
'' AS NumCheque, '' AS Referencia, '' AS ModdDev, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, '' AS Observacion, 
'' AS IdEstado, '' AS Estado, CAST('' AS DATETIME) AS TimeSys,CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFacturaFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFacturaFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS Tip_Doc, '' AS TipoDoc, CAST('' AS INT) AS NumFactura, '' AS CdCia, '' AS Compania, CAST('' AS DATETIME) AS FechaDoc, '' AS CdConcepto, '' AS DescConcepto, '' AS IdCliente,
''  AS NomCliente, '' AS IdAgenc, '' AS NomAgencia, '' AS Cod_Agencia, CAST('' AS DATETIME) AS FechaVence, CAST('' AS MONEY) AS VrSubTotal, CAST('' AS MONEY) AS VrDcto,
CAST('' AS MONEY) AS VrIva, CAST('' AS MONEY) AS VrRetFte, CAST('' AS MONEY) AS VrRetIca, CAST('' AS MONEY) AS VrReteIVA, CAST('' AS MONEY) AS VrFletes,  CAST('' AS MONEY) AS VrOtros,
CAST('' AS MONEY) AS VrCargos, CAST('' AS MONEY) AS VrOtrDcto, CAST('' AS MONEY) AS  VrCostos, CAST('' AS MONEY) AS VrSobretasa, CAST('' AS MONEY) AS VrImpGlobal, CAST('' AS MONEY) AS VrFaltantes,
CAST('' AS MONEY) AS VrAnticipos, CAST('' AS MONEY) AS VrNeto, CAST('' AS MONEY) AS VrAplicado, CAST(@VrDef AS DECIMAL(14,4)) AS CantTotal, CAST(@VrDef AS DECIMAL(14,4)) AS PesoTotal, 
CAST(@VrDef AS DECIMAL(14,4)) AS UnidTotal, CAST(@VrDef AS DECIMAL(14,4)) AS VolTotal, CAST(@VrDef AS DECIMAL(14,4)) AS CantFalt, CAST('' AS MONEY) AS VrCostoRem, CAST('' AS MONEY) AS VrCostoAfi,
CAST('' AS MONEY) AS BaseImp, CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS BaseIca, CAST('' AS MONEY) AS BaseRiv, CAST(@VrDef AS DECIMAL(14,4)) AS TarifIva, CAST(@VrDef AS DECIMAL(14,4)) AS TarifRet,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifIca, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRiv, '' AS NitVend, '' AS Vendedor, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaCom,  '' AS  CodiTarIva, '' AS CodiTarRet,
'' AS CodiTarIca, '' AS CodiTarRiv, '' AS DirEnvio, '' AS IdCiuEnvio,
'' AS CiudadEnvio, CAST('' AS INT) AS DiasEntraga, '' AS FacNitContac, '' AS FacNomContac, '' AS FacTelContac, '' AS FacEmailContac, '' AS CargoContac, '' AS  CdForma, '' AS DetallePago,
CAST('' AS BIT) AS MulPlazos, '' AS CdPlazo, '' AS Plazo, CAST('' AS INT) AS NVmto, CAST('' AS INT) AS DiasPago, '' AS NitEmpTrans, '' AS EmpTrans, '' AS TipPed, CAST('' AS INT) AS Pedido, '' AS IdCiaPed,
'' AS TipRemision, CAST('' AS INT) AS NumRemision, '' AS TipCot, CAST('' AS INT) AS NumCotizacion, '' AS CiaCotiza, CAST('' AS DATETIME) AS FecPedido,  CAST('' AS INT) AS AutzaMora, CAST('' AS INT) AS AutzaCupo,
'' AS Modalidad, CAST(@VrDef AS DECIMAL(14,4)) AS KmtVehic, '' AS TipCom, ''AS TipoCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, CAST('' AS BIT) AS FacAnulado, CAST('' AS INT) AS NumDev,
CAST('' AS DATETIME) AS FecDev, '' AS Observ, CAST('' AS MONEY) AS VrReteCREE, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodiTarRtc, '' AS CdEstado, CAST('' AS DATETIME) AS Fec_Add, 
CAST('' AS DATETIME) AS Fec_Update, '' AS IdCiaCrea, '' AS CdUsuario, '' AS Usuario, '' AS Leyenda,
--detalles de la reserva
CAST('' AS INT) AS Item, CAST('' AS INT) AS TipoReg, CAST('' AS DATETIME) AS FechaFact, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS DATETIME) AS FecReserva,
'' AS Descripcion, CAST(@VrDef AS DECIMAL(14,4)) AS  Cantidad, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrUnitario, CAST('' AS MONEY) AS VrCosto, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIva,
CAST('' AS MONEY) AS VrImpuesto, CAST(@VrDef AS DECIMAL(14,4))  AS TarifaDct, CAST('' AS MONEY) AS VrDescuento, '' AS DocCliente, '' AS Referencia1, '' AS Referencia2,
--26-05-2021.Yaqueline Lizarazo Diaz. Se agrega campo para mostrar el nombre del estudiante, correspondiente al documento de la Referencia2.
'' AS NomEstudiante,
'' AS Referencia3, '' AS CdConceptoD,
'' AS CdCCosto, '' AS CdSubCos, '' AS NitTercero, '' AS CdAgencia,  '' AS pVehiculo, '' AS IdOrigen, '' AS IdDestino, CAST('' AS BIT) AS Anulado, '' AS TipDocRef, CAST('' AS INT) AS NumDocRef,
'' AS IdCiaRef, CAST('' AS DATETIME) AS FecDocRef, '' AS CodTarDct, '' AS CodTarRet, '' AS CodTarIca,  CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, CAST('' AS MONEY) AS VrRetencion, CAST('' AS BIT) AS Anulado, '' AS TipDocRef, 
CAST('' AS INT) AS NumDocRef, '' AS IdCiaRef, CAST('' AS DATETIME) AS FecDocRef,  '' AS CodTarDct, '' AS CodTarRet, '' AS CodTarIca,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet,  CAST('' AS MONEY) AS VrRetencion, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca,  CAST('' AS MONEY) AS VrReteIca,
--26-05-2021.Yaqueline Lizarazo Diaz. Se agrega campo para identificar si es una reserva de ESTUDIANTES.
CAST('' AS BIT) AS EsItemPME,
--AuxFactura
'' AS Resolucion, '' AS Rango, CAST('' AS DATETIME) AS FechaResl, ''AS Prefijo, '' AS TipDocPf, '' AS PreFactura, '' AS IdCiaPf,    
--InformaciÃ³n del cliente
'' AS TercTipo, '' AS TercDv, '' AS TercCodigo, '' AS TercNomCial, '' AS TercSigal, '' AS TercDireccion, '' AS TercCdCiudad, '' AS NomCiudad, '' AS CdDep, '' AS TercDpto, '' AS TercTelefono, '' AS TercFax,
'' AS TercEmail, '' AS TercSitioWeb, '' AS CdSector, '' AS SectorEco, '' AS CdRegimen, '' AS Regimen, '' AS TercTipEnte, '' AS NitRepLeg, '' AS NomRepLeg, '' AS ClieNitContac, '' AS ClieNomContacto, '' AS ClieTelContac,
'' AS ClieEmailContac, '' AS CargContac, CAST('' AS INT) AS DiasEntga, '' AS CdSubzona, '' AS Subzona, '' AS Zona, '' AS CdGrupoCli, '' AS GrupoClie, CAST('' AS BIT) AS ExcIva, CAST('' AS BIT) AS LiqFletes,
CAST('' AS BIT) AS Autoret, CAST('' AS MONEY) AS VrCupo, CAST('' AS MONEY) AS VrSaldo, '' AS AgeDireccion, '' AS AgeTelefono, '' AS AgeFax, '' AS AgeIdCiudad, '' AS AgeCiudad, '' AS AgeCodDep, ''AS AgeDpto,
'' AS AgeReferencia,
--Memo
CAST('' AS INT) AS cantimp, '' AS Comentarios,
--FACE
'' AS EstadoFE, '' AS PrefijoFace, CAST('' AS INT) AS NumFace, '' AS CUFE, '' AS ResolucionFace, '' AS RangoNum, '' AS FecVigencia, CAST('' AS IMAGE) AS QR, CAST('' AS DATETIME) AS FechaValidacion
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFacturasRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFacturasRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Factura, '' AS IdCia, CAST('' AS DATETIME) AS Fecha, '' AS CdConcepto, '' AS Concepto, '' AS IdCliente,
''  AS NomCliente, '' AS IdAgencia, CAST('' AS DATETIME) AS FechaVence, CAST('' AS MONEY) AS VrSubTotal, CAST('' AS MONEY) AS VrDescuento,
CAST('' AS MONEY) AS VrImpuesto, CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteICA, CAST('' AS MONEY) AS VrReteIVA, CAST('' AS MONEY) AS VrFletes,  CAST('' AS MONEY) AS VrOtros,
CAST('' AS MONEY) AS VrCargos, CAST('' AS MONEY) AS VrOtrDcto, CAST('' AS MONEY) AS  VrCostos, CAST('' AS MONEY) AS VrSobretasa, CAST('' AS MONEY) AS VrImpGlobal, CAST('' AS MONEY) AS VrFaltantes,
CAST('' AS MONEY) AS VrAnticipos, CAST('' AS MONEY) AS VrNeto, CAST('' AS MONEY) AS VrAplicado, CAST(@VrDef AS DECIMAL(14,4)) AS Cantidad, CAST(@VrDef AS DECIMAL(14,4)) AS CantPuntos, 
CAST(@VrDef AS DECIMAL(14,4)) AS PuntosAcum, CAST(@VrDef AS DECIMAL(14,4)) AS BaseImp, CAST(@VrDef AS DECIMAL(14,4)) AS BaseRet, CAST(@VrDef AS DECIMAL(14,4)) AS BaseIca, 
CAST(@VrDef AS DECIMAL(14,4)) AS BaseRiv, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIva, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRiv, '' AS CodTarIva, '' AS CodTarRet, '' AS CodTarIca, '' AS CodTarRiv, '' AS IdCCosto, '' AS IdSubCos, '' AS IdVend, '' AS Vendedor,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaCom, '' AS CodTarCom, '' AS DirEnvio, '' AS IdLocEnv, CAST('' AS INT) AS DiasEntraga, '' AS NitContac, '' AS NomContac, '' AS TelContac,
'' AS emlContac, '' AS CargoContac, '' AS IdForma, '' AS DetallePago, CAST('' AS BIT) AS MulPlazos,  '' AS IdPlazo, '' AS CdMney, '' AS NitEmpTrans, '' AS EmpTrans,
'' AS pVehiculo, '' AS CdConductor, CAST('' AS INT) AS KmtVehic, '' AS CdRuta, '' AS TipPed, CAST('' AS INT) AS Pedido,  '' AS IdCiaPed,  '' AS TipRem, CAST('' AS INT) AS Remision, 
'' AS IdCiaRem, '' AS TipCot, CAST('' AS INT) AS Cotizacion, '' AS IdCiaCot, CAST('' AS DATETIME) AS FecPedido, CAST('' AS INT) AS AutzaMora, CAST('' AS INT) AS AutzaCupo,
'' AS Modalidad, '' AS CodAutoRet, '' AS OrigenAdd, '' AS TipCom,  CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, CAST('' AS INT) AS ZonaFrontera, CAST(@VrDef AS DECIMAL(14,4)) AS PesoTotal,
CAST(@VrDef AS DECIMAL(14,4)) AS UnidTotal, CAST(@VrDef AS DECIMAL(14,4)) AS VolTotal, CAST(@VrDef AS DECIMAL(14,4)) AS CantFalt, CAST('' AS MONEY) AS VrCostoRem, CAST('' AS MONEY) AS VrCostoAfi,
CAST('' AS MONEY) AS VrImpCons, CAST('' AS MONEY) AS VrReteCREE, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodTarRtc, CAST('' AS MONEY) AS BaseIvaObsq, CAST('' AS MONEY) AS VrIvaObsequio,
CAST('' AS MONEY) AS VrImpCarbono, CAST('' AS BIT) AS Parqueadero, CAST('' AS DATETIME) AS FecCuotaParq, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev,
'' AS Observ, '' AS CdEstado, '' AS Estado, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuari, '' AS Usuario
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFacturasRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFacturasRelDet]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipoDoc, CAST('' AS INT) AS Factura, '' AS IdCia, CAST('' AS INT) AS Item, CAST('' AS INT) AS TipoReg, CAST('' AS DATETIME) AS FechaFact, 
'' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS DATETIME) AS FecReserva, '' AS Descripcion,
CAST(@VrDef AS DECIMAL(14,4)) AS Cantidad, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrUnitario, CAST('' AS MONEY) AS VrCosto,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIva, CAST('' AS MONEY) AS VrImpuesto, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaDct, 
CAST('' AS MONEY) AS VrDescuento, '' AS DocCliente, '' AS Referencia1, '' AS Referencia2,  '' AS Referencia3, '' AS CdConcepto, '' AS CdCCosto,
'' AS CdSubCos, '' AS NitTercero, '' AS CdAgencia, '' AS pVehiculo, '' AS TipoAfiVehic, '' AS IdOrigen, '' AS CiuOrigen, '' AS DeptOrigen,
'' AS IdDestino, '' AS CiuDestino, '' AS DeptDestino, CAST('' AS BIT) AS Anulado, '' AS TipDocRef, CAST('' AS INT) AS NumDocRef, '' AS IdCiaRef,
CAST('' AS DATETIME) AS FecDocRef, '' AS CodTarDct, '' AS CodTarRet, '' AS CodTarIca, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet,
CAST('' AS MONEY) AS VrRetencion, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca, CAST('' AS MONEY) AS VrReteIca, '' AS EstadoItem
END
            
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecCond]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecCond]
WITH EXECUTE AS CALLER
AS
BEGIN
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Fuec, '' AS IdCia, CAST('' AS INT) AS ItemC, '' AS CedConductor, '' as Conductor, '' AS LicenciaC, CAST('' AS DATETIME) AS FecLicenciaC, CAST('' AS DATETIME) AS VigLicenciaC,
 '' AS TelefonoC, '' AS TelMovilC
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
	DECLARE @VrDef VARCHAR(1) = '1'

	SELECT 
	--Encabezado
	''	AS TipDoc, 
	CAST('' AS INT) AS Fuec, 
	'' AS IdCia, 
	'' AS Compania, 
	'' AS Numero, 
	CAST('' AS DATETIME) AS Fecha, 
	CAST('' AS DATETIME) AS FechaInicio,
	CAST('' AS DATETIME) AS FechaFin, 
	'' AS CdCarga,
	'' AS IdVehiculo, 
	'' AS NumVeh, 
	'' AS Modelo, 
	'' AS TarjOper,
	'' AS IdTipoVeh, 
	'' AS TipoVehiculo, 
	'' AS TipoAfil, 
	'' AS Marca,
	'' AS Itinerario,
	--datos conductor principal
	'' AS IdConductor, 
	'' AS NomConductor, 
	'' AS Licencia,
	CAST('' AS DATETIME) AS FecLicencia, 
	CAST('' AS DATETIME) AS VigLicencia, 
	'' AS Telefono, 
	'' AS TelMovil,
	--datos conductor remplazo 1
	--'' AS IdConductor2, '' AS  NomConductor2, '' AS  Licencia2, CAST('' AS DATETIME) AS  FecLicencia2, CAST('' AS DATETIME) AS  VigLicencia2,
	--datos conductor remplazo 2
	--'' AS IdConductor3, '' AS  NomConductor3, '' AS Licencia3, CAST('' AS DATETIME) AS FecLicencia3, CAST('' AS DATETIME) AS VigLicencia3,
	'' AS IdPoseedor, 
	'' AS NomPoseedor, 
	'' AS IdRuta, 
	'' AS CdTipRuta, 
	'' AS IdOrigen, 
	'' AS CiuOrigen, 
	'' AS DeptOrigen, 
	'' AS IdDestino,
	'' AS CiuDestino, 
	'' AS DeptDestino, 
	'' AS Modalidad,
	CAST(@VrDef AS DECIMAL(14,4)) AS CantPasajeros, 
	'' AS CodTarRet, 
	'' AS CodTarIca,
	CAST('' AS MONEY) AS  VrPresupuesto, 
	CAST('' AS MONEY) AS  VrCobro, 
	CAST('' AS MONEY) AS VrPagos, 
	CAST('' AS MONEY) AS VrCargos, 
	CAST('' AS MONEY) AS VrDctos,
	CAST('' AS MONEY) AS VrIva,
	CAST('' AS MONEY) AS VrRetencion, 
	CAST('' AS MONEY) AS VrReteIca, 
	CAST(@VrDef AS DECIMAL(14,4)) AS Cantidad,
	CAST(@VrDef AS DECIMAL(14,4)) AS Peso, 
	'' AS TipDocPgr, 
	CAST('' AS INT) AS NumPgr, 
	'' AS IdCiaPgr, 
	CAST('' AS INT) AS ItemPgr, 
	'' AS TipDocCnt,
	CAST('' AS INT) AS Contrato, 
	'' AS CiaCnt, 
	CAST('' AS INT) AS Consecutivo, 
	'' AS OrigenAdd, 
	CAST('' AS BIT) AS Anulado, 
	CAST('' AS DATETIME) AS FecDev,
	'' AS IdEstado, 
	'' AS Estado, 
	CAST('' AS DATETIME) AS TimeSys, 
	CAST('' AS DATETIME) AS FecUpdate, 
	'' AS IdCiaCrea, 
	'' AS IdUsuario, 
	'' AS Usuario,
	--datos anexos
	'' AS TipContrato, 
	'' AS IdContrato,
	'' AS ObjContrato, 
	'' AS DescripCarga, 
	'' AS Observacion, 
	'' AS RespViaje, 
	CAST('' AS BIT) AS VehConvenio, 
	'' AS EmpresaVehCon, 
	'' AS Empresa,
	--datos de detalles
	CAST('' AS INT) AS Item, 
	'' AS TipRes, 
	CAST('' AS INT) AS Reserva, 
	'' AS IdCiaRes, 
	CAST('' AS INT) AS ItemRes, 
	CAST('' AS INT) AS NumPasajeros,
	CAST(@VrDef AS DECIMAL(14,4)) AS PesoNeto, 
	CAST('' AS MONEY) AS VrCobroD, 
	CAST('' AS MONEY) AS VrPagosD, 
	'' AS Referencia1, 
	'' AS Referencia2, 
	'' AS Referencia3,
	'' AS CdTipServicio, 
	CAST('' AS BIT) AS EsRutaCliente, 
	CAST(@VrDef AS DECIMAL(14,4)) AS Kilometros, 
	'' AS DirOrigen, 
	CAST('' AS DATETIME) AS FecOrigen,
	'' AS DirDestino,
	CAST('' AS DATETIME) AS FecDestino,
	CAST('' AS IMAGE) AS Qr
	--datos conductores
	--CAST('' AS INT) AS ItemC, '' AS CedConductor, '' as Conductor, '' AS LicenciaC, CAST('' AS DATETIME) AS FecLicenciaC, CAST('' AS DATETIME) AS VigLicenciaC
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecRel]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Fuec,'' IdCia,'' AS Compania, '' AS Numero,'' AS TipContrato, '' AS IdContrato, '' AS ObjContrato,
'' AS CdCarga,'' AS DescripCarga,CAST('' AS datetime) AS Fecha, CAST('' AS datetime) AS FechaInicio,CAST('' AS datetime) AS FechaFin, '' AS IdVehiculo, 
'' AS TipoVehiculo, '' AS IdConductor, '' AS NomConductor, '' AS IdConductor2, '' AS NomConductor2, '' AS IdConductor3, '' AS NomConductor3,
'' AS IdPoseedor, '' AS NomPoseedor, '' AS IdRuta, '' AS CdTipRuta,  '' AS IdOrigen, '' AS CiuOrigen, '' AS DeptOrigen, '' AS  IdDestino,
'' AS CiuDestino, '' AS DeptDestino, '' AS Modalidad, CAST('' AS INT) AS CantPasajeros, '' AS CodTarRet, '' AS CodTarIca, CAST('' AS MONEY) AS VrPresupuesto,
CAST('' AS MONEY) AS VrCobro, CAST('' AS MONEY) AS VrPagos, CAST('' AS MONEY) AS VrDctos, CAST('' AS MONEY) AS VrIva, CAST('' AS MONEY) AS VrRetencion,
CAST('' AS MONEY) AS VrReteIca,  CAST('' AS MONEY) AS Cantidad, '' AS Peso, '' AS Observacion, '' AS TipDocPgr, CAST('' AS INT) AS NumPgr, '' AS IdCiaPgr,
CAST('' AS INT) AS ItemPgr, '' AS TipDocCnt, CAST('' AS INT) AS Contrato, '' AS CiaCnt, '' AS OrigenAdd, CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev,
'' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspFuecRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspFuecRelDet]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Fuec,'' IdCia,'' AS Compania, '' AS Numero, CAST('' AS datetime) AS Fecha, CAST('' AS datetime) AS FechaInicio,
CAST('' AS datetime) AS FechaFin, '' AS CdCarga, '' AS IdVehiculo, '' AS NumVeh, '' AS IdTipoVeh, '' AS TipoVehiculo, '' AS TipoAfil,
--Datos conductor principal
'' AS IdConductor, '' AS  NomConductor,  '' AS Licencia,  CAST('' AS datetime) AS FecLicencia,  CAST('' AS datetime) AS VigLicencia,
--Datos conductor Alterno 1
'' AS IdConductor2, '' AS  NomConductor2,  '' AS Licencia2,  CAST('' AS datetime) AS FecLicencia2,  CAST('' AS datetime) AS VigLicencia2,
--Datos conductor Alterno 2
'' AS IdConductor3, '' AS  NomConductor3,  '' AS Licencia3,  CAST('' AS datetime) AS FecLicencia3,  CAST('' AS datetime) AS VigLicencia3,
'' AS IdPoseedor, '' AS NomPoseedor, '' AS IdRuta, '' AS CdTipRuta,  '' AS IdOrigen, '' AS CiuOrigen, '' AS DeptOrigen, '' AS  IdDestino,
'' AS CiuDestino, '' AS DeptDestino, '' AS Modalidad, CAST('' AS INT) AS CantPasajeros, '' AS CodTarRet, '' AS CodTarIca, CAST('' AS MONEY) AS VrPresupuesto,
CAST('' AS MONEY) AS VrCobro, CAST('' AS MONEY) AS VrPagos, CAST('' AS MONEY) AS VrCargos, CAST('' AS MONEY) AS VrDctos, CAST('' AS MONEY) AS VrIva, 
CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteIca,  CAST('' AS MONEY) AS Cantidad, '' AS Peso, '' AS TipDocPgr, CAST('' AS INT) AS NumPgr,
'' AS IdCiaPgr, CAST('' AS INT) AS ItemPgr, '' AS TipDocCnt, CAST('' AS INT) AS Contrato, '' AS CiaCnt, '' AS OrigenAdd, CAST('' AS bit) AS Anulado, 
CAST('' AS datetime) AS FecDev, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario,
--Datos anexos
'' AS TipContrato, '' AS IdContrato, '' AS ObjContrato, '' AS DescripCarga, '' AS Observacion,
--Datos de detalles
CAST('' AS INT) AS Item, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS INT) AS NumPasajeros,
'' AS PesoNeto, CAST('' AS MONEY) AS VrCobro, CAST('' AS MONEY) AS VrPagos, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3, '' AS CdTipServicio,
CAST('' AS BIT) AS EsRutaCliente, '' AS Kilometros, '' AS DirOrigen, CAST('' AS datetime) AS FecOrigen, '' AS DirDestino, CAST('' AS datetime) AS FecDestino

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspGenRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspGenRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Cumplido, '' AS IdCia, '' Compania, CAST('' AS DATETIME) AS Fecha, '' AS TipRes, CAST('' AS INT) AS Reserva,
'' AS IdCiaRes, CAST('' AS INT) AS ItemRes, '' AS TipFac, CAST('' AS INT) AS Factura, '' AS IdCiaFac, '' AS IdClieFac, '' AS RazonSocial,
'' AS CdRuta, '' AS CdOrigen, '' AS CiuOrigen, '' AS CdDestino, '' AS CiuDestino, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev, 
'' AS TipoComp, CAST('' AS INT) AS NumComp, '' AS CodConcepto, '' AS Observacion, '' AS IdEstado, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys, 
CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS ObservAnulado, '' AS CdCenCosto, '' AS CdSubCenCos, CAST('' AS MONEY) AS VrPago, 
CAST('' AS MONEY) AS VrCobro, CAST('' AS MONEY) AS VrAfiliados, CAST('' AS MONEY) AS VrPropios, CAST('' AS MONEY) AS VrTotalServ, CAST('' AS MONEY) AS VrTotalPagos, 
'' AS CodTarRtc, CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrNeto,
 --Datos del cliente
'' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail, '' AS NitRepLeg,
'' AS NomRepLeg, '' AS IdGrupo
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspGenRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspGenRelDet]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Cumplido, '' AS IdCia, '' AS Compania, CAST('' AS INT) AS Item, '' AS Estado,
'' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, '' AS EstadoItemRes,
--Datos de Reserva
'' AS CdCiuOrigen, '' AS CiuOrigen, '' AS CdCiuDestino, '' AS CiuDestino, CAST('' AS MONEY) AS VrRecorridos,
'' AS IdVehiculo, '' AS IdPoseedor, '' AS NomPoseedor, '' AS IdConductor, '' AS NomConductor, '' AS TipoAfil
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaDedFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaDedFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Liquidacion, '' AS IdCia, '' AS Compania, CAST('' AS INT) AS Item, '' AS  TipCau,  CAST('' AS INT) AS Causacion,
'' AS IdCiaCau, CAST('' AS INT) AS ItemCau,  CAST('' AS DATETIME) AS FechaCau, '' AS IdConcepto, ''AS Descripcion,  CAST('' AS MONEY) AS VrAbono,
'' AS NitPoseedor, ''  AS NomPoseedor, '' AS pVehiculo, CAST('' AS BIT) AS EsVence, '' AS TipOdp, CAST('' AS INT) AS OrdenPago, '' AS IdCiaOdp,
'' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS DATETIME) AS FechaRes, CAST('' AS MONEY) AS VrSaldoOrden, '' AS CdCuenta,
'' AS CdCuePagar, '' AS NumFactura, '' AS CdCCosto, '' AS CCosto, '' AS CdSubCos, '' AS SubCosto,
--Datos del detalle(esto se maneja en buses)
'' AS CauDescripcion, CAST('' AS MONEY) AS VrTotalDed, CAST('' AS INT) AS  EstadoReg, CAST('' AS MONEY) AS  VrTotAbonado, '' AS TipFac,
--datos del poseedor
'' AS TercTipId, '' AS TercDv, '' AS TercCodigo, '' AS TercDireccion, '' AS TercCdCiudad, '' AS NomCiudad, '' AS TercTelefono , ''  AS TercEmail,
'' AS NumVeh, '' AS CdTipVeh, '' AS TipoVehiculo, '' AS CdMarca, '' AS MarcaVeh, '' AS CdColor, '' AS NomColor, '' AS Modelo, '' AS Config,
CAST(@VrDef AS DECIMAL(14,4)) AS PesoVacio, CAST(@VrDef AS DECIMAL(14,4)) AS PesoMax, '' AS NumMotor, '' AS SerieChasis, '' AS NumSerie,
''AS CdRemque, ''AS NitEmpresa, '' AS VehNomEmpresa, '' AS TipoAfil, '' AS VehDescripcion
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaEgrFac]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaEgrFac]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCia, CAST('' AS INT) AS Item,  CAST('' AS DATETIME) AS  Fecha,'' AS  TipFac,  
'' AS Factura, '' AS IdCiaFac, CAST('' AS INT) AS ItemFac,  CAST('' AS DATETIME) AS FechaCau,
'' AS IdProveedor, ''  AS Proveedor, '' AS IdCuenta, CAST('' AS MONEY) AS VrAbono, CAST('' AS BIT) AS EsEgreso, CAST('' AS INT) AS ItemCom,
'' AS pVehiculo, CAST('' AS BIT) AS VehPropio, '' AS TipDev, CAST('' AS INT) AS NumDev, '' AS DetAbono
 END


GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Liquidacion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, '' AS IdVehiculo, '' AS IdPoseedor,
''  AS Poseedor, '' AS IdConductor, '' AS NomConductor, CAST('' AS MONEY) AS VrTotal, CAST('' AS BIT) AS CxPagar, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,
CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev, '' AS Observacion, '' AS IdEstado, '' AS Estado,
CAST('' AS DATETIME) AS FecIniCau, CAST('' AS DATETIME) AS FecFinCau, CAST('' AS DATETIME) AS FecIniOdp, CAST('' AS DATETIME) AS FecFinOdp, '' AS ModLiquida,
CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario,
--datos de la orden
'' AS TipOdp, CAST('' AS INT) AS OrdPago, '' AS IdCiaOdp, '' AS NomCiaOrden, CAST('' AS DATETIME)  AS FechaOdp, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes,
CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento, CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS  VrReteIca, CAST('' AS MONEY) AS  VrReteCree,
CAST('' AS MONEY) AS  VrAnticipos, CAST('' AS MONEY) AS  VrOtrosDctos, CAST('' AS MONEY) AS  VrImpuestos,  CAST('' AS MONEY) AS VrAportes,  CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto,
CAST('' AS MONEY) AS  BaseRet, CAST('' AS MONEY) AS  BaseIca, CAST('' AS MONEY) AS  BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet,  CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodTarRet, '' AS CodTarIca, '' AS CodTarRtc,  CAST('' AS BIT) AS  CxPagar, CAST('' AS MONEY) MulPlazos, '' AS  IdPlazo, '' AS Plazo,
CAST('' AS INT) AS NVmto, CAST('' AS DATETIME) AS FechaVence, CAST('' AS MONEY) AS  VrConcPagos,CAST('' AS MONEY) AS  VrConcDctos,CAST('' AS MONEY) AS  VrConcFondo, CAST('' AS MONEY) AS  VrConcSeguro,
CAST('' AS MONEY) AS VrConcAporte, CAST('' AS MONEY) AS  VrConcImpuesto, CAST('' AS MONEY) AS VrRecCaja, CAST('' AS MONEY) AS VrReteCREE, '' AS NumCheque, '' AS Referencia,
'' AS CdCiuOrigen, '' AS  CiuOrigen, '' AS CodDepOrigen, '' AS DptoOrigen, '' AS CdCiuDestino, '' AS CiuDestino, ''  AS CodDepDestino, '' AS DptoDestino,  '' AS IdRuta, '' AS Ruta,
--datos del poseedor
'' AS TercTipId, ''  AS TercDv, ''  AS TercCodigo, '' AS TercNomCial, '' AS TercDireccion, '' AS TercCdCiudad, '' AS NomCiudad, '' AS TercTelefono, '' AS TercEmail,
'' AS NumVeh, '' AS CdTipVeh, '' AS TipoVehiculo, '' AS CdMarca, '' AS MarcaVeh, '' AS CdLinVeh, '' AS LineaVeh, '' AS CdColor, '' AS NomColor, '' AS CdCarr, '' AS TipoCar, '' AS Modelo,
'' AS Config, CAST(@VrDef AS DECIMAL(14,4)) AS PesoVacio, CAST(@VrDef AS DECIMAL(14,4)) PesoMax, ''AS NumMotor, '' AS SerieChasis, '' AS NumSerie, '' AS CdRemque, '' AS NitEmpresa, 
'' AS VehNomEmpresa, '' AS CdTipProp, '' AS TipoProp, '' AS VehPropio, '' AS TipoAfil, '' AS NumSoat, CAST('' AS DATETIME) FecSoat, CAST('' AS DATETIME) AS VigSoat,
'' AS NitEmpSoat, '' AS CertGases,  CAST('' AS DATETIME) FecCertGas,  CAST('' AS DATETIME) AS VigCertGas, '' AS VehDescripcion,  CAST('' AS DATETIME) AS FecRes, '' AS NumCtaProveedor,
'' AS ClaseCuenta,  '' AS NitContac, '' AS NomContac, '' AS Banco,
--Datos del cliente la factura
'' AS IdCliente,  '' AS RazonSocialCli
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaOtrFmtCauDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaOtrFmtCauDet]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
CAST('' AS INT) AS Item, '' AS TipCau,  CAST('' AS INT) AS Causacion, '' AS IdCiaCau, CAST('' AS INT) AS ItemCau, '' AS Factura,  '' AS Descripcion, 
CAST('' AS MONEY)  AS VrTotal, CAST('' AS MONEY) AS  VrFactura,  '' AS CdCuenta, '' AS pVehiculo
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspLiquidaRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspLiquidaRel]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Liquidacion, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, '' AS IdVehiculo, '' AS IdPoseedor,
''  AS Poseedor, '' AS IdPropietario, '' AS Propietario,  '' AS IdTipoVeh, '' AS TipoVehiculo, '' AS TipoAfil, '' AS IdConductor, '' AS Conductor,
CAST('' AS MONEY) AS VrTotal, CAST('' AS BIT) AS CxPagar, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,
CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev, '' AS Observacion, '' AS IdEstado,
CAST('' AS DATETIME) AS FecIniCau, CAST('' AS DATETIME) AS FecFinCau, CAST('' AS DATETIME) AS FecIniOdp, CAST('' AS DATETIME) AS FecFinOdp, 
'' AS ModLiquida, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, 
'' AS IdUsuario, '' AS Usuario
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspListaPasaFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspListaPasaFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
CAST('' AS INT) AS IdLista, '' AS Documento, '' AS Apellidos, '' AS Nombres, '' AS IdResponsable, '' AS Responsable, CAST(@VrDef AS DECIMAL(14,4)) AS VrPago, CAST(@VrDef AS DECIMAL(14,4)) AS Porcentaje, 
'' AS Cargo, CAST('' AS BIT) AS EsMonitor, CAST('' AS BIT) AS EsEstudiante, '' AS Telefono, '' AS TipDoc, CAST('' AS INT) AS Contrato, '' AS IdCia, ''AS IdCliente, '' AS  NomCliente, CAST('' AS DATETIME) AS FechaInicio,
CAST('' AS DATETIME) AS FechaFin, '' AS CodObjContrato, '' AS ObjetoContrato, CAST('' AS INT) AS Item, CAST('' AS DATETIME) AS FecOrigen, CAST('' AS DATETIME) AS FecDestino, CAST('' AS INT) AS NumPasajeros, CAST('' AS BIT) AS EsItemPME, '' AS IdColegio, 
'' AS NomColegio, '' AS IdVehiculo, CAST('' AS DATETIME) AS Fecha, '' AS IdEstado, CAST('' AS DATETIME) AS FecUpdate, '' AS IdUsuario, '' AS Usuario,
--AdmRegistro
'' AS NitRepLegal, '' AS RepLegal, '' AS CiudadReplegal, '' AS NitEmpresa, '' AS NomEmpresa, '' AS CiudadEmpresa
 END

         
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspListaPasaResFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspListaPasaResFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
CAST('' AS INT) AS IdLista, '' AS Documento, '' AS Apellidos, '' AS Nombres, '' AS IdResponsable, '' AS Responsable, CAST(@VrDef AS DECIMAL(14,4)) AS VrPago, CAST(@VrDef AS DECIMAL(14,4)) AS Porcentaje, 
'' AS Cargo, CAST('' AS BIT) AS EsMonitor, CAST('' AS BIT) AS EsEstudiante, '' AS Telefono, '' AS TipDoc, CAST('' AS INT) AS Reserva, '' AS IdCia, ''AS IdCliente, '' AS  NomCliente, CAST('' AS DATETIME) AS FechaInicio,
CAST('' AS DATETIME) AS FechaFin, CAST('' AS INT) AS Item, CAST('' AS DATETIME) AS FecOrigen, CAST('' AS DATETIME) AS FecDestino, CAST('' AS INT) AS NumPasajeros, CAST('' AS BIT) AS EsItemPME, '' AS IdColegio, 
'' AS NomColegio, '' AS IdVehiculo, CAST('' AS DATETIME) AS Fecha, '' AS IdEstado, CAST('' AS DATETIME) AS FecUpdate, '' AS IdUsuario, '' AS Usuario,
--AdmRegistro
'' AS NitRepLegal, '' AS RepLegal, '' AS CiudadReplegal, '' AS NitEmpresa, '' AS NomEmpresa, '' AS CiudadEmpresa
 END

         
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspNovResFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspNovResFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT
--Datos de la Novedad
'' AS TipDoc, '' AS Documento, '' AS IdCia, CAST('' AS INT) AS Item,'' AS IdConcepto,'' AS Descripcion,
CAST('' AS INT) AS Cantidad, CAST('' AS MONEY) AS VrUnitario,CAST('' AS MONEY) AS VrTotal, '' AS RubroConcep,
'' AS TipoConc,'' AS NitTercero,'' AS RazonSocial,'' AS CdTipoEsc,'' AS TipoEscolta,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifIva,'' AS Concepto,'' AS CdCuenta,
CAST(@VrDef AS DECIMAL(14,4)) AS Tarifa,CAST('' AS DATETIME) AS FechaNov,CAST('' AS MONEY) AS VrBase,'' AS TipoTarif,'' AS RefConc,
CAST('' AS INT) AS Fijos,CAST('' AS MONEY) AS IncBaseRet,'' AS Referencia2,'' AS Referencia3,CAST('' AS INT) AS ItemDoc
END



GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDet]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipoDoc, CAST('' AS INT) AS OrdPago, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto,
'' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS DATETIME) AS FechaRes,
'' AS CdCiuOrigen, '' AS CiuOrigen, '' AS CodDepOrigen, '' AS DptoOrigen, '' AS CdCiuDestino, '' AS CiuDestino, '' AS CodDepDestino,
'' AS DptoDestino, '' AS IdRuta, '' AS Ruta, '' AS IdVehiculo, '' AS NumVeh, '' AS IdPropietario, '' AS Propietario, '' AS IdPoseedor,
''  AS Poseedor, '' AS IdConductor, '' AS NomConductor, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento, 
CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteIca, CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrAnticipos, 
CAST('' AS MONEY) AS VrOtrosDctos, CAST('' AS MONEY) AS VrImpuestos, CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto, 
CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS BaseIca, CAST('' AS MONEY) AS BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, 
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, CAST('' AS BIT) AS CxPagar, CAST('' AS BIT) AS MulPlazos,
'' AS CdPlazo, '' AS Plazo, CAST('' AS INT) AS DiasPago, CAST('' AS DATETIME) AS FechaVence,  '' AS TipCom, CAST('' AS INT) AS Comprobante,
'' AS IdCiaCom, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev, '' AS Observacion, '' AS IdCiaCrea, 
'' AS IdUsuario, '' AS Usuario, '' AS TipEgr, CAST('' AS INT) AS Egreso, '' AS IdCiaEgr, '' AS NumCheque, '' AS Referencia, 
CAST('' AS MONEY) AS VrConcPagos, CAST('' AS MONEY) AS VrConcDctos, CAST('' AS MONEY) AS VrConcFondo, CAST('' AS MONEY) AS VrConcSeguro, 
CAST('' AS MONEY) AS VrConcAporte, CAST('' AS MONEY) AS VrConcImpuesto, CAST('' AS MONEY) AS VrRecCaja, CAST('' AS MONEY) AS VrSeguros,  
CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrAportes,
--COMFACTURA
CAST('' AS MONEY) AS VrTotalFac, CAST('' AS MONEY) AS VrTotalAbo, CAST('' AS MONEY) AS VrSaldo,
---Encabezado de factura
'' AS TipFac,  CAST('' AS INT) AS Factura, '' AS CiaFac,
--Detalle de factura
CAST('' AS MONEY) VrServicioFact
END



GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDetRen]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOPagoNetoDetRen]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipoDoc, CAST('' AS INT) AS OrdPago, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto,
'' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS DATETIME) AS FechaRes,
'' AS CdCiuOrigen, '' AS CiuOrigen, '' AS CodDepOrigen, '' AS DptoOrigen, '' AS CdCiuDestino, '' AS CiuDestino, '' AS CodDepDestino,
'' AS DptoDestino, '' AS IdRuta, '' AS Ruta, '' AS IdVehiculo, '' AS NumVeh, '' AS IdPropietario, '' AS Propietario, '' AS IdPoseedor, 
''  AS Poseedor, '' AS IdConductor, '' AS NomConductor,
CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento, CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteIca, 
CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrAnticipos, CAST('' AS MONEY) AS VrOtrosDctos, CAST('' AS MONEY) AS VrImpuestos, 
CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto, CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS BaseIca, 
CAST('' AS MONEY) AS BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca, 
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, CAST('' AS BIT) AS CxPagar, CAST('' AS BIT) AS MulPlazos, '' AS CdPlazo, '' AS Plazo,
CAST('' AS INT) AS DiasPago, CAST('' AS DATETIME) AS FechaVence,  '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, 
CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev, CAST('' AS DATETIME) AS FecDev, '' AS Observacion, '' AS IdCiaCrea, 
'' AS IdUsuario, '' AS Usuario, '' AS TipEgr, CAST('' AS INT) AS Egreso, '' AS IdCiaEgr, '' AS NumCheque, '' AS Referencia, 
CAST('' AS MONEY) AS VrConcPagos, CAST('' AS MONEY) AS VrConcDctos, CAST('' AS MONEY) AS VrConcFondo, CAST('' AS MONEY) AS VrConcSeguro, 
CAST('' AS MONEY) AS VrConcAporte, CAST('' AS MONEY) AS VrConcImpuesto, CAST('' AS MONEY) AS VrRecCaja, CAST('' AS MONEY) AS VrSeguros,  
CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrAportes, CAST('' AS INT) AS EdoLiqCausac, '' AS EstadoItem,
--Datos del vehiculo
'' AS TercTipId, '' AS TercDv, '' AS  TercCdCiudad, '' AS NomCiudad, '' AS DirPoseedor, '' AS TelPoseedor, '' AS TelMovilPosee, 
'' AS emailPoseedor, '' AS IdIcaOdp, '' AS CiudadICaOdp, '' AS IdLugarLic, '' AS LugarLicencia, '' AS CdTipVeh, '' AS TipoVehiculo,
'' AS CdMarca, '' AS MarcaVeh, '' AS Modelo, '' AS Config, '' AS TipoAfil, '' AS VehDescripcion,    
---Encabezado de factura
'' AS TipFac,  CAST('' AS INT) AS Factura, '' AS CiaFac,
--Detalle de factura
CAST('' AS MONEY) VrServicioFact
END


GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOPagoRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOPagoRelDet]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
CAST('' AS INT) AS OrdPago, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, 
CAST('' AS INT) AS ItemRes, '' AS IdVehiculo, '' AS NumVeh, '' AS IdPropietario, '' AS Propietario, '' AS NitPoseedor, ''  AS Poseedor,
'' AS CedConductor, '' AS Conductor, CAST('' AS BIT) AS LiqReservas, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento,
CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteIca, CAST('' AS MONEY) AS VrReteCree, CAST('' AS MONEY) AS VrAnticipos,
CAST('' AS MONEY) AS VrOtrosDctos, CAST('' AS MONEY) AS VrImpuestos, CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto,
CAST('' AS MONEY) AS BaseRet, CAST('' AS MONEY) AS BaseIca, CAST('' AS MONEY) AS BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet,
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodTarRet, '' AS CodTarIca, '' AS CodTarRtc,
CAST('' AS BIT) AS CxPagar, CAST('' AS BIT) AS MulPlazos, '' AS IdPlazo, '' AS Plazo, CAST('' AS INT) AS NVmto, CAST('' AS DATETIME) AS FechaVence,
CAST('' AS MONEY) AS VrConcPagos, CAST('' AS MONEY) AS VrConcDctos, CAST('' AS MONEY) AS VrConcFondo, CAST('' AS MONEY) AS VrConcSeguro, 
CAST('' AS MONEY) AS VrConcAporte, CAST('' AS MONEY) AS VrConcImpuesto, CAST('' AS MONEY) AS VrRecCaja, CAST('' AS MONEY) AS VrReteCREE, '' AS CdForma,
'' AS CdCenCosto, '' AS CdSubCenCos, CAST('' AS MONEY) AS VrSeguros, CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrAportes, '' AS IdConcepto,
'' AS Concepto, '' AS Modalidad, '' AS TipEgr, CAST('' AS INT) AS Egreso, '' AS IdCiaEgr, CAST('' AS DATETIME) AS FechaEgr, '' AS NumCheque,
'' AS Referencia, '' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom, CAST('' AS BIT) AS Anulado, CAST('' AS INT) AS NumDev,
CAST('' AS DATETIME) AS FecDev, '' AS Observacion, '' AS IdEstado, '' AS Estado, '' AS OrigenAdd, CAST('' AS DATETIME) AS TimeSys,
CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario,
--Datos de Orden_Reserva_Prog
'' AS TipPgr, CAST('' AS INT) AS Programa, '' AS IdCiaPgr, CAST('' AS INT) AS ItemPgr, CAST('' AS MONEY) AS VrRecorrido
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOrdenPagoLta]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOrdenPagoLta]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
--Encabezado
SELECT CAST('' AS INT) AS Numero, CAST('' AS DATETIME) AS Fecha, CAST('' AS INT) AS EstadoProc, '' AS Observacion, CAST('' AS DATETIME) AS TimeSys, 
'' AS IdUsuario, '' AS Nombre, CAST('' AS INT) AS Item, '' AS TipDoc, CAST('' AS INT) AS Orden, '' AS IdCia, '' AS IdConcepto, '' AS TipoCom, 
CAST('' AS INT) AS Comprobante, '' AS TipRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, '' AS IdOrigen, '' AS CiuOrigen, 
'' AS IdDestino, '' AS CiuDestino, '' AS IdRuta, '' AS Ruta, '' AS IdVehiculo, '' AS IdConductor, '' AS IdPropietario, '' AS IdPoseedor, 
CAST('' AS INT) AS Cumplido, '' AS IdCiaCum, CAST('' AS INT) AS EstadoReg, CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento, 
CAST('' AS MONEY) AS VrRetencion, CAST('' AS MONEY) AS VrReteIca, CAST('' AS MONEY) AS VrReteCREE, CAST('' AS MONEY) AS VrAnticipos, CAST('' AS MONEY) AS VrOtrosDctos, 
CAST('' AS MONEY) AS VrImpuestos, CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRet, 
CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc, '' AS CodTarRet, '' AS CodTarIca, '' AS CodTarRtc, 
CAST('' AS MONEY) AS VrConcPagos, CAST('' AS MONEY) AS VrConcDctos, CAST('' AS MONEY) AS VrConcFondo, CAST('' AS MONEY) AS VrConcSeguro, 
CAST('' AS MONEY) AS VrConcAporte, CAST('' AS MONEY) AS VrConcImpuesto, CAST('' AS MONEY) AS VrRecCaja, '' AS CdForma, '' AS IdCCosto, '' AS IdSubCos,
 CAST('' AS MONEY) AS VrSeguros, CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrAportes, '' AS Comentarios
END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOrdPagoFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOrdPagoFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
--Trn_TraEspOrdenPago
'' AS TipDoc, CAST('' AS INT) AS OrdPago, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha, '' AS IdConcepto, '' AS Concepto, '' AS Modalidad,
CAST('' AS BIT) AS LiqReservas,  CAST('' AS BIT) AS  CxPagar,  CAST('' AS BIT) AS MulPlazos, '' AS IdPlazo, '' AS Plazo, ''AS DiasPago,  CAST('' AS DATETIME) AS FechaVence,
'' AS TipCom, CAST('' AS INT) AS Comprobante, '' AS IdCiaCom,  CAST('' AS BIT) AS Anulado,  CAST('' AS INT) AS NumDev,  CAST('' AS DATETIME) AS  FecDev, '' AS Observacion, 
'' AS IdEstado, '' AS Estado,  CAST('' AS DATETIME) AS TimeSys,  CAST('' AS DATETIME) AS FecUpdate,  '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario,
--Orden reservas
'' AS TipRes,  CAST('' AS INT) AS Reserva, '' AS IdCiaRes,  CAST('' AS INT) AS ItemRes, '' AS IdRuta, '' AS Ruta, CAST(@VrDef AS DECIMAL(14,4)) AS  Distkmt, 
'' AS IdVehiculo, '' AS NumVeh, '' AS IdTipoVeh, '' AS TipoVehiculo, '' AS TipoAfil,'' AS IdConductor, '' AS NomConductor, '' AS IdPropietario,'' AS Propietario, '' AS IdPoseedor, '' AS Poseedor,
 CAST('' AS MONEY) AS VrServicio, CAST('' AS MONEY) AS VrDescuento,  CAST('' AS MONEY) AS VrRetencion,  CAST('' AS MONEY) AS VrReteIca, CAST('' AS MONEY) AS VrReteCree,  
CAST('' AS MONEY) AS VrAnticipos,  CAST('' AS MONEY) AS VrOtrosDctos,  CAST('' AS MONEY) AS VrImpuestos,  CAST('' AS MONEY) AS VrOtrosPagos, CAST('' AS MONEY) AS VrNeto, CAST('' AS MONEY) AS BaseRet,
CAST('' AS MONEY) AS BaseIca, CAST('' AS MONEY) AS BaseCree, CAST(@VrDef AS DECIMAL(14,4)) AS  TarifaRet, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaIca, CAST(@VrDef AS DECIMAL(14,4)) AS TarifaRtc,
''AS CodTarRet, '' AS CodTarIca, ''AS CodTarRtc, '' AS TipEgr, CAST('' AS INT) AS Egreso, '' AS IdCiaEgr, CAST('' AS DATETIME) AS FechaEgr, '' AS NumCheque, '' AS Referencia,
CAST('' AS MONEY) AS VrConcPagos, CAST('' AS MONEY) AS VrConcDctos, CAST('' AS MONEY) AS VrConcFondo, CAST('' AS MONEY) AS VrConcSeguro, CAST('' AS MONEY) AS VrConcAporte, CAST('' AS MONEY) AS VrConcImpuesto,
CAST('' AS MONEY) AS VrRecCaja, CAST('' AS MONEY) AS VrReteCREE, '' AS CdForma, '' AS CdCenCosto, '' AS CdSubCenCos, CAST('' AS MONEY) AS VrSeguros, CAST('' AS MONEY) AS VrFondos, CAST('' AS MONEY) AS VrAportes,
'' AS TipPgr, CAST('' AS INT) AS Programa, '' AS IdCiaPgr, CAST('' AS INT) AS ItemPgr,CAST('' AS MONEY) AS VrRecorrido,
--Trn_TraEspConceptos
CAST('' AS INT) AS Item, '' AS IdConc, '' AS Descripcion , CAST('' AS INT) AS Cantidad, 
CAST('' AS MONEY) AS VrUnitario, CAST('' AS MONEY)  AS VrTotal, '' AS RubroConcep,  '' AS TipoConc, '' AS NitTercero, '' AS RazonSocial, '' AS CdTipoEsc,
'' AS TipoEscolta, CAST('' AS MONEY) AS TarifIva, '' AS ConcG,'' AS CdCuenta, CAST(@VrDef AS DECIMAL(14,4)) AS Tarifa, CAST('' AS DATETIME) AS FechaNov, 
CAST('' AS MONEY) AS VrBase, '' AS TipoTarif, '' AS RefConc, CAST('' AS BIT) AS Fijos, CAST('' AS INT) AS IncBaseRet, '' AS Referencia2, '' AS Referencia3,
--ComFactura
'' AS TipFac, CAST('' AS INT) AS Factura, '' AS IdCiaF, CAST('' AS INT) AS ItemF, '' AS IdProveedor, '' AS IdCuentaF,
CAST('' AS DATETIME) AS FecEmision, CAST('' AS DATETIME) AS FecVence, CAST('' AS MONEY) AS VrFactura, CAST('' AS MONEY) AS VrAbonado,
'' AS TipComF, CAST('' AS INT) AS ComprobanteF, CAST('' AS MONEY) AS ItemCom, '' AS ReferenciaF, '' AS Detalle, '' AS pVehiculo,  CAST('' AS BIT) AS VehPropio,
'' AS TipRef, '' AS DocRef, '' AS IdCiaRef,  CAST('' AS INT) AS EstadoApr,
--Anticipos_Abonos
'' AS ItemAnt,  CAST('' AS DATETIME) AS FechaAnt, '' AS TipAnt,  CAST('' AS INT) AS Anticipo,
'' AS IdCiaAnt,  '' AS Placa, '' AS ObsAnt, CAST('' AS MONEY) AS VrAbono,  CAST('' AS MONEY) AS VrAnticipo,  CAST('' AS MONEY) AS VrAbonadoAnt,  CAST('' AS MONEY) AS VsSaldo, '' AS TipoAplica,
'' AS DetalleAnt, '' AS CdCuentaAnt,
--DetCuentas
'' AS ConceptoDC,  CAST('' AS INT) AS ItemDC, '' AS IdCuenta,  CAST('' AS MONEY) AS Valor, '' AS DetalleDC,  CAST('' AS MONEY) AS VrBaseDC, '' AS  IdTercero, '' AS RazonSocialDC,
'' AS CodAgncia, '' AS CdCCosto, ''AS CCosto, '' AS CdSubCos, '' AS SubCosto, '' AS PlacaDC, '' AS TipFacDC,  CAST('' AS INT) AS FacturaDC, '' AS IdCiaFac,  CAST('' AS INT) AS ItemFac,
 CAST('' AS DATETIME) AS FecVenceDC, '' AS Cheque, '' AS CodConc, '' AS ReferenciaDC, '' AS CiuOrigen, ''AS Localidad,  CAST('' AS MONEY) AS  VrTarifa, '' AS TipoTarifDC	
 END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOtroSiFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOtroSiFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT CAST('' AS INT) AS IdOtroSi, CAST('' AS datetime) AS Fecha, CAST('' AS BIT) AS Adicion, CAST('' AS BIT) AS CFecha, CAST('' AS BIT) AS Items, CAST('' AS BIT) AS Aplicado, 
CAST('' AS datetime) AS TimeSys, '' AS Observacion, '' AS IdUsuario, '' AS Usuario, CAST('' AS BIT) AS Anulado, CAST('' AS datetime) AS FecDev,
--Datos COE
'' AS IdCliente, '' AS NomCliente,  '' AS Responsable, '' AS NombreResp, CAST('' AS INT) AS CantPasajeros, '' AS CdCarga,  CAST('' AS BIT) AS EsLicitacion, 
CAST('' AS datetime) AS FechaInicio, '' AS IdObjCOE, '' AS ObjContrato,  CAST('' AS datetime) AS FecContrato, '' AS Modalidad, '' AS IdGrupo,
--Detalle
'' AS TipDocCnt, CAST('' AS INT) AS ContratoOS, '' AS IdCiaCnt, CAST('' AS datetime) AS FechaFinAnt, CAST('' AS datetime) AS FechaFinNew, CAST('' AS Money) AS VrPpto,
CAST('' AS Money) AS VrSaldoPpo, CAST('' AS Money) AS VrAdicionPpto,
--Detalle De Items COE
'' AS TipDoc, CAST('' AS INT) AS Contrato, '' AS IdCia, CAST('' AS INT) AS Item, '' AS IdHorario, '' AS TipPed, CAST('' AS INT) AS Pedido, '' AS CiaPed, 
CAST('' AS INT) AS ItemPed, '' AS IdVehiculo, '' AS CdTipVeh, '' AS TipoVehiculo, CAST('' AS INT) AS NumPasajeros, CAST(@VrDef AS DECIMAL(14,4)) AS PesoNeto, 
CAST('' AS Money) AS VrUnitario, CAST('' AS Money) AS VrPago, '' AS IdRuta,'' AS Ruta, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3, 
CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' AS CiuOrigenD, '' AS DeptOrigen, '' AS DirOrigen, CAST('' AS datetime) AS FecOrigen, '' AS CdCiuDestino, 
'' AS CiuDestinoD, '' AS DeptDestino, '' AS DirDestino, CAST('' AS datetime) AS FecDestino, CAST('' AS INT) AS DiasDisp, CAST('' AS Money) AS VrDia, '' AS Parada, 
'' AS CdTipRuta, '' AS CdTipServicio, '' AS TipRes, CAST('' AS INT) AS NumRes, '' AS IdCiaRes, CAST('' AS INT) AS ItemRes, CAST('' AS INT) AS CantVeh, 
CAST('' AS BIT) AS Retorno, CAST('' AS Money) AS VrMonitor, CAST('' AS INT) AS CantMonitor, CAST('' AS Money) AS VrMaxRec, CAST('' AS INT) AS NumDias, '' AS TipoTarifa,
'' AS IdColegio, '' AS NomColegio, '' AS Codigo, '' AS Itinerario, CAST('' AS BIT) AS VLargo, CAST('' AS INT) AS IdOtroSiDet, CAST('' AS BIT) AS ItemAnuladoOS
END

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspOtroSiRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspOtroSiRel]
WITH EXECUTE AS CALLER
AS
SELECT '' AS IdOtroSi, CAST('' AS datetime) AS Fecha, CAST('' AS BIT) AS Adicion, CAST('' AS BIT) AS CFecha, CAST('' AS BIT) AS Items, CAST('' AS BIT) AS Aplicado, 
CAST('' AS datetime) AS TimeSys, '' AS IdUsuario, '' AS Usuario, CAST('' AS BIT) AS Anulado, CAST('' AS datetime) AS FecDev,
--Detalle
'' AS TipDocCnt, CAST('' AS INT) AS Contrato, '' AS IdCiaCnt, CAST('' AS datetime) AS FechaFinAnt, CAST('' AS datetime) AS FechaFinNew, CAST('' AS Money) AS VrPpto, 
CAST('' AS Money) AS VrSaldoPpo, CAST('' AS Money) AS VrAdicionPpto

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPedidoFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPedidoFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
--Encabezado
'' AS TipDoc, CAST('' AS INT) AS Pedido, '' AS IdCia, '' AS Compania, CAST('' AS DATETIME) AS Fecha,CAST('' AS DATETIME) AS FechaVence, CAST('' AS DATETIME) AS FecInicio,
CAST('' AS DATETIME) AS FecFinal,'' AS IdCliente, '' AS RazonSocial, '' AS IdAgencia, '' AS CodAgencia, '' AS Agencia, '' AS DirAgncia, '' AS TelAgncia,'' AS Referencia, 
'' AS IdVend, '' AS NomVendedor, '' AS TipoContrato, '' AS  TipoPago, CAST('' AS DATETIME) AS Vigencia, '' AS IdTarifCom, '' AS Modalidad, CAST('' AS MONEY) AS  VrCobro,
CAST('' AS MONEY) AS VrEditado, CAST('' AS MONEY) AS  VrPagos, CAST('' AS MONEY) AS VrCargos, CAST('' AS MONEY) AS  VrDctos, CAST('' AS MONEY) AS VrIva, '' AS CdDescuento,
CAST(@VrDef AS DECIMAL(14,4)) AS Cantidad, CAST(@VrDef AS DECIMAL(14,4)) AS CantPasajeros, CAST('' AS INT) AS NumAprob, ''AS IdCiaApr, CAST('' AS DATETIME) AS FecAprob,
'' AS OrigenAdd, CAST('' AS BIT) AS Anulado, CAST('' AS DATETIME) AS FecDev, '' AS Observacion, CAST('' AS MONEY) AS Presupuesto, CAST('' AS MONEY) AS Peso, '' AS IdMneda,
'' AS Mneda, CAST('' AS BIT) AS EsLicitacion, '' AS IdEstado, '' AS  Estado, CAST('' AS DATETIME) AS TimeSys, CAST('' AS DATETIME) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario,
'' AS Usuario,'' AS CdCarga, CAST('' AS INT) AS CantDias,
-- Datos de anexo
'' AS NomCliente, '' AS DirCliente, '' AS NomContacto, '' AS TelContacto, '' AS emlContacto, '' AS emlCliente, '' AS DescripCarga, '' AS Clausulas,
--Datos de detalles
CAST('' AS INT) AS Item, '' AS CdTipVeh, '' AS TipoVehiculo, CAST('' AS INT) AS NumPasajeros, '' AS Parada, CAST(@VrDef AS DECIMAL(14,4)) AS PesoNeto, CAST('' AS MONEY) AS VrUnitario,
'' AS IdRuta, '' AS Ruta,'' AS Referencia1, '' AS Referencia2, ''AS Referencia3,CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' AS CiuOrigenD, '' AS DeptOrigen, '' AS DirOrigen,
CAST('' AS DATETIME) AS FecOrigen,'' AS CdCiuDestino, '' AS  CiuDestinoD, '' AS  DeptDestino, '' AS DirDestino, CAST('' AS DATETIME) AS FecDestino, '' AS CdTipRuta, '' AS CdTipServicio,
CAST('' AS INT) AS DiasDisp, CAST('' AS MONEY) AS  VrDia, '' AS TipCtn, CAST('' AS INT) AS  NumCnt, '' AS IdCiaCnt, CAST('' AS INT) AS ItemCnt, CAST('' AS INT) AS Cantveh, CAST('' AS BIT) AS Retorno,
CAST('' AS MONEY) AS VrMonitor, CAST('' AS INT) AS CantMonitor, '' AS TipoTarifa, CAST('' AS INT) AS Dias, '' AS Itinerario, CAST('' AS BIT) AS VLargo, CAST('' AS INT) AS ItemPpalRet,
'' AS CiaPpalRet, CAST('' AS MONEY) AS  VrPago,
--Datos de conceptos
'' AS TipoDoc, CAST('' AS INT) AS Documento, '' AS IdCiaC, CAST('' AS INT) AS Itemc, '' AS Descripcion, CAST(@VrDef AS DECIMAL(14,4)) AS Tarifa, '' AS TipoConc, '' AS RubroConcep, CAST('' AS INT) AS Cantidadc,
CAST('' AS MONEY) AS VrUnitarioc, CAST(@VrDef AS DECIMAL(14,4)) AS TarifIva, '' AS IdConcepto, '' AS CdCuenta, '' AS NitTercero, '' AS  NombreTerc, '' AS CdTipoEscc, '' AS TipEsc, CAST('' AS DATETIME) AS FechaNov, 
CAST('' AS MONEY) AS VrBase, '' AS TipoTarif, '' AS RefConc, CAST('' AS BIT) AS Fijos, CAST('' AS INT) AS IncBaseRet, '' AS Referencia2c, '' AS Referencia3c, CAST('' AS INT) AS ItemDoc,
--Datos del cliente
'' AS TipoId, '' AS Dv, ''AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail,
'' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona, '' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupo, '' AS GrupoClie
 END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPedidoRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPedidoRel]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Pedido,'' IdCia,'' AS Compania,'' AS CdCarga,'' AS DescripCarga,CAST('' AS datetime) AS Fecha,CAST('' AS datetime) AS FechaVence,CAST('' AS datetime) AS FecInicio,CAST('' AS datetime) AS FecFinal,
'' AS IdCliente,'' AS RazonSocial,'' AS IdAgencia, '' AS CodAgencia,'' AS Agencia,'' AS DirAgncia,'' AS TelAgncia,CAST('' AS Money) AS VrCupo,CAST('' AS Money) AS VrSaldo,
'' AS NomCliente,'' AS DirCliente,'' AS NomContacto,'' AS TelContacto, '' AS emlContacto,'' AS IdVend,''  AS NomVendedor,'' AS IdTarifCom,'' AS Modalidad,
'' AS TipoContrato,'' AS  TipoPago,'' AS  Vigencia, CAST('' AS Money) AS VrCobro,CAST('' AS Money) AS  VrEditado,CAST('' AS Money) AS  VrPagos,CAST('' AS Money) AS  VrCargos,CAST('' AS Money) AS  VrDctos,CAST('' AS Money) AS  VrIva,
'' AS  CdDescuento,CAST('' AS INT) AS  Cantidad,CAST('' AS INT) AS CantPasajeros, '' AS  NumAprob,'' AS IdCiaApr,CAST('' AS datetime) AS FecAprob,CAST('' AS Money) AS Presupuesto,'' AS Peso,'' AS IdMneda,'' AS Mneda,
CAST('' AS bit) AS EsLicitacion, CAST('' AS datetime) AS FecDev,'' AS  Observacion,'' AS IdEstado,'' AS Estado,CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate,
'' AS OrigenAdd,CAST('' AS bit) AS Anulado,'' AS IdCiaCrea, '' AS IdUsuario,'' AS Usuario
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPedidoRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPedidoRelDet]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT '' AS TipDoc, CAST('' AS INT) AS Pedido, '' AS IdCia, '' AS Compania, CAST('' as datetime) AS Fecha, CAST('' as datetime) AS FechaVence, 
CAST('' as datetime) AS FecInicio, CAST('' as datetime) AS FecFinal, '' AS IdCliente, '' AS RazonSocial, '' AS IdAgencia, '' AS CodAgencia, '' AS Agencia,
'' AS DirAgncia, '' AS TelAgncia, '' AS Referencia, '' AS IdVend, '' AS NomVendedor, '' AS TipoContrato, '' AS TipoPago, CAST('' AS INT) AS Vigencia,
'' AS IdTarifCom, '' AS Modalidad, CAST('' AS Money) AS VrCobro, CAST('' AS Money) AS VrEditado, CAST('' AS Money) AS VrPagos, CAST('' AS Money) AS VrCargos,
CAST('' AS Money) AS VrDctos,CAST('' AS Money) AS VrIva, '' AS CdDescuento, CAST('' AS INT) AS Cantidad, CAST('' AS INT) AS CantPasajeros,
 '' AS NumAprob, '' AS IdCiaApr,CAST('' AS datetime) AS FecAprob, CAST('' AS bit) AS Anulado,CAST('' AS datetime) AS FecDev,'' AS Observacion,
CAST('' AS Money) AS Presupuesto,'' AS Peso,'' AS IdMneda, '' AS Mneda, CAST('' AS bit) AS EsLicitacion, '' AS IdEstado, '' AS Estado,
CAST('' AS datetime) AS TimeSys, CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea, '' AS IdUsuario, '' AS Usuario, '' AS CdCarga,
--Anexos
'' AS NomCliente,'' AS DirCliente,''  AS NomContacto,'' AS TelContacto,'' AS emlContacto, '' AS emlCliente,'' AS DescripCarga, '' AS Clausulas,
--Detalles
CAST('' AS INT) AS Item, '' AS CdTipVeh, '' AS TipoVehiculo, CAST('' AS INT) AS NumPasajeros,
'' AS Parada,'' AS PesoNeto, CAST('' AS Money) AS VrUnitario, '' AS IdRuta, '' AS Ruta, '' AS  Referencia1, '' AS Referencia2, '' AS Referencia3, 
CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' as CiuOrigenD, '' AS DeptOrigen, ''AS DirOrigen, CAST('' AS datetime) AS FecOrigen,
'' AS CdCiuDestino, '' AS  CiuDestinoD,'' AS DeptDestino, '' AS DirDestino,CAST('' AS datetime) AS FecDestino, '' AS CdTipRuta, '' AS CdTipServicio, 
CAST('' AS INT) AS  DiasDisp,CAST('' AS Money) AS VrDia,'' AS TipCtn,CAST('' AS INT) AS NumCnt, '' AS IdCiaCnt, CAST('' AS INT) AS ItemCnt,
CAST('' AS bit) AS VLargo, CAST('' AS INT) AS ItemPpalRet, '' AS CiaPpalRet,
--Conceptos
'' AS TipoDoc, '' AS Documento,''  AS IdCiaC, CAST('' AS INT) AS Itemc, '' AS Descripcion,'' AS Tarifa, '' AS TipoConc, '' AS RubroConcep, 
CAST('' AS INT) AS Cantidadc, CAST('' AS Money) AS VrUnitarioc, '' AS TarifIva, '' AS IdConcepto, '' AS CdCuenta, '' AS NitTercero,
'' AS NombreTerc,'' AS CdTipoEscc, '' AS TipEsc, CAST('' AS datetime) AS FechaNov, CAST('' AS Money) AS VrBase, ''  AS TipoTarif, '' AS RefConc,
'' AS Fijos, '' AS IncBaseRet, '' AS Referencia2c,'' AS Referencia3c,
--Datos del cliente
'' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail, '' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona,
'' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupo, '' AS GrupoClie




GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPgrFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPgrFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
--Encabezado
SELECT '' AS TipDoc, CAST('' AS INT) AS Programa,'' IdCia,'' AS Compania, CAST('' AS datetime) AS Fecha, '' AS OrigenAdd,
CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys,
CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario,
--Detalles
CAST('' AS INT) AS Item, CAST('' AS datetime) AS FechaInicio, CAST('' AS datetime) AS FechaFin,'' AS TipDocRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, 
CAST('' AS INT) AS ItemRes, CAST('' AS datetime) AS eFechaIniRes, CAST('' AS datetime) AS eFechaFinRes, '' AS IdEstadoRes, '' AS EstadoItemRes, '' Modalidad,
'' AS IdOrigen, '' AS CiuOrigen, '' AS DeptOrigen, '' AS IdDestino, '' AS CiuDestino, '' AS DeptDestino, '' AS IdVehiculo, '' AS NumVeh, ''   AS TipoAfil,
'' AS CdTipVeh, '' AS TipoVehiculo, '' AS ClaseMat, '' AS IdConductor, '' AS NomConductor, CAST('' AS INT) AS NumPasajeros,  '' AS TipDocFuec, 
CAST('' AS INT) AS NumFuec, '' AS IdCiaFuec,  '' AS TipDocOdp, CAST('' AS INT) AS NumOdp, '' AS IdCiaOdp, CAST('' AS datetime) FechaOdp,
'' AS IdNovedad, '' AS Novedad, CAST('' AS BIT) AS Cumplido, CAST('' AS datetime) AS FecIniCump, CAST('' AS datetime) AS FecFinCump,
CAST('' AS MONEY) AS VrCobro, CAST('' AS MONEY) AS VrPagos, CAST('' AS INT) AS DiasDisp, '' AS Parada, '' AS CdTipServicio, '' AS DirOrigen, ''  AS DirDestino,
'' AS IdRuta, '' AS Ruta, '' AS CdTipRuta, CAST(@VrDef AS DECIMAL(14,4)) AS PesoNeto, '' AS EstadoItem, CAST('' AS money) AS VrMonitor,
CAST('' AS INT) AS CantMonitor, CAST('' AS money) AS VrRecorrido, '' AS Observacion, CAST('' AS BIT) AS VLargo,
--Datos de la reserva
'' AS IdCliente, '' AS Cliente, '' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS CiuCliente, '' AS Telefono, '' AS e_mail, '' AS EstadoRes,
'' AS IdAgencia, '' AS Agencia , '' AS Modalidad, '' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona, '' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupo, '' AS GrupoClie,
CAST('' AS datetime) AS FechaIniRes, CAST('' AS datetime) AS FechaFinRes, '' AS TipFac, CAST('' AS INT) AS Factura, CAST('' AS INT) AS IdCiaFac, CAST('' AS datetime) AS FechaFac, '' AS ObsReserva, '' AS NombreResp
END
          
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPgrRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPgrRel]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Programa,'' IdCia,'' AS Compania, CAST('' AS datetime) AS Fecha, '' AS OrigenAdd,
CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys,
CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspPgrRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspPgrRelDet]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Programa,'' IdCia,'' AS Compania, CAST('' AS datetime) AS Fecha, '' AS OrigenAdd,
CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys,
CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario,
--Detalles
CAST('' AS INT) AS Item, CAST('' AS datetime) AS FechaInicio, CAST('' AS datetime) AS FechaFin,'' AS TipDocRes, CAST('' AS INT) AS Reserva, '' AS IdCiaRes, 
CAST('' AS INT) AS ItemRes, CAST('' AS datetime) AS FechaIniRes, CAST('' AS datetime) AS FechaFinRes, '' AS IdEstadoRes, '' AS EstadoItemRes, '' AS Modalidad, '' AS IdOrigen,
'' AS CiuOrigen, '' AS DeptOrigen, '' AS IdDestino, '' AS CiuDestino, '' AS DeptDestino, '' AS IdVehiculo, '' AS NumVeh, '' AS TipoAfil, '' AS CdTipVeh, '' AS TipoVehiculo,
'' AS IdConductor, '' AS NomConductor, CAST('' AS INT) AS NumPasajeros, '' AS TipDocFuec, CAST('' AS INT) AS NumFuec, '' AS IdCiaFuec, '' AS TipDocOds, 
CAST('' AS INT) AS NumOds, '' AS IdCiaOds, '' AS IdNovedad, '' AS Novedad, CAST('' AS BIT) AS Cumplido, CAST('' AS datetime) AS FecIniCump, CAST('' AS datetime) AS FecFinCump,
CAST('' AS MONEY) AS VrCobro, CAST('' AS MONEY) AS VrPagos, CAST('' AS INT) AS DiasDisp, '' AS Parada, '' AS CdTipServicio, '' AS DirOrigen, ''  AS DirDestino,
'' AS IdRuta, '' AS Ruta, '' AS CdTipRuta, '' AS PesoNeto, '' AS EstadoItem, CAST('' AS money) AS VrRecorrido,
--Datos de la reserva
'' AS IdCliente, '' AS Cliente, '' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail, '' AS EstadoRes,
'' AS IdAgencia, '' AS Agencia , '' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona, '' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupo, '' AS GrupoClie
          
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspProgramaPers]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspProgramaPers]
WITH EXECUTE AS CALLER
AS
--Detalle
SELECT '' AS TipDoc,  CAST('' AS INT) AS Programa, '' AS IdCia, CAST('' AS INT) AS  Item, '' AS IdVehiculo, '' AS Nit, '' AS RazonSocial,
'' AS IdNovedad, '' AS Novedad, CAST('' AS BIT) AS Cumplido, '' AS IdRuta, '' AS Ruta

GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspReservasFmt]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspReservasFmt]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
--Encabezado
SELECT '' AS TipDoc, CAST('' AS INT) AS Reserva,'' IdCia,'' AS Compania, '' AS TipDocCnt, CAST('' AS INT) AS Contrato, '' AS IdCiaCnt, CAST('' AS Money) AS VrPresupuesto,
CAST('' AS Money) AS VrSaldoPresup, '' AS IdCliente,'' AS RazonSocial,CAST('' AS datetime) AS Fecha, CAST('' AS datetime) AS FechaInicio,CAST('' AS datetime) AS FechaFin,
'' AS EstadoRes, '' AS IdAgencia,'' AS Agencia, '' AS IdMneda, '' AS Mneda, '' AS CdCarga,'' AS Modalidad, '' AS TipoLiquid, '' AS TipFac, CAST('' AS INT) AS  Factura,
'' AS IdCiaFac,CAST('' AS datetime) AS FechaFac, '' AS TipFuec, CAST('' AS INT) AS  NumFuec, '' AS IdCiaFuec,CAST('' AS Money) AS  TotalCobro,CAST('' AS Money) AS  TotalPagos, 
'' AS OrigenAdd,CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate,
'' AS IdCiaCrea, '' AS IdUsuario,'' AS Usuario, '' AS IdGrupo,'' AS Grupo, ''AS IdRutaG, '' AS RutaG,
--Anexos
'' AS NomCliente, '' AS TelCliente, '' AS emlCliente,'' AS DireccionCli,
'' AS Observacion,''  AS NombArchivo,'' AS DescripCarga, '' AS Clausulas, '' AS Responsable,
--Detalles
CAST('' AS INT) AS Item, CAST('' AS INT) AS ItemCnt, '' AS IdVehiculo, '' AS NumVeh, '' AS ClaseMat, '' AS CdTipVeh, '' AS TipoVehiculo,'' AS TipoAfil, '' AS IdMarca, '' AS Marca,
'' AS TarjOper, '' AS Modelo, '' AS IdPropietario,'' AS NomPropietario, '' AS IdPoseedor,'' AS NomPoseedor, '' AS IdConductor,'' AS NomConductor, '' AS IdRuta, '' AS Ruta, 
'' AS CdTipRuta, CAST('' AS INT) AS NumPasajeros, CAST(@VrDef AS DECIMAL(14,4)) AS PesoNeto, CAST('' AS Money) AS VrCobro, CAST('' AS Money) AS VrPagos, '' AS Referencia1, 
'' AS Referencia2, '' AS Referencia3, CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' as CiuOrigenD, '' AS DeptOrigen, '' AS DirOrigen, CAST('' AS datetime) AS FecOrigen, 
'' AS CdCiuDestino, '' AS  CiuDestinoD,'' AS DeptDestino, '' AS DirDestino,CAST('' AS datetime) AS FecDestino, CAST('' AS INT) AS  DiasDisp, CAST('' AS Money) AS VrDia, '' AS Parada, 
'' AS CdTipServicio, '' AS EstadoItem, CAST('' AS MONEY) AS VrMonitor, CAST('' AS INT) AS CantMonitor, CAST('' AS MONEY) AS VrRecorrido, CAST('' AS INT) AS NumDias, '' AS TipoTarifa, 
'' AS IdColegio, '' AS NomColegio, '' AS TFac, CAST('' AS INT) AS Fact, '' AS CiaFact, CAST('' AS datetime) AS FecFac, '' AS TipCum, CAST('' AS INT) AS Cumplido, '' AS IdCiaCum, 
CAST('' AS datetime) AS FechaCum, '' AS Codigo, '' AS Itinerario, CAST('' AS BIT) AS VLargo, CAST('' AS BIT) AS IdOtroSi, CAST('' AS BIT) AS ProcEstudte,
--Datos del cliente
'' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail, '' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona,
'' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupoClie, '' AS GrupoClie,
--Detalles programaciÃ³n  Se suprime porque duplica los Ã­tems ya que una reserva puede estar enmuchas programaciones
--'' AS TipDocPgr, CAST('' AS INT) AS Programa, '' AS IdCiaPgr, CAST('' AS INT) AS ItemPgr, CAST('' AS datetime) AS FecInicPgr,  CAST('' AS datetime) AS FecFinPgr,
--Datos de Ruta
CAST(@VrDef AS DECIMAL(14,4)) AS Distkmt
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspReservasRel]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspReservasRel]
WITH EXECUTE AS CALLER
AS
SELECT '' AS TipDoc, CAST('' AS INT) AS Reserva,'' IdCia,'' AS Compania, '' AS TipDocCnt, CAST('' AS INT) AS Contrato, '' AS IdCiaCnt,
'' AS CdCarga,'' AS DescripCarga,CAST('' AS datetime) AS Fecha, CAST('' AS datetime) AS FechaInicio,CAST('' AS datetime) AS FechaFin,
'' AS IdCliente,'' AS RazonSocial,'' AS IdAgencia, '' AS CodAgencia,'' AS Agencia,'' AS DirAgncia,'' AS TelAgncia,CAST('' AS Money) AS VrCupo,
CAST('' AS Money) AS VrSaldo, '' AS NomCliente,'' AS TelCliente, '' AS emlCliente , '' AS DireccionCli,'' AS IdMneda, '' AS Mneda, '' AS EstadoRes,
'' AS Modalidad,'' AS  TipoLiquid,  '' AS TipFac, CAST('' AS INT) AS  Factura, '' AS IdCiaFac,CAST('' AS datetime) AS FechaFac, '' AS TipOdp, 
CAST('' AS INT) AS  NumOdp, '' AS IdCiaOdp,CAST('' AS datetime) AS FechaOdp, '' AS TipFuec, CAST('' AS INT) AS NumFuec, '' AS IdCiaFuec,
CAST('' AS Money) AS  VrCobro,CAST('' AS Money) AS  VrPagos, '' AS OrigenAdd, CAST('' AS bit) AS Anulado, CAST('' AS datetime) AS FecDev,
'' AS Observacion, '' AS NombArchivo, '' AS Clausulas, '' AS Responsable, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys,
CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,'' AS IdUsuario,'' AS Usuario
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_TraEspReservasRelDet]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_TraEspReservasRelDet]
WITH EXECUTE AS CALLER
AS
--Encabezado
SELECT '' AS TipDoc, CAST('' AS INT) AS Reserva,'' IdCia,'' AS Compania, '' AS TipDocCnt, CAST('' AS INT) AS Contrato, '' AS IdCiaCnt, CAST('' AS Money) AS VrPresupuesto,
CAST('' AS Money) AS VrSaldoPresup, '' AS IdCliente,'' AS RazonSocial,CAST('' AS datetime) AS Fecha, CAST('' AS datetime) AS FechaInicio,CAST('' AS datetime) AS FechaFin,
'' AS EstadoRes, '' AS IdAgencia,'' AS Agencia, '' AS IdMneda, '' AS Mneda, '' AS CdCarga,'' AS Modalidad, '' AS TipoLiquid, '' AS TipFac, CAST('' AS INT) AS  Factura,
'' AS IdCiaFac,CAST('' AS datetime) AS FechaFac, '' AS TipOdp, CAST('' AS INT) AS  NumOdp, '' AS IdCiaOdp,CAST('' AS datetime) AS FechaOdp,'' AS TipFuec,
CAST('' AS INT) AS NumFuec, '' AS IdCiaFuec, CAST('' AS Money) AS  TotalCobro,CAST('' AS Money) AS  TotalPagos, '' AS OrigenAdd,CAST('' AS bit) AS Anulado,
CAST('' AS datetime) AS FecDev, '' AS IdEstado,'' AS Estado, CAST('' AS datetime) TimeSys, CAST('' AS datetime) AS FecUpdate, '' AS IdCiaCrea,
'' AS IdUsuario,'' AS Usuario,
--Anexos
'' AS NomCliente, '' AS TelCliente, '' AS emlCliente,'' AS DireccionCli,
'' AS Observacion,''  AS NombArchivo,'' AS DescripCarga, '' AS Clausulas, '' AS Responsable,
--Detalles
CAST('' AS INT) AS Item, CAST('' AS INT) AS ItemCnt, '' AS IdVehiculo,'' AS CdTipVeh, '' AS TipoVehiculo,'' AS TipoAfil, '' AS IdPropietario,'' AS NomPropietario,
'' AS IdPoseedor,'' AS NomPoseedor, '' AS IdConductor,'' AS NomConductor, '' AS IdRuta, '' AS Ruta, '' AS CdTipRuta, CAST('' AS INT) AS NumPasajeros, '' AS PesoNeto, 
CAST('' AS Money) AS VrCobro, CAST('' AS Money) AS VrPagos, '' AS Referencia1, '' AS Referencia2, '' AS Referencia3, '' AS TipOdp, CAST('' AS INT) AS  NumOdp, 
'' AS IdCiaOdp,CAST('' AS datetime) AS FechaOdp, CAST('' AS BIT) AS EsRutaCliente, '' AS CdCiuOrigen, '' as CiuOrigenD, '' AS DeptOrigen, '' AS DirOrigen, 
CAST('' AS datetime) AS FecOrigen, '' AS CdCiuDestino, '' AS  CiuDestinoD,'' AS DeptDestino, '' AS DirDestino,CAST('' AS datetime) AS FecDestino, CAST('' AS INT) AS  DiasDisp,
CAST('' AS Money) AS VrDia, '' AS Parada, '' AS CdTipServicio, '' AS EstadoItem, CAST('' AS MONEY) AS VrMonitor, CAST('' AS INT) AS CantMonitor, CAST('' AS MONEY) AS VrRecorrido,
CAST('' AS INT) AS NumDias, '' AS TipoTarifa, '' AS IdColegio, '' AS NomColegio, '' AS TFac, CAST('' AS INT) AS Fact, '' AS CiaFact, CAST('' AS datetime) AS FecFac,
'' AS TipCum, CAST('' AS INT) AS Cumplido, '' AS IdCiaCum, CAST('' AS datetime) AS FechaCum, '' AS Codigo,
--Datos del cliente
'' AS TipoId, '' AS Dv, '' AS Codigo, '' AS NomCial, '' AS Direccion, '' AS Telefono, '' AS e_mail, '' AS NitRepLeg, '' AS NomRepLeg, '' AS IdSzona,
'' AS Subzona, '' AS IdZona, '' AS Zona, '' AS IdGrupo, '' AS GrupoClie,
--Detalles programaciÃ³n
'' AS TipDocPgr, CAST('' AS INT) AS Programa, '' AS IdCiaPgr, CAST('' AS INT) AS ItemPgr, CAST('' AS datetime) AS FecInicPgr,  CAST('' AS datetime) AS FecFinPgr,
--Datos de Ruta
'' AS Distkmt,
--Fecha DÃ­a para reporte estimado horas
CAST('' AS datetime) FechaDia
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_VenceAbonos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_VenceAbonos]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
 '' AS TipRec, CAST('' AS INT) AS Recibo, '' AS IdCia, '' AS Item, '' AS Fecha,
 '' AS TipDoc, CAST('' AS INT) AS Factura, '' AS IdCiaFac, CAST('' AS INT) AS ItemFac, 
 CAST('' AS MONEY) AS VrAbono, CAST('' AS MONEY) AS VrDescto, CAST('' AS MONEY) VrBaseCms, ''  AS IdCliente,
'' AS IdAgncia, '' AS IdVend, CAST(@VrDef AS DECIMAL(14,4)) AS Comision, '' AS Detalle, CAST('' AS DATETIME) AS FecPago,  
 '' AS TipoAplica, CAST('' AS DATETIME) AS TimeSys
--datos del vencimiento
--CAST('' AS DATETIME) AS FechaFac, CAST('' AS DATETIME) AS FechaVence, CAST('' AS MONEY) AS VrFactura, CAST('' AS MONEY) AS TotalAbonos,
--CAST(@VrDef AS DECIMAL(14,4)) AS TarifDcto, '' AS TipoDcto, '' AS TipoBase, CAST('' AS DATETIME) AS FecLmtDcto, '' AS CdConcepto, '' AS Concepto,
--'' AS Referncia, '' AS DetalleVecmto, '' AS TipRef, CAST('' AS INT) AS DocRef, '' AS IdCiaRef, CAST('' AS DATETIME) AS FecUltPago,
--CAST('' AS INT) AS NumNota, '' AS IdCiaNot, CAST(@VrDef AS DECIMAL(14,4)) AS TarifInt, CAST('' AS DATETIME) AS FecLiqMora
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeLisTrn_VencimientosDoc]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeLisTrn_VencimientosDoc]
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @VrDef VARCHAR(1) = '1'
SELECT 
'' AS TipDoc, CAST('' AS INT) AS Factura,'' AS IdCia,'' AS Compania, CAST('' AS INT) AS Item, CAST('' AS datetime) AS Fecha, 
CAST('' AS datetime) AS FechaVence,  CAST('' AS money) AS VrFactura, CAST('' AS money) AS VrAbonado, '' AS IdCliente, '' AS IdAgencia,
'' AS IdVend, CAST(@VrDef AS DECIMAL(14,4)) AS Comision, CAST(@VrDef AS DECIMAL(14,4)) AS TarifDcto, CAST('' AS char) AS TipoDcto, 
'' AS TipoBase, CAST('' AS datetime) AS FecLmtDcto, '' AS IdConcepto, '' AS Referencia, '' AS Detalle, '' AS TipRef, CAST('' AS INT) AS DocRef,
'' AS IdCiaRef, CAST('' AS datetime) AS FecUltPago,	 CAST('' AS INT) AS NumNota, '' AS IdCiaNot, CAST(@VrDef AS DECIMAL(14,4)) AS TarifInt,
CAST('' AS smalldatetime) AS FecLiqMora, CAST('' AS smalldatetime) AS FecPlazoCal
END
GO
/****** Object:  StoredProcedure [dbo].[paWcfSeUpdateItemTrn_TraEspPrograma]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfSeUpdateItemTrn_TraEspPrograma]
	@Trn_TraEspPrograma [dbo].[dataTypeTrn_TraEspPrograma] READONLY,
	@Trn_TraEspProgramaDet [dbo].[dataTypeTrn_TraEspProgramaDet] READONLY,
	@Trn_TraEspProgramaPers [dbo].[dataTypeTrn_TraEspProgramaPers] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
DECLARE @Documento INT --Esta variable guarda el nÃºmero de consecutivo del Reserva/CotizaciÃ³n
DECLARE @TipDoc VARCHAR(3) --Esta variable guarda el tipo de documento del Reserva/CotizaciÃ³n
DECLARE @IdCia VARCHAR(4) --Esta variable guarda la compaÃ±ia del Reserva/CotizaciÃ³n
declare @IdEstado varchar(4)
declare @item int 
declare @kmp varchar 
	BEGIN TRAN
		BEGIN TRY
			--UPDATE SI-EXISTE RECORDS
			IF(@operacion = 'u')
			BEGIN

			IF(EXISTS(SELECT * FROM @Trn_TraEspPrograma))
			begin
			   UPDATE Trn_TraEspPrograma
			   SET 
			   TipDoc = t2.TipDoc,Programa = t2.Programa,IdCia = t2.IdCia,
			   Fecha = t2.Fecha,OrigenAdd = t2.OrigenAdd,Anulado = t2.Anulado,
			   FecDev = t2.FecDev,IdEstado = t2.IdEstado,TimeSys = t2.TimeSys,
			   FecUpdate = t2.FecUpdate,IdCiaCrea = t2.IdCiaCrea,IdUsuario = t2.IdUsuario
		       FROM Trn_TraEspPrograma t1
			   JOIN @Trn_TraEspPrograma t2 ON t1.TipDoc = t2.TipDoc and t1.Programa = t2.Programa and t1.IdCia = t2.IdCia
			end

			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaDet))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Programa FROM @Trn_TraEspProgramaDet
			   select @item =  isnull(MAX(Item),0) from Trn_TraEspProgramaDet where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia

			   --se actuallizan los que vienen en el tipo de dato y coincidan con los que estan el la tabla
			   UPDATE Trn_TraEspProgramaDet
			   SET 
			   TipDoc = t2.TipDoc,Programa = t2.Programa,IdCia = t2.IdCia,Item = t2.Item,
			   FechaInicio = t2.FechaInicio,FechaFin = t2.FechaFin,TipDocRes = t2.TipDocRes,
			   Reserva = t2.Reserva,IdCiaRes = t2.IdCiaRes,ItemRes = t2.ItemRes,IdOrigen = t2.IdOrigen,
			   IdDestino = t2.IdDestino,IdVehiculo = t2.IdVehiculo,
			   CdTipVeh = t2.CdTipVeh,IdConductor = t2.IdConductor,NumPasajeros = t2.NumPasajeros,TipDocFuec = t2.TipDocFuec,
			   NumFuec = t2.NumFuec,IdCiaFuec = t2.IdCiaFuec,TipDocOdp = t2.TipDocOdp,NumOdp = t2.NumOdp,
			   IdCiaOdp = t2.IdCiaOdp,FechaOdp=t2.FechaOdp,IdNovedad = t2.IdNovedad,Novedad = t2.Novedad,Cumplido = t2.Cumplido,FecIniCump = t2.FecIniCump, FecFinCump = t2.FecFinCump,
			   VrCobro = t2.VrCobro, VrPagos = t2.VrPagos,DiasDisp= t2.DiasDisp,Parada= t2.Parada,CdTipServicio= t2.CdTipServicio,
			   DirOrigen= t2.DirOrigen,DirDestino= t2.DirDestino,IdRuta= t2.IdRuta,CdTipRuta= t2.CdTipRuta,PesoNeto= t2.PesoNeto,EstadoItem=t2.EstadoItem,
			   VrMonitor=t2.VrMonitor,CantMonitor=t2.CantMonitor,VrRecorrido= t2.VrRecorrido, Observacion= t2.Observacion,VLargo = t2.VLargo
		       FROM Trn_TraEspProgramaDet t1
			   JOIN @Trn_TraEspProgramaDet t2 ON t1.TipDoc = t2.TipDoc and t1.Programa = t2.Programa and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   WHERE t1.TipDoc = t2.TipDoc and t1.Programa = t2.Programa and t1.IdCia = t2.IdCia and t1.Item = t2.Item
			   --Actualizar estado de vehiculo CUANDO NO TIENE NOVEDAD
			   UPDATE Vehiculos
			   SET IdEstado = '0002'
			   FROM Vehiculos v
			   JOIN @Trn_TraEspProgramaDet pd ON v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad = '0' and pd.Cumplido = 0
			   WHERE v.IdVehiculo = pd.IdVehiculo 


			   --Actualizar estado de vehiculo CUANDO TENGA NOVEDAD DE TIPO VEHICULO
			   ----DECLARE @IDNOV VARCHAR(4)
			   ----SELECT @IDNOV = IdNovedad FROM @Trn_TraEspProgramaDet
			   ----IF(UPPER((select Tipo from TiposNovPgr where IdNovedad = @IDNOV)) = 'VEHICULO')
			   ----BEGIN
				  ---- UPDATE Vehiculos
				  ---- SET IdEstado = (select IdEstado from TiposNovPgr where IdNovedad = pd.IdNovedad and Tipo = 'VEHICULO')
				  ---- FROM Vehiculos v
				  ---- JOIN @Trn_TraEspProgramaDet pd ON v.IdVehiculo = pd.IdVehiculo and pd.IdNovedad != '0' and pd.Cumplido = 0
				  ---- WHERE v.IdVehiculo = pd.IdVehiculo 
			   ----END

			    declare @acveh varchar(11)
			    declare @acidnov varchar(4)
				--declare @acItem int
				
				DECLARE acvehic CURSOR
				FOR SELECT IdVehiculo,IdNovedad FROM @Trn_TraEspProgramaDet where IdNovedad != '0' and Cumplido = 0
				OPEN acvehic
				FETCH NEXT FROM acvehic INTO @acveh,@acidnov
				WHILE @@FETCH_STATUS = 0
				BEGIN
				   UPDATE Vehiculos
				   SET IdEstado = tn.IdEstado
				   FROM Vehiculos v, TiposNovPgr tn
				   WHERE v.IdVehiculo = @acveh and tn.IdNovedad = @acidnov and tn.Tipo = 'VEHICULO'
				FETCH NEXT FROM acvehic INTO @acveh,@acidnov
				END
				CLOSE acvehic
				DEALLOCATE acvehic

			   --ACTUALIZAR RESERVAS 
			   ----UPDATE Trn_TraEspResDetalle
			   ----SET EstadoItem = 'PROGRAMADA'
			   ----FROM Trn_TraEspResDetalle p
			   ----JOIN @Trn_TraEspProgramaDet d ON p.TipDoc = d.TipDocRes  and p.Reserva = d.Reserva and p.IdCia = d.IdCiaRes and p.Item = d.ItemRes
			   ----WHERE d.TipDoc = @TipDoc and d.Programa = @Documento and d.IdCia = @IdCia and d.IdNovedad = '0' and d.Cumplido = 0

			   	declare @acReserva int
				declare @acCiaRes varchar(2)
				declare @acItem int
				
				DECLARE acres CURSOR
				FOR SELECT Reserva,IdCiaRes,ItemRes FROM @Trn_TraEspProgramaDet where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and IdNovedad = '0' and Cumplido = 0
				OPEN acres
				FETCH NEXT FROM acres INTO @acReserva,@acCiaRes,@acItem
				WHILE @@FETCH_STATUS = 0
				BEGIN
					UPDATE Trn_TraEspResDetalle
					SET EstadoItem = 'PROGRAMADA'
					FROM Trn_TraEspResDetalle p
					WHERE  p.TipDoc = 'RES' and p.Reserva = @acReserva and p.IdCia = @acCiaRes and p.Item = @acItem
					-- Fecha:20/11/2017 Se desactiva esta condiciÃ³n porque al entrar 2 usuarios a hacer la misma operaciÃ³n queda desactualizado 
					-- el nÃºmero de consecutivo que se obtiene en el software y se actualizarÃ­a reservas del primera operaciÃ³n, en este caso, quedarÃ­a mal para la segunada transacciÃ³n.
					--WHERE d.TipDoc = @TipDoc and d.Programa = @Documento and d.IdCia = @IdCia
				FETCH NEXT FROM acres INTO @acReserva,@acCiaRes,@acItem
				END
				CLOSE acres
				DEALLOCATE acres

			   --ACTUALIZAR Vehiculos en ProgramaPers 
			   UPDATE Trn_TraEspProgramaPers
			   SET IdVehiculo = d.IdVehiculo
			   FROM Trn_TraEspProgramaPers p
			   JOIN @Trn_TraEspProgramaDet d ON p.TipDoc = d.TipDoc  and p.Programa = d.Programa and p.IdCia = d.IdCia and p.Item = d.Item
			   WHERE p.TipDoc = d.TipDoc and p.Programa = d.Programa and p.IdCia = d.IdCia and p.Item= d.Item and d.IdNovedad = '0' and d.Cumplido = 0

			   end

			   IF(EXISTS(SELECT * FROM @Trn_TraEspProgramaPers))
			   begin
			   SELECT TOP 1 @TipDoc = TipDoc, @IdCia = IdCia, @Documento = Programa, @item = Item FROM @Trn_TraEspProgramaPers
			
			  --Eliminar los registros
			   delete from Trn_TraEspProgramaPers where TipDoc = @TipDoc and Programa = @Documento and IdCia = @IdCia and Item = @item 
			   --Inserta los que no existen
			   INSERT INTO Trn_TraEspProgramaPers(
			   TipDoc,Programa,IdCia,Item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
	           ) 
			   SELECT 
			   @TipDoc,@Documento,@IdCia,@item,IdVehiculo,Nit,IdNovedad,Novedad,Cumplido,IdRuta
			   FROM @Trn_TraEspProgramaPers
			   			   
			   end

			END
			SELECT @Documento

			COMMIT TRAN
		END TRY
		BEGIN CATCH
			ROLLBACK TRAN
			DECLARE @ErrorMessage NVARCHAR(4000);
			DECLARE @ErrorSeverity INT;
			DECLARE @ErrorState INT;

			SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();
			RAISERROR(
			@ErrorMessage, -- Message text.
			@ErrorSeverity, -- Severity.
			@ErrorState -- State.
			);
		END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[paWcfUpdateKmVehs]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paWcfUpdateKmVehs]
	@UpdateKmVehs [dbo].[dataTypeUpdateKmVehs] READONLY,
	@operacion [varchar](1)
WITH EXECUTE AS CALLER
AS
BEGIN TRAN
	BEGIN TRY		 
		--UPDATE SI-EXISTE RECORDS
		IF(@operacion = 'u')
			BEGIN
				UPDATE Vehiculos
				SET 
				KmActual = t2.KmActual, FechaUpdate = t2.FechaUpdate
				FROM Vehiculos t1
				JOIN @UpdateKmVehs t2 ON t1.Idvehiculo = t2.IdVehiculo
				where t1.IdVehiculo = t2.IdVehiculo and t2.KmActual >= t1.KmActual
			END
		SELECT '1'
		COMMIT TRAN
	END TRY
    BEGIN CATCH
		ROLLBACK TRAN
		DECLARE @ErrorMessage NVARCHAR(4000);
		DECLARE @ErrorSeverity INT;
		DECLARE @ErrorState INT;

		SELECT 
		@ErrorMessage = ERROR_MESSAGE(),
		@ErrorSeverity = ERROR_SEVERITY(),
		@ErrorState = ERROR_STATE();
		RAISERROR(
		@ErrorMessage, -- Message text.
		@ErrorSeverity, -- Severity.
		@ErrorState -- State.
		);
	END CATCH
RETURN 0
GO
/****** Object:  StoredProcedure [dbo].[spArticulos]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[spArticulos] @Tanques BIT,@Fecha SMALLDATETIME
AS
 SELECT IdProducto,DescripProd,DescripAbrv,Referencia,CodBarras,VrCostPmd AS CostoPromed,Precio1,Precio2 
 ,Precio3,Precio4,Precio5,IvaInc,Tarifa AS TarifaIva,ExtciaMax,ExtciaAct,P.IdUnd AS CodUnidad,Unidad,IdEstado,P.Inactivo AS ProdInactivo
,FechaAdd AS FechaCreacion,FechaUpdate AS FechaActualizacion
 FROM  ProdMcias AS P INNER JOIN UndMed AS U ON P.IdUnd=U.IdUnd  LEFT JOIN Tablapor AS T ON P.IdTarIva=T.IdTarifa
 WHERE  TipoRef='PRODUCTO'  AND Tanques=@Tanques 
 AND ISNULL(FechaUpdate,FechaAdd)>@Fecha
ORDER BY IdProducto
GO
/****** Object:  StoredProcedure [dbo].[spClientes]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[spClientes] @Fecha SMALLDATETIME
AS
 SELECT  IdClie AS NitCliente,RazonSocial,Codigo,TipoId,Dv,Direccion,T.IdLocal AS CodLocalidad,Localidad,Telefono,TelMovil,Fax,e_mail
 ,VrCupo,VrSaldo,VrCupo-VrSaldo AS Disponible,Cmntario1,C.IdEstado AS CodEstado,C.Inactivo AS ClieInactivo
,C.FechaAdd AS FechaCreacion,C.FechaUpdate  AS FechaActualizacion
 FROM TercCliente AS C INNER JOIN Terceros AS T ON C.IdClie=T.IdTercero
 INNER JOIN Localidades AS L ON T.IdLocal=L.IdLocal
 WHERE ISNULL(C.FechaUpdate,C.FechaAdd)>@Fecha
 ORDER BY RazonSocial
GO
/****** Object:  StoredProcedure [dbo].[spClieSalarios]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[spClieSalarios] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16) 
 AS 
 SELECT nMes,nAnno,VrSalario,TarifDcto 
 FROM TercClieSalarios
 WHERE  IdClie=@pmIdClie AND IdAgencia=@pmIdAgencia  
 ORDER BY nAnno,nMes
GO
/****** Object:  StoredProcedure [dbo].[spConsultaDatosEventoDian]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spConsultaDatosEventoDian]

AS
BEGIN

	SET NOCOUNT ON;

	SELECT 
	R.NitEmpresa AS NumDocumentoFacturador,
	R.DvNit AS DvFacturador,
	CASE R.TipoId
		WHEN 'N' THEN '31'
		WHEN 'C' THEN '13'
		WHEN 'T' THEN '12'
		WHEN 'R' THEN '11'
		WHEN 'P' THEN '41'
		WHEN 'X' THEN '22'
		ELSE '31'
	END AS TipoDocumentoFacturador,	
	CASE R.TipoPersna
		WHEN 'J' THEN '1'
		ELSE '2'
	END AS TipoPersonaFacturador, 
	R.RazonSocial AS RazonSocialFacturador,
	CASE R.TipoId 
		WHEN 'N' THEN ''
		ELSE SUBSTRING(T.RazonSocial, 0, T.IniStgNom-1)
	END AS ApellidosFacturador,
	CASE R.TipoId 
		WHEN 'N' THEN ''
		ELSE SUBSTRING(T.RazonSocial, T.IniStgNom, LEN(T.RazonSocial))
	END AS NombresFacturador
FROM 
	adm_Registro AS R 
	INNER JOIN Terceros AS T ON R.NitEmpresa = T.IdTercero
END
GO
/****** Object:  StoredProcedure [dbo].[spFinCliente]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[spFinCliente] @pmIdClie VARCHAR(16),@pmIdAgencia VARCHAR(16) 
 AS 
 SELECT RazonSocial,TipoId,Dv,NomCial,e_mail,nPlazo,TipoPlazo,CupoCredito,MaxCupoSmlv,TipoCausac,DiasVence
,EtdoAprob,TipoAprob,DescAprob,EstadoAct,L.FechaCrea AS LinFechaCrea
,EsExento,FecIngreso,VrSalBasico,MaxDcto,TipoSalario,C.IdEstado AS EdoCliente,C.Inactivo AS ClieInactivo,C.FechaCrea AS ClieFechaCrea
,NumTarj,PwdTarj,FecVenceTc
 FROM TercClieLineas AS L INNER JOIN TercCliePrestamo AS C ON L.IdClie=C.IdClie AND L.IdAgencia=C.IdAgencia
 INNER JOIN Terceros AS T ON L.IdClie=T.IdTercero
 WHERE L.IdClie=@pmIdClie AND L.IdAgencia=@pmIdAgencia AND L.IdLinea='0005'
GO
/****** Object:  StoredProcedure [dbo].[spFinCuotas]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spFinCuotas]  @pmIdCliente VARCHAR(16),@pmIdAgencia  VARCHAR(16)
 AS 
 SELECT SUM(CASE Causacion WHEN 'QUINCENAL' THEN VrCuota*2 ELSE VrCuota END) AS TotalCuotas
 FROM Trn_FinPrestamo
 WHERE TipDoc='PR1' AND IdCliente=@pmIdCliente AND IdAgencia=@pmIdAgencia 
 AND TipoCredito IN ('PRESTAMO','TC') AND  IdEstado='0001' AND Anulado=0 
 AND (VrPrestamo>AcumCapital OR (CauAnticipado=1
  AND ISNULL((SELECT SUM(VrTotal-VrAbonado) AS VrSaldo FROM Trn_FinCuotas WHERE Trn_FinCuotas.TipDoc=Trn_FinPrestamo.TipDoc
  AND Trn_FinCuotas.IdPrestamo=Trn_FinPrestamo.IdPrestamo AND Trn_FinCuotas.IdCia=Trn_FinPrestamo.IdCia
  AND Trn_FinCuotas.Concepto='CAPITAL'),0)>0))
GO
/****** Object:  StoredProcedure [dbo].[spFinCuposSML]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[spFinCuposSML] @pmnAnno INT
AS
 SELECT   Item, nSmlvIni, nSmlvFin, Antig_Ini, Antig_Fin, MontoConGar, MontoSinGar 
 FROM   FinCuposEmp
 WHERE nAnno=@pmnAnno
 ORDER BY Item
GO
/****** Object:  StoredProcedure [dbo].[spFinPrestamo]    Script Date: 10/12/2025 8:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spFinPrestamo]  @pmIdCliente VARCHAR(16),@pmIdAgencia  VARCHAR(16)
 AS 
 SELECT  SUM(VrPrestamo) AS TotalPrestamos,SUM(TotalAbonos) AS TotalPagos
 FROM Trn_FinPrestamo AS P LEFT JOIN (SELECT A.TipDoc AS TipPrest,A.IdPrestamo AS NumPrest,A.IdCiaPre AS CdCiaPrest,SUM(A.TotalAbono) AS TotalAbonos
 FROM Trn_FinAbonos AS A INNER JOIN Trn_FinCuotas AS C ON A.TipDoc=C.TipDoc AND A.IdPrestamo=C.IdPrestamo AND A.IdCiaPre=C.IdCia AND A.ItemPre=C.Item
 WHERE A.IdCliente=@pmIdCliente AND A.IdAgencia=@pmIdAgencia AND C.Concepto='CAPITAL'  GROUP BY A.TipDoc,A.IdPrestamo,A.IdCiaPre)
  AS PG ON P.TipDoc=PG.TipPrest AND P.IdPrestamo=PG.NumPrest AND  P.IdCia=PG.CdCiaPrest
 WHERE  P.TipDoc='PR1' AND P.IdCliente=@pmIdCliente AND P.IdAgencia=@pmIdAgencia 
 AND P.IdLinea='0005' AND P.TipoCredito='TC'  AND P.Anulado=0
GO
